From ee31c392ac73dcd67fb25ac368e2ffb7d4c9c0e7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Jul 1999 16:10:18 +0000 Subject: [PATCH] 1. Assorted Motif fixes a) tear off menus b) native dialogs c) crash in ~wxWindow fixed d) compilation and linking fixes 2. test code removed from minimal sample, text one compiles without clipboard 3. wxAppBase/wxApp small fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3074 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 20 ++++ include/wx/gtk/app.h | 22 ---- include/wx/gtk1/app.h | 22 ---- include/wx/motif/app.h | 187 +++++++++++-------------------- include/wx/motif/menu.h | 217 ++++++++++++++++++++---------------- include/wx/motif/msgdlg.h | 38 ++++--- include/wx/motif/private.h | 32 ++++++ include/wx/motif/window.h | 3 +- include/wx/msw/app.h | 10 -- samples/minimal/minimal.cpp | 78 ------------- samples/text/text.cpp | 3 + src/motif/Makefile.am | 2 +- src/motif/app.cpp | 110 +++++++++++++----- src/motif/menu.cpp | 89 ++++----------- src/motif/msgdlg.cpp | 192 +++++++++++++++++++++++++++++-- src/motif/window.cpp | 74 ++++++++++++ 16 files changed, 635 insertions(+), 464 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index 06ec920cc3..52fe9ea5d4 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -250,6 +250,26 @@ protected: #include "wx/stubs/app.h" #endif +// ---------------------------------------------------------------------------- +// the global data +// ---------------------------------------------------------------------------- + +// the one and only application object - use of wxTheApp in application code +// is discouraged, consider using DECLARE_APP() after which you may call +// wxGetApp() which will return the object of the correct type (i.e. MyApp and +// not wxApp) +WXDLLEXPORT_DATA(extern wxApp*) wxTheApp; + +// ---------------------------------------------------------------------------- +// global functions +// ---------------------------------------------------------------------------- + +// Force an exit from main loop +void WXDLLEXPORT wxExit(); + +// Yield to other apps/messages +bool WXDLLEXPORT wxYield(); + // ---------------------------------------------------------------------------- // macros for dynamic creation of the application object // ---------------------------------------------------------------------------- diff --git a/include/wx/gtk/app.h b/include/wx/gtk/app.h index 3657155ade..056c8c6729 100644 --- a/include/wx/gtk/app.h +++ b/include/wx/gtk/app.h @@ -14,8 +14,6 @@ #pragma interface #endif -#include "wx/defs.h" -#include "wx/window.h" #include "wx/frame.h" #include "wx/icon.h" @@ -26,26 +24,6 @@ class wxApp; class wxLog; -//----------------------------------------------------------------------------- -// global data -//----------------------------------------------------------------------------- - -extern wxApp *wxTheApp; - -//----------------------------------------------------------------------------- -// global functions -//----------------------------------------------------------------------------- - -void wxExit(void); -bool wxYield(void); - -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -#define wxPRINT_WINDOWS 1 -#define wxPRINT_POSTSCRIPT 2 - //----------------------------------------------------------------------------- // wxApp //----------------------------------------------------------------------------- diff --git a/include/wx/gtk1/app.h b/include/wx/gtk1/app.h index 3657155ade..056c8c6729 100644 --- a/include/wx/gtk1/app.h +++ b/include/wx/gtk1/app.h @@ -14,8 +14,6 @@ #pragma interface #endif -#include "wx/defs.h" -#include "wx/window.h" #include "wx/frame.h" #include "wx/icon.h" @@ -26,26 +24,6 @@ class wxApp; class wxLog; -//----------------------------------------------------------------------------- -// global data -//----------------------------------------------------------------------------- - -extern wxApp *wxTheApp; - -//----------------------------------------------------------------------------- -// global functions -//----------------------------------------------------------------------------- - -void wxExit(void); -bool wxYield(void); - -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -#define wxPRINT_WINDOWS 1 -#define wxPRINT_POSTSCRIPT 2 - //----------------------------------------------------------------------------- // wxApp //----------------------------------------------------------------------------- diff --git a/include/wx/motif/app.h b/include/wx/motif/app.h index d70e0d98be..7787929380 100644 --- a/include/wx/motif/app.h +++ b/include/wx/motif/app.h @@ -13,167 +13,114 @@ #define _WX_APP_H_ #ifdef __GNUG__ -#pragma interface "app.h" + #pragma interface "app.h" #endif -#include "wx/defs.h" -#include "wx/object.h" +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #include "wx/gdicmn.h" #include "wx/event.h" +// ---------------------------------------------------------------------------- +// forward declarations +// ---------------------------------------------------------------------------- + class WXDLLEXPORT wxFrame; class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxApp ; class WXDLLEXPORT wxKeyEvent; class WXDLLEXPORT wxLog; -#define wxPRINT_WINDOWS 1 -#define wxPRINT_POSTSCRIPT 2 - -WXDLLEXPORT_DATA(extern wxApp*) wxTheApp; - -// Force an exit from main loop -void WXDLLEXPORT wxExit(); - -// Yield to other apps/messages -bool WXDLLEXPORT wxYield(); +// ---------------------------------------------------------------------------- +// the wxApp class for Motif - see wxAppBase for more details +// ---------------------------------------------------------------------------- -// Represents the application. Derive OnInit and declare -// a new App object to start application -class WXDLLEXPORT wxApp: public wxEvtHandler +class WXDLLEXPORT wxApp : public wxAppBase { - DECLARE_DYNAMIC_CLASS(wxApp) - wxApp(); - inline ~wxApp() {} - - static void SetInitializerFunction(wxAppInitializerFunction fn) { m_appInitFn = fn; } - static wxAppInitializerFunction GetInitializerFunction() { return m_appInitFn; } - - virtual int MainLoop(); - void ExitMainLoop(); - bool Initialized(); - virtual bool Pending() ; - virtual void Dispatch() ; - - void OnIdle(wxIdleEvent& event); - -// Generic - virtual bool OnInit() { return FALSE; }; +DECLARE_DYNAMIC_CLASS(wxApp) - // Create an application context - virtual bool OnInitGui(); - - // Called to set off the main loop - virtual int OnRun() { return MainLoop(); }; - virtual int OnExit() { return 0; } - - /** Returns the standard icons for the msg dialogs, implemented in - src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ - virtual wxIcon GetStdIcon(int which) const; - - inline void SetPrintMode(int mode) { m_printMode = mode; } - inline int GetPrintMode() const { return m_printMode; } - - inline void SetExitOnFrameDelete(bool flag) { m_exitOnFrameDelete = flag; } - inline bool GetExitOnFrameDelete() const { return m_exitOnFrameDelete; } - - inline wxString GetAppName() const { - if (m_appName != "") - return m_appName; - else return m_className; - } +public: + wxApp(); + ~wxApp() {} - inline void SetAppName(const wxString& name) { m_appName = name; }; - inline wxString GetClassName() const { return m_className; } - inline void SetClassName(const wxString& name) { m_className = name; } + // override base class (pure) virtuals + // ----------------------------------- - void SetVendorName(const wxString& vendorName) { m_vendorName = vendorName; } - const wxString& GetVendorName() const { return m_vendorName; } + virtual int MainLoop(); + virtual void ExitMainLoop(); + virtual bool Initialized(); + virtual bool Pending() ; + virtual void Dispatch() ; - wxWindow *GetTopWindow() const ; - inline void SetTopWindow(wxWindow *win) { m_topWindow = win; } + virtual bool OnInitGui(); - inline void SetWantDebugOutput(bool flag) { m_wantDebugOutput = flag; } - inline bool GetWantDebugOutput() { return m_wantDebugOutput; } + virtual wxIcon GetStdIcon(int which) const; - // Send idle event to all top-level windows. - // Returns TRUE if more idle time is requested. - bool SendIdleEvents(); + // implementation from now on + // -------------------------- - // Send idle event to window and all subwindows - // Returns TRUE if more idle time is requested. - bool SendIdleEvents(wxWindow* win); + void OnIdle(wxIdleEvent& event); - // Windows only, but for compatibility... - inline void SetAuto3D(bool flag) { m_auto3D = flag; } - inline bool GetAuto3D() const { return m_auto3D; } + // Send idle event to all top-level windows. + // Returns TRUE if more idle time is requested. + bool SendIdleEvents(); - // Creates a log object - virtual wxLog* CreateLogTarget(); + // Send idle event to window and all subwindows + // Returns TRUE if more idle time is requested. + bool SendIdleEvents(wxWindow* win); -// Motif implementation. + // Motif implementation. - // Processes an X event. - virtual void ProcessXEvent(WXEvent* event); + // Processes an X event. + virtual void ProcessXEvent(WXEvent* event); - // Returns TRUE if an accelerator has been processed - virtual bool CheckForAccelerator(WXEvent* event); + // Returns TRUE if an accelerator has been processed + virtual bool CheckForAccelerator(WXEvent* event); -public: - // Will always be set to the appropriate, main-style values. - int argc; - char ** argv; + // Returns TRUE if a key down event has been processed + virtual bool CheckForKeyDown(WXEvent* event); protected: - bool m_wantDebugOutput ; - wxString m_className; - wxString m_appName, - m_vendorName; - wxWindow * m_topWindow; - bool m_exitOnFrameDelete; - bool m_showOnInit; - int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT - bool m_auto3D ; // Always use 3D controls, except - // where overriden - static wxAppInitializerFunction m_appInitFn; + bool m_showOnInit; public: + // Implementation + static bool Initialize(); + static void CleanUp(); - // Implementation - static bool Initialize(); - static void CleanUp(); - - void DeletePendingObjects(); - bool ProcessIdle(); + void DeletePendingObjects(); + bool ProcessIdle(); #if wxUSE_THREADS - void ProcessPendingEvents(); + void ProcessPendingEvents(); #endif - // Motif-specific - inline WXAppContext GetAppContext() const { return m_appContext; } - inline WXWidget GetTopLevelWidget() const { return m_topLevelWidget; } - WXColormap GetMainColormap(WXDisplay* display) ; - WXDisplay* GetInitialDisplay() const { return m_initialDisplay; } - inline long GetMaxRequestSize() const { return m_maxRequestSize; } + // Motif-specific + WXAppContext GetAppContext() const { return m_appContext; } + WXWidget GetTopLevelWidget() const { return m_topLevelWidget; } + WXColormap GetMainColormap(WXDisplay* display) ; + WXDisplay* GetInitialDisplay() const { return m_initialDisplay; } + long GetMaxRequestSize() const { return m_maxRequestSize; } - // This handler is called when a property change event occurs - virtual void HandlePropertyChange(WXEvent *event); + // This handler is called when a property change event occurs + virtual void HandlePropertyChange(WXEvent *event); public: - static long sm_lastMessageTime; - int m_nCmdShow; + static long sm_lastMessageTime; + int m_nCmdShow; protected: - bool m_keepGoing ; + bool m_keepGoing ; -// Motif-specific - WXAppContext m_appContext; - WXWidget m_topLevelWidget; - WXColormap m_mainColormap; - WXDisplay* m_initialDisplay; - long m_maxRequestSize; + // Motif-specific + WXAppContext m_appContext; + WXWidget m_topLevelWidget; + WXColormap m_mainColormap; + WXDisplay* m_initialDisplay; + long m_maxRequestSize; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; int WXDLLEXPORT wxEntry( int argc, char *argv[] ); diff --git a/include/wx/motif/menu.h b/include/wx/motif/menu.h index 22ddece86e..d3d4705654 100644 --- a/include/wx/motif/menu.h +++ b/include/wx/motif/menu.h @@ -6,7 +6,7 @@ // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_MENU_H_ @@ -36,8 +36,17 @@ class WXDLLEXPORT wxMenu: public wxEvtHandler public: // ctor & dtor - wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL); - ~wxMenu(); +#ifdef WXWIN_COMPATIBILITY + wxMenu( const wxString& title, const wxFunction func) + { + Init(title, 0, func); + } +#endif // WXWIN_COMPATIBILITY + wxMenu( const wxString& title = wxEmptyString, long style = 0 ) + { + Init(title, style); + } + virtual ~wxMenu(); // construct menu // append items to the menu @@ -47,7 +56,7 @@ public: void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString, bool checkable = FALSE); // a submenu - void Append(int id, const wxString& Label, wxMenu *SubMenu, + void Append(int id, const wxString& Label, wxMenu *SubMenu, const wxString& helpString = wxEmptyString); // the most generic form (create wxMenuItem first and use it's functions) void Append(wxMenuItem *pItem); @@ -59,14 +68,14 @@ public: // menu item control void Enable(int id, bool Flag); bool Enabled(int id) const; - inline bool IsEnabled(int id) const { return Enabled(id); }; + bool IsEnabled(int id) const { return Enabled(id); }; void Check(int id, bool Flag); bool Checked(int id) const; - inline bool IsChecked(int id) const { return IsChecked(id); }; + bool IsChecked(int id) const { return IsChecked(id); }; // Client data - inline void SetClientData(void* clientData) { m_clientData = clientData; } - inline void* GetClientData() const { return m_clientData; } + void SetClientData(void* clientData) { m_clientData = clientData; } + void* GetClientData() const { return m_clientData; } // item properties // title @@ -92,26 +101,29 @@ public: void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL); void ProcessCommand(wxCommandEvent& event); - inline void Callback(const wxFunction func) { m_callback = func; } + +#ifdef WXWIN_COMPATIBILITY + void Callback(const wxFunction func) { m_callback = func; } +#endif // WXWIN_COMPATIBILITY virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; } - inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } - inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } + void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } + wxEvtHandler *GetEventHandler() { return m_eventHandler; } - inline wxList& GetItems() const { return (wxList&) m_menuItems; } + wxList& GetItems() const { return (wxList&) m_menuItems; } void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; } wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; } //// Motif-specific - inline WXWidget GetButtonWidget() const { return m_buttonWidget; } - inline void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } - inline WXWidget GetMainWidget() const { return m_menuWidget; } - inline wxMenu* GetParent() const { return m_menuParent; } - inline int GetId() const { return m_menuId; } - inline void SetId(int id) { m_menuId = id; } - inline void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } - inline wxMenuBar* GetMenuBar() const { return m_menuBar; } + WXWidget GetButtonWidget() const { return m_buttonWidget; } + void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } + WXWidget GetMainWidget() const { return m_menuWidget; } + wxMenu* GetParent() const { return m_menuParent; } + int GetId() const { return m_menuId; } + void SetId(int id) { m_menuId = id; } + void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } + wxMenuBar* GetMenuBar() const { return m_menuBar; } void CreatePopup (WXWidget logicalParent, int x, int y); void DestroyPopup (void); @@ -135,8 +147,14 @@ public: void SetFont(const wxFont& colour); void ChangeFont(bool keepOriginalSize = FALSE); + // implementation from now on + WXWidget GetHandle() const { return m_menuWidget; } + bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; } + public: +#ifdef WXWIN_COMPATIBILITY wxFunction m_callback; +#endif // WXWIN_COMPATIBILITY int m_noItems; wxString m_title; @@ -147,6 +165,8 @@ public: void* m_clientData; wxWindow* m_pInvokingWindow; + long m_style; + //// Motif-specific int m_numColumns; WXWidget m_menuWidget; @@ -159,88 +179,99 @@ public: wxColour m_foregroundColour; wxColour m_backgroundColour; wxFont m_font; + +private: + // common code for both constructors: + void Init( const wxString& title, + long style +#ifdef WXWIN_COMPATIBILITY + , const wxFunction func = (wxFunction) NULL +#endif + ); }; // ---------------------------------------------------------------------------- // Menu Bar (a la Windows) // ---------------------------------------------------------------------------- + class WXDLLEXPORT wxFrame; -class WXDLLEXPORT wxMenuBar: public wxEvtHandler +class WXDLLEXPORT wxMenuBar : public wxEvtHandler { - DECLARE_DYNAMIC_CLASS(wxMenuBar) - - wxMenuBar( long style ); - wxMenuBar(); - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); - ~wxMenuBar(); - - void Append(wxMenu *menu, const wxString& title); - // Must only be used AFTER menu has been attached to frame, - // otherwise use individual menus to enable/disable items - void Enable(int Id, bool Flag); - bool Enabled(int Id) const ; - inline bool IsEnabled(int Id) const { return Enabled(Id); }; - void EnableTop(int pos, bool Flag); - void Check(int id, bool Flag); - bool Checked(int id) const ; - inline bool IsChecked(int Id) const { return Checked(Id); }; - void SetLabel(int id, const wxString& label) ; - wxString GetLabel(int id) const ; - void SetLabelTop(int pos, const wxString& label) ; - wxString GetLabelTop(int pos) const ; - virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */ - virtual bool OnAppend(wxMenu *menu, const char *title); - virtual bool OnDelete(wxMenu *menu, int index); - - virtual void SetHelpString(int Id, const wxString& helpString); - virtual wxString GetHelpString(int Id) const ; - - virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ; - - // Find wxMenuItem for item ID, and return item's - // menu too if itemMenu is non-NULL. - wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ; - - inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } - inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } - - inline int GetMenuCount() const { return m_menuCount; } - inline wxMenu* GetMenu(int i) const { return m_menus[i]; } - - //// Motif-specific - inline wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; } - inline void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; } - inline WXWidget GetMainWidget() const { return m_mainWidget; } - inline void SetMainWidget(WXWidget widget) { m_mainWidget = widget; } - - // Create menubar - bool CreateMenuBar(wxFrame* frame); +DECLARE_DYNAMIC_CLASS(wxMenuBar) - // Destroy menubar, but keep data structures intact so we can recreate it. - bool DestroyMenuBar(); - - const wxColour& GetBackgroundColour() const { return m_backgroundColour; } - const wxColour& GetForegroundColour() const { return m_foregroundColour; } - const wxFont& GetFont() const { return m_font; } - - void SetBackgroundColour(const wxColour& colour); - void SetForegroundColour(const wxColour& colour); - void SetFont(const wxFont& colour); - void ChangeFont(bool keepOriginalSize = FALSE); - - public: - wxEvtHandler * m_eventHandler; - int m_menuCount; - wxMenu ** m_menus; - wxString * m_titles; - wxFrame * m_menuBarFrame; - - //// Motif-specific - WXWidget m_mainWidget; +public: + wxMenuBar( long style ); + wxMenuBar(); + wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + ~wxMenuBar(); + + void Append(wxMenu *menu, const wxString& title); + // Must only be used AFTER menu has been attached to frame, + // otherwise use individual menus to enable/disable items + void Enable(int Id, bool Flag); + bool Enabled(int Id) const ; + bool IsEnabled(int Id) const { return Enabled(Id); }; + void EnableTop(int pos, bool Flag); + void Check(int id, bool Flag); + bool Checked(int id) const ; + bool IsChecked(int Id) const { return Checked(Id); }; + void SetLabel(int id, const wxString& label) ; + wxString GetLabel(int id) const ; + void SetLabelTop(int pos, const wxString& label) ; + wxString GetLabelTop(int pos) const ; + virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */ + virtual bool OnAppend(wxMenu *menu, const char *title); + virtual bool OnDelete(wxMenu *menu, int index); + + virtual void SetHelpString(int Id, const wxString& helpString); + virtual wxString GetHelpString(int Id) const ; + + virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ; + + // Find wxMenuItem for item ID, and return item's + // menu too if itemMenu is non-NULL. + wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ; + + void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } + wxEvtHandler *GetEventHandler() { return m_eventHandler; } + + int GetMenuCount() const { return m_menuCount; } + wxMenu* GetMenu(int i) const { return m_menus[i]; } + + //// Motif-specific + wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; } + void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; } + WXWidget GetMainWidget() const { return m_mainWidget; } + void SetMainWidget(WXWidget widget) { m_mainWidget = widget; } + + // Create menubar + bool CreateMenuBar(wxFrame* frame); + + // Destroy menubar, but keep data structures intact so we can recreate it. + bool DestroyMenuBar(); + + const wxColour& GetBackgroundColour() const { return m_backgroundColour; } + const wxColour& GetForegroundColour() const { return m_foregroundColour; } + const wxFont& GetFont() const { return m_font; } + + void SetBackgroundColour(const wxColour& colour); + void SetForegroundColour(const wxColour& colour); + void SetFont(const wxFont& colour); + void ChangeFont(bool keepOriginalSize = FALSE); - wxColour m_foregroundColour; - wxColour m_backgroundColour; - wxFont m_font; +public: + wxEvtHandler * m_eventHandler; + int m_menuCount; + wxMenu ** m_menus; + wxString * m_titles; + wxFrame * m_menuBarFrame; + + //// Motif-specific + WXWidget m_mainWidget; + + wxColour m_foregroundColour; + wxColour m_backgroundColour; + wxFont m_font; }; #endif // _WX_MENU_H_ diff --git a/include/wx/motif/msgdlg.h b/include/wx/motif/msgdlg.h index 4e8b790290..4275fa2874 100644 --- a/include/wx/motif/msgdlg.h +++ b/include/wx/motif/msgdlg.h @@ -7,7 +7,7 @@ // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_MSGBOXDLG_H_ @@ -20,31 +20,43 @@ #include "wx/setup.h" #include "wx/dialog.h" -/* - * Message box dialog - */ +// ---------------------------------------------------------------------------- +// Message box dialog +// ---------------------------------------------------------------------------- WXDLLEXPORT_DATA(extern const char*) wxMessageBoxCaptionStr; class WXDLLEXPORT wxMessageDialog: public wxDialog { -DECLARE_DYNAMIC_CLASS(wxMessageDialog) + DECLARE_DYNAMIC_CLASS(wxMessageDialog) + +public: + wxMessageDialog(wxWindow *parent, + const wxString& message, + const wxString& caption = wxMessageBoxCaptionStr, + long style = wxOK | wxCENTRE, + const wxPoint& pos = wxDefaultPosition); + + int ShowModal(); + + // implementation only from now on + // called by the Motif callback + void SetResult(long result) { m_result = result; } + protected: wxString m_caption; wxString m_message; long m_dialogStyle; wxWindow * m_parent; -public: - wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption = wxMessageBoxCaptionStr, - long style = wxOK|wxCENTRE, const wxPoint& pos = wxDefaultPosition); - - int ShowModal(); + long m_result; }; -int WXDLLEXPORT wxMessageBox(const wxString& message, const wxString& caption = wxMessageBoxCaptionStr, - long style = wxOK|wxCENTRE, - wxWindow *parent = NULL, int x = -1, int y = -1); +int WXDLLEXPORT wxMessageBox(const wxString& message, + const wxString& caption = wxMessageBoxCaptionStr, + long style = wxOK | wxCENTRE, + wxWindow *parent = NULL, + int x = -1, int y = -1); #endif // _WX_MSGBOXDLG_H_ diff --git a/include/wx/motif/private.h b/include/wx/motif/private.h index f8dbeba90d..f72bd63cd8 100644 --- a/include/wx/motif/private.h +++ b/include/wx/motif/private.h @@ -72,5 +72,37 @@ extern XColor itemColors[5] ; #define wxTOPS_INDEX 3 #define wxBOTS_INDEX 4 +// ---------------------------------------------------------------------------- +// utility classes +// ---------------------------------------------------------------------------- + +// XmString made easy to use in wxWindows (and has an added benefit of +// cleaning up automatically) +class wxXmString +{ +public: + wxXmString(const wxString& str) + { + m_string = XmStringCreateLtoR((char *)str.c_str(), + XmSTRING_DEFAULT_CHARSET); + } + + ~wxXmString() { XmStringFree(m_string); } + + // semi-implicit conversion to XmString (shouldn't rely on implicit + // conversion because many of Motif functions are macros) + XmString operator()() const { return m_string; } + +private: + XmString m_string; +}; + +// ---------------------------------------------------------------------------- +// macros to avoid casting WXFOO to Foo all the time +// ---------------------------------------------------------------------------- + +// argument is of type "wxWindow *" +#define GetWidget(w) ((Widget)(w)->GetHandle()) + #endif // _WX_PRIVATE_H_ diff --git a/include/wx/motif/window.h b/include/wx/motif/window.h index 90be6d7037..77b8625430 100644 --- a/include/wx/motif/window.h +++ b/include/wx/motif/window.h @@ -91,8 +91,6 @@ public: const wxFont *theFont = (const wxFont *) NULL) const; - virtual bool PopupMenu( wxMenu *menu, int x, int y ); - virtual void SetScrollbar( int orient, int pos, int thumbVisible, int range, bool refresh = TRUE ); virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ); @@ -319,6 +317,7 @@ protected: int width, int height, int sizeFlags = wxSIZE_AUTO); virtual void DoSetClientSize(int width, int height); + virtual bool DoPopupMenu(wxMenu *menu, int x, int y); #if wxUSE_TOOLTIPS virtual void DoSetToolTip( wxToolTip *tip ); diff --git a/include/wx/msw/app.h b/include/wx/msw/app.h index 2f1cf96ad2..ae15f3f359 100644 --- a/include/wx/msw/app.h +++ b/include/wx/msw/app.h @@ -16,8 +16,6 @@ #pragma interface "app.h" #endif -#include "wx/defs.h" -#include "wx/object.h" #include "wx/event.h" #include "wx/icon.h" @@ -27,14 +25,6 @@ class WXDLLEXPORT wxApp ; class WXDLLEXPORT wxKeyEvent; class WXDLLEXPORT wxLog; -WXDLLEXPORT_DATA(extern wxApp*) wxTheApp; - -// Force an exit from main loop -void WXDLLEXPORT wxExit(); - -// Yield to other apps/messages -bool WXDLLEXPORT wxYield(); - // Represents the application. Derive OnInit and declare // a new App object to start application class WXDLLEXPORT wxApp : public wxAppBase diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index 87122a4e3a..93536a6b4d 100644 --- a/samples/minimal/minimal.cpp +++ b/samples/minimal/minimal.cpp @@ -69,7 +69,6 @@ public: // event handlers (these functions should _not_ be virtual) void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - void OnTest(wxCommandEvent& event); void OnPaint(wxPaintEvent& event); @@ -88,10 +87,6 @@ enum // menu items Minimal_Quit = 1, Minimal_About, - Minimal_Test, - - // controls start here (the numbers are, of course, arbitrary) - Minimal_Text = 1000, }; // ---------------------------------------------------------------------------- @@ -104,10 +99,6 @@ enum BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Minimal_Quit, MyFrame::OnQuit) EVT_MENU(Minimal_About, MyFrame::OnAbout) - - EVT_MENU(Minimal_Test, MyFrame::OnTest) - - EVT_PAINT(MyFrame::OnPaint) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWindows to create @@ -158,7 +149,6 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF); menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); - menuFile->Append(Minimal_Test, "&Test...\tCtrl-T", "Test"); menuFile->AppendSeparator(); menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); @@ -202,71 +192,3 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxMessageBox(msg, "About Minimal", wxOK | wxICON_INFORMATION, this); } -struct Foo -{ - Foo(int n_) { n = n_; } - - int n; -}; - -WX_DECLARE_LIST(Foo, FooList); - -#include - -WX_DEFINE_LIST(FooList); - -int FooSort(const Foo **item1, const Foo **item2) -{ - return (*item2)->n - (*item1)->n; -} - -void ShowList(const FooList& list) -{ - wxString msg, str; - msg = "The list elements: ("; - for ( FooList::Node *node = list.GetFirst(); node; node = node->GetNext() ) - { - if ( !!str ) - msg += ", "; - str.Printf("%d", node->GetData()->n); - msg += str; - } - - msg += ')'; - - wxMessageBox(msg, "List contents", wxOK | wxICON_INFORMATION); -} - -void MyFrame::OnTest(wxCommandEvent& event) -{ - FooList list; - list.Append(new Foo(12)); - list.Append(new Foo(3)); - list.Append(new Foo(1)); - list.Append(new Foo(7)); - list.Append(new Foo(4)); - ShowList(list); - list.Sort(FooSort); - ShowList(list); -} - -void MyFrame::OnPaint(wxPaintEvent& event) -{ - wxPaintDC dc(this); - - wxMemoryDC dcMem; - wxSize size(GetClientSize()); - dcMem.SelectObject(wxBitmap(size.x, size.y, -1)); - - dcMem.SetBackground(wxBrush(wxColour(0, 0, 255), wxSOLID)); - dcMem.SetTextForeground(wxColour(0, 255, 0)); - dcMem.SetTextBackground(wxColour(0, 0, 0)); - dcMem.SetBackgroundMode(wxSOLID); - dcMem.Clear(); - dcMem.DrawText("Hello, wxWindows!", 10, 10); - - wxPoint ptOrig(0, 0); - dc.Blit(ptOrig, size, &dcMem, ptOrig); - - dcMem.SelectObject(wxNullBitmap); -} diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 73787e4089..f19bd1159c 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -569,8 +569,11 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEXT_TOOLTIPS_ENABLE, MyFrame::OnToggleTooltips) #endif // wxUSE_TOOLTIPS +#if wxUSE_CLIPBOARD EVT_MENU(TEXT_CLIPBOARD_PASTE, MyFrame::OnPasteFromClipboard) EVT_MENU(TEXT_CLIPBOARD_COPY, MyFrame::OnCopyToClipboard) +#endif // wxUSE_CLIPBOARD + EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText) EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry) diff --git a/src/motif/Makefile.am b/src/motif/Makefile.am index 5822878182..1e501e5d2d 100644 --- a/src/motif/Makefile.am +++ b/src/motif/Makefile.am @@ -12,7 +12,7 @@ SUFFIXES = .cpp .c DEFS = $(TOOLKIT_DEF) $(WXDEBUG_DEFINE) LIBS = $(GUILIBS) -VPATH = .:${srcdir}:${srcdir}/xmcombo:${srcdir}/../common:${srcdir}/../generic:${EXTRA_VPATH} +VPATH = .:${srcdir}:${srcdir}/xmcombo:${srcdir}/../common:${srcdir}/../generic:${srcdir}/../html:${EXTRA_VPATH} EXTRA_DIST = "${srcdir}/../common ${srcdir}/../generic ${srcdir}" diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 0ccb67f1dd..5ef52fda83 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -10,7 +10,8 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "app.h" + #pragma implementation "app.h" + #pragma implementation "appbase.h" #endif #include "wx/frame.h" @@ -77,7 +78,7 @@ bool wxApp::Initialize() wxClassInfo::InitializeClasses(); - // GL: I'm annoyed ... I don't know where to put this and I don't want to + // GL: I'm annoyed ... I don't know where to put this and I don't want to // create a module for that as it's part of the core. #if wxUSE_THREADS wxPendingEvents = new wxList(); @@ -261,7 +262,7 @@ int wxEntry( int argc, char *argv[] ) }; // Static member initialization -wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL; +wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; wxApp::wxApp() { @@ -272,9 +273,7 @@ wxApp::wxApp() m_appName = ""; argc = 0; argv = NULL; - m_printMode = wxPRINT_POSTSCRIPT; m_exitOnFrameDelete = TRUE; - m_auto3D = TRUE; m_mainColormap = (WXColormap) NULL; m_appContext = (WXAppContext) NULL; @@ -339,10 +338,24 @@ void wxApp::ProcessXEvent(WXEvent* _event) { XEvent* event = (XEvent*) _event; - if ((event->type == KeyPress) && CheckForAccelerator(_event)) + if (event->type == KeyPress) { - // Do nothing! We intercepted and processed the event as an accelerator. + if (CheckForAccelerator(_event)) + { + // Do nothing! We intercepted and processed the event as an + // accelerator. + return; + } + else if (CheckForKeyDown(_event)) + { + // We intercepted and processed the key down event return; + } + else + { + XtDispatchEvent(event); + return; + } } else if (event->type == PropertyNotify) { @@ -351,10 +364,10 @@ void wxApp::ProcessXEvent(WXEvent* _event) } else if (event->type == ResizeRequest) { - /* Terry Gitnick - 1/21/98 - * If resize event, don't resize until the last resize event for this - * window is recieved. Prevents flicker as windows are resized. - */ + /* Terry Gitnick - 1/21/98 + * If resize event, don't resize until the last resize event for this + * window is recieved. Prevents flicker as windows are resized. + */ Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()); Window win = event->xany.window; @@ -527,21 +540,6 @@ void wxApp::ProcessPendingEvents() } #endif // wxUSE_THREADS -wxLog* wxApp::CreateLogTarget() -{ - return new wxLogGui; -} - -wxWindow* wxApp::GetTopWindow() const -{ - if (m_topWindow) - return m_topWindow; - else if (wxTopLevelWindows.GetCount() > 0) - return wxTopLevelWindows.GetFirst()->GetData(); - else - return NULL; -} - // Create an application context bool wxApp::OnInitGui() { @@ -631,6 +629,37 @@ bool wxApp::CheckForAccelerator(WXEvent* event) return FALSE; } +bool wxApp::CheckForKeyDown(WXEvent* event) +{ + XEvent* xEvent = (XEvent*) event; + // VZ: this code doesn't work for me because it never finds the correct + // window. Also, if we go this way, we should generate KEY_UP and + // CHAR events as well, not only KEY_DOWN. +#if 0 + if (xEvent->xany.type == KeyPress) + { + Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), + xEvent->xany.window); + wxWindow* win = NULL; + + // Find the first wxWindow that corresponds to this event window + while (widget && !(win = wxGetWindowFromTable(widget))) + widget = XtParent(widget); + + if (!widget || !win) + return FALSE; + + wxKeyEvent keyEvent(wxEVT_KEY_DOWN); + wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent); + + win->ProcessEvent( keyEvent ); + return (keyEvent.GetSkipped() != TRUE); + } +#endif // 0 + + return FALSE; +} + void wxExit() { int retValue = 0; @@ -659,3 +688,32 @@ bool wxYield() return TRUE; } +// TODO use XmGetPixmap (?) to get the really standard icons! + +#include "wx/generic/info.xpm" +#include "wx/generic/error.xpm" +#include "wx/generic/question.xpm" +#include "wx/generic/warning.xpm" + +wxIcon +wxApp::GetStdIcon(int which) const +{ + switch(which) + { + case wxICON_INFORMATION: + return wxIcon(info_xpm); + + case wxICON_QUESTION: + return wxIcon(question_xpm); + + case wxICON_EXCLAMATION: + return wxIcon(warning_xpm); + + default: + wxFAIL_MSG("requested non existent standard icon"); + // still fall through + + case wxICON_HAND: + return wxIcon(error_xpm); + } +} diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 5dcec13e48..c02f30d72a 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -58,7 +58,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) // Menus // Construct a menu with optional title (then use append) -wxMenu::wxMenu(const wxString& title, const wxFunction func) +void wxMenu::Init(const wxString& title, + long style +#ifdef WXWIN_COMPATIBILITY + , const wxFunction func +#endif + ) { m_title = title; m_parent = (wxEvtHandler*) NULL; @@ -66,6 +71,7 @@ wxMenu::wxMenu(const wxString& title, const wxFunction func) m_noItems = 0; m_menuBar = NULL; m_pInvokingWindow = NULL; + m_style = style; //// Motif-specific members m_numColumns = 1; @@ -87,7 +93,9 @@ wxMenu::wxMenu(const wxString& title, const wxFunction func) m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT); m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); +#ifdef WXWIN_COMPATIBILITY Callback(func); +#endif } // The wxWindow destructor will take care of deleting the submenus. @@ -426,72 +434,6 @@ void wxMenu::UpdateUI(wxEvtHandler* source) } } -bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) -{ - Widget widget = (Widget) GetMainWidget(); - - /* The menuId field seems to be usused, so we'll use it to - indicate whether a menu is popped up or not: - 0: Not currently created as a popup - -1: Created as a popup, but not active - 1: Active popup. - */ - - if (menu->GetParent() && (menu->GetId() != -1)) - return FALSE; - - if (menu->GetMainWidget()) { - menu->DestroyMenu(TRUE); - } - - menu->SetId(1); /* Mark as popped-up */ - menu->CreateMenu(NULL, widget, menu); - menu->SetInvokingWindow(this); - - menu->UpdateUI(); - - // menu->SetParent(parent); - // parent->children->Append(menu); // Store menu for later deletion - - Widget menuWidget = (Widget) menu->GetMainWidget(); - - int rootX = 0; - int rootY = 0; - - int deviceX = x; - int deviceY = y; - /* - if (this->IsKindOf(CLASSINFO(wxCanvas))) - { - wxCanvas *canvas = (wxCanvas *) this; - deviceX = canvas->GetDC ()->LogicalToDeviceX (x); - deviceY = canvas->GetDC ()->LogicalToDeviceY (y); - } - */ - - Display *display = XtDisplay (widget); - Window rootWindow = RootWindowOfScreen (XtScreen((Widget)widget)); - Window thisWindow = XtWindow (widget); - Window childWindow; - XTranslateCoordinates (display, thisWindow, rootWindow, (int) deviceX, (int) deviceY, - &rootX, &rootY, &childWindow); - - XButtonPressedEvent event; - event.type = ButtonPress; - event.button = 1; - - event.x = deviceX; - event.y = deviceY; - - event.x_root = rootX; - event.y_root = rootY; - - XmMenuPosition (menuWidget, &event); - XtManageChild (menuWidget); - - return TRUE; -} - // Menu Bar wxMenuBar::wxMenuBar() { @@ -836,13 +778,20 @@ bool wxMenuBar::CreateMenuBar(wxFrame* parent) wxString title(m_titles[i]); menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE)); - /* - * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU - */ wxStripMenuCodes ((char*) (const char*) title, wxBuffer); if (strcmp (wxBuffer, "Help") == 0) XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL); + + // tear off menu support +#if (XmVersion >= 1002) + if ( menu->IsTearOff() ) + { + XtVaSetValues(GetWidget(menu), + XmNtearOffModel, XmTEAR_OFF_ENABLED, + NULL); +#endif + } } SetBackgroundColour(m_backgroundColour); diff --git a/src/motif/msgdlg.cpp b/src/motif/msgdlg.cpp index 2c4a2369e1..b2f5d743c7 100644 --- a/src/motif/msgdlg.cpp +++ b/src/motif/msgdlg.cpp @@ -6,21 +6,87 @@ // Created: 04/01/98 // RCS-ID: $$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + #ifdef __GNUG__ -#pragma implementation "msgdlg.h" + #pragma implementation "msgdlg.h" #endif +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include + +#include +#include + +#include "wx/app.h" +#include "wx/intl.h" #include "wx/motif/msgdlg.h" +#include "wx/motif/private.h" + +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- #if !USE_SHARED_LIBRARY -IMPLEMENT_CLASS(wxMessageDialog, wxDialog) + IMPLEMENT_CLASS(wxMessageDialog, wxDialog) #endif -wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption, - long style, const wxPoint& pos) +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// the callbacks for message box buttons +// ---------------------------------------------------------------------------- + +// the common part +static void msgboxCallBack(Widget w, int client_data, int id) +{ + // close the dialog + XtUnmanageChild(w); + + wxMessageDialog *dlg = (wxMessageDialog *)client_data; + dlg->SetResult(id); +} + +static void msgboxCallBackOk(Widget w, + int client_data, + XmAnyCallbackStruct *call_data) +{ + msgboxCallBack(w, client_data, wxID_OK); +} + +static void msgboxCallBackCancel(Widget w, + int client_data, + XmAnyCallbackStruct *call_data) +{ + msgboxCallBack(w, client_data, wxID_CANCEL); +} + +static void msgboxCallBackClose(Widget w, + int client_data, + XmAnyCallbackStruct *call_data) +{ + msgboxCallBack(w, client_data, wxID_CANCEL); +} + +// ---------------------------------------------------------------------------- +// wxMessageDialog +// ---------------------------------------------------------------------------- + +wxMessageDialog::wxMessageDialog(wxWindow *parent, + const wxString& message, + const wxString& caption, + long style, + const wxPoint& pos) { m_caption = caption; m_message = message; @@ -30,7 +96,119 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, cons int wxMessageDialog::ShowModal() { - // TODO - return wxID_CANCEL; + Widget (*dialogCreateFunction)(Widget, String, ArgList, Cardinal) = NULL; + if ( m_dialogStyle & wxYES_NO ) + { + // if we have [Yes], it must be a question + dialogCreateFunction = XmCreateQuestionDialog; + + // TODO we could support this by using the help button... + wxASSERT_MSG( !(m_dialogStyle & wxCANCEL), "not supported" ); + } + else if ( m_dialogStyle & wxICON_STOP ) + { + // error dialog is the one with error icon... + dialogCreateFunction = XmCreateErrorDialog; + } + else if ( m_dialogStyle & wxICON_EXCLAMATION ) + { + // ...and the warning dialog too + dialogCreateFunction = XmCreateWarningDialog; + } + else + { + // finally, use the info dialog by default + dialogCreateFunction = XmCreateInformationDialog; + } + + // prepare the arg list + Arg args[2]; + int ac = 0; + + wxXmString text(m_message); + wxXmString title(m_caption); + XtSetArg(args[ac], XmNmessageString, text()); ac++; + XtSetArg(args[ac], XmNdialogTitle, title()); ac++; + + // do create message box + Widget wParent = m_parent ? GetWidget(m_parent) : NULL; + if ( !wParent ) + { + wxWindow *window = wxTheApp->GetTopWindow(); + if ( !window ) + { + wxFAIL_MSG("can't show message box without parent window"); + + return wxID_CANCEL; + } + + wParent = GetWidget(window); + } + + Widget wMsgBox = (*dialogCreateFunction)(wParent, "", args, ac); + + wxCHECK_MSG( wMsgBox, wxID_CANCEL, "msg box creation failed" ); + + // remove the [Help] button which wouldn't do anything anyhow + XtUnmanageChild(XmMessageBoxGetChild(wMsgBox, XmDIALOG_HELP_BUTTON)); + + // and the [Cancel] button too if we were not asked for it + if ( !(m_dialogStyle & wxCANCEL) ) + { + Widget wBtnCancel = XmMessageBoxGetChild(wMsgBox, + XmDIALOG_CANCEL_BUTTON); + + // ... unless it's a wxYES_NO dialog in which case we just rename + // [Cancel] to [No] instead + if ( m_dialogStyle & wxYES_NO ) + { + Widget wBtnOk = XmMessageBoxGetChild(wMsgBox, + XmDIALOG_OK_BUTTON); + + wxXmString yes(_("Yes")), no(_("No")); + XtVaSetValues(wBtnOk, XmNlabelString, yes(), NULL); + XtVaSetValues(wBtnCancel, XmNlabelString, no(), NULL); + } + else + { + XtUnmanageChild(wBtnCancel); + } + } + + // set the callbacks for the message box buttons + XtAddCallback(wMsgBox, XmNokCallback, + (XtCallbackProc)msgboxCallBackOk, (XtPointer)this); + XtAddCallback(wMsgBox, XmNcancelCallback, + (XtCallbackProc)msgboxCallBackCancel, (XtPointer)this); + + XtAddCallback(wMsgBox, XmNunmapCallback, + (XtCallbackProc)msgboxCallBackClose, (XtPointer)this); + + // show it as a modal dialog + XtManageChild(wMsgBox); + XtAddGrab(wMsgBox, True, False); + + // the m_result will be changed when message box goes away + m_result = -1; + + // local message loop + XtAppContext context = XtWidgetToApplicationContext(wParent); + XEvent event; + while ( m_result == -1 ) + { + XtAppNextEvent(context, &event); + XtDispatchEvent(&event); + } + + // translate the result if necessary + if ( m_dialogStyle & wxYES_NO ) + { + if ( m_result == wxID_OK ) + m_result = wxID_YES; + else if ( m_result == wxID_CANCEL ) + m_result = wxID_NO; + } + + return m_result; } diff --git a/src/motif/window.cpp b/src/motif/window.cpp index c8537834bf..87a3090c26 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -53,6 +53,7 @@ #include #include #include +#include // for XmMenuPosition #include "wx/motif/private.h" @@ -369,6 +370,9 @@ wxWindow::~wxWindow() ClearUpdateRects(); + if ( m_parent ) + m_parent->RemoveChild( this ); + // If m_drawingArea, we're a fully-fledged window with drawing area, // scrollbars etc. (what wxCanvas used to be) if ( m_drawingArea ) @@ -1040,6 +1044,76 @@ void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) #endif // wxUSE_TOOLTIPS +// ---------------------------------------------------------------------------- +// popup menus +// ---------------------------------------------------------------------------- + +bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) +{ + Widget widget = (Widget) GetMainWidget(); + + /* The menuId field seems to be usused, so we'll use it to + indicate whether a menu is popped up or not: + 0: Not currently created as a popup + -1: Created as a popup, but not active + 1: Active popup. + */ + + if (menu->GetParent() && (menu->GetId() != -1)) + return FALSE; + + if (menu->GetMainWidget()) { + menu->DestroyMenu(TRUE); + } + + menu->SetId(1); /* Mark as popped-up */ + menu->CreateMenu(NULL, widget, menu); + menu->SetInvokingWindow(this); + + menu->UpdateUI(); + + // menu->SetParent(parent); + // parent->children->Append(menu); // Store menu for later deletion + + Widget menuWidget = (Widget) menu->GetMainWidget(); + + int rootX = 0; + int rootY = 0; + + int deviceX = x; + int deviceY = y; + /* + if (this->IsKindOf(CLASSINFO(wxCanvas))) + { + wxCanvas *canvas = (wxCanvas *) this; + deviceX = canvas->GetDC ()->LogicalToDeviceX (x); + deviceY = canvas->GetDC ()->LogicalToDeviceY (y); + } + */ + + Display *display = XtDisplay (widget); + Window rootWindow = RootWindowOfScreen (XtScreen((Widget)widget)); + Window thisWindow = XtWindow (widget); + Window childWindow; + XTranslateCoordinates (display, thisWindow, rootWindow, (int) deviceX, (int) deviceY, + &rootX, &rootY, &childWindow); + + XButtonPressedEvent event; + event.type = ButtonPress; + event.button = 1; + + event.x = deviceX; + event.y = deviceY; + + event.x_root = rootX; + event.y_root = rootY; + + XmMenuPosition (menuWidget, &event); + XtManageChild (menuWidget); + + return TRUE; +} + // --------------------------------------------------------------------------- // moving and resizing // --------------------------------------------------------------------------- -- 2.47.2