Mercurial > vim
comparison src/gui_gtk_f.c @ 11271:cd8dbed175a1 v8.0.0521
patch 8.0.0521: GtkForm handling is outdated
commit https://github.com/vim/vim/commit/99a6e8dd824399332563caa6cacfcda33da1f366
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 29 18:07:40 2017 +0200
patch 8.0.0521: GtkForm handling is outdated
Problem: GtkForm handling is outdated.
Solution: Get rid of event filter functions. Get rid of GtkForm.width and
.height. Eliminate gtk_widget_size_request() calls. (Kazunobu
Kuriyama)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 29 Mar 2017 18:15:05 +0200 |
parents | 51888fb2599f |
children | 049857c9b1c4 |
comparison
equal
deleted
inserted
replaced
11270:eacea025e9b9 | 11271:cd8dbed175a1 |
---|---|
90 static void gtk_form_position_child(GtkForm *form, | 90 static void gtk_form_position_child(GtkForm *form, |
91 GtkFormChild *child, | 91 GtkFormChild *child, |
92 gboolean force_allocate); | 92 gboolean force_allocate); |
93 static void gtk_form_position_children(GtkForm *form); | 93 static void gtk_form_position_children(GtkForm *form); |
94 | 94 |
95 #if !GTK_CHECK_VERSION(3,0,0) | |
96 static GdkFilterReturn gtk_form_filter(GdkXEvent *gdk_xevent, | |
97 GdkEvent *event, | |
98 gpointer data); | |
99 static GdkFilterReturn gtk_form_main_filter(GdkXEvent *gdk_xevent, | |
100 GdkEvent *event, | |
101 gpointer data); | |
102 #endif | |
103 #if !GTK_CHECK_VERSION(3,16,0) | 95 #if !GTK_CHECK_VERSION(3,16,0) |
104 static void gtk_form_set_static_gravity(GdkWindow *window, | 96 static void gtk_form_set_static_gravity(GdkWindow *window, |
105 gboolean use_static); | 97 gboolean use_static); |
106 #endif | 98 #endif |
107 | 99 |
169 if (GTK_WIDGET_REALIZED(form)) | 161 if (GTK_WIDGET_REALIZED(form)) |
170 #endif | 162 #endif |
171 gtk_form_attach_child_window(form, child); | 163 gtk_form_attach_child_window(form, child); |
172 | 164 |
173 gtk_widget_set_parent(child_widget, GTK_WIDGET(form)); | 165 gtk_widget_set_parent(child_widget, GTK_WIDGET(form)); |
174 #if !GTK_CHECK_VERSION(3,0,0) | |
175 gtk_widget_size_request(child->widget, NULL); | |
176 #endif | |
177 | 166 |
178 #if GTK_CHECK_VERSION(3,0,0) | 167 #if GTK_CHECK_VERSION(3,0,0) |
179 if (gtk_widget_get_realized(GTK_WIDGET(form)) | 168 if (gtk_widget_get_realized(GTK_WIDGET(form)) |
180 && !gtk_widget_get_realized(child_widget)) | 169 && !gtk_widget_get_realized(child_widget)) |
181 #else | 170 #else |
299 { | 288 { |
300 #if GTK_CHECK_VERSION(3,0,0) | 289 #if GTK_CHECK_VERSION(3,0,0) |
301 gtk_widget_set_has_window(GTK_WIDGET(form), TRUE); | 290 gtk_widget_set_has_window(GTK_WIDGET(form), TRUE); |
302 #endif | 291 #endif |
303 form->children = NULL; | 292 form->children = NULL; |
304 | |
305 #if !GTK_CHECK_VERSION(3,0,0) | |
306 form->width = 1; | |
307 form->height = 1; | |
308 #endif | |
309 | |
310 form->bin_window = NULL; | 293 form->bin_window = NULL; |
311 | |
312 #if !GTK_CHECK_VERSION(3,0,0) | |
313 form->configure_serial = 0; | |
314 form->visibility = GDK_VISIBILITY_PARTIAL; | |
315 #endif | |
316 | |
317 form->freeze_count = 0; | 294 form->freeze_count = 0; |
318 } | 295 } |
319 | 296 |
320 /* | 297 /* |
321 * Widget methods | 298 * Widget methods |
410 } | 387 } |
411 #else | 388 #else |
412 widget->style = gtk_style_attach(widget->style, widget->window); | 389 widget->style = gtk_style_attach(widget->style, widget->window); |
413 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); | 390 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); |
414 gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL); | 391 gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL); |
415 #endif | |
416 | |
417 #if !GTK_CHECK_VERSION(3,0,0) | |
418 gdk_window_add_filter(widget->window, gtk_form_main_filter, form); | |
419 gdk_window_add_filter(form->bin_window, gtk_form_filter, form); | |
420 #endif | 392 #endif |
421 | 393 |
422 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) | 394 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) |
423 { | 395 { |
424 GtkFormChild *child = tmp_list->data; | 396 GtkFormChild *child = tmp_list->data; |
538 } | 510 } |
539 | 511 |
540 static void | 512 static void |
541 gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition) | 513 gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition) |
542 { | 514 { |
543 #if !GTK_CHECK_VERSION(3,0,0) | |
544 GList *tmp_list; | |
545 GtkForm *form; | |
546 #endif | |
547 | |
548 g_return_if_fail(GTK_IS_FORM(widget)); | 515 g_return_if_fail(GTK_IS_FORM(widget)); |
549 | 516 g_return_if_fail(requisition != NULL); |
550 #if !GTK_CHECK_VERSION(3,0,0) | 517 |
551 form = GTK_FORM(widget); | |
552 #endif | |
553 | |
554 #if GTK_CHECK_VERSION(3,0,0) | |
555 requisition->width = 1; | 518 requisition->width = 1; |
556 requisition->height = 1; | 519 requisition->height = 1; |
557 #else | |
558 requisition->width = form->width; | |
559 requisition->height = form->height; | |
560 | |
561 tmp_list = form->children; | |
562 | |
563 while (tmp_list) | |
564 { | |
565 GtkFormChild *child = tmp_list->data; | |
566 gtk_widget_size_request(child->widget, NULL); | |
567 tmp_list = tmp_list->next; | |
568 } | |
569 #endif | |
570 } | 520 } |
571 | 521 |
572 #if GTK_CHECK_VERSION(3,0,0) | 522 #if GTK_CHECK_VERSION(3,0,0) |
573 static void | 523 static void |
574 gtk_form_get_preferred_width(GtkWidget *widget, | 524 gtk_form_get_preferred_width(GtkWidget *widget, |
733 | 683 |
734 if (event->window == form->bin_window) | 684 if (event->window == form->bin_window) |
735 return FALSE; | 685 return FALSE; |
736 | 686 |
737 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) | 687 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) |
738 { | 688 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
739 GtkFormChild *formchild = tmp_list->data; | 689 GTK_WIDGET(((GtkFormChild *)tmp_list->data)->widget), |
740 GtkWidget *child = formchild->widget; | 690 event); |
741 /* | |
742 * The following chunk of code is taken from gtkcontainer.c. The | |
743 * gtk1.x code synthesized expose events directly on the child widgets, | |
744 * which can't be done in gtk2 | |
745 */ | |
746 if (GTK_WIDGET_DRAWABLE(child) && GTK_WIDGET_NO_WINDOW(child) | |
747 && child->window == event->window) | |
748 { | |
749 GdkEventExpose child_event; | |
750 child_event = *event; | |
751 | |
752 child_event.region = gtk_widget_region_intersect(child, event->region); | |
753 if (!gdk_region_empty(child_event.region)) | |
754 { | |
755 gdk_region_get_clipbox(child_event.region, &child_event.area); | |
756 gtk_widget_send_expose(child, (GdkEvent *)&child_event); | |
757 } | |
758 } | |
759 } | |
760 | 691 |
761 return FALSE; | 692 return FALSE; |
762 } | 693 } |
763 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 694 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
764 | 695 |
1066 | 997 |
1067 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) | 998 for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) |
1068 gtk_form_position_child(form, tmp_list->data, FALSE); | 999 gtk_form_position_child(form, tmp_list->data, FALSE); |
1069 } | 1000 } |
1070 | 1001 |
1071 /* Callbacks */ | |
1072 | |
1073 /* The main event filter. Actually, we probably don't really need | |
1074 * to install this as a filter at all, since we are calling it | |
1075 * directly above in the expose-handling hack. | |
1076 * | |
1077 * This routine identifies expose events that are generated when | |
1078 * we've temporarily moved the bin_window_origin, and translates | |
1079 * them or discards them, depending on whether we are obscured | |
1080 * or not. | |
1081 */ | |
1082 #if !GTK_CHECK_VERSION(3,0,0) | |
1083 static GdkFilterReturn | |
1084 gtk_form_filter(GdkXEvent *gdk_xevent, GdkEvent *event UNUSED, gpointer data) | |
1085 { | |
1086 XEvent *xevent; | |
1087 GtkForm *form; | |
1088 | |
1089 xevent = (XEvent *) gdk_xevent; | |
1090 form = GTK_FORM(data); | |
1091 | |
1092 switch (xevent->type) | |
1093 { | |
1094 case Expose: | |
1095 if (xevent->xexpose.serial == form->configure_serial) | |
1096 { | |
1097 if (form->visibility == GDK_VISIBILITY_UNOBSCURED) | |
1098 return GDK_FILTER_REMOVE; | |
1099 else | |
1100 break; | |
1101 } | |
1102 break; | |
1103 | |
1104 case ConfigureNotify: | |
1105 if ((xevent->xconfigure.x != 0) || (xevent->xconfigure.y != 0)) | |
1106 form->configure_serial = xevent->xconfigure.serial; | |
1107 break; | |
1108 } | |
1109 | |
1110 return GDK_FILTER_CONTINUE; | |
1111 } | |
1112 | |
1113 /* Although GDK does have a GDK_VISIBILITY_NOTIFY event, | |
1114 * there is no corresponding event in GTK, so we have | |
1115 * to get the events from a filter | |
1116 */ | |
1117 static GdkFilterReturn | |
1118 gtk_form_main_filter(GdkXEvent *gdk_xevent, | |
1119 GdkEvent *event UNUSED, | |
1120 gpointer data) | |
1121 { | |
1122 XEvent *xevent; | |
1123 GtkForm *form; | |
1124 | |
1125 xevent = (XEvent *) gdk_xevent; | |
1126 form = GTK_FORM(data); | |
1127 | |
1128 if (xevent->type == VisibilityNotify) | |
1129 { | |
1130 switch (xevent->xvisibility.state) | |
1131 { | |
1132 case VisibilityFullyObscured: | |
1133 form->visibility = GDK_VISIBILITY_FULLY_OBSCURED; | |
1134 break; | |
1135 | |
1136 case VisibilityPartiallyObscured: | |
1137 form->visibility = GDK_VISIBILITY_PARTIAL; | |
1138 break; | |
1139 | |
1140 case VisibilityUnobscured: | |
1141 form->visibility = GDK_VISIBILITY_UNOBSCURED; | |
1142 break; | |
1143 } | |
1144 | |
1145 return GDK_FILTER_REMOVE; | |
1146 } | |
1147 return GDK_FILTER_CONTINUE; | |
1148 } | |
1149 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | |
1150 | |
1151 #if !GTK_CHECK_VERSION(3,16,0) | 1002 #if !GTK_CHECK_VERSION(3,16,0) |
1152 static void | 1003 static void |
1153 gtk_form_set_static_gravity(GdkWindow *window, gboolean use_static) | 1004 gtk_form_set_static_gravity(GdkWindow *window, gboolean use_static) |
1154 { | 1005 { |
1155 /* We don't check if static gravity is actually supported, because it | 1006 /* We don't check if static gravity is actually supported, because it |