X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/43a18898651f71010606d8682fdf88cfc1c02193..e487524e492809638b7e335937c41fd432458a54:/src/gtk1/window.cpp diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 6da95fff04..6de4b2c637 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -26,6 +26,7 @@ #include "wx/menu.h" #include "wx/statusbr.h" #include "wx/intl.h" +#include "wx/settings.h" #include "gdk/gdkprivate.h" #include "gdk/gdkkeysyms.h" @@ -108,13 +109,13 @@ */ -//----------------------------------------------------------------------------- -// cond comp -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------- +// conditional compilation +//------------------------------------------------------------------------- #if (GTK_MINOR_VERSION == 1) -#if (GTK_MICRO_VERSION >= 3) -#define NEW_GTK_DND_CODE +#if (GTK_MICRO_VERSION >= 5) +#define NEW_GTK_SCROLL_CODE #endif #endif @@ -125,6 +126,7 @@ extern wxList wxPendingDelete; extern wxList wxTopLevelWindows; extern bool g_blockEventsOnDrag; +extern bool g_blockEventsOnScroll; static bool g_capturing = FALSE; // hack: we need something to pass to gtk_menu_popup, so we store the time of @@ -138,7 +140,6 @@ static guint32 gs_timeLastClick = 0; static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win ) { if (!win->HasVMT()) return; - if (g_blockEventsOnDrag) return; win->m_updateRegion.Union( gdk_event->area.x, gdk_event->area.y, @@ -168,7 +169,6 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win ) { if (!win->HasVMT()) return; - if (g_blockEventsOnDrag) return; win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); @@ -321,6 +321,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; if (g_blockEventsOnDrag) return TRUE; + if (g_blockEventsOnScroll) return TRUE; if (win->m_wxwindow) { @@ -431,6 +432,7 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; if (g_blockEventsOnDrag) return TRUE; + if (g_blockEventsOnScroll) return TRUE; if (!win->HasVMT()) return TRUE; @@ -501,7 +503,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; if (g_blockEventsOnDrag) return TRUE; - + if (g_blockEventsOnScroll) return TRUE; + if (!win->HasVMT()) return TRUE; /* @@ -713,11 +716,20 @@ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * float line_step = win->m_vAdjust->step_increment; float page_step = win->m_vAdjust->page_increment; - if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; - else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; - else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; - else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; - else command = wxEVT_SCROLL_THUMBTRACK; + if (win->m_isScrolling) + { + command = wxEVT_SCROLL_THUMBTRACK; + } + else + { + if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM; + else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP; + else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; + else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; + else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; + else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; + else command = wxEVT_SCROLL_THUMBTRACK; + } int value = (int)(win->m_vAdjust->value+0.5); @@ -750,12 +762,21 @@ static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * float line_step = win->m_hAdjust->step_increment; float page_step = win->m_hAdjust->page_increment; - - if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; - else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; - else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; - else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; - else command = wxEVT_SCROLL_THUMBTRACK; + + if (win->m_isScrolling) + { + command = wxEVT_SCROLL_THUMBTRACK; + } + else + { + if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM; + else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP; + else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; + else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; + else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; + else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; + else command = wxEVT_SCROLL_THUMBTRACK; + } int value = (int)(win->m_hAdjust->value+0.5); @@ -818,11 +839,14 @@ static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW // "button_press_event" from scrollbar //----------------------------------------------------------------------------- -static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win ) +static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), + GdkEventButton *WXUNUSED(gdk_event), + wxWindow *win ) { - if (gdk_event->window != widget->slider) return FALSE; - +// if (gdk_event->window != widget->slider) return FALSE; + win->m_isScrolling = TRUE; + g_blockEventsOnScroll = TRUE; return FALSE; } @@ -831,9 +855,15 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButto // "button_release_event" from scrollbar //----------------------------------------------------------------------------- -static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win ) +static gint gtk_scrollbar_button_release_callback( GtkRange *widget, + GdkEventButton *WXUNUSED(gdk_event), + wxWindow *win ) { - if (gdk_event->window != widget->slider) return FALSE; + +// don't test here as we can reelase the mouse while being over +// a different window then the slider +// +// if (gdk_event->window != widget->slider) return FALSE; GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(win->m_widget); @@ -843,43 +873,11 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventBut gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" ); win->m_isScrolling = FALSE; + g_blockEventsOnScroll = FALSE; return FALSE; } - -#ifdef NEW_GTK_DND_CODE - -#else - -//----------------------------------------------------------------------------- -// "drop_data_available_event" -//----------------------------------------------------------------------------- - -static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win ) -{ - if (!win->HasVMT()) return; - - if (win->GetDropTarget()) - { - int x = 0; - int y = 0; - gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); - - printf( "Drop data is of type %s.\n", event->data_type ); - - win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); - } - -/* - g_free (event->dropdataavailable.data); - g_free (event->dropdataavailable.data_type); -*/ -} - -#endif - // NEW_GTK_DND_CODE - //----------------------------------------------------------------------------- // InsertChild for wxWindow. //----------------------------------------------------------------------------- @@ -994,22 +992,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, PreCreation( parent, id, pos, size, style, name ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); - m_hasScrolling = TRUE; + GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); 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; @@ -1021,17 +1007,15 @@ 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", - (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", - (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); - - gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed", - (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this ); - gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed", - (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this ); + m_wxwindow = gtk_myfixed_new(); +#ifdef NEW_GTK_SCROLL_CODE + gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow ); + GtkViewport *viewport = GTK_VIEWPORT(s_window->child); +#else + gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport); +#endif if (m_windowStyle & wxRAISED_BORDER) { @@ -1046,17 +1030,11 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE ); } - m_wxwindow = gtk_myfixed_new(); - - GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); - if (m_windowStyle & wxTAB_TRAVERSAL == wxTAB_TRAVERSAL) GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); else GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); - gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); - // shut the viewport up gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); @@ -1077,6 +1055,36 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_hAdjust->page_size = 5.0; gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); + // these handlers block mouse events to any window during scrolling + // such as motion events and prevent GTK and wxWindows from fighting + // over where the slider should be + + 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 ); + + // these handers het notified when screen updates are required either when + // scrolling or when the window size (and therefore scrollbar configuration) + // has 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", + (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed", + (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this ); + gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed", + (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this ); + gtk_widget_show( m_wxwindow ); if (m_parent) m_parent->AddChild( this ); @@ -1108,7 +1116,7 @@ wxWindow::~wxWindow() if (m_wxwindow) gtk_widget_destroy( m_wxwindow ); if (m_widget) gtk_widget_destroy( m_widget ); - + if (m_cursor) delete m_cursor; DeleteRelatedConstraints(); @@ -1187,7 +1195,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, m_eventHandler = this; - m_windowId = id; + m_windowId = id == -1 ? wxNewId() : id; m_sizeSet = FALSE; @@ -1341,56 +1349,64 @@ void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags ) wxASSERT_MSG( (m_widget != NULL), "invalid window" ); wxASSERT_MSG( (m_parent != NULL), "wxWindow::SetSize requires parent.\n" ); - // Don't do anything for children of wxNotebook - if (m_parent->m_wxwindow == NULL) return; - if (m_resizing) return; // I don't like recursions m_resizing = TRUE; - int old_width = m_width; - int old_height = m_height; - - if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) - { - if (x != -1) m_x = x; - if (y != -1) m_y = y; - if (width != -1) m_width = width; - if (height != -1) m_height = height; - } - else + if (m_parent->m_wxwindow == NULL) // i.e. wxNotebook { + // don't set the size for children of wxNotebook, just take the values. m_x = x; m_y = y; m_width = width; - m_height = height; + m_height = height; } - - if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) + else { - if (width == -1) m_width = 80; - } + int old_width = m_width; + int old_height = m_height; + + if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) + { + if (x != -1) m_x = x; + if (y != -1) m_y = y; + if (width != -1) m_width = width; + if (height != -1) m_height = height; + } + else + { + m_x = x; + m_y = y; + m_width = width; + m_height = height; + } - if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) - { - if (height == -1) m_height = 26; - } + if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) + { + if (width == -1) m_width = 80; + } + + if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) + { + if (height == -1) m_height = 26; + } - if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; - if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; - if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; - if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; + if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; + if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; + if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; + if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; - wxPoint pt( m_parent->GetClientAreaOrigin() ); - gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y ); + wxPoint pt( m_parent->GetClientAreaOrigin() ); + gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y ); - if ((old_width != m_width) || (old_height != m_height)) - gtk_widget_set_usize( m_widget, m_width, m_height ); + if ((old_width != m_width) || (old_height != m_height)) + gtk_widget_set_usize( m_widget, m_width, m_height ); + } m_sizeSet = TRUE; wxSizeEvent event( wxSize(m_width,m_height), GetId() ); event.SetEventObject( this ); - ProcessEvent( event ); + GetEventHandler()->ProcessEvent( event ); m_resizing = FALSE; } @@ -1428,21 +1444,26 @@ void wxWindow::SetClientSize( int width, int height ) if (!m_hasScrolling) { -/* - do we have sunken dialogs ? - GtkStyleClass *window_class = m_wxwindow->style->klass; - dw += 2 * window_class->xthickness; - dh += 2 * window_class->ythickness; -*/ + if ((m_windowStyle & wxRAISED_BORDER) || + (m_windowStyle & wxSUNKEN_BORDER)) + { + dw += 2 * window_class->xthickness; + dh += 2 * window_class->ythickness; + } } else { GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); +#ifdef NEW_GTK_SCROLL_CODE + GtkWidget *viewport = scroll_window->child; +#else GtkWidget *viewport = scroll_window->viewport; +#endif + GtkStyleClass *viewport_class = viewport->style->klass; GtkWidget *hscrollbar = scroll_window->hscrollbar; @@ -1455,13 +1476,13 @@ void wxWindow::SetClientSize( int width, int height ) dh += 2 * viewport_class->ythickness; } - if (GTK_WIDGET_VISIBLE(vscrollbar)) + if (scroll_window->vscrollbar_visible) { dw += vscrollbar->allocation.width; dw += scroll_class->scrollbar_spacing; } - if (GTK_WIDGET_VISIBLE(hscrollbar)) + if (scroll_window->hscrollbar_visible) { dh += hscrollbar->allocation.height; dw += scroll_class->scrollbar_spacing; @@ -1488,25 +1509,27 @@ void wxWindow::GetClientSize( int *width, int *height ) const if (!m_hasScrolling) { -/* - do we have sunken dialogs ? - GtkStyleClass *window_class = m_wxwindow->style->klass; - dw += 2 * window_class->xthickness; - dh += 2 * window_class->ythickness; -*/ + if ((m_windowStyle & wxRAISED_BORDER) || + (m_windowStyle & wxSUNKEN_BORDER)) + { + dw += 2 * window_class->xthickness; + dh += 2 * window_class->ythickness; + } } else { GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); +#ifdef NEW_GTK_SCROLL_CODE + GtkWidget *viewport = scroll_window->child; +#else GtkWidget *viewport = scroll_window->viewport; - GtkStyleClass *viewport_class = viewport->style->klass; +#endif - GtkWidget *hscrollbar = scroll_window->hscrollbar; - GtkWidget *vscrollbar = scroll_window->vscrollbar; + GtkStyleClass *viewport_class = viewport->style->klass; if ((m_windowStyle & wxRAISED_BORDER) || (m_windowStyle & wxSUNKEN_BORDER)) @@ -1515,14 +1538,14 @@ void wxWindow::GetClientSize( int *width, int *height ) const dh += 2 * viewport_class->ythickness; } - if (GTK_WIDGET_VISIBLE(vscrollbar)) + if (scroll_window->vscrollbar_visible) { // dw += vscrollbar->allocation.width; dw += 15; // range.slider_width = 11 + 2*2pts edge dw += scroll_class->scrollbar_spacing; } - if (GTK_WIDGET_VISIBLE(hscrollbar)) + if (scroll_window->hscrollbar_visible) { // dh += hscrollbar->allocation.height; dh += 15; @@ -1664,7 +1687,7 @@ void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSE void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) { - //if (GetAutoLayout()) Layout(); +// if (GetAutoLayout()) Layout(); } bool wxWindow::Show( bool show ) @@ -1704,38 +1727,38 @@ int wxWindow::GetCharHeight() const int wxWindow::GetCharWidth() const { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - if (!m_font.Ok()) - { - wxFAIL_MSG( "invalid font" ); - return -1; - } + if (!m_font.Ok()) + { + wxFAIL_MSG( "invalid font" ); + return -1; + } - GdkFont *font = m_font.GetInternalFont( 1.0 ); - return gdk_string_width( font, "H" ); + GdkFont *font = m_font.GetInternalFont( 1.0 ); + return gdk_string_width( font, "H" ); } 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" ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - wxFont fontToUse = m_font; - if (theFont) fontToUse = *theFont; + wxFont fontToUse = m_font; + if (theFont) fontToUse = *theFont; - if (!fontToUse.Ok()) - { - wxFAIL_MSG( "invalid font" ); - return; - } - wxASSERT_MSG( (m_font.Ok()), "invalid font" ); + 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; - if (descent) (*descent) = font->descent; - if (externalLeading) (*externalLeading) = 0; // ?? + GdkFont *font = fontToUse.GetInternalFont( 1.0 ); + if (x) (*x) = gdk_string_width( font, string ); + if (y) (*y) = font->ascent + font->descent; + if (descent) (*descent) = font->descent; + if (externalLeading) (*externalLeading) = 0; // ?? } void wxWindow::MakeModal( bool modal ) @@ -1758,105 +1781,122 @@ void wxWindow::MakeModal( bool modal ) void wxWindow::SetFocus() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - GtkWidget *connect_widget = GetConnectWidget(); - if (connect_widget) - { - if (GTK_WIDGET_CAN_FOCUS(connect_widget) && !GTK_WIDGET_HAS_FOCUS (connect_widget) ) + GtkWidget *connect_widget = GetConnectWidget(); + if (connect_widget) { - gtk_widget_grab_focus (connect_widget); + if (GTK_WIDGET_CAN_FOCUS(connect_widget) && !GTK_WIDGET_HAS_FOCUS (connect_widget) ) + { + gtk_widget_grab_focus (connect_widget); + } } - } } bool wxWindow::OnClose() { - return TRUE; + return TRUE; } void wxWindow::AddChild( wxWindow *child ) { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - wxASSERT_MSG( (child != NULL), "invalid child" ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxASSERT_MSG( (child != NULL), "invalid child" ); - m_children.Append( child ); + m_children.Append( child ); } wxList *wxWindow::GetChildren() { - return (&m_children); + return (&m_children); +} + +wxWindow *wxWindow::ReParent( wxWindow *newParent ) +{ + wxWindow *oldParent = GetParent(); + + if (oldParent) oldParent->RemoveChild( this ); + + gtk_widget_unparent( m_widget ); + + if (newParent) + { + newParent->AddChild( this ); + (newParent->m_insertCallback)( newParent, this ); + } + + return oldParent; } void wxWindow::RemoveChild( wxWindow *child ) { - if (GetChildren()) GetChildren()->DeleteObject( child ); - child->m_parent = (wxWindow *) NULL; + if (GetChildren()) GetChildren()->DeleteObject( child ); + child->m_parent = (wxWindow *) NULL; } void wxWindow::SetReturnCode( int retCode ) { - m_retCode = retCode; + m_retCode = retCode; } int wxWindow::GetReturnCode() { - return m_retCode; + return m_retCode; } void wxWindow::Raise() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - if (m_widget) gdk_window_raise( m_widget->window ); + if (m_widget) gdk_window_raise( m_widget->window ); } void wxWindow::Lower() { - wxASSERT_MSG( (m_widget != NULL), "invalid window" ); + wxASSERT_MSG( (m_widget != NULL), "invalid window" ); - if (m_widget) gdk_window_lower( m_widget->window ); + if (m_widget) gdk_window_lower( m_widget->window ); } wxEvtHandler *wxWindow::GetEventHandler() { - return m_eventHandler; + return m_eventHandler; } void wxWindow::SetEventHandler( wxEvtHandler *handler ) { - m_eventHandler = handler; + m_eventHandler = 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) + if (GetEventHandler()) { - delete handlerA; - return (wxEvtHandler*) NULL; - } - else - return handlerA; - } - else - return (wxEvtHandler *) NULL; + 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() { - return m_windowValidator; + return m_windowValidator; } void wxWindow::SetValidator( const wxValidator& validator ) @@ -2002,47 +2042,54 @@ bool wxWindow::IsExposed( const wxRect& rect ) const void wxWindow::Clear() { - wxCHECK_RET( m_widget != NULL, "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); - if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); + if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); } wxColour wxWindow::GetBackgroundColour() const { - return m_backgroundColour; + return m_backgroundColour; } void wxWindow::SetBackgroundColour( const wxColour &colour ) { - wxCHECK_RET( m_widget != NULL, "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); - m_backgroundColour = colour; - if (!m_backgroundColour.Ok()) return; + if (m_backgroundColour == colour) return; + + if (!m_backgroundColour.Ok()) + if (wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) == colour) return; - if (m_wxwindow) - { - GdkWindow *window = m_wxwindow->window; - m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); - gdk_window_set_background( window, m_backgroundColour.GetColor() ); - gdk_window_clear( window ); - } + m_backgroundColour = colour; + if (!m_backgroundColour.Ok()) return; - ApplyWidgetStyle(); + if (m_wxwindow) + { + GdkWindow *window = m_wxwindow->window; + m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); + gdk_window_set_background( window, m_backgroundColour.GetColor() ); + gdk_window_clear( window ); + } + + ApplyWidgetStyle(); } wxColour wxWindow::GetForegroundColour() const { - return m_foregroundColour; + return m_foregroundColour; } void wxWindow::SetForegroundColour( const wxColour &colour ) { - wxCHECK_RET( m_widget != NULL, "invalid window" ); + wxCHECK_RET( m_widget != NULL, "invalid window" ); - m_foregroundColour = colour; - if (!m_foregroundColour.Ok()) return; + if (m_foregroundColour == colour) return; - ApplyWidgetStyle(); + m_foregroundColour = colour; + if (!m_foregroundColour.Ok()) return; + + ApplyWidgetStyle(); } GtkStyle *wxWindow::GetWidgetStyle() @@ -2195,12 +2242,12 @@ void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) GtkWidget *dnd_widget = GetConnectWidget(); - DisconnectDnDWidget( dnd_widget ); + if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget ); if (m_dropTarget) delete m_dropTarget; m_dropTarget = dropTarget; - ConnectDnDWidget( dnd_widget ); + if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget ); } wxDropTarget *wxWindow::GetDropTarget() const @@ -2208,40 +2255,6 @@ wxDropTarget *wxWindow::GetDropTarget() const return m_dropTarget; } -void wxWindow::ConnectDnDWidget( GtkWidget *widget ) -{ - if (!m_dropTarget) return; - - m_dropTarget->RegisterWidget( widget ); - -#ifdef NEW_GTK_DND_CODE - -#else - - gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event", - GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this ); - -#endif - -} - -void wxWindow::DisconnectDnDWidget( GtkWidget *widget ) -{ - if (!m_dropTarget) return; - -#ifdef NEW_GTK_DND_CODE - -#else - - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), - GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this ); - - m_dropTarget->UnregisterWidget( widget ); - -#endif - -} - GtkWidget* wxWindow::GetConnectWidget() { GtkWidget *connect_widget = m_widget; @@ -2382,6 +2395,8 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); if (!m_wxwindow) return; + + m_hasScrolling = TRUE; if (orient == wxHORIZONTAL) {