X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/545176521071a4edd242a2cd4163b363e818ec56..8aaef28406647d6aa706c34f57dd151f00b18e5b:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 1e1dcdc207..c6b827a1e4 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -57,6 +57,8 @@ some more information about what the wxWindow, which is the base class for all other window classes, does seems required as well. + I) + What does wxWindow do? It contains the common interface for the following jobs of its descendants: @@ -82,6 +84,8 @@ 5) A multitude of helper or extra methods for special purposes, such as Drag'n'Drop, managing validators etc. + 6) Display a border (sunken, raised, simple or none). + Normally one might expect, that one wxWindows window would always correspond to one GTK widget. Under GTK, there is no such allround widget that has all the functionality. Moreover, the GTK defines a client area as a different @@ -120,6 +124,55 @@ If the m_wxwindow field is set, then all input to this widget is inter- cepted and sent to the wxWindows class. If not, all input to the widget that gets pointed to by m_widget gets intercepted and sent to the class. + + II) + + The design of scrolling in wxWindows is markedly different from that offered + by the GTK itself and therefore we cannot simply take it as it is. In GTK, + clicking on a scrollbar belonging to scrolled window will inevitably move + the window. In wxWindows, the scrollbar will only emit an event, send this + to (normally) a wxScrolledWindow and that class will call ScrollWindow() + which actually moves the window and its subchildren. Note that GtkMyFixed + memorizes how much it has been scrolled but that wxWindows forgets this + so that the two coordinates systems have to be kept in synch. This is done + in various places using the myfixed->xoffset and myfixed->yoffset values. + + III) + + Singularily the most broken code in GTK is the code that is supposes to + inform subwindows (child windows) about new positions. Very often, duplicate + events are sent without changes in size or position, equally often no + events are sent at all (All this is due to a bug in the GtkContainer code + which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores + GTK's own system and it simply waits for size events for toplevel windows + and then iterates down the respective size events to all window. This has + the disadvantage, that windows might get size events before the GTK widget + actually has the reported size. This doesn't normally pose any problem, but + the OpenGl drawing routines rely on correct behaviour. Therefore, I have + added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas, + i.e. the wxGLCanvas will emit a size event, when (and not before) the X11 + window that is used for OpenGl output really has that size (as reported by + GTK). + + IV) + + If someone at some point of time feels the immense desire to have a look at, + change or attempt to optimse the Refresh() logic, this person will need an + intimate understanding of what a "draw" and what an "expose" events are and + what there are used for, in particular when used in connection with GTK's + own windowless widgets. Beware. + + V) + + Cursors, too, have been a constant source of pleasure. The main difficulty + is that a GdkWindow inherits a cursor if the programmer sets a new cursor + for the parent. To prevent this from doing too much harm, I use idle time + to set the cursor over and over again, starting from the toplevel windows + and ending with the youngest generation (speaking of parent and child windows). + Also don't forget that cursors (like much else) are connected to GdkWindows, + not GtkWidgets and that the "window" field of a GtkWidget might very well + point to the GdkWindow of the parent widget (-> "window less widget") and + that the two obviously have very different meanings. */ @@ -313,39 +366,6 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU #endif // GTK_MINOR_VERSION > 0 - -//----------------------------------------------------------------------------- -// "size_allocate" -//----------------------------------------------------------------------------- - -static void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) -{ - if (g_isIdle) - wxapp_install_idle_handler(); - - if (!win->m_hasVMT) - return; - - if (win->m_sizeSet) - return; - - win->m_sizeSet = TRUE; - -/* - wxPrintf( "OnSize from " ); - if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - wxPrintf( win->GetClassInfo()->GetClassName() ); - wxPrintf( " %d %d %d %d\n", (int)alloc->x, - (int)alloc->y, - (int)alloc->width, - (int)alloc->height ); -*/ - - wxSizeEvent event( win->GetSize(), win->GetId() ); - event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); -} - //----------------------------------------------------------------------------- // key event conversion routines //----------------------------------------------------------------------------- @@ -803,13 +823,12 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e GdkModifierType state; if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state); + bool ret = FALSE; + long key_code = map_to_unmodified_wx_keysym( gdk_event->keyval ); - /* sending unknown key events doesn't really make sense */ if (key_code == 0) return FALSE; - bool ret = FALSE; - wxKeyEvent event( wxEVT_KEY_DOWN ); event.SetTimestamp( gdk_event->time ); event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); @@ -823,8 +842,6 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e event.SetEventObject( win ); ret = win->GetEventHandler()->ProcessEvent( event ); - key_code = map_to_wx_keysym( gdk_event->keyval ); - #if wxUSE_ACCEL if (!ret) { @@ -842,10 +859,14 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e } } #endif // wxUSE_ACCEL + /* wxMSW doesn't send char events with Alt pressed */ /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x - will only be sent if it is not a menu accelerator. */ - if ((key_code != 0) && ! ret ) + will only be sent if it is not in an accelerator table. */ + key_code = map_to_wx_keysym( gdk_event->keyval ); + + if ( (!ret) && + (key_code != 0)) { wxKeyEvent event2( wxEVT_CHAR ); event2.SetTimestamp( gdk_event->time ); @@ -858,7 +879,7 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e event2.m_x = x; event2.m_y = y; event2.SetEventObject( win ); - ret = (ret || win->GetEventHandler()->ProcessEvent( event2 )); + ret = win->GetEventHandler()->ProcessEvent( event2 ); } /* win is a control: tab can be propagated up */ @@ -886,6 +907,7 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e #if (GTK_MINOR_VERSION > 0) /* pressing F10 will activate the menu bar of the top frame */ +/* if ( (!ret) && (gdk_event->keyval == GDK_F10) ) { @@ -901,10 +923,9 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e wxNode *node = menubar->GetMenus().First(); if (node) { - // doesn't work correctly - // wxMenu *firstMenu = (wxMenu*) node->Data(); - // gtk_menu_item_select( GTK_MENU_ITEM(firstMenu->m_owner) ); - // ret = TRUE; + wxMenu *firstMenu = (wxMenu*) node->Data(); + gtk_menu_item_select( GTK_MENU_ITEM(firstMenu->m_owner) ); + ret = TRUE; break; } } @@ -912,6 +933,7 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e ancestor = ancestor->GetParent(); } } +*/ #endif /* @@ -1039,13 +1061,6 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton } } -/* - wxPrintf( wxT("2) OnButtonPress from ") ); - if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - wxPrintf( win->GetClassInfo()->GetClassName() ); - wxPrintf( wxT(".\n") ); -*/ - wxEventType event_type = wxEVT_LEFT_DOWN; if (gdk_event->button == 1) @@ -1094,16 +1109,27 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton if (!g_captureWindow) { + int x = event.m_x; + int y = event.m_y; + if (win->m_wxwindow) + { + GtkMyFixed *myfixed = GTK_MYFIXED(win->m_wxwindow); + x += myfixed->xoffset; + y += myfixed->yoffset; + } + wxNode *node = win->GetChildren().First(); while (node) { wxWindow *child = (wxWindow*)node->Data(); + + node = node->Next(); + if (!child->IsShown()) + continue; if (child->m_isStaticBox) { // wxStaticBox is transparent in the box itself - int x = event.m_x; - int y = event.m_y; int xx1 = child->m_x; int yy1 = child->m_y; int xx2 = child->m_x + child->m_width; @@ -1128,10 +1154,10 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton else { if ((child->m_wxwindow == (GtkWidget*) NULL) && - (child->m_x <= event.m_x) && - (child->m_y <= event.m_y) && - (child->m_x+child->m_width >= event.m_x) && - (child->m_y+child->m_height >= event.m_y)) + (child->m_x <= x) && + (child->m_y <= y) && + (child->m_x+child->m_width >= x) && + (child->m_y+child->m_height >= y)) { win = child; event.m_x -= child->m_x; @@ -1139,7 +1165,6 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton break; } } - node = node->Next(); } } @@ -1147,6 +1172,13 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton gs_timeLastClick = gdk_event->time; +/* + wxPrintf( wxT("2) OnButtonPress from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( wxT(".\n") ); +*/ + if (win->GetEventHandler()->ProcessEvent( event )) { gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" ); @@ -1204,16 +1236,27 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto if (!g_captureWindow) { + int x = event.m_x; + int y = event.m_y; + if (win->m_wxwindow) + { + GtkMyFixed *myfixed = GTK_MYFIXED(win->m_wxwindow); + x += myfixed->xoffset; + y += myfixed->yoffset; + } + wxNode *node = win->GetChildren().First(); while (node) { wxWindow *child = (wxWindow*)node->Data(); + node = node->Next(); + if (!child->IsShown()) + continue; + if (child->m_isStaticBox) { // wxStaticBox is transparent in the box itself - int x = event.m_x; - int y = event.m_y; int xx1 = child->m_x; int yy1 = child->m_y; int xx2 = child->m_x + child->m_width; @@ -1238,10 +1281,10 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto else { if ((child->m_wxwindow == (GtkWidget*) NULL) && - (child->m_x <= event.m_x) && - (child->m_y <= event.m_y) && - (child->m_x+child->m_width >= event.m_x) && - (child->m_y+child->m_height >= event.m_y)) + (child->m_x <= x) && + (child->m_y <= y) && + (child->m_x+child->m_width >= x) && + (child->m_y+child->m_height >= y)) { win = child; event.m_x -= child->m_x; @@ -1249,7 +1292,6 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto break; } } - node = node->Next(); } } @@ -1314,16 +1356,27 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion if (!g_captureWindow) { + int x = event.m_x; + int y = event.m_y; + if (win->m_wxwindow) + { + GtkMyFixed *myfixed = GTK_MYFIXED(win->m_wxwindow); + x += myfixed->xoffset; + y += myfixed->yoffset; + } + wxNode *node = win->GetChildren().First(); while (node) { wxWindow *child = (wxWindow*)node->Data(); + node = node->Next(); + if (!child->IsShown()) + continue; + if (child->m_isStaticBox) { // wxStaticBox is transparent in the box itself - int x = event.m_x; - int y = event.m_y; int xx1 = child->m_x; int yy1 = child->m_y; int xx2 = child->m_x + child->m_width; @@ -1348,10 +1401,10 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion else { if ((child->m_wxwindow == (GtkWidget*) NULL) && - (child->m_x <= event.m_x) && - (child->m_y <= event.m_y) && - (child->m_x+child->m_width >= event.m_x) && - (child->m_y+child->m_height >= event.m_y)) + (child->m_x <= x) && + (child->m_y <= y) && + (child->m_x+child->m_width >= x) && + (child->m_y+child->m_height >= y)) { win = child; event.m_x -= child->m_x; @@ -1359,7 +1412,6 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion break; } } - node = node->Next(); } } @@ -1809,7 +1861,8 @@ void wxWindow::Init() m_isBeingDeleted = FALSE; m_noExpose = FALSE; - + m_nativeSizeEvent = FALSE; + m_hasScrolling = FALSE; m_isScrolling = FALSE; @@ -2069,13 +2122,6 @@ void wxWindow::PostCreation() { wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); - if (!m_isFrame) - { - /* frames have their own callback */ - gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this ); - } - if (m_wxwindow) { if (!m_noExpose) @@ -2164,14 +2210,9 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) m_y = y; m_width = width; m_height = height; - - m_sizeSet = FALSE; } else { - int old_width = m_width; - int old_height = m_height; - GtkMyFixed *myfixed = GTK_MYFIXED(m_parent->m_wxwindow); if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) @@ -2220,19 +2261,22 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) m_y-border, m_width+2*border, m_height+border+bottom_border ); - - if ((old_width != m_width) || - (old_height != m_height)) - { - m_sizeSet = FALSE; - } } - + /* - wxSizeEvent event( wxSize(m_width,m_height), GetId() ); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + wxPrintf( "OnSize sent from " ); + if (GetClassInfo() && GetClassInfo()->GetClassName()) + wxPrintf( GetClassInfo()->GetClassName() ); + wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height ); */ + + if (!m_nativeSizeEvent) + { + wxSizeEvent event( wxSize(m_width,m_height), GetId() ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + } + m_resizing = FALSE; } @@ -2243,7 +2287,7 @@ void wxWindow::OnInternalIdle() if (cursor.Ok()) { - /* I now set the cursor the anew in every OnInternalIdle call + /* I now set the cursor anew in every OnInternalIdle call as setting the cursor in a parent window also effects the windows above so that checking for the current cursor is not possible. */ @@ -2628,7 +2672,7 @@ bool wxWindow::Reparent( wxWindowBase *newParentBase ) if (oldParent) { - gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget ); + gtk_container_remove( GTK_CONTAINER(m_widget->parent), m_widget ); } wxASSERT( GTK_IS_WIDGET(m_widget) );