Mercurial > dwindows
comparison gtk4/dw.c @ 2757:b91bc30d0e4a
GTK4: dw_menu_popup() coordinates are relative to the parent window.
The coordinates in the context events in GTK4 had been relative to the
container or tree widget, causing the menu to popup in offset locations.
Added a function to convert from the widget coordinate to the window.
The events now pass window relative coordinates so when passed to
dw_menu_popup() the menu appears in about the right location.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 03 Jan 2022 15:45:15 +0000 |
parents | ee1cfa7d645e |
children | e1b5dbec0796 |
comparison
equal
deleted
inserted
replaced
2756:4f09bf72b391 | 2757:b91bc30d0e4a |
---|---|
988 } | 988 } |
989 } | 989 } |
990 return retval; | 990 return retval; |
991 } | 991 } |
992 | 992 |
993 /* Convert coordinate system from the widget to the window */ | |
994 void _dw_event_coordinates_to_window(GtkWidget *widget, double *x, double *y) | |
995 { | |
996 GtkRoot *root = (widget && GTK_IS_WIDGET(widget)) ? gtk_widget_get_root(widget) : NULL; | |
997 | |
998 if(root && GTK_IS_WIDGET(root)) | |
999 { | |
1000 GtkWidget *parent = GTK_WIDGET(root); | |
1001 | |
1002 /* If the parent is a window, try to use the box attached to it... */ | |
1003 if(GTK_IS_WINDOW(parent)) | |
1004 { | |
1005 GtkWidget *box = g_object_get_data(G_OBJECT(parent), "_dw_grid"); | |
1006 | |
1007 if(box && GTK_IS_GRID(box)) | |
1008 parent = box; | |
1009 } | |
1010 | |
1011 graphene_point_t *treepoint = graphene_point_init(graphene_point_alloc(), (float)*x, (float)*y); | |
1012 graphene_point_t *windowpoint = graphene_point_alloc(); | |
1013 | |
1014 if(gtk_widget_compute_point(widget, GTK_WIDGET(root), treepoint, windowpoint)) | |
1015 { | |
1016 *x = (double)windowpoint->x; | |
1017 *y = (double)windowpoint->y; | |
1018 } | |
1019 | |
1020 graphene_point_free(treepoint); | |
1021 graphene_point_free(windowpoint); | |
1022 } | |
1023 } | |
1024 | |
993 #define _DW_DATA_TYPE_STRING 0 | 1025 #define _DW_DATA_TYPE_STRING 0 |
994 #define _DW_DATA_TYPE_POINTER 1 | 1026 #define _DW_DATA_TYPE_POINTER 1 |
995 | 1027 |
996 static gint _dw_tree_context_event(GtkGestureSingle *gesture, int n_press, double x, double y, gpointer data) | 1028 static gint _dw_tree_context_event(GtkGestureSingle *gesture, int n_press, double x, double y, gpointer data) |
997 { | 1029 { |
1006 { | 1038 { |
1007 int (*contextfunc)(HWND, char *, int, int, void *, void *) = work.func; | 1039 int (*contextfunc)(HWND, char *, int, int, void *, void *) = work.func; |
1008 char *text = NULL; | 1040 char *text = NULL; |
1009 void *itemdata = NULL; | 1041 void *itemdata = NULL; |
1010 GtkWidget *widget = work.window; | 1042 GtkWidget *widget = work.window; |
1011 | 1043 |
1044 _dw_event_coordinates_to_window(widget, &x, &y); | |
1045 | |
1012 /* Containers and trees are inside scrolled window widgets */ | 1046 /* Containers and trees are inside scrolled window widgets */ |
1013 if(GTK_IS_SCROLLED_WINDOW(widget)) | 1047 if(GTK_IS_SCROLLED_WINDOW(widget)) |
1014 widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "_dw_user")); | 1048 widget = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "_dw_user")); |
1015 | 1049 |
1016 if(widget && GTK_IS_TREE_VIEW(widget)) | 1050 if(widget && GTK_IS_TREE_VIEW(widget)) |