From 6ca41e57f48db4c1a2de7ae67c7e4b655d9809af Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 3 Nov 1998 11:19:58 +0000 Subject: [PATCH] Fix for TextCtrl problem as reported by Vegh Move definition of wxMenuItem to /gtk/menuitem.h Radical change of how to insert a child into a paren window. As C++ doesn't have any VMT in a class's consructor, I have to use a callback. Fixed culumn resizing bug in wxListCtrl Fixed menu height bug in MDI code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@955 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 1 + include/wx/gtk/frame.h | 16 +-- include/wx/gtk/mdi.h | 1 - include/wx/gtk/menu.h | 51 +--------- include/wx/gtk/menuitem.h | 131 ++++++++++++------------- include/wx/gtk/notebook.h | 12 +-- include/wx/gtk/window.h | 49 ++++++---- include/wx/gtk1/frame.h | 16 +-- include/wx/gtk1/mdi.h | 1 - include/wx/gtk1/menu.h | 51 +--------- include/wx/gtk1/menuitem.h | 131 ++++++++++++------------- include/wx/gtk1/notebook.h | 12 +-- include/wx/gtk1/window.h | 49 ++++++---- samples/controls/controls.cpp | 2 + samples/mdi/mdi.cpp | 4 +- src/generic/listctrl.cpp | 1 + src/gtk/bmpbuttn.cpp | 4 + src/gtk/button.cpp | 4 + src/gtk/checkbox.cpp | 4 + src/gtk/choice.cpp | 4 + src/gtk/combobox.cpp | 4 + src/gtk/dialog.cpp | 3 + src/gtk/frame.cpp | 160 +++++++++--------------------- src/gtk/gauge.cpp | 4 + src/gtk/listbox.cpp | 4 + src/gtk/mdi.cpp | 82 +++++++++------- src/gtk/menu.cpp | 2 +- src/gtk/notebook.cpp | 73 +++++++------- src/gtk/radiobox.cpp | 3 + src/gtk/radiobut.cpp | 3 + src/gtk/scrolbar.cpp | 4 + src/gtk/slider.cpp | 5 +- src/gtk/statbmp.cpp | 4 + src/gtk/statbox.cpp | 4 + src/gtk/stattext.cpp | 4 + src/gtk/tbargtk.cpp | 4 + src/gtk/textctrl.cpp | 5 + src/gtk/treectrl.cpp | 4 + src/gtk/window.cpp | 179 ++++++++++++++++++---------------- src/gtk1/bmpbuttn.cpp | 4 + src/gtk1/button.cpp | 4 + src/gtk1/checkbox.cpp | 4 + src/gtk1/choice.cpp | 4 + src/gtk1/combobox.cpp | 4 + src/gtk1/dialog.cpp | 3 + src/gtk1/frame.cpp | 160 +++++++++--------------------- src/gtk1/gauge.cpp | 4 + src/gtk1/listbox.cpp | 4 + src/gtk1/mdi.cpp | 82 +++++++++------- src/gtk1/menu.cpp | 2 +- src/gtk1/notebook.cpp | 73 +++++++------- src/gtk1/radiobox.cpp | 3 + src/gtk1/radiobut.cpp | 3 + src/gtk1/scrolbar.cpp | 4 + src/gtk1/slider.cpp | 5 +- src/gtk1/statbmp.cpp | 4 + src/gtk1/statbox.cpp | 4 + src/gtk1/stattext.cpp | 4 + src/gtk1/tbargtk.cpp | 4 + src/gtk1/textctrl.cpp | 5 + src/gtk1/treectrl.cpp | 4 + src/gtk1/window.cpp | 179 ++++++++++++++++++---------------- 62 files changed, 810 insertions(+), 852 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index e9fa47859e..23efce8e35 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -21,6 +21,7 @@ #include "glib.h" #include "gdk/gdk.h" #include "gtk/gtk.h" +#include "wx/gtk/win_gtk.h" #endif diff --git a/include/wx/gtk/frame.h b/include/wx/gtk/frame.h index af0fe7328a..38f27d5375 100644 --- a/include/wx/gtk/frame.h +++ b/include/wx/gtk/frame.h @@ -59,7 +59,6 @@ public: bool Destroy(); virtual bool Show( bool show ); - virtual void Enable( bool enable ); virtual void Centre( int direction = wxHORIZONTAL ); virtual void GetClientSize( int *width, int *height ) const; @@ -98,28 +97,17 @@ public: void OnCloseWindow( wxCloseEvent& event ); void OnIdle(wxIdleEvent& event); - void AddChild( wxWindow *child ); - // implementation virtual void GtkOnSize( int x, int y, int width, int height ); - -private: - friend wxWindow; - friend wxMDIChildFrame; - friend wxMDIClientWindow; - - // update frame's menus (called from OnIdle) + virtual void ImplementSetPosition(); + virtual wxPoint GetClientAreaOrigin() const; void DoMenuUpdates(); void DoMenuUpdates(wxMenu* menu); - virtual void ImplementSetPosition(); - GtkWidget *m_mainWindow; wxMenuBar *m_frameMenuBar; wxStatusBar *m_frameStatusBar; wxToolBar *m_frameToolBar; - int m_toolBarHeight; - bool m_addPrivateChild; // for toolbar (and maybe menubar) wxString m_title; wxIcon m_icon; diff --git a/include/wx/gtk/mdi.h b/include/wx/gtk/mdi.h index 2651f98366..95d9df89f4 100644 --- a/include/wx/gtk/mdi.h +++ b/include/wx/gtk/mdi.h @@ -178,7 +178,6 @@ class wxMDIClientWindow: public wxWindow wxMDIClientWindow( wxMDIParentFrame *parent, long style = 0 ); ~wxMDIClientWindow(void); virtual bool CreateClient( wxMDIParentFrame *parent, long style = wxVSCROLL | wxHSCROLL ); - void AddChild( wxWindow *child ); }; #endif // __MDIH__ diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index 7060ea2dd0..300a1918b8 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -19,6 +19,7 @@ #include "wx/object.h" #include "wx/list.h" #include "wx/window.h" +#include "wx/menuitem.h" //----------------------------------------------------------------------------- // classes @@ -67,56 +68,6 @@ public: // wxMenu //----------------------------------------------------------------------------- -class wxMenuItem: public wxObject -{ -DECLARE_DYNAMIC_CLASS(wxMenuItem) - -public: - wxMenuItem(); - - // accessors - // id - void SetId(int id) { m_id = id; } - int GetId() const { return m_id; } - bool IsSeparator() const { return m_id == ID_SEPARATOR; } - - // the item's text - void SetText(const wxString& str); - const wxString& GetText() const { return m_text; } - - // what kind of menu item we are - void SetCheckable(bool checkable) { m_isCheckMenu = checkable; } - bool IsCheckable() const { return m_isCheckMenu; } - void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } - wxMenu *GetSubMenu() const { return m_subMenu; } - bool IsSubMenu() const { return m_subMenu != NULL; } - - // state - void Enable( bool enable = TRUE ); - bool IsEnabled() const { return m_isEnabled; } - void Check( bool check = TRUE ); - bool IsChecked() const; - - // help string (displayed in the status bar by default) - void SetHelp(const wxString& str) { m_helpStr = str; } - const wxString& GetHelp() const { return m_helpStr; } - - // implementation - void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } - GtkWidget *GetMenuItem() const { return m_menuItem; } - -private: - int m_id; - wxString m_text; - bool m_isCheckMenu; - bool m_isChecked; - bool m_isEnabled; - wxMenu *m_subMenu; - wxString m_helpStr; - - GtkWidget *m_menuItem; // GtkMenuItem -}; - class wxMenu: public wxEvtHandler { DECLARE_DYNAMIC_CLASS(wxMenu) diff --git a/include/wx/gtk/menuitem.h b/include/wx/gtk/menuitem.h index 9c912967f1..f20657838a 100644 --- a/include/wx/gtk/menuitem.h +++ b/include/wx/gtk/menuitem.h @@ -1,95 +1,90 @@ /////////////////////////////////////////////////////////////////////////////// // Name: menuitem.h // Purpose: wxMenuItem class -// Author: Vadim Zeitlin -// Modified by: -// Created: 11.11.97 +// Author: Robert Roebling // RCS-ID: $Id$ -// Copyright: (c) 1998 Vadim Zeitlin +// Copyright: (c) 1998 Robert Roebling // Licence: wxWindows license /////////////////////////////////////////////////////////////////////////////// -#ifndef _MENUITEM_H -#define _MENUITEM_H +#ifndef __GTKMENUITEMH__ +#define __GTKMENUITEMH__ #ifdef __GNUG__ -#pragma interface "menuitem.h" +#pragma interface #endif -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/setup.h" - -// an exception to the general rule that a normal header doesn't include other -// headers - only because ownerdrw.h is not always included and I don't want -// to write #ifdef's everywhere... -#if wxUSE_OWNER_DRAWN -#include "wx/ownerdrw.h" -#endif +#include "wx/defs.h" +#include "wx/string.h" // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- -// id for a separator line in the menu (invalid for normal item) #define ID_SEPARATOR (-1) -// ---------------------------------------------------------------------------- -// wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour -// ---------------------------------------------------------------------------- -class WXDLLEXPORT wxMenuItem: public wxObject -#if wxUSE_OWNER_DRAWN - , public wxOwnerDrawn -#endif -{ -DECLARE_DYNAMIC_CLASS(wxMenuItem) - -public: - // ctor & dtor - wxMenuItem(wxMenu *pParentMenu = NULL, int id = ID_SEPARATOR, - const wxString& strName = "", const wxString& wxHelp = "", - bool bCheckable = FALSE, wxMenu *pSubMenu = NULL); - virtual ~wxMenuItem(); +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- - // accessors (some more are inherited from wxOwnerDrawn or are below) - bool IsSeparator() const { return m_idItem == ID_SEPARATOR; } - bool IsEnabled() const { return m_bEnabled; } - bool IsChecked() const { return m_bChecked; } +class wxMenuItem; - int GetId() const { return m_idItem; } - const wxString& GetHelp() const { return m_strHelp; } - wxMenu *GetSubMenu() const { return m_pSubMenu; } +class wxMenu; - // operations - void SetName(const wxString& strName) { m_strName = strName; } - void SetHelp(const wxString& strHelp) { m_strHelp = strHelp; } +//----------------------------------------------------------------------------- +// wxMenuItem +//----------------------------------------------------------------------------- - void Enable(bool bDoEnable = TRUE); - void Check(bool bDoCheck = TRUE); +class wxMenuItem: public wxObject +{ +DECLARE_DYNAMIC_CLASS(wxMenuItem) - void DeleteSubMenu(); +public: + wxMenuItem(); + + // accessors + // id + void SetId(int id) { m_id = id; } + int GetId() const { return m_id; } + bool IsSeparator() const { return m_id == ID_SEPARATOR; } + + // the item's text + void SetText(const wxString& str); + const wxString& GetText() const { return m_text; } + + // what kind of menu item we are + void SetCheckable(bool checkable) { m_isCheckMenu = checkable; } + bool IsCheckable() const { return m_isCheckMenu; } + void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } + wxMenu *GetSubMenu() const { return m_subMenu; } + bool IsSubMenu() const { return m_subMenu != NULL; } + + // state + void Enable( bool enable = TRUE ); + bool IsEnabled() const { return m_isEnabled; } + void Check( bool check = TRUE ); + bool IsChecked() const; + + // help string (displayed in the status bar by default) + void SetHelp(const wxString& str) { m_helpStr = str; } + const wxString& GetHelp() const { return m_helpStr; } + + // implementation + void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } + GtkWidget *GetMenuItem() const { return m_menuItem; } private: - int m_idItem; // numeric id of the item - wxString m_strHelp; // associated help string - wxMenu *m_pSubMenu, // may be NULL - *m_pParentMenu; // menu this item is contained in - bool m_bEnabled, // enabled or greyed? - m_bChecked; // checked? (only if checkable) - -#if wxUSE_OWNER_DRAWN - // wxOwnerDrawn base class already has these variables - nothing to do - -#else //!owner drawn - bool m_bCheckable; // can be checked? - wxString m_strName; // name or label of the item - -public: - const wxString& GetName() const { return m_strName; } - bool IsCheckable() const { return m_bCheckable; } -#endif //owner drawn + int m_id; + wxString m_text; + bool m_isCheckMenu; + bool m_isChecked; + bool m_isEnabled; + wxMenu *m_subMenu; + wxString m_helpStr; + + GtkWidget *m_menuItem; // GtkMenuItem }; -#endif //_MENUITEM_H + +#endif + //__GTKMENUITEMH__ diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index ac362bcffe..46ae493e57 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -8,11 +8,11 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#ifndef __NOTEBOOKH__ -#define __NOTEBOOKH__ +#ifndef __GTKNOTEBOOKH__ +#define __GTKNOTEBOOKH__ #ifdef __GNUG__ -#pragma interface "notebook.h" +#pragma interface #endif #include "wx/defs.h" @@ -137,15 +137,13 @@ public: // get the panel which represents the given page wxWindow *GetPage(int nPage) const; + // implementation - void AddChild(wxWindow *child); void SetConstraintSizes(bool recurse); bool DoPhase(int phase); void ApplyWidgetStyle(); - -private: // common part of all ctors void Init(); @@ -183,4 +181,4 @@ typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&); }, #endif - // __NOTEBOOKH__ + // __GTKNOTEBOOKH__ diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 9766527a36..bb9545f723 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -46,6 +46,12 @@ class wxItemResource; class wxWindow; class wxCanvas; +//----------------------------------------------------------------------------- +// callback definition for inserting a window +//----------------------------------------------------------------------------- + +typedef void (*wxInsertChildFunction)( wxWindow*, wxWindow* ); + //----------------------------------------------------------------------------- // global data //----------------------------------------------------------------------------- @@ -64,14 +70,11 @@ class wxWindow: public wxEvtHandler public: wxWindow(); - inline wxWindow(wxWindow *parent, wxWindowID id, + wxWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxPanelNameStr) - { - Create(parent, id, pos, size, style, name); - } + const wxString& name = wxPanelNameStr); bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -230,21 +233,27 @@ public: // implementation - virtual GtkWidget* GetConnectWidget(void); - virtual bool IsOwnGtkWindow( GdkWindow *window ); - void ConnectWidget( GtkWidget *widget ); - void ConnectDnDWidget( GtkWidget *widget ); - void DisconnectDnDWidget( GtkWidget *widget ); + virtual GtkWidget *GetConnectWidget(void); + virtual bool IsOwnGtkWindow( GdkWindow *window ); + void ConnectWidget( GtkWidget *widget ); + void ConnectDnDWidget( GtkWidget *widget ); + void DisconnectDnDWidget( GtkWidget *widget ); + + void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, + const wxSize &size, long style, const wxString &name ); + void PostCreation(); + bool HasVMT(); + + virtual void ImplementSetSize(); + virtual void ImplementSetPosition(); + + virtual wxPoint GetClientAreaOrigin() const; + virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); + + GtkStyle *GetWidgetStyle(); + void SetWidgetStyle(); + virtual void ApplyWidgetStyle(); - void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, - const wxSize &size, long style, const wxString &name ); - void PostCreation(); - bool HasVMT(); - virtual void ImplementSetSize(); - virtual void ImplementSetPosition(); - GtkStyle *GetWidgetStyle(); - void SetWidgetStyle(); - virtual void ApplyWidgetStyle(); wxWindow *m_parent; wxList m_children; @@ -281,6 +290,8 @@ public: bool m_resizing; GdkGC *m_scrollGC; GtkStyle *m_widgetStyle; + + wxInsertChildFunction m_insertCallback; public: diff --git a/include/wx/gtk1/frame.h b/include/wx/gtk1/frame.h index af0fe7328a..38f27d5375 100644 --- a/include/wx/gtk1/frame.h +++ b/include/wx/gtk1/frame.h @@ -59,7 +59,6 @@ public: bool Destroy(); virtual bool Show( bool show ); - virtual void Enable( bool enable ); virtual void Centre( int direction = wxHORIZONTAL ); virtual void GetClientSize( int *width, int *height ) const; @@ -98,28 +97,17 @@ public: void OnCloseWindow( wxCloseEvent& event ); void OnIdle(wxIdleEvent& event); - void AddChild( wxWindow *child ); - // implementation virtual void GtkOnSize( int x, int y, int width, int height ); - -private: - friend wxWindow; - friend wxMDIChildFrame; - friend wxMDIClientWindow; - - // update frame's menus (called from OnIdle) + virtual void ImplementSetPosition(); + virtual wxPoint GetClientAreaOrigin() const; void DoMenuUpdates(); void DoMenuUpdates(wxMenu* menu); - virtual void ImplementSetPosition(); - GtkWidget *m_mainWindow; wxMenuBar *m_frameMenuBar; wxStatusBar *m_frameStatusBar; wxToolBar *m_frameToolBar; - int m_toolBarHeight; - bool m_addPrivateChild; // for toolbar (and maybe menubar) wxString m_title; wxIcon m_icon; diff --git a/include/wx/gtk1/mdi.h b/include/wx/gtk1/mdi.h index 2651f98366..95d9df89f4 100644 --- a/include/wx/gtk1/mdi.h +++ b/include/wx/gtk1/mdi.h @@ -178,7 +178,6 @@ class wxMDIClientWindow: public wxWindow wxMDIClientWindow( wxMDIParentFrame *parent, long style = 0 ); ~wxMDIClientWindow(void); virtual bool CreateClient( wxMDIParentFrame *parent, long style = wxVSCROLL | wxHSCROLL ); - void AddChild( wxWindow *child ); }; #endif // __MDIH__ diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index 7060ea2dd0..300a1918b8 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -19,6 +19,7 @@ #include "wx/object.h" #include "wx/list.h" #include "wx/window.h" +#include "wx/menuitem.h" //----------------------------------------------------------------------------- // classes @@ -67,56 +68,6 @@ public: // wxMenu //----------------------------------------------------------------------------- -class wxMenuItem: public wxObject -{ -DECLARE_DYNAMIC_CLASS(wxMenuItem) - -public: - wxMenuItem(); - - // accessors - // id - void SetId(int id) { m_id = id; } - int GetId() const { return m_id; } - bool IsSeparator() const { return m_id == ID_SEPARATOR; } - - // the item's text - void SetText(const wxString& str); - const wxString& GetText() const { return m_text; } - - // what kind of menu item we are - void SetCheckable(bool checkable) { m_isCheckMenu = checkable; } - bool IsCheckable() const { return m_isCheckMenu; } - void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } - wxMenu *GetSubMenu() const { return m_subMenu; } - bool IsSubMenu() const { return m_subMenu != NULL; } - - // state - void Enable( bool enable = TRUE ); - bool IsEnabled() const { return m_isEnabled; } - void Check( bool check = TRUE ); - bool IsChecked() const; - - // help string (displayed in the status bar by default) - void SetHelp(const wxString& str) { m_helpStr = str; } - const wxString& GetHelp() const { return m_helpStr; } - - // implementation - void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } - GtkWidget *GetMenuItem() const { return m_menuItem; } - -private: - int m_id; - wxString m_text; - bool m_isCheckMenu; - bool m_isChecked; - bool m_isEnabled; - wxMenu *m_subMenu; - wxString m_helpStr; - - GtkWidget *m_menuItem; // GtkMenuItem -}; - class wxMenu: public wxEvtHandler { DECLARE_DYNAMIC_CLASS(wxMenu) diff --git a/include/wx/gtk1/menuitem.h b/include/wx/gtk1/menuitem.h index 9c912967f1..f20657838a 100644 --- a/include/wx/gtk1/menuitem.h +++ b/include/wx/gtk1/menuitem.h @@ -1,95 +1,90 @@ /////////////////////////////////////////////////////////////////////////////// // Name: menuitem.h // Purpose: wxMenuItem class -// Author: Vadim Zeitlin -// Modified by: -// Created: 11.11.97 +// Author: Robert Roebling // RCS-ID: $Id$ -// Copyright: (c) 1998 Vadim Zeitlin +// Copyright: (c) 1998 Robert Roebling // Licence: wxWindows license /////////////////////////////////////////////////////////////////////////////// -#ifndef _MENUITEM_H -#define _MENUITEM_H +#ifndef __GTKMENUITEMH__ +#define __GTKMENUITEMH__ #ifdef __GNUG__ -#pragma interface "menuitem.h" +#pragma interface #endif -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/setup.h" - -// an exception to the general rule that a normal header doesn't include other -// headers - only because ownerdrw.h is not always included and I don't want -// to write #ifdef's everywhere... -#if wxUSE_OWNER_DRAWN -#include "wx/ownerdrw.h" -#endif +#include "wx/defs.h" +#include "wx/string.h" // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- -// id for a separator line in the menu (invalid for normal item) #define ID_SEPARATOR (-1) -// ---------------------------------------------------------------------------- -// wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour -// ---------------------------------------------------------------------------- -class WXDLLEXPORT wxMenuItem: public wxObject -#if wxUSE_OWNER_DRAWN - , public wxOwnerDrawn -#endif -{ -DECLARE_DYNAMIC_CLASS(wxMenuItem) - -public: - // ctor & dtor - wxMenuItem(wxMenu *pParentMenu = NULL, int id = ID_SEPARATOR, - const wxString& strName = "", const wxString& wxHelp = "", - bool bCheckable = FALSE, wxMenu *pSubMenu = NULL); - virtual ~wxMenuItem(); +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- - // accessors (some more are inherited from wxOwnerDrawn or are below) - bool IsSeparator() const { return m_idItem == ID_SEPARATOR; } - bool IsEnabled() const { return m_bEnabled; } - bool IsChecked() const { return m_bChecked; } +class wxMenuItem; - int GetId() const { return m_idItem; } - const wxString& GetHelp() const { return m_strHelp; } - wxMenu *GetSubMenu() const { return m_pSubMenu; } +class wxMenu; - // operations - void SetName(const wxString& strName) { m_strName = strName; } - void SetHelp(const wxString& strHelp) { m_strHelp = strHelp; } +//----------------------------------------------------------------------------- +// wxMenuItem +//----------------------------------------------------------------------------- - void Enable(bool bDoEnable = TRUE); - void Check(bool bDoCheck = TRUE); +class wxMenuItem: public wxObject +{ +DECLARE_DYNAMIC_CLASS(wxMenuItem) - void DeleteSubMenu(); +public: + wxMenuItem(); + + // accessors + // id + void SetId(int id) { m_id = id; } + int GetId() const { return m_id; } + bool IsSeparator() const { return m_id == ID_SEPARATOR; } + + // the item's text + void SetText(const wxString& str); + const wxString& GetText() const { return m_text; } + + // what kind of menu item we are + void SetCheckable(bool checkable) { m_isCheckMenu = checkable; } + bool IsCheckable() const { return m_isCheckMenu; } + void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } + wxMenu *GetSubMenu() const { return m_subMenu; } + bool IsSubMenu() const { return m_subMenu != NULL; } + + // state + void Enable( bool enable = TRUE ); + bool IsEnabled() const { return m_isEnabled; } + void Check( bool check = TRUE ); + bool IsChecked() const; + + // help string (displayed in the status bar by default) + void SetHelp(const wxString& str) { m_helpStr = str; } + const wxString& GetHelp() const { return m_helpStr; } + + // implementation + void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } + GtkWidget *GetMenuItem() const { return m_menuItem; } private: - int m_idItem; // numeric id of the item - wxString m_strHelp; // associated help string - wxMenu *m_pSubMenu, // may be NULL - *m_pParentMenu; // menu this item is contained in - bool m_bEnabled, // enabled or greyed? - m_bChecked; // checked? (only if checkable) - -#if wxUSE_OWNER_DRAWN - // wxOwnerDrawn base class already has these variables - nothing to do - -#else //!owner drawn - bool m_bCheckable; // can be checked? - wxString m_strName; // name or label of the item - -public: - const wxString& GetName() const { return m_strName; } - bool IsCheckable() const { return m_bCheckable; } -#endif //owner drawn + int m_id; + wxString m_text; + bool m_isCheckMenu; + bool m_isChecked; + bool m_isEnabled; + wxMenu *m_subMenu; + wxString m_helpStr; + + GtkWidget *m_menuItem; // GtkMenuItem }; -#endif //_MENUITEM_H + +#endif + //__GTKMENUITEMH__ diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index ac362bcffe..46ae493e57 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -8,11 +8,11 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#ifndef __NOTEBOOKH__ -#define __NOTEBOOKH__ +#ifndef __GTKNOTEBOOKH__ +#define __GTKNOTEBOOKH__ #ifdef __GNUG__ -#pragma interface "notebook.h" +#pragma interface #endif #include "wx/defs.h" @@ -137,15 +137,13 @@ public: // get the panel which represents the given page wxWindow *GetPage(int nPage) const; + // implementation - void AddChild(wxWindow *child); void SetConstraintSizes(bool recurse); bool DoPhase(int phase); void ApplyWidgetStyle(); - -private: // common part of all ctors void Init(); @@ -183,4 +181,4 @@ typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&); }, #endif - // __NOTEBOOKH__ + // __GTKNOTEBOOKH__ diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 9766527a36..bb9545f723 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -46,6 +46,12 @@ class wxItemResource; class wxWindow; class wxCanvas; +//----------------------------------------------------------------------------- +// callback definition for inserting a window +//----------------------------------------------------------------------------- + +typedef void (*wxInsertChildFunction)( wxWindow*, wxWindow* ); + //----------------------------------------------------------------------------- // global data //----------------------------------------------------------------------------- @@ -64,14 +70,11 @@ class wxWindow: public wxEvtHandler public: wxWindow(); - inline wxWindow(wxWindow *parent, wxWindowID id, + wxWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxPanelNameStr) - { - Create(parent, id, pos, size, style, name); - } + const wxString& name = wxPanelNameStr); bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -230,21 +233,27 @@ public: // implementation - virtual GtkWidget* GetConnectWidget(void); - virtual bool IsOwnGtkWindow( GdkWindow *window ); - void ConnectWidget( GtkWidget *widget ); - void ConnectDnDWidget( GtkWidget *widget ); - void DisconnectDnDWidget( GtkWidget *widget ); + virtual GtkWidget *GetConnectWidget(void); + virtual bool IsOwnGtkWindow( GdkWindow *window ); + void ConnectWidget( GtkWidget *widget ); + void ConnectDnDWidget( GtkWidget *widget ); + void DisconnectDnDWidget( GtkWidget *widget ); + + void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, + const wxSize &size, long style, const wxString &name ); + void PostCreation(); + bool HasVMT(); + + virtual void ImplementSetSize(); + virtual void ImplementSetPosition(); + + virtual wxPoint GetClientAreaOrigin() const; + virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); + + GtkStyle *GetWidgetStyle(); + void SetWidgetStyle(); + virtual void ApplyWidgetStyle(); - void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, - const wxSize &size, long style, const wxString &name ); - void PostCreation(); - bool HasVMT(); - virtual void ImplementSetSize(); - virtual void ImplementSetPosition(); - GtkStyle *GetWidgetStyle(); - void SetWidgetStyle(); - virtual void ApplyWidgetStyle(); wxWindow *m_parent; wxList m_children; @@ -281,6 +290,8 @@ public: bool m_resizing; GdkGC *m_scrollGC; GtkStyle *m_widgetStyle; + + wxInsertChildFunction m_insertCallback; public: diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index fa791e095f..7e784c9590 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -324,8 +324,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : panel->SetBackgroundColour("cadet blue"); panel->SetForegroundColour("blue"); wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(350,28)); + (*tc) << " More text."; tc->SetBackgroundColour("wheat"); tc = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(350,160), wxTE_MULTILINE ); + (*tc) << " More text."; tc->SetBackgroundColour("wheat"); m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text); diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index a1ac5a7ec1..6409aa52f0 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -54,7 +54,7 @@ bool MyApp::OnInit(void) { // Create the main frame window - frame = new MyFrame((wxFrame *) NULL, -1, (char *) "MDI Demo", wxPoint(0, 0), wxSize(500, 400), + frame = new MyFrame((wxFrame *) NULL, -1, (char *) "MDI Demo", wxPoint(-1, -1), wxSize(500, 400), wxDEFAULT_FRAME | wxHSCROLL | wxVSCROLL); // Give it an icon (this is ignored in MDI mode: uses resources) @@ -331,7 +331,7 @@ void MyFrame::InitToolBar(wxToolBar* toolBar) #endif int currentX = 5; - toolBar->AddTool(0, *(bitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file"); + toolBar->AddTool( MDI_NEW_WINDOW, *(bitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file"); currentX += width + 5; toolBar->AddTool(1, *bitmaps[1], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file"); currentX += width + 5; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index dd6990c517..448f068c3f 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -674,6 +674,7 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMain // m_currentCursor = wxSTANDARD_CURSOR; m_currentCursor = (wxCursor *) NULL; m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); + m_isDraging = FALSE; } void wxListHeaderWindow::DoDrawRect( wxPaintDC *dc, int x, int y, int w, int h ) diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index 431e677569..c4a757b53a 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -83,6 +83,10 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &b gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index 249465f366..db5235be66 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -71,6 +71,10 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index d75e1c9cfb..c125d9d2df 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -65,6 +65,10 @@ bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); gtk_widget_realize( GTK_BUTTON( m_widget )->child ); diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 6cc9718298..b61e049afb 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -82,6 +82,10 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, } gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 1b72045d73..ebc9849d38 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -93,6 +93,10 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value, GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this ); } + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); ConnectWidget( GTK_COMBO(m_widget)->button ); diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index bdeafd1bd3..589ef94f45 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -98,6 +98,9 @@ bool wxDialog::Create( wxWindow *parent, gtk_widget_set_usize( m_widget, m_width, m_height ); + if (m_parent) m_parent->AddChild( this ); + + PostCreation(); return TRUE; diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 235078cff1..118c1cb401 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -18,7 +18,6 @@ #include "wx/menu.h" #include "wx/toolbar.h" #include "wx/statusbr.h" -#include "wx/mdi.h" #include "wx/dcclient.h" #include "wx/gtk/win_gtk.h" @@ -104,9 +103,6 @@ wxFrame::wxFrame() m_frameStatusBar = (wxStatusBar *) NULL; m_frameToolBar = (wxToolBar *) NULL; m_sizeSet = FALSE; - m_addPrivateChild = FALSE; - m_wxwindow = (GtkWidget *) NULL; - m_mainWindow = (GtkWidget *) NULL; wxTopLevelWindows.Insert( this ); } @@ -118,9 +114,6 @@ wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, m_frameStatusBar = (wxStatusBar *) NULL; m_frameToolBar = (wxToolBar *) NULL; m_sizeSet = FALSE; - m_addPrivateChild = FALSE; - m_wxwindow = (GtkWidget *) NULL; - m_mainWindow = (GtkWidget *) NULL; Create( parent, id, title, pos, size, style, name ); wxTopLevelWindows.Insert( this ); } @@ -147,23 +140,16 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, gtk_window_set_title( GTK_WINDOW(m_widget), title ); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); - gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL); + gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL ); gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); - m_mainWindow = gtk_myfixed_new(); - gtk_widget_show( m_mainWindow ); - GTK_WIDGET_UNSET_FLAGS( m_mainWindow, GTK_CAN_FOCUS ); - - gtk_container_add( GTK_CONTAINER(m_widget), m_mainWindow ); - gtk_widget_set_uposition( m_mainWindow, 0, 0 ); - m_wxwindow = gtk_myfixed_new(); gtk_widget_show( m_wxwindow ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); - gtk_container_add( GTK_CONTAINER(m_mainWindow), m_wxwindow ); + gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); @@ -171,10 +157,10 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); + if (m_parent) m_parent->AddChild( this ); + PostCreation(); - gtk_widget_realize( m_mainWindow ); - return TRUE; } @@ -184,8 +170,6 @@ wxFrame::~wxFrame() if (m_frameStatusBar) delete m_frameStatusBar; if (m_frameToolBar) delete m_frameToolBar; -// if (m_mainWindow) gtk_widget_destroy( m_mainWindow ); - wxTopLevelWindows.DeleteObject( this ); if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); } @@ -203,16 +187,6 @@ bool wxFrame::Show( bool show ) return wxWindow::Show( show ); } -void wxFrame::Enable( bool enable ) -{ - wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); - - if (!m_mainWindow) return; - - wxWindow::Enable( enable ); - gtk_widget_set_sensitive( m_mainWindow, enable ); -} - void wxFrame::OnCloseWindow( wxCloseEvent &event ) { if (GetEventHandler()->OnClose() || event.GetForce()) this->Destroy(); @@ -228,6 +202,24 @@ bool wxFrame::Destroy() return TRUE; } +wxPoint wxFrame::GetClientAreaOrigin() const +{ + wxPoint pt(0, 0); + if (m_frameMenuBar) + { + int h = 0; + m_frameMenuBar->GetSize( (int*)NULL, &h ); + pt.y += h + 2; + } + if (m_frameToolBar) + { + int h = 0; + m_frameToolBar->GetSize( (int*)NULL, &h ); + pt.y += h; + } + return pt; +} + void wxFrame::ImplementSetPosition(void) { if ((m_x != -1) || (m_y != -1)) @@ -240,6 +232,7 @@ void wxFrame::Centre( int direction ) if (direction & wxHORIZONTAL == wxHORIZONTAL) m_x = (gdk_screen_width () - m_width) / 2; if (direction & wxVERTICAL == wxVERTICAL) m_y = (gdk_screen_height () - m_height) / 2; + ImplementSetPosition(); } @@ -285,7 +278,6 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height if ((m_height == height) && (m_width == width) && (m_sizeSet)) return; - if (!m_mainWindow) return; if (!m_wxwindow) return; m_width = width; @@ -295,57 +287,41 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; - gtk_widget_set_usize( m_widget, width, height ); - - int main_x = 0; - int main_y = 0; - int main_height = height; - int main_width = width; - - // This emulates Windows behaviour: - // The menu bar is part of the main window, but the status bar - // is on the implementation side in the client area. The - // function GetClientSize returns the size of the client area - // minus the status bar height. Under wxGTK, the main window - // is represented by m_mainWindow. The menubar is inserted - // into m_mainWindow whereas the statusbar is insertes into - // m_wxwindow just like any other window. + gtk_widget_set_usize( m_widget, m_width, m_height ); -// not really needed -// gtk_widget_set_usize( m_mainWindow, width, height ); + // This emulates the new wxMSW behaviour if (m_frameMenuBar) { - main_y = wxMENU_HEIGHT; - main_height -= wxMENU_HEIGHT; - } - - int toolbar_height = 0; - if (m_frameToolBar) m_frameToolBar->GetSize( (int *) NULL, &toolbar_height ); - - main_y += toolbar_height; - main_height -= toolbar_height; - - gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_wxwindow, main_x, main_y ); - gtk_widget_set_usize( m_wxwindow, main_width, main_height ); - - if (m_frameMenuBar) - { - gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_frameMenuBar->m_widget, 1, 1 ); - gtk_widget_set_usize( m_frameMenuBar->m_widget, width-2, wxMENU_HEIGHT-2 ); + m_frameMenuBar->m_x = 1; + m_frameMenuBar->m_y = 1; + m_frameMenuBar->m_width = m_width-2; + m_frameMenuBar->m_height = wxMENU_HEIGHT-2; + gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, 1, 1 ); + gtk_widget_set_usize( m_frameMenuBar->m_widget, m_width-2, wxMENU_HEIGHT-2 ); } if (m_frameToolBar) { int y = 0; if (m_frameMenuBar) y = wxMENU_HEIGHT; - gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_frameToolBar->m_widget, 1, y ); - gtk_widget_set_usize( m_frameToolBar->m_widget, width-2, toolbar_height ); + int h = m_frameToolBar->m_height; + + m_frameToolBar->m_x = 2; + gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, 2, y ); + gtk_widget_set_usize( m_frameToolBar->m_widget, m_width-3, h ); } if (m_frameStatusBar) { - m_frameStatusBar->SetSize( 0, main_height-wxSTATUS_HEIGHT, width, wxSTATUS_HEIGHT ); + // OK, this hurts in the eye, but I don't want to call SetSize() + // because I don't want to call any non-native functions here. + m_frameStatusBar->m_x = 0; + m_frameStatusBar->m_y = m_height-wxSTATUS_HEIGHT; + m_frameStatusBar->m_width = m_width; + m_frameStatusBar->m_height = wxSTATUS_HEIGHT; + gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, 0, m_height-wxSTATUS_HEIGHT ); + gtk_widget_set_usize( m_frameStatusBar->m_widget, m_width, wxSTATUS_HEIGHT ); } m_sizeSet = TRUE; @@ -372,7 +348,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) { wxWindow *win = (wxWindow *)node->Data(); if (!IS_KIND_OF(win,wxFrame) && !IS_KIND_OF(win,wxDialog) -#if 0 // not in m_children anyway +#if 0 // not in m_children anyway ? && (win != m_frameMenuBar) && (win != m_frameToolBar) && (win != m_frameStatusBar) @@ -393,45 +369,6 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) } } -void wxFrame::AddChild( wxWindow *child ) -{ - wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); - wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); - wxASSERT_MSG( (m_mainWindow != NULL), "invalid frame" ); - wxASSERT_MSG( (child != NULL), "invalid child" ); - wxASSERT_MSG( (child->m_widget != NULL), "invalid child" ); - - // wxFrame and wxDialog as children aren't placed into the parents - - if (IS_KIND_OF(child,wxMDIChildFrame)) wxFAIL_MSG( "wxFrame::AddChild error.\n" ); - - if ( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog)) - { - m_children.Append( child ); - - if ((child->m_x != -1) && (child->m_y != -1)) - gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y ); - - return; - } - - if (m_addPrivateChild) - { - gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), child->m_widget, child->m_x, child->m_y ); - - gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); - } - else - { - m_children.Append( child ); - - if (m_wxwindow) - gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget, child->m_x, child->m_y ); - - gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); - } -} - static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) { menu->SetInvokingWindow( win ); @@ -449,7 +386,6 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) { wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); - wxASSERT_MSG( (m_mainWindow != NULL), "invalid frame" ); m_frameMenuBar = menuBar; @@ -466,7 +402,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) if (m_frameMenuBar->m_parent != this) { m_frameMenuBar->m_parent = this; - gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), + gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); } } @@ -483,9 +419,9 @@ wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& nam wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" ); - m_addPrivateChild = TRUE; m_frameToolBar = OnCreateToolBar( style, id, name ); - m_addPrivateChild = FALSE; + + GetChildren()->DeleteObject( m_frameToolBar ); return m_frameToolBar; } diff --git a/src/gtk/gauge.cpp b/src/gtk/gauge.cpp index 82e27351ce..eb0f339bb0 100644 --- a/src/gtk/gauge.cpp +++ b/src/gtk/gauge.cpp @@ -35,6 +35,10 @@ bool wxGauge::Create( wxWindow *parent, wxWindowID id, int range, m_widget = gtk_progress_bar_new(); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index bca38181d5..eb2a1cd5f2 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -121,6 +121,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_widget_show( list_item ); } + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); gtk_widget_realize( GTK_WIDGET(m_list) ); diff --git a/src/gtk/mdi.cpp b/src/gtk/mdi.cpp index 112eb90a9f..8b5f30689b 100644 --- a/src/gtk/mdi.cpp +++ b/src/gtk/mdi.cpp @@ -17,12 +17,20 @@ #include "wx/gtk/win_gtk.h" #include +//----------------------------------------------------------------------------- +// constants +//----------------------------------------------------------------------------- + +const int wxMENU_HEIGHT = 30; + +//----------------------------------------------------------------------------- +// globals //----------------------------------------------------------------------------- extern wxList wxPendingDelete; //----------------------------------------------------------------------------- -// wxMDIParentFrame +// "size_allocate" //----------------------------------------------------------------------------- static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) @@ -38,7 +46,10 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); } +//----------------------------------------------------------------------------- // page change callback +//----------------------------------------------------------------------------- + static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget), GtkNotebookPage *page, gint WXUNUSED(nPage), @@ -59,6 +70,8 @@ static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget), } } +//----------------------------------------------------------------------------- +// wxMDIParentFrame //----------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame) @@ -109,7 +122,7 @@ void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height ) int x = 0; int y = 0; GetClientSize( &x, &y ); - m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); + m_mdiMenuBar->SetSize( 1, 1, x-2, wxMENU_HEIGHT-2, wxSIZE_NO_ADJUSTMENTS ); } } @@ -122,7 +135,7 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar ) int x = 0; int y = 0; GetClientSize( &x, &y ); - m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); + m_mdiMenuBar->SetSize( 1, 1, x-2, wxMENU_HEIGHT-2, wxSIZE_NO_ADJUSTMENTS ); m_mdiMenuBar->Show( TRUE ); } } @@ -214,6 +227,7 @@ bool wxMDIChildFrame::Create( wxMDIParentFrame *parent, long style, const wxString& name ) { m_title = title; + return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name ); } @@ -262,7 +276,7 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar ) } mdi_frame->SetMDIMenuBar( m_menuBar ); - gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_mainWindow), + gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow), m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y ); } } @@ -280,6 +294,32 @@ void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) ) { } +//----------------------------------------------------------------------------- +// InsertChild callback for wxMDIClientWindow +//----------------------------------------------------------------------------- + +static void wxInsertChildInMDI( wxMDIClientWindow* parent, wxMDIChildFrame* child ) +{ + wxString s = child->m_title; + if (s.IsNull()) s = _("MDI child"); + + GtkWidget *label_widget = gtk_label_new( s ); + gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 ); + + gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); + + GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); + + gtk_notebook_append_page( notebook, child->m_widget, label_widget ); + + child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); + + gtk_notebook_set_page( notebook, parent->m_children.Number()-1 ); + + gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent ); +} + //----------------------------------------------------------------------------- // wxMDIClientWindow //----------------------------------------------------------------------------- @@ -302,6 +342,8 @@ wxMDIClientWindow::~wxMDIClientWindow(void) bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) { m_needParent = TRUE; + + m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI; PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" ); @@ -312,6 +354,8 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); + PostCreation(); Show( TRUE ); @@ -319,35 +363,5 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) return TRUE; } -void wxMDIClientWindow::AddChild( wxWindow *child ) -{ - if (!child->IsKindOf(CLASSINFO(wxMDIChildFrame))) - { - wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame"); - return; - } - - m_children.Append( child ); - - wxString s; - wxMDIChildFrame* mdi_child = (wxMDIChildFrame*) child; - s = mdi_child->m_title; - if (s.IsNull()) s = _("MDI child"); - - GtkWidget *label_widget; - label_widget = gtk_label_new( s ); - gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 ); - - gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); - - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), child->m_widget, label_widget ); - - mdi_child->m_page = (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); - - gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), m_children.Number()-1 ); - - gtk_page_change_callback( (GtkNotebook *) NULL, mdi_child->m_page, 0, this ); -} diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index b6d4de7986..d01b340ad2 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -7,9 +7,9 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - #ifdef __GNUG__ #pragma implementation "menu.h" +#pragma implementation "menuitem.h" #endif #include "wx/menu.h" diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index ec2257fb24..feb8c042c5 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -36,7 +36,6 @@ public: m_box = (GtkWidget *) NULL; } -//private: int m_id; wxString m_text; int m_image; @@ -87,6 +86,40 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); } +//----------------------------------------------------------------------------- +// InsertChild callback for wxNotebook +//----------------------------------------------------------------------------- + +static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) +{ + wxNotebookPage *page = new wxNotebookPage(); + + page->m_id = parent->GetPageCount(); + + page->m_box = gtk_hbox_new (FALSE, 0); + gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); + + GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); + + page->m_client = child; + gtk_notebook_append_page( notebook, child->m_widget, page->m_box ); + + page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); + + page->m_parent = notebook; + + gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); + + if (!page->m_page) + { + wxLogFatalError( "Notebook page creation error" ); + return; + } + + parent->m_pages.Append( page ); +} + //----------------------------------------------------------------------------- // wxNotebook //----------------------------------------------------------------------------- @@ -127,6 +160,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name ) { m_needParent = TRUE; + m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; PreCreation( parent, id, pos, size, style, name ); @@ -141,6 +175,10 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, (gpointer)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); @@ -411,39 +449,6 @@ wxWindow *wxNotebook::GetPage( int page ) const return nb_page->m_client; } -void wxNotebook::AddChild( wxWindow *win ) -{ - wxCHECK_RET( m_widget != NULL, "invalid notebook" ); - - m_children.Append(win); - - wxNotebookPage *page = new wxNotebookPage(); - - page->m_id = GetPageCount(); - - page->m_box = gtk_hbox_new (FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); - - page->m_client = win; - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, page->m_box ); - - page->m_page = - (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); - - page->m_parent = GTK_NOTEBOOK(m_widget); - - gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); - - if (!page->m_page) - { - wxLogFatalError( "Notebook page creation error" ); - return; - } - - m_pages.Append( page ); -} - // override these 2 functions to do nothing: everything is done in OnSize void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) { diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index c9e905199e..2547f4e97f 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -159,6 +159,9 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, if (newSize.y == -1) newSize.y = height; SetSize( newSize.x, newSize.y ); + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); + gtk_widget_set_usize( m_widget, m_width, m_height ); + PostCreation(); SetLabel( title ); diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index 4091543d8e..3936fb8ad7 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -60,6 +60,9 @@ bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& lab gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); + gtk_widget_set_usize( m_widget, m_width, m_height ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index e5e2cd59f7..0cd5adbd31 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -126,6 +126,10 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, gtk_signal_connect( GTK_OBJECT(m_widget), "button_release_event", (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index 7450b6ac34..b9d368a62f 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -99,10 +99,13 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, SetRange( minValue, maxValue ); SetValue( value ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); - SetForegroundColour( parent->GetForegroundColour() ); Show( TRUE ); diff --git a/src/gtk/statbmp.cpp b/src/gtk/statbmp.cpp index 524bfe575b..c51db3746f 100644 --- a/src/gtk/statbmp.cpp +++ b/src/gtk/statbmp.cpp @@ -57,6 +57,10 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi m_widget = gtk_label_new( "Bitmap" ); } + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); diff --git a/src/gtk/statbox.cpp b/src/gtk/statbox.cpp index 59282af991..fa7822024c 100644 --- a/src/gtk/statbox.cpp +++ b/src/gtk/statbox.cpp @@ -40,6 +40,10 @@ bool wxStaticBox::Create( wxWindow *parent, wxWindowID id, const wxString &label m_widget = gtk_frame_new(m_label); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetLabel(label); diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 978321af9f..d753dc0155 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -92,6 +92,10 @@ bool wxStaticText::Create( wxWindow *parent, wxWindowID id, const wxString &labe SetSize( newSize.x, newSize.y ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 5af767a335..27f465108c 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -118,6 +118,10 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id, gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 6b6ed2ffe2..d7e77bbc56 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -119,6 +119,10 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, if (newSize.y == -1) newSize.y = 26; SetSize( newSize.x, newSize.y ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); if (bMultiLine) @@ -136,6 +140,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, { gint tmp = 0; gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp ); + SetInsertionPointEnd(); } if (style & wxTE_READONLY) diff --git a/src/gtk/treectrl.cpp b/src/gtk/treectrl.cpp index dbdf733b00..8768e4e867 100644 --- a/src/gtk/treectrl.cpp +++ b/src/gtk/treectrl.cpp @@ -132,6 +132,10 @@ printf("5\n"); SetName(name); SetValidator(validator); +printf("Robert's new insertion code :-)\n"); + m_parent->AddChild( this ); + (m_parent->m_insertCallback)( m_parent, this ); + printf("postcreate\n"); PostCreation(); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index eaba8b03e1..2ad8406d0c 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -23,12 +23,9 @@ #include "wx/msgdlg.h" #include "wx/dcclient.h" #include "wx/dnd.h" -#include "wx/mdi.h" #include "wx/menu.h" -#include "wx/notebook.h" #include "wx/statusbr.h" #include "wx/intl.h" -#include "wx/gtk/win_gtk.h" #include "gdk/gdkprivate.h" #include "gdk/gdkkeysyms.h" @@ -862,6 +859,29 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailab */ } +//----------------------------------------------------------------------------- +// 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 //----------------------------------------------------------------------------- @@ -917,8 +937,17 @@ wxWindow::wxWindow() m_resizing = FALSE; m_scrollGC = (GdkGC*) NULL; m_widgetStyle = (GtkStyle*) NULL; + m_insertCallback = wxInsertChildInWindow; } +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 ) @@ -927,8 +956,6 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_isEnabled = TRUE; m_needParent = TRUE; - m_cursor = (wxCursor *) NULL; - PreCreation( parent, id, pos, size, style, name ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); @@ -1016,7 +1043,11 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); gtk_widget_show( m_wxwindow ); + + if (m_parent) m_parent->AddChild( this ); + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); @@ -1081,17 +1112,34 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, { if (m_needParent && (parent == NULL)) wxFatalError( "Need complete parent.", name ); - + m_widget = (GtkWidget *) NULL; m_hasVMT = FALSE; m_parent = parent; m_children.DeleteContents( FALSE ); - m_x = (int)pos.x; - m_y = (int)pos.y; + m_width = size.x; if (m_width == -1) m_width = 20; m_height = size.y; if (m_height == -1) m_height = 20; + + m_x = (int)pos.x; + m_y = (int)pos.y; + + if (!m_needParent) // some reasonable defaults + { + if (m_x == -1) + { + m_x = (gdk_screen_width () - m_width) / 2; + if (m_x < 10) m_x = 10; + } + if (m_y == -1) + { + m_y = (gdk_screen_height () - m_height) / 2; + if (m_y < 10) m_y = 10; + } + } + m_minWidth = -1; m_minHeight = -1; m_maxWidth = -1; @@ -1123,8 +1171,6 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, void wxWindow::PostCreation() { - if (m_parent) m_parent->AddChild( this ); - if (m_wxwindow) { gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", @@ -1220,6 +1266,21 @@ void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) ) // are we to set fonts here ? } +wxPoint wxWindow::GetClientAreaOrigin() const +{ + return wxPoint(0,0); +} + +void wxWindow::AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ) +{ + if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) + { + wxPoint pt(GetParent()->GetClientAreaOrigin()); + x += pt.x; + y += pt.y; + } +} + void wxWindow::ImplementSetSize() { if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; @@ -1231,13 +1292,6 @@ void wxWindow::ImplementSetSize() void wxWindow::ImplementSetPosition() { - if (IS_KIND_OF(this,wxFrame) || IS_KIND_OF(this,wxDialog)) - { - if ((m_x != -1) || (m_y != -1)) - gtk_widget_set_uposition( m_widget, m_x, m_y ); - return; - } - if (!m_parent) { wxFAIL_MSG( "wxWindow::SetSize error.\n" ); @@ -1280,12 +1334,15 @@ void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags ) if (newH == -1) newH = 26; } + AdjustForParentClientOrigin( newX, newY, sizeFlags ); + if ((m_x != newX) || (m_y != newY) || (!m_sizeSet)) { m_x = newX; m_y = newY; ImplementSetPosition(); } + if ((m_width != newW) || (m_height != newH) || (!m_sizeSet)) { m_width = newW; @@ -1445,8 +1502,18 @@ 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; + int xx = m_x; + int yy = m_y; + + if (GetParent()) + { + wxPoint pt(GetParent()->GetClientAreaOrigin()); + xx -= pt.x; + yy -= pt.y; + } + + if (x) (*x) = xx; + if (y) (*y) = yy; } void wxWindow::ClientToScreen( int *x, int *y ) @@ -1472,6 +1539,10 @@ void wxWindow::ClientToScreen( int *x, int *y ) } } + wxPoint pt(GetClientAreaOrigin()); + org_x += pt.x; + org_y += pt.y; + if (x) *x += org_x; if (y) *y += org_y; } @@ -1499,6 +1570,10 @@ void wxWindow::ScreenToClient( int *x, int *y ) } } + wxPoint pt(GetClientAreaOrigin()); + org_x -= pt.x; + org_y -= pt.y; + if (x) *x -= org_x; if (y) *y -= org_y; } @@ -1676,72 +1751,9 @@ bool wxWindow::OnClose() 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 - // practically imitates virtual tables, i.e. it - // implements a different AddChild() behaviour - // for wxFrame, wxDialog, wxWindow and - // wxMDIParentFrame. - - // wxFrame and wxDialog as children aren't placed into the parents - - if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) /*&& - (!IS_KIND_OF(child,wxMDIChildFrame))*/) - { - m_children.Append( child ); - - if ((child->m_x != -1) && (child->m_y != -1)) - gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y ); - - return; - } - - // In the case of an wxMDIChildFrame descendant, we use the - // client windows's AddChild() - - if (IS_KIND_OF(this,wxMDIParentFrame)) - { - if (IS_KIND_OF(child,wxMDIChildFrame)) - { - wxMDIClientWindow *client = ((wxMDIParentFrame*)this)->GetClientWindow(); - if (client) - { - client->AddChild( child ); - return; - } - } - } - - // wxNotebook is very special, so it has a private AddChild() - - if (IS_KIND_OF(this,wxNotebook)) - { - wxNotebook *tab = (wxNotebook*)this; - tab->AddChild( child ); - return; - } - - // wxFrame has a private AddChild - - if (IS_KIND_OF(this,wxFrame) && !IS_KIND_OF(this,wxMDIChildFrame)) - { - wxFrame *frame = (wxFrame*)this; - frame->AddChild( child ); - return; - } - - // All the rest m_children.Append( child ); - if (m_wxwindow) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget, - child->m_x, child->m_y ); - - gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); } wxList *wxWindow::GetChildren() @@ -1751,8 +1763,7 @@ wxList *wxWindow::GetChildren() void wxWindow::RemoveChild( wxWindow *child ) { - if (GetChildren()) - GetChildren()->DeleteObject( child ); + if (GetChildren()) GetChildren()->DeleteObject( child ); child->m_parent = (wxWindow *) NULL; } diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index 431e677569..c4a757b53a 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -83,6 +83,10 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &b gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index 249465f366..db5235be66 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -71,6 +71,10 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk1/checkbox.cpp b/src/gtk1/checkbox.cpp index d75e1c9cfb..c125d9d2df 100644 --- a/src/gtk1/checkbox.cpp +++ b/src/gtk1/checkbox.cpp @@ -65,6 +65,10 @@ bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); gtk_widget_realize( GTK_BUTTON( m_widget )->child ); diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 6cc9718298..b61e049afb 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -82,6 +82,10 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, } gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 1b72045d73..ebc9849d38 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -93,6 +93,10 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value, GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this ); } + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); ConnectWidget( GTK_COMBO(m_widget)->button ); diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index bdeafd1bd3..589ef94f45 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -98,6 +98,9 @@ bool wxDialog::Create( wxWindow *parent, gtk_widget_set_usize( m_widget, m_width, m_height ); + if (m_parent) m_parent->AddChild( this ); + + PostCreation(); return TRUE; diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index 235078cff1..118c1cb401 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -18,7 +18,6 @@ #include "wx/menu.h" #include "wx/toolbar.h" #include "wx/statusbr.h" -#include "wx/mdi.h" #include "wx/dcclient.h" #include "wx/gtk/win_gtk.h" @@ -104,9 +103,6 @@ wxFrame::wxFrame() m_frameStatusBar = (wxStatusBar *) NULL; m_frameToolBar = (wxToolBar *) NULL; m_sizeSet = FALSE; - m_addPrivateChild = FALSE; - m_wxwindow = (GtkWidget *) NULL; - m_mainWindow = (GtkWidget *) NULL; wxTopLevelWindows.Insert( this ); } @@ -118,9 +114,6 @@ wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, m_frameStatusBar = (wxStatusBar *) NULL; m_frameToolBar = (wxToolBar *) NULL; m_sizeSet = FALSE; - m_addPrivateChild = FALSE; - m_wxwindow = (GtkWidget *) NULL; - m_mainWindow = (GtkWidget *) NULL; Create( parent, id, title, pos, size, style, name ); wxTopLevelWindows.Insert( this ); } @@ -147,23 +140,16 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, gtk_window_set_title( GTK_WINDOW(m_widget), title ); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); - gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL); + gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL ); gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); - m_mainWindow = gtk_myfixed_new(); - gtk_widget_show( m_mainWindow ); - GTK_WIDGET_UNSET_FLAGS( m_mainWindow, GTK_CAN_FOCUS ); - - gtk_container_add( GTK_CONTAINER(m_widget), m_mainWindow ); - gtk_widget_set_uposition( m_mainWindow, 0, 0 ); - m_wxwindow = gtk_myfixed_new(); gtk_widget_show( m_wxwindow ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); - gtk_container_add( GTK_CONTAINER(m_mainWindow), m_wxwindow ); + gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); @@ -171,10 +157,10 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); + if (m_parent) m_parent->AddChild( this ); + PostCreation(); - gtk_widget_realize( m_mainWindow ); - return TRUE; } @@ -184,8 +170,6 @@ wxFrame::~wxFrame() if (m_frameStatusBar) delete m_frameStatusBar; if (m_frameToolBar) delete m_frameToolBar; -// if (m_mainWindow) gtk_widget_destroy( m_mainWindow ); - wxTopLevelWindows.DeleteObject( this ); if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); } @@ -203,16 +187,6 @@ bool wxFrame::Show( bool show ) return wxWindow::Show( show ); } -void wxFrame::Enable( bool enable ) -{ - wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); - - if (!m_mainWindow) return; - - wxWindow::Enable( enable ); - gtk_widget_set_sensitive( m_mainWindow, enable ); -} - void wxFrame::OnCloseWindow( wxCloseEvent &event ) { if (GetEventHandler()->OnClose() || event.GetForce()) this->Destroy(); @@ -228,6 +202,24 @@ bool wxFrame::Destroy() return TRUE; } +wxPoint wxFrame::GetClientAreaOrigin() const +{ + wxPoint pt(0, 0); + if (m_frameMenuBar) + { + int h = 0; + m_frameMenuBar->GetSize( (int*)NULL, &h ); + pt.y += h + 2; + } + if (m_frameToolBar) + { + int h = 0; + m_frameToolBar->GetSize( (int*)NULL, &h ); + pt.y += h; + } + return pt; +} + void wxFrame::ImplementSetPosition(void) { if ((m_x != -1) || (m_y != -1)) @@ -240,6 +232,7 @@ void wxFrame::Centre( int direction ) if (direction & wxHORIZONTAL == wxHORIZONTAL) m_x = (gdk_screen_width () - m_width) / 2; if (direction & wxVERTICAL == wxVERTICAL) m_y = (gdk_screen_height () - m_height) / 2; + ImplementSetPosition(); } @@ -285,7 +278,6 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height if ((m_height == height) && (m_width == width) && (m_sizeSet)) return; - if (!m_mainWindow) return; if (!m_wxwindow) return; m_width = width; @@ -295,57 +287,41 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; - gtk_widget_set_usize( m_widget, width, height ); - - int main_x = 0; - int main_y = 0; - int main_height = height; - int main_width = width; - - // This emulates Windows behaviour: - // The menu bar is part of the main window, but the status bar - // is on the implementation side in the client area. The - // function GetClientSize returns the size of the client area - // minus the status bar height. Under wxGTK, the main window - // is represented by m_mainWindow. The menubar is inserted - // into m_mainWindow whereas the statusbar is insertes into - // m_wxwindow just like any other window. + gtk_widget_set_usize( m_widget, m_width, m_height ); -// not really needed -// gtk_widget_set_usize( m_mainWindow, width, height ); + // This emulates the new wxMSW behaviour if (m_frameMenuBar) { - main_y = wxMENU_HEIGHT; - main_height -= wxMENU_HEIGHT; - } - - int toolbar_height = 0; - if (m_frameToolBar) m_frameToolBar->GetSize( (int *) NULL, &toolbar_height ); - - main_y += toolbar_height; - main_height -= toolbar_height; - - gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_wxwindow, main_x, main_y ); - gtk_widget_set_usize( m_wxwindow, main_width, main_height ); - - if (m_frameMenuBar) - { - gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_frameMenuBar->m_widget, 1, 1 ); - gtk_widget_set_usize( m_frameMenuBar->m_widget, width-2, wxMENU_HEIGHT-2 ); + m_frameMenuBar->m_x = 1; + m_frameMenuBar->m_y = 1; + m_frameMenuBar->m_width = m_width-2; + m_frameMenuBar->m_height = wxMENU_HEIGHT-2; + gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, 1, 1 ); + gtk_widget_set_usize( m_frameMenuBar->m_widget, m_width-2, wxMENU_HEIGHT-2 ); } if (m_frameToolBar) { int y = 0; if (m_frameMenuBar) y = wxMENU_HEIGHT; - gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_frameToolBar->m_widget, 1, y ); - gtk_widget_set_usize( m_frameToolBar->m_widget, width-2, toolbar_height ); + int h = m_frameToolBar->m_height; + + m_frameToolBar->m_x = 2; + gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, 2, y ); + gtk_widget_set_usize( m_frameToolBar->m_widget, m_width-3, h ); } if (m_frameStatusBar) { - m_frameStatusBar->SetSize( 0, main_height-wxSTATUS_HEIGHT, width, wxSTATUS_HEIGHT ); + // OK, this hurts in the eye, but I don't want to call SetSize() + // because I don't want to call any non-native functions here. + m_frameStatusBar->m_x = 0; + m_frameStatusBar->m_y = m_height-wxSTATUS_HEIGHT; + m_frameStatusBar->m_width = m_width; + m_frameStatusBar->m_height = wxSTATUS_HEIGHT; + gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, 0, m_height-wxSTATUS_HEIGHT ); + gtk_widget_set_usize( m_frameStatusBar->m_widget, m_width, wxSTATUS_HEIGHT ); } m_sizeSet = TRUE; @@ -372,7 +348,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) { wxWindow *win = (wxWindow *)node->Data(); if (!IS_KIND_OF(win,wxFrame) && !IS_KIND_OF(win,wxDialog) -#if 0 // not in m_children anyway +#if 0 // not in m_children anyway ? && (win != m_frameMenuBar) && (win != m_frameToolBar) && (win != m_frameStatusBar) @@ -393,45 +369,6 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) } } -void wxFrame::AddChild( wxWindow *child ) -{ - wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); - wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); - wxASSERT_MSG( (m_mainWindow != NULL), "invalid frame" ); - wxASSERT_MSG( (child != NULL), "invalid child" ); - wxASSERT_MSG( (child->m_widget != NULL), "invalid child" ); - - // wxFrame and wxDialog as children aren't placed into the parents - - if (IS_KIND_OF(child,wxMDIChildFrame)) wxFAIL_MSG( "wxFrame::AddChild error.\n" ); - - if ( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog)) - { - m_children.Append( child ); - - if ((child->m_x != -1) && (child->m_y != -1)) - gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y ); - - return; - } - - if (m_addPrivateChild) - { - gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), child->m_widget, child->m_x, child->m_y ); - - gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); - } - else - { - m_children.Append( child ); - - if (m_wxwindow) - gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget, child->m_x, child->m_y ); - - gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); - } -} - static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) { menu->SetInvokingWindow( win ); @@ -449,7 +386,6 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) { wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); - wxASSERT_MSG( (m_mainWindow != NULL), "invalid frame" ); m_frameMenuBar = menuBar; @@ -466,7 +402,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) if (m_frameMenuBar->m_parent != this) { m_frameMenuBar->m_parent = this; - gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), + gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); } } @@ -483,9 +419,9 @@ wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& nam wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" ); - m_addPrivateChild = TRUE; m_frameToolBar = OnCreateToolBar( style, id, name ); - m_addPrivateChild = FALSE; + + GetChildren()->DeleteObject( m_frameToolBar ); return m_frameToolBar; } diff --git a/src/gtk1/gauge.cpp b/src/gtk1/gauge.cpp index 82e27351ce..eb0f339bb0 100644 --- a/src/gtk1/gauge.cpp +++ b/src/gtk1/gauge.cpp @@ -35,6 +35,10 @@ bool wxGauge::Create( wxWindow *parent, wxWindowID id, int range, m_widget = gtk_progress_bar_new(); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index bca38181d5..eb2a1cd5f2 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -121,6 +121,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_widget_show( list_item ); } + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); gtk_widget_realize( GTK_WIDGET(m_list) ); diff --git a/src/gtk1/mdi.cpp b/src/gtk1/mdi.cpp index 112eb90a9f..8b5f30689b 100644 --- a/src/gtk1/mdi.cpp +++ b/src/gtk1/mdi.cpp @@ -17,12 +17,20 @@ #include "wx/gtk/win_gtk.h" #include +//----------------------------------------------------------------------------- +// constants +//----------------------------------------------------------------------------- + +const int wxMENU_HEIGHT = 30; + +//----------------------------------------------------------------------------- +// globals //----------------------------------------------------------------------------- extern wxList wxPendingDelete; //----------------------------------------------------------------------------- -// wxMDIParentFrame +// "size_allocate" //----------------------------------------------------------------------------- static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) @@ -38,7 +46,10 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); } +//----------------------------------------------------------------------------- // page change callback +//----------------------------------------------------------------------------- + static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget), GtkNotebookPage *page, gint WXUNUSED(nPage), @@ -59,6 +70,8 @@ static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget), } } +//----------------------------------------------------------------------------- +// wxMDIParentFrame //----------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame) @@ -109,7 +122,7 @@ void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height ) int x = 0; int y = 0; GetClientSize( &x, &y ); - m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); + m_mdiMenuBar->SetSize( 1, 1, x-2, wxMENU_HEIGHT-2, wxSIZE_NO_ADJUSTMENTS ); } } @@ -122,7 +135,7 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar ) int x = 0; int y = 0; GetClientSize( &x, &y ); - m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); + m_mdiMenuBar->SetSize( 1, 1, x-2, wxMENU_HEIGHT-2, wxSIZE_NO_ADJUSTMENTS ); m_mdiMenuBar->Show( TRUE ); } } @@ -214,6 +227,7 @@ bool wxMDIChildFrame::Create( wxMDIParentFrame *parent, long style, const wxString& name ) { m_title = title; + return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name ); } @@ -262,7 +276,7 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar ) } mdi_frame->SetMDIMenuBar( m_menuBar ); - gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_mainWindow), + gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow), m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y ); } } @@ -280,6 +294,32 @@ void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) ) { } +//----------------------------------------------------------------------------- +// InsertChild callback for wxMDIClientWindow +//----------------------------------------------------------------------------- + +static void wxInsertChildInMDI( wxMDIClientWindow* parent, wxMDIChildFrame* child ) +{ + wxString s = child->m_title; + if (s.IsNull()) s = _("MDI child"); + + GtkWidget *label_widget = gtk_label_new( s ); + gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 ); + + gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); + + GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); + + gtk_notebook_append_page( notebook, child->m_widget, label_widget ); + + child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); + + gtk_notebook_set_page( notebook, parent->m_children.Number()-1 ); + + gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent ); +} + //----------------------------------------------------------------------------- // wxMDIClientWindow //----------------------------------------------------------------------------- @@ -302,6 +342,8 @@ wxMDIClientWindow::~wxMDIClientWindow(void) bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) { m_needParent = TRUE; + + m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI; PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" ); @@ -312,6 +354,8 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); + PostCreation(); Show( TRUE ); @@ -319,35 +363,5 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) return TRUE; } -void wxMDIClientWindow::AddChild( wxWindow *child ) -{ - if (!child->IsKindOf(CLASSINFO(wxMDIChildFrame))) - { - wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame"); - return; - } - - m_children.Append( child ); - - wxString s; - wxMDIChildFrame* mdi_child = (wxMDIChildFrame*) child; - s = mdi_child->m_title; - if (s.IsNull()) s = _("MDI child"); - - GtkWidget *label_widget; - label_widget = gtk_label_new( s ); - gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 ); - - gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); - - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), child->m_widget, label_widget ); - - mdi_child->m_page = (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); - - gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), m_children.Number()-1 ); - - gtk_page_change_callback( (GtkNotebook *) NULL, mdi_child->m_page, 0, this ); -} diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index b6d4de7986..d01b340ad2 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -7,9 +7,9 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - #ifdef __GNUG__ #pragma implementation "menu.h" +#pragma implementation "menuitem.h" #endif #include "wx/menu.h" diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index ec2257fb24..feb8c042c5 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -36,7 +36,6 @@ public: m_box = (GtkWidget *) NULL; } -//private: int m_id; wxString m_text; int m_image; @@ -87,6 +86,40 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); } +//----------------------------------------------------------------------------- +// InsertChild callback for wxNotebook +//----------------------------------------------------------------------------- + +static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) +{ + wxNotebookPage *page = new wxNotebookPage(); + + page->m_id = parent->GetPageCount(); + + page->m_box = gtk_hbox_new (FALSE, 0); + gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); + + GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); + + page->m_client = child; + gtk_notebook_append_page( notebook, child->m_widget, page->m_box ); + + page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); + + page->m_parent = notebook; + + gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); + + if (!page->m_page) + { + wxLogFatalError( "Notebook page creation error" ); + return; + } + + parent->m_pages.Append( page ); +} + //----------------------------------------------------------------------------- // wxNotebook //----------------------------------------------------------------------------- @@ -127,6 +160,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name ) { m_needParent = TRUE; + m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; PreCreation( parent, id, pos, size, style, name ); @@ -141,6 +175,10 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, (gpointer)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); @@ -411,39 +449,6 @@ wxWindow *wxNotebook::GetPage( int page ) const return nb_page->m_client; } -void wxNotebook::AddChild( wxWindow *win ) -{ - wxCHECK_RET( m_widget != NULL, "invalid notebook" ); - - m_children.Append(win); - - wxNotebookPage *page = new wxNotebookPage(); - - page->m_id = GetPageCount(); - - page->m_box = gtk_hbox_new (FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); - - page->m_client = win; - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, page->m_box ); - - page->m_page = - (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); - - page->m_parent = GTK_NOTEBOOK(m_widget); - - gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); - - if (!page->m_page) - { - wxLogFatalError( "Notebook page creation error" ); - return; - } - - m_pages.Append( page ); -} - // override these 2 functions to do nothing: everything is done in OnSize void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) { diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index c9e905199e..2547f4e97f 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -159,6 +159,9 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, if (newSize.y == -1) newSize.y = height; SetSize( newSize.x, newSize.y ); + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); + gtk_widget_set_usize( m_widget, m_width, m_height ); + PostCreation(); SetLabel( title ); diff --git a/src/gtk1/radiobut.cpp b/src/gtk1/radiobut.cpp index 4091543d8e..3936fb8ad7 100644 --- a/src/gtk1/radiobut.cpp +++ b/src/gtk1/radiobut.cpp @@ -60,6 +60,9 @@ bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& lab gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); + gtk_widget_set_usize( m_widget, m_width, m_height ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk1/scrolbar.cpp b/src/gtk1/scrolbar.cpp index e5e2cd59f7..0cd5adbd31 100644 --- a/src/gtk1/scrolbar.cpp +++ b/src/gtk1/scrolbar.cpp @@ -126,6 +126,10 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, gtk_signal_connect( GTK_OBJECT(m_widget), "button_release_event", (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index 7450b6ac34..b9d368a62f 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -99,10 +99,13 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, SetRange( minValue, maxValue ); SetValue( value ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); - SetForegroundColour( parent->GetForegroundColour() ); Show( TRUE ); diff --git a/src/gtk1/statbmp.cpp b/src/gtk1/statbmp.cpp index 524bfe575b..c51db3746f 100644 --- a/src/gtk1/statbmp.cpp +++ b/src/gtk1/statbmp.cpp @@ -57,6 +57,10 @@ bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi m_widget = gtk_label_new( "Bitmap" ); } + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); diff --git a/src/gtk1/statbox.cpp b/src/gtk1/statbox.cpp index 59282af991..fa7822024c 100644 --- a/src/gtk1/statbox.cpp +++ b/src/gtk1/statbox.cpp @@ -40,6 +40,10 @@ bool wxStaticBox::Create( wxWindow *parent, wxWindowID id, const wxString &label m_widget = gtk_frame_new(m_label); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetLabel(label); diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 978321af9f..d753dc0155 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -92,6 +92,10 @@ bool wxStaticText::Create( wxWindow *parent, wxWindowID id, const wxString &labe SetSize( newSize.x, newSize.y ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); SetBackgroundColour( parent->GetBackgroundColour() ); diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index 5af767a335..27f465108c 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -118,6 +118,10 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id, gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 6b6ed2ffe2..d7e77bbc56 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -119,6 +119,10 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, if (newSize.y == -1) newSize.y = 26; SetSize( newSize.x, newSize.y ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); if (bMultiLine) @@ -136,6 +140,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, { gint tmp = 0; gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp ); + SetInsertionPointEnd(); } if (style & wxTE_READONLY) diff --git a/src/gtk1/treectrl.cpp b/src/gtk1/treectrl.cpp index dbdf733b00..8768e4e867 100644 --- a/src/gtk1/treectrl.cpp +++ b/src/gtk1/treectrl.cpp @@ -132,6 +132,10 @@ printf("5\n"); SetName(name); SetValidator(validator); +printf("Robert's new insertion code :-)\n"); + m_parent->AddChild( this ); + (m_parent->m_insertCallback)( m_parent, this ); + printf("postcreate\n"); PostCreation(); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index eaba8b03e1..2ad8406d0c 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -23,12 +23,9 @@ #include "wx/msgdlg.h" #include "wx/dcclient.h" #include "wx/dnd.h" -#include "wx/mdi.h" #include "wx/menu.h" -#include "wx/notebook.h" #include "wx/statusbr.h" #include "wx/intl.h" -#include "wx/gtk/win_gtk.h" #include "gdk/gdkprivate.h" #include "gdk/gdkkeysyms.h" @@ -862,6 +859,29 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailab */ } +//----------------------------------------------------------------------------- +// 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 //----------------------------------------------------------------------------- @@ -917,8 +937,17 @@ wxWindow::wxWindow() m_resizing = FALSE; m_scrollGC = (GdkGC*) NULL; m_widgetStyle = (GtkStyle*) NULL; + m_insertCallback = wxInsertChildInWindow; } +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 ) @@ -927,8 +956,6 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_isEnabled = TRUE; m_needParent = TRUE; - m_cursor = (wxCursor *) NULL; - PreCreation( parent, id, pos, size, style, name ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); @@ -1016,7 +1043,11 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); gtk_widget_show( m_wxwindow ); + + if (m_parent) m_parent->AddChild( this ); + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); @@ -1081,17 +1112,34 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, { if (m_needParent && (parent == NULL)) wxFatalError( "Need complete parent.", name ); - + m_widget = (GtkWidget *) NULL; m_hasVMT = FALSE; m_parent = parent; m_children.DeleteContents( FALSE ); - m_x = (int)pos.x; - m_y = (int)pos.y; + m_width = size.x; if (m_width == -1) m_width = 20; m_height = size.y; if (m_height == -1) m_height = 20; + + m_x = (int)pos.x; + m_y = (int)pos.y; + + if (!m_needParent) // some reasonable defaults + { + if (m_x == -1) + { + m_x = (gdk_screen_width () - m_width) / 2; + if (m_x < 10) m_x = 10; + } + if (m_y == -1) + { + m_y = (gdk_screen_height () - m_height) / 2; + if (m_y < 10) m_y = 10; + } + } + m_minWidth = -1; m_minHeight = -1; m_maxWidth = -1; @@ -1123,8 +1171,6 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, void wxWindow::PostCreation() { - if (m_parent) m_parent->AddChild( this ); - if (m_wxwindow) { gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", @@ -1220,6 +1266,21 @@ void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) ) // are we to set fonts here ? } +wxPoint wxWindow::GetClientAreaOrigin() const +{ + return wxPoint(0,0); +} + +void wxWindow::AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ) +{ + if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) + { + wxPoint pt(GetParent()->GetClientAreaOrigin()); + x += pt.x; + y += pt.y; + } +} + void wxWindow::ImplementSetSize() { if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; @@ -1231,13 +1292,6 @@ void wxWindow::ImplementSetSize() void wxWindow::ImplementSetPosition() { - if (IS_KIND_OF(this,wxFrame) || IS_KIND_OF(this,wxDialog)) - { - if ((m_x != -1) || (m_y != -1)) - gtk_widget_set_uposition( m_widget, m_x, m_y ); - return; - } - if (!m_parent) { wxFAIL_MSG( "wxWindow::SetSize error.\n" ); @@ -1280,12 +1334,15 @@ void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags ) if (newH == -1) newH = 26; } + AdjustForParentClientOrigin( newX, newY, sizeFlags ); + if ((m_x != newX) || (m_y != newY) || (!m_sizeSet)) { m_x = newX; m_y = newY; ImplementSetPosition(); } + if ((m_width != newW) || (m_height != newH) || (!m_sizeSet)) { m_width = newW; @@ -1445,8 +1502,18 @@ 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; + int xx = m_x; + int yy = m_y; + + if (GetParent()) + { + wxPoint pt(GetParent()->GetClientAreaOrigin()); + xx -= pt.x; + yy -= pt.y; + } + + if (x) (*x) = xx; + if (y) (*y) = yy; } void wxWindow::ClientToScreen( int *x, int *y ) @@ -1472,6 +1539,10 @@ void wxWindow::ClientToScreen( int *x, int *y ) } } + wxPoint pt(GetClientAreaOrigin()); + org_x += pt.x; + org_y += pt.y; + if (x) *x += org_x; if (y) *y += org_y; } @@ -1499,6 +1570,10 @@ void wxWindow::ScreenToClient( int *x, int *y ) } } + wxPoint pt(GetClientAreaOrigin()); + org_x -= pt.x; + org_y -= pt.y; + if (x) *x -= org_x; if (y) *y -= org_y; } @@ -1676,72 +1751,9 @@ bool wxWindow::OnClose() 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 - // practically imitates virtual tables, i.e. it - // implements a different AddChild() behaviour - // for wxFrame, wxDialog, wxWindow and - // wxMDIParentFrame. - - // wxFrame and wxDialog as children aren't placed into the parents - - if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) /*&& - (!IS_KIND_OF(child,wxMDIChildFrame))*/) - { - m_children.Append( child ); - - if ((child->m_x != -1) && (child->m_y != -1)) - gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y ); - - return; - } - - // In the case of an wxMDIChildFrame descendant, we use the - // client windows's AddChild() - - if (IS_KIND_OF(this,wxMDIParentFrame)) - { - if (IS_KIND_OF(child,wxMDIChildFrame)) - { - wxMDIClientWindow *client = ((wxMDIParentFrame*)this)->GetClientWindow(); - if (client) - { - client->AddChild( child ); - return; - } - } - } - - // wxNotebook is very special, so it has a private AddChild() - - if (IS_KIND_OF(this,wxNotebook)) - { - wxNotebook *tab = (wxNotebook*)this; - tab->AddChild( child ); - return; - } - - // wxFrame has a private AddChild - - if (IS_KIND_OF(this,wxFrame) && !IS_KIND_OF(this,wxMDIChildFrame)) - { - wxFrame *frame = (wxFrame*)this; - frame->AddChild( child ); - return; - } - - // All the rest m_children.Append( child ); - if (m_wxwindow) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget, - child->m_x, child->m_y ); - - gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); } wxList *wxWindow::GetChildren() @@ -1751,8 +1763,7 @@ wxList *wxWindow::GetChildren() void wxWindow::RemoveChild( wxWindow *child ) { - if (GetChildren()) - GetChildren()->DeleteObject( child ); + if (GetChildren()) GetChildren()->DeleteObject( child ); child->m_parent = (wxWindow *) NULL; } -- 2.45.2