[dasher: 5/43] ClearAllContext: provide default impl, override to optimize in Gtk + iPhone
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 5/43] ClearAllContext: provide default impl, override to optimize in Gtk + iPhone
- Date: Thu, 23 Jun 2011 18:56:10 +0000 (UTC)
commit ca9793ba14218ee71c32b9c9ddebe6815228f6f8
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Mon May 9 10:59:10 2011 +0100
ClearAllContext: provide default impl, override to optimize in Gtk + iPhone
Src/DasherCore/DasherInterfaceBase.cpp | 2 ++
Src/DasherCore/DasherInterfaceBase.h | 7 +++++--
Src/Gtk2/DasherControl.cpp | 6 ++++++
Src/Gtk2/DasherControl.h | 1 +
Src/Gtk2/GtkDasherControl.cpp | 5 +++++
Src/Gtk2/GtkDasherControl.h | 1 +
Src/Gtk2/dasher_editor.cpp | 6 ++++++
Src/Gtk2/dasher_editor.h | 2 ++
Src/Gtk2/dasher_editor_internal.cpp | 21 +++++++++++----------
Src/MacOSX/COSXDasherControl.mm | 2 +-
Src/iPhone/Classes/CDasherInterfaceBridge.h | 1 +
Src/iPhone/Classes/CDasherInterfaceBridge.mm | 4 ++++
12 files changed, 45 insertions(+), 13 deletions(-)
---
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 5a0ee0d..89bf202 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -686,6 +686,8 @@ void CDasherInterfaceBase::ResetNats() {
}
void CDasherInterfaceBase::ClearAllContext() {
+ ctrlDelete(true, CControlManager::EDIT_FILE);
+ ctrlDelete(false, CControlManager::EDIT_FILE);
SetBuffer(0);
}
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index 029bab6..893ef2d 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -410,8 +410,11 @@ public:
///Subclasses should return the contents of (the specified subrange of) the edit buffer
virtual std::string GetContext(unsigned int iStart, unsigned int iLength)=0;
- ///Subclasses should override to clear text edit box, etc., etc., but then
- /// call this (superclass) implementation as well to rebuild the model...
+ ///Clears all written text from edit buffer and rebuilds the model. The default
+ /// implementation does this using the control mode editDelete mechanism
+ /// (one call forward, one back), followed by a call to SetBuffer(0). Subclasses
+ /// may (optionally) override with more efficient / easier implementations, but
+ /// should make the same call to SetBuffer.
virtual void ClearAllContext();
virtual std::string GetAllContext()=0;
diff --git a/Src/Gtk2/DasherControl.cpp b/Src/Gtk2/DasherControl.cpp
index 59bad50..f1fba80 100644
--- a/Src/Gtk2/DasherControl.cpp
+++ b/Src/Gtk2/DasherControl.cpp
@@ -199,6 +199,12 @@ void CDasherControl::ScanColourFiles(std::vector<std::string> &vFileList) {
g_pattern_spec_free(colourglob);
}
+void CDasherControl::ClearAllContext() {
+ gtk_dasher_control_clear_all_context(m_pDasherControl);
+ //SetBuffer(0); //the editor's clear method emits a "buffer_changed" signal,
+ //which does this for us automatically.
+}
+
std::string CDasherControl::GetAllContext() {
const gchar *text = gtk_dasher_control_get_all_text(m_pDasherControl);
return text;
diff --git a/Src/Gtk2/DasherControl.h b/Src/Gtk2/DasherControl.h
index 07fcb88..c2a8ac2 100644
--- a/Src/Gtk2/DasherControl.h
+++ b/Src/Gtk2/DasherControl.h
@@ -137,6 +137,7 @@ public:
virtual void WriteTrainFile(const std::string &filename, const std::string &strNewText);
+ virtual void ClearAllContext();
virtual std::string GetAllContext();
std::string GetContext(unsigned int iStart, unsigned int iLength);
diff --git a/Src/Gtk2/GtkDasherControl.cpp b/Src/Gtk2/GtkDasherControl.cpp
index f338bd6..a752b96 100644
--- a/Src/Gtk2/GtkDasherControl.cpp
+++ b/Src/Gtk2/GtkDasherControl.cpp
@@ -213,6 +213,11 @@ gtk_dasher_control_get_all_text(GtkDasherControl *pControl) {
return dasher_editor_get_all_text(pPrivate->pEditor);
}
+void gtk_dasher_control_clear_all_context(GtkDasherControl *pControl) {
+ GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pControl);
+ dasher_editor_clear(pPrivate->pEditor);
+}
+
void
gtk_dasher_control_set_buffer(GtkDasherControl *pControl, int iOffset) {
GtkDasherControlPrivate *pPrivate = GTK_DASHER_CONTROL_GET_PRIVATE(pControl);
diff --git a/Src/Gtk2/GtkDasherControl.h b/Src/Gtk2/GtkDasherControl.h
index 5968a20..af59972 100644
--- a/Src/Gtk2/GtkDasherControl.h
+++ b/Src/Gtk2/GtkDasherControl.h
@@ -79,6 +79,7 @@ const char *gtk_dasher_control_get_parameter_string(GtkDasherControl * pControl,
GArray *gtk_dasher_control_get_allowed_values(GtkDasherControl * pControl, int iParameter);
void gtk_dasher_control_train(GtkDasherControl * pControl, const gchar * szFilename);
void gtk_dasher_control_set_editor(GtkDasherControl *pControl, DasherEditor *pEditor);
+void gtk_dasher_control_clear_all_context(GtkDasherControl *pControl);
const gchar* gtk_dasher_control_get_all_text(GtkDasherControl *pControl);
const gchar* gtk_dasher_control_get_context(GtkDasherControl *pControl, unsigned int iOffset, unsigned int iLength);
//void gtk_dasher_control_invalidate_context(GtkDasherControl *pControl, bool bForceStart);
diff --git a/Src/Gtk2/dasher_editor.cpp b/Src/Gtk2/dasher_editor.cpp
index 53d8db3..7cf2989 100644
--- a/Src/Gtk2/dasher_editor.cpp
+++ b/Src/Gtk2/dasher_editor.cpp
@@ -141,6 +141,7 @@ dasher_editor_class_init(DasherEditorClass *pClass) {
pClass->action_set_control = NULL;
pClass->action_set_auto = NULL;
#endif
+ pClass->clear = NULL;
pClass->get_all_text = NULL;
pClass->get_new_text = NULL;
pClass->output = NULL;
@@ -364,6 +365,11 @@ dasher_editor_get_filename(DasherEditor *pSelf) {
return NULL;
}
+void dasher_editor_clear(DasherEditor *pSelf) {
+ if (DASHER_EDITOR_GET_CLASS(pSelf)->clear)
+ DASHER_EDITOR_GET_CLASS(pSelf)->clear(pSelf);
+}
+
const gchar *
dasher_editor_get_all_text(DasherEditor *pSelf) {
if(DASHER_EDITOR_GET_CLASS(pSelf)->get_all_text)
diff --git a/Src/Gtk2/dasher_editor.h b/Src/Gtk2/dasher_editor.h
index 373628a..f03cf4d 100644
--- a/Src/Gtk2/dasher_editor.h
+++ b/Src/Gtk2/dasher_editor.h
@@ -46,6 +46,7 @@ struct _DasherEditorClass {
void (*action_set_control)(DasherEditor *, int, bool);
void (*action_set_auto)(DasherEditor *, int, bool);
#endif
+ void (*clear)(DasherEditor *);
const gchar *(*get_all_text)(DasherEditor *);
const gchar *(*get_new_text)(DasherEditor *);
void (*output)(DasherEditor *, const gchar *, int);
@@ -102,6 +103,7 @@ void dasher_editor_action_set_control(DasherEditor *pSelf, int iActionID, bool b
void dasher_editor_action_set_auto(DasherEditor *pSelf, int iActionID, bool bValue);
#endif
+void dasher_editor_clear(DasherEditor *pSelf);
const gchar *dasher_editor_get_all_text(DasherEditor *pSelf);
const gchar *dasher_editor_get_new_text(DasherEditor *pSelf);
diff --git a/Src/Gtk2/dasher_editor_internal.cpp b/Src/Gtk2/dasher_editor_internal.cpp
index 008191b..9052143 100644
--- a/Src/Gtk2/dasher_editor_internal.cpp
+++ b/Src/Gtk2/dasher_editor_internal.cpp
@@ -162,7 +162,6 @@ static void dasher_editor_internal_generate_filename(DasherEditor *pSelf);
static void dasher_editor_internal_open(DasherEditor *pSelf, const gchar *szFilename);
static bool dasher_editor_internal_save_as(DasherEditor *pSelf, const gchar *szFilename, bool bAppend);
static void dasher_editor_internal_create_buffer(DasherEditor *pSelf);
-static void dasher_editor_internal_clear(DasherEditor *pSelf, gboolean bStore);
static void dasher_editor_internal_clipboard(DasherEditor *pSelf, clipboard_action act);
/* To be obsoleted by movement to GTK buffers */
@@ -196,6 +195,7 @@ void dasher_editor_internal_grab_focus(DasherEditor *pSelf);
gboolean dasher_editor_internal_file_changed(DasherEditor *pSelf);
const gchar *dasher_editor_internal_get_filename(DasherEditor *pSelf);
+static void dasher_editor_internal_clear(DasherEditor *pSelf);
const gchar *dasher_editor_internal_get_all_text(DasherEditor *pSelf);
const gchar *dasher_editor_internal_get_new_text(DasherEditor *pSelf);
@@ -247,6 +247,7 @@ dasher_editor_internal_class_init(DasherEditorInternalClass *pClass) {
pParentClass->grab_focus = dasher_editor_internal_grab_focus;
pParentClass->file_changed = dasher_editor_internal_file_changed;
pParentClass->get_filename = dasher_editor_internal_get_filename;
+ pParentClass->clear = dasher_editor_internal_clear;
pParentClass->get_all_text = dasher_editor_internal_get_all_text;
pParentClass->get_new_text = dasher_editor_internal_get_new_text;
pParentClass->handle_parameter_change = dasher_editor_internal_handle_parameter_change;
@@ -354,7 +355,7 @@ dasher_editor_internal_initialise(DasherEditor *pSelf, DasherAppSettings *pAppSe
dasher_editor_internal_open(pSelf, szFullPath);
else {
dasher_editor_internal_generate_filename(pSelf);
- dasher_editor_internal_clear(pSelf, false);
+ dasher_editor_internal_clear(pSelf);
}
// pPrivate->pGameModeHelper = GAME_MODE_HELPER(game_mode_helper_new(pXML, (void*)pSelf));
@@ -434,16 +435,13 @@ void
dasher_editor_internal_action_button(DasherEditor *pSelf, DasherAction *pAction) {
if(pAction) {
dasher_action_execute(pAction, DASHER_EDITOR(pSelf), -1);
- dasher_editor_internal_clear(pSelf, true);
- }
- else { // Clear button
- dasher_editor_internal_clear(pSelf, false);
- }
+ } //else, Clear button (?!)
+ dasher_editor_internal_clear(pSelf);
}
#endif
static void
-dasher_editor_internal_clear(DasherEditor *pSelf, gboolean bStore) {
+dasher_editor_internal_clear(DasherEditor *pSelf) {
DasherEditorInternalPrivate *pPrivate = DASHER_EDITOR_INTERNAL_GET_PRIVATE(pSelf);
GtkTextIter start, end;
@@ -646,7 +644,10 @@ dasher_editor_internal_delete(DasherEditor *pSelf, int iLength, int iOffset) {
GtkTextIter end;
- gtk_text_buffer_get_iter_at_mark(pPrivate->pBuffer, &end, gtk_text_buffer_get_insert(pPrivate->pBuffer));
+ //Dasher offset 0 = "the first character"; Gtk Text Buffer offset 0
+ // = "the cursor position just before the first character" (and we want
+ // the cursor position just after)
+ gtk_text_buffer_get_iter_at_offset(pPrivate->pBuffer, &end, iOffset+1);
GtkTextIter start = end;
@@ -1733,7 +1734,7 @@ dasher_editor_internal_new_buffer(DasherEditor *pSelf, const gchar *szFilename)
}
else {
dasher_editor_internal_generate_filename(pSelf);
- dasher_editor_internal_clear(pSelf, false);
+ dasher_editor_internal_clear(pSelf);
}
// g_signal_emit_by_name(G_OBJECT(pSelf), "buffer_changed", G_OBJECT(pSelf), NULL, NULL);
diff --git a/Src/MacOSX/COSXDasherControl.mm b/Src/MacOSX/COSXDasherControl.mm
index 2600f21..4a51408 100644
--- a/Src/MacOSX/COSXDasherControl.mm
+++ b/Src/MacOSX/COSXDasherControl.mm
@@ -325,7 +325,7 @@ std::string COSXDasherControl::GetAllContext() {
void COSXDasherControl::ClearAllContext() {
[dasherEdit clearContext];
- CDasherInterfaceBase::ClearAllContext();
+ SetBuffer(0);
}
diff --git a/Src/iPhone/Classes/CDasherInterfaceBridge.h b/Src/iPhone/Classes/CDasherInterfaceBridge.h
index f3cef4d..42cfd20 100644
--- a/Src/iPhone/Classes/CDasherInterfaceBridge.h
+++ b/Src/iPhone/Classes/CDasherInterfaceBridge.h
@@ -48,6 +48,7 @@ public:
void CopyToClipboard(const std::string &strText);
bool SupportsSpeech();
void Speak(const std::string &strText, bool bInterrupt);
+ void ClearAllContext();
std::string GetAllContext();
std::string GetContext(unsigned int iStart, unsigned int iLength);
unsigned int ctrlMove(bool bForwards, CControlManager::EditDistance dist);
diff --git a/Src/iPhone/Classes/CDasherInterfaceBridge.mm b/Src/iPhone/Classes/CDasherInterfaceBridge.mm
index 0eaabfe..fa1a09b 100644
--- a/Src/iPhone/Classes/CDasherInterfaceBridge.mm
+++ b/Src/iPhone/Classes/CDasherInterfaceBridge.mm
@@ -217,6 +217,10 @@ void CDasherInterfaceBridge::Speak(const std::string &strText, bool bInterrupt)
[dasherApp speak:NSStringFromStdString(strText) interrupt:bInterrupt];
}
+void CDasherInterfaceBridge::ClearAllContext() {
+ [dasherApp clearText];
+}
+
string CDasherInterfaceBridge::GetAllContext() {
return StdStringFromNSString([dasherApp allText]);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]