Fix up highlighting

svn path=/trunk/; revision=20791
This commit is contained in:
Matthias Clasen 2008-07-06 07:24:02 +00:00
parent a2802754f1
commit 75c668dbf2
5 changed files with 240 additions and 150 deletions

View File

@ -1,3 +1,10 @@
2008-07-06 Matthias Clasen <mclasen@redhat.com>
Bug 343663 source-buffer highlighting highlights "char" in
gtk_text_iter_forward_char
* demos/gtk-demo/*.c: Fix up the handrolled hilighting a bit.
2008-07-06 Matthias Clasen <mclasen@redhat.com>
Bug 327582 Incomplete docs for GtkSettings::gtk-icon-sizes

View File

@ -21,25 +21,25 @@ static GdkPixmap *pixmap = NULL;
/* Create a new pixmap of the appropriate size to store our scribbles */
static gboolean
scribble_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer data)
scribble_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer data)
{
if (pixmap)
g_object_unref (pixmap);
pixmap = gdk_pixmap_new (widget->window,
widget->allocation.width,
widget->allocation.height,
-1);
widget->allocation.width,
widget->allocation.height,
-1);
/* Initialize the pixmap to white */
gdk_draw_rectangle (pixmap,
widget->style->white_gc,
TRUE,
0, 0,
widget->allocation.width,
widget->allocation.height);
widget->style->white_gc,
TRUE,
0, 0,
widget->allocation.width,
widget->allocation.height);
/* We've handled the configure event, no need for further processing. */
return TRUE;
@ -48,8 +48,8 @@ scribble_configure_event (GtkWidget *widget,
/* Redraw the screen from the pixmap */
static gboolean
scribble_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
GdkEventExpose *event,
gpointer data)
{
/* We use the "foreground GC" for the widget since it already exists,
* but honestly any GC would work. The only thing to worry about
@ -57,12 +57,12 @@ scribble_expose_event (GtkWidget *widget,
*/
gdk_draw_drawable (widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
pixmap,
/* Only copy the area that was exposed. */
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
pixmap,
/* Only copy the area that was exposed. */
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return FALSE;
}
@ -70,8 +70,8 @@ scribble_expose_event (GtkWidget *widget,
/* Draw a rectangle on the screen */
static void
draw_brush (GtkWidget *widget,
gdouble x,
gdouble y)
gdouble x,
gdouble y)
{
GdkRectangle update_rect;
@ -82,21 +82,21 @@ draw_brush (GtkWidget *widget,
/* Paint to the pixmap, where we store our state */
gdk_draw_rectangle (pixmap,
widget->style->black_gc,
TRUE,
update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
widget->style->black_gc,
TRUE,
update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
/* Now invalidate the affected region of the drawing area. */
gdk_window_invalidate_rect (widget->window,
&update_rect,
FALSE);
&update_rect,
FALSE);
}
static gboolean
scribble_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
scribble_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
if (pixmap == NULL)
return FALSE; /* paranoia check, in case we haven't gotten a configure event */
@ -109,9 +109,9 @@ scribble_button_press_event (GtkWidget *widget,
}
static gboolean
scribble_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
gpointer data)
scribble_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
gpointer data)
{
int x, y;
GdkModifierType state;
@ -141,9 +141,9 @@ scribble_motion_notify_event (GtkWidget *widget,
static gboolean
checkerboard_expose (GtkWidget *da,
GdkEventExpose *event,
gpointer data)
checkerboard_expose (GtkWidget *da,
GdkEventExpose *event,
gpointer data)
{
gint i, j, xcount, ycount;
GdkGC *gc1, *gc2;
@ -182,28 +182,28 @@ checkerboard_expose (GtkWidget *da,
j = SPACING;
ycount = xcount % 2; /* start with even/odd depending on row */
while (j < da->allocation.height)
{
GdkGC *gc;
if (ycount % 2)
gc = gc1;
else
gc = gc2;
{
GdkGC *gc;
if (ycount % 2)
gc = gc1;
else
gc = gc2;
/* If we're outside event->area, this will do nothing.
* It might be mildly more efficient if we handled
* the clipping ourselves, but again we're feeling lazy.
*/
gdk_draw_rectangle (da->window,
gc,
TRUE,
i, j,
CHECK_SIZE,
CHECK_SIZE);
/* If we're outside event->area, this will do nothing.
* It might be mildly more efficient if we handled
* the clipping ourselves, but again we're feeling lazy.
*/
gdk_draw_rectangle (da->window,
gc,
TRUE,
i, j,
CHECK_SIZE,
CHECK_SIZE);
j += CHECK_SIZE + SPACING;
++ycount;
}
j += CHECK_SIZE + SPACING;
++ycount;
}
i += CHECK_SIZE + SPACING;
++xcount;
@ -240,7 +240,7 @@ do_drawingarea (GtkWidget *do_widget)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (do_widget));
gtk_widget_get_screen (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Drawing Area");
g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL);
@ -257,7 +257,7 @@ do_drawingarea (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Checkerboard pattern</u>");
"<u>Checkerboard pattern</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL);
@ -271,7 +271,7 @@ do_drawingarea (GtkWidget *do_widget)
gtk_container_add (GTK_CONTAINER (frame), da);
g_signal_connect (da, "expose_event",
G_CALLBACK (checkerboard_expose), NULL);
G_CALLBACK (checkerboard_expose), NULL);
/*
* Create the scribble area
@ -279,7 +279,7 @@ do_drawingarea (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Scribble area</u>");
"<u>Scribble area</u>");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL);
@ -295,26 +295,26 @@ do_drawingarea (GtkWidget *do_widget)
/* Signals used to handle backing pixmap */
g_signal_connect (da, "expose_event",
G_CALLBACK (scribble_expose_event), NULL);
G_CALLBACK (scribble_expose_event), NULL);
g_signal_connect (da,"configure_event",
G_CALLBACK (scribble_configure_event), NULL);
G_CALLBACK (scribble_configure_event), NULL);
/* Event signals */
g_signal_connect (da, "motion_notify_event",
G_CALLBACK (scribble_motion_notify_event), NULL);
G_CALLBACK (scribble_motion_notify_event), NULL);
g_signal_connect (da, "button_press_event",
G_CALLBACK (scribble_button_press_event), NULL);
G_CALLBACK (scribble_button_press_event), NULL);
/* Ask to receive events the drawing area doesn't normally
* subscribe to
*/
gtk_widget_set_events (da, gtk_widget_get_events (da)
| GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_POINTER_MOTION_MASK
| GDK_POINTER_MOTION_HINT_MASK);
| GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_POINTER_MOTION_MASK
| GDK_POINTER_MOTION_HINT_MASK);
}

View File

@ -16,16 +16,16 @@
*/
static void
insert_link (GtkTextBuffer *buffer,
GtkTextIter *iter,
gchar *text,
gint page)
GtkTextIter *iter,
gchar *text,
gint page)
{
GtkTextTag *tag;
tag = gtk_text_buffer_create_tag (buffer, NULL,
"foreground", "blue",
"underline", PANGO_UNDERLINE_SINGLE,
NULL);
"foreground", "blue",
"underline", PANGO_UNDERLINE_SINGLE,
NULL);
g_object_set_data (G_OBJECT (tag), "page", GINT_TO_POINTER (page));
gtk_text_buffer_insert_with_tags (buffer, iter, text, -1, tag, NULL);
}
@ -35,7 +35,7 @@ insert_link (GtkTextBuffer *buffer,
*/
static void
show_page (GtkTextBuffer *buffer,
gint page)
gint page)
{
GtkTextIter iter;
@ -52,12 +52,12 @@ show_page (GtkTextBuffer *buffer,
else if (page == 2)
{
gtk_text_buffer_insert (buffer, &iter,
"A tag is an attribute that can be applied to some range of text. "
"For example, a tag might be called \"bold\" and make the text inside "
"the tag bold. However, the tag concept is more general than that; "
"tags don't have to affect appearance. They can instead affect the "
"behavior of mouse and key presses, \"lock\" a range of text so the "
"user can't edit it, or countless other things.\n", -1);
"A tag is an attribute that can be applied to some range of text. "
"For example, a tag might be called \"bold\" and make the text inside "
"the tag bold. However, the tag concept is more general than that; "
"tags don't have to affect appearance. They can instead affect the "
"behavior of mouse and key presses, \"lock\" a range of text so the "
"user can't edit it, or countless other things.\n", -1);
insert_link (buffer, &iter, "Go back", 1);
}
else if (page == 3)
@ -65,12 +65,12 @@ show_page (GtkTextBuffer *buffer,
GtkTextTag *tag;
tag = gtk_text_buffer_create_tag (buffer, NULL,
"weight", PANGO_WEIGHT_BOLD,
NULL);
"weight", PANGO_WEIGHT_BOLD,
NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, "hypertext:\n", -1, tag, NULL);
gtk_text_buffer_insert (buffer, &iter,
"machine-readable text that is not sequential but is organized "
"so that related items of information are connected.\n", -1);
"machine-readable text that is not sequential but is organized "
"so that related items of information are connected.\n", -1);
insert_link (buffer, &iter, "Go back", 1);
}
}
@ -81,7 +81,7 @@ show_page (GtkTextBuffer *buffer,
*/
static void
follow_if_link (GtkWidget *text_view,
GtkTextIter *iter)
GtkTextIter *iter)
{
GSList *tags = NULL, *tagp = NULL;
@ -93,8 +93,8 @@ follow_if_link (GtkWidget *text_view,
if (page != 0)
{
show_page (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), page);
break;
show_page (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), page);
break;
}
}
@ -106,7 +106,7 @@ follow_if_link (GtkWidget *text_view,
*/
static gboolean
key_press_event (GtkWidget *text_view,
GdkEventKey *event)
GdkEventKey *event)
{
GtkTextIter iter;
GtkTextBuffer *buffer;
@ -132,7 +132,7 @@ key_press_event (GtkWidget *text_view,
*/
static gboolean
event_after (GtkWidget *text_view,
GdkEvent *ev)
GdkEvent *ev)
{
GtkTextIter start, end, iter;
GtkTextBuffer *buffer;
@ -215,7 +215,7 @@ set_cursor_if_appropriate (GtkTextView *text_view,
*/
static gboolean
motion_notify_event (GtkWidget *text_view,
GdkEventMotion *event)
GdkEventMotion *event)
{
gint x, y;
@ -234,7 +234,7 @@ motion_notify_event (GtkWidget *text_view,
*/
static gboolean
visibility_notify_event (GtkWidget *text_view,
GdkEventVisibility *event)
GdkEventVisibility *event)
{
gint wx, wy, bx, by;
@ -265,12 +265,12 @@ do_hypertext (GtkWidget *do_widget)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (do_widget));
gtk_widget_get_screen (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window),
450, 450);
450, 450);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
G_CALLBACK (gtk_widget_destroyed), &window);
gtk_window_set_title (GTK_WINDOW (window), "Hypertext");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
@ -278,20 +278,20 @@ do_hypertext (GtkWidget *do_widget)
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
g_signal_connect (view, "key-press-event",
G_CALLBACK (key_press_event), NULL);
G_CALLBACK (key_press_event), NULL);
g_signal_connect (view, "event-after",
G_CALLBACK (event_after), NULL);
G_CALLBACK (event_after), NULL);
g_signal_connect (view, "motion-notify-event",
G_CALLBACK (motion_notify_event), NULL);
G_CALLBACK (motion_notify_event), NULL);
g_signal_connect (view, "visibility-notify-event",
G_CALLBACK (visibility_notify_event), NULL);
G_CALLBACK (visibility_notify_event), NULL);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (window), sw);
gtk_container_add (GTK_CONTAINER (sw), view);

View File

@ -195,11 +195,12 @@ static gchar *types[] =
"const ",
"void",
"gint",
"int ",
"char ",
" int ",
" char ",
"gchar ",
"gfloat",
"float",
"double",
"gint8",
"gint16",
"gint32",
@ -234,6 +235,87 @@ static gchar *types[] =
"GdkPixbuf ",
"GError",
"size_t",
"GtkAboutDialog ",
"GtkAction ",
"GtkActionEntry ",
"GtkRadioActionEntry ",
"GtkIconFactory ",
"GtkStockItem ",
"GtkIconSet ",
"GtkTextBuffer ",
"GtkStatusbar ",
"GtkTextIter ",
"GtkTextMark ",
"GdkEventWindowState ",
"GtkActionGroup ",
"GtkUIManager ",
"GtkRadioAction ",
"GtkActionClass ",
"GtkToggleActionEntry ",
"GtkAssistant ",
"GtkBuilder ",
"GtkSizeGroup ",
"GtkTreeModel ",
"GtkTreeSelection ",
"GdkDisplay ",
"GdkScreen ",
"GdkWindow ",
"GdkEventButton ",
"GdkCursor ",
"GtkTreeIter ",
"GtkTreeViewColumn ",
"GdkDisplayManager ",
"GtkClipboard ",
"GtkIconSize ",
"GtkImage ",
"GdkDragContext ",
"GtkSelectionData ",
"GtkDialog ",
"GtkMenuItem ",
"GtkListStore ",
"GtkCellLayout ",
"GtkCellRenderer ",
"GtkTreePath ",
"GtkTreeStore ",
"GtkEntry ",
"GtkEditable ",
"GtkEditableClass ",
"GdkPixmap ",
"GdkEventConfigure ",
"GdkEventMotion ",
"GdkModifierType ",
"GtkEntryCompletion ",
"GtkToolItem ",
"GDir ",
"GtkIconView ",
"GtkCellRendererText ",
"GtkContainer ",
"GtkAccelGroup ",
"GtkPaned ",
"GtkPrintOperation ",
"GtkPrintContext ",
"cairo_t ",
"PangoLayout "
"PangoFontDescription ",
"PangoRenderer ",
"PangoMatrix ",
"PangoContext ",
"PangoLayout ",
"GtkTable ",
"GtkToggleButton ",
"GString ",
"GtkIconSize ",
"GtkTreeView ",
"GtkTextTag ",
"GdkEvent ",
"GdkEventKey ",
"GtkTextView ",
"GdkEventVisibility ",
"GdkBitmap ",
"GtkTextChildAnchor ",
"GArray ",
"GtkCellEditable ",
"GtkCellRendererToggle ",
NULL
};
@ -308,7 +390,8 @@ parse_chars (gchar *text,
}
/* check for types */
for (i = 0; types[i] != NULL; i++)
if (!strncmp (text, types[i], strlen (types[i])))
if (!strncmp (text, types[i], strlen (types[i])) ||
(start && types[i][0] == ' ' && !strncmp (text, types[i] + 1, strlen (types[i]) - 1)))
{
*end_ptr = text + strlen (types[i]);
*tag = "type";

View File

@ -82,13 +82,13 @@ load_pixbufs (GError **error)
{
filename = demo_find_file (image_names[i], error);
if (!filename)
return FALSE; /* Note that "error" was filled with a GError */
return FALSE; /* Note that "error" was filled with a GError */
images[i] = gdk_pixbuf_new_from_file (filename, error);
g_free (filename);
if (!images[i])
return FALSE; /* Note that "error" was filled with a GError */
return FALSE; /* Note that "error" was filled with a GError */
}
return TRUE;
@ -96,9 +96,9 @@ load_pixbufs (GError **error)
/* Expose callback for the drawing area */
static gint
expose_cb (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
expose_cb (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
{
guchar *pixels;
int rowstride;
@ -108,12 +108,12 @@ expose_cb (GtkWidget *widget,
pixels = gdk_pixbuf_get_pixels (frame) + rowstride * event->area.y + event->area.x * 3;
gdk_draw_rgb_image_dithalign (widget->window,
widget->style->black_gc,
event->area.x, event->area.y,
event->area.width, event->area.height,
GDK_RGB_DITHER_NORMAL,
pixels, rowstride,
event->area.x, event->area.y);
widget->style->black_gc,
event->area.x, event->area.y,
event->area.width, event->area.height,
GDK_RGB_DITHER_NORMAL,
pixels, rowstride,
event->area.x, event->area.y);
return TRUE;
}
@ -132,7 +132,7 @@ timeout (gpointer data)
double radius;
gdk_pixbuf_copy_area (background, 0, 0, back_width, back_height,
frame, 0, 0);
frame, 0, 0);
f = (double) (frame_num % CYCLE_LEN) / CYCLE_LEN;
@ -175,16 +175,16 @@ timeout (gpointer data)
r2.height = back_height;
if (gdk_rectangle_intersect (&r1, &r2, &dest))
gdk_pixbuf_composite (images[i],
frame,
dest.x, dest.y,
dest.width, dest.height,
xpos, ypos,
k, k,
GDK_INTERP_NEAREST,
((i & 1)
? MAX (127, fabs (255 * sin (f * 2.0 * G_PI)))
: MAX (127, fabs (255 * cos (f * 2.0 * G_PI)))));
gdk_pixbuf_composite (images[i],
frame,
dest.x, dest.y,
dest.width, dest.height,
xpos, ypos,
k, k,
GDK_INTERP_NEAREST,
((i & 1)
? MAX (127, fabs (255 * sin (f * 2.0 * G_PI)))
: MAX (127, fabs (255 * cos (f * 2.0 * G_PI)))));
}
GDK_THREADS_ENTER ();
@ -199,7 +199,7 @@ static guint timeout_id;
static void
cleanup_callback (GtkObject *object,
gpointer data)
gpointer data)
{
g_source_remove (timeout_id);
timeout_id = 0;
@ -214,7 +214,7 @@ do_pixbufs (GtkWidget *do_widget)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (do_widget));
gtk_widget_get_screen (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Pixbufs");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
@ -224,38 +224,38 @@ do_pixbufs (GtkWidget *do_widget)
error = NULL;
if (!load_pixbufs (&error))
{
GtkWidget *dialog;
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to load an image: %s",
error->message);
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to load an image: %s",
error->message);
g_error_free (error);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
gtk_widget_show (dialog);
}
gtk_widget_show (dialog);
}
else
{
gtk_widget_set_size_request (window, back_width, back_height);
{
gtk_widget_set_size_request (window, back_width, back_height);
frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, back_width, back_height);
frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, back_width, back_height);
da = gtk_drawing_area_new ();
da = gtk_drawing_area_new ();
g_signal_connect (da, "expose_event",
G_CALLBACK (expose_cb), NULL);
g_signal_connect (da, "expose_event",
G_CALLBACK (expose_cb), NULL);
gtk_container_add (GTK_CONTAINER (window), da);
gtk_container_add (GTK_CONTAINER (window), da);
timeout_id = g_timeout_add (FRAME_DELAY, timeout, NULL);
}
timeout_id = g_timeout_add (FRAME_DELAY, timeout, NULL);
}
}
if (!GTK_WIDGET_VISIBLE (window))