]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
Karsten's correction undone - this code is (was) correct!
[wxWidgets.git] / src / gtk / window.cpp
index a59b3b29f97129ec975d61b7c123cab0ec645b6c..81628667f9ec0fe5ce41aa9fdd112b482247d0a8 100644 (file)
@@ -29,7 +29,6 @@
 #include "wx/notebook.h"
 #include "wx/statusbr.h"
 #include <wx/intl.h>
-//#include "wx/treectrl.h"
 #include "gdk/gdkkeysyms.h"
 #include <math.h>
 #include "wx/gtk/win_gtk.h"
@@ -272,9 +271,10 @@ gint gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), GdkEventKey *gd
 //-----------------------------------------------------------------------------
 // button_press
 
-gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
-{ 
-  if (widget->window != gdk_event->window) return TRUE;
+gint gtk_window_button_press_callback( GtkWidget *WXUNUSED(widget), GdkEventButton *gdk_event, wxWindow *win )
+{
+  if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
+  
   if (g_blockEventsOnDrag) return TRUE;
 
   if (win->m_wxwindow)
@@ -353,10 +353,9 @@ gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_ev
 //-----------------------------------------------------------------------------
 // button_release
 
-gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
+gint gtk_window_button_release_callback( GtkWidget *WXUNUSED(widget), GdkEventButton *gdk_event, wxWindow *win )
 { 
-  if (widget->window != gdk_event->window) return TRUE;
-
+  if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
   if (g_blockEventsOnDrag) return TRUE;
 
   if (!win->HasVMT()) return TRUE;
@@ -397,10 +396,9 @@ gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_
 //-----------------------------------------------------------------------------
 // motion_notify
 
-gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win )
+gint gtk_window_motion_notify_callback( GtkWidget *WXUNUSED(widget), GdkEventMotion *gdk_event, wxWindow *win )
 { 
-  if (widget->window != gdk_event->window) return TRUE;
-
+  if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
   if (g_blockEventsOnDrag) return TRUE;
 
   if (!win->HasVMT()) return TRUE;
@@ -754,22 +752,16 @@ wxWindow::wxWindow()
   m_resizing = FALSE;
 }
 
-wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
-      const wxPoint &pos, const wxSize &size,
-      long style, const wxString &name )
-{
-  m_cursor = NULL;
-  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 )
+      long style, const wxString &name  )
 {
   m_isShown = FALSE;
   m_isEnabled = TRUE;
   m_needParent = TRUE;
   
+  m_cursor = NULL;
+  
   PreCreation( parent, id, pos, size, style, name );
   
   m_widget = gtk_scrolled_window_new( NULL, NULL );
@@ -887,8 +879,7 @@ wxWindow::~wxWindow(void)
     m_windowSizer = NULL;
   }
   // If this is a child of a sizer, remove self from parent
-  if (m_sizerParent)
-    m_sizerParent->RemoveChild((wxWindow *)this);
+  if (m_sizerParent) m_sizerParent->RemoveChild((wxWindow *)this);
 
   // Just in case the window has been Closed, but
   // we're then deleting immediately: don't leave
@@ -900,6 +891,7 @@ wxWindow::~wxWindow(void)
   // class
   wxTopLevelWindows.DeleteObject(this);
     
+  if (m_windowValidator) delete m_windowValidator;
 }
 
 void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
@@ -921,7 +913,6 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
   if (m_height == -1) m_height = 20;
   m_retCode = 0;
   m_eventHandler = this;
-  m_windowValidator = NULL;
   m_windowId = id;
   m_sizeSet = FALSE;
   if (m_cursor == NULL)
@@ -940,6 +931,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
   m_drawingOffsetY = 0;
   m_pDropTarget = NULL;
   m_resizing = FALSE;
+  m_windowValidator = NULL;
 }
 
 void wxWindow::PostCreation(void)
@@ -1083,7 +1075,7 @@ void wxWindow::ImplementSetPosition(void)
   
   if (!m_parent)
   {
-    printf( _("wxWindow::SetSize error.\n") );
+    wxFAIL_MSG( _("wxWindow::SetSize error.\n") );
     return;
   }
   
@@ -1401,6 +1393,31 @@ void wxWindow::Enable( bool enable )
   if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable );
 }
 
+int wxWindow::GetCharHeight(void) const
+{
+  GdkFont *font = m_font.GetInternalFont( 1.0 );
+  return font->ascent + font->descent;
+}
+
+int wxWindow::GetCharWidth(void) const
+{
+  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
+{
+  wxFont fontToUse = m_font;
+  if (theFont) fontToUse = *theFont;
+  
+  GdkFont *font = fontToUse.GetInternalFont( 1.0 );
+  if (x) (*y) = 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 )
 {
   return;
@@ -1524,11 +1541,6 @@ int wxWindow::GetReturnCode(void)
   return m_retCode;
 }
 
-wxWindow *wxWindow::GetParent(void)
-{
-  return m_parent;
-}
-
 void wxWindow::Raise(void)
 {
   if (m_widget) gdk_window_raise( m_widget->window );
@@ -1544,19 +1556,47 @@ wxEvtHandler *wxWindow::GetEventHandler(void)
   return m_eventHandler;
 }
 
-void wxWindow::SetEventhandler( wxEvtHandler *handler )
+void wxWindow::SetEventHandler( wxEvtHandler *handler )
 {
   m_eventHandler = handler;
 }
 
+void wxWindow::PushEventHandler(wxEvtHandler *handler)
+{
+       handler->SetNextHandler(GetEventHandler());
+       SetEventHandler(handler);
+}
+
+wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
+{
+       if ( GetEventHandler() )
+       {
+               wxEvtHandler *handlerA = GetEventHandler();
+               wxEvtHandler *handlerB = handlerA->GetNextHandler();
+               handlerA->SetNextHandler(NULL);
+               SetEventHandler(handlerB);
+               if ( deleteHandler )
+               {
+                       delete handlerA;
+                       return NULL;
+               }
+               else
+                       return handlerA;
+       }
+       else
+               return NULL;
+}
+
 wxValidator *wxWindow::GetValidator(void)
 {
   return m_windowValidator;
 }
 
-void wxWindow::SetValidator( wxValidator *validator )
+void wxWindow::SetValidator( const wxValidator& validator )
 {
-  m_windowValidator = validator;
+  if (m_windowValidator) delete m_windowValidator;
+  m_windowValidator = validator.Clone();
+  if (m_windowValidator) m_windowValidator->SetWindow(this);
 }
 
 bool wxWindow::IsBeingDeleted(void)
@@ -1670,6 +1710,16 @@ void wxWindow::SetBackgroundColour( const wxColour &colour )
   // do something ?
 }
 
+wxColour wxWindow::GetForegroundColour(void) const
+{
+  return m_foregroundColour;
+}
+
+void wxWindow::SetForegroundColour( const wxColour &colour )
+{
+  m_foregroundColour = colour;
+}
+
 bool wxWindow::Validate(void)
 {
   wxNode *node = GetChildren()->First();
@@ -1780,6 +1830,12 @@ GtkWidget* wxWindow::GetConnectWidget(void)
   return connect_widget;
 }
   
+bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
+{
+  if (m_wxwindow) return (window == m_wxwindow->window);
+  return (window == m_widget->window);
+}
+
 void wxWindow::SetFont( const wxFont &font )
 {
   m_font = font;