+ if (g_blockEventsOnDrag) return;
+
+/*
+ printf( "OnVScroll change from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
+*/
+
+ if (!win->HasVMT()) return;
+
+ wxEventType command = wxEVT_SCROLL_THUMBTRACK;
+ int value = (int)(win->m_vAdjust->value+0.5);
+
+ wxScrollEvent event( command, win->GetId(), value, wxVERTICAL );
+ event.SetEventObject( win );
+ win->GetEventHandler()->ProcessEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+// "changed" from m_hAdjust
+//-----------------------------------------------------------------------------
+
+static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
+{
+ if (g_blockEventsOnDrag) return;
+
+/*
+ printf( "OnHScroll change from " );
+ if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+ printf( win->GetClassInfo()->GetClassName() );
+ printf( ".\n" );
+*/
+
+ if (!win->HasVMT()) return;
+
+ wxEventType command = wxEVT_SCROLL_THUMBTRACK;
+ int value = (int)(win->m_hAdjust->value+0.5);
+
+ wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL );
+ event.SetEventObject( win );
+ win->GetEventHandler()->ProcessEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+// "button_press_event" from scrollbar
+//-----------------------------------------------------------------------------
+
+static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget),
+ GdkEventButton *WXUNUSED(gdk_event),
+ wxWindow *win )
+{
+// if (gdk_event->window != widget->slider) return FALSE;
+
+ win->m_isScrolling = TRUE;
+ g_blockEventsOnScroll = TRUE;
+
+ return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// "button_release_event" from scrollbar
+//-----------------------------------------------------------------------------
+
+static gint gtk_scrollbar_button_release_callback( GtkRange *widget,
+ GdkEventButton *WXUNUSED(gdk_event),
+ wxWindow *win )
+{
+
+// 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);
+
+ 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;
+ g_blockEventsOnScroll = FALSE;
+
+ return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// InsertChild for wxWindow.
+//-----------------------------------------------------------------------------
+
+// Callback for wxWindow. This very strange beast has to be used because
+// C++ has no virtual methods in a constructor. We have to emulate a
+// virtual function here as wxNotebook requires a different way to insert
+// a child in it. I had opted for creating a wxNotebookPage window class
+// which would have made this superflouus (such in the MDI window system),
+// but no-one is listening to me...
+
+static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
+{
+ gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
+ GTK_WIDGET(child->m_widget),
+ child->m_x,
+ child->m_y );
+
+ gtk_widget_set_usize( GTK_WIDGET(child->m_widget),
+ child->m_width,
+ child->m_height );
+}
+
+//-----------------------------------------------------------------------------
+// wxWindow
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxWindow,wxEvtHandler)
+
+BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
+ EVT_SIZE(wxWindow::OnSize)
+ EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
+ EVT_INIT_DIALOG(wxWindow::OnInitDialog)
+ EVT_IDLE(wxWindow::OnIdle)
+END_EVENT_TABLE()
+
+wxWindow::wxWindow()
+{
+ m_widget = (GtkWidget *) NULL;
+ m_wxwindow = (GtkWidget *) NULL;
+ m_parent = (wxWindow *) NULL;
+ m_children.DeleteContents( FALSE );
+
+ m_x = 0;
+ m_y = 0;
+ m_width = 0;
+ m_height = 0;
+ m_minWidth = -1;
+ m_minHeight = -1;
+ m_maxWidth = -1;
+ m_maxHeight = -1;
+
+ m_retCode = 0;
+
+ m_eventHandler = this;
+ m_windowValidator = (wxValidator *) NULL;
+
+ m_windowId = -1;
+
+ m_cursor = (wxCursor *) NULL;
+ m_font = *wxSWISS_FONT;
+ m_windowStyle = 0;
+ m_windowName = "noname";
+
+ m_constraints = (wxLayoutConstraints *) NULL;
+ m_constraintsInvolvedIn = (wxList *) NULL;
+ m_windowSizer = (wxSizer *) NULL;
+ m_sizerParent = (wxWindow *) NULL;
+ m_autoLayout = FALSE;
+
+ m_sizeSet = FALSE;
+ m_hasVMT = FALSE;
+ m_needParent = TRUE;
+
+ m_hasScrolling = FALSE;
+ m_isScrolling = FALSE;
+ m_hAdjust = (GtkAdjustment*) NULL;
+ m_vAdjust = (GtkAdjustment*) NULL;
+ m_oldHorizontalPos = 0.0;
+ m_oldVerticalPos = 0.0;
+
+ m_isShown = FALSE;
+ m_isEnabled = TRUE;
+
+ m_dropTarget = (wxDropTarget*) NULL;
+ m_resizing = FALSE;
+ m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
+
+ m_insertCallback = wxInsertChildInWindow;
+
+ m_clientObject = (wxClientData*) NULL;
+ m_clientData = NULL;
+}
+
+wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
+ const wxPoint &pos, const wxSize &size,
+ long style, const wxString &name )
+{
+ m_insertCallback = wxInsertChildInWindow;
+ Create( parent, id, pos, size, style, name );
+}
+
+bool wxWindow::Create( wxWindow *parent, wxWindowID id,
+ const wxPoint &pos, const wxSize &size,
+ long style, const wxString &name )
+{
+ m_isShown = FALSE;
+ m_isEnabled = TRUE;
+ m_needParent = TRUE;
+
+ PreCreation( parent, id, pos, size, style, name );
+
+ m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
+ GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
+
+ GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
+
+ GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+ scroll_class->scrollbar_spacing = 0;
+
+ gtk_scrolled_window_set_policy( s_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
+
+ m_oldHorizontalPos = 0.0;
+ m_oldVerticalPos = 0.0;
+
+ m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->hscrollbar) );
+ m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->vscrollbar) );
+
+ 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)
+ {
+ gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
+ }
+ else if (m_windowStyle & wxSUNKEN_BORDER)
+ {
+ gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN );
+ }
+ else
+ {
+ gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
+ }
+
+ 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 );
+
+ // 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) );
+
+ // I _really_ don't want scrollbars in the beginning
+ m_vAdjust->lower = 0.0;
+ m_vAdjust->upper = 1.0;
+ m_vAdjust->value = 0.0;
+ m_vAdjust->step_increment = 1.0;
+ m_vAdjust->page_increment = 1.0;
+ m_vAdjust->page_size = 5.0;
+ gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
+ m_hAdjust->lower = 0.0;
+ m_hAdjust->upper = 1.0;
+ m_hAdjust->value = 0.0;
+ m_hAdjust->step_increment = 1.0;
+ m_hAdjust->page_increment = 1.0;
+ 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 );