gdl statusbar patch
- From: Jeroen Zwartepoorte <Jeroen xs4all nl>
- To: gnome-devtools gnome org
- Subject: gdl statusbar patch
- Date: 25 Aug 2001 23:20:44 +0200
Hi,
This patch adds a statusbar item to scintilla-ui.xml. The item is
implemented in scintilla-control.c. It displays the line & column
position of the cursor in the format "lines:columns".
For some reason, "cvs diff -u" doesn't include the addition to
ChangeLog, so please add that manually:
2001-08-25 Jeroen Zwartepoorte <jeroen xs4all nl>
* scintilla-control/scintilla-ui.xml: Added EditorStats statusbar item.
* scintilla-control/scintilla-control.c: Implemented EditorStats
statusbar item. Displays "lines:columns" information.
Jeroen
Index: scintilla-control/scintilla-control.c
===================================================================
RCS file: /cvs/gnome/gdl/scintilla-control/scintilla-control.c,v
retrieving revision 1.13
diff -u -r1.13 scintilla-control.c
--- scintilla-control/scintilla-control.c 2001/07/20 04:35:16 1.13
+++ scintilla-control/scintilla-control.c 2001/08/25 21:17:19
@@ -61,6 +61,8 @@
CORBA_Environment *ev,
gpointer user_data);
+static void scintilla_update_statusbar (ScintillaObject *sci);
+
static void notify_cb (ScintillaObject *sci, int wparam, void *lparam,
gpointer user_data);
static void destroy_cb (ScintillaObject *sci, gpointer data);
@@ -176,6 +178,11 @@
ScintillaObject *sci)
{
BonoboUIComponent *ui_component;
+ GtkWidget *fixed, *lines, *colon, *cols, *frame;
+ GtkRequisition req;
+ int pos;
+ BonoboControl *status;
+
ui_component = bonobo_control_get_ui_component (control);
if (activate) {
@@ -193,10 +200,55 @@
bonobo_ui_util_set_ui (ui_component, GDL_DATADIR,
"scintilla-ui.xml", "scintilla-control");
bonobo_ui_component_thaw (ui_component, NULL);
+
+ /* Sadly, we need to recreate the statusbar widget everytime
+ * scintilla activates: the widget can't be reparented atm */
+
+ /* Create widgets */
+ lines = gtk_label_new ("WWW");
+ colon = gtk_label_new (":");
+ cols = gtk_label_new ("WWW");
+ fixed = gtk_fixed_new ();
+
+ /* Add widgets and set size */
+ gtk_misc_set_alignment (GTK_MISC (lines), 1.0, 0.5);
+ gtk_fixed_put (GTK_FIXED (fixed), lines, 0, 0);
+ gtk_widget_size_request (lines, &req);
+ gtk_fixed_put (GTK_FIXED (fixed), colon, req.width, 0);
+ pos = req.width;
+ gtk_widget_size_request (colon, &req);
+ pos += req.width;
+ gtk_fixed_put (GTK_FIXED (fixed), cols, pos, 0);
+ gtk_widget_size_request (cols, &req);
+ gtk_widget_set_usize (fixed, pos + req.width, req.height);
+
+ /* Create frame for labels */
+ frame = gtk_frame_new (NULL);
+ status = bonobo_control_new (frame);
+
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ gtk_container_add (GTK_CONTAINER (frame), fixed);
+ gtk_widget_show_all (frame);
+
+ /* Store lines, colon and cols labels as data (needed for updating) */
+ gtk_object_set_data (GTK_OBJECT (sci), "lines", lines);
+ gtk_object_set_data (GTK_OBJECT (sci), "colon", colon);
+ gtk_object_set_data (GTK_OBJECT (sci), "cols", cols);
+
+ /* Add control to statusbar */
+ bonobo_ui_component_object_set (ui_component, "/status/EditorStats",
+ BONOBO_OBJREF (status),
+ NULL);
+
+ scintilla_update_statusbar (sci);
} else {
#if 0
bonobo_ui_component_rm (ui_component, "/", NULL);
#endif
+ gtk_object_set_data (GTK_OBJECT (sci), "lines", NULL);
+ gtk_object_set_data (GTK_OBJECT (sci), "colon", NULL);
+ gtk_object_set_data (GTK_OBJECT (sci), "cols", NULL);
+
bonobo_ui_component_unset_container (ui_component);
}
}
@@ -285,6 +337,37 @@
}
}
+static void
+scintilla_update_statusbar (ScintillaObject *sci)
+{
+ GtkWidget *lines, *colon, *cols;
+ GtkRequisition req;
+ int caretPos, linePos, colPos;
+ gchar text[10];
+
+ lines = gtk_object_get_data (GTK_OBJECT (sci), "lines");
+ colon = gtk_object_get_data (GTK_OBJECT (sci), "colon");
+ cols = gtk_object_get_data (GTK_OBJECT (sci), "cols");
+
+ if (lines) {
+ /* Get data */
+ caretPos = scintilla_send_message (sci, SCI_GETCURRENTPOS, 0, 0);
+ linePos = scintilla_send_message (sci, SCI_LINEFROMPOSITION, caretPos, 0);
+ colPos = scintilla_send_message (sci, SCI_GETCOLUMN, caretPos, 0);
+
+ /* Set label text */
+ snprintf (text, 10, "%i", linePos);
+ gtk_label_set_text (GTK_LABEL (lines), text);
+ snprintf (text, 10, "%i", colPos);
+ gtk_label_set_text (GTK_LABEL (cols), text);
+
+ /* Reposition lines label */
+ gtk_widget_size_request (lines, &req);
+ gtk_widget_set_uposition (lines, colon->allocation.x - req.width,
+ colon->allocation.y);
+ }
+}
+
/*
* Verb Implementations
*/
@@ -443,6 +526,9 @@
notification->foldLevelNow,
notification->foldLevelPrev);
}
+ break;
+ case SCN_UPDATEUI :
+ scintilla_update_statusbar (sci);
break;
}
}
Index: scintilla-control/scintilla-ui.xml
===================================================================
RCS file: /cvs/gnome/gdl/scintilla-control/scintilla-ui.xml,v
retrieving revision 1.5
diff -u -r1.5 scintilla-ui.xml
--- scintilla-control/scintilla-ui.xml 2001/07/20 04:35:16 1.5
+++ scintilla-control/scintilla-ui.xml 2001/08/25 21:17:19
@@ -51,4 +51,7 @@
<menuitem name="EditReplace" verb="" _label="_Replace"/>
</placeholder>
</dockitem>
+ <status>
+ <control name="EditorStats"/>
+ </status>
</Root>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]