X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a60c99e6a919bad02f33ee1429a831f00b0df819..8fdca65cf20ae4dba861fa6667d6e233cbb900cf:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 863f51e463..e382126ada 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -116,6 +116,7 @@ extern wxList wxPendingDelete; extern wxList wxTopLevelWindows; extern bool g_blockEventsOnDrag; + bool g_capturing = FALSE; //----------------------------------------------------------------------------- // "expose_event" (of m_wxwindow, not of m_widget) @@ -133,6 +134,13 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp if (gdk_event->count > 0) return; +/* + printf( "OnExpose from " ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + printf( win->GetClassInfo()->GetClassName() ); + printf( ".\n" ); +*/ + wxPaintEvent event( win->GetId() ); event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( event ); @@ -371,21 +379,24 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton // Some control don't have their own X window and thus cannot get // any events. - wxNode *node = win->GetChildren()->First(); - while (node) + if (!g_capturing) { - wxWindow *child = (wxWindow*)node->Data(); - if ((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)) + wxNode *node = win->GetChildren()->First(); + while (node) { - win = child; - event.m_x -= child->m_x; - event.m_y -= child->m_y; - break; + wxWindow *child = (wxWindow*)node->Data(); + if ((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)) + { + win = child; + event.m_x -= child->m_x; + event.m_y -= child->m_y; + break; + } + node = node->Next(); } - node = node->Next(); } event.SetEventObject( win ); @@ -403,6 +414,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; + if (g_blockEventsOnDrag) return TRUE; if (!win->HasVMT()) return TRUE; @@ -437,21 +449,24 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto // Some control don't have their own X window and thus cannot get // any events. - wxNode *node = win->GetChildren()->First(); - while (node) + if (!g_capturing) { - wxWindow *child = (wxWindow*)node->Data(); - if ((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)) + wxNode *node = win->GetChildren()->First(); + while (node) { - win = child; - event.m_x -= child->m_x; - event.m_y -= child->m_y; - break; + wxWindow *child = (wxWindow*)node->Data(); + if ((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)) + { + win = child; + event.m_x -= child->m_x; + event.m_y -= child->m_y; + break; + } + node = node->Next(); } - node = node->Next(); } event.SetEventObject( win ); @@ -469,6 +484,7 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win ) { if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; + if (g_blockEventsOnDrag) return TRUE; if (!win->HasVMT()) return TRUE; @@ -495,21 +511,24 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion // Some control don't have their own X window and thus cannot get // any events. - wxNode *node = win->GetChildren()->First(); - while (node) + if (!g_capturing) { - wxWindow *child = (wxWindow*)node->Data(); - if ((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)) + wxNode *node = win->GetChildren()->First(); + while (node) { - win = child; - event.m_x -= child->m_x; - event.m_y -= child->m_y; - break; + wxWindow *child = (wxWindow*)node->Data(); + if ((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)) + { + win = child; + event.m_x -= child->m_x; + event.m_y -= child->m_y; + break; + } + node = node->Next(); } - node = node->Next(); } event.SetEventObject( win ); @@ -599,10 +618,19 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { if (widget->window != gdk_event->window) return TRUE; + if (g_blockEventsOnDrag) return TRUE; + if (!win->HasVMT()) return TRUE; - if (widget->window) +/* + printf( "OnEnter from " ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + printf( win->GetClassInfo()->GetClassName() ); + printf( ".\n" ); +*/ + + if ((widget->window) && (win->m_cursor)) gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() ); wxMouseEvent event( wxEVT_ENTER_WINDOW ); @@ -621,10 +649,19 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { if (widget->window != gdk_event->window) return TRUE; - if (!win->HasVMT()) return TRUE; + if (g_blockEventsOnDrag) return TRUE; - if (widget->window) + if (!win->HasVMT()) return TRUE; + +/* + printf( "OnLeave from " ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + printf( win->GetClassInfo()->GetClassName() ); + printf( ".\n" ); +*/ + + if ((widget->window) && (win->m_cursor)) gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() ); wxMouseEvent event( wxEVT_LEAVE_WINDOW ); @@ -762,6 +799,39 @@ static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW win->GetEventHandler()->ProcessEvent( event ); } +//----------------------------------------------------------------------------- +// "button_press_event" from scrollbar +//----------------------------------------------------------------------------- + +static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win ) +{ + if (gdk_event->window != widget->slider) return FALSE; + + win->m_isScrolling = TRUE; + + return FALSE; +} + +//----------------------------------------------------------------------------- +// "button_release_event" from scrollbar +//----------------------------------------------------------------------------- + +static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win ) +{ + if (gdk_event->window != widget->slider) return FALSE; + + GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(win->m_widget); + + if (widget == GTK_RANGE(s_window->vscrollbar)) + gtk_signal_emit_by_name( GTK_OBJECT(win->m_hAdjust), "value_changed" ); + else + gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" ); + + win->m_isScrolling = FALSE; + + return FALSE; +} + //----------------------------------------------------------------------------- // "drop_data_available_event" //----------------------------------------------------------------------------- @@ -815,7 +885,7 @@ wxWindow::wxWindow() m_eventHandler = this; m_windowValidator = (wxValidator *) NULL; m_windowId = -1; - m_cursor = new wxCursor( wxCURSOR_ARROW ); + m_cursor = (wxCursor *) NULL; m_font = *wxSWISS_FONT; m_windowStyle = 0; m_windowName = "noname"; @@ -828,6 +898,7 @@ wxWindow::wxWindow() m_hasVMT = FALSE; m_needParent = TRUE; m_hasScrolling = FALSE; + m_isScrolling = FALSE; m_hAdjust = (GtkAdjustment *) NULL; m_vAdjust = (GtkAdjustment *) NULL; m_oldHorizontalPos = 0.0; @@ -854,9 +925,20 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); m_hasScrolling = TRUE; - GtkScrolledWindow *s_window; - s_window = GTK_SCROLLED_WINDOW(m_widget); - + GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); + + gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_press_event", + (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_press_event", + (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_release_event", + (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_release_event", + (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); + GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); scroll_class->scrollbar_spacing = 0; @@ -868,18 +950,17 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->hscrollbar) ); m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->vscrollbar) ); - gtk_signal_connect (GTK_OBJECT (m_hAdjust), "value_changed", + gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); - gtk_signal_connect (GTK_OBJECT (m_vAdjust), "value_changed", + gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); - gtk_signal_connect (GTK_OBJECT (m_hAdjust), "changed", + gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed", (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this ); - gtk_signal_connect (GTK_OBJECT (m_vAdjust), "changed", + gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed", (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this ); - GtkViewport *viewport; - viewport = GTK_VIEWPORT(s_window->viewport); + GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport); if (m_windowStyle & wxRAISED_BORDER) { @@ -1018,6 +1099,8 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, m_windowSizer = (wxSizer *) NULL; m_sizerParent = (wxWindow *) NULL; m_autoLayout = FALSE; + m_hasScrolling = FALSE; + m_isScrolling = FALSE; m_pDropTarget = (wxDropTarget *) NULL; m_resizing = FALSE; m_windowValidator = (wxValidator *) NULL; @@ -1047,7 +1130,7 @@ void wxWindow::PostCreation(void) gdk_gc_set_exposures( m_wxwindow->style->fg_gc[0], TRUE ); } - SetCursor( wxSTANDARD_CURSOR ); + SetCursor( *wxSTANDARD_CURSOR ); m_hasVMT = TRUE; } @@ -1086,6 +1169,8 @@ bool wxWindow::HasVMT(void) bool wxWindow::Close( bool force ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); event.SetEventObject(this); event.SetForce(force); @@ -1095,6 +1180,8 @@ bool wxWindow::Close( bool force ) bool wxWindow::Destroy(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + m_hasVMT = FALSE; delete this; return TRUE; @@ -1155,6 +1242,8 @@ void wxWindow::ImplementSetPosition(void) void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (m_resizing) return; // I don't like recursions m_resizing = TRUE; @@ -1214,12 +1303,16 @@ void wxWindow::Move( int x, int y ) void wxWindow::GetSize( int *width, int *height ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (width) (*width) = m_width; if (height) (*height) = m_height; } void wxWindow::SetClientSize( int width, int height ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (!m_wxwindow) { SetSize( width, height ); @@ -1277,6 +1370,8 @@ void wxWindow::SetClientSize( int width, int height ) void wxWindow::GetClientSize( int *width, int *height ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (!m_wxwindow) { if (width) (*width) = m_width; @@ -1338,12 +1433,16 @@ void wxWindow::GetClientSize( int *width, int *height ) const void wxWindow::GetPosition( int *x, int *y ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (x) (*x) = m_x; if (y) (*y) = m_y; } void wxWindow::ClientToScreen( int *x, int *y ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) source = m_wxwindow->window; @@ -1369,6 +1468,8 @@ void wxWindow::ClientToScreen( int *x, int *y ) void wxWindow::ScreenToClient( int *x, int *y ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) source = m_wxwindow->window; @@ -1394,6 +1495,8 @@ void wxWindow::ScreenToClient( int *x, int *y ) void wxWindow::Centre( int direction ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (IS_KIND_OF(this,wxDialog) || IS_KIND_OF(this,wxFrame)) { if (direction & wxHORIZONTAL == wxHORIZONTAL) m_x = (gdk_screen_width () - m_width) / 2; @@ -1416,6 +1519,8 @@ void wxWindow::Centre( int direction ) void wxWindow::Fit(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + int maxX = 0; int maxY = 0; wxNode *node = GetChildren()->First(); @@ -1437,6 +1542,8 @@ void wxWindow::Fit(void) void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH) ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + m_minWidth = minW; m_minHeight = minH; m_maxWidth = maxW; @@ -1450,6 +1557,8 @@ void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) bool wxWindow::Show( bool show ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (show) gtk_widget_show( m_widget ); else @@ -1460,6 +1569,8 @@ bool wxWindow::Show( bool show ) void wxWindow::Enable( bool enable ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + m_isEnabled = enable; gtk_widget_set_sensitive( m_widget, enable ); if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable ); @@ -1467,12 +1578,28 @@ void wxWindow::Enable( bool enable ) int wxWindow::GetCharHeight(void) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + if (!m_font.Ok()) + { + wxFAIL_MSG( "invalid font" ); + return -1; + } + GdkFont *font = m_font.GetInternalFont( 1.0 ); return font->ascent + font->descent; } int wxWindow::GetCharWidth(void) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + if (!m_font.Ok()) + { + wxFAIL_MSG( "invalid font" ); + return -1; + } + GdkFont *font = m_font.GetInternalFont( 1.0 ); return gdk_string_width( font, "H" ); } @@ -1480,9 +1607,18 @@ int wxWindow::GetCharWidth(void) const void wxWindow::GetTextExtent( const wxString& string, int *x, int *y, int *descent, int *externalLeading, const wxFont *theFont, bool WXUNUSED(use16) ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxFont fontToUse = m_font; if (theFont) fontToUse = *theFont; + if (!fontToUse.Ok()) + { + wxFAIL_MSG( "invalid font" ); + return; + } + wxASSERT_MSG( (m_font.Ok()), "invalid font" ); + GdkFont *font = fontToUse.GetInternalFont( 1.0 ); if (x) (*x) = gdk_string_width( font, string ); if (y) (*y) = font->ascent + font->descent; @@ -1510,6 +1646,8 @@ void wxWindow::MakeModal( bool modal ) void wxWindow::SetFocus(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + GtkWidget *connect_widget = GetConnectWidget(); if (connect_widget) { @@ -1527,6 +1665,11 @@ bool wxWindow::OnClose(void) void wxWindow::AddChild( wxWindow *child ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxASSERT_MSG( (m_wxwindow != NULL), "window need client area" ); + wxASSERT_MSG( (child != NULL), "invalid child" ); + wxASSERT_MSG( (child->m_widget != NULL), "invalid child" ); + // Addchild is (often) called before the program // has left the parents constructor so that no // virtual tables work yet. The approach below @@ -1599,7 +1742,7 @@ wxList *wxWindow::GetChildren(void) void wxWindow::RemoveChild( wxWindow *child ) { if (GetChildren()) - GetChildren()->DeleteObject( child ); + GetChildren()->DeleteObject( child ); child->m_parent = (wxWindow *) NULL; } @@ -1615,11 +1758,15 @@ int wxWindow::GetReturnCode(void) void wxWindow::Raise(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (m_widget) gdk_window_raise( m_widget->window ); } void wxWindow::Lower(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (m_widget) gdk_window_lower( m_widget->window ); } @@ -1635,28 +1782,28 @@ void wxWindow::SetEventHandler( wxEvtHandler *handler ) void wxWindow::PushEventHandler(wxEvtHandler *handler) { - handler->SetNextHandler(GetEventHandler()); - SetEventHandler(handler); + handler->SetNextHandler(GetEventHandler()); + SetEventHandler(handler); } wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) { - if ( GetEventHandler() ) - { - wxEvtHandler *handlerA = GetEventHandler(); - wxEvtHandler *handlerB = handlerA->GetNextHandler(); - handlerA->SetNextHandler((wxEvtHandler *) NULL); - SetEventHandler(handlerB); - if ( deleteHandler ) - { - delete handlerA; - return (wxEvtHandler *) NULL; - } - else - return handlerA; - } - else - return (wxEvtHandler *) NULL; + if (GetEventHandler()) + { + wxEvtHandler *handlerA = GetEventHandler(); + wxEvtHandler *handlerB = handlerA->GetNextHandler(); + handlerA->SetNextHandler((wxEvtHandler *) NULL); + SetEventHandler(handlerB); + if (deleteHandler) + { + delete handlerA; + return (wxEvtHandler*) NULL; + } + else + return handlerA; + } + else + return (wxEvtHandler *) NULL; } wxValidator *wxWindow::GetValidator(void) @@ -1688,20 +1835,35 @@ wxWindowID wxWindow::GetId(void) void wxWindow::SetCursor( const wxCursor &cursor ) { - wxASSERT(m_cursor != NULL); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + if (m_cursor == NULL) + { + wxFAIL_MSG( "wxWindow::SetCursor m_cursor == NULL" ); + m_cursor = new wxCursor( wxCURSOR_ARROW ); + } + + if (cursor.Ok()) + { + if (*((wxCursor*)&cursor) == m_cursor) return; + *m_cursor = cursor; + } + else + { + *m_cursor = *wxSTANDARD_CURSOR; + } - if (m_cursor != NULL) - if (*m_cursor == cursor) - return; - (*m_cursor) = cursor; - if (m_widget->window) + if ((m_widget) && (m_widget->window)) gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); - if (m_wxwindow && m_wxwindow->window) + + if ((m_wxwindow) && (m_wxwindow->window)) gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() ); } void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (eraseBackground && m_wxwindow && m_wxwindow->window) { if (rect) @@ -1771,6 +1933,8 @@ bool wxWindow::IsExposed( const wxRect& rect ) const void wxWindow::Clear(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); } @@ -1781,6 +1945,8 @@ wxColour wxWindow::GetBackgroundColour(void) const void wxWindow::SetBackgroundColour( const wxColour &colour ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + m_backgroundColour = colour; if (m_wxwindow) { @@ -1803,6 +1969,8 @@ void wxWindow::SetForegroundColour( const wxColour &colour ) bool wxWindow::Validate(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxNode *node = GetChildren()->First(); while (node) { @@ -1816,6 +1984,8 @@ bool wxWindow::Validate(void) bool wxWindow::TransferDataToWindow(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxNode *node = GetChildren()->First(); while (node) { @@ -1833,6 +2003,8 @@ bool wxWindow::TransferDataToWindow(void) bool wxWindow::TransferDataFromWindow(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxNode *node = GetChildren()->First(); while (node) { @@ -1856,6 +2028,8 @@ void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) void wxWindow::InitDialog(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxInitDialogEvent event(GetId()); event.SetEventObject( this ); GetEventHandler()->ProcessEvent(event); @@ -1876,6 +2050,8 @@ static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + SetInvokingWindow( menu, this ); gtk_menu_popup( GTK_MENU(menu->m_menu), (GtkWidget *) NULL, (GtkWidget *) NULL, (GtkMenuPositionFunc) NULL, NULL, 0, 0 ); return TRUE; @@ -1883,6 +2059,8 @@ bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) ) void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + GtkWidget *dnd_widget = GetConnectWidget(); DisconnectDnDWidget( dnd_widget ); @@ -1934,6 +2112,8 @@ bool wxWindow::IsOwnGtkWindow( GdkWindow *window ) void wxWindow::SetFont( const wxFont &font ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + if (((wxFont*)&font)->Ok()) m_font = font; else @@ -1973,6 +2153,10 @@ long wxWindow::GetWindowStyleFlag(void) const void wxWindow::CaptureMouse(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (g_capturing == FALSE), "CaptureMouse called twice" ); + GtkWidget *connect_widget = GetConnectWidget(); gtk_grab_add( connect_widget ); gdk_pointer_grab ( connect_widget->window, FALSE, @@ -1981,13 +2165,19 @@ void wxWindow::CaptureMouse(void) GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK), (GdkWindow *) NULL, (GdkCursor *) NULL, GDK_CURRENT_TIME ); + g_capturing = TRUE; } void wxWindow::ReleaseMouse(void) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (g_capturing == TRUE), "ReleaseMouse called twice" ); + GtkWidget *connect_widget = GetConnectWidget(); gtk_grab_remove( connect_widget ); gdk_pointer_ungrab ( GDK_CURRENT_TIME ); + g_capturing = FALSE; } void wxWindow::SetTitle( const wxString &WXUNUSED(title) ) @@ -2053,46 +2243,56 @@ wxWindow *wxWindow::FindWindow( const wxString& name ) } void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, - int range, bool WXUNUSED(refresh) ) + int range, bool refresh ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); + if (!m_wxwindow) return; if (orient == wxHORIZONTAL) { float fpos = (float)pos; - m_oldHorizontalPos = fpos; float frange = (float)range; float fthumb = (float)thumbVisible; - if ((fabs(fpos-m_hAdjust->value) < 0.2) && - (fabs(frange-m_hAdjust->upper) < 0.2) && - (fabs(fthumb-m_hAdjust->page_size) < 0.2)) + if ((fabs(frange-m_hAdjust->upper) < 0.2) && + (fabs(fthumb-m_hAdjust->page_size) < 0.2)) + { + SetScrollPos( orient, pos, refresh ); return; + } + m_oldHorizontalPos = fpos; + m_hAdjust->lower = 0.0; m_hAdjust->upper = frange; m_hAdjust->value = fpos; m_hAdjust->step_increment = 1.0; - m_hAdjust->page_increment = (float)(wxMax(fthumb-2,0)); + m_hAdjust->page_increment = (float)(wxMax(fthumb,0)); m_hAdjust->page_size = fthumb; } else { float fpos = (float)pos; - m_oldVerticalPos = fpos; float frange = (float)range; float fthumb = (float)thumbVisible; - if ((fabs(fpos-m_vAdjust->value) < 0.2) && - (fabs(frange-m_vAdjust->upper) < 0.2) && - (fabs(fthumb-m_vAdjust->page_size) < 0.2)) + if ((fabs(frange-m_vAdjust->upper) < 0.2) && + (fabs(fthumb-m_vAdjust->page_size) < 0.2)) + { + SetScrollPos( orient, pos, refresh ); return; + } + + m_oldVerticalPos = fpos; m_vAdjust->lower = 0.0; m_vAdjust->upper = frange; m_vAdjust->value = fpos; m_vAdjust->step_increment = 1.0; - m_vAdjust->page_increment = (float)(wxMax(fthumb-2,0)); + m_vAdjust->page_increment = (float)(wxMax(fthumb,0)); m_vAdjust->page_size = fthumb; } @@ -2109,6 +2309,10 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); + if (!m_wxwindow) return; if (orient == wxHORIZONTAL) @@ -2127,17 +2331,24 @@ void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) m_vAdjust->value = fpos; } - if (m_wxwindow->window) - { - if (orient == wxHORIZONTAL) - gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); - else - gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); + if (!m_isScrolling) + { + if (m_wxwindow->window) + { + if (orient == wxHORIZONTAL) + gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); + else + gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); + } } } int wxWindow::GetScrollThumb( int orient ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); + if (!m_wxwindow) return 0; if (orient == wxHORIZONTAL) @@ -2148,6 +2359,10 @@ int wxWindow::GetScrollThumb( int orient ) const int wxWindow::GetScrollPos( int orient ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); + if (!m_wxwindow) return 0; if (orient == wxHORIZONTAL) @@ -2158,6 +2373,10 @@ int wxWindow::GetScrollPos( int orient ) const int wxWindow::GetScrollRange( int orient ) const { + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + + wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); + if (!m_wxwindow) return 0; if (orient == wxHORIZONTAL) @@ -2168,32 +2387,11 @@ int wxWindow::GetScrollRange( int orient ) const void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) { - if (!m_wxwindow) return; - -/* - bool refresh = FALSE; - - if ((m_drawingOffsetX == 0) && (m_drawingOffsetY == 0)) - { - m_drawingOffsetX = -16000; - m_drawingOffsetY = -16000; - refresh = TRUE; - } - else - { - m_drawingOffsetX += dx; - m_drawingOffsetY += dy; - } - -// printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY ); - - gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - if (refresh) Refresh(); + wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); - The code here is very nifty, but it doesn't work with - overlapping windows... -*/ + if (!m_wxwindow) return; int cw = 0; int ch = 0;