From e75491071dbefcada61175e3eb89ce4edf335983 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 9 Nov 1999 15:24:52 +0000 Subject: [PATCH] mac adaptions git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4458 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cmndata.h | 15 + include/wx/dataobj.h | 4 +- include/wx/db.h | 12 +- include/wx/dcprint.h | 3 + include/wx/filefn.h | 9 +- include/wx/mac/button.h | 4 + include/wx/mac/clipbrd.h | 124 ++-- include/wx/mac/colour.h | 2 +- include/wx/mac/control.h | 37 +- include/wx/mac/dialog.h | 170 +++-- include/wx/mac/font.h | 66 +- include/wx/mac/frame.h | 8 +- include/wx/mac/icon.h | 2 + include/wx/mac/listbox.h | 193 +++--- include/wx/mac/menu.h | 307 +++++---- include/wx/mac/print.h | 44 +- include/wx/mac/printdlg.h | 17 +- include/wx/mac/setup.h | 242 +++++-- include/wx/mac/spinbutt.h | 97 ++- include/wx/mac/window.h | 65 +- include/wx/notebook.h | 2 +- include/wx/os2/dataform.h | 6 +- include/wx/os2/dataobj.h | 10 +- include/wx/print.h | 11 + include/wx/thread.h | 17 +- src/common/db.cpp | 13 + src/common/dbtable.cpp | 12 + src/common/filefn.cpp | 235 ++++--- src/mac/app.cpp | 4 +- src/mac/button.cpp | 19 +- src/mac/carbon/app.cpp | 4 +- src/mac/carbon/button.cpp | 19 +- src/mac/carbon/clipbrd.cpp | 168 ++++- src/mac/carbon/control.cpp | 146 ++--- src/mac/carbon/dialog.cpp | 199 ++---- src/mac/carbon/font.cpp | 185 +++--- src/mac/carbon/frame.cpp | 5 +- src/mac/carbon/listbox.cpp | 202 +++--- src/mac/carbon/mdi.cpp | 23 +- src/mac/carbon/menu.cpp | 820 +++++++++++------------ src/mac/carbon/menuitem.cpp | 74 ++- src/mac/carbon/print.cpp | 82 --- src/mac/carbon/printdlg.cpp | 35 +- src/mac/carbon/radiobox.cpp | 34 +- src/mac/carbon/spinbutt.cpp | 25 +- src/mac/carbon/stattext.cpp | 2 +- src/mac/carbon/textctrl.cpp | 68 +- src/mac/carbon/thread.cpp | 806 ++++++++++++++++++++--- src/mac/carbon/window.cpp | 1237 ++++++----------------------------- src/mac/clipbrd.cpp | 168 ++++- src/mac/control.cpp | 146 ++--- src/mac/dialog.cpp | 199 ++---- src/mac/font.cpp | 185 +++--- src/mac/frame.cpp | 5 +- src/mac/listbox.cpp | 202 +++--- src/mac/mdi.cpp | 23 +- src/mac/menu.cpp | 820 +++++++++++------------ src/mac/menuitem.cpp | 74 ++- src/mac/print.cpp | 82 --- src/mac/printdlg.cpp | 35 +- src/mac/radiobox.cpp | 34 +- src/mac/spinbutt.cpp | 25 +- src/mac/stattext.cpp | 2 +- src/mac/textctrl.cpp | 68 +- src/mac/thread.cpp | 806 ++++++++++++++++++++--- src/mac/window.cpp | 1237 ++++++----------------------------- 66 files changed, 4789 insertions(+), 5206 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index 408d3827b1..2745dcb0aa 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -176,11 +176,16 @@ class WXDLLEXPORT wxPrintData: public wxObject void ConvertFromNative(); void* GetNativeData() const { return m_devMode; } void SetNativeData(void* data) { m_devMode = data; } +#elif defined( __WXMAC__) + void ConvertToNative(); + void ConvertFromNative(); #endif public: #ifdef __WXMSW__ void* m_devMode; +#elif defined( __WXMAC__ ) + THPrint m_macPrintInfo ; #endif private: @@ -270,10 +275,15 @@ class WXDLLEXPORT wxPrintDialogData: public wxObject void ConvertFromNative(); void SetOwnerWindow(wxWindow* win); void* GetNativeData() const { return m_printDlgData; } +#elif defined( __WXMAC__) + void ConvertToNative(); + void ConvertFromNative(); #endif #ifdef __WXMSW__ void* m_printDlgData; +#elif defined( __WXMAC__ ) + THPrint m_macPrintInfo ; #endif private: @@ -356,6 +366,9 @@ public: void ConvertFromNative(); void SetOwnerWindow(wxWindow* win); void* GetNativeData() const { return m_pageSetupData; } +#elif defined( __WXMAC__) + void ConvertToNative(); + void ConvertFromNative(); #endif // Use paper size defined in this object to set the wxPrintData @@ -373,6 +386,8 @@ public: #if defined(__WIN95__) void* m_pageSetupData; +#elif defined( __WXMAC__ ) + THPrint m_macPageSetupInfo ; #endif private: diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index a0c06370bc..f12dbe67d6 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -79,6 +79,8 @@ public: #include "wx/motif/dataform.h" #elif defined(__WXGTK__) #include "wx/gtk/dataform.h" +#elif defined(__WXMAC__) + #include "wx/mac/dataform.h" #elif defined(__WXPM__) #include "wx/os2/dataform.h" #endif @@ -159,7 +161,7 @@ public: #elif defined(__WXQT__) #include "wx/qt/dnd.h" #elif defined(__WXMAC__) - #include "wx/mac/dnd.h" + #include "wx/mac/dataobj.h" #elif defined(__WXPM__) #include "wx/os2/dataobj.h" #elif defined(__WXSTUBS__) diff --git a/include/wx/db.h b/include/wx/db.h index 2d39f12b9c..4faa42317d 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -69,19 +69,29 @@ typedef double SDOUBLE; typedef unsigned int UINT; #define ULONG UDWORD +#elif defined(__WXMAC__) + extern "C" { + #include "../../src/iodbc/isql.h" + #include "../../src/iodbc/isqlext.h" + } + typedef float SFLOAT; + typedef double SDOUBLE; + typedef unsigned int UINT; + #define ULONG UDWORD #else // msw #define ODBCVER 0x0250 #include #include #endif -#ifdef __UNIX__ +#ifdef __UNIX__ # ifndef strnicmp # define strnicmp strncasecmp # endif # ifndef stricmp # define stricmp strcasecmp # endif +#elif defined(__WXMAC__) #else # include #endif diff --git a/include/wx/dcprint.h b/include/wx/dcprint.h index 37ebb5469c..040f8dc390 100644 --- a/include/wx/dcprint.h +++ b/include/wx/dcprint.h @@ -7,6 +7,9 @@ #if defined(__WXPM__) #include "wx/os2/dcprint.h" #endif +#if defined(__WXMAC__) +#include "wx/mac/dcprint.h" +#endif #endif // _WX_DCPRINT_H_BASE_ diff --git a/include/wx/filefn.h b/include/wx/filefn.h index 91bc0c1fa8..c2e21609ad 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -84,9 +84,12 @@ WXDLLEXPORT void wxUnix2DosFilename(wxChar *s); #define Unix2DosFilename wxUnix2DosFilename #ifdef __WXMAC__ - WXDLLEXPORT void wxMacPathToFSSpec( const wxChar *path , FSSpec *spec ) ; - WXDLLEXPORT void wxMac2UnixFilename(wxChar *s); - WXDLLEXPORT void wxUnix2MacFilename(wxChar *s); + WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ; + WXDLLEXPORT wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) ; + WXDLLEXPORT void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) ; + WXDLLEXPORT void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) ; + WXDLLEXPORT wxString wxMac2UnixFilename( const char *s) ; + WXDLLEXPORT wxString wxUnix2MacFilename( const char *s); #endif // Strip the extension, in situ diff --git a/include/wx/mac/button.h b/include/wx/mac/button.h index 3f4d688452..d581f9a97b 100644 --- a/include/wx/mac/button.h +++ b/include/wx/mac/button.h @@ -43,8 +43,12 @@ class WXDLLEXPORT wxButton: public wxControl const wxString& name = wxButtonNameStr); virtual void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; + static wxSize GetDefaultSize(); + virtual void SetDefault(); virtual void Command(wxCommandEvent& event); +protected: + virtual wxSize DoGetBestSize(); }; #endif diff --git a/include/wx/mac/clipbrd.h b/include/wx/mac/clipbrd.h index 4d3658ed3c..0c9bee6acf 100644 --- a/include/wx/mac/clipbrd.h +++ b/include/wx/mac/clipbrd.h @@ -19,75 +19,87 @@ #pragma interface "clipbrd.h" #endif -#include "wx/defs.h" -#include "wx/setup.h" +#if wxUSE_CLIPBOARD #include "wx/list.h" - -/* A clipboard client holds data belonging to the clipboard. - For plain text, a client is not necessary. */ -class WXDLLEXPORT wxClipboardClient : public wxObject -{ - DECLARE_ABSTRACT_CLASS(wxClipboardClient) - - public: - /* This list should be filled in with strings indicating the formats - this client can provide. Almost all clients will provide "TEXT". - Format names should be 4 characters long, so things will work - out on the Macintosh */ - wxStringList formats; - - /* This method is called when the client is losing the selection. */ - virtual void BeingReplaced() = 0; - - /* This method is called when someone wants the data this client is - supplying to the clipboard. "format" is a string indicating the - format of the data - one of the strings from the "formats" - list. "*size" should be filled with the size of the resulting - data. In the case of text, "*size" does not count the - NULL terminator. */ - virtual char *GetData(char *format, long *size) = 0; -}; - -/* ONE instance of this class: */ +#include "wx/module.h" +#include "wx/dataobj.h" // for wxDataFormat + +// These functions superceded by wxClipboard, but retained in order to +// implement wxClipboard, and for compatibility. + +// open/close the clipboard +WXDLLEXPORT bool wxOpenClipboard(); +WXDLLEXPORT bool wxIsClipboardOpened(); +#define wxClipboardOpen wxIsClipboardOpened +WXDLLEXPORT bool wxCloseClipboard(); + +// get/set data +WXDLLEXPORT bool wxEmptyClipboard(); +WXDLLEXPORT bool wxSetClipboardData(wxDataFormat dataFormat, + const void *data, + int width = 0, int height = 0); +WXDLLEXPORT void* wxGetClipboardData(wxDataFormat dataFormat, + long *len = NULL); + +// clipboard formats +WXDLLEXPORT bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat); +WXDLLEXPORT wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat); +WXDLLEXPORT int wxRegisterClipboardFormat(wxChar *formatName); +WXDLLEXPORT bool wxGetClipboardFormatName(wxDataFormat dataFormat, + wxChar *formatName, + int maxCount); + +//----------------------------------------------------------------------------- +// wxClipboard +//----------------------------------------------------------------------------- + +class WXDLLEXPORT wxDataObject; class WXDLLEXPORT wxClipboard : public wxObject { - DECLARE_DYNAMIC_CLASS(wxClipboard) + DECLARE_DYNAMIC_CLASS(wxClipboard) - public: - wxClipboardClient *clipOwner; - char *cbString, *sentString, *receivedString; - void *receivedTargets; - long receivedLength; +public: + wxClipboard(); + ~wxClipboard(); - wxClipboard(); - ~wxClipboard(); + // open the clipboard before SetData() and GetData() + virtual bool Open(); - /* Set the clipboard data owner. "time" comes from the event record. */ - void SetClipboardClient(wxClipboardClient *, long time); + // close the clipboard after SetData() and GetData() + virtual void Close(); - /* Set the clipboard string; does not require a client. */ - void SetClipboardString(char *, long time); + // query whether the clipboard is opened + virtual bool IsOpened() const; - /* Get data from the clipboard in the format "TEXT". */ - char *GetClipboardString(long time); + // set the clipboard data. all other formats will be deleted. + virtual bool SetData( wxDataObject *data ); - /* Get data from the clipboard */ - char *GetClipboardData(char *format, long *length, long time); + // add to the clipboard data. + virtual bool AddData( wxDataObject *data ); - /* Get the clipboard client directly. Will be NULL if clipboard data - is a string, or if some other application owns the clipboard. - This can be useful for shortcutting data translation, if the - clipboard user can check for a specific client. (This is used - by the wxMediaEdit class.) */ - wxClipboardClient *GetClipboardClient(); -}; + // ask if data in correct format is available + virtual bool IsSupported( wxDataFormat format ); -/* Initialize wxTheClipboard. Can be called repeatedly */ -void WXDLLEXPORT wxInitClipboard(); + // fill data with data on the clipboard (if available) + virtual bool GetData( wxDataObject& data ); + + // clears wxTheClipboard and the system's clipboard if possible + virtual void Clear(); + + // flushes the clipboard: this means that the data which is currently on + // clipboard will stay available even after the application exits (possibly + // eating memory), otherwise the clipboard will be emptied on exit + virtual bool Flush(); + + // X11 has two clipboards which get selected by this call. Empty on MSW. + void UsePrimarySelection( bool WXUNUSED(primary) = FALSE ) { } + +private: + bool m_clearOnExit; +}; -/* The clipboard */ -WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard; +#endif // wxUSE_CLIPBOARD #endif // _WX_CLIPBRD_H_ diff --git a/include/wx/mac/colour.h b/include/wx/mac/colour.h index 407c0140ca..d9f82e8eb1 100644 --- a/include/wx/mac/colour.h +++ b/include/wx/mac/colour.h @@ -64,7 +64,7 @@ public: unsigned char Blue() const { return m_blue; } // comparison - bool operator == (const wxColour& colour) + bool operator == (const wxColour& colour) const { return (m_red == colour.m_red && m_green == colour.m_green && diff --git a/include/wx/mac/control.h b/include/wx/mac/control.h index 7d8f6d185d..6f7c964c95 100644 --- a/include/wx/mac/control.h +++ b/include/wx/mac/control.h @@ -33,12 +33,36 @@ public: // Calls the callback and appropriate event handlers bool ProcessCommand(wxCommandEvent& event); - + virtual void SetLabel(const wxString& title) ; wxList& GetSubcontrols() { return m_subControls; } void OnEraseBackground(wxEraseEvent& event); + virtual bool Enable(bool enabled) ; + virtual bool Show(bool show) ; + + virtual void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; + virtual void MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name , Rect *outBounds , StringPtr maclabel ) ; + virtual void MacPostControlCreate() ; + virtual void MacAdjustControlRect() ; + virtual ControlHandle MacGetContainerForEmbedding() ; + virtual void MacSuperChangedPosition() ; + virtual void MacSuperEnabled( bool enabled ) ; + virtual void MacSuperShown( bool show ) ; + virtual bool MacCanFocus() const ; + + void DoSetSize(int x, int y,int width, int height,int sizeFlags ) ; + virtual void OnKeyDown( wxKeyEvent &event ) ; + virtual void OnMouseEvent( wxMouseEvent &event ) ; + virtual void OnPaint(wxPaintEvent& event) ; + virtual void Refresh(bool eraseBack = TRUE, const wxRect *rect = NULL) ; + ControlHandle GetMacControl() { return m_macControl ;} + #if WXWIN_COMPATIBILITY virtual void SetButtonColour(const wxColour& WXUNUSED(col)) { } wxColour* GetButtonColour() const { return NULL; } @@ -59,18 +83,13 @@ protected: protected: // For controls like radiobuttons which are really composite + ControlHandle m_macControl ; + int m_macHorizontalBorder ; + int m_macVerticalBorder ; wxList m_subControls; virtual wxSize DoGetBestSize(); - // create the control of the given class with the given style, returns FALSE - // if creation failed - bool MSWCreateControl(const wxChar *classname, WXDWORD style); - - // determine the extended styles combination for this window (may slightly - // modify styl parameter) - WXDWORD GetExStyle(WXDWORD& style) const; - private: DECLARE_EVENT_TABLE() }; diff --git a/include/wx/mac/dialog.h b/include/wx/mac/dialog.h index 0b595e9c9d..1aa01b36f0 100644 --- a/include/wx/mac/dialog.h +++ b/include/wx/mac/dialog.h @@ -20,79 +20,111 @@ WXDLLEXPORT_DATA(extern const char*) wxDialogNameStr; +WXDLLEXPORT_DATA(extern const wxChar*) wxDialogNameStr; + +class WXDLLEXPORT wxMacToolTip ; + // Dialog boxes -class WXDLLEXPORT wxDialog: public wxPanel +class WXDLLEXPORT wxDialog : public wxDialogBase { - DECLARE_DYNAMIC_CLASS(wxDialog) + DECLARE_DYNAMIC_CLASS(wxDialog) + public: + wxDialog(); + + // Constructor with a modal flag, but no window id - the old convention + wxDialog(wxWindow *parent, + const wxString& title, bool modal, + int x = -1, int y= -1, int width = 500, int height = 500, + long style = wxDEFAULT_DIALOG_STYLE, + const wxString& name = wxDialogNameStr) + { + long modalStyle = modal ? wxDIALOG_MODAL : wxDIALOG_MODELESS ; + Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), + style | modalStyle, name); + } + + // Constructor with no modal flag - the new convention. + wxDialog(wxWindow *parent, wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_DIALOG_STYLE, + const wxString& name = wxDialogNameStr) + { + Create(parent, id, title, pos, size, style, name); + } + + bool Create(wxWindow *parent, wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_DIALOG_STYLE, + const wxString& name = wxDialogNameStr); + + ~wxDialog(); + + virtual bool Destroy(); + + virtual void DoSetClientSize(int width, int height); + + virtual void GetPosition(int *x, int *y) const; + + bool Show(bool show); + bool IsShown() const; + void Iconize(bool iconize); + +#if WXWIN_COMPATIBILITY + bool Iconized() const { return IsIconized(); }; +#endif + + virtual bool IsIconized() const; + void Fit(); + + void SetTitle(const wxString& title); + wxString GetTitle() const ; + + void OnSize(wxSizeEvent& event); + bool OnClose(); + void OnCharHook(wxKeyEvent& event); + void OnPaint(wxPaintEvent& event); + void OnCloseWindow(wxCloseEvent& event); + + void SetModal(bool flag); + + virtual void Centre(int direction = wxBOTH); + virtual bool IsModal() const; + + // For now, same as Show(TRUE) but returns return code + virtual int ShowModal(); + virtual void EndModal(int retCode); + + // Standard buttons + void OnOK(wxCommandEvent& event); + void OnApply(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + + // Responds to colour changes + void OnSysColourChanged(wxSysColourChangedEvent& event); + + // implementation + // -------------- + + bool IsModalShowing() const { return m_modalShowing; } + + // tooltip management +#if wxUSE_TOOLTIPS + wxMacToolTip* GetToolTipCtrl() const { return m_hwndToolTip; } + void SetToolTipCtrl(wxMacToolTip *tt) { m_hwndToolTip = tt; } + wxMacToolTip* m_hwndToolTip ; +#endif // tooltips + +protected: + bool m_modalShowing; + WXHWND m_hwndOldFocus; // the window which had focus before we were shown - wxDialog(); - - // Constructor with a modal flag, but no window id - the old convention - inline wxDialog(wxWindow *parent, - const wxString& title, bool modal, - int x = -1, int y= -1, int width = 500, int height = 500, - long style = wxDEFAULT_DIALOG_STYLE, - const wxString& name = wxDialogNameStr) - { - long modalStyle = modal ? wxDIALOG_MODAL : wxDIALOG_MODELESS ; - Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), style|modalStyle, name); - } - - // Constructor with no modal flag - the new convention. - inline wxDialog(wxWindow *parent, wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_DIALOG_STYLE, - const wxString& name = wxDialogNameStr) - { - Create(parent, id, title, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID id, - const wxString& title, // bool modal = FALSE, // TODO make this a window style? - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_DIALOG_STYLE, - const wxString& name = wxDialogNameStr); - - ~wxDialog(); - - virtual bool Destroy(); - bool Show(bool show); - void Fit(); - - void Iconize(bool iconize); - - virtual bool IsIconized() const; - void OnCharHook(wxKeyEvent& event); - void OnCloseWindow(wxCloseEvent& event); - - void SetModal(bool flag); - - virtual bool IsModal() const { return ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL); } - - virtual int ShowModal(); - virtual void EndModal(int retCode); - - // Standard buttons - void OnOK(wxCommandEvent& event); - void OnApply(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); - - void OnSize(wxSizeEvent& event) ; - // Responds to colour changes - void OnSysColourChanged(wxSysColourChangedEvent& event); - - // splits text up at newlines and places the - // lines into a vertical wxBoxSizer - wxSizer *CreateTextSizer( const wxString &message ); - - // places buttons into a horizontal wxBoxSizer - wxSizer *CreateButtonSizer( long flags ); - -DECLARE_EVENT_TABLE() +private: + DECLARE_EVENT_TABLE() }; #endif diff --git a/include/wx/mac/font.h b/include/wx/mac/font.h index f7596f241b..1dd3f3da7c 100644 --- a/include/wx/mac/font.h +++ b/include/wx/mac/font.h @@ -16,15 +16,66 @@ #pragma interface "font.h" #endif -// ---------------------------------------------------------------------------- -// public functions -// ---------------------------------------------------------------------------- +class WXDLLEXPORT wxFontRefData: public wxGDIRefData +{ + friend class WXDLLEXPORT wxFont; +public: + wxFontRefData() + { + Init(12, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, + "", wxFONTENCODING_DEFAULT); + } -// convert wxFontEncoding into one of Windows XXX_CHARSET constants (fill exact -// parameter if it's not NULL with TRUE if encoding is realyl supported under -// Windows and FALSE if not and we just chose something close to it) -extern int wxCharsetFromEncoding(wxFontEncoding encoding, bool *exact = NULL); + wxFontRefData(const wxFontRefData& data) + { + Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, + data.m_underlined, data.m_faceName, data.m_encoding); + m_macFontNum = data.m_macFontNum ; + m_macFontSize = data.m_macFontSize; + m_macFontStyle = data.m_macFontStyle; + m_fontId = data.m_fontId; + } + + wxFontRefData(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) + { + Init(size, family, style, weight, underlined, faceName, encoding); + } + + virtual ~wxFontRefData(); +protected: + // common part of all ctors + void Init(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding); + + // font characterstics + int m_fontId; + int m_pointSize; + int m_family; + int m_style; + int m_weight; + bool m_underlined; + wxString m_faceName; + wxFontEncoding m_encoding; + +public : + short m_macFontNum ; + short m_macFontSize ; + Style m_macFontStyle ; +public : + void MacFindFont() ; +}; // ---------------------------------------------------------------------------- // wxFont // ---------------------------------------------------------------------------- @@ -87,6 +138,7 @@ public: virtual bool RealizeResource(); virtual WXHANDLE GetResourceHandle(); virtual bool FreeResource(bool force = FALSE); + void MacInstall() const ; /* virtual bool UseResource(); virtual bool ReleaseResource(); diff --git a/include/wx/mac/frame.h b/include/wx/mac/frame.h index ae5e085877..5feb46e42f 100644 --- a/include/wx/mac/frame.h +++ b/include/wx/mac/frame.h @@ -125,8 +125,9 @@ public: void OnSysColourChanged(wxSysColourChangedEvent& event); // Query app for menu item updates (called from OnIdle) - void DoMenuUpdates(); - void DoMenuUpdates(wxMenu* menu); + // Query app for menu item updates (called from OnIdle) + void DoMenuUpdates(); + void DoMenuUpdates(wxMenu* menu, wxWindow* focusWin); // Checks if there is a toolbar, and returns the first free client position virtual wxPoint GetClientAreaOrigin() const; @@ -136,7 +137,8 @@ public: // tooltip management #if wxUSE_TOOLTIPS wxMacToolTip* GetToolTipCtrl() const { return m_hwndToolTip; } - void SetToolTipCtrl(wxMacToolTip *tt) { m_hwndToolTip = wxMacToolTip; } + void SetToolTipCtrl(wxMacToolTip *tt) { m_hwndToolTip = tt; } + wxMacToolTip* m_hwndToolTip ; #endif // tooltips protected: diff --git a/include/wx/mac/icon.h b/include/wx/mac/icon.h index fed25013ff..90d99dbfed 100644 --- a/include/wx/mac/icon.h +++ b/include/wx/mac/icon.h @@ -44,6 +44,8 @@ public: // Copy constructors inline wxIcon(const wxIcon& icon) { Ref(icon); } + wxIcon( const char **bits, int width=-1, int height=-1 ); + wxIcon( char **bits, int width=-1, int height=-1 ); wxIcon(const char bits[], int width, int height); wxIcon(const wxString& name, long flags = wxBITMAP_TYPE_ICON_RESOURCE, int desiredWidth = -1, int desiredHeight = -1); diff --git a/include/wx/mac/listbox.h b/include/wx/mac/listbox.h index 0ab770ac57..061c146b0e 100644 --- a/include/wx/mac/listbox.h +++ b/include/wx/mac/listbox.h @@ -9,93 +9,116 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// + #ifndef _WX_LISTBOX_H_ #define _WX_LISTBOX_H_ #ifdef __GNUG__ -#pragma interface "listbox.h" + #pragma interface "listbox.h" #endif -#include "wx/control.h" -#include "wx/dynarray.h" +// ---------------------------------------------------------------------------- +// simple types +// ---------------------------------------------------------------------------- -WXDLLEXPORT_DATA(extern const char*) wxListBoxNameStr; +#if wxUSE_OWNER_DRAWN + class WXDLLEXPORT wxOwnerDrawn; -// forward decl for GetSelections() -class WXDLLEXPORT wxArrayInt; + // define the array of list box items + #include -WXDLLEXPORT_DATA(extern const char*) wxEmptyString; + WX_DEFINE_EXPORTED_ARRAY(wxOwnerDrawn *, wxListBoxItemsArray); +#endif // wxUSE_OWNER_DRAWN + +// forward decl for GetSelections() +class wxArrayInt; // List box item WX_DEFINE_ARRAY( char * , wxListDataArray ) ; -class WXDLLEXPORT wxListBox: public wxControl +// ---------------------------------------------------------------------------- +// List box control +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxListBox : public wxListBoxBase { - DECLARE_DYNAMIC_CLASS(wxListBox) - public: - - wxListBox(); - inline wxListBox(wxWindow *parent, wxWindowID id, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr) - { - Create(parent, id, pos, size, n, choices, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID id, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr); - - ~wxListBox(); - - virtual void Append(const wxString& item); - virtual void Append(const wxString& item, char *clientData); - virtual void Set(int n, const wxString* choices, char **clientData = NULL); - virtual int FindString(const wxString& s) const ; - virtual void Clear(); - virtual void SetSelection(int n, bool select = TRUE); - - virtual void Deselect(int n); - - // For single choice list item only - virtual int GetSelection() const ; - virtual void Delete(int n); - virtual char *GetClientData(int n) const ; - virtual void SetClientData(int n, char *clientData); - virtual void SetString(int n, const wxString& s); - - // For single or multiple choice list item - virtual int GetSelections(wxArrayInt& aSelections) const; - virtual bool Selected(int n) const ; - virtual wxString GetString(int n) const ; - - // Set the specified item at the first visible item - // or scroll to max range. - virtual void SetFirstItem(int n) ; - virtual void SetFirstItem(const wxString& s) ; - - virtual void InsertItems(int nItems, const wxString items[], int pos); - - virtual wxString GetStringSelection() const ; - virtual bool SetStringSelection(const wxString& s, bool flag = TRUE); - virtual int Number() const ; - - void Command(wxCommandEvent& event); - - void MacSetRedraw( bool doDraw ) ; - protected: - int m_noItems; - int m_selected; - +public: + // ctors and such + wxListBox(); + wxListBox(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr) + { + Create(parent, id, pos, size, n, choices, style, validator, name); + } + + bool Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr); + + virtual ~wxListBox(); + + // implement base class pure virtuals + virtual void Clear(); + virtual void Delete(int n); + + virtual int GetCount() const; + virtual wxString GetString(int n) const; + virtual void SetString(int n, const wxString& s); + virtual int FindString(const wxString& s) const; + + virtual bool IsSelected(int n) const; + virtual void SetSelection(int n, bool select = TRUE); + virtual int GetSelection() const; + virtual int GetSelections(wxArrayInt& aSelections) const; + + virtual int DoAppend(const wxString& item); + virtual void DoInsertItems(const wxArrayString& items, int pos); + virtual void DoSetItems(const wxArrayString& items, void **clientData); + + virtual void DoSetFirstItem(int n); + + virtual void DoSetItemClientData(int n, void* clientData); + virtual void* DoGetItemClientData(int n) const; + virtual void DoSetItemClientObject(int n, wxClientData* clientData); + virtual wxClientData* DoGetItemClientObject(int n) const; + + // wxCheckListBox support +#if wxUSE_OWNER_DRAWN + // plug-in for derived classes + virtual wxOwnerDrawn *CreateItem(size_t n); + + // allows to get the item and use SetXXX functions to set it's appearance + wxOwnerDrawn *GetItem(size_t n) const { return m_aItems[n]; } + + // get the index of the given item + int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); } +#endif // wxUSE_OWNER_DRAWN + + // Windows-specific code to set the horizontal extent of the listbox, if + // necessary. If s is non-NULL, it's used to calculate the horizontal + // extent. Otherwise, all strings are used. + virtual void SetHorizontalExtent(const wxString& s = wxEmptyString); + + // Windows callbacks + + virtual void SetupColours(); + virtual void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; + + ListHandle m_macList ; + wxArrayString m_stringArray ; + wxListDataArray m_dataArray ; + void MacSetRedraw( bool doDraw ) ; +protected: void MacDestroy() ; void MacDelete( int n ) ; void MacInsert( int n , const char * text) ; @@ -111,13 +134,25 @@ class WXDLLEXPORT wxListBox: public wxControl void MacDoClick() ; void MacDoDoubleClick() ; - public : - ListHandle m_macList ; - wxArrayString m_stringArray ; - wxListDataArray m_dataArray ; - - virtual void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; -DECLARE_EVENT_TABLE() + // do we have multiple selections? + bool HasMultipleSelection() const; + + // free memory (common part of Clear() and dtor) + void Free(); + + int m_noItems; + int m_selected; + + virtual wxSize DoGetBestSize(); + +#if wxUSE_OWNER_DRAWN + // control items + wxListBoxItemsArray m_aItems; +#endif + +private: + DECLARE_DYNAMIC_CLASS(wxListBox) + DECLARE_EVENT_TABLE() }; #endif diff --git a/include/wx/mac/menu.h b/include/wx/mac/menu.h index 3c5634d202..98b840a56f 100644 --- a/include/wx/mac/menu.h +++ b/include/wx/mac/menu.h @@ -16,168 +16,193 @@ #pragma interface "menu.h" #endif -#include "wx/defs.h" -#include "wx/event.h" +#if wxUSE_ACCEL + #include "wx/accel.h" + #include "wx/dynarray.h" -class WXDLLEXPORT wxMenuItem; -class WXDLLEXPORT wxMenuBar; -class WXDLLEXPORT wxMenu; + WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray); +#endif // wxUSE_ACCEL -WXDLLEXPORT_DATA(extern const char*) wxEmptyString; +class WXDLLEXPORT wxFrame; // ---------------------------------------------------------------------------- // Menu // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxMenu: public wxEvtHandler -{ - DECLARE_DYNAMIC_CLASS(wxMenu) +class WXDLLEXPORT wxMenu : public wxMenuBase +{ public: - // ctor & dtor - wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL); - ~wxMenu(); - - // construct menu - // append items to the menu - // separator line - void AppendSeparator(); - // normal item - 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, - const wxString& helpString = wxEmptyString); - // the most generic form (create wxMenuItem first and use it's functions) - void Append(wxMenuItem *pItem); - // insert a break in the menu - void Break(); - // delete an item - void Delete(int id); - - // menu item control - void Enable(int id, bool Flag); - bool Enabled(int id) const; - inline 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); }; - - // Client data - inline void SetClientData(void* clientData) { m_clientData = clientData; } - inline void* GetClientData() const { return m_clientData; } - - // item properties - // title - void SetTitle(const wxString& label); - const wxString GetTitle() const; - // label - void SetLabel(int id, const wxString& label); - wxString GetLabel(int id) const; - // help string - virtual void SetHelpString(int id, const wxString& helpString); - virtual wxString GetHelpString(int id) const ; - - // find item - // Finds the item id matching the given string, -1 if not found. - virtual int FindItem(const wxString& itemString) const ; - // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. - wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; - - void ProcessCommand(wxCommandEvent& event); - inline void Callback(const wxFunction func) { m_callback = func; } - - virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; } - inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } - inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } - - inline wxList& GetItems() const { return (wxList&) m_menuItems; } - - void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; } - wxWindow * GetInvokingWindow() const { return m_pInvokingWindow; } - - bool MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) ; -public: - wxFunction m_callback; - - int m_noItems; - wxString m_title; - wxMenuBar * m_menuBar; - wxList m_menuItems; - wxEvtHandler * m_parent; - wxEvtHandler * m_eventHandler; - wxWindow* m_pInvokingWindow; - void* m_clientData; - - MenuHandle m_macMenuHandle; - short m_macMenuId; - bool m_macMenuEnabled ; - - // void MacSetTitle(const wxString& title); - int MacGetIndexFromId( int id ) ; - int MacGetIndexFromItem( wxMenuItem *pItem ) ; - void MacEnableMenu( bool bDoEnable ) ; - - static short s_macNextMenuId ; + // ctors & dtor + wxMenu(const wxString& title, long style = 0) + : wxMenuBase(title, style) { Init(); } -protected: + wxMenu(long style = 0) : wxMenuBase(style) { Init(); } + + virtual ~wxMenu(); + + // implement base class virtuals + virtual bool DoAppend(wxMenuItem *item); + virtual bool DoInsert(size_t pos, wxMenuItem *item); + virtual wxMenuItem *DoRemove(wxMenuItem *item); + + virtual void Break(); + + virtual void SetTitle(const wxString& title); + + // MSW-specific + bool ProcessCommand(wxCommandEvent& event); + +#if WXWIN_COMPATIBILITY + wxMenu(const wxString& title, const wxFunction func) + : wxMenuBase(title) + { + Callback(func); + } +#endif // WXWIN_COMPATIBILITY + + // implementation only from now on + // ------------------------------- + + bool MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) ; + int MacGetIndexFromId( int id ) ; + int MacGetIndexFromItem( wxMenuItem *pItem ) ; + void MacEnableMenu( bool bDoEnable ) ; + + // semi-private accessors + // get the window which contains this menu + wxWindow *GetWindow() const; + // get the menu handle + WXHMENU GetHMenu() const { return m_hMenu; } + + // attach/detach menu to/from wxMenuBar + void Attach(wxMenuBar *menubar); + void Detach(); + short MacGetMenuId() { return m_macMenuId ; } +#if wxUSE_ACCEL + // called by wxMenuBar to build its accel table from the accels of all menus + bool HasAccels() const { return !m_accels.IsEmpty(); } + size_t GetAccelCount() const { return m_accels.GetCount(); } + size_t CopyAccels(wxAcceleratorEntry *accels) const; + + // called by wxMenuItem when its accels changes + void UpdateAccel(wxMenuItem *item); + + // helper used by wxMenu itself (returns the index in m_accels) + int FindAccel(int id) const; +#endif // wxUSE_ACCEL + +private: + // common part of all ctors + void Init(); + + // common part of Append/Insert (behaves as Append is pos == (size_t)-1) + bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1); + + // if TRUE, insert a breal before appending the next item + bool m_doBreak; + + // the menu handle of this menu + WXHMENU m_hMenu; + + short m_macMenuId; + + static short s_macNextMenuId ; +#if wxUSE_ACCEL + // the accelerators for our menu items + wxAcceleratorArray m_accels; +#endif // wxUSE_ACCEL + + DECLARE_DYNAMIC_CLASS(wxMenu) }; // ---------------------------------------------------------------------------- // Menu Bar (a la Windows) // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxFrame; -class WXDLLEXPORT wxMenuBar: public wxEvtHandler + +class WXDLLEXPORT wxMenuBar : public wxMenuBarBase { - DECLARE_DYNAMIC_CLASS(wxMenuBar) - - 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]; } +public: + // ctors & dtor + // default constructor + wxMenuBar(); + // unused under MSW + wxMenuBar(long style); + // menubar takes ownership of the menus arrays but copies the titles + wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + virtual ~wxMenuBar(); + + // menubar construction + virtual bool Append( wxMenu *menu, const wxString &title ); + virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); + virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); + virtual wxMenu *Remove(size_t pos); + + virtual int FindMenuItem(const wxString& menuString, + const wxString& itemString) const; + virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const; + + virtual void EnableTop( size_t pos, bool flag ); + virtual void SetLabelTop( size_t pos, const wxString& label ); + virtual wxString GetLabelTop( size_t pos ) const; + + // compatibility: these functions are deprecated +#if WXWIN_COMPATIBILITY + void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } + wxEvtHandler *GetEventHandler() { return m_eventHandler; } + + bool Enabled(int id) const { return IsEnabled(id); } + bool Checked(int id) const { return IsChecked(id); } +#endif // WXWIN_COMPATIBILITY + + // implementation from now on + WXHMENU Create(); + int FindMenu(const wxString& title); + void Detach(); + + // returns TRUE if we're attached to a frame + bool IsAttached() const { return m_menuBarFrame != NULL; } + // get the frame we live in + wxFrame *GetFrame() const { return m_menuBarFrame; } + // attach to a frame + void Attach(wxFrame *frame); + +#if wxUSE_ACCEL + // get the accel table for all the menus + const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; } + + // update the accel table (must be called after adding/deletign a menu) + void RebuildAccelTable(); +#endif // wxUSE_ACCEL + + // if the menubar is modified, the display is not updated automatically, + // call this function to update it (m_menuBarFrame should be !NULL) + void Refresh(); void MacInstallMenuBar() ; void MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) ; + static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; } + +protected: + // common part of all ctors + void Init(); - public: - wxEvtHandler * m_eventHandler; - int m_menuCount; - wxMenu ** m_menus; - wxString * m_titles; - wxFrame * m_menuBarFrame; +#if WXWIN_COMPATIBILITY + wxEvtHandler *m_eventHandler; +#endif // WXWIN_COMPATIBILITY + wxArrayString m_titles; + + wxFrame *m_menuBarFrame; + +#if wxUSE_ACCEL + // the accelerator table for all accelerators in all our menus + wxAcceleratorTable m_accelTable; +#endif // wxUSE_ACCEL + +private: static wxMenuBar* s_macInstalledMenuBar ; + + DECLARE_DYNAMIC_CLASS(wxMenuBar) }; #endif // _WX_MENU_H_ diff --git a/include/wx/mac/print.h b/include/wx/mac/print.h index bac3703496..f70265e0e6 100644 --- a/include/wx/mac/print.h +++ b/include/wx/mac/print.h @@ -11,46 +11,4 @@ #ifndef _WX_PRINT_H_ #define _WX_PRINT_H_ - -#ifdef __GNUG__ -#pragma interface "print.h" -#endif - -#include "wx/prntbase.h" - -/* - * Represents the printer: manages printing a wxPrintout object - */ - -class WXDLLEXPORT wxPrinter: public wxPrinterBase -{ - DECLARE_DYNAMIC_CLASS(wxPrinter) - - public: - wxPrinter(wxPrintData *data = NULL); - ~wxPrinter(); - - virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE); - virtual bool PrintDialog(wxWindow *parent); - virtual bool Setup(wxWindow *parent); -}; - -/* - * wxPrintPreview - * Programmer creates an object of this class to preview a wxPrintout. - */ - -class WXDLLEXPORT wxPrintPreview: public wxPrintPreviewBase -{ - DECLARE_CLASS(wxPrintPreview) - - public: - wxPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting = NULL, wxPrintData *data = NULL); - ~wxPrintPreview(); - - virtual bool Print(bool interactive); - virtual void DetermineScaling(); -}; - -#endif - // _WX_PRINT_H_ +#endif \ No newline at end of file diff --git a/include/wx/mac/printdlg.h b/include/wx/mac/printdlg.h index ac31a49096..1c6eb915cb 100644 --- a/include/wx/mac/printdlg.h +++ b/include/wx/mac/printdlg.h @@ -33,18 +33,21 @@ class WXDLLEXPORT wxPrintDialog: public wxDialog public: wxPrintDialog(); - wxPrintDialog(wxWindow *parent, wxPrintData* data = NULL); + wxPrintDialog(wxWindow *parent, wxPrintDialogData* data = NULL); + wxPrintDialog(wxWindow *parent, wxPrintData* data ); ~wxPrintDialog(); - bool Create(wxWindow *parent, wxPrintData* data = NULL); + bool Create(wxWindow *parent, wxPrintDialogData* data = NULL); virtual int ShowModal(); - inline wxPrintData& GetPrintData() { return m_printData; } + wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; } + wxPrintData& GetPrintData() { return m_printDialogData.GetPrintData(); } virtual wxDC *GetPrintDC(); private: - wxPrintData m_printData; + wxPrintDialogData m_printDialogData; wxDC* m_printerDC; + bool m_destroyDC; wxWindow* m_dialogParent; }; @@ -52,9 +55,6 @@ class WXDLLEXPORT wxPageSetupDialog: public wxDialog { DECLARE_DYNAMIC_CLASS(wxPageSetupDialog) - private: - wxPageSetupData m_pageSetupData; - wxWindow* m_dialogParent; public: wxPageSetupDialog(); wxPageSetupDialog(wxWindow *parent, wxPageSetupData *data = NULL); @@ -64,6 +64,9 @@ class WXDLLEXPORT wxPageSetupDialog: public wxDialog virtual int ShowModal(); inline wxPageSetupData& GetPageSetupData() { return m_pageSetupData; } + private: + wxPageSetupData m_pageSetupData; + wxWindow* m_dialogParent; }; #endif diff --git a/include/wx/mac/setup.h b/include/wx/mac/setup.h index a538bafcb0..0ae5dd8e72 100644 --- a/include/wx/mac/setup.h +++ b/include/wx/mac/setup.h @@ -16,71 +16,109 @@ * General features * */ -#define wxUSE_BUSYINFO 1 - -#define WORDS_BIGENDIAN 1 - -#define wxUSE_LIBPNG 1 - // Use PNG bitmap code -#define wxUSE_LIBJPEG 1 - // Use JPEG bitmap code -#define wxUSE_STREAMS 1 - -#define wxUSE_ZLIB 1 -#define wxUSE_ZIPSTREAM 1 -#define wxUSE_SOCKETS 1 - -#define wxUSE_CONSTRAINTS 1 - // Use constraints mechanism + #define wxUSE_CONFIG 1 // Use wxConfig, with CreateConfig in wxApp -#define _WX_GOODCOMPILER__ - // gcc can have problems, but Windows compilers - // are generally OK. + #define WXWIN_COMPATIBILITY 0 // Compatibility with 1.66 API. // Level 0: no backward compatibility, all new features // Level 1: wxDC, OnSize (etc.) compatibility, but // some new features such as event tables - -#define wxUSE_AUTOTRANS 0 - // Define wxTString #define wxUSE_POSTSCRIPT 0 // 0 for no PostScript device context #define wxUSE_AFM_FOR_POSTSCRIPT 0 // 1 to use font metric files in GetTextExtent #define wxUSE_METAFILE 1 // 0 for no Metafile and metafile device context -#define wxUSE_FORM 0 - // 0 for no wxForm #define wxUSE_IPC 0 // 0 for no interprocess comms #define wxUSE_HELP 0 // 0 for no help facility #define wxUSE_RESOURCES 1 // 0 for no wxGetResource/wxWriteResource +#define wxUSE_CONSTRAINTS 1 + // Use constraints mechanism +#define wxUSE_TIMEDATE 1 + // 0 for no wxTime/wxDate classes + #define wxUSE_CLIPBOARD 1 - // 0 for no clipboard functions -#define wxUSE_SPLINES 0 - // 0 for no splines -#define wxUSE_XFIG_SPLINE_CODE 0 - // 1 for XFIG spline code, 0 for AIAI spline code. -// AIAI spline code is slower, but freer of copyright issues. - // 0 for no splines - -#define wxUSE_TOOLBAR 1 - // Use toolbars + // 0 for no clipboard functions + +#define wxUSE_SPLINES 1 + // 0 for no splines + #define wxUSE_DRAG_AND_DROP 0 - // 0 for no drag and drop + // 0 for no drag and drop + +#define wxUSE_TOOLBAR 1 + // Define 1 to use toolbar classes +#define wxUSE_BUTTONBAR 1 + // Define 1 to use buttonbar classes (enhanced toolbar + // for MS Windows) +#define wxUSE_GAUGE 1 + // Define 1 to use Microsoft's gauge (Windows) + // or Bull's gauge (Motif) library (both in contrib). +#define wxUSE_COMBOBOX 1 + // Define 1 to use COMBOXBOX control (Windows) + // or FWW's ComboBox widget (Motif). +#define wxUSE_CHOICE 1 + // Define 1 to use CHOICE + +#define wxUSE_RADIOBUTTON 1 + // Define 1 to use radio button control +#define wxUSE_RADIOBTN 1 + // Unfortunately someone introduced this one, too + +#define wxUSE_SCROLLBAR 1 + // Define 1 to compile contributed wxScrollBar class + +#define wxUSE_CHECKBOX 1 + // Define 1 to compile checkbox + +#define wxUSE_LISTBOX 1 + // Define 1 to compile listbox + +#define wxUSE_SPINBTN 1 + // Define 1 to compile spin button + +// use wxStaticLine class (separator line in the dialog)? +#define wxUSE_STATLINE 1 +#define wxUSE_CHECKLISTBOX 1 + // Define 1 to compile check listbox + +#define wxUSE_CHOICE 1 + // Define 1 to compile choice + +#define wxUSE_CARET 1 + // Define 1 to use wxCaret class +#define wxUSE_XPM_IN_MSW 1 + // Define 1 to support the XPM package in wxBitmap. +#define wxUSE_IMAGE_LOADING_IN_MSW 1 + // Use dynamic DIB loading/saving code in utils/dib under MSW. +#define wxUSE_RESOURCE_LOADING_IN_MSW 1 + // Use dynamic icon/cursor loading/saving code + // under MSW. #define wxUSE_WX_RESOURCES 1 // Use .wxr resource mechanism (requires PrologIO library) +// support for startup tips (wxShowTip &c) +#define wxUSE_STARTUP_TIPS 1 + +// BC++/Win16 can't cope with the amount of data in resource.cpp +#if defined(__WIN16__) && defined(__BORLANDC__) +#undef wxUSE_WX_RESOURCES +#define wxUSE_WX_RESOURCES 0 +#endif + #define wxUSE_DOC_VIEW_ARCHITECTURE 1 // Set to 0 to disable document/view architecture +#define wxUSE_MDI_ARCHITECTURE 1 + // Set to 0 to disable MDI document/view architecture #define wxUSE_PRINTING_ARCHITECTURE 1 // Set to 0 to disable print/preview architecture code -#define wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW 0 +#define wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW 1 // Set to 0 to disable PostScript print/preview architecture code // under Windows (just use Windows printing). #define wxUSE_DYNAMIC_CLASSES 1 @@ -88,19 +126,19 @@ // NOW MANDATORY: don't change. #define wxUSE_MEMORY_TRACING 1 // If 1, enables debugging versions of wxObject::new and - // wxObject::delete *IF* WXDEBUG is also defined. + // wxObject::delete *IF* __WXDEBUG__ is also defined. // WARNING: this code may not work with all architectures, especially // if alignment is an issue. #define wxUSE_DEBUG_CONTEXT 1 // If 1, enables wxDebugContext, for // writing error messages to file, etc. - // If WXDEBUG is not defined, will still use + // If __WXDEBUG__ is not defined, will still use // normal memory operators. // It's recommended to set this to 1, // since you may well need to output // an error log in a production // version (or non-debugging beta) -#define wxUSE_GLOBAL_MEMORY_OPERATORS 0 +#define wxUSE_GLOBAL_MEMORY_OPERATORS 1 // In debug mode, cause new and delete to be redefined globally. // If this causes problems (e.g. link errors), set this to 0. @@ -108,16 +146,16 @@ // In debug mode, causes new to be defined to // be WXDEBUG_NEW (see object.h). // If this causes problems (e.g. link errors), set this to 0. + // You may need to set this to 0 if using templates (at least + // for VC++). #define REMOVE_UNUSED_ARG 1 // Set this to 0 if your compiler can't cope // with omission of prototype parameters. -#define wxUSE_C_MAIN 0 - // Set to 1 to use main.c instead of main.cpp (UNIX only) +#define wxUSE_ODBC 1 + // Define 1 to use ODBC classes -#define wxUSE_ODBC 0 - // Define 1 to use ODBC classes #define wxODBC_FWD_ONLY_CURSORS 1 // Some databases/ODBC drivers only allow forward scrolling cursors. @@ -129,36 +167,67 @@ +#ifndef __MWERKS__ #define wxUSE_IOSTREAMH 0 +#else +#define wxUSE_IOSTREAMH 1 +#endif // VC++ 4.2 and above allows and // but you can't mix them. Set to 1 for , // 0 for -#define wxUSE_ZIPSTREAM 1 - -#define wxUSE_FS_ZIP 1 - -#define wxUSE_FS_INET 1 - #define wxUSE_STREAMS 1 // If enabled (1), compiles wxWindows streams classes #define wxUSE_STD_IOSTREAM 1 // Use standard C++ streams if 1. If 0, use wxWin // streams implementation. -#define wxUSE_WXCONFIG 0 + +#define wxUSE_WXCONFIG 1 // if enabled, compiles built-in OS independent wxConfig // class and it's file (any platform) and registry (Win) // based implementations +#define wxUSE_THREADS 1 + // support for multithreaded applications: if + // 1, compile in thread classes (thread.h) + // and make the library thread safe +#define wxUSE_ZLIB 1 + // Use zlib for compression in streams and PNG code +#define wxUSE_LIBPNG 1 + // Use PNG bitmap code +#define wxUSE_LIBJPEG 0 + // Use JPEG bitmap code +#define wxUSE_SERIAL 0 + // Use serialization (requires utils/serialize) +#define wxUSE_DYNLIB_CLASS 0 + // Compile in wxLibrary class for run-time + // DLL loading and function calling +#define wxUSE_TOOLTIPS 1 + // Define to use wxToolTip class and + // wxWindow::SetToolTip() method +#define wxUSE_SOCKETS 1 // 0 + // Set to 1 to use socket classes +#define wxUSE_HTML 1 // 0 + // Set to 1 to use wxHTML sub-library +#define wxUSE_FS_ZIP 1 // 0 +#define wxUSE_FS_INET 1 // 0 // Set to 1 to enable virtual file systems + +#define wxUSE_BUSYINFO 1 // 0 + // wxBusyInfo displays window with message + // when app is busy. Works in same way as + // wxBusyCursor +#define wxUSE_ZIPSTREAM 1 // 0 + // input stream for reading from zip archives + /* * Finer detail * */ -#define wxUSE_APPLE_IEEE 1 - // if enabled, the float codec written by Apple - // will be used to write, in a portable way, - // float on the disk +#define wxUSE_APPLE_IEEE 1 + // if enabled, the float codec written by Apple + // will be used to write, in a portable way, + // float on the disk // use wxFile class - required by i18n code, wxConfig and others - recommended #define wxUSE_FILE 1 @@ -184,8 +253,6 @@ // text entry dialog and wxGetTextFromUser function #define wxUSE_TEXTDLG 1 -#define wxUSE_STATLINE 1 - // wxToolBar class #define wxUSE_TOOLBAR 1 @@ -198,5 +265,68 @@ // wxDirDlg class for getting a directory name from user #define wxUSE_DIRDLG 1 +/* + * MS Windows/Windows NT + * + */ + +#define wxUSE_OLE 1 + // drag-and-drop, clipboard, OLE Automation + +#if defined(__WIN95__) +#define wxUSE_CTL3D 0 +#else +#define wxUSE_CTL3D 1 + // Define 1 to use Microsoft CTL3D library. + // See note above about using FAFA and CTL3D. +#endif + +#define wxUSE_COMMON_DIALOGS 1 + // On rare occasions (e.g. using DJGPP) may want + // to omit common dialogs + // (e.g. file selector, printer dialog). + // Switching this off also switches off + // the printing architecture and interactive + // wxPrinterDC. +#define wxUSE_ITSY_BITSY 1 + // Define 1 to use Microsoft's ItsyBitsy + // small title bar library, for wxMiniFrame +#define wxUSE_BITMAP_MESSAGE 1 + // Define 1 to use bitmap messages. +#define wxUSE_PORTABLE_FONTS_IN_MSW 0 + // Define 1 to use new portable font scheme in Windows + // (used by default under X) +#define wxFONT_SIZE_COMPATIBILITY 0 + // Define 1 for font size to be backward compatible + // to 1.63 and earlier. 1.64 and later define point + // sizes to be compatible with Windows. +#define wxUSE_GENERIC_DIALOGS_IN_MSW 1 + // Define 1 to use generic dialogs in Windows, even though + // they duplicate native common dialog (e.g. wxColourDialog) +#define wxUSE_PENWINDOWS 0 + // Set to 1 to use PenWindows + +#define wxUSE_OWNER_DRAWN 1 + // Owner-drawn menus and listboxes + +#define wxUSE_NATIVE_STATUSBAR 1 + // Set to 0 to use cross-platform wxStatusBar +#define wxUSE_DBWIN32 1 + // Use Andrew Tucker's OutputDebugString implementation + // (required on Win95 only). See utils.cpp. + +/* + * Any platform + * + */ + +#define wxUSE_TYPEDEFS 1 + // Use typedefs not classes for wxPoint + // and others, to reduce overhead and avoid + // MS C7 memory bug. Bounds checker + // complains about deallocating + // arrays of wxPoints if wxPoint is a class. + + #endif // _WX_SETUP_H_ diff --git a/include/wx/mac/spinbutt.h b/include/wx/mac/spinbutt.h index caa1b77db2..3903eecb29 100644 --- a/include/wx/mac/spinbutt.h +++ b/include/wx/mac/spinbutt.h @@ -29,71 +29,48 @@ wxSP_WRAP: value wraps at either end */ -class WXDLLEXPORT wxSpinButton: public wxControl +class WXDLLEXPORT wxSpinButton : public wxSpinButtonBase { - DECLARE_DYNAMIC_CLASS(wxSpinButton) - public: - /* - * Public interface - */ - - wxSpinButton(); - - inline wxSpinButton(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_VERTICAL, const wxString& name = "wxSpinButton") - { - Create(parent, id, pos, size, style, name); - } - ~wxSpinButton(); - - bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_VERTICAL, const wxString& name = "wxSpinButton"); - - - // Attributes - //////////////////////////////////////////////////////////////////////////// - - int GetValue() const ; - void SetValue(int val) ; - void SetRange(int minVal, int maxVal) ; - inline int GetMin() const { return m_min; } - inline int GetMax() const { return m_max; } - - // Operations - //////////////////////////////////////////////////////////////////////////// - - void Command(wxCommandEvent& event) { ProcessCommand(event); }; - virtual void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; +public: + // construction + wxSpinButton() { } + + wxSpinButton(wxWindow *parent, + wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, + const wxString& name = "wxSpinButton") + { + Create(parent, id, pos, size, style, name); + } + + virtual ~wxSpinButton(); + + bool Create(wxWindow *parent, + wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, + const wxString& name = "wxSpinButton"); + + + // accessors + virtual int GetValue() const; + virtual void SetValue(int val); + virtual void SetRange(int minVal, int maxVal); + + // implementation + + virtual void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; protected: - int m_min; - int m_max; - int m_value ; -}; - -class WXDLLEXPORT wxSpinEvent: public wxScrollEvent -{ - DECLARE_DYNAMIC_CLASS(wxSpinEvent) + virtual wxSize DoGetBestSize(); + int m_value ; - public: - wxSpinEvent(wxEventType commandType = wxEVT_NULL, int id = 0); +private: + DECLARE_DYNAMIC_CLASS(wxSpinButton) }; -typedef void (wxEvtHandler::*wxSpinEventFunction)(wxSpinEvent&); - -// Spin events - -#define EVT_SPIN_UP(id, func) { wxEVT_SCROLL_LINEUP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func } -#define EVT_SPIN_DOWN(id, func) { wxEVT_SCROLL_LINEDOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func } - -#define EVT_SPIN(id, func) \ - { wxEVT_SCROLL_TOP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func },\ - { wxEVT_SCROLL_BOTTOM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func },\ - { wxEVT_SCROLL_LINEUP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func },\ - { wxEVT_SCROLL_LINEDOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func },\ - { wxEVT_SCROLL_PAGEUP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func },\ - { wxEVT_SCROLL_PAGEDOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func },\ - { wxEVT_SCROLL_THUMBTRACK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSpinEventFunction) & func }, - #endif // _WX_SPINBUTT_H_ diff --git a/include/wx/mac/window.h b/include/wx/mac/window.h index 7c4bb6b097..8a33aa8051 100644 --- a/include/wx/mac/window.h +++ b/include/wx/mac/window.h @@ -21,6 +21,7 @@ // --------------------------------------------------------------------------- class WXDLLEXPORT wxButton; +class WXDLLEXPORT wxScrollBar; // --------------------------------------------------------------------------- // constants @@ -169,9 +170,9 @@ public: // simple accessors // ---------------- - WXHWND GetHWND() const { return m_hWnd; } - void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; } - virtual WXWidget GetHandle() const { return (WXWidget) GetHWND(); } +// WXHWND GetHWND() const { return m_hWnd; } +// void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; } + virtual WXWidget GetHandle() const { return (WXWidget) NULL ; } bool GetUseCtl3D() const { return m_useCtl3D; } bool GetTransparentBackground() const { return m_backgroundTransparent; } @@ -226,12 +227,57 @@ public: // Responds to colour changes: passes event on to children. void OnSysColourChanged(wxSysColourChangedEvent& event); +public : + static bool MacGetWindowFromPoint( const wxPoint &point , wxWindow** outWin ) ; + virtual void MacActivate( EventRecord *ev , bool inIsActivating ) ; + virtual void MacUpdate( EventRecord *ev ) ; + virtual void MacUpdateImmediately() ; + virtual void MacRedraw( RgnHandle updatergn , long time) ; + virtual void MacMouseDown( EventRecord *ev , short windowPart ) ; + virtual void MacMouseUp( EventRecord *ev , short windowPart ) ; + virtual void MacMouseMoved( EventRecord *ev , short windowPart ) ; + virtual void MacKeyDown( EventRecord *ev ) ; + virtual bool MacCanFocus() const { return true ; } + + virtual void MacFireMouseEvent( EventRecord *ev ) ; + virtual bool MacDispatchMouseEvent(wxMouseEvent& event ) ; + virtual void MacEraseBackground( Rect *rect ) ; + WindowRef GetMacRootWindow() const ; + + virtual ControlHandle MacGetContainerForEmbedding() ; + virtual void MacSuperChangedPosition() ; + + bool MacSetupFocusPort() ; + bool MacSetupDrawingPort() ; + bool MacSetupFocusClientPort() ; + bool MacSetupDrawingClientPort() ; + + virtual bool MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* rootwin ) ; + virtual bool MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* rootwin ) ; + + virtual void MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) ; + virtual void MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin) ; + MacWindowData* MacGetWindowData() { return m_macWindowData ; } + static WindowRef MacGetWindowInUpdate() { return s_macWindowInUpdate ; } + static wxWindow* s_lastMouseWindow ; +private: + virtual bool MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin ) ; protected: - // the window handle - WXHWND m_hWnd; - // the old window proc (we subclass all windows) - WXFARPROC m_oldWndProc; + MacWindowData* m_macWindowData ; + static WindowRef s_macWindowInUpdate ; + + int m_x ; + int m_y ; + int m_width ; + int m_height ; + + wxScrollBar* m_hScrollBar ; + wxScrollBar* m_vScrollBar ; + wxString m_label ; + + void MacCreateScrollBars( long style ) ; + void MacRepositionScrollBars() ; // additional (MSW specific) flags bool m_useCtl3D:1; // Using CTL3D for this control @@ -244,10 +290,7 @@ protected: int m_xThumbSize; int m_yThumbSize; - WXHMENU m_hMenu; // Menu, if any - - // the return value of WM_GETDLGCODE handler - long m_lDlgCode; +// WXHMENU m_hMenu; // Menu, if any // implement the base class pure virtuals virtual void DoClientToScreen( int *x, int *y ) const; diff --git a/include/wx/notebook.h b/include/wx/notebook.h index 63bbee89ea..4dea9653ef 100644 --- a/include/wx/notebook.h +++ b/include/wx/notebook.h @@ -102,7 +102,7 @@ typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&); #elif defined(__WXQT__) #include "wx/qt/notebook.h" #elif defined(__WXMAC__) - #include "wx/mac/notebook.h" + #include "wx/generic/notebook.h" #elif defined(__WXPM__) #include "wx/os2/notebook.h" #elif defined(__WXSTUBS__) diff --git a/include/wx/os2/dataform.h b/include/wx/os2/dataform.h index d052bf4e0c..1b5b229e1a 100644 --- a/include/wx/os2/dataform.h +++ b/include/wx/os2/dataform.h @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: os2/dataform.h +// Name: mac/dataform.h // Purpose: declaration of the wxDataFormat class -// Author: David Webster (lifted from dnd.h) +// Author: Stefan Csomor // Modified by: // Created: 10/21/99 // RCS-ID: $Id$ -// Copyright: (c) 1999 David Webster +// Copyright: (c) 1999 Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// diff --git a/include/wx/os2/dataobj.h b/include/wx/os2/dataobj.h index 2f6ed49da5..148b637c77 100644 --- a/include/wx/os2/dataobj.h +++ b/include/wx/os2/dataobj.h @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: os2/dataobj.h +// Name: mac/dataobj.h // Purpose: declaration of the wxDataObject -// Author: David Webster (adapted from Robert Roebling's gtk port) +// Author: Stefan Csomor // Modified by: // Created: 10/21/99 // RCS-ID: $Id$ @@ -9,8 +9,8 @@ // Licence: wxWindows license /////////////////////////////////////////////////////////////////////////////// -#ifndef _WX_GTK_DATAOBJ_H_ -#define _WX_GTK_DATAOBJ_H_ +#ifndef _WX_MAC_DATAOBJ_H_ +#define _WX_MAC_DATAOBJ_H_ #ifdef __GNUG__ #pragma interface "dataobj.h" @@ -28,5 +28,5 @@ public: virtual bool IsSupportedFormat( const wxDataFormat& format, Direction dir = Get ) const; }; -#endif // _WX_GTK_DATAOBJ_H_ +#endif // _WX_MAC_DATAOBJ_H_ diff --git a/include/wx/print.h b/include/wx/print.h index 5d7c7a4f60..801dea98ae 100644 --- a/include/wx/print.h +++ b/include/wx/print.h @@ -11,6 +11,17 @@ #define wxPrintPreview wxWindowsPrintPreview #endif +#elif defined(__WXMAC__) + +#include "wx/mac/printmac.h" + +#ifndef wxPrinter +#define wxPrinter wxMacPrinter +#endif +#ifndef wxPrintPreview +#define wxPrintPreview wxMacPrintPreview +#endif + #else #include "wx/generic/printps.h" diff --git a/include/wx/thread.h b/include/wx/thread.h index 2140c3f777..6775fdf760 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -137,6 +137,9 @@ private: #if defined(__WXMSW__) || defined(__WXPM__) class WXDLLEXPORT wxCriticalSectionInternal; #define WXCRITICAL_INLINE +#elif defined(__WXMAC__) + class WXDLLEXPORT wxCriticalSectionInternal; + #define WXCRITICAL_INLINE #else // !MSW && !PM #define WXCRITICAL_INLINE inline #endif // MSW/!MSW @@ -160,7 +163,7 @@ private: wxCriticalSection(const wxCriticalSection&); wxCriticalSection& operator=(const wxCriticalSection&); -#if defined(__WXMSW__) || defined(__WXPM__) +#if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXMAC__) wxCriticalSectionInternal *m_critsect; #else // !MSW wxMutex m_mutex; @@ -396,6 +399,18 @@ public: // wakes up the main thread if it's sleeping inside ::GetMessage() extern void WXDLLEXPORT wxWakeUpMainThread(); + // return TRUE if the main thread is waiting for some other to terminate: + // wxApp then should block all "dangerous" messages + extern bool WXDLLEXPORT wxIsWaitingForThread(); +#elif defined(__WXMAC__) + extern void WXDLLEXPORT wxMutexGuiLeaveOrEnter(); + + // returns TRUE if the main thread has GUI lock + extern bool WXDLLEXPORT wxGuiOwnedByMainThread(); + + // wakes up the main thread if it's sleeping inside ::GetMessage() + extern void WXDLLEXPORT wxWakeUpMainThread(); + // return TRUE if the main thread is waiting for some other to terminate: // wxApp then should block all "dangerous" messages extern bool WXDLLEXPORT wxIsWaitingForThread(); diff --git a/src/common/db.cpp b/src/common/db.cpp index 78b9dc7db5..5e34839f63 100644 --- a/src/common/db.cpp +++ b/src/common/db.cpp @@ -96,6 +96,19 @@ DbList WXDLLEXPORT *PtrBegDbList = 0; extern wxList TablesInUse; #endif + +#ifdef __MWERKS__ +#ifdef __WXMSW__ +#define stricmp _stricmp +#define strnicmp _strnicmp +#else //__WXMSW_ +int strcasecmp(const char *str_1, const char *str_2) ; +int strncasecmp(const char *str_1, const char *str_2, size_t maxchar) ; +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif +#endif //__MWERKS__ + // SQL Log defaults to be used by GetDbConnection enum sqlLog SQLLOGstate = sqlLogOFF; diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index 51ff59a1a2..1113157d90 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -81,6 +81,18 @@ #include "wx/dbtable.h" #endif +#ifdef __MWERKS__ +#ifdef __WXMSW__ +#define stricmp _stricmp +#define strnicmp _strnicmp +#else +int strcasecmp(const char *str_1, const char *str_2) ; +int strncasecmp(const char *str_1, const char *str_2, size_t maxchar) ; +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif +#endif + #ifdef __UNIX__ // The HPUX preprocessor lines below were commented out on 8/20/97 // because macros.h currently redefines DEBUG and is unneeded. diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 0783aa903d..cef3b561f0 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -112,10 +112,14 @@ #define _MAXPATHLEN 500 +extern char *wxBuffer; + #ifdef __WXMAC__ - extern wxChar gwxMacFileName[] ; - extern wxChar gwxMacFileName2[] ; - extern wxChar gwxMacFileName3[] ; + +#include "morefile.h" +#include "moreextr.h" +#include "fullpath.h" +#include "fspcompa.h" #endif #if !USE_SHARED_LIBRARIES @@ -262,10 +266,8 @@ wxFileExists (const wxString& filename) return TRUE; #elif defined(__WXMAC__) struct stat stbuf; - wxStrcpy( gwxMacFileName , filename ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - if (gwxMacFileName && stat (WXSTRINGCAST gwxMacFileName, &stbuf) == 0) - return TRUE; + if (filename && stat (wxUnix2MacFilename(filename), &stbuf) == 0 ) + return TRUE; return FALSE ; #else @@ -824,78 +826,129 @@ wxString wxPathOnly (const wxString& path) // Also, convert to lower case, since case is significant in UNIX. #ifdef __WXMAC__ -void -wxMac2UnixFilename (wxChar *s) + +static char sMacFileNameConversion[ 1000 ] ; + +wxString wxMac2UnixFilename (const char *str) { - if (s) - { - memmove( s+1 , s ,(strlen( s ) + 1)*sizeof(wxChar)) ; - if ( *s == wxT(':') ) - *s = wxT('.') ; - else - *s = wxT('/') ; - - while (*s) - { - if (*s == wxT(':')) - *s = wxT('/'); - else - *s = wxTolower(*s); // Case INDEPENDENT - s++; - } - } + char *s = sMacFileNameConversion ; + strcpy( s , str ) ; + if (s) + { + memmove( s+1 , s ,strlen( s ) + 1) ; + if ( *s == ':' ) + *s = '.' ; + else + *s = '/' ; + + while (*s) + { + if (*s == ':') + *s = '/'; + else + *s = wxTolower (*s); // Case INDEPENDENT + s++; + } + } + return wxString (sMacFileNameConversion) ; } -void -wxUnix2MacFilename (wxChar *s) +wxString wxUnix2MacFilename (const char *str) { - if (s) - { - if ( *s == wxT('.') ) - { - // relative path , since it goes on with slash which is translated to a : - memmove( s , s+1 ,strlen( s )*sizeof(wxChar) ) ; - } - else if ( *s == wxT('/') ) - { - // absolute path -> on mac just start with the drive name - memmove( s , s+1 ,strlen( s )*sizeof(wxChar) ) ; - } - else - { - wxASSERT_MSG( 1 , wxT("unknown path beginning") ) ; - } - while (*s) - { - if (*s == wxT('/') || *s == wxT('\\')) - *s = wxT(':'); + char *s = sMacFileNameConversion ; + strcpy( s , str ) ; + if (s) + { + if ( *s == '.' ) + { + // relative path , since it goes on with slash which is translated to a : + memmove( s , s+1 ,strlen( s ) ) ; + } + else if ( *s == '/' ) + { + // absolute path -> on mac just start with the drive name + memmove( s , s+1 ,strlen( s ) ) ; + } + else + { + wxASSERT_MSG( 1 , "unkown path beginning" ) ; + } + while (*s) + { + if (*s == '/' || *s == '\\') + { + // convert any back-directory situations + if ( *(s+1) == '.' && *(s+2) == '.' && ( (*(s+3) == '/' || *(s+3) == '\\') ) ) + { + *s = ':'; + memmove( s+1 , s+3 ,strlen( s+3 ) + 1 ) ; + } + else + *s = ':'; + } - s++ ; - } - } + s++ ; + } + } + return wxString (sMacFileNameConversion) ; +} + +wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) +{ + Handle myPath ; + short length ; + + FSpGetFullPath( spec , &length , &myPath ) ; + ::SetHandleSize( myPath , length + 1 ) ; + ::HLock( myPath ) ; + (*myPath)[length] = 0 ; + if ( length > 0 && (*myPath)[length-1] ==':' ) + (*myPath)[length-1] = 0 ; + + wxString result( (char*) *myPath ) ; + ::HUnlock( myPath ) ; + ::DisposeHandle( myPath ) ; + return result ; +} + +wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) +{ + return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec) ) ; } + +void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) +{ + FSpLocationFromFullPath( strlen(path ) , path , spec ) ; +} + +void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) +{ + wxString var = wxUnix2MacFilename( path ) ; + wxMacFilename2FSSpec( var , spec ) ; +} + #endif void -wxDos2UnixFilename (wxChar *s) +wxDos2UnixFilename (char *s) { if (s) while (*s) { - if (*s == wxT('\\')) - *s = wxT('/'); -#if defined(__WXMSW__) || defined(__WXPM__) + if (*s == '\\') + *s = '/'; +#ifdef __WXMSW__ else - *s = wxTolower(*s); // Case INDEPENDENT + *s = wxTolower (*s); // Case INDEPENDENT #endif s++; } } void -#if defined(__WXMSW__) || defined(__WXPM__) -wxUnix2DosFilename (wxChar *s) +#ifdef __WXMSW__ +wxUnix2DosFilename (char *s) #else -wxUnix2DosFilename (wxChar *WXUNUSED(s)) +wxUnix2DosFilename (char *WXUNUSED(s) ) #endif { // Yes, I really mean this to happen under DOS only! JACS @@ -921,20 +974,13 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil FILE *fp3 = (FILE *) NULL; // Open the inputs and outputs #ifdef __WXMAC__ - wxStrcpy( gwxMacFileName , file1 ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - wxStrcpy( gwxMacFileName2 , file2) ; - wxUnix2MacFilename( gwxMacFileName2 ) ; - wxStrcpy( gwxMacFileName3 , outfile) ; - wxUnix2MacFilename( gwxMacFileName3 ) ; - - if ((fp1 = fopen (gwxMacFileName, "rb")) == NULL || - (fp2 = fopen (gwxMacFileName2, "rb")) == NULL || - (fp3 = fopen (gwxMacFileName3, "wb")) == NULL) + if ((fp1 = fopen (wxUnix2MacFilename( file1 ), "rb")) == NULL || + (fp2 = fopen (wxUnix2MacFilename( file2 ), "rb")) == NULL || + (fp3 = fopen (wxUnix2MacFilename( outfile ), "wb")) == NULL) #else - if ((fp1 = fopen (wxFNSTRINGCAST file1.fn_str(), "rb")) == NULL || - (fp2 = fopen (wxFNSTRINGCAST file2.fn_str(), "rb")) == NULL || - (fp3 = fopen (wxFNCONV(outfile), "wb")) == NULL) + if ((fp1 = fopen (WXSTRINGCAST file1, "rb")) == NULL || + (fp2 = fopen (WXSTRINGCAST file2, "rb")) == NULL || + (fp3 = fopen (outfile, "wb")) == NULL) #endif { if (fp1) @@ -970,18 +1016,13 @@ wxCopyFile (const wxString& file1, const wxString& file2) int ch; #ifdef __WXMAC__ - wxStrcpy( gwxMacFileName , file1 ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - wxStrcpy( gwxMacFileName2 , file2) ; - wxUnix2MacFilename( gwxMacFileName2 ) ; - - if ((fd1 = fopen (gwxMacFileName, "rb")) == NULL) + if ((fd1 = fopen (wxUnix2MacFilename( file1 ), "rb")) == NULL) return FALSE; - if ((fd2 = fopen (gwxMacFileName2, "wb")) == NULL) + if ((fd2 = fopen (wxUnix2MacFilename( file2 ), "wb")) == NULL) #else - if ((fd1 = fopen (wxFNSTRINGCAST file1.fn_str(), "rb")) == NULL) + if ((fd1 = fopen (WXSTRINGCAST file1, "rb")) == NULL) return FALSE; - if ((fd2 = fopen (wxFNSTRINGCAST file2.fn_str(), "wb")) == NULL) + if ((fd2 = fopen (WXSTRINGCAST file2, "wb")) == NULL) #endif { fclose (fd1); @@ -1000,12 +1041,7 @@ bool wxRenameFile (const wxString& file1, const wxString& file2) { #ifdef __WXMAC__ - wxStrcpy( gwxMacFileName , file1 ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - wxStrcpy( gwxMacFileName2 , file2) ; - wxUnix2MacFilename( gwxMacFileName2 ) ; - - if (0 == rename (gwxMacFileName, gwxMacFileName2)) + if (0 == rename (wxUnix2MacFilename( file1 ), wxUnix2MacFilename( file2 ))) return TRUE; #else // Normal system call @@ -1026,9 +1062,7 @@ bool wxRemoveFile(const wxString& file) #if defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__) int flag = remove(wxFNSTRINGCAST file.fn_str()); #elif defined( __WXMAC__ ) - wxStrcpy( gwxMacFileName , file ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - int flag = unlink(gwxMacFileName); + int flag = unlink(wxUnix2MacFilename( file )); #else int flag = unlink(wxFNSTRINGCAST file.fn_str()); #endif @@ -1038,12 +1072,9 @@ bool wxRemoveFile(const wxString& file) bool wxMkdir(const wxString& dir, int perm) { #if defined( __WXMAC__ ) - wxStrcpy( gwxMacFileName , dir ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - const wxChar *dirname = gwxMacFileName; + return (mkdir(wxUnix2MacFilename( dir ) , 0 ) == 0); #else // !Mac const wxChar *dirname = dir.c_str(); -#endif // Mac/!Mac // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too // for the GNU compiler @@ -1059,6 +1090,7 @@ bool wxMkdir(const wxString& dir, int perm) } return TRUE; +#endif // Mac/!Mac } bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) @@ -1066,9 +1098,7 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) #ifdef __VMS__ return FALSE; #elif defined( __WXMAC__ ) - wxStrcpy( gwxMacFileName , dir ) ; - wxUnix2MacFilename( gwxMacFileName ) ; - return (rmdir(WXSTRINGCAST gwxMacFileName) == 0); + return (rmdir(wxUnix2MacFilename( dir )) == 0); #else #ifdef __SALFORDC__ @@ -1481,6 +1511,17 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) char *cbuf = new char[sz+1]; #ifdef _MSC_VER if (_getcwd(cbuf, sz) == NULL) { +#elif defined( __WXMAC__) + enum + { + SFSaveDisk = 0x214, CurDirStore = 0x398 + }; + FSSpec cwdSpec ; + + FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ; + wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ; + strcpy( buf , res ) ; + if (0) #else if (getcwd(cbuf, sz) == NULL) { #endif diff --git a/src/mac/app.cpp b/src/mac/app.cpp index fd5a0009b0..7d28b4bb30 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -1338,8 +1338,8 @@ void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) else { wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ; - if ( frontwindow && wxMenuBar::s_macInstalledMenuBar ) - wxMenuBar::s_macInstalledMenuBar->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ; + if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() ) + wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ; } HiliteMenu(0); } diff --git a/src/mac/button.cpp b/src/mac/button.cpp index cb44786443..1f42bad606 100644 --- a/src/mac/button.cpp +++ b/src/mac/button.cpp @@ -47,14 +47,23 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, void wxButton::SetDefault() { - wxWindow *parent = (wxWindow *)GetParent(); - if (parent) - parent->SetDefaultItem(this); - + wxWindow *parent = GetParent(); + wxButton *btnOldDefault = NULL; + wxPanel *panel = wxDynamicCast(parent, wxPanel); + if ( panel ) + { + btnOldDefault = panel->GetDefaultItem(); + panel->SetDefaultItem(this); + } + + if ( btnOldDefault && btnOldDefault->m_macControl ) + { + UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ; + } if ( m_macControl ) { UMASetControlData( m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ; - } + } } void wxButton::Command (wxCommandEvent & event) diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index fd5a0009b0..7d28b4bb30 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -1338,8 +1338,8 @@ void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) else { wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ; - if ( frontwindow && wxMenuBar::s_macInstalledMenuBar ) - wxMenuBar::s_macInstalledMenuBar->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ; + if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() ) + wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ; } HiliteMenu(0); } diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index cb44786443..1f42bad606 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -47,14 +47,23 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, void wxButton::SetDefault() { - wxWindow *parent = (wxWindow *)GetParent(); - if (parent) - parent->SetDefaultItem(this); - + wxWindow *parent = GetParent(); + wxButton *btnOldDefault = NULL; + wxPanel *panel = wxDynamicCast(parent, wxPanel); + if ( panel ) + { + btnOldDefault = panel->GetDefaultItem(); + panel->SetDefaultItem(this); + } + + if ( btnOldDefault && btnOldDefault->m_macControl ) + { + UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ; + } if ( m_macControl ) { UMASetControlData( m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ; - } + } } void wxButton::Command (wxCommandEvent & event) diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index 28a4b9ef3f..828b8984fc 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -23,11 +23,6 @@ #include -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) -IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject) -#endif - bool wxOpenClipboard() { return TRUE; @@ -90,26 +85,36 @@ bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount) * Generalized clipboard implementation by Matthew Flatt */ -wxClipboard *wxTheClipboard = NULL; +wxClipboard::wxClipboard() +{ + m_clearOnExit = FALSE; +} -void wxInitClipboard() +wxClipboard::~wxClipboard() { - if (!wxTheClipboard) - wxTheClipboard = new wxClipboard; + if ( m_clearOnExit ) + { + Clear(); + } } -wxClipboard::wxClipboard() +void wxClipboard::Clear() { - clipOwner = NULL; - cbString = NULL; } -wxClipboard::~wxClipboard() +bool wxClipboard::Flush() { - if (clipOwner) - clipOwner->BeingReplaced(); - if (cbString) - delete[] cbString; + return FALSE; +} + +bool wxClipboard::Open() +{ + return wxOpenClipboard(); +} + +bool wxClipboard::IsOpened() const +{ + return wxIsClipboardOpened(); } static int FormatStringToID(char *str) @@ -120,6 +125,129 @@ static int FormatStringToID(char *str) return wxRegisterClipboardFormat(str); } +bool wxClipboard::SetData( wxDataObject *data ) +{ + (void)wxEmptyClipboard(); + + if ( data ) + return AddData(data); + else + return TRUE; +} + +bool wxClipboard::AddData( wxDataObject *data ) +{ + wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); + +#if wxUSE_DATAOBJ + wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); + + wxDataFormat format = data->GetFormat(); + + switch ( format ) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + { + wxTextDataObject* textDataObject = (wxTextDataObject*) data; + wxString str(textDataObject->GetText()); + return wxSetClipboardData(format, str.c_str()); + } + + case wxDF_BITMAP: + case wxDF_DIB: + { + wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; + wxBitmap bitmap(bitmapDataObject->GetBitmap()); + return wxSetClipboardData(data->GetFormat(), &bitmap); + } + +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafileDataObject* metaFileDataObject = + (wxMetafileDataObject*) data; + wxMetafile metaFile = metaFileDataObject->GetMetafile(); + return wxSetClipboardData(wxDF_METAFILE, &metaFile, + metaFileDataObject->GetWidth(), + metaFileDataObject->GetHeight()); + } +#endif // wxUSE_METAFILE + + default: + return wxSetClipboardData(data); + } +#else // !wxUSE_DATAOBJ + return FALSE; +#endif +} + +void wxClipboard::Close() +{ + wxCloseClipboard(); +} + +bool wxClipboard::IsSupported( wxDataFormat format ) +{ + return wxIsClipboardFormatAvailable(format); +} + +bool wxClipboard::GetData( wxDataObject& data ) +{ +#if wxUSE_DATAOBJ + wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); + + wxDataFormat format = data.GetFormat(); + switch ( format ) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + { + wxTextDataObject& textDataObject = (wxTextDataObject &)data; + char* s = (char*)wxGetClipboardData(format); + if ( !s ) + return FALSE; + + textDataObject.SetText(s); + delete [] s; + + return TRUE; + } + + case wxDF_BITMAP: + case wxDF_DIB: + { + wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data; + wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data->GetFormat()); + if ( !bitmap ) + return FALSE; + + bitmapDataObject.SetBitmap(*bitmap); + delete bitmap; + + return TRUE; + } +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data; + wxMetafile* metaFile = (wxMetafile *)wxGetClipboardData(wxDF_METAFILE); + if ( !metaFile ) + return FALSE; + + metaFileDataObject.SetMetafile(*metaFile); + delete metaFile; + + return TRUE; + } +#endif // wxUSE_METAFILE + } +#else // !wxUSE_DATAOBJ + wxFAIL_MSG( wxT("no clipboard implementation") ); +#endif + return FALSE; +} +/* void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time) { bool got_selection; @@ -167,7 +295,7 @@ wxClipboardClient *wxClipboard::GetClipboardClient() } void wxClipboard::SetClipboardString(char *str, long time) -{/* +{ bool got_selection; if (clipOwner) { @@ -193,9 +321,7 @@ void wxClipboard::SetClipboardString(char *str, long time) delete[] cbString; cbString = NULL; } - */ } - char *wxClipboard::GetClipboardString(long time) { char *str; @@ -210,6 +336,7 @@ char *wxClipboard::GetClipboardString(long time) return str; } + char *wxClipboard::GetClipboardData(char *format, long *length, long time) { if (clipOwner) { @@ -233,4 +360,5 @@ char *wxClipboard::GetClipboardData(char *format, long *length, long time) return receivedString; } } +*/ diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index d570e2c5a1..220ff1e0a9 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -53,7 +53,9 @@ wxControl::wxControl() m_macVerticalBorder = 0 ; m_backgroundColour = *wxWHITE; m_foregroundColour = *wxBLACK; - m_callback = 0; +#if WXWIN_COMPATIBILITY + m_callback = 0; +#endif // WXWIN_COMPATIBILITY if ( wxMacLiveScrollbarActionUPP == NULL ) { @@ -63,13 +65,14 @@ wxControl::wxControl() wxControl::~wxControl() { + m_isBeingDeleted = TRUE; // If we delete an item, we should initialize the parent panel, // because it could now be invalid. - wxWindow *parent = (wxWindow *)GetParent(); - if (parent) + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + if ( panel ) { - if (parent->GetDefaultItem() == (wxButton*) this) - parent->SetDefaultItem(NULL); + if (panel->GetDefaultItem() == (wxButton*) this) + panel->SetDefaultItem(NULL); } if ( m_macControl ) { @@ -78,13 +81,19 @@ wxControl::~wxControl() } } -void wxControl::SetLabel(const wxString& label) +void wxControl::SetLabel(const wxString& title) { - m_label = label ; + m_label = title ; if ( m_macControl ) { Str255 maclabel ; + wxString label ; + + if( wxApp::s_macDefaultEncodingIsPC ) + label = wxMacMakeMacStringFromPC( title ) ; + else + label = title ; strcpy( (char*) maclabel , label ) ; c2pstr( (char*) maclabel ) ; @@ -93,56 +102,31 @@ void wxControl::SetLabel(const wxString& label) } } -wxString wxControl::GetLabel() const +wxSize wxControl::DoGetBestSize() { - return m_label ; + return wxSize(20, 20); } -void wxControl::ProcessCommand (wxCommandEvent & event) +bool wxControl::ProcessCommand (wxCommandEvent & event) { // Tries: // 1) A callback function (to become obsolete) // 2) OnCommand, starting at this window and working up parent hierarchy // 3) OnCommand then calls ProcessEvent to search the event tables. - if (m_callback) +#if WXWIN_COMPATIBILITY + if ( m_callback ) { - (void) (*(m_callback)) (*this, event); + (void)(*m_callback)(this, event); + + return TRUE; } else +#endif // WXWIN_COMPATIBILITY { - GetEventHandler()->OnCommand(*this, event); + return GetEventHandler()->ProcessEvent(event); } } -void wxControl::Centre (int direction) -{ - int x, y, width, height, panel_width, panel_height, new_x, new_y; - - wxWindow *parent = (wxWindow *) GetParent (); - if (!parent) - return; - - parent->GetClientSize (&panel_width, &panel_height); - GetSize (&width, &height); - GetPosition (&x, &y); - - new_x = x; - new_y = y; - - if (direction & wxHORIZONTAL) - new_x = (int) ((panel_width - width) / 2); - - if (direction & wxVERTICAL) - new_y = (int) ((panel_height - height) / 2); - - SetSize (new_x, new_y, width, height); -} - -void wxControl::SetClientSize (int width, int height) -{ - SetSize (-1, -1, width, height); -} - // ------------------------ wxList *wxWinMacControlList = NULL; wxControl *wxFindControlFromMacControl(ControlHandle inControl ) @@ -352,6 +336,7 @@ void wxControl::MacSuperChangedPosition() void wxControl::MacSuperEnabled( bool enabled ) { +/* if ( m_macControl ) { if ( UMAHasAppearance() ) @@ -380,10 +365,12 @@ void wxControl::MacSuperEnabled( bool enabled ) } } wxWindow::MacSuperEnabled( enabled ) ; + */ } void wxControl::MacSuperShown( bool show ) { + /* if ( m_macControl ) { if ( !show ) @@ -398,6 +385,7 @@ void wxControl::MacSuperShown( bool show ) } wxWindow::MacSuperShown( show ) ; + */ } void wxControl::DoSetSize(int x, int y, @@ -503,51 +491,45 @@ void wxControl::DoSetSize(int x, int y, } } -void wxControl::DoSetClientSize(int width, int height) -{ - DoSetSize( -1 , -1 , width , height ) ; -} - bool wxControl::Show(bool show) { - if ( m_macControl == NULL ) - return wxWindow::Show( show ) ; - - if ( m_macShown == show ) - return TRUE ; - - if ( show ) - ::UMAShowControl( m_macControl ) ; - else - ::UMAHideControl( m_macControl ) ; - - return wxWindow::Show( show ) ; + if ( !wxWindow::Show( show ) ) + return FALSE ; + + if ( m_macControl ) + { + if ( show ) + ::UMAShowControl( m_macControl ) ; + else + ::UMAHideControl( m_macControl ) ; + } + return TRUE ; } -void wxControl::Enable(bool enable) +bool wxControl::Enable(bool enable) { - if ( m_macControl == NULL ) - return wxWindow::Enable( enable ) ; - - if ( m_macEnabled == enable ) - return ; + if ( !wxWindow::Enable(enable) ) + return FALSE; - if ( UMAHasAppearance() ) - { - if ( enable ) - ::ActivateControl( m_macControl ) ; - else - ::DeactivateControl( m_macControl ) ; - } - else + if ( m_macControl ) { - if ( enable ) - ::HiliteControl( m_macControl , 0 ) ; + + if ( UMAHasAppearance() ) + { + if ( enable ) + ::ActivateControl( m_macControl ) ; + else + ::DeactivateControl( m_macControl ) ; + } else - ::HiliteControl( m_macControl , 255 ) ; + { + if ( enable ) + ::HiliteControl( m_macControl , 0 ) ; + else + ::HiliteControl( m_macControl , 255 ) ; + } } - - return wxWindow::Enable( enable ) ; + return TRUE ; } void wxControl::Refresh(bool eraseBack, const wxRect *rect) @@ -579,9 +561,9 @@ void wxControl::OnPaint(wxPaintEvent& event) wxWindow* parent = GetParent() ; while ( parent ) { - if( parent->m_macWindowData ) + if( parent->MacGetWindowData() ) { - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; break ; } @@ -596,13 +578,13 @@ void wxControl::OnPaint(wxPaintEvent& event) } UMADrawControl( m_macControl ) ; - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; } } } else { - wxWindow::OnPaint( event ) ; + // wxWindow::OnPaint( event ) ; } } diff --git a/src/mac/carbon/dialog.cpp b/src/mac/carbon/dialog.cpp index 7e82133eb2..2acc18174e 100644 --- a/src/mac/carbon/dialog.cpp +++ b/src/mac/carbon/dialog.cpp @@ -108,7 +108,6 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ; UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; m_macWindowData->m_macFocus = NULL ; - m_macShown = false ; return TRUE; } @@ -127,10 +126,13 @@ void wxDialog::SetModal(bool flag) wxDialog::~wxDialog() { + m_isBeingDeleted = TRUE ; wxTopLevelWindows.DeleteObject(this); - if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) - wxModelessWindows.DeleteObject(this); + m_modalShowing = FALSE; + + if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) + wxModelessWindows.DeleteObject(this); // If this is the last top-level window, exit. if (wxTheApp && (wxTopLevelWindows.Number() == 0)) @@ -176,37 +178,64 @@ extern bool s_macIsInModalLoop ; bool wxDialog::Show(bool show) { - if ( m_macShown == show ) - return TRUE ; + m_isShown = show; - m_macShown = show ; + if (show) + InitDialog(); bool modal = ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL) ; +#if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ + if (!modal) + { + if (show) + { + if (!wxModelessWindows.Find(this)) + wxModelessWindows.Append(this); + } + else + wxModelessWindows.DeleteObject(this); + } + if (show) + { + if (!wxTopLevelWindows.Find(this)) + wxTopLevelWindows.Append(this); + } + else + wxTopLevelWindows.DeleteObject(this); +#endif + if ( modal ) { s_macIsInModalLoop = true ; - if (show) - { - // if we don't do it, some window might be deleted while we have pointers - // to them in our disabledWindows list and the program will crash when it - // will try to reenable them after the modal dialog end - wxTheApp->DeletePendingObjects(); - - UMAShowWindow( m_macWindowData->m_macWindow ) ; - UMASelectWindow( m_macWindowData->m_macWindow ) ; - - if (!wxModalDialogs.Member(this)) - wxModalDialogs.Append(this); - - while (wxModalDialogs.Member(this) ) - { - wxTheApp->MacDoOneEvent() ; - } + if (show) + { + if (m_modalShowing) + { +// BringWindowToTop((HWND) GetHWND()); + return TRUE; + } + + m_modalShowing = TRUE; + // if we don't do it, some window might be deleted while we have pointers + // to them in our disabledWindows list and the program will crash when it + // will try to reenable them after the modal dialog end + wxTheApp->DeletePendingObjects(); + + UMAShowWindow( m_macWindowData->m_macWindow ) ; + UMASelectWindow( m_macWindowData->m_macWindow ) ; + + if (!wxModalDialogs.Member(this)) + wxModalDialogs.Append(this); + + while (wxModalDialogs.Member(this) ) + { + wxTheApp->MacDoOneEvent() ; + } } else { - wxModalDialogs.DeleteObject(this); + wxModalDialogs.DeleteObject(this); UMAHideWindow( m_macWindowData->m_macWindow ) ; } s_macIsInModalLoop = false ; @@ -334,125 +363,3 @@ void wxDialog::Fit() wxWindow::Fit(); } -wxSizer *wxDialog::CreateTextSizer( const wxString &message ) -{ - wxBoxSizer *box = new wxBoxSizer( wxVERTICAL ); - - // get line height for empty lines - int y = 0; - wxFont new_font( GetFont() ); - if (!new_font.Ok()) new_font = *wxSWISS_FONT; - GetTextExtent( "H", (int*)NULL, &y, (int*)NULL, (int*)NULL, &new_font ); - - wxString line; - for (size_t pos = 0; pos < message.Len(); pos++) - { - if (message[pos] == _T('\n')) - { - if (!line.IsEmpty()) - { - wxStaticText *s1 = new wxStaticText( this, -1, line ); - box->Add( s1 ); - line = _T(""); - } - else - { - box->Add( 5, y ); - } - } - else - { - line += message[pos]; - } - } - - // remaining text behind last '\n' - if (!line.IsEmpty()) - { - wxStaticText *s2 = new wxStaticText( this, -1, line ); - box->Add( s2 ); - } - - return box; -} - -wxSizer *wxDialog::CreateButtonSizer( long flags ) -{ - wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL ); - -#if defined(__WXMSW__) || defined(__WXMAC__) - int margin = 6; -#else - int margin = 10; -#endif - - wxButton *ok = (wxButton *) NULL; - wxButton *cancel = (wxButton *) NULL; - wxButton *yes = (wxButton *) NULL; - wxButton *no = (wxButton *) NULL; - - // always show an OK button, unless only YES_NO is given - if ((flags & wxYES_NO) == 0) flags = flags | wxOK; - - if (flags & wxYES_NO) - { - yes = new wxButton( this, wxID_YES, _("Yes") ); - box->Add( yes, 0, wxLEFT|wxRIGHT, margin ); - no = new wxButton( this, wxID_NO, _("No") ); - box->Add( no, 0, wxLEFT|wxRIGHT, margin ); - } else - if (flags & wxYES) - { - yes = new wxButton( this, wxID_YES, _("Yes") ); - box->Add( yes, 0, wxLEFT|wxRIGHT, margin ); - } else - if (flags & wxNO) - { - no = new wxButton( this, wxID_NO, _("No") ); - box->Add( no, 0, wxLEFT|wxRIGHT, margin ); - } - - if (flags & wxOK) - { - ok = new wxButton( this, wxID_OK, _("OK") ); - box->Add( ok, 0, wxLEFT|wxRIGHT, margin ); - } - - if (flags & wxFORWARD) - box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxBACKWARD) - box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxSETUP) - box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxMORE) - box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxHELP) - box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxCANCEL) - { - cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); - box->Add( cancel, 0, wxLEFT|wxRIGHT, margin ); - } - - if ((flags & wxNO_DEFAULT) == 0) - { - if (ok) - { - ok->SetDefault(); - ok->SetFocus(); - } - else if (yes) - { - yes->SetDefault(); - yes->SetFocus(); - } - } - - return box; -} - diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index 2409e1a38b..d7d7b12cc8 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -22,39 +22,42 @@ IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) #endif -wxFontRefData::wxFontRefData() -{ - m_style = 0; - m_pointSize = 0; - m_family = 0; - m_style = 0; - m_weight = 0; - m_underlined = 0; - m_faceName = ""; - - m_macFontSize = m_pointSize ; - m_macFontNum = systemFont ; - m_macFontStyle = normal ; -} -wxFontRefData::wxFontRefData(const wxFontRefData& data) + + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxFontRefData +// ---------------------------------------------------------------------------- + +void wxFontRefData::Init(int pointSize, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) { - m_style = data.m_style; - m_pointSize = data.m_pointSize; - m_family = data.m_family; - m_style = data.m_style; - m_weight = data.m_weight; - m_underlined = data.m_underlined; - m_faceName = data.m_faceName; - - m_macFontSize = m_pointSize ; - m_macFontNum = systemFont ; - m_macFontStyle = normal ; + m_style = style; + m_pointSize = pointSize; + m_family = family; + m_style = style; + m_weight = weight; + m_underlined = underlined; + m_faceName = faceName; + m_encoding = encoding; + + m_macFontNum = 0 ; + m_macFontSize = 0; + m_macFontStyle = 0; + m_fontId = 0; } wxFontRefData::~wxFontRefData() { - // TODO: delete font data } void wxFontRefData::MacFindFont() @@ -107,31 +110,27 @@ void wxFontRefData::MacFindFont() m_macFontSize = m_pointSize ; } -wxFont::wxFont() -{ - if ( wxTheFontList ) - wxTheFontList->Append(this); -} +// ---------------------------------------------------------------------------- +// wxFont +// ---------------------------------------------------------------------------- -wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) +void wxFont::Init() { - Create(pointSize, family, style, weight, underlined, faceName); - if ( wxTheFontList ) wxTheFontList->Append(this); } -bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) +bool wxFont::Create(int pointSize, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) { UnRef(); - m_refData = new wxFontRefData; - - M_FONTDATA->m_family = family; - M_FONTDATA->m_style = style; - M_FONTDATA->m_weight = weight; - M_FONTDATA->m_pointSize = pointSize; - M_FONTDATA->m_underlined = underlined; - M_FONTDATA->m_faceName = faceName; + m_refData = new wxFontRefData(pointSize, family, style, weight, + underlined, faceName, encoding); RealizeResource(); @@ -219,78 +218,50 @@ void wxFont::SetUnderlined(bool underlined) RealizeResource(); } -wxString wxFont::GetFamilyString() const +// ---------------------------------------------------------------------------- +// accessors +// ---------------------------------------------------------------------------- + +int wxFont::GetPointSize() const { - wxString fam(""); - switch (GetFamily()) - { - case wxDECORATIVE: - fam = "wxDECORATIVE"; - break; - case wxROMAN: - fam = "wxROMAN"; - break; - case wxSCRIPT: - fam = "wxSCRIPT"; - break; - case wxSWISS: - fam = "wxSWISS"; - break; - case wxMODERN: - fam = "wxMODERN"; - break; - case wxTELETYPE: - fam = "wxTELETYPE"; - break; - default: - fam = "wxDEFAULT"; - break; - } - return fam; + return M_FONTDATA->m_pointSize; } -/* New font system */ -wxString wxFont::GetFaceName() const +int wxFont::GetFamily() const { - wxString str(""); - if (M_FONTDATA) - str = M_FONTDATA->m_faceName ; - return str; + return M_FONTDATA->m_family; } -wxString wxFont::GetStyleString() const +int wxFont::GetFontId() const { - wxString styl(""); - switch (GetStyle()) - { - case wxITALIC: - styl = "wxITALIC"; - break; - case wxSLANT: - styl = "wxSLANT"; - break; - default: - styl = "wxNORMAL"; - break; - } - return styl; + return M_FONTDATA->m_fontId; } -wxString wxFont::GetWeightString() const +int wxFont::GetStyle() const { - wxString w(""); - switch (GetWeight()) - { - case wxBOLD: - w = "wxBOLD"; - break; - case wxLIGHT: - w = "wxLIGHT"; - break; - default: - w = "wxNORMAL"; - break; - } - return w; + return M_FONTDATA->m_style; +} + +int wxFont::GetWeight() const +{ + return M_FONTDATA->m_weight; +} + +bool wxFont::GetUnderlined() const +{ + return M_FONTDATA->m_underlined; +} + +wxString wxFont::GetFaceName() const +{ + wxString str; + if ( M_FONTDATA ) + str = M_FONTDATA->m_faceName ; + return str; +} + +wxFontEncoding wxFont::GetEncoding() const +{ + return M_FONTDATA->m_encoding; } diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index 5a95ac9097..cd7a3deeff 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -52,12 +52,10 @@ wxFrame::wxFrame() #if wxUSE_TOOLBAR m_frameToolBar = NULL ; #endif - m_macShown = false ; + // in order to be able to give size events on show m_frameMenuBar = NULL; m_frameStatusBar = NULL; - - m_windowParent = NULL; m_iconized = FALSE; } @@ -147,7 +145,6 @@ bool wxFrame::Create(wxWindow *parent, UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; m_macWindowData->m_macFocus = NULL ; - m_macShown = false ; return TRUE; } diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index e17f1b8213..3b9c54ce77 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -106,57 +106,120 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { -// DisposeExtLDEFInfo( m_macList ) ; + Free() ; + DisposeExtLDEFInfo( m_macList ) ; } -void wxListBox::SetFirstItem(int N) +void wxListBox::Free() { - MacScrollTo( N ) ; +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + size_t uiCount = m_aItems.Count(); + while ( uiCount-- != 0 ) { + delete m_aItems[uiCount]; + } + + m_aItems.Clear(); + } + else +#endif // wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + for ( size_t n = 0; n < (size_t)m_noItems; n++ ) + { + delete GetClientObject(n); + } + } } -void wxListBox::SetFirstItem(const wxString& s) +void wxListBox::DoSetFirstItem(int N) { - MacScrollTo( FindString( s ) ) ; + MacScrollTo( N ) ; } void wxListBox::Delete(int N) { - m_dataArray.Remove( N ) ; + wxCHECK_RET( N >= 0 && N < m_noItems, + wxT("invalid index in wxListBox::Delete") ); + +#if wxUSE_OWNER_DRAWN + delete m_aItems[N]; + m_aItems.Remove(N); +#else // !wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + delete GetClientObject(N); + } +#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN m_stringArray.Remove( N ) ; m_noItems --; MacDelete( N ) ; + SetHorizontalExtent(""); } -void wxListBox::Append(const wxString& item) -{ - Append( item , NULL ) ; -} - -void wxListBox::Append(const wxString& item, char *Client_data) +int wxListBox::DoAppend(const wxString& item) { + int index = m_noItems ; if( wxApp::s_macDefaultEncodingIsPC ) { m_stringArray.Add( wxMacMakeMacStringFromPC( item ) ) ; } else m_stringArray.Add( item ) ; - m_dataArray.Add( Client_data ) ; - m_noItems ++; - + m_noItems ++; MacAppend( item ) ; + + SetHorizontalExtent(item); + + return index ; } -void wxListBox::Set(int n, const wxString *choices, char** clientData) -{ +void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) +{ + MacSetRedraw( false ) ; Clear() ; + int n = choices.GetCount(); + for( int i = 0 ; i < n ; ++i ) { if ( clientData ) + { +#if wxUSE_OWNER_DRAWN + wxASSERT_MSG(clientData[i] == NULL, + wxT("Can't use client data with owner-drawn listboxes")); +#else // !wxUSE_OWNER_DRAWN Append( choices[i] , clientData[0] ) ; + #endif + } else Append( choices[i] ) ; } + +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) { + // first delete old items + size_t ui = m_aItems.Count(); + while ( ui-- != 0 ) { + delete m_aItems[ui]; + } + m_aItems.Empty(); + + // then create new ones + for ( ui = 0; ui < (size_t)m_noItems; ui++ ) { + wxOwnerDrawn *pNewItem = CreateItem(ui); + pNewItem->SetName(choices[ui]); + m_aItems.Add(pNewItem); + } + } +#endif // wxUSE_OWNER_DRAWN + MacSetRedraw( true ) ; +} + +bool wxListBox::HasMultipleSelection() const +{ + return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); } int wxListBox::FindString(const wxString& st) const @@ -192,10 +255,12 @@ int wxListBox::FindString(const wxString& st) const void wxListBox::Clear() { + Free(); m_noItems = 0; m_stringArray.Empty() ; m_dataArray.Empty() ; MacClear() ; + SetHorizontalExtent(); } void wxListBox::SetSelection(int N, bool select) @@ -205,7 +270,7 @@ void wxListBox::SetSelection(int N, bool select) MacSetSelection( N , select ) ; } -bool wxListBox::Selected(int N) const +bool wxListBox::IsSelected(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE, "invalid index in wxListBox::Selected" ); @@ -213,28 +278,33 @@ bool wxListBox::Selected(int N) const return MacIsSelected( N ) ; } -void wxListBox::Deselect(int N) -{ - wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::Deselect" ); - - SetSelection( N , false ) ; -} - -char *wxListBox::GetClientData(int N) const +void *wxListBox::DoGetItemClientData(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, NULL, "invalid index in wxListBox::GetClientData" ); - return m_dataArray[N]; + return (void *)m_dataArray[N]; } -void wxListBox::SetClientData(int N, char *Client_data) +void wxListBox::DoSetItemClientData(int N, void *Client_data) { wxCHECK_RET( N >= 0 && N < m_noItems, "invalid index in wxListBox::SetClientData" ); - m_dataArray[N] = Client_data ; +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + // client data must be pointer to wxOwnerDrawn, otherwise we would crash + // in OnMeasure/OnDraw. + wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); + } +#endif // wxUSE_OWNER_DRAWN + m_dataArray[N] = (char*) Client_data ; +} + +void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData) +{ + DoSetItemClientData(n, clientData); } // Return number of selections and an array of selected integers @@ -277,8 +347,13 @@ wxString wxListBox::GetString(int N) const return m_stringArray[N] ; } -void wxListBox::InsertItems(int nItems, const wxString items[], int pos) +void wxListBox::DoInsertItems(const wxArrayString& items, int pos) { + wxCHECK_RET( pos >= 0 && pos <= m_noItems, + wxT("invalid index in wxListBox::InsertItems") ); + + int nItems = items.GetCount(); + for ( int i = 0 ; i < nItems ; i++ ) { m_stringArray.Insert( items[i] , pos + i ) ; @@ -295,46 +370,11 @@ void wxListBox::SetString(int N, const wxString& s) MacSet( N , s ) ; } -int wxListBox::Number () const -{ - return m_noItems; -} - -// For single selection items only -wxString wxListBox::GetStringSelection () const -{ - int sel = GetSelection (); - if (sel > -1) - { - return GetString (sel); - } - else - return wxString(""); -} - -bool wxListBox::SetStringSelection (const wxString& s, bool flag) +wxSize wxListBox::DoGetBestSize() { - int sel = FindString (s); - if (sel > -1) - { - SetSelection (sel, flag); - return TRUE; - } - else - return FALSE; + return wxSize(100, 100); } -void wxListBox::Command (wxCommandEvent & event) -{ - if (event.m_extraLong) - SetSelection (event.m_commandInt); - else - { - Deselect (event.m_commandInt); - return; - } - ProcessCommand (event); -} // ============================================================================ // list box control implementation @@ -484,29 +524,27 @@ void wxListBox::MacSetRedraw( bool doDraw ) void wxListBox::MacDoClick() { wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); + event.SetEventObject( this ); + wxArrayInt aSelections; - int count = GetSelections(aSelections); + int n, count = GetSelections(aSelections); if ( count > 0 ) { event.m_commandInt = aSelections[0] ; - event.m_clientData = GetClientData(event.m_commandInt); - wxString str(GetString(event.m_commandInt)); - if (str != "") - event.m_commandString = copystring((char *)(const char *)str); + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + event.SetString( GetString(n) ); } else { - return ; - /* - event.m_commandInt = -1 ; - event.m_commandString = copystring("") ; - */ + n = -1; } - event.SetEventObject( this ); - ProcessCommand(event); - if (event.m_commandString) - delete[] event.m_commandString ; + event.m_commandInt = n; + + GetEventHandler()->ProcessEvent(event); } void wxListBox::MacDoDoubleClick() diff --git a/src/mac/carbon/mdi.cpp b/src/mac/carbon/mdi.cpp index 4869697cd7..de142a0e29 100644 --- a/src/mac/carbon/mdi.cpp +++ b/src/mac/carbon/mdi.cpp @@ -82,17 +82,7 @@ void wxMDIParentFrame::GetClientSize(int *x, int *y) const void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) { - // TODO - if (!menu_bar) - { - m_frameMenuBar = NULL; - return; - } - - if (menu_bar->m_menuBarFrame) - return; - - m_frameMenuBar = menu_bar; + wxFrame::SetMenuBar( menu_bar ) ; } void wxMDIParentFrame::OnSize(wxSizeEvent& event) @@ -211,16 +201,7 @@ void wxMDIChildFrame::GetPosition(int *x, int *y) const void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) { - // TODO - if (!menu_bar) - { - m_frameMenuBar = NULL; - return; - } - - if (menu_bar->m_menuBarFrame) - return; - m_frameMenuBar = menu_bar; + return wxFrame::SetMenuBar( menu_bar ) ; } // MDI operations diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index b22001b870..35589ca6e1 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -178,69 +178,114 @@ static void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutC short wxMenu::s_macNextMenuId = 2 ; -wxMenu::wxMenu(const wxString& title, const wxFunction func) +void wxMenu::Init() { - m_title = title; - m_parent = NULL; - m_eventHandler = this; - m_noItems = 0; - m_menuBar = NULL; - m_pInvokingWindow = NULL ; - m_clientData = (void*) NULL; - if (m_title != "") + m_doBreak = FALSE; + + // create the menu + Str255 label; + wxMacBuildMenuString( label, NULL , NULL , m_title , false ); + m_macMenuId = s_macNextMenuId++; + wxCHECK_RET( s_macNextMenuId < 236 , "menu ids > 235 cannot be used for submenus on mac" ); + m_hMenu = ::NewMenu(m_macMenuId, label); + + if ( !m_hMenu ) + { + wxLogLastError("CreatePopupMenu"); + } + + // if we have a title, insert it in the beginning of the menu + if ( !!m_title ) { Append(idMenuTitle, m_title) ; AppendSeparator() ; } +} - Callback(func); +wxMenu::~wxMenu() +{ + if (m_hMenu) + ::DisposeMenu(m_hMenu); - Str255 label; - wxMacBuildMenuString( label, NULL , NULL , title , false ); - m_macMenuId = s_macNextMenuId++; - wxCHECK_RET( s_macNextMenuId < 236 , "menu ids > 235 cannot be used for submenus on mac" ); - m_macMenuHandle = ::NewMenu(m_macMenuId, label); - m_macMenuEnabled = true ; +#if wxUSE_ACCEL + // delete accels + WX_CLEAR_ARRAY(m_accels); +#endif // wxUSE_ACCEL } -// The wxWindow destructor will take care of deleting the submenus. -wxMenu::~wxMenu() +void wxMenu::Break() { - wxNode *node = m_menuItems.First(); - while (node) - { - wxMenuItem *item = (wxMenuItem *)node->Data(); + // not available on the mac platform +} - // Delete child menus. - // Beware: they must not be appended to children list!!! - // (because order of delete is significant) - if (item->GetSubMenu()) - item->DeleteSubMenu(); +#if wxUSE_ACCEL - wxNode *next = node->Next(); - delete item; - delete node; - node = next; +int wxMenu::FindAccel(int id) const +{ + size_t n, count = m_accels.GetCount(); + for ( n = 0; n < count; n++ ) + { + if ( m_accels[n]->m_command == id ) + return n; } - if (m_macMenuHandle) - ::DisposeMenu(m_macMenuHandle); + + return wxNOT_FOUND; } -void wxMenu::Break() +void wxMenu::UpdateAccel(wxMenuItem *item) { - // not available on the mac platform + // find the (new) accel for this item + wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText()); + if ( accel ) + accel->m_command = item->GetId(); + + // find the old one + int n = FindAccel(item->GetId()); + if ( n == wxNOT_FOUND ) + { + // no old, add new if any + if ( accel ) + m_accels.Add(accel); + else + return; // skipping RebuildAccelTable() below + } + else + { + // replace old with new or just remove the old one if no new + delete m_accels[n]; + if ( accel ) + m_accels[n] = accel; + else + m_accels.Remove(n); + } + + if ( IsAttached() ) + { + m_menuBar->RebuildAccelTable(); + } } +#endif // wxUSE_ACCEL + // function appends a new item or submenu to the menu -void wxMenu::Append(wxMenuItem *pItem) +// append a new item or submenu to the menu +bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { - wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" ); - - m_menuItems.Append(pItem); + wxASSERT_MSG( pItem != NULL, "can't append NULL item to the menu" ); +#if wxUSE_ACCEL + UpdateAccel(pItem); +#endif // wxUSE_ACCEL if ( pItem->IsSeparator() ) { - MacAppendMenu(m_macMenuHandle, "\p-"); + if ( pos == (size_t)-1 ) + { + MacAppendMenu(m_hMenu, "\p-"); + } + else + { + MacInsertMenuItem(m_hMenu, "\p-" , pos); + } } else { @@ -248,9 +293,9 @@ void wxMenu::Append(wxMenuItem *pItem) if ( pSubMenu != NULL ) { Str255 label; - wxCHECK_RET( pSubMenu->m_macMenuHandle != NULL , "invalid submenu added"); - pSubMenu->m_parent = this ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetName() ,false); + wxASSERT_MSG( pSubMenu->m_hMenu != NULL , "invalid submenu added"); + pSubMenu->m_menuParent = this ; + wxMacBuildMenuString( label , NULL , NULL , pItem->GetText() ,false); // hardcoded adding of the submenu combination for mac @@ -264,144 +309,139 @@ void wxMenu::Append(wxMenuItem *pItem) label[theEnd] = 0x00; label[0] = theEnd; - if (wxMenuBar::s_macInstalledMenuBar == m_menuBar) + if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar) { - ::InsertMenu( pSubMenu->m_macMenuHandle , -1 ) ; + ::InsertMenu( pSubMenu->m_hMenu , -1 ) ; } - ::AppendMenu(m_macMenuHandle, label); + if ( pos == (size_t)-1 ) + { + MacAppendMenu(m_hMenu, label); + } + else + { + MacInsertMenuItem(m_hMenu, label , pos); + } } else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetName(), pItem->GetId() == wxApp::s_macAboutMenuItemId); + wxMacBuildMenuString( label , NULL , NULL , pItem->GetText(), pItem->GetId() == wxApp::s_macAboutMenuItemId); if ( label[0] == 0 ) { // we cannot add empty menus on mac label[0] = 1 ; label[1] = ' ' ; } - ::AppendMenu(m_macMenuHandle, label ); + if ( pos == (size_t)-1 ) + { + MacAppendMenu(m_hMenu, label); + } + else + { + MacInsertMenuItem(m_hMenu, label , pos); + } if ( pItem->GetId() == idMenuTitle ) { - UMADisableMenuItem( m_macMenuHandle , CountMItems( m_macMenuHandle ) ) ; + if ( pos == (size_t)-1 ) + { + UMADisableMenuItem( m_hMenu , CountMItems( m_hMenu ) ) ; + } + else + { + UMADisableMenuItem( m_hMenu , pos + 1 ) ; + } } } } - - m_noItems++; + // if we're already attached to the menubar, we must update it + if ( IsAttached() ) + { + m_menuBar->Refresh(); + } + return TRUE ; } -void wxMenu::AppendSeparator() +bool wxMenu::DoAppend(wxMenuItem *item) { - Append(new wxMenuItem(this, ID_SEPARATOR)); + return wxMenuBase::DoAppend(item) && DoInsertOrAppend(item); } -// Pullright item -void wxMenu::Append(int Id, const wxString& label, wxMenu *SubMenu, - const wxString& helpString) +bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) { - Append(new wxMenuItem(this, Id, label, helpString, FALSE, SubMenu)); + return wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos); } -// Ordinary menu item -void wxMenu::Append(int Id, const wxString& label, - const wxString& helpString, bool checkable) +wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) { - // 'checkable' parameter is useless for Windows. - Append(new wxMenuItem(this, Id, label, helpString, checkable)); -} + // we need to find the items position in the child list + size_t pos; + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( pos = 0; node; pos++ ) + { + if ( node->GetData() == item ) + break; -void wxMenu::Delete(int id) -{ - wxNode *node; - wxMenuItem *item; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) { - item = (wxMenuItem *)node->Data(); - if (item->GetId() == id) - break; + node = node->GetNext(); } - if (!node) - return; - - int index = pos + 1 ; + // DoRemove() (unlike Remove) can only be called for existing item! + wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") ); - if (index < 1) - return; +#if wxUSE_ACCEL + // remove the corresponding accel from the accel table + int n = FindAccel(item->GetId()); + if ( n != wxNOT_FOUND ) + { + delete m_accels[n]; - wxMenu *pSubMenu = item->GetSubMenu(); - if ( pSubMenu != NULL ) - { - ::DeleteMenuItem( m_macMenuHandle , index); - pSubMenu->m_parent = NULL; - // TODO: Why isn't subMenu deleted here??? - // Will put this in for now. Assuming this is supposed - // to delete the menu, not just remove it. - item->DeleteSubMenu(); - } - else - { - ::DeleteMenuItem( m_macMenuHandle , index); - } + m_accels.Remove(n); + } + //else: this item doesn't have an accel, nothing to do +#endif // wxUSE_ACCEL - m_menuItems.DeleteNode(node); - // TODO shouldn't we do this ? ÂŽ_m_noItems--; - delete item; -} + ::DeleteMenuItem( m_hMenu , pos + 1); -void wxMenu::Enable(int Id, bool Flag) -{ - wxMenuItem *item = FindItemForId(Id); - wxCHECK_RET( item != NULL, "can't enable non-existing menu item" ); + if ( IsAttached() ) + { + // otherwise, the chane won't be visible + m_menuBar->Refresh(); + } - item->Enable(Flag); + // and from internal data structures + return wxMenuBase::DoRemove(item); } -bool wxMenu::Enabled(int Id) const -{ - wxMenuItem *item = FindItemForId(Id); - wxCHECK( item != NULL, FALSE ); +// --------------------------------------------------------------------------- +// accelerator helpers +// --------------------------------------------------------------------------- - return item->IsEnabled(); -} +#if wxUSE_ACCEL -void wxMenu::Check(int Id, bool Flag) +// create the wxAcceleratorEntries for our accels and put them into provided +// array - return the number of accels we have +size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const { - wxMenuItem *item = FindItemForId(Id); - wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" ); + size_t count = GetAccelCount(); + for ( size_t n = 0; n < count; n++ ) + { + *accels++ = *m_accels[n]; + } - item->Check(Flag); + return count; } -bool wxMenu::Checked(int Id) const -{ - wxMenuItem *item = FindItemForId(Id); - wxCHECK( item != NULL, FALSE ); - - return item->IsChecked(); -} +#endif // wxUSE_ACCEL void wxMenu::SetTitle(const wxString& label) { Str255 title ; m_title = label ; wxMacBuildMenuString( title, NULL , NULL , label , false ); - UMASetMenuTitle( m_macMenuHandle , title ) ; - if (wxMenuBar::s_macInstalledMenuBar == m_menuBar) // are we currently installed ? - { - ::SetMenuBar( GetMenuBar() ) ; - ::InvalMenuBar() ; - } - // TODO:for submenus -> their parent item text must be corrected + UMASetMenuTitle( m_hMenu , title ) ; } -const wxString wxMenu::GetTitle() const -{ - return m_title; -} +/* void wxMenu::SetLabel(int id, const wxString& label) { @@ -418,12 +458,12 @@ void wxMenu::SetLabel(int id, const wxString& label) if (item->GetSubMenu()==NULL) { wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_macMenuHandle , index , maclabel ) ; + ::SetMenuItemText( m_hMenu , index , maclabel ) ; } else { wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_macMenuHandle , index , maclabel ) ; + ::SetMenuItemText( m_hMenu , index , maclabel ) ; } item->SetName(label); } @@ -502,60 +542,96 @@ wxString wxMenu::GetHelpString (int itemId) const wxString str(""); return (item == NULL) ? str : item->GetHelp(); } +*/ -void wxMenu::ProcessCommand(wxCommandEvent & event) +bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; +#if WXWIN_COMPATIBILITY // Try a callback if (m_callback) { - (void) (*(m_callback)) (*this, event); - processed = TRUE; + (void)(*(m_callback))(*this, event); + processed = TRUE; } +#endif WXWIN_COMPATIBILITY // Try the menu's event handler if ( !processed && GetEventHandler()) { - processed = GetEventHandler()->ProcessEvent(event); + processed = GetEventHandler()->ProcessEvent(event); } - // Try the window the menu was popped up from (and up - // through the hierarchy) - if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); + // Try the window the menu was popped up from (and up through the + // hierarchy) + wxWindow *win = GetInvokingWindow(); + if ( !processed && win ) + processed = win->GetEventHandler()->ProcessEvent(event); + + return processed; +} + + +// --------------------------------------------------------------------------- +// other +// --------------------------------------------------------------------------- + +void wxMenu::Attach(wxMenuBar *menubar) +{ + // menu can be in at most one menubar because otherwise they would both + // delete the menu pointer + wxASSERT_MSG( !m_menuBar, wxT("menu belongs to 2 menubars, expect a crash") ); + + m_menuBar = menubar; } +void wxMenu::Detach() +{ + wxASSERT_MSG( m_menuBar, wxT("can't detach menu if it's not attached") ); + + m_menuBar = NULL; +} + +wxWindow *wxMenu::GetWindow() const +{ + if ( m_invokingWindow != NULL ) + return m_invokingWindow; + else if ( m_menuBar != NULL) + return m_menuBar->GetFrame(); + + return NULL; +} +/* bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) { menu->SetInvokingWindow(this); ClientToScreen( &x , &y ) ; - ::InsertMenu( menu->m_macMenuHandle , -1 ) ; - long menuResult = ::PopUpMenuSelect(menu->m_macMenuHandle ,y,x, 0) ; + ::InsertMenu( menu->m_hMenu , -1 ) ; + long menuResult = ::PopUpMenuSelect(menu->m_hMenu ,y,x, 0) ; menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; ::DeleteMenu( menu->m_macMenuId ) ; menu->SetInvokingWindow(NULL); return TRUE; } - +*/ // helper functions returning the mac menu position for a certain item, note that this is // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0 int wxMenu::MacGetIndexFromId( int id ) { - wxNode *node; - wxMenuItem *item; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + size_t pos; + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( pos = 0; node; pos++ ) { - item = (wxMenuItem *)node->Data(); - if (item->GetId() == id) - break; - } + if ( node->GetData()->GetId() == id ) + break; + node = node->GetNext(); + } + if (!node) return 0; @@ -564,13 +640,14 @@ int wxMenu::MacGetIndexFromId( int id ) int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem ) { - wxNode *node; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + size_t pos; + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( pos = 0; node; pos++ ) { - if ((wxMenuItem *)node->Data() == pItem) - break; + if ( node->GetData() == pItem ) + break; + + node = node->GetNext(); } if (!node) @@ -581,11 +658,10 @@ int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem ) void wxMenu::MacEnableMenu( bool bDoEnable ) { - m_macMenuEnabled = bDoEnable ; if ( bDoEnable ) - UMAEnableMenuItem( m_macMenuHandle , 0 ) ; + UMAEnableMenuItem( m_hMenu , 0 ) ; else - UMADisableMenuItem( m_macMenuHandle , 0 ) ; + UMADisableMenuItem( m_hMenu , 0 ) ; ::DrawMenuBar() ; } @@ -597,7 +673,7 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in if ( m_macMenuId == macMenuId ) { - node = m_menuItems.Nth(macMenuItemNum-1); + node = GetMenuItems().Nth(macMenuItemNum-1); if (node) { wxMenuItem *pItem = (wxMenuItem*)node->Data(); @@ -605,36 +681,15 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, pItem->GetId()); event.m_timeStamp = when; event.SetEventObject(handler); - event.SetInt( pItem->GetId() ); - - { - bool processed = false ; - - // Try a callback - if (m_callback) - { - (void) (*(m_callback)) (*this, event); - processed = TRUE; - } - - // Try the menu's event handler - if ( !processed && handler) - { - processed = handler->ProcessEvent(event); - } - - // Try the window the menu was popped up from (and up - // through the hierarchy) - if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); - } + event.SetInt( pItem->GetId() ); + ProcessCommand( event ) ; return true ; } } else if ( macMenuId == kHMHelpMenuID ) { int menuItem = formerHelpMenuItems ; - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + for (pos = 0, node = GetMenuItems().First(); node; node = node->Next(), pos++) { wxMenuItem * pItem = (wxMenuItem *) node->Data() ; @@ -652,40 +707,19 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, pItem->GetId()); event.m_timeStamp = when; event.SetEventObject(handler); - event.SetInt( pItem->GetId() ); - - { - bool processed = false ; - // Try a callback - if (m_callback) - { - (void) (*(m_callback)) (*this, event); - processed = TRUE; - } - - // Try the menu's event handler - if ( !processed && handler) - { - processed = handler->ProcessEvent(event); - } - - // Try the window the menu was popped up from (and up - // through the hierarchy) - if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); - } - + event.SetInt( pItem->GetId() ); + ProcessCommand( event ) ; return true ; } } } } - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + for (pos = 0, node = GetMenuItems().First(); node; node = node->Next(), pos++) { - wxMenuItem * pItem = (wxMenuItem *) node->Data() ; + wxMenuItem * pItem = (wxMenuItem *) node->Data() ; - wxMenu *pSubMenu = pItem->GetSubMenu() ; + wxMenu *pSubMenu = pItem->GetSubMenu() ; if ( pSubMenu != NULL ) { if ( pSubMenu->MacMenuSelect( handler , when , macMenuId , macMenuItemNum ) ) @@ -717,25 +751,26 @@ auto-merge for MDI in case this will be necessary wxMenuBar* wxMenuBar::s_macInstalledMenuBar = NULL ; -wxMenuBar::wxMenuBar() +void wxMenuBar::Init() { m_eventHandler = this; - m_menuCount = 0; - m_menus = NULL; - m_titles = NULL; m_menuBarFrame = NULL; } -wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[]) + +wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) { - m_eventHandler = this; - m_menuCount = n; - m_menus = menus; - m_titles = new wxString[n]; - int i; - for ( i = 0; i < n; i++ ) - m_titles[i] = titles[i]; - m_menuBarFrame = NULL; + Init(); + + m_titles.Alloc(count); + + for ( int i = 0; i < count; i++ ) + { + m_menus.Append(menus[i]); + m_titles.Add(titles[i]); + + menus[i]->Attach(this); + } } wxMenuBar::~wxMenuBar() @@ -746,14 +781,13 @@ wxMenuBar::~wxMenuBar() s_macInstalledMenuBar = NULL; } - int i; - for (i = 0; i < m_menuCount; i++) - { - delete m_menus[i]; - } - delete[] m_menus; - delete[] m_titles; +} + +void wxMenuBar::Refresh() +{ + wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") ); + DrawMenuBar(); } void wxMenuBar::MacInstallMenuBar() @@ -767,7 +801,7 @@ void wxMenuBar::MacInstallMenuBar() MenuHandle menu = ::GetMenuHandle( kwxMacAppleMenuId ) ; ::AppendResMenu(menu, 'DRVR'); - for (int i = 0; i < m_menuCount; i++) + for (int i = 0; i < m_menus.GetCount(); i++) { Str255 label; wxNode *node; @@ -789,7 +823,7 @@ void wxMenuBar::MacInstallMenuBar() formerHelpMenuItems = CountMenuItems( mh ) ; } - for (pos = 0 , node = menu->m_menuItems.First(); node; node = node->Next(), pos++) + for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; @@ -800,7 +834,7 @@ void wxMenuBar::MacInstallMenuBar() else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , item->GetName(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu + wxMacBuildMenuString( label , NULL , NULL , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu if ( label[0] == 0 ) { // we cannot add empty menus on mac @@ -824,17 +858,17 @@ void wxMenuBar::MacInstallMenuBar() else { wxMacBuildMenuString( label, NULL , NULL , m_titles[i] , false ); - UMASetMenuTitle( menu->m_macMenuHandle , label ) ; - for (pos = 0, node = menu->m_menuItems.First(); node; node = node->Next(), pos++) + UMASetMenuTitle( menu->GetHMenu() , label ) ; + for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; if (subMenu) { - ::InsertMenu( subMenu->m_macMenuHandle , -1 ) ; + ::InsertMenu( subMenu->GetHMenu() , -1 ) ; } } - ::InsertMenu(m_menus[i]->m_macMenuHandle, 0); + ::InsertMenu(m_menus[i]->GetHMenu(), 0); } } ::DrawMenuBar() ; @@ -842,263 +876,139 @@ void wxMenuBar::MacInstallMenuBar() s_macInstalledMenuBar = this; } - -// Must only be used AFTER menu has been attached to frame, -// otherwise use individual menus to enable/disable items -void wxMenuBar::Enable(int id, bool flag) +void wxMenuBar::EnableTop(size_t pos, bool enable) { - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return; - - item->Enable( flag ) ; -} - -void wxMenuBar::EnableTop(int pos, bool flag) -{ - m_menus[pos]->MacEnableMenu( flag ) ; -} - -// Must only be used AFTER menu has been attached to frame, -// otherwise use individual menus -void wxMenuBar::Check(int id, bool flag) -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return; - - if (!item->IsCheckable()) - return ; - - item->Check( flag ) ; -} - -bool wxMenuBar::Checked(int id) const -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return FALSE; - - if (!item->IsCheckable()) - return FALSE ; - - return item->IsChecked() ; + wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") ); + m_menus[pos]->MacEnableMenu( enable ) ; + Refresh(); } -bool wxMenuBar::Enabled(int id) const +void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return FALSE; - - if ( !item->IsEnabled() ) - return FALSE ; - - if ( itemMenu->m_macMenuEnabled == false ) - return FALSE ; - - while( itemMenu->m_parent ) - { - itemMenu = (wxMenu*) itemMenu->m_parent ; - if ( itemMenu->IsKindOf( CLASSINFO( wxMenu ) ) ) - { - if ( itemMenu->m_macMenuEnabled == false ) - return FALSE ; - } - } - - return TRUE ; -} + wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); + m_titles[pos] = label; -void wxMenuBar::SetLabel(int id, const wxString& label) -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - - if (!item) + if ( !IsAttached() ) + { return; + } - itemMenu->SetLabel( id , label ) ; -} - -wxString wxMenuBar::GetLabel(int id) const -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - - if (!item) - return wxString(""); - - return itemMenu->GetLabel( id ) ; -} - -void wxMenuBar::SetLabelTop(int pos, const wxString& label) -{ m_menus[pos]->SetTitle( label ) ; -} - -wxString wxMenuBar::GetLabelTop(int pos) const -{ - return m_menus[pos]->GetTitle() ; -} - -bool wxMenuBar::OnDelete(wxMenu *a_menu, int pos) -{ - if (s_macInstalledMenuBar == this) + if (wxMenuBar::s_macInstalledMenuBar == this) // are we currently installed ? { - ::DeleteMenu( a_menu->m_macMenuId /* m_menus[pos]->m_macMenuId */ ) ; + ::SetMenuBar( GetMenuBar() ) ; ::InvalMenuBar() ; - return TRUE ; - } - else - { - return TRUE ; } } -bool wxMenuBar::OnAppend(wxMenu *a_menu, const char *title) +wxString wxMenuBar::GetLabelTop(size_t pos) const { - if (!a_menu->m_macMenuHandle) - return FALSE; + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetLabelTop") ); - if (s_macInstalledMenuBar == this) - { - Str255 label; - wxMacBuildMenuString( label, NULL , NULL , title , false ); - UMASetMenuTitle( a_menu->m_macMenuHandle , label ) ; - ::InsertMenu( a_menu->m_macMenuHandle , 0 ) ; - ::InvalMenuBar() ; - return TRUE ; - } - else - { - return TRUE ; - } + return m_titles[pos]; } -void wxMenuBar::Append (wxMenu * menu, const wxString& title) +int wxMenuBar::FindMenu(const wxString& title) { - if (!OnAppend(menu, title)) - return; + wxString menuTitle = wxStripMenuCodes(title); - m_menuCount ++; - wxMenu **new_menus = new wxMenu *[m_menuCount]; - wxString *new_titles = new wxString[m_menuCount]; - int i; - - for (i = 0; i < m_menuCount - 1; i++) - { - new_menus[i] = m_menus[i]; - m_menus[i] = NULL; - new_titles[i] = m_titles[i]; - m_titles[i] = ""; - } - if (m_menus) + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) { - delete[]m_menus; - delete[]m_titles; + wxString title = wxStripMenuCodes(m_titles[i]); + if ( menuTitle == title ) + return i; } - m_menus = new_menus; - m_titles = new_titles; - m_menus[m_menuCount - 1] = (wxMenu *)menu; - m_titles[m_menuCount - 1] = title; + return wxNOT_FOUND; - ((wxMenu *)menu)->m_menuBar = (wxMenuBar *) this; - ((wxMenu *)menu)->SetParent(this); } -void wxMenuBar::Delete(wxMenu * menu, int i) + +// --------------------------------------------------------------------------- +// wxMenuBar construction +// --------------------------------------------------------------------------- + +// --------------------------------------------------------------------------- +// wxMenuBar construction +// --------------------------------------------------------------------------- + +wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { - int j; - int ii = (int) i; + wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title); + if ( !menuOld ) + return FALSE; + m_titles[pos] = title; - if (menu != 0) - { - for (ii = 0; ii < m_menuCount; ii++) - { - if (m_menus[ii] == menu) - break; - } - if (ii >= m_menuCount) - return; - } else + if ( IsAttached() ) { - if (ii < 0 || ii >= m_menuCount) - return; - menu = m_menus[ii]; - } + if (s_macInstalledMenuBar == this) + { + ::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; + { + Str255 label; + wxMacBuildMenuString( label, NULL , NULL , title , false ); + UMASetMenuTitle( menu->GetHMenu() , label ) ; + if ( pos == m_menus.GetCount() - 1) + { + ::InsertMenu( menu->GetHMenu() , 0 ) ; + } + else + { + ::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; + } + } + } - if (!OnDelete(menu, ii)) - return; - menu->SetParent(NULL); +#if wxUSE_ACCEL + if ( menuOld->HasAccels() || menu->HasAccels() ) + { + // need to rebuild accell table + RebuildAccelTable(); + } +#endif // wxUSE_ACCEL - -- m_menuCount; - for (j = ii; j < m_menuCount; j++) - { - m_menus[j] = m_menus[j + 1]; - m_titles[j] = m_titles[j + 1]; + Refresh(); } -} -// Find the menu menuString, item itemString, and return the item id. -// Returns -1 if none found. -int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const -{ - char buf1[200]; - char buf2[200]; - wxStripMenuCodes ((char *)(const char *)menuString, buf1); - int i; - for (i = 0; i < m_menuCount; i++) - { - wxStripMenuCodes ((char *)(const char *)m_titles[i], buf2); - if (strcmp (buf1, buf2) == 0) - return m_menus[i]->FindItem (itemString); - } - return -1; + return menuOld; } -wxMenuItem *wxMenuBar::FindItemForId (int Id, wxMenu ** itemMenu) const +bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) { - if (itemMenu) - *itemMenu = NULL; + if ( !wxMenuBarBase::Insert(pos, menu, title) ) + return FALSE; - wxMenuItem *item = NULL; - int i; - for (i = 0; i < m_menuCount; i++) - if ((item = m_menus[i]->FindItemForId (Id, itemMenu))) - return item; - return NULL; -} + m_titles.Insert(title, pos); -void wxMenuBar::SetHelpString (int Id, const wxString& helpString) -{ - int i; - for (i = 0; i < m_menuCount; i++) + menu->Attach(this); + + if ( IsAttached() ) { - if (m_menus[i]->FindItemForId (Id)) + if ( pos == (size_t) -1 ) + { + ::InsertMenu( menu->GetHMenu() , 0 ) ; + } + else + { + ::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; + } + +#if wxUSE_ACCEL + if ( menu->HasAccels() ) { - m_menus[i]->SetHelpString (Id, helpString); - return; + // need to rebuild accell table + RebuildAccelTable(); } - } -} +#endif // wxUSE_ACCEL -wxString wxMenuBar::GetHelpString (int Id) const -{ - int i; - for (i = 0; i < m_menuCount; i++) - { - if (m_menus[i]->FindItemForId (Id)) - return wxString(m_menus[i]->GetHelpString (Id)); + Refresh(); } - return wxString(""); + + return TRUE; } void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) @@ -1115,9 +1025,9 @@ void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, } else { - for (int i = 0; i < m_menuCount; i++) + for (int i = 0; i < m_menus.GetCount() ; i++) { - if ( m_menus[i]->m_macMenuId == macMenuId || + if ( m_menus[i]->MacGetMenuId() == macMenuId || ( macMenuId == kHMHelpMenuID && ( m_titles[i] == "?" || m_titles[i] == wxApp::s_macHelpMenuTitleName ) ) ) { @@ -1131,7 +1041,7 @@ void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, } } - for (int i = 0; i < m_menuCount; i++) + for (int i = 0; i < m_menus.GetCount(); i++) { if ( m_menus[i]->MacMenuSelect( handler , when , macMenuId , macMenuItemNum ) ) { diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 9195fdc50a..ef67483ca3 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -37,24 +37,26 @@ // ----------- wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id, - const wxString& strName, const wxString& strHelp, + const wxString& text, const wxString& strHelp, bool bCheckable, - wxMenu *pSubMenu) : - m_bCheckable(bCheckable), - m_strName(strName), - m_strHelp(strHelp) + wxMenu *pSubMenu) { - wxASSERT( pParentMenu != NULL ); + wxASSERT( pParentMenu != NULL ); - m_pParentMenu = pParentMenu; - m_pSubMenu = pSubMenu; - m_idItem = id; - m_bEnabled = TRUE; + m_parentMenu = pParentMenu; + m_subMenu = pSubMenu; + m_isEnabled = TRUE; + m_isChecked = FALSE; + m_id = id; + m_text = text; + m_isCheckable = bCheckable; + m_help = strHelp; - if ( m_strName == "E&xit" ||m_strName == "Exit" ) - { - m_strName = "Quit\tCtrl+Q" ; - } + + if ( m_text == "E&xit" ||m_text == "Exit" ) + { + m_text = "Quit\tCtrl+Q" ; + } } wxMenuItem::~wxMenuItem() @@ -64,53 +66,57 @@ wxMenuItem::~wxMenuItem() // misc // ---- +/* + // delete the sub menu void wxMenuItem::DeleteSubMenu() { - wxASSERT( m_pSubMenu != NULL ); + wxASSERT( m_subMenu != NULL ); - delete m_pSubMenu; - m_pSubMenu = NULL; + delete m_subMenu; + m_subMenu = NULL; } +*/ + // change item state // ----------------- void wxMenuItem::Enable(bool bDoEnable) { - if ( m_bEnabled != bDoEnable ) { - if ( m_pSubMenu == NULL ) + if ( m_isEnabled != bDoEnable ) { + if ( m_subMenu == NULL ) { // normal menu item - if ( m_pParentMenu->m_macMenuHandle ) + if ( m_parentMenu->GetHMenu() ) { - int index = m_pParentMenu->MacGetIndexFromItem( this ) ; + int index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( index >= 1 ) { if ( bDoEnable ) - UMAEnableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ; else - UMADisableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ; } } } else { // submenu - if ( m_pParentMenu->m_macMenuHandle ) + if ( m_parentMenu->GetHMenu() ) { - int index = m_pParentMenu->MacGetIndexFromItem( this ) ; + int index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( index >= 1 ) { if ( bDoEnable ) - UMAEnableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ; else - UMADisableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ; } } } - m_bEnabled = bDoEnable; + m_isEnabled = bDoEnable; } } @@ -118,18 +124,18 @@ void wxMenuItem::Check(bool bDoCheck) { wxCHECK_RET( IsCheckable(), "only checkable items may be checked" ); - if ( m_bChecked != bDoCheck ) + if ( m_isChecked != bDoCheck ) { - m_bChecked = bDoCheck; - if ( m_pParentMenu->m_macMenuHandle ) + m_isChecked = bDoCheck; + if ( m_parentMenu->GetHMenu() ) { - int index = m_pParentMenu->MacGetIndexFromItem( this ) ; + int index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( index >= 1 ) { if ( bDoCheck ) - ::SetItemMark( m_pParentMenu->m_macMenuHandle , index , 0x12 ) ; // checkmark + ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark else - ::SetItemMark( m_pParentMenu->m_macMenuHandle , index , 0 ) ; // no mark + ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark } } } diff --git a/src/mac/carbon/print.cpp b/src/mac/carbon/print.cpp index 1064058925..e69de29bb2 100644 --- a/src/mac/carbon/print.cpp +++ b/src/mac/carbon/print.cpp @@ -1,82 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: print.cpp -// Purpose: Print framework -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 -// RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "print.h" -#endif - -#include "wx/mac/print.h" -#include "wx/mac/printdlg.h" - -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxPrinter, wxPrinterBase) -IMPLEMENT_CLASS(wxPrintPreview, wxPrintPreviewBase) -#endif - -/* - * Printer - */ - -wxPrinter::wxPrinter(wxPrintData *data): - wxPrinterBase(data) -{ -} - -wxPrinter::~wxPrinter() -{ -} - -bool wxPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) -{ - // TODO. See wxPostScriptPrinter::Print for hints. - return FALSE; -} - -bool wxPrinter::PrintDialog(wxWindow *parent) -{ - wxPrintDialog dialog(parent, & m_printData); - return (dialog.ShowModal() == wxID_OK); -} - -bool wxPrinter::Setup(wxWindow *parent) -{ - wxPrintDialog dialog(parent, & m_printData); - dialog.GetPrintData().SetSetupDialog(TRUE); - return (dialog.ShowModal() == wxID_OK); -} - -/* - * Print preview - */ - -wxPrintPreview::wxPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): - wxPrintPreviewBase(printout, printoutForPrinting, data) -{ - DetermineScaling(); -} - -wxPrintPreview::~wxPrintPreview() -{ -} - -bool wxPrintPreview::Print(bool interactive) -{ - if (!m_printPrintout) - return FALSE; - wxPrinter printer(&m_printData); - return printer.Print(m_previewFrame, m_printPrintout, interactive); -} - -void wxPrintPreview::DetermineScaling() -{ - // TODO -} - diff --git a/src/mac/carbon/printdlg.cpp b/src/mac/carbon/printdlg.cpp index 18c7a8427e..5f914ddbfd 100644 --- a/src/mac/carbon/printdlg.cpp +++ b/src/mac/carbon/printdlg.cpp @@ -14,7 +14,7 @@ #endif #include "wx/object.h" -#include "wx/mac/printdlg.h" +#include "wx/printdlg.h" #include "wx/dcprint.h" // Use generic page setup dialog: use your own native one if one exists. @@ -24,30 +24,43 @@ IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog) IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) #endif -wxPrintDialog::wxPrintDialog(): - wxDialog() +wxPrintDialog::wxPrintDialog() { m_dialogParent = NULL; + m_printerDC = NULL; + m_destroyDC = TRUE; } -wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data): - wxDialog() +wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data) { Create(p, data); } -bool wxPrintDialog::Create(wxWindow *p, wxPrintData* data) +wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data) +{ + wxPrintDialogData data2; + if ( data ) + data2 = *data; + + Create(p, &data2); +} + +bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) { m_dialogParent = p; + m_printerDC = NULL; + m_destroyDC = TRUE; if ( data ) - m_printData = *data; + m_printDialogData = *data; return TRUE; } wxPrintDialog::~wxPrintDialog() { + if (m_destroyDC && m_printerDC) + delete m_printerDC; } int wxPrintDialog::ShowModal() @@ -60,10 +73,10 @@ int wxPrintDialog::ShowModal() if ( !err ) { - m_printData.ConvertToNative() ; - if ( m_printData.macPrintInfo && ::PrJobDialog( m_printData.macPrintInfo ) ) + m_printDialogData.ConvertToNative() ; + if ( m_printDialogData.m_macPrintInfo && ::PrJobDialog( m_printDialogData.m_macPrintInfo ) ) { - m_printData.ConvertFromNative() ; + m_printDialogData.ConvertFromNative() ; result = wxID_OK ; } @@ -80,7 +93,7 @@ int wxPrintDialog::ShowModal() wxDC *wxPrintDialog::GetPrintDC() { - return new wxPrinterDC( m_printData ) ; + return new wxPrinterDC( m_printDialogData.GetPrintData() ) ; } /* diff --git a/src/mac/carbon/radiobox.cpp b/src/mac/carbon/radiobox.cpp index 3393009f47..b1f4dbf615 100644 --- a/src/mac/carbon/radiobox.cpp +++ b/src/mac/carbon/radiobox.cpp @@ -67,17 +67,6 @@ wxRadioBox::~wxRadioBox() // TODO } -wxString wxRadioBox::GetLabel(int item) const -{ - // TODO - return wxString(""); -} - -void wxRadioBox::SetLabel(int item, const wxString& label) -{ - // TODO -} - int wxRadioBox::FindString(const wxString& s) const { // TODO @@ -106,28 +95,28 @@ wxString wxRadioBox::GetString(int n) const return wxString(""); } -void wxRadioBox::SetSize(int x, int y, int width, int height, int sizeFlags) +void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - wxControl::SetSize( x , y , width , height , sizeFlags ) ; + wxControl::DoSetSize( x , y , width , height , sizeFlags ) ; } void wxRadioBox::GetSize(int *width, int *height) const { - // TODO + wxControl::GetSize( width , height ) ; } void wxRadioBox::GetPosition(int *x, int *y) const { - // TODO + wxControl::GetPosition( x , y ) ; } -wxString wxRadioBox::GetLabel() const +wxString wxRadioBox::GetLabel( int item ) const { // TODO return wxString(""); } -void wxRadioBox::SetLabel(const wxString& label) +void wxRadioBox::SetLabel(int item , const wxString& label) { // TODO } @@ -139,23 +128,18 @@ void wxRadioBox::SetFocus() bool wxRadioBox::Show(bool show) { - // TODO - return wxWindow::Show( show ) ; + return wxControl::Show( show ) ; } // Enable a specific button void wxRadioBox::Enable(int item, bool enable) { - wxControl::Enable(enable); - // TODO } // Enable all controls -void wxRadioBox::Enable(bool enable) +bool wxRadioBox::Enable(bool enable) { - wxControl::Enable(enable); - - // TODO + return wxControl::Enable(enable); } // Show a specific button diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index 8f3e1533b8..d91374445a 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -16,16 +16,19 @@ #include "wx/spinbutt.h" #include "wx/mac/uma.h" +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- + #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) + IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) + IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); #endif -wxSpinButton::wxSpinButton() -{ - m_min = 0; - m_max = 100; -} - bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { @@ -78,14 +81,6 @@ void wxSpinButton::SetRange(int minVal, int maxVal) m_max = maxVal; } -// Spin event -IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) - -wxSpinEvent::wxSpinEvent(wxEventType commandType, int id): - wxScrollEvent(commandType, id) -{ -} - void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) { if ( m_macControl == NULL ) diff --git a/src/mac/carbon/stattext.cpp b/src/mac/carbon/stattext.cpp index 14c69f1d96..54f6eb4e58 100644 --- a/src/mac/carbon/stattext.cpp +++ b/src/mac/carbon/stattext.cpp @@ -47,7 +47,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, void wxStaticText::SetLabel(const wxString& st , bool resize ) { - m_label = st ; + SetTitle( st ) ; wxString label ; if( wxApp::s_macDefaultEncodingIsPC ) diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index d553477f93..21648fc476 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -409,73 +409,51 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) void wxTextCtrl::OnChar(wxKeyEvent& event) { - bool handleIt = true ; switch( event.KeyCode() ) { case WXK_RETURN: { -/* Oh yes it will, because we also specify DLGC_WANTCHARS - wxASSERT_MSG( m_windowStyle & wxTE_PROCESS_ENTER, - "this text ctrl should never receive return" ); -*/ - - if ( (m_windowStyle & wxTE_MULTILINE) == 0 ) + if ( !(m_windowStyle & wxTE_MULTILINE) ) { - wxWindow* parent = GetParent() ; - while( parent ) - { - if ( parent->GetDefaultItem() ) - { - wxButton *defaultBtn = parent->GetDefaultItem() ; - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, defaultBtn->GetId() ); - event.SetEventObject(defaultBtn); - defaultBtn->Command(event); - return ; - } - parent = parent->GetParent() ; - } ; + wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + event.SetEventObject( this ); + if ( GetEventHandler()->ProcessEvent(event) ) + return; } + //else: multiline controls need Enter for themselves + break; } case WXK_TAB: - // only produce navigation event if we don't process TAB ourself or - // if it's a Shift-Tab keypress (we assume nobody will ever need - // this key combo for himself) + // always produce navigation event - even if we process TAB + // ourselves the fact that we got here means that the user code + // decided to skip processing of this TAB - probably to let it + // do its default job. // // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is // handled by Windows - if ( event.ShiftDown() || !(m_windowStyle & wxTE_PROCESS_TAB) ) { wxNavigationKeyEvent eventNav; eventNav.SetDirection(!event.ShiftDown()); eventNav.SetWindowChange(FALSE); eventNav.SetEventObject(this); - + if ( GetEventHandler()->ProcessEvent(eventNav) ) return; } break; + + default: + event.Skip(); + return; } - if ( handleIt ) - { - EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; - if ( keychar >= 0x20 ) - { - { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - wxString val(GetValue()); - if ( !val.IsNull() ) - event.m_commandString = WXSTRINGCAST val; - event.SetEventObject( this ); - ProcessCommand(event); - } - } - } + + // don't just call event.Skip() because this will cause TABs and ENTERs + // be passed upwards and we don't always want this - instead process it + // right here + + // FIXME + event.Skip(); } // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp index 8dd23bdce9..3dca96a6fa 100644 --- a/src/mac/carbon/thread.cpp +++ b/src/mac/carbon/thread.cpp @@ -1,71 +1,146 @@ ///////////////////////////////////////////////////////////////////////////// // Name: thread.cpp -// Purpose: wxThread Implementation. For Unix ports, see e.g. src/gtk +// Purpose: wxThread Implementation // Author: Original from Wolfram Gloger/Guilhem Lavaux -// Modified by: +// Modified by: Vadim Zeitlin to make it work :-) // Created: 04/22/98 // RCS-ID: $Id$ -// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998) +// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998), +// Vadim Zeitlin (1999) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "thread.h" + #pragma implementation "thread.h" #endif +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#if wxUSE_THREADS + +#include + +#include + #include "wx/module.h" #include "wx/thread.h" -#include "wx/utils.h" -enum thread_state { - STATE_IDLE = 0, - STATE_RUNNING, - STATE_CANCELED, - STATE_EXITED +// the possible states of the thread ("=>" shows all possible transitions from +// this state) +enum wxThreadState +{ + STATE_NEW, // didn't start execution yet (=> RUNNING) + STATE_RUNNING, // thread is running (=> PAUSED, CANCELED) + STATE_PAUSED, // thread is temporarily suspended (=> RUNNING) + STATE_CANCELED, // thread should terminate a.s.a.p. (=> EXITED) + STATE_EXITED // thread is terminating }; -#if wxUSE_THREADS +// ---------------------------------------------------------------------------- +// static variables +// ---------------------------------------------------------------------------- -///////////////////////////////////////////////////////////////////////////// -// Static variables -///////////////////////////////////////////////////////////////////////////// +// if it's FALSE, some secondary thread is holding the GUI lock +static bool s_bGuiOwnedByMainThread = TRUE; -wxMutex *wxMainMutex; // controls access to all GUI functions +// critical section which controls access to all GUI functions: any secondary +// thread (i.e. except the main one) must enter this crit section before doing +// any GUI calls +static wxCriticalSection *s_critsectGui = NULL; -///////////////////////////////////////////////////////////////////////////// -// Windows implementation -///////////////////////////////////////////////////////////////////////////// +// critical section which protects s_nWaitingForGui variable +static wxCriticalSection *s_critsectWaitingForGui = NULL; + +// number of threads waiting for GUI in wxMutexGuiEnter() +static size_t s_nWaitingForGui = 0; + +// are we waiting for a thread termination? +static bool s_waitingForThread = FALSE; -class wxMutexInternal { +// ============================================================================ +// Windows implementation of thread classes +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxMutex implementation +// ---------------------------------------------------------------------------- +class wxMutexInternal +{ public: - // TODO: internal mutex handle + Handle p_mutex; }; wxMutex::wxMutex() { p_internal = new wxMutexInternal; - // TODO: create internal mutext handle +// p_internal->p_mutex = CreateMutex(NULL, FALSE, NULL); + if ( !p_internal->p_mutex ) + { + wxLogSysError(_("Can not create mutex.")); + } + m_locked = 0; } wxMutex::~wxMutex() { if (m_locked > 0) - wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked); - // TODO: free internal mutext handle + wxLogDebug(wxT("Warning: freeing a locked mutex (%d locks)."), m_locked); +// CloseHandle(p_internal->p_mutex); } wxMutexError wxMutex::Lock() { - // TODO +/* + DWORD ret; + + ret = WaitForSingleObject(p_internal->p_mutex, INFINITE); + switch ( ret ) + { + case WAIT_ABANDONED: + return wxMUTEX_BUSY; + + case WAIT_OBJECT_0: + // ok + break; + + case WAIT_FAILED: + wxLogSysError(_("Couldn't acquire a mutex lock")); + return wxMUTEX_MISC_ERROR; + + case WAIT_TIMEOUT: + default: + wxFAIL_MSG(wxT("impossible return value in wxMutex::Lock")); + } +*/ m_locked++; return wxMUTEX_NO_ERROR; } wxMutexError wxMutex::TryLock() { - // TODO +/* + DWORD ret; + + ret = WaitForSingleObject(p_internal->p_mutex, 0); + if (ret == WAIT_TIMEOUT || ret == WAIT_ABANDONED) + return wxMUTEX_BUSY; + m_locked++; +*/ return wxMUTEX_NO_ERROR; } @@ -73,192 +148,715 @@ wxMutexError wxMutex::Unlock() { if (m_locked > 0) m_locked--; - - // TODO +/* + BOOL ret = ReleaseMutex(p_internal->p_mutex); + if ( ret == 0 ) + { + wxLogSysError(_("Couldn't release a mutex")); + return wxMUTEX_MISC_ERROR; + } +*/ return wxMUTEX_NO_ERROR; } -class wxConditionInternal { +// ---------------------------------------------------------------------------- +// wxCondition implementation +// ---------------------------------------------------------------------------- + +class wxConditionInternal +{ public: - // TODO: internal handle - int waiters; + Handle event; + int waiters; }; wxCondition::wxCondition() { p_internal = new wxConditionInternal; - // TODO: create internal handle +// p_internal->event = CreateEvent(NULL, FALSE, FALSE, NULL); + if ( !p_internal->event ) + { + wxLogSysError(_("Can not create event object.")); + } + p_internal->waiters = 0; } wxCondition::~wxCondition() { - // TODO: destroy internal handle +// CloseHandle(p_internal->event); } void wxCondition::Wait(wxMutex& mutex) { mutex.Unlock(); p_internal->waiters++; - // TODO wait here +// WaitForSingleObject(p_internal->event, INFINITE); p_internal->waiters--; mutex.Lock(); } -bool wxCondition::Wait(wxMutex& mutex, unsigned long sec, +bool wxCondition::Wait(wxMutex& mutex, + unsigned long sec, unsigned long nsec) { +// DWORD ret; + mutex.Unlock(); p_internal->waiters++; - - // TODO wait here + // ret = WaitForSingleObject(p_internal->event, (sec*1000)+(nsec/1000000)); p_internal->waiters--; mutex.Lock(); - return FALSE; + return TRUE; // false for timeout } void wxCondition::Signal() { - // TODO +// SetEvent(p_internal->event); } void wxCondition::Broadcast() { - // TODO + int i; + + for (i=0;iwaiters;i++) + { +// if ( SetEvent(p_internal->event) == 0 ) + { + wxLogSysError(_("Couldn't change the state of event object.")); + } + } } -class wxThreadInternal { +// ---------------------------------------------------------------------------- +// wxCriticalSection implementation +// ---------------------------------------------------------------------------- + +class wxCriticalSectionInternal +{ public: - // TODO + // init the critical section object + wxCriticalSectionInternal() + { /* ::InitializeCriticalSection(&m_data);*/ } + + // implicit cast to the associated data + operator Handle *() { return &m_data; } + + // free the associated ressources + ~wxCriticalSectionInternal() + { /* ::DeleteCriticalSection(&m_data); */} + +private: + Handle m_data; }; +wxCriticalSection::wxCriticalSection() +{ + m_critsect = new wxCriticalSectionInternal; +} + +wxCriticalSection::~wxCriticalSection() +{ + delete m_critsect; +} + +void wxCriticalSection::Enter() +{ +// ::EnterCriticalSection(*m_critsect); +} + +void wxCriticalSection::Leave() +{ +// ::LeaveCriticalSection(*m_critsect); +} + +// ---------------------------------------------------------------------------- +// wxThread implementation +// ---------------------------------------------------------------------------- + +// wxThreadInternal class +// ---------------------- + +/* +class wxThreadInternal +{ +public: + wxThreadInternal() + { + m_hThread = 0; + m_state = STATE_NEW; + m_priority = WXTHREAD_DEFAULT_PRIORITY; + } + + // create a new (suspended) thread (for the given thread object) + bool Create(wxThread *thread); + + // suspend/resume/terminate + bool Suspend(); + bool Resume(); + void Cancel() { m_state = STATE_CANCELED; } + + // thread state + void SetState(wxThreadState state) { m_state = state; } + wxThreadState GetState() const { return m_state; } + + // thread priority + void SetPriority(unsigned int priority) { m_priority = priority; } + unsigned int GetPriority() const { return m_priority; } + + // thread handle and id + HANDLE GetHandle() const { return m_hThread; } + DWORD GetId() const { return m_tid; } + + // thread function + static DWORD WinThreadStart(wxThread *thread); + +private: + Handle m_hThread; // handle of the thread + wxThreadState m_state; // state, see wxThreadState enum + unsigned int m_priority; // thread priority in "wx" units + ThreadId m_tid; // thread id +}; + +DWORD wxThreadInternal::WinThreadStart(wxThread *thread) +{ + // store the thread object in the TLS + if ( !::TlsSetValue(s_tlsThisThread, thread) ) + { + wxLogSysError(_("Can not start thread: error writing TLS.")); + + return (DWORD)-1; + } + + DWORD ret = (DWORD)thread->Entry(); + thread->p_internal->SetState(STATE_EXITED); + thread->OnExit(); + + delete thread; + + return ret; +} + +bool wxThreadInternal::Create(wxThread *thread) +{ + m_hThread = ::CreateThread + ( + NULL, // default security + 0, // default stack size + (LPTHREAD_START_ROUTINE) // thread entry point + wxThreadInternal::WinThreadStart, // + (LPVOID)thread, // parameter + CREATE_SUSPENDED, // flags + &m_tid // [out] thread id + ); + + if ( m_hThread == NULL ) + { + wxLogSysError(_("Can't create thread")); + + return FALSE; + } + + // translate wxWindows priority to the Windows one + int win_priority; + if (m_priority <= 20) + win_priority = THREAD_PRIORITY_LOWEST; + else if (m_priority <= 40) + win_priority = THREAD_PRIORITY_BELOW_NORMAL; + else if (m_priority <= 60) + win_priority = THREAD_PRIORITY_NORMAL; + else if (m_priority <= 80) + win_priority = THREAD_PRIORITY_ABOVE_NORMAL; + else if (m_priority <= 100) + win_priority = THREAD_PRIORITY_HIGHEST; + else + { + wxFAIL_MSG(wxT("invalid value of thread priority parameter")); + win_priority = THREAD_PRIORITY_NORMAL; + } + + if ( ::SetThreadPriority(m_hThread, win_priority) == 0 ) + { + wxLogSysError(_("Can't set thread priority")); + } + + return TRUE; +} + +bool wxThreadInternal::Suspend() +{ + DWORD nSuspendCount = ::SuspendThread(m_hThread); + if ( nSuspendCount == (DWORD)-1 ) + { + wxLogSysError(_("Can not suspend thread %x"), m_hThread); + + return FALSE; + } + + m_state = STATE_PAUSED; + + return TRUE; +} + +bool wxThreadInternal::Resume() +{ + DWORD nSuspendCount = ::ResumeThread(m_hThread); + if ( nSuspendCount == (DWORD)-1 ) + { + wxLogSysError(_("Can not resume thread %x"), m_hThread); + + return FALSE; + } + + m_state = STATE_RUNNING; + + return TRUE; +} + +// static functions +// ---------------- + +wxThread *wxThread::This() +{ + wxThread *thread = (wxThread *)::TlsGetValue(s_tlsThisThread); + + // be careful, 0 may be a valid return value as well + if ( !thread && (::GetLastError() != NO_ERROR) ) + { + wxLogSysError(_("Couldn't get the current thread pointer")); + + // return NULL... + } + + return thread; +} + +bool wxThread::IsMain() +{ + return ::GetCurrentThreadId() == s_idMainThread; +} + +#ifdef Yield + #undef Yield +#endif + +void wxThread::Yield() +{ + // 0 argument to Sleep() is special + ::Sleep(0); +} + +void wxThread::Sleep(unsigned long milliseconds) +{ + ::Sleep(milliseconds); +} + +// create/start thread +// ------------------- + wxThreadError wxThread::Create() { - // TODO + if ( !p_internal->Create(this) ) + return wxTHREAD_NO_RESOURCE; + return wxTHREAD_NO_ERROR; } -wxThreadError wxThread::Destroy() +wxThreadError wxThread::Run() { - // TODO - return wxTHREAD_NO_ERROR; + wxCriticalSectionLocker lock(m_critsect); + + if ( p_internal->GetState() != STATE_NEW ) + { + // actually, it may be almost any state at all, not only STATE_RUNNING + return wxTHREAD_RUNNING; + } + + return Resume(); } +// suspend/resume thread +// --------------------- + wxThreadError wxThread::Pause() { - // TODO - return wxTHREAD_NO_ERROR; + wxCriticalSectionLocker lock(m_critsect); + + return p_internal->Suspend() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR; } wxThreadError wxThread::Resume() { - // TODO - return wxTHREAD_NO_ERROR; -} + wxCriticalSectionLocker lock(m_critsect); -void wxThread::Exit(void *status) -{ - // TODO + return p_internal->Resume() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR; } -void wxThread::SetPriority(int prio) +// stopping thread +// --------------- + +wxThread::ExitCode wxThread::Delete() { - // TODO + ExitCode rc = 0; + + // Delete() is always safe to call, so consider all possible states + if ( IsPaused() ) + Resume(); + + if ( IsRunning() ) + { + if ( IsMain() ) + { + // set flag for wxIsWaitingForThread() + s_waitingForThread = TRUE; + + wxBeginBusyCursor(); + } + + HANDLE hThread; + { + wxCriticalSectionLocker lock(m_critsect); + + p_internal->Cancel(); + hThread = p_internal->GetHandle(); + } + + // we can't just wait for the thread to terminate because it might be + // calling some GUI functions and so it will never terminate before we + // process the Windows messages that result from these functions + DWORD result; + do + { + result = ::MsgWaitForMultipleObjects + ( + 1, // number of objects to wait for + &hThread, // the objects + FALSE, // don't wait for all objects + INFINITE, // no timeout + QS_ALLEVENTS // return as soon as there are any events + ); + + switch ( result ) + { + case 0xFFFFFFFF: + // error + wxLogSysError(_("Can not wait for thread termination")); + Kill(); + return (ExitCode)-1; + + case WAIT_OBJECT_0: + // thread we're waiting for terminated + break; + + case WAIT_OBJECT_0 + 1: + // new message arrived, process it + if ( !wxTheApp->DoMessage() ) + { + // WM_QUIT received: kill the thread + Kill(); + + return (ExitCode)-1; + } + + if ( IsMain() ) + { + // give the thread we're waiting for chance to exit + // from the GUI call it might have been in + if ( (s_nWaitingForGui > 0) && wxGuiOwnedByMainThread() ) + { + wxMutexGuiLeave(); + } + } + + break; + + default: + wxFAIL_MSG(wxT("unexpected result of MsgWaitForMultipleObject")); + } + } while ( result != WAIT_OBJECT_0 ); + + if ( IsMain() ) + { + s_waitingForThread = FALSE; + + wxEndBusyCursor(); + } + + if ( !::GetExitCodeThread(hThread, (LPDWORD)&rc) ) + { + wxLogLastError("GetExitCodeThread"); + + rc = (ExitCode)-1; + } + + wxASSERT_MSG( (LPVOID)rc != (LPVOID)STILL_ACTIVE, + wxT("thread must be already terminated.") ); + + ::CloseHandle(hThread); + } + + return rc; } -int wxThread::GetPriority() const +wxThreadError wxThread::Kill() { - // TODO - return 0; + if ( !IsRunning() ) + return wxTHREAD_NOT_RUNNING; + + if ( !::TerminateThread(p_internal->GetHandle(), (DWORD)-1) ) + { + wxLogSysError(_("Couldn't terminate thread")); + + return wxTHREAD_MISC_ERROR; + } + + delete this; + + return wxTHREAD_NO_ERROR; } -void wxThread::DeferDestroy(bool on) +void wxThread::Exit(void *status) { - // TODO + delete this; + + ::ExitThread((DWORD)status); + + wxFAIL_MSG(wxT("Couldn't return from ExitThread()!")); } -void wxThread::TestDestroy() +void wxThread::SetPriority(unsigned int prio) { - // TODO + wxCriticalSectionLocker lock(m_critsect); + + p_internal->SetPriority(prio); } -void *wxThread::Join() +unsigned int wxThread::GetPriority() const { - // TODO - return (void*) NULL; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return p_internal->GetPriority(); } unsigned long wxThread::GetID() const { - // TODO - return 0; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return (unsigned long)p_internal->GetId(); } -/* is this needed somewhere ? -wxThread *wxThread::GetThreadFromID(unsigned long id) +bool wxThread::IsRunning() const { - // TODO - return NULL; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return p_internal->GetState() == STATE_RUNNING; } -*/ bool wxThread::IsAlive() const { - // TODO - return FALSE; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return (p_internal->GetState() == STATE_RUNNING) || + (p_internal->GetState() == STATE_PAUSED); } -bool wxThread::IsRunning() const +bool wxThread::IsPaused() const { - // TODO - return FALSE; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return (p_internal->GetState() == STATE_PAUSED); } -bool wxThread::IsMain() +bool wxThread::TestDestroy() { - // TODO - return FALSE; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return p_internal->GetState() == STATE_CANCELED; } wxThread::wxThread() { p_internal = new wxThreadInternal(); - - // TODO } wxThread::~wxThread() { - Destroy(); - Join(); delete p_internal; } -// The default callback just joins the thread and throws away the result. -void wxThread::OnExit() -{ - Join(); -} +// ---------------------------------------------------------------------------- +// Automatic initialization for thread module +// ---------------------------------------------------------------------------- -// Automatic initialization -class wxThreadModule : public wxModule { - DECLARE_DYNAMIC_CLASS(wxThreadModule) +class wxThreadModule : public wxModule +{ public: - virtual bool OnInit() { - /* TODO p_mainid = GetCurrentThread(); */ - wxMainMutex = new wxMutex(); - wxMainMutex->Lock(); - return TRUE; - } + virtual bool OnInit(); + virtual void OnExit(); - // Global cleanup - virtual void OnExit() { - wxMainMutex->Unlock(); - delete wxMainMutex; - } +private: + DECLARE_DYNAMIC_CLASS(wxThreadModule) }; IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) -#endif +bool wxThreadModule::OnInit() +{ + // allocate TLS index for storing the pointer to the current thread + s_tlsThisThread = ::TlsAlloc(); + if ( s_tlsThisThread == 0xFFFFFFFF ) + { + // in normal circumstances it will only happen if all other + // TLS_MINIMUM_AVAILABLE (>= 64) indices are already taken - in other + // words, this should never happen + wxLogSysError(_("Thread module initialization failed: " + "impossible to allocate index in thread " + "local storage")); + + return FALSE; + } + + // main thread doesn't have associated wxThread object, so store 0 in the + // TLS instead + if ( !::TlsSetValue(s_tlsThisThread, (LPVOID)0) ) + { + ::TlsFree(s_tlsThisThread); + s_tlsThisThread = 0xFFFFFFFF; + + wxLogSysError(_("Thread module initialization failed: " + "can not store value in thread local storage")); + + return FALSE; + } + + s_critsectWaitingForGui = new wxCriticalSection(); + + s_critsectGui = new wxCriticalSection(); + s_critsectGui->Enter(); + + // no error return for GetCurrentThreadId() + s_idMainThread = ::GetCurrentThreadId(); + + return TRUE; +} + +void wxThreadModule::OnExit() +{ + if ( !::TlsFree(s_tlsThisThread) ) + { + wxLogLastError("TlsFree failed."); + } + + if ( s_critsectGui ) + { + s_critsectGui->Leave(); + delete s_critsectGui; + s_critsectGui = NULL; + } + + wxDELETE(s_critsectWaitingForGui); +} + +// ---------------------------------------------------------------------------- +// under Windows, these functions are implemented usign a critical section and +// not a mutex, so the names are a bit confusing +// ---------------------------------------------------------------------------- + +void WXDLLEXPORT wxMutexGuiEnter() +{ + // this would dead lock everything... + wxASSERT_MSG( !wxThread::IsMain(), + wxT("main thread doesn't want to block in wxMutexGuiEnter()!") ); + + // the order in which we enter the critical sections here is crucial!! + + // set the flag telling to the main thread that we want to do some GUI + { + wxCriticalSectionLocker enter(*s_critsectWaitingForGui); + + s_nWaitingForGui++; + } + + wxWakeUpMainThread(); + + // now we may block here because the main thread will soon let us in + // (during the next iteration of OnIdle()) + s_critsectGui->Enter(); +} + +void WXDLLEXPORT wxMutexGuiLeave() +{ + wxCriticalSectionLocker enter(*s_critsectWaitingForGui); + + if ( wxThread::IsMain() ) + { + s_bGuiOwnedByMainThread = FALSE; + } + else + { + // decrement the number of waiters now + wxASSERT_MSG( s_nWaitingForGui > 0, + wxT("calling wxMutexGuiLeave() without entering it first?") ); + + s_nWaitingForGui--; + + wxWakeUpMainThread(); + } + + s_critsectGui->Leave(); +} + +void WXDLLEXPORT wxMutexGuiLeaveOrEnter() +{ + wxASSERT_MSG( wxThread::IsMain(), + wxT("only main thread may call wxMutexGuiLeaveOrEnter()!") ); + + wxCriticalSectionLocker enter(*s_critsectWaitingForGui); + + if ( s_nWaitingForGui == 0 ) + { + // no threads are waiting for GUI - so we may acquire the lock without + // any danger (but only if we don't already have it) + if ( !wxGuiOwnedByMainThread() ) + { + s_critsectGui->Enter(); + + s_bGuiOwnedByMainThread = TRUE; + } + //else: already have it, nothing to do + } + else + { + // some threads are waiting, release the GUI lock if we have it + if ( wxGuiOwnedByMainThread() ) + { + wxMutexGuiLeave(); + } + //else: some other worker thread is doing GUI + } +} + +bool WXDLLEXPORT wxGuiOwnedByMainThread() +{ + return s_bGuiOwnedByMainThread; +} + +// wake up the main thread if it's in ::GetMessage() +void WXDLLEXPORT wxWakeUpMainThread() +{ + // sending any message would do - hopefully WM_NULL is harmless enough + if ( !::PostThreadMessage(s_idMainThread, WM_NULL, 0, 0) ) + { + // should never happen + wxLogLastError("PostThreadMessage(WM_NULL)"); + } +} + +bool WXDLLEXPORT wxIsWaitingForThread() +{ + return s_waitingForThread; +} +*/ + +#endif // wxUSE_THREADS diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index e8015acc3b..18ab38338a 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -54,59 +54,84 @@ wxWindow* gFocusWindow = NULL ; IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) - EVT_CHAR(wxWindow::OnChar) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) - EVT_PAINT(wxWindow::OnPaint) END_EVENT_TABLE() #endif -// Constructor -wxWindow::wxWindow() + +// =========================================================================== +// implementation +// =========================================================================== + +// --------------------------------------------------------------------------- +// wxWindow utility functions +// --------------------------------------------------------------------------- + +// Find an item given the Macintosh Window Reference + +wxList *wxWinMacWindowList = NULL; +wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef) { - Init() ; + wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); + if (!node) + return NULL; + return (wxWindow *)node->Data(); } +void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win) +{ + // adding NULL WindowRef is (first) surely a result of an error and + // (secondly) breaks menu command processing + wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); + + if ( !wxWinMacWindowList->Find((long)inWindowRef) ) + wxWinMacWindowList->Append((long)inWindowRef, win); +} + +void wxRemoveMacWindowAssociation(wxWindow *win) +{ + wxWinMacWindowList->DeleteObject(win); +} + +// ---------------------------------------------------------------------------- +// constructors and such +// ---------------------------------------------------------------------------- + void wxWindow::Init() { + // generic + InitBase(); + + // MSW specific + m_doubleClickAllowed = 0; + m_winCaptured = FALSE; + + m_isBeingDeleted = FALSE; + + m_useCtl3D = FALSE; + m_mouseInWindow = FALSE; + + m_xThumbSize = 0; + m_yThumbSize = 0; + m_backgroundTransparent = FALSE; + + // as all windows are created with WS_VISIBLE style... + m_isShown = TRUE; + m_macWindowData = NULL ; - m_isWindow = TRUE; + m_x = 0; m_y = 0 ; m_width = 0 ; m_height = 0 ; - // these are the defaults for MSW - m_macShown = true ; - m_macEnabled = true ; - // Generic - m_windowId = 0; - m_windowStyle = 0; - m_windowParent = NULL; - m_windowEventHandler = this; - m_windowName = ""; - m_windowCursor = *wxSTANDARD_CURSOR; - m_children = new wxWindowList; - m_constraints = NULL; - m_constraintsInvolvedIn = NULL; - m_windowSizer = NULL; - m_sizerParent = NULL; - m_autoLayout = FALSE; - m_windowValidator = NULL; - m_defaultItem = NULL; - m_returnCode = 0; - m_caretWidth = 0; m_caretHeight = 0; - m_caretEnabled = FALSE; - m_caretShown = FALSE; - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; - // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; - m_foregroundColour = *wxBLACK; + m_hScrollBar = NULL ; m_vScrollBar = NULL ; - m_mouseInWindow = FALSE; #if wxUSE_DRAG_AND_DROP m_pDropTarget = NULL; @@ -116,69 +141,29 @@ void wxWindow::Init() // Destructor wxWindow::~wxWindow() { + m_isBeingDeleted = TRUE; + if ( s_lastMouseWindow == this ) { s_lastMouseWindow = NULL ; } - // Have to delete constraints/sizer FIRST otherwise - // sizers may try to look at deleted windows as they - // delete themselves. -#if wxUSE_CONSTRAINTS - DeleteRelatedConstraints(); - if (m_constraints) - { - // This removes any dangling pointers to this window - // in other windows' constraintsInvolvedIn lists. - UnsetConstraints(m_constraints); - delete m_constraints; - m_constraints = NULL; - } - if (m_windowSizer) + + if ( gFocusWindow == this ) { - delete m_windowSizer; - m_windowSizer = NULL; + gFocusWindow = NULL ; } - // If this is a child of a sizer, remove self from parent - if (m_sizerParent) - m_sizerParent->RemoveChild((wxWindow *)this); -#endif - - if ( FindFocus() == this ) - { - // really a bad thing - maybe an error ? - // we cannot even send it a kill focus message at this stage - gFocusWindow = NULL ; - } - if (m_windowParent) - m_windowParent->RemoveChild(this); + if ( m_parent ) + m_parent->RemoveChild(this); DestroyChildren(); - if ( m_macWindowData ) - { + if ( m_macWindowData ) + { UMADisposeWindow( m_macWindowData->m_macWindow ) ; delete m_macWindowData ; wxRemoveMacWindowAssociation( this ) ; } - - delete m_children; - m_children = NULL; - - // Just in case the window has been Closed, but - // we're then deleting immediately: don't leave - // dangling pointers. - wxPendingDelete.DeleteObject(this); - - if ( m_windowValidator ) - delete m_windowValidator; -} - -// Destroy the window (delayed, if a managed window) -bool wxWindow::Destroy() -{ - delete this; - return TRUE; } // Constructor @@ -188,64 +173,18 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - m_isWindow = TRUE; - // Generic - m_windowId = 0; - m_windowStyle = 0; - m_windowParent = NULL; - m_windowEventHandler = this; - m_windowName = ""; - m_windowCursor = *wxSTANDARD_CURSOR; - m_constraints = NULL; - m_constraintsInvolvedIn = NULL; - m_windowSizer = NULL; - m_sizerParent = NULL; - m_autoLayout = FALSE; - m_windowValidator = NULL; - -#if wxUSE_DRAG_AND_DROP - m_pDropTarget = NULL; -#endif + wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") ); - m_caretWidth = 0; m_caretHeight = 0; - m_caretEnabled = FALSE; - m_caretShown = FALSE; - m_minSizeX = -1; - m_minSizeY = -1; - m_maxSizeX = -1; - m_maxSizeY = -1; - m_defaultItem = NULL; - m_windowParent = NULL; - if (!parent) + if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; - if (parent) parent->AddChild(this); - - m_returnCode = 0; - - SetName(name); - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - - // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; - m_foregroundColour = *wxBLACK; - - m_windowStyle = style; - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; + parent->AddChild(this); m_x = (int)pos.x; m_y = (int)pos.y; - AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); - m_width = size.x; - m_height = size.y; + AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); + m_width = WidthDefault( size.x ); + m_height = HeightDefault( size.y ) ; MacCreateScrollBars( style ) ; @@ -282,15 +221,26 @@ void wxWindow::SetFocus() } } -void wxWindow::Enable(bool enable) +bool wxWindow::Enable(bool enable) { - if ( m_macEnabled == enable ) - return ; - - m_macEnabled = enable ; - - MacSuperEnabled( enable ) ; - return; + if ( !wxWindowBase::Enable(enable) ) + return FALSE; +/* + HWND hWnd = GetHwnd(); + if ( hWnd ) + ::EnableWindow(hWnd, (BOOL)enable); +*/ + + wxWindowList::Node *node = GetChildren().GetFirst(); + while ( node ) + { + wxWindow *child = node->GetData(); + child->Enable(enable); + + node = node->GetNext(); + } + + return TRUE; } void wxWindow::CaptureMouse() @@ -303,34 +253,6 @@ void wxWindow::ReleaseMouse() wxTheApp->s_captureWindow = NULL ; } -// Push/pop event handler (i.e. allow a chain of event handlers -// be searched) -void wxWindow::PushEventHandler(wxEvtHandler *handler) -{ - handler->SetNextHandler(GetEventHandler()); - SetEventHandler(handler); -} - -wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) -{ - if ( GetEventHandler() ) - { - wxEvtHandler *handlerA = GetEventHandler(); - wxEvtHandler *handlerB = handlerA->GetNextHandler(); - handlerA->SetNextHandler(NULL); - SetEventHandler(handlerB); - if ( deleteHandler ) - { - delete handlerA; - return NULL; - } - else - return handlerA; - } - else - return NULL; -} - #if wxUSE_DRAG_AND_DROP void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) @@ -355,13 +277,13 @@ void wxWindow::DragAcceptFiles(bool accept) } // Get total size -void wxWindow::GetSize(int *x, int *y) const +void wxWindow::DoGetSize(int *x, int *y) const { *x = m_width ; *y = m_height ; } -void wxWindow::GetPosition(int *x, int *y) const +void wxWindow::DoGetPosition(int *x, int *y) const { *x = m_x ; *y = m_y ; @@ -373,7 +295,7 @@ void wxWindow::GetPosition(int *x, int *y) const } } -void wxWindow::ScreenToClient(int *x, int *y) const +void wxWindow::DoScreenToClient(int *x, int *y) const { WindowRef window = GetMacRootWindow() ; @@ -393,7 +315,7 @@ void wxWindow::ScreenToClient(int *x, int *y) const MacRootWindowToClient( x , y ) ; } -void wxWindow::ClientToScreen(int *x, int *y) const +void wxWindow::DoClientToScreen(int *x, int *y) const { WindowRef window = GetMacRootWindow() ; @@ -438,20 +360,37 @@ void wxWindow::MacRootWindowToClient( int *x , int *y ) const } } -void wxWindow::SetCursor(const wxCursor& cursor) +bool wxWindow::SetCursor(const wxCursor& cursor) { - m_windowCursor = cursor; - if (m_windowCursor.Ok()) + if ( !wxWindowBase::SetCursor(cursor) ) + { + // no change + return FALSE; + } + + wxASSERT_MSG( m_cursor.Ok(), + wxT("cursor must be valid after call to the base version")); + + Point pt ; + wxWindow *mouseWin ; + GetMouse( &pt ) ; + + // Change the cursor NOW if we're within the correct window + + if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) { - // since this only affects the window-cursor, we adopt the same - // behaviour as windows -> it will only change on mouse moved events - // otherwise the ::WxSetCursor routine will have to be used + if ( mouseWin == this && !wxIsBusy() ) + { + cursor.MacInstall() ; + } } + + return TRUE ; } // Get size *available for subwindows* i.e. excluding menu bar etc. -void wxWindow::GetClientSize(int *x, int *y) const +void wxWindow::DoGetClientSize(int *x, int *y) const { *x = m_width ; *y = m_height ; @@ -600,6 +539,8 @@ void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) void wxWindow::SetTitle(const wxString& title) { + m_label = title ; + wxString label ; if( wxApp::s_macDefaultEncodingIsPC ) @@ -613,57 +554,14 @@ void wxWindow::SetTitle(const wxString& title) wxString wxWindow::GetTitle() const { - if ( m_macWindowData ) - { - char title[256] ; - wxString label ; - UMAGetWTitleC( m_macWindowData->m_macWindow , title ) ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakePCStringFromMac( title ) ; - else - label = title ; - return label; - } - - return wxEmptyString ; + return m_label ; } -void wxWindow::Centre(int direction) -{ - int x_offset,y_offset ; - int display_width, display_height; - int width, height, x, y; - wxWindow *parent = GetParent(); - if ((direction & wxCENTER_FRAME) && parent) - { - parent->GetPosition(&x_offset,&y_offset) ; - parent->GetSize(&display_width,&display_height) ; - } - else - { - wxDisplaySize(&display_width, &display_height); - x_offset = 0 ; - y_offset = LMGetMBarHeight() + LMGetMBarHeight() / 2 ; // approx. the window title height - } - - GetSize(&width, &height); - GetPosition(&x, &y); - - if (direction & wxHORIZONTAL) - x = (int)((display_width - width)/2); - if (direction & wxVERTICAL) - y = (int)((display_height - height)/2); - - SetSize(x+x_offset, y+y_offset, width, height); -} - - bool wxWindow::Show(bool show) { - if ( m_macShown == show ) - return TRUE ; - - m_macShown = show ; + if ( !wxWindowBase::Show(show) ) + return FALSE; + if ( m_macWindowData ) { if (show) @@ -681,13 +579,8 @@ bool wxWindow::Show(bool show) } } Refresh() ; - MacSuperShown( show ) ; - return TRUE; -} -bool wxWindow::IsShown() const -{ - return m_macShown; + return TRUE; } int wxWindow::GetCharHeight() const @@ -703,13 +596,22 @@ int wxWindow::GetCharWidth() const } void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, - int *descent, int *externalLeading, const wxFont *theFont, bool) const + int *descent, int *externalLeading, const wxFont *theFont ) const { - wxFont *fontToUse = (wxFont *)theFont; - if (!fontToUse) - fontToUse = (wxFont *) & m_windowFont; + const wxFont *fontToUse = theFont; + if ( !fontToUse ) + fontToUse = &m_font; +/* + if ( x ) + *x = sizeRect.cx; + if ( y ) + *y = sizeRect.cy; + if ( descent ) + *descent = tm.tmDescent; + if ( externalLeading ) + *externalLeading = tm.tmExternalLeading; +*/ - // TODO } void wxWindow::MacEraseBackground( Rect *rect ) @@ -764,7 +666,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) EraseRect( rect ) ; - for (wxNode *node = m_children->First(); node; node = node->Next()) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); // int width ; @@ -776,7 +678,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) SectRect( &clientrect , rect , &clientrect ) ; OffsetRect( &clientrect , -child->m_x , -child->m_y ) ; - if ( child->GetMacRootWindow() == window && child->IsReallyShown() ) + if ( child->GetMacRootWindow() == window && child->IsShown() ) { wxMacDrawingClientHelper focus( this ) ; if ( focus.Ok() ) @@ -831,60 +733,47 @@ void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) } } -// This can be called by the app (or wxWindows) to do default processing for the current -// event. Save message/event info in wxWindow so they can be used in this function. -long wxWindow::Default() -{ - // TODO - return 0; -} - -void wxWindow::InitDialog() -{ - wxInitDialogEvent event(GetId()); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); -} - -// Default init dialog behaviour is to transfer data to window -void wxWindow::OnInitDialog(wxInitDialogEvent& event) -{ - TransferDataToWindow(); -} - +#if wxUSE_CARET && WXWIN_COMPATIBILITY +// --------------------------------------------------------------------------- // Caret manipulation +// --------------------------------------------------------------------------- + void wxWindow::CreateCaret(int w, int h) { - m_caretWidth = w; - m_caretHeight = h; - m_caretEnabled = TRUE; + SetCaret(new wxCaret(this, w, h)); } void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) { - // TODO + wxFAIL_MSG("not implemented"); } void wxWindow::ShowCaret(bool show) { - // TODO + wxCHECK_RET( m_caret, "no caret to show" ); + + m_caret->Show(show); } void wxWindow::DestroyCaret() { - // TODO - m_caretEnabled = FALSE; + SetCaret(NULL); } void wxWindow::SetCaretPos(int x, int y) { - // TODO + wxCHECK_RET( m_caret, "no caret to move" ); + + m_caret->Move(x, y); } void wxWindow::GetCaretPos(int *x, int *y) const { - // TODO + wxCHECK_RET( m_caret, "no caret to get position of" ); + + m_caret->GetPosition(x, y); } +#endif // wxUSE_CARET wxWindow *wxGetActiveWindow() { @@ -892,15 +781,6 @@ wxWindow *wxGetActiveWindow() return NULL; } -void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) -{ - m_minSizeX = minW; - m_minSizeY = minH; - m_maxSizeX = maxW; - m_maxSizeY = maxH; -} - - // Coordinates relative to the window void wxWindow::WarpPointer (int x_pos, int y_pos) { @@ -1038,595 +918,53 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) } } -void wxWindow::SetFont(const wxFont& font) -{ - m_windowFont = font; - - if (!m_windowFont.Ok()) - return; - // TODO -} - -void wxWindow::OnChar(wxKeyEvent& event) +bool wxWindow::SetFont(const wxFont& font) { - if ( event.KeyCode() == WXK_TAB ) { - // propagate the TABs to the parent - it's up to it to decide what - // to do with it - if ( GetParent() ) { - if ( GetParent()->ProcessEvent(event) ) - return; - } + if ( !wxWindowBase::SetFont(font) ) + { + // nothing to do + return FALSE; } -} - -void wxWindow::OnPaint(wxPaintEvent& event) -{ -/* - if ( m_macWindowData ) - { - wxMacDrawingClientHelper helper ( this ) ; - long x ,y ,w ,h ; - GetUpdateRegion().GetBox( x , y , w , h ) ; - UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; - Rect r = { y , x, y+h , x+w } ; - EraseRect( &r ) ; - } - else - { - wxMacDrawingClientHelper helper ( this ) ; - long x ,y ,w ,h ; - GetUpdateRegion().GetBox( x , y , w , h ) ; - RGBBackColor( &m_backgroundColour.GetPixel() ) ; - Rect r = { y , x, y+h , x+w } ; - EraseRect( &r ) ; - } -*/ -} - -bool wxWindow::IsEnabled() const -{ - return m_macEnabled ; -} - -// Dialog support: override these and call -// base class members to add functionality -// that can't be done using validators. -// NOTE: these functions assume that controls -// are direct children of this window, not grandchildren -// or other levels of descendant. - -// Transfer values to controls. If returns FALSE, -// it's an application error (pops up a dialog) -bool wxWindow::TransferDataToWindow() -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && - !child->GetValidator()->TransferToWindow() ) - { - wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION); - return FALSE; - } - - node = node->Next(); - } - return TRUE; -} - -// Transfer values from controls. If returns FALSE, -// validation failed: don't quit -bool wxWindow::TransferDataFromWindow() -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) - { - return FALSE; - } - node = node->Next(); - } - return TRUE; -} - -bool wxWindow::Validate() -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) - { - return FALSE; - } - - node = node->Next(); - } - return TRUE; + return TRUE; } // Get the window with the focus -wxWindow *wxWindow::FindFocus() +wxWindow *wxWindowBase::FindFocus() { return gFocusWindow ; } -// ---------------------------------------------------------------------------- -// RTTI -// ---------------------------------------------------------------------------- - -bool wxWindow::IsTopLevel() const -{ - return wxDynamicCast(this, wxFrame) || wxDynamicCast(this, wxDialog); -} - -void wxWindow::AddChild(wxWindow *child) -{ - GetChildren().Append(child); - child->m_windowParent = this; -} - -void wxWindow::RemoveChild(wxWindow *child) -{ - GetChildren().DeleteObject(child); - child->m_windowParent = NULL; -} - -void wxWindow::DestroyChildren() -{ - wxNode *node; - while ((node = GetChildren().First()) != (wxNode *)NULL) { - wxWindow *child; - if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { - delete child; - if ( GetChildren().Find(child) ) - delete node; - } - } /* while */ -} - -void wxWindow::MakeModal(bool modal) -{ - // Disable all other windows - if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) - { - wxNode *node = wxTopLevelWindows.First(); - while (node) - { - wxWindow *win = (wxWindow *)node->Data(); - if (win != this) - win->Enable(!modal); - - node = node->Next(); - } - } -} - +#if WXWIN_COMPATIBILITY // If nothing defined for this, try the parent. // E.g. we may be a button loaded from a resource, with no callback function // defined. void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) { - if (GetEventHandler()->ProcessEvent(event) ) - return; - if (m_windowParent) - m_windowParent->GetEventHandler()->OnCommand(win, event); -} - -// ---------------------------------------------------------------------------- -// constraints and sizers -// ---------------------------------------------------------------------------- - -#if wxUSE_CONSTRAINTS - -void wxWindow::SetConstraints( wxLayoutConstraints *constraints ) -{ - if ( m_constraints ) - { - UnsetConstraints(m_constraints); - delete m_constraints; - } - m_constraints = constraints; - if ( m_constraints ) - { - // Make sure other windows know they're part of a 'meaningful relationship' - if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) - m_constraints->left.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) - m_constraints->top.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) - m_constraints->right.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) - m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) - m_constraints->width.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) - m_constraints->height.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) - m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) - m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); - } -} - -// This removes any dangling pointers to this window in other windows' -// constraintsInvolvedIn lists. -void wxWindow::UnsetConstraints(wxLayoutConstraints *c) -{ - if ( c ) - { - if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) - c->left.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) - c->top.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) - c->right.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) - c->bottom.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) - c->width.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) - c->height.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) - c->centreX.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) - c->centreY.GetOtherWindow()->RemoveConstraintReference(this); - } -} - -// Back-pointer to other windows we're involved with, so if we delete this -// window, we must delete any constraints we're involved with. -void wxWindow::AddConstraintReference(wxWindow *otherWin) -{ - if ( !m_constraintsInvolvedIn ) - m_constraintsInvolvedIn = new wxWindowList; - if ( !m_constraintsInvolvedIn->Find(otherWin) ) - m_constraintsInvolvedIn->Append(otherWin); -} - -// REMOVE back-pointer to other windows we're involved with. -void wxWindow::RemoveConstraintReference(wxWindow *otherWin) -{ - if ( m_constraintsInvolvedIn ) - m_constraintsInvolvedIn->DeleteObject(otherWin); -} - -// Reset any constraints that mention this window -void wxWindow::DeleteRelatedConstraints() -{ - if ( m_constraintsInvolvedIn ) - { - wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); - while (node) - { - wxWindow *win = node->GetData(); - wxLayoutConstraints *constr = win->GetConstraints(); - - // Reset any constraints involving this window - if ( constr ) - { - constr->left.ResetIfWin(this); - constr->top.ResetIfWin(this); - constr->right.ResetIfWin(this); - constr->bottom.ResetIfWin(this); - constr->width.ResetIfWin(this); - constr->height.ResetIfWin(this); - constr->centreX.ResetIfWin(this); - constr->centreY.ResetIfWin(this); - } - - wxWindowList::Node *next = node->GetNext(); - delete node; - node = next; - } - - delete m_constraintsInvolvedIn; - m_constraintsInvolvedIn = (wxWindowList *) NULL; - } -} - -void wxWindow::SetSizer(wxSizer *sizer) -{ - if (m_windowSizer) delete m_windowSizer; - - m_windowSizer = sizer; -} - -bool wxWindow::Layout() -{ - int w, h; - GetClientSize(&w, &h); - - // If there is a sizer, use it instead of the constraints - if ( GetSizer() ) - { - GetSizer()->SetDimension( 0, 0, w, h ); - return TRUE; - } - - if ( GetConstraints() ) - { - GetConstraints()->width.SetValue(w); - GetConstraints()->height.SetValue(h); - } - - // Evaluate child constraints - ResetConstraints(); // Mark all constraints as unevaluated - DoPhase(1); // Just one phase need if no sizers involved - DoPhase(2); - SetConstraintSizes(); // Recursively set the real window sizes - - return TRUE; -} - - -// Do a phase of evaluating constraints: the default behaviour. wxSizers may -// do a similar thing, but also impose their own 'constraints' and order the -// evaluation differently. -bool wxWindow::LayoutPhase1(int *noChanges) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - return constr->SatisfyConstraints(this, noChanges); - } - else - return TRUE; -} - -bool wxWindow::LayoutPhase2(int *noChanges) -{ - *noChanges = 0; - - // Layout children - DoPhase(1); - DoPhase(2); - return TRUE; -} - -// Do a phase of evaluating child constraints -bool wxWindow::DoPhase(int phase) -{ - int noIterations = 0; - int maxIterations = 500; - int noChanges = 1; - int noFailures = 0; - wxWindowList succeeded; - while ((noChanges > 0) && (noIterations < maxIterations)) - { - noChanges = 0; - noFailures = 0; - wxWindowList::Node *node = GetChildren().GetFirst(); - while (node) - { - wxWindow *child = node->GetData(); - if ( !child->IsTopLevel() ) - { - wxLayoutConstraints *constr = child->GetConstraints(); - if ( constr ) - { - if ( !succeeded.Find(child) ) - { - int tempNoChanges = 0; - bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; - noChanges += tempNoChanges; - if ( success ) - { - succeeded.Append(child); - } - } - } - } - node = node->GetNext(); - } - - noIterations++; - } - - return TRUE; -} - -void wxWindow::ResetConstraints() -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - constr->left.SetDone(FALSE); - constr->top.SetDone(FALSE); - constr->right.SetDone(FALSE); - constr->bottom.SetDone(FALSE); - constr->width.SetDone(FALSE); - constr->height.SetDone(FALSE); - constr->centreX.SetDone(FALSE); - constr->centreY.SetDone(FALSE); - } - wxWindowList::Node *node = GetChildren().GetFirst(); - while (node) - { - wxWindow *win = node->GetData(); - if ( !win->IsTopLevel() ) - win->ResetConstraints(); - node = node->GetNext(); - } -} - -// Need to distinguish between setting the 'fake' size for windows and sizers, -// and setting the real values. -void wxWindow::SetConstraintSizes(bool recurse) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr && constr->left.GetDone() && constr->right.GetDone( ) && - constr->width.GetDone() && constr->height.GetDone()) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - int w = constr->width.GetValue(); - int h = constr->height.GetValue(); - - if ( (constr->width.GetRelationship() != wxAsIs ) || - (constr->height.GetRelationship() != wxAsIs) ) - { - SetSize(x, y, w, h); - } - else - { - // If we don't want to resize this window, just move it... - Move(x, y); - } - } - else if ( constr ) - { - char *windowClass = GetClassInfo()->GetClassName(); - - wxString winName; - if ( GetName() == _T("") ) - winName = _T("unnamed"); - else - winName = GetName(); - wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"), - (const char *)windowClass, - (const char *)winName); - if ( !constr->left.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") ); - if ( !constr->right.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") ); - if ( !constr->width.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") ); - if ( !constr->height.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") ); - wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") ); - } - - if ( recurse ) - { - wxWindowList::Node *node = GetChildren().GetFirst(); - while (node) - { - wxWindow *win = node->GetData(); - if ( !win->IsTopLevel() ) - win->SetConstraintSizes(); - node = node->GetNext(); - } - } -} - -// Only set the size/position of the constraint (if any) -void wxWindow::SetSizeConstraint(int x, int y, int w, int h) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - if ( x != -1 ) - { - constr->left.SetValue(x); - constr->left.SetDone(TRUE); - } - if ( y != -1 ) - { - constr->top.SetValue(y); - constr->top.SetDone(TRUE); - } - if ( w != -1 ) - { - constr->width.SetValue(w); - constr->width.SetDone(TRUE); - } - if ( h != -1 ) - { - constr->height.SetValue(h); - constr->height.SetDone(TRUE); - } - } -} - -void wxWindow::MoveConstraint(int x, int y) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - if ( x != -1 ) - { - constr->left.SetValue(x); - constr->left.SetDone(TRUE); - } - if ( y != -1 ) - { - constr->top.SetValue(y); - constr->top.SetDone(TRUE); - } - } + if ( GetEventHandler()->ProcessEvent(event) ) + return; + if ( m_parent ) + m_parent->GetEventHandler()->OnCommand(win, event); } +#endif // WXWIN_COMPATIBILITY_2 -void wxWindow::GetSizeConstraint(int *w, int *h) const -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - *w = constr->width.GetValue(); - *h = constr->height.GetValue(); - } - else - GetSize(w, h); -} - -void wxWindow::GetClientSizeConstraint(int *w, int *h) const -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - *w = constr->width.GetValue(); - *h = constr->height.GetValue(); - } - else - GetClientSize(w, h); -} - -void wxWindow::GetPositionConstraint(int *x, int *y) const +#if WXWIN_COMPATIBILITY +wxObject* wxWindow::GetChild(int number) const { - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) + // Return a pointer to the Nth object in the Panel + wxNode *node = GetChildren().First(); + int n = number; + while (node && n--) + node = node->Next(); + if ( node ) { - *x = constr->left.GetValue(); - *y = constr->top.GetValue(); + wxObject *obj = (wxObject *)node->Data(); + return(obj); } else - GetPosition(x, y); -} - -#endif // wxUSE_CONSTRAINTS - -bool wxWindow::Close(bool force) -{ - wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); - event.SetEventObject(this); -#if WXWIN_COMPATIBILITY - event.SetForce(force); -#endif - event.SetCanVeto(!force); - - return GetEventHandler()->ProcessEvent(event); -} - -wxObject* wxWindow::GetChild(int number) const -{ - // Return a pointer to the Nth object in the window - wxNode *node = GetChildren().First(); - int n = number; - while (node && n--) - node = node->Next() ; - if (node) - { - wxObject *obj = (wxObject *)node->Data(); - return(obj) ; - } - else - return NULL ; -} - -void wxWindow::OnDefaultAction(wxControl *initiatingItem) -{ - // Obsolete function + return NULL; } +#endif // WXWIN_COMPATIBILITY void wxWindow::Clear() { @@ -1649,76 +987,11 @@ void wxWindow::Clear() } } -// Fits the panel around the items -void wxWindow::Fit() -{ - int maxX = 0; - int maxY = 0; - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *win = (wxWindow *)node->Data(); - int wx, wy, ww, wh; - win->GetPosition(&wx, &wy); - win->GetSize(&ww, &wh); - if ( wx + ww > maxX ) - maxX = wx + ww; - if ( wy + wh > maxY ) - maxY = wy + wh; - - node = node->Next(); - } - SetClientSize(maxX + 5, maxY + 5); -} - -void wxWindow::SetValidator(const wxValidator& validator) -{ - if ( m_windowValidator ) - delete m_windowValidator; - m_windowValidator = validator.Clone(); - - if ( m_windowValidator ) - m_windowValidator->SetWindow(this) ; -} - -void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) -{ - m_acceleratorTable = accel; -} - -// Find a window by id or name -wxWindow *wxWindow::FindWindow(long id) -{ - if ( GetId() == id) - return this; - - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - wxWindow *found = child->FindWindow(id); - if ( found ) - return found; - node = node->Next(); - } - return NULL; -} - -wxWindow *wxWindow::FindWindow(const wxString& name) +// Setup background and foreground colours correctly +void wxWindow::SetupColours() { - if ( GetName() == name) - return this; - - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - wxWindow *found = child->FindWindow(name); - if ( found ) - return found; - node = node->Next(); - } - return NULL; + if ( GetParent() ) + SetBackgroundColour(GetParent()->GetBackgroundColour()); } void wxWindow::OnIdle(wxIdleEvent& event) @@ -1755,43 +1028,6 @@ void wxWindow::Lower() // TODO } -bool wxWindow::AcceptsFocus() const -{ - return IsShown() && IsEnabled() && MacCanFocus() ; -} - -// Update region access -wxRegion wxWindow::GetUpdateRegion() const -{ - return m_updateRegion; -} - -bool wxWindow::IsExposed(int x, int y, int w, int h) const -{ - return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); -} - -bool wxWindow::IsExposed(const wxPoint& pt) const -{ - return (m_updateRegion.Contains(pt) != wxOutRegion); -} - -bool wxWindow::IsExposed(const wxRect& rect) const -{ - return (m_updateRegion.Contains(rect) != wxOutRegion); -} - -/* - * Allocates control IDs - */ - -int wxWindow::NewControlId() -{ - static int s_controlId = 0; - s_controlId ++; - return s_controlId; -} - void wxWindow::DoSetClientSize(int width, int height) { if ( width != -1 || height != -1 ) @@ -1806,30 +1042,6 @@ void wxWindow::DoSetClientSize(int width, int height) } } -// ------------------------ -wxList *wxWinMacWindowList = NULL; -wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef) -{ - wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); - if (!node) - return NULL; - return (wxWindow *)node->Data(); -} - -void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win) -{ - // adding NULL WindowRef is (first) surely a result of an error and - // (secondly) breaks menu command processing - wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); - - if ( !wxWinMacWindowList->Find((long)inWindowRef) ) - wxWinMacWindowList->Append((long)inWindowRef, win); -} - -void wxRemoveMacWindowAssociation(wxWindow *win) -{ - wxWinMacWindowList->DeleteObject(win); -} wxWindow* wxWindow::s_lastMouseWindow = NULL ; @@ -1846,16 +1058,13 @@ bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWi newPoint.x -= m_x; newPoint.y -= m_y; - if ( m_children ) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { - for (wxNode *node = m_children->First(); node; node = node->Next()) + wxWindow *child = (wxWindow*)node->Data(); + if ( child->GetMacRootWindow() == window ) { - wxWindow *child = (wxWindow*)node->Data(); - if ( child->GetMacRootWindow() == window ) - { - if (child->MacGetWindowFromPointSub(newPoint , outWin )) - return TRUE; - } + if (child->MacGetWindowFromPointSub(newPoint , outWin )) + return TRUE; } } @@ -1896,16 +1105,13 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) int x = event.m_x ; int y = event.m_y ; - if ( m_children ) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { - for (wxNode *node = m_children->First(); node; node = node->Next()) + wxWindow *child = (wxWindow*)node->Data(); + if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() ) { - wxWindow *child = (wxWindow*)node->Data(); - if ( child->GetMacRootWindow() == window && child->IsReallyShown() && child->IsReallyEnabled() ) - { - if (child->MacDispatchMouseEvent(event)) - return TRUE; - } + if (child->MacDispatchMouseEvent(event)) + return TRUE; } } @@ -1914,7 +1120,7 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) if ( wxBusyCursorCount == 0 ) { - m_windowCursor.MacInstall() ; + m_cursor.MacInstall() ; } GetEventHandler()->ProcessEvent( event ) ; return TRUE; @@ -1989,7 +1195,7 @@ void wxWindow::MacFireMouseEvent( EventRecord *ev ) wxTheApp->s_captureWindow = NULL ; if ( wxBusyCursorCount == 0 ) { - m_windowCursor.MacInstall() ; + m_cursor.MacInstall() ; } } } @@ -2118,7 +1324,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) RgnHandle childupdate = NewRgn() ; - for (wxNode *node = m_children->First(); node; node = node->Next()) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); int width ; @@ -2129,7 +1335,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ; SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ; OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; - if ( child->GetMacRootWindow() == window && child->IsReallyShown() ) + if ( child->GetMacRootWindow() == window && child->IsShown() ) { // because dialogs may also be children child->MacRedraw( childupdate , time ) ; @@ -2274,45 +1480,6 @@ void wxWindow::MacSuperChangedPosition() node = node->Next(); } } - -bool wxWindow::IsReallyShown() const -{ - if ( m_macWindowData ) - return m_macShown ; - else - return m_macShown && GetParent()->IsReallyShown() ; -} - -bool wxWindow::IsReallyEnabled() const -{ - if ( m_macWindowData ) - return m_macEnabled ; - else - return m_macEnabled && GetParent()->IsReallyEnabled() ; -} - -void wxWindow::MacSuperEnabled( bool enabled ) -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->m_macEnabled ) - child->MacSuperEnabled( enabled ) ; - node = node->Next(); - } -} -void wxWindow::MacSuperShown( bool show ) -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->m_macShown ) - child->MacSuperShown( show ) ; - node = node->Next(); - } -} bool wxWindow::MacSetupFocusPort( ) { diff --git a/src/mac/clipbrd.cpp b/src/mac/clipbrd.cpp index 28a4b9ef3f..828b8984fc 100644 --- a/src/mac/clipbrd.cpp +++ b/src/mac/clipbrd.cpp @@ -23,11 +23,6 @@ #include -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) -IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject) -#endif - bool wxOpenClipboard() { return TRUE; @@ -90,26 +85,36 @@ bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount) * Generalized clipboard implementation by Matthew Flatt */ -wxClipboard *wxTheClipboard = NULL; +wxClipboard::wxClipboard() +{ + m_clearOnExit = FALSE; +} -void wxInitClipboard() +wxClipboard::~wxClipboard() { - if (!wxTheClipboard) - wxTheClipboard = new wxClipboard; + if ( m_clearOnExit ) + { + Clear(); + } } -wxClipboard::wxClipboard() +void wxClipboard::Clear() { - clipOwner = NULL; - cbString = NULL; } -wxClipboard::~wxClipboard() +bool wxClipboard::Flush() { - if (clipOwner) - clipOwner->BeingReplaced(); - if (cbString) - delete[] cbString; + return FALSE; +} + +bool wxClipboard::Open() +{ + return wxOpenClipboard(); +} + +bool wxClipboard::IsOpened() const +{ + return wxIsClipboardOpened(); } static int FormatStringToID(char *str) @@ -120,6 +125,129 @@ static int FormatStringToID(char *str) return wxRegisterClipboardFormat(str); } +bool wxClipboard::SetData( wxDataObject *data ) +{ + (void)wxEmptyClipboard(); + + if ( data ) + return AddData(data); + else + return TRUE; +} + +bool wxClipboard::AddData( wxDataObject *data ) +{ + wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); + +#if wxUSE_DATAOBJ + wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); + + wxDataFormat format = data->GetFormat(); + + switch ( format ) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + { + wxTextDataObject* textDataObject = (wxTextDataObject*) data; + wxString str(textDataObject->GetText()); + return wxSetClipboardData(format, str.c_str()); + } + + case wxDF_BITMAP: + case wxDF_DIB: + { + wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; + wxBitmap bitmap(bitmapDataObject->GetBitmap()); + return wxSetClipboardData(data->GetFormat(), &bitmap); + } + +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafileDataObject* metaFileDataObject = + (wxMetafileDataObject*) data; + wxMetafile metaFile = metaFileDataObject->GetMetafile(); + return wxSetClipboardData(wxDF_METAFILE, &metaFile, + metaFileDataObject->GetWidth(), + metaFileDataObject->GetHeight()); + } +#endif // wxUSE_METAFILE + + default: + return wxSetClipboardData(data); + } +#else // !wxUSE_DATAOBJ + return FALSE; +#endif +} + +void wxClipboard::Close() +{ + wxCloseClipboard(); +} + +bool wxClipboard::IsSupported( wxDataFormat format ) +{ + return wxIsClipboardFormatAvailable(format); +} + +bool wxClipboard::GetData( wxDataObject& data ) +{ +#if wxUSE_DATAOBJ + wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); + + wxDataFormat format = data.GetFormat(); + switch ( format ) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + { + wxTextDataObject& textDataObject = (wxTextDataObject &)data; + char* s = (char*)wxGetClipboardData(format); + if ( !s ) + return FALSE; + + textDataObject.SetText(s); + delete [] s; + + return TRUE; + } + + case wxDF_BITMAP: + case wxDF_DIB: + { + wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data; + wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data->GetFormat()); + if ( !bitmap ) + return FALSE; + + bitmapDataObject.SetBitmap(*bitmap); + delete bitmap; + + return TRUE; + } +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data; + wxMetafile* metaFile = (wxMetafile *)wxGetClipboardData(wxDF_METAFILE); + if ( !metaFile ) + return FALSE; + + metaFileDataObject.SetMetafile(*metaFile); + delete metaFile; + + return TRUE; + } +#endif // wxUSE_METAFILE + } +#else // !wxUSE_DATAOBJ + wxFAIL_MSG( wxT("no clipboard implementation") ); +#endif + return FALSE; +} +/* void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time) { bool got_selection; @@ -167,7 +295,7 @@ wxClipboardClient *wxClipboard::GetClipboardClient() } void wxClipboard::SetClipboardString(char *str, long time) -{/* +{ bool got_selection; if (clipOwner) { @@ -193,9 +321,7 @@ void wxClipboard::SetClipboardString(char *str, long time) delete[] cbString; cbString = NULL; } - */ } - char *wxClipboard::GetClipboardString(long time) { char *str; @@ -210,6 +336,7 @@ char *wxClipboard::GetClipboardString(long time) return str; } + char *wxClipboard::GetClipboardData(char *format, long *length, long time) { if (clipOwner) { @@ -233,4 +360,5 @@ char *wxClipboard::GetClipboardData(char *format, long *length, long time) return receivedString; } } +*/ diff --git a/src/mac/control.cpp b/src/mac/control.cpp index d570e2c5a1..220ff1e0a9 100644 --- a/src/mac/control.cpp +++ b/src/mac/control.cpp @@ -53,7 +53,9 @@ wxControl::wxControl() m_macVerticalBorder = 0 ; m_backgroundColour = *wxWHITE; m_foregroundColour = *wxBLACK; - m_callback = 0; +#if WXWIN_COMPATIBILITY + m_callback = 0; +#endif // WXWIN_COMPATIBILITY if ( wxMacLiveScrollbarActionUPP == NULL ) { @@ -63,13 +65,14 @@ wxControl::wxControl() wxControl::~wxControl() { + m_isBeingDeleted = TRUE; // If we delete an item, we should initialize the parent panel, // because it could now be invalid. - wxWindow *parent = (wxWindow *)GetParent(); - if (parent) + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + if ( panel ) { - if (parent->GetDefaultItem() == (wxButton*) this) - parent->SetDefaultItem(NULL); + if (panel->GetDefaultItem() == (wxButton*) this) + panel->SetDefaultItem(NULL); } if ( m_macControl ) { @@ -78,13 +81,19 @@ wxControl::~wxControl() } } -void wxControl::SetLabel(const wxString& label) +void wxControl::SetLabel(const wxString& title) { - m_label = label ; + m_label = title ; if ( m_macControl ) { Str255 maclabel ; + wxString label ; + + if( wxApp::s_macDefaultEncodingIsPC ) + label = wxMacMakeMacStringFromPC( title ) ; + else + label = title ; strcpy( (char*) maclabel , label ) ; c2pstr( (char*) maclabel ) ; @@ -93,56 +102,31 @@ void wxControl::SetLabel(const wxString& label) } } -wxString wxControl::GetLabel() const +wxSize wxControl::DoGetBestSize() { - return m_label ; + return wxSize(20, 20); } -void wxControl::ProcessCommand (wxCommandEvent & event) +bool wxControl::ProcessCommand (wxCommandEvent & event) { // Tries: // 1) A callback function (to become obsolete) // 2) OnCommand, starting at this window and working up parent hierarchy // 3) OnCommand then calls ProcessEvent to search the event tables. - if (m_callback) +#if WXWIN_COMPATIBILITY + if ( m_callback ) { - (void) (*(m_callback)) (*this, event); + (void)(*m_callback)(this, event); + + return TRUE; } else +#endif // WXWIN_COMPATIBILITY { - GetEventHandler()->OnCommand(*this, event); + return GetEventHandler()->ProcessEvent(event); } } -void wxControl::Centre (int direction) -{ - int x, y, width, height, panel_width, panel_height, new_x, new_y; - - wxWindow *parent = (wxWindow *) GetParent (); - if (!parent) - return; - - parent->GetClientSize (&panel_width, &panel_height); - GetSize (&width, &height); - GetPosition (&x, &y); - - new_x = x; - new_y = y; - - if (direction & wxHORIZONTAL) - new_x = (int) ((panel_width - width) / 2); - - if (direction & wxVERTICAL) - new_y = (int) ((panel_height - height) / 2); - - SetSize (new_x, new_y, width, height); -} - -void wxControl::SetClientSize (int width, int height) -{ - SetSize (-1, -1, width, height); -} - // ------------------------ wxList *wxWinMacControlList = NULL; wxControl *wxFindControlFromMacControl(ControlHandle inControl ) @@ -352,6 +336,7 @@ void wxControl::MacSuperChangedPosition() void wxControl::MacSuperEnabled( bool enabled ) { +/* if ( m_macControl ) { if ( UMAHasAppearance() ) @@ -380,10 +365,12 @@ void wxControl::MacSuperEnabled( bool enabled ) } } wxWindow::MacSuperEnabled( enabled ) ; + */ } void wxControl::MacSuperShown( bool show ) { + /* if ( m_macControl ) { if ( !show ) @@ -398,6 +385,7 @@ void wxControl::MacSuperShown( bool show ) } wxWindow::MacSuperShown( show ) ; + */ } void wxControl::DoSetSize(int x, int y, @@ -503,51 +491,45 @@ void wxControl::DoSetSize(int x, int y, } } -void wxControl::DoSetClientSize(int width, int height) -{ - DoSetSize( -1 , -1 , width , height ) ; -} - bool wxControl::Show(bool show) { - if ( m_macControl == NULL ) - return wxWindow::Show( show ) ; - - if ( m_macShown == show ) - return TRUE ; - - if ( show ) - ::UMAShowControl( m_macControl ) ; - else - ::UMAHideControl( m_macControl ) ; - - return wxWindow::Show( show ) ; + if ( !wxWindow::Show( show ) ) + return FALSE ; + + if ( m_macControl ) + { + if ( show ) + ::UMAShowControl( m_macControl ) ; + else + ::UMAHideControl( m_macControl ) ; + } + return TRUE ; } -void wxControl::Enable(bool enable) +bool wxControl::Enable(bool enable) { - if ( m_macControl == NULL ) - return wxWindow::Enable( enable ) ; - - if ( m_macEnabled == enable ) - return ; + if ( !wxWindow::Enable(enable) ) + return FALSE; - if ( UMAHasAppearance() ) - { - if ( enable ) - ::ActivateControl( m_macControl ) ; - else - ::DeactivateControl( m_macControl ) ; - } - else + if ( m_macControl ) { - if ( enable ) - ::HiliteControl( m_macControl , 0 ) ; + + if ( UMAHasAppearance() ) + { + if ( enable ) + ::ActivateControl( m_macControl ) ; + else + ::DeactivateControl( m_macControl ) ; + } else - ::HiliteControl( m_macControl , 255 ) ; + { + if ( enable ) + ::HiliteControl( m_macControl , 0 ) ; + else + ::HiliteControl( m_macControl , 255 ) ; + } } - - return wxWindow::Enable( enable ) ; + return TRUE ; } void wxControl::Refresh(bool eraseBack, const wxRect *rect) @@ -579,9 +561,9 @@ void wxControl::OnPaint(wxPaintEvent& event) wxWindow* parent = GetParent() ; while ( parent ) { - if( parent->m_macWindowData ) + if( parent->MacGetWindowData() ) { - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; break ; } @@ -596,13 +578,13 @@ void wxControl::OnPaint(wxPaintEvent& event) } UMADrawControl( m_macControl ) ; - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; } } } else { - wxWindow::OnPaint( event ) ; + // wxWindow::OnPaint( event ) ; } } diff --git a/src/mac/dialog.cpp b/src/mac/dialog.cpp index 7e82133eb2..2acc18174e 100644 --- a/src/mac/dialog.cpp +++ b/src/mac/dialog.cpp @@ -108,7 +108,6 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ; UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; m_macWindowData->m_macFocus = NULL ; - m_macShown = false ; return TRUE; } @@ -127,10 +126,13 @@ void wxDialog::SetModal(bool flag) wxDialog::~wxDialog() { + m_isBeingDeleted = TRUE ; wxTopLevelWindows.DeleteObject(this); - if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) - wxModelessWindows.DeleteObject(this); + m_modalShowing = FALSE; + + if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) + wxModelessWindows.DeleteObject(this); // If this is the last top-level window, exit. if (wxTheApp && (wxTopLevelWindows.Number() == 0)) @@ -176,37 +178,64 @@ extern bool s_macIsInModalLoop ; bool wxDialog::Show(bool show) { - if ( m_macShown == show ) - return TRUE ; + m_isShown = show; - m_macShown = show ; + if (show) + InitDialog(); bool modal = ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL) ; +#if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ + if (!modal) + { + if (show) + { + if (!wxModelessWindows.Find(this)) + wxModelessWindows.Append(this); + } + else + wxModelessWindows.DeleteObject(this); + } + if (show) + { + if (!wxTopLevelWindows.Find(this)) + wxTopLevelWindows.Append(this); + } + else + wxTopLevelWindows.DeleteObject(this); +#endif + if ( modal ) { s_macIsInModalLoop = true ; - if (show) - { - // if we don't do it, some window might be deleted while we have pointers - // to them in our disabledWindows list and the program will crash when it - // will try to reenable them after the modal dialog end - wxTheApp->DeletePendingObjects(); - - UMAShowWindow( m_macWindowData->m_macWindow ) ; - UMASelectWindow( m_macWindowData->m_macWindow ) ; - - if (!wxModalDialogs.Member(this)) - wxModalDialogs.Append(this); - - while (wxModalDialogs.Member(this) ) - { - wxTheApp->MacDoOneEvent() ; - } + if (show) + { + if (m_modalShowing) + { +// BringWindowToTop((HWND) GetHWND()); + return TRUE; + } + + m_modalShowing = TRUE; + // if we don't do it, some window might be deleted while we have pointers + // to them in our disabledWindows list and the program will crash when it + // will try to reenable them after the modal dialog end + wxTheApp->DeletePendingObjects(); + + UMAShowWindow( m_macWindowData->m_macWindow ) ; + UMASelectWindow( m_macWindowData->m_macWindow ) ; + + if (!wxModalDialogs.Member(this)) + wxModalDialogs.Append(this); + + while (wxModalDialogs.Member(this) ) + { + wxTheApp->MacDoOneEvent() ; + } } else { - wxModalDialogs.DeleteObject(this); + wxModalDialogs.DeleteObject(this); UMAHideWindow( m_macWindowData->m_macWindow ) ; } s_macIsInModalLoop = false ; @@ -334,125 +363,3 @@ void wxDialog::Fit() wxWindow::Fit(); } -wxSizer *wxDialog::CreateTextSizer( const wxString &message ) -{ - wxBoxSizer *box = new wxBoxSizer( wxVERTICAL ); - - // get line height for empty lines - int y = 0; - wxFont new_font( GetFont() ); - if (!new_font.Ok()) new_font = *wxSWISS_FONT; - GetTextExtent( "H", (int*)NULL, &y, (int*)NULL, (int*)NULL, &new_font ); - - wxString line; - for (size_t pos = 0; pos < message.Len(); pos++) - { - if (message[pos] == _T('\n')) - { - if (!line.IsEmpty()) - { - wxStaticText *s1 = new wxStaticText( this, -1, line ); - box->Add( s1 ); - line = _T(""); - } - else - { - box->Add( 5, y ); - } - } - else - { - line += message[pos]; - } - } - - // remaining text behind last '\n' - if (!line.IsEmpty()) - { - wxStaticText *s2 = new wxStaticText( this, -1, line ); - box->Add( s2 ); - } - - return box; -} - -wxSizer *wxDialog::CreateButtonSizer( long flags ) -{ - wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL ); - -#if defined(__WXMSW__) || defined(__WXMAC__) - int margin = 6; -#else - int margin = 10; -#endif - - wxButton *ok = (wxButton *) NULL; - wxButton *cancel = (wxButton *) NULL; - wxButton *yes = (wxButton *) NULL; - wxButton *no = (wxButton *) NULL; - - // always show an OK button, unless only YES_NO is given - if ((flags & wxYES_NO) == 0) flags = flags | wxOK; - - if (flags & wxYES_NO) - { - yes = new wxButton( this, wxID_YES, _("Yes") ); - box->Add( yes, 0, wxLEFT|wxRIGHT, margin ); - no = new wxButton( this, wxID_NO, _("No") ); - box->Add( no, 0, wxLEFT|wxRIGHT, margin ); - } else - if (flags & wxYES) - { - yes = new wxButton( this, wxID_YES, _("Yes") ); - box->Add( yes, 0, wxLEFT|wxRIGHT, margin ); - } else - if (flags & wxNO) - { - no = new wxButton( this, wxID_NO, _("No") ); - box->Add( no, 0, wxLEFT|wxRIGHT, margin ); - } - - if (flags & wxOK) - { - ok = new wxButton( this, wxID_OK, _("OK") ); - box->Add( ok, 0, wxLEFT|wxRIGHT, margin ); - } - - if (flags & wxFORWARD) - box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxBACKWARD) - box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxSETUP) - box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxMORE) - box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxHELP) - box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin ); - - if (flags & wxCANCEL) - { - cancel = new wxButton( this, wxID_CANCEL, _("Cancel") ); - box->Add( cancel, 0, wxLEFT|wxRIGHT, margin ); - } - - if ((flags & wxNO_DEFAULT) == 0) - { - if (ok) - { - ok->SetDefault(); - ok->SetFocus(); - } - else if (yes) - { - yes->SetDefault(); - yes->SetFocus(); - } - } - - return box; -} - diff --git a/src/mac/font.cpp b/src/mac/font.cpp index 2409e1a38b..d7d7b12cc8 100644 --- a/src/mac/font.cpp +++ b/src/mac/font.cpp @@ -22,39 +22,42 @@ IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) #endif -wxFontRefData::wxFontRefData() -{ - m_style = 0; - m_pointSize = 0; - m_family = 0; - m_style = 0; - m_weight = 0; - m_underlined = 0; - m_faceName = ""; - - m_macFontSize = m_pointSize ; - m_macFontNum = systemFont ; - m_macFontStyle = normal ; -} -wxFontRefData::wxFontRefData(const wxFontRefData& data) + + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxFontRefData +// ---------------------------------------------------------------------------- + +void wxFontRefData::Init(int pointSize, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) { - m_style = data.m_style; - m_pointSize = data.m_pointSize; - m_family = data.m_family; - m_style = data.m_style; - m_weight = data.m_weight; - m_underlined = data.m_underlined; - m_faceName = data.m_faceName; - - m_macFontSize = m_pointSize ; - m_macFontNum = systemFont ; - m_macFontStyle = normal ; + m_style = style; + m_pointSize = pointSize; + m_family = family; + m_style = style; + m_weight = weight; + m_underlined = underlined; + m_faceName = faceName; + m_encoding = encoding; + + m_macFontNum = 0 ; + m_macFontSize = 0; + m_macFontStyle = 0; + m_fontId = 0; } wxFontRefData::~wxFontRefData() { - // TODO: delete font data } void wxFontRefData::MacFindFont() @@ -107,31 +110,27 @@ void wxFontRefData::MacFindFont() m_macFontSize = m_pointSize ; } -wxFont::wxFont() -{ - if ( wxTheFontList ) - wxTheFontList->Append(this); -} +// ---------------------------------------------------------------------------- +// wxFont +// ---------------------------------------------------------------------------- -wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) +void wxFont::Init() { - Create(pointSize, family, style, weight, underlined, faceName); - if ( wxTheFontList ) wxTheFontList->Append(this); } -bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) +bool wxFont::Create(int pointSize, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) { UnRef(); - m_refData = new wxFontRefData; - - M_FONTDATA->m_family = family; - M_FONTDATA->m_style = style; - M_FONTDATA->m_weight = weight; - M_FONTDATA->m_pointSize = pointSize; - M_FONTDATA->m_underlined = underlined; - M_FONTDATA->m_faceName = faceName; + m_refData = new wxFontRefData(pointSize, family, style, weight, + underlined, faceName, encoding); RealizeResource(); @@ -219,78 +218,50 @@ void wxFont::SetUnderlined(bool underlined) RealizeResource(); } -wxString wxFont::GetFamilyString() const +// ---------------------------------------------------------------------------- +// accessors +// ---------------------------------------------------------------------------- + +int wxFont::GetPointSize() const { - wxString fam(""); - switch (GetFamily()) - { - case wxDECORATIVE: - fam = "wxDECORATIVE"; - break; - case wxROMAN: - fam = "wxROMAN"; - break; - case wxSCRIPT: - fam = "wxSCRIPT"; - break; - case wxSWISS: - fam = "wxSWISS"; - break; - case wxMODERN: - fam = "wxMODERN"; - break; - case wxTELETYPE: - fam = "wxTELETYPE"; - break; - default: - fam = "wxDEFAULT"; - break; - } - return fam; + return M_FONTDATA->m_pointSize; } -/* New font system */ -wxString wxFont::GetFaceName() const +int wxFont::GetFamily() const { - wxString str(""); - if (M_FONTDATA) - str = M_FONTDATA->m_faceName ; - return str; + return M_FONTDATA->m_family; } -wxString wxFont::GetStyleString() const +int wxFont::GetFontId() const { - wxString styl(""); - switch (GetStyle()) - { - case wxITALIC: - styl = "wxITALIC"; - break; - case wxSLANT: - styl = "wxSLANT"; - break; - default: - styl = "wxNORMAL"; - break; - } - return styl; + return M_FONTDATA->m_fontId; } -wxString wxFont::GetWeightString() const +int wxFont::GetStyle() const { - wxString w(""); - switch (GetWeight()) - { - case wxBOLD: - w = "wxBOLD"; - break; - case wxLIGHT: - w = "wxLIGHT"; - break; - default: - w = "wxNORMAL"; - break; - } - return w; + return M_FONTDATA->m_style; +} + +int wxFont::GetWeight() const +{ + return M_FONTDATA->m_weight; +} + +bool wxFont::GetUnderlined() const +{ + return M_FONTDATA->m_underlined; +} + +wxString wxFont::GetFaceName() const +{ + wxString str; + if ( M_FONTDATA ) + str = M_FONTDATA->m_faceName ; + return str; +} + +wxFontEncoding wxFont::GetEncoding() const +{ + return M_FONTDATA->m_encoding; } diff --git a/src/mac/frame.cpp b/src/mac/frame.cpp index 5a95ac9097..cd7a3deeff 100644 --- a/src/mac/frame.cpp +++ b/src/mac/frame.cpp @@ -52,12 +52,10 @@ wxFrame::wxFrame() #if wxUSE_TOOLBAR m_frameToolBar = NULL ; #endif - m_macShown = false ; + // in order to be able to give size events on show m_frameMenuBar = NULL; m_frameStatusBar = NULL; - - m_windowParent = NULL; m_iconized = FALSE; } @@ -147,7 +145,6 @@ bool wxFrame::Create(wxWindow *parent, UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; m_macWindowData->m_macFocus = NULL ; - m_macShown = false ; return TRUE; } diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index e17f1b8213..3b9c54ce77 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -106,57 +106,120 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { -// DisposeExtLDEFInfo( m_macList ) ; + Free() ; + DisposeExtLDEFInfo( m_macList ) ; } -void wxListBox::SetFirstItem(int N) +void wxListBox::Free() { - MacScrollTo( N ) ; +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + size_t uiCount = m_aItems.Count(); + while ( uiCount-- != 0 ) { + delete m_aItems[uiCount]; + } + + m_aItems.Clear(); + } + else +#endif // wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + for ( size_t n = 0; n < (size_t)m_noItems; n++ ) + { + delete GetClientObject(n); + } + } } -void wxListBox::SetFirstItem(const wxString& s) +void wxListBox::DoSetFirstItem(int N) { - MacScrollTo( FindString( s ) ) ; + MacScrollTo( N ) ; } void wxListBox::Delete(int N) { - m_dataArray.Remove( N ) ; + wxCHECK_RET( N >= 0 && N < m_noItems, + wxT("invalid index in wxListBox::Delete") ); + +#if wxUSE_OWNER_DRAWN + delete m_aItems[N]; + m_aItems.Remove(N); +#else // !wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + delete GetClientObject(N); + } +#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN m_stringArray.Remove( N ) ; m_noItems --; MacDelete( N ) ; + SetHorizontalExtent(""); } -void wxListBox::Append(const wxString& item) -{ - Append( item , NULL ) ; -} - -void wxListBox::Append(const wxString& item, char *Client_data) +int wxListBox::DoAppend(const wxString& item) { + int index = m_noItems ; if( wxApp::s_macDefaultEncodingIsPC ) { m_stringArray.Add( wxMacMakeMacStringFromPC( item ) ) ; } else m_stringArray.Add( item ) ; - m_dataArray.Add( Client_data ) ; - m_noItems ++; - + m_noItems ++; MacAppend( item ) ; + + SetHorizontalExtent(item); + + return index ; } -void wxListBox::Set(int n, const wxString *choices, char** clientData) -{ +void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) +{ + MacSetRedraw( false ) ; Clear() ; + int n = choices.GetCount(); + for( int i = 0 ; i < n ; ++i ) { if ( clientData ) + { +#if wxUSE_OWNER_DRAWN + wxASSERT_MSG(clientData[i] == NULL, + wxT("Can't use client data with owner-drawn listboxes")); +#else // !wxUSE_OWNER_DRAWN Append( choices[i] , clientData[0] ) ; + #endif + } else Append( choices[i] ) ; } + +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) { + // first delete old items + size_t ui = m_aItems.Count(); + while ( ui-- != 0 ) { + delete m_aItems[ui]; + } + m_aItems.Empty(); + + // then create new ones + for ( ui = 0; ui < (size_t)m_noItems; ui++ ) { + wxOwnerDrawn *pNewItem = CreateItem(ui); + pNewItem->SetName(choices[ui]); + m_aItems.Add(pNewItem); + } + } +#endif // wxUSE_OWNER_DRAWN + MacSetRedraw( true ) ; +} + +bool wxListBox::HasMultipleSelection() const +{ + return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); } int wxListBox::FindString(const wxString& st) const @@ -192,10 +255,12 @@ int wxListBox::FindString(const wxString& st) const void wxListBox::Clear() { + Free(); m_noItems = 0; m_stringArray.Empty() ; m_dataArray.Empty() ; MacClear() ; + SetHorizontalExtent(); } void wxListBox::SetSelection(int N, bool select) @@ -205,7 +270,7 @@ void wxListBox::SetSelection(int N, bool select) MacSetSelection( N , select ) ; } -bool wxListBox::Selected(int N) const +bool wxListBox::IsSelected(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE, "invalid index in wxListBox::Selected" ); @@ -213,28 +278,33 @@ bool wxListBox::Selected(int N) const return MacIsSelected( N ) ; } -void wxListBox::Deselect(int N) -{ - wxCHECK_RET( N >= 0 && N < m_noItems, - "invalid index in wxListBox::Deselect" ); - - SetSelection( N , false ) ; -} - -char *wxListBox::GetClientData(int N) const +void *wxListBox::DoGetItemClientData(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, NULL, "invalid index in wxListBox::GetClientData" ); - return m_dataArray[N]; + return (void *)m_dataArray[N]; } -void wxListBox::SetClientData(int N, char *Client_data) +void wxListBox::DoSetItemClientData(int N, void *Client_data) { wxCHECK_RET( N >= 0 && N < m_noItems, "invalid index in wxListBox::SetClientData" ); - m_dataArray[N] = Client_data ; +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + // client data must be pointer to wxOwnerDrawn, otherwise we would crash + // in OnMeasure/OnDraw. + wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); + } +#endif // wxUSE_OWNER_DRAWN + m_dataArray[N] = (char*) Client_data ; +} + +void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData) +{ + DoSetItemClientData(n, clientData); } // Return number of selections and an array of selected integers @@ -277,8 +347,13 @@ wxString wxListBox::GetString(int N) const return m_stringArray[N] ; } -void wxListBox::InsertItems(int nItems, const wxString items[], int pos) +void wxListBox::DoInsertItems(const wxArrayString& items, int pos) { + wxCHECK_RET( pos >= 0 && pos <= m_noItems, + wxT("invalid index in wxListBox::InsertItems") ); + + int nItems = items.GetCount(); + for ( int i = 0 ; i < nItems ; i++ ) { m_stringArray.Insert( items[i] , pos + i ) ; @@ -295,46 +370,11 @@ void wxListBox::SetString(int N, const wxString& s) MacSet( N , s ) ; } -int wxListBox::Number () const -{ - return m_noItems; -} - -// For single selection items only -wxString wxListBox::GetStringSelection () const -{ - int sel = GetSelection (); - if (sel > -1) - { - return GetString (sel); - } - else - return wxString(""); -} - -bool wxListBox::SetStringSelection (const wxString& s, bool flag) +wxSize wxListBox::DoGetBestSize() { - int sel = FindString (s); - if (sel > -1) - { - SetSelection (sel, flag); - return TRUE; - } - else - return FALSE; + return wxSize(100, 100); } -void wxListBox::Command (wxCommandEvent & event) -{ - if (event.m_extraLong) - SetSelection (event.m_commandInt); - else - { - Deselect (event.m_commandInt); - return; - } - ProcessCommand (event); -} // ============================================================================ // list box control implementation @@ -484,29 +524,27 @@ void wxListBox::MacSetRedraw( bool doDraw ) void wxListBox::MacDoClick() { wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); + event.SetEventObject( this ); + wxArrayInt aSelections; - int count = GetSelections(aSelections); + int n, count = GetSelections(aSelections); if ( count > 0 ) { event.m_commandInt = aSelections[0] ; - event.m_clientData = GetClientData(event.m_commandInt); - wxString str(GetString(event.m_commandInt)); - if (str != "") - event.m_commandString = copystring((char *)(const char *)str); + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + event.SetString( GetString(n) ); } else { - return ; - /* - event.m_commandInt = -1 ; - event.m_commandString = copystring("") ; - */ + n = -1; } - event.SetEventObject( this ); - ProcessCommand(event); - if (event.m_commandString) - delete[] event.m_commandString ; + event.m_commandInt = n; + + GetEventHandler()->ProcessEvent(event); } void wxListBox::MacDoDoubleClick() diff --git a/src/mac/mdi.cpp b/src/mac/mdi.cpp index 4869697cd7..de142a0e29 100644 --- a/src/mac/mdi.cpp +++ b/src/mac/mdi.cpp @@ -82,17 +82,7 @@ void wxMDIParentFrame::GetClientSize(int *x, int *y) const void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) { - // TODO - if (!menu_bar) - { - m_frameMenuBar = NULL; - return; - } - - if (menu_bar->m_menuBarFrame) - return; - - m_frameMenuBar = menu_bar; + wxFrame::SetMenuBar( menu_bar ) ; } void wxMDIParentFrame::OnSize(wxSizeEvent& event) @@ -211,16 +201,7 @@ void wxMDIChildFrame::GetPosition(int *x, int *y) const void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) { - // TODO - if (!menu_bar) - { - m_frameMenuBar = NULL; - return; - } - - if (menu_bar->m_menuBarFrame) - return; - m_frameMenuBar = menu_bar; + return wxFrame::SetMenuBar( menu_bar ) ; } // MDI operations diff --git a/src/mac/menu.cpp b/src/mac/menu.cpp index b22001b870..35589ca6e1 100644 --- a/src/mac/menu.cpp +++ b/src/mac/menu.cpp @@ -178,69 +178,114 @@ static void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutC short wxMenu::s_macNextMenuId = 2 ; -wxMenu::wxMenu(const wxString& title, const wxFunction func) +void wxMenu::Init() { - m_title = title; - m_parent = NULL; - m_eventHandler = this; - m_noItems = 0; - m_menuBar = NULL; - m_pInvokingWindow = NULL ; - m_clientData = (void*) NULL; - if (m_title != "") + m_doBreak = FALSE; + + // create the menu + Str255 label; + wxMacBuildMenuString( label, NULL , NULL , m_title , false ); + m_macMenuId = s_macNextMenuId++; + wxCHECK_RET( s_macNextMenuId < 236 , "menu ids > 235 cannot be used for submenus on mac" ); + m_hMenu = ::NewMenu(m_macMenuId, label); + + if ( !m_hMenu ) + { + wxLogLastError("CreatePopupMenu"); + } + + // if we have a title, insert it in the beginning of the menu + if ( !!m_title ) { Append(idMenuTitle, m_title) ; AppendSeparator() ; } +} - Callback(func); +wxMenu::~wxMenu() +{ + if (m_hMenu) + ::DisposeMenu(m_hMenu); - Str255 label; - wxMacBuildMenuString( label, NULL , NULL , title , false ); - m_macMenuId = s_macNextMenuId++; - wxCHECK_RET( s_macNextMenuId < 236 , "menu ids > 235 cannot be used for submenus on mac" ); - m_macMenuHandle = ::NewMenu(m_macMenuId, label); - m_macMenuEnabled = true ; +#if wxUSE_ACCEL + // delete accels + WX_CLEAR_ARRAY(m_accels); +#endif // wxUSE_ACCEL } -// The wxWindow destructor will take care of deleting the submenus. -wxMenu::~wxMenu() +void wxMenu::Break() { - wxNode *node = m_menuItems.First(); - while (node) - { - wxMenuItem *item = (wxMenuItem *)node->Data(); + // not available on the mac platform +} - // Delete child menus. - // Beware: they must not be appended to children list!!! - // (because order of delete is significant) - if (item->GetSubMenu()) - item->DeleteSubMenu(); +#if wxUSE_ACCEL - wxNode *next = node->Next(); - delete item; - delete node; - node = next; +int wxMenu::FindAccel(int id) const +{ + size_t n, count = m_accels.GetCount(); + for ( n = 0; n < count; n++ ) + { + if ( m_accels[n]->m_command == id ) + return n; } - if (m_macMenuHandle) - ::DisposeMenu(m_macMenuHandle); + + return wxNOT_FOUND; } -void wxMenu::Break() +void wxMenu::UpdateAccel(wxMenuItem *item) { - // not available on the mac platform + // find the (new) accel for this item + wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText()); + if ( accel ) + accel->m_command = item->GetId(); + + // find the old one + int n = FindAccel(item->GetId()); + if ( n == wxNOT_FOUND ) + { + // no old, add new if any + if ( accel ) + m_accels.Add(accel); + else + return; // skipping RebuildAccelTable() below + } + else + { + // replace old with new or just remove the old one if no new + delete m_accels[n]; + if ( accel ) + m_accels[n] = accel; + else + m_accels.Remove(n); + } + + if ( IsAttached() ) + { + m_menuBar->RebuildAccelTable(); + } } +#endif // wxUSE_ACCEL + // function appends a new item or submenu to the menu -void wxMenu::Append(wxMenuItem *pItem) +// append a new item or submenu to the menu +bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { - wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" ); - - m_menuItems.Append(pItem); + wxASSERT_MSG( pItem != NULL, "can't append NULL item to the menu" ); +#if wxUSE_ACCEL + UpdateAccel(pItem); +#endif // wxUSE_ACCEL if ( pItem->IsSeparator() ) { - MacAppendMenu(m_macMenuHandle, "\p-"); + if ( pos == (size_t)-1 ) + { + MacAppendMenu(m_hMenu, "\p-"); + } + else + { + MacInsertMenuItem(m_hMenu, "\p-" , pos); + } } else { @@ -248,9 +293,9 @@ void wxMenu::Append(wxMenuItem *pItem) if ( pSubMenu != NULL ) { Str255 label; - wxCHECK_RET( pSubMenu->m_macMenuHandle != NULL , "invalid submenu added"); - pSubMenu->m_parent = this ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetName() ,false); + wxASSERT_MSG( pSubMenu->m_hMenu != NULL , "invalid submenu added"); + pSubMenu->m_menuParent = this ; + wxMacBuildMenuString( label , NULL , NULL , pItem->GetText() ,false); // hardcoded adding of the submenu combination for mac @@ -264,144 +309,139 @@ void wxMenu::Append(wxMenuItem *pItem) label[theEnd] = 0x00; label[0] = theEnd; - if (wxMenuBar::s_macInstalledMenuBar == m_menuBar) + if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar) { - ::InsertMenu( pSubMenu->m_macMenuHandle , -1 ) ; + ::InsertMenu( pSubMenu->m_hMenu , -1 ) ; } - ::AppendMenu(m_macMenuHandle, label); + if ( pos == (size_t)-1 ) + { + MacAppendMenu(m_hMenu, label); + } + else + { + MacInsertMenuItem(m_hMenu, label , pos); + } } else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetName(), pItem->GetId() == wxApp::s_macAboutMenuItemId); + wxMacBuildMenuString( label , NULL , NULL , pItem->GetText(), pItem->GetId() == wxApp::s_macAboutMenuItemId); if ( label[0] == 0 ) { // we cannot add empty menus on mac label[0] = 1 ; label[1] = ' ' ; } - ::AppendMenu(m_macMenuHandle, label ); + if ( pos == (size_t)-1 ) + { + MacAppendMenu(m_hMenu, label); + } + else + { + MacInsertMenuItem(m_hMenu, label , pos); + } if ( pItem->GetId() == idMenuTitle ) { - UMADisableMenuItem( m_macMenuHandle , CountMItems( m_macMenuHandle ) ) ; + if ( pos == (size_t)-1 ) + { + UMADisableMenuItem( m_hMenu , CountMItems( m_hMenu ) ) ; + } + else + { + UMADisableMenuItem( m_hMenu , pos + 1 ) ; + } } } } - - m_noItems++; + // if we're already attached to the menubar, we must update it + if ( IsAttached() ) + { + m_menuBar->Refresh(); + } + return TRUE ; } -void wxMenu::AppendSeparator() +bool wxMenu::DoAppend(wxMenuItem *item) { - Append(new wxMenuItem(this, ID_SEPARATOR)); + return wxMenuBase::DoAppend(item) && DoInsertOrAppend(item); } -// Pullright item -void wxMenu::Append(int Id, const wxString& label, wxMenu *SubMenu, - const wxString& helpString) +bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) { - Append(new wxMenuItem(this, Id, label, helpString, FALSE, SubMenu)); + return wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos); } -// Ordinary menu item -void wxMenu::Append(int Id, const wxString& label, - const wxString& helpString, bool checkable) +wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) { - // 'checkable' parameter is useless for Windows. - Append(new wxMenuItem(this, Id, label, helpString, checkable)); -} + // we need to find the items position in the child list + size_t pos; + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( pos = 0; node; pos++ ) + { + if ( node->GetData() == item ) + break; -void wxMenu::Delete(int id) -{ - wxNode *node; - wxMenuItem *item; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) { - item = (wxMenuItem *)node->Data(); - if (item->GetId() == id) - break; + node = node->GetNext(); } - if (!node) - return; - - int index = pos + 1 ; + // DoRemove() (unlike Remove) can only be called for existing item! + wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") ); - if (index < 1) - return; +#if wxUSE_ACCEL + // remove the corresponding accel from the accel table + int n = FindAccel(item->GetId()); + if ( n != wxNOT_FOUND ) + { + delete m_accels[n]; - wxMenu *pSubMenu = item->GetSubMenu(); - if ( pSubMenu != NULL ) - { - ::DeleteMenuItem( m_macMenuHandle , index); - pSubMenu->m_parent = NULL; - // TODO: Why isn't subMenu deleted here??? - // Will put this in for now. Assuming this is supposed - // to delete the menu, not just remove it. - item->DeleteSubMenu(); - } - else - { - ::DeleteMenuItem( m_macMenuHandle , index); - } + m_accels.Remove(n); + } + //else: this item doesn't have an accel, nothing to do +#endif // wxUSE_ACCEL - m_menuItems.DeleteNode(node); - // TODO shouldn't we do this ? ÂŽ_m_noItems--; - delete item; -} + ::DeleteMenuItem( m_hMenu , pos + 1); -void wxMenu::Enable(int Id, bool Flag) -{ - wxMenuItem *item = FindItemForId(Id); - wxCHECK_RET( item != NULL, "can't enable non-existing menu item" ); + if ( IsAttached() ) + { + // otherwise, the chane won't be visible + m_menuBar->Refresh(); + } - item->Enable(Flag); + // and from internal data structures + return wxMenuBase::DoRemove(item); } -bool wxMenu::Enabled(int Id) const -{ - wxMenuItem *item = FindItemForId(Id); - wxCHECK( item != NULL, FALSE ); +// --------------------------------------------------------------------------- +// accelerator helpers +// --------------------------------------------------------------------------- - return item->IsEnabled(); -} +#if wxUSE_ACCEL -void wxMenu::Check(int Id, bool Flag) +// create the wxAcceleratorEntries for our accels and put them into provided +// array - return the number of accels we have +size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const { - wxMenuItem *item = FindItemForId(Id); - wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" ); + size_t count = GetAccelCount(); + for ( size_t n = 0; n < count; n++ ) + { + *accels++ = *m_accels[n]; + } - item->Check(Flag); + return count; } -bool wxMenu::Checked(int Id) const -{ - wxMenuItem *item = FindItemForId(Id); - wxCHECK( item != NULL, FALSE ); - - return item->IsChecked(); -} +#endif // wxUSE_ACCEL void wxMenu::SetTitle(const wxString& label) { Str255 title ; m_title = label ; wxMacBuildMenuString( title, NULL , NULL , label , false ); - UMASetMenuTitle( m_macMenuHandle , title ) ; - if (wxMenuBar::s_macInstalledMenuBar == m_menuBar) // are we currently installed ? - { - ::SetMenuBar( GetMenuBar() ) ; - ::InvalMenuBar() ; - } - // TODO:for submenus -> their parent item text must be corrected + UMASetMenuTitle( m_hMenu , title ) ; } -const wxString wxMenu::GetTitle() const -{ - return m_title; -} +/* void wxMenu::SetLabel(int id, const wxString& label) { @@ -418,12 +458,12 @@ void wxMenu::SetLabel(int id, const wxString& label) if (item->GetSubMenu()==NULL) { wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_macMenuHandle , index , maclabel ) ; + ::SetMenuItemText( m_hMenu , index , maclabel ) ; } else { wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_macMenuHandle , index , maclabel ) ; + ::SetMenuItemText( m_hMenu , index , maclabel ) ; } item->SetName(label); } @@ -502,60 +542,96 @@ wxString wxMenu::GetHelpString (int itemId) const wxString str(""); return (item == NULL) ? str : item->GetHelp(); } +*/ -void wxMenu::ProcessCommand(wxCommandEvent & event) +bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; +#if WXWIN_COMPATIBILITY // Try a callback if (m_callback) { - (void) (*(m_callback)) (*this, event); - processed = TRUE; + (void)(*(m_callback))(*this, event); + processed = TRUE; } +#endif WXWIN_COMPATIBILITY // Try the menu's event handler if ( !processed && GetEventHandler()) { - processed = GetEventHandler()->ProcessEvent(event); + processed = GetEventHandler()->ProcessEvent(event); } - // Try the window the menu was popped up from (and up - // through the hierarchy) - if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); + // Try the window the menu was popped up from (and up through the + // hierarchy) + wxWindow *win = GetInvokingWindow(); + if ( !processed && win ) + processed = win->GetEventHandler()->ProcessEvent(event); + + return processed; +} + + +// --------------------------------------------------------------------------- +// other +// --------------------------------------------------------------------------- + +void wxMenu::Attach(wxMenuBar *menubar) +{ + // menu can be in at most one menubar because otherwise they would both + // delete the menu pointer + wxASSERT_MSG( !m_menuBar, wxT("menu belongs to 2 menubars, expect a crash") ); + + m_menuBar = menubar; } +void wxMenu::Detach() +{ + wxASSERT_MSG( m_menuBar, wxT("can't detach menu if it's not attached") ); + + m_menuBar = NULL; +} + +wxWindow *wxMenu::GetWindow() const +{ + if ( m_invokingWindow != NULL ) + return m_invokingWindow; + else if ( m_menuBar != NULL) + return m_menuBar->GetFrame(); + + return NULL; +} +/* bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) { menu->SetInvokingWindow(this); ClientToScreen( &x , &y ) ; - ::InsertMenu( menu->m_macMenuHandle , -1 ) ; - long menuResult = ::PopUpMenuSelect(menu->m_macMenuHandle ,y,x, 0) ; + ::InsertMenu( menu->m_hMenu , -1 ) ; + long menuResult = ::PopUpMenuSelect(menu->m_hMenu ,y,x, 0) ; menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; ::DeleteMenu( menu->m_macMenuId ) ; menu->SetInvokingWindow(NULL); return TRUE; } - +*/ // helper functions returning the mac menu position for a certain item, note that this is // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0 int wxMenu::MacGetIndexFromId( int id ) { - wxNode *node; - wxMenuItem *item; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + size_t pos; + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( pos = 0; node; pos++ ) { - item = (wxMenuItem *)node->Data(); - if (item->GetId() == id) - break; - } + if ( node->GetData()->GetId() == id ) + break; + node = node->GetNext(); + } + if (!node) return 0; @@ -564,13 +640,14 @@ int wxMenu::MacGetIndexFromId( int id ) int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem ) { - wxNode *node; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + size_t pos; + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( pos = 0; node; pos++ ) { - if ((wxMenuItem *)node->Data() == pItem) - break; + if ( node->GetData() == pItem ) + break; + + node = node->GetNext(); } if (!node) @@ -581,11 +658,10 @@ int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem ) void wxMenu::MacEnableMenu( bool bDoEnable ) { - m_macMenuEnabled = bDoEnable ; if ( bDoEnable ) - UMAEnableMenuItem( m_macMenuHandle , 0 ) ; + UMAEnableMenuItem( m_hMenu , 0 ) ; else - UMADisableMenuItem( m_macMenuHandle , 0 ) ; + UMADisableMenuItem( m_hMenu , 0 ) ; ::DrawMenuBar() ; } @@ -597,7 +673,7 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in if ( m_macMenuId == macMenuId ) { - node = m_menuItems.Nth(macMenuItemNum-1); + node = GetMenuItems().Nth(macMenuItemNum-1); if (node) { wxMenuItem *pItem = (wxMenuItem*)node->Data(); @@ -605,36 +681,15 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, pItem->GetId()); event.m_timeStamp = when; event.SetEventObject(handler); - event.SetInt( pItem->GetId() ); - - { - bool processed = false ; - - // Try a callback - if (m_callback) - { - (void) (*(m_callback)) (*this, event); - processed = TRUE; - } - - // Try the menu's event handler - if ( !processed && handler) - { - processed = handler->ProcessEvent(event); - } - - // Try the window the menu was popped up from (and up - // through the hierarchy) - if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); - } + event.SetInt( pItem->GetId() ); + ProcessCommand( event ) ; return true ; } } else if ( macMenuId == kHMHelpMenuID ) { int menuItem = formerHelpMenuItems ; - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + for (pos = 0, node = GetMenuItems().First(); node; node = node->Next(), pos++) { wxMenuItem * pItem = (wxMenuItem *) node->Data() ; @@ -652,40 +707,19 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, pItem->GetId()); event.m_timeStamp = when; event.SetEventObject(handler); - event.SetInt( pItem->GetId() ); - - { - bool processed = false ; - // Try a callback - if (m_callback) - { - (void) (*(m_callback)) (*this, event); - processed = TRUE; - } - - // Try the menu's event handler - if ( !processed && handler) - { - processed = handler->ProcessEvent(event); - } - - // Try the window the menu was popped up from (and up - // through the hierarchy) - if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); - } - + event.SetInt( pItem->GetId() ); + ProcessCommand( event ) ; return true ; } } } } - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) + for (pos = 0, node = GetMenuItems().First(); node; node = node->Next(), pos++) { - wxMenuItem * pItem = (wxMenuItem *) node->Data() ; + wxMenuItem * pItem = (wxMenuItem *) node->Data() ; - wxMenu *pSubMenu = pItem->GetSubMenu() ; + wxMenu *pSubMenu = pItem->GetSubMenu() ; if ( pSubMenu != NULL ) { if ( pSubMenu->MacMenuSelect( handler , when , macMenuId , macMenuItemNum ) ) @@ -717,25 +751,26 @@ auto-merge for MDI in case this will be necessary wxMenuBar* wxMenuBar::s_macInstalledMenuBar = NULL ; -wxMenuBar::wxMenuBar() +void wxMenuBar::Init() { m_eventHandler = this; - m_menuCount = 0; - m_menus = NULL; - m_titles = NULL; m_menuBarFrame = NULL; } -wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[]) + +wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) { - m_eventHandler = this; - m_menuCount = n; - m_menus = menus; - m_titles = new wxString[n]; - int i; - for ( i = 0; i < n; i++ ) - m_titles[i] = titles[i]; - m_menuBarFrame = NULL; + Init(); + + m_titles.Alloc(count); + + for ( int i = 0; i < count; i++ ) + { + m_menus.Append(menus[i]); + m_titles.Add(titles[i]); + + menus[i]->Attach(this); + } } wxMenuBar::~wxMenuBar() @@ -746,14 +781,13 @@ wxMenuBar::~wxMenuBar() s_macInstalledMenuBar = NULL; } - int i; - for (i = 0; i < m_menuCount; i++) - { - delete m_menus[i]; - } - delete[] m_menus; - delete[] m_titles; +} + +void wxMenuBar::Refresh() +{ + wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") ); + DrawMenuBar(); } void wxMenuBar::MacInstallMenuBar() @@ -767,7 +801,7 @@ void wxMenuBar::MacInstallMenuBar() MenuHandle menu = ::GetMenuHandle( kwxMacAppleMenuId ) ; ::AppendResMenu(menu, 'DRVR'); - for (int i = 0; i < m_menuCount; i++) + for (int i = 0; i < m_menus.GetCount(); i++) { Str255 label; wxNode *node; @@ -789,7 +823,7 @@ void wxMenuBar::MacInstallMenuBar() formerHelpMenuItems = CountMenuItems( mh ) ; } - for (pos = 0 , node = menu->m_menuItems.First(); node; node = node->Next(), pos++) + for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; @@ -800,7 +834,7 @@ void wxMenuBar::MacInstallMenuBar() else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , item->GetName(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu + wxMacBuildMenuString( label , NULL , NULL , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu if ( label[0] == 0 ) { // we cannot add empty menus on mac @@ -824,17 +858,17 @@ void wxMenuBar::MacInstallMenuBar() else { wxMacBuildMenuString( label, NULL , NULL , m_titles[i] , false ); - UMASetMenuTitle( menu->m_macMenuHandle , label ) ; - for (pos = 0, node = menu->m_menuItems.First(); node; node = node->Next(), pos++) + UMASetMenuTitle( menu->GetHMenu() , label ) ; + for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; if (subMenu) { - ::InsertMenu( subMenu->m_macMenuHandle , -1 ) ; + ::InsertMenu( subMenu->GetHMenu() , -1 ) ; } } - ::InsertMenu(m_menus[i]->m_macMenuHandle, 0); + ::InsertMenu(m_menus[i]->GetHMenu(), 0); } } ::DrawMenuBar() ; @@ -842,263 +876,139 @@ void wxMenuBar::MacInstallMenuBar() s_macInstalledMenuBar = this; } - -// Must only be used AFTER menu has been attached to frame, -// otherwise use individual menus to enable/disable items -void wxMenuBar::Enable(int id, bool flag) +void wxMenuBar::EnableTop(size_t pos, bool enable) { - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return; - - item->Enable( flag ) ; -} - -void wxMenuBar::EnableTop(int pos, bool flag) -{ - m_menus[pos]->MacEnableMenu( flag ) ; -} - -// Must only be used AFTER menu has been attached to frame, -// otherwise use individual menus -void wxMenuBar::Check(int id, bool flag) -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return; - - if (!item->IsCheckable()) - return ; - - item->Check( flag ) ; -} - -bool wxMenuBar::Checked(int id) const -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return FALSE; - - if (!item->IsCheckable()) - return FALSE ; - - return item->IsChecked() ; + wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") ); + m_menus[pos]->MacEnableMenu( enable ) ; + Refresh(); } -bool wxMenuBar::Enabled(int id) const +void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - if (!item) - return FALSE; - - if ( !item->IsEnabled() ) - return FALSE ; - - if ( itemMenu->m_macMenuEnabled == false ) - return FALSE ; - - while( itemMenu->m_parent ) - { - itemMenu = (wxMenu*) itemMenu->m_parent ; - if ( itemMenu->IsKindOf( CLASSINFO( wxMenu ) ) ) - { - if ( itemMenu->m_macMenuEnabled == false ) - return FALSE ; - } - } - - return TRUE ; -} + wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); + m_titles[pos] = label; -void wxMenuBar::SetLabel(int id, const wxString& label) -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - - if (!item) + if ( !IsAttached() ) + { return; + } - itemMenu->SetLabel( id , label ) ; -} - -wxString wxMenuBar::GetLabel(int id) const -{ - wxMenu *itemMenu = NULL; - wxMenuItem *item = FindItemForId(id, &itemMenu) ; - - if (!item) - return wxString(""); - - return itemMenu->GetLabel( id ) ; -} - -void wxMenuBar::SetLabelTop(int pos, const wxString& label) -{ m_menus[pos]->SetTitle( label ) ; -} - -wxString wxMenuBar::GetLabelTop(int pos) const -{ - return m_menus[pos]->GetTitle() ; -} - -bool wxMenuBar::OnDelete(wxMenu *a_menu, int pos) -{ - if (s_macInstalledMenuBar == this) + if (wxMenuBar::s_macInstalledMenuBar == this) // are we currently installed ? { - ::DeleteMenu( a_menu->m_macMenuId /* m_menus[pos]->m_macMenuId */ ) ; + ::SetMenuBar( GetMenuBar() ) ; ::InvalMenuBar() ; - return TRUE ; - } - else - { - return TRUE ; } } -bool wxMenuBar::OnAppend(wxMenu *a_menu, const char *title) +wxString wxMenuBar::GetLabelTop(size_t pos) const { - if (!a_menu->m_macMenuHandle) - return FALSE; + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetLabelTop") ); - if (s_macInstalledMenuBar == this) - { - Str255 label; - wxMacBuildMenuString( label, NULL , NULL , title , false ); - UMASetMenuTitle( a_menu->m_macMenuHandle , label ) ; - ::InsertMenu( a_menu->m_macMenuHandle , 0 ) ; - ::InvalMenuBar() ; - return TRUE ; - } - else - { - return TRUE ; - } + return m_titles[pos]; } -void wxMenuBar::Append (wxMenu * menu, const wxString& title) +int wxMenuBar::FindMenu(const wxString& title) { - if (!OnAppend(menu, title)) - return; + wxString menuTitle = wxStripMenuCodes(title); - m_menuCount ++; - wxMenu **new_menus = new wxMenu *[m_menuCount]; - wxString *new_titles = new wxString[m_menuCount]; - int i; - - for (i = 0; i < m_menuCount - 1; i++) - { - new_menus[i] = m_menus[i]; - m_menus[i] = NULL; - new_titles[i] = m_titles[i]; - m_titles[i] = ""; - } - if (m_menus) + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) { - delete[]m_menus; - delete[]m_titles; + wxString title = wxStripMenuCodes(m_titles[i]); + if ( menuTitle == title ) + return i; } - m_menus = new_menus; - m_titles = new_titles; - m_menus[m_menuCount - 1] = (wxMenu *)menu; - m_titles[m_menuCount - 1] = title; + return wxNOT_FOUND; - ((wxMenu *)menu)->m_menuBar = (wxMenuBar *) this; - ((wxMenu *)menu)->SetParent(this); } -void wxMenuBar::Delete(wxMenu * menu, int i) + +// --------------------------------------------------------------------------- +// wxMenuBar construction +// --------------------------------------------------------------------------- + +// --------------------------------------------------------------------------- +// wxMenuBar construction +// --------------------------------------------------------------------------- + +wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { - int j; - int ii = (int) i; + wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title); + if ( !menuOld ) + return FALSE; + m_titles[pos] = title; - if (menu != 0) - { - for (ii = 0; ii < m_menuCount; ii++) - { - if (m_menus[ii] == menu) - break; - } - if (ii >= m_menuCount) - return; - } else + if ( IsAttached() ) { - if (ii < 0 || ii >= m_menuCount) - return; - menu = m_menus[ii]; - } + if (s_macInstalledMenuBar == this) + { + ::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; + { + Str255 label; + wxMacBuildMenuString( label, NULL , NULL , title , false ); + UMASetMenuTitle( menu->GetHMenu() , label ) ; + if ( pos == m_menus.GetCount() - 1) + { + ::InsertMenu( menu->GetHMenu() , 0 ) ; + } + else + { + ::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; + } + } + } - if (!OnDelete(menu, ii)) - return; - menu->SetParent(NULL); +#if wxUSE_ACCEL + if ( menuOld->HasAccels() || menu->HasAccels() ) + { + // need to rebuild accell table + RebuildAccelTable(); + } +#endif // wxUSE_ACCEL - -- m_menuCount; - for (j = ii; j < m_menuCount; j++) - { - m_menus[j] = m_menus[j + 1]; - m_titles[j] = m_titles[j + 1]; + Refresh(); } -} -// Find the menu menuString, item itemString, and return the item id. -// Returns -1 if none found. -int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const -{ - char buf1[200]; - char buf2[200]; - wxStripMenuCodes ((char *)(const char *)menuString, buf1); - int i; - for (i = 0; i < m_menuCount; i++) - { - wxStripMenuCodes ((char *)(const char *)m_titles[i], buf2); - if (strcmp (buf1, buf2) == 0) - return m_menus[i]->FindItem (itemString); - } - return -1; + return menuOld; } -wxMenuItem *wxMenuBar::FindItemForId (int Id, wxMenu ** itemMenu) const +bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) { - if (itemMenu) - *itemMenu = NULL; + if ( !wxMenuBarBase::Insert(pos, menu, title) ) + return FALSE; - wxMenuItem *item = NULL; - int i; - for (i = 0; i < m_menuCount; i++) - if ((item = m_menus[i]->FindItemForId (Id, itemMenu))) - return item; - return NULL; -} + m_titles.Insert(title, pos); -void wxMenuBar::SetHelpString (int Id, const wxString& helpString) -{ - int i; - for (i = 0; i < m_menuCount; i++) + menu->Attach(this); + + if ( IsAttached() ) { - if (m_menus[i]->FindItemForId (Id)) + if ( pos == (size_t) -1 ) + { + ::InsertMenu( menu->GetHMenu() , 0 ) ; + } + else + { + ::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; + } + +#if wxUSE_ACCEL + if ( menu->HasAccels() ) { - m_menus[i]->SetHelpString (Id, helpString); - return; + // need to rebuild accell table + RebuildAccelTable(); } - } -} +#endif // wxUSE_ACCEL -wxString wxMenuBar::GetHelpString (int Id) const -{ - int i; - for (i = 0; i < m_menuCount; i++) - { - if (m_menus[i]->FindItemForId (Id)) - return wxString(m_menus[i]->GetHelpString (Id)); + Refresh(); } - return wxString(""); + + return TRUE; } void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, int macMenuItemNum) @@ -1115,9 +1025,9 @@ void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, } else { - for (int i = 0; i < m_menuCount; i++) + for (int i = 0; i < m_menus.GetCount() ; i++) { - if ( m_menus[i]->m_macMenuId == macMenuId || + if ( m_menus[i]->MacGetMenuId() == macMenuId || ( macMenuId == kHMHelpMenuID && ( m_titles[i] == "?" || m_titles[i] == wxApp::s_macHelpMenuTitleName ) ) ) { @@ -1131,7 +1041,7 @@ void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, } } - for (int i = 0; i < m_menuCount; i++) + for (int i = 0; i < m_menus.GetCount(); i++) { if ( m_menus[i]->MacMenuSelect( handler , when , macMenuId , macMenuItemNum ) ) { diff --git a/src/mac/menuitem.cpp b/src/mac/menuitem.cpp index 9195fdc50a..ef67483ca3 100644 --- a/src/mac/menuitem.cpp +++ b/src/mac/menuitem.cpp @@ -37,24 +37,26 @@ // ----------- wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id, - const wxString& strName, const wxString& strHelp, + const wxString& text, const wxString& strHelp, bool bCheckable, - wxMenu *pSubMenu) : - m_bCheckable(bCheckable), - m_strName(strName), - m_strHelp(strHelp) + wxMenu *pSubMenu) { - wxASSERT( pParentMenu != NULL ); + wxASSERT( pParentMenu != NULL ); - m_pParentMenu = pParentMenu; - m_pSubMenu = pSubMenu; - m_idItem = id; - m_bEnabled = TRUE; + m_parentMenu = pParentMenu; + m_subMenu = pSubMenu; + m_isEnabled = TRUE; + m_isChecked = FALSE; + m_id = id; + m_text = text; + m_isCheckable = bCheckable; + m_help = strHelp; - if ( m_strName == "E&xit" ||m_strName == "Exit" ) - { - m_strName = "Quit\tCtrl+Q" ; - } + + if ( m_text == "E&xit" ||m_text == "Exit" ) + { + m_text = "Quit\tCtrl+Q" ; + } } wxMenuItem::~wxMenuItem() @@ -64,53 +66,57 @@ wxMenuItem::~wxMenuItem() // misc // ---- +/* + // delete the sub menu void wxMenuItem::DeleteSubMenu() { - wxASSERT( m_pSubMenu != NULL ); + wxASSERT( m_subMenu != NULL ); - delete m_pSubMenu; - m_pSubMenu = NULL; + delete m_subMenu; + m_subMenu = NULL; } +*/ + // change item state // ----------------- void wxMenuItem::Enable(bool bDoEnable) { - if ( m_bEnabled != bDoEnable ) { - if ( m_pSubMenu == NULL ) + if ( m_isEnabled != bDoEnable ) { + if ( m_subMenu == NULL ) { // normal menu item - if ( m_pParentMenu->m_macMenuHandle ) + if ( m_parentMenu->GetHMenu() ) { - int index = m_pParentMenu->MacGetIndexFromItem( this ) ; + int index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( index >= 1 ) { if ( bDoEnable ) - UMAEnableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ; else - UMADisableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ; } } } else { // submenu - if ( m_pParentMenu->m_macMenuHandle ) + if ( m_parentMenu->GetHMenu() ) { - int index = m_pParentMenu->MacGetIndexFromItem( this ) ; + int index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( index >= 1 ) { if ( bDoEnable ) - UMAEnableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ; else - UMADisableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ; + UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ; } } } - m_bEnabled = bDoEnable; + m_isEnabled = bDoEnable; } } @@ -118,18 +124,18 @@ void wxMenuItem::Check(bool bDoCheck) { wxCHECK_RET( IsCheckable(), "only checkable items may be checked" ); - if ( m_bChecked != bDoCheck ) + if ( m_isChecked != bDoCheck ) { - m_bChecked = bDoCheck; - if ( m_pParentMenu->m_macMenuHandle ) + m_isChecked = bDoCheck; + if ( m_parentMenu->GetHMenu() ) { - int index = m_pParentMenu->MacGetIndexFromItem( this ) ; + int index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( index >= 1 ) { if ( bDoCheck ) - ::SetItemMark( m_pParentMenu->m_macMenuHandle , index , 0x12 ) ; // checkmark + ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark else - ::SetItemMark( m_pParentMenu->m_macMenuHandle , index , 0 ) ; // no mark + ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark } } } diff --git a/src/mac/print.cpp b/src/mac/print.cpp index 1064058925..e69de29bb2 100644 --- a/src/mac/print.cpp +++ b/src/mac/print.cpp @@ -1,82 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: print.cpp -// Purpose: Print framework -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 -// RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "print.h" -#endif - -#include "wx/mac/print.h" -#include "wx/mac/printdlg.h" - -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxPrinter, wxPrinterBase) -IMPLEMENT_CLASS(wxPrintPreview, wxPrintPreviewBase) -#endif - -/* - * Printer - */ - -wxPrinter::wxPrinter(wxPrintData *data): - wxPrinterBase(data) -{ -} - -wxPrinter::~wxPrinter() -{ -} - -bool wxPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) -{ - // TODO. See wxPostScriptPrinter::Print for hints. - return FALSE; -} - -bool wxPrinter::PrintDialog(wxWindow *parent) -{ - wxPrintDialog dialog(parent, & m_printData); - return (dialog.ShowModal() == wxID_OK); -} - -bool wxPrinter::Setup(wxWindow *parent) -{ - wxPrintDialog dialog(parent, & m_printData); - dialog.GetPrintData().SetSetupDialog(TRUE); - return (dialog.ShowModal() == wxID_OK); -} - -/* - * Print preview - */ - -wxPrintPreview::wxPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): - wxPrintPreviewBase(printout, printoutForPrinting, data) -{ - DetermineScaling(); -} - -wxPrintPreview::~wxPrintPreview() -{ -} - -bool wxPrintPreview::Print(bool interactive) -{ - if (!m_printPrintout) - return FALSE; - wxPrinter printer(&m_printData); - return printer.Print(m_previewFrame, m_printPrintout, interactive); -} - -void wxPrintPreview::DetermineScaling() -{ - // TODO -} - diff --git a/src/mac/printdlg.cpp b/src/mac/printdlg.cpp index 18c7a8427e..5f914ddbfd 100644 --- a/src/mac/printdlg.cpp +++ b/src/mac/printdlg.cpp @@ -14,7 +14,7 @@ #endif #include "wx/object.h" -#include "wx/mac/printdlg.h" +#include "wx/printdlg.h" #include "wx/dcprint.h" // Use generic page setup dialog: use your own native one if one exists. @@ -24,30 +24,43 @@ IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog) IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) #endif -wxPrintDialog::wxPrintDialog(): - wxDialog() +wxPrintDialog::wxPrintDialog() { m_dialogParent = NULL; + m_printerDC = NULL; + m_destroyDC = TRUE; } -wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data): - wxDialog() +wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data) { Create(p, data); } -bool wxPrintDialog::Create(wxWindow *p, wxPrintData* data) +wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data) +{ + wxPrintDialogData data2; + if ( data ) + data2 = *data; + + Create(p, &data2); +} + +bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) { m_dialogParent = p; + m_printerDC = NULL; + m_destroyDC = TRUE; if ( data ) - m_printData = *data; + m_printDialogData = *data; return TRUE; } wxPrintDialog::~wxPrintDialog() { + if (m_destroyDC && m_printerDC) + delete m_printerDC; } int wxPrintDialog::ShowModal() @@ -60,10 +73,10 @@ int wxPrintDialog::ShowModal() if ( !err ) { - m_printData.ConvertToNative() ; - if ( m_printData.macPrintInfo && ::PrJobDialog( m_printData.macPrintInfo ) ) + m_printDialogData.ConvertToNative() ; + if ( m_printDialogData.m_macPrintInfo && ::PrJobDialog( m_printDialogData.m_macPrintInfo ) ) { - m_printData.ConvertFromNative() ; + m_printDialogData.ConvertFromNative() ; result = wxID_OK ; } @@ -80,7 +93,7 @@ int wxPrintDialog::ShowModal() wxDC *wxPrintDialog::GetPrintDC() { - return new wxPrinterDC( m_printData ) ; + return new wxPrinterDC( m_printDialogData.GetPrintData() ) ; } /* diff --git a/src/mac/radiobox.cpp b/src/mac/radiobox.cpp index 3393009f47..b1f4dbf615 100644 --- a/src/mac/radiobox.cpp +++ b/src/mac/radiobox.cpp @@ -67,17 +67,6 @@ wxRadioBox::~wxRadioBox() // TODO } -wxString wxRadioBox::GetLabel(int item) const -{ - // TODO - return wxString(""); -} - -void wxRadioBox::SetLabel(int item, const wxString& label) -{ - // TODO -} - int wxRadioBox::FindString(const wxString& s) const { // TODO @@ -106,28 +95,28 @@ wxString wxRadioBox::GetString(int n) const return wxString(""); } -void wxRadioBox::SetSize(int x, int y, int width, int height, int sizeFlags) +void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - wxControl::SetSize( x , y , width , height , sizeFlags ) ; + wxControl::DoSetSize( x , y , width , height , sizeFlags ) ; } void wxRadioBox::GetSize(int *width, int *height) const { - // TODO + wxControl::GetSize( width , height ) ; } void wxRadioBox::GetPosition(int *x, int *y) const { - // TODO + wxControl::GetPosition( x , y ) ; } -wxString wxRadioBox::GetLabel() const +wxString wxRadioBox::GetLabel( int item ) const { // TODO return wxString(""); } -void wxRadioBox::SetLabel(const wxString& label) +void wxRadioBox::SetLabel(int item , const wxString& label) { // TODO } @@ -139,23 +128,18 @@ void wxRadioBox::SetFocus() bool wxRadioBox::Show(bool show) { - // TODO - return wxWindow::Show( show ) ; + return wxControl::Show( show ) ; } // Enable a specific button void wxRadioBox::Enable(int item, bool enable) { - wxControl::Enable(enable); - // TODO } // Enable all controls -void wxRadioBox::Enable(bool enable) +bool wxRadioBox::Enable(bool enable) { - wxControl::Enable(enable); - - // TODO + return wxControl::Enable(enable); } // Show a specific button diff --git a/src/mac/spinbutt.cpp b/src/mac/spinbutt.cpp index 8f3e1533b8..d91374445a 100644 --- a/src/mac/spinbutt.cpp +++ b/src/mac/spinbutt.cpp @@ -16,16 +16,19 @@ #include "wx/spinbutt.h" #include "wx/mac/uma.h" +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- + #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) + IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) + IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); #endif -wxSpinButton::wxSpinButton() -{ - m_min = 0; - m_max = 100; -} - bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { @@ -78,14 +81,6 @@ void wxSpinButton::SetRange(int minVal, int maxVal) m_max = maxVal; } -// Spin event -IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) - -wxSpinEvent::wxSpinEvent(wxEventType commandType, int id): - wxScrollEvent(commandType, id) -{ -} - void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) { if ( m_macControl == NULL ) diff --git a/src/mac/stattext.cpp b/src/mac/stattext.cpp index 14c69f1d96..54f6eb4e58 100644 --- a/src/mac/stattext.cpp +++ b/src/mac/stattext.cpp @@ -47,7 +47,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, void wxStaticText::SetLabel(const wxString& st , bool resize ) { - m_label = st ; + SetTitle( st ) ; wxString label ; if( wxApp::s_macDefaultEncodingIsPC ) diff --git a/src/mac/textctrl.cpp b/src/mac/textctrl.cpp index d553477f93..21648fc476 100644 --- a/src/mac/textctrl.cpp +++ b/src/mac/textctrl.cpp @@ -409,73 +409,51 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) void wxTextCtrl::OnChar(wxKeyEvent& event) { - bool handleIt = true ; switch( event.KeyCode() ) { case WXK_RETURN: { -/* Oh yes it will, because we also specify DLGC_WANTCHARS - wxASSERT_MSG( m_windowStyle & wxTE_PROCESS_ENTER, - "this text ctrl should never receive return" ); -*/ - - if ( (m_windowStyle & wxTE_MULTILINE) == 0 ) + if ( !(m_windowStyle & wxTE_MULTILINE) ) { - wxWindow* parent = GetParent() ; - while( parent ) - { - if ( parent->GetDefaultItem() ) - { - wxButton *defaultBtn = parent->GetDefaultItem() ; - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, defaultBtn->GetId() ); - event.SetEventObject(defaultBtn); - defaultBtn->Command(event); - return ; - } - parent = parent->GetParent() ; - } ; + wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + event.SetEventObject( this ); + if ( GetEventHandler()->ProcessEvent(event) ) + return; } + //else: multiline controls need Enter for themselves + break; } case WXK_TAB: - // only produce navigation event if we don't process TAB ourself or - // if it's a Shift-Tab keypress (we assume nobody will ever need - // this key combo for himself) + // always produce navigation event - even if we process TAB + // ourselves the fact that we got here means that the user code + // decided to skip processing of this TAB - probably to let it + // do its default job. // // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is // handled by Windows - if ( event.ShiftDown() || !(m_windowStyle & wxTE_PROCESS_TAB) ) { wxNavigationKeyEvent eventNav; eventNav.SetDirection(!event.ShiftDown()); eventNav.SetWindowChange(FALSE); eventNav.SetEventObject(this); - + if ( GetEventHandler()->ProcessEvent(eventNav) ) return; } break; + + default: + event.Skip(); + return; } - if ( handleIt ) - { - EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; - if ( keychar >= 0x20 ) - { - { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - wxString val(GetValue()); - if ( !val.IsNull() ) - event.m_commandString = WXSTRINGCAST val; - event.SetEventObject( this ); - ProcessCommand(event); - } - } - } + + // don't just call event.Skip() because this will cause TABs and ENTERs + // be passed upwards and we don't always want this - instead process it + // right here + + // FIXME + event.Skip(); } // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers diff --git a/src/mac/thread.cpp b/src/mac/thread.cpp index 8dd23bdce9..3dca96a6fa 100644 --- a/src/mac/thread.cpp +++ b/src/mac/thread.cpp @@ -1,71 +1,146 @@ ///////////////////////////////////////////////////////////////////////////// // Name: thread.cpp -// Purpose: wxThread Implementation. For Unix ports, see e.g. src/gtk +// Purpose: wxThread Implementation // Author: Original from Wolfram Gloger/Guilhem Lavaux -// Modified by: +// Modified by: Vadim Zeitlin to make it work :-) // Created: 04/22/98 // RCS-ID: $Id$ -// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998) +// Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998), +// Vadim Zeitlin (1999) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "thread.h" + #pragma implementation "thread.h" #endif +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#if wxUSE_THREADS + +#include + +#include + #include "wx/module.h" #include "wx/thread.h" -#include "wx/utils.h" -enum thread_state { - STATE_IDLE = 0, - STATE_RUNNING, - STATE_CANCELED, - STATE_EXITED +// the possible states of the thread ("=>" shows all possible transitions from +// this state) +enum wxThreadState +{ + STATE_NEW, // didn't start execution yet (=> RUNNING) + STATE_RUNNING, // thread is running (=> PAUSED, CANCELED) + STATE_PAUSED, // thread is temporarily suspended (=> RUNNING) + STATE_CANCELED, // thread should terminate a.s.a.p. (=> EXITED) + STATE_EXITED // thread is terminating }; -#if wxUSE_THREADS +// ---------------------------------------------------------------------------- +// static variables +// ---------------------------------------------------------------------------- -///////////////////////////////////////////////////////////////////////////// -// Static variables -///////////////////////////////////////////////////////////////////////////// +// if it's FALSE, some secondary thread is holding the GUI lock +static bool s_bGuiOwnedByMainThread = TRUE; -wxMutex *wxMainMutex; // controls access to all GUI functions +// critical section which controls access to all GUI functions: any secondary +// thread (i.e. except the main one) must enter this crit section before doing +// any GUI calls +static wxCriticalSection *s_critsectGui = NULL; -///////////////////////////////////////////////////////////////////////////// -// Windows implementation -///////////////////////////////////////////////////////////////////////////// +// critical section which protects s_nWaitingForGui variable +static wxCriticalSection *s_critsectWaitingForGui = NULL; + +// number of threads waiting for GUI in wxMutexGuiEnter() +static size_t s_nWaitingForGui = 0; + +// are we waiting for a thread termination? +static bool s_waitingForThread = FALSE; -class wxMutexInternal { +// ============================================================================ +// Windows implementation of thread classes +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxMutex implementation +// ---------------------------------------------------------------------------- +class wxMutexInternal +{ public: - // TODO: internal mutex handle + Handle p_mutex; }; wxMutex::wxMutex() { p_internal = new wxMutexInternal; - // TODO: create internal mutext handle +// p_internal->p_mutex = CreateMutex(NULL, FALSE, NULL); + if ( !p_internal->p_mutex ) + { + wxLogSysError(_("Can not create mutex.")); + } + m_locked = 0; } wxMutex::~wxMutex() { if (m_locked > 0) - wxDebugMsg("wxMutex warning: freeing a locked mutex (%d locks)\n", m_locked); - // TODO: free internal mutext handle + wxLogDebug(wxT("Warning: freeing a locked mutex (%d locks)."), m_locked); +// CloseHandle(p_internal->p_mutex); } wxMutexError wxMutex::Lock() { - // TODO +/* + DWORD ret; + + ret = WaitForSingleObject(p_internal->p_mutex, INFINITE); + switch ( ret ) + { + case WAIT_ABANDONED: + return wxMUTEX_BUSY; + + case WAIT_OBJECT_0: + // ok + break; + + case WAIT_FAILED: + wxLogSysError(_("Couldn't acquire a mutex lock")); + return wxMUTEX_MISC_ERROR; + + case WAIT_TIMEOUT: + default: + wxFAIL_MSG(wxT("impossible return value in wxMutex::Lock")); + } +*/ m_locked++; return wxMUTEX_NO_ERROR; } wxMutexError wxMutex::TryLock() { - // TODO +/* + DWORD ret; + + ret = WaitForSingleObject(p_internal->p_mutex, 0); + if (ret == WAIT_TIMEOUT || ret == WAIT_ABANDONED) + return wxMUTEX_BUSY; + m_locked++; +*/ return wxMUTEX_NO_ERROR; } @@ -73,192 +148,715 @@ wxMutexError wxMutex::Unlock() { if (m_locked > 0) m_locked--; - - // TODO +/* + BOOL ret = ReleaseMutex(p_internal->p_mutex); + if ( ret == 0 ) + { + wxLogSysError(_("Couldn't release a mutex")); + return wxMUTEX_MISC_ERROR; + } +*/ return wxMUTEX_NO_ERROR; } -class wxConditionInternal { +// ---------------------------------------------------------------------------- +// wxCondition implementation +// ---------------------------------------------------------------------------- + +class wxConditionInternal +{ public: - // TODO: internal handle - int waiters; + Handle event; + int waiters; }; wxCondition::wxCondition() { p_internal = new wxConditionInternal; - // TODO: create internal handle +// p_internal->event = CreateEvent(NULL, FALSE, FALSE, NULL); + if ( !p_internal->event ) + { + wxLogSysError(_("Can not create event object.")); + } + p_internal->waiters = 0; } wxCondition::~wxCondition() { - // TODO: destroy internal handle +// CloseHandle(p_internal->event); } void wxCondition::Wait(wxMutex& mutex) { mutex.Unlock(); p_internal->waiters++; - // TODO wait here +// WaitForSingleObject(p_internal->event, INFINITE); p_internal->waiters--; mutex.Lock(); } -bool wxCondition::Wait(wxMutex& mutex, unsigned long sec, +bool wxCondition::Wait(wxMutex& mutex, + unsigned long sec, unsigned long nsec) { +// DWORD ret; + mutex.Unlock(); p_internal->waiters++; - - // TODO wait here + // ret = WaitForSingleObject(p_internal->event, (sec*1000)+(nsec/1000000)); p_internal->waiters--; mutex.Lock(); - return FALSE; + return TRUE; // false for timeout } void wxCondition::Signal() { - // TODO +// SetEvent(p_internal->event); } void wxCondition::Broadcast() { - // TODO + int i; + + for (i=0;iwaiters;i++) + { +// if ( SetEvent(p_internal->event) == 0 ) + { + wxLogSysError(_("Couldn't change the state of event object.")); + } + } } -class wxThreadInternal { +// ---------------------------------------------------------------------------- +// wxCriticalSection implementation +// ---------------------------------------------------------------------------- + +class wxCriticalSectionInternal +{ public: - // TODO + // init the critical section object + wxCriticalSectionInternal() + { /* ::InitializeCriticalSection(&m_data);*/ } + + // implicit cast to the associated data + operator Handle *() { return &m_data; } + + // free the associated ressources + ~wxCriticalSectionInternal() + { /* ::DeleteCriticalSection(&m_data); */} + +private: + Handle m_data; }; +wxCriticalSection::wxCriticalSection() +{ + m_critsect = new wxCriticalSectionInternal; +} + +wxCriticalSection::~wxCriticalSection() +{ + delete m_critsect; +} + +void wxCriticalSection::Enter() +{ +// ::EnterCriticalSection(*m_critsect); +} + +void wxCriticalSection::Leave() +{ +// ::LeaveCriticalSection(*m_critsect); +} + +// ---------------------------------------------------------------------------- +// wxThread implementation +// ---------------------------------------------------------------------------- + +// wxThreadInternal class +// ---------------------- + +/* +class wxThreadInternal +{ +public: + wxThreadInternal() + { + m_hThread = 0; + m_state = STATE_NEW; + m_priority = WXTHREAD_DEFAULT_PRIORITY; + } + + // create a new (suspended) thread (for the given thread object) + bool Create(wxThread *thread); + + // suspend/resume/terminate + bool Suspend(); + bool Resume(); + void Cancel() { m_state = STATE_CANCELED; } + + // thread state + void SetState(wxThreadState state) { m_state = state; } + wxThreadState GetState() const { return m_state; } + + // thread priority + void SetPriority(unsigned int priority) { m_priority = priority; } + unsigned int GetPriority() const { return m_priority; } + + // thread handle and id + HANDLE GetHandle() const { return m_hThread; } + DWORD GetId() const { return m_tid; } + + // thread function + static DWORD WinThreadStart(wxThread *thread); + +private: + Handle m_hThread; // handle of the thread + wxThreadState m_state; // state, see wxThreadState enum + unsigned int m_priority; // thread priority in "wx" units + ThreadId m_tid; // thread id +}; + +DWORD wxThreadInternal::WinThreadStart(wxThread *thread) +{ + // store the thread object in the TLS + if ( !::TlsSetValue(s_tlsThisThread, thread) ) + { + wxLogSysError(_("Can not start thread: error writing TLS.")); + + return (DWORD)-1; + } + + DWORD ret = (DWORD)thread->Entry(); + thread->p_internal->SetState(STATE_EXITED); + thread->OnExit(); + + delete thread; + + return ret; +} + +bool wxThreadInternal::Create(wxThread *thread) +{ + m_hThread = ::CreateThread + ( + NULL, // default security + 0, // default stack size + (LPTHREAD_START_ROUTINE) // thread entry point + wxThreadInternal::WinThreadStart, // + (LPVOID)thread, // parameter + CREATE_SUSPENDED, // flags + &m_tid // [out] thread id + ); + + if ( m_hThread == NULL ) + { + wxLogSysError(_("Can't create thread")); + + return FALSE; + } + + // translate wxWindows priority to the Windows one + int win_priority; + if (m_priority <= 20) + win_priority = THREAD_PRIORITY_LOWEST; + else if (m_priority <= 40) + win_priority = THREAD_PRIORITY_BELOW_NORMAL; + else if (m_priority <= 60) + win_priority = THREAD_PRIORITY_NORMAL; + else if (m_priority <= 80) + win_priority = THREAD_PRIORITY_ABOVE_NORMAL; + else if (m_priority <= 100) + win_priority = THREAD_PRIORITY_HIGHEST; + else + { + wxFAIL_MSG(wxT("invalid value of thread priority parameter")); + win_priority = THREAD_PRIORITY_NORMAL; + } + + if ( ::SetThreadPriority(m_hThread, win_priority) == 0 ) + { + wxLogSysError(_("Can't set thread priority")); + } + + return TRUE; +} + +bool wxThreadInternal::Suspend() +{ + DWORD nSuspendCount = ::SuspendThread(m_hThread); + if ( nSuspendCount == (DWORD)-1 ) + { + wxLogSysError(_("Can not suspend thread %x"), m_hThread); + + return FALSE; + } + + m_state = STATE_PAUSED; + + return TRUE; +} + +bool wxThreadInternal::Resume() +{ + DWORD nSuspendCount = ::ResumeThread(m_hThread); + if ( nSuspendCount == (DWORD)-1 ) + { + wxLogSysError(_("Can not resume thread %x"), m_hThread); + + return FALSE; + } + + m_state = STATE_RUNNING; + + return TRUE; +} + +// static functions +// ---------------- + +wxThread *wxThread::This() +{ + wxThread *thread = (wxThread *)::TlsGetValue(s_tlsThisThread); + + // be careful, 0 may be a valid return value as well + if ( !thread && (::GetLastError() != NO_ERROR) ) + { + wxLogSysError(_("Couldn't get the current thread pointer")); + + // return NULL... + } + + return thread; +} + +bool wxThread::IsMain() +{ + return ::GetCurrentThreadId() == s_idMainThread; +} + +#ifdef Yield + #undef Yield +#endif + +void wxThread::Yield() +{ + // 0 argument to Sleep() is special + ::Sleep(0); +} + +void wxThread::Sleep(unsigned long milliseconds) +{ + ::Sleep(milliseconds); +} + +// create/start thread +// ------------------- + wxThreadError wxThread::Create() { - // TODO + if ( !p_internal->Create(this) ) + return wxTHREAD_NO_RESOURCE; + return wxTHREAD_NO_ERROR; } -wxThreadError wxThread::Destroy() +wxThreadError wxThread::Run() { - // TODO - return wxTHREAD_NO_ERROR; + wxCriticalSectionLocker lock(m_critsect); + + if ( p_internal->GetState() != STATE_NEW ) + { + // actually, it may be almost any state at all, not only STATE_RUNNING + return wxTHREAD_RUNNING; + } + + return Resume(); } +// suspend/resume thread +// --------------------- + wxThreadError wxThread::Pause() { - // TODO - return wxTHREAD_NO_ERROR; + wxCriticalSectionLocker lock(m_critsect); + + return p_internal->Suspend() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR; } wxThreadError wxThread::Resume() { - // TODO - return wxTHREAD_NO_ERROR; -} + wxCriticalSectionLocker lock(m_critsect); -void wxThread::Exit(void *status) -{ - // TODO + return p_internal->Resume() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR; } -void wxThread::SetPriority(int prio) +// stopping thread +// --------------- + +wxThread::ExitCode wxThread::Delete() { - // TODO + ExitCode rc = 0; + + // Delete() is always safe to call, so consider all possible states + if ( IsPaused() ) + Resume(); + + if ( IsRunning() ) + { + if ( IsMain() ) + { + // set flag for wxIsWaitingForThread() + s_waitingForThread = TRUE; + + wxBeginBusyCursor(); + } + + HANDLE hThread; + { + wxCriticalSectionLocker lock(m_critsect); + + p_internal->Cancel(); + hThread = p_internal->GetHandle(); + } + + // we can't just wait for the thread to terminate because it might be + // calling some GUI functions and so it will never terminate before we + // process the Windows messages that result from these functions + DWORD result; + do + { + result = ::MsgWaitForMultipleObjects + ( + 1, // number of objects to wait for + &hThread, // the objects + FALSE, // don't wait for all objects + INFINITE, // no timeout + QS_ALLEVENTS // return as soon as there are any events + ); + + switch ( result ) + { + case 0xFFFFFFFF: + // error + wxLogSysError(_("Can not wait for thread termination")); + Kill(); + return (ExitCode)-1; + + case WAIT_OBJECT_0: + // thread we're waiting for terminated + break; + + case WAIT_OBJECT_0 + 1: + // new message arrived, process it + if ( !wxTheApp->DoMessage() ) + { + // WM_QUIT received: kill the thread + Kill(); + + return (ExitCode)-1; + } + + if ( IsMain() ) + { + // give the thread we're waiting for chance to exit + // from the GUI call it might have been in + if ( (s_nWaitingForGui > 0) && wxGuiOwnedByMainThread() ) + { + wxMutexGuiLeave(); + } + } + + break; + + default: + wxFAIL_MSG(wxT("unexpected result of MsgWaitForMultipleObject")); + } + } while ( result != WAIT_OBJECT_0 ); + + if ( IsMain() ) + { + s_waitingForThread = FALSE; + + wxEndBusyCursor(); + } + + if ( !::GetExitCodeThread(hThread, (LPDWORD)&rc) ) + { + wxLogLastError("GetExitCodeThread"); + + rc = (ExitCode)-1; + } + + wxASSERT_MSG( (LPVOID)rc != (LPVOID)STILL_ACTIVE, + wxT("thread must be already terminated.") ); + + ::CloseHandle(hThread); + } + + return rc; } -int wxThread::GetPriority() const +wxThreadError wxThread::Kill() { - // TODO - return 0; + if ( !IsRunning() ) + return wxTHREAD_NOT_RUNNING; + + if ( !::TerminateThread(p_internal->GetHandle(), (DWORD)-1) ) + { + wxLogSysError(_("Couldn't terminate thread")); + + return wxTHREAD_MISC_ERROR; + } + + delete this; + + return wxTHREAD_NO_ERROR; } -void wxThread::DeferDestroy(bool on) +void wxThread::Exit(void *status) { - // TODO + delete this; + + ::ExitThread((DWORD)status); + + wxFAIL_MSG(wxT("Couldn't return from ExitThread()!")); } -void wxThread::TestDestroy() +void wxThread::SetPriority(unsigned int prio) { - // TODO + wxCriticalSectionLocker lock(m_critsect); + + p_internal->SetPriority(prio); } -void *wxThread::Join() +unsigned int wxThread::GetPriority() const { - // TODO - return (void*) NULL; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return p_internal->GetPriority(); } unsigned long wxThread::GetID() const { - // TODO - return 0; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return (unsigned long)p_internal->GetId(); } -/* is this needed somewhere ? -wxThread *wxThread::GetThreadFromID(unsigned long id) +bool wxThread::IsRunning() const { - // TODO - return NULL; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return p_internal->GetState() == STATE_RUNNING; } -*/ bool wxThread::IsAlive() const { - // TODO - return FALSE; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return (p_internal->GetState() == STATE_RUNNING) || + (p_internal->GetState() == STATE_PAUSED); } -bool wxThread::IsRunning() const +bool wxThread::IsPaused() const { - // TODO - return FALSE; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return (p_internal->GetState() == STATE_PAUSED); } -bool wxThread::IsMain() +bool wxThread::TestDestroy() { - // TODO - return FALSE; + wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect); + + return p_internal->GetState() == STATE_CANCELED; } wxThread::wxThread() { p_internal = new wxThreadInternal(); - - // TODO } wxThread::~wxThread() { - Destroy(); - Join(); delete p_internal; } -// The default callback just joins the thread and throws away the result. -void wxThread::OnExit() -{ - Join(); -} +// ---------------------------------------------------------------------------- +// Automatic initialization for thread module +// ---------------------------------------------------------------------------- -// Automatic initialization -class wxThreadModule : public wxModule { - DECLARE_DYNAMIC_CLASS(wxThreadModule) +class wxThreadModule : public wxModule +{ public: - virtual bool OnInit() { - /* TODO p_mainid = GetCurrentThread(); */ - wxMainMutex = new wxMutex(); - wxMainMutex->Lock(); - return TRUE; - } + virtual bool OnInit(); + virtual void OnExit(); - // Global cleanup - virtual void OnExit() { - wxMainMutex->Unlock(); - delete wxMainMutex; - } +private: + DECLARE_DYNAMIC_CLASS(wxThreadModule) }; IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) -#endif +bool wxThreadModule::OnInit() +{ + // allocate TLS index for storing the pointer to the current thread + s_tlsThisThread = ::TlsAlloc(); + if ( s_tlsThisThread == 0xFFFFFFFF ) + { + // in normal circumstances it will only happen if all other + // TLS_MINIMUM_AVAILABLE (>= 64) indices are already taken - in other + // words, this should never happen + wxLogSysError(_("Thread module initialization failed: " + "impossible to allocate index in thread " + "local storage")); + + return FALSE; + } + + // main thread doesn't have associated wxThread object, so store 0 in the + // TLS instead + if ( !::TlsSetValue(s_tlsThisThread, (LPVOID)0) ) + { + ::TlsFree(s_tlsThisThread); + s_tlsThisThread = 0xFFFFFFFF; + + wxLogSysError(_("Thread module initialization failed: " + "can not store value in thread local storage")); + + return FALSE; + } + + s_critsectWaitingForGui = new wxCriticalSection(); + + s_critsectGui = new wxCriticalSection(); + s_critsectGui->Enter(); + + // no error return for GetCurrentThreadId() + s_idMainThread = ::GetCurrentThreadId(); + + return TRUE; +} + +void wxThreadModule::OnExit() +{ + if ( !::TlsFree(s_tlsThisThread) ) + { + wxLogLastError("TlsFree failed."); + } + + if ( s_critsectGui ) + { + s_critsectGui->Leave(); + delete s_critsectGui; + s_critsectGui = NULL; + } + + wxDELETE(s_critsectWaitingForGui); +} + +// ---------------------------------------------------------------------------- +// under Windows, these functions are implemented usign a critical section and +// not a mutex, so the names are a bit confusing +// ---------------------------------------------------------------------------- + +void WXDLLEXPORT wxMutexGuiEnter() +{ + // this would dead lock everything... + wxASSERT_MSG( !wxThread::IsMain(), + wxT("main thread doesn't want to block in wxMutexGuiEnter()!") ); + + // the order in which we enter the critical sections here is crucial!! + + // set the flag telling to the main thread that we want to do some GUI + { + wxCriticalSectionLocker enter(*s_critsectWaitingForGui); + + s_nWaitingForGui++; + } + + wxWakeUpMainThread(); + + // now we may block here because the main thread will soon let us in + // (during the next iteration of OnIdle()) + s_critsectGui->Enter(); +} + +void WXDLLEXPORT wxMutexGuiLeave() +{ + wxCriticalSectionLocker enter(*s_critsectWaitingForGui); + + if ( wxThread::IsMain() ) + { + s_bGuiOwnedByMainThread = FALSE; + } + else + { + // decrement the number of waiters now + wxASSERT_MSG( s_nWaitingForGui > 0, + wxT("calling wxMutexGuiLeave() without entering it first?") ); + + s_nWaitingForGui--; + + wxWakeUpMainThread(); + } + + s_critsectGui->Leave(); +} + +void WXDLLEXPORT wxMutexGuiLeaveOrEnter() +{ + wxASSERT_MSG( wxThread::IsMain(), + wxT("only main thread may call wxMutexGuiLeaveOrEnter()!") ); + + wxCriticalSectionLocker enter(*s_critsectWaitingForGui); + + if ( s_nWaitingForGui == 0 ) + { + // no threads are waiting for GUI - so we may acquire the lock without + // any danger (but only if we don't already have it) + if ( !wxGuiOwnedByMainThread() ) + { + s_critsectGui->Enter(); + + s_bGuiOwnedByMainThread = TRUE; + } + //else: already have it, nothing to do + } + else + { + // some threads are waiting, release the GUI lock if we have it + if ( wxGuiOwnedByMainThread() ) + { + wxMutexGuiLeave(); + } + //else: some other worker thread is doing GUI + } +} + +bool WXDLLEXPORT wxGuiOwnedByMainThread() +{ + return s_bGuiOwnedByMainThread; +} + +// wake up the main thread if it's in ::GetMessage() +void WXDLLEXPORT wxWakeUpMainThread() +{ + // sending any message would do - hopefully WM_NULL is harmless enough + if ( !::PostThreadMessage(s_idMainThread, WM_NULL, 0, 0) ) + { + // should never happen + wxLogLastError("PostThreadMessage(WM_NULL)"); + } +} + +bool WXDLLEXPORT wxIsWaitingForThread() +{ + return s_waitingForThread; +} +*/ + +#endif // wxUSE_THREADS diff --git a/src/mac/window.cpp b/src/mac/window.cpp index e8015acc3b..18ab38338a 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -54,59 +54,84 @@ wxWindow* gFocusWindow = NULL ; IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) - EVT_CHAR(wxWindow::OnChar) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) - EVT_PAINT(wxWindow::OnPaint) END_EVENT_TABLE() #endif -// Constructor -wxWindow::wxWindow() + +// =========================================================================== +// implementation +// =========================================================================== + +// --------------------------------------------------------------------------- +// wxWindow utility functions +// --------------------------------------------------------------------------- + +// Find an item given the Macintosh Window Reference + +wxList *wxWinMacWindowList = NULL; +wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef) { - Init() ; + wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); + if (!node) + return NULL; + return (wxWindow *)node->Data(); } +void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win) +{ + // adding NULL WindowRef is (first) surely a result of an error and + // (secondly) breaks menu command processing + wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); + + if ( !wxWinMacWindowList->Find((long)inWindowRef) ) + wxWinMacWindowList->Append((long)inWindowRef, win); +} + +void wxRemoveMacWindowAssociation(wxWindow *win) +{ + wxWinMacWindowList->DeleteObject(win); +} + +// ---------------------------------------------------------------------------- +// constructors and such +// ---------------------------------------------------------------------------- + void wxWindow::Init() { + // generic + InitBase(); + + // MSW specific + m_doubleClickAllowed = 0; + m_winCaptured = FALSE; + + m_isBeingDeleted = FALSE; + + m_useCtl3D = FALSE; + m_mouseInWindow = FALSE; + + m_xThumbSize = 0; + m_yThumbSize = 0; + m_backgroundTransparent = FALSE; + + // as all windows are created with WS_VISIBLE style... + m_isShown = TRUE; + m_macWindowData = NULL ; - m_isWindow = TRUE; + m_x = 0; m_y = 0 ; m_width = 0 ; m_height = 0 ; - // these are the defaults for MSW - m_macShown = true ; - m_macEnabled = true ; - // Generic - m_windowId = 0; - m_windowStyle = 0; - m_windowParent = NULL; - m_windowEventHandler = this; - m_windowName = ""; - m_windowCursor = *wxSTANDARD_CURSOR; - m_children = new wxWindowList; - m_constraints = NULL; - m_constraintsInvolvedIn = NULL; - m_windowSizer = NULL; - m_sizerParent = NULL; - m_autoLayout = FALSE; - m_windowValidator = NULL; - m_defaultItem = NULL; - m_returnCode = 0; - m_caretWidth = 0; m_caretHeight = 0; - m_caretEnabled = FALSE; - m_caretShown = FALSE; - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; - // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; - m_foregroundColour = *wxBLACK; + m_hScrollBar = NULL ; m_vScrollBar = NULL ; - m_mouseInWindow = FALSE; #if wxUSE_DRAG_AND_DROP m_pDropTarget = NULL; @@ -116,69 +141,29 @@ void wxWindow::Init() // Destructor wxWindow::~wxWindow() { + m_isBeingDeleted = TRUE; + if ( s_lastMouseWindow == this ) { s_lastMouseWindow = NULL ; } - // Have to delete constraints/sizer FIRST otherwise - // sizers may try to look at deleted windows as they - // delete themselves. -#if wxUSE_CONSTRAINTS - DeleteRelatedConstraints(); - if (m_constraints) - { - // This removes any dangling pointers to this window - // in other windows' constraintsInvolvedIn lists. - UnsetConstraints(m_constraints); - delete m_constraints; - m_constraints = NULL; - } - if (m_windowSizer) + + if ( gFocusWindow == this ) { - delete m_windowSizer; - m_windowSizer = NULL; + gFocusWindow = NULL ; } - // If this is a child of a sizer, remove self from parent - if (m_sizerParent) - m_sizerParent->RemoveChild((wxWindow *)this); -#endif - - if ( FindFocus() == this ) - { - // really a bad thing - maybe an error ? - // we cannot even send it a kill focus message at this stage - gFocusWindow = NULL ; - } - if (m_windowParent) - m_windowParent->RemoveChild(this); + if ( m_parent ) + m_parent->RemoveChild(this); DestroyChildren(); - if ( m_macWindowData ) - { + if ( m_macWindowData ) + { UMADisposeWindow( m_macWindowData->m_macWindow ) ; delete m_macWindowData ; wxRemoveMacWindowAssociation( this ) ; } - - delete m_children; - m_children = NULL; - - // Just in case the window has been Closed, but - // we're then deleting immediately: don't leave - // dangling pointers. - wxPendingDelete.DeleteObject(this); - - if ( m_windowValidator ) - delete m_windowValidator; -} - -// Destroy the window (delayed, if a managed window) -bool wxWindow::Destroy() -{ - delete this; - return TRUE; } // Constructor @@ -188,64 +173,18 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - m_isWindow = TRUE; - // Generic - m_windowId = 0; - m_windowStyle = 0; - m_windowParent = NULL; - m_windowEventHandler = this; - m_windowName = ""; - m_windowCursor = *wxSTANDARD_CURSOR; - m_constraints = NULL; - m_constraintsInvolvedIn = NULL; - m_windowSizer = NULL; - m_sizerParent = NULL; - m_autoLayout = FALSE; - m_windowValidator = NULL; - -#if wxUSE_DRAG_AND_DROP - m_pDropTarget = NULL; -#endif + wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") ); - m_caretWidth = 0; m_caretHeight = 0; - m_caretEnabled = FALSE; - m_caretShown = FALSE; - m_minSizeX = -1; - m_minSizeY = -1; - m_maxSizeX = -1; - m_maxSizeY = -1; - m_defaultItem = NULL; - m_windowParent = NULL; - if (!parent) + if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; - if (parent) parent->AddChild(this); - - m_returnCode = 0; - - SetName(name); - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - - // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; - m_foregroundColour = *wxBLACK; - - m_windowStyle = style; - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; + parent->AddChild(this); m_x = (int)pos.x; m_y = (int)pos.y; - AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); - m_width = size.x; - m_height = size.y; + AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); + m_width = WidthDefault( size.x ); + m_height = HeightDefault( size.y ) ; MacCreateScrollBars( style ) ; @@ -282,15 +221,26 @@ void wxWindow::SetFocus() } } -void wxWindow::Enable(bool enable) +bool wxWindow::Enable(bool enable) { - if ( m_macEnabled == enable ) - return ; - - m_macEnabled = enable ; - - MacSuperEnabled( enable ) ; - return; + if ( !wxWindowBase::Enable(enable) ) + return FALSE; +/* + HWND hWnd = GetHwnd(); + if ( hWnd ) + ::EnableWindow(hWnd, (BOOL)enable); +*/ + + wxWindowList::Node *node = GetChildren().GetFirst(); + while ( node ) + { + wxWindow *child = node->GetData(); + child->Enable(enable); + + node = node->GetNext(); + } + + return TRUE; } void wxWindow::CaptureMouse() @@ -303,34 +253,6 @@ void wxWindow::ReleaseMouse() wxTheApp->s_captureWindow = NULL ; } -// Push/pop event handler (i.e. allow a chain of event handlers -// be searched) -void wxWindow::PushEventHandler(wxEvtHandler *handler) -{ - handler->SetNextHandler(GetEventHandler()); - SetEventHandler(handler); -} - -wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) -{ - if ( GetEventHandler() ) - { - wxEvtHandler *handlerA = GetEventHandler(); - wxEvtHandler *handlerB = handlerA->GetNextHandler(); - handlerA->SetNextHandler(NULL); - SetEventHandler(handlerB); - if ( deleteHandler ) - { - delete handlerA; - return NULL; - } - else - return handlerA; - } - else - return NULL; -} - #if wxUSE_DRAG_AND_DROP void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) @@ -355,13 +277,13 @@ void wxWindow::DragAcceptFiles(bool accept) } // Get total size -void wxWindow::GetSize(int *x, int *y) const +void wxWindow::DoGetSize(int *x, int *y) const { *x = m_width ; *y = m_height ; } -void wxWindow::GetPosition(int *x, int *y) const +void wxWindow::DoGetPosition(int *x, int *y) const { *x = m_x ; *y = m_y ; @@ -373,7 +295,7 @@ void wxWindow::GetPosition(int *x, int *y) const } } -void wxWindow::ScreenToClient(int *x, int *y) const +void wxWindow::DoScreenToClient(int *x, int *y) const { WindowRef window = GetMacRootWindow() ; @@ -393,7 +315,7 @@ void wxWindow::ScreenToClient(int *x, int *y) const MacRootWindowToClient( x , y ) ; } -void wxWindow::ClientToScreen(int *x, int *y) const +void wxWindow::DoClientToScreen(int *x, int *y) const { WindowRef window = GetMacRootWindow() ; @@ -438,20 +360,37 @@ void wxWindow::MacRootWindowToClient( int *x , int *y ) const } } -void wxWindow::SetCursor(const wxCursor& cursor) +bool wxWindow::SetCursor(const wxCursor& cursor) { - m_windowCursor = cursor; - if (m_windowCursor.Ok()) + if ( !wxWindowBase::SetCursor(cursor) ) + { + // no change + return FALSE; + } + + wxASSERT_MSG( m_cursor.Ok(), + wxT("cursor must be valid after call to the base version")); + + Point pt ; + wxWindow *mouseWin ; + GetMouse( &pt ) ; + + // Change the cursor NOW if we're within the correct window + + if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) { - // since this only affects the window-cursor, we adopt the same - // behaviour as windows -> it will only change on mouse moved events - // otherwise the ::WxSetCursor routine will have to be used + if ( mouseWin == this && !wxIsBusy() ) + { + cursor.MacInstall() ; + } } + + return TRUE ; } // Get size *available for subwindows* i.e. excluding menu bar etc. -void wxWindow::GetClientSize(int *x, int *y) const +void wxWindow::DoGetClientSize(int *x, int *y) const { *x = m_width ; *y = m_height ; @@ -600,6 +539,8 @@ void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) void wxWindow::SetTitle(const wxString& title) { + m_label = title ; + wxString label ; if( wxApp::s_macDefaultEncodingIsPC ) @@ -613,57 +554,14 @@ void wxWindow::SetTitle(const wxString& title) wxString wxWindow::GetTitle() const { - if ( m_macWindowData ) - { - char title[256] ; - wxString label ; - UMAGetWTitleC( m_macWindowData->m_macWindow , title ) ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakePCStringFromMac( title ) ; - else - label = title ; - return label; - } - - return wxEmptyString ; + return m_label ; } -void wxWindow::Centre(int direction) -{ - int x_offset,y_offset ; - int display_width, display_height; - int width, height, x, y; - wxWindow *parent = GetParent(); - if ((direction & wxCENTER_FRAME) && parent) - { - parent->GetPosition(&x_offset,&y_offset) ; - parent->GetSize(&display_width,&display_height) ; - } - else - { - wxDisplaySize(&display_width, &display_height); - x_offset = 0 ; - y_offset = LMGetMBarHeight() + LMGetMBarHeight() / 2 ; // approx. the window title height - } - - GetSize(&width, &height); - GetPosition(&x, &y); - - if (direction & wxHORIZONTAL) - x = (int)((display_width - width)/2); - if (direction & wxVERTICAL) - y = (int)((display_height - height)/2); - - SetSize(x+x_offset, y+y_offset, width, height); -} - - bool wxWindow::Show(bool show) { - if ( m_macShown == show ) - return TRUE ; - - m_macShown = show ; + if ( !wxWindowBase::Show(show) ) + return FALSE; + if ( m_macWindowData ) { if (show) @@ -681,13 +579,8 @@ bool wxWindow::Show(bool show) } } Refresh() ; - MacSuperShown( show ) ; - return TRUE; -} -bool wxWindow::IsShown() const -{ - return m_macShown; + return TRUE; } int wxWindow::GetCharHeight() const @@ -703,13 +596,22 @@ int wxWindow::GetCharWidth() const } void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, - int *descent, int *externalLeading, const wxFont *theFont, bool) const + int *descent, int *externalLeading, const wxFont *theFont ) const { - wxFont *fontToUse = (wxFont *)theFont; - if (!fontToUse) - fontToUse = (wxFont *) & m_windowFont; + const wxFont *fontToUse = theFont; + if ( !fontToUse ) + fontToUse = &m_font; +/* + if ( x ) + *x = sizeRect.cx; + if ( y ) + *y = sizeRect.cy; + if ( descent ) + *descent = tm.tmDescent; + if ( externalLeading ) + *externalLeading = tm.tmExternalLeading; +*/ - // TODO } void wxWindow::MacEraseBackground( Rect *rect ) @@ -764,7 +666,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) EraseRect( rect ) ; - for (wxNode *node = m_children->First(); node; node = node->Next()) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); // int width ; @@ -776,7 +678,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) SectRect( &clientrect , rect , &clientrect ) ; OffsetRect( &clientrect , -child->m_x , -child->m_y ) ; - if ( child->GetMacRootWindow() == window && child->IsReallyShown() ) + if ( child->GetMacRootWindow() == window && child->IsShown() ) { wxMacDrawingClientHelper focus( this ) ; if ( focus.Ok() ) @@ -831,60 +733,47 @@ void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) } } -// This can be called by the app (or wxWindows) to do default processing for the current -// event. Save message/event info in wxWindow so they can be used in this function. -long wxWindow::Default() -{ - // TODO - return 0; -} - -void wxWindow::InitDialog() -{ - wxInitDialogEvent event(GetId()); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); -} - -// Default init dialog behaviour is to transfer data to window -void wxWindow::OnInitDialog(wxInitDialogEvent& event) -{ - TransferDataToWindow(); -} - +#if wxUSE_CARET && WXWIN_COMPATIBILITY +// --------------------------------------------------------------------------- // Caret manipulation +// --------------------------------------------------------------------------- + void wxWindow::CreateCaret(int w, int h) { - m_caretWidth = w; - m_caretHeight = h; - m_caretEnabled = TRUE; + SetCaret(new wxCaret(this, w, h)); } void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) { - // TODO + wxFAIL_MSG("not implemented"); } void wxWindow::ShowCaret(bool show) { - // TODO + wxCHECK_RET( m_caret, "no caret to show" ); + + m_caret->Show(show); } void wxWindow::DestroyCaret() { - // TODO - m_caretEnabled = FALSE; + SetCaret(NULL); } void wxWindow::SetCaretPos(int x, int y) { - // TODO + wxCHECK_RET( m_caret, "no caret to move" ); + + m_caret->Move(x, y); } void wxWindow::GetCaretPos(int *x, int *y) const { - // TODO + wxCHECK_RET( m_caret, "no caret to get position of" ); + + m_caret->GetPosition(x, y); } +#endif // wxUSE_CARET wxWindow *wxGetActiveWindow() { @@ -892,15 +781,6 @@ wxWindow *wxGetActiveWindow() return NULL; } -void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) -{ - m_minSizeX = minW; - m_minSizeY = minH; - m_maxSizeX = maxW; - m_maxSizeY = maxH; -} - - // Coordinates relative to the window void wxWindow::WarpPointer (int x_pos, int y_pos) { @@ -1038,595 +918,53 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) } } -void wxWindow::SetFont(const wxFont& font) -{ - m_windowFont = font; - - if (!m_windowFont.Ok()) - return; - // TODO -} - -void wxWindow::OnChar(wxKeyEvent& event) +bool wxWindow::SetFont(const wxFont& font) { - if ( event.KeyCode() == WXK_TAB ) { - // propagate the TABs to the parent - it's up to it to decide what - // to do with it - if ( GetParent() ) { - if ( GetParent()->ProcessEvent(event) ) - return; - } + if ( !wxWindowBase::SetFont(font) ) + { + // nothing to do + return FALSE; } -} - -void wxWindow::OnPaint(wxPaintEvent& event) -{ -/* - if ( m_macWindowData ) - { - wxMacDrawingClientHelper helper ( this ) ; - long x ,y ,w ,h ; - GetUpdateRegion().GetBox( x , y , w , h ) ; - UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; - Rect r = { y , x, y+h , x+w } ; - EraseRect( &r ) ; - } - else - { - wxMacDrawingClientHelper helper ( this ) ; - long x ,y ,w ,h ; - GetUpdateRegion().GetBox( x , y , w , h ) ; - RGBBackColor( &m_backgroundColour.GetPixel() ) ; - Rect r = { y , x, y+h , x+w } ; - EraseRect( &r ) ; - } -*/ -} - -bool wxWindow::IsEnabled() const -{ - return m_macEnabled ; -} - -// Dialog support: override these and call -// base class members to add functionality -// that can't be done using validators. -// NOTE: these functions assume that controls -// are direct children of this window, not grandchildren -// or other levels of descendant. - -// Transfer values to controls. If returns FALSE, -// it's an application error (pops up a dialog) -bool wxWindow::TransferDataToWindow() -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && - !child->GetValidator()->TransferToWindow() ) - { - wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION); - return FALSE; - } - - node = node->Next(); - } - return TRUE; -} - -// Transfer values from controls. If returns FALSE, -// validation failed: don't quit -bool wxWindow::TransferDataFromWindow() -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) - { - return FALSE; - } - node = node->Next(); - } - return TRUE; -} - -bool wxWindow::Validate() -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) - { - return FALSE; - } - - node = node->Next(); - } - return TRUE; + return TRUE; } // Get the window with the focus -wxWindow *wxWindow::FindFocus() +wxWindow *wxWindowBase::FindFocus() { return gFocusWindow ; } -// ---------------------------------------------------------------------------- -// RTTI -// ---------------------------------------------------------------------------- - -bool wxWindow::IsTopLevel() const -{ - return wxDynamicCast(this, wxFrame) || wxDynamicCast(this, wxDialog); -} - -void wxWindow::AddChild(wxWindow *child) -{ - GetChildren().Append(child); - child->m_windowParent = this; -} - -void wxWindow::RemoveChild(wxWindow *child) -{ - GetChildren().DeleteObject(child); - child->m_windowParent = NULL; -} - -void wxWindow::DestroyChildren() -{ - wxNode *node; - while ((node = GetChildren().First()) != (wxNode *)NULL) { - wxWindow *child; - if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { - delete child; - if ( GetChildren().Find(child) ) - delete node; - } - } /* while */ -} - -void wxWindow::MakeModal(bool modal) -{ - // Disable all other windows - if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) - { - wxNode *node = wxTopLevelWindows.First(); - while (node) - { - wxWindow *win = (wxWindow *)node->Data(); - if (win != this) - win->Enable(!modal); - - node = node->Next(); - } - } -} - +#if WXWIN_COMPATIBILITY // If nothing defined for this, try the parent. // E.g. we may be a button loaded from a resource, with no callback function // defined. void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) { - if (GetEventHandler()->ProcessEvent(event) ) - return; - if (m_windowParent) - m_windowParent->GetEventHandler()->OnCommand(win, event); -} - -// ---------------------------------------------------------------------------- -// constraints and sizers -// ---------------------------------------------------------------------------- - -#if wxUSE_CONSTRAINTS - -void wxWindow::SetConstraints( wxLayoutConstraints *constraints ) -{ - if ( m_constraints ) - { - UnsetConstraints(m_constraints); - delete m_constraints; - } - m_constraints = constraints; - if ( m_constraints ) - { - // Make sure other windows know they're part of a 'meaningful relationship' - if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) - m_constraints->left.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) - m_constraints->top.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) - m_constraints->right.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) - m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) - m_constraints->width.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) - m_constraints->height.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) - m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); - if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) - m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); - } -} - -// This removes any dangling pointers to this window in other windows' -// constraintsInvolvedIn lists. -void wxWindow::UnsetConstraints(wxLayoutConstraints *c) -{ - if ( c ) - { - if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) - c->left.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) - c->top.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) - c->right.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) - c->bottom.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) - c->width.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) - c->height.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) - c->centreX.GetOtherWindow()->RemoveConstraintReference(this); - if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) - c->centreY.GetOtherWindow()->RemoveConstraintReference(this); - } -} - -// Back-pointer to other windows we're involved with, so if we delete this -// window, we must delete any constraints we're involved with. -void wxWindow::AddConstraintReference(wxWindow *otherWin) -{ - if ( !m_constraintsInvolvedIn ) - m_constraintsInvolvedIn = new wxWindowList; - if ( !m_constraintsInvolvedIn->Find(otherWin) ) - m_constraintsInvolvedIn->Append(otherWin); -} - -// REMOVE back-pointer to other windows we're involved with. -void wxWindow::RemoveConstraintReference(wxWindow *otherWin) -{ - if ( m_constraintsInvolvedIn ) - m_constraintsInvolvedIn->DeleteObject(otherWin); -} - -// Reset any constraints that mention this window -void wxWindow::DeleteRelatedConstraints() -{ - if ( m_constraintsInvolvedIn ) - { - wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); - while (node) - { - wxWindow *win = node->GetData(); - wxLayoutConstraints *constr = win->GetConstraints(); - - // Reset any constraints involving this window - if ( constr ) - { - constr->left.ResetIfWin(this); - constr->top.ResetIfWin(this); - constr->right.ResetIfWin(this); - constr->bottom.ResetIfWin(this); - constr->width.ResetIfWin(this); - constr->height.ResetIfWin(this); - constr->centreX.ResetIfWin(this); - constr->centreY.ResetIfWin(this); - } - - wxWindowList::Node *next = node->GetNext(); - delete node; - node = next; - } - - delete m_constraintsInvolvedIn; - m_constraintsInvolvedIn = (wxWindowList *) NULL; - } -} - -void wxWindow::SetSizer(wxSizer *sizer) -{ - if (m_windowSizer) delete m_windowSizer; - - m_windowSizer = sizer; -} - -bool wxWindow::Layout() -{ - int w, h; - GetClientSize(&w, &h); - - // If there is a sizer, use it instead of the constraints - if ( GetSizer() ) - { - GetSizer()->SetDimension( 0, 0, w, h ); - return TRUE; - } - - if ( GetConstraints() ) - { - GetConstraints()->width.SetValue(w); - GetConstraints()->height.SetValue(h); - } - - // Evaluate child constraints - ResetConstraints(); // Mark all constraints as unevaluated - DoPhase(1); // Just one phase need if no sizers involved - DoPhase(2); - SetConstraintSizes(); // Recursively set the real window sizes - - return TRUE; -} - - -// Do a phase of evaluating constraints: the default behaviour. wxSizers may -// do a similar thing, but also impose their own 'constraints' and order the -// evaluation differently. -bool wxWindow::LayoutPhase1(int *noChanges) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - return constr->SatisfyConstraints(this, noChanges); - } - else - return TRUE; -} - -bool wxWindow::LayoutPhase2(int *noChanges) -{ - *noChanges = 0; - - // Layout children - DoPhase(1); - DoPhase(2); - return TRUE; -} - -// Do a phase of evaluating child constraints -bool wxWindow::DoPhase(int phase) -{ - int noIterations = 0; - int maxIterations = 500; - int noChanges = 1; - int noFailures = 0; - wxWindowList succeeded; - while ((noChanges > 0) && (noIterations < maxIterations)) - { - noChanges = 0; - noFailures = 0; - wxWindowList::Node *node = GetChildren().GetFirst(); - while (node) - { - wxWindow *child = node->GetData(); - if ( !child->IsTopLevel() ) - { - wxLayoutConstraints *constr = child->GetConstraints(); - if ( constr ) - { - if ( !succeeded.Find(child) ) - { - int tempNoChanges = 0; - bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; - noChanges += tempNoChanges; - if ( success ) - { - succeeded.Append(child); - } - } - } - } - node = node->GetNext(); - } - - noIterations++; - } - - return TRUE; -} - -void wxWindow::ResetConstraints() -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - constr->left.SetDone(FALSE); - constr->top.SetDone(FALSE); - constr->right.SetDone(FALSE); - constr->bottom.SetDone(FALSE); - constr->width.SetDone(FALSE); - constr->height.SetDone(FALSE); - constr->centreX.SetDone(FALSE); - constr->centreY.SetDone(FALSE); - } - wxWindowList::Node *node = GetChildren().GetFirst(); - while (node) - { - wxWindow *win = node->GetData(); - if ( !win->IsTopLevel() ) - win->ResetConstraints(); - node = node->GetNext(); - } -} - -// Need to distinguish between setting the 'fake' size for windows and sizers, -// and setting the real values. -void wxWindow::SetConstraintSizes(bool recurse) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr && constr->left.GetDone() && constr->right.GetDone( ) && - constr->width.GetDone() && constr->height.GetDone()) - { - int x = constr->left.GetValue(); - int y = constr->top.GetValue(); - int w = constr->width.GetValue(); - int h = constr->height.GetValue(); - - if ( (constr->width.GetRelationship() != wxAsIs ) || - (constr->height.GetRelationship() != wxAsIs) ) - { - SetSize(x, y, w, h); - } - else - { - // If we don't want to resize this window, just move it... - Move(x, y); - } - } - else if ( constr ) - { - char *windowClass = GetClassInfo()->GetClassName(); - - wxString winName; - if ( GetName() == _T("") ) - winName = _T("unnamed"); - else - winName = GetName(); - wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"), - (const char *)windowClass, - (const char *)winName); - if ( !constr->left.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") ); - if ( !constr->right.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") ); - if ( !constr->width.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") ); - if ( !constr->height.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") ); - wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") ); - } - - if ( recurse ) - { - wxWindowList::Node *node = GetChildren().GetFirst(); - while (node) - { - wxWindow *win = node->GetData(); - if ( !win->IsTopLevel() ) - win->SetConstraintSizes(); - node = node->GetNext(); - } - } -} - -// Only set the size/position of the constraint (if any) -void wxWindow::SetSizeConstraint(int x, int y, int w, int h) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - if ( x != -1 ) - { - constr->left.SetValue(x); - constr->left.SetDone(TRUE); - } - if ( y != -1 ) - { - constr->top.SetValue(y); - constr->top.SetDone(TRUE); - } - if ( w != -1 ) - { - constr->width.SetValue(w); - constr->width.SetDone(TRUE); - } - if ( h != -1 ) - { - constr->height.SetValue(h); - constr->height.SetDone(TRUE); - } - } -} - -void wxWindow::MoveConstraint(int x, int y) -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - if ( x != -1 ) - { - constr->left.SetValue(x); - constr->left.SetDone(TRUE); - } - if ( y != -1 ) - { - constr->top.SetValue(y); - constr->top.SetDone(TRUE); - } - } + if ( GetEventHandler()->ProcessEvent(event) ) + return; + if ( m_parent ) + m_parent->GetEventHandler()->OnCommand(win, event); } +#endif // WXWIN_COMPATIBILITY_2 -void wxWindow::GetSizeConstraint(int *w, int *h) const -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - *w = constr->width.GetValue(); - *h = constr->height.GetValue(); - } - else - GetSize(w, h); -} - -void wxWindow::GetClientSizeConstraint(int *w, int *h) const -{ - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) - { - *w = constr->width.GetValue(); - *h = constr->height.GetValue(); - } - else - GetClientSize(w, h); -} - -void wxWindow::GetPositionConstraint(int *x, int *y) const +#if WXWIN_COMPATIBILITY +wxObject* wxWindow::GetChild(int number) const { - wxLayoutConstraints *constr = GetConstraints(); - if ( constr ) + // Return a pointer to the Nth object in the Panel + wxNode *node = GetChildren().First(); + int n = number; + while (node && n--) + node = node->Next(); + if ( node ) { - *x = constr->left.GetValue(); - *y = constr->top.GetValue(); + wxObject *obj = (wxObject *)node->Data(); + return(obj); } else - GetPosition(x, y); -} - -#endif // wxUSE_CONSTRAINTS - -bool wxWindow::Close(bool force) -{ - wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); - event.SetEventObject(this); -#if WXWIN_COMPATIBILITY - event.SetForce(force); -#endif - event.SetCanVeto(!force); - - return GetEventHandler()->ProcessEvent(event); -} - -wxObject* wxWindow::GetChild(int number) const -{ - // Return a pointer to the Nth object in the window - wxNode *node = GetChildren().First(); - int n = number; - while (node && n--) - node = node->Next() ; - if (node) - { - wxObject *obj = (wxObject *)node->Data(); - return(obj) ; - } - else - return NULL ; -} - -void wxWindow::OnDefaultAction(wxControl *initiatingItem) -{ - // Obsolete function + return NULL; } +#endif // WXWIN_COMPATIBILITY void wxWindow::Clear() { @@ -1649,76 +987,11 @@ void wxWindow::Clear() } } -// Fits the panel around the items -void wxWindow::Fit() -{ - int maxX = 0; - int maxY = 0; - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *win = (wxWindow *)node->Data(); - int wx, wy, ww, wh; - win->GetPosition(&wx, &wy); - win->GetSize(&ww, &wh); - if ( wx + ww > maxX ) - maxX = wx + ww; - if ( wy + wh > maxY ) - maxY = wy + wh; - - node = node->Next(); - } - SetClientSize(maxX + 5, maxY + 5); -} - -void wxWindow::SetValidator(const wxValidator& validator) -{ - if ( m_windowValidator ) - delete m_windowValidator; - m_windowValidator = validator.Clone(); - - if ( m_windowValidator ) - m_windowValidator->SetWindow(this) ; -} - -void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) -{ - m_acceleratorTable = accel; -} - -// Find a window by id or name -wxWindow *wxWindow::FindWindow(long id) -{ - if ( GetId() == id) - return this; - - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - wxWindow *found = child->FindWindow(id); - if ( found ) - return found; - node = node->Next(); - } - return NULL; -} - -wxWindow *wxWindow::FindWindow(const wxString& name) +// Setup background and foreground colours correctly +void wxWindow::SetupColours() { - if ( GetName() == name) - return this; - - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - wxWindow *found = child->FindWindow(name); - if ( found ) - return found; - node = node->Next(); - } - return NULL; + if ( GetParent() ) + SetBackgroundColour(GetParent()->GetBackgroundColour()); } void wxWindow::OnIdle(wxIdleEvent& event) @@ -1755,43 +1028,6 @@ void wxWindow::Lower() // TODO } -bool wxWindow::AcceptsFocus() const -{ - return IsShown() && IsEnabled() && MacCanFocus() ; -} - -// Update region access -wxRegion wxWindow::GetUpdateRegion() const -{ - return m_updateRegion; -} - -bool wxWindow::IsExposed(int x, int y, int w, int h) const -{ - return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); -} - -bool wxWindow::IsExposed(const wxPoint& pt) const -{ - return (m_updateRegion.Contains(pt) != wxOutRegion); -} - -bool wxWindow::IsExposed(const wxRect& rect) const -{ - return (m_updateRegion.Contains(rect) != wxOutRegion); -} - -/* - * Allocates control IDs - */ - -int wxWindow::NewControlId() -{ - static int s_controlId = 0; - s_controlId ++; - return s_controlId; -} - void wxWindow::DoSetClientSize(int width, int height) { if ( width != -1 || height != -1 ) @@ -1806,30 +1042,6 @@ void wxWindow::DoSetClientSize(int width, int height) } } -// ------------------------ -wxList *wxWinMacWindowList = NULL; -wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef) -{ - wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); - if (!node) - return NULL; - return (wxWindow *)node->Data(); -} - -void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win) -{ - // adding NULL WindowRef is (first) surely a result of an error and - // (secondly) breaks menu command processing - wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); - - if ( !wxWinMacWindowList->Find((long)inWindowRef) ) - wxWinMacWindowList->Append((long)inWindowRef, win); -} - -void wxRemoveMacWindowAssociation(wxWindow *win) -{ - wxWinMacWindowList->DeleteObject(win); -} wxWindow* wxWindow::s_lastMouseWindow = NULL ; @@ -1846,16 +1058,13 @@ bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWi newPoint.x -= m_x; newPoint.y -= m_y; - if ( m_children ) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { - for (wxNode *node = m_children->First(); node; node = node->Next()) + wxWindow *child = (wxWindow*)node->Data(); + if ( child->GetMacRootWindow() == window ) { - wxWindow *child = (wxWindow*)node->Data(); - if ( child->GetMacRootWindow() == window ) - { - if (child->MacGetWindowFromPointSub(newPoint , outWin )) - return TRUE; - } + if (child->MacGetWindowFromPointSub(newPoint , outWin )) + return TRUE; } } @@ -1896,16 +1105,13 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) int x = event.m_x ; int y = event.m_y ; - if ( m_children ) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { - for (wxNode *node = m_children->First(); node; node = node->Next()) + wxWindow *child = (wxWindow*)node->Data(); + if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() ) { - wxWindow *child = (wxWindow*)node->Data(); - if ( child->GetMacRootWindow() == window && child->IsReallyShown() && child->IsReallyEnabled() ) - { - if (child->MacDispatchMouseEvent(event)) - return TRUE; - } + if (child->MacDispatchMouseEvent(event)) + return TRUE; } } @@ -1914,7 +1120,7 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) if ( wxBusyCursorCount == 0 ) { - m_windowCursor.MacInstall() ; + m_cursor.MacInstall() ; } GetEventHandler()->ProcessEvent( event ) ; return TRUE; @@ -1989,7 +1195,7 @@ void wxWindow::MacFireMouseEvent( EventRecord *ev ) wxTheApp->s_captureWindow = NULL ; if ( wxBusyCursorCount == 0 ) { - m_windowCursor.MacInstall() ; + m_cursor.MacInstall() ; } } } @@ -2118,7 +1324,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) RgnHandle childupdate = NewRgn() ; - for (wxNode *node = m_children->First(); node; node = node->Next()) + for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); int width ; @@ -2129,7 +1335,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ; SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ; OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; - if ( child->GetMacRootWindow() == window && child->IsReallyShown() ) + if ( child->GetMacRootWindow() == window && child->IsShown() ) { // because dialogs may also be children child->MacRedraw( childupdate , time ) ; @@ -2274,45 +1480,6 @@ void wxWindow::MacSuperChangedPosition() node = node->Next(); } } - -bool wxWindow::IsReallyShown() const -{ - if ( m_macWindowData ) - return m_macShown ; - else - return m_macShown && GetParent()->IsReallyShown() ; -} - -bool wxWindow::IsReallyEnabled() const -{ - if ( m_macWindowData ) - return m_macEnabled ; - else - return m_macEnabled && GetParent()->IsReallyEnabled() ; -} - -void wxWindow::MacSuperEnabled( bool enabled ) -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->m_macEnabled ) - child->MacSuperEnabled( enabled ) ; - node = node->Next(); - } -} -void wxWindow::MacSuperShown( bool show ) -{ - wxNode *node = GetChildren().First(); - while ( node ) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->m_macShown ) - child->MacSuperShown( show ) ; - node = node->Next(); - } -} bool wxWindow::MacSetupFocusPort( ) { -- 2.45.2