From 524c47aa3adf2af11a3069fd5da035a604f08f66 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 2 Sep 2008 16:53:23 +0000 Subject: [PATCH] osx new layout git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55419 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/carbon/app.h | 14 +- include/wx/osx/carbon/bitmap.h | 4 + include/wx/osx/carbon/button.h | 9 +- include/wx/osx/carbon/checkbox.h | 4 +- include/wx/osx/carbon/checklst.h | 24 +- include/wx/osx/carbon/choice.h | 8 +- include/wx/osx/carbon/combobox.h | 4 +- include/wx/osx/carbon/evtloop.h | 40 +- include/wx/osx/carbon/font.h | 2 + include/wx/osx/carbon/frame.h | 5 + include/wx/osx/carbon/glcanvas.h | 36 +- include/wx/osx/carbon/listbox.h | 35 +- include/wx/osx/carbon/listctrl.h | 3 +- include/wx/osx/carbon/menu.h | 78 +- include/wx/osx/carbon/menuitem.h | 8 +- include/wx/osx/carbon/nonownedwnd.h | 6 + include/wx/osx/carbon/notebook.h | 4 +- include/wx/osx/carbon/private.h | 232 ++- include/wx/osx/carbon/private/mactext.h | 13 +- include/wx/osx/carbon/radiobut.h | 4 +- include/wx/osx/carbon/scrolbar.h | 6 +- include/wx/osx/carbon/slider.h | 4 +- include/wx/osx/carbon/spinbutt.h | 18 +- include/wx/osx/carbon/tglbtn.h | 4 +- include/wx/osx/carbon/toolbar.h | 2 +- include/wx/osx/carbon/uma.h | 4 - include/wx/osx/carbon/window.h | 5 + include/wx/osx/cocoa/chkconf.h | 38 +- include/wx/osx/cocoa/private.h | 108 +- include/wx/osx/core/mimetype.h | 174 ++ include/wx/osx/core/private.h | 348 +++- include/wx/osx/iphone/chkconf.h | 78 + include/wx/osx/mimetype.h | 2 +- include/wx/osx/private.h | 5 + include/wx/osx/statbmp.h | 7 +- include/wx/osx/statline.h | 4 +- src/osx/artmac.cpp | 2 +- src/osx/button_osx.cpp | 21 +- src/osx/carbon/Info.plist.in | 13 +- src/osx/carbon/aboutdlg.cpp | 3 +- src/osx/carbon/app.cpp | 305 ++- src/osx/carbon/bmpbuttn.cpp | 141 +- src/osx/carbon/button.cpp | 228 +-- src/osx/carbon/checkbox.cpp | 174 +- src/osx/carbon/checklst.cpp | 273 --- src/osx/carbon/choice.cpp | 300 +-- src/osx/carbon/clipbrd.cpp | 2 +- src/osx/carbon/colordlgosx.mm | 2 +- src/osx/carbon/combobox.cpp | 19 +- src/osx/carbon/combobxc.cpp | 16 +- src/osx/carbon/control.cpp | 7 +- src/osx/carbon/cursor.cpp | 2 +- src/osx/carbon/databrow.cpp | 2 +- src/osx/carbon/dataobj.cpp | 4 +- src/osx/carbon/dataview.cpp | 2 +- src/osx/carbon/dcclient.cpp | 9 +- src/osx/carbon/dcprint.cpp | 4 +- src/osx/carbon/dcscreen.cpp | 2 +- src/osx/carbon/dialog.cpp | 149 +- src/osx/carbon/dirdlg.cpp | 16 +- src/osx/carbon/dnd.cpp | 2 +- src/osx/carbon/evtloop.cpp | 96 +- src/osx/carbon/filedlg.cpp | 2 +- src/osx/carbon/font.cpp | 8 +- src/osx/carbon/fontdlg.cpp | 13 +- src/osx/carbon/fontdlgosx.mm | 8 +- src/osx/carbon/frame.cpp | 28 +- src/osx/carbon/gauge.cpp | 132 +- src/osx/carbon/gdiobj.cpp | 10 +- src/osx/carbon/glcanvas.cpp | 299 ++- src/osx/carbon/graphics.cpp | 2 +- src/osx/carbon/icon.cpp | 4 +- src/osx/carbon/listbox.cpp | 614 +++--- src/osx/carbon/listctrl_mac.cpp | 31 +- src/osx/carbon/mdi.cpp | 2 +- src/osx/carbon/mediactrl.cpp | 17 +- src/osx/carbon/menu.cpp | 1294 +++--------- src/osx/carbon/menuitem.cpp | 272 +-- src/osx/carbon/metafile.cpp | 4 +- src/osx/carbon/mimetmac.cpp | 2 +- src/osx/carbon/msgdlg.cpp | 2 +- src/osx/carbon/nonownedwnd.cpp | 461 +---- src/osx/carbon/notebmac.cpp | 485 +---- src/osx/carbon/overlay.cpp | 2 +- src/osx/carbon/popupwin.cpp | 2 +- src/osx/carbon/printdlg.cpp | 13 +- src/osx/carbon/radiobut.cpp | 176 +- src/osx/carbon/renderer.cpp | 7 +- src/osx/carbon/scrolbar.cpp | 178 +- src/osx/carbon/settings.cpp | 10 +- src/osx/carbon/slider.cpp | 543 +---- src/osx/carbon/sound.cpp | 2 +- src/osx/carbon/spinbutt.cpp | 208 +- src/osx/carbon/srchctrl.cpp | 2 +- src/osx/carbon/statbmp.cpp | 2 +- src/osx/carbon/statbox.cpp | 68 +- src/osx/carbon/statbrma.cpp | 2 +- src/osx/carbon/statlmac.cpp | 40 +- src/osx/carbon/stattext.cpp | 147 +- src/osx/carbon/tabctrl.cpp | 188 +- src/osx/carbon/taskbar.cpp | 12 +- src/osx/carbon/textctrl.cpp | 931 +-------- src/osx/carbon/tglbtn.cpp | 163 +- src/osx/carbon/thread.cpp | 2 +- src/osx/carbon/toolbar.cpp | 69 +- src/osx/carbon/tooltip.cpp | 2 +- src/osx/carbon/uma.cpp | 18 +- src/osx/carbon/utils.cpp | 417 +--- src/osx/carbon/utilscocoa.mm | 15 +- src/osx/carbon/window.cpp | 2443 ++--------------------- src/osx/checkbox_osx.cpp | 54 +- src/osx/checklst.cpp | 152 ++ src/osx/choice_osx.cpp | 291 +++ src/osx/cocoa/glcanvas.mm | 49 +- src/osx/cocoa/msgdlg.mm | 284 +++ src/osx/cocoa/srchctrl.mm | 394 ++++ src/osx/cocoa/window.mm | 127 ++ src/osx/core/bitmap.cpp | 16 +- src/osx/core/cfstring.cpp | 4 +- src/osx/core/colour.cpp | 2 +- src/osx/core/gsockosx.cpp | 2 +- src/osx/core/hid.cpp | 2 +- src/osx/core/hidjoystick.cpp | 2 +- src/osx/core/printmac.cpp | 2 +- src/osx/core/strconv_cf.cpp | 2 +- src/osx/core/utilsexc_cf.cpp | 4 +- src/osx/gauge_osx.cpp | 75 + src/osx/glcanvas_osx.cpp | 185 ++ src/osx/iphone/nonownedwnd.mm | 9 +- src/osx/iphone/utils.mm | 2 +- src/osx/iphone/window.mm | 26 +- src/osx/listbox_osx.cpp | 373 ++++ src/osx/menu_osx.cpp | 993 +++++++++ src/osx/menuitem_osx.cpp | 252 +++ src/osx/nonownedwnd_osx.cpp | 27 +- src/osx/{carbon => }/radiobox.cpp | 18 +- src/osx/radiobut_osx.cpp | 9 +- src/osx/scrolbar_osx.cpp | 126 ++ src/osx/slider_osx.cpp | 534 +++++ src/osx/spinbutt_osx.cpp | 98 + src/osx/{carbon => }/spinctrl.cpp | 2 +- src/osx/srchctrl_osx.cpp | 32 + src/osx/statline_osx.cpp | 2 +- src/osx/stattext_osx.cpp | 2 +- src/osx/textctrl_osx.cpp | 939 +++++++++ src/osx/toolbar_osx.cpp | 31 + src/osx/{carbon => }/toplevel.cpp | 2 +- src/osx/utils_osx.cpp | 43 - src/osx/window_osx.cpp | 2362 ++++++++++++++++++++++ 149 files changed, 10275 insertions(+), 9740 deletions(-) create mode 100644 include/wx/osx/core/mimetype.h delete mode 100644 src/osx/carbon/checklst.cpp create mode 100644 src/osx/checklst.cpp create mode 100644 src/osx/choice_osx.cpp create mode 100644 src/osx/cocoa/msgdlg.mm create mode 100644 src/osx/cocoa/srchctrl.mm create mode 100644 src/osx/gauge_osx.cpp create mode 100644 src/osx/glcanvas_osx.cpp create mode 100644 src/osx/listbox_osx.cpp create mode 100644 src/osx/menu_osx.cpp create mode 100644 src/osx/menuitem_osx.cpp rename src/osx/{carbon => }/radiobox.cpp (95%) create mode 100644 src/osx/scrolbar_osx.cpp create mode 100644 src/osx/slider_osx.cpp create mode 100644 src/osx/spinbutt_osx.cpp rename src/osx/{carbon => }/spinctrl.cpp (99%) create mode 100644 src/osx/srchctrl_osx.cpp create mode 100644 src/osx/textctrl_osx.cpp create mode 100644 src/osx/toolbar_osx.cpp rename src/osx/{carbon => }/toplevel.cpp (98%) create mode 100644 src/osx/window_osx.cpp diff --git a/include/wx/osx/carbon/app.h b/include/wx/osx/carbon/app.h index c5b56e8e0b..5f6321dc46 100644 --- a/include/wx/osx/carbon/app.h +++ b/include/wx/osx/carbon/app.h @@ -44,21 +44,20 @@ class WXDLLIMPEXP_CORE wxApp: public wxAppBase virtual void SetPrintMode(int mode) { m_printMode = mode; } virtual int GetPrintMode() const { return m_printMode; } + // calling OnInit with an auto-release pool ready ... + virtual bool CallOnInit(); #if wxUSE_GUI // setting up all MacOS Specific Event-Handlers etc virtual bool OnInitGui(); #endif // wxUSE_GUI -#if wxOSX_USE_IPHONE - virtual bool CallOnInit(); - virtual int OnRun(); -#endif + + virtual bool ProcessIdle(); + // implementation only void OnIdle(wxIdleEvent& event); void OnEndSession(wxCloseEvent& event); void OnQueryEndSession(wxCloseEvent& event); - void MacDoOneEvent() ; - protected: int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT @@ -88,6 +87,8 @@ public: private: // mac specifics + virtual bool DoInitGui(); + virtual void DoCleanUp(); WXEVENTHANDLERREF m_macEventHandler ; WXEVENTHANDLERCALLREF m_macCurrentEventHandlerCallRef ; @@ -101,7 +102,6 @@ public: static wxString s_macHelpMenuTitleName ; WXEVENTREF MacGetCurrentEvent() { return m_macCurrentEvent ; } - void MacHandleOneEvent( WXEVENTREF ev ) ; // For embedded use. By default does nothing. virtual void MacHandleUnhandledEvent( WXEVENTREF ev ); diff --git a/include/wx/osx/carbon/bitmap.h b/include/wx/osx/carbon/bitmap.h index 5aa1ce31b3..8a4e71ec0d 100644 --- a/include/wx/osx/carbon/bitmap.h +++ b/include/wx/osx/carbon/bitmap.h @@ -162,6 +162,10 @@ public: // returns a CGImageRef which must released after usage with CGImageRelease CGImageRef CreateCGImage() const ; +#if wxOSX_USE_COCOA_OR_IPHONE + // returns an autoreleased version of the image + WX_NSImage GetNSImage() const; +#endif // returns a IconRef which must be retained before and released after usage IconRef GetIconRef() const; // returns a IconRef which must be released after usage diff --git a/include/wx/osx/carbon/button.h b/include/wx/osx/carbon/button.h index 1c3b4d01ae..ccf647576f 100644 --- a/include/wx/osx/carbon/button.h +++ b/include/wx/osx/carbon/button.h @@ -43,12 +43,15 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; static wxSize GetDefaultSize(); virtual wxWindow *SetDefault(); virtual void Command(wxCommandEvent& event); + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); + protected: virtual wxSize DoGetBestSize() const ; @@ -82,7 +85,9 @@ public: void SetOpen( bool open ); bool IsOpen() const; - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: virtual wxSize DoGetBestSize() const ; diff --git a/include/wx/osx/carbon/checkbox.h b/include/wx/osx/carbon/checkbox.h index 981a66b7cc..85ea0b7739 100644 --- a/include/wx/osx/carbon/checkbox.h +++ b/include/wx/osx/carbon/checkbox.h @@ -34,9 +34,11 @@ public: virtual void SetValue(bool); virtual bool GetValue() const; - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; virtual void Command(wxCommandEvent& event); + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: void DoSet3StateValue(wxCheckBoxState val); virtual wxCheckBoxState DoGet3StateValue() const; diff --git a/include/wx/osx/carbon/checklst.h b/include/wx/osx/carbon/checklst.h index 8be9e99c08..5e2fb9774b 100644 --- a/include/wx/osx/carbon/checklst.h +++ b/include/wx/osx/carbon/checklst.h @@ -13,15 +13,6 @@ #ifndef _WX_MAC_CHECKLST_H_ #define _WX_MAC_CHECKLST_H_ -class wxMacCheckListControl -{ -public : - virtual bool MacIsChecked(unsigned int n) const = 0; - virtual void MacCheck(unsigned int n, bool bCheck = true) = 0; - - virtual ~wxMacCheckListControl() { } -}; - class WXDLLIMPEXP_CORE wxCheckListBox : public wxCheckListBoxBase { public: @@ -77,9 +68,22 @@ public: bool IsChecked(unsigned int uiIndex) const; void Check(unsigned int uiIndex, bool bCheck = true); - wxMacCheckListControl* GetPeer() const; + // data callbacks + virtual void GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ); + virtual void SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ); protected: + // override all methods which add/delete items to update m_checks array as + // well + virtual void OnItemInserted(unsigned int pos); + virtual void DoDeleteOneItem(unsigned int n); + virtual void DoClear(); + + // the array containing the checked status of the items + wxArrayInt m_checks; + + wxListWidgetColumn* m_checkColumn ; + void Init(); private: diff --git a/include/wx/osx/carbon/choice.h b/include/wx/osx/carbon/choice.h index c73a831069..829843be36 100644 --- a/include/wx/osx/carbon/choice.h +++ b/include/wx/osx/carbon/choice.h @@ -28,7 +28,7 @@ class WXDLLIMPEXP_CORE wxChoice: public wxChoiceBase public: wxChoice() - : m_strings(), m_datas(), m_macPopUpMenuHandle(NULL) + : m_strings(), m_datas() {} virtual ~wxChoice() ; @@ -76,7 +76,9 @@ public: virtual int FindString(const wxString& s, bool bCase = false) const; virtual wxString GetString(unsigned int n) const ; virtual void SetString(unsigned int pos, const wxString& s); - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: virtual void DoDeleteOneItem(unsigned int n); @@ -92,7 +94,7 @@ protected: wxArrayString m_strings; wxChoiceDataArray m_datas ; - WXHMENU m_macPopUpMenuHandle ; + wxMenu* m_popUpMenu ; }; #endif diff --git a/include/wx/osx/carbon/combobox.h b/include/wx/osx/carbon/combobox.h index f8ff5bd4e5..6e0c649aaa 100644 --- a/include/wx/osx/carbon/combobox.h +++ b/include/wx/osx/carbon/combobox.h @@ -125,7 +125,9 @@ class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase virtual wxClientDataType GetClientDataType() const; - wxInt32 MacControlHit( WXEVENTHANDLERREF handler, WXEVENTREF event ); + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST diff --git a/include/wx/osx/carbon/evtloop.h b/include/wx/osx/carbon/evtloop.h index dd8a6b448a..60f5704574 100644 --- a/include/wx/osx/carbon/evtloop.h +++ b/include/wx/osx/carbon/evtloop.h @@ -12,53 +12,19 @@ #ifndef _WX_MAC_CARBON_EVTLOOP_H_ #define _WX_MAC_CARBON_EVTLOOP_H_ -// set wxOSX_USE_RUN_APP_EVENT_LOOP to 1 if the standard -// RunApplicationEventLoop function should be used, otherwise -// the lower level CarbonEventLoop will be used -// -// in the long run we should make this 1 by default but we will have to clean -// up event handling to make sure we don't miss handling of things like pending -// events etc and perhaps we will also have to pipe events through an -// ueber-event-handler to make sure we have one place to do all these -// house-keeping functions -#define wxOSX_USE_RUN_APP_EVENT_LOOP 0 - -// ---------------------------------------------------------------------------- -// wxEventLoop -// ---------------------------------------------------------------------------- - -#if wxOSX_USE_RUN_APP_EVENT_LOOP - -class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase -{ -public: - wxGUIEventLoop() { m_exitcode = 0; } - - // implement base class pure virtuals - virtual int Run(); - virtual void Exit(int rc = 0); - virtual bool Pending() const; - virtual bool Dispatch(); - -private: - int m_exitcode; -}; - -#else // manual event loop - class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopManual { public: - wxGUIEventLoop() { } + wxGUIEventLoop(); virtual bool Pending() const; virtual bool Dispatch(); // implement base class pure virtual virtual void WakeUp(); +private: + double m_sleepTime; }; -#endif // auto/manual event loop - #endif // _WX_MAC_CARBON_EVTLOOP_H_ diff --git a/include/wx/osx/carbon/font.h b/include/wx/osx/carbon/font.h index a9f62f22c9..c51f9edcba 100644 --- a/include/wx/osx/carbon/font.h +++ b/include/wx/osx/carbon/font.h @@ -50,7 +50,9 @@ public: bool Create(const wxNativeFontInfo& info); +#if wxOSX_USE_CARBON bool MacCreateFromThemeFont( wxUint16 themeFontID ) ; +#endif #if wxOSX_USE_CORE_TEXT bool MacCreateFromUIFont( wxUint32 coreTextFontType ); bool MacCreateFromCTFontDescriptor( const void * ctFontDescriptor, int pointSize = 0 ); diff --git a/include/wx/osx/carbon/frame.h b/include/wx/osx/carbon/frame.h index 4eb04e2435..8ed5ff1937 100644 --- a/include/wx/osx/carbon/frame.h +++ b/include/wx/osx/carbon/frame.h @@ -103,8 +103,13 @@ protected: virtual void DoGetClientSize(int *width, int *height) const; virtual void DoSetClientSize(int width, int height); +#if wxUSE_MENUS virtual void DetachMenuBar(); virtual void AttachMenuBar(wxMenuBar *menubar); +#endif + + // osx specific event handling common for all osx-ports + virtual void HandleResized( long timestamp ); protected: // the last focused child: we restore focus to it on activation diff --git a/include/wx/osx/carbon/glcanvas.h b/include/wx/osx/carbon/glcanvas.h index cced04ff48..2d032aaad7 100644 --- a/include/wx/osx/carbon/glcanvas.h +++ b/include/wx/osx/carbon/glcanvas.h @@ -12,13 +12,17 @@ #ifndef _WX_GLCANVAS_H_ #define _WX_GLCANVAS_H_ -#ifdef __DARWIN__ -# include -# include -#else -# include -# include -#endif +#include + +// low level calls + +WXDLLIMPEXP_GL WXGLContext WXGLCreateContext( WXGLPixelFormat pixelFormat, WXGLContext shareContext ); +WXDLLIMPEXP_GL void WXGLDestroyContext( WXGLContext context ); +WXDLLIMPEXP_GL WXGLContext WXGLGetCurrentContext(); +WXDLLIMPEXP_GL void WXGLSwapBuffers( WXGLContext context ); + +WXDLLIMPEXP_GL WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList); +WXDLLIMPEXP_GL void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat ); class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase { @@ -29,10 +33,10 @@ public: virtual bool SetCurrent(const wxGLCanvas& win) const; // Mac-specific - AGLContext GetAGLContext() const { return m_aglContext; } - + WXGLContext GetWXGLContext() const { return m_glContext; } + private: - AGLContext m_aglContext; + WXGLContext m_glContext; DECLARE_NO_COPY_CLASS(wxGLContext) }; @@ -71,7 +75,7 @@ public: static bool IsAGLMultiSampleAvailable(); // return the pixel format used by this window - AGLPixelFormat GetAGLPixelFormat() const { return m_aglFormat; } + WXGLPixelFormat GetWXGLPixelFormat() const { return m_glFormat; } // update the view port of the current context to match this window void SetViewport(); @@ -119,6 +123,7 @@ public: // implementation-only from now on +#if wxOSX_USE_CARBON // Unlike some other platforms, this must get called if you override it, // i.e. don't forget "event.Skip()" in your EVT_SIZE handler void OnSize(wxSizeEvent& event); @@ -128,12 +133,19 @@ public: virtual void MacVisibilityChanged(); void MacUpdateView(); + + GLint GetAglBufferName() const { return m_bufferName; } +#endif protected: - AGLPixelFormat m_aglFormat; + WXGLPixelFormat m_glFormat; +#if wxOSX_USE_CARBON bool m_macCanvasIsShown, m_needsUpdate; + WXGLContext m_dummyContext; + GLint m_bufferName; +#endif DECLARE_EVENT_TABLE() DECLARE_CLASS(wxGLCanvas) diff --git a/include/wx/osx/carbon/listbox.h b/include/wx/osx/carbon/listbox.h index cac622dfe9..be6959f2aa 100644 --- a/include/wx/osx/carbon/listbox.h +++ b/include/wx/osx/carbon/listbox.h @@ -21,8 +21,8 @@ // forward decl for GetSelections() class wxArrayInt; -// forward decl for wxMacListControl data type. -class wxMacListControl; +// forward decl for wxListWidgetImpl data type. +class wxListWidgetImpl; // List box item @@ -32,6 +32,10 @@ WX_DEFINE_ARRAY( char* , wxListDataArray ); // List box control // ---------------------------------------------------------------------------- +class WXDLLIMPEXP_CORE wxListWidgetColumn; + +class WXDLLIMPEXP_CORE wxListWidgetCellValue; + class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase { public: @@ -86,7 +90,7 @@ public: const wxString& name = wxListBoxNameStr); virtual ~wxListBox(); - + // implement base class pure virtuals virtual void Refresh(bool eraseBack = true, const wxRect *rect = NULL); @@ -95,6 +99,10 @@ public: virtual void SetString(unsigned int n, const wxString& s); virtual int FindString(const wxString& s, bool bCase = false) const; + // data callbacks + virtual void GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ); + virtual void SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ); + virtual bool IsSelected(int n) const; virtual int GetSelection() const; virtual int GetSelections(wxArrayInt& aSelections) const; @@ -110,11 +118,15 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); - wxMacListControl* GetPeer() const; + wxListWidgetImpl* GetListPeer() const; bool MacGetBlockEvents() const { return m_blockEvents; } protected: + // callback for derived classes which may have to insert additional data + // at a certain line - which cannot be predetermined for sorted list data + virtual void OnItemInserted(unsigned int pos); + virtual void DoClear(); virtual void DoDeleteOneItem(unsigned int n); @@ -139,6 +151,21 @@ protected: bool m_blockEvents; + wxListWidgetColumn* m_textColumn; + + // data storage (copied from univ) + + // the array containing all items (it is sorted if the listbox has + // wxLB_SORT style) + union + { + wxArrayString *unsorted; + wxSortedArrayString *sorted; + } m_strings; + + // and this one the client data (either void or wxClientData) + wxArrayPtrVoid m_itemsClientData; + private: DECLARE_DYNAMIC_CLASS(wxListBox) DECLARE_EVENT_TABLE() diff --git a/include/wx/osx/carbon/listctrl.h b/include/wx/osx/carbon/listctrl.h index 0b05f6763c..1d38ef46eb 100644 --- a/include/wx/osx/carbon/listctrl.h +++ b/include/wx/osx/carbon/listctrl.h @@ -18,7 +18,6 @@ #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic") class wxMacDataBrowserListCtrlControl; -class wxMacListControl; class wxListCtrlTextCtrlWrapper; class wxListCtrlRenameTimer; @@ -281,7 +280,7 @@ class WXDLLIMPEXP_CORE wxListCtrl: public wxControl // data is arbitrary data to be passed to the sort function. bool SortItems(wxListCtrlCompare fn, long data); - wxMacListControl* GetPeer() const; + wxMacDataBrowserListCtrlControl* GetListPeer() const; // these functions are only used for virtual list view controls, i.e. the // ones with wxLC_VIRTUAL style diff --git a/include/wx/osx/carbon/menu.h b/include/wx/osx/carbon/menu.h index 4d5fa44c5a..ff8e0e06cf 100644 --- a/include/wx/osx/carbon/menu.h +++ b/include/wx/osx/carbon/menu.h @@ -20,6 +20,8 @@ class WXDLLIMPEXP_FWD_CORE wxFrame; // Menu // ---------------------------------------------------------------------------- +class WXDLLIMPEXP_FWD_CORE wxMenuImpl ; + class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase { public: @@ -37,34 +39,40 @@ public: virtual void SetTitle(const wxString& title); - // MSW-specific bool ProcessCommand(wxCommandEvent& event); - // implementation only from now on - // ------------------------------- - - int MacGetIndexFromId( int id ) ; - int MacGetIndexFromItem( wxMenuItem *pItem ) ; - void MacEnableMenu( bool bDoEnable ) ; - // MacOS needs to know about submenus somewhere within this menu - // before it can be displayed , also hide special menu items like preferences - // that are handled by the OS - void MacBeforeDisplay( bool isSubMenu ) ; - // undo all changes from the MacBeforeDisplay call - void MacAfterDisplay( bool isSubMenu ) ; - // semi-private accessors - // get the window which contains this menu - wxWindow *GetWindow() const; - // get the menu handle - WXHMENU GetHMenu() const { return m_hMenu; } - short MacGetMenuId() { return m_macMenuId ; } + // get the window which contains this menu + wxWindow *GetWindow() const; + // get the menu handle + WXHMENU GetHMenu() const ; - wxInt32 MacHandleCommandProcess( wxMenuItem* item, int id, wxWindow* targetWindow = NULL ); - wxInt32 MacHandleCommandUpdateStatus( wxMenuItem* item, int id, wxWindow* targetWindow = NULL); + // implementation only from now on + // ------------------------------- + bool HandleCommandUpdateStatus( wxMenuItem* menuItem, wxWindow* senderWindow = NULL); + bool HandleCommandProcess( wxMenuItem* menuItem, wxWindow* senderWindow = NULL); + void HandleMenuItemHighlighted( wxMenuItem* menuItem ); + void HandleMenuOpened(); + void HandleMenuClosed(); + + wxMenuImpl* GetPeer() { return m_peer; } + + // make sure we can veto + void SetAllowRearrange( bool allow ); + bool AllowRearrange() const { return m_allowRearrange; } + + // if a menu is used purely for internal implementation reasons (eg wxChoice) + // we don't want native menu events being triggered + void SetNoEventsMode( bool noEvents ); + bool GetNoEventsMode() const { return m_noEventsMode; } protected: + // hide special menu items like exit, preferences etc + // that are expected in the app menu + void DoRearrange() ; + + bool DoHandleMenuEvent( wxEvent& evt ); virtual wxMenuItem* DoAppend(wxMenuItem *item); virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); virtual wxMenuItem* DoRemove(wxMenuItem *item); @@ -82,19 +90,24 @@ private: // if TRUE, insert a breal before appending the next item bool m_doBreak; + // in this menu rearranging of menu items (esp hiding) is allowed + bool m_allowRearrange; + + // don't trigger native events + bool m_noEventsMode; + // the position of the first item in the current radio group or -1 int m_startRadioGroup; - - // the menu handle of this menu - WXHMENU m_hMenu; - - short m_macMenuId; - - static short s_macNextMenuId ; + + wxMenuImpl* m_peer; DECLARE_DYNAMIC_CLASS(wxMenu) }; +#if wxOSX_USE_COCOA_OR_CARBON + +// the iphone only has popup-menus + // ---------------------------------------------------------------------------- // Menu Bar (a la Windows) // ---------------------------------------------------------------------------- @@ -132,7 +145,6 @@ public: } // implementation from now on - WXHMENU Create(); int FindMenu(const wxString& title); void Detach(); @@ -173,10 +185,14 @@ protected: static WXHMENU s_macWindowMenuHandle ; private: - static wxMenuBar* s_macInstalledMenuBar ; - static wxMenuBar* s_macCommonMenuBar ; + static wxMenuBar* s_macInstalledMenuBar ; + static wxMenuBar* s_macCommonMenuBar ; + + wxMenu* m_rootMenu; DECLARE_DYNAMIC_CLASS(wxMenuBar) }; +#endif + #endif // _WX_MENU_H_ diff --git a/include/wx/osx/carbon/menuitem.h b/include/wx/osx/carbon/menuitem.h index cae5583583..6171b124ee 100644 --- a/include/wx/osx/carbon/menuitem.h +++ b/include/wx/osx/carbon/menuitem.h @@ -22,6 +22,9 @@ // ---------------------------------------------------------------------------- // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour // ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_FWD_CORE wxMenuItemImpl ; + class WXDLLIMPEXP_CORE wxMenuItem: public wxMenuItemBase { public: @@ -53,9 +56,8 @@ public: void SetRadioGroupStart(int start); void SetRadioGroupEnd(int end); + wxMenuItemImpl* GetPeer() { return m_peer; } private: - void DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) ; - void UncheckRadio() ; // the positions of the first and last items of the radio group this item @@ -73,6 +75,8 @@ private: wxBitmap m_bitmap; // Bitmap for menuitem, if any void* m_menu ; // the appropriate menu , may also be a system menu + + wxMenuItemImpl* m_peer; DECLARE_DYNAMIC_CLASS(wxMenuItem) }; diff --git a/include/wx/osx/carbon/nonownedwnd.h b/include/wx/osx/carbon/nonownedwnd.h index 664abc33e4..3ce7ae952c 100644 --- a/include/wx/osx/carbon/nonownedwnd.h +++ b/include/wx/osx/carbon/nonownedwnd.h @@ -97,7 +97,13 @@ public: wxNonOwnedWindowImpl* GetNonOwnedPeer() const { return m_nowpeer; } + // osx specific event handling common for all osx-ports + virtual void HandleActivated( double timestampsec, bool didActivate ); + virtual void HandleResized( double timestampsec ); + virtual void HandleMoved( double timestampsec ); + virtual void HandleResizing( double timestampsec, wxRect* rect ); + protected: // common part of all ctors void Init(); diff --git a/include/wx/osx/carbon/notebook.h b/include/wx/osx/carbon/notebook.h index 49750b8439..6a7d4a2e44 100644 --- a/include/wx/osx/carbon/notebook.h +++ b/include/wx/osx/carbon/notebook.h @@ -117,7 +117,9 @@ public: // base class virtuals // ------------------- virtual void Command(wxCommandEvent& event); - virtual wxInt32 MacControlHit(WXEVENTHANDLERREF handler, WXEVENTREF event); + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: virtual wxNotebookPage *DoRemovePage(size_t page) ; diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index c4f2ee8200..933bd32a3b 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -25,6 +25,8 @@ typedef SInt32 SRefCon; #if wxUSE_GUI +#include "wx/osx/uma.h" + #include "wx/listbox.h" #include "wx/osx/carbon/dc.h" #include "wx/osx/carbon/dcclient.h" @@ -289,8 +291,6 @@ public : void Init(); - virtual void Destroy(); - void SetReferenceInNativeControl(); static wxMacControl* GetReferenceFromNativeControl(ControlRef control); @@ -313,6 +313,7 @@ public : virtual void Move(int x, int y, int width, int height); virtual void GetPosition( int &x, int &y ) const; virtual void GetSize( int &width, int &height ) const; + virtual void SetControlSize( wxWindowVariant variant ) ; // where is in native window relative coordinates virtual void SetNeedsDisplay( const wxRect* where = NULL ); @@ -325,6 +326,28 @@ public : void RemoveFromParent(); void Embed( wxWidgetImpl *parent ); + + void SetDefaultButton( bool isDefault ); + void PerformClick(); + void SetLabel( const wxString& title, wxFontEncoding encoding ); + + wxInt32 GetValue() const; + void SetValue( wxInt32 v ); + void SetBitmap( const wxBitmap& bitmap ); + void SetupTabs( const wxNotebook ¬ebook ); + + void GetBestRect( wxRect *r ) const; + bool IsEnabled() const; + void Enable( bool enable ); + bool ButtonClickDidStateChange() { return false ;} + void SetMinimum( wxInt32 v ); + void SetMaximum( wxInt32 v ); + void PulseGauge() ; + void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ); + + // temp convenience methods + + void GetBestRect( Rect *r ) const; /* void operator= (ControlRef c) { m_controlRef = c; } operator ControlRef () { return m_controlRef; } @@ -340,14 +363,8 @@ public : virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ); - virtual SInt32 GetValue() const; virtual SInt32 GetMaximum() const; - virtual SInt32 GetMinimum() const; - - virtual void SetValue( SInt32 v ); - virtual void SetMinimum( SInt32 v ); - virtual void SetMaximum( SInt32 v ); - + virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ); virtual void SetRange( SInt32 minimum , SInt32 maximum ); @@ -404,7 +421,6 @@ public : } // Flash the control for the specified amount of time - virtual void Flash( ControlPartCode part , UInt32 ticks = 8 ); virtual void VisibilityChanged( bool shown ); virtual void SuperChangedPosition(); @@ -414,13 +430,11 @@ public : virtual void SetBackgroundColour( const wxColour& col ); virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ); void SetActionProc( ControlActionUPP actionProc ); - void SetViewSize( SInt32 viewSize ); SInt32 GetViewSize() const; virtual void SetVisibility( bool visible ); - virtual bool IsEnabled() const; + virtual bool IsActive() const; - virtual void Enable( bool enable ); // invalidates this control and all children virtual void InvalidateWithChildren(); @@ -429,9 +443,7 @@ public : // in native parent window relative coordinates virtual void GetRectInWindowCoords( Rect *r ); - virtual void GetBestRect( Rect *r ); - virtual void SetLabel( const wxString &title ); virtual void GetFeatures( UInt32 *features ); virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region ); @@ -614,38 +626,23 @@ const DataBrowserPropertyID kMinColumnId = 1050; // base API for high-level databrowser operations -class WXDLLIMPEXP_CORE wxMacListControl -{ -public: - virtual void MacDelete( unsigned int n ) = 0; - virtual void MacInsert( unsigned int n, const wxArrayStringsAdapter& items, int column = -1 ) = 0; - // returns index of newly created line - virtual int MacAppend( const wxString& item ) = 0; - virtual void MacSetString( unsigned int n, const wxString& item ) = 0; - virtual void MacClear() = 0; - virtual void MacDeselectAll() = 0; - virtual void MacSetSelection( unsigned int n, bool select, bool multi ) = 0; - virtual int MacGetSelection() const = 0; - virtual int MacGetSelections( wxArrayInt& aSelections ) const = 0; - virtual bool MacIsSelected( unsigned int n ) const = 0; - virtual void MacScrollTo( unsigned int n ) = 0; - virtual wxString MacGetString( unsigned int n) const = 0; - virtual unsigned int MacGetCount() const = 0; - - virtual void MacSetClientData( unsigned int n, void * data) = 0; - virtual void * MacGetClientData( unsigned int) const = 0; - - virtual ~wxMacListControl() { } -}; - // base class for databrowser items enum DataItemType { DataItem_Text }; +/* class WXDLLIMPEXP_CORE wxMacDataItem { +public : + wxMacDataItem(); + virtual ~wxMacDataItem(); +} ; +*/ + +class WXDLLIMPEXP_CORE wxMacDataItem +{ public : wxMacDataItem(); virtual ~wxMacDataItem(); @@ -664,24 +661,11 @@ public : DataBrowserItemNotification message, DataBrowserItemDataRef itemData ) const; - void SetLabel( const wxString& str); - const wxString& GetLabel() const; - void SetOrder( SInt32 order ); SInt32 GetOrder() const; - void SetData( void* data); - void* GetData() const; - - void SetColumn( short col ); - short GetColumn(); - protected : - wxString m_label; - wxCFStringRef m_cfLabel; - void * m_data; SInt32 m_order; - DataBrowserPropertyID m_colId; }; @@ -693,18 +677,17 @@ enum ListSortOrder { typedef wxMacDataItem* wxMacDataItemPtr; const wxMacDataItemPtr wxMacDataBrowserRootContainer = NULL; +typedef void * wxListColumnId ; WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxMacDataItemPtr, wxArrayMacDataItemPtr, class WXDLLIMPEXP_CORE); -class WXDLLIMPEXP_CORE wxMacDataItemBrowserControl : public wxMacDataBrowserControl, public wxMacListControl +class WXDLLIMPEXP_CORE wxMacDataItemBrowserControl : public wxMacDataBrowserControl { public : wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style); wxMacDataItemBrowserControl() {} // create a list item (can be a subclass of wxMacListBoxItem) - virtual wxMacDataItem* CreateItem(); - unsigned int GetItemCount(const wxMacDataItem* container, bool recurse , DataBrowserItemState state) const; void GetItems(const wxMacDataItem* container, bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items ) const; @@ -741,6 +724,18 @@ public : void GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const; + // add and remove + + virtual void MacDelete( unsigned int n ); + virtual void MacInsert( unsigned int n, wxMacDataItem* item); + virtual void MacClear(); + + // accessing content + + virtual unsigned int MacGetCount() const; + +public : + // item aware methods, to be used in subclasses virtual Boolean CompareItems(const wxMacDataItem* itemOneID, @@ -763,35 +758,6 @@ public : bool IsSelectionSuppressed() const { return m_suppressSelection; } bool SuppressSelection( bool suppress ); - - // wxMacListControl Methods - // add and remove - - virtual void MacDelete( unsigned int n ); - virtual void MacInsert( unsigned int n, const wxArrayStringsAdapter& items, int column = -1 ); - virtual int MacAppend( const wxString& item ); - virtual void MacClear(); - - // selecting - - virtual void MacDeselectAll(); - virtual void MacSetSelection( unsigned int n, bool select, bool multi = false ); - virtual int MacGetSelection() const; - virtual int MacGetSelections( wxArrayInt& aSelections ) const; - virtual bool MacIsSelected( unsigned int n ) const; - - // display - - virtual void MacScrollTo( unsigned int n ); - - // accessing content - - virtual void MacSetString( unsigned int n, const wxString& item ); - virtual void MacSetClientData( unsigned int n, void * data); - virtual wxString MacGetString( unsigned int n) const; - virtual void * MacGetClientData( unsigned int) const; - virtual unsigned int MacGetCount() const; - // client data virtual wxClientDataType GetClientDataType() const; @@ -854,28 +820,112 @@ public : virtual ~wxMacListBoxItem(); + virtual OSStatus GetSetData(wxMacDataItemBrowserControl *owner , + DataBrowserPropertyID property, + DataBrowserItemDataRef itemData, + bool changeValue ); + virtual void Notification(wxMacDataItemBrowserControl *owner , DataBrowserItemNotification message, DataBrowserItemDataRef itemData ) const; +protected : }; -class WXDLLIMPEXP_CORE wxMacDataBrowserListControl : public wxMacDataItemBrowserControl +class WXDLLIMPEXP_CORE wxMacDataBrowserColumn : public wxListWidgetColumn +{ +public : + wxMacDataBrowserColumn( DataBrowserPropertyID propertyId, DataBrowserPropertyType colType, bool editable ) + : m_property(propertyId), m_editable(editable), m_type( colType ) + { + } + ~wxMacDataBrowserColumn() + { + } + DataBrowserPropertyID GetProperty() const { return m_property ; } + + bool IsEditable() const { return m_editable; } + + DataBrowserPropertyType GetType() const { return m_type; } + +protected : + DataBrowserPropertyID m_property; + bool m_editable; + DataBrowserPropertyType m_type; +} ; + +WX_DEFINE_ARRAY_PTR(wxMacDataBrowserColumn *, wxArrayMacDataBrowserColumns); + + +class WXDLLIMPEXP_CORE wxMacDataBrowserCellValue : public wxListWidgetCellValue +{ +public : + wxMacDataBrowserCellValue(DataBrowserItemDataRef data) : m_data(data) {} + virtual ~wxMacDataBrowserCellValue() {} + + virtual void Set( CFStringRef value ); + virtual void Set( const wxString& value ); + virtual void Set( int value ) ; + + virtual int GetIntValue() const ; + virtual wxString GetStringValue() const ; +protected : + DataBrowserItemDataRef m_data; +} ; + + +class WXDLLIMPEXP_CORE wxMacDataBrowserListControl : public wxMacDataItemBrowserControl, public wxListWidgetImpl { public: wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style ); wxMacDataBrowserListControl() {} virtual ~wxMacDataBrowserListControl(); - virtual wxMacDataItem* CreateItem(); + // wxListWidgetImpl Methods - virtual void ItemNotification( - const wxMacDataItem* itemID, - DataBrowserItemNotification message, - DataBrowserItemDataRef itemData); + wxListWidgetColumn* InsertTextColumn( unsigned int pos, const wxString& title, bool editable = false, + wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) ; + wxListWidgetColumn* InsertCheckColumn( unsigned int pos , const wxString& title, bool editable = false, + wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) ; + + wxMacDataBrowserColumn* DoInsertColumn( unsigned int pos, DataBrowserPropertyID property, + const wxString& title, bool editable, + DataBrowserPropertyType colType, SInt16 just, int width ); + // add and remove + + virtual void ListDelete( unsigned int n ); + virtual void ListInsert( unsigned int n ); + virtual void ListClear(); + + // selecting + + virtual void ListDeselectAll(); + virtual void ListSetSelection( unsigned int n, bool select, bool multi = false ); + virtual int ListGetSelection() const; + virtual int ListGetSelections( wxArrayInt& aSelections ) const; + virtual bool ListIsSelected( unsigned int n ) const; + + // display + + virtual void ListScrollTo( unsigned int n ); + + // accessing content + + virtual unsigned int ListGetCount() const; + + virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ); + virtual void UpdateLineToEnd( unsigned int n) ; + + virtual void ItemNotification( + const wxMacDataItem* itemID, + DataBrowserItemNotification message, + DataBrowserItemDataRef itemData); // pointing back - // wxWindow * GetPeer() const; + wxMacDataBrowserColumn* GetColumnFromProperty( DataBrowserPropertyID ); +private: + wxArrayMacDataBrowserColumns m_columns; + int m_nextColumnId ; DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListControl) }; diff --git a/include/wx/osx/carbon/private/mactext.h b/include/wx/osx/carbon/private/mactext.h index 133371f16c..9d07080667 100644 --- a/include/wx/osx/carbon/private/mactext.h +++ b/include/wx/osx/carbon/private/mactext.h @@ -15,10 +15,19 @@ #include "wx/osx/private.h" // common interface for all implementations -class wxMacTextControl : public wxMacControl +class wxMacTextControl : +#if wxOSX_USE_CARBON + public wxMacControl +#else + public wxWidgetCocoaImpl +#endif { public : +#if wxOSX_USE_CARBON wxMacTextControl( wxTextCtrl *peer ) ; +#else + wxMacTextControl::wxMacTextControl(wxTextCtrl* peer, WXWidget w) ; +#endif virtual ~wxMacTextControl() ; virtual bool CanFocus() const { return true; } @@ -61,6 +70,7 @@ public : virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ); }; +#if wxOSX_USE_CARBON class wxMacUnicodeTextControl : public wxMacTextControl { public : @@ -95,5 +105,6 @@ protected : public : ControlEditTextSelectionRec m_selection ; }; +#endif #endif // _WX_MAC_PRIVATE_MACTEXT_H_ diff --git a/include/wx/osx/carbon/radiobut.h b/include/wx/osx/carbon/radiobut.h index 6514d218e7..9c719eed3b 100644 --- a/include/wx/osx/carbon/radiobut.h +++ b/include/wx/osx/carbon/radiobut.h @@ -41,12 +41,14 @@ public: // implementation - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; void Command(wxCommandEvent& event); wxRadioButton *AddInCycle(wxRadioButton *cycle); void RemoveFromCycle(); inline wxRadioButton *NextInCycle() {return m_cycle;} + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: wxRadioButton *m_cycle; diff --git a/include/wx/osx/carbon/scrolbar.h b/include/wx/osx/carbon/scrolbar.h index b699adafcb..cd32595315 100644 --- a/include/wx/osx/carbon/scrolbar.h +++ b/include/wx/osx/carbon/scrolbar.h @@ -48,12 +48,12 @@ public: // implementation only from now on void Command(wxCommandEvent& event); +#if wxOSX_USE_CARBON virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , - WXEVENTREF mevent ) ; - +#endif + virtual bool HandleClicked( double timestampsec ); protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/osx/carbon/slider.h b/include/wx/osx/carbon/slider.h index 04dc08a6d0..f2f40043e4 100644 --- a/include/wx/osx/carbon/slider.h +++ b/include/wx/osx/carbon/slider.h @@ -75,7 +75,9 @@ public: void SetTick(int tickPos) ; void Command(wxCommandEvent& event); - virtual wxInt32 MacControlHit(WXEVENTHANDLERREF handler, WXEVENTREF event); + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); void MacHandleControlClick(WXWidget control, wxInt16 controlpart, bool mouseStillDown); protected: diff --git a/include/wx/osx/carbon/spinbutt.h b/include/wx/osx/carbon/spinbutt.h index f7cdb58006..5c34e911d8 100644 --- a/include/wx/osx/carbon/spinbutt.h +++ b/include/wx/osx/carbon/spinbutt.h @@ -52,21 +52,23 @@ public: // accessors - virtual int GetMin() const; - virtual int GetMax() const; - virtual int GetValue() const; - virtual void SetValue(int val); virtual void SetRange(int minVal, int maxVal); + virtual int GetValue() const ; + virtual void SetValue(int val); // implementation +#if wxOSX_USE_CARBON virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; +#endif + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: - void MacHandleValueChanged( int inc ) ; - virtual wxSize DoGetBestSize() const; - int m_value ; + void SendThumbTrackEvent() ; + + virtual wxSize DoGetBestSize() const; private: DECLARE_DYNAMIC_CLASS(wxSpinButton) diff --git a/include/wx/osx/carbon/tglbtn.h b/include/wx/osx/carbon/tglbtn.h index 0091fbc8f0..44d4df5b9c 100644 --- a/include/wx/osx/carbon/tglbtn.h +++ b/include/wx/osx/carbon/tglbtn.h @@ -44,7 +44,7 @@ public: virtual void SetValue(bool value); virtual bool GetValue() const ; - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; + virtual bool HandleClicked( double timestampsec ); virtual void Command(wxCommandEvent& event); @@ -88,7 +88,7 @@ public: virtual void SetValue(bool value); virtual bool GetValue() const ; - virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; + virtual bool HandleClicked( double timestampsec ); virtual void Command(wxCommandEvent& event); diff --git a/include/wx/osx/carbon/toolbar.h b/include/wx/osx/carbon/toolbar.h index 9646b8e249..6dd02028cb 100644 --- a/include/wx/osx/carbon/toolbar.h +++ b/include/wx/osx/carbon/toolbar.h @@ -99,7 +99,7 @@ protected: DECLARE_EVENT_TABLE() #if wxOSX_USE_NATIVE_TOOLBAR bool m_macUsesNativeToolbar ; - void* m_macHIToolbarRef ; + void* m_macToolbar ; #endif }; diff --git a/include/wx/osx/carbon/uma.h b/include/wx/osx/carbon/uma.h index 7b5ccc0023..00477c6b25 100644 --- a/include/wx/osx/carbon/uma.h +++ b/include/wx/osx/carbon/uma.h @@ -14,8 +14,6 @@ #include "wx/osx/private.h" -long UMAGetSystemVersion() ; - #if wxUSE_GUI // menu manager @@ -24,8 +22,6 @@ MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding e void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding) ; void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex item , bool enable ) ; -void UMAAppendSubMenuItem( MenuRef menu , const wxString& title , wxFontEncoding encoding , SInt16 submenuid ) ; -void UMAInsertSubMenuItem( MenuRef menu , const wxString& title , wxFontEncoding encoding , MenuItemIndex item , SInt16 submenuid ) ; void UMAAppendMenuItem( MenuRef menu , const wxString& title , wxFontEncoding encoding , wxAcceleratorEntry *entry = NULL ) ; void UMAInsertMenuItem( MenuRef menu , const wxString& title , wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry = NULL ) ; void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) ; diff --git a/include/wx/osx/carbon/window.h b/include/wx/osx/carbon/window.h index 4cb6f8c7c8..783aee0929 100644 --- a/include/wx/osx/carbon/window.h +++ b/include/wx/osx/carbon/window.h @@ -84,7 +84,9 @@ public: const; protected: virtual void DoEnable( bool enable ); +#if wxUSE_MENUS virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); +#endif virtual void DoFreeze(); virtual void DoThaw(); @@ -247,6 +249,9 @@ public: void * MacGetCGContextRef() { return m_cgContextRef ; } void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; } + // osx specific event handling common for all osx-ports + + virtual bool HandleClicked( double timestampsec ); protected: // For controls like radio buttons which are genuinely composite wxList m_subControls; diff --git a/include/wx/osx/cocoa/chkconf.h b/include/wx/osx/cocoa/chkconf.h index 22704a9fde..0dc2e991fc 100644 --- a/include/wx/osx/cocoa/chkconf.h +++ b/include/wx/osx/cocoa/chkconf.h @@ -84,44 +84,8 @@ #define wxUSE_TASKBARICON 0 #endif -/* -#if wxUSE_POPUPWIN -#undef wxUSE_POPUPWIN -#define wxUSE_POPUPWIN 0 -#endif - -#if wxUSE_COMBOBOX -#undef wxUSE_COMBOBOX -#define wxUSE_COMBOBOX 0 -#endif - - -#if wxUSE_MENUS -#undef wxUSE_MENUS -#define wxUSE_MENUS 0 -#endif - -#if wxUSE_CALENDARCTRL -#undef wxUSE_CALENDARCTRL -#define wxUSE_CALENDARCTRL 0 -#endif - -#if wxUSE_WXHTML_HELP -#undef wxUSE_WXHTML_HELP -#define wxUSE_WXHTML_HELP 0 -#endif - -#if wxUSE_DOC_VIEW_ARCHITECTURE -#undef wxUSE_DOC_VIEW_ARCHITECTURE #define wxUSE_DOC_VIEW_ARCHITECTURE 0 -#endif - -#if wxUSE_PRINTING_ARCHITECTURE -#undef wxUSE_PRINTING_ARCHITECTURE -#define wxUSE_PRINTING_ARCHITECTURE 0 -#endif - -*/ +#define wxUSE_WXHTML_HELP 0 #endif /* _WX_MAC_CHKCONF_H_ */ diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 80e4b9dbb0..51f7015479 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -24,9 +24,72 @@ extern wxRect wxFromNSRect( NSView* parent, const NSRect& rect ); extern NSPoint wxToNSPoint( NSView* parent, const wxPoint& p ); extern wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p ); + + // used for many wxControls + + @interface wxNSButton : NSButton + { + wxWidgetImpl* impl; + } + + - (void)setImplementation: (wxWidgetImpl *) theImplementation; + - (wxWidgetImpl*) implementation; + - (BOOL) isFlipped; + - (void) clickedAction: (id) sender; + + @end + + @interface wxNSBox : NSBox + { + wxWidgetImpl* impl; + } + + - (void)setImplementation: (wxWidgetImpl *) theImplementation; + - (wxWidgetImpl*) implementation; + - (BOOL) isFlipped; + + @end + + @interface wxNSTextField : NSTextField + { + wxWidgetImpl* impl; + } + + - (void)setImplementation: (wxWidgetImpl *) theImplementation; + - (wxWidgetImpl*) implementation; + - (BOOL) isFlipped; + + @end + + NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , + bool adjustForOrigin = true ); #endif // __OBJC__ +// +// shared between Cocoa and Carbon +// + +// bring in themeing types without pulling in the headers + +typedef SInt16 ThemeBrush; +long UMAGetSystemVersion() ; +CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ; +OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage( + CGContextRef inContext, + const CGRect * inBounds, + CGImageRef inImage) ; +WX_NSImage wxOSXCreateNSImageFromCGImage( CGImageRef image ); + +WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to ); +WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ); +WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ); +WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ); + +// +// +// + #if wxUSE_GUI class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl @@ -39,7 +102,8 @@ public : void Init(); virtual bool IsVisible() const ; - + virtual void SetVisibility(bool); + virtual void Raise(); virtual void Lower(); @@ -48,10 +112,13 @@ public : virtual WXWidget GetWXWidget() const { return m_osxView; } + virtual void SetBackgroundColour(const wxColour&); + virtual void GetContentArea( int &left , int &top , int &width , int &height ) const; virtual void Move(int x, int y, int width, int height); virtual void GetPosition( int &x, int &y ) const; virtual void GetSize( int &width, int &height ) const; + virtual void SetControlSize( wxWindowVariant variant ); virtual void SetNeedsDisplay( const wxRect* where = NULL ); virtual bool GetNeedsDisplay() const; @@ -63,6 +130,24 @@ public : void RemoveFromParent(); void Embed( wxWidgetImpl *parent ); + + void SetDefaultButton( bool isDefault ); + void PerformClick(); + void SetLabel(const wxString& title, wxFontEncoding encoding); + + wxInt32 GetValue() const; + void SetValue( wxInt32 v ); + void SetBitmap( const wxBitmap& bitmap ); + void SetupTabs( const wxNotebook ¬ebook ); + void GetBestRect( wxRect *r ) const; + bool IsEnabled() const; + void Enable( bool enable ); + bool ButtonClickDidStateChange() { return true ;} + void SetMinimum( wxInt32 v ); + void SetMaximum( wxInt32 v ); + void PulseGauge(); + void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ); + protected: WXWidget m_osxView; DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl) @@ -142,6 +227,27 @@ typedef struct tagClassicCursor wxInt16 hotspot[2]; }ClassicCursor; +const short kwxCursorBullseye = 0; +const short kwxCursorBlank = 1; +const short kwxCursorPencil = 2; +const short kwxCursorMagnifier = 3; +const short kwxCursorNoEntry = 4; +const short kwxCursorPaintBrush = 5; +const short kwxCursorPointRight = 6; +const short kwxCursorPointLeft = 7; +const short kwxCursorQuestionArrow = 8; +const short kwxCursorRightArrow = 9; +const short kwxCursorSizeNS = 10; +const short kwxCursorSize = 11; +const short kwxCursorSizeNESW = 12; +const short kwxCursorSizeNWSE = 13; +const short kwxCursorRoller = 14; +const short kwxCursorLast = kwxCursorRoller; + +// exposing our fallback cursor map + +extern ClassicCursor gMacCursors[]; + #endif #endif diff --git a/include/wx/osx/core/mimetype.h b/include/wx/osx/core/mimetype.h new file mode 100644 index 0000000000..46058b070f --- /dev/null +++ b/include/wx/osx/core/mimetype.h @@ -0,0 +1,174 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/osx/core/mimetype.h +// Purpose: classes and functions to manage MIME types +// Author: Vadim Zeitlin +// Modified by: +// Created: 23.09.98 +// RCS-ID: $Id: mimetype.h 54448 2008-07-01 09:28:08Z RR $ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows licence (part of wxExtra library) +///////////////////////////////////////////////////////////////////////////// + +#ifndef _MIMETYPE_IMPL_H +#define _MIMETYPE_IMPL_H + +#include "wx/mimetype.h" + +#if wxUSE_MIMETYPE + +class wxMimeTypeCommands; + +WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray); + +// this is the real wxMimeTypesManager for Unix +class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl +{ +public: + // ctor and dtor + wxMimeTypesManagerImpl(); + virtual ~wxMimeTypesManagerImpl(); + + // load all data into memory - done when it is needed for the first time + void Initialize(int mailcapStyles = wxMAILCAP_ALL, + const wxString& extraDir = wxEmptyString); + + // and delete the data here + void ClearData(); + + // implement containing class functions + wxFileType *GetFileTypeFromExtension(const wxString& ext); + wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); + + size_t EnumAllFileTypes(wxArrayString& mimetypes); + + void AddFallback(const wxFileTypeInfo& filetype); + + // add information about the given mimetype + void AddMimeTypeInfo(const wxString& mimetype, + const wxString& extensions, + const wxString& description); + void AddMailcapInfo(const wxString& strType, + const wxString& strOpenCmd, + const wxString& strPrintCmd, + const wxString& strTest, + const wxString& strDesc); + + // add a new record to the user .mailcap/.mime.types files + wxFileType *Associate(const wxFileTypeInfo& ftInfo); + // remove association + bool Unassociate(wxFileType *ft); + + // accessors + // get the string containing space separated extensions for the given + // file type + wxString GetExtension(size_t index) { return m_aExtensions[index]; } + +protected: + void InitIfNeeded(); + + wxArrayString m_aTypes, // MIME types + m_aDescriptions, // descriptions (just some text) + m_aExtensions, // space separated list of extensions + m_aIcons; // Icon filenames + + // verb=command pairs for this file type + wxMimeCommandsArray m_aEntries; + + // are we initialized? + bool m_initialized; + + wxString GetCommand(const wxString &verb, size_t nIndex) const; + + // Read XDG *.desktop file + void LoadXDGApp(const wxString& filename); + // Scan XDG directory + void LoadXDGAppsFilesFromDir(const wxString& dirname); + + // Load XDG globs files + void LoadXDGGlobs(const wxString& filename); + + // functions used to do associations + virtual int AddToMimeData(const wxString& strType, + const wxString& strIcon, + wxMimeTypeCommands *entry, + const wxArrayString& strExtensions, + const wxString& strDesc, + bool replaceExisting = TRUE); + virtual bool DoAssociation(const wxString& strType, + const wxString& strIcon, + wxMimeTypeCommands *entry, + const wxArrayString& strExtensions, + const wxString& strDesc); + + // give it access to m_aXXX variables + friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl; +}; + +class WXDLLIMPEXP_BASE wxFileTypeImpl +{ +public: + // initialization functions + // this is used to construct a list of mimetypes which match; + // if built with GetFileTypeFromMimetype index 0 has the exact match and + // index 1 the type / * match + // if built with GetFileTypeFromExtension, index 0 has the mimetype for + // the first extension found, index 1 for the second and so on + + void Init(wxMimeTypesManagerImpl *manager, size_t index) + { m_manager = manager; m_index.Add(index); } + + // accessors + bool GetExtensions(wxArrayString& extensions); + bool GetMimeType(wxString *mimeType) const + { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; } + bool GetMimeTypes(wxArrayString& mimeTypes) const; + bool GetIcon(wxIconLocation *iconLoc) const; + + bool GetDescription(wxString *desc) const + { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; } + + bool GetOpenCommand(wxString *openCmd, + const wxFileType::MessageParameters& params) const + { + *openCmd = GetExpandedCommand(wxT("open"), params); + return (! openCmd -> IsEmpty() ); + } + + bool GetPrintCommand(wxString *printCmd, + const wxFileType::MessageParameters& params) const + { + *printCmd = GetExpandedCommand(wxT("print"), params); + return (! printCmd -> IsEmpty() ); + } + + // return the number of commands defined for this file type, 0 if none + size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, + const wxFileType::MessageParameters& params) const; + + + // remove the record for this file type + // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead + bool Unassociate(wxFileType *ft) + { + return m_manager->Unassociate(ft); + } + + // set an arbitrary command, ask confirmation if it already exists and + // overwriteprompt is TRUE + bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE); + bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0); + +private: + wxString + GetExpandedCommand(const wxString & verb, + const wxFileType::MessageParameters& params) const; + + wxMimeTypesManagerImpl *m_manager; + wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays +}; + +#endif // wxUSE_MIMETYPE + +#endif // _MIMETYPE_IMPL_H + + diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index d14d919dc8..718cce143f 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -21,6 +21,10 @@ #include "wx/osx/core/cfstring.h" #include "wx/osx/core/cfdataref.h" +#if wxOSX_USE_COCOA_OR_CARBON +WXDLLIMPEXP_BASE long UMAGetSystemVersion() ; +#endif + #if wxUSE_GUI #if wxOSX_USE_IPHONE @@ -79,6 +83,79 @@ class wxWindowMac; extern wxWindow* g_MacLastWindow; class wxNonOwnedWindow; +// temporary typedef so that no additional casts are necessary within carbon code at the moment + +class wxMacControl; +class wxWidgetImpl; +class wxNotebook; + +#if wxOSX_USE_CARBON +typedef wxMacControl wxWidgetImplType; +#else +typedef wxWidgetImpl wxWidgetImplType; +#endif + +class wxMenuItemImpl : public wxObject +{ +public : + wxMenuItemImpl( wxMenuItem* peer ) : m_peer(peer) + { + } + + virtual ~wxMenuItemImpl() ; + virtual void SetBitmap( const wxBitmap& bitmap ) = 0; + virtual void Enable( bool enable ) = 0; + virtual void Check( bool check ) = 0; + virtual void SetLabel( const wxString& text, wxAcceleratorEntry *entry ) = 0; + virtual void Hide( bool hide = true ) = 0; + + virtual void * GetHMenuItem() = 0; + + wxMenuItem* GetWXPeer() { return m_peer ; } + + static wxMenuItemImpl* Create( wxMenuItem* peer, wxMenu *pParentMenu, + int id, + const wxString& text, + wxAcceleratorEntry *entry, + const wxString& strHelp, + wxItemKind kind, + wxMenu *pSubMenu ); + +protected : + wxMenuItem* m_peer; + + DECLARE_ABSTRACT_CLASS(wxMenuItemImpl); +} ; + +class wxMenuImpl : public wxObject +{ +public : + wxMenuImpl( wxMenu* peer ) : m_peer(peer) + { + } + + virtual ~wxMenuImpl() ; + virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) = 0; + virtual void Remove( wxMenuItem *pItem ) = 0; + + virtual void MakeRoot() = 0; + + virtual void SetTitle( const wxString& text ) = 0; + + virtual WXHMENU GetHMenu() = 0; + + wxMenu* GetWXPeer() { return m_peer ; } + + static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); + static wxMenuImpl* CreateRootMenu( wxMenu* peer ); +protected : + wxMenu* m_peer; + + DECLARE_ABSTRACT_CLASS(wxMenuItemImpl); +} ; + + + class WXDLLIMPEXP_CORE wxWidgetImpl : public wxObject { public : @@ -88,8 +165,6 @@ public : void Init(); - virtual void Destroy(); - bool IsRootControl() const { return m_isRootControl; } wxWindowMac* GetWXPeer() const { return m_wxPeer; } @@ -117,6 +192,7 @@ public : virtual void Move(int x, int y, int width, int height) = 0; virtual void GetPosition( int &x, int &y ) const = 0; virtual void GetSize( int &width, int &height ) const = 0; + virtual void SetControlSize( wxWindowVariant variant ) = 0; virtual void SetNeedsDisplay( const wxRect* where = NULL ) = 0; virtual bool GetNeedsDisplay() const = 0; @@ -131,12 +207,201 @@ public : virtual void RemoveFromParent() = 0; virtual void Embed( wxWidgetImpl *parent ) = 0; + + virtual void SetDefaultButton( bool isDefault ) = 0; + virtual void PerformClick() = 0; + virtual void SetLabel( const wxString& title, wxFontEncoding encoding ) = 0; + + virtual wxInt32 GetValue() const = 0; + virtual void SetValue( wxInt32 v ) = 0; + virtual void SetBitmap( const wxBitmap& bitmap ) = 0; + virtual void SetupTabs( const wxNotebook ¬ebook ) =0; + virtual void GetBestRect( wxRect *r ) const = 0; + virtual bool IsEnabled() const = 0; + virtual void Enable( bool enable ) = 0; + virtual void SetMinimum( wxInt32 v ) = 0; + virtual void SetMaximum( wxInt32 v ) = 0; + virtual void PulseGauge() = 0; + virtual void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) = 0; + + // is the clicked event sent AFTER the state already changed, so no additional + // state changing logic is required from the outside + virtual bool ButtonClickDidStateChange() = 0; // static creation methods, must be implemented by all toolkits - static wxWidgetImpl* CreateUserPane( wxWindowMac* wxpeer, const wxPoint& pos, const wxSize& size, - long style, long extraStyle, const wxString& name) ; - static wxWidgetImpl* CreateContentView( wxNonOwnedWindow* now ) ; + static wxWidgetImplType* CreateUserPane( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + static wxWidgetImplType* CreateContentView( wxNonOwnedWindow* now ) ; + + static wxWidgetImplType* CreateButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + + static wxWidgetImplType* CreateDisclosureTriangle( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + + static wxWidgetImplType* CreateStaticLine( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + + static wxWidgetImplType* CreateGroupBox( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + + static wxWidgetImplType* CreateStaticText( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + + static wxWidgetImplType* CreateTextControl( wxTextCtrl* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& content, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) ; + + static wxWidgetImplType* CreateCheckBox( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateRadioButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateToggleButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateBitmapToggleButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateBitmapButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateTabView( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateGauge( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxInt32 value, + wxInt32 minimum, + wxInt32 maximum, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateSlider( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxInt32 value, + wxInt32 minimum, + wxInt32 maximum, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateSpinButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxInt32 value, + wxInt32 minimum, + wxInt32 maximum, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateScrollBar( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateChoice( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxMenu* menu, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); + + static wxWidgetImplType* CreateListBox( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle); // converts from Toplevel-Content relative to local static void Convert( wxPoint *pt , wxWidgetImpl *from , wxWidgetImpl *to ); @@ -148,6 +413,73 @@ protected : DECLARE_ABSTRACT_CLASS(wxWidgetImpl) }; +// +// the interface to be implemented eg by a listbox +// + +class WXDLLIMPEXP_CORE wxMacDataItem ; + +class WXDLLIMPEXP_CORE wxListWidgetColumn +{ +public : + virtual ~wxListWidgetColumn() {} +} ; + +class WXDLLIMPEXP_CORE wxListWidgetCellValue +{ +public : + wxListWidgetCellValue() {} + virtual ~wxListWidgetCellValue() {} + + virtual void Set( CFStringRef value ) = 0; + virtual void Set( const wxString& value ) = 0; + virtual void Set( int value ) = 0; + + virtual int GetIntValue() const = 0; + virtual wxString GetStringValue() const = 0; +} ; + +class WXDLLIMPEXP_CORE wxListWidgetImpl +{ +public: + wxListWidgetImpl() {} + virtual ~wxListWidgetImpl() { } + + virtual wxListWidgetColumn* InsertTextColumn( unsigned pos, const wxString& title, bool editable = false, + wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) = 0 ; + virtual wxListWidgetColumn* InsertCheckColumn( unsigned pos , const wxString& title, bool editable = false, + wxAlignment just = wxALIGN_LEFT , int defaultWidth = -1) = 0 ; + + // add and remove + + // TODO will be replaced + virtual void ListDelete( unsigned int n ) = 0; + virtual void ListInsert( unsigned int n ) = 0; + virtual void ListClear() = 0; + + // selecting + + virtual void ListDeselectAll() = 0; + virtual void ListSetSelection( unsigned int n, bool select, bool multi ) = 0; + virtual int ListGetSelection() const = 0; + virtual int ListGetSelections( wxArrayInt& aSelections ) const = 0; + virtual bool ListIsSelected( unsigned int n ) const = 0; + + // display + + virtual void ListScrollTo( unsigned int n ) = 0; + virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) = 0; + virtual void UpdateLineToEnd( unsigned int n) = 0; + + // accessing content + + virtual unsigned int ListGetCount() const = 0; +}; + +// +// toplevel window implementation class +// + class wxNonOwnedWindowImpl : public wxObject { public : @@ -248,6 +580,12 @@ public : virtual void WindowToScreen( int *x, int *y ) = 0; wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; } + + // static creation methods, must be implemented by all toolkits + + static wxNonOwnedWindowImpl* CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, + long style, long extraStyle, const wxString& name ) ; + protected : wxNonOwnedWindow* m_wxPeer; DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl) diff --git a/include/wx/osx/iphone/chkconf.h b/include/wx/osx/iphone/chkconf.h index 53f08b67c3..8825251fde 100644 --- a/include/wx/osx/iphone/chkconf.h +++ b/include/wx/osx/iphone/chkconf.h @@ -67,6 +67,84 @@ #define wxUSE_TASKBARICON 0 #endif +#define wxUSE_BUTTON 1 +#define wxUSE_CARET 1 +#define wxUSE_CHOICE 1 +#define wxUSE_SCROLLBAR 1 +#define wxUSE_STATUSBAR 1 +#define wxUSE_NATIVE_STATUSBAR 0 +#define wxUSE_TEXTCTRL 1 +#define wxUSE_ABOUTDLG 1 +#define wxUSE_STATTEXT 1 +#define wxUSE_STATLINE 1 +#define wxUSE_COLLPANE 1 +#define wxUSE_STATBMP 1 +#define wxUSE_STATBOX 1 +#define wxUSE_CHECKBOX 1 +#define wxUSE_RADIOBTN 1 +#define wxUSE_RADIOBOX 1 +#define wxUSE_TOGGLEBTN 1 + +#define wxUSE_TOOLBAR 0 +#define wxUSE_HTML 0 + +#define wxUSE_RICHTEXT 0 + +#define wxUSE_ANIMATIONCTRL 0 +#define wxUSE_CALENDARCTRL 0 +#define wxUSE_COMBOBOX 0 +#define wxUSE_COMBOCTRL 0 +#define wxUSE_ODCOMBOBOX 0 +#define wxUSE_BITMAPCOMBOBOX 0 +#define wxUSE_BMPBUTTON 0 +#define wxUSE_CHECKLISTBOX 0 +#define wxUSE_GAUGE 0 +#define wxUSE_GRID 0 +#define wxUSE_LISTBOX 0 +#define wxUSE_LISTCTRL 0 +#define wxUSE_NOTEBOOK 0 +#define wxUSE_SLIDER 0 +#define wxUSE_SPINBTN 0 +#define wxUSE_SPINCTRL 0 +#define wxUSE_TREECTRL 0 +#define wxUSE_DATEPICKCTRL 0 +#define wxUSE_DATAVIEWCTRL 0 +#define wxUSE_EDITABLELISTBOX 0 +#define wxUSE_FILEPICKERCTRL 0 +#define wxUSE_DIRPICKERCTRL 0 +#define wxUSE_FILECTRL 0 +#define wxUSE_COLOURPICKERCTRL 0 +#define wxUSE_FONTPICKERCTRL 0 +#define wxUSE_DEBUGREPORT 0 +#define wxUSE_HYPERLINKCTRL 0 +#define wxUSE_STC 0 +#define wxUSE_AUI 0 +#define wxUSE_BUSYINFO 0 +#define wxUSE_SEARCHCTRL 0 + +#define wxUSE_LOGWINDOW 0 +#define wxUSE_LOG_DIALOG 0 +#define wxUSE_LISTBOOK 0 +#define wxUSE_CHOICEBOOK 0 +#define wxUSE_TREEBOOK 0 +#define wxUSE_TOOLBOOK 0 +#define wxUSE_CHOICEDLG 0 +#define wxUSE_HELP 0 +#define wxUSE_PROGRESSDLG 0 +#define wxUSE_FONTDLG 0 +#define wxUSE_FILEDLG 0 +#define wxUSE_CHOICEDLG 0 +#define wxUSE_NUMBERDLG 0 +#define wxUSE_TEXTDLG 0 +#define wxUSE_DIRDLG 0 +#define wxUSE_STARTUP_TIPS 0 +#define wxUSE_WIZARDDLG 0 +#define wxUSE_TOOLBAR_NATIVE 0 +#define wxUSE_FINDREPLDLG 0 +#define wxUSE_TAB_DIALOG 0 +#define wxUSE_TASKBARICON 0 + + /* #if wxUSE_POPUPWIN #undef wxUSE_POPUPWIN diff --git a/include/wx/osx/mimetype.h b/include/wx/osx/mimetype.h index c45adc576b..cd3a3a1e43 100644 --- a/include/wx/osx/mimetype.h +++ b/include/wx/osx/mimetype.h @@ -1,5 +1,5 @@ #ifdef __WXMAC_CLASSIC__ #include "wx/osx/classic/mimetype.h" #else -#include "wx/osx/carbon/mimetype.h" +#include "wx/osx/core/mimetype.h" #endif diff --git a/include/wx/osx/private.h b/include/wx/osx/private.h index 89cc04313e..ba09d40872 100644 --- a/include/wx/osx/private.h +++ b/include/wx/osx/private.h @@ -4,6 +4,9 @@ #error "this files should only be included after platform.h was included #endif +#ifndef _WX_PRIVATE_OSX_H_ +#define _WX_PRIVATE_OSX_H_ + #if wxOSX_USE_IPHONE #include "wx/osx/iphone/private.h" #elif wxOSX_USE_CARBON @@ -11,3 +14,5 @@ #elif wxOSX_USE_COCOA #include "wx/osx/cocoa/private.h" #endif + +#endif \ No newline at end of file diff --git a/include/wx/osx/statbmp.h b/include/wx/osx/statbmp.h index 01cb68184b..59bf91a8f0 100644 --- a/include/wx/osx/statbmp.h +++ b/include/wx/osx/statbmp.h @@ -1,5 +1,6 @@ -#ifdef __WXMAC_CLASSIC__ -#include "wx/osx/classic/statbmp.h" -#else +#if wxOSX_USE_CARBON #include "wx/osx/carbon/statbmp.h" +#else +#define wxGenericStaticBitmap wxStaticBitmap +#include "wx/generic/statbmpg.h" #endif diff --git a/include/wx/osx/statline.h b/include/wx/osx/statline.h index 416ee24a1c..b491cb2580 100644 --- a/include/wx/osx/statline.h +++ b/include/wx/osx/statline.h @@ -1,5 +1,5 @@ -#ifdef __WXMAC_CLASSIC__ -#include "wx/osx/classic/statline.h" +#if wxOSX_USE_CARBON +#include "wx/osx/carbon/statline.h" #else #include "wx/osx/carbon/statline.h" #endif diff --git a/src/osx/artmac.cpp b/src/osx/artmac.cpp index 548eb2ce97..a68ca81346 100644 --- a/src/osx/artmac.cpp +++ b/src/osx/artmac.cpp @@ -23,7 +23,7 @@ #include "wx/image.h" #endif -#if !defined(__WXUNIVERSAL__) +#if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON #include "wx/artprov.h" #include "wx/image.h" diff --git a/src/osx/button_osx.cpp b/src/osx/button_osx.cpp index 239ded9d35..526e3a6522 100644 --- a/src/osx/button_osx.cpp +++ b/src/osx/button_osx.cpp @@ -92,22 +92,7 @@ bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxStrin if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; -#if wxOSX_USE_CARBON - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_peer = new wxMacControl(this) ; - - OSStatus err = CreateDisclosureTriangleControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, - kControlDisclosureTrianglePointDefault, - wxCFStringRef( label ), - 0, // closed - TRUE, // draw title - TRUE, // auto toggle back and forth - m_peer->GetControlRefAddr() ); - - verify_noerr( err ); -#endif - wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid Mac control") ) ; + m_peer = wxWidgetImpl::CreateDisclosureTriangle(this, parent, id, label, pos, size, style, GetExtraStyle() ); MacPostControlCreate( pos, size ); // passing the text in the param doesn't seem to work, so lets do if again @@ -118,16 +103,12 @@ bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxStrin void wxDisclosureTriangle::SetOpen( bool open ) { -#if wxOSX_USE_CARBON m_peer->SetValue( open ? 1 : 0 ); -#endif } bool wxDisclosureTriangle::IsOpen() const { -#if wxOSX_USE_CARBON return m_peer->GetValue() == 1; -#endif } bool wxDisclosureTriangle::HandleClicked( double timestampsec ) diff --git a/src/osx/carbon/Info.plist.in b/src/osx/carbon/Info.plist.in index de35d6de27..1f6860d0e7 100644 --- a/src/osx/carbon/Info.plist.in +++ b/src/osx/carbon/Info.plist.in @@ -8,6 +8,13 @@ org.wxwindows.IDENTIFIER CFBundleDevelopmentRegion English + CFBundleLocalizations + + de + en + fr + it + CFBundleExecutable EXECUTABLE CFBundleIconFile @@ -23,11 +30,11 @@ CFBundleShortVersionString VERSION CFBundleGetInfoString - EXECUTABLE version VERSION, (c) 2002-2006 wxWidgets + EXECUTABLE version VERSION, (c) 2002-2008 wxWidgets CFBundleLongVersionString - VERSION, (c) 2002-2006 wxWidgets + VERSION, (c) 2002-2008 wxWidgets NSHumanReadableCopyright - Copyright 2002-2006 wxWidgets + Copyright 2002-2008 wxWidgets LSRequiresCarbon CSResourcesFileMapped diff --git a/src/osx/carbon/aboutdlg.cpp b/src/osx/carbon/aboutdlg.cpp index 49dd82abfa..061a42b2a5 100644 --- a/src/osx/carbon/aboutdlg.cpp +++ b/src/osx/carbon/aboutdlg.cpp @@ -61,7 +61,7 @@ void wxAboutBox(const wxAboutDialogInfo& info) // Mac native about box currently can show only name, version, copyright // and description fields and we also shoehorn the credits text into the // description but if we have anything else we must use the generic version -#if wxOSX_USE_CARBON + if ( info.IsSimple() ) { AboutBoxOptions opts; @@ -82,7 +82,6 @@ void wxAboutBox(const wxAboutDialogInfo& info) HIAboutBox(opts); } else // simple "native" version is not enough -#endif { // we need to use the full-blown generic version wxGenericAboutBox(info); diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index c62b44ff63..1067c8a8e5 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/app.cpp +// Name: src/osx/carbon/app.cpp // Purpose: wxApp // Author: Stefan Csomor // Modified by: @@ -40,6 +40,7 @@ #include "wx/filename.h" #include "wx/link.h" #include "wx/thread.h" +#include "wx/evtloop.h" #include @@ -57,13 +58,6 @@ // Keep linker from discarding wxStockGDIMac wxFORCE_LINK_MODULE(gdiobj) -// statics for implementation -static bool s_inYield = false; -static bool s_inReceiveEvent = false ; -#if wxOSX_USE_COCOA_OR_CARBON -static EventTime sleepTime = kEventDurationNoWait ; -#endif - IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) @@ -514,12 +508,12 @@ wxMenu* wxFindMenuFromMacCommand( const HICommand &command , wxMenuItem* &item ) } else { - URefCon refCon ; + URefCon refCon = NULL ; GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ; itemMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ; - if ( itemMenu != NULL ) - item = (wxMenuItem*) refCon ; + if ( itemMenu != NULL && refCon != 0) + item = ((wxMenuItemImpl*) refCon)->GetWXPeer() ; } } #endif @@ -569,22 +563,31 @@ wxMacAppMenuEventHandler( EventHandlerCallRef WXUNUSED(handler), if ( menu ) { - wxEventType type=0; - MenuCommand cmd=0; switch (GetEventKind(event)) { case kEventMenuOpening: - type = wxEVT_MENU_OPEN; + menu->HandleMenuOpened(); break; case kEventMenuClosed: - type = wxEVT_MENU_CLOSE; + menu->HandleMenuClosed(); break; case kEventMenuTargetItem: - cmd = cEvent.GetParameter(kEventParamMenuCommand,typeMenuCommand) ; - if (cmd != 0) - type = wxEVT_MENU_HIGHLIGHT; + { + HICommand command ; + + command.menu.menuRef = menuRef; + command.menu.menuItemIndex = cEvent.GetParameter(kEventParamMenuItemIndex,typeMenuItemIndex) ; + command.commandID = cEvent.GetParameter(kEventParamMenuCommand,typeMenuCommand) ; + if (command.commandID != 0) + { + wxMenuItem* item = NULL ; + wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ; + if ( itemMenu && item ) + itemMenu->HandleMenuItemHighlighted( item ); + } + } break; default: @@ -592,23 +595,6 @@ wxMacAppMenuEventHandler( EventHandlerCallRef WXUNUSED(handler), break; } - if ( type ) - { - wxMenuEvent wxevent(type, cmd, menu); - wxevent.SetEventObject(menu); - - wxEvtHandler* handler = menu->GetEventHandler(); - if (handler && handler->ProcessEvent(wxevent)) - { - // handled - } - else - { - wxWindow *win = menu->GetInvokingWindow(); - if (win) - win->HandleWindowEvent(wxevent); - } - } } #endif return eventNotHandledErr; @@ -628,7 +614,6 @@ wxMacAppCommandEventHandler( EventHandlerCallRef WXUNUSED(handler) , wxMenuItem* item = NULL ; wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ; - int id = wxMacCommandToId( command.commandID ) ; if ( item ) { @@ -637,11 +622,13 @@ wxMacAppCommandEventHandler( EventHandlerCallRef WXUNUSED(handler) , switch ( cEvent.GetKind() ) { case kEventProcessCommand : - result = itemMenu->MacHandleCommandProcess( item, id ); + if ( itemMenu->HandleCommandProcess( item ) ) + result = noErr; break ; case kEventCommandUpdateStatus: - result = itemMenu->MacHandleCommandUpdateStatus( item, id ); + if ( itemMenu->HandleCommandUpdateStatus( item ) ) + result = noErr; break ; default : @@ -843,21 +830,43 @@ bool wxApp::Initialize(int& argc, wxChar **argv) /* connect posted events to common-mode run loop so that wxPostEvent events are handled even while we're in the menu or on a scrollbar */ + /* CFRunLoopSourceContext event_posted_context = {0}; event_posted_context.perform = macPostedEventCallback; m_macEventPosted = CFRunLoopSourceCreate(NULL,0,&event_posted_context); CFRunLoopAddSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); // run loop takes ownership CFRelease(m_macEventPosted); - + */ return true; } +bool wxApp::CallOnInit() +{ + wxMacAutoreleasePool autoreleasepool; + return OnInit(); +} + bool wxApp::OnInitGui() { if ( !wxAppBase::OnInitGui() ) return false ; + + if ( !DoInitGui() ) + return false; + + return true ; +} + +bool wxApp::ProcessIdle() +{ + wxMacAutoreleasePool autoreleasepool; + return wxAppBase::ProcessIdle(); +} + #if wxOSX_USE_CARBON +bool wxApp::DoInitGui() +{ InstallStandardEventHandler( GetApplicationEventTarget() ) ; if (!sm_isEmbedded) { @@ -865,9 +874,7 @@ bool wxApp::OnInitGui() GetwxMacAppEventHandlerUPP(), GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); } -#endif -#if wxOSX_USE_COCOA_OR_CARBON if (!sm_isEmbedded) { sODocHandler = NewAEEventHandlerUPP(AEHandleODoc) ; @@ -890,32 +897,15 @@ bool wxApp::OnInitGui() AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , sQuitHandler , 0 , FALSE ) ; } -#endif -#if wxOSX_USE_CARBON + if ( !wxMacInitCocoa() ) return false; -#endif - - return true ; + + return true; } -void wxApp::CleanUp() +void wxApp::DoCleanUp() { -#if wxUSE_TOOLTIPS - wxToolTip::RemoveToolTips() ; -#endif - - if (m_macEventPosted) - { - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); - m_macEventPosted = NULL; - } - - // One last chance for pending objects to be cleaned up - wxTheApp->DeletePendingObjects(); - -#if wxOSX_USE_COCOA_OR_CARBON - if (!sm_isEmbedded) RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) ); @@ -941,9 +931,24 @@ void wxApp::CleanUp() DisposeAEEventHandlerUPP( sRAppHandler ) ; DisposeAEEventHandlerUPP( sQuitHandler ) ; } +} #endif +void wxApp::CleanUp() +{ +#if wxUSE_TOOLTIPS + wxToolTip::RemoveToolTips() ; +#endif + + if (m_macEventPosted) + { + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); + m_macEventPosted = NULL; + } + + DoCleanUp(); + wxAppBase::CleanUp(); } @@ -1052,15 +1057,31 @@ wxApp::wxApp() m_macEventPosted = NULL ; } +CFMutableArrayRef GetAutoReleaseArray() +{ + static CFMutableArrayRef array = 0; + if ( array == 0) + array= CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks); + return array; +} + +void wxApp::MacAddToAutorelease( void* cfrefobj ) +{ + CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj ); +} + void wxApp::OnIdle(wxIdleEvent& WXUNUSED(event)) { // If they are pending events, we must process them: pending events are // either events to the threads other than main or events posted with // wxPostEvent() functions #ifndef __WXUNIVERSAL__ +#if wxUSE_MENU if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); #endif +#endif + CFArrayRemoveAllValues( GetAutoReleaseArray() ); } void wxApp::WakeUpIdle() @@ -1100,16 +1121,6 @@ void wxCYield() bool wxApp::Yield(bool onlyIfNeeded) { - if (s_inYield) - { - if ( !onlyIfNeeded ) - { - wxFAIL_MSG( wxT("wxYield called recursively" ) ); - } - - return false; - } - #if wxUSE_THREADS // Yielding from a non-gui thread needs to bail out, otherwise we end up // possibly sending events in the thread too. @@ -1119,138 +1130,55 @@ bool wxApp::Yield(bool onlyIfNeeded) } #endif // wxUSE_THREADS - s_inYield = true; + static bool s_inYield = false; - // by definition yield should handle all non-processed events + if (s_inYield) + { + if ( !onlyIfNeeded ) + { + wxFAIL_MSG( wxT("wxYield called recursively" ) ); + } -#if wxOSX_USE_COCOA_OR_CARBON + return false; + } - EventRef theEvent; + s_inYield = true; - OSStatus status = noErr ; +#if wxUSE_LOG + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); +#endif // wxUSE_LOG - while ( status == noErr ) + wxEventLoop * const + loop = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive()); + if ( loop ) { - s_inReceiveEvent = true ; - status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; - s_inReceiveEvent = false ; - - if ( status == eventLoopTimedOutErr ) - { - // make sure next time the event loop will trigger idle events - sleepTime = kEventDurationNoWait ; - } - else if ( status == eventLoopQuitErr ) - { - // according to QA1061 this may also occur when a WakeUp Process - // is executed - } - else - { - MacHandleOneEvent( theEvent ) ; - ReleaseEvent(theEvent); - } + // process all pending events: + while ( loop->Pending() ) + loop->Dispatch(); } -#else - -#endif - + // it's necessary to call ProcessIdle() to update the frames sizes which + // might have been changed (it also will update other things set from + // OnUpdateUI() which is a nice (and desired) side effect) + while ( ProcessIdle() ) {} + +#if wxUSE_LOG + wxLog::Resume(); +#endif // wxUSE_LOG s_inYield = false; return true; } -void wxApp::MacDoOneEvent() -{ -#if wxOSX_USE_COCOA_OR_CARBON - wxMacAutoreleasePool autoreleasepool; - EventRef theEvent; - - s_inReceiveEvent = true ; - OSStatus status = ReceiveNextEvent(0, NULL, sleepTime, true, &theEvent) ; - s_inReceiveEvent = false ; - - switch (status) - { - case eventLoopTimedOutErr : - if ( wxTheApp->ProcessIdle() ) - sleepTime = kEventDurationNoWait ; - else - { - sleepTime = kEventDurationSecond; -#if wxUSE_THREADS - wxMutexGuiLeave(); - wxMilliSleep(20); - wxMutexGuiEnter(); -#endif - } - break; - - case eventLoopQuitErr : - // according to QA1061 this may also occur - // when a WakeUp Process is executed - break; - - default: - MacHandleOneEvent( theEvent ) ; - ReleaseEvent( theEvent ); - sleepTime = kEventDurationNoWait ; - break; - } - // repeaters -#else -#endif - DeletePendingObjects() ; -} - // virtual void wxApp::MacHandleUnhandledEvent( WXEVENTREF WXUNUSED(evr) ) { // Override to process unhandled events as you please } -CFMutableArrayRef GetAutoReleaseArray() -{ - static CFMutableArrayRef array = 0; - if ( array == 0) - array= CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks); - return array; -} - -// -// -// - - -// -// -// - -void wxApp::MacHandleOneEvent( WXEVENTREF evr ) -{ -#if wxOSX_USE_COCOA_OR_CARBON - EventTargetRef theTarget; - theTarget = GetEventDispatcherTarget(); - m_macCurrentEvent = evr ; - - OSStatus status = SendEventToEventTarget((EventRef) evr , theTarget); - if (status == eventNotHandledErr) - MacHandleUnhandledEvent(evr); -#else - // TODO Threads -#endif - - - CFArrayRemoveAllValues( GetAutoReleaseArray() ); -} - -void wxApp::MacAddToAutorelease( void* cfrefobj ) -{ - CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj ); -} - -#if wxOSX_USE_COCOA_OR_CARBON +#if wxOSX_USE_CARBON long wxMacTranslateKey(unsigned char key, unsigned char code) { @@ -1422,12 +1350,12 @@ int wxMacKeyCodeToModifier(wxKeyCode key) wxMouseState wxGetMouseState() { wxMouseState ms; -#if wxOSX_USE_COCOA_OR_CARBON wxPoint pt = wxGetMousePosition(); ms.SetX(pt.x); ms.SetY(pt.y); +#if wxOSX_USE_CARBON UInt32 buttons = GetCurrentButtonState(); ms.SetLeftDown( (buttons & 0x01) != 0 ); ms.SetMiddleDown( (buttons & 0x04) != 0 ); @@ -1438,7 +1366,8 @@ wxMouseState wxGetMouseState() ms.SetShiftDown(modifiers & shiftKey); ms.SetAltDown(modifiers & optionKey); ms.SetMetaDown(modifiers & cmdKey); - +#else + // TODO #endif return ms; } @@ -1598,7 +1527,7 @@ bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers // This method handles common code for SendKeyDown, SendKeyUp, and SendChar events. void wxApp::MacCreateKeyEvent( wxKeyEvent& event, wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) { -#if wxOSX_USE_COCOA_OR_CARBON +#if wxOSX_USE_CARBON short keycode, keychar ; keychar = short(keymessage & charCodeMask); diff --git a/src/osx/carbon/bmpbuttn.cpp b/src/osx/carbon/bmpbuttn.cpp index 4421c143d7..2b5eddec7c 100644 --- a/src/osx/carbon/bmpbuttn.cpp +++ b/src/osx/carbon/bmpbuttn.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/bmpbuttn.cpp +// Name: src/osx/carbon/bmpbuttn.cpp // Purpose: wxBitmapButton // Author: Stefan Csomor // Modified by: @@ -20,9 +20,7 @@ #include "wx/dcmemory.h" #endif -IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) - -#include "wx/osx/uma.h" +#include "wx/osx/private.h" //--------------------------------------------------------------------------- // Helper functions @@ -79,111 +77,88 @@ static wxBitmap wxMakeStdSizeBitmap(const wxBitmap& bitmap) //--------------------------------------------------------------------------- -bool wxBitmapButton::Create( wxWindow *parent, - wxWindowID id, const wxBitmap& bitmap, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name ) +class wxMacBitmapButton : public wxMacControl { - m_macIsUserPane = false; - - // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create - // essentially creates an additional button - if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) - return false; - - if ( style & wxBU_AUTODRAW ) +public: + wxMacBitmapButton( wxWindowMac* peer ) : wxMacControl(peer) { - m_marginX = - m_marginY = wxDEFAULT_BUTTON_MARGIN; } - else + + void SetBitmap(const wxBitmap& bitmap) { - m_marginX = - m_marginY = 0; - } + wxBitmap bmp; + if ( GetWXPeer()->HasFlag( wxBORDER_NONE ) ) + { + bmp = wxMakeStdSizeBitmap(bitmap); + // TODO set bitmap in peer as well + } + else + bmp = bitmap; + + ControlButtonContentInfo info; + if ( GetWXPeer()->HasFlag( wxBORDER_NONE ) ) + { + wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef ); + if ( info.contentType != kControlNoContent ) + SetData( kControlIconPart, kControlIconContentTag, info ); + } + else + { + wxMacCreateBitmapButton( &info, bmp ); + if ( info.contentType != kControlNoContent ) + SetData( kControlButtonPart, kControlBevelButtonContentTag, info ); + } + + wxMacReleaseBitmapButton( &info ); + } +}; + +wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxBitmap& bitmap, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ OSStatus err = noErr; ControlButtonContentInfo info; - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - m_peer = new wxMacControl( this ); + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); + wxMacControl* peer = new wxMacBitmapButton( wxpeer ); + wxBitmap bmp; - if ( bitmap.Ok() && HasFlag(wxBORDER_NONE) ) - m_bmpNormal = wxMakeStdSizeBitmap(bitmap); + if ( bitmap.Ok() && (style & wxBORDER_NONE) ) + { + bmp = wxMakeStdSizeBitmap(bitmap); + // TODO set bitmap in peer as well + } else - m_bmpNormal = bitmap; + bmp = bitmap; - if ( HasFlag( wxBORDER_NONE ) ) + if ( style & wxBORDER_NONE ) { // contrary to the docs this control only works with iconrefs - wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef ); + wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef ); err = CreateIconControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), - &bounds, &info, false, m_peer->GetControlRefAddr() ); + &bounds, &info, false, peer->GetControlRefAddr() ); } else { - wxMacCreateBitmapButton( &info, m_bmpNormal ); + wxMacCreateBitmapButton( &info, bmp ); err = CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""), ((style & wxBU_AUTODRAW) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ), - kControlBehaviorOffsetContents, &info, 0, 0, 0, m_peer->GetControlRefAddr() ); + kControlBehaviorOffsetContents, &info, 0, 0, 0, peer->GetControlRefAddr() ); } verify_noerr( err ); wxMacReleaseBitmapButton( &info ); - wxASSERT_MSG( m_peer != NULL && m_peer->IsOk(), wxT("No valid native Mac control") ); - - MacPostControlCreate( pos, size ); - - return true; + return peer; } - -void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) -{ - if ( HasFlag( wxBORDER_NONE ) ) - m_bmpNormal = wxMakeStdSizeBitmap(bitmap); - else - m_bmpNormal = bitmap; - - InvalidateBestSize(); - - ControlButtonContentInfo info; - - if ( HasFlag( wxBORDER_NONE ) ) - { - wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef ); - if ( info.contentType != kControlNoContent ) - m_peer->SetData( kControlIconPart, kControlIconContentTag, info ); - } - else - { - wxMacCreateBitmapButton( &info, m_bmpNormal ); - if ( info.contentType != kControlNoContent ) - m_peer->SetData( kControlButtonPart, kControlBevelButtonContentTag, info ); - } - - wxMacReleaseBitmapButton( &info ); -} - -wxSize wxBitmapButton::DoGetBestSize() const -{ - wxSize best; - - best.x = 2 * m_marginX; - best.y = 2 * m_marginY; - if ( m_bmpNormal.Ok() ) - { - best.x += m_bmpNormal.GetWidth(); - best.y += m_bmpNormal.GetHeight(); - } - - return best; -} - #endif diff --git a/src/osx/carbon/button.cpp b/src/osx/carbon/button.cpp index 9974fc5aa4..955a27382f 100644 --- a/src/osx/carbon/button.cpp +++ b/src/osx/carbon/button.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/button.cpp +// Name: src/osx/carbon/button.cpp // Purpose: wxButton // Author: Stefan Csomor // Modified by: @@ -21,98 +21,11 @@ #include "wx/stockitem.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) - - -bool wxButton::Create(wxWindow *parent, - wxWindowID id, - const wxString& lbl, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxString label(lbl); - if (label.empty() && wxIsStockID(id)) - label = wxGetStockLabel(id); - - m_macIsUserPane = false ; - - if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) ) - return false; - - m_labelOrig = m_label = label ; - - OSStatus err; - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_peer = new wxMacControl(this) ; - if ( id == wxID_HELP ) - { - ControlButtonContentInfo info ; - info.contentType = kControlContentIconRef ; - GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef); - err = CreateRoundButtonControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), - &bounds, kControlRoundButtonNormalSize, - &info, m_peer->GetControlRefAddr() ); - } - else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND) - { - // Button height is static in Mac, can't be changed, so we need to force it here - if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE ) - { - bounds.bottom = bounds.top + 20 ; - m_maxHeight = 20 ; - } - else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL ) - { - bounds.bottom = bounds.top + 17 ; - m_maxHeight = 17 ; - } - else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) - { - bounds.bottom = bounds.top + 15 ; - m_maxHeight = 15 ; - } - err = CreatePushButtonControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), - &bounds, CFSTR(""), m_peer->GetControlRefAddr() ); - } - else - { - ControlButtonContentInfo info ; - info.contentType = kControlNoContent ; - err = CreateBevelButtonControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""), - kControlBevelButtonLargeBevel, kControlBehaviorPushbutton, - &info, 0, 0, 0, m_peer->GetControlRefAddr() ); - } - - verify_noerr( err ); - wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid Mac control") ) ; - - MacPostControlCreate( pos, size ); - - return true; -} - -wxWindow *wxButton::SetDefault() -{ - wxWindow *btnOldDefault = wxButtonBase::SetDefault(); - - if ( btnOldDefault ) - { - // cast needed to access the protected member - btnOldDefault->GetPeer()->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ; - } - - m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ; - - return btnOldDefault; -} +// +// +// wxSize wxButton::DoGetBestSize() const { @@ -140,6 +53,7 @@ wxSize wxButton::DoGetBestSize() const break; } +#if wxOSX_USE_CARBON Rect bestsize = { 0 , 0 , 0 , 0 } ; m_peer->GetBestRect( &bestsize ) ; @@ -181,9 +95,9 @@ wxSize wxButton::DoGetBestSize() const // non 'normal' window variants don't return the correct height // sz.y = bestsize.bottom - bestsize.top ; } - if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT)) sz.x = wBtn; +#endif return sz ; } @@ -196,35 +110,80 @@ wxSize wxButton::GetDefaultSize() return wxSize(wBtn, hBtn); } -void wxButton::Command (wxCommandEvent & event) +wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_peer->Flash(kControlButtonPart) ; - ProcessCommand(event); + OSStatus err; + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; + if ( id == wxID_HELP ) + { + ControlButtonContentInfo info ; + info.contentType = kControlContentIconRef ; + GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef); + err = CreateRoundButtonControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()), + &bounds, kControlRoundButtonNormalSize, + &info, peer->GetControlRefAddr() ); + } + else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND) + { + // Button height is static in Mac, can't be changed, so we need to force it here + int maxHeight; + switch (wxpeer->GetWindowVariant() ) + { + case wxWINDOW_VARIANT_NORMAL: + case wxWINDOW_VARIANT_LARGE: + maxHeight = 20 ; + break; + case wxWINDOW_VARIANT_SMALL: + maxHeight = 17; + case wxWINDOW_VARIANT_MINI: + maxHeight = 15; + default: + break; + } + bounds.bottom = bounds.top + maxHeight ; + wxpeer->SetMaxSize( wxSize( wxpeer->GetMaxWidth() , maxHeight )); + err = CreatePushButtonControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()), + &bounds, CFSTR(""), peer->GetControlRefAddr() ); + } + else + { + ControlButtonContentInfo info ; + info.contentType = kControlNoContent ; + err = CreateBevelButtonControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""), + kControlBevelButtonLargeBevel, kControlBehaviorPushbutton, + &info, 0, 0, 0, peer->GetControlRefAddr() ); + } + verify_noerr( err ); + return peer; } -wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId); - event.SetEventObject(this); - ProcessCommand(event); - - return noErr; +void wxMacControl::SetDefaultButton( bool isDefault ) +{ + SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ; } -//------------------------------------------------------- -// wxDisclosureTriangle -//------------------------------------------------------- - -bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxString& label, - const wxPoint& pos, const wxSize& size, long style,const wxValidator& validator, const wxString& name ) +wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_macIsUserPane = false ; - - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_peer = new wxMacControl(this) ; + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; OSStatus err = CreateDisclosureTriangleControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, @@ -233,41 +192,10 @@ bool wxDisclosureTriangle::Create(wxWindow *parent, wxWindowID id, const wxStrin 0, // closed TRUE, // draw title TRUE, // auto toggle back and forth - m_peer->GetControlRefAddr() ); + peer->GetControlRefAddr() ); verify_noerr( err ); - wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid Mac control") ) ; - - MacPostControlCreate( pos, size ); - // passing the text in the param doesn't seem to work, so lets do if again - SetLabel( label ); - - return true; -} - -void wxDisclosureTriangle::SetOpen( bool open ) -{ - m_peer->SetValue( open ? 1 : 0 ); -} - -bool wxDisclosureTriangle::IsOpen() const -{ - return m_peer->GetValue() == 1; -} - -wxInt32 wxDisclosureTriangle::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - // Just emit button event for now - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId); - event.SetEventObject(this); - ProcessCommand(event); - - return noErr; -} - -wxSize wxDisclosureTriangle::DoGetBestSize() const -{ - return wxSize(16,16); + return peer; } - + diff --git a/src/osx/carbon/checkbox.cpp b/src/osx/carbon/checkbox.cpp index ccb5ab2afb..f31d0413fc 100644 --- a/src/osx/carbon/checkbox.cpp +++ b/src/osx/carbon/checkbox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/checkbox.cpp +// Name: src/osx/carbon/checkbox.cpp // Purpose: wxCheckBox // Author: Stefan Csomor // Modified by: @@ -16,171 +16,27 @@ #include "wx/checkbox.h" #include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) - - -// Single check box item -bool wxCheckBox::Create(wxWindow *parent, - wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) +wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_macIsUserPane = false ; - - if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) - return false; - - m_labelOrig = m_label = label ; + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; + verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , + CFSTR("") , 0 , false , peer->GetControlRefAddr() ) ); SInt32 maxValue = 1 /* kControlCheckboxCheckedValue */; if (style & wxCHK_3STATE) maxValue = 2 /* kControlCheckboxMixedValue */; - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_peer = new wxMacControl( this ) ; - verify_noerr( CreateCheckBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , - CFSTR("") , 0 , false , m_peer->GetControlRefAddr() ) ); - - m_peer->SetMaximum( maxValue ) ; - - MacPostControlCreate(pos, size) ; - - return true; -} - -void wxCheckBox::SetValue(bool val) -{ - if (val) - Set3StateValue(wxCHK_CHECKED); - else - Set3StateValue(wxCHK_UNCHECKED); -} - -bool wxCheckBox::GetValue() const -{ - return (DoGet3StateValue() != 0); -} - -void wxCheckBox::Command(wxCommandEvent & event) -{ - int state = event.GetInt(); - - wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED) - || (state == wxCHK_UNDETERMINED), - wxT("event.GetInt() returned an invalid checkbox state") ); - - Set3StateValue((wxCheckBoxState)state); - - ProcessCommand(event); -} - -wxCheckBoxState wxCheckBox::DoGet3StateValue() const -{ - return (wxCheckBoxState)m_peer->GetValue() ; -} - -void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) -{ - m_peer->SetValue( val ) ; -} - -wxInt32 wxCheckBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCheckBoxState origState, newState; - - newState = origState = Get3StateValue(); - - switch (origState) - { - case wxCHK_UNCHECKED: - newState = wxCHK_CHECKED; - break; - - case wxCHK_CHECKED: - // If the style flag to allow the user setting the undetermined state is set, - // then set the state to undetermined; otherwise set state to unchecked. - newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED; - break; - - case wxCHK_UNDETERMINED: - newState = wxCHK_UNCHECKED; - break; - - default: - break; - } - - if (newState != origState) - { - Set3StateValue( newState ); - - wxCommandEvent event( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); - event.SetInt( newState ); - event.SetEventObject( this ); - ProcessCommand( event ); - } - - return noErr; -} - -// Bitmap checkbox -bool wxBitmapCheckBox::Create(wxWindow *parent, - wxWindowID id, - const wxBitmap *WXUNUSED(label), - const wxPoint& WXUNUSED(pos), - const wxSize& WXUNUSED(size), - long style, - const wxValidator& wxVALIDATOR_PARAM(validator), - const wxString& name) -{ - SetName(name); -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif - m_windowStyle = style; - - if (parent) - parent->AddChild(this); - - if ( id == -1 ) - m_windowId = NewControlId(); - else - m_windowId = id; - - // TODO: Create the bitmap checkbox - - return false; -} - -void wxBitmapCheckBox::SetLabel(const wxBitmap *WXUNUSED(bitmap)) -{ - // TODO - wxFAIL_MSG(wxT("wxBitmapCheckBox::SetLabel() not yet implemented")); -} - -void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxControl::SetSize( x , y , width , height , sizeFlags ) ; -} - -void wxBitmapCheckBox::SetValue(bool WXUNUSED(val)) -{ - // TODO - wxFAIL_MSG(wxT("wxBitmapCheckBox::SetValue() not yet implemented")); -} - -bool wxBitmapCheckBox::GetValue() const -{ - // TODO - wxFAIL_MSG(wxT("wxBitmapCheckBox::GetValue() not yet implemented")); + peer->SetMaximum( maxValue ) ; - return false; + return peer; } #endif diff --git a/src/osx/carbon/checklst.cpp b/src/osx/carbon/checklst.cpp deleted file mode 100644 index 218600348f..0000000000 --- a/src/osx/carbon/checklst.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/checklst.cpp -// Purpose: implementation of wxCheckListBox class -// Author: Stefan Csomor -// Modified by: -// Created: 1998-01-01 -// RCS-ID: $Id$ -// Copyright: (c) Stefan Csomor -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// -// -// new DataBrowser-based version - - -#include "wx/wxprec.h" - -#if wxUSE_CHECKLISTBOX - -#include "wx/checklst.h" - -#ifndef WX_PRECOMP - #include "wx/arrstr.h" -#endif - -#include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) - -BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox) -END_EVENT_TABLE() - -class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl -{ -public: - wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style ); - wxMacDataBrowserCheckListControl() {} - virtual ~wxMacDataBrowserCheckListControl(); - - virtual wxMacDataItem* CreateItem(); - - virtual bool MacIsChecked(unsigned int n) const; - virtual void MacCheck(unsigned int n, bool bCheck = true); - DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserCheckListControl) -}; - -IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl , wxMacDataBrowserListControl ) - -void wxCheckListBox::Init() -{ -} - -bool wxCheckListBox::Create( - wxWindow *parent, - wxWindowID id, - const wxPoint &pos, - const wxSize &size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString &name ) -{ - wxCArrayString chs( choices ); - - return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name ); -} - -bool wxCheckListBox::Create( - wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - int n, - const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name ) -{ - m_macIsUserPane = false; - - wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), - wxT("only one of listbox selection modes can be specified") ); - - if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) - return false; - - // this will be increased by our Append command - wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style ); - // TODO CHECK control->SetClientDataType( m_clientDataItemsType ); - m_peer = control; - - MacPostControlCreate(pos,size); - - InsertItems( n , choices , 0 ); - - // Needed because it is a wxControlWithItems - SetInitialSize( size ); - - return true; -} - -// ---------------------------------------------------------------------------- -// wxCheckListBox functions -// ---------------------------------------------------------------------------- - -bool wxCheckListBox::IsChecked(unsigned int item) const -{ - wxCHECK_MSG( IsValid(item), false, - wxT("invalid index in wxCheckListBox::IsChecked") ); - - return GetPeer()->MacIsChecked( item ); -} - -void wxCheckListBox::Check(unsigned int item, bool check) -{ - wxCHECK_RET( IsValid(item), - wxT("invalid index in wxCheckListBox::Check") ); - - bool isChecked = GetPeer()->MacIsChecked( item ); - if ( check != isChecked ) - { - GetPeer()->MacCheck( item , check ); - } -} - -wxMacCheckListControl* wxCheckListBox::GetPeer() const -{ - wxMacDataBrowserCheckListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserCheckListControl); - return lb ? wx_static_cast(wxMacCheckListControl*,lb) : 0 ; -} - -const short kCheckboxColumnId = 1026; - -wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style) - : wxMacDataBrowserListControl( peer, pos, size, style ) -{ - OSStatus err = noErr; - - DataBrowserListViewColumnDesc columnDesc; - columnDesc.headerBtnDesc.titleOffset = 0; - columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; - - columnDesc.headerBtnDesc.btnFontStyle.flags = - kControlUseFontMask | kControlUseJustMask; - - columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; - columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; - columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; - columnDesc.headerBtnDesc.btnFontStyle.style = normal; - columnDesc.headerBtnDesc.titleString = NULL; - - columnDesc.headerBtnDesc.minimumWidth = 30; - columnDesc.headerBtnDesc.maximumWidth = 30; - - columnDesc.propertyDesc.propertyID = kCheckboxColumnId; - columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType; - columnDesc.propertyDesc.propertyFlags = - kDataBrowserPropertyIsMutable - | kDataBrowserTableViewSelectionColumn - | kDataBrowserDefaultPropertyFlags; - - err = AddColumn( &columnDesc, 0 ); - verify_noerr( err ); -} - -wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl() -{ - -} - -class wxMacCheckListBoxItem : public wxMacListBoxItem -{ -public : - wxMacCheckListBoxItem() - { - m_isChecked = false; - } - - virtual ~wxMacCheckListBoxItem() - { - } - - virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner , - DataBrowserPropertyID property, - DataBrowserItemDataRef itemData, - bool changeValue ) - { - OSStatus err = errDataBrowserPropertyNotSupported; - - wxCheckListBox *checklist = wxDynamicCast( owner->GetWXPeer() , wxCheckListBox ); - wxCHECK_MSG( checklist != NULL , errDataBrowserPropertyNotSupported , wxT("wxCheckListBox expected")); - - if ( !changeValue ) - { - switch (property) - { - case kCheckboxColumnId: - verify_noerr(SetDataBrowserItemDataButtonValue( itemData, m_isChecked ? kThemeButtonOn : kThemeButtonOff )); - err = noErr; - break; - - case kDataBrowserItemIsEditableProperty: - verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true )); - err = noErr; - break; - - default: - break; - } - } - else - { - switch (property) - { - case kCheckboxColumnId: - { - // we have to change this behind the back, since Check() would be triggering another update round - bool newVal = !m_isChecked; - verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff )); - m_isChecked = newVal; - err = noErr; - - wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() ); - event.SetInt( owner->GetLineFromItem( this ) ); - event.SetEventObject( checklist ); - checklist->HandleWindowEvent( event ); - } - break; - - default: - break; - } - } - - if ( err == errDataBrowserPropertyNotSupported ) - err = wxMacListBoxItem::GetSetData( owner , property, itemData , changeValue); - - return err; - } - - void Check( bool check ) - { - m_isChecked = check; - } - bool IsChecked() const - { - return m_isChecked; - } - -protected : - bool m_isChecked; -}; - -wxMacDataItem* wxMacDataBrowserCheckListControl::CreateItem() -{ - return new wxMacCheckListBoxItem(); -} - -void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck) -{ - wxMacCheckListBoxItem* item = wx_static_cast(wxMacCheckListBoxItem*, GetItemFromLine( n) ); - item->Check( bCheck); - UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId); -} - -bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const -{ - wxMacCheckListBoxItem * item = wx_static_cast( wxMacCheckListBoxItem*, GetItemFromLine( n ) ); - return item->IsChecked(); -} - - - -#endif // wxUSE_CHECKLISTBOX diff --git a/src/osx/carbon/choice.cpp b/src/osx/carbon/choice.cpp index c0bd7f8abe..00eb309d38 100644 --- a/src/osx/carbon/choice.cpp +++ b/src/osx/carbon/choice.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/choice.cpp +// Name: src/osx/carbon/choice.cpp // Purpose: wxChoice // Author: Stefan Csomor // Modified by: @@ -20,289 +20,47 @@ #include "wx/dcclient.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" -extern MenuHandle NewUniqueMenu() ; +// adapt the number offset (mac menu are 1 based) -IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControlWithItems) - - -wxChoice::~wxChoice() +class wxMacChoiceCarbonControl : public wxMacControl { - if ( HasClientObjectData() ) +public : + wxMacChoiceCarbonControl( wxWindowMac* peer ) : wxMacControl( peer ) { - unsigned int i, max = GetCount(); - - for ( i = 0; i < max; ++i ) - delete GetClientObject( i ); } - - // DeleteMenu( m_macPopUpMenuId ) ; - // DisposeMenu( m_macPopUpMenuHandle ) ; -} - -bool wxChoice::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString& name ) -{ - if ( !Create( parent, id, pos, size, 0, NULL, style, validator, name ) ) - return false; - - Append( choices ); - - if ( !choices.empty() ) - SetSelection( 0 ); - - SetInitialSize( size ); - - return true; -} - -bool wxChoice::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - int n, - const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name ) -{ - m_macIsUserPane = false; - - if ( !wxChoiceBase::Create( parent, id, pos, size, style, validator, name ) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ); - - m_peer = new wxMacControl( this ) ; - OSStatus err = CreatePopupButtonControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , - -12345 , false /* no variable width */ , 0 , 0 , 0 , m_peer->GetControlRefAddr() ); - verify_noerr( err ); - - m_macPopUpMenuHandle = NewUniqueMenu() ; - m_peer->SetData( kControlNoPart , kControlPopupButtonMenuHandleTag , (MenuHandle) m_macPopUpMenuHandle ) ; - m_peer->SetValueAndRange( n > 0 ? 1 : 0 , 0 , 0 ); - MacPostControlCreate( pos, size ); - -#if !wxUSE_STL - if ( style & wxCB_SORT ) - // autosort - m_strings = wxArrayString( 1 ); -#endif - - Append(n, choices); - - // Set the first item as being selected - if (n > 0) - SetSelection( 0 ); - - // Needed because it is a wxControlWithItems - SetInitialSize( size ); - - return true; -} - -// ---------------------------------------------------------------------------- -// adding/deleting items to/from the list -// ---------------------------------------------------------------------------- - -int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, - unsigned int pos, - void **clientData, wxClientDataType type) -{ - const unsigned int numItems = items.GetCount(); - for( unsigned int i = 0; i < numItems; ++i, ++pos ) + + void SetValue(wxInt32 v) { - unsigned int idx; - -#if wxUSE_STL - if ( IsSorted() ) - { - wxArrayString::iterator - insertPoint = std::lower_bound( m_strings.begin(), m_strings.end(), items[i] ); - idx = insertPoint - m_strings.begin(); - m_strings.insert( insertPoint, items[i] ); - } - else -#endif // wxUSE_STL - { - idx = pos; - m_strings.Insert( items[i], idx ); - } - - UMAInsertMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ), - items[i], - GetFont().GetEncoding(), - idx); - m_datas.Insert( NULL, idx ); - AssignNewItemClientData(idx, clientData, i, type); + wxMacControl::SetValue( v + 1 ); } - - m_peer->SetMaximum( GetCount() ); - - return pos - 1; -} - -void wxChoice::DoDeleteOneItem(unsigned int n) -{ - wxCHECK_RET( IsValid(n) , wxT("wxChoice::Delete: invalid index") ); - - if ( HasClientObjectData() ) - delete GetClientObject( n ); - - ::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1 ) ; - m_strings.RemoveAt( n ) ; - m_datas.RemoveAt( n ) ; - m_peer->SetMaximum( GetCount() ) ; -} - -void wxChoice::DoClear() -{ - for ( unsigned int i = 0 ; i < GetCount() ; i++ ) + + wxInt32 GetValue() { - ::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , 1 ) ; + return wxMacControl::GetValue() - 1; } + }; - m_strings.Empty() ; - m_datas.Empty() ; - m_peer->SetMaximum( 0 ) ; -} - -// ---------------------------------------------------------------------------- -// selection -// ---------------------------------------------------------------------------- -int wxChoice::GetSelection() const -{ - return m_peer->GetValue() - 1 ; -} - -void wxChoice::SetSelection( int n ) +wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxMenu* menu, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStylew) { - m_peer->SetValue( n + 1 ) ; -} - -// ---------------------------------------------------------------------------- -// string list functions -// ---------------------------------------------------------------------------- + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ); -unsigned int wxChoice::GetCount() const -{ - return m_strings.GetCount() ; -} - -int wxChoice::FindString( const wxString& s, bool bCase ) const -{ -#if !wxUSE_STL - // Avoid assert for non-default args passed to sorted array Index - if ( IsSorted() ) - bCase = true; -#endif - - return m_strings.Index( s , bCase ) ; -} - -void wxChoice::SetString(unsigned int n, const wxString& s) -{ - wxCHECK_RET( IsValid(n), wxT("wxChoice::SetString(): invalid index") ); - - m_strings[n] = s ; - - // apple menu pos is 1-based - UMASetMenuItemText( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1 , s , wxFont::GetDefaultEncoding() ) ; -} - -wxString wxChoice::GetString(unsigned int n) const -{ - wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("wxChoice::GetString(): invalid index") ); - - return m_strings[n] ; -} - -// ---------------------------------------------------------------------------- -// client data -// ---------------------------------------------------------------------------- -void wxChoice::DoSetItemClientData(unsigned int n, void* clientData) -{ - wxCHECK_RET( IsValid(n), wxT("wxChoice::DoSetItemClientData: invalid index") ); - - m_datas[n] = (char*)clientData ; -} - -void * wxChoice::DoGetItemClientData(unsigned int n) const -{ - wxCHECK_MSG( IsValid(n), NULL, wxT("wxChoice::DoGetClientData: invalid index") ); - - return (void *)m_datas[n]; -} - -wxInt32 wxChoice::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event( wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); - - // actually n should be made sure by the os to be a valid selection, but ... - int n = GetSelection(); - if ( n > -1 ) - { - event.SetInt( n ); - event.SetString( GetStringSelection() ); - event.SetEventObject( this ); - - if ( HasClientObjectData() ) - event.SetClientObject( GetClientObject( n ) ); - else if ( HasClientUntypedData() ) - event.SetClientData( GetClientData( n ) ); - - ProcessCommand( event ); - } - - return noErr ; -} - -wxSize wxChoice::DoGetBestSize() const -{ - int lbWidth = GetCount() > 0 ? 20 : 100; // some defaults - int lbHeight = 20; - int wLine; - - SInt32 metric ; - - GetThemeMetric( kThemeMetricPopupButtonHeight , &metric ); - lbHeight = metric ; - - { - wxClientDC dc(const_cast(this)); - - // Find the widest line - for(unsigned int i = 0; i < GetCount(); i++) - { - wxString str(GetString(i)); - - wxCoord width, height ; - dc.GetTextExtent( str , &width, &height); - wLine = width ; - - lbWidth = wxMax( lbWidth, wLine ) ; - } - - // Add room for the popup arrow - lbWidth += 2 * lbHeight ; - - wxCoord width, height ; - dc.GetTextExtent( wxT("X"), &width, &height); - int cx = width ; - lbHeight += 4; - - lbWidth += cx ; - } + wxMacControl* peer = new wxMacChoiceCarbonControl( wxpeer ) ; + OSStatus err = CreatePopupButtonControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , + -12345 , false /* no variable width */ , 0 , 0 , 0 , peer->GetControlRefAddr() ); + verify_noerr( err ); - return wxSize( lbWidth, lbHeight ); + peer->SetData( kControlNoPart , kControlPopupButtonMenuHandleTag , (MenuHandle) menu->GetHMenu() ) ; + return peer; } #endif // wxUSE_CHOICE diff --git a/src/osx/carbon/clipbrd.cpp b/src/osx/carbon/clipbrd.cpp index 1fa330c6d3..56ad3acfe9 100644 --- a/src/osx/carbon/clipbrd.cpp +++ b/src/osx/carbon/clipbrd.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/clipbrd.cpp +// Name: src/osx/carbon/clipbrd.cpp // Purpose: Clipboard functionality // Author: Stefan Csomor; // Generalized clipboard implementation by Matthew Flatt diff --git a/src/osx/carbon/colordlgosx.mm b/src/osx/carbon/colordlgosx.mm index 4c6f3a3ad8..d35a0d57bd 100644 --- a/src/osx/carbon/colordlgosx.mm +++ b/src/osx/carbon/colordlgosx.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/colordlg.mm +// Name: src/osx/carbon/colordlg.mm // Purpose: wxColourDialog class. NOTE: you can use the generic class // if you wish, instead of implementing this. // Author: Ryan Norton diff --git a/src/osx/carbon/combobox.cpp b/src/osx/carbon/combobox.cpp index 1174358e29..5bae247235 100644 --- a/src/osx/carbon/combobox.cpp +++ b/src/osx/carbon/combobox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/combobox.cpp +// Name: src/osx/carbon/combobox.cpp // Purpose: wxComboBox class // Author: Stefan Csomor, Dan "Bud" Keith (composite combobox) // Modified by: @@ -23,7 +23,7 @@ #include "wx/textctrl.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) @@ -34,17 +34,6 @@ BEGIN_EVENT_TABLE(wxComboBox, wxControl) END_EVENT_TABLE() -static int nextPopUpMenuId = 1000 ; - -MenuHandle NewUniqueMenu() -{ - MenuHandle handle = UMANewMenu(nextPopUpMenuId, wxString(wxT("Menu")), wxFont::GetDefaultEncoding() ); - nextPopUpMenuId++ ; - - return handle ; -} - - // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -651,7 +640,7 @@ bool wxComboBox::CanRedo() const return false; } -wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +bool wxComboBox::HandleClicked( double timestampsec ) { /* For consistency with other platforms, clicking in the text area does not constitute a selection @@ -662,7 +651,7 @@ wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENT ProcessCommand(event); */ - return noErr ; + return true ; } #endif // wxUSE_COMBOBOX diff --git a/src/osx/carbon/combobxc.cpp b/src/osx/carbon/combobxc.cpp index 8a67fd323f..1f47fd78c8 100644 --- a/src/osx/carbon/combobxc.cpp +++ b/src/osx/carbon/combobxc.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/combobxc.cpp +// Name: src/osx/carbon/combobxc.cpp // Purpose: wxComboBox class using HIView ComboBox // Author: Stefan Csomor // Modified by: @@ -219,14 +219,8 @@ wxComboBox::~wxComboBox() // delete the controls now, don't leave them alive even though they would // still be eventually deleted by our parent - but it will be too late, the // user code expects them to be gone now - if (m_text != NULL) { - delete m_text; - m_text = NULL; - } - if (m_choice != NULL) { - delete m_choice; - m_choice = NULL; - } + wxDELETE( m_text ); + wxDELETE( m_choice ); } @@ -782,12 +776,12 @@ bool wxComboBox::CanRedo() const #endif } -wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +bool wxComboBox::HandleClicked( double timestampsec ) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(GetStringSelection()); ProcessCommand(event); - return noErr; + return true; } diff --git a/src/osx/carbon/control.cpp b/src/osx/carbon/control.cpp index 0389a007de..dca650e0c8 100644 --- a/src/osx/carbon/control.cpp +++ b/src/osx/carbon/control.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/control.cpp +// Name: src/osx/carbon/control.cpp // Purpose: wxControl class // Author: Stefan Csomor // Modified by: @@ -31,7 +31,6 @@ #include "wx/tabctrl.h" #include "wx/spinbutt.h" -#include "wx/osx/uma.h" #include "wx/osx/private.h" IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) @@ -86,6 +85,7 @@ void wxControl::OnKeyDown( wxKeyEvent &WXUNUSED(event) ) if ( m_peer == NULL || !m_peer->IsOk() ) return; +#if wxOSX_USE_CARBON UInt32 keyCode, modifiers; char charCode; @@ -94,4 +94,7 @@ void wxControl::OnKeyDown( wxKeyEvent &WXUNUSED(event) ) GetEventParameter( (EventRef)wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers ); m_peer->HandleKey( keyCode, charCode, modifiers ); +#else + // TODO +#endif } diff --git a/src/osx/carbon/cursor.cpp b/src/osx/carbon/cursor.cpp index b7849bc732..4b39a42024 100644 --- a/src/osx/carbon/cursor.cpp +++ b/src/osx/carbon/cursor.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/cursor.cpp +// Name: src/osx/carbon/cursor.cpp // Purpose: wxCursor class // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/databrow.cpp b/src/osx/carbon/databrow.cpp index b8f5eef04a..89816a01ca 100644 --- a/src/osx/carbon/databrow.cpp +++ b/src/osx/carbon/databrow.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/databrow.cpp +// Name: src/osx/carbon/databrow.cpp // Purpose: Classes and functions for the Carbon data browser // Author: // Modified by: diff --git a/src/osx/carbon/dataobj.cpp b/src/osx/carbon/dataobj.cpp index 0a4cb0f0be..e58a05f0b5 100644 --- a/src/osx/carbon/dataobj.cpp +++ b/src/osx/carbon/dataobj.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dataobj.cpp +// Name: src/osx/carbon/dataobj.cpp // Purpose: implementation of wxDataObject class // Author: Stefan Csomor // Modified by: @@ -27,7 +27,7 @@ #include "wx/metafile.h" #include "wx/tokenzr.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #ifdef __DARWIN__ #include diff --git a/src/osx/carbon/dataview.cpp b/src/osx/carbon/dataview.cpp index 775ef9e4cc..111109c986 100644 --- a/src/osx/carbon/dataview.cpp +++ b/src/osx/carbon/dataview.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/datavgen.cpp +// Name: src/osx/carbon/datavgen.cpp // Purpose: wxDataViewCtrl native mac implementation // Author: // Id: $Id$ diff --git a/src/osx/carbon/dcclient.cpp b/src/osx/carbon/dcclient.cpp index 9264e8b2d8..2a7404bd44 100644 --- a/src/osx/carbon/dcclient.cpp +++ b/src/osx/carbon/dcclient.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dcclient.cpp +// Name: src/osx/carbon/dcclient.cpp // Purpose: wxClientDCImpl class // Author: Stefan Csomor // Modified by: @@ -96,7 +96,6 @@ void wxWindowDCImpl::DoGetSize( int* width, int* height ) const *height = m_height; } -#if wxOSX_USE_CARBON wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const { // wxScreenDC is derived from wxWindowDC, so a screen dc will @@ -104,6 +103,7 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const if (!m_window) return wxNullBitmap; +#if wxOSX_USE_CARBON ControlRef handle = (ControlRef) m_window->GetHandle(); if ( !handle ) return wxNullBitmap; @@ -135,10 +135,11 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const CGContextDrawImage( context, rect, image ); CGContextRestoreGState(context); - return bmp; -} +#else + return wxNullBitmap; #endif +} /* * wxClientDCImpl diff --git a/src/osx/carbon/dcprint.cpp b/src/osx/carbon/dcprint.cpp index 7bec2b5eaf..5163f0d17c 100644 --- a/src/osx/carbon/dcprint.cpp +++ b/src/osx/carbon/dcprint.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dcprint.cpp +// Name: src/osx/carbon/dcprint.cpp // Purpose: wxPrinterDC class // Author: Julian Smart // Modified by: @@ -25,7 +25,7 @@ #include "wx/math.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include "wx/osx/private/print.h" #include "wx/osx/carbon/dcprint.h" #include "wx/graphics.h" diff --git a/src/osx/carbon/dcscreen.cpp b/src/osx/carbon/dcscreen.cpp index 6cd9b891fe..e544aa4ae4 100644 --- a/src/osx/carbon/dcscreen.cpp +++ b/src/osx/carbon/dcscreen.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dcscreen.cpp +// Name: src/osx/carbon/dcscreen.cpp // Purpose: wxScreenDC class // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/dialog.cpp b/src/osx/carbon/dialog.cpp index c97b487fb6..4779594662 100644 --- a/src/osx/carbon/dialog.cpp +++ b/src/osx/carbon/dialog.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dialog.cpp +// Name: src/osx/carbon/dialog.cpp // Purpose: wxDialog class // Author: Stefan Csomor // Modified by: @@ -20,112 +20,10 @@ #include "wx/settings.h" #endif // WX_PRECOMP -#include "wx/osx/uma.h" +#include "wx/osx/private.h" +#include "wx/evtloop.h" - -// Lists to keep track of windows, so we can disable/enable them -// for modal dialogs -wxList wxModalDialogs; - -IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) - -void wxDialog::Init() -{ - m_isModalStyle = false; -} - -bool wxDialog::Create( wxWindow *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) -{ - SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG ); - - // All dialogs should really have this style... - style |= wxTAB_TRAVERSAL; - - // ...but not these styles - style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL - - if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) - return false; - - return true; -} - -void wxDialog::SetModal( bool flag ) -{ - if ( flag ) - { - m_isModalStyle = true; - - SetWindowModality( (WindowRef)GetWXWindow(), kWindowModalityAppModal, NULL ) ; - } - else - { - m_isModalStyle = false; - } -} - -wxDialog::~wxDialog() -{ - m_isBeingDeleted = true; - - // if the dialog is modal, this will end its event loop - Show(false); -} - -// On mac command-stop does the same thing as Esc, let the base class know -// about it -bool wxDialog::IsEscapeKey(const wxKeyEvent& event) -{ - if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) - return true; - - return wxDialogBase::IsEscapeKey(event); -} - -bool wxDialog::IsModal() const -{ - return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast - // return m_isModalStyle; -} - - -bool wxDialog::Show(bool show) -{ - if ( !wxDialogBase::Show(show) ) - // nothing to do - return false; - - if (show && CanDoLayoutAdaptation()) - DoLayoutAdaptation(); - - if ( show ) - // usually will result in TransferDataToWindow() being called - InitDialog(); - - HiliteMenu(0); - - if ( m_isModalStyle ) - { - if ( show ) - { - DoShowModal(); - } - else // end of modal dialog - { - // this will cause IsModalShowing() return false and our local - // message loop will terminate - wxModalDialogs.DeleteObject(this); - } - } - - return true; -} +extern wxList wxModalDialogs; void wxDialog::DoShowModal() { @@ -149,10 +47,16 @@ void wxDialog::DoShowModal() } BeginAppModalStateForWindow(windowRef) ; - while ( IsModal() ) + wxEventLoop * const + loop = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive()); + + + wxASSERT_MSG( loop , wxT("No Event Loop in place") ); + + if ( loop ) { - wxTheApp->MacDoOneEvent() ; - // calls process idle itself + while ( IsModal() ) + loop->Dispatch(); } EndAppModalStateForWindow(windowRef) ; @@ -160,29 +64,4 @@ void wxDialog::DoShowModal() { SetWindowGroupParent( windowGroup , formerParentGroup ); } -} - - -// Replacement for Show(true) for modal dialogs - returns return code -int wxDialog::ShowModal() -{ - if ( !m_isModalStyle ) - SetModal(true); - - if ( IsShown() ) - DoShowModal(); - else - Show(true); - - return GetReturnCode(); -} - -// NB: this function (surprizingly) may be called for both modal and modeless -// dialogs and should work for both of them -void wxDialog::EndModal(int retCode) -{ - SetReturnCode(retCode); - Show(false); - SetModal(false); -} - +} \ No newline at end of file diff --git a/src/osx/carbon/dirdlg.cpp b/src/osx/carbon/dirdlg.cpp index e3f1a95ba6..157e07845d 100644 --- a/src/osx/carbon/dirdlg.cpp +++ b/src/osx/carbon/dirdlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dirdlg.cpp +// Name: src/osx/carbon/dirdlg.cpp // Purpose: wxDirDialog // Author: Stefan Csomor // Modified by: @@ -25,12 +25,6 @@ #include "wx/osx/private.h" -#ifdef __DARWIN__ - #include -#else - #include -#endif - IMPLEMENT_CLASS(wxDirDialog, wxDialog) static pascal void NavEventProc( @@ -64,15 +58,17 @@ static pascal void NavEventProc( wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message, const wxString& defaultPath, - long WXUNUSED(style), + long style, const wxPoint& WXUNUSED(pos), const wxSize& WXUNUSED(size), const wxString& WXUNUSED(name)) { wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; - m_message = message; m_parent = parent; - m_path = defaultPath; + + SetMessage( message ); + SetWindowStyle(style); + SetPath(defaultPath); } int wxDirDialog::ShowModal() diff --git a/src/osx/carbon/dnd.cpp b/src/osx/carbon/dnd.cpp index c6b659df3a..baf0e8885d 100644 --- a/src/osx/carbon/dnd.cpp +++ b/src/osx/carbon/dnd.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dnd.cpp +// Name: src/osx/carbon/dnd.cpp // Purpose: wxDropTarget, wxDropSource implementations // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/evtloop.cpp b/src/osx/carbon/evtloop.cpp index 48fcf2f110..ec51ee972b 100644 --- a/src/osx/carbon/evtloop.cpp +++ b/src/osx/carbon/evtloop.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/evtloop.cpp +// Name: src/osx/carbon/evtloop.cpp // Purpose: implementation of wxEventLoop for wxMac // Author: Vadim Zeitlin // Modified by: @@ -30,47 +30,17 @@ #include "wx/app.h" #endif // WX_PRECOMP -#if wxOSX_USE_CARBON - #include -#else - #include -#endif +#include "wx/osx/private.h" + // ============================================================================ // wxEventLoop implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// high level functions for RunApplicationEventLoop() case -// ---------------------------------------------------------------------------- - - - -#if wxOSX_USE_RUN_APP_EVENT_LOOP - -int wxGUIEventLoop::Run() +wxGUIEventLoop::wxGUIEventLoop() { - wxEventLoopActivator activate(this); - - RunApplicationEventLoop(); - - return m_exitcode; -} - -void wxGUIEventLoop::Exit(int rc) -{ - m_exitcode = rc; - - QuitApplicationEventLoop(); - - OnExit(); + m_sleepTime = kEventDurationNoWait; } -#else // manual event loop - -// ---------------------------------------------------------------------------- -// functions only used by wxEventLoopManual-based implementation -// ---------------------------------------------------------------------------- - void wxGUIEventLoop::WakeUp() { extern void wxMacWakeUp(); @@ -78,15 +48,8 @@ void wxGUIEventLoop::WakeUp() wxMacWakeUp(); } -#endif // high/low-level event loop - -// ---------------------------------------------------------------------------- -// low level functions used in both cases -// ---------------------------------------------------------------------------- - bool wxGUIEventLoop::Pending() const { -#if wxOSX_USE_CARBON EventRef theEvent; return ReceiveNextEvent @@ -97,9 +60,6 @@ bool wxGUIEventLoop::Pending() const false, // don't remove the event from queue &theEvent ) == noErr; -#else - return true; // TODO -#endif } bool wxGUIEventLoop::Dispatch() @@ -107,13 +67,45 @@ bool wxGUIEventLoop::Dispatch() if ( !wxTheApp ) return false; -#if wxOSX_USE_CARBON - // TODO: we probably should do the dispatching directly from here but for - // now it's easier to forward to wxApp which has all the code to do - // it - wxTheApp->MacDoOneEvent(); -#else - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 0); + wxMacAutoreleasePool autoreleasepool; + + EventRef theEvent; + + OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ; + + switch (status) + { + case eventLoopTimedOutErr : + if ( wxTheApp->ProcessIdle() ) + m_sleepTime = kEventDurationNoWait ; + else + { + m_sleepTime = kEventDurationSecond; +#if wxUSE_THREADS + wxMutexGuiLeave(); + wxMilliSleep(20); + wxMutexGuiEnter(); #endif + } + break; + + case eventLoopQuitErr : + // according to QA1061 this may also occur + // when a WakeUp Process is executed + break; + + default: + if ( wxTheApp ) + wxTheApp->MacSetCurrentEvent( theEvent, NULL ); + + OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); + if (status == eventNotHandledErr && wxTheApp) + wxTheApp->MacHandleUnhandledEvent(theEvent); + + ReleaseEvent( theEvent ); + m_sleepTime = kEventDurationNoWait ; + break; + } + return true; } diff --git a/src/osx/carbon/filedlg.cpp b/src/osx/carbon/filedlg.cpp index b42165fde3..9ffded74f3 100644 --- a/src/osx/carbon/filedlg.cpp +++ b/src/osx/carbon/filedlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/filedlg.cpp +// Name: src/osx/carbon/filedlg.cpp // Purpose: wxFileDialog // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index ba91fabee4..c2bf64488a 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/font.cpp +// Name: src/osx/carbon/font.cpp // Purpose: wxFont class // Author: Stefan Csomor // Modified by: @@ -31,10 +31,6 @@ #include "wx/osx/private.h" #endif -#ifndef __DARWIN__ -#include -#endif - #include #include @@ -739,6 +735,7 @@ bool wxFont::MacCreateFromCTFontDescriptor( const void * ctFontDescriptor , int #endif +#if wxOSX_USE_CARBON bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID) { #if wxOSX_USE_CORE_TEXT @@ -762,6 +759,7 @@ bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID) #endif return false; } +#endif wxFont::~wxFont() { diff --git a/src/osx/carbon/fontdlg.cpp b/src/osx/carbon/fontdlg.cpp index bfc19e1386..c61ea57612 100644 --- a/src/osx/carbon/fontdlg.cpp +++ b/src/osx/carbon/fontdlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/fontdlg.cpp +// Name: src/osx/carbon/fontdlg.cpp // Purpose: wxFontDialog class for carbon 10.2+. // Author: Ryan Norton // Modified by: @@ -46,12 +46,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) -#include "wx/osx/uma.h" +#include "wx/osx/private.h" // --------------------------------------------------------------------------- // wxFontDialog // --------------------------------------------------------------------------- +#if wxOSX_USE_CARBON + static const EventTypeSpec eventList[] = { { kEventClassFont, kEventFontSelection } , @@ -191,6 +193,7 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler), } DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacCarbonFontPanelHandler ) +#endif wxFontDialog::wxFontDialog() { @@ -213,6 +216,8 @@ bool wxFontDialog::Create(wxWindow *WXUNUSED(parent), const wxFontData& data) int wxFontDialog::ShowModal() { +#if wxOSX_USE_CARBON + OSStatus err ; wxFont font = *wxNORMAL_FONT ; if ( m_fontData.m_initialFont.Ok() ) @@ -247,10 +252,12 @@ int wxFontDialog::ShowModal() if ( !FPIsFontPanelVisible() ) FPShowHideFontPanel(); - +#endif int retval = RunMixedFontDialog(this); +#if wxOSX_USE_CARBON ::RemoveEventHandler(handler); +#endif return retval ; } diff --git a/src/osx/carbon/fontdlgosx.mm b/src/osx/carbon/fontdlgosx.mm index 7b771bd1e4..93acda991e 100644 --- a/src/osx/carbon/fontdlgosx.mm +++ b/src/osx/carbon/fontdlgosx.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/fontdlgosx.cpp +// Name: src/osx/carbon/fontdlgosx.cpp // Purpose: wxFontDialog class. // Author: Ryan Norton // Modified by: @@ -42,7 +42,7 @@ #import #import -#include "wx/osx/uma.h" +#include "wx/osx/private.h" @interface wxMacFontPanelAccView : NSView { @@ -152,9 +152,11 @@ int RunMixedFontDialog(wxFontDialog* WXUNUSED(dialog)) NSFontPanel* fontPanel = [NSFontPanel sharedFontPanel] ; // adjust modality for carbon environment +#if wxOSX_USE_CARBON WindowRef carbonWindowRef = (WindowRef)[fontPanel windowRef] ; SetWindowModality(carbonWindowRef, kWindowModalityAppModal , 0) ; SetWindowGroup(carbonWindowRef , GetWindowGroupOfClass(kMovableModalWindowClass)); +#endif [fontPanel setFloatingPanel:NO] ; [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:NO] ; @@ -179,8 +181,10 @@ int RunMixedFontDialog(wxFontDialog* WXUNUSED(dialog)) // if we don't reenable it, FPShowHideFontPanel does not work [[fontPanel standardWindowButton:NSWindowCloseButton] setEnabled:YES] ; +#if wxOSX_USE_CARBON if( FPIsFontPanelVisible()) FPShowHideFontPanel() ; +#endif if ( [accessoryView closedWithOk]) { diff --git a/src/osx/carbon/frame.cpp b/src/osx/carbon/frame.cpp index 515da910a2..17df9bcf0d 100644 --- a/src/osx/carbon/frame.cpp +++ b/src/osx/carbon/frame.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/frame.cpp +// Name: src/osx/carbon/frame.cpp // Purpose: wxFrame // Author: Stefan Csomor // Modified by: @@ -24,14 +24,11 @@ #include "wx/menuitem.h" #endif // WX_PRECOMP -#include "wx/osx/uma.h" +#include "wx/osx/private.h" BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) EVT_ACTIVATE(wxFrame::OnActivate) - // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) -// EVT_IDLE(wxFrame::OnIdle) -// EVT_CLOSE(wxFrame::OnCloseWindow) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) @@ -101,6 +98,7 @@ bool wxFrame::Enable(bool enable) if ( !wxWindow::Enable(enable) ) return false; +#if wxUSE_MENUS if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) { int iMaxMenu = m_frameMenuBar->GetMenuCount(); @@ -109,7 +107,7 @@ bool wxFrame::Enable(bool enable) m_frameMenuBar->EnableTop( i , enable ) ; } } - +#endif return true; } @@ -198,6 +196,7 @@ void wxFrame::OnActivate(wxActivateEvent& event) wxSetFocusToChild(parent, &m_winLastFocused); +#if wxUSE_MENUS if (m_frameMenuBar != NULL) { m_frameMenuBar->MacInstallMenuBar(); @@ -212,9 +211,21 @@ void wxFrame::OnActivate(wxActivateEvent& event) tlf->GetMenuBar()->MacInstallMenuBar(); } } +#endif } } +void wxFrame::HandleResized( long timestamp ) +{ + // according to the other ports we handle this within the OS level + // resize event, not within a wxSizeEvent + + PositionBars(); + + wxNonOwnedWindow::HandleResized( timestamp ); +} + +#if wxUSE_MENUS void wxFrame::DetachMenuBar() { if ( m_frameMenuBar ) @@ -225,7 +236,11 @@ void wxFrame::DetachMenuBar() void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) { +#if wxOSX_USE_CARBON wxFrame* tlf = wxDynamicCast( wxNonOwnedWindow::GetFromWXWindow( (WXWindow) FrontNonFloatingWindow() ) , wxFrame ); +#else + wxFrame* tlf = (wxFrame*) wxTheApp->GetTopWindow(); +#endif bool makeCurrent = false; // if this is already the current menubar or we are the frontmost window @@ -244,6 +259,7 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) m_frameMenuBar->MacInstallMenuBar(); } } +#endif void wxFrame::DoGetClientSize(int *x, int *y) const { diff --git a/src/osx/carbon/gauge.cpp b/src/osx/carbon/gauge.cpp index d0fcd56142..5a63c43507 100644 --- a/src/osx/carbon/gauge.cpp +++ b/src/osx/carbon/gauge.cpp @@ -15,113 +15,81 @@ #include "wx/gauge.h" -IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) +#include "wx/osx/private.h" -#include "wx/osx/uma.h" - -bool wxGauge::Create( wxWindow *parent, - wxWindowID id, - int range, - const wxPoint& pos, - const wxSize& s, - long style, - const wxValidator& validator, - const wxString& name ) -{ - m_macIsUserPane = false; - - if ( !wxGaugeBase::Create( parent, id, range, pos, s, style & 0xE0FFFFFF, validator, name ) ) - return false; - - wxSize size = s; - -#if 0 - if (size.x == wxDefaultCoord && size.y == wxDefaultCoord) - size = wxSize( 200 , 16 ); -#endif - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - m_peer = new wxMacControl( this ); - OSStatus err = CreateProgressBarControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, - GetValue(), 0, GetRange(), false /* not indeterminate */, m_peer->GetControlRefAddr() ); - verify_noerr( err ); - - if ( GetValue() == 0 ) - m_peer->SetData( kControlEntireControl, kControlProgressBarAnimatingTag, (Boolean)false ); - - MacPostControlCreate( pos, size ); - - return true; -} - -void wxGauge::SetRange(int r) +class wxMacGaugeCarbonControl : public wxMacControl { - // we are going via the base class in case there is - // some change behind the values by it - wxGaugeBase::SetRange( r ) ; - if ( m_peer && m_peer->IsOk() ){ +public : + wxMacGaugeCarbonControl( wxWindowMac* peer ) : wxMacControl( peer ) + { + } + + void SetMaximum(wxInt32 v) + { // switch back to determinate mode if not there already - if ( m_peer->GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) + if ( GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) { - m_peer->SetData( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); + SetData( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); } - m_peer->SetMaximum( GetRange() ) ; + wxMacControl::SetMaximum( v ) ; } -} - -void wxGauge::SetValue(int pos) -{ - // we are going via the base class in case there is - // some change behind the values by it - wxGaugeBase::SetValue( pos ) ; - - if ( m_peer && m_peer->IsOk() ) + + void SetValue(wxInt32 v) { // switch back to determinate mode if not there already - if ( m_peer->GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) + if ( GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) { - m_peer->SetData( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); + SetData( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); } - m_peer->SetValue( GetValue() ) ; + wxMacControl::SetValue( v ) ; // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise - Boolean shouldAnimate = ( GetValue() > 0 && GetValue() < GetRange() ) ; - if ( m_peer->GetData( kControlEntireControl, kControlProgressBarAnimatingTag ) != shouldAnimate ) + Boolean shouldAnimate = ( v > 0 && v < GetMaximum() ) ; + if ( GetData( kControlEntireControl, kControlProgressBarAnimatingTag ) != shouldAnimate ) { - m_peer->SetData( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ; + SetData( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ; if ( !shouldAnimate ) - Refresh() ; + SetNeedsDisplay(NULL) ; } } -} - -int wxGauge::GetValue() const -{ -#if 0 - if ( m_peer && m_peer->Ok() ) - return m_peer->GetValue() ; -#endif - - return m_gaugePos ; -} - -void wxGauge::Pulse() -{ - if ( m_peer && m_peer->IsOk() ) + + void PulseGauge() { - if ( m_peer->GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != true ) + if ( GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != true ) { - m_peer->SetData( kControlNoPart, kControlProgressBarIndeterminateTag, true); + SetData( kControlNoPart, kControlProgressBarIndeterminateTag, true); } - if ( m_peer->GetData( kControlEntireControl, kControlProgressBarAnimatingTag ) != true ) + if ( GetData( kControlEntireControl, kControlProgressBarAnimatingTag ) != true ) { - m_peer->SetData( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ; + SetData( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ; } } +}; + + +wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxInt32 value, + wxInt32 minimum, + wxInt32 maximum, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); + wxMacGaugeCarbonControl* peer = new wxMacGaugeCarbonControl( wxpeer ); + OSStatus err = CreateProgressBarControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, + value, minimum, maximum, false /* not indeterminate */, peer->GetControlRefAddr() ); + verify_noerr( err ); + if ( value == 0 ) + peer->SetData( kControlEntireControl, kControlProgressBarAnimatingTag, (Boolean)false ); + return peer; } #endif // wxUSE_GAUGE diff --git a/src/osx/carbon/gdiobj.cpp b/src/osx/carbon/gdiobj.cpp index 81fb05c458..9dcae80012 100644 --- a/src/osx/carbon/gdiobj.cpp +++ b/src/osx/carbon/gdiobj.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/gdiobj.cpp +// Name: src/osx/carbon/gdiobj.cpp // Purpose: wxGDIObject class // Author: Stefan Csomor // Modified by: @@ -64,11 +64,19 @@ const wxFont* wxStockGDIMac::GetFont(Item item) #if wxOSX_USE_COCOA_OR_CARBON case FONT_NORMAL: font = new wxFont; +#if wxOSX_USE_CARBON font->MacCreateFromThemeFont(kThemeSystemFont); +#else + font->MacCreateFromUIFont(kCTFontSystemFontType); +#endif break; case FONT_SMALL: font = new wxFont; +#if wxOSX_USE_CARBON font->MacCreateFromThemeFont(kThemeSmallSystemFont); +#else + font->MacCreateFromUIFont(kCTFontSmallSystemFontType); +#endif break; #else case FONT_NORMAL: diff --git a/src/osx/carbon/glcanvas.cpp b/src/osx/carbon/glcanvas.cpp index 4bfc12cc9e..f61a03cb47 100644 --- a/src/osx/carbon/glcanvas.cpp +++ b/src/osx/carbon/glcanvas.cpp @@ -36,6 +36,7 @@ #include "wx/osx/uma.h" #include "wx/osx/private.h" +#include // ---------------------------------------------------------------------------- // helper functions @@ -54,146 +55,47 @@ static void wxLogAGLError(const char *func) // ============================================================================ // ---------------------------------------------------------------------------- -// wxGLContext +// low level implementation routines // ---------------------------------------------------------------------------- -wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other) +WXGLContext WXGLCreateContext( WXGLPixelFormat pixelFormat, WXGLContext shareContext ) { - m_aglContext = aglCreateContext(win->GetAGLPixelFormat(), - other ? other->m_aglContext : NULL); - if ( !m_aglContext ) + WXGLContext context = aglCreateContext(pixelFormat, shareContext); + if ( !context ) wxLogAGLError("aglCreateContext"); + return context ; } -wxGLContext::~wxGLContext() +void WXGLDestroyContext( WXGLContext context ) { - if ( m_aglContext ) + if ( context ) { - // it's ok to pass the current context to this function - if ( !aglDestroyContext(m_aglContext) ) + if ( !aglDestroyContext(context) ) + { wxLogAGLError("aglDestroyContext"); + } } } -bool wxGLContext::SetCurrent(const wxGLCanvas& win) const -{ - if ( !m_aglContext ) - return false; - - AGLDrawable drawable = (AGLDrawable)GetWindowPort( - MAC_WXHWND(win.MacGetTopLevelWindowRef())); - if ( !aglSetDrawable(m_aglContext, drawable) ) - { - wxLogAGLError("aglSetDrawable"); - return false; - } - - if ( !aglSetCurrentContext(m_aglContext) ) - { - wxLogAGLError("aglSetCurrentContext"); - return false; - } - - wx_const_cast(wxGLCanvas&, win).SetViewport(); - return true; -} - -// ---------------------------------------------------------------------------- -// wxGLCanvas -// ---------------------------------------------------------------------------- - -IMPLEMENT_CLASS(wxGLCanvas, wxWindow) - -BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) - EVT_SIZE(wxGLCanvas::OnSize) -END_EVENT_TABLE() - -wxGLCanvas::wxGLCanvas(wxWindow *parent, - wxWindowID id, - const int *attribList, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name, - const wxPalette& palette) -{ - Create(parent, id, pos, size, style, name, attribList, palette); -} - -#if WXWIN_COMPATIBILITY_2_8 - -wxGLCanvas::wxGLCanvas(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name, - const int *attribList, - const wxPalette& palette) -{ - if ( Create(parent, id, pos, size, style, name, attribList, palette) ) - m_glContext = new wxGLContext(this); -} - -wxGLCanvas::wxGLCanvas(wxWindow *parent, - const wxGLContext *shared, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name, - const int *attribList, - const wxPalette& palette) +void WXGLSwapBuffers( WXGLContext context ) { - if ( Create(parent, id, pos, size, style, name, attribList, palette) ) - m_glContext = new wxGLContext(this, shared); + aglSwapBuffers(context); } -wxGLCanvas::wxGLCanvas(wxWindow *parent, - const wxGLCanvas *shared, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name, - const int *attribList, - const wxPalette& palette) +WXGLContext WXGLGetCurrentContext() { - if ( Create(parent, id, pos, size, style, name, attribList, palette) ) - m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL); + return aglGetCurrentContext(); } -#endif // WXWIN_COMPATIBILITY_2_8 - -/* static */ -bool wxGLCanvasBase::IsExtensionSupported(const char *extension) +void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat ) { - // we need a valid context to query for extensions. - const GLint defaultAttribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_NONE }; - AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, defaultAttribs); - AGLContext ctx = aglCreateContext(fmt, NULL); - if ( !ctx ) - return false; - - wxString extensions = wxString::FromAscii(glGetString(GL_EXTENSIONS)); - - aglDestroyPixelFormat(fmt); - aglDestroyContext(ctx); - - return IsExtensionInList(extensions, extension); -} - -/* static */ -bool wxGLCanvas::IsAGLMultiSampleAvailable() -{ - static int s_isMultiSampleAvailable = -1; - if ( s_isMultiSampleAvailable == -1 ) - s_isMultiSampleAvailable = IsExtensionSupported("GL_ARB_multisample"); - - return s_isMultiSampleAvailable != 0; + if ( pixelFormat ) + { + aglDestroyPixelFormat(pixelFormat); + } } -static AGLPixelFormat ChoosePixelFormat(const int *attribList) +WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList) { GLint data[512]; const GLint defaultAttribs[] = @@ -340,6 +242,83 @@ static AGLPixelFormat ChoosePixelFormat(const int *attribList) return aglChoosePixelFormat(NULL, 0, attribs); } +// ---------------------------------------------------------------------------- +// wxGLContext +// ---------------------------------------------------------------------------- + +bool wxGLContext::SetCurrent(const wxGLCanvas& win) const +{ + if ( !m_glContext ) + return false; + + AGLDrawable drawable = (AGLDrawable)GetWindowPort( + MAC_WXHWND(win.MacGetTopLevelWindowRef())); + + GLint bufnummer = win.GetAglBufferName(); + aglSetInteger(m_glContext, AGL_BUFFER_NAME, &bufnummer); + //win.SetLastContext(m_glContext); + + wx_const_cast(wxGLCanvas&, win).SetViewport(); + + if ( !aglSetDrawable(m_glContext, drawable) ) + { + wxLogAGLError("aglSetDrawable"); + return false; + } + + if ( !aglSetCurrentContext(m_glContext) ) + { + wxLogAGLError("aglSetCurrentContext"); + return false; + } + return true; +} + +// ---------------------------------------------------------------------------- +// wxGLCanvas +// ---------------------------------------------------------------------------- + +/* + +sharing contexts under AGL is not straightforward, to quote from + +http://lists.apple.com/archives/mac-opengl/2003/Jan/msg00402.html : + +In Carbon OpenGL (AGL) you would use call aglSetInteger to setup a +buffer name and attached each context to that same name. From AGL +you can do: + +GLint id = 1; + +ctx1 = aglCreateContext... +aglSetInteger(ctx1, AGL_BUFFER_NAME, &id); // create name +aglAttachDrawable (ctx1,...); // create surface with associated with +name (first time) +ctx2 = aglCreateContext... +aglSetInteger(ctx2, AGL_BUFFER_NAME, &id); // uses previously created name +aglAttachDrawable (ctx2, ...); // uses existing surface with existing name + +AGL Docs say: +AGL_BUFFER_NAME +params contains one value: a non-negative integer name of the surface to be +associated to be with the current context. If this value is non-zero, and a +surface of this name is not associated to this drawable, a new surface with +this name is created and associated with the context when +aglSetDrawable is called subsequently. If this is a previously allocated +buffer name within the namespace of the current window (e.g., drawable), +that previously allocated surface is associated with the context (e.g., no +new surface is created) and the subsequent call to aglSetDrawable will +attach that surface. This allows multiple contexts to be attached to a single +surface. Using the default buffer name zero, returns to one surface per +context behavior. +*/ + +/* +so what I'm doing is to have a dummy aglContext attached to a wxGLCanvas, +assign it a buffer number +*/ + + bool wxGLCanvas::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, @@ -352,44 +331,34 @@ bool wxGLCanvas::Create(wxWindow *parent, m_needsUpdate = false; m_macCanvasIsShown = false; - m_aglFormat = ChoosePixelFormat(attribList); - if ( !m_aglFormat ) + m_glFormat = WXGLChoosePixelFormat(attribList); + if ( !m_glFormat ) return false; if ( !wxWindow::Create(parent, id, pos, size, style, name) ) return false; - m_macCanvasIsShown = true; - - return true; -} - -wxGLCanvas::~wxGLCanvas() -{ - if ( m_aglFormat ) - aglDestroyPixelFormat(m_aglFormat); -} - -/* static */ -bool wxGLCanvasBase::IsDisplaySupported(const int *attribList) -{ - AGLPixelFormat aglFormat = ChoosePixelFormat(attribList); + m_dummyContext = WXGLCreateContext(m_glFormat, NULL); - if ( !aglFormat ) - return false; + static GLint gCurrentBufferName = 1; + m_bufferName = gCurrentBufferName++; + aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); + + AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); + aglSetDrawable(m_dummyContext, drawable); - aglDestroyPixelFormat(aglFormat); + m_macCanvasIsShown = true; return true; } -bool wxGLCanvas::SwapBuffers() +wxGLCanvas::~wxGLCanvas() { - AGLContext context = aglGetCurrentContext(); - wxCHECK_MSG(context, false, _T("should have current context")); - - aglSwapBuffers(context); - return true; + if ( m_glFormat ) + WXGLDestroyPixelFormat(m_glFormat); + + if ( m_dummyContext ) + WXGLDestroyContext(m_dummyContext); } void wxGLCanvas::SetViewport() @@ -399,9 +368,9 @@ void wxGLCanvas::SetViewport() m_needsUpdate = false; - AGLContext context = aglGetCurrentContext(); - if ( !context ) - return; +// AGLContext context = aglGetCurrentContext(); +// if ( !context ) +// return; // viewport is initially set to entire port, adjust it to just this window int x = 0, @@ -414,36 +383,23 @@ void wxGLCanvas::SetViewport() Rect bounds; GetWindowPortBounds(MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds); -#if 0 - // TODO in case we adopt point vs pixel coordinates, this will make the conversion - HIRect hiRect = CGRectMake( x, y, width, height ); - HIRectConvert( &hiRect, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL); - HIRect hiBounds = CGRectMake( 0, 0, bounds.right - bounds.left , bounds.bottom - bounds.top ); - HIRectConvert( &hiBounds, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL); - GLint parms[4]; - parms[0] = hiRect.origin.x; - parms[1] = hiBounds.size.height - (hiRect.origin.y + hiRect.size.height); - parms[2] = hiRect.size.width; - parms[3] = hiRect.size.height; -#else GLint parms[4]; parms[0] = x; parms[1] = bounds.bottom - bounds.top - ( y + height ); parms[2] = width; parms[3] = height; -#endif // move the buffer rect out of sight if we're hidden if ( !m_macCanvasIsShown ) parms[0] += 20000; - if ( !aglSetInteger(context, AGL_BUFFER_RECT, parms) ) + if ( !aglSetInteger(m_dummyContext, AGL_BUFFER_RECT, parms) ) wxLogAGLError("aglSetInteger(AGL_BUFFER_RECT)"); - if ( !aglEnable(context, AGL_BUFFER_RECT) ) + if ( !aglEnable(m_dummyContext, AGL_BUFFER_RECT) ) wxLogAGLError("aglEnable(AGL_BUFFER_RECT)"); - if ( !aglUpdateContext(context) ) + if ( !aglUpdateContext(m_dummyContext) ) wxLogAGLError("aglUpdateContext"); } @@ -462,6 +418,7 @@ void wxGLCanvas::MacUpdateView() void wxGLCanvas::MacSuperChangedPosition() { MacUpdateView(); + SetViewport(); wxWindow::MacSuperChangedPosition(); } @@ -482,18 +439,4 @@ void wxGLCanvas::MacVisibilityChanged() wxWindowMac::MacVisibilityChanged(); } -// ---------------------------------------------------------------------------- -// wxGLApp -// ---------------------------------------------------------------------------- - -bool wxGLApp::InitGLVisual(const int *attribList) -{ - AGLPixelFormat fmt = ChoosePixelFormat(attribList); - if ( !fmt ) - return false; - - aglDestroyPixelFormat(fmt); - return true; -} - #endif // wxUSE_GLCANVAS diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index cef1c5d805..2ae8e6388d 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/dccg.cpp +// Name: src/osx/carbon/dccg.cpp // Purpose: wxDC class // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/icon.cpp b/src/osx/carbon/icon.cpp index 38e86abec3..4b0ffbe322 100644 --- a/src/osx/carbon/icon.cpp +++ b/src/osx/carbon/icon.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/icon.cpp +// Name: src/osx/carbon/icon.cpp // Purpose: wxIcon class // Author: Stefan Csomor // Modified by: @@ -53,7 +53,7 @@ private: wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight ) { - m_iconRef = MAC_WXHICON( icon ) ; + m_iconRef = (IconRef)( icon ) ; // Standard sizes SetWidth( desiredWidth == -1 ? 32 : desiredWidth ) ; diff --git a/src/osx/carbon/listbox.cpp b/src/osx/carbon/listbox.cpp index 5e63f1cf8a..23f6443ba0 100644 --- a/src/osx/carbon/listbox.cpp +++ b/src/osx/carbon/listbox.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/listbox.cpp +// Name: src/osx/carbon/listbox.cpp // Purpose: wxListBox // Author: Stefan Csomor // Modified by: @@ -24,271 +24,23 @@ #include "wx/dcclient.h" #endif -IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems) - -BEGIN_EVENT_TABLE(wxListBox, wxControl) -END_EVENT_TABLE() - -#include "wx/osx/uma.h" +#include "wx/osx/private.h" // ============================================================================ // list box control implementation // ============================================================================ -wxListBox::wxListBox() -{ -} - -bool wxListBox::Create( - wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString& name ) -{ - wxCArrayString chs(choices); - - return Create( - parent, id, pos, size, chs.GetCount(), chs.GetStrings(), - style, validator, name ); -} - -wxMacListControl* wxListBox::GetPeer() const +wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - wxMacDataBrowserListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListControl); - return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ; -} - -bool wxListBox::Create( - wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - int n, - const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name ) -{ - m_blockEvents = false; - m_macIsUserPane = false; - - wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), - wxT("only a single listbox selection mode can be specified") ); - - if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) - return false; - - wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( this, pos, size, style ); + wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( wxpeer, pos, size, style ); // TODO CHECK control->SetClientDataType( m_clientDataItemsType ); - m_peer = control; - - MacPostControlCreate( pos, size ); - - Append(n, choices); - - // Needed because it is a wxControlWithItems - SetInitialSize( size ); - - return true; -} - -wxListBox::~wxListBox() -{ - FreeData(); - m_peer->SetReference( 0 ); -} - -void wxListBox::FreeData() -{ - GetPeer()->MacClear(); -} - -void wxListBox::DoSetFirstItem(int n) -{ - GetPeer()->MacScrollTo( n ); -} - -void wxListBox::EnsureVisible(int n) -{ - GetPeer()->MacScrollTo( n ); -} - -void wxListBox::DoDeleteOneItem(unsigned int n) -{ - wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::Delete") ); - - m_blockEvents = true; - GetPeer()->MacDelete( n ); - m_blockEvents = false; - - UpdateOldSelections(); -} - -int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, - unsigned int pos, - void **clientData, - wxClientDataType type) -{ - InvalidateBestSize(); - - GetPeer()->MacInsert( pos, items ); - const unsigned int count = items.GetCount(); - if ( clientData ) - { - for (unsigned int i = 0; i < count; ++i) - AssignNewItemClientData( pos + i, clientData, i, type ); - } - - return pos + count - 1; - - UpdateOldSelections(); -} - -int wxListBox::FindString(const wxString& s, bool bCase) const -{ - for ( size_t i = 0; i < GetCount(); ++ i ) - { - if (s.IsSameAs( GetString( i ), bCase) ) - return (int)i; - } - - return wxNOT_FOUND; -} - -void wxListBox::DoClear() -{ - m_blockEvents = true; - FreeData(); - m_blockEvents = false; - - UpdateOldSelections(); -} - -void wxListBox::DoSetSelection(int n, bool select) -{ - wxCHECK_RET( n == wxNOT_FOUND || IsValid(n), - wxT("invalid index in wxListBox::SetSelection") ); - - m_blockEvents = true; - - if ( n == wxNOT_FOUND ) - GetPeer()->MacDeselectAll(); - else - GetPeer()->MacSetSelection( n, select, HasMultipleSelection() ); - - m_blockEvents = false; - - UpdateOldSelections(); -} - -bool wxListBox::IsSelected(int n) const -{ - wxCHECK_MSG( IsValid(n), false, wxT("invalid index in wxListBox::Selected") ); - - return GetPeer()->MacIsSelected( n ); -} - -void *wxListBox::DoGetItemClientData(unsigned int n) const -{ - wxCHECK_MSG( IsValid(n), NULL, wxT("invalid index in wxListBox::GetClientData")); - return GetPeer()->MacGetClientData( n ); -} - -void wxListBox::DoSetItemClientData(unsigned int n, void *clientData) -{ - wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetClientData") ); - GetPeer()->MacSetClientData( n , clientData); -} - -// Return number of selections and an array of selected integers -int wxListBox::GetSelections(wxArrayInt& aSelections) const -{ - return GetPeer()->MacGetSelections( aSelections ); -} - -// Get single selection, for single choice list items -int wxListBox::GetSelection() const -{ - return GetPeer()->MacGetSelection(); -} - -// Find string for position -wxString wxListBox::GetString(unsigned int n) const -{ - wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("invalid index in wxListBox::GetString") ); - return GetPeer()->MacGetString(n); -} - -void wxListBox::SetString(unsigned int n, const wxString& s) -{ - GetPeer()->MacSetString( n, s ); -} - -wxSize wxListBox::DoGetBestSize() const -{ - int lbWidth = 100; // some defaults - int lbHeight = 110; - int wLine; - - { - wxClientDC dc(const_cast(this)); - dc.SetFont(GetFont()); - - // Find the widest line - for (unsigned int i = 0; i < GetCount(); i++) - { - wxString str( GetString( i ) ); - - wxCoord width, height ; - dc.GetTextExtent( str , &width, &height); - wLine = width ; - lbWidth = wxMax( lbWidth, wLine ); - } - - // Add room for the scrollbar - lbWidth += wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ); - - // And just a bit more - int cy = 12; - - wxCoord width, height ; - dc.GetTextExtent( wxT("XX") , &width, &height); - int cx = width ; - lbWidth += cx; - - // don't make the listbox too tall (limit height to around 10 items) - // but don't make it too small neither - lbHeight = wxMax( (cy + 4) * wxMin( wxMax( GetCount(), 3 ), 10 ), 70 ); - } - - return wxSize( lbWidth, lbHeight ); -} - -unsigned int wxListBox::GetCount() const -{ - return GetPeer()->MacGetCount(); -} - -void wxListBox::Refresh(bool eraseBack, const wxRect *rect) -{ - wxControl::Refresh( eraseBack, rect ); -} - -// Some custom controls depend on this -/* static */ wxVisualAttributes -wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) -{ - wxVisualAttributes attr; - - attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); - attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font.MacCreateFromThemeFont(kThemeViewsFont); - - return attr; + return control; } int wxListBox::DoListHitTest(const wxPoint& inpoint) const @@ -407,6 +159,77 @@ wxMacListBoxItem::~wxMacListBoxItem() { } +OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner , + DataBrowserPropertyID property, + DataBrowserItemDataRef itemData, + bool changeValue ) +{ + wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl); + OSStatus err = errDataBrowserPropertyNotSupported; + if ( !changeValue ) + { + if ( property >= kMinColumnId ) + { + wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( property ); + unsigned int n = owner->GetLineFromItem( this ); + wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox ); + wxMacDataBrowserCellValue valueholder(itemData); + list->GetValueCallback( n , col, valueholder ); + + err = noErr; + } + else + { + if ( property == kDataBrowserItemIsEditableProperty ) + { + DataBrowserPropertyID propertyToEdit ; + GetDataBrowserItemDataProperty( itemData, &propertyToEdit ); + wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( propertyToEdit ); + + verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, col->IsEditable() )); + err = noErr; + } + + } + + } + else + { + if ( property >= kMinColumnId ) + { + wxMacDataBrowserColumn* col = lb->GetColumnFromProperty( property ); + + unsigned int n = owner->GetLineFromItem( this ); + wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox ); + wxMacDataBrowserCellValue valueholder(itemData); + list->SetValueCallback( n , col, valueholder ); + + /* + // we have to change this behind the back, since Check() would be triggering another update round + bool newVal = !m_isChecked; + verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff )); + m_isChecked = newVal; + err = noErr; + + wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() ); + event.SetInt( owner->GetLineFromItem( this ) ); + event.SetEventObject( checklist ); + checklist->HandleWindowEvent( event ); + + */ + err = noErr; + } + } + + // call inherited if not ours + if ( err == errDataBrowserPropertyNotSupported ) + { + err = wxMacDataItem::GetSetData(owner, property, itemData, changeValue); + } + + return err; +} + void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner , DataBrowserItemNotification message, DataBrowserItemDataRef WXUNUSED(itemData) ) const @@ -417,28 +240,24 @@ void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner , if ( message == kDataBrowserItemRemoved) { - if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object ) - { - delete (wxClientData*) (m_data); - } - delete this; return; } - wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox ); + wxListBox *list = wxDynamicCast( lb->GetWXPeer() , wxListBox ); wxCHECK_RET( list != NULL , wxT("Listbox expected")); if (message == kDataBrowserItemDoubleClicked) { + unsigned int n = owner->GetLineFromItem( this ); wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, list->GetId() ); event.SetEventObject( list ); if ( list->HasClientObjectData() ) - event.SetClientObject( (wxClientData*) m_data ); + event.SetClientObject( list->GetClientObject(n) ); else if ( list->HasClientUntypedData() ) - event.SetClientData( m_data ); - event.SetString( m_label ); - event.SetInt( owner->GetLineFromItem( this ) ); + event.SetClientData( list->GetClientData(n) ); + event.SetString( list->GetString(n) ); + event.SetInt( n ); event.SetExtraLong( 1 ); list->HandleWindowEvent(event); return; @@ -450,6 +269,8 @@ IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserContr wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style) : wxMacDataItemBrowserControl( peer, pos, size, style ) { + m_nextColumnId = 0 ; + OSStatus err = noErr; m_clientDataItemsType = wxClientData_None; if ( style & wxLB_SORT ) @@ -483,7 +304,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; columnDesc.headerBtnDesc.btnFontStyle.style = normal; columnDesc.headerBtnDesc.titleString = NULL; - +/* columnDesc.headerBtnDesc.minimumWidth = 0; columnDesc.headerBtnDesc.maximumWidth = 10000; @@ -493,7 +314,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); - +*/ columnDesc.headerBtnDesc.minimumWidth = 0; columnDesc.headerBtnDesc.maximumWidth = 0; columnDesc.propertyDesc.propertyID = kNumericOrderColumnId; @@ -503,6 +324,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); +/* SetDataBrowserSortProperty( m_controlRef , kTextColumnId); if ( m_sortOrder == SortOrder_Text_Ascending ) { @@ -510,6 +332,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); } else +*/ { SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId); SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); @@ -566,15 +389,260 @@ void wxMacDataBrowserListControl::ItemNotification( // call super for item level(wxMacDataItem->Notification) callback processing wxMacDataItemBrowserControl::ItemNotification( itemID, message, itemData); } + + /* wxWindow * wxMacDataBrowserListControl::GetPeer() const { return wxDynamicCast( wxMacControl::GetWX() , wxWindow ); } */ -wxMacDataItem* wxMacDataBrowserListControl::CreateItem() + +// +// List Methods +// + +wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned int pos, DataBrowserPropertyID property, + const wxString& title, bool editable, + DataBrowserPropertyType colType, SInt16 just, int width ) +{ + DataBrowserListViewColumnDesc columnDesc; + columnDesc.headerBtnDesc.titleOffset = 0; + columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; + + columnDesc.headerBtnDesc.btnFontStyle.flags = + kControlUseFontMask | kControlUseJustMask; + + columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly; + columnDesc.headerBtnDesc.btnFontStyle.just = just; + columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; + columnDesc.headerBtnDesc.btnFontStyle.style = normal; + + // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is + // defined for other modes? + wxFontEncoding enc; + if ( m_font.Ok() ) + enc = m_font.GetEncoding(); + else + enc = wxLocale::GetSystemEncoding(); + wxCFStringRef cfTitle( title, enc ); + columnDesc.headerBtnDesc.titleString = cfTitle; + + columnDesc.headerBtnDesc.minimumWidth = 0; + columnDesc.headerBtnDesc.maximumWidth = 30000; + + columnDesc.propertyDesc.propertyID = property; + columnDesc.propertyDesc.propertyType = colType; + columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn; + columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; + columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; + + if ( editable ) + columnDesc.propertyDesc.propertyFlags |= kDataBrowserPropertyIsMutable; + + verify_noerr( AddColumn( &columnDesc, pos ) ); + + if (width > 0) + { + wxMacDataBrowserControl::SetColumnWidth(property, width); + } + + wxMacDataBrowserColumn *col = new wxMacDataBrowserColumn( property, colType, editable ); + + m_columns.Insert( col, pos ); + + return col; +} + +wxListWidgetColumn* wxMacDataBrowserListControl::InsertTextColumn( unsigned pos, const wxString& title, bool editable, + wxAlignment just, int defaultWidth) +{ + DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++; + + SInt16 j = teFlushLeft; + if ( just & wxALIGN_RIGHT ) + j = teFlushRight; + else if ( just & wxALIGN_CENTER_HORIZONTAL ) + j = teCenter; + + return DoInsertColumn( pos, property, title, editable, kDataBrowserTextType, just, defaultWidth ); +} + +wxListWidgetColumn* wxMacDataBrowserListControl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable, + wxAlignment just, int defaultWidth ) +{ + DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++; + + SInt16 j = teFlushLeft; + if ( just & wxALIGN_RIGHT ) + j = teFlushRight; + else if ( just & wxALIGN_CENTER_HORIZONTAL ) + j = teCenter; + + return DoInsertColumn( pos, property, title, editable, kDataBrowserCheckboxType, just, defaultWidth ); +} + +wxMacDataBrowserColumn* wxMacDataBrowserListControl::GetColumnFromProperty( DataBrowserPropertyID property) +{ + for ( unsigned int i = 0; i < m_columns.size() ; ++ i ) + if ( m_columns[i]->GetProperty() == property ) + return m_columns[i]; + + return NULL; +} + +/* +wxMacDataItem* wxMacDataBrowserListControl::ListGetLineItem( unsigned int n ) +{ + return (wxMacDataItem*) GetItemFromLine(n); +} +*/ + +unsigned int wxMacDataBrowserListControl::ListGetCount() const +{ + return MacGetCount(); +} + +void wxMacDataBrowserListControl::ListDelete( unsigned int n ) +{ + MacDelete( n ); +} + +void wxMacDataBrowserListControl::ListInsert( unsigned int n ) +{ + MacInsert( n , new wxMacListBoxItem() ); +} + +void wxMacDataBrowserListControl::ListClear() +{ + MacClear(); +} + +void wxMacDataBrowserListControl::ListDeselectAll() +{ + wxMacDataItemBrowserSelectionSuppressor suppressor(this); + SetSelectedAllItems( kDataBrowserItemsRemove ); +} + +void wxMacDataBrowserListControl::ListSetSelection( unsigned int n, bool select, bool multi ) +{ + wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); + wxMacDataItemBrowserSelectionSuppressor suppressor(this); + + if ( IsItemSelected( item ) != select ) + { + if ( select ) + SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign ); + else + SetSelectedItem( item, kDataBrowserItemsRemove ); + } + + ListScrollTo( n ); +} + +bool wxMacDataBrowserListControl::ListIsSelected( unsigned int n ) const +{ + wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); + return IsItemSelected( item ); +} + +int wxMacDataBrowserListControl::ListGetSelection() const +{ + wxMacDataItemPtr first, last; + GetSelectionAnchor( &first, &last ); + + if ( first != NULL ) + { + return GetLineFromItem( first ); + } + + return -1; +} + +int wxMacDataBrowserListControl::ListGetSelections( wxArrayInt& aSelections ) const +{ + aSelections.Empty(); + wxArrayMacDataItemPtr selectedItems; + GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems); + + int count = selectedItems.GetCount(); + + for ( int i = 0; i < count; ++i) + { + aSelections.Add(GetLineFromItem(selectedItems[i])); + } + + return count; +} + +void wxMacDataBrowserListControl::ListScrollTo( unsigned int n ) +{ + UInt32 top , left ; + GetScrollPosition( &top , &left ) ; + wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); + + // there is a bug in RevealItem that leads to situations + // in large lists, where the item does not get scrolled + // into sight, so we do a pre-scroll if necessary + UInt16 height ; + GetRowHeight( (DataBrowserItemID) item , &height ) ; + UInt32 linetop = n * ((UInt32) height ); + UInt32 linebottom = linetop + height; + Rect rect ; + GetControlBounds( m_controlRef, &rect ); + + if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) ) + SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ; + + RevealItem( item , kDataBrowserRevealWithoutSelecting ); +} + +void wxMacDataBrowserListControl::UpdateLine( unsigned int n, wxListWidgetColumn* col ) +{ + wxMacDataBrowserColumn* dbcol = dynamic_cast (col); + wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); + UpdateItem(wxMacDataBrowserRootContainer, item, dbcol ? dbcol->GetProperty() : kDataBrowserNoItem ); +} + +void wxMacDataBrowserListControl::UpdateLineToEnd( unsigned int n) +{ + // with databrowser inserting does not need updating the entire model, it's done by databrowser itself + wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); + UpdateItem(wxMacDataBrowserRootContainer, item, kDataBrowserNoItem ); +} + +// value setters + +void wxMacDataBrowserCellValue::Set( CFStringRef value ) +{ + SetDataBrowserItemDataText( m_data, value ); +} + +void wxMacDataBrowserCellValue::Set( const wxString& value ) +{ + wxCFStringRef cf(value); + SetDataBrowserItemDataText( m_data, (CFStringRef) cf); +} + +void wxMacDataBrowserCellValue::Set( int value ) +{ + SetDataBrowserItemDataValue( m_data, value ); + // SetDataBrowserItemDataButtonValue( m_data, value ? kThemeButtonOn : kThemeButtonOff); +} + +int wxMacDataBrowserCellValue::GetIntValue() const +{ + SInt32 value; + GetDataBrowserItemDataValue( m_data, &value ); + return value; +} + +wxString wxMacDataBrowserCellValue::GetStringValue() const { - return new wxMacListBoxItem(); + CFStringRef value; + GetDataBrowserItemDataText ( m_data, &value ); + wxCFStringRef cf(value); + return cf.AsString(); } #if 0 diff --git a/src/osx/carbon/listctrl_mac.cpp b/src/osx/carbon/listctrl_mac.cpp index 8ba6fa0a1c..a933d4ad0e 100644 --- a/src/osx/carbon/listctrl_mac.cpp +++ b/src/osx/carbon/listctrl_mac.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/listctrl_mac.cpp +// Name: src/osx/listctrl_mac.cpp // Purpose: wxListCtrl // Author: Julian Smart // Modified by: Agron Selimaj @@ -176,7 +176,7 @@ static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler ) -class wxMacListCtrlItem : public wxMacListBoxItem +class wxMacListCtrlItem : public wxMacDataItem { public: wxMacListCtrlItem(); @@ -214,8 +214,6 @@ public: // create a list item (can be a subclass of wxMacListBoxItem) - virtual wxMacDataItem* CreateItem(); - virtual void MacInsertItem( unsigned int n, wxListItem* item ); virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item ); virtual void MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item ); @@ -517,10 +515,9 @@ END_EVENT_TABLE() // implementation // ============================================================================ -wxMacListControl* wxListCtrl::GetPeer() const +wxMacDataBrowserListCtrlControl* wxListCtrl::GetListPeer() const { - wxMacDataBrowserListCtrlControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListCtrlControl); - return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ; + return dynamic_cast ( GetPeer() ); } // ---------------------------------------------------------------------------- @@ -2433,11 +2430,6 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , // we want to depend on as little as possible to make sure tear-down of controls is safe if ( message == kDataBrowserItemRemoved) { - if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object ) - { - delete (wxClientData*) (m_data); - } - delete this; return; } @@ -3245,18 +3237,14 @@ void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsign } } } - + void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item ) { - wxMacDataItemBrowserControl::MacInsert(n, item->GetText()); + + wxMacDataItemBrowserControl::MacInsert(n, new wxMacListCtrlItem() ); MacSetColumnInfo(n, 0, item); } -wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem() -{ - return new wxMacListCtrlItem(); -} - wxMacListCtrlItem::wxMacListCtrlItem() { m_rowItems = wxListItemList(); @@ -3278,9 +3266,10 @@ void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex wxString wxMacListCtrlItem::GetColumnTextValue( unsigned int column ) { +/* TODO CHECK REMOVE if ( column == 0 ) return GetLabel(); - +*/ if ( HasColumnInfo(column) ) return GetColumnInfo(column)->GetText(); @@ -3292,9 +3281,11 @@ void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& if ( HasColumnInfo(column) ) GetColumnInfo(column)->SetText(text); +/* TODO CHECK REMOVE // for compatibility with superclass APIs if ( column == 0 ) SetLabel(text); +*/ } wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column ) diff --git a/src/osx/carbon/mdi.cpp b/src/osx/carbon/mdi.cpp index 6134f5267b..cee55ca047 100644 --- a/src/osx/carbon/mdi.cpp +++ b/src/osx/carbon/mdi.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/mdi.cpp +// Name: src/osx/carbon/mdi.cpp // Purpose: MDI classes // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/mediactrl.cpp b/src/osx/carbon/mediactrl.cpp index 96151b354b..40deec3d81 100644 --- a/src/osx/carbon/mediactrl.cpp +++ b/src/osx/carbon/mediactrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/mediactrl.cpp +// Name: src/osx/carbon/mediactrl.cpp // Purpose: Built-in Media Backends for Mac // Author: Ryan Norton // Modified by: @@ -45,18 +45,6 @@ #include "wx/timer.h" #endif -// uma is for wxMacFSSpec -#include "wx/osx/uma.h" - -// standard QT stuff -#ifndef __DARWIN__ -#include -#include -#include -#else -#include -#endif - #if wxOSX_USE_CARBON #define USE_QUICKTIME 1 #else @@ -65,6 +53,9 @@ #if USE_QUICKTIME +#include "wx/osx/private.h" +#include + //--------------------------------------------------------------------------- // Height and Width of movie controller in the movie control (apple samples) //--------------------------------------------------------------------------- diff --git a/src/osx/carbon/menu.cpp b/src/osx/carbon/menu.cpp index 8d1277c7f7..5f6a7a75d0 100644 --- a/src/osx/carbon/menu.cpp +++ b/src/osx/carbon/menu.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/menu.cpp +// Name: src/osx/carbon/menu.cpp // Purpose: wxMenu, wxMenuBar, wxMenuItem // Author: Stefan Csomor // Modified by: @@ -28,1158 +28,378 @@ #include "wx/menuitem.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" +#include "wx/stockitem.h" // other standard headers // ---------------------- #include -IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) -IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) +// under carbon there's no such thing as a MenuItemRef, everything is done +// on the 'parent' menu via index APIs (first line having index 1 !) +// so to make things still work, we store the wxMenuItemImpl instance as a +// RefCon at the respective menu line -// the (popup) menu title has this special id -static const int idMenuTitle = -3; - -static const short kwxMacAppleMenuId = 1 ; - - -// Find an item given the Macintosh Menu Reference - -WX_DECLARE_HASH_MAP(MenuRef, wxMenu*, wxPointerHash, wxPointerEqual, MacMenuMap); - -static MacMenuMap wxWinMacMenuList; - -wxMenu *wxFindMenuFromMacMenu(MenuRef inMenuRef) -{ - MacMenuMap::iterator node = wxWinMacMenuList.find(inMenuRef); - - return (node == wxWinMacMenuList.end()) ? NULL : node->second; -} - -void wxAssociateMenuWithMacMenu(MenuRef inMenuRef, wxMenu *menu) ; -void wxAssociateMenuWithMacMenu(MenuRef inMenuRef, wxMenu *menu) -{ - // adding NULL MenuRef is (first) surely a result of an error and - // (secondly) breaks menu command processing - wxCHECK_RET( inMenuRef != (MenuRef) NULL, wxT("attempt to add a NULL MenuRef to menu list") ); - - wxWinMacMenuList[inMenuRef] = menu; -} - -void wxRemoveMacMenuAssociation(wxMenu *menu) ; -void wxRemoveMacMenuAssociation(wxMenu *menu) +class wxMenuItemCarbonImpl : public wxMenuItemImpl { - // iterate over all the elements in the class - MacMenuMap::iterator it; - for ( it = wxWinMacMenuList.begin(); it != wxWinMacMenuList.end(); ++it ) +public : + wxMenuItemCarbonImpl( wxMenuItem* peer ) : wxMenuItemImpl(peer) { - if ( it->second == menu ) - { - wxWinMacMenuList.erase(it); - break; - } + // the parent menu ref is only set, once the item has been attached + m_parentMenuRef = NULL; } -} - -void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter) -{ - wxMenuItemList::compatibility_iterator node; - wxMenuItem *item; - wxMenu *subMenu = NULL ; - bool newItems = false; - - for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) + + ~wxMenuItemCarbonImpl(); + + void SetBitmap( const wxBitmap& bitmap ) { - item = (wxMenuItem *)node->GetData(); - subMenu = item->GetSubMenu() ; - if (subMenu) - { - wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0); - } - if ( item->IsSeparator() ) + MenuItemIndex i = FindMenuItemIndex() ; + if ( i > 0 ) { - if ( wm && newItems) - InsertMenuItemTextWithCFString( wm, - CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0); - - newItems = false; - } - else - { - wxAcceleratorEntry* - entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; - - MenuItemIndex winListPos = (MenuItemIndex)-1; - OSStatus err = GetIndMenuItemWithCommandID(wm, - wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos); - - if ( wm && err == menuItemNotFoundErr ) + if ( bitmap.Ok() ) { - // NB: the only way to determine whether or not we should add - // a separator is to know if we've added menu items to the menu - // before the separator. - newItems = true; - UMAInsertMenuItem(wm, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), insertAfter, entry); - SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ; - SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ; - } - - delete entry ; - } - } -} - -// ============================================================================ -// implementation -// ============================================================================ -static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ; -static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ); - -// Menus - -// Construct a menu with optional title (then use append) - -#ifdef __DARWIN__ -short wxMenu::s_macNextMenuId = 3 ; -#else -short wxMenu::s_macNextMenuId = 2 ; +#if wxUSE_BMPBUTTON + ControlButtonContentInfo info ; + wxMacCreateBitmapButton( &info , bitmap ) ; + if ( info.contentType != kControlNoContent ) + { + if ( info.contentType == kControlContentIconRef ) + SetMenuItemIconHandle( m_parentMenuRef, i , + kMenuIconRefType , (Handle) info.u.iconRef ) ; + else if ( info.contentType == kControlContentCGImageRef ) + SetMenuItemIconHandle( m_parentMenuRef, i , + kMenuCGImageRefType , (Handle) info.u.imageRef ) ; + } + wxMacReleaseBitmapButton( &info ) ; #endif - -static -wxMenu * -_wxMenuAt(const wxMenuList &menuList, size_t pos) -{ - wxMenuList::compatibility_iterator menuIter = menuList.GetFirst(); - - while (pos-- > 0) - menuIter = menuIter->GetNext(); - - return menuIter->GetData() ; -} - -void wxMenu::Init() -{ - m_doBreak = false; - m_startRadioGroup = -1; - - // create the menu - m_macMenuId = s_macNextMenuId++; - m_hMenu = UMANewMenu(m_macMenuId, m_title, wxFont::GetDefaultEncoding() ); - - if ( !m_hMenu ) - { - wxLogLastError(wxT("UMANewMenu failed")); - } - - wxAssociateMenuWithMacMenu( (MenuRef)m_hMenu , this ) ; - - // if we have a title, insert it in the beginning of the menu - if ( !m_title.empty() ) - { - Append(idMenuTitle, m_title) ; - AppendSeparator() ; - } -} - -wxMenu::~wxMenu() -{ - wxRemoveMacMenuAssociation( this ) ; - if (MAC_WXHMENU(m_hMenu)) - ::DisposeMenu(MAC_WXHMENU(m_hMenu)); -} - -void wxMenu::Break() -{ - // not available on the mac platform -} - -void wxMenu::Attach(wxMenuBarBase *menubar) -{ - wxMenuBase::Attach(menubar); - - EndRadioGroup(); -} - -// function appends a new item or submenu to the menu -// append a new item or submenu to the menu -bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) -{ - wxASSERT_MSG( pItem != NULL, wxT("can't append NULL item to the menu") ); - - if ( pItem->IsSeparator() ) - { - if ( pos == (size_t)-1 ) - AppendMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), - CFSTR(""), kMenuItemAttrSeparator, 0,NULL); - else - InsertMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), - CFSTR(""), pos, kMenuItemAttrSeparator, 0); - } - else - { - wxMenu *pSubMenu = pItem->GetSubMenu() ; - if ( pSubMenu != NULL ) - { - wxASSERT_MSG( pSubMenu->m_hMenu != NULL , wxT("invalid submenu added")); - pSubMenu->m_menuParent = this ; - - // We need the !GetMenuBar() check to make sure we run MacBeforeDisplay() - // for popup menus and other menus which may not be part of the main - // menu bar. - if (!GetMenuBar() || wxMenuBar::MacGetInstalledMenuBar() == GetMenuBar()) - pSubMenu->MacBeforeDisplay( true ) ; - - if ( pos == (size_t)-1 ) - UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetItemLabel()), wxFont::GetDefaultEncoding(), pSubMenu->m_macMenuId); - else - UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetItemLabel()), wxFont::GetDefaultEncoding(), pos, pSubMenu->m_macMenuId); - - pItem->UpdateItemBitmap() ; - pItem->UpdateItemStatus() ; - } - else - { - if ( pos == (size_t)-1 ) - { - UMAAppendMenuItem(MAC_WXHMENU(m_hMenu), wxT("a") , wxFont::GetDefaultEncoding() ); - pos = CountMenuItems(MAC_WXHMENU(m_hMenu)) ; - } - else - { - // MacOS counts menu items from 1 and inserts after, therefore having the - // same effect as wx 0 based and inserting before, we must correct pos - // after however for updates to be correct - UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), wxT("a"), wxFont::GetDefaultEncoding(), pos); - pos += 1 ; } - - SetMenuItemCommandID( MAC_WXHMENU(m_hMenu) , pos , wxIdToMacCommand ( pItem->GetId() ) ) ; - SetMenuItemRefCon( MAC_WXHMENU(m_hMenu) , pos , (URefCon) pItem ) ; - pItem->UpdateItemText() ; - pItem->UpdateItemBitmap() ; - pItem->UpdateItemStatus() ; - - if ( pItem->GetId() == idMenuTitle ) - UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , pos , false ) ; } - } - - // if we're already attached to the menubar, we must update it - if ( IsAttached() && GetMenuBar()->IsAttached() ) - GetMenuBar()->Refresh(); - - return true ; -} - -void wxMenu::EndRadioGroup() -{ - // we're not inside a radio group any longer - m_startRadioGroup = -1; -} - -wxMenuItem* wxMenu::DoAppend(wxMenuItem *item) -{ - wxCHECK_MSG( item, NULL, _T("NULL item in wxMenu::DoAppend") ); - - bool check = false; - - if ( item->GetKind() == wxITEM_RADIO ) + } + + void Enable( bool enable ) { - int count = GetMenuItemCount(); - - if ( m_startRadioGroup == -1 ) - { - // start a new radio group - m_startRadioGroup = count; - - // for now it has just one element - item->SetAsRadioGroupStart(); - item->SetRadioGroupEnd(m_startRadioGroup); - - // ensure that we have a checked item in the radio group - check = true; - } - else // extend the current radio group + MenuItemIndex i = FindMenuItemIndex() ; + if ( i > 0 ) { - // we need to update its end item - item->SetRadioGroupStart(m_startRadioGroup); - wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_startRadioGroup); - - if ( node ) + + if ( GetWXPeer()->GetId() == wxApp::s_macPreferencesMenuItemId) + { + if ( enable ) + EnableMenuCommand( NULL , kHICommandPreferences ) ; + else + DisableMenuCommand( NULL , kHICommandPreferences ) ; + } + else if ( GetWXPeer()->GetId() == wxApp::s_macExitMenuItemId) { - node->GetData()->SetRadioGroupEnd(count); + if ( enable ) + EnableMenuCommand( NULL , kHICommandQuit ) ; + else + DisableMenuCommand( NULL , kHICommandQuit ) ; } + + if ( enable ) + EnableMenuItem(m_parentMenuRef , i); else + DisableMenuItem(m_parentMenuRef , i); + + if ( GetWXPeer()->IsSubMenu() ) { - wxFAIL_MSG( _T("where is the radio group start item?") ); + UMAEnableMenuItem( GetWXPeer()->GetSubMenu()->GetHMenu() , 0 , enable ) ; } } - } - else // not a radio item - { - EndRadioGroup(); - } - - if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) ) - return NULL; - - if ( check ) - // check the item initially - item->Check(true); - - return item; -} - -wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item) -{ - if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos)) - return item; - - return NULL; -} - -wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) -{ - // we need to find the items position in the child list - size_t pos; - wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); - - for ( pos = 0; node; pos++ ) - { - if ( node->GetData() == item ) - break; - - node = node->GetNext(); - } - - // DoRemove() (unlike Remove) can only be called for existing item! - wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") ); - - ::DeleteMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1); - - if ( IsAttached() && GetMenuBar()->IsAttached() ) - // otherwise, the change won't be visible - GetMenuBar()->Refresh(); - - // and from internal data structures - return wxMenuBase::DoRemove(item); -} - -void wxMenu::SetTitle(const wxString& label) -{ - m_title = label ; - UMASetMenuTitle(MAC_WXHMENU(m_hMenu) , label , wxFont::GetDefaultEncoding() ) ; -} - -bool wxMenu::ProcessCommand(wxCommandEvent & event) -{ - bool processed = false; - - // Try the menu's event handler - if ( /* !processed && */ GetEventHandler()) - processed = GetEventHandler()->SafelyProcessEvent(event); - - // Try the window the menu was popped up from - // (and up through the hierarchy) - wxWindow *win = GetInvokingWindow(); - if ( !processed && win ) - processed = win->HandleWindowEvent(event); - - return processed; -} - -// --------------------------------------------------------------------------- -// other -// --------------------------------------------------------------------------- - -wxWindow *wxMenu::GetWindow() const -{ - if ( m_invokingWindow != NULL ) - return m_invokingWindow; - else if ( GetMenuBar() != NULL) - return (wxWindow *) GetMenuBar()->GetFrame(); - - return NULL; -} - -// 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 ) -{ - size_t pos; - wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); - for ( pos = 0; node; pos++ ) - { - if ( node->GetData()->GetId() == id ) - break; - - node = node->GetNext(); - } - - if (!node) - return 0; - - return pos + 1 ; -} - -int wxMenu::MacGetIndexFromItem( wxMenuItem *pItem ) -{ - size_t pos; - wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); - for ( pos = 0; node; pos++ ) - { - if ( node->GetData() == pItem ) - break; - - node = node->GetNext(); - } - - if (!node) - return 0; - - return pos + 1 ; -} - -void wxMenu::MacEnableMenu( bool bDoEnable ) -{ - UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , 0 , bDoEnable ) ; - - ::DrawMenuBar() ; -} - -// MacOS needs to know about submenus somewhere within this menu -// before it can be displayed, also hide special menu items -// like preferences that are handled by the OS -void wxMenu::MacBeforeDisplay( bool isSubMenu ) -{ - wxMenuItem* previousItem = NULL ; - size_t pos ; - wxMenuItemList::compatibility_iterator node; - wxMenuItem *item; - - for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++) + } + + void Check( bool check ) { - item = (wxMenuItem *)node->GetData(); - wxMenu* subMenu = item->GetSubMenu() ; - if (subMenu) - { - subMenu->MacBeforeDisplay( true ) ; - } - else // normal item + MenuItemIndex i = FindMenuItemIndex() ; + if ( i > 0 ) { - // what we do here is to hide the special items which are - // shown in the application menu anyhow -- it doesn't make - // sense to show them in their normal place as well - if ( item->GetId() == wxApp::s_macAboutMenuItemId || - item->GetId() == wxApp::s_macPreferencesMenuItemId || - item->GetId() == wxApp::s_macExitMenuItemId ) - - { - ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ), - pos + 1, kMenuItemAttrHidden, 0 ); - - // also check for a separator which was used just to - // separate this item from the others, so don't leave - // separator at the menu start or end nor 2 consecutive - // separators - wxMenuItemList::compatibility_iterator nextNode = node->GetNext(); - wxMenuItem *next = nextNode ? nextNode->GetData() : NULL; - - size_t posSeptoHide; - if ( !previousItem && next && next->IsSeparator() ) - { - // next (i.e. second as we must be first) item is - // the separator to hide - wxASSERT_MSG( pos == 0, _T("should be the menu start") ); - posSeptoHide = 2; - } - else if ( GetMenuItems().GetCount() == pos + 1 && - previousItem != NULL && - previousItem->IsSeparator() ) - { - // prev item is a trailing separator we want to hide - posSeptoHide = pos; - } - else if ( previousItem && previousItem->IsSeparator() && - next && next->IsSeparator() ) - { - // two consecutive separators, this is one too many - posSeptoHide = pos; - } - else // no separators to hide - { - posSeptoHide = 0; - } - - if ( posSeptoHide ) - { - // hide the separator as well - ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ), - posSeptoHide, - kMenuItemAttrHidden, - 0 ); - } - } + if ( check ) + ::SetItemMark( m_parentMenuRef, i, 0x12 ) ; // checkmark + else + ::SetItemMark( m_parentMenuRef, i, 0 ) ; // no mark } + } - previousItem = item ; - } - - if ( isSubMenu ) - ::InsertMenu(MAC_WXHMENU( GetHMenu()), -1); -} - -// undo all changes from the MacBeforeDisplay call -void wxMenu::MacAfterDisplay( bool isSubMenu ) -{ - if ( isSubMenu ) - ::DeleteMenu(MacGetMenuId()); - - wxMenuItemList::compatibility_iterator node; - wxMenuItem *item; - - for (node = GetMenuItems().GetFirst(); node; node = node->GetNext()) + void Hide( bool hide ) { - item = (wxMenuItem *)node->GetData(); - wxMenu* subMenu = item->GetSubMenu() ; - if (subMenu) - { - subMenu->MacAfterDisplay( true ) ; - } - else + MenuItemIndex i = FindMenuItemIndex() ; + if ( i > 0 ) { - // no need to undo hidings + if ( hide ) + ChangeMenuItemAttributes( m_parentMenuRef, i, kMenuItemAttrHidden, 0 ); + else + ChangeMenuItemAttributes( m_parentMenuRef, i, 0 , kMenuItemAttrHidden ); } - } -} - -wxInt32 wxMenu::MacHandleCommandProcess( wxMenuItem* item, int id, wxWindow* targetWindow ) -{ - OSStatus result = eventNotHandledErr ; - if (item->IsCheckable()) - item->Check( !item->IsChecked() ) ; - - if ( SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ) - result = noErr ; - else + } + + void SetLabel( const wxString& text, wxAcceleratorEntry *entry ) { - if ( targetWindow != NULL ) + MenuItemIndex i = FindMenuItemIndex() ; + if ( i > 0 ) { - wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , id); - event.SetEventObject(targetWindow); - event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); - - if ( targetWindow->HandleWindowEvent(event) ) - result = noErr ; - } + SetMenuItemTextWithCFString( m_parentMenuRef, i, wxCFStringRef(text)); + UMASetMenuItemShortcut( m_parentMenuRef, i , entry ) ; + } } - return result; -} - -wxInt32 wxMenu::MacHandleCommandUpdateStatus(wxMenuItem* WXUNUSED(item), - int id, - wxWindow* targetWindow) -{ - OSStatus result = eventNotHandledErr ; - wxUpdateUIEvent event(id); - event.SetEventObject( this ); - - bool processed = false; - - // Try the menu's event handler + + void * GetHMenuItem() { return NULL; } + + // Carbon Only + + void AttachToParent( MenuRef parentMenuRef, MenuItemIndex index ) { - wxEvtHandler *handler = GetEventHandler(); - if ( handler ) - processed = handler->ProcessEvent(event); + m_parentMenuRef = parentMenuRef; + if ( m_parentMenuRef && index > 0 ) + SetMenuItemRefCon( m_parentMenuRef, index, (URefCon) this ); } - // Try the window the menu was popped up from - // (and up through the hierarchy) - if ( !processed ) + MenuItemIndex FindMenuItemIndex() { - const wxMenuBase *menu = this; - while ( menu ) + MenuItemIndex hit = 0 ; + if ( m_parentMenuRef ) { - wxWindow *win = menu->GetInvokingWindow(); - if ( win ) + for ( MenuItemIndex i = 1 ; i <= CountMenuItems(m_parentMenuRef) ; ++i ) { - processed = win->HandleWindowEvent(event); - break; + URefCon storedRef = 0; + GetMenuItemRefCon(m_parentMenuRef, i, &storedRef ); + if ( storedRef == (URefCon) this ) + { + hit = i; + break; + } } - - menu = menu->GetParent(); } + return hit; } +protected : + MenuRef m_parentMenuRef; +} ; - if ( !processed && targetWindow != NULL) - { - processed = targetWindow->HandleWindowEvent(event); - } - - if ( processed ) - { - // if anything changed, update the changed attribute - if (event.GetSetText()) - SetLabel(id, event.GetText()); - if (event.GetSetChecked()) - Check(id, event.GetChecked()); - if (event.GetSetEnabled()) - Enable(id, event.GetEnabled()); - - result = noErr ; - } - return result; -} - -// Menu Bar - -/* - -Mac Implementation note : - -The Mac has only one global menubar, so we attempt to install the currently -active menubar from a frame, we currently don't take into account mdi-frames -which would ask for menu-merging +// +// wxMenuImpl +// -Secondly there is no mac api for changing a menubar that is not the current -menubar, so we have to wait for preparing the actual menubar until the -wxMenubar is to be used - -We can in subsequent versions use MacInstallMenuBar to provide some sort of -auto-merge for MDI in case this will be necessary - -*/ - -wxMenuBar* wxMenuBar::s_macInstalledMenuBar = NULL ; -wxMenuBar* wxMenuBar::s_macCommonMenuBar = NULL ; -bool wxMenuBar::s_macAutoWindowMenu = true ; -WXHMENU wxMenuBar::s_macWindowMenuHandle = NULL ; - -void wxMenuBar::Init() -{ - m_eventHandler = this; - m_menuBarFrame = NULL; - m_invokingWindow = (wxWindow*) NULL; -} - -wxMenuBar::wxMenuBar() -{ - Init(); -} - -wxMenuBar::wxMenuBar( long WXUNUSED(style) ) -{ - Init(); -} - -wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) +class wxMenuCarbonImpl : public wxMenuImpl { - Init(); - - m_titles.Alloc(count); - - for ( size_t i = 0; i < count; i++ ) +public : + wxMenuCarbonImpl( wxMenu* peer , MenuRef menu) : wxMenuImpl(peer), m_osxMenu(menu) { - m_menus.Append(menus[i]); - m_titles.Add(titles[i]); - - menus[i]->Attach(this); } -} -wxMenuBar::~wxMenuBar() -{ - if (s_macCommonMenuBar == this) - s_macCommonMenuBar = NULL; + virtual ~wxMenuCarbonImpl(); + - if (s_macInstalledMenuBar == this) + virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) { - ::ClearMenuBar(); - s_macInstalledMenuBar = NULL; - } -} - -void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect)) -{ - wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") ); - - DrawMenuBar(); -} - -void wxMenuBar::MacInstallMenuBar() -{ - if ( s_macInstalledMenuBar == this ) - return ; - - MenuBarHandle menubar = NULL ; - - menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ; - - ::SetMenuBar( menubar ) ; - DisposeMenuBar( menubar ) ; - MenuHandle appleMenu = NULL ; - - verify_noerr( CreateNewMenu( kwxMacAppleMenuId , 0 , &appleMenu ) ) ; - verify_noerr( SetMenuTitleWithCFString( appleMenu , CFSTR( "\x14" ) ) ); - - // Add About/Preferences separator only on OS X - // KH/RN: Separator is always present on 10.3 but not on 10.2 - // However, the change from 10.2 to 10.3 suggests it is preferred - InsertMenuItemTextWithCFString( appleMenu, - CFSTR(""), 0, kMenuItemAttrSeparator, 0); - InsertMenuItemTextWithCFString( appleMenu, - CFSTR("About..."), 0, 0, 0); - MacInsertMenu( appleMenu , 0 ) ; + // MacOS counts menu items from 1 and inserts after, therefore having the + // same effect as wx 0 based and inserting before, we must correct pos + // after however for updates to be correct - // if we have a mac help menu, clean it up before adding new items - MenuHandle helpMenuHandle ; - MenuItemIndex firstUserHelpMenuItem ; - - if ( UMAGetHelpMenuDontCreate( &helpMenuHandle , &firstUserHelpMenuItem) == noErr ) - { - for ( int i = CountMenuItems( helpMenuHandle ) ; i >= firstUserHelpMenuItem ; --i ) - DeleteMenuItem( helpMenuHandle , i ) ; - } - else - { - helpMenuHandle = NULL ; - } - - if ( wxApp::s_macPreferencesMenuItemId) - { - wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; - if ( item == NULL || !(item->IsEnabled()) ) - DisableMenuCommand( NULL , kHICommandPreferences ) ; - else - EnableMenuCommand( NULL , kHICommandPreferences ) ; - } - - // Unlike preferences which may or may not exist, the Quit item should be always - // enabled unless it is added by the application and then disabled, otherwise - // a program would be required to add an item with wxID_EXIT in order to get the - // Quit menu item to be enabled, which seems a bit burdensome. - if ( wxApp::s_macExitMenuItemId) - { - wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; - if ( item != NULL && !(item->IsEnabled()) ) - DisableMenuCommand( NULL , kHICommandQuit ) ; - else - EnableMenuCommand( NULL , kHICommandQuit ) ; - } - - wxString strippedHelpMenuTitle = wxStripMenuCodes( wxApp::s_macHelpMenuTitleName ) ; - wxString strippedTranslatedHelpMenuTitle = wxStripMenuCodes( wxString( _("&Help") ) ) ; - wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); - for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) - { - wxMenuItemList::compatibility_iterator node; - wxMenuItem *item; - wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; - wxString strippedMenuTitle = wxStripMenuCodes(m_titles[i]); - - if ( strippedMenuTitle == wxT("?") || strippedMenuTitle == strippedHelpMenuTitle || strippedMenuTitle == strippedTranslatedHelpMenuTitle ) + MenuItemIndex index = pos; + if ( pos == (size_t) -1 ) + index = CountMenuItems(m_osxMenu); + + if ( pItem->IsSeparator() ) { - for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) - { - item = (wxMenuItem *)node->GetData(); - subMenu = item->GetSubMenu() ; - if (subMenu) - { - // we don't support hierarchical menus in the help menu yet - } - else - { - if ( item->GetId() != wxApp::s_macAboutMenuItemId ) - { - // we have found a user help menu and an item other than the about item, - // so we can create the mac help menu now, if we haven't created it yet - if ( helpMenuHandle == NULL ) - { - if ( UMAGetHelpMenu( &helpMenuHandle , &firstUserHelpMenuItem) != noErr ) - { - helpMenuHandle = NULL ; - break ; - } - } - } - - if ( item->IsSeparator() ) - { - if ( helpMenuHandle ) - AppendMenuItemTextWithCFString( helpMenuHandle, - CFSTR(""), kMenuItemAttrSeparator, 0,NULL); - } - else - { - wxAcceleratorEntry* - entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; - - if ( item->GetId() == wxApp::s_macAboutMenuItemId ) - { - // this will be taken care of below - } - else - { - if ( helpMenuHandle ) - { - UMAAppendMenuItem(helpMenuHandle, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), entry); - SetMenuItemCommandID( helpMenuHandle , CountMenuItems(helpMenuHandle) , wxIdToMacCommand ( item->GetId() ) ) ; - SetMenuItemRefCon( helpMenuHandle , CountMenuItems(helpMenuHandle) , (URefCon) item ) ; - } - } - - delete entry ; - } - } - } + InsertMenuItemTextWithCFString( m_osxMenu, CFSTR(""), index, kMenuItemAttrSeparator, 0); + // now switch to the Carbon 1 based counting + index += 1 ; } - - else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) - && GetAutoWindowMenu() ) + else { - if ( MacGetWindowMenuHMenu() == NULL ) + InsertMenuItemTextWithCFString( m_osxMenu, CFSTR("placeholder"), index, 0, 0 ); + + // now switch to the Carbon 1 based counting + index += 1 ; + if ( pItem->IsSubMenu() ) { - CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; + MenuRef submenu = pItem->GetSubMenu()->GetHMenu(); + SetMenuItemHierarchicalMenu(m_osxMenu, index, submenu); + // carbon is using the title of the submenu, eg in the menubar + SetMenuTitleWithCFString(submenu, wxCFStringRef(wxStripMenuCodes(pItem->GetLabel()))); } - - MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); - if ( wm == NULL ) - break; - - // get the insertion point in the standard menu - MenuItemIndex winListStart; - GetIndMenuItemWithCommandID(wm, - kHICommandWindowListSeparator, 1, NULL, &winListStart); - - // add a separator so that the standard items and the custom items - // aren't mixed together, but only if this is the first run - OSStatus err = GetIndMenuItemWithCommandID(wm, - 'WXWM', 1, NULL, NULL); - - if ( err == menuItemNotFoundErr ) + else { - InsertMenuItemTextWithCFString( wm, - CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); + SetMenuItemCommandID( m_osxMenu, index , wxIdToMacCommand(pItem->GetId()) ) ; } - - wxInsertMenuItemsInMenu(menu, wm, winListStart); - } - else - { - UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], GetFont().GetEncoding() ) ; - menu->MacBeforeDisplay(false) ; - - ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0); } - } - - // take care of the about menu item wherever it is - { - wxMenu* aboutMenu ; - wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; - if ( aboutMenuItem ) + + wxMenuItemCarbonImpl* impl = (wxMenuItemCarbonImpl*) pItem->GetPeer(); + impl->AttachToParent( m_osxMenu, index ); + // only now can all settings be updated correctly + pItem->UpdateItemText(); + pItem->UpdateItemStatus(); + pItem->UpdateItemBitmap(); + } + + virtual void Remove( wxMenuItem *pItem ) + { + wxMenuItemCarbonImpl* impl = (wxMenuItemCarbonImpl*) pItem->GetPeer(); + if ( impl ) { - wxAcceleratorEntry* - entry = wxAcceleratorEntry::Create( aboutMenuItem->GetItemLabel() ) ; - UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetItemLabel() ) , wxFont::GetDefaultEncoding() ); - UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); - SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; - SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; - UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; + MenuItemIndex i = impl->FindMenuItemIndex(); + if ( i > 0 ) + { + DeleteMenuItem(m_osxMenu , i); + impl->AttachToParent( NULL, 0 ); + } delete entry; } } - - if ( GetAutoWindowMenu() ) + + virtual void MakeRoot() { - if ( MacGetWindowMenuHMenu() == NULL ) - CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; - - InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; + SetRootMenu( m_osxMenu ); } - ::DrawMenuBar() ; - s_macInstalledMenuBar = this; -} - -void wxMenuBar::EnableTop(size_t pos, bool enable) -{ - wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") ); - - _wxMenuAt(m_menus, pos)->MacEnableMenu( enable ) ; - Refresh(); -} - -bool wxMenuBar::Enable(bool enable) -{ - wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") ); + virtual void SetTitle( const wxString& text ) + { + SetMenuTitleWithCFString(m_osxMenu, wxCFStringRef(text)); + } - size_t i; - for (i = 0; i < GetMenuCount(); i++) - EnableTop(i, enable); + WXHMENU GetHMenu() { return m_osxMenu; } - return true; -} + static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); + static wxMenuImpl* CreateRootMenu( wxMenu* peer ); +protected : + wxCFRef m_osxMenu; +} ; -void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label) -{ - wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); - - m_titles[pos] = label; +// static const short kwxMacAppleMenuId = 1 ; - if ( !IsAttached() ) - return; +// Find an item given the Macintosh Menu Reference - _wxMenuAt(m_menus, pos)->SetTitle( label ) ; +WX_DECLARE_HASH_MAP(WXHMENU, wxMenu*, wxPointerHash, wxPointerEqual, MacMenuMap); - if (wxMenuBar::s_macInstalledMenuBar == this) // are we currently installed ? - { - ::SetMenuBar( GetMenuBar() ) ; - ::InvalMenuBar() ; - } -} +static MacMenuMap wxWinMacMenuList; -wxString wxMenuBar::GetMenuLabel(size_t pos) const +wxMenu *wxFindMenuFromMacMenu(WXHMENU inMenuRef) { - wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, - wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + MacMenuMap::iterator node = wxWinMacMenuList.find(inMenuRef); - return m_titles[pos]; + return (node == wxWinMacMenuList.end()) ? NULL : node->second; } -int wxMenuBar::FindMenu(const wxString& title) +void wxAssociateMenuWithMacMenu(WXHMENU inMenuRef, wxMenu *menu) ; +void wxAssociateMenuWithMacMenu(WXHMENU inMenuRef, wxMenu *menu) { - wxString menuTitle = wxStripMenuCodes(title); - - size_t count = GetMenuCount(); - for ( size_t i = 0; i < count; i++ ) - { - wxString title = wxStripMenuCodes(m_titles[i]); - if ( menuTitle == title ) - return i; - } + // adding NULL MenuRef is (first) surely a result of an error and + // (secondly) breaks menu command processing + wxCHECK_RET( inMenuRef != (WXHMENU) NULL, wxT("attempt to add a NULL MenuRef to menu list") ); - return wxNOT_FOUND; + wxWinMacMenuList[inMenuRef] = menu; } -// --------------------------------------------------------------------------- -// wxMenuBar construction -// --------------------------------------------------------------------------- - -wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) +void wxRemoveMacMenuAssociation(wxMenu *menu) ; +void wxRemoveMacMenuAssociation(wxMenu *menu) { - wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title); - if ( !menuOld ) - return NULL; - - m_titles[pos] = title; - - if ( IsAttached() ) + // iterate over all the elements in the class + MacMenuMap::iterator it; + for ( it = wxWinMacMenuList.begin(); it != wxWinMacMenuList.end(); ++it ) { - if (s_macInstalledMenuBar == this) + if ( it->second == menu ) { - menuOld->MacAfterDisplay( false ) ; - ::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; - - menu->MacBeforeDisplay( false ) ; - UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , GetFont().GetEncoding() ) ; - if ( pos == m_menus.GetCount() - 1) - ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ; - else - ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , _wxMenuAt(m_menus, pos + 1)->MacGetMenuId() ) ; + wxWinMacMenuList.erase(it); + break; } - - Refresh(); } - - if (m_invokingWindow) - wxMenubarSetInvokingWindow( menu, m_invokingWindow ); - - return menuOld; } -bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) +wxMenuCarbonImpl::~wxMenuCarbonImpl() { - if ( !wxMenuBarBase::Insert(pos, menu, title) ) - return false; - - m_titles.Insert(title, pos); - - UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , GetFont().GetEncoding() ) ; - - if ( IsAttached() && s_macInstalledMenuBar == this ) - { - if (s_macInstalledMenuBar == this) - { - menu->MacBeforeDisplay( false ) ; - - if ( pos == (size_t) -1 || pos + 1 == m_menus.GetCount() ) - ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ; - else - ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , _wxMenuAt(m_menus, pos+1)->MacGetMenuId() ) ; - } - - Refresh(); - } - - if (m_invokingWindow) - wxMenubarSetInvokingWindow( menu, m_invokingWindow ); - - return true; + wxRemoveMacMenuAssociation( GetWXPeer() ); } -wxMenu *wxMenuBar::Remove(size_t pos) +wxMenuImpl* wxMenuImpl::Create( wxMenu* peer, const wxString& title ) { - wxMenu *menu = wxMenuBarBase::Remove(pos); + // create the menu + static SInt16 s_macNextMenuId = 3; + WXHMENU menu = NULL; + CreateNewMenu( s_macNextMenuId++ , 0 , &menu ) ; if ( !menu ) - return NULL; - - if ( IsAttached() ) { - if (s_macInstalledMenuBar == this) - ::DeleteMenu( menu->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; - - Refresh(); + wxLogLastError(wxT("CreateNewMenu failed")); + return NULL; } - m_titles.RemoveAt(pos); - - return menu; + wxMenuImpl* c = new wxMenuCarbonImpl( peer, menu ); + c->SetTitle(title); + wxAssociateMenuWithMacMenu( menu , peer ) ; + return c; } -bool wxMenuBar::Append(wxMenu *menu, const wxString& title) -{ - WXHMENU submenu = menu ? menu->GetHMenu() : 0; - wxCHECK_MSG( submenu, false, wxT("can't append invalid menu to menubar") ); - - if ( !wxMenuBarBase::Append(menu, title) ) - return false; - - m_titles.Add(title); - - UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , GetFont().GetEncoding() ) ; - - if ( IsAttached() ) - { - if (s_macInstalledMenuBar == this) - { - menu->MacBeforeDisplay( false ) ; - ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ; - } +// +// +// - Refresh(); - } - - // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables - // adding menu later on. - if (m_invokingWindow) - wxMenubarSetInvokingWindow( menu, m_invokingWindow ); - - return true; -} - -static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) +wxMenuItemCarbonImpl::~wxMenuItemCarbonImpl() { - menu->SetInvokingWindow( (wxWindow*) NULL ); - wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); - - while (node) - { - wxMenuItem *menuitem = node->GetData(); - if (menuitem->IsSubMenu()) - wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() ); - - node = node->GetNext(); - } } -static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) -{ - menu->SetInvokingWindow( win ); - wxMenuItem *menuitem; - wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); - - while (node) - { - menuitem = node->GetData(); - if (menuitem->IsSubMenu()) - wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win ); - - node = node->GetNext(); - } -} -void wxMenuBar::UnsetInvokingWindow() +wxMenuItemImpl* wxMenuItemImpl::Create( wxMenuItem* peer, + wxMenu * WXUNUSED(pParentMenu), + int WXUNUSED(id), + const wxString& WXUNUSED(text), + wxAcceleratorEntry *WXUNUSED(entry), + const wxString& WXUNUSED(strHelp), + wxItemKind WXUNUSED(kind), + wxMenu *WXUNUSED(pSubMenu) ) { - m_invokingWindow = (wxWindow*) NULL; - wxMenu *menu; - wxMenuList::compatibility_iterator node = m_menus.GetFirst(); + wxMenuItemImpl* c = NULL; - while (node) - { - menu = node->GetData(); - wxMenubarUnsetInvokingWindow( menu ); - - node = node->GetNext(); - } + c = new wxMenuItemCarbonImpl( peer ); + return c; } -void wxMenuBar::SetInvokingWindow(wxFrame *frame) +void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter) { - m_invokingWindow = frame; - wxMenu *menu; - wxMenuList::compatibility_iterator node = m_menus.GetFirst(); + wxMenuItemList::compatibility_iterator node; + wxMenuItem *item; + wxMenu *subMenu = NULL ; + bool newItems = false; - while (node) + for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { - menu = node->GetData(); - wxMenubarSetInvokingWindow( menu, frame ); - - node = node->GetNext(); - } -} + item = (wxMenuItem *)node->GetData(); + subMenu = item->GetSubMenu() ; + if (subMenu) + { + wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0); + } + if ( item->IsSeparator() ) + { + if ( wm && newItems) + InsertMenuItemTextWithCFString( wm, + CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0); -void wxMenuBar::Detach() -{ - wxMenuBarBase::Detach() ; -} + newItems = false; + } + else + { + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; -void wxMenuBar::Attach(wxFrame *frame) -{ - wxMenuBarBase::Attach( frame ) ; -} + MenuItemIndex winListPos = (MenuItemIndex)-1; + OSStatus err = GetIndMenuItemWithCommandID(wm, + wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos); -// --------------------------------------------------------------------------- -// wxMenuBar searching for menu items -// --------------------------------------------------------------------------- + if ( wm && err == menuItemNotFoundErr ) + { + // NB: the only way to determine whether or not we should add + // a separator is to know if we've added menu items to the menu + // before the separator. + newItems = true; + UMAInsertMenuItem(wm, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), insertAfter, entry); + SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ; + SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ; + } -// Find the itemString in menuString, and return the item id or wxNOT_FOUND -int wxMenuBar::FindMenuItem(const wxString& menuString, - const wxString& itemString) const -{ - wxString menuLabel = wxStripMenuCodes(menuString); - size_t count = GetMenuCount(); - for ( size_t i = 0; i < count; i++ ) - { - wxString title = wxStripMenuCodes(m_titles[i]); - if ( menuLabel == title ) - return _wxMenuAt(m_menus, i)->FindItem(itemString); + delete entry ; + } } - - return wxNOT_FOUND; } -wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const -{ - if ( itemMenu ) - *itemMenu = NULL; - - wxMenuItem *item = NULL; - size_t count = GetMenuCount(); - for ( size_t i = 0; !item && (i < count); i++ ) - item = _wxMenuAt(m_menus, i)->FindItem(id, itemMenu); - return item; -} diff --git a/src/osx/carbon/menuitem.cpp b/src/osx/carbon/menuitem.cpp index ada8a8be84..6e6c26d3f7 100644 --- a/src/osx/carbon/menuitem.cpp +++ b/src/osx/carbon/menuitem.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/menuitem.cpp +// Name: src/osx/carbon/menuitem.cpp // Purpose: wxMenuItem implementation // Author: Stefan Csomor // Modified by: @@ -19,271 +19,7 @@ #include "wx/menu.h" #endif // WX_PRECOMP -#include "wx/osx/uma.h" +#include "wx/osx/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) - - -wxMenuItem::wxMenuItem(wxMenu *pParentMenu, - int id, - const wxString& text, - const wxString& strHelp, - wxItemKind kind, - wxMenu *pSubMenu) - :wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu) -{ - wxASSERT_MSG( id != 0 || pSubMenu != NULL , wxT("A MenuItem ID of Zero does not work under Mac") ) ; - - // In other languages there is no difference in naming the Exit/Quit menu item between MacOS and Windows guidelines - // therefore these item must not be translated - if ( wxStripMenuCodes(m_text).Upper() == wxT("EXIT") ) - m_text = wxT("Quit\tCtrl+Q") ; - - m_radioGroup.start = -1; - m_isRadioGroupStart = false; -} - -wxMenuItem::~wxMenuItem() -{ -} - -// change item state -// ----------------- - -void wxMenuItem::SetBitmap(const wxBitmap& bitmap) -{ - m_bitmap = bitmap; - UpdateItemBitmap(); -} - -void wxMenuItem::UpdateItemBitmap() -{ - if ( !m_parentMenu ) - return ; - - MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; - MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ; - DoUpdateItemBitmap( mhandle, index ); -} - -void wxMenuItem::DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) -{ - MenuHandle mhandle = (MenuHandle) menu; - - if ( mhandle == NULL || index == 0) - return ; - - if ( m_bitmap.Ok() ) - { -#if wxUSE_BMPBUTTON - ControlButtonContentInfo info ; - wxMacCreateBitmapButton( &info , m_bitmap ) ; - if ( info.contentType != kControlNoContent ) - { - if ( info.contentType == kControlContentIconRef ) - SetMenuItemIconHandle( mhandle , index , - kMenuIconRefType , (Handle) info.u.iconRef ) ; - else if ( info.contentType == kControlContentCGImageRef ) - SetMenuItemIconHandle( mhandle , index , - kMenuCGImageRefType , (Handle) info.u.imageRef ) ; - } - wxMacReleaseBitmapButton( &info ) ; -#endif - } -} - -void wxMenuItem::UpdateItemStatus() -{ - if ( !m_parentMenu ) - return ; - - if ( IsSeparator() ) - return ; - - if ( GetId() == wxApp::s_macPreferencesMenuItemId) - { - if ( !IsEnabled() ) - DisableMenuCommand( NULL , kHICommandPreferences ) ; - else - EnableMenuCommand( NULL , kHICommandPreferences ) ; - } - - if ( GetId() == wxApp::s_macExitMenuItemId) - { - if ( !IsEnabled() ) - DisableMenuCommand( NULL , kHICommandQuit ) ; - else - EnableMenuCommand( NULL , kHICommandQuit ) ; - } - - { - MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; - MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ; - if ( mhandle == NULL || index == 0) - return ; - - UMAEnableMenuItem( mhandle , index , m_isEnabled ) ; - if ( IsCheckable() && IsChecked() ) - ::SetItemMark( mhandle , index , 0x12 ) ; // checkmark - else - ::SetItemMark( mhandle , index , 0 ) ; // no mark - - UMASetMenuItemText( mhandle , index , wxStripMenuCodes(m_text) , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; - UMASetMenuItemShortcut( mhandle , index , entry ) ; - delete entry ; - } -} - -void wxMenuItem::UpdateItemText() -{ - if ( !m_parentMenu ) - return ; - - MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; - MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ; - if (mhandle == NULL || index == 0) - return ; - - wxString text = m_text; - if (text.IsEmpty() && !IsSeparator()) - { - wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); - text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); - } - - UMASetMenuItemText( mhandle , index , wxStripMenuCodes(text) , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( text ) ; - UMASetMenuItemShortcut( mhandle , index , entry ) ; - delete entry ; -} - -void wxMenuItem::Enable(bool bDoEnable) -{ - if (( m_isEnabled != bDoEnable - // avoid changing menuitem state when menu is disabled - // eg. BeginAppModalStateForWindow() will disable menus and ignore this change - // which in turn causes m_isEnabled to become out of sync with real menuitem state - && !(m_parentMenu && !IsMenuItemEnabled(MAC_WXHMENU(m_parentMenu->GetHMenu()), 0)) ) - // always update builtin menuitems - || ( GetId() == wxApp::s_macPreferencesMenuItemId - || GetId() == wxApp::s_macExitMenuItemId - || GetId() == wxApp::s_macAboutMenuItemId - )) - { - wxMenuItemBase::Enable( bDoEnable ) ; - UpdateItemStatus() ; - } -} - -void wxMenuItem::UncheckRadio() -{ - if ( m_isChecked ) - { - wxMenuItemBase::Check( false ) ; - UpdateItemStatus() ; - } -} - -void wxMenuItem::Check(bool bDoCheck) -{ - wxCHECK_RET( IsCheckable() && !IsSeparator(), wxT("only checkable items may be checked") ); - - if ( m_isChecked != bDoCheck ) - { - if ( GetKind() == wxITEM_RADIO ) - { - if ( bDoCheck ) - { - wxMenuItemBase::Check( bDoCheck ) ; - UpdateItemStatus() ; - - // get the index of this item in the menu - const wxMenuItemList& items = m_parentMenu->GetMenuItems(); - int pos = items.IndexOf(this); - wxCHECK_RET( pos != wxNOT_FOUND, - _T("menuitem not found in the menu items list?") ); - - // get the radio group range - int start, end; - - if ( m_isRadioGroupStart ) - { - // we already have all information we need - start = pos; - end = m_radioGroup.end; - } - else // next radio group item - { - // get the radio group end from the start item - start = m_radioGroup.start; - end = items.Item(start)->GetData()->m_radioGroup.end; - } - - // also uncheck all the other items in this radio group - wxMenuItemList::compatibility_iterator node = items.Item(start); - for ( int n = start; n <= end && node; n++ ) - { - if ( n != pos ) - ((wxMenuItem*)node->GetData())->UncheckRadio(); - - node = node->GetNext(); - } - } - } - else - { - wxMenuItemBase::Check( bDoCheck ) ; - UpdateItemStatus() ; - } - } -} - -void wxMenuItem::SetItemLabel(const wxString& text) -{ - // don't do anything if label didn't change - if ( m_text == text ) - return; - - wxMenuItemBase::SetItemLabel(text); - - UpdateItemText() ; -} - -// radio group stuff -// ----------------- - -void wxMenuItem::SetAsRadioGroupStart() -{ - m_isRadioGroupStart = true; -} - -void wxMenuItem::SetRadioGroupStart(int start) -{ - wxASSERT_MSG( !m_isRadioGroupStart, - wxT("should only be called for the next radio items") ); - - m_radioGroup.start = start; -} - -void wxMenuItem::SetRadioGroupEnd(int end) -{ - wxASSERT_MSG( m_isRadioGroupStart, - wxT("should only be called for the first radio item") ); - - m_radioGroup.end = end; -} - -// ---------------------------------------------------------------------------- -// wxMenuItemBase -// ---------------------------------------------------------------------------- - -wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, - int id, - const wxString& name, - const wxString& help, - wxItemKind kind, - wxMenu *subMenu) -{ - return new wxMenuItem(parentMenu, id, name, help, kind, subMenu); -} +// because on mac carbon everything is done through MenuRef APIs both implementation +// classes are in menu.cpp diff --git a/src/osx/carbon/metafile.cpp b/src/osx/carbon/metafile.cpp index 464cd9ae63..a671b772b5 100644 --- a/src/osx/carbon/metafile.cpp +++ b/src/osx/carbon/metafile.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/metafile.cpp +// Name: src/osx/carbon/metafile.cpp // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional. // Author: Stefan Csomor // Modified by: @@ -24,7 +24,7 @@ #include "wx/metafile.h" #include "wx/clipbrd.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include "wx/graphics.h" #include "wx/osx/carbon/metafile.h" diff --git a/src/osx/carbon/mimetmac.cpp b/src/osx/carbon/mimetmac.cpp index 4bf9a586c2..586b6e0c83 100644 --- a/src/osx/carbon/mimetmac.cpp +++ b/src/osx/carbon/mimetmac.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/mimetype.cpp +// Name: src/osx/carbon/mimetype.cpp // Purpose: Mac Carbon implementation for wx MIME-related classes // Author: Ryan Norton // Modified by: diff --git a/src/osx/carbon/msgdlg.cpp b/src/osx/carbon/msgdlg.cpp index 3adc6bbca4..a0aaaf36da 100644 --- a/src/osx/carbon/msgdlg.cpp +++ b/src/osx/carbon/msgdlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/msgdlg.cpp +// Name: src/osx/carbon/msgdlg.cpp // Purpose: wxMessageDialog // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/nonownedwnd.cpp b/src/osx/carbon/nonownedwnd.cpp index 8a5b11cd8b..7f0cbbdc9b 100644 --- a/src/osx/carbon/nonownedwnd.cpp +++ b/src/osx/carbon/nonownedwnd.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/nonownedwnd.cpp +// Name: src/osx/carbon/nonownedwnd.cpp // Purpose: implementation of wxNonOwnedWindow // Author: Stefan Csomor // Created: 2008-03-24 @@ -28,374 +28,15 @@ #include "wx/sysopt.h" #endif -// -// TODO BEGIN move to nonowned_osx.cpp -// - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -// trace mask for activation tracing messages -#define TRACE_ACTIVATE "activation" - -wxWindow* g_MacLastWindow = NULL ; +// ============================================================================ +// wxNonOwnedWindow implementation +// ============================================================================ // unified title and toolbar constant - not in Tiger headers, so we duplicate it here #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) -// --------------------------------------------------------------------------- -// wxWindowMac utility functions -// --------------------------------------------------------------------------- - -// Find an item given the Macintosh Window Reference - -WX_DECLARE_HASH_MAP(WXWindow, wxNonOwnedWindow*, wxPointerHash, wxPointerEqual, MacWindowMap); - -static MacWindowMap wxWinMacWindowList; - -wxNonOwnedWindow *wxFindWindowFromWXWindow(WXWindow inWindowRef) -{ - MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); - - return (node == wxWinMacWindowList.end()) ? NULL : node->second; -} - -void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) ; -void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) -{ - // adding NULL WindowRef is (first) surely a result of an error and - // nothing else :-) - wxCHECK_RET( inWindowRef != (WXWindow) NULL, wxT("attempt to add a NULL WindowRef to window list") ); - - wxWinMacWindowList[inWindowRef] = win; -} - -void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) ; -void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) -{ - MacWindowMap::iterator it; - for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) - { - if ( it->second == win ) - { - wxWinMacWindowList.erase(it); - break; - } - } -} - -wxNonOwnedWindow* wxNonOwnedWindow::GetFromWXWindow( WXWindow win ) -{ - return wxFindWindowFromWXWindow( win ); -} - -// ---------------------------------------------------------------------------- -// wxNonOwnedWindow creation -// ---------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl , wxObject ) - -wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL; - -void wxNonOwnedWindow::Init() -{ - m_nowpeer = NULL; -} - -bool wxNonOwnedWindow::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - // init our fields - Init(); - - m_windowStyle = style; - - SetName( name ); - - m_windowId = id == -1 ? NewControlId() : id; - m_windowStyle = style; - m_isShown = false; - - // create frame. - int x = (int)pos.x; - int y = (int)pos.y; - - wxRect display = wxGetClientDisplayRect() ; - - if ( x == wxDefaultPosition.x ) - x = display.x ; - - if ( y == wxDefaultPosition.y ) - y = display.y ; - - int w = WidthDefault(size.x); - int h = HeightDefault(size.y); - - // temporary define, TODO -#if wxOSX_USE_CARBON - m_nowpeer = new wxNonOwnedWindowCarbonImpl( this ); -#elif wxOSX_USE_COCOA - m_nowpeer = new wxNonOwnedWindowCocoaImpl( this ); -#elif wxOSX_USE_IPHONE - m_nowpeer = new wxNonOwnedWindowIPhoneImpl( this ); -#endif - - m_nowpeer->Create( parent, wxPoint(x,y) , wxSize(w,h) , style , GetExtraStyle(), name ) ; - wxAssociateWindowWithWXWindow( m_nowpeer->GetWXWindow() , this ) ; -#if wxOSX_USE_CARBON - // temporary cast, TODO - m_peer = (wxMacControl*) wxWidgetImpl::CreateContentView(this); -#else - m_peer = wxWidgetImpl::CreateContentView(this); -#endif - - DoSetWindowVariant( m_windowVariant ) ; - - wxWindowCreateEvent event(this); - HandleWindowEvent(event); - - SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); - - if ( parent ) - parent->AddChild(this); - - return true; -} - -wxNonOwnedWindow::~wxNonOwnedWindow() -{ - wxRemoveWXWindowAssociation( this ) ; - if ( m_nowpeer ) - m_nowpeer->Destroy(); - - // avoid dangling refs - if ( s_macDeactivateWindow == this ) - s_macDeactivateWindow = NULL; -} - -// ---------------------------------------------------------------------------- -// wxNonOwnedWindow misc -// ---------------------------------------------------------------------------- - -bool wxNonOwnedWindow::ShowWithEffect(wxShowEffect effect, - unsigned timeout ) -{ - if ( !wxWindow::Show(true) ) - return false; - - // because apps expect a size event to occur at this moment - wxSizeEvent event(GetSize() , m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - - - return m_nowpeer->ShowWithEffect(true, effect, timeout); -} - -bool wxNonOwnedWindow::HideWithEffect(wxShowEffect effect, - unsigned timeout ) -{ - if ( !wxWindow::Show(false) ) - return false; - - return m_nowpeer->ShowWithEffect(false, effect, timeout); -} - -wxPoint wxNonOwnedWindow::GetClientAreaOrigin() const -{ - int left, top, width, height; - m_nowpeer->GetContentArea(left, top, width, height); - return wxPoint(left, top); -} - -bool wxNonOwnedWindow::SetBackgroundColour(const wxColour& c ) -{ - if ( !wxWindow::SetBackgroundColour(c) && m_hasBgCol ) - return false ; - - if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM ) - { - return m_nowpeer->SetBackgroundColour(c); - } - return true; -} - -// Raise the window to the top of the Z order -void wxNonOwnedWindow::Raise() -{ - m_nowpeer->Raise(); -} - -// Lower the window to the bottom of the Z order -void wxNonOwnedWindow::Lower() -{ - m_nowpeer->Lower(); -} - -void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp) -{ - if (s_macDeactivateWindow) - { - wxLogTrace(TRACE_ACTIVATE, - wxT("Doing delayed deactivation of %p"), - s_macDeactivateWindow); - - s_macDeactivateWindow->MacActivate(timestamp, false); - } -} - -void wxNonOwnedWindow::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) ) -{ - wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this); - - if (s_macDeactivateWindow == this) - s_macDeactivateWindow = NULL; - - MacDelayedDeactivation(timestamp); -} - -bool wxNonOwnedWindow::Show(bool show) -{ - if ( !wxWindow::Show(show) ) - return false; - - if ( m_nowpeer ) - m_nowpeer->Show(show); - - if ( show ) - { - // because apps expect a size event to occur at this moment - wxSizeEvent event(GetSize() , m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - } - - return true ; -} - -bool wxNonOwnedWindow::SetTransparent(wxByte alpha) -{ - return m_nowpeer->SetTransparent(alpha); -} - - -bool wxNonOwnedWindow::CanSetTransparent() -{ - return m_nowpeer->CanSetTransparent(); -} - - -void wxNonOwnedWindow::SetExtraStyle(long exStyle) -{ - if ( GetExtraStyle() == exStyle ) - return ; - - wxWindow::SetExtraStyle( exStyle ) ; - - if ( m_nowpeer ) - m_nowpeer->SetExtraStyle(exStyle); -} - -bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style) -{ - if ( !wxWindow::SetBackgroundStyle(style) ) - return false ; - - return m_nowpeer->SetBackgroundStyle(style); -} - -void wxNonOwnedWindow::DoMoveWindow(int x, int y, int width, int height) -{ - m_cachedClippedRectValid = false ; - - m_nowpeer->MoveWindow(x, y, width, height); - wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified -} - -void wxNonOwnedWindow::DoGetPosition( int *x, int *y ) const -{ - int x1,y1 ; - m_nowpeer->GetPosition(x1, y1); - - if (x) - *x = x1 ; - if (y) - *y = y1 ; -} - -void wxNonOwnedWindow::DoGetSize( int *width, int *height ) const -{ - int w,h; - - m_nowpeer->GetSize(w, h); - - if (width) - *width = w ; - if (height) - *height = h ; -} - -void wxNonOwnedWindow::DoGetClientSize( int *width, int *height ) const -{ - int left, top, w, h; - m_nowpeer->GetContentArea(left, top, w, h); - - if (width) - *width = w ; - if (height) - *height = h ; -} - - -void wxNonOwnedWindow::Update() -{ - m_nowpeer->Update(); -} - -WXWindow wxNonOwnedWindow::GetWXWindow() const -{ - return m_nowpeer ? m_nowpeer->GetWXWindow() : NULL; -} - -// --------------------------------------------------------------------------- -// Shape implementation -// --------------------------------------------------------------------------- - - -bool wxNonOwnedWindow::SetShape(const wxRegion& region) -{ - wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, - _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); - - // The empty region signifies that the shape - // should be removed from the window. - if ( region.IsEmpty() ) - { - wxSize sz = GetClientSize(); - wxRegion rgn(0, 0, sz.x, sz.y); - if ( rgn.IsEmpty() ) - return false ; - else - return SetShape(rgn); - } - - return m_nowpeer->SetShape(region); -} - -// -// TODO END move to nonowned_osx.cpp -// - -#if wxOSX_USE_CARBON - IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl , wxNonOwnedWindowImpl ) - WXWindow wxNonOwnedWindowCarbonImpl::GetWXWindow() const { return (WXWindow) m_macWindow; @@ -585,7 +226,10 @@ void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set ) // for wx. // TODO: Determine if we need this on Leopard as well. (should be harmless either way, // though) + // since when creating the peering is not yet completely set-up we call both setters + // explicitely m_wxPeer->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; + SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; } @@ -595,12 +239,6 @@ void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set ) static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); -// ============================================================================ -// wxNonOwnedWindow implementation -// ============================================================================ - -// unified title and toolbar constant - not in Tiger headers, so we duplicate it here -#define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) // --------------------------------------------------------------------------- // Carbon Events @@ -1036,6 +674,18 @@ wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), ::HiliteMenu(0); result = noErr ; } + } + else if ( window && windowPart == inProxyIcon ) + { + // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves + if ( cEvent.GetKind() == kEventMouseDown ) + { + if ( ::TrackWindowProxyDrag( window, screenMouseLocation ) != errUserWantsToDragWindow ) + { + // TODO Track change of file path and report back + result = noErr ; + } + } } else if ( currentMouseWindow ) { @@ -1138,22 +788,14 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), { case kEventWindowActivated : { - toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; - wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); - wxevent.SetTimestamp( cEvent.GetTicks() ) ; - wxevent.SetEventObject(toplevelWindow); - toplevelWindow->HandleWindowEvent(wxevent); + toplevelWindow->HandleActivated( cEvent.GetTicks() , true) ; // we still sending an eventNotHandledErr in order to allow for default processing } break ; case kEventWindowDeactivated : { - toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; - wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); - wxevent.SetTimestamp( cEvent.GetTicks() ) ; - wxevent.SetEventObject(toplevelWindow); - toplevelWindow->HandleWindowEvent(wxevent); + toplevelWindow->HandleActivated( cEvent.GetTicks() , false) ; // we still sending an eventNotHandledErr in order to allow for default processing } break ; @@ -1175,27 +817,12 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; if ( attributes & kWindowBoundsChangeSizeChanged ) { -#ifndef __WXUNIVERSAL__ - // according to the other ports we handle this within the OS level - // resize event, not within a wxSizeEvent - wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; - if ( frame ) - { - frame->PositionBars(); - } -#endif - wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; - event.SetEventObject( toplevelWindow ) ; - - toplevelWindow->HandleWindowEvent(event) ; - toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified + toplevelWindow->HandleResized(cEvent.GetTicks() ) ; } if ( attributes & kWindowBoundsChangeOriginChanged ) { - wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; - event.SetEventObject( toplevelWindow ) ; - toplevelWindow->HandleWindowEvent(event) ; + toplevelWindow->HandleMoved(cEvent.GetTicks() ) ; } result = noErr ; @@ -1214,31 +841,17 @@ wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), toplevelWindow->GetNonOwnedPeer()->GetContentArea(left, top, right, bottom); - wxRect r( + wxRect adjustR( newRect.left - left, newRect.top - top, newRect.right - newRect.left + left + right, newRect.bottom - newRect.top + top + bottom ) ; - // this is a EVT_SIZING not a EVT_SIZE type ! - wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; - wxevent.SetEventObject( toplevelWindow ) ; - wxRect adjustR = r ; - if ( toplevelWindow->HandleWindowEvent(wxevent) ) - adjustR = wxevent.GetRect() ; - - if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) - adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; - if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) - adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; - if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) - adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; - if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) - adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; + toplevelWindow->HandleResizing( cEvent.GetTicks(), &adjustR ); + const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; if ( !EqualRect( &newRect , &adjustedRect ) ) cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; - toplevelWindow->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified } result = noErr ; @@ -1292,7 +905,12 @@ pascal OSStatus wxNonOwnedEventHandler( EventHandlerCallRef handler , EventRef e switch ( GetEventClass( event ) ) { case kEventClassTextInput : - result = wxMacUnicodeTextEventHandler( handler, event , data ) ; + { + // TODO remove as soon as all events are on implementation classes only + wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL; + + result = wxMacUnicodeTextEventHandler( handler, event , toplevelWindow ) ; + } break ; case kEventClassKeyboard : @@ -1498,6 +1116,12 @@ wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl() void wxNonOwnedWindowCarbonImpl::Destroy() { + if ( m_macEventHandler ) + { + ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); + m_macEventHandler = NULL ; + } + wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ) ; } @@ -2014,4 +1638,11 @@ void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y ) if ( y ) *y = p.y; } -#endif // wxOSX_USE_CARBON + +wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, + long style, long extraStyle, const wxString& name ) +{ + wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer ); + now->Create( parent, pos, size, style , extraStyle, name ); + return now; +} diff --git a/src/osx/carbon/notebmac.cpp b/src/osx/carbon/notebmac.cpp index c534473ad4..6119fbde1e 100644 --- a/src/osx/carbon/notebmac.cpp +++ b/src/osx/carbon/notebmac.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/notebmac.cpp +// Name: src/osx/carbon/notebmac.cpp // Purpose: implementation of wxNotebook // Author: Stefan Csomor // Modified by: @@ -24,64 +24,21 @@ #include "wx/string.h" #include "wx/imaglist.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" // check that the page index is valid #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) -BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) - EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) - - EVT_SIZE(wxNotebook::OnSize) - EVT_SET_FOCUS(wxNotebook::OnSetFocus) - EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) -END_EVENT_TABLE() - -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) - - -// common part of all ctors -void wxNotebook::Init() -{ - m_nSelection = -1; -} - -// default for dynamic class -wxNotebook::wxNotebook() -{ - Init(); -} - -// the same arguments as for wxControl -wxNotebook::wxNotebook( wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) +wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - Init(); - - Create( parent, id, pos, size, style, name ); -} - -bool wxNotebook::Create( wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) -{ - m_macIsUserPane = false ; - - if (! (style & wxBK_ALIGN_MASK)) - style |= wxBK_TOP; - - if ( !wxNotebookBase::Create( parent, id, pos, size, style, name ) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); if ( bounds.right <= bounds.left ) bounds.right = bounds.left + 100; @@ -89,15 +46,15 @@ bool wxNotebook::Create( wxWindow *parent, bounds.bottom = bounds.top + 100; UInt16 tabstyle = kControlTabDirectionNorth; - if ( HasFlag(wxBK_LEFT) ) + if ( style & wxBK_LEFT ) tabstyle = kControlTabDirectionWest; - else if ( HasFlag( wxBK_RIGHT ) ) + else if ( style & wxBK_RIGHT ) tabstyle = kControlTabDirectionEast; - else if ( HasFlag( wxBK_BOTTOM ) ) + else if ( style & wxBK_BOTTOM ) tabstyle = kControlTabDirectionSouth; ControlTabSize tabsize; - switch (GetWindowVariant()) + switch (wxpeer->GetWindowVariant()) { case wxWINDOW_VARIANT_MINI: tabsize = 3 ; @@ -112,211 +69,20 @@ bool wxNotebook::Create( wxWindow *parent, break; } - m_peer = new wxMacControl( this ); + wxMacControl* peer = new wxMacControl( wxpeer ); OSStatus err = CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, - tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() ); + tabsize, tabstyle, 0, NULL, peer->GetControlRefAddr() ); verify_noerr( err ); - MacPostControlCreate( pos, size ); - - return true ; + return peer; } -// dtor -wxNotebook::~wxNotebook() -{ -} - -// ---------------------------------------------------------------------------- -// wxNotebook accessors -// ---------------------------------------------------------------------------- - -void wxNotebook::SetPadding(const wxSize& WXUNUSED(padding)) -{ - // unsupported by OS -} - -void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz)) -{ - // unsupported by OS -} - -void wxNotebook::SetPageSize(const wxSize& size) -{ - SetSize( CalcSizeFromPage( size ) ); -} - -wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const -{ - return DoGetSizeFromClientSize( sizePage ); -} - -int wxNotebook::DoSetSelection(size_t nPage, int flags) -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") ); - - if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) - { - if ( flags & SetSelection_SendEvent ) - { - if ( !SendPageChangingEvent(nPage) ) - { - // vetoed by program - return m_nSelection; - } - //else: program allows the page change - - SendPageChangedEvent(m_nSelection, nPage); - } - - ChangePage(m_nSelection, nPage); - } - //else: no change - - return m_nSelection; -} - -bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") ); - - wxNotebookPage *page = m_pages[nPage]; - page->SetLabel(wxStripMenuCodes(strText)); - MacSetupTabs(); - - return true; -} - -wxString wxNotebook::GetPageText(size_t nPage) const -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("GetPageText: invalid notebook page") ); - - wxNotebookPage *page = m_pages[nPage]; - - return page->GetLabel(); -} - -int wxNotebook::GetPageImage(size_t nPage) const -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("GetPageImage: invalid notebook page") ); - - return m_images[nPage]; -} - -bool wxNotebook::SetPageImage(size_t nPage, int nImage) -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), false, - wxT("SetPageImage: invalid notebook page") ); - wxCHECK_MSG( m_imageList && nImage < m_imageList->GetImageCount(), false, - wxT("SetPageImage: invalid image index") ); - - if ( nImage != m_images[nPage] ) - { - // if the item didn't have an icon before or, on the contrary, did have - // it but has lost it now, its size will change - but if the icon just - // changes, it won't - m_images[nPage] = nImage; - - MacSetupTabs() ; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// wxNotebook operations -// ---------------------------------------------------------------------------- - -// remove one page from the notebook, without deleting the window -wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage) -{ - wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, - wxT("DoRemovePage: invalid notebook page") ); - - wxNotebookPage* page = m_pages[nPage] ; - m_pages.RemoveAt(nPage); - - MacSetupTabs(); - - if (m_nSelection >= (int)GetPageCount()) - m_nSelection = GetPageCount() - 1; - - if (m_nSelection >= 0) - m_pages[m_nSelection]->Show(true); - - InvalidateBestSize(); - - return page; -} - -// remove all pages -bool wxNotebook::DeleteAllPages() -{ - WX_CLEAR_ARRAY(m_pages) ; - MacSetupTabs(); - m_nSelection = -1 ; - InvalidateBestSize(); - - return true; -} - -// same as AddPage() but does it at given position -bool wxNotebook::InsertPage(size_t nPage, - wxNotebookPage *pPage, - const wxString& strText, - bool bSelect, - int imageId ) -{ - if ( !wxNotebookBase::InsertPage( nPage, pPage, strText, bSelect, imageId ) ) - return false; - - wxASSERT_MSG( pPage->GetParent() == this, wxT("notebook pages must have notebook as parent") ); - - // don't show pages by default (we'll need to adjust their size first) - pPage->Show( false ) ; - - pPage->SetLabel( wxStripMenuCodes(strText) ); - - m_images.Insert( imageId, nPage ); - - MacSetupTabs(); - wxRect rect = GetPageRect() ; - pPage->SetSize( rect ); - if ( pPage->GetAutoLayout() ) - pPage->Layout(); - // now deal with the selection - // --------------------------- - // if the inserted page is before the selected one, we must update the - // index of the selected page - - if ( int(nPage) <= m_nSelection ) - { - m_nSelection++; - - // while this still is the same page showing, we need to update the tabs - m_peer->SetValue( m_nSelection + 1 ) ; - } - - // some page should be selected: either this one or the first one if there - // is still no selection - int selNew = -1; - if ( bSelect ) - selNew = nPage; - else if ( m_nSelection == -1 ) - selNew = 0; - - if ( selNew != -1 ) - SetSelection( selNew ); - - InvalidateBestSize(); - - return true; -} +/* int wxNotebook::HitTest(const wxPoint& pt, long * flags) const { int resultV = wxNOT_FOUND; @@ -375,39 +141,41 @@ int wxNotebook::HitTest(const wxPoint& pt, long * flags) const return resultV; } +*/ // Added by Mark Newsam // When a page is added or deleted to the notebook this function updates // information held in the control so that it matches the order // the user would expect. // -void wxNotebook::MacSetupTabs() + +void wxMacControl::SetupTabs( const wxNotebook& notebook) { - m_peer->SetMaximum( GetPageCount() ) ; + const size_t countPages = notebook.GetPageCount(); + SetMaximum( countPages ) ; wxNotebookPage *page; ControlTabInfoRecV1 info; - const size_t countPages = GetPageCount(); for (size_t ii = 0; ii < countPages; ii++) { - page = m_pages[ii]; + page = (wxNotebookPage*) notebook.GetPage(ii); info.version = kControlTabInfoVersionOne; info.iconSuiteID = 0; - wxCFStringRef cflabel( page->GetLabel(), GetFont().GetEncoding() ) ; + wxCFStringRef cflabel( page->GetLabel(), page->GetFont().GetEncoding() ) ; info.name = cflabel ; - m_peer->SetData( ii + 1, kControlTabInfoTag, &info ) ; + SetData( ii + 1, kControlTabInfoTag, &info ) ; - if ( GetImageList() && GetPageImage(ii) >= 0 ) + if ( notebook.GetImageList() && notebook.GetPageImage(ii) >= 0 ) { - const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ; + const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( ii ) ) ; if ( bmap.Ok() ) { ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info, bmap ) ; - OSStatus err = m_peer->SetData( ii + 1, kControlTabImageContentTag, &info ); + OSStatus err = SetData( ii + 1, kControlTabImageContentTag, &info ); if ( err != noErr ) { wxFAIL_MSG("Error when setting icon on tab"); @@ -416,201 +184,8 @@ void wxNotebook::MacSetupTabs() wxMacReleaseBitmapButton( &info ) ; } } - - m_peer->SetTabEnabled( ii + 1, true ) ; - } - - Refresh(); -} - -wxRect wxNotebook::GetPageRect() const -{ - wxSize size = GetClientSize() ; - - return wxRect( 0 , 0 , size.x , size.y ) ; -} - -// ---------------------------------------------------------------------------- -// wxNotebook callbacks -// ---------------------------------------------------------------------------- - -// @@@ OnSize() is used for setting the font when it's called for the first -// time because doing it in ::Create() doesn't work (for unknown reasons) -void wxNotebook::OnSize(wxSizeEvent& event) -{ - unsigned int nCount = m_pages.Count(); - wxRect rect = GetPageRect() ; - - for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) - { - wxNotebookPage *pPage = m_pages[nPage]; - pPage->SetSize(rect); - if ( pPage->GetAutoLayout() ) - pPage->Layout(); + SetTabEnabled( ii + 1, true ) ; } - - // Processing continues to next OnSize - event.Skip(); -} - -void wxNotebook::OnSelChange(wxBookCtrlEvent& event) -{ - // is it our tab control? - if ( event.GetEventObject() == this ) - ChangePage(event.GetOldSelection(), event.GetSelection()); - - // we want to give others a chance to process this message as well - event.Skip(); -} - -void wxNotebook::OnSetFocus(wxFocusEvent& event) -{ - // set focus to the currently selected page if any - if ( m_nSelection != -1 ) - m_pages[m_nSelection]->SetFocus(); - - event.Skip(); -} - -void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) -{ - if ( event.IsWindowChange() ) - { - // change pages - AdvanceSelection( event.GetDirection() ); - } - else - { - // we get this event in 2 cases - // - // a) one of our pages might have generated it because the user TABbed - // out from it in which case we should propagate the event upwards and - // our parent will take care of setting the focus to prev/next sibling - // - // or - // - // b) the parent panel wants to give the focus to us so that we - // forward it to our selected page. We can't deal with this in - // OnSetFocus() because we don't know which direction the focus came - // from in this case and so can't choose between setting the focus to - // first or last panel child - wxWindow *parent = GetParent(); - - // the cast is here to fix a GCC ICE - if ( ((wxWindow*)event.GetEventObject()) == parent ) - { - // no, it doesn't come from child, case (b): forward to a page - if ( m_nSelection != -1 ) - { - // so that the page knows that the event comes from it's parent - // and is being propagated downwards - event.SetEventObject( this ); - - wxWindow *page = m_pages[m_nSelection]; - if ( !page->HandleWindowEvent( event ) ) - { - page->SetFocus(); - } - //else: page manages focus inside it itself - } - else - { - // we have no pages - still have to give focus to _something_ - SetFocus(); - } - } - else - { - // it comes from our child, case (a), pass to the parent - if ( parent ) - { - event.SetCurrentFocus( this ); - parent->HandleWindowEvent( event ); - } - } - } -} - -// ---------------------------------------------------------------------------- -// wxNotebook base class virtuals -// ---------------------------------------------------------------------------- - -#if wxUSE_CONSTRAINTS - -// override these 2 functions to do nothing: everything is done in OnSize - -void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) -{ - // don't set the sizes of the pages - their correct size is not yet known - wxControl::SetConstraintSizes( false ); -} - -bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) -{ - return true; -} - -#endif // wxUSE_CONSTRAINTS - -void wxNotebook::Command(wxCommandEvent& WXUNUSED(event)) -{ - wxFAIL_MSG(wxT("wxNotebook::Command not implemented")); -} - -// ---------------------------------------------------------------------------- -// wxNotebook helper functions -// ---------------------------------------------------------------------------- - -// hide the currently active panel and show the new one -void wxNotebook::ChangePage(int nOldSel, int nSel) -{ - if (nOldSel == nSel) - return; - - if ( nOldSel != -1 ) - m_pages[nOldSel]->Show( false ); - - if ( nSel != -1 ) - { - wxNotebookPage *pPage = m_pages[nSel]; - pPage->Show( true ); - pPage->SetFocus(); - } - - m_nSelection = nSel; - m_peer->SetValue( m_nSelection + 1 ) ; -} - -wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - OSStatus status = eventNotHandledErr ; - - SInt32 newSel = m_peer->GetValue() - 1 ; - if ( newSel != m_nSelection ) - { - wxBookCtrlEvent changing( - wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, - newSel , m_nSelection ); - changing.SetEventObject( this ); - HandleWindowEvent( changing ); - - if ( changing.IsAllowed() ) - { - wxBookCtrlEvent event( - wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, - newSel, m_nSelection ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - } - else - { - m_peer->SetValue( m_nSelection + 1 ) ; - } - - status = noErr ; - } - - return (wxInt32)status ; } #endif diff --git a/src/osx/carbon/overlay.cpp b/src/osx/carbon/overlay.cpp index 0cdcf578df..70a73399ee 100644 --- a/src/osx/carbon/overlay.cpp +++ b/src/osx/carbon/overlay.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/overlay.cpp +// Name: src/osx/carbon/overlay.cpp // Purpose: common wxOverlay code // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/popupwin.cpp b/src/osx/carbon/popupwin.cpp index 4889db8958..299d903862 100644 --- a/src/osx/carbon/popupwin.cpp +++ b/src/osx/carbon/popupwin.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/popupwin.cpp +// Name: src/osx/popupwin.cpp // Purpose: implements wxPopupWindow for wxMac // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/printdlg.cpp b/src/osx/carbon/printdlg.cpp index f7d1d1df67..28a6e24338 100644 --- a/src/osx/carbon/printdlg.cpp +++ b/src/osx/carbon/printdlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/printdlg.cpp +// Name: src/osx/carbon/printdlg.cpp // Purpose: wxPrintDialog, wxPageSetupDialog // Author: Stefan Csomor // Modified by: @@ -84,9 +84,7 @@ int wxMacPrintDialog::ShowModal() int result = wxID_CANCEL; -#ifdef __LP64__ - // TODO use NSPrintPanel -#else +#if wxOSX_USE_CARBON OSErr err = noErr; Boolean accepted; err = PMSessionPrintDialog( @@ -120,6 +118,8 @@ int wxMacPrintDialog::ShowModal() m_printDialogData.GetPrintData().ConvertFromNative(); ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData ); } +#else + // TODO use NSPrintPanel #endif return result; } @@ -162,8 +162,7 @@ int wxMacPageSetupDialog::ShowModal() ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData ); int result = wxID_CANCEL; -#ifdef __LP64__ -#else +#if wxOSX_USE_CARBON OSErr err = noErr; Boolean accepted; @@ -200,6 +199,8 @@ int wxMacPageSetupDialog::ShowModal() m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() ); ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferTo( &m_pageSetupData ); } +#else + // TODO #endif return result; } diff --git a/src/osx/carbon/radiobut.cpp b/src/osx/carbon/radiobut.cpp index 3fa8079c7b..38730a0b27 100644 --- a/src/osx/carbon/radiobut.cpp +++ b/src/osx/carbon/radiobut.cpp @@ -1,11 +1,11 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: radiobut.cpp +// Name: src/osx/carbon/radiobut.cpp // Purpose: wxRadioButton -// Author: AUTHOR +// Author: Stefan Csomor // Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox -// Created: ??/??/98 +// Created: 01/01/98 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR +// Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -14,165 +14,25 @@ #if wxUSE_RADIOBTN #include "wx/radiobut.h" -#include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) - - -bool wxRadioButton::Create( wxWindow *parent, - wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name ) +#include "wx/osx/private.h" + +wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_macIsUserPane = false; - - if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) - return false; - - m_labelOrig = m_label = label; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - - m_peer = new wxMacControl( this ); + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; OSStatus err = CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""), - 0, false /* no autotoggle */, m_peer->GetControlRefAddr() ); + 0, false /* no autotoggle */, peer->GetControlRefAddr() ); verify_noerr( err ); - MacPostControlCreate( pos, size ); - - m_cycle = this; - - if (HasFlag( wxRB_GROUP )) - { - AddInCycle( NULL ); - } - else - { - // search backward for last group start - wxRadioButton *chief = NULL; - wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast(); - while (node) - { - wxWindow *child = node->GetData(); - if (child->IsKindOf( CLASSINFO( wxRadioButton ) )) - { - chief = (wxRadioButton*)child; - if (child->HasFlag( wxRB_GROUP )) - break; - } - - node = node->GetPrevious(); - } - - AddInCycle( chief ); - } - - return true; -} - -wxRadioButton::~wxRadioButton() -{ - RemoveFromCycle(); -} - -void wxRadioButton::SetValue(bool val) -{ - wxRadioButton *cycle; - if (m_peer->GetValue() == val) - return; - - m_peer->SetValue( val ); - if (val) - { - cycle = this->NextInCycle(); - if (cycle != NULL) - { - while (cycle != this) - { - cycle->SetValue( false ); - cycle = cycle->NextInCycle(); - } - } - } -} - -bool wxRadioButton::GetValue() const -{ - return m_peer->GetValue(); -} - -void wxRadioButton::Command(wxCommandEvent& event) -{ - SetValue( (event.GetInt() != 0) ); - ProcessCommand( event ); -} - -wxInt32 wxRadioButton::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler), WXEVENTREF WXUNUSED(event) ) -{ - // if already set -> no action - if (GetValue()) - return noErr; - - wxRadioButton *cycle; - cycle = this->NextInCycle(); - if (cycle != NULL) - { - while (cycle != this) - { - if (cycle->GetValue()) - cycle->SetValue( false ); - - cycle = cycle->NextInCycle(); - } - } - - SetValue( true ); - - wxCommandEvent event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId ); - event2.SetEventObject( this ); - event2.SetInt( true ); - ProcessCommand( event2 ); - - return noErr; -} - -wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle) -{ - wxRadioButton *current; - - if (cycle == NULL) - { - m_cycle = this; - } - else - { - current = cycle; - while (current->m_cycle != cycle) - current = current->m_cycle; - - m_cycle = cycle; - current->m_cycle = this; - } - - return m_cycle; -} - -void wxRadioButton::RemoveFromCycle() -{ - if ((m_cycle == NULL) || (m_cycle == this)) - return; - - // Find the previous one and make it point to the next one - wxRadioButton* prev = this; - while (prev->m_cycle != this) - prev = prev->m_cycle; - - prev->m_cycle = m_cycle; + return peer; } #endif diff --git a/src/osx/carbon/renderer.cpp b/src/osx/carbon/renderer.cpp index c693596282..ee4b05d680 100644 --- a/src/osx/carbon/renderer.cpp +++ b/src/osx/carbon/renderer.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/renderer.cpp +// Name: src/osx/carbon/renderer.cpp // Purpose: implementation of wxRendererNative for Mac // Author: Vadim Zeitlin // Modified by: @@ -27,8 +27,13 @@ #include "wx/renderer.h" #include "wx/graphics.h" +#include "wx/dcgraph.h" #include "wx/osx/private.h" +#if wxOSX_USE_COCOA +// bring in the theme headers +#include +#endif class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative { diff --git a/src/osx/carbon/scrolbar.cpp b/src/osx/carbon/scrolbar.cpp index fbf084395c..7fc53b8ae5 100644 --- a/src/osx/carbon/scrolbar.cpp +++ b/src/osx/carbon/scrolbar.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/scrolbar.cpp +// Name: src/osx/carbon/scrolbar.cpp // Purpose: wxScrollBar // Author: Stefan Csomor // Modified by: @@ -19,84 +19,49 @@ #include "wx/settings.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) - -BEGIN_EVENT_TABLE(wxScrollBar, wxControl) -END_EVENT_TABLE() - - -bool wxScrollBar::Create( wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name ) +class wxOSXScrollBarCarbonImpl : public wxMacControl { - m_macIsUserPane = false; - - if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); +public : + wxOSXScrollBarCarbonImpl( wxWindowMac* peer) : wxMacControl( peer ) + { + } + + void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) + { + SetValue( value ); + SetControlViewSize(m_controlRef , thumbSize ); + } +protected: +}; + +wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); - m_peer = new wxMacControl( this ); + wxMacControl* peer = new wxOSXScrollBarCarbonImpl( wxpeer ); OSStatus err = CreateScrollBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, 0, 0, 100, 1, true /* liveTracking */, GetwxMacLiveScrollbarActionProc(), - m_peer->GetControlRefAddr() ); + peer->GetControlRefAddr() ); verify_noerr( err ); - - MacPostControlCreate( pos, size ); - - return true; -} - -wxScrollBar::~wxScrollBar() -{ -} - -void wxScrollBar::SetThumbPosition( int viewStart ) -{ - m_peer->SetValue( viewStart ); -} - -int wxScrollBar::GetThumbPosition() const -{ - return m_peer->GetValue(); -} - -void wxScrollBar::SetScrollbar( int position, - int thumbSize, - int range, - int pageSize, - bool WXUNUSED(refresh) ) -{ - m_pageSize = pageSize; - m_viewSize = thumbSize; - m_objectSize = range; - - int range1 = wxMax( (m_objectSize - m_viewSize), 0 ); - - m_peer->SetMinimum( 0 ); - m_peer->SetMaximum( range1 ); - m_peer->SetValue( position ); - m_peer->SetViewSize( m_viewSize ); -} - -void wxScrollBar::Command( wxCommandEvent& event ) -{ - SetThumbPosition( event.GetInt() ); - ProcessCommand( event ); + return peer; } void wxScrollBar::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 controlpart, bool mouseStillDown ) { +#if wxOSX_USE_CARBON + int position = m_peer->GetValue(); - int minPos = m_peer->GetMinimum(); + int minPos = 0 ; int maxPos = m_peer->GetMaximum(); wxEventType scrollEvent = wxEVT_NULL; @@ -166,82 +131,5 @@ void wxScrollBar::MacHandleControlClick( WXWidget WXUNUSED(control), wxInt16 con window->MacOnScroll( event ); else HandleWindowEvent( event ); -} - -wxInt32 wxScrollBar::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler), WXEVENTREF mevent ) -{ - int position = m_peer->GetValue(); - int minPos = m_peer->GetMinimum(); - int maxPos = m_peer->GetMaximum(); - - wxEventType scrollEvent = wxEVT_NULL; - int nScrollInc = 0; - - wxMacCarbonEvent cEvent( (EventRef)mevent ); - ControlPartCode controlpart = cEvent.GetParameter(kEventParamControlPart, typeControlPartCode); - - // all events have already been reported during mouse down, except for THUMBRELEASE - // NB: this may need to be reviewed in light of the fact that scroll wheel events - // aren't being handled properly - if ( controlpart != kControlIndicatorPart ) - return eventNotHandledErr; - - switch ( controlpart ) - { - case kControlIndicatorPart: - nScrollInc = 0; - scrollEvent = wxEVT_SCROLL_THUMBRELEASE; - break; - - default: - wxFAIL_MSG(wxT("unknown scrollbar selector")); - break; - } - - int new_pos = position + nScrollInc; - - if (new_pos < minPos) - new_pos = minPos; - else if (new_pos > maxPos) - new_pos = maxPos; - - if ( nScrollInc ) - SetThumbPosition( new_pos ); - - wxScrollEvent event( scrollEvent, m_windowId ); - if ( m_windowStyle & wxHORIZONTAL ) - event.SetOrientation( wxHORIZONTAL ); - else - event.SetOrientation( wxVERTICAL ); - - event.SetPosition( new_pos ); - event.SetEventObject( this ); - wxWindow* window = GetParent(); - if (window && window->MacIsWindowScrollbar( this )) - // this is hardcoded - window->MacOnScroll( event ); - else - HandleWindowEvent( event ); - - return noErr; -} - - -wxSize wxScrollBar::DoGetBestSize() const -{ - int w = 100; - int h = 100; - - if ( IsVertical() ) - { - w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); - } - else - { - h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); - } - - wxSize best(w, h); - CacheBestSize(best); - return best; -} +#endif +} \ No newline at end of file diff --git a/src/osx/carbon/settings.cpp b/src/osx/carbon/settings.cpp index b2ceb365f1..be6c68ca1b 100644 --- a/src/osx/carbon/settings.cpp +++ b/src/osx/carbon/settings.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/settings.cpp +// Name: src/osx/carbon/settings.cpp // Purpose: wxSettings // Author: Stefan Csomor // Modified by: @@ -39,7 +39,7 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) { case wxSYS_COLOUR_WINDOW: #if wxOSX_USE_COCOA_OR_CARBON - resultColor = wxColour(wxMacCreateCGColorFromHITheme( kThemeBrushDocumentWindowBackground )) ; + resultColor = wxColour(wxMacCreateCGColorFromHITheme( 15 /* kThemeBrushDocumentWindowBackground */ )) ; #else resultColor = *wxWHITE; #endif @@ -55,7 +55,7 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) case wxSYS_COLOUR_BTNFACE: case wxSYS_COLOUR_MENUBAR: #if wxOSX_USE_COCOA_OR_CARBON - resultColor = wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)); + resultColor = wxColour(wxMacCreateCGColorFromHITheme( 3 /* kThemeBrushDialogBackgroundActive */)); #else resultColor = wxColour( 0xBE, 0xBE, 0xBE ) ; #endif @@ -85,7 +85,7 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) // NB: enable this case as desired colorBrushID = kThemeBrushAlternatePrimaryHighlightColor; #else - colorBrushID = kThemeBrushPrimaryHighlightColor; + colorBrushID = -3 /* kThemeBrushPrimaryHighlightColor */; #endif resultColor = wxColour( wxMacCreateCGColorFromHITheme(colorBrushID) ); #else @@ -110,7 +110,7 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) case wxSYS_COLOUR_HIGHLIGHTTEXT : #if wxOSX_USE_COCOA_OR_CARBON { - wxColour highlightcolor( wxMacCreateCGColorFromHITheme(kThemeBrushPrimaryHighlightColor) ); + wxColour highlightcolor( wxMacCreateCGColorFromHITheme(-3 /* kThemeBrushPrimaryHighlightColor */) ); if ((highlightcolor.Red() + highlightcolor.Green() + highlightcolor.Blue() ) == 0) resultColor = *wxWHITE ; else diff --git a/src/osx/carbon/slider.cpp b/src/osx/carbon/slider.cpp index d79fe630c2..38daf07216 100644 --- a/src/osx/carbon/slider.cpp +++ b/src/osx/carbon/slider.cpp @@ -14,544 +14,41 @@ #if wxUSE_SLIDER #include "wx/slider.h" -#include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) - -BEGIN_EVENT_TABLE(wxSlider, wxControl) -END_EVENT_TABLE() - - // The dimensions of the different styles of sliders (from Aqua document) -#define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24 -#define wxSLIDER_DIMENSIONACROSS_ARROW 18 - -// Distance between slider and text -#define wxSLIDER_BORDERTEXT 5 - -// NB: The default orientation for a slider is horizontal; however, if the user specifies -// some slider styles but doesn't specify the orientation we have to assume he wants a -// horizontal one. Therefore in this file when testing for the slider's orientation -// vertical is tested for if this is not set then we use the horizontal one -// e.g., if (GetWindowStyle() & wxSL_VERTICAL) {} else { horizontal case }. - -wxSlider::wxSlider() -{ - m_pageSize = 1; - m_lineSize = 1; - m_rangeMax = 0; - m_rangeMin = 0; - m_tickFreq = 0; - - m_macMinimumStatic = NULL; - m_macMaximumStatic = NULL; - m_macValueStatic = NULL; -} - -bool wxSlider::Create(wxWindow *parent, - wxWindowID id, - int value, int minValue, int maxValue, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) -{ - m_macIsUserPane = false; - - m_macMinimumStatic = NULL; - m_macMaximumStatic = NULL; - m_macValueStatic = NULL; - - m_lineSize = 1; - m_tickFreq = 0; - - m_rangeMax = maxValue; - m_rangeMin = minValue; - - m_pageSize = (int)((maxValue - minValue) / 10); - - // our styles are redundant: wxSL_LEFT/RIGHT imply wxSL_VERTICAL and - // wxSL_TOP/BOTTOM imply wxSL_HORIZONTAL, but for backwards compatibility - // reasons we can't really change it, instead try to infer the orientation - // from the flags given to us here - switch ( style & (wxSL_LEFT | wxSL_RIGHT | wxSL_TOP | wxSL_BOTTOM) ) - { - case wxSL_LEFT: - case wxSL_RIGHT: - style |= wxSL_VERTICAL; - break; - - case wxSL_TOP: - case wxSL_BOTTOM: - style |= wxSL_HORIZONTAL; - break; - - case 0: - default: - // no specific direction, do we have at least the orientation? - if ( !(style & (wxSL_HORIZONTAL | wxSL_VERTICAL)) ) - // no: choose default - style |= wxSL_BOTTOM | wxSL_HORIZONTAL; - break; - } - - wxASSERT_MSG( !(style & wxSL_VERTICAL) || !(style & wxSL_HORIZONTAL), - wxT("incompatible slider direction and orientation") ); - - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ); - - // NB: (RN) Ticks here are sometimes off in the GUI if there - // are not as many tick marks as there are values - // +#include "wx/osx/private.h" + +wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxInt32 value, + wxInt32 minimum, + wxInt32 maximum, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); int tickMarks = 0; if ( style & wxSL_AUTOTICKS ) - tickMarks = (maxValue - minValue) + 1; // +1 for the 0 value + tickMarks = (maximum - minimum) + 1; // +1 for the 0 value // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast // it to a UInt16 while (tickMarks > 20) tickMarks /= 5; - m_peer = new wxMacControl( this ); + + wxMacControl* peer = new wxMacControl( wxpeer ); OSStatus err = CreateSliderControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, - value, minValue, maxValue, + value, minimum, maximum, kControlSliderPointsDownOrRight, (UInt16) tickMarks, true /* liveTracking */, GetwxMacLiveScrollbarActionProc(), - m_peer->GetControlRefAddr() ); + peer->GetControlRefAddr() ); verify_noerr( err ); - if (style & wxSL_VERTICAL) - // Forces SetSize to use the proper width - SetSizeHints(10, -1, 10, -1); - else - // Forces SetSize to use the proper height - SetSizeHints(-1, 10, -1, 10); - - // NB: SetSizeHints is overloaded by wxSlider and will substitute 10 with the - // proper dimensions, it also means other people cannot bugger the slider with - // other values - - if (style & wxSL_LABELS) - { - m_macMinimumStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); - m_macMaximumStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); - m_macValueStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); - } - - SetRange(minValue, maxValue); - SetValue(value); - - MacPostControlCreate(pos, size); - - return true; -} - -wxSlider::~wxSlider() -{ - // this is a special case, as we had to add windows as siblings we are - // responsible for their disposal, but only if we are not part of a DestroyAllChildren - if ( m_parent && !m_parent->IsBeingDeleted() ) - { - delete m_macMinimumStatic; - delete m_macMaximumStatic; - delete m_macValueStatic; - } -} - -int wxSlider::GetValue() const -{ - // We may need to invert the value returned by the widget - return ValueInvertOrNot( m_peer->GetValue() ) ; -} - -void wxSlider::SetValue(int value) -{ - if ( m_macValueStatic ) - { - wxString valuestring; - valuestring.Printf( wxT("%d"), value ); - m_macValueStatic->SetLabel( valuestring ); - } - - // We only invert for the setting of the actual native widget - m_peer->SetValue( ValueInvertOrNot( value ) ); -} - -void wxSlider::SetRange(int minValue, int maxValue) -{ - wxString value; - - m_rangeMin = minValue; - m_rangeMax = maxValue; - - m_peer->SetMinimum( m_rangeMin ); - m_peer->SetMaximum( m_rangeMax ); - - if (m_macMinimumStatic) - { - value.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMin ) ); - m_macMinimumStatic->SetLabel( value ); - } - - if (m_macMaximumStatic) - { - value.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMax ) ); - m_macMaximumStatic->SetLabel( value ); - } - - // If the range is out of bounds, set it to a - // value that is within bounds - // RN: Testing reveals OSX does its own - // bounding, perhaps this isn't needed? - int currentValue = GetValue(); - - if(currentValue < m_rangeMin) - SetValue(m_rangeMin); - else if(currentValue > m_rangeMax) - SetValue(m_rangeMax); -} - -// For trackbars only -void wxSlider::SetTickFreq(int n, int WXUNUSED(pos)) -{ - // TODO - m_tickFreq = n; -} - -void wxSlider::SetPageSize(int pageSize) -{ - // TODO - m_pageSize = pageSize; -} - -int wxSlider::GetPageSize() const -{ - return m_pageSize; -} - -void wxSlider::ClearSel() -{ - // TODO -} - -void wxSlider::ClearTicks() -{ - // TODO -} - -void wxSlider::SetLineSize(int lineSize) -{ - m_lineSize = lineSize; - // TODO -} - -int wxSlider::GetLineSize() const -{ - // TODO - return m_lineSize; -} - -int wxSlider::GetSelEnd() const -{ - // TODO - return 0; -} - -int wxSlider::GetSelStart() const -{ - // TODO - return 0; -} - -void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos)) -{ - // TODO -} - -void wxSlider::SetThumbLength(int WXUNUSED(len)) -{ - // TODO -} - -int wxSlider::GetThumbLength() const -{ - // TODO - return 0; -} - -void wxSlider::SetTick(int WXUNUSED(tickPos)) -{ - // TODO -} - -void wxSlider::Command(wxCommandEvent &event) -{ - SetValue(event.GetInt()); - ProcessCommand(event); -} - -void wxSlider::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 WXUNUSED(controlpart), - bool WXUNUSED(mouseStillDown)) -{ - // Whatever the native value is, we may need to invert it for calling - // SetValue and putting the possibly inverted value in the event - int value = ValueInvertOrNot( m_peer->GetValue() ); - - SetValue( value ); - - wxScrollEvent event( wxEVT_SCROLL_THUMBTRACK, m_windowId ); - event.SetPosition( value ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); - cevent.SetInt( value ); - cevent.SetEventObject( this ); - HandleWindowEvent( cevent ); -} - -wxInt32 wxSlider::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler), - WXEVENTREF WXUNUSED(mevent)) -{ - // Whatever the native value is, we may need to invert it for calling - // SetValue and putting the possibly inverted value in the event - int value = ValueInvertOrNot( m_peer->GetValue() ) ; - - SetValue( value ) ; - - wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId ); - event.SetPosition( value ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); - cevent.SetInt( value ); - cevent.SetEventObject( this ); - - HandleWindowEvent( cevent ); - - return noErr; -} - -// This is overloaded in wxSlider so that the proper width/height will always be used -// for the slider different values would cause redrawing and mouse detection problems -// -void wxSlider::DoSetSizeHints( int minW, int minH, - int maxW, int maxH, - int WXUNUSED(incW), int WXUNUSED(incH) ) -{ - wxSize size = GetBestSize(); - - if (GetWindowStyle() & wxSL_VERTICAL) - { - SetMinSize( wxSize(size.x,minH) ); - SetMaxSize( wxSize(size.x,maxH) ); - } - else - { - SetMinSize( wxSize(minW,size.y) ); - SetMaxSize( wxSize(maxW,size.y) ); - } -} - -wxSize wxSlider::DoGetBestSize() const -{ - wxSize size; - int textwidth, textheight; - int mintwidth, mintheight; - int maxtwidth, maxtheight; - - textwidth = textheight = 0; - mintwidth = mintheight = 0; - maxtwidth = maxtheight = 0; - - if (GetWindowStyle() & wxSL_LABELS) - { - wxString text; - - // Get maximum text label width and height - text.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMin ) ); - GetTextExtent(text, &mintwidth, &mintheight); - text.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMax ) ); - GetTextExtent(text, &maxtwidth, &maxtheight); - - if (maxtheight > mintheight) - textheight = maxtheight; - else - textheight = mintheight; - - if (maxtwidth > mintwidth) - textwidth = maxtwidth; - else - textwidth = mintwidth; - } - - if (GetWindowStyle() & wxSL_VERTICAL) - { - size.y = 150; - - if (GetWindowStyle() & wxSL_AUTOTICKS) - size.x = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS; - else - size.x = wxSLIDER_DIMENSIONACROSS_ARROW; - - if (GetWindowStyle() & wxSL_LABELS) - size.x += textwidth + wxSLIDER_BORDERTEXT; - } - else - { - size.x = 150; - - if (GetWindowStyle() & wxSL_AUTOTICKS) - size.y = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS; - else - size.y = wxSLIDER_DIMENSIONACROSS_ARROW; - - if (GetWindowStyle() & wxSL_LABELS) - { - size.y += textheight + wxSLIDER_BORDERTEXT; - size.x += (mintwidth / 2) + (maxtwidth / 2); - } - } - - return size; -} - -void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags) -{ - int yborder = 0; - int minValWidth, maxValWidth, textheight; - int sliderBreadth; - int width = w; - - if (GetWindowStyle() & wxSL_LABELS) - { - wxString text; - int ht, valValWidth; - - // Get maximum text label width and height - text.Printf(wxT("%d"), ValueInvertOrNot( m_rangeMin ) ); - GetTextExtent(text, &minValWidth, &textheight); - text.Printf(wxT("%d"), ValueInvertOrNot( m_rangeMax ) ); - GetTextExtent(text, &maxValWidth, &ht); - - if (ht > textheight) - textheight = ht; - - if (GetWindowStyle() & wxSL_HORIZONTAL) - { - if ( m_macMinimumStatic ) - { - w -= minValWidth / 2; - x += minValWidth / 2; - } - - if ( m_macMaximumStatic ) - w -= maxValWidth / 2; - } - - // Labels have this control's parent as their parent - // so if this control is not at 0,0 relative to the parent - // the labels need to know the position of this control - // relative to its parent in order to size properly, so - // move the control first so we can use GetPosition() - wxControl::DoSetSize( x, y, w, h, sizeFlags ); - - if (GetWindowStyle() & wxSL_VERTICAL) - // If vertical, use current value - text.Printf(wxT("%d"), (int)m_peer->GetValue()); - else - // Use max so that the current value doesn't drift as centering would need to change - text.Printf(wxT("%d"), m_rangeMax); - - GetTextExtent(text, &valValWidth, &ht); - - yborder = textheight + wxSLIDER_BORDERTEXT; - - // Get slider breadth - if (GetWindowStyle() & wxSL_AUTOTICKS) - sliderBreadth = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS; - else - sliderBreadth = wxSLIDER_DIMENSIONACROSS_ARROW; - - if (GetWindowStyle() & wxSL_VERTICAL) - { - h = h - yborder; - - if ( m_macMinimumStatic ) - m_macMinimumStatic->Move(GetPosition().x + sliderBreadth + wxSLIDER_BORDERTEXT, GetPosition().y + h - yborder); - if ( m_macMaximumStatic ) - m_macMaximumStatic->Move(GetPosition().x + sliderBreadth + wxSLIDER_BORDERTEXT, GetPosition().y + 0); - if ( m_macValueStatic ) - m_macValueStatic->Move(GetPosition().x + sliderBreadth + wxSLIDER_BORDERTEXT, GetPosition().y + (h / 2) - (ht / 2)); - } - else - { - if ( m_macMinimumStatic ) - m_macMinimumStatic->Move(GetPosition().x, GetPosition().y + sliderBreadth + wxSLIDER_BORDERTEXT); - if ( m_macMaximumStatic ) - m_macMaximumStatic->Move(GetPosition().x + w - maxValWidth, GetPosition().y + sliderBreadth + wxSLIDER_BORDERTEXT); - if ( m_macValueStatic ) - m_macValueStatic->Move(GetPosition().x + (w / 2) - (valValWidth / 2), GetPosition().y + sliderBreadth + wxSLIDER_BORDERTEXT); - } - } - - // yet another hack since this is a composite control - // when wxSlider has it's size hardcoded, we're not allowed to - // change the size. But when the control has labels, we DO need - // to resize the internal Mac control to accommodate the text labels. - // We need to trick the wxWidgets resize mechanism so that we can - // resize the slider part of the control ONLY. - - // TODO: Can all of this code go in the conditional wxSL_LABELS block? - - int minWidth = m_minWidth; - - if (GetWindowStyle() & wxSL_LABELS) - { - // make sure we don't allow the entire control to be resized accidently - if (width == GetSize().x) - m_minWidth = -1; - } - - // If the control has labels, we still need to call this again because - // the labels alter the control's w and h values. - wxControl::DoSetSize( x, y, w, h, sizeFlags ); - - m_minWidth = minWidth; -} - -void wxSlider::DoMoveWindow(int x, int y, int width, int height) -{ - wxControl::DoMoveWindow( x, y, width, height ); -} - -// Common processing to invert slider values based on wxSL_INVERSE -int wxSlider::ValueInvertOrNot(int value) const -{ - int result = 0; - - if (m_windowStyle & wxSL_VERTICAL) - { - // The reason for the backwards logic is that Mac's vertical sliders are - // inverted compared to Windows and GTK, hence we want inversion to be the - // default, and if wxSL_INVERSE is set, then we do not invert (use native) - if (m_windowStyle & wxSL_INVERSE) - result = value; - else - result = (m_rangeMax + m_rangeMin) - value; - } - else // normal logic applies to HORIZONTAL sliders - { - result = wxSliderBase::ValueInvertOrNot(value); - } - - return result; + return peer; } #endif // wxUSE_SLIDER diff --git a/src/osx/carbon/sound.cpp b/src/osx/carbon/sound.cpp index ca532ebab5..7414db493c 100644 --- a/src/osx/carbon/sound.cpp +++ b/src/osx/carbon/sound.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/sound.cpp +// Name: src/osx/carbon/sound.cpp // Purpose: wxSound class implementation: optional // Author: Ryan Norton // Modified by: Stefan Csomor diff --git a/src/osx/carbon/spinbutt.cpp b/src/osx/carbon/spinbutt.cpp index 16bd9e4892..2f6fc34266 100644 --- a/src/osx/carbon/spinbutt.cpp +++ b/src/osx/carbon/spinbutt.cpp @@ -14,195 +14,101 @@ #if wxUSE_SPINBTN #include "wx/spinbutt.h" -#include "wx/osx/uma.h" - - -IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) - - -wxSpinButton::wxSpinButton() - : wxSpinButtonBase() +#include "wx/osx/private.h" + + +wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + wxInt32 value, + wxInt32 minimum, + wxInt32 maximum, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { -} - -bool wxSpinButton::Create( wxWindow *parent, - wxWindowID id, const wxPoint& pos, const wxSize& size, - long style, const wxString& name ) -{ - m_macIsUserPane = false; - - if ( !wxSpinButtonBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) - return false; - - m_min = 0; - m_max = 100; - - if (!parent) - return false; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ); + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ); - m_peer = new wxMacControl( this ); + wxMacControl* peer = new wxMacControl( wxpeer ); OSStatus err = CreateLittleArrowsControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, 0, m_min, m_max, 1, - m_peer->GetControlRefAddr() ); + MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, value, + minimum, maximum, 1, peer->GetControlRefAddr() ); verify_noerr( err ); - m_peer->SetActionProc( GetwxMacLiveScrollbarActionProc() ); - MacPostControlCreate( pos, size ); - - return true; -} - -wxSpinButton::~wxSpinButton() -{ -} - -int wxSpinButton::GetMin() const -{ - return m_min; -} - -int wxSpinButton::GetMax() const -{ - return m_max; + peer->SetActionProc( GetwxMacLiveScrollbarActionProc() ); + return peer ; } -int wxSpinButton::GetValue() const +void wxSpinButton::MacHandleControlClick(WXWidget WXUNUSED(control), + wxInt16 controlpart, + bool WXUNUSED(mouseStillDown)) { - int n = m_value; - - if (n < m_min) - n = m_min; - else if (n > m_max) - n = m_max; - - return n; -} + int inc = 0; -void wxSpinButton::SetValue(int val) -{ - m_value = val; -} + switch ( controlpart ) + { + case kControlUpButtonPart : + inc = 1; + break; -void wxSpinButton::SetRange(int minVal, int maxVal) -{ - m_min = minVal; - m_max = maxVal; - m_peer->SetMaximum( maxVal ); - m_peer->SetMinimum( minVal ); -} + case kControlDownButtonPart : + inc = -1; + break; -void wxSpinButton::MacHandleValueChanged( int inc ) -{ + default: + break; + } + + // trigger scroll events + wxEventType scrollEvent = wxEVT_NULL; - int oldValue = m_value; + int oldValue = GetValue() ; - m_value = oldValue + inc; + int newValue = oldValue + inc; - if (m_value < m_min) + if (newValue < m_min) { if ( m_windowStyle & wxSP_WRAP ) - m_value = m_max; + newValue = m_max; else - m_value = m_min; + newValue = m_min; } - if (m_value > m_max) + if (newValue > m_max) { if ( m_windowStyle & wxSP_WRAP ) - m_value = m_min; + newValue = m_min; else - m_value = m_max; + newValue = m_max; } - if ( m_value - oldValue == -1 ) + if ( newValue - oldValue == -1 ) scrollEvent = wxEVT_SCROLL_LINEDOWN; - else if ( m_value - oldValue == 1 ) + else if ( newValue - oldValue == 1 ) scrollEvent = wxEVT_SCROLL_LINEUP; else scrollEvent = wxEVT_SCROLL_THUMBTRACK; // Do not send an event if the value has not actually changed // (Also works for wxSpinCtrl) - if ( m_value == oldValue ) + if ( newValue == oldValue ) return; - wxSpinEvent event( scrollEvent, m_windowId ); - - event.SetPosition( m_value ); - event.SetEventObject( this ); - if ((HandleWindowEvent( event )) && !event.IsAllowed()) - m_value = oldValue; - - m_peer->SetValue( m_value ); - - // always send a thumbtrack event - if (scrollEvent != wxEVT_SCROLL_THUMBTRACK) - { - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - wxSpinEvent event2( scrollEvent, GetId() ); - event2.SetPosition( m_value ); - event2.SetEventObject( this ); - HandleWindowEvent( event2 ); - } -} - -void wxSpinButton::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 controlpart, - bool WXUNUSED(mouseStillDown)) -{ - int nScrollInc = 0; - - switch ( controlpart ) - { - case kControlUpButtonPart : - nScrollInc = 1; - break; - - case kControlDownButtonPart : - nScrollInc = -1; - break; - - default: - break; - } - - MacHandleValueChanged( nScrollInc ) ; -} - -wxInt32 wxSpinButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler), - WXEVENTREF WXUNUSED(event)) -{ -#if 0 - // these have been handled by the live action proc already - int nScrollInc = 0; - wxMacCarbonEvent cEvent( (EventRef)event ); - - switch ( cEvent.GetParameter(kEventParamControlPart, typeControlPartCode) ) + if ( scrollEvent != wxEVT_SCROLL_THUMBTRACK ) { - case kControlUpButtonPart : - nScrollInc = 1; - break; - - case kControlDownButtonPart : - nScrollInc = -1; - break; + wxSpinEvent event( scrollEvent, m_windowId ); - default : - break; + event.SetPosition( newValue ); + event.SetEventObject( this ); + if ((HandleWindowEvent( event )) && !event.IsAllowed()) + newValue = oldValue; } - MacHandleValueChanged( nScrollInc ) ; -#endif - - return noErr; -} + m_peer->SetValue( newValue ); -wxSize wxSpinButton::DoGetBestSize() const -{ - return wxSize( 16, 24 ); + // always send a thumbtrack event + SendThumbTrackEvent() ; } #endif // wxUSE_SPINBTN diff --git a/src/osx/carbon/srchctrl.cpp b/src/osx/carbon/srchctrl.cpp index 0a7eb7a767..9fed17dce6 100644 --- a/src/osx/carbon/srchctrl.cpp +++ b/src/osx/carbon/srchctrl.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/srchctrl.cpp +// Name: src/osx/carbon/srchctrl.cpp // Purpose: implements mac carbon wxSearchCtrl // Author: Vince Harron // Created: 2006-02-19 diff --git a/src/osx/carbon/statbmp.cpp b/src/osx/carbon/statbmp.cpp index 8948b0c3e5..ab6915452a 100644 --- a/src/osx/carbon/statbmp.cpp +++ b/src/osx/carbon/statbmp.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/statbmp.cpp +// Name: src/osx/carbon/statbmp.cpp // Purpose: wxStaticBitmap // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/statbox.cpp b/src/osx/carbon/statbox.cpp index a7eec879bb..d6ac0a91e7 100644 --- a/src/osx/carbon/statbox.cpp +++ b/src/osx/carbon/statbox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: statbox.cpp +// Name: src/osx/carbon/statbox.cpp // Purpose: wxStaticBox // Author: Stefan Csomor // Modified by: @@ -14,63 +14,25 @@ #if wxUSE_STATBOX #include "wx/statbox.h" -#include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) - - -bool wxStaticBox::Create( wxWindow *parent, - wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) +#include "wx/osx/private.h" + +wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_macIsUserPane = false; - - if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) - return false; + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); - m_labelOrig = m_label = label; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - - m_peer = new wxMacControl( this ); + wxMacControl* peer = new wxMacControl( wxpeer ); OSStatus err = CreateGroupBoxControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""), - true /*primary*/, m_peer->GetControlRefAddr() ); + true /*primary*/, peer->GetControlRefAddr() ); verify_noerr( err ); - - MacPostControlCreate( pos, size ); - - return true; + return peer; } - -void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const -{ - static int extraTop = -1; // Uninitted - static int other = 5; - - if ( extraTop == -1 ) - { - // The minimal border used for the top. - // Later on, the staticbox's font height is added to this. - extraTop = 0; - - // As indicated by the HIG, Panther needs an extra border of 11 - // pixels (otherwise overlapping occurs at the top). The "other" - // border has to be 11. - extraTop = 11; - other = 11; - } - - *borderTop = extraTop; - if ( !m_label.empty() ) - *borderTop += GetCharHeight(); - - *borderOther = other; -} - #endif // wxUSE_STATBOX diff --git a/src/osx/carbon/statbrma.cpp b/src/osx/carbon/statbrma.cpp index fc136abeb2..dff7641652 100644 --- a/src/osx/carbon/statbrma.cpp +++ b/src/osx/carbon/statbrma.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/statbarma.cpp +// Name: src/osx/carbon/statbarma.cpp // Purpose: native implementation of wxStatusBar (optional) // Author: Stefan Csomor // Modified by: diff --git a/src/osx/carbon/statlmac.cpp b/src/osx/carbon/statlmac.cpp index 2b74eb9912..4f97dba28b 100644 --- a/src/osx/carbon/statlmac.cpp +++ b/src/osx/carbon/statlmac.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/statlmac.cpp +// Name: src/osx/carbon/statlmac.cpp // Purpose: a generic wxStaticLine class // Author: Vadim Zeitlin // Created: 28.06.99 @@ -31,38 +31,24 @@ #include "wx/statbox.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" // ============================================================================ // implementation // ============================================================================ -IMPLEMENT_DYNAMIC_CLASS(wxStaticLine, wxControl) - -// ---------------------------------------------------------------------------- -// wxStaticLine -// ---------------------------------------------------------------------------- - -bool wxStaticLine::Create( wxWindow *parent, - wxWindowID id, - const wxPoint &pos, - const wxSize &size, - long style, - const wxString &name) +wxWidgetImplType* wxWidgetImpl::CreateStaticLine( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_macIsUserPane = false ; - - if ( !wxStaticLineBase::Create(parent, id, pos, size, - style, wxDefaultValidator, name) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_peer = new wxMacControl(this) ; - verify_noerr(CreateSeparatorControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, m_peer->GetControlRefAddr() ) ) ; - - MacPostControlCreate(pos,size) ; - - return true; + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; + verify_noerr(CreateSeparatorControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, peer->GetControlRefAddr() ) ) ; + return peer; } #endif //wxUSE_STATLINE diff --git a/src/osx/carbon/stattext.cpp b/src/osx/carbon/stattext.cpp index 10873f3c22..bced016eb7 100644 --- a/src/osx/carbon/stattext.cpp +++ b/src/osx/carbon/stattext.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/stattext.cpp +// Name: src/osx/carbon/stattext.cpp // Purpose: wxStaticText // Author: Stefan Csomor // Modified by: @@ -26,55 +26,29 @@ #include "wx/notebook.h" #include "wx/tabctrl.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include -IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) - - -bool wxStaticText::Create( wxWindow *parent, - wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) +class wxMacStaticText : public wxMacControl { - m_macIsUserPane = false; - - if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - - m_peer = new wxMacControl( this ); - OSStatus err = CreateStaticTextControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), - &bounds, NULL, NULL, m_peer->GetControlRefAddr() ); - verify_noerr( err ); - - if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) +public: + wxMacStaticText( wxWindowMac* peer ) : wxMacControl(peer) { - TruncCode tCode = truncEnd; - if ( style & wxST_ELLIPSIZE_MIDDLE ) - tCode = truncMiddle; - - err = m_peer->SetData( kControlStaticTextTruncTag, tCode ); - err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); } - - MacPostControlCreate( pos, size ); - - SetLabel(label); - - return true; -} + void SetLabel(const wxString& title, wxFontEncoding encoding) + { + wxCFStringRef str( title, encoding ); + OSStatus err = SetData(kControlEntireControl, kControlStaticTextCFStringTag, str); + verify_noerr( err ); + } +}; wxSize wxStaticText::DoGetBestSize() const { - Rect bestsize = { 0 , 0 , 0 , 0 } ; Point bounds; +#if wxOSX_USE_CARBON + Rect bestsize = { 0 , 0 , 0 , 0 } ; // try the built-in best size if available Boolean former = m_peer->GetData( kControlStaticTextIsMultilineTag); @@ -87,7 +61,9 @@ wxSize wxStaticText::DoGetBestSize() const bounds.v = bestsize.bottom - bestsize.top ; } else +#endif { +#if wxOSX_USE_CARBON ControlFontStyleRec controlFont; OSStatus err = m_peer->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); verify_noerr( err ); @@ -104,6 +80,7 @@ wxSize wxStaticText::DoGetBestSize() const verify_noerr( err ); } else +#endif #endif { wxClientDC dc(const_cast(this)); @@ -122,76 +99,38 @@ wxSize wxStaticText::DoGetBestSize() const return wxSize( bounds.h, bounds.v ); } -void wxStaticText::SetLabel(const wxString& label) -{ - m_labelOrig = label; +/* + FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set + to allow correct dynamic ellipsizing of the label +*/ - // middle/end ellipsization is handled by the OS: - if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) ) - { - // remove markup - wxString str(label); - if (HasFlag(wxST_MARKUP)) - str = RemoveMarkup(label); +wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ + Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); - // and leave ellipsization to the OS - DoSetLabel(str); - } - else // not supported natively - { - DoSetLabel(GetEllipsizedLabelWithoutMarkup()); - } + wxMacControl* peer = new wxMacStaticText( wxpeer ); + OSStatus err = CreateStaticTextControl( + MAC_WXHWND(parent->MacGetTopLevelWindowRef()), + &bounds, NULL, NULL, peer->GetControlRefAddr() ); + verify_noerr( err ); - if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) && - !IsEllipsized() ) // don't resize if we adjust to current size + if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) ) { - InvalidateBestSize(); - SetSize( GetBestSize() ); - } - - Refresh(); - - // we shouldn't need forced updates - // Update(); -} - -bool wxStaticText::SetFont(const wxFont& font) -{ - bool ret = wxControl::SetFont( font ); + TruncCode tCode = truncEnd; + if ( style & wxST_ELLIPSIZE_MIDDLE ) + tCode = truncMiddle; - if ( ret ) - { - if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) - { - InvalidateBestSize(); - SetSize( GetBestSize() ); - } + err = peer->SetData( kControlStaticTextTruncTag, tCode ); + err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); } - - return ret; -} - - -// for wxST_ELLIPSIZE_* support: - -void wxStaticText::DoSetLabel(const wxString& label) -{ - m_labelOrig = label; - m_label = RemoveMnemonics(label); - - wxCFStringRef str( m_label, GetFont().GetEncoding() ); - OSStatus err = m_peer->SetData(kControlEntireControl, kControlStaticTextCFStringTag, str); - verify_noerr( err ); + return peer; } -wxString wxStaticText::DoGetLabel() const -{ - return m_label; -} - -/* - FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set - to allow correct dynamic ellipsizing of the label -*/ - #endif //if wxUSE_STATTEXT diff --git a/src/osx/carbon/tabctrl.cpp b/src/osx/carbon/tabctrl.cpp index a55c65dfde..16bb6fe4d3 100644 --- a/src/osx/carbon/tabctrl.cpp +++ b/src/osx/carbon/tabctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/tabctrl.cpp +// Name: src/osx/carbon/tabctrl.cpp // Purpose: wxTabCtrl // Author: Stefan Csomor // Modified by: @@ -13,190 +13,6 @@ #if wxUSE_TAB_DIALOG -#include "wx/tabctrl.h" - -#ifndef WX_PRECOMP - #include "wx/control.h" -#endif - -#include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxTabEvent, wxNotifyEvent) - -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TAB_SEL_CHANGED) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TAB_SEL_CHANGING) - - -BEGIN_EVENT_TABLE(wxTabCtrl, wxControl) -END_EVENT_TABLE() - - -wxTabCtrl::wxTabCtrl() -{ - m_macIsUserPane = false; - m_imageList = NULL; -} - -bool wxTabCtrl::Create( wxWindow *parent, - wxWindowID id, const wxPoint& pos, const wxSize& size, - long style, const wxString& name ) -{ - m_macIsUserPane = false; - m_imageList = NULL; - - if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - - UInt16 tabstyle = kControlTabDirectionNorth; - ControlTabSize tabsize = kControlTabSizeLarge; - if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL ) - tabsize = kControlTabSizeSmall ; - else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) - { - tabsize = 3 ; - } - - m_peer = new wxMacControl( this ); - OSStatus err = CreateTabsControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, - tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() ); - verify_noerr( err ); - - MacPostControlCreate( pos, size ); - - return true; -} - -wxTabCtrl::~wxTabCtrl() -{ -} - -void wxTabCtrl::Command(wxCommandEvent& event) -{ -} - -bool wxTabCtrl::DeleteAllItems() -{ - // TODO: - return false; -} - -bool wxTabCtrl::DeleteItem(int item) -{ - // TODO: - return false; -} - -int wxTabCtrl::GetSelection() const -{ - // TODO: - return 0; -} - -// Get the tab with the current keyboard focus -// -int wxTabCtrl::GetCurFocus() const -{ - // TODO: - return 0; -} - -wxImageList * wxTabCtrl::GetImageList() const -{ - return m_imageList; -} - -int wxTabCtrl::GetItemCount() const -{ - // TODO: - return 0; -} - -// Get the rect corresponding to the tab -bool wxTabCtrl::GetItemRect(int item, wxRect& wxrect) const -{ - // TODO: - return false; -} - -int wxTabCtrl::GetRowCount() const -{ - // TODO: - return 0; -} - -wxString wxTabCtrl::GetItemText(int item) const -{ - // TODO: - return wxEmptyString; -} - -int wxTabCtrl::GetItemImage(int item) const -{ - // TODO: - return 0; -} - -void* wxTabCtrl::GetItemData(int item) const -{ - // TODO: - return NULL; -} - -int wxTabCtrl::HitTest(const wxPoint& pt, long& flags) -{ - // TODO: - return 0; -} - -bool wxTabCtrl::InsertItem(int item, const wxString& text, int imageId, void* data) -{ - // TODO: - return false; -} - -int wxTabCtrl::SetSelection(int item) -{ - // TODO: - return 0; -} - -void wxTabCtrl::SetImageList(wxImageList* imageList) -{ - // TODO: -} - -bool wxTabCtrl::SetItemText(int item, const wxString& text) -{ - // TODO: - return false; -} - -bool wxTabCtrl::SetItemImage(int item, int image) -{ - // TODO: - return false; -} - -bool wxTabCtrl::SetItemData(int item, void* data) -{ - // TODO: - return false; -} - -// Set the size for a fixed-width tab control -void wxTabCtrl::SetItemSize(const wxSize& size) -{ - // TODO: -} - -// Set the padding between tabs -void wxTabCtrl::SetPadding(const wxSize& padding) -{ - // TODO: -} +// superseeded by wxNotebook implementation, skeleton moved to src/osx/ #endif // wxUSE_TAB_DIALOG diff --git a/src/osx/carbon/taskbar.cpp b/src/osx/carbon/taskbar.cpp index b2f00b26ad..ffca169573 100644 --- a/src/osx/carbon/taskbar.cpp +++ b/src/osx/carbon/taskbar.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/taskbar.cpp +// Name: src/osx/carbon/taskbar.cpp // Purpose: wxTaskBarIcon // Author: Ryan Norton // Modified by: @@ -186,9 +186,15 @@ wxDockEventHandler(EventHandlerCallRef WXUNUSED(inHandlerCallRef), if (item && itemMenu ) { if ( eventKind == kEventCommandProcess ) - err = itemMenu->MacHandleCommandProcess( item, id ); + { + if ( itemMenu->HandleCommandProcess( item ) ) + err = noErr; + } else if ( eventKind == kEventCommandUpdateStatus ) - err = itemMenu->MacHandleCommandUpdateStatus( item, id ); + { + if ( itemMenu->HandleCommandUpdateStatus( item ) ) + err = noErr; + } } } } diff --git a/src/osx/carbon/textctrl.cpp b/src/osx/carbon/textctrl.cpp index ee48f1247c..9397eca99f 100644 --- a/src/osx/carbon/textctrl.cpp +++ b/src/osx/carbon/textctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/textctrl.cpp +// Name: src/osx/carbon/textctrl.cpp // Purpose: wxTextCtrl // Author: Stefan Csomor // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) @@ -46,7 +46,7 @@ #include "wx/sysopt.h" #include "wx/thread.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include "wx/osx/carbon/private/mactext.h" class wxMacFunctor @@ -357,92 +357,14 @@ private : SInt32 m_lastVerticalValue ; }; - -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) - -BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) - EVT_DROP_FILES(wxTextCtrl::OnDropFiles) - EVT_CHAR(wxTextCtrl::OnChar) - EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) - EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) - EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) - EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) - EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) - EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) - EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) - - EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) - - EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) - EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) - EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) - EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) - EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) - EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) - EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) -END_EVENT_TABLE() - - -void wxTextCtrl::Init() -{ - m_editable = true ; - m_dirty = false; - - m_maxLength = 0; - m_privateContextMenu = NULL; - m_triggerOnSetValue = true ; -} - -wxTextCtrl::~wxTextCtrl() -{ - delete m_privateContextMenu; -} - -bool wxTextCtrl::Create( wxWindow *parent, - wxWindowID id, - const wxString& str, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name ) -{ - m_macIsUserPane = false ; - m_editable = true ; - - if ( ! (style & wxNO_BORDER) ) - style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; - - if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) - return false; - - if ( m_windowStyle & wxTE_MULTILINE ) - { - // always turn on this style for multi-line controls - m_windowStyle |= wxTE_PROCESS_ENTER; - style |= wxTE_PROCESS_ENTER ; - } - - CreatePeer( str, pos, size, style ); - - MacPostControlCreate(pos, size) ; - - // only now the embedding is correct and we can do a positioning update - - MacSuperChangedPosition() ; - - if ( m_windowStyle & wxTE_READONLY) - SetEditable( false ) ; - - SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; - - return true; -} - -void wxTextCtrl::CreatePeer( - const wxString& str, - const wxPoint& pos, - const wxSize& size, long style ) +wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& str, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { bool forceMLTE = false ; @@ -456,820 +378,29 @@ void wxTextCtrl::CreatePeer( if ( UMAGetSystemVersion() >= 0x1050 ) forceMLTE = false; + wxMacTextControl* peer = NULL; + if ( !forceMLTE ) { - if ( m_windowStyle & wxTE_MULTILINE || ( UMAGetSystemVersion() >= 0x1050 ) ) - m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; + if ( style & wxTE_MULTILINE || ( UMAGetSystemVersion() >= 0x1050 ) ) + peer = new wxMacMLTEHIViewControl( wxpeer , str , pos , size , style ) ; } - if ( !m_peer ) + if ( !peer ) { - if ( !(m_windowStyle & wxTE_MULTILINE) && !forceMLTE ) + if ( !(style & wxTE_MULTILINE) && !forceMLTE ) { - m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; + peer = new wxMacUnicodeTextControl( wxpeer , str , pos , size , style ) ; } } // the horizontal single line scrolling bug that made us keep the classic implementation // is fixed in 10.5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 - if ( !m_peer ) - m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; -#endif -} - -void wxTextCtrl::MacSuperChangedPosition() -{ - wxWindow::MacSuperChangedPosition() ; - GetPeer()->SuperChangedPosition() ; -} - -void wxTextCtrl::MacVisibilityChanged() -{ - GetPeer()->VisibilityChanged( GetPeer()->IsVisible() ); -} - -void wxTextCtrl::MacCheckSpelling(bool check) -{ - GetPeer()->CheckSpelling(check); -} - -wxString wxTextCtrl::GetValue() const -{ - return GetPeer()->GetStringValue() ; -} - -void wxTextCtrl::GetSelection(long* from, long* to) const -{ - GetPeer()->GetSelection( from , to ) ; -} - -void wxTextCtrl::DoSetValue(const wxString& str, int flags) -{ - // optimize redraws - if ( GetValue() == str ) - return; - - GetPeer()->SetStringValue( str ) ; - - if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) - { - SendTextUpdatedEvent(); - } -} - -void wxTextCtrl::SetMaxLength(unsigned long len) -{ - m_maxLength = len ; -} - -bool wxTextCtrl::SetFont( const wxFont& font ) -{ - if ( !wxTextCtrlBase::SetFont( font ) ) - return false ; - - GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; - - return true ; -} - -bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) -{ - GetPeer()->SetStyle( start , end , style ) ; - - return true ; -} - -bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) -{ - wxTextCtrlBase::SetDefaultStyle( style ) ; - SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; - - return true ; -} - -// Clipboard operations - -void wxTextCtrl::Copy() -{ - if (CanCopy()) - GetPeer()->Copy() ; -} - -void wxTextCtrl::Cut() -{ - if (CanCut()) - { - GetPeer()->Cut() ; - - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - } -} - -void wxTextCtrl::Paste() -{ - if (CanPaste()) - { - GetPeer()->Paste() ; - - // TODO: eventually we should add setting the default style again - - wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); - event.SetEventObject( this ); - HandleWindowEvent( event ); - } -} - -bool wxTextCtrl::CanCopy() const -{ - // Can copy if there's a selection - long from, to; - GetSelection( &from, &to ); - - return (from != to); -} - -bool wxTextCtrl::CanCut() const -{ - if ( !IsEditable() ) - return false; - - // Can cut if there's a selection - long from, to; - GetSelection( &from, &to ); - - return (from != to); -} - -bool wxTextCtrl::CanPaste() const -{ - if (!IsEditable()) - return false; - - return GetPeer()->CanPaste() ; -} - -void wxTextCtrl::SetEditable(bool editable) -{ - if ( editable != m_editable ) - { - m_editable = editable ; - GetPeer()->SetEditable( editable ) ; - } -} - -void wxTextCtrl::SetInsertionPoint(long pos) -{ - SetSelection( pos , pos ) ; -} - -void wxTextCtrl::SetInsertionPointEnd() -{ - wxTextPos pos = GetLastPosition(); - SetInsertionPoint( pos ); -} - -long wxTextCtrl::GetInsertionPoint() const -{ - long begin, end ; - GetSelection( &begin , &end ) ; - - return begin ; -} - -wxTextPos wxTextCtrl::GetLastPosition() const -{ - return GetPeer()->GetLastPosition() ; -} - -void wxTextCtrl::Replace(long from, long to, const wxString& str) -{ - GetPeer()->Replace( from , to , str ) ; -} - -void wxTextCtrl::Remove(long from, long to) -{ - GetPeer()->Remove( from , to ) ; -} - -void wxTextCtrl::SetSelection(long from, long to) -{ - GetPeer()->SetSelection( from , to ) ; -} - -void wxTextCtrl::WriteText(const wxString& str) -{ - // TODO: this MPRemoting will be moved into a remoting peer proxy for any command - if ( !wxIsMainThread() ) - { - // unfortunately CW 8 is not able to correctly deduce the template types, - // so we have to instantiate explicitly - wxMacMPRemoteGUICall( this , &wxTextCtrl::WriteText , str ) ; - - return ; - } - - GetPeer()->WriteText( str ) ; -} - -void wxTextCtrl::AppendText(const wxString& text) -{ - SetInsertionPointEnd(); - WriteText( text ); -} - -void wxTextCtrl::Clear() -{ - GetPeer()->Clear() ; -} - -bool wxTextCtrl::IsModified() const -{ - return m_dirty; -} - -bool wxTextCtrl::IsEditable() const -{ - return IsEnabled() && m_editable ; -} - -bool wxTextCtrl::AcceptsFocus() const -{ - // we don't want focus if we can't be edited - return /*IsEditable() && */ wxControl::AcceptsFocus(); -} - -wxSize wxTextCtrl::DoGetBestSize() const -{ - int wText, hText; - - // these are the numbers from the HIG: - // we reduce them by the borders first - wText = 100 ; - - switch ( m_windowVariant ) - { - case wxWINDOW_VARIANT_NORMAL : - hText = 22 - 6 ; - break ; - - case wxWINDOW_VARIANT_SMALL : - hText = 19 - 6 ; - break ; - - case wxWINDOW_VARIANT_MINI : - hText = 15 - 6 ; - break ; - - default : - hText = 22 - 6; - break ; - } - - // as the above numbers have some free space around the text - // we get 5 lines like this anyway - if ( m_windowStyle & wxTE_MULTILINE ) - hText *= 5 ; - - if ( !HasFlag(wxNO_BORDER) ) - hText += 6 ; - - return wxSize(wText, hText); -} - -// ---------------------------------------------------------------------------- -// Undo/redo -// ---------------------------------------------------------------------------- - -void wxTextCtrl::Undo() -{ - if (CanUndo()) - GetPeer()->Undo() ; -} - -void wxTextCtrl::Redo() -{ - if (CanRedo()) - GetPeer()->Redo() ; -} - -bool wxTextCtrl::CanUndo() const -{ - if ( !IsEditable() ) - return false ; - - return GetPeer()->CanUndo() ; -} - -bool wxTextCtrl::CanRedo() const -{ - if ( !IsEditable() ) - return false ; - - return GetPeer()->CanRedo() ; -} - -void wxTextCtrl::MarkDirty() -{ - m_dirty = true; -} - -void wxTextCtrl::DiscardEdits() -{ - m_dirty = false; -} - -int wxTextCtrl::GetNumberOfLines() const -{ - return GetPeer()->GetNumberOfLines() ; -} - -long wxTextCtrl::XYToPosition(long x, long y) const -{ - return GetPeer()->XYToPosition( x , y ) ; -} - -bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const -{ - return GetPeer()->PositionToXY( pos , x , y ) ; -} - -void wxTextCtrl::ShowPosition(long pos) -{ - return GetPeer()->ShowPosition(pos) ; -} - -int wxTextCtrl::GetLineLength(long lineNo) const -{ - return GetPeer()->GetLineLength(lineNo) ; -} - -wxString wxTextCtrl::GetLineText(long lineNo) const -{ - return GetPeer()->GetLineText(lineNo) ; -} - -void wxTextCtrl::Command(wxCommandEvent & event) -{ - SetValue(event.GetString()); - ProcessCommand(event); -} - -void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) -{ - // By default, load the first file into the text window. - if (event.GetNumberOfFiles() > 0) - LoadFile( event.GetFiles()[0] ); -} - -void wxTextCtrl::OnChar(wxKeyEvent& event) -{ - int key = event.GetKeyCode() ; - bool eat_key = false ; - long from, to; - - if ( key == 'a' && event.MetaDown() ) - { - SelectAll() ; - - return ; - } - - if ( key == 'c' && event.MetaDown() ) - { - if ( CanCopy() ) - Copy() ; - - return ; - } - - if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && - !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) -// && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END - ) - { - // eat it - return ; - } - - // Check if we have reached the max # of chars (if it is set), but still - // allow navigation and deletion - GetSelection( &from, &to ); - if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && - key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && key != WXK_UP && key != WXK_DOWN && - key != WXK_BACK && key != WXK_DELETE && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && - from == to ) - { - // eat it, we don't want to add more than allowed # of characters - - // TODO: generate EVT_TEXT_MAXLEN() - return; - } - - // assume that any key not processed yet is going to modify the control - m_dirty = true; - - if ( key == 'v' && event.MetaDown() ) - { - if ( CanPaste() ) - Paste() ; - - return ; - } - - if ( key == 'x' && event.MetaDown() ) - { - if ( CanCut() ) - Cut() ; - - return ; - } - - switch ( key ) - { - case WXK_RETURN: - if (m_windowStyle & wxTE_PROCESS_ENTER) - { - wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); - event.SetEventObject( this ); - event.SetString( GetValue() ); - if ( HandleWindowEvent(event) ) - return; - } - - if ( !(m_windowStyle & wxTE_MULTILINE) ) - { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - if ( tlw && tlw->GetDefaultItem() ) - { - wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); - if ( def && def->IsEnabled() ) - { - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); - event.SetEventObject(def); - def->Command(event); - - return ; - } - } - - // this will make wxWidgets eat the ENTER key so that - // we actually prevent line wrapping in a single line text control - eat_key = true; - } - break; - - case WXK_TAB: - if ( !(m_windowStyle & wxTE_PROCESS_TAB)) - { - int flags = 0; - if (!event.ShiftDown()) - flags |= wxNavigationKeyEvent::IsForward ; - if (event.ControlDown()) - flags |= wxNavigationKeyEvent::WinChange ; - Navigate(flags); - - return; - } - else - { - // This is necessary (don't know why); - // otherwise the tab will not be inserted. - WriteText(wxT("\t")); - eat_key = true; - } - break; - - default: - break; - } - - if (!eat_key) - { - // perform keystroke handling - event.Skip(true) ; - } - - if ( ( key >= 0x20 && key < WXK_START ) || - ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || - key == WXK_RETURN || - key == WXK_DELETE || - key == WXK_BACK) - { - wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - event1.SetEventObject( this ); - wxPostEvent( GetEventHandler(), event1 ); - } -} - -// ---------------------------------------------------------------------------- -// standard handlers for standard edit menu events -// ---------------------------------------------------------------------------- - -void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) -{ - Cut(); -} - -void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) -{ - Copy(); -} - -void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) -{ - Paste(); -} - -void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) -{ - Undo(); -} - -void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) -{ - Redo(); -} - -void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) -{ - long from, to; - - GetSelection( &from, &to ); - if (from != -1 && to != -1) - Remove( from, to ); -} - -void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) -{ - SetSelection(-1, -1); -} - -void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) -{ - event.Enable( CanCut() ); -} - -void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) -{ - event.Enable( CanCopy() ); -} - -void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) -{ - event.Enable( CanPaste() ); -} - -void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) -{ - event.Enable( CanUndo() ); -} - -void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) -{ - event.Enable( CanRedo() ); -} - -void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) -{ - long from, to; - - GetSelection( &from, &to ); - event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ; -} - -void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) -{ - event.Enable(GetLastPosition() > 0); -} - -// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment - -void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) -{ - if ( GetPeer()->HasOwnContextMenu() ) - { - event.Skip() ; - return ; - } - - if (m_privateContextMenu == NULL) - { - m_privateContextMenu = new wxMenu; - m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); - m_privateContextMenu->Append(wxID_REDO, _("&Redo")); - m_privateContextMenu->AppendSeparator(); - m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); - m_privateContextMenu->Append(wxID_COPY, _("&Copy")); - m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); - m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); - m_privateContextMenu->AppendSeparator(); - m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); - } - - if (m_privateContextMenu != NULL) - PopupMenu(m_privateContextMenu); -} - -bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) -{ - if ( !GetPeer()->SetupCursor( pt ) ) - return wxWindow::MacSetupCursor( pt ) ; - else - return true ; -} - -// ---------------------------------------------------------------------------- -// implementation base class -// ---------------------------------------------------------------------------- - -wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : - wxMacControl( peer ) -{ -} - -wxMacTextControl::~wxMacTextControl() -{ -} - -void wxMacTextControl::SetStyle(long WXUNUSED(start), - long WXUNUSED(end), - const wxTextAttr& WXUNUSED(style)) -{ -} - -void wxMacTextControl::Copy() -{ -} - -void wxMacTextControl::Cut() -{ -} - -void wxMacTextControl::Paste() -{ -} - -bool wxMacTextControl::CanPaste() const -{ - return false ; -} - -void wxMacTextControl::SetEditable(bool WXUNUSED(editable)) -{ -} - -wxTextPos wxMacTextControl::GetLastPosition() const -{ - return GetStringValue().length() ; -} - -void wxMacTextControl::Replace( long from , long to , const wxString &val ) -{ - SetSelection( from , to ) ; - WriteText( val ) ; -} - -void wxMacTextControl::Remove( long from , long to ) -{ - SetSelection( from , to ) ; - WriteText( wxEmptyString) ; -} - -void wxMacTextControl::Clear() -{ - SetStringValue( wxEmptyString ) ; -} - -bool wxMacTextControl::CanUndo() const -{ - return false ; -} - -void wxMacTextControl::Undo() -{ -} - -bool wxMacTextControl::CanRedo() const -{ - return false ; -} - -void wxMacTextControl::Redo() -{ -} - -long wxMacTextControl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const -{ - return 0 ; -} - -bool wxMacTextControl::PositionToXY(long WXUNUSED(pos), - long *WXUNUSED(x), - long *WXUNUSED(y)) const -{ - return false ; -} - -void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) -{ -} - -int wxMacTextControl::GetNumberOfLines() const -{ - ItemCount lines = 0 ; - wxString content = GetStringValue() ; - lines = 1; - - for (size_t i = 0; i < content.length() ; i++) - { - if (content[i] == '\r') - lines++; - } - - return lines ; -} - -wxString wxMacTextControl::GetLineText(long lineNo) const -{ - // TODO: change this if possible to reflect real lines - wxString content = GetStringValue() ; - - // Find line first - int count = 0; - for (size_t i = 0; i < content.length() ; i++) - { - if (count == lineNo) - { - // Add chars in line then - wxString tmp; - - for (size_t j = i; j < content.length(); j++) - { - if (content[j] == '\n') - return tmp; - - tmp += content[j]; - } - - return tmp; - } - - if (content[i] == '\n') - count++; - } - - return wxEmptyString ; -} - -int wxMacTextControl::GetLineLength(long lineNo) const -{ - // TODO: change this if possible to reflect real lines - wxString content = GetStringValue() ; - - // Find line first - int count = 0; - for (size_t i = 0; i < content.length() ; i++) - { - if (count == lineNo) - { - // Count chars in line then - count = 0; - for (size_t j = i; j < content.length(); j++) - { - count++; - if (content[j] == '\n') - return count; - } - - return count; - } - - if (content[i] == '\n') - count++; - } - - return 0 ; -} - -void wxMacTextControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) -{ - wxMacControl::SetFont(font, foreground, windowStyle ); -#ifndef __LP64__ - - // overrule the barrier in wxMacControl for supporting disabled controls, in order to support - // setting the color to eg red and back to black by controllers - - if ( foreground == *wxBLACK ) - { - ControlFontStyleRec fontStyle; - fontStyle.foreColor.red = fontStyle.foreColor.green = fontStyle.foreColor.blue = 0; - fontStyle.flags = kControlUseForeColorMask; - ::SetControlFontStyle( m_controlRef , &fontStyle ); - } + if ( !peer ) + peer = new wxMacMLTEClassicControl( wxpeer , str , pos , size , style ) ; #endif + return peer; } // ---------------------------------------------------------------------------- @@ -1514,6 +645,17 @@ void wxMacUnicodeTextControl::SetSelection( long from , long to ) void wxMacUnicodeTextControl::WriteText( const wxString& str ) { + // TODO: this MPRemoting will be moved into a remoting peer proxy for any command + if ( !wxIsMainThread() ) + { +#if wxOSX_USE_CARBON + // unfortunately CW 8 is not able to correctly deduce the template types, + // so we have to instantiate explicitly + wxMacMPRemoteGUICall( (wxTextCtrl*) GetWXPeer() , &wxTextCtrl::WriteText , str ) ; +#endif + return ; + } + wxString st = str ; wxMacConvertNewlines10To13( &st ) ; @@ -2053,6 +1195,17 @@ void wxMacMLTEControl::SetSelection( long from , long to ) void wxMacMLTEControl::WriteText( const wxString& str ) { + // TODO: this MPRemoting will be moved into a remoting peer proxy for any command + if ( !wxIsMainThread() ) + { +#if wxOSX_USE_CARBON + // unfortunately CW 8 is not able to correctly deduce the template types, + // so we have to instantiate explicitly + wxMacMPRemoteGUICall( (wxTextCtrl*) GetWXPeer() , &wxTextCtrl::WriteText , str ) ; +#endif + return ; + } + wxString st = str ; wxMacConvertNewlines10To13( &st ) ; diff --git a/src/osx/carbon/tglbtn.cpp b/src/osx/carbon/tglbtn.cpp index ced569714d..9682aa306e 100644 --- a/src/osx/carbon/tglbtn.cpp +++ b/src/osx/carbon/tglbtn.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/tglbtn.cpp +// Name: src/osx/carbon/tglbtn.cpp // Purpose: Definition of the wxToggleButton class, which implements a // toggle button under wxMac. // Author: Stefan Csomor @@ -23,152 +23,47 @@ #if wxUSE_TOGGLEBTN #include "wx/tglbtn.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" // Button -// ---------------------------------------------------------------------------- -// macros -// ---------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) - -// ============================================================================ -// implementation -// ============================================================================ -// ---------------------------------------------------------------------------- -// wxToggleButton -// ---------------------------------------------------------------------------- - -bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) +wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) { - m_macIsUserPane = FALSE ; + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) - return false; - - m_labelOrig = m_label = label ; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - - m_peer = new wxMacControl(this) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , - kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); - - - MacPostControlCreate(pos,size) ; - - return TRUE; -} - -wxSize wxToggleButton::DoGetBestSize() const -{ - int wBtn = 70 ; - int hBtn = 20 ; - - int lBtn = m_label.Length() * 8 + 12 ; - if (lBtn > wBtn) - wBtn = lBtn; - - return wxSize ( wBtn , hBtn ) ; -} - -void wxToggleButton::SetValue(bool val) -{ - m_peer->SetValue( val ) ; -} - -bool wxToggleButton::GetValue() const -{ - return m_peer->GetValue() ; -} - -void wxToggleButton::Command(wxCommandEvent & event) -{ - SetValue((event.GetInt() != 0)); - ProcessCommand(event); -} - -wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); - event.SetInt(GetValue()); - event.SetEventObject(this); - ProcessCommand(event); - return noErr ; + kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , peer->GetControlRefAddr() ) ); + return peer; } - -// ---------------------------------------------------------------------------- -// wxBitmapToggleButton -// ---------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl) - -bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, - const wxBitmap& label, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) -{ - m_macIsUserPane = FALSE ; - - m_bitmap = label; - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) - return false; - - Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - - m_peer = new wxMacControl(this) ; +wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer, + wxWindowMac* parent, + wxWindowID id, + const wxBitmap& label, + const wxPoint& pos, + const wxSize& size, + long style, + long extraStyle) +{ + Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; + wxMacControl* peer = new wxMacControl(wxpeer) ; ControlButtonContentInfo info; - wxMacCreateBitmapButton( &info, m_bitmap ); + wxMacCreateBitmapButton( &info, label ); verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , - kControlBevelButtonNormalBevel , kControlBehaviorOffsetContents | kControlBehaviorToggles , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); - - MacPostControlCreate(pos,size) ; - - return TRUE; -} - -wxSize wxBitmapToggleButton::DoGetBestSize() const -{ - if (!m_bitmap.IsOk()) - return wxSize(20,20); - - return wxSize ( m_bitmap.GetWidth()+6, m_bitmap.GetHeight()+6 ) ; -} - -void wxBitmapToggleButton::SetValue(bool val) -{ - m_peer->SetValue( val ) ; -} + kControlBevelButtonNormalBevel , kControlBehaviorOffsetContents | kControlBehaviorToggles , &info , 0 , 0 , 0 , peer->GetControlRefAddr() ) ); -bool wxBitmapToggleButton::GetValue() const -{ - return m_peer->GetValue() ; + wxMacReleaseBitmapButton( &info ) ; + return peer; } -void wxBitmapToggleButton::Command(wxCommandEvent & event) -{ - SetValue((event.GetInt() != 0)); - ProcessCommand(event); -} - -wxInt32 wxBitmapToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); - event.SetInt(GetValue()); - event.SetEventObject(this); - ProcessCommand(event); - return noErr ; -} #endif // wxUSE_TOGGLEBTN diff --git a/src/osx/carbon/thread.cpp b/src/osx/carbon/thread.cpp index ded1084d36..2b254f96cf 100644 --- a/src/osx/carbon/thread.cpp +++ b/src/osx/carbon/thread.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/thread.cpp +// Name: src/osx/carbon/thread.cpp // Purpose: wxThread Implementation // Author: Original from Wolfram Gloger/Guilhem Lavaux/Vadim Zeitlin // Modified by: Aj Lavin, Stefan Csomor diff --git a/src/osx/carbon/toolbar.cpp b/src/osx/carbon/toolbar.cpp index a3aedf7db6..d2e2b5cccb 100644 --- a/src/osx/carbon/toolbar.cpp +++ b/src/osx/carbon/toolbar.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/toolbar.cpp +// Name: src/osx/carbon/toolbar.cpp // Purpose: wxToolBar // Author: Stefan Csomor // Modified by: @@ -20,7 +20,7 @@ #endif #include "wx/app.h" -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include "wx/geometry.h" #include "wx/sysopt.h" @@ -32,9 +32,6 @@ const short kwxMacToolBarLeftMargin = 4; const short kwxMacToolBorder = 0; const short kwxMacToolSpacing = 6; - -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) - BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) EVT_PAINT( wxToolBar::OnPaint ) END_EVENT_TABLE() @@ -43,7 +40,6 @@ END_EVENT_TABLE() #pragma mark - #pragma mark Tool Implementation - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -224,7 +220,6 @@ private: wxFontEncoding GetToolBarFontEncoding() const { wxFont f; - wxFontEncoding enc; if ( GetToolBar() ) f = GetToolBar()->GetFont(); return f.IsOk() ? f.GetEncoding() : wxFont::GetDefaultEncoding(); @@ -562,7 +557,7 @@ void wxToolBar::Init() m_defaultHeight = kwxMacToolBarToolDefaultHeight; #if wxOSX_USE_NATIVE_TOOLBAR - m_macHIToolbarRef = NULL; + m_macToolbar = NULL; m_macUsesNativeToolbar = false; #endif } @@ -652,8 +647,6 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, CFIndex count = CFGetRetainCount( viewRef ) ; if ( count >= 1 ) { - wxFAIL_MSG("Reference count of native tool was illegal before removal"); - CFRelease( viewRef ) ; } } @@ -857,11 +850,11 @@ bool wxToolBar::Create( wxString labelStr = wxString::Format( wxT("%p"), this ); err = HIToolbarCreate( wxCFStringRef( labelStr, wxFont::GetDefaultEncoding() ), 0, - (HIToolbarRef*) &m_macHIToolbarRef ); + (HIToolbarRef*) &m_macToolbar ); - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { - InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macHIToolbarRef ), ToolbarDelegateHandler, + InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macToolbar ), ToolbarDelegateHandler, GetEventTypeCount( kToolbarEvents ), kToolbarEvents, this, NULL ); HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault; @@ -874,8 +867,8 @@ bool wxToolBar::Create( else mode = kHIToolbarDisplayModeIconOnly; - HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode ); - HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize ); + HIToolbarSetDisplayMode( (HIToolbarRef) m_macToolbar, mode ); + HIToolbarSetDisplaySize( (HIToolbarRef) m_macToolbar, displaySize ); } } #endif // wxOSX_USE_NATIVE_TOOLBAR @@ -886,13 +879,13 @@ bool wxToolBar::Create( wxToolBar::~wxToolBar() { #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { // if this is the installed toolbar, then deinstall it if (m_macUsesNativeToolbar) MacInstallNativeToolbar( false ); - CFIndex count = CFGetRetainCount( m_macHIToolbarRef ) ; + CFIndex count = CFGetRetainCount( m_macToolbar ) ; // Leopard seems to have one refcount more, so we cannot check reliably at the moment if ( UMAGetSystemVersion() < 0x1050 ) { @@ -901,8 +894,8 @@ wxToolBar::~wxToolBar() wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor"); } } - CFRelease( (HIToolbarRef)m_macHIToolbarRef ); - m_macHIToolbarRef = NULL; + CFRelease( (HIToolbarRef)m_macToolbar ); + m_macToolbar = NULL; } #endif } @@ -967,7 +960,7 @@ void wxToolBar::DoGetSize( int *width, int *height ) const if ( ownToolbarInstalled ) { // TODO: is this really a control ? - GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR ); + GetControlBounds( (ControlRef) m_macToolbar, &boundsR ); if ( width != NULL ) *width = boundsR.right - boundsR.left; if ( height != NULL ) @@ -995,7 +988,7 @@ void wxToolBar::SetWindowStyleFlag( long style ) wxToolBarBase::SetWindowStyleFlag( style ); #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault; @@ -1006,7 +999,7 @@ void wxToolBar::SetWindowStyleFlag( long style ) else mode = kHIToolbarDisplayModeIconOnly; - HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode ); + HIToolbarSetDisplayMode( (HIToolbarRef) m_macToolbar, mode ); } #endif } @@ -1031,7 +1024,7 @@ bool wxToolBar::MacTopLevelHasNativeToolbar(bool *ownToolbarInstalled) const OSStatus err = GetWindowToolbar( tlw, &curToolbarRef ); bResultV = ((err == noErr) && (curToolbarRef != NULL)); if (bResultV && (ownToolbarInstalled != NULL)) - *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef); + *ownToolbarInstalled = (curToolbarRef == m_macToolbar); } return bResultV; @@ -1041,7 +1034,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bool bResult = false; - if (usesNative && (m_macHIToolbarRef == NULL)) + if (usesNative && (m_macToolbar == NULL)) return bResult; if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0)) @@ -1066,7 +1059,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bResult = true; - SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef ); + SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar ); ShowHideWindowToolbar( tlw, true, false ); ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 ); SetAutomaticControlDragTrackingEnabledForWindow( tlw, true ); @@ -1080,7 +1073,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) else { // only deinstall toolbar if this is the installed one - if (m_macHIToolbarRef == curToolbarRef) + if (m_macToolbar == curToolbarRef) { bResult = true; @@ -1143,7 +1136,7 @@ bool wxToolBar::Realize() CFIndex currentPosition = 0; bool insertAll = false; - HIToolbarRef refTB = (HIToolbarRef)m_macHIToolbarRef; + HIToolbarRef refTB = (HIToolbarRef)m_macToolbar; wxFont f; wxFontEncoding enc; f = GetFont(); @@ -1370,7 +1363,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) m_defaultHeight = size.y + kwxMacToolBorder; #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { int maxs = wxMax( size.x, size.y ); HIToolbarDisplaySize sizeSpec; @@ -1381,7 +1374,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) else sizeSpec = kHIToolbarDisplaySizeSmall; - HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec ); + HIToolbarSetDisplaySize( (HIToolbarRef) m_macToolbar, sizeSpec ); } #endif } @@ -1495,7 +1488,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) #if wxOSX_USE_NATIVE_TOOLBAR wxString label = tool->GetLabel(); - if (m_macHIToolbarRef && !label.empty() ) + if (m_macToolbar && !label.empty() ) { // strip mnemonics from the label for compatibility // with the usual labels in wxStaticText sense @@ -1517,7 +1510,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) // in flat style we need a visual separator #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { HIToolbarItemRef item; err = HIToolbarItemCreate( @@ -1561,7 +1554,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) } #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { HIToolbarItemRef item; wxString labelStr = wxString::Format(wxT("%p"), tool); @@ -1606,13 +1599,13 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) case wxTOOL_STYLE_CONTROL: #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") ); HIToolbarItemRef item; HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ; CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ; - err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID, + err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macToolbar,kControlToolbarItemClassID, data , &item ) ; if (err == noErr) @@ -1688,11 +1681,11 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) #endif #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { - if ( removeIndex != -1 && m_macHIToolbarRef ) + if ( removeIndex != -1 && m_macToolbar ) { - HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex ); + HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macToolbar, removeIndex ); tool->SetIndex( -1 ); } } @@ -1715,7 +1708,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) tool2->SetPosition( pt ); #if wxOSX_USE_NATIVE_TOOLBAR - if (m_macHIToolbarRef != NULL) + if (m_macToolbar != NULL) { if ( removeIndex != -1 && tool2->GetIndex() > removeIndex ) tool2->SetIndex( tool2->GetIndex() - 1 ); diff --git a/src/osx/carbon/tooltip.cpp b/src/osx/carbon/tooltip.cpp index 701023ad5f..4252ce410c 100644 --- a/src/osx/carbon/tooltip.cpp +++ b/src/osx/carbon/tooltip.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/tooltip.cpp +// Name: src/osx/carbon/tooltip.cpp // Purpose: wxToolTip implementation // Author: Stefan Csomor // Id: $Id$ diff --git a/src/osx/carbon/uma.cpp b/src/osx/carbon/uma.cpp index 7601f161a4..3009393821 100644 --- a/src/osx/carbon/uma.cpp +++ b/src/osx/carbon/uma.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/uma.cpp +// Name: src/osx/carbon/uma.cpp // Purpose: UMA support // Author: Stefan Csomor // Modified by: @@ -20,17 +20,6 @@ #include "wx/osx/uma.h" -static SInt32 sUMASystemVersion = 0 ; - -long UMAGetSystemVersion() -{ - if ( sUMASystemVersion == 0 ) - { - verify_noerr(Gestalt(gestaltSystemVersion, &sUMASystemVersion)); - } - return sUMASystemVersion ; -} - // menu manager #if wxOSX_USE_CARBON @@ -69,12 +58,13 @@ void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable) DisableMenuItem( inMenu , inItem ) ; } -void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id ) +void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuRef submenu ) { AppendMenuItemTextWithCFString( menu, CFSTR("A"), 0, 0,NULL); UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding ); - SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ; + SetMenuItemHierarchicalMenu( menu , CountMenuItems( menu ) , submenu ) ; + SetMenuTitleWithCFString(submenu , wxCFStringRef(title , encoding) ); } void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id ) diff --git a/src/osx/carbon/utils.cpp b/src/osx/carbon/utils.cpp index bf61f5b116..7030447039 100644 --- a/src/osx/carbon/utils.cpp +++ b/src/osx/carbon/utils.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/utils.cpp +// Name: src/osx/carbon/utils.cpp // Purpose: Various utilities // Author: Stefan Csomor // Modified by: @@ -51,228 +51,6 @@ #endif #endif -// -// TODO BEGIN move to utils_osx.cpp -// - -#if wxUSE_BASE - -extern bool WXDLLEXPORT wxIsDebuggerRunning() -{ - // TODO : try to find out ... - return false; -} - -#if wxOSX_USE_COCOA_OR_CARBON - -// our OS version is the same in non GUI and GUI cases -wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) -{ - SInt32 theSystem; - Gestalt(gestaltSystemVersion, &theSystem); - - if ( majorVsn != NULL ) - *majorVsn = (theSystem >> 8); - - if ( minorVsn != NULL ) - *minorVsn = (theSystem & 0xFF); - - return wxOS_MAC_OSX_DARWIN; -} - -#include - -wxString wxGetOsDescription() -{ - struct utsname name; - uname(&name); - return wxString::Format(_T("Mac OS X (%s %s %s)"), - wxString::FromAscii(name.sysname).c_str(), - wxString::FromAscii(name.release).c_str(), - wxString::FromAscii(name.machine).c_str()); -} - -#endif // wxOSX_USE_COCOA_OR_CARBON - - -//--------------------------------------------------------------------------- -// wxMac Specific utility functions -//--------------------------------------------------------------------------- - -void wxMacStringToPascal( const wxString&from , StringPtr to ) -{ - wxCharBuffer buf = from.mb_str( wxConvLocal ); - int len = strlen(buf); - - if ( len > 255 ) - len = 255; - to[0] = len; - memcpy( (char*) &to[1] , buf , len ); -} - -wxString wxMacMakeStringFromPascal( ConstStringPtr from ) -{ - return wxString( (char*) &from[1] , wxConvLocal , from[0] ); -} - -#endif // wxUSE_BASE - -#if wxUSE_GUI - -// Check whether this window wants to process messages, e.g. Stop button -// in long calculations. -bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd)) -{ - // TODO - return false; -} - -// Return true if we have a colour display -bool wxColourDisplay() -{ - return true; -} - -#if wxOSX_USE_COCOA_OR_CARBON -// Returns depth of screen -int wxDisplayDepth() -{ - int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID()); - return theDepth; -} - -// Get size of display -void wxDisplaySize(int *width, int *height) -{ - // TODO adapt for multi-displays - CGRect bounds = CGDisplayBounds(CGMainDisplayID()); - if ( width ) - *width = (int)bounds.size.width ; - if ( height ) - *height = (int)bounds.size.height; -} -#endif - -void wxDisplaySizeMM(int *width, int *height) -{ - wxDisplaySize(width, height); - // on mac 72 is fixed (at least now;-) - double cvPt2Mm = 25.4 / 72; - - if (width != NULL) - *width = int( *width * cvPt2Mm ); - - if (height != NULL) - *height = int( *height * cvPt2Mm ); -} - - -wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const -{ - // We suppose that toolkit version is the same as OS version under Mac - wxGetOsVersion(verMaj, verMin); - - return wxPORT_OSX; -} - -wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() -{ - return new wxEventLoop; -} - -wxWindow* wxFindWindowAtPoint(const wxPoint& pt) -{ - return wxGenericFindWindowAtPoint(pt); -} - -/* - Return the generic RGB color space. This is a 'get' function and the caller should - not release the returned value unless the caller retains it first. Usually callers - of this routine will immediately use the returned colorspace with CoreGraphics - so they typically do not need to retain it themselves. - - This function creates the generic RGB color space once and hangs onto it so it can - return it whenever this function is called. -*/ - -CGColorSpaceRef wxMacGetGenericRGBColorSpace() -{ - static wxCFRef genericRGBColorSpace; - - if (genericRGBColorSpace == NULL) - { -#if wxOSX_USE_IPHONE - genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() ); -#else - genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) ); -#endif - } - - return genericRGBColorSpace; -} - -#if wxOSX_USE_COCOA_OR_CARBON - -CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) -{ - CGColorRef color ; - HIThemeBrushCreateCGColor( brush, &color ); - return color; -} - -#endif // wxOSX_USE_COCOA_OR_CARBON - -IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject ) - -wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl ) -{ - Init(); - m_isRootControl = isRootControl; - m_wxPeer = peer; -} - -wxWidgetImpl::wxWidgetImpl() -{ - Init(); -} - -wxWidgetImpl::~wxWidgetImpl() -{ -} - -void wxWidgetImpl::Init() -{ - m_isRootControl = false; - m_wxPeer = NULL; - m_needsFocusRect = false; -} - -void wxWidgetImpl::Destroy() -{ -} - -void wxWidgetImpl::SetNeedsFocusRect( bool needs ) -{ - m_needsFocusRect = needs; -} - -bool wxWidgetImpl::NeedsFocusRect() const -{ - return m_needsFocusRect; -} - -#endif // wxUSE_GUI - -// -// TODO END move to utils_osx.cpp -// - -// -// carbon version -// - -#if wxOSX_USE_CARBON - #if wxUSE_BASE // Emit a beeeeeep @@ -845,10 +623,10 @@ OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID pro wxMacDataItem::wxMacDataItem() { - m_data = NULL; +// m_data = NULL; m_order = 0; - m_colId = kTextColumnId; // for compat with existing wx*ListBox impls. +// m_colId = kTextColumnId; // for compat with existing wx*ListBox impls. } wxMacDataItem::~wxMacDataItem() @@ -864,7 +642,7 @@ SInt32 wxMacDataItem::GetOrder() const { return m_order; } - +/* void wxMacDataItem::SetData( void* data) { m_data = data; @@ -895,6 +673,7 @@ const wxString& wxMacDataItem::GetLabel() const { return m_label; } +*/ bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) , const wxMacDataItem* rhs, @@ -903,11 +682,7 @@ bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) , const wxMacDataItem* otherItem = wx_const_cast(wxMacDataItem*,rhs); bool retval = false; - if ( sortProperty == m_colId ){ - retval = m_label.CmpNoCase( otherItem->m_label) < 0; - } - - else if ( sortProperty == kNumericOrderColumnId ) + if ( sortProperty == kNumericOrderColumnId ) retval = m_order < otherItem->m_order; return retval; @@ -921,25 +696,11 @@ OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) OSStatus err = errDataBrowserPropertyNotSupported; if ( !changeValue ) { - if ( property == m_colId ){ - err = ::SetDataBrowserItemDataText( itemData, m_cfLabel ); - err = noErr; - } - else if ( property == kNumericOrderColumnId ){ + if ( property == kNumericOrderColumnId ) + { err = ::SetDataBrowserItemDataValue( itemData, m_order ); err = noErr; } - else{ - } - } - else - { - switch (property) - { - // no editable props here - default: - break; - } } return err; @@ -961,11 +722,6 @@ wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const m_clientDataItemsType = wxClientData_None; } -wxMacDataItem* wxMacDataItemBrowserControl::CreateItem() -{ - return new wxMacDataItem(); -} - wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser) { m_former = browser->SuppressSelection(true); @@ -1274,25 +1030,14 @@ void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataI m_clientDataItemsType = clientDataItemsType; } -unsigned int wxMacDataItemBrowserControl::MacGetCount() const -{ - return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState); -} - void wxMacDataItemBrowserControl::MacDelete( unsigned int n ) { wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n ); RemoveItem( wxMacDataBrowserRootContainer, item ); } -void wxMacDataItemBrowserControl::MacInsert( unsigned int n, - const wxArrayStringsAdapter& items, - int column ) +void wxMacDataItemBrowserControl::MacInsert( unsigned int n, wxMacDataItem* item) { - size_t itemsCount = items.GetCount(); - if ( itemsCount == 0 ) - return; - SInt32 frontLineOrder = 0; if ( m_sortOrder == SortOrder_None ) @@ -1302,7 +1047,7 @@ void wxMacDataItemBrowserControl::MacInsert( unsigned int n, for ( unsigned int i = n; i < lines; ++i) { wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i); - iter->SetOrder( iter->GetOrder() + itemsCount ); + iter->SetOrder( iter->GetOrder() + 1 ); } if ( n > 0 ) { @@ -1312,156 +1057,26 @@ void wxMacDataItemBrowserControl::MacInsert( unsigned int n, } wxArrayMacDataItemPtr ids; - ids.SetCount( itemsCount ); - - for ( unsigned int i = 0; i < itemsCount; ++i ) - { - wxMacDataItem* item = CreateItem(); - item->SetLabel( items[i]); - if ( column != -1 ) - item->SetColumn( kMinColumnId + column ); + ids.SetCount( 1 ); - if ( m_sortOrder == SortOrder_None ) - item->SetOrder( frontLineOrder + 1 + i ); + if ( m_sortOrder == SortOrder_None ) + item->SetOrder( frontLineOrder + 1 ); - ids[i] = item; - } + ids[0] = item; AddItems( wxMacDataBrowserRootContainer, ids ); } -int wxMacDataItemBrowserControl::MacAppend( const wxString& text) -{ - wxMacDataItem* item = CreateItem(); - item->SetLabel( text ); - if ( m_sortOrder == SortOrder_None ) - { - unsigned int lines = MacGetCount(); - if ( lines == 0 ) - item->SetOrder( 1 ); - else - { - wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1); - item->SetOrder( frontItem->GetOrder() + 1 ); - } - } - AddItem( wxMacDataBrowserRootContainer, item ); - - return GetLineFromItem(item); -} - void wxMacDataItemBrowserControl::MacClear() { wxMacDataItemBrowserSelectionSuppressor suppressor(this); RemoveAllItems(wxMacDataBrowserRootContainer); } -void wxMacDataItemBrowserControl::MacDeselectAll() -{ - wxMacDataItemBrowserSelectionSuppressor suppressor(this); - SetSelectedAllItems( kDataBrowserItemsRemove ); -} - -void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi ) -{ - wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); - wxMacDataItemBrowserSelectionSuppressor suppressor(this); - - if ( IsItemSelected( item ) != select ) - { - if ( select ) - SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign ); - else - SetSelectedItem( item, kDataBrowserItemsRemove ); - } - - MacScrollTo( n ); -} - -bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const -{ - wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); - return IsItemSelected( item ); -} - -int wxMacDataItemBrowserControl::MacGetSelection() const -{ - wxMacDataItemPtr first, last; - GetSelectionAnchor( &first, &last ); - - if ( first != NULL ) - { - return GetLineFromItem( first ); - } - - return -1; -} - -int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const -{ - aSelections.Empty(); - wxArrayMacDataItemPtr selectedItems; - GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems); - - int count = selectedItems.GetCount(); - - for ( int i = 0; i < count; ++i) - { - aSelections.Add(GetLineFromItem(selectedItems[i])); - } - - return count; -} - -void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text ) -{ - // as we don't store the strings we only have to issue a redraw - wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n); - item->SetLabel( text ); - UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId ); -} - -wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const -{ - wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); - return item->GetLabel(); -} - -void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data) -{ - wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n); - item->SetData( data ); - // not displayed, therefore no Update infos to DataBrowser -} - -void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const -{ - wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); - return item->GetData(); -} - -void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n ) +unsigned int wxMacDataItemBrowserControl::MacGetCount() const { - UInt32 top , left ; - GetScrollPosition( &top , &left ) ; - wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); - - // there is a bug in RevealItem that leads to situations - // in large lists, where the item does not get scrolled - // into sight, so we do a pre-scroll if necessary - UInt16 height ; - GetRowHeight( (DataBrowserItemID) item , &height ) ; - UInt32 linetop = n * ((UInt32) height ); - UInt32 linebottom = linetop + height; - Rect rect ; - GetControlBounds( m_controlRef, &rect ); - - if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) ) - SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ; - - RevealItem( item , kDataBrowserRevealWithoutSelecting ); + return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState); } #endif // wxUSE_GUI -#endif // wxOSX_USE_CARBON diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 4fdf07c240..9420e4c9ac 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/utils.mm +// Name: src/osx/carbon/utils.mm // Purpose: various cocoa mixin utility functions // Author: Stefan Csomor // Modified by: @@ -81,7 +81,7 @@ void wxMacCocoaRetain( void* obj ) // ---------------------------------------------------------------------------- // From "Cocoa Drawing Guide:Working with Images" -WX_NSImage CreateNSImageFromCGImage( CGImageRef image ) +WX_NSImage wxOSXCreateNSImageFromCGImage( CGImageRef image ) { NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0); @@ -98,6 +98,15 @@ WX_NSImage CreateNSImageFromCGImage( CGImageRef image ) CGContextDrawImage( imageContext, *(CGRect*)&imageRect, image ); [newImage unlockFocus]; + /* + // Create a bitmap rep from the image... + NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; + // Create an NSImage and add the bitmap rep to it... + NSImage *image = [[NSImage alloc] init]; + [image addRepresentation:bitmapRep]; + [bitmapRep release]; + */ + [newImage autorelease]; return( newImage ); } @@ -284,7 +293,7 @@ WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hot firstTime = NO; } - NSImage *nsImage = CreateNSImageFromCGImage( cgImageRef ); + NSImage *nsImage = wxOSXCreateNSImageFromCGImage( cgImageRef ); NSCursor *cursor = [[NSCursor alloc] initWithImage:nsImage hotSpot:NSMakePoint( hotSpotX, hotSpotY )]; [nsImage release]; diff --git a/src/osx/carbon/window.cpp b/src/osx/carbon/window.cpp index 30f236281a..a24d1a6f55 100644 --- a/src/osx/carbon/window.cpp +++ b/src/osx/carbon/window.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/window.cpp +// Name: src/osx/carbon/window.cpp // Purpose: wxWindowMac // Author: Stefan Csomor // Modified by: @@ -65,6 +65,8 @@ #include "wx/osx/uma.h" #else #include "wx/osx/private.h" +// bring in themeing +#include #endif #define MAC_SCROLLBAR_SIZE 15 @@ -72,2303 +74,55 @@ #include -#ifdef __WXUNIVERSAL__ - IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) -#else - IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) -#endif - -BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) - EVT_NC_PAINT(wxWindowMac::OnNcPaint) - EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) - EVT_PAINT(wxWindowMac::OnPaint) - EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) -END_EVENT_TABLE() - -#define wxMAC_DEBUG_REDRAW 0 -#ifndef wxMAC_DEBUG_REDRAW -#define wxMAC_DEBUG_REDRAW 0 -#endif - -// -// TODO BEGIN move to window_osx.cpp -// -// =========================================================================== -// implementation -// =========================================================================== - -WX_DECLARE_HASH_MAP(WXWidget, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap); - -static MacControlMap wxWinMacControlList; - -wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl ) -{ - MacControlMap::iterator node = wxWinMacControlList.find(inControl); - - return (node == wxWinMacControlList.end()) ? NULL : node->second; -} - -void wxAssociateWindowWithWXWidget(WXWidget inControl, wxWindow *control) -{ - // adding NULL ControlRef is (first) surely a result of an error and - // (secondly) breaks native event processing - wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WindowRef to window list") ); - - wxWinMacControlList[inControl] = control; -} - -void wxRemoveWXWidgetAssociation(wxWindow *control) -{ - // iterate over all the elements in the class - // is the iterator stable ? as we might have two associations pointing to the same wxWindow - // we should go on... - - bool found = true ; - while ( found ) - { - found = false ; - MacControlMap::iterator it; - for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) - { - if ( it->second == control ) - { - wxWinMacControlList.erase(it); - found = true ; - break; - } - } - } -} - -// ---------------------------------------------------------------------------- - // constructors and such -// ---------------------------------------------------------------------------- - -wxWindowMac::wxWindowMac() -{ - Init(); -} - -wxWindowMac::wxWindowMac(wxWindowMac *parent, - wxWindowID id, - const wxPoint& pos , - const wxSize& size , - long style , - const wxString& name ) -{ - Init(); - Create(parent, id, pos, size, style, name); -} - -void wxWindowMac::Init() -{ - m_peer = NULL ; - m_macAlpha = 255 ; - m_cgContextRef = NULL ; - - // as all windows are created with WS_VISIBLE style... - m_isShown = true; - - m_hScrollBar = NULL ; - m_vScrollBar = NULL ; - m_hScrollBarAlwaysShown = false; - m_vScrollBarAlwaysShown = false; - - m_macIsUserPane = true; - m_clipChildren = false ; - m_cachedClippedRectValid = false ; -} - -wxWindowMac::~wxWindowMac() -{ - SendDestroyEvent(); - - m_isBeingDeleted = true; - - MacInvalidateBorders() ; - -#ifndef __WXUNIVERSAL__ - // VS: make sure there's no wxFrame with last focus set to us: - for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) - { - wxFrame *frame = wxDynamicCast(win, wxFrame); - if ( frame ) - { - if ( frame->GetLastFocus() == this ) - frame->SetLastFocus((wxWindow*)NULL); - break; - } - } -#endif - - // destroy children before destroying this window itself - DestroyChildren(); - - // wxRemoveMacControlAssociation( this ) ; - // If we delete an item, we should initialize the parent panel, - // because it could now be invalid. - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow); - if ( tlw ) - { - if ( tlw->GetDefaultItem() == (wxButton*) this) - tlw->SetDefaultItem(NULL); - } - - if ( m_peer && m_peer->IsOk() ) - { - m_peer->Destroy() ; - } - - if ( g_MacLastWindow == this ) - g_MacLastWindow = NULL ; - -#ifndef __WXUNIVERSAL__ - wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ; - if ( frame ) - { - if ( frame->GetLastFocus() == this ) - frame->SetLastFocus( NULL ) ; - } -#endif - - // delete our drop target if we've got one -#if wxUSE_DRAG_AND_DROP - if ( m_dropTarget != NULL ) - { - delete m_dropTarget; - m_dropTarget = NULL; - } -#endif - - delete m_peer ; -} - -WXWidget wxWindowMac::GetHandle() const -{ - return (WXWidget) m_peer->GetWXWidget() ; -} - -// -// TODO END move to window_osx.cpp -// - -// --------------------------------------------------------------------------- -// Utility Routines to move between different coordinate systems -// --------------------------------------------------------------------------- - -/* - * Right now we have the following setup : - * a border that is not part of the native control is always outside the - * control's border (otherwise we loose all native intelligence, future ways - * may be to have a second embedding control responsible for drawing borders - * and backgrounds eventually) - * so all this border calculations have to be taken into account when calling - * native methods or getting native oriented data - * so we have three coordinate systems here - * wx client coordinates - * wx window coordinates (including window frames) - * native coordinates - */ - -// -// - -// Constructor -bool wxWindowMac::Create(wxWindowMac *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); - - if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) - return false; - - m_windowVariant = parent->GetWindowVariant() ; - - if ( m_macIsUserPane ) - { -#if wxOSX_USE_CARBON - m_peer = (wxMacControl*) wxWidgetImpl::CreateUserPane( this, pos, size , style, GetExtraStyle() , name ); -#else - m_peer = wxWidgetImpl::CreateUserPane( this, pos, size , style, GetExtraStyle() , name ); -#endif - MacPostControlCreate(pos, size) ; - } - -#ifndef __WXUNIVERSAL__ - // Don't give scrollbars to wxControls unless they ask for them - if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) - || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) - { - MacCreateScrollBars( style ) ; - } -#endif - - wxWindowCreateEvent event((wxWindow*)this); - GetEventHandler()->AddPendingEvent(event); - - return true; -} - -void wxWindowMac::MacChildAdded() -{ - if ( m_vScrollBar ) - m_vScrollBar->Raise() ; - if ( m_hScrollBar ) - m_hScrollBar->Raise() ; -} - -void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size) -{ - wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid mac control") ) ; - -#if wxOSX_USE_CARBON - m_peer->SetReference( (URefCon) this ) ; -#endif - - GetParent()->AddChild( this ); - -#if wxOSX_USE_CARBON - m_peer->InstallEventHandler(); - - ControlRef container = (ControlRef) GetParent()->GetHandle() ; - wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; - ::EmbedControl( m_peer->GetControlRef() , container ) ; -#endif - GetParent()->MacChildAdded() ; - - // adjust font, controlsize etc - DoSetWindowVariant( m_windowVariant ) ; -#if wxOSX_USE_CARBON - m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ; -#endif - if (!m_macIsUserPane) - SetInitialSize(size); - - SetCursor( *wxSTANDARD_CURSOR ) ; -} - -void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) -{ - // Don't assert, in case we set the window variant before - // the window is created - // wxASSERT( m_peer->Ok() ) ; - - m_windowVariant = variant ; - - if (m_peer == NULL || !m_peer->IsOk()) - return; - -#if wxOSX_USE_COCOA_OR_CARBON - - ControlSize size ; - ThemeFontID themeFont = kThemeSystemFont ; - - // we will get that from the settings later - // and make this NORMAL later, but first - // we have a few calculations that we must fix - - switch ( variant ) - { - case wxWINDOW_VARIANT_NORMAL : - size = kControlSizeNormal; - themeFont = kThemeSystemFont ; - break ; - - case wxWINDOW_VARIANT_SMALL : - size = kControlSizeSmall; - themeFont = kThemeSmallSystemFont ; - break ; - - case wxWINDOW_VARIANT_MINI : - // not always defined in the headers - size = 3 ; - themeFont = 109 ; - break ; - - case wxWINDOW_VARIANT_LARGE : - size = kControlSizeLarge; - themeFont = kThemeSystemFont ; - break ; - - default: - wxFAIL_MSG(_T("unexpected window variant")); - break ; - } - -#if wxOSX_USE_CARBON - m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; -#endif - - wxFont font ; - font.MacCreateFromThemeFont( themeFont ) ; - SetFont( font ) ; -#endif -} - -void wxWindowMac::MacUpdateControlFont() -{ -#if wxOSX_USE_CARBON - m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; -#endif - // do not trigger refreshes upon invisible and possible partly created objects - if ( IsShownOnScreen() ) - Refresh() ; -} - -bool wxWindowMac::SetFont(const wxFont& font) -{ - bool retval = wxWindowBase::SetFont( font ); - - MacUpdateControlFont() ; - - return retval; -} - -bool wxWindowMac::SetForegroundColour(const wxColour& col ) -{ - bool retval = wxWindowBase::SetForegroundColour( col ); - - if (retval) - MacUpdateControlFont(); - - return retval; -} - -bool wxWindowMac::SetBackgroundColour(const wxColour& col ) -{ - if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) - return false ; - - if ( m_peer ) - m_peer->SetBackgroundColour( col ) ; - - return true ; -} - -void wxWindowMac::SetFocus() -{ - if ( !AcceptsFocus() ) - return ; - - wxWindow* former = FindFocus() ; - if ( former == this ) - return ; - - m_peer->SetFocus() ; -} - -void wxWindowMac::DoCaptureMouse() -{ - wxApp::s_captureWindow = (wxWindow*) this ; -} - -wxWindow * wxWindowBase::GetCapture() -{ - return wxApp::s_captureWindow ; -} - -void wxWindowMac::DoReleaseMouse() -{ - wxApp::s_captureWindow = NULL ; -} - -#if wxUSE_DRAG_AND_DROP - -void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) -{ - if ( m_dropTarget != NULL ) - delete m_dropTarget; - - m_dropTarget = pDropTarget; - if ( m_dropTarget != NULL ) - { - // TODO: - } -} - -#endif - -// Old-style File Manager Drag & Drop -void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept)) -{ - // TODO: -} - -// From a wx position / size calculate the appropriate size of the native control - -bool wxWindowMac::MacGetBoundsForControl( - const wxPoint& pos, - const wxSize& size, - int& x, int& y, - int& w, int& h , bool adjustOrigin ) const -{ - // the desired size, minus the border pixels gives the correct size of the control - x = (int)pos.x; - y = (int)pos.y; - - // TODO: the default calls may be used as soon as PostCreateControl Is moved here - w = wxMax(size.x, 0) ; // WidthDefault( size.x ); - h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ; - - x += MacGetLeftBorderSize() ; - y += MacGetTopBorderSize() ; - w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; - h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; - - if ( adjustOrigin ) - AdjustForParentClientOrigin( x , y ) ; - - // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border - if ( !GetParent()->IsTopLevel() ) - { - x -= GetParent()->MacGetLeftBorderSize() ; - y -= GetParent()->MacGetTopBorderSize() ; - } - - return true ; -} - -// Get window size (not client size) -void wxWindowMac::DoGetSize(int *x, int *y) const -{ - int width, height; - m_peer->GetSize( width, height ); - - if (x) - *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ; - if (y) - *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ; -} - -// get the position of the bounds of this window in client coordinates of its parent -void wxWindowMac::DoGetPosition(int *x, int *y) const -{ - int x1, y1; - - m_peer->GetPosition( x1, y1 ) ; - - // get the wx window position from the native one - x1 -= MacGetLeftBorderSize() ; - y1 -= MacGetTopBorderSize() ; - - if ( !IsTopLevel() ) - { - wxWindow *parent = GetParent(); - if ( parent ) - { - // we must first adjust it to be in window coordinates of the parent, - // as otherwise it gets lost by the ClientAreaOrigin fix - x1 += parent->MacGetLeftBorderSize() ; - y1 += parent->MacGetTopBorderSize() ; - - // and now to client coordinates - wxPoint pt(parent->GetClientAreaOrigin()); - x1 -= pt.x ; - y1 -= pt.y ; - } - } - - if (x) - *x = x1 ; - if (y) - *y = y1 ; -} - -void wxWindowMac::DoScreenToClient(int *x, int *y) const -{ - wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; - wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ; - tlw->GetNonOwnedPeer()->ScreenToWindow( x, y); - MacRootWindowToWindow( x , y ) ; - - wxPoint origin = GetClientAreaOrigin() ; - if (x) - *x -= origin.x ; - if (y) - *y -= origin.y ; -} - -void wxWindowMac::DoClientToScreen(int *x, int *y) const -{ - wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; - wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ; - - wxPoint origin = GetClientAreaOrigin() ; - if (x) - *x += origin.x ; - if (y) - *y += origin.y ; - - MacWindowToRootWindow( x , y ) ; - tlw->GetNonOwnedPeer()->WindowToScreen( x , y ); -} - -void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const -{ - wxPoint origin = GetClientAreaOrigin() ; - if (x) - *x += origin.x ; - if (y) - *y += origin.y ; - - MacWindowToRootWindow( x , y ) ; -} - -void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const -{ - wxPoint pt ; - - if (x) - pt.x = *x ; - if (y) - pt.y = *y ; - - if ( !IsTopLevel() ) - { - wxNonOwnedWindow* top = MacGetTopLevelWindow(); - if (top) - { - pt.x -= MacGetLeftBorderSize() ; - pt.y -= MacGetTopBorderSize() ; - wxWidgetImpl::Convert( &pt , m_peer , top->m_peer ) ; - } - } - - if (x) - *x = (int) pt.x ; - if (y) - *y = (int) pt.y ; -} - -void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const -{ - wxPoint pt ; - - if (x) - pt.x = *x ; - if (y) - pt.y = *y ; - - if ( !IsTopLevel() ) - { - wxNonOwnedWindow* top = MacGetTopLevelWindow(); - if (top) - { - wxWidgetImpl::Convert( &pt , top->m_peer , m_peer ) ; - pt.x += MacGetLeftBorderSize() ; - pt.y += MacGetTopBorderSize() ; - } - } - - if (x) - *x = (int) pt.x ; - if (y) - *y = (int) pt.y ; -} - -wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const -{ - wxSize sizeTotal = size; - - int innerwidth, innerheight; - int left, top; - int outerwidth, outerheight; - - m_peer->GetContentArea( left, top, innerwidth, innerheight ); - m_peer->GetSize( outerwidth, outerheight ); - - sizeTotal.x += left + (outerwidth-innerwidth); - sizeTotal.y += top + (outerheight-innerheight); - - sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; - sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; - - return sizeTotal; -} - -// Get size *available for subwindows* i.e. excluding menu bar etc. -void wxWindowMac::DoGetClientSize( int *x, int *y ) const -{ - int ww, hh; - - int left, top; - - m_peer->GetContentArea( left, top, ww, hh ); - - if (m_hScrollBar && m_hScrollBar->IsShown() ) - hh -= m_hScrollBar->GetSize().y ; - - if (m_vScrollBar && m_vScrollBar->IsShown() ) - ww -= m_vScrollBar->GetSize().x ; - - if (x) - *x = ww; - if (y) - *y = hh; -} - -bool wxWindowMac::SetCursor(const wxCursor& cursor) -{ - if (m_cursor.IsSameAs(cursor)) - return false; - - if (!cursor.IsOk()) - { - if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) - return false ; - } - else - { - if ( ! wxWindowBase::SetCursor( cursor ) ) - return false ; - } - - wxASSERT_MSG( m_cursor.Ok(), - wxT("cursor must be valid after call to the base version")); - - wxWindowMac *mouseWin = 0 ; -#if wxOSX_USE_CARBON - { - wxNonOwnedWindow *tlw = MacGetTopLevelWindow() ; - WindowRef window = (WindowRef) ( tlw ? tlw->GetWXWindow() : 0 ) ; - - ControlPartCode part ; - ControlRef control ; - Point pt ; - #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - HIPoint hiPoint ; - HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint); - pt.h = hiPoint.x; - pt.v = hiPoint.y; - #else - GetGlobalMouse( &pt ); - int x = pt.h; - int y = pt.v; - ScreenToClient(&x, &y); - pt.h = x; - pt.v = y; -#endif - control = FindControlUnderMouse( pt , window , &part ) ; - if ( control ) - mouseWin = wxFindWindowFromWXWidget( (WXWidget) control ) ; - - } -#endif - - if ( mouseWin == this && !wxIsBusy() ) - m_cursor.MacInstall() ; - - return true ; -} - -#if wxUSE_MENUS -bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) -{ -#ifndef __WXUNIVERSAL__ - menu->SetInvokingWindow((wxWindow*)this); - menu->UpdateUI(); - - if ( x == wxDefaultCoord && y == wxDefaultCoord ) - { - wxPoint mouse = wxGetMousePosition(); - x = mouse.x; - y = mouse.y; - } - else - { - ClientToScreen( &x , &y ) ; - } - - menu->MacBeforeDisplay( true ) ; - long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ; - if ( HiWord(menuResult) != 0 ) - { - MenuCommand macid; - GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); - int id = wxMacCommandToId( macid ); - wxMenuItem* item = NULL ; - wxMenu* realmenu ; - item = menu->FindItem( id, &realmenu ) ; - if ( item ) - { - if (item->IsCheckable()) - item->Check( !item->IsChecked() ) ; - - menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; - } - } - - menu->MacAfterDisplay( true ) ; - menu->SetInvokingWindow( NULL ); - - return true; -#else - // actually this shouldn't be called, because universal is having its own implementation - return false; -#endif -} -#endif - -// ---------------------------------------------------------------------------- -// tooltips -// ---------------------------------------------------------------------------- - -#if wxUSE_TOOLTIPS - -void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) -{ - wxWindowBase::DoSetToolTip(tooltip); - - if ( m_tooltip ) - m_tooltip->SetWindow(this); -} - -#endif - -void wxWindowMac::MacInvalidateBorders() -{ - if ( m_peer == NULL ) - return ; - - bool vis = IsShownOnScreen() ; - if ( !vis ) - return ; - - int outerBorder = MacGetLeftBorderSize() ; -#if wxOSX_USE_CARBON - if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ ) - outerBorder += 4 ; -#endif - - if ( outerBorder == 0 ) - return ; - - // now we know that we have something to do at all - - - int tx,ty,tw,th; - - m_peer->GetSize( tw, th ); - m_peer->GetPosition( tx, ty ); - - wxRect leftupdate( tx-outerBorder,ty,outerBorder,th ); - wxRect rightupdate( tx+tw, ty, outerBorder, th ); - wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder ); - wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder ); - - GetParent()->m_peer->SetNeedsDisplay(&leftupdate); - GetParent()->m_peer->SetNeedsDisplay(&rightupdate); - GetParent()->m_peer->SetNeedsDisplay(&topupdate); - GetParent()->m_peer->SetNeedsDisplay(&bottomupdate); -} - -void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) -{ - // this is never called for a toplevel window, so we know we have a parent - int former_x , former_y , former_w, former_h ; - - // Get true coordinates of former position - DoGetPosition( &former_x , &former_y ) ; - DoGetSize( &former_w , &former_h ) ; - - wxWindow *parent = GetParent(); - if ( parent ) - { - wxPoint pt(parent->GetClientAreaOrigin()); - former_x += pt.x ; - former_y += pt.y ; - } - - int actualWidth = width ; - int actualHeight = height ; - int actualX = x; - int actualY = y; - - if ((m_minWidth != -1) && (actualWidth < m_minWidth)) - actualWidth = m_minWidth; - if ((m_minHeight != -1) && (actualHeight < m_minHeight)) - actualHeight = m_minHeight; - if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) - actualWidth = m_maxWidth; - if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) - actualHeight = m_maxHeight; - - bool doMove = false, doResize = false ; - - if ( actualX != former_x || actualY != former_y ) - doMove = true ; - - if ( actualWidth != former_w || actualHeight != former_h ) - doResize = true ; - - if ( doMove || doResize ) - { - // as the borders are drawn outside the native control, we adjust now - - wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), - wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , - actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; - - if ( !GetParent()->IsTopLevel() ) - { - bounds.Offset( -GetParent()->MacGetLeftBorderSize(), -GetParent()->MacGetTopBorderSize() ); - } - - MacInvalidateBorders() ; - - m_cachedClippedRectValid = false ; - - m_peer->Move( bounds.x, bounds.y, bounds.width, bounds.height); - - wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified - - MacInvalidateBorders() ; - - MacRepositionScrollBars() ; - if ( doMove ) - { - wxPoint point(actualX, actualY); - wxMoveEvent event(point, m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event) ; - } - - if ( doResize ) - { - MacRepositionScrollBars() ; - wxSize size(actualWidth, actualHeight); - wxSizeEvent event(size, m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - } - } -} - -wxSize wxWindowMac::DoGetBestSize() const -{ - if ( m_macIsUserPane || IsTopLevel() ) - { - return wxWindowBase::DoGetBestSize() ; - } - else - { - - Rect bestsize = { 0 , 0 , 0 , 0 } ; - int bestWidth, bestHeight ; - -#if wxOSX_USE_COCOA_OR_CARBON -#if wxOSX_USE_CARBON - m_peer->GetBestRect( &bestsize ) ; -#endif - if ( EmptyRect( &bestsize ) ) - { - bestsize.left = - bestsize.top = 0 ; - bestsize.right = - bestsize.bottom = 16 ; - - if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) - { - bestsize.bottom = 16 ; - } - #if wxUSE_SPINBTN - else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) - { - bestsize.bottom = 24 ; - } - #endif - else - { - // return wxWindowBase::DoGetBestSize() ; - } - } -#endif - bestWidth = bestsize.right - bestsize.left + MacGetLeftBorderSize() + - MacGetRightBorderSize(); - bestHeight = bestsize.bottom - bestsize.top + MacGetTopBorderSize() + - MacGetBottomBorderSize(); - if ( bestHeight < 10 ) - bestHeight = 13 ; - - return wxSize(bestWidth, bestHeight); - } -} - -// set the size of the window: if the dimensions are positive, just use them, -// but if any of them is equal to -1, it means that we must find the value for -// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in -// which case -1 is a valid value for x and y) -// -// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate -// the width/height to best suit our contents, otherwise we reuse the current -// width/height -void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - // get the current size and position... - int currentX, currentY; - int currentW, currentH; - - GetPosition(¤tX, ¤tY); - GetSize(¤tW, ¤tH); - - // ... and don't do anything (avoiding flicker) if it's already ok - if ( x == currentX && y == currentY && - width == currentW && height == currentH && ( height != -1 && width != -1 ) ) - { - // TODO: REMOVE - MacRepositionScrollBars() ; // we might have a real position shift - - return; - } - - if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) - { - if ( x == wxDefaultCoord ) - x = currentX; - if ( y == wxDefaultCoord ) - y = currentY; - } - - AdjustForParentClientOrigin( x, y, sizeFlags ); - - wxSize size = wxDefaultSize; - if ( width == wxDefaultCoord ) - { - if ( sizeFlags & wxSIZE_AUTO_WIDTH ) - { - size = DoGetBestSize(); - width = size.x; - } - else - { - // just take the current one - width = currentW; - } - } - - if ( height == wxDefaultCoord ) - { - if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) - { - if ( size.x == wxDefaultCoord ) - size = DoGetBestSize(); - // else: already called DoGetBestSize() above - - height = size.y; - } - else - { - // just take the current one - height = currentH; - } - } - - DoMoveWindow( x, y, width, height ); -} - -wxPoint wxWindowMac::GetClientAreaOrigin() const -{ -#if wxOSX_USE_CARBON - RgnHandle rgn = NewRgn() ; - Rect content ; - if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) - { - GetRegionBounds( rgn , &content ) ; - } - else - { - content.left = - content.top = 0 ; - } - - DisposeRgn( rgn ) ; - - return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() ); -#else - return wxPoint(0,0); -#endif -} - -void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) -{ - if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord ) - { - int currentclientwidth , currentclientheight ; - int currentwidth , currentheight ; - - GetClientSize( ¤tclientwidth , ¤tclientheight ) ; - GetSize( ¤twidth , ¤theight ) ; - - DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth , - currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; - } -} - -void wxWindowMac::SetLabel(const wxString& title) -{ - m_label = title ; - -#if wxOSX_USE_CARBON - if ( m_peer && m_peer->IsOk() ) - m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ; -#endif - - // do not trigger refreshes upon invisible and possible partly created objects - if ( IsShownOnScreen() ) - Refresh() ; -} - -wxString wxWindowMac::GetLabel() const -{ - return m_label ; -} - -bool wxWindowMac::Show(bool show) -{ - if ( !wxWindowBase::Show(show) ) - return false; - - if ( m_peer ) - m_peer->SetVisibility( show ) ; - - return true; -} - -void wxWindowMac::DoEnable(bool enable) -{ -#if wxOSX_USE_CARBON - m_peer->Enable( enable ) ; -#endif -} - -// -// status change notifications -// - -void wxWindowMac::MacVisibilityChanged() -{ -} - -void wxWindowMac::MacHiliteChanged() -{ -} - -void wxWindowMac::MacEnabledStateChanged() -{ -#if wxOSX_USE_CARBON - OnEnabled( m_peer->IsEnabled() ); -#endif -} - -// -// status queries on the inherited window's state -// - -bool wxWindowMac::MacIsReallyEnabled() -{ -#if wxOSX_USE_CARBON - return m_peer->IsEnabled() ; -#endif -} - -bool wxWindowMac::MacIsReallyHilited() -{ -#if wxOSX_USE_CARBON - return m_peer->IsActive(); -#endif -} - -int wxWindowMac::GetCharHeight() const -{ - wxClientDC dc( (wxWindow*)this ) ; - - return dc.GetCharHeight() ; -} - -int wxWindowMac::GetCharWidth() const -{ - wxClientDC dc( (wxWindow*)this ) ; - - return dc.GetCharWidth() ; -} - -void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, - int *descent, int *externalLeading, const wxFont *theFont ) const -{ - const wxFont *fontToUse = theFont; - wxFont tempFont; - if ( !fontToUse ) - { - tempFont = GetFont(); - fontToUse = &tempFont; - } - - wxClientDC dc( (wxWindow*) this ) ; - wxCoord lx,ly,ld,le ; - dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; - if ( externalLeading ) - *externalLeading = le ; - if ( descent ) - *descent = ld ; - if ( x ) - *x = lx ; - if ( y ) - *y = ly ; -} - -/* - * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect - * we always intersect with the entire window, not only with the client area - */ - -void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) -{ - if ( m_peer == NULL ) - return ; - - if ( !IsShownOnScreen() ) - return ; - - m_peer->SetNeedsDisplay( rect ) ; -} - -void wxWindowMac::DoFreeze() -{ -#if wxOSX_USE_CARBON - if ( m_peer && m_peer->IsOk() ) - m_peer->SetDrawingEnabled( false ) ; -#endif -} - -void wxWindowMac::DoThaw() -{ -#if wxOSX_USE_CARBON - if ( m_peer && m_peer->IsOk() ) - { - m_peer->SetDrawingEnabled( true ) ; - m_peer->InvalidateWithChildren() ; - } -#endif -} - -wxWindow *wxGetActiveWindow() -{ - // actually this is a windows-only concept - return NULL; -} - -// Coordinates relative to the window -void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos)) -{ - // We really don't move the mouse programmatically under Mac. -} - -void wxWindowMac::OnEraseBackground(wxEraseEvent& event) -{ - if ( MacGetTopLevelWindow() == NULL ) - return ; -/* -#if TARGET_API_MAC_OSX - if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) - { - } - else -#endif -*/ - if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR ) - { - event.GetDC()->Clear() ; - } - else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM ) - { - // don't skip the event here, custom background means that the app - // is drawing it itself in its OnPaint(), so don't draw it at all - // now to avoid flicker - } - else - { - event.Skip() ; - } -} - -void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) -{ - event.Skip() ; -} - -int wxWindowMac::GetScrollPos(int orient) const -{ - if ( orient == wxHORIZONTAL ) - { - if ( m_hScrollBar ) - return m_hScrollBar->GetThumbPosition() ; - } - else - { - if ( m_vScrollBar ) - return m_vScrollBar->GetThumbPosition() ; - } - - return 0; -} - -// This now returns the whole range, not just the number -// of positions that we can scroll. -int wxWindowMac::GetScrollRange(int orient) const -{ - if ( orient == wxHORIZONTAL ) - { - if ( m_hScrollBar ) - return m_hScrollBar->GetRange() ; - } - else - { - if ( m_vScrollBar ) - return m_vScrollBar->GetRange() ; - } - - return 0; -} - -int wxWindowMac::GetScrollThumb(int orient) const -{ - if ( orient == wxHORIZONTAL ) - { - if ( m_hScrollBar ) - return m_hScrollBar->GetThumbSize() ; - } - else - { - if ( m_vScrollBar ) - return m_vScrollBar->GetThumbSize() ; - } - - return 0; -} - -void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) -{ - if ( orient == wxHORIZONTAL ) - { - if ( m_hScrollBar ) - m_hScrollBar->SetThumbPosition( pos ) ; - } - else - { - if ( m_vScrollBar ) - m_vScrollBar->SetThumbPosition( pos ) ; - } -} - -void -wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag) -{ - bool needVisibilityUpdate = false; - - if ( m_hScrollBarAlwaysShown != hflag ) - { - m_hScrollBarAlwaysShown = hflag; - needVisibilityUpdate = true; - } - - if ( m_vScrollBarAlwaysShown != vflag ) - { - m_vScrollBarAlwaysShown = vflag; - needVisibilityUpdate = true; - } - - if ( needVisibilityUpdate ) - DoUpdateScrollbarVisibility(); -} - -// -// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef -// our own window origin is at leftOrigin/rightOrigin -// - -void wxWindowMac::MacPaintGrowBox() -{ - if ( IsTopLevel() ) - return ; - - if ( MacHasScrollBarCorner() ) - { - CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; - wxASSERT( cgContext ) ; - - int tx,ty,tw,th; - - m_peer->GetSize( tw, th ); - m_peer->GetPosition( tx, ty ); - - Rect rect = { ty,tx, ty+th, tx+tw }; - - - int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; - CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; - CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; - CGContextSaveGState( cgContext ); - - if ( m_backgroundColour.Ok() ) - { - CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); - } - else - { - CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 ); - } - CGContextFillRect( cgContext, cgrect ); - CGContextRestoreGState( cgContext ); - } -} - -void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) ) -{ - if ( IsTopLevel() ) - return ; - - bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; - - // back to the surrounding frame rectangle - int tx,ty,tw,th; - - m_peer->GetSize( tw, th ); - m_peer->GetPosition( tx, ty ); - - Rect rect = { ty,tx, ty+th, tx+tw }; - -#if wxOSX_USE_COCOA_OR_CARBON - - InsetRect( &rect, -1 , -1 ) ; - - { - CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , - rect.bottom - rect.top ) ; - - HIThemeFrameDrawInfo info ; - memset( &info, 0 , sizeof(info) ) ; - - info.version = 0 ; - info.kind = 0 ; - info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; - info.isFocused = hasFocus ; - - CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; - wxASSERT( cgContext ) ; - - if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) - { - info.kind = kHIThemeFrameTextFieldSquare ; - HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; - } - else if ( HasFlag(wxSIMPLE_BORDER) ) - { - info.kind = kHIThemeFrameListBox ; - HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; - } - else if ( hasFocus ) - { - HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; - } -#if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself - m_peer->GetRect( &rect ) ; - if ( MacHasScrollBarCorner() ) - { - int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant(); - int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; - CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; - CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; - HIThemeGrowBoxDrawInfo info ; - memset( &info, 0, sizeof(info) ) ; - info.version = 0 ; - info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; - info.kind = kHIThemeGrowBoxKindNone ; - // contrary to the docs ...SizeSmall does not work - info.size = kHIThemeGrowBoxSizeNormal ; - info.direction = 0 ; - HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; - } -#endif - } -#endif // wxOSX_USE_COCOA_OR_CARBON -} - -void wxWindowMac::RemoveChild( wxWindowBase *child ) -{ - if ( child == m_hScrollBar ) - m_hScrollBar = NULL ; - if ( child == m_vScrollBar ) - m_vScrollBar = NULL ; - - wxWindowBase::RemoveChild( child ) ; -} - -void wxWindowMac::DoUpdateScrollbarVisibility() -{ - bool triggerSizeEvent = false; - - if ( m_hScrollBar ) - { - bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded(); - - if ( m_hScrollBar->IsShown() != showHScrollBar ) - { - m_hScrollBar->Show( showHScrollBar ); - triggerSizeEvent = true; - } - } - - if ( m_vScrollBar) - { - bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded(); - - if ( m_vScrollBar->IsShown() != showVScrollBar ) - { - m_vScrollBar->Show( showVScrollBar ) ; - triggerSizeEvent = true; - } - } - - MacRepositionScrollBars() ; - if ( triggerSizeEvent ) - { - wxSizeEvent event(GetSize(), m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - } -} - -// New function that will replace some of the above. -void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, - int range, bool refresh) -{ - if ( orient == wxHORIZONTAL && m_hScrollBar ) - m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); - else if ( orient == wxVERTICAL && m_vScrollBar ) - m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); - - DoUpdateScrollbarVisibility(); -} - -// Does a physical scroll -void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) -{ - if ( dx == 0 && dy == 0 ) - return ; - - int width , height ; - GetClientSize( &width , &height ) ; - - { - wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; - if ( rect ) - scrollrect.Intersect( *rect ) ; - // as the native control might be not a 0/0 wx window coordinates, we have to offset - scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; - - m_peer->ScrollRect( &scrollrect, dx, dy ); - } - - wxWindowMac *child; - int x, y, w, h; - for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - child = node->GetData(); - if (child == NULL) - continue; - if (child == m_vScrollBar) - continue; - if (child == m_hScrollBar) - continue; - if (child->IsTopLevel()) - continue; - - child->GetPosition( &x, &y ); - child->GetSize( &w, &h ); - if (rect) - { - wxRect rc( x, y, w, h ); - if (rect->Intersects( rc )) - child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); - } - else - { - child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); - } - } -} - -void wxWindowMac::MacOnScroll( wxScrollEvent &event ) -{ - if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) - { - wxScrollWinEvent wevent; - wevent.SetPosition(event.GetPosition()); - wevent.SetOrientation(event.GetOrientation()); - wevent.SetEventObject(this); - - if (event.GetEventType() == wxEVT_SCROLL_TOP) - wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); - else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) - wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); - else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) - wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); - else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) - wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); - else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) - wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); - else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) - wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); - else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) - wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); - else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) - wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); - - HandleWindowEvent(wevent); - } -} - -// Get the window with the focus -wxWindow *wxWindowBase::DoFindFocus() -{ -#if wxOSX_USE_CARBON - ControlRef control ; - GetKeyboardFocus( GetUserFocusWindow() , &control ) ; - return wxFindWindowFromWXWidget( (WXWidget) control ) ; -#else - return NULL; -#endif -} - -void wxWindowMac::OnInternalIdle() -{ - // This calls the UI-update mechanism (querying windows for - // menu/toolbar/control state information) - if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen()) - UpdateWindowUI(wxUPDATE_UI_FROMIDLE); -} - -// Raise the window to the top of the Z order -void wxWindowMac::Raise() -{ - m_peer->Raise(); -} - -// Lower the window to the bottom of the Z order -void wxWindowMac::Lower() -{ - m_peer->Lower(); -} - -// static wxWindow *gs_lastWhich = NULL; - -bool wxWindowMac::MacSetupCursor( const wxPoint& pt ) -{ - // first trigger a set cursor event - - wxPoint clientorigin = GetClientAreaOrigin() ; - wxSize clientsize = GetClientSize() ; - wxCursor cursor ; - if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) - { - wxSetCursorEvent event( pt.x , pt.y ); - - bool processedEvtSetCursor = HandleWindowEvent(event); - if ( processedEvtSetCursor && event.HasCursor() ) - { - cursor = event.GetCursor() ; - } - else - { - // the test for processedEvtSetCursor is here to prevent using m_cursor - // if the user code caught EVT_SET_CURSOR() and returned nothing from - // it - this is a way to say that our cursor shouldn't be used for this - // point - if ( !processedEvtSetCursor && m_cursor.Ok() ) - cursor = m_cursor ; - - if ( !wxIsBusy() && !GetParent() ) - cursor = *wxSTANDARD_CURSOR ; - } - - if ( cursor.Ok() ) - cursor.MacInstall() ; - } - - return cursor.Ok() ; -} - -wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) ) -{ -#if wxUSE_TOOLTIPS - if ( m_tooltip ) - return m_tooltip->GetTip() ; -#endif - - return wxEmptyString ; -} - -void wxWindowMac::ClearBackground() -{ - Refresh() ; - Update() ; -} - -void wxWindowMac::Update() -{ - wxNonOwnedWindow* top = MacGetTopLevelWindow(); - if (top) - top->Update() ; -} - -wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const -{ - wxWindowMac *iter = (wxWindowMac*)this ; - - while ( iter ) - { - if ( iter->IsTopLevel() ) - { - wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow); - if ( toplevel ) - return toplevel; -#if wxUSE_POPUPWIN - wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow); - if ( popupwin ) - return popupwin; -#endif - } - iter = iter->GetParent() ; - } - - return NULL ; -} - -const wxRect& wxWindowMac::MacGetClippedClientRect() const -{ - MacUpdateClippedRects() ; - - return m_cachedClippedClientRect ; -} - -const wxRect& wxWindowMac::MacGetClippedRect() const -{ - MacUpdateClippedRects() ; - - return m_cachedClippedRect ; -} - -const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const -{ - MacUpdateClippedRects() ; - - return m_cachedClippedRectWithOuterStructure ; -} - -const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) -{ - static wxRegion emptyrgn ; - - if ( !m_isBeingDeleted && IsShownOnScreen() ) - { - MacUpdateClippedRects() ; - if ( includeOuterStructures ) - return m_cachedClippedRegionWithOuterStructure ; - else - return m_cachedClippedRegion ; - } - else - { - return emptyrgn ; - } -} - -void wxWindowMac::MacUpdateClippedRects() const -{ -#if wxOSX_USE_CARBON - if ( m_cachedClippedRectValid ) - return ; - - // includeOuterStructures is true if we try to draw somthing like a focus ring etc. - // also a window dc uses this, in this case we only clip in the hierarchy for hard - // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having - // to add focus borders everywhere - - Rect rIncludingOuterStructures ; - - int tx,ty,tw,th; - - m_peer->GetSize( tw, th ); - m_peer->GetPosition( tx, ty ); - - Rect r = { ty,tx, ty+th, tx+tw }; - - r.left -= MacGetLeftBorderSize() ; - r.top -= MacGetTopBorderSize() ; - r.bottom += MacGetBottomBorderSize() ; - r.right += MacGetRightBorderSize() ; - - r.right -= r.left ; - r.bottom -= r.top ; - r.left = 0 ; - r.top = 0 ; - - rIncludingOuterStructures = r ; - InsetRect( &rIncludingOuterStructures , -4 , -4 ) ; - - wxRect cl = GetClientRect() ; - Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ; - - int x , y ; - wxSize size ; - const wxWindow* child = (wxWindow*) this ; - const wxWindow* parent = NULL ; - - while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL ) - { - if ( parent->MacIsChildOfClientArea(child) ) - { - size = parent->GetClientSize() ; - wxPoint origin = parent->GetClientAreaOrigin() ; - x = origin.x ; - y = origin.y ; - } - else - { - // this will be true for scrollbars, toolbars etc. - size = parent->GetSize() ; - y = parent->MacGetTopBorderSize() ; - x = parent->MacGetLeftBorderSize() ; - size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ; - size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ; - } - - parent->MacWindowToRootWindow( &x, &y ) ; - MacRootWindowToWindow( &x , &y ) ; - - Rect rparent = { y , x , y + size.y , x + size.x } ; - - // the wxwindow and client rects will always be clipped - SectRect( &r , &rparent , &r ) ; - SectRect( &rClient , &rparent , &rClient ) ; - - // the structure only at 'hard' borders - if ( parent->MacClipChildren() || - ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) ) - { - SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ; - } - - child = parent ; - } - - m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ; - m_cachedClippedClientRect = wxRect( rClient.left , rClient.top , - rClient.right - rClient.left , rClient.bottom - rClient.top ) ; - m_cachedClippedRectWithOuterStructure = wxRect( - rIncludingOuterStructures.left , rIncludingOuterStructures.top , - rIncludingOuterStructures.right - rIncludingOuterStructures.left , - rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ; - - m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ; - m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ; - m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ; - - m_cachedClippedRectValid = true ; -#endif -} - -/* - This function must not change the updatergn ! - */ -bool wxWindowMac::MacDoRedraw( void* updatergnr , long time ) -{ - bool handled = false ; -#if wxOSX_USE_CARBON - Rect updatebounds ; - RgnHandle updatergn = (RgnHandle) updatergnr ; - GetRegionBounds( updatergn , &updatebounds ) ; - - // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ; - - if ( !EmptyRgn(updatergn) ) - { - RgnHandle newupdate = NewRgn() ; - wxSize point = GetClientSize() ; - wxPoint origin = GetClientAreaOrigin() ; - SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y + point.y ) ; - SectRgn( newupdate , updatergn , newupdate ) ; - - // first send an erase event to the entire update area - { - // for the toplevel window this really is the entire area - // for all the others only their client area, otherwise they - // might be drawing with full alpha and eg put blue into - // the grow-box area of a scrolled window (scroll sample) - wxDC* dc = new wxWindowDC(this); - if ( IsTopLevel() ) - dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn))); - else - dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate))); - - wxEraseEvent eevent( GetId(), dc ); - eevent.SetEventObject( this ); - HandleWindowEvent( eevent ); - delete dc ; - } - - MacPaintGrowBox(); - - // calculate a client-origin version of the update rgn and set m_updateRegion to that - OffsetRgn( newupdate , -origin.x , -origin.y ) ; - m_updateRegion = wxRegion(HIShapeCreateWithQDRgn(newupdate)) ; - DisposeRgn( newupdate ) ; - - if ( !m_updateRegion.Empty() ) - { - // paint the window itself - - wxPaintEvent event; - event.SetTimestamp(time); - event.SetEventObject(this); - HandleWindowEvent(event); - handled = true ; - } - - // now we cannot rely on having its borders drawn by a window itself, as it does not - // get the updateRgn wide enough to always do so, so we do it from the parent - // this would also be the place to draw any custom backgrounds for native controls - // in Composited windowing - wxPoint clientOrigin = GetClientAreaOrigin() ; - - wxWindowMac *child; - int x, y, w, h; - for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - child = node->GetData(); - if (child == NULL) - continue; - if (child == m_vScrollBar) - continue; - if (child == m_hScrollBar) - continue; - if (child->IsTopLevel()) - continue; - if (!child->IsShown()) - continue; - - // only draw those in the update region (add a safety margin of 10 pixels for shadow effects - - child->GetPosition( &x, &y ); - child->GetSize( &w, &h ); - Rect childRect = { y , x , y + h , x + w } ; - OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; - InsetRect( &childRect , -10 , -10) ; - - if ( RectInRgn( &childRect , updatergn ) ) - { - // paint custom borders - wxNcPaintEvent eventNc( child->GetId() ); - eventNc.SetEventObject( child ); - if ( !child->HandleWindowEvent( eventNc ) ) - { - child->MacPaintBorders(0, 0) ; - } - } - } - } -#endif - return handled ; -} - - -WXWindow wxWindowMac::MacGetTopLevelWindowRef() const -{ - wxNonOwnedWindow* tlw = MacGetTopLevelWindow(); - return tlw ? tlw->GetWXWindow() : NULL ; -} - -bool wxWindowMac::MacHasScrollBarCorner() const -{ - /* Returns whether the scroll bars in a wxScrolledWindow should be - * shortened. Scroll bars should be shortened if either: - * - * - both scroll bars are visible, or - * - * - there is a resize box in the parent frame's corner and this - * window shares the bottom and right edge with the parent - * frame. - */ - - if ( m_hScrollBar == NULL && m_vScrollBar == NULL ) - return false; - - if ( ( m_hScrollBar && m_hScrollBar->IsShown() ) - && ( m_vScrollBar && m_vScrollBar->IsShown() ) ) - { - // Both scroll bars visible - return true; - } - else - { - wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight(); - - for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() ) - { - const wxFrame *frame = wxDynamicCast( win, wxFrame ) ; - if ( frame ) - { - if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER ) - { - // Parent frame has resize handle - wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight(); - - // Note: allow for some wiggle room here as wxMac's - // window rect calculations seem to be imprecise - if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2 - && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 ) - { - // Parent frame has resize handle and shares - // right bottom corner - return true ; - } - else - { - // Parent frame has resize handle but doesn't - // share right bottom corner - return false ; - } - } - else - { - // Parent frame doesn't have resize handle - return false ; - } - } - } - - // No parent frame found - return false ; - } -} - -void wxWindowMac::MacCreateScrollBars( long style ) -{ - wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; - - if ( style & ( wxVSCROLL | wxHSCROLL ) ) - { - int scrlsize = MAC_SCROLLBAR_SIZE ; - if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) - { - scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; - } - - int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ; - int width, height ; - GetClientSize( &width , &height ) ; - - wxPoint vPoint(width - scrlsize, 0) ; - wxSize vSize(scrlsize, height - adjust) ; - wxPoint hPoint(0, height - scrlsize) ; - wxSize hSize(width - adjust, scrlsize) ; - - // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize) - if ( style & wxVSCROLL ) - { - m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL); - m_vScrollBar->SetMinSize( wxDefaultSize ); - } - - if ( style & wxHSCROLL ) - { - m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL); - m_hScrollBar->SetMinSize( wxDefaultSize ); - } - } - - // because the create does not take into account the client area origin - // we might have a real position shift - MacRepositionScrollBars() ; -} - -bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const -{ - bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar))); - - return result ; -} - -void wxWindowMac::MacRepositionScrollBars() -{ - if ( !m_hScrollBar && !m_vScrollBar ) - return ; - - int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; - int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ; - - // get real client area - int width, height ; - GetSize( &width , &height ); - - width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); - height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); - - wxPoint vPoint( width - scrlsize, 0 ) ; - wxSize vSize( scrlsize, height - adjust ) ; - wxPoint hPoint( 0 , height - scrlsize ) ; - wxSize hSize( width - adjust, scrlsize ) ; - - if ( m_vScrollBar ) - m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE ); - if ( m_hScrollBar ) - m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE ); -} - -bool wxWindowMac::AcceptsFocus() const -{ - return m_peer->CanFocus() && wxWindowBase::AcceptsFocus(); -} - -void wxWindowMac::MacSuperChangedPosition() -{ - // only window-absolute structures have to be moved i.e. controls - - m_cachedClippedRectValid = false ; - - wxWindowMac *child; - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - while ( node ) - { - child = node->GetData(); - child->MacSuperChangedPosition() ; - - node = node->GetNext(); - } -} - -void wxWindowMac::MacTopLevelWindowChangedPosition() -{ - // only screen-absolute structures have to be moved i.e. glcanvas - - wxWindowMac *child; - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - while ( node ) - { - child = node->GetData(); - child->MacTopLevelWindowChangedPosition() ; - - node = node->GetNext(); - } -} - -long wxWindowMac::MacGetLeftBorderSize() const -{ - if ( IsTopLevel() ) - return 0 ; - - SInt32 border = 0 ; - - if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER)) - { -#if wxOSX_USE_COCOA_OR_CARBON - // this metric is only the 'outset' outside the simple frame rect - GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; - border += 1; -#else - border += 2; -#endif - } - else if (HasFlag(wxSIMPLE_BORDER)) - { -#if wxOSX_USE_COCOA_OR_CARBON - // this metric is only the 'outset' outside the simple frame rect - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; - border += 1; -#else - border += 1; -#endif - } - - return border ; -} - -long wxWindowMac::MacGetRightBorderSize() const -{ - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; -} - -long wxWindowMac::MacGetTopBorderSize() const -{ - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; -} - -long wxWindowMac::MacGetBottomBorderSize() const -{ - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; -} - -long wxWindowMac::MacRemoveBordersFromStyle( long style ) -{ - return style & ~wxBORDER_MASK ; -} - -// Find the wxWindowMac at the current mouse position, returning the mouse -// position. -wxWindow * wxFindWindowAtPointer( wxPoint& pt ) -{ - pt = wxGetMousePosition(); - wxWindowMac* found = wxFindWindowAtPoint(pt); - - return (wxWindow*) found; -} - -// Get the current mouse position. -wxPoint wxGetMousePosition() -{ - int x, y; - - wxGetMousePosition( &x, &y ); - - return wxPoint(x, y); -} - -void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) -{ - if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) - { - // copied from wxGTK : CS - // VZ: shouldn't we move this to base class then? - - // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN - // except that: - // - // (a) it's a command event and so is propagated to the parent - // (b) under MSW it can be generated from kbd too - // (c) it uses screen coords (because of (a)) - wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, - this->GetId(), - this->ClientToScreen(event.GetPosition())); - evtCtx.SetEventObject(this); - if ( ! HandleWindowEvent(evtCtx) ) - event.Skip() ; - } - else - { - event.Skip() ; - } -} - -void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) ) -{ -#if wxOSX_USE_COCOA_OR_CARBON - // for native controls: call their native paint method - if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) ) - { - if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL - && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT ) - CallNextEventHandler( - (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , - (EventRef) wxTheApp->MacGetCurrentEvent() ) ; - } +#define wxMAC_DEBUG_REDRAW 0 +#ifndef wxMAC_DEBUG_REDRAW +#define wxMAC_DEBUG_REDRAW 0 #endif -} - -void wxWindowMac::MacHandleControlClick(WXWidget WXUNUSED(control), - wxInt16 WXUNUSED(controlpart), - bool WXUNUSED(mouseStillDown)) -{ -} - -Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) -{ - int x, y, w, h ; - window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ; - Rect bounds = { y, x, y + h, x + w }; - return bounds ; -} +WX_DECLARE_HASH_MAP(WXWidget, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap); -wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) -{ -#if wxOSX_USE_COCOA_OR_CARBON - return eventNotHandledErr ; -#else - return 0; -#endif -} +static MacControlMap wxWinMacControlList; -bool wxWindowMac::Reparent(wxWindowBase *newParentBase) +wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl ) { - wxWindowMac *newParent = (wxWindowMac *)newParentBase; - if ( !wxWindowBase::Reparent(newParent) ) - return false; + MacControlMap::iterator node = wxWinMacControlList.find(inControl); - m_peer->RemoveFromParent(); - m_peer->Embed( GetParent()->GetPeer() ); - return true; + return (node == wxWinMacControlList.end()) ? NULL : node->second; } -bool wxWindowMac::SetTransparent(wxByte alpha) +void wxAssociateWindowWithWXWidget(WXWidget inControl, wxWindow *control) { - SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); - - if ( alpha != m_macAlpha ) - { - m_macAlpha = alpha ; - Refresh() ; - } - return true ; -} - + // adding NULL ControlRef is (first) surely a result of an error and + // (secondly) breaks native event processing + wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WindowRef to window list") ); -bool wxWindowMac::CanSetTransparent() -{ - return true ; + wxWinMacControlList[inControl] = control; } -wxByte wxWindowMac::GetTransparent() const +void wxRemoveWXWidgetAssociation(wxWindow *control) { - return m_macAlpha ; -} + // iterate over all the elements in the class + // is the iterator stable ? as we might have two associations pointing to the same wxWindow + // we should go on... -bool wxWindowMac::IsShownOnScreen() const -{ - if ( m_peer && m_peer->IsOk() ) + bool found = true ; + while ( found ) { - bool peerVis = m_peer->IsVisible(); - bool wxVis = wxWindowBase::IsShownOnScreen(); - if( peerVis != wxVis ) + found = false ; + MacControlMap::iterator it; + for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) { - // CS : put a breakpoint here to investigate differences - // between native an wx visibilities - // the only place where I've encountered them until now - // are the hiding/showing sequences where the vis-changed event is - // first sent to the innermost control, while wx does things - // from the outmost control - wxVis = wxWindowBase::IsShownOnScreen(); - return wxVis; + if ( it->second == control ) + { + wxWinMacControlList.erase(it); + found = true ; + break; + } } - - return m_peer->IsVisible(); } - return wxWindowBase::IsShownOnScreen(); } -#if wxOSX_USE_CARBON -// -// impl -// - - // --------------------------------------------------------------------------- // Carbon Events // --------------------------------------------------------------------------- @@ -2989,7 +743,6 @@ wxMacWindowCommandEventHandler(EventHandlerCallRef WXUNUSED(handler), wxMenuItem* item = NULL ; wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ; - int id = wxMacCommandToId( command.commandID ) ; if ( item ) { @@ -2998,11 +751,13 @@ wxMacWindowCommandEventHandler(EventHandlerCallRef WXUNUSED(handler), switch ( cEvent.GetKind() ) { case kEventProcessCommand : - result = itemMenu->MacHandleCommandProcess( item, id, focus ); + if ( itemMenu->HandleCommandProcess( item, focus ) ) + result = noErr; break ; case kEventCommandUpdateStatus: - result = itemMenu->MacHandleCommandUpdateStatus( item, id, focus ); + if ( itemMenu->HandleCommandUpdateStatus( item, focus ) ) + result = noErr; break ; default : @@ -3064,8 +819,8 @@ pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode p } wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ; -wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, const wxPoint& pos, const wxSize& size, - long style, long extraStyle, const wxString& name) +wxWidgetImplType* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, + long style, long extraStyle) { OSStatus err = noErr; Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; @@ -3109,26 +864,25 @@ wxMacControl::wxMacControl(wxWindowMac* peer , bool isRootControl ) : wxMacControl::~wxMacControl() { -} + if ( m_controlRef && !IsRootControl() ) + { + wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") ); + wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") ); -void wxMacControl::Init() -{ + wxRemoveWXWidgetAssociation( m_wxPeer) ; + // we cannot check the ref count here anymore, as autorelease objects might delete their refs later + // we can have situations when being embedded, where the control gets deleted behind our back, so only + // CFRelease if we are safe + if ( IsValidControlHandle(m_controlRef) ) + CFRelease(m_controlRef); + } m_controlRef = NULL; - m_macControlEventHandler = NULL; } -void wxMacControl::Destroy() +void wxMacControl::Init() { - wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") ); - wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") ); - - wxRemoveWXWidgetAssociation( m_wxPeer) ; - // we cannot check the ref count here anymore, as autorelease objects might delete their refs later - // we can have situations when being embedded, where the control gets deleted behind our back, so only - // CFRelease if we are safe - if ( IsValidControlHandle(m_controlRef) ) - CFRelease(m_controlRef); m_controlRef = NULL; + m_macControlEventHandler = NULL; } void wxMacControl::SetReference( URefCon data ) @@ -3180,7 +934,13 @@ void wxMacControl::GetContentArea(int &left , int &top , int &width , int &heigh if ( GetControlRegion( m_controlRef, kControlContentMetaPart , rgn ) == noErr ) GetRegionBounds( rgn , &content ) ; else + { GetControlBounds( m_controlRef , &content ); + content.right -= content.left; + content.left = 0; + content.bottom -= content.top; + content.top = 0; + } DisposeRgn( rgn ) ; left = content.left; @@ -3212,6 +972,36 @@ void wxMacControl::GetSize( int &width, int &height ) const height = r.bottom - r.top; } +void wxMacControl::SetControlSize( wxWindowVariant variant ) +{ + ControlSize size ; + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + size = kControlSizeNormal; + break ; + + case wxWINDOW_VARIANT_SMALL : + size = kControlSizeSmall; + break ; + + case wxWINDOW_VARIANT_MINI : + // not always defined in the headers + size = 3 ; + break ; + + case wxWINDOW_VARIANT_LARGE : + size = kControlSizeLarge; + break ; + + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + + SetData(kControlEntireControl, kControlSizeTag, &size ) ; +} + void wxMacControl::ScrollRect( const wxRect *rect, int dx, int dy ) { if (GetNeedsDisplay() ) @@ -3342,16 +1132,12 @@ OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) return SendHICommand( command , inOptions ); } -void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) +void wxMacControl::PerformClick() { - unsigned long finalTicks; - - HiliteControl( m_controlRef , part ); - Delay( ticks , &finalTicks ); - HiliteControl( m_controlRef , kControlNoPart ); + HIViewSimulateClick (m_controlRef, kControlButtonPart, 0, NULL ); } -SInt32 wxMacControl::GetValue() const +wxInt32 wxMacControl::GetValue() const { return ::GetControl32BitValue( m_controlRef ); } @@ -3361,22 +1147,24 @@ SInt32 wxMacControl::GetMaximum() const return ::GetControl32BitMaximum( m_controlRef ); } -SInt32 wxMacControl::GetMinimum() const +/* +wxInt32 wxMacControl::GetMinimum() const { return ::GetControl32BitMinimum( m_controlRef ); } +*/ -void wxMacControl::SetValue( SInt32 v ) +void wxMacControl::SetValue( wxInt32 v ) { ::SetControl32BitValue( m_controlRef , v ); } -void wxMacControl::SetMinimum( SInt32 v ) +void wxMacControl::SetMinimum( wxInt32 v ) { ::SetControl32BitMinimum( m_controlRef , v ); } -void wxMacControl::SetMaximum( SInt32 v ) +void wxMacControl::SetMaximum( wxInt32 v ) { ::SetControl32BitMaximum( m_controlRef , v ); } @@ -3495,11 +1283,6 @@ void wxMacControl::SetActionProc( ControlActionUPP actionProc ) SetControlAction( m_controlRef , actionProc ); } -void wxMacControl::SetViewSize( SInt32 viewSize ) -{ - SetControlViewSize(m_controlRef , viewSize ); -} - SInt32 wxMacControl::GetViewSize() const { return GetControlViewSize( m_controlRef ); @@ -3554,22 +1337,23 @@ void wxMacControl::GetRectInWindowCoords( Rect *r ) } } -void wxMacControl::GetBestRect( Rect *r ) +void wxMacControl::GetBestRect( wxRect *rect ) const { short baselineoffset; + Rect r = {0,0,0,0}; - GetBestControlRect( m_controlRef , r , &baselineoffset ); + GetBestControlRect( m_controlRef , &r , &baselineoffset ); + *rect = wxRect( r.left, r.top, r.right - r.left, r.bottom-r.top ); } -void wxMacControl::SetLabel( const wxString &title ) +void wxMacControl::GetBestRect( Rect *r ) const { - wxFontEncoding encoding; - - if ( m_font.Ok() ) - encoding = m_font.GetEncoding(); - else - encoding = wxFont::GetDefaultEncoding(); + short baselineoffset; + GetBestControlRect( m_controlRef , r , &baselineoffset ); +} +void wxMacControl::SetLabel( const wxString &title , wxFontEncoding encoding) +{ SetControlTitleWithCFString( m_controlRef , wxCFStringRef( title , encoding ) ); } @@ -3584,6 +1368,10 @@ OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) return err; } +void wxMacControl::PulseGauge() +{ +} + // SetNeedsDisplay would not invalidate the children static void InvalidateControlAndChildren( HIViewRef control ) { @@ -3634,6 +1422,15 @@ wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control) return NULL; } +void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) ) +{ + // implemented in the respective subclasses +} + +void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(viewsize) ) +{ + // implemented in respective subclass +} // // Tab Control @@ -3648,7 +1445,7 @@ OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) // Control Factory -wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) +wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) { // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of // the content view, so we have to retrieve it explicitly @@ -3666,5 +1463,3 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) contentview->InstallEventHandler() ; return contentview; } - -#endif // wxOSX_USE_CARBON diff --git a/src/osx/checkbox_osx.cpp b/src/osx/checkbox_osx.cpp index 0e224f15d7..968e557a6e 100644 --- a/src/osx/checkbox_osx.cpp +++ b/src/osx/checkbox_osx.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/checkbox.cpp +// Name: src/osx/carbon/checkbox.cpp // Purpose: wxCheckBox // Author: Stefan Csomor // Modified by: @@ -82,31 +82,39 @@ void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) bool wxCheckBox::HandleClicked( double timestampsec ) { - wxCheckBoxState origState, newState; - - newState = origState = Get3StateValue(); - - switch (origState) + bool sendEvent = true; + wxCheckBoxState newState = Get3StateValue(); + + if ( !m_peer->ButtonClickDidStateChange() ) { - case wxCHK_UNCHECKED: - newState = wxCHK_CHECKED; - break; - - case wxCHK_CHECKED: - // If the style flag to allow the user setting the undetermined state is set, - // then set the state to undetermined; otherwise set state to unchecked. - newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED; - break; - - case wxCHK_UNDETERMINED: - newState = wxCHK_UNCHECKED; - break; - - default: - break; + wxCheckBoxState origState ; + + newState = origState = Get3StateValue(); + + switch (origState) + { + case wxCHK_UNCHECKED: + newState = wxCHK_CHECKED; + break; + + case wxCHK_CHECKED: + // If the style flag to allow the user setting the undetermined state is set, + // then set the state to undetermined; otherwise set state to unchecked. + newState = Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED; + break; + + case wxCHK_UNDETERMINED: + newState = wxCHK_UNCHECKED; + break; + + default: + break; + } + if (newState == origState) + sendEvent = false; } - if (newState != origState) + if (sendEvent) { Set3StateValue( newState ); diff --git a/src/osx/checklst.cpp b/src/osx/checklst.cpp new file mode 100644 index 0000000000..574d9ecf83 --- /dev/null +++ b/src/osx/checklst.cpp @@ -0,0 +1,152 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/osx/checklst.cpp +// Purpose: implementation of wxCheckListBox class +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id$ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// +// +// new DataBrowser-based version + + +#include "wx/wxprec.h" + +#if wxUSE_CHECKLISTBOX + +#include "wx/checklst.h" + +#ifndef WX_PRECOMP + #include "wx/arrstr.h" +#endif + +#include "wx/osx/private.h" + +IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) + +BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox) +END_EVENT_TABLE() + +void wxCheckListBox::Init() +{ +} + +bool wxCheckListBox::Create( + wxWindow *parent, + wxWindowID id, + const wxPoint &pos, + const wxSize &size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString &name ) +{ + wxCArrayString chs( choices ); + + return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name ); +} + +bool wxCheckListBox::Create( + wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + int n, + const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_macIsUserPane = false; + + wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), + wxT("only one of listbox selection modes can be specified") ); + + if ( !wxCheckListBoxBase::Create( parent, id, pos, size, n, choices, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) + return false; + + int colwidth = 30; + // TODO adapt the width according to the window variant + m_checkColumn = GetListPeer()->InsertCheckColumn(0, wxEmptyString, true, wxALIGN_CENTER, colwidth); + + return true; +} + +// ---------------------------------------------------------------------------- +// wxCheckListBox functions +// ---------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------- +// wxCheckListBox functions +// ---------------------------------------------------------------------------- + +bool wxCheckListBox::IsChecked(unsigned int n) const +{ + wxCHECK_MSG( IsValid(n), false, + _T("invalid index in wxCheckListBox::IsChecked") ); + + return m_checks[n] != 0; +} + +void wxCheckListBox::Check(unsigned int n, bool check) +{ + wxCHECK_RET( IsValid(n), + _T("invalid index in wxCheckListBox::Check") ); + + // intermediate var is needed to avoid compiler warning with VC++ + bool isChecked = m_checks[n] != 0; + if ( check != isChecked ) + { + m_checks[n] = check; + + GetListPeer()->UpdateLine(n); + } +} + +void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) +{ + if ( col == m_checkColumn ) + value.Set( IsChecked( n ) ); + else + wxListBox::GetValueCallback( n, col, value ); +} + +void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) +{ + if ( col == m_checkColumn ) + { + Check( n, value.GetIntValue() ); + + wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() ); + event.SetInt( n ); + event.SetEventObject( this ); + HandleWindowEvent( event ); + } +} + + + +// ---------------------------------------------------------------------------- +// methods forwarded to wxListBox +// ---------------------------------------------------------------------------- + +void wxCheckListBox::OnItemInserted(unsigned int pos) +{ + m_checks.Insert(false, pos ); +} + +void wxCheckListBox::DoDeleteOneItem(unsigned int n) +{ + wxListBox::DoDeleteOneItem(n); + + m_checks.RemoveAt(n); +} + +void wxCheckListBox::DoClear() +{ + m_checks.Empty(); +} + +#endif // wxUSE_CHECKLISTBOX diff --git a/src/osx/choice_osx.cpp b/src/osx/choice_osx.cpp new file mode 100644 index 0000000000..1481b1419c --- /dev/null +++ b/src/osx/choice_osx.cpp @@ -0,0 +1,291 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/carbon/choice.cpp +// Purpose: wxChoice +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: choice.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_CHOICE + +#include "wx/choice.h" + +#ifndef WX_PRECOMP + #include "wx/menu.h" + #include "wx/dcclient.h" +#endif + +#include "wx/osx/private.h" + +IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControlWithItems) + +wxChoice::~wxChoice() +{ + if ( HasClientObjectData() ) + { + unsigned int i, max = GetCount(); + + for ( i = 0; i < max; ++i ) + delete GetClientObject( i ); + } + delete m_popUpMenu; +} + +bool wxChoice::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString& name ) +{ + if ( !Create( parent, id, pos, size, 0, NULL, style, validator, name ) ) + return false; + + Append( choices ); + + if ( !choices.empty() ) + SetSelection( 0 ); + + SetInitialSize( size ); + + return true; +} + +bool wxChoice::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + int n, + const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_macIsUserPane = false; + + if ( !wxChoiceBase::Create( parent, id, pos, size, style, validator, name ) ) + return false; + + m_popUpMenu = new wxMenu(); + m_popUpMenu->SetNoEventsMode(true); + + m_peer = wxWidgetImpl::CreateChoice( this, parent, id, m_popUpMenu, pos, size, style, GetExtraStyle() ); + + MacPostControlCreate( pos, size ); + +#if !wxUSE_STL + if ( style & wxCB_SORT ) + // autosort + m_strings = wxArrayString( 1 ); +#endif + + Append(n, choices); + + // Set the first item as being selected + if (n > 0) + SetSelection( 0 ); + + // Needed because it is a wxControlWithItems + SetInitialSize( size ); + + return true; +} + +// ---------------------------------------------------------------------------- +// adding/deleting items to/from the list +// ---------------------------------------------------------------------------- + +int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, + unsigned int pos, + void **clientData, wxClientDataType type) +{ + const unsigned int numItems = items.GetCount(); + for( unsigned int i = 0; i < numItems; ++i, ++pos ) + { + unsigned int idx; + +#if wxUSE_STL + if ( IsSorted() ) + { + wxArrayString::iterator + insertPoint = std::lower_bound( m_strings.begin(), m_strings.end(), items[i] ); + idx = insertPoint - m_strings.begin(); + m_strings.insert( insertPoint, items[i] ); + } + else +#endif // wxUSE_STL + { + idx = pos; + m_strings.Insert( items[i], idx ); + } + + m_popUpMenu->Insert( idx, i+1, items[i] ); + m_datas.Insert( NULL, idx ); + AssignNewItemClientData(idx, clientData, i, type); + } + + m_peer->SetMaximum( GetCount() ); + + return pos - 1; +} + +void wxChoice::DoDeleteOneItem(unsigned int n) +{ + wxCHECK_RET( IsValid(n) , wxT("wxChoice::Delete: invalid index") ); + + if ( HasClientObjectData() ) + delete GetClientObject( n ); + + m_popUpMenu->Delete( m_popUpMenu->FindItemByPosition( n ) ); + + m_strings.RemoveAt( n ) ; + m_datas.RemoveAt( n ) ; + m_peer->SetMaximum( GetCount() ) ; + +} + +void wxChoice::DoClear() +{ + for ( unsigned int i = 0 ; i < GetCount() ; i++ ) + { + m_popUpMenu->Delete( m_popUpMenu->FindItemByPosition( 0 ) ); + } + + m_strings.Empty() ; + m_datas.Empty() ; + + m_peer->SetMaximum( 0 ) ; +} + +// ---------------------------------------------------------------------------- +// selection +// ---------------------------------------------------------------------------- +int wxChoice::GetSelection() const +{ + return m_peer->GetValue() ; +} + +void wxChoice::SetSelection( int n ) +{ + m_peer->SetValue( n ) ; +} + +// ---------------------------------------------------------------------------- +// string list functions +// ---------------------------------------------------------------------------- + +unsigned int wxChoice::GetCount() const +{ + return m_strings.GetCount() ; +} + +int wxChoice::FindString( const wxString& s, bool bCase ) const +{ +#if !wxUSE_STL + // Avoid assert for non-default args passed to sorted array Index + if ( IsSorted() ) + bCase = true; +#endif + + return m_strings.Index( s , bCase ) ; +} + +void wxChoice::SetString(unsigned int n, const wxString& s) +{ + wxCHECK_RET( IsValid(n), wxT("wxChoice::SetString(): invalid index") ); + + m_strings[n] = s ; + + m_popUpMenu->FindItemByPosition( n )->SetItemLabel( s ) ; +} + +wxString wxChoice::GetString(unsigned int n) const +{ + wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("wxChoice::GetString(): invalid index") ); + + return m_strings[n] ; +} + +// ---------------------------------------------------------------------------- +// client data +// ---------------------------------------------------------------------------- +void wxChoice::DoSetItemClientData(unsigned int n, void* clientData) +{ + wxCHECK_RET( IsValid(n), wxT("wxChoice::DoSetItemClientData: invalid index") ); + + m_datas[n] = (char*)clientData ; +} + +void * wxChoice::DoGetItemClientData(unsigned int n) const +{ + wxCHECK_MSG( IsValid(n), NULL, wxT("wxChoice::DoGetClientData: invalid index") ); + + return (void *)m_datas[n]; +} + +bool wxChoice::HandleClicked( double timestampsec ) +{ + wxCommandEvent event( wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); + + // actually n should be made sure by the os to be a valid selection, but ... + int n = GetSelection(); + if ( n > -1 ) + { + event.SetInt( n ); + event.SetString( GetStringSelection() ); + event.SetEventObject( this ); + + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject( n ) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData( n ) ); + + ProcessCommand( event ); + } + + return true ; +} + +wxSize wxChoice::DoGetBestSize() const +{ + int lbWidth = GetCount() > 0 ? 20 : 100; // some defaults + int lbHeight = 20; + int wLine; + + { + wxClientDC dc(const_cast(this)); + + // Find the widest line + for(unsigned int i = 0; i < GetCount(); i++) + { + wxString str(GetString(i)); + + wxCoord width, height ; + dc.GetTextExtent( str , &width, &height); + wLine = width ; + + lbWidth = wxMax( lbWidth, wLine ) ; + } + + // Add room for the popup arrow + lbWidth += 2 * lbHeight ; + + wxCoord width, height ; + dc.GetTextExtent( wxT("X"), &width, &height); + int cx = width ; + lbHeight += 4; + + lbWidth += cx ; + } + + return wxSize( lbWidth, lbHeight ); +} + +#endif // wxUSE_CHOICE diff --git a/src/osx/cocoa/glcanvas.mm b/src/osx/cocoa/glcanvas.mm index b00ff4a235..fa9a2e5f04 100644 --- a/src/osx/cocoa/glcanvas.mm +++ b/src/osx/cocoa/glcanvas.mm @@ -77,6 +77,10 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList) const NSOpenGLPixelFormatAttribute defaultAttribs[] = { NSOpenGLPFADoubleBuffer, + NSOpenGLPFAMinimumPolicy, + NSOpenGLPFAColorSize,8, + NSOpenGLPFAAlphaSize,0, + NSOpenGLPFADepthSize,8, (NSOpenGLPixelFormatAttribute)nil }; @@ -217,6 +221,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const return false; [m_glContext setView: win.GetHandle() ]; + [m_glContext update]; [m_glContext makeCurrentContext]; @@ -280,12 +285,12 @@ bool wxGLCanvas::Create(wxWindow *parent, if ( !m_glFormat ) return false; - m_macIsUserPane = false ; + // m_macIsUserPane = false ; if ( !wxWindow::Create(parent, id, pos, size, style, name) ) return false; - +/* NSView* sv = (parent->GetHandle() ); NSRect r = wxOSXGetFrameForControl( this, pos , size ) ; @@ -295,8 +300,48 @@ bool wxGLCanvas::Create(wxWindow *parent, [v setImplementation:m_peer]; MacPostControlCreate(pos, size) ; +*/ + return true; +} + +bool wxGLCanvas::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const int *attribList, + const wxPalette& WXUNUSED(palette)) +{ + m_needsUpdate = false; + m_macCanvasIsShown = false; + + m_glFormat = WXGLChoosePixelFormat(attribList); + if ( !m_glFormat ) + return false; + + if ( !wxWindow::Create(parent, id, pos, size, style, name) ) + return false; + + m_dummyContext = WXGLCreateContext(m_glFormat, NULL); + + static GLint gCurrentBufferName = 1; + m_bufferName = gCurrentBufferName++; + aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); + + AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); + aglSetDrawable(m_dummyContext, drawable); + + m_macCanvasIsShown = true; return true; } +wxGLCanvas::~wxGLCanvas() +{ + if ( m_glFormat ) + WXGLDestroyPixelFormat(m_glFormat); +} + + #endif // wxUSE_GLCANVAS diff --git a/src/osx/cocoa/msgdlg.mm b/src/osx/cocoa/msgdlg.mm new file mode 100644 index 0000000000..bf82c5c956 --- /dev/null +++ b/src/osx/cocoa/msgdlg.mm @@ -0,0 +1,284 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/cocoa/msgdlg.mm +// Purpose: wxMessageDialog +// Author: Stefan Csomor +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id: msgdlg.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#include "wx/msgdlg.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/app.h" +#endif + +#include "wx/thread.h" +#include "wx/osx/private.h" + + +IMPLEMENT_CLASS(wxMessageDialog, wxDialog) + + +wxMessageDialog::wxMessageDialog(wxWindow *parent, + const wxString& message, + const wxString& caption, + long style, + const wxPoint& WXUNUSED(pos)) + : wxMessageDialogBase(parent, message, caption, style) +{ + m_yes = _("Yes"); + m_no = _("No"); + m_ok = _("OK"); + m_cancel = _("Cancel"); +} + +bool wxMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no) +{ + m_yes = yes; + m_no = no; + return true; +} + +bool wxMessageDialog::SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel) +{ + m_yes = yes; + m_no = no; + m_cancel = cancel; + return true; +} + +bool wxMessageDialog::SetOKLabel(const wxString& ok) +{ + m_ok = ok; + return true; +} + +bool wxMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel) +{ + m_ok = ok; + m_cancel = cancel; + return true; +} + +int wxMessageDialog::ShowModal() +{ + int resultbutton = wxID_CANCEL; + + const long style = GetMessageDialogStyle(); + + wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") ); + + AlertType alertType = kAlertPlainAlert; + if (style & wxICON_EXCLAMATION) + alertType = kAlertCautionAlert; + else if (style & wxICON_HAND) + alertType = kAlertStopAlert; + else if (style & wxICON_INFORMATION) + alertType = kAlertNoteAlert; + else if (style & wxICON_QUESTION) + alertType = kAlertNoteAlert; + + + // work out what to display + // if the extended text is empty then we use the caption as the title + // and the message as the text (for backwards compatibility) + // but if the extended message is not empty then we use the message as the title + // and the extended message as the text because that makes more sense + + wxString msgtitle,msgtext; + if(m_extendedMessage.IsEmpty()) + { + msgtitle = m_caption; + msgtext = m_message; + } + else + { + msgtitle = m_message; + msgtext = m_extendedMessage; + } + + + if ( !wxIsMainThread() ) + { + CFStringRef defaultButtonTitle = NULL; + CFStringRef alternateButtonTitle = NULL; + CFStringRef otherButtonTitle = NULL; + + wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); + wxCFStringRef cfText( msgtext, GetFont().GetEncoding() ); + + wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() ); + wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() ); + wxCFStringRef cfOKString( m_ok.c_str() , GetFont().GetEncoding()) ; + wxCFStringRef cfCancelString( m_cancel.c_str(), GetFont().GetEncoding() ); + + int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; + + if (style & wxYES_NO) + { + if ( style & wxNO_DEFAULT ) + { + defaultButtonTitle = cfNoString; + alternateButtonTitle = cfYesString; + buttonId[0] = wxID_NO; + buttonId[1] = wxID_YES; + } + else + { + defaultButtonTitle = cfYesString; + alternateButtonTitle = cfNoString; + buttonId[0] = wxID_YES; + buttonId[1] = wxID_NO; + } + if (style & wxCANCEL) + { + otherButtonTitle = cfCancelString; + buttonId[2] = wxID_CANCEL; + } + } + else + { + // the MSW implementation even shows an OK button if it is not specified, we'll do the same + buttonId[0] = wxID_OK; + // using null as default title does not work on earlier systems + defaultButtonTitle = cfOKString; + if (style & wxCANCEL) + { + alternateButtonTitle = cfCancelString; + buttonId[1] = wxID_CANCEL; + } + } + + CFOptionFlags exitButton; + OSStatus err = CFUserNotificationDisplayAlert( + 0, alertType, NULL, NULL, NULL, cfTitle, cfText, + defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); + if (err == noErr) + resultbutton = buttonId[exitButton]; + } + else + { + short result; + + AlertStdCFStringAlertParamRec param; + wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() ); + wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() ); + wxCFStringRef cfOKString( m_ok.c_str(), GetFont().GetEncoding() ); + wxCFStringRef cfCancelString( m_cancel.c_str(), GetFont().GetEncoding() ); + + wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); + wxCFStringRef cfText( msgtext, GetFont().GetEncoding() ); + + param.movable = true; + param.flags = 0; + param.version = kStdCFStringAlertVersionOne; + + bool skipDialog = false; + + if (style & wxYES_NO) + { + if (style & wxCANCEL) + { + param.defaultText = cfYesString; + param.cancelText = cfCancelString; + param.otherText = cfNoString; + param.helpButton = false; + param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; + param.cancelButton = kAlertStdAlertCancelButton; + } + else + { + param.defaultText = cfYesString; + param.cancelText = NULL; + param.otherText = cfNoString; + param.helpButton = false; + param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; + param.cancelButton = 0; + } + } + // the MSW implementation even shows an OK button if it is not specified, we'll do the same + else + { + if (style & wxCANCEL) + { + // that's a cancel missing + param.defaultText = cfOKString; + param.cancelText = cfCancelString; + param.otherText = NULL; + param.helpButton = false; + param.defaultButton = kAlertStdAlertOKButton; + param.cancelButton = 0; + } + else + { + param.defaultText = cfOKString; + param.cancelText = NULL; + param.otherText = NULL; + param.helpButton = false; + param.defaultButton = kAlertStdAlertOKButton; + param.cancelButton = 0; + } + } + + param.position = kWindowDefaultPosition; + if ( !skipDialog ) + { + DialogRef alertRef; + CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); + RunStandardAlert( alertRef, NULL, &result ); + } + else + { + return wxID_CANCEL; + } + + if (style & wxOK) + { + switch ( result ) + { + case 1: + resultbutton = wxID_OK; + break; + + case 2: + // TODO: add Cancel button + // if (style & wxCANCEL) + // resultbutton = wxID_CANCEL; + break; + + case 3: + default: + break; + } + } + else if (style & wxYES_NO) + { + switch ( result ) + { + case 1: + resultbutton = wxID_YES; + break; + + case 2: + if (!(style & wxCANCEL)) + resultbutton = wxID_CANCEL; + break; + + case 3: + resultbutton = wxID_NO; + break; + + default: + break; + } + } + } + + return resultbutton; +} diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm new file mode 100644 index 0000000000..cc744f8c72 --- /dev/null +++ b/src/osx/cocoa/srchctrl.mm @@ -0,0 +1,394 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/osx/carbon/srchctrl.cpp +// Purpose: implements mac carbon wxSearchCtrl +// Author: Vince Harron +// Created: 2006-02-19 +// RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: Vince Harron +// License: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_SEARCHCTRL + +#include "wx/srchctrl.h" + +#ifndef WX_PRECOMP + #include "wx/menu.h" +#endif //WX_PRECOMP + +#if wxUSE_NATIVE_SEARCH_CONTROL + +#include "wx/osx/uma.h" +#include "wx/osx/carbon/private/mactext.h" + +BEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) +END_EVENT_TABLE() + +IMPLEMENT_DYNAMIC_CLASS(wxSearchCtrl, wxSearchCtrlBase) + +// ============================================================================ +// wxMacSearchFieldControl +// ============================================================================ + +static const EventTypeSpec eventList[] = +{ + { kEventClassSearchField, kEventSearchFieldCancelClicked } , + { kEventClassSearchField, kEventSearchFieldSearchClicked } , +}; + +class wxMacSearchFieldControl : public wxMacUnicodeTextControl +{ +public : + wxMacSearchFieldControl( wxTextCtrl *wxPeer, + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) : wxMacUnicodeTextControl( wxPeer ) + { + Create( wxPeer, str, pos, size, style ); + } + + // search field options + virtual void ShowSearchButton( bool show ); + virtual bool IsSearchButtonVisible() const; + + virtual void ShowCancelButton( bool show ); + virtual bool IsCancelButtonVisible() const; + + virtual void SetSearchMenu( wxMenu* menu ); + virtual wxMenu* GetSearchMenu() const; + + virtual void SetDescriptiveText(const wxString& text); + virtual wxString GetDescriptiveText() const; + + virtual bool SetFocus(); + +protected : + virtual void CreateControl( wxTextCtrl* peer, const Rect* bounds, CFStringRef crf ); + +private: + wxMenu* m_menu; +} ; + +void wxMacSearchFieldControl::CreateControl(wxTextCtrl* WXUNUSED(peer), + const Rect* bounds, + CFStringRef WXUNUSED(crf)) +{ + OptionBits attributes = kHISearchFieldAttributesSearchIcon; + + HIRect hibounds = { { bounds->left, bounds->top }, { bounds->right-bounds->left, bounds->bottom-bounds->top } }; + verify_noerr( HISearchFieldCreate( + &hibounds, + attributes, + 0, // MenuRef + CFSTR("Search"), + &m_controlRef + ) ); + HIViewSetVisible (m_controlRef, true); +} + +// search field options +void wxMacSearchFieldControl::ShowSearchButton( bool show ) +{ + OptionBits set = 0; + OptionBits clear = 0; + if ( show ) + { + set |= kHISearchFieldAttributesSearchIcon; + } + else + { + clear |= kHISearchFieldAttributesSearchIcon; + } + HISearchFieldChangeAttributes( m_controlRef, set, clear ); +} + +bool wxMacSearchFieldControl::IsSearchButtonVisible() const +{ + OptionBits attributes = 0; + verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); + return ( attributes & kHISearchFieldAttributesSearchIcon ) != 0; +} + +void wxMacSearchFieldControl::ShowCancelButton( bool show ) +{ + OptionBits set = 0; + OptionBits clear = 0; + if ( show ) + { + set |= kHISearchFieldAttributesCancel; + } + else + { + clear |= kHISearchFieldAttributesCancel; + } + HISearchFieldChangeAttributes( m_controlRef, set, clear ); +} + +bool wxMacSearchFieldControl::IsCancelButtonVisible() const +{ + OptionBits attributes = 0; + verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) ); + return ( attributes & kHISearchFieldAttributesCancel ) != 0; +} + +void wxMacSearchFieldControl::SetSearchMenu( wxMenu* menu ) +{ + m_menu = menu; + if ( m_menu ) + { + verify_noerr( HISearchFieldSetSearchMenu( m_controlRef, MAC_WXHMENU(m_menu->GetHMenu()) ) ); + } + else + { + verify_noerr( HISearchFieldSetSearchMenu( m_controlRef, 0 ) ); + } +} + +wxMenu* wxMacSearchFieldControl::GetSearchMenu() const +{ + return m_menu; +} + + +void wxMacSearchFieldControl::SetDescriptiveText(const wxString& text) +{ + verify_noerr( HISearchFieldSetDescriptiveText( + m_controlRef, + wxCFStringRef( text, wxFont::GetDefaultEncoding() ))); +} + +wxString wxMacSearchFieldControl::GetDescriptiveText() const +{ + CFStringRef cfStr; + verify_noerr( HISearchFieldCopyDescriptiveText( m_controlRef, &cfStr )); + if ( cfStr ) + { + return wxCFStringRef(cfStr).AsString(); + } + else + { + return wxEmptyString; + } +} + +bool wxMacSearchFieldControl::SetFocus() +{ + // NB: We have to implement SetFocus a little differently because kControlFocusNextPart + // leads to setting the focus on the search icon rather than the text area. + // We get around this by explicitly telling the control to set focus to the + // text area. + + OSStatus err = SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, kControlEditTextPart ); + if ( err == errCouldntSetFocus ) + return false ; + SetUserFocusWindow(GetControlOwner( m_controlRef ) ); + return true; +} + + +// ============================================================================ +// implementation +// ============================================================================ + +static pascal OSStatus wxMacSearchControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + wxMacCarbonEvent cEvent( event ) ; + + ControlRef controlRef ; + wxSearchCtrl* thisWindow = (wxSearchCtrl*) data ; + cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; + + switch( GetEventKind( event ) ) + { + case kEventSearchFieldCancelClicked : + thisWindow->MacSearchFieldCancelHit( handler , event ) ; + break ; + case kEventSearchFieldSearchClicked : + thisWindow->MacSearchFieldSearchHit( handler , event ) ; + break ; + } + + return result ; +} + +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacSearchControlEventHandler ) + + +// ---------------------------------------------------------------------------- +// wxSearchCtrl creation +// ---------------------------------------------------------------------------- + +// creation +// -------- + +wxSearchCtrl::wxSearchCtrl() +{ + Init(); +} + +wxSearchCtrl::wxSearchCtrl(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) +{ + Init(); + + Create(parent, id, value, pos, size, style, validator, name); +} + +void wxSearchCtrl::Init() +{ + m_menu = 0; +} + +bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, + const wxString& value, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) +{ + if ( !wxTextCtrl::Create(parent, id, wxEmptyString, pos, size, wxBORDER_NONE | style, validator, name) ) + { + return false; + } + + EventHandlerRef searchEventHandler; + InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacSearchControlEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, this, + (EventHandlerRef *)&searchEventHandler); + + SetValue(value); + + return true; +} + +wxSearchCtrl::~wxSearchCtrl() +{ + delete m_menu; +} + +wxSize wxSearchCtrl::DoGetBestSize() const +{ + wxSize size = wxWindow::DoGetBestSize(); + // it seems to return a default width of about 16, which is way too small here. + if (size.GetWidth() < 100) + size.SetWidth(100); + + return size; +} + + +// search control specific interfaces +// wxSearchCtrl owns menu after this call +void wxSearchCtrl::SetMenu( wxMenu* menu ) +{ + if ( menu == m_menu ) + { + // no change + return; + } + + if ( m_menu ) + { + m_menu->SetInvokingWindow( 0 ); + } + + delete m_menu; + m_menu = menu; + + if ( m_menu ) + { + m_menu->SetInvokingWindow( this ); + } + + GetPeer()->SetSearchMenu( m_menu ); +} + +wxMenu* wxSearchCtrl::GetMenu() +{ + return m_menu; +} + +void wxSearchCtrl::ShowSearchButton( bool show ) +{ + if ( IsSearchButtonVisible() == show ) + { + // no change + return; + } + GetPeer()->ShowSearchButton( show ); +} + +bool wxSearchCtrl::IsSearchButtonVisible() const +{ + return GetPeer()->IsSearchButtonVisible(); +} + + +void wxSearchCtrl::ShowCancelButton( bool show ) +{ + if ( IsCancelButtonVisible() == show ) + { + // no change + return; + } + GetPeer()->ShowCancelButton( show ); +} + +bool wxSearchCtrl::IsCancelButtonVisible() const +{ + return GetPeer()->IsCancelButtonVisible(); +} + +void wxSearchCtrl::SetDescriptiveText(const wxString& text) +{ + GetPeer()->SetDescriptiveText(text); +} + +wxString wxSearchCtrl::GetDescriptiveText() const +{ + return GetPeer()->GetDescriptiveText(); +} + +wxInt32 wxSearchCtrl::MacSearchFieldSearchHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId ); + event.SetEventObject(this); + ProcessCommand(event); + return eventNotHandledErr ; +} + +wxInt32 wxSearchCtrl::MacSearchFieldCancelHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +{ + wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, m_windowId ); + event.SetEventObject(this); + ProcessCommand(event); + return eventNotHandledErr ; +} + + +void wxSearchCtrl::CreatePeer( + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) +{ + m_peer = new wxMacSearchFieldControl( this , str , pos , size , style ); +} + +#endif // wxUSE_NATIVE_SEARCH_CONTROL + +#endif // wxUSE_SEARCHCTRL diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index f2f51d18d9..7cff3356c6 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -43,14 +43,114 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const -(void)otherMouseUp:(NSEvent *)event ; -(void)handleMouseEvent:(NSEvent *)event; +- (void)keyDown:(NSEvent *)event; +- (void)keyUp:(NSEvent *)event; +- (void)flagsChanged:(NSEvent *)event; +- (void)handleKeyEvent:(NSEvent *)event; + - (void)setImplementation: (wxWidgetImpl *) theImplementation; - (wxWidgetImpl*) implementation; - (BOOL) isFlipped; - (BOOL) becomeFirstResponder; - (BOOL) resignFirstResponder; +- (BOOL) canBecomeKeyView; @end // wxNSView +long wxOSXTranslateCocoaKey(unsigned short code, int unichar ) +{ + long retval = code; + switch( unichar ) + { + case NSUpArrowFunctionKey : + retval = WXK_UP; + break; + case NSDownArrowFunctionKey : + retval = WXK_DOWN; + break; + case NSLeftArrowFunctionKey : + retval = WXK_LEFT; + break; + case NSRightArrowFunctionKey : + retval = WXK_RIGHT; + break; + case NSInsertFunctionKey : + retval = WXK_INSERT; + break; + case NSDeleteFunctionKey : + retval = WXK_DELETE; + break; + case NSHomeFunctionKey : + retval = WXK_HOME; + break; +// case NSBeginFunctionKey : +// retval = WXK_BEGIN; +// break; + case NSEndFunctionKey : + retval = WXK_END; + break; + case NSPageUpFunctionKey : + retval = WXK_PAGEUP; + break; + case NSPageDownFunctionKey : + retval = WXK_PAGEDOWN; + break; + case NSHelpFunctionKey : + retval = WXK_HELP; + break; + + default : + if ( unichar >= NSF1FunctionKey && unichar >= NSF24FunctionKey ) + retval = WXK_F1 + (unichar - NSF1FunctionKey ); + break; + } + return retval; +} + +void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent ) +{ + UInt32 modifiers = [nsEvent modifierFlags] ; + + wxevent.m_shiftDown = modifiers & NSShiftKeyMask; + wxevent.m_controlDown = modifiers & NSControlKeyMask; + wxevent.m_altDown = modifiers & NSAlternateKeyMask; + wxevent.m_metaDown = modifiers & NSCommandKeyMask; + + wxString chars; + NSString* nschars = [nsEvent characters]; + if ( nschars ) + { + wxCFStringRef cfchars((CFStringRef)[nschars retain]); + chars = cfchars.AsString(); + } + + int unichar = chars.Length() > 0 ? chars[0] : 0; + +#if wxUSE_UNICODE + wxevent.m_uniChar = unichar; +#endif + wxevent.m_keyCode = wxOSXTranslateCocoaKey( [nsEvent keyCode], unichar ) ; +// wxevent.m_rawCode = keymessage; + wxevent.m_rawFlags = modifiers; + + wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ; + int eventType = [nsEvent type]; + switch (eventType) + { + case NSKeyDown : + wxevent.SetEventType( wxEVT_KEY_DOWN ) ; + break; + case NSKeyUp : + wxevent.SetEventType( wxEVT_KEY_UP ) ; + break; + case NSFlagsChanged : + // setup common code here + break; + default : + break ; + } +} + void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) { UInt32 modifiers = [nsEvent modifierFlags] ; @@ -285,6 +385,29 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) impl->GetWXPeer()->HandleWindowEvent(wxevent); } +- (void)keyDown:(NSEvent *)event +{ + [self handleKeyEvent:event]; +} + +- (void)keyUp:(NSEvent *)event +{ + [self handleKeyEvent:event]; +} + +- (void)flagsChanged:(NSEvent *)event +{ + [self handleKeyEvent:event]; +} + +- (void)handleKeyEvent:(NSEvent *)event +{ + wxKeyEvent wxevent(wxEVT_KEY_DOWN); + SetupKeyEvent( wxevent, event ); + impl->GetWXPeer()->HandleWindowEvent(wxevent); +} + + - (void)setImplementation: (wxWidgetImpl *) theImplementation { impl = theImplementation; @@ -318,6 +441,10 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent ) return r; } +- (BOOL) canBecomeKeyView +{ + return YES; +} @end // wxNSView diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 0b4dfcf11a..83e6b6c6f5 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -791,8 +791,8 @@ bool wxBitmap::CopyFromIcon(const wxIcon& icon) int w = icon.GetWidth() ; int h = icon.GetHeight() ; - Create( icon.GetWidth() , icon.GetHeight() ) ; -#ifndef __WXOSX_IPHONE__ + Create( w , h ) ; +#ifdef __WXOSX_CARBON__ if ( w == h && ( w == 16 || w == 32 || w == 48 || w == 128 ) ) { IconFamilyHandle iconFamily = NULL ; @@ -1021,6 +1021,16 @@ IconRef wxBitmap::CreateIconRef() const } #endif +#if wxOSX_USE_COCOA_OR_IPHONE + +WX_NSImage wxBitmap::GetNSImage() const +{ + wxCFRef< CGImageRef > cgimage(CreateCGImage()); + return wxOSXCreateNSImageFromCGImage( cgimage ); +} + +#endif + wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const { wxCHECK_MSG( Ok() && @@ -1693,7 +1703,7 @@ void wxBitmap::InitStandardHandlers() #if !defined( __LP64__ ) && !defined(__WXOSX_IPHONE__) AddHandler( new wxPICTResourceHandler ) ; #endif -#if wxOSX_USE_COCOA_OR_CARBON +#if wxOSX_USE_CARBON AddHandler( new wxICONResourceHandler ) ; #endif } diff --git a/src/osx/core/cfstring.cpp b/src/osx/core/cfstring.cpp index 2d2df5084c..f99511c1b6 100644 --- a/src/osx/core/cfstring.cpp +++ b/src/osx/core/cfstring.cpp @@ -1,9 +1,9 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/corefoundation/cfstring.cpp +// Name: src/osx/corefoundation/cfstring.cpp // Purpose: wxCFStringHolder and other string functions // Author: Stefan Csomor // Modified by: -// Created: 2004-10-29 (from code in src/mac/carbon/utils.cpp) +// Created: 2004-10-29 (from code in src/osx/carbon/utils.cpp) // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence diff --git a/src/osx/core/colour.cpp b/src/osx/core/colour.cpp index c196590923..81348d24bd 100644 --- a/src/osx/core/colour.cpp +++ b/src/osx/core/colour.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/colour.cpp +// Name: src/osx/carbon/colour.cpp // Purpose: wxColour class // Author: Stefan Csomor // Modified by: diff --git a/src/osx/core/gsockosx.cpp b/src/osx/core/gsockosx.cpp index 695dab74ca..000252b236 100644 --- a/src/osx/core/gsockosx.cpp +++ b/src/osx/core/gsockosx.cpp @@ -1,6 +1,6 @@ /* ------------------------------------------------------------------------- * Project: GSocket (Generic Socket) for WX - * Name: src/mac/corefoundation/gsockosx.c + * Name: src/osx/corefoundation/gsockosx.c * Purpose: GSocket: Mac OS X mach-o part * CVSID: $Id$ * Mac code by Brian Victor, February 2002. Email comments to bhv1@psu.edu diff --git a/src/osx/core/hid.cpp b/src/osx/core/hid.cpp index e9f4cdbaca..8b09c43ff2 100644 --- a/src/osx/core/hid.cpp +++ b/src/osx/core/hid.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/corefoundation/hid.cpp +// Name: src/osx/corefoundation/hid.cpp // Purpose: DARWIN HID layer for WX Implementation // Author: Ryan Norton // Modified by: diff --git a/src/osx/core/hidjoystick.cpp b/src/osx/core/hidjoystick.cpp index 95bc4a7bf0..2d6242d0b3 100644 --- a/src/osx/core/hidjoystick.cpp +++ b/src/osx/core/hidjoystick.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/corefoundation/joystick.cpp +// Name: src/osx/corefoundation/joystick.cpp // Purpose: wxJoystick class // Author: Ryan Norton // Modified by: diff --git a/src/osx/core/printmac.cpp b/src/osx/core/printmac.cpp index d7aae24967..522d6b8892 100644 --- a/src/osx/core/printmac.cpp +++ b/src/osx/core/printmac.cpp @@ -27,7 +27,7 @@ #include "wx/math.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" #include "wx/osx/printmac.h" #include "wx/osx/private/print.h" diff --git a/src/osx/core/strconv_cf.cpp b/src/osx/core/strconv_cf.cpp index 0c2abfbcc8..be04c8a881 100644 --- a/src/osx/core/strconv_cf.cpp +++ b/src/osx/core/strconv_cf.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/corefoundation/strconv.cpp +// Name: src/osx/corefoundation/strconv.cpp // Purpose: Unicode conversion classes // Author: David Elliott // Modified by: diff --git a/src/osx/core/utilsexc_cf.cpp b/src/osx/core/utilsexc_cf.cpp index 2d95454fe9..be96bcfb36 100644 --- a/src/osx/core/utilsexc_cf.cpp +++ b/src/osx/core/utilsexc_cf.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/corefoundation/utilsexec_cf.cpp +// Name: src/osx/corefoundation/utilsexec_cf.cpp // Purpose: Execution-related utilities for Darwin // Author: David Elliott, Ryan Norton (wxMacExecute) // Modified by: Stefan Csomor (added necessary wxT for unicode builds) @@ -7,7 +7,7 @@ // RCS-ID: $Id$ // Copyright: (c) David Elliott, Ryan Norton // Licence: wxWindows licence -// Notes: This code comes from src/mac/carbon/utilsexc.cpp,1.11 +// Notes: This code comes from src/osx/carbon/utilsexc.cpp,1.11 ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" diff --git a/src/osx/gauge_osx.cpp b/src/osx/gauge_osx.cpp new file mode 100644 index 0000000000..426e858daa --- /dev/null +++ b/src/osx/gauge_osx.cpp @@ -0,0 +1,75 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/gauge_osx.cpp +// Purpose: wxGauge class +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: gauge.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_GAUGE + +#include "wx/gauge.h" + +IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) + +#include "wx/osx/private.h" + +bool wxGauge::Create( wxWindow *parent, + wxWindowID id, + int range, + const wxPoint& pos, + const wxSize& s, + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_macIsUserPane = false; + + if ( !wxGaugeBase::Create( parent, id, range, pos, s, style & 0xE0FFFFFF, validator, name ) ) + return false; + + wxSize size = s; + + m_peer = wxWidgetImpl::CreateGauge( this, parent, id, GetValue() , 0, GetRange(), pos, size, style, GetExtraStyle() ); + + MacPostControlCreate( pos, size ); + + return true; +} + +void wxGauge::SetRange(int r) +{ + // we are going via the base class in case there is + // some change behind the values by it + wxGaugeBase::SetRange( r ) ; + if ( m_peer ) + m_peer->SetMaximum( GetRange() ) ; +} + +void wxGauge::SetValue(int pos) +{ + // we are going via the base class in case there is + // some change behind the values by it + wxGaugeBase::SetValue( pos ) ; + + if ( m_peer ) + m_peer->SetValue( GetValue() ) ; +} + +int wxGauge::GetValue() const +{ + return m_gaugePos ; +} + +void wxGauge::Pulse() +{ + m_peer->PulseGauge(); +} + +#endif // wxUSE_GAUGE + diff --git a/src/osx/glcanvas_osx.cpp b/src/osx/glcanvas_osx.cpp new file mode 100644 index 0000000000..5811ff545d --- /dev/null +++ b/src/osx/glcanvas_osx.cpp @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/mac/carbon/glcanvas.cpp +// Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Macintosh +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: glcanvas.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#if wxUSE_GLCANVAS + +#include "wx/glcanvas.h" + +#ifndef WX_PRECOMP + #include "wx/frame.h" + #include "wx/log.h" + #include "wx/settings.h" +#endif + +#include "wx/osx/private.h" + +// ---------------------------------------------------------------------------- +// wxGLCanvas +// ---------------------------------------------------------------------------- + +wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other) +{ + m_glContext = WXGLCreateContext(win->GetWXGLPixelFormat(), + other ? other->m_glContext : NULL); +} + +wxGLContext::~wxGLContext() +{ + if ( m_glContext ) + { + WXGLDestroyContext(m_glContext); + } +} + +// ---------------------------------------------------------------------------- +// wxGLCanvas +// ---------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLCanvas, wxWindow) + +BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) + EVT_SIZE(wxGLCanvas::OnSize) +END_EVENT_TABLE() + +wxGLCanvas::wxGLCanvas(wxWindow *parent, + wxWindowID id, + const int *attribList, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const wxPalette& palette) +{ + Create(parent, id, pos, size, style, name, attribList, palette); +} + +#if WXWIN_COMPATIBILITY_2_8 + +wxGLCanvas::wxGLCanvas(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const int *attribList, + const wxPalette& palette) +{ + if ( Create(parent, id, pos, size, style, name, attribList, palette) ) + m_glContext = new wxGLContext(this); +} + +wxGLCanvas::wxGLCanvas(wxWindow *parent, + const wxGLContext *shared, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const int *attribList, + const wxPalette& palette) +{ + if ( Create(parent, id, pos, size, style, name, attribList, palette) ) + m_glContext = new wxGLContext(this, shared); +} + +wxGLCanvas::wxGLCanvas(wxWindow *parent, + const wxGLCanvas *shared, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const int *attribList, + const wxPalette& palette) +{ + if ( Create(parent, id, pos, size, style, name, attribList, palette) ) + m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL); +} + +#endif // WXWIN_COMPATIBILITY_2_8 + +/* static */ +bool wxGLCanvas::IsAGLMultiSampleAvailable() +{ + static int s_isMultiSampleAvailable = -1; + if ( s_isMultiSampleAvailable == -1 ) + s_isMultiSampleAvailable = IsExtensionSupported("GL_ARB_multisample"); + + return s_isMultiSampleAvailable != 0; +} + +/* static */ +bool wxGLCanvasBase::IsDisplaySupported(const int *attribList) +{ + WXGLPixelFormat glFormat = WXGLChoosePixelFormat(attribList); + + if ( !glFormat ) + return false; + + WXGLDestroyPixelFormat(glFormat); + + return true; +} + +bool wxGLCanvas::SwapBuffers() +{ + WXGLContext context = WXGLGetCurrentContext(); + wxCHECK_MSG(context, false, _T("should have current context")); + + WXGLSwapBuffers(context); + return true; +} + +bool wxGLCanvasBase::IsExtensionSupported(const char *extension) +{ + // we need a valid context to query for extensions. + WXGLPixelFormat fmt = WXGLChoosePixelFormat(NULL); + WXGLContext ctx = WXGLCreateContext(fmt, NULL); + if ( !ctx ) + return false; + + wxString extensions = wxString::FromAscii(glGetString(GL_EXTENSIONS)); + + WXGLDestroyPixelFormat(fmt); + WXGLDestroyContext(ctx); + + return IsExtensionInList(extensions, extension); +} + +// ---------------------------------------------------------------------------- +// wxGLApp +// ---------------------------------------------------------------------------- + +bool wxGLApp::InitGLVisual(const int *attribList) +{ + WXGLPixelFormat fmt = WXGLChoosePixelFormat(attribList); + if ( !fmt ) + return false; + + WXGLDestroyPixelFormat(fmt); + return true; +} + +#endif // wxUSE_GLCANVAS diff --git a/src/osx/iphone/nonownedwnd.mm b/src/osx/iphone/nonownedwnd.mm index 4aefdca111..641357a072 100644 --- a/src/osx/iphone/nonownedwnd.mm +++ b/src/osx/iphone/nonownedwnd.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/cocoa/nonownedwnd.mm +// Name: src/osx/cocoa/nonownedwnd.mm // Purpose: non owned window for iphone // Author: Stefan Csomor // Modified by: @@ -230,3 +230,10 @@ void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y ) *y = p.y; } +wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, + long style, long extraStyle, const wxString& name ) +{ + wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer ); + now->Create( parent, pos, size, style , extraStyle, name ); + return now; +} diff --git a/src/osx/iphone/utils.mm b/src/osx/iphone/utils.mm index ba3bcf967c..6f1cb5dc33 100644 --- a/src/osx/iphone/utils.mm +++ b/src/osx/iphone/utils.mm @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/cocoa/utils.mm +// Name: src/osx/cocoa/utils.mm // Purpose: various cocoa utility functions // Author: Stefan Csomor // Modified by: diff --git a/src/osx/iphone/window.mm b/src/osx/iphone/window.mm index c5a78eb7c7..be4fcfea1c 100644 --- a/src/osx/iphone/window.mm +++ b/src/osx/iphone/window.mm @@ -19,7 +19,7 @@ @interface wxUIView : UIView { - wxWidgetImpl* m_impl; + wxWidgetImpl* ; } - (void)drawRect: (CGRect) rect; @@ -171,13 +171,13 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent - (void)drawRect: (CGRect) rect { - if ( m_impl ) + if ( ) { CGContextRef context = (CGContextRef) UIGraphicsGetCurrentContext(); CGContextSaveGState( context ); // draw background - CGContextSetFillColorWithColor( context, m_impl->GetWXPeer()->GetBackgroundColour().GetCGColor()); + CGContextSetFillColorWithColor( context, ->GetWXPeer()->GetBackgroundColour().GetCGColor()); CGContextFillRect(context, rect ); if ( [ self isFlipped ] == NO ) @@ -186,15 +186,15 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent CGContextScaleCTM( context, 1, -1 ); } - m_impl->GetWXPeer()->MacSetCGContextRef( context ); + ->GetWXPeer()->MacSetCGContextRef( context ); - m_impl->GetWXPeer()->GetUpdateRegion() = + ->GetWXPeer()->GetUpdateRegion() = wxRegion(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height) ; wxPaintEvent event; event.SetTimestamp(0); // todo - event.SetEventObject(m_impl->GetWXPeer()); - m_impl->GetWXPeer()->HandleWindowEvent(event); + event.SetEventObject(->GetWXPeer()); + ->GetWXPeer()->HandleWindowEvent(event); CGContextRestoreGState( context ); } @@ -226,19 +226,19 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSSet* touches, UIEvent * nsEvent SetupMouseEvent( wxevent , touches, event ) ; wxevent.m_x = clickLocation.x; wxevent.m_y = clickLocation.y; - wxevent.SetEventObject( m_impl->GetWXPeer() ) ; - wxevent.SetId( m_impl->GetWXPeer()->GetId() ) ; - m_impl->GetWXPeer()->HandleWindowEvent(wxevent); + wxevent.SetEventObject( ->GetWXPeer() ) ; + wxevent.SetId( ->GetWXPeer()->GetId() ) ; + ->GetWXPeer()->HandleWindowEvent(wxevent); } - (void)setImplementation: (wxWidgetImpl *) theImplementation { - m_impl = theImplementation; + = theImplementation; } - (wxWidgetImpl*) implementation { - return m_impl; + return ; } - (BOOL) isFlipped @@ -430,7 +430,7 @@ void wxWidgetIPhoneImpl::SetBackgroundColour( const wxColour &col ) // wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, const wxPoint& pos, const wxSize& size, - long style, long extraStyle, const wxString& name) + long style, long extraStyle) { UIView* sv = (wxpeer->GetParent()->GetHandle() ); diff --git a/src/osx/listbox_osx.cpp b/src/osx/listbox_osx.cpp new file mode 100644 index 0000000000..157eef3251 --- /dev/null +++ b/src/osx/listbox_osx.cpp @@ -0,0 +1,373 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/osx/carbon/listbox.cpp +// Purpose: wxListBox +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: listbox.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_LISTBOX + +#include "wx/listbox.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/intl.h" + #include "wx/utils.h" + #include "wx/settings.h" + #include "wx/arrstr.h" + #include "wx/dcclient.h" +#endif + +IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems) + +BEGIN_EVENT_TABLE(wxListBox, wxControl) +END_EVENT_TABLE() + +#include "wx/osx/private.h" + +// ============================================================================ +// list box control implementation +// ============================================================================ + +wxListBox::wxListBox() +{ +} + +bool wxListBox::Create( + wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString& name ) +{ + wxCArrayString chs(choices); + + return Create( + parent, id, pos, size, chs.GetCount(), chs.GetStrings(), + style, validator, name ); +} + +wxListWidgetImpl* wxListBox::GetListPeer() const +{ + wxListWidgetImpl* impl = dynamic_cast ( GetPeer() ); + return impl; +} + +bool wxListBox::Create( + wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + int n, + const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_blockEvents = false; + m_macIsUserPane = false; + + wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), + wxT("only a single listbox selection mode can be specified") ); + + if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) + return false; + + if ( IsSorted() ) + m_strings.sorted = new wxSortedArrayString; + else + m_strings.unsorted = new wxArrayString; + + m_peer = wxWidgetImpl::CreateListBox( this, parent, id, pos, size, style, GetExtraStyle() ); + + MacPostControlCreate( pos, size ); + + m_textColumn = GetListPeer()->InsertTextColumn(0,wxEmptyString); + + Append(n, choices); + + // Needed because it is a wxControlWithItems + SetInitialSize( size ); + + return true; +} + +wxListBox::~wxListBox() +{ + FreeData(); + // make sure no native events get sent to a object in destruction + delete m_peer; + m_peer = NULL; + + if ( IsSorted() ) + delete m_strings.sorted; + else + delete m_strings.unsorted; + + m_strings.sorted = NULL; +} + +void wxListBox::FreeData() +{ + if ( IsSorted() ) + m_strings.sorted->Clear(); + else + m_strings.unsorted->Clear(); + + m_itemsClientData.Clear(); + + GetListPeer()->ListClear(); +} + +void wxListBox::DoSetFirstItem(int n) +{ + GetListPeer()->ListScrollTo( n ); +} + +void wxListBox::EnsureVisible(int n) +{ + GetListPeer()->ListScrollTo( n ); +} + +void wxListBox::DoDeleteOneItem(unsigned int n) +{ + wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::Delete") ); + + m_blockEvents = true; + if ( IsSorted() ) + m_strings.sorted->RemoveAt(n); + else + m_strings.unsorted->RemoveAt(n); + + m_itemsClientData.RemoveAt(n); + + GetListPeer()->ListDelete( n ); + m_blockEvents = false; + + UpdateOldSelections(); +} + +void wxListBox::DoClear() +{ + m_blockEvents = true; + FreeData(); + m_blockEvents = false; + + UpdateOldSelections(); +} + +// ---------------------------------------------------------------------------- +// selection +// ---------------------------------------------------------------------------- + +void wxListBox::DoSetSelection(int n, bool select) +{ + wxCHECK_RET( n == wxNOT_FOUND || IsValid(n), + wxT("invalid index in wxListBox::SetSelection") ); + + m_blockEvents = true; + + if ( n == wxNOT_FOUND ) + GetListPeer()->ListDeselectAll(); + else + GetListPeer()->ListSetSelection( n, select, HasMultipleSelection() ); + + m_blockEvents = false; + + UpdateOldSelections(); +} + +bool wxListBox::IsSelected(int n) const +{ + wxCHECK_MSG( IsValid(n), false, wxT("invalid index in wxListBox::Selected") ); + + return GetListPeer()->ListIsSelected( n ); +} + +// Return number of selections and an array of selected integers +int wxListBox::GetSelections(wxArrayInt& aSelections) const +{ + return GetListPeer()->ListGetSelections( aSelections ); +} + +// Get single selection, for single choice list items +int wxListBox::GetSelection() const +{ + return GetListPeer()->ListGetSelection(); +} + +// ---------------------------------------------------------------------------- +// display +// ---------------------------------------------------------------------------- + +void wxListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) +{ + if ( col == m_textColumn ) + value.Set( GetString( n ) ); +} + +void wxListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) +{ +} + +wxSize wxListBox::DoGetBestSize() const +{ + int lbWidth = 100; // some defaults + int lbHeight = 110; + int wLine; + + { + wxClientDC dc(const_cast(this)); + dc.SetFont(GetFont()); + + // Find the widest line + for (unsigned int i = 0; i < GetCount(); i++) + { + wxString str( GetString( i ) ); + + wxCoord width, height ; + dc.GetTextExtent( str , &width, &height); + wLine = width ; + lbWidth = wxMax( lbWidth, wLine ); + } + + // Add room for the scrollbar + lbWidth += wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ); + + // And just a bit more + int cy = 12; + + wxCoord width, height ; + dc.GetTextExtent( wxT("XX") , &width, &height); + int cx = width ; + lbWidth += cx; + + // don't make the listbox too tall (limit height to around 10 items) + // but don't make it too small neither + lbHeight = wxMax( (cy + 4) * wxMin( wxMax( GetCount(), 3 ), 10 ), 70 ); + } + + return wxSize( lbWidth, lbHeight ); +} + +void wxListBox::Refresh(bool eraseBack, const wxRect *rect) +{ + wxControl::Refresh( eraseBack, rect ); +} + +// Some custom controls depend on this +/* static */ wxVisualAttributes +wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + wxVisualAttributes attr; + + attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); + attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); +#if wxOSX_USE_CARBON + attr.font.MacCreateFromThemeFont(kThemeViewsFont); +#else + attr.font.MacCreateFromUIFont(kCTFontViewsFontType); +#endif + + return attr; +} + +// below is all code copied from univ + +// ---------------------------------------------------------------------------- +// client data handling +// ---------------------------------------------------------------------------- + +void wxListBox::DoSetItemClientData(unsigned int n, void* clientData) +{ + m_itemsClientData[n] = clientData; +} + +void *wxListBox::DoGetItemClientData(unsigned int n) const +{ + return m_itemsClientData[n]; +} + +// ---------------------------------------------------------------------------- +// accessing strings +// ---------------------------------------------------------------------------- + +unsigned int wxListBox::GetCount() const +{ + return IsSorted() ? m_strings.sorted->size() + : m_strings.unsorted->size(); +} + +wxString wxListBox::GetString(unsigned int n) const +{ + return IsSorted() ? m_strings.sorted->Item(n) + : m_strings.unsorted->Item(n); +} + +int wxListBox::FindString(const wxString& s, bool bCase) const +{ + return IsSorted() ? m_strings.sorted->Index(s, bCase) + : m_strings.unsorted->Index(s, bCase); +} + +// ---------------------------------------------------------------------------- +// adding/inserting strings +// ---------------------------------------------------------------------------- + +void wxListBox::OnItemInserted(unsigned int WXUNUSED(pos)) +{ + +} + +int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, + unsigned int pos, + void **clientData, + wxClientDataType type) +{ + int idx = wxNOT_FOUND; + unsigned int startpos = pos; + + const unsigned int numItems = items.GetCount(); + for ( unsigned int i = 0; i < numItems; ++i ) + { + const wxString& item = items[i]; + idx = IsSorted() ? m_strings.sorted->Add(item) + : (m_strings.unsorted->Insert(item, pos), pos++); + + m_itemsClientData.Insert(NULL, idx); + AssignNewItemClientData(idx, clientData, i, type); + + GetListPeer()->ListInsert(startpos+i); + + OnItemInserted(idx); + } + + GetListPeer()->UpdateLineToEnd(startpos); + + UpdateOldSelections(); + + return idx; +} + +void wxListBox::SetString(unsigned int n, const wxString& s) +{ + wxCHECK_RET( !IsSorted(), _T("can't set string in sorted listbox") ); + + if ( IsSorted() ) + (*m_strings.sorted)[n] = s; + else + (*m_strings.unsorted)[n] = s; + + GetListPeer()->UpdateLine(n); +} + +#endif // wxUSE_LISTBOX diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp new file mode 100644 index 0000000000..c2ac17c2e9 --- /dev/null +++ b/src/osx/menu_osx.cpp @@ -0,0 +1,993 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/menu_osx.cpp +// Purpose: wxMenu, wxMenuBar, wxMenuItem +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// headers & declarations +// ============================================================================ + +// wxWidgets headers +// ----------------- + +#include "wx/wxprec.h" + +#include "wx/menu.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/frame.h" + #include "wx/menuitem.h" +#endif + +#include "wx/osx/private.h" + +// other standard headers +// ---------------------- +#include + +IMPLEMENT_ABSTRACT_CLASS( wxMenuImpl , wxObject ) + +wxMenuImpl::~wxMenuImpl() +{ +} + +IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) +IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) + +// the (popup) menu title has this special id +static const int idMenuTitle = -3; + +// ============================================================================ +// implementation +// ============================================================================ +static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ; +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ); + +// Menus + +// Construct a menu with optional title (then use append) + +static +wxMenu * +_wxMenuAt(const wxMenuList &menuList, size_t pos) +{ + wxMenuList::compatibility_iterator menuIter = menuList.GetFirst(); + + while (pos-- > 0) + menuIter = menuIter->GetNext(); + + return menuIter->GetData() ; +} + +void wxMenu::Init() +{ + m_doBreak = false; + m_startRadioGroup = -1; + m_allowRearrange = true; + m_noEventsMode = false; + + m_peer = wxMenuImpl::Create( this, wxStripMenuCodes(m_title) ); + + + // if we have a title, insert it in the beginning of the menu + if ( !m_title.empty() ) + { + Append(idMenuTitle, m_title) ; + AppendSeparator() ; + } +} + +wxMenu::~wxMenu() +{ + delete m_peer; +} + +WXHMENU wxMenu::GetHMenu() const +{ + if ( m_peer ) + return m_peer->GetHMenu(); + return NULL; +} + +void wxMenu::Break() +{ + // not available on the mac platform +} + +void wxMenu::Attach(wxMenuBarBase *menubar) +{ + wxMenuBase::Attach(menubar); + + EndRadioGroup(); +} + +void wxMenu::SetAllowRearrange( bool allow ) +{ + m_allowRearrange = allow; +} + +void wxMenu::SetNoEventsMode( bool noEvents ) +{ + m_noEventsMode = noEvents; +} + +// function appends a new item or submenu to the menu +// append a new item or submenu to the menu +bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) +{ + wxASSERT_MSG( pItem != NULL, wxT("can't append NULL item to the menu") ); + m_peer->InsertOrAppend( pItem, pos ); + + if ( pItem->IsSeparator() ) + { + // nothing to do here + } + else + { + wxMenu *pSubMenu = pItem->GetSubMenu() ; + if ( pSubMenu != NULL ) + { + wxASSERT_MSG( pSubMenu->GetHMenu() != NULL , wxT("invalid submenu added")); + pSubMenu->m_menuParent = this ; + + pSubMenu->DoRearrange(); + } + else + { + if ( pItem->GetId() == idMenuTitle ) + pItem->GetMenu()->Enable( idMenuTitle, false ); + } + } + + // if we're already attached to the menubar, we must update it + if ( IsAttached() && GetMenuBar()->IsAttached() ) + GetMenuBar()->Refresh(); + + return true ; +} + +void wxMenu::EndRadioGroup() +{ + // we're not inside a radio group any longer + m_startRadioGroup = -1; +} + +wxMenuItem* wxMenu::DoAppend(wxMenuItem *item) +{ + wxCHECK_MSG( item, NULL, _T("NULL item in wxMenu::DoAppend") ); + + bool check = false; + + if ( item->GetKind() == wxITEM_RADIO ) + { + int count = GetMenuItemCount(); + + if ( m_startRadioGroup == -1 ) + { + // start a new radio group + m_startRadioGroup = count; + + // for now it has just one element + item->SetAsRadioGroupStart(); + item->SetRadioGroupEnd(m_startRadioGroup); + + // ensure that we have a checked item in the radio group + check = true; + } + else // extend the current radio group + { + // we need to update its end item + item->SetRadioGroupStart(m_startRadioGroup); + wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_startRadioGroup); + + if ( node ) + { + node->GetData()->SetRadioGroupEnd(count); + } + else + { + wxFAIL_MSG( _T("where is the radio group start item?") ); + } + } + } + else // not a radio item + { + EndRadioGroup(); + } + + if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) ) + return NULL; + + if ( check ) + // check the item initially + item->Check(true); + + return item; +} + +wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item) +{ + if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos)) + return item; + + return NULL; +} + +wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) +{ +/* + // we need to find the items position in the child list + size_t pos; + wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); + + for ( pos = 0; node; pos++ ) + { + if ( node->GetData() == item ) + break; + + node = node->GetNext(); + } + + // DoRemove() (unlike Remove) can only be called for existing item! + wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") ); + + wxOSXMenuRemoveItem(m_hMenu , pos ); + */ + m_peer->Remove( item ); + // and from internal data structures + return wxMenuBase::DoRemove(item); +} + +void wxMenu::SetTitle(const wxString& label) +{ + m_title = label ; + m_peer->SetTitle( wxStripMenuCodes( label ) ); +} + +bool wxMenu::ProcessCommand(wxCommandEvent & event) +{ + bool processed = false; + + // Try the menu's event handler + if ( /* !processed && */ GetEventHandler()) + processed = GetEventHandler()->SafelyProcessEvent(event); + + // Try the window the menu was popped up from + // (and up through the hierarchy) + wxWindow *win = GetInvokingWindow(); + if ( !processed && win ) + processed = win->HandleWindowEvent(event); + + return processed; +} + +// --------------------------------------------------------------------------- +// other +// --------------------------------------------------------------------------- + +wxWindow *wxMenu::GetWindow() const +{ + if ( m_invokingWindow != NULL ) + return m_invokingWindow; + else if ( GetMenuBar() != NULL) + return (wxWindow *) GetMenuBar()->GetFrame(); + + return NULL; +} + +// MacOS needs to know about submenus somewhere within this menu +// before it can be displayed, also hide special menu items +// like preferences that are handled by the OS +void wxMenu::DoRearrange() +{ + if ( !AllowRearrange() ) + return; + + wxMenuItem* previousItem = NULL ; + size_t pos ; + wxMenuItemList::compatibility_iterator node; + wxMenuItem *item; + + for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++) + { + item = (wxMenuItem *)node->GetData(); + wxMenu* subMenu = item->GetSubMenu() ; + if (subMenu) + { + // already done + } + else // normal item + { + // what we do here is to hide the special items which are + // shown in the application menu anyhow -- it doesn't make + // sense to show them in their normal place as well + if ( item->GetId() == wxApp::s_macAboutMenuItemId || + item->GetId() == wxApp::s_macPreferencesMenuItemId || + item->GetId() == wxApp::s_macExitMenuItemId ) + + { + item->GetPeer()->Hide( true ); + + // also check for a separator which was used just to + // separate this item from the others, so don't leave + // separator at the menu start or end nor 2 consecutive + // separators + wxMenuItemList::compatibility_iterator nextNode = node->GetNext(); + wxMenuItem *next = nextNode ? nextNode->GetData() : NULL; + + wxMenuItem *sepToHide = 0; + if ( !previousItem && next && next->IsSeparator() ) + { + // next (i.e. second as we must be first) item is + // the separator to hide + wxASSERT_MSG( pos == 0, _T("should be the menu start") ); + sepToHide = next; + } + else if ( GetMenuItems().GetCount() == pos + 1 && + previousItem != NULL && + previousItem->IsSeparator() ) + { + // prev item is a trailing separator we want to hide + sepToHide = previousItem; + } + else if ( previousItem && previousItem->IsSeparator() && + next && next->IsSeparator() ) + { + // two consecutive separators, this is one too many + sepToHide = next; + } + + if ( sepToHide ) + { + // hide the separator as well + sepToHide->GetPeer()->Hide( true ); + } + } + } + + previousItem = item ; + } +} + + +bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow ) +{ + int id = item ? item->GetId() : 0; + wxUpdateUIEvent event(id); + event.SetEventObject( this ); + + bool processed = false; + + // Try the menu's event handler + { + wxEvtHandler *handler = GetEventHandler(); + if ( handler ) + processed = handler->ProcessEvent(event); + } + + // Try the window the menu was popped up from + // (and up through the hierarchy) + if ( !processed ) + { + const wxMenuBase *menu = this; + while ( menu ) + { + wxWindow *win = menu->GetInvokingWindow(); + if ( win ) + { + processed = win->HandleWindowEvent(event); + break; + } + + menu = menu->GetParent(); + } + } + + if ( !processed && senderWindow != NULL) + { + processed = senderWindow->HandleWindowEvent(event); + } + + if ( processed ) + { + // if anything changed, update the changed attribute + if (event.GetSetText()) + SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + Enable(id, event.GetEnabled()); + } + return processed; +} + +bool wxMenu::HandleCommandProcess( wxMenuItem* item, wxWindow* senderWindow ) +{ + int id = item ? item->GetId() : 0; + bool processed = false; + if (item->IsCheckable()) + item->Check( !item->IsChecked() ) ; + + if ( SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ) + processed = true ; + else + { + if ( senderWindow != NULL ) + { + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , id); + event.SetEventObject(senderWindow); + event.SetInt(item->IsCheckable() ? item->IsChecked() : -1); + + if ( senderWindow->HandleWindowEvent(event) ) + processed = true ; + } + } + return processed; +} + +void wxMenu::HandleMenuItemHighlighted( wxMenuItem* item ) +{ + int id = item ? item->GetId() : 0; + wxMenuEvent wxevent(wxEVT_MENU_HIGHLIGHT, id, this); + DoHandleMenuEvent( wxevent ); +} + +void wxMenu::HandleMenuOpened() +{ + wxMenuEvent wxevent(wxEVT_MENU_OPEN, 0, this); + DoHandleMenuEvent( wxevent ); +} + +void wxMenu::HandleMenuClosed() +{ + wxMenuEvent wxevent(wxEVT_MENU_CLOSE, 0, this); + DoHandleMenuEvent( wxevent ); +} + +bool wxMenu::DoHandleMenuEvent(wxEvent& wxevent) +{ + wxevent.SetEventObject(this); + wxEvtHandler* handler = GetEventHandler(); + if (handler && handler->ProcessEvent(wxevent)) + { + return true; + } + else + { + wxWindow *win = GetInvokingWindow(); + if (win) + { + if ( win->HandleWindowEvent(wxevent) ) + return true; + } + } + return false; +} + +// Menu Bar + +/* + +Mac Implementation note : + +The Mac has only one global menubar, so we attempt to install the currently +active menubar from a frame, we currently don't take into account mdi-frames +which would ask for menu-merging + +Secondly there is no mac api for changing a menubar that is not the current +menubar, so we have to wait for preparing the actual menubar until the +wxMenubar is to be used + +We can in subsequent versions use MacInstallMenuBar to provide some sort of +auto-merge for MDI in case this will be necessary + +*/ + +wxMenuBar* wxMenuBar::s_macInstalledMenuBar = NULL ; +wxMenuBar* wxMenuBar::s_macCommonMenuBar = NULL ; +bool wxMenuBar::s_macAutoWindowMenu = true ; +WXHMENU wxMenuBar::s_macWindowMenuHandle = NULL ; + +void wxMenuBar::Init() +{ + m_eventHandler = this; + m_menuBarFrame = NULL; + m_invokingWindow = (wxWindow*) NULL; + m_rootMenu = new wxMenu(); + wxMenu* applemenu = new wxMenu(); + applemenu->SetAllowRearrange(false); + applemenu->Append( wxApp::s_macAboutMenuItemId, "About..." ); + applemenu->AppendSeparator(); + applemenu->Append( wxApp::s_macPreferencesMenuItemId, "Preferences..." ); + applemenu->AppendSeparator(); + +#if ! wxOSX_USE_CARBON + applemenu->Append( wxApp::s_macExitMenuItemId, "Quit\tCtrl+Q" ); +#endif + + m_rootMenu->AppendSubMenu(applemenu, "\x14") ; +} + +wxMenuBar::wxMenuBar() +{ + Init(); +} + +wxMenuBar::wxMenuBar( long WXUNUSED(style) ) +{ + Init(); +} + +wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) +{ + Init(); + + m_titles.Alloc(count); + + for ( size_t i = 0; i < count; i++ ) + { + m_menus.Append(menus[i]); + m_titles.Add(titles[i]); + + menus[i]->Attach(this); + Append( menus[i], titles[i] ); + } +} + +wxMenuBar::~wxMenuBar() +{ + if (s_macCommonMenuBar == this) + s_macCommonMenuBar = NULL; + + if (s_macInstalledMenuBar == this) + { + s_macInstalledMenuBar = NULL; + } +} + +void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect)) +{ + wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") ); +} + +void wxMenuBar::MacInstallMenuBar() +{ + if ( s_macInstalledMenuBar == this ) + return ; + + m_rootMenu->GetPeer()->MakeRoot(); +#if 0 + + MenuBarHandle menubar = NULL ; + + menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ; + + ::SetMenuBar( menubar ) ; + DisposeMenuBar( menubar ) ; + MenuHandle appleMenu = NULL ; + + verify_noerr( CreateNewMenu( kwxMacAppleMenuId , 0 , &appleMenu ) ) ; + verify_noerr( SetMenuTitleWithCFString( appleMenu , CFSTR( "\x14" ) ) ); + + // Add About/Preferences separator only on OS X + // KH/RN: Separator is always present on 10.3 but not on 10.2 + // However, the change from 10.2 to 10.3 suggests it is preferred + InsertMenuItemTextWithCFString( appleMenu, + CFSTR(""), 0, kMenuItemAttrSeparator, 0); + InsertMenuItemTextWithCFString( appleMenu, + CFSTR("About..."), 0, 0, 0); + MacInsertMenu( appleMenu , 0 ) ; + + // if we have a mac help menu, clean it up before adding new items + MenuHandle helpMenuHandle ; + MenuItemIndex firstUserHelpMenuItem ; + + if ( UMAGetHelpMenuDontCreate( &helpMenuHandle , &firstUserHelpMenuItem) == noErr ) + { + for ( int i = CountMenuItems( helpMenuHandle ) ; i >= firstUserHelpMenuItem ; --i ) + DeleteMenuItem( helpMenuHandle , i ) ; + } + else + { + helpMenuHandle = NULL ; + } + + if ( wxApp::s_macPreferencesMenuItemId) + { + wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; + if ( item == NULL || !(item->IsEnabled()) ) + DisableMenuCommand( NULL , kHICommandPreferences ) ; + else + EnableMenuCommand( NULL , kHICommandPreferences ) ; + } + + // Unlike preferences which may or may not exist, the Quit item should be always + // enabled unless it is added by the application and then disabled, otherwise + // a program would be required to add an item with wxID_EXIT in order to get the + // Quit menu item to be enabled, which seems a bit burdensome. + if ( wxApp::s_macExitMenuItemId) + { + wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; + if ( item != NULL && !(item->IsEnabled()) ) + DisableMenuCommand( NULL , kHICommandQuit ) ; + else + EnableMenuCommand( NULL , kHICommandQuit ) ; + } + + wxString strippedHelpMenuTitle = wxStripMenuCodes( wxApp::s_macHelpMenuTitleName ) ; + wxString strippedTranslatedHelpMenuTitle = wxStripMenuCodes( wxString( _("&Help") ) ) ; + wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); + for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) + { + wxMenuItemList::compatibility_iterator node; + wxMenuItem *item; + wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; + wxString strippedMenuTitle = wxStripMenuCodes(m_titles[i]); + + if ( strippedMenuTitle == wxT("?") || strippedMenuTitle == strippedHelpMenuTitle || strippedMenuTitle == strippedTranslatedHelpMenuTitle ) + { + for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) + { + item = (wxMenuItem *)node->GetData(); + subMenu = item->GetSubMenu() ; + if (subMenu) + { + // we don't support hierarchical menus in the help menu yet + } + else + { + if ( item->GetId() != wxApp::s_macAboutMenuItemId ) + { + // we have found a user help menu and an item other than the about item, + // so we can create the mac help menu now, if we haven't created it yet + if ( helpMenuHandle == NULL ) + { + if ( UMAGetHelpMenu( &helpMenuHandle , &firstUserHelpMenuItem) != noErr ) + { + helpMenuHandle = NULL ; + break ; + } + } + } + + if ( item->IsSeparator() ) + { + if ( helpMenuHandle ) + AppendMenuItemTextWithCFString( helpMenuHandle, + CFSTR(""), kMenuItemAttrSeparator, 0,NULL); + } + else + { + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; + + if ( item->GetId() == wxApp::s_macAboutMenuItemId ) + { + // this will be taken care of below + } + else + { + if ( helpMenuHandle ) + { + UMAAppendMenuItem(helpMenuHandle, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), entry); + SetMenuItemCommandID( helpMenuHandle , CountMenuItems(helpMenuHandle) , wxIdToMacCommand ( item->GetId() ) ) ; + SetMenuItemRefCon( helpMenuHandle , CountMenuItems(helpMenuHandle) , (URefCon) item ) ; + } + } + + delete entry ; + } + } + } + } + + else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) + && GetAutoWindowMenu() ) + { + if ( MacGetWindowMenuHMenu() == NULL ) + { + CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; + } + + MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); + if ( wm == NULL ) + break; + + // get the insertion point in the standard menu + MenuItemIndex winListStart; + GetIndMenuItemWithCommandID(wm, + kHICommandWindowListSeparator, 1, NULL, &winListStart); + + // add a separator so that the standard items and the custom items + // aren't mixed together, but only if this is the first run + OSStatus err = GetIndMenuItemWithCommandID(wm, + 'WXWM', 1, NULL, NULL); + + if ( err == menuItemNotFoundErr ) + { + InsertMenuItemTextWithCFString( wm, + CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); + } + + wxInsertMenuItemsInMenu(menu, wm, winListStart); + } + else + { + UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], GetFont().GetEncoding() ) ; + menu->MacBeforeDisplay(false) ; + + ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0); + } + } + + // take care of the about menu item wherever it is + { + wxMenu* aboutMenu ; + wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; + if ( aboutMenuItem ) + { + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( aboutMenuItem->GetItemLabel() ) ; + UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetItemLabel() ) , wxFont::GetDefaultEncoding() ); + UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); + SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; + SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; + UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; + delete entry; + } + } + + if ( GetAutoWindowMenu() ) + { + if ( MacGetWindowMenuHMenu() == NULL ) + CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; + + InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; + } + + ::DrawMenuBar() ; +#endif + + s_macInstalledMenuBar = this; +} + +void wxMenuBar::EnableTop(size_t pos, bool enable) +{ + wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") ); + + m_rootMenu->FindItemByPosition( pos )->Enable(enable); + + Refresh(); +} + +bool wxMenuBar::Enable(bool enable) +{ + wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") ); + + size_t i; + for (i = 0; i < GetMenuCount(); i++) + EnableTop(i, enable); + + return true; +} + +void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label) +{ + wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); + + m_titles[pos] = label; + + if ( !IsAttached() ) + return; + + _wxMenuAt(m_menus, pos)->SetTitle( label ) ; +} + +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + + return m_titles[pos]; +} + +int wxMenuBar::FindMenu(const wxString& title) +{ + wxString menuTitle = wxStripMenuCodes(title); + + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) + { + wxString title = wxStripMenuCodes(m_titles[i]); + if ( menuTitle == title ) + return i; + } + + return wxNOT_FOUND; +} + +// --------------------------------------------------------------------------- +// wxMenuBar construction +// --------------------------------------------------------------------------- + +const int firstMenuPos = 1; // to account for the 0th application menu on mac + +wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) +{ + wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title); + if ( !menuOld ) + return NULL; + + m_titles[pos] = title; + + wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos); + m_rootMenu->Remove(item); + m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) ); + + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); + + return menuOld; +} + +bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) +{ + if ( !wxMenuBarBase::Insert(pos, menu, title) ) + return false; + + m_titles.Insert(title, pos); + + m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) ); + + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); + + return true; +} + +wxMenu *wxMenuBar::Remove(size_t pos) +{ + wxMenu *menu = wxMenuBarBase::Remove(pos); + if ( !menu ) + return NULL; + + wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos); + m_rootMenu->Remove(item); + + m_titles.RemoveAt(pos); + + return menu; +} + +bool wxMenuBar::Append(wxMenu *menu, const wxString& title) +{ + WXHMENU submenu = menu ? menu->GetHMenu() : 0; + wxCHECK_MSG( submenu, false, wxT("can't append invalid menu to menubar") ); + + if ( !wxMenuBarBase::Append(menu, title) ) + return false; + + m_titles.Add(title); + + m_rootMenu->AppendSubMenu(menu, title); + + // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables + // adding menu later on. + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); + + return true; +} + +static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) +{ + menu->SetInvokingWindow( (wxWindow*) NULL ); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); + + while (node) + { + wxMenuItem *menuitem = node->GetData(); + if (menuitem->IsSubMenu()) + wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() ); + + node = node->GetNext(); + } +} + +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) +{ + menu->SetInvokingWindow( win ); + wxMenuItem *menuitem; + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); + + while (node) + { + menuitem = node->GetData(); + if (menuitem->IsSubMenu()) + wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win ); + + node = node->GetNext(); + } +} + +void wxMenuBar::UnsetInvokingWindow() +{ + m_invokingWindow = (wxWindow*) NULL; + wxMenu *menu; + wxMenuList::compatibility_iterator node = m_menus.GetFirst(); + + while (node) + { + menu = node->GetData(); + wxMenubarUnsetInvokingWindow( menu ); + + node = node->GetNext(); + } +} + +void wxMenuBar::SetInvokingWindow(wxFrame *frame) +{ + m_invokingWindow = frame; + wxMenu *menu; + wxMenuList::compatibility_iterator node = m_menus.GetFirst(); + + while (node) + { + menu = node->GetData(); + wxMenubarSetInvokingWindow( menu, frame ); + + node = node->GetNext(); + } +} + +void wxMenuBar::Detach() +{ + wxMenuBarBase::Detach() ; +} + +void wxMenuBar::Attach(wxFrame *frame) +{ + wxMenuBarBase::Attach( frame ) ; +} + +// --------------------------------------------------------------------------- +// wxMenuBar searching for menu items +// --------------------------------------------------------------------------- + +// Find the itemString in menuString, and return the item id or wxNOT_FOUND +int wxMenuBar::FindMenuItem(const wxString& menuString, + const wxString& itemString) const +{ + wxString menuLabel = wxStripMenuCodes(menuString); + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) + { + wxString title = wxStripMenuCodes(m_titles[i]); + if ( menuLabel == title ) + return _wxMenuAt(m_menus, i)->FindItem(itemString); + } + + return wxNOT_FOUND; +} + +wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const +{ + if ( itemMenu ) + *itemMenu = NULL; + + wxMenuItem *item = NULL; + size_t count = GetMenuCount(); + for ( size_t i = 0; !item && (i < count); i++ ) + item = _wxMenuAt(m_menus, i)->FindItem(id, itemMenu); + + return item; +} diff --git a/src/osx/menuitem_osx.cpp b/src/osx/menuitem_osx.cpp new file mode 100644 index 0000000000..a680ad71fc --- /dev/null +++ b/src/osx/menuitem_osx.cpp @@ -0,0 +1,252 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/osx/menuitem_osx.cpp +// Purpose: wxMenuItem implementation +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: menuitem.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#include "wx/menuitem.h" +#include "wx/stockitem.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/menu.h" +#endif // WX_PRECOMP + +#include "wx/osx/private.h" + +IMPLEMENT_ABSTRACT_CLASS( wxMenuItemImpl , wxObject ) + +wxMenuItemImpl::~wxMenuItemImpl() +{ +} + +IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) + +wxMenuItem::wxMenuItem(wxMenu *pParentMenu, + int id, + const wxString& t, + const wxString& strHelp, + wxItemKind kind, + wxMenu *pSubMenu) + :wxMenuItemBase(pParentMenu, id, t, strHelp, kind, pSubMenu) +{ + wxASSERT_MSG( id != 0 || pSubMenu != NULL , wxT("A MenuItem ID of Zero does not work under Mac") ) ; + + // In other languages there is no difference in naming the Exit/Quit menu item between MacOS and Windows guidelines + // therefore these item must not be translated + if ( wxStripMenuCodes(m_text).Upper() == wxT("EXIT") ) + m_text = wxT("Quit\tCtrl+Q") ; + + m_radioGroup.start = -1; + m_isRadioGroupStart = false; + + wxString text = wxStripMenuCodes(m_text); + if (text.IsEmpty() && !IsSeparator()) + { + wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); + text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); + } + + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; + m_peer = wxMenuItemImpl::Create( this, pParentMenu, id, text, entry, strHelp, kind, pSubMenu ); + delete entry; +} + +wxMenuItem::~wxMenuItem() +{ + delete m_peer; +} + +// change item state +// ----------------- + +void wxMenuItem::SetBitmap(const wxBitmap& bitmap) +{ + m_bitmap = bitmap; + UpdateItemBitmap(); +} + +void wxMenuItem::Enable(bool bDoEnable) +{ + if (( m_isEnabled != bDoEnable + // avoid changing menuitem state when menu is disabled + // eg. BeginAppModalStateForWindow() will disable menus and ignore this change + // which in turn causes m_isEnabled to become out of sync with real menuitem state +#if wxOSX_USE_CARBON + && !(m_parentMenu && !IsMenuItemEnabled(MAC_WXHMENU(m_parentMenu->GetHMenu()), 0)) +#endif + ) + // always update builtin menuitems + || ( GetId() == wxApp::s_macPreferencesMenuItemId + || GetId() == wxApp::s_macExitMenuItemId + || GetId() == wxApp::s_macAboutMenuItemId + )) + { + wxMenuItemBase::Enable( bDoEnable ) ; + UpdateItemStatus() ; + } +} + +void wxMenuItem::UncheckRadio() +{ + if ( m_isChecked ) + { + wxMenuItemBase::Check( false ) ; + UpdateItemStatus() ; + } +} + +void wxMenuItem::Check(bool bDoCheck) +{ + wxCHECK_RET( IsCheckable() && !IsSeparator(), wxT("only checkable items may be checked") ); + + if ( m_isChecked != bDoCheck ) + { + if ( GetKind() == wxITEM_RADIO ) + { + if ( bDoCheck ) + { + wxMenuItemBase::Check( bDoCheck ) ; + UpdateItemStatus() ; + + // get the index of this item in the menu + const wxMenuItemList& items = m_parentMenu->GetMenuItems(); + int pos = items.IndexOf(this); + wxCHECK_RET( pos != wxNOT_FOUND, + _T("menuitem not found in the menu items list?") ); + + // get the radio group range + int start, end; + + if ( m_isRadioGroupStart ) + { + // we already have all information we need + start = pos; + end = m_radioGroup.end; + } + else // next radio group item + { + // get the radio group end from the start item + start = m_radioGroup.start; + end = items.Item(start)->GetData()->m_radioGroup.end; + } + + // also uncheck all the other items in this radio group + wxMenuItemList::compatibility_iterator node = items.Item(start); + for ( int n = start; n <= end && node; n++ ) + { + if ( n != pos ) + ((wxMenuItem*)node->GetData())->UncheckRadio(); + + node = node->GetNext(); + } + } + } + else + { + wxMenuItemBase::Check( bDoCheck ) ; + UpdateItemStatus() ; + } + } +} + +void wxMenuItem::SetItemLabel(const wxString& text) +{ + // don't do anything if label didn't change + if ( m_text == text ) + return; + + wxMenuItemBase::SetItemLabel(text); + + UpdateItemText() ; +} + + +void wxMenuItem::UpdateItemBitmap() +{ + if ( !m_parentMenu ) + return; + + if ( m_bitmap.Ok() ) + { + m_peer->SetBitmap( m_bitmap ); + } +} + +void wxMenuItem::UpdateItemStatus() +{ + if ( !m_parentMenu ) + return ; + + if ( IsSeparator() ) + return ; + + if ( IsCheckable() && IsChecked() ) + m_peer->Check( true ); + else + m_peer->Check( false ); + + m_peer->Enable( IsEnabled() ); +} + +void wxMenuItem::UpdateItemText() +{ + if ( !m_parentMenu ) + return ; + + wxString text = wxStripMenuCodes(m_text); + if (text.IsEmpty() && !IsSeparator()) + { + wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); + text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); + } + + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; + m_peer->SetLabel( text, entry ); + delete entry ; +} + +// radio group stuff +// ----------------- + +void wxMenuItem::SetAsRadioGroupStart() +{ + m_isRadioGroupStart = true; +} + +void wxMenuItem::SetRadioGroupStart(int start) +{ + wxASSERT_MSG( !m_isRadioGroupStart, + wxT("should only be called for the next radio items") ); + + m_radioGroup.start = start; +} + +void wxMenuItem::SetRadioGroupEnd(int end) +{ + wxASSERT_MSG( m_isRadioGroupStart, + wxT("should only be called for the first radio item") ); + + m_radioGroup.end = end; +} + +// ---------------------------------------------------------------------------- +// wxMenuItemBase +// ---------------------------------------------------------------------------- + +wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, + int id, + const wxString& name, + const wxString& help, + wxItemKind kind, + wxMenu *subMenu) +{ + return new wxMenuItem(parentMenu, id, name, help, kind, subMenu); +} diff --git a/src/osx/nonownedwnd_osx.cpp b/src/osx/nonownedwnd_osx.cpp index f586fcbaee..59905b824f 100644 --- a/src/osx/nonownedwnd_osx.cpp +++ b/src/osx/nonownedwnd_osx.cpp @@ -132,23 +132,9 @@ bool wxNonOwnedWindow::Create(wxWindow *parent, int w = WidthDefault(size.x); int h = HeightDefault(size.y); - // temporary define, TODO -#if wxOSX_USE_CARBON - m_nowpeer = new wxNonOwnedWindowCarbonImpl( this ); -#elif wxOSX_USE_COCOA - m_nowpeer = new wxNonOwnedWindowCocoaImpl( this ); -#elif wxOSX_USE_IPHONE - m_nowpeer = new wxNonOwnedWindowIPhoneImpl( this ); -#endif - - m_nowpeer->Create( parent, wxPoint(x,y) , wxSize(w,h) , style , GetExtraStyle(), name ) ; + m_nowpeer = wxNonOwnedWindowImpl::CreateNonOwnedWindow(this, parent, wxPoint(x,y) , wxSize(w,h) , style , GetExtraStyle(), name ); wxAssociateWindowWithWXWindow( m_nowpeer->GetWXWindow() , this ) ; -#if wxOSX_USE_CARBON - // temporary cast, TODO - m_peer = (wxMacControl*) wxWidgetImpl::CreateContentView(this); -#else m_peer = wxWidgetImpl::CreateContentView(this); -#endif DoSetWindowVariant( m_windowVariant ) ; @@ -165,9 +151,13 @@ bool wxNonOwnedWindow::Create(wxWindow *parent, wxNonOwnedWindow::~wxNonOwnedWindow() { + m_isBeingDeleted = true; + wxRemoveWXWindowAssociation( this ) ; - if ( m_nowpeer ) - m_nowpeer->Destroy(); + + DestroyChildren(); + + delete m_nowpeer; // avoid dangling refs if ( s_macDeactivateWindow == this ) @@ -216,7 +206,8 @@ bool wxNonOwnedWindow::SetBackgroundColour(const wxColour& c ) if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM ) { - return m_nowpeer->SetBackgroundColour(c); + if ( m_nowpeer ) + return m_nowpeer->SetBackgroundColour(c); } return true; } diff --git a/src/osx/carbon/radiobox.cpp b/src/osx/radiobox.cpp similarity index 95% rename from src/osx/carbon/radiobox.cpp rename to src/osx/radiobox.cpp index 9eae7ec48a..6ad4a138f9 100644 --- a/src/osx/carbon/radiobox.cpp +++ b/src/osx/radiobox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/radiobox.cpp +// Name: src/osx/radiobox.cpp // Purpose: wxRadioBox // Author: Stefan Csomor // Modified by: JS Lair (99/11/15) first implementation @@ -20,7 +20,7 @@ #include "wx/arrstr.h" #endif -#include "wx/osx/uma.h" +#include "wx/osx/private.h" IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) @@ -109,19 +109,7 @@ bool wxRadioBox::Create( wxWindow *parent, m_labelOrig = m_label = label; - Rect bounds = wxMacGetBoundsForControl( this, pos, size ); - if ( bounds.right <= bounds.left ) - bounds.right = bounds.left + 100; - if ( bounds.bottom <= bounds.top ) - bounds.bottom = bounds.top + 100; - - m_peer = new wxMacControl( this ); - - OSStatus err = CreateGroupBoxControl( - MAC_WXHWND(parent->MacGetTopLevelWindowRef()), - &bounds, CFSTR("") , true /*primary*/, - m_peer->GetControlRefAddr() ); - verify_noerr( err ); + m_peer = wxWidgetImpl::CreateGroupBox( this, parent, id, label, pos, size, style, GetExtraStyle() ); for (i = 0; i < n; i++) { diff --git a/src/osx/radiobut_osx.cpp b/src/osx/radiobut_osx.cpp index f091b9e039..a2908a0cf2 100644 --- a/src/osx/radiobut_osx.cpp +++ b/src/osx/radiobut_osx.cpp @@ -108,9 +108,12 @@ void wxRadioButton::Command(wxCommandEvent& event) bool wxRadioButton::HandleClicked( double timestampsec ) { - // if already set -> no action - if (GetValue()) - return true; + if ( !m_peer->ButtonClickDidStateChange() ) + { + // if already set -> no action + if (GetValue()) + return true; + } wxRadioButton *cycle; cycle = this->NextInCycle(); diff --git a/src/osx/scrolbar_osx.cpp b/src/osx/scrolbar_osx.cpp new file mode 100644 index 0000000000..f9e695b48b --- /dev/null +++ b/src/osx/scrolbar_osx.cpp @@ -0,0 +1,126 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/carbon/scrolbar.cpp +// Purpose: wxScrollBar +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: scrolbar.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#include "wx/scrolbar.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/settings.h" +#endif + +#include "wx/osx/private.h" + +IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) + +BEGIN_EVENT_TABLE(wxScrollBar, wxControl) +END_EVENT_TABLE() + + +bool wxScrollBar::Create( wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_macIsUserPane = false; + + if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) + return false; + + m_peer = wxWidgetImpl::CreateScrollBar( this, parent, id, pos, size, style, GetExtraStyle() ); + + MacPostControlCreate( pos, size ); + + return true; +} + +wxScrollBar::~wxScrollBar() +{ +} + +void wxScrollBar::SetThumbPosition( int viewStart ) +{ + m_peer->SetScrollThumb( viewStart, m_viewSize ); +} + +int wxScrollBar::GetThumbPosition() const +{ + return m_peer->GetValue(); +} + +void wxScrollBar::SetScrollbar( int position, + int thumbSize, + int range, + int pageSize, + bool WXUNUSED(refresh) ) +{ + m_pageSize = pageSize; + m_viewSize = thumbSize; + m_objectSize = range; + + int range1 = wxMax( (m_objectSize - m_viewSize), 0 ); + + m_peer->SetMaximum( range1 ); + m_peer->SetScrollThumb( position, m_viewSize ); +} + +void wxScrollBar::Command( wxCommandEvent& event ) +{ + SetThumbPosition( event.GetInt() ); + ProcessCommand( event ); +} + +bool wxScrollBar::HandleClicked( double timestampsec ) +{ + int new_pos = m_peer->GetValue(); + + wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId ); + if ( m_windowStyle & wxHORIZONTAL ) + event.SetOrientation( wxHORIZONTAL ); + else + event.SetOrientation( wxVERTICAL ); + + event.SetPosition( new_pos ); + event.SetEventObject( this ); + wxWindow* window = GetParent(); + if (window && window->MacIsWindowScrollbar( this )) + // this is hardcoded + window->MacOnScroll( event ); + else + HandleWindowEvent( event ); + + return true; +} + + +wxSize wxScrollBar::DoGetBestSize() const +{ + int w = 100; + int h = 100; + + if ( IsVertical() ) + { + w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + } + else + { + h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); + } + + wxSize best(w, h); + CacheBestSize(best); + return best; +} diff --git a/src/osx/slider_osx.cpp b/src/osx/slider_osx.cpp new file mode 100644 index 0000000000..45b335899d --- /dev/null +++ b/src/osx/slider_osx.cpp @@ -0,0 +1,534 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/slider_osx.cpp +// Purpose: wxSlider +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: slider.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_SLIDER + +#include "wx/slider.h" +#include "wx/osx/private.h" + +IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) + +BEGIN_EVENT_TABLE(wxSlider, wxControl) +END_EVENT_TABLE() + + // The dimensions of the different styles of sliders (from Aqua document) +#define wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS 24 +#define wxSLIDER_DIMENSIONACROSS_ARROW 18 + +// Distance between slider and text +#define wxSLIDER_BORDERTEXT 5 + +// NB: The default orientation for a slider is horizontal; however, if the user specifies +// some slider styles but doesn't specify the orientation we have to assume he wants a +// horizontal one. Therefore in this file when testing for the slider's orientation +// vertical is tested for if this is not set then we use the horizontal one +// e.g., if (GetWindowStyle() & wxSL_VERTICAL) {} else { horizontal case }. + +wxSlider::wxSlider() +{ + m_pageSize = 1; + m_lineSize = 1; + m_rangeMax = 0; + m_rangeMin = 0; + m_tickFreq = 0; + + m_macMinimumStatic = NULL; + m_macMaximumStatic = NULL; + m_macValueStatic = NULL; +} + +bool wxSlider::Create(wxWindow *parent, + wxWindowID id, + int value, int minValue, int maxValue, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + m_macIsUserPane = false; + + m_macMinimumStatic = NULL; + m_macMaximumStatic = NULL; + m_macValueStatic = NULL; + + m_lineSize = 1; + m_tickFreq = 0; + + m_rangeMax = maxValue; + m_rangeMin = minValue; + + m_pageSize = (int)((maxValue - minValue) / 10); + + // our styles are redundant: wxSL_LEFT/RIGHT imply wxSL_VERTICAL and + // wxSL_TOP/BOTTOM imply wxSL_HORIZONTAL, but for backwards compatibility + // reasons we can't really change it, instead try to infer the orientation + // from the flags given to us here + switch ( style & (wxSL_LEFT | wxSL_RIGHT | wxSL_TOP | wxSL_BOTTOM) ) + { + case wxSL_LEFT: + case wxSL_RIGHT: + style |= wxSL_VERTICAL; + break; + + case wxSL_TOP: + case wxSL_BOTTOM: + style |= wxSL_HORIZONTAL; + break; + + case 0: + default: + // no specific direction, do we have at least the orientation? + if ( !(style & (wxSL_HORIZONTAL | wxSL_VERTICAL)) ) + // no: choose default + style |= wxSL_BOTTOM | wxSL_HORIZONTAL; + break; + } + + wxASSERT_MSG( !(style & wxSL_VERTICAL) || !(style & wxSL_HORIZONTAL), + wxT("incompatible slider direction and orientation") ); + + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) + return false; + + m_peer = wxWidgetImpl::CreateSlider( this, parent, id, value, minValue, maxValue, pos, size, style, GetExtraStyle() ); + + if (style & wxSL_VERTICAL) + // Forces SetSize to use the proper width + SetSizeHints(10, -1, 10, -1); + else + // Forces SetSize to use the proper height + SetSizeHints(-1, 10, -1, 10); + + // NB: SetSizeHints is overloaded by wxSlider and will substitute 10 with the + // proper dimensions, it also means other people cannot bugger the slider with + // other values + + if (style & wxSL_LABELS) + { + m_macMinimumStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); + m_macMaximumStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); + m_macValueStatic = new wxStaticText( parent, wxID_ANY, wxEmptyString ); + } + + SetRange(minValue, maxValue); + SetValue(value); + + MacPostControlCreate(pos, size); + + return true; +} + +wxSlider::~wxSlider() +{ + // this is a special case, as we had to add windows as siblings we are + // responsible for their disposal, but only if we are not part of a DestroyAllChildren + if ( m_parent && !m_parent->IsBeingDeleted() ) + { + delete m_macMinimumStatic; + delete m_macMaximumStatic; + delete m_macValueStatic; + } +} + +int wxSlider::GetValue() const +{ + // We may need to invert the value returned by the widget + return ValueInvertOrNot( m_peer->GetValue() ) ; +} + +void wxSlider::SetValue(int value) +{ + if ( m_macValueStatic ) + { + wxString valuestring; + valuestring.Printf( wxT("%d"), value ); + m_macValueStatic->SetLabel( valuestring ); + } + + // We only invert for the setting of the actual native widget + m_peer->SetValue( ValueInvertOrNot( value ) ); +} + +void wxSlider::SetRange(int minValue, int maxValue) +{ + wxString value; + + m_rangeMin = minValue; + m_rangeMax = maxValue; + + m_peer->SetMinimum( m_rangeMin ); + m_peer->SetMaximum( m_rangeMax ); + + if (m_macMinimumStatic) + { + value.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMin ) ); + m_macMinimumStatic->SetLabel( value ); + } + + if (m_macMaximumStatic) + { + value.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMax ) ); + m_macMaximumStatic->SetLabel( value ); + } + + // If the range is out of bounds, set it to a + // value that is within bounds + // RN: Testing reveals OSX does its own + // bounding, perhaps this isn't needed? + int currentValue = GetValue(); + + if(currentValue < m_rangeMin) + SetValue(m_rangeMin); + else if(currentValue > m_rangeMax) + SetValue(m_rangeMax); +} + +// For trackbars only +void wxSlider::SetTickFreq(int n, int WXUNUSED(pos)) +{ + // TODO + m_tickFreq = n; +} + +void wxSlider::SetPageSize(int pageSize) +{ + // TODO + m_pageSize = pageSize; +} + +int wxSlider::GetPageSize() const +{ + return m_pageSize; +} + +void wxSlider::ClearSel() +{ + // TODO +} + +void wxSlider::ClearTicks() +{ + // TODO +} + +void wxSlider::SetLineSize(int lineSize) +{ + m_lineSize = lineSize; + // TODO +} + +int wxSlider::GetLineSize() const +{ + // TODO + return m_lineSize; +} + +int wxSlider::GetSelEnd() const +{ + // TODO + return 0; +} + +int wxSlider::GetSelStart() const +{ + // TODO + return 0; +} + +void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos)) +{ + // TODO +} + +void wxSlider::SetThumbLength(int WXUNUSED(len)) +{ + // TODO +} + +int wxSlider::GetThumbLength() const +{ + // TODO + return 0; +} + +void wxSlider::SetTick(int WXUNUSED(tickPos)) +{ + // TODO +} + +void wxSlider::Command(wxCommandEvent &event) +{ + SetValue(event.GetInt()); + ProcessCommand(event); +} + +void wxSlider::MacHandleControlClick(WXWidget WXUNUSED(control), + wxInt16 WXUNUSED(controlpart), + bool WXUNUSED(mouseStillDown)) +{ + // Whatever the native value is, we may need to invert it for calling + // SetValue and putting the possibly inverted value in the event + int value = ValueInvertOrNot( m_peer->GetValue() ); + + SetValue( value ); + + wxScrollEvent event( wxEVT_SCROLL_THUMBTRACK, m_windowId ); + event.SetPosition( value ); + event.SetEventObject( this ); + HandleWindowEvent( event ); + + wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); + cevent.SetInt( value ); + cevent.SetEventObject( this ); + HandleWindowEvent( cevent ); +} + +bool wxSlider::HandleClicked( double timestampsec ) +{ + // Whatever the native value is, we may need to invert it for calling + // SetValue and putting the possibly inverted value in the event + int value = ValueInvertOrNot( m_peer->GetValue() ) ; + + SetValue( value ) ; + + wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId ); + event.SetPosition( value ); + event.SetEventObject( this ); + HandleWindowEvent( event ); + + wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, m_windowId ); + cevent.SetInt( value ); + cevent.SetEventObject( this ); + + HandleWindowEvent( cevent ); + + return true; +} + +// This is overloaded in wxSlider so that the proper width/height will always be used +// for the slider different values would cause redrawing and mouse detection problems +// +void wxSlider::DoSetSizeHints( int minW, int minH, + int maxW, int maxH, + int WXUNUSED(incW), int WXUNUSED(incH) ) +{ + wxSize size = GetBestSize(); + + if (GetWindowStyle() & wxSL_VERTICAL) + { + SetMinSize( wxSize(size.x,minH) ); + SetMaxSize( wxSize(size.x,maxH) ); + } + else + { + SetMinSize( wxSize(minW,size.y) ); + SetMaxSize( wxSize(maxW,size.y) ); + } +} + +wxSize wxSlider::DoGetBestSize() const +{ + wxSize size; + int textwidth, textheight; + int mintwidth, mintheight; + int maxtwidth, maxtheight; + + textwidth = textheight = 0; + mintwidth = mintheight = 0; + maxtwidth = maxtheight = 0; + + if (GetWindowStyle() & wxSL_LABELS) + { + wxString text; + + // Get maximum text label width and height + text.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMin ) ); + GetTextExtent(text, &mintwidth, &mintheight); + text.Printf( wxT("%d"), ValueInvertOrNot( m_rangeMax ) ); + GetTextExtent(text, &maxtwidth, &maxtheight); + + if (maxtheight > mintheight) + textheight = maxtheight; + else + textheight = mintheight; + + if (maxtwidth > mintwidth) + textwidth = maxtwidth; + else + textwidth = mintwidth; + } + + if (GetWindowStyle() & wxSL_VERTICAL) + { + size.y = 150; + + if (GetWindowStyle() & wxSL_AUTOTICKS) + size.x = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS; + else + size.x = wxSLIDER_DIMENSIONACROSS_ARROW; + + if (GetWindowStyle() & wxSL_LABELS) + size.x += textwidth + wxSLIDER_BORDERTEXT; + } + else + { + size.x = 150; + + if (GetWindowStyle() & wxSL_AUTOTICKS) + size.y = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS; + else + size.y = wxSLIDER_DIMENSIONACROSS_ARROW; + + if (GetWindowStyle() & wxSL_LABELS) + { + size.y += textheight + wxSLIDER_BORDERTEXT; + size.x += (mintwidth / 2) + (maxtwidth / 2); + } + } + + return size; +} + +void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags) +{ + int yborder = 0; + int minValWidth, maxValWidth, textheight; + int sliderBreadth; + int width = w; + + if (GetWindowStyle() & wxSL_LABELS) + { + wxString text; + int ht, valValWidth; + + // Get maximum text label width and height + text.Printf(wxT("%d"), ValueInvertOrNot( m_rangeMin ) ); + GetTextExtent(text, &minValWidth, &textheight); + text.Printf(wxT("%d"), ValueInvertOrNot( m_rangeMax ) ); + GetTextExtent(text, &maxValWidth, &ht); + + if (ht > textheight) + textheight = ht; + + if (GetWindowStyle() & wxSL_HORIZONTAL) + { + if ( m_macMinimumStatic ) + { + w -= minValWidth / 2; + x += minValWidth / 2; + } + + if ( m_macMaximumStatic ) + w -= maxValWidth / 2; + } + + // Labels have this control's parent as their parent + // so if this control is not at 0,0 relative to the parent + // the labels need to know the position of this control + // relative to its parent in order to size properly, so + // move the control first so we can use GetPosition() + wxControl::DoSetSize( x, y, w, h, sizeFlags ); + + if (GetWindowStyle() & wxSL_VERTICAL) + // If vertical, use current value + text.Printf(wxT("%d"), (int)m_peer->GetValue()); + else + // Use max so that the current value doesn't drift as centering would need to change + text.Printf(wxT("%d"), m_rangeMax); + + GetTextExtent(text, &valValWidth, &ht); + + yborder = textheight + wxSLIDER_BORDERTEXT; + + // Get slider breadth + if (GetWindowStyle() & wxSL_AUTOTICKS) + sliderBreadth = wxSLIDER_DIMENSIONACROSS_WITHTICKMARKS; + else + sliderBreadth = wxSLIDER_DIMENSIONACROSS_ARROW; + + if (GetWindowStyle() & wxSL_VERTICAL) + { + h = h - yborder; + + if ( m_macMinimumStatic ) + m_macMinimumStatic->Move(GetPosition().x + sliderBreadth + wxSLIDER_BORDERTEXT, GetPosition().y + h - yborder); + if ( m_macMaximumStatic ) + m_macMaximumStatic->Move(GetPosition().x + sliderBreadth + wxSLIDER_BORDERTEXT, GetPosition().y + 0); + if ( m_macValueStatic ) + m_macValueStatic->Move(GetPosition().x + sliderBreadth + wxSLIDER_BORDERTEXT, GetPosition().y + (h / 2) - (ht / 2)); + } + else + { + if ( m_macMinimumStatic ) + m_macMinimumStatic->Move(GetPosition().x, GetPosition().y + sliderBreadth + wxSLIDER_BORDERTEXT); + if ( m_macMaximumStatic ) + m_macMaximumStatic->Move(GetPosition().x + w - maxValWidth, GetPosition().y + sliderBreadth + wxSLIDER_BORDERTEXT); + if ( m_macValueStatic ) + m_macValueStatic->Move(GetPosition().x + (w / 2) - (valValWidth / 2), GetPosition().y + sliderBreadth + wxSLIDER_BORDERTEXT); + } + } + + // yet another hack since this is a composite control + // when wxSlider has it's size hardcoded, we're not allowed to + // change the size. But when the control has labels, we DO need + // to resize the internal Mac control to accommodate the text labels. + // We need to trick the wxWidgets resize mechanism so that we can + // resize the slider part of the control ONLY. + + // TODO: Can all of this code go in the conditional wxSL_LABELS block? + + int minWidth = m_minWidth; + + if (GetWindowStyle() & wxSL_LABELS) + { + // make sure we don't allow the entire control to be resized accidently + if (width == GetSize().x) + m_minWidth = -1; + } + + // If the control has labels, we still need to call this again because + // the labels alter the control's w and h values. + wxControl::DoSetSize( x, y, w, h, sizeFlags ); + + m_minWidth = minWidth; +} + +void wxSlider::DoMoveWindow(int x, int y, int width, int height) +{ + wxControl::DoMoveWindow( x, y, width, height ); +} + +// Common processing to invert slider values based on wxSL_INVERSE +int wxSlider::ValueInvertOrNot(int value) const +{ + int result = 0; + + if (m_windowStyle & wxSL_VERTICAL) + { + // The reason for the backwards logic is that Mac's vertical sliders are + // inverted compared to Windows and GTK, hence we want inversion to be the + // default, and if wxSL_INVERSE is set, then we do not invert (use native) + if (m_windowStyle & wxSL_INVERSE) + result = value; + else + result = (m_rangeMax + m_rangeMin) - value; + } + else // normal logic applies to HORIZONTAL sliders + { + result = wxSliderBase::ValueInvertOrNot(value); + } + + return result; +} + +#endif // wxUSE_SLIDER diff --git a/src/osx/spinbutt_osx.cpp b/src/osx/spinbutt_osx.cpp new file mode 100644 index 0000000000..340678c273 --- /dev/null +++ b/src/osx/spinbutt_osx.cpp @@ -0,0 +1,98 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: spinbutt.cpp +// Purpose: wxSpinButton +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: spinbutt.cpp 54129 2008-06-11 19:30:52Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_SPINBTN + +#include "wx/spinbutt.h" +#include "wx/osx/private.h" + + +IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) + + +wxSpinButton::wxSpinButton() + : wxSpinButtonBase() +{ +} + +bool wxSpinButton::Create( wxWindow *parent, + wxWindowID id, const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) +{ + m_macIsUserPane = false; + + if ( !wxSpinButtonBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ) ) + return false; + + m_min = 0; + m_max = 100; + + if (!parent) + return false; + + m_peer = wxWidgetImpl::CreateSpinButton( this , parent, id, 0, m_min, m_max, pos, size, + style, GetExtraStyle() ); + + MacPostControlCreate( pos, size ); + + return true; +} + +wxSpinButton::~wxSpinButton() +{ +} + +void wxSpinButton::SetValue( int val ) +{ + m_peer->SetValue( val ); +} + +int wxSpinButton::GetValue() const +{ + return m_peer->GetValue(); +} + +void wxSpinButton::SetRange(int minVal, int maxVal) +{ + m_min = minVal; + m_max = maxVal; + m_peer->SetMaximum( maxVal ); + m_peer->SetMinimum( minVal ); +} + +void wxSpinButton::SendThumbTrackEvent() +{ + wxSpinEvent event( wxEVT_SCROLL_THUMBTRACK, GetId() ); + event.SetPosition( GetValue() ); + event.SetEventObject( this ); + HandleWindowEvent( event ); +} + +bool wxSpinButton::HandleClicked( double timestampsec ) +{ +#if wxOSX_USE_CARBON + // these have been handled by the live action proc already +#else + SendThumbTrackEvent() ; +#endif + + return true; +} + +wxSize wxSpinButton::DoGetBestSize() const +{ + return wxSize( 16, 24 ); +} + +#endif // wxUSE_SPINBTN diff --git a/src/osx/carbon/spinctrl.cpp b/src/osx/spinctrl.cpp similarity index 99% rename from src/osx/carbon/spinctrl.cpp rename to src/osx/spinctrl.cpp index f9b3fb9e95..3d2ed855aa 100644 --- a/src/osx/carbon/spinctrl.cpp +++ b/src/osx/spinctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/spinbutt.cpp +// Name: src/osx/carbon/spinbutt.cpp // Purpose: wxSpinCtrl // Author: Robert // Modified by: Mark Newsam (Based on GTK file) diff --git a/src/osx/srchctrl_osx.cpp b/src/osx/srchctrl_osx.cpp new file mode 100644 index 0000000000..c5de244400 --- /dev/null +++ b/src/osx/srchctrl_osx.cpp @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/osx/srchctrl_osx.cpp +// Purpose: implements mac carbon wxSearchCtrl +// Author: Vince Harron +// Created: 2006-02-19 +// RCS-ID: $Id: srchctrl.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: Vince Harron +// License: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_SEARCHCTRL + +#include "wx/srchctrl.h" + +#ifndef WX_PRECOMP + #include "wx/menu.h" +#endif //WX_PRECOMP + +#if wxUSE_NATIVE_SEARCH_CONTROL + +// no common code yet, only here as placeholder + +#endif // wxUSE_NATIVE_SEARCH_CONTROL + +#endif // wxUSE_SEARCHCTRL diff --git a/src/osx/statline_osx.cpp b/src/osx/statline_osx.cpp index edb5b50158..51903d0e91 100644 --- a/src/osx/statline_osx.cpp +++ b/src/osx/statline_osx.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/statlmac.cpp +// Name: src/osx/carbon/statlmac.cpp // Purpose: a generic wxStaticLine class // Author: Vadim Zeitlin // Created: 28.06.99 diff --git a/src/osx/stattext_osx.cpp b/src/osx/stattext_osx.cpp index 6cf8127b4e..dbaac3eede 100644 --- a/src/osx/stattext_osx.cpp +++ b/src/osx/stattext_osx.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/stattext.cpp +// Name: src/osx/carbon/stattext.cpp // Purpose: wxStaticText // Author: Stefan Csomor // Modified by: diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp new file mode 100644 index 0000000000..861cc4b92b --- /dev/null +++ b/src/osx/textctrl_osx.cpp @@ -0,0 +1,939 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/textctrl_osx.cpp +// Purpose: wxTextCtrl +// Author: Stefan Csomor +// Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) +// Created: 1998-01-01 +// RCS-ID: $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_TEXTCTRL + +#include "wx/textctrl.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/dc.h" + #include "wx/button.h" + #include "wx/menu.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" + #include "wx/toplevel.h" +#endif + +#ifdef __DARWIN__ + #include + #include +#else + #include +#endif + +#if wxUSE_STD_IOSTREAM + #if wxUSE_IOSTREAMH + #include + #else + #include + #endif +#endif + +#include "wx/filefn.h" +#include "wx/sysopt.h" +#include "wx/thread.h" + +#include "wx/osx/private.h" +#include "wx/osx/carbon/private/mactext.h" + +IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) + +BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) + EVT_DROP_FILES(wxTextCtrl::OnDropFiles) + EVT_CHAR(wxTextCtrl::OnChar) + EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) + EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) + EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) + EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) + EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) + EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) + EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) + + EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) + + EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) + EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) + EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) +END_EVENT_TABLE() + + +void wxTextCtrl::Init() +{ + m_editable = true ; + m_dirty = false; + + m_maxLength = 0; + m_privateContextMenu = NULL; + m_triggerOnSetValue = true ; +} + +wxTextCtrl::~wxTextCtrl() +{ +#if wxUSE_MENUS + delete m_privateContextMenu; +#endif +} + +bool wxTextCtrl::Create( wxWindow *parent, + wxWindowID id, + const wxString& str, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name ) +{ + m_macIsUserPane = false ; + m_editable = true ; + + if ( ! (style & wxNO_BORDER) ) + style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; + + if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) + return false; + + if ( m_windowStyle & wxTE_MULTILINE ) + { + // always turn on this style for multi-line controls + m_windowStyle |= wxTE_PROCESS_ENTER; + style |= wxTE_PROCESS_ENTER ; + } + + m_peer = wxWidgetImpl::CreateTextControl( this, parent, id, str, pos, size, style, GetExtraStyle() ); + + // CreatePeer( str, pos, size, style ); + + MacPostControlCreate(pos, size) ; + + // only now the embedding is correct and we can do a positioning update + + MacSuperChangedPosition() ; + + if ( m_windowStyle & wxTE_READONLY) + SetEditable( false ) ; + + SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; + + return true; +} + +void wxTextCtrl::CreatePeer( + const wxString& str, + const wxPoint& pos, + const wxSize& size, long style ) +{ +} + +void wxTextCtrl::MacSuperChangedPosition() +{ + wxWindow::MacSuperChangedPosition() ; +#if wxOSX_USE_CARBON + GetPeer()->SuperChangedPosition() ; +#endif +} + +void wxTextCtrl::MacVisibilityChanged() +{ +#if wxOSX_USE_CARBON + GetPeer()->VisibilityChanged( GetPeer()->IsVisible() ); +#endif +} + +void wxTextCtrl::MacCheckSpelling(bool check) +{ + GetPeer()->CheckSpelling(check); +} + +wxString wxTextCtrl::GetValue() const +{ + return GetPeer()->GetStringValue() ; +} + +void wxTextCtrl::GetSelection(long* from, long* to) const +{ + GetPeer()->GetSelection( from , to ) ; +} + +void wxTextCtrl::DoSetValue(const wxString& str, int flags) +{ + // optimize redraws + if ( GetValue() == str ) + return; + + GetPeer()->SetStringValue( str ) ; + + if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) + { + SendTextUpdatedEvent(); + } +} + +void wxTextCtrl::SetMaxLength(unsigned long len) +{ + m_maxLength = len ; +} + +bool wxTextCtrl::SetFont( const wxFont& font ) +{ + if ( !wxTextCtrlBase::SetFont( font ) ) + return false ; + + GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; + + return true ; +} + +bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) +{ + GetPeer()->SetStyle( start , end , style ) ; + + return true ; +} + +bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) +{ + wxTextCtrlBase::SetDefaultStyle( style ) ; + SetStyle( -1 /*current selection*/ , -1 /*current selection*/ , GetDefaultStyle() ) ; + + return true ; +} + +// Clipboard operations + +void wxTextCtrl::Copy() +{ + if (CanCopy()) + GetPeer()->Copy() ; +} + +void wxTextCtrl::Cut() +{ + if (CanCut()) + { + GetPeer()->Cut() ; + + wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); + event.SetEventObject( this ); + HandleWindowEvent( event ); + } +} + +void wxTextCtrl::Paste() +{ + if (CanPaste()) + { + GetPeer()->Paste() ; + + // TODO: eventually we should add setting the default style again + + wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); + event.SetEventObject( this ); + HandleWindowEvent( event ); + } +} + +bool wxTextCtrl::CanCopy() const +{ + // Can copy if there's a selection + long from, to; + GetSelection( &from, &to ); + + return (from != to); +} + +bool wxTextCtrl::CanCut() const +{ + if ( !IsEditable() ) + return false; + + // Can cut if there's a selection + long from, to; + GetSelection( &from, &to ); + + return (from != to); +} + +bool wxTextCtrl::CanPaste() const +{ + if (!IsEditable()) + return false; + + return GetPeer()->CanPaste() ; +} + +void wxTextCtrl::SetEditable(bool editable) +{ + if ( editable != m_editable ) + { + m_editable = editable ; + GetPeer()->SetEditable( editable ) ; + } +} + +void wxTextCtrl::SetInsertionPoint(long pos) +{ + SetSelection( pos , pos ) ; +} + +void wxTextCtrl::SetInsertionPointEnd() +{ + wxTextPos pos = GetLastPosition(); + SetInsertionPoint( pos ); +} + +long wxTextCtrl::GetInsertionPoint() const +{ + long begin, end ; + GetSelection( &begin , &end ) ; + + return begin ; +} + +wxTextPos wxTextCtrl::GetLastPosition() const +{ + return GetPeer()->GetLastPosition() ; +} + +void wxTextCtrl::Replace(long from, long to, const wxString& str) +{ + GetPeer()->Replace( from , to , str ) ; +} + +void wxTextCtrl::Remove(long from, long to) +{ + GetPeer()->Remove( from , to ) ; +} + +void wxTextCtrl::SetSelection(long from, long to) +{ + GetPeer()->SetSelection( from , to ) ; +} + +void wxTextCtrl::WriteText(const wxString& str) +{ + GetPeer()->WriteText( str ) ; +} + +void wxTextCtrl::AppendText(const wxString& text) +{ + SetInsertionPointEnd(); + WriteText( text ); +} + +void wxTextCtrl::Clear() +{ + GetPeer()->Clear() ; +} + +bool wxTextCtrl::IsModified() const +{ + return m_dirty; +} + +bool wxTextCtrl::IsEditable() const +{ + return IsEnabled() && m_editable ; +} + +bool wxTextCtrl::AcceptsFocus() const +{ + // we don't want focus if we can't be edited + return /*IsEditable() && */ wxControl::AcceptsFocus(); +} + +wxSize wxTextCtrl::DoGetBestSize() const +{ + int wText, hText; + + // these are the numbers from the HIG: + // we reduce them by the borders first + wText = 100 ; + + switch ( m_windowVariant ) + { + case wxWINDOW_VARIANT_NORMAL : + hText = 22 - 6 ; + break ; + + case wxWINDOW_VARIANT_SMALL : + hText = 19 - 6 ; + break ; + + case wxWINDOW_VARIANT_MINI : + hText = 15 - 6 ; + break ; + + default : + hText = 22 - 6; + break ; + } + + // as the above numbers have some free space around the text + // we get 5 lines like this anyway + if ( m_windowStyle & wxTE_MULTILINE ) + hText *= 5 ; + + if ( !HasFlag(wxNO_BORDER) ) + hText += 6 ; + + return wxSize(wText, hText); +} + +// ---------------------------------------------------------------------------- +// Undo/redo +// ---------------------------------------------------------------------------- + +void wxTextCtrl::Undo() +{ + if (CanUndo()) + GetPeer()->Undo() ; +} + +void wxTextCtrl::Redo() +{ + if (CanRedo()) + GetPeer()->Redo() ; +} + +bool wxTextCtrl::CanUndo() const +{ + if ( !IsEditable() ) + return false ; + + return GetPeer()->CanUndo() ; +} + +bool wxTextCtrl::CanRedo() const +{ + if ( !IsEditable() ) + return false ; + + return GetPeer()->CanRedo() ; +} + +void wxTextCtrl::MarkDirty() +{ + m_dirty = true; +} + +void wxTextCtrl::DiscardEdits() +{ + m_dirty = false; +} + +int wxTextCtrl::GetNumberOfLines() const +{ + return GetPeer()->GetNumberOfLines() ; +} + +long wxTextCtrl::XYToPosition(long x, long y) const +{ + return GetPeer()->XYToPosition( x , y ) ; +} + +bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const +{ + return GetPeer()->PositionToXY( pos , x , y ) ; +} + +void wxTextCtrl::ShowPosition(long pos) +{ + return GetPeer()->ShowPosition(pos) ; +} + +int wxTextCtrl::GetLineLength(long lineNo) const +{ + return GetPeer()->GetLineLength(lineNo) ; +} + +wxString wxTextCtrl::GetLineText(long lineNo) const +{ + return GetPeer()->GetLineText(lineNo) ; +} + +void wxTextCtrl::Command(wxCommandEvent & event) +{ + SetValue(event.GetString()); + ProcessCommand(event); +} + +void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) +{ + // By default, load the first file into the text window. + if (event.GetNumberOfFiles() > 0) + LoadFile( event.GetFiles()[0] ); +} + +void wxTextCtrl::OnChar(wxKeyEvent& event) +{ + int key = event.GetKeyCode() ; + bool eat_key = false ; + long from, to; + + if ( key == 'a' && event.MetaDown() ) + { + SelectAll() ; + + return ; + } + + if ( key == 'c' && event.MetaDown() ) + { + if ( CanCopy() ) + Copy() ; + + return ; + } + + if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && + !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) +// && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END + ) + { + // eat it + return ; + } + + // Check if we have reached the max # of chars (if it is set), but still + // allow navigation and deletion + GetSelection( &from, &to ); + if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && + key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && key != WXK_UP && key != WXK_DOWN && + key != WXK_BACK && key != WXK_DELETE && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && + from == to ) + { + // eat it, we don't want to add more than allowed # of characters + + // TODO: generate EVT_TEXT_MAXLEN() + return; + } + + // assume that any key not processed yet is going to modify the control + m_dirty = true; + + if ( key == 'v' && event.MetaDown() ) + { + if ( CanPaste() ) + Paste() ; + + return ; + } + + if ( key == 'x' && event.MetaDown() ) + { + if ( CanCut() ) + Cut() ; + + return ; + } + + switch ( key ) + { + case WXK_RETURN: + if (m_windowStyle & wxTE_PROCESS_ENTER) + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); + event.SetEventObject( this ); + event.SetString( GetValue() ); + if ( HandleWindowEvent(event) ) + return; + } + + if ( !(m_windowStyle & wxTE_MULTILINE) ) + { + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw && tlw->GetDefaultItem() ) + { + wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); + if ( def && def->IsEnabled() ) + { + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + + return ; + } + } + + // this will make wxWidgets eat the ENTER key so that + // we actually prevent line wrapping in a single line text control + eat_key = true; + } + break; + + case WXK_TAB: + if ( !(m_windowStyle & wxTE_PROCESS_TAB)) + { + int flags = 0; + if (!event.ShiftDown()) + flags |= wxNavigationKeyEvent::IsForward ; + if (event.ControlDown()) + flags |= wxNavigationKeyEvent::WinChange ; + Navigate(flags); + + return; + } + else + { + // This is necessary (don't know why); + // otherwise the tab will not be inserted. + WriteText(wxT("\t")); + eat_key = true; + } + break; + + default: + break; + } + + if (!eat_key) + { + // perform keystroke handling + event.Skip(true) ; + } + + if ( ( key >= 0x20 && key < WXK_START ) || + ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || + key == WXK_RETURN || + key == WXK_DELETE || + key == WXK_BACK) + { + wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event1.SetEventObject( this ); + wxPostEvent( GetEventHandler(), event1 ); + } +} + +// ---------------------------------------------------------------------------- +// standard handlers for standard edit menu events +// ---------------------------------------------------------------------------- + +void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) +{ + Cut(); +} + +void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) +{ + Copy(); +} + +void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) +{ + Paste(); +} + +void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) +{ + Undo(); +} + +void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) +{ + Redo(); +} + +void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) +{ + long from, to; + + GetSelection( &from, &to ); + if (from != -1 && to != -1) + Remove( from, to ); +} + +void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) +{ + SetSelection(-1, -1); +} + +void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) +{ + event.Enable( CanCut() ); +} + +void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) +{ + event.Enable( CanCopy() ); +} + +void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) +{ + event.Enable( CanPaste() ); +} + +void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); +} + +void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) +{ + long from, to; + + GetSelection( &from, &to ); + event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ; +} + +void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) +{ + event.Enable(GetLastPosition() > 0); +} + +// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment + +void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) +{ + if ( GetPeer()->HasOwnContextMenu() ) + { + event.Skip() ; + return ; + } + +#if wxUSE_MENUS + if (m_privateContextMenu == NULL) + { + m_privateContextMenu = new wxMenu; + m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); + m_privateContextMenu->Append(wxID_REDO, _("&Redo")); + m_privateContextMenu->AppendSeparator(); + m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); + m_privateContextMenu->Append(wxID_COPY, _("&Copy")); + m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); + m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); + m_privateContextMenu->AppendSeparator(); + m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); + } + + if (m_privateContextMenu != NULL) + PopupMenu(m_privateContextMenu); +#endif +} + +bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) +{ + if ( !GetPeer()->SetupCursor( pt ) ) + return wxWindow::MacSetupCursor( pt ) ; + else + return true ; +} + +// ---------------------------------------------------------------------------- +// implementation base class +// ---------------------------------------------------------------------------- + +#if wxOSX_USE_CARBON + wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : + wxMacControl( peer ) +#else + wxMacTextControl::wxMacTextControl(wxTextCtrl* peer, WXWidget w) : + wxWidgetCocoaImpl( peer, w ) +#endif +{ +} + +wxMacTextControl::~wxMacTextControl() +{ +} + +void wxMacTextControl::SetStyle(long WXUNUSED(start), + long WXUNUSED(end), + const wxTextAttr& WXUNUSED(style)) +{ +} + +void wxMacTextControl::Copy() +{ +} + +void wxMacTextControl::Cut() +{ +} + +void wxMacTextControl::Paste() +{ +} + +bool wxMacTextControl::CanPaste() const +{ + return false ; +} + +void wxMacTextControl::SetEditable(bool WXUNUSED(editable)) +{ +} + +wxTextPos wxMacTextControl::GetLastPosition() const +{ + return GetStringValue().length() ; +} + +void wxMacTextControl::Replace( long from , long to , const wxString &val ) +{ + SetSelection( from , to ) ; + WriteText( val ) ; +} + +void wxMacTextControl::Remove( long from , long to ) +{ + SetSelection( from , to ) ; + WriteText( wxEmptyString) ; +} + +void wxMacTextControl::Clear() +{ + SetStringValue( wxEmptyString ) ; +} + +bool wxMacTextControl::CanUndo() const +{ + return false ; +} + +void wxMacTextControl::Undo() +{ +} + +bool wxMacTextControl::CanRedo() const +{ + return false ; +} + +void wxMacTextControl::Redo() +{ +} + +long wxMacTextControl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const +{ + return 0 ; +} + +bool wxMacTextControl::PositionToXY(long WXUNUSED(pos), + long *WXUNUSED(x), + long *WXUNUSED(y)) const +{ + return false ; +} + +void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) +{ +} + +int wxMacTextControl::GetNumberOfLines() const +{ + ItemCount lines = 0 ; + wxString content = GetStringValue() ; + lines = 1; + + for (size_t i = 0; i < content.length() ; i++) + { + if (content[i] == '\r') + lines++; + } + + return lines ; +} + +wxString wxMacTextControl::GetLineText(long lineNo) const +{ + // TODO: change this if possible to reflect real lines + wxString content = GetStringValue() ; + + // Find line first + int count = 0; + for (size_t i = 0; i < content.length() ; i++) + { + if (count == lineNo) + { + // Add chars in line then + wxString tmp; + + for (size_t j = i; j < content.length(); j++) + { + if (content[j] == '\n') + return tmp; + + tmp += content[j]; + } + + return tmp; + } + + if (content[i] == '\n') + count++; + } + + return wxEmptyString ; +} + +int wxMacTextControl::GetLineLength(long lineNo) const +{ + // TODO: change this if possible to reflect real lines + wxString content = GetStringValue() ; + + // Find line first + int count = 0; + for (size_t i = 0; i < content.length() ; i++) + { + if (count == lineNo) + { + // Count chars in line then + count = 0; + for (size_t j = i; j < content.length(); j++) + { + count++; + if (content[j] == '\n') + return count; + } + + return count; + } + + if (content[i] == '\n') + count++; + } + + return 0 ; +} + +void wxMacTextControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) +{ +#if wxOSX_USE_CARBON + wxMacControl::SetFont(font, foreground, windowStyle ); + + // overrule the barrier in wxMacControl for supporting disabled controls, in order to support + // setting the color to eg red and back to black by controllers + + if ( foreground == *wxBLACK ) + { + ControlFontStyleRec fontStyle; + fontStyle.foreColor.red = fontStyle.foreColor.green = fontStyle.foreColor.blue = 0; + fontStyle.flags = kControlUseForeColorMask; + ::SetControlFontStyle( m_controlRef , &fontStyle ); + } +#endif +} + +#endif // wxUSE_TEXTCTRL diff --git a/src/osx/toolbar_osx.cpp b/src/osx/toolbar_osx.cpp new file mode 100644 index 0000000000..310eb916b5 --- /dev/null +++ b/src/osx/toolbar_osx.cpp @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/carbon/toolbar.cpp +// Purpose: wxToolBar +// Author: Stefan Csomor +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id: toolbar.cpp 54954 2008-08-03 11:27:03Z VZ $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#if wxUSE_TOOLBAR + +#include "wx/toolbar.h" + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/app.h" +#include "wx/osx/private.h" +#include "wx/geometry.h" +#include "wx/sysopt.h" + +IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) + +// no common implementation + +#endif // wxUSE_TOOLBAR diff --git a/src/osx/carbon/toplevel.cpp b/src/osx/toplevel.cpp similarity index 98% rename from src/osx/carbon/toplevel.cpp rename to src/osx/toplevel.cpp index f80a5382d6..1886e988c9 100644 --- a/src/osx/carbon/toplevel.cpp +++ b/src/osx/toplevel.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/toplevel.cpp +// Name: src/osx/toplevel.cpp // Purpose: implements wxTopLevelWindow for Mac // Author: Stefan Csomor // Modified by: diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp index 963451ea4a..452a61cac7 100644 --- a/src/osx/utils_osx.cpp +++ b/src/osx/utils_osx.cpp @@ -57,10 +57,6 @@ #endif #endif -// -// TODO BEGIN move to utils_osx.cpp -// - #if wxUSE_BASE extern bool WXDLLEXPORT wxIsDebuggerRunning() @@ -240,43 +236,4 @@ CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) #endif // wxOSX_USE_COCOA_OR_CARBON -IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject ) - -wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl ) -{ - Init(); - m_isRootControl = isRootControl; - m_wxPeer = peer; -} - -wxWidgetImpl::wxWidgetImpl() -{ - Init(); -} - -wxWidgetImpl::~wxWidgetImpl() -{ -} - -void wxWidgetImpl::Init() -{ - m_isRootControl = false; - m_wxPeer = NULL; - m_needsFocusRect = false; -} - -void wxWidgetImpl::Destroy() -{ -} - -void wxWidgetImpl::SetNeedsFocusRect( bool needs ) -{ - m_needsFocusRect = needs; -} - -bool wxWidgetImpl::NeedsFocusRect() const -{ - return m_needsFocusRect; -} - #endif // wxUSE_GUI diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp new file mode 100644 index 0000000000..24c45ddb07 --- /dev/null +++ b/src/osx/window_osx.cpp @@ -0,0 +1,2362 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/osx/carbon/window.cpp +// Purpose: wxWindowMac +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#include "wx/window.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/panel.h" + #include "wx/frame.h" + #include "wx/dc.h" + #include "wx/dcclient.h" + #include "wx/button.h" + #include "wx/menu.h" + #include "wx/dialog.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" + #include "wx/scrolbar.h" + #include "wx/statbox.h" + #include "wx/textctrl.h" + #include "wx/toolbar.h" + #include "wx/layout.h" + #include "wx/statusbr.h" + #include "wx/menuitem.h" + #include "wx/treectrl.h" + #include "wx/listctrl.h" +#endif + +#include "wx/tooltip.h" +#include "wx/spinctrl.h" +#include "wx/geometry.h" + +#if wxUSE_LISTCTRL + #include "wx/listctrl.h" +#endif + +#if wxUSE_TREECTRL + #include "wx/treectrl.h" +#endif + +#if wxUSE_CARET + #include "wx/caret.h" +#endif + +#if wxUSE_POPUPWIN + #include "wx/popupwin.h" +#endif + +#if wxUSE_DRAG_AND_DROP +#include "wx/dnd.h" +#endif + +#if wxOSX_USE_CARBON +#include "wx/osx/uma.h" +#else +#include "wx/osx/private.h" +// bring in themeing +#include +#endif + +#define MAC_SCROLLBAR_SIZE 15 +#define MAC_SMALL_SCROLLBAR_SIZE 11 + +#include + +#ifdef __WXUNIVERSAL__ + IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) +#else + IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) +#endif + +BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) + EVT_NC_PAINT(wxWindowMac::OnNcPaint) + EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) + EVT_PAINT(wxWindowMac::OnPaint) + EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) +END_EVENT_TABLE() + +#define wxMAC_DEBUG_REDRAW 0 +#ifndef wxMAC_DEBUG_REDRAW +#define wxMAC_DEBUG_REDRAW 0 +#endif + +// =========================================================================== +// implementation +// =========================================================================== + +// ---------------------------------------------------------------------------- + // constructors and such +// ---------------------------------------------------------------------------- + +wxWindowMac::wxWindowMac() +{ + Init(); +} + +wxWindowMac::wxWindowMac(wxWindowMac *parent, + wxWindowID id, + const wxPoint& pos , + const wxSize& size , + long style , + const wxString& name ) +{ + Init(); + Create(parent, id, pos, size, style, name); +} + +void wxWindowMac::Init() +{ + m_peer = NULL ; + m_macAlpha = 255 ; + m_cgContextRef = NULL ; + + // as all windows are created with WS_VISIBLE style... + m_isShown = true; + + m_hScrollBar = NULL ; + m_vScrollBar = NULL ; + m_hScrollBarAlwaysShown = false; + m_vScrollBarAlwaysShown = false; + + m_macIsUserPane = true; + m_clipChildren = false ; + m_cachedClippedRectValid = false ; +} + +wxWindowMac::~wxWindowMac() +{ + SendDestroyEvent(); + + m_isBeingDeleted = true; + + MacInvalidateBorders() ; + +#ifndef __WXUNIVERSAL__ + // VS: make sure there's no wxFrame with last focus set to us: + for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) + { + wxFrame *frame = wxDynamicCast(win, wxFrame); + if ( frame ) + { + if ( frame->GetLastFocus() == this ) + frame->SetLastFocus((wxWindow*)NULL); + break; + } + } +#endif + + // destroy children before destroying this window itself + DestroyChildren(); + + // wxRemoveMacControlAssociation( this ) ; + // If we delete an item, we should initialize the parent panel, + // because it could now be invalid. + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow); + if ( tlw ) + { + if ( tlw->GetDefaultItem() == (wxButton*) this) + tlw->SetDefaultItem(NULL); + } + + if ( g_MacLastWindow == this ) + g_MacLastWindow = NULL ; + +#ifndef __WXUNIVERSAL__ + wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ; + if ( frame ) + { + if ( frame->GetLastFocus() == this ) + frame->SetLastFocus( NULL ) ; + } +#endif + + // delete our drop target if we've got one +#if wxUSE_DRAG_AND_DROP + if ( m_dropTarget != NULL ) + { + delete m_dropTarget; + m_dropTarget = NULL; + } +#endif + + delete m_peer ; +} + +WXWidget wxWindowMac::GetHandle() const +{ + return (WXWidget) m_peer->GetWXWidget() ; +} + +// +// TODO END move to window_osx.cpp +// + +// --------------------------------------------------------------------------- +// Utility Routines to move between different coordinate systems +// --------------------------------------------------------------------------- + +/* + * Right now we have the following setup : + * a border that is not part of the native control is always outside the + * control's border (otherwise we loose all native intelligence, future ways + * may be to have a second embedding control responsible for drawing borders + * and backgrounds eventually) + * so all this border calculations have to be taken into account when calling + * native methods or getting native oriented data + * so we have three coordinate systems here + * wx client coordinates + * wx window coordinates (including window frames) + * native coordinates + */ + +// +// + +// Constructor +bool wxWindowMac::Create(wxWindowMac *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) +{ + wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); + + if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) + return false; + + m_windowVariant = parent->GetWindowVariant() ; + + if ( m_macIsUserPane ) + { + m_peer = wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() ); + MacPostControlCreate(pos, size) ; + } + +#ifndef __WXUNIVERSAL__ + // Don't give scrollbars to wxControls unless they ask for them + if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) + || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) + { + MacCreateScrollBars( style ) ; + } +#endif + + wxWindowCreateEvent event((wxWindow*)this); + GetEventHandler()->AddPendingEvent(event); + + return true; +} + +void wxWindowMac::MacChildAdded() +{ + if ( m_vScrollBar ) + m_vScrollBar->Raise() ; + if ( m_hScrollBar ) + m_hScrollBar->Raise() ; +} + +void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size) +{ + wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid mac control") ) ; + +#if wxOSX_USE_CARBON + m_peer->SetReference( (URefCon) this ) ; +#endif + + GetParent()->AddChild( this ); + +#if wxOSX_USE_CARBON + m_peer->InstallEventHandler(); + + ControlRef container = (ControlRef) GetParent()->GetHandle() ; + wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; + ::EmbedControl( m_peer->GetControlRef() , container ) ; +#endif + GetParent()->MacChildAdded() ; + + // adjust font, controlsize etc + DoSetWindowVariant( m_windowVariant ) ; + + m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; + + if (!m_macIsUserPane) + SetInitialSize(size); + + SetCursor( *wxSTANDARD_CURSOR ) ; +} + +void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) +{ + // Don't assert, in case we set the window variant before + // the window is created + // wxASSERT( m_peer->Ok() ) ; + + m_windowVariant = variant ; + + if (m_peer == NULL || !m_peer->IsOk()) + return; + + m_peer->SetControlSize( variant ); +#if wxOSX_USE_COCOA_OR_CARBON + wxFont font ; + +#if wxOSX_USE_CARBON + ControlSize size ; + ThemeFontID themeFont = kThemeSystemFont ; + + // we will get that from the settings later + // and make this NORMAL later, but first + // we have a few calculations that we must fix + + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + size = kControlSizeNormal; + themeFont = kThemeSystemFont ; + break ; + + case wxWINDOW_VARIANT_SMALL : + size = kControlSizeSmall; + themeFont = kThemeSmallSystemFont ; + break ; + + case wxWINDOW_VARIANT_MINI : + // not always defined in the headers + size = 3 ; + themeFont = 109 ; + break ; + + case wxWINDOW_VARIANT_LARGE : + size = kControlSizeLarge; + themeFont = kThemeSystemFont ; + break ; + + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + + m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; + font.MacCreateFromThemeFont( themeFont ) ; +#else + CTFontUIFontType themeFont = kCTFontSystemFontType ; + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + themeFont = kCTFontSystemFontType; + break ; + + case wxWINDOW_VARIANT_SMALL : + themeFont = kCTFontSmallSystemFontType; + break ; + + case wxWINDOW_VARIANT_MINI : + themeFont = kCTFontMiniSystemFontType; + break ; + + case wxWINDOW_VARIANT_LARGE : + themeFont = kCTFontSystemFontType; + break ; + + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + font.MacCreateFromUIFont( themeFont ) ; +#endif + + SetFont( font ) ; +#endif +} + +void wxWindowMac::MacUpdateControlFont() +{ +#if wxOSX_USE_CARBON + m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; +#endif + // do not trigger refreshes upon invisible and possible partly created objects + if ( IsShownOnScreen() ) + Refresh() ; +} + +bool wxWindowMac::SetFont(const wxFont& font) +{ + bool retval = wxWindowBase::SetFont( font ); + + MacUpdateControlFont() ; + + return retval; +} + +bool wxWindowMac::SetForegroundColour(const wxColour& col ) +{ + bool retval = wxWindowBase::SetForegroundColour( col ); + + if (retval) + MacUpdateControlFont(); + + return retval; +} + +bool wxWindowMac::SetBackgroundColour(const wxColour& col ) +{ + if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) + return false ; + + if ( m_peer ) + m_peer->SetBackgroundColour( col ) ; + + return true ; +} + +void wxWindowMac::SetFocus() +{ + if ( !AcceptsFocus() ) + return ; + + wxWindow* former = FindFocus() ; + if ( former == this ) + return ; + + m_peer->SetFocus() ; +} + +void wxWindowMac::DoCaptureMouse() +{ + wxApp::s_captureWindow = (wxWindow*) this ; +} + +wxWindow * wxWindowBase::GetCapture() +{ + return wxApp::s_captureWindow ; +} + +void wxWindowMac::DoReleaseMouse() +{ + wxApp::s_captureWindow = NULL ; +} + +#if wxUSE_DRAG_AND_DROP + +void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) +{ + if ( m_dropTarget != NULL ) + delete m_dropTarget; + + m_dropTarget = pDropTarget; + if ( m_dropTarget != NULL ) + { + // TODO: + } +} + +#endif + +// Old-style File Manager Drag & Drop +void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept)) +{ + // TODO: +} + +// From a wx position / size calculate the appropriate size of the native control + +bool wxWindowMac::MacGetBoundsForControl( + const wxPoint& pos, + const wxSize& size, + int& x, int& y, + int& w, int& h , bool adjustOrigin ) const +{ + // the desired size, minus the border pixels gives the correct size of the control + x = (int)pos.x; + y = (int)pos.y; + + // TODO: the default calls may be used as soon as PostCreateControl Is moved here + w = wxMax(size.x, 0) ; // WidthDefault( size.x ); + h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ; + + x += MacGetLeftBorderSize() ; + y += MacGetTopBorderSize() ; + w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; + h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; + + if ( adjustOrigin ) + AdjustForParentClientOrigin( x , y ) ; + + // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border + if ( !GetParent()->IsTopLevel() ) + { + x -= GetParent()->MacGetLeftBorderSize() ; + y -= GetParent()->MacGetTopBorderSize() ; + } + + return true ; +} + +// Get window size (not client size) +void wxWindowMac::DoGetSize(int *x, int *y) const +{ + int width, height; + m_peer->GetSize( width, height ); + + if (x) + *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ; + if (y) + *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ; +} + +// get the position of the bounds of this window in client coordinates of its parent +void wxWindowMac::DoGetPosition(int *x, int *y) const +{ + int x1, y1; + + m_peer->GetPosition( x1, y1 ) ; + + // get the wx window position from the native one + x1 -= MacGetLeftBorderSize() ; + y1 -= MacGetTopBorderSize() ; + + if ( !IsTopLevel() ) + { + wxWindow *parent = GetParent(); + if ( parent ) + { + // we must first adjust it to be in window coordinates of the parent, + // as otherwise it gets lost by the ClientAreaOrigin fix + x1 += parent->MacGetLeftBorderSize() ; + y1 += parent->MacGetTopBorderSize() ; + + // and now to client coordinates + wxPoint pt(parent->GetClientAreaOrigin()); + x1 -= pt.x ; + y1 -= pt.y ; + } + } + + if (x) + *x = x1 ; + if (y) + *y = y1 ; +} + +void wxWindowMac::DoScreenToClient(int *x, int *y) const +{ + wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; + wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ; + tlw->GetNonOwnedPeer()->ScreenToWindow( x, y); + MacRootWindowToWindow( x , y ) ; + + wxPoint origin = GetClientAreaOrigin() ; + if (x) + *x -= origin.x ; + if (y) + *y -= origin.y ; +} + +void wxWindowMac::DoClientToScreen(int *x, int *y) const +{ + wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; + wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ; + + wxPoint origin = GetClientAreaOrigin() ; + if (x) + *x += origin.x ; + if (y) + *y += origin.y ; + + MacWindowToRootWindow( x , y ) ; + tlw->GetNonOwnedPeer()->WindowToScreen( x , y ); +} + +void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const +{ + wxPoint origin = GetClientAreaOrigin() ; + if (x) + *x += origin.x ; + if (y) + *y += origin.y ; + + MacWindowToRootWindow( x , y ) ; +} + +void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const +{ + wxPoint pt ; + + if (x) + pt.x = *x ; + if (y) + pt.y = *y ; + + if ( !IsTopLevel() ) + { + wxNonOwnedWindow* top = MacGetTopLevelWindow(); + if (top) + { + pt.x -= MacGetLeftBorderSize() ; + pt.y -= MacGetTopBorderSize() ; + wxWidgetImpl::Convert( &pt , m_peer , top->m_peer ) ; + } + } + + if (x) + *x = (int) pt.x ; + if (y) + *y = (int) pt.y ; +} + +void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const +{ + wxPoint pt ; + + if (x) + pt.x = *x ; + if (y) + pt.y = *y ; + + if ( !IsTopLevel() ) + { + wxNonOwnedWindow* top = MacGetTopLevelWindow(); + if (top) + { + wxWidgetImpl::Convert( &pt , top->m_peer , m_peer ) ; + pt.x += MacGetLeftBorderSize() ; + pt.y += MacGetTopBorderSize() ; + } + } + + if (x) + *x = (int) pt.x ; + if (y) + *y = (int) pt.y ; +} + +wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const +{ + wxSize sizeTotal = size; + + int innerwidth, innerheight; + int left, top; + int outerwidth, outerheight; + + m_peer->GetContentArea( left, top, innerwidth, innerheight ); + m_peer->GetSize( outerwidth, outerheight ); + + sizeTotal.x += left + (outerwidth-innerwidth); + sizeTotal.y += top + (outerheight-innerheight); + + sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; + sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; + + return sizeTotal; +} + +// Get size *available for subwindows* i.e. excluding menu bar etc. +void wxWindowMac::DoGetClientSize( int *x, int *y ) const +{ + int ww, hh; + + int left, top; + + m_peer->GetContentArea( left, top, ww, hh ); + + if (m_hScrollBar && m_hScrollBar->IsShown() ) + hh -= m_hScrollBar->GetSize().y ; + + if (m_vScrollBar && m_vScrollBar->IsShown() ) + ww -= m_vScrollBar->GetSize().x ; + + if (x) + *x = ww; + if (y) + *y = hh; +} + +bool wxWindowMac::SetCursor(const wxCursor& cursor) +{ + if (m_cursor.IsSameAs(cursor)) + return false; + + if (!cursor.IsOk()) + { + if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) + return false ; + } + else + { + if ( ! wxWindowBase::SetCursor( cursor ) ) + return false ; + } + + wxASSERT_MSG( m_cursor.Ok(), + wxT("cursor must be valid after call to the base version")); + + wxWindowMac *mouseWin = 0 ; +#if wxOSX_USE_CARBON + { + wxNonOwnedWindow *tlw = MacGetTopLevelWindow() ; + WindowRef window = (WindowRef) ( tlw ? tlw->GetWXWindow() : 0 ) ; + + ControlPartCode part ; + ControlRef control ; + Point pt ; + #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + HIPoint hiPoint ; + HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint); + pt.h = hiPoint.x; + pt.v = hiPoint.y; + #else + GetGlobalMouse( &pt ); + int x = pt.h; + int y = pt.v; + ScreenToClient(&x, &y); + pt.h = x; + pt.v = y; +#endif + control = FindControlUnderMouse( pt , window , &part ) ; + if ( control ) + mouseWin = wxFindWindowFromWXWidget( (WXWidget) control ) ; + + } +#endif + + if ( mouseWin == this && !wxIsBusy() ) + m_cursor.MacInstall() ; + + return true ; +} + +#if wxUSE_MENUS +bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) +{ +#ifndef __WXUNIVERSAL__ + menu->SetInvokingWindow((wxWindow*)this); + menu->UpdateUI(); + + if ( x == wxDefaultCoord && y == wxDefaultCoord ) + { + wxPoint mouse = wxGetMousePosition(); + x = mouse.x; + y = mouse.y; + } + else + { + ClientToScreen( &x , &y ) ; + } +#ifdef __WXOSX_CARBON__ + long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ; + if ( HiWord(menuResult) != 0 ) + { + MenuCommand macid; + GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid ); + int id = wxMacCommandToId( macid ); + wxMenuItem* item = NULL ; + wxMenu* realmenu ; + item = menu->FindItem( id, &realmenu ) ; + if ( item ) + { + if (item->IsCheckable()) + item->Check( !item->IsChecked() ) ; + + menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; + } + } + + menu->MacAfterDisplay( true ) ; + menu->SetInvokingWindow( NULL ); +#else + menu->SetInvokingWindow( NULL ); + return false; +#endif + + return true; +#else + // actually this shouldn't be called, because universal is having its own implementation + return false; +#endif +} +#endif + +// ---------------------------------------------------------------------------- +// tooltips +// ---------------------------------------------------------------------------- + +#if wxUSE_TOOLTIPS + +void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) +{ + wxWindowBase::DoSetToolTip(tooltip); + + if ( m_tooltip ) + m_tooltip->SetWindow(this); +} + +#endif + +void wxWindowMac::MacInvalidateBorders() +{ + if ( m_peer == NULL ) + return ; + + bool vis = IsShownOnScreen() ; + if ( !vis ) + return ; + + int outerBorder = MacGetLeftBorderSize() ; +#if wxOSX_USE_CARBON + if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ ) + outerBorder += 4 ; +#endif + + if ( outerBorder == 0 ) + return ; + + // now we know that we have something to do at all + + + int tx,ty,tw,th; + + m_peer->GetSize( tw, th ); + m_peer->GetPosition( tx, ty ); + + wxRect leftupdate( tx-outerBorder,ty,outerBorder,th ); + wxRect rightupdate( tx+tw, ty, outerBorder, th ); + wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder ); + wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder ); + + GetParent()->m_peer->SetNeedsDisplay(&leftupdate); + GetParent()->m_peer->SetNeedsDisplay(&rightupdate); + GetParent()->m_peer->SetNeedsDisplay(&topupdate); + GetParent()->m_peer->SetNeedsDisplay(&bottomupdate); +} + +void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) +{ + // this is never called for a toplevel window, so we know we have a parent + int former_x , former_y , former_w, former_h ; + + // Get true coordinates of former position + DoGetPosition( &former_x , &former_y ) ; + DoGetSize( &former_w , &former_h ) ; + + wxWindow *parent = GetParent(); + if ( parent ) + { + wxPoint pt(parent->GetClientAreaOrigin()); + former_x += pt.x ; + former_y += pt.y ; + } + + int actualWidth = width ; + int actualHeight = height ; + int actualX = x; + int actualY = y; + + if ((m_minWidth != -1) && (actualWidth < m_minWidth)) + actualWidth = m_minWidth; + if ((m_minHeight != -1) && (actualHeight < m_minHeight)) + actualHeight = m_minHeight; + if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) + actualWidth = m_maxWidth; + if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) + actualHeight = m_maxHeight; + + bool doMove = false, doResize = false ; + + if ( actualX != former_x || actualY != former_y ) + doMove = true ; + + if ( actualWidth != former_w || actualHeight != former_h ) + doResize = true ; + + if ( doMove || doResize ) + { + // as the borders are drawn outside the native control, we adjust now + + wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), + wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , + actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; + + if ( !GetParent()->IsTopLevel() ) + { + bounds.Offset( -GetParent()->MacGetLeftBorderSize(), -GetParent()->MacGetTopBorderSize() ); + } + + MacInvalidateBorders() ; + + m_cachedClippedRectValid = false ; + + m_peer->Move( bounds.x, bounds.y, bounds.width, bounds.height); + + wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified + + MacInvalidateBorders() ; + + MacRepositionScrollBars() ; + if ( doMove ) + { + wxPoint point(actualX, actualY); + wxMoveEvent event(point, m_windowId); + event.SetEventObject(this); + HandleWindowEvent(event) ; + } + + if ( doResize ) + { + MacRepositionScrollBars() ; + wxSize size(actualWidth, actualHeight); + wxSizeEvent event(size, m_windowId); + event.SetEventObject(this); + HandleWindowEvent(event); + } + } +} + +wxSize wxWindowMac::DoGetBestSize() const +{ + if ( m_macIsUserPane || IsTopLevel() ) + { + return wxWindowBase::DoGetBestSize() ; + } + else + { + wxRect r ; + + m_peer->GetBestRect(&r); + + if ( r.GetWidth() == 0 && r.GetHeight() == 0 ) + { + r.x = + r.y = 0 ; + r.width = + r.height = 16 ; + + if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) + { + r.height = 16 ; + } + #if wxUSE_SPINBTN + else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) + { + r.height = 24 ; + } + #endif + else + { + // return wxWindowBase::DoGetBestSize() ; + } + } + + int bestWidth = r.width + MacGetLeftBorderSize() + + MacGetRightBorderSize(); + int bestHeight = r.height + MacGetTopBorderSize() + + MacGetBottomBorderSize(); + if ( bestHeight < 10 ) + bestHeight = 13 ; + + return wxSize(bestWidth, bestHeight); + } +} + +// set the size of the window: if the dimensions are positive, just use them, +// but if any of them is equal to -1, it means that we must find the value for +// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in +// which case -1 is a valid value for x and y) +// +// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate +// the width/height to best suit our contents, otherwise we reuse the current +// width/height +void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) +{ + // get the current size and position... + int currentX, currentY; + int currentW, currentH; + + GetPosition(¤tX, ¤tY); + GetSize(¤tW, ¤tH); + + // ... and don't do anything (avoiding flicker) if it's already ok + if ( x == currentX && y == currentY && + width == currentW && height == currentH && ( height != -1 && width != -1 ) ) + { + // TODO: REMOVE + MacRepositionScrollBars() ; // we might have a real position shift + + return; + } + + if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) + { + if ( x == wxDefaultCoord ) + x = currentX; + if ( y == wxDefaultCoord ) + y = currentY; + } + + AdjustForParentClientOrigin( x, y, sizeFlags ); + + wxSize size = wxDefaultSize; + if ( width == wxDefaultCoord ) + { + if ( sizeFlags & wxSIZE_AUTO_WIDTH ) + { + size = DoGetBestSize(); + width = size.x; + } + else + { + // just take the current one + width = currentW; + } + } + + if ( height == wxDefaultCoord ) + { + if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) + { + if ( size.x == wxDefaultCoord ) + size = DoGetBestSize(); + // else: already called DoGetBestSize() above + + height = size.y; + } + else + { + // just take the current one + height = currentH; + } + } + + DoMoveWindow( x, y, width, height ); +} + +wxPoint wxWindowMac::GetClientAreaOrigin() const +{ + int left,top,width,height; + m_peer->GetContentArea( left , top , width , height); + return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() ); +} + +void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) +{ + if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord ) + { + int currentclientwidth , currentclientheight ; + int currentwidth , currentheight ; + + GetClientSize( ¤tclientwidth , ¤tclientheight ) ; + GetSize( ¤twidth , ¤theight ) ; + + DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth , + currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; + } +} + +void wxWindowMac::SetLabel(const wxString& title) +{ + m_label = title ; + + if ( m_peer && m_peer->IsOk() ) + m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; + + // do not trigger refreshes upon invisible and possible partly created objects + if ( IsShownOnScreen() ) + Refresh() ; +} + +wxString wxWindowMac::GetLabel() const +{ + return m_label ; +} + +bool wxWindowMac::Show(bool show) +{ + if ( !wxWindowBase::Show(show) ) + return false; + + if ( m_peer ) + m_peer->SetVisibility( show ) ; + + return true; +} + +void wxWindowMac::DoEnable(bool enable) +{ + m_peer->Enable( enable ) ; +} + +// +// status change notifications +// + +void wxWindowMac::MacVisibilityChanged() +{ +} + +void wxWindowMac::MacHiliteChanged() +{ +} + +void wxWindowMac::MacEnabledStateChanged() +{ + OnEnabled( m_peer->IsEnabled() ); +} + +// +// status queries on the inherited window's state +// + +bool wxWindowMac::MacIsReallyEnabled() +{ + return m_peer->IsEnabled() ; +} + +bool wxWindowMac::MacIsReallyHilited() +{ +#if wxOSX_USE_CARBON + return m_peer->IsActive(); +#else + return true; // TODO +#endif +} + +int wxWindowMac::GetCharHeight() const +{ + wxClientDC dc( (wxWindow*)this ) ; + + return dc.GetCharHeight() ; +} + +int wxWindowMac::GetCharWidth() const +{ + wxClientDC dc( (wxWindow*)this ) ; + + return dc.GetCharWidth() ; +} + +void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, + int *descent, int *externalLeading, const wxFont *theFont ) const +{ + const wxFont *fontToUse = theFont; + wxFont tempFont; + if ( !fontToUse ) + { + tempFont = GetFont(); + fontToUse = &tempFont; + } + + wxClientDC dc( (wxWindow*) this ) ; + wxCoord lx,ly,ld,le ; + dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; + if ( externalLeading ) + *externalLeading = le ; + if ( descent ) + *descent = ld ; + if ( x ) + *x = lx ; + if ( y ) + *y = ly ; +} + +/* + * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect + * we always intersect with the entire window, not only with the client area + */ + +void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) +{ + if ( m_peer == NULL ) + return ; + + if ( !IsShownOnScreen() ) + return ; + + m_peer->SetNeedsDisplay( rect ) ; +} + +void wxWindowMac::DoFreeze() +{ +#if wxOSX_USE_CARBON + if ( m_peer && m_peer->IsOk() ) + m_peer->SetDrawingEnabled( false ) ; +#endif +} + +void wxWindowMac::DoThaw() +{ +#if wxOSX_USE_CARBON + if ( m_peer && m_peer->IsOk() ) + { + m_peer->SetDrawingEnabled( true ) ; + m_peer->InvalidateWithChildren() ; + } +#endif +} + +wxWindow *wxGetActiveWindow() +{ + // actually this is a windows-only concept + return NULL; +} + +// Coordinates relative to the window +void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos)) +{ + // We really don't move the mouse programmatically under Mac. +} + +void wxWindowMac::OnEraseBackground(wxEraseEvent& event) +{ + if ( MacGetTopLevelWindow() == NULL ) + return ; +/* +#if TARGET_API_MAC_OSX + if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) + { + } + else +#endif +*/ + if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR ) + { + event.GetDC()->Clear() ; + } + else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM ) + { + // don't skip the event here, custom background means that the app + // is drawing it itself in its OnPaint(), so don't draw it at all + // now to avoid flicker + } + else + { + event.Skip() ; + } +} + +void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) +{ + event.Skip() ; +} + +int wxWindowMac::GetScrollPos(int orient) const +{ + if ( orient == wxHORIZONTAL ) + { + if ( m_hScrollBar ) + return m_hScrollBar->GetThumbPosition() ; + } + else + { + if ( m_vScrollBar ) + return m_vScrollBar->GetThumbPosition() ; + } + + return 0; +} + +// This now returns the whole range, not just the number +// of positions that we can scroll. +int wxWindowMac::GetScrollRange(int orient) const +{ + if ( orient == wxHORIZONTAL ) + { + if ( m_hScrollBar ) + return m_hScrollBar->GetRange() ; + } + else + { + if ( m_vScrollBar ) + return m_vScrollBar->GetRange() ; + } + + return 0; +} + +int wxWindowMac::GetScrollThumb(int orient) const +{ + if ( orient == wxHORIZONTAL ) + { + if ( m_hScrollBar ) + return m_hScrollBar->GetThumbSize() ; + } + else + { + if ( m_vScrollBar ) + return m_vScrollBar->GetThumbSize() ; + } + + return 0; +} + +void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) +{ + if ( orient == wxHORIZONTAL ) + { + if ( m_hScrollBar ) + m_hScrollBar->SetThumbPosition( pos ) ; + } + else + { + if ( m_vScrollBar ) + m_vScrollBar->SetThumbPosition( pos ) ; + } +} + +void +wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag) +{ + bool needVisibilityUpdate = false; + + if ( m_hScrollBarAlwaysShown != hflag ) + { + m_hScrollBarAlwaysShown = hflag; + needVisibilityUpdate = true; + } + + if ( m_vScrollBarAlwaysShown != vflag ) + { + m_vScrollBarAlwaysShown = vflag; + needVisibilityUpdate = true; + } + + if ( needVisibilityUpdate ) + DoUpdateScrollbarVisibility(); +} + +// +// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef +// our own window origin is at leftOrigin/rightOrigin +// + +void wxWindowMac::MacPaintGrowBox() +{ + if ( IsTopLevel() ) + return ; + + if ( MacHasScrollBarCorner() ) + { + CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; + wxASSERT( cgContext ) ; + + int tx,ty,tw,th; + + m_peer->GetSize( tw, th ); + m_peer->GetPosition( tx, ty ); + + Rect rect = { ty,tx, ty+th, tx+tw }; + + + int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; + CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; + CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; + CGContextSaveGState( cgContext ); + + if ( m_backgroundColour.Ok() ) + { + CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); + } + else + { + CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 ); + } + CGContextFillRect( cgContext, cgrect ); + CGContextRestoreGState( cgContext ); + } +} + +void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) ) +{ + if ( IsTopLevel() ) + return ; + + bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ; + + // back to the surrounding frame rectangle + int tx,ty,tw,th; + + m_peer->GetSize( tw, th ); + m_peer->GetPosition( tx, ty ); + + Rect rect = { ty,tx, ty+th, tx+tw }; + +#if wxOSX_USE_COCOA_OR_CARBON + + InsetRect( &rect, -1 , -1 ) ; + + { + CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , + rect.bottom - rect.top ) ; + + HIThemeFrameDrawInfo info ; + memset( &info, 0 , sizeof(info) ) ; + + info.version = 0 ; + info.kind = 0 ; + info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; + info.isFocused = hasFocus ; + + CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; + wxASSERT( cgContext ) ; + + if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) + { + info.kind = kHIThemeFrameTextFieldSquare ; + HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; + } + else if ( HasFlag(wxSIMPLE_BORDER) ) + { + info.kind = kHIThemeFrameListBox ; + HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; + } + else if ( hasFocus ) + { + HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; + } +#if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself + m_peer->GetRect( &rect ) ; + if ( MacHasScrollBarCorner() ) + { + int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant(); + int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; + CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; + CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; + HIThemeGrowBoxDrawInfo info ; + memset( &info, 0, sizeof(info) ) ; + info.version = 0 ; + info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; + info.kind = kHIThemeGrowBoxKindNone ; + // contrary to the docs ...SizeSmall does not work + info.size = kHIThemeGrowBoxSizeNormal ; + info.direction = 0 ; + HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; + } +#endif + } +#endif // wxOSX_USE_COCOA_OR_CARBON +} + +void wxWindowMac::RemoveChild( wxWindowBase *child ) +{ + if ( child == m_hScrollBar ) + m_hScrollBar = NULL ; + if ( child == m_vScrollBar ) + m_vScrollBar = NULL ; + + wxWindowBase::RemoveChild( child ) ; +} + +void wxWindowMac::DoUpdateScrollbarVisibility() +{ + bool triggerSizeEvent = false; + + if ( m_hScrollBar ) + { + bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded(); + + if ( m_hScrollBar->IsShown() != showHScrollBar ) + { + m_hScrollBar->Show( showHScrollBar ); + triggerSizeEvent = true; + } + } + + if ( m_vScrollBar) + { + bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded(); + + if ( m_vScrollBar->IsShown() != showVScrollBar ) + { + m_vScrollBar->Show( showVScrollBar ) ; + triggerSizeEvent = true; + } + } + + MacRepositionScrollBars() ; + if ( triggerSizeEvent ) + { + wxSizeEvent event(GetSize(), m_windowId); + event.SetEventObject(this); + HandleWindowEvent(event); + } +} + +// New function that will replace some of the above. +void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, + int range, bool refresh) +{ + if ( orient == wxHORIZONTAL && m_hScrollBar ) + m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); + else if ( orient == wxVERTICAL && m_vScrollBar ) + m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); + + DoUpdateScrollbarVisibility(); +} + +// Does a physical scroll +void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) +{ + if ( dx == 0 && dy == 0 ) + return ; + + int width , height ; + GetClientSize( &width , &height ) ; + + { + wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; + if ( rect ) + scrollrect.Intersect( *rect ) ; + // as the native control might be not a 0/0 wx window coordinates, we have to offset + scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; + + m_peer->ScrollRect( &scrollrect, dx, dy ); + } + + wxWindowMac *child; + int x, y, w, h; + for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) + { + child = node->GetData(); + if (child == NULL) + continue; + if (child == m_vScrollBar) + continue; + if (child == m_hScrollBar) + continue; + if (child->IsTopLevel()) + continue; + + child->GetPosition( &x, &y ); + child->GetSize( &w, &h ); + if (rect) + { + wxRect rc( x, y, w, h ); + if (rect->Intersects( rc )) + child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); + } + else + { + child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); + } + } +} + +void wxWindowMac::MacOnScroll( wxScrollEvent &event ) +{ + if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) + { + wxScrollWinEvent wevent; + wevent.SetPosition(event.GetPosition()); + wevent.SetOrientation(event.GetOrientation()); + wevent.SetEventObject(this); + + if (event.GetEventType() == wxEVT_SCROLL_TOP) + wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); + else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) + wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); + else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) + wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); + else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) + wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); + else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) + wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); + else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) + wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); + else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) + wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); + else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) + wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); + + HandleWindowEvent(wevent); + } +} + +// Get the window with the focus +wxWindow *wxWindowBase::DoFindFocus() +{ +#if wxOSX_USE_CARBON + ControlRef control ; + GetKeyboardFocus( GetUserFocusWindow() , &control ) ; + return wxFindWindowFromWXWidget( (WXWidget) control ) ; +#else + return NULL; +#endif +} + +void wxWindowMac::OnInternalIdle() +{ + // This calls the UI-update mechanism (querying windows for + // menu/toolbar/control state information) + if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen()) + UpdateWindowUI(wxUPDATE_UI_FROMIDLE); +} + +// Raise the window to the top of the Z order +void wxWindowMac::Raise() +{ + m_peer->Raise(); +} + +// Lower the window to the bottom of the Z order +void wxWindowMac::Lower() +{ + m_peer->Lower(); +} + +// static wxWindow *gs_lastWhich = NULL; + +bool wxWindowMac::MacSetupCursor( const wxPoint& pt ) +{ + // first trigger a set cursor event + + wxPoint clientorigin = GetClientAreaOrigin() ; + wxSize clientsize = GetClientSize() ; + wxCursor cursor ; + if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) + { + wxSetCursorEvent event( pt.x , pt.y ); + + bool processedEvtSetCursor = HandleWindowEvent(event); + if ( processedEvtSetCursor && event.HasCursor() ) + { + cursor = event.GetCursor() ; + } + else + { + // the test for processedEvtSetCursor is here to prevent using m_cursor + // if the user code caught EVT_SET_CURSOR() and returned nothing from + // it - this is a way to say that our cursor shouldn't be used for this + // point + if ( !processedEvtSetCursor && m_cursor.Ok() ) + cursor = m_cursor ; + + if ( !wxIsBusy() && !GetParent() ) + cursor = *wxSTANDARD_CURSOR ; + } + + if ( cursor.Ok() ) + cursor.MacInstall() ; + } + + return cursor.Ok() ; +} + +wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) ) +{ +#if wxUSE_TOOLTIPS + if ( m_tooltip ) + return m_tooltip->GetTip() ; +#endif + + return wxEmptyString ; +} + +void wxWindowMac::ClearBackground() +{ + Refresh() ; + Update() ; +} + +void wxWindowMac::Update() +{ + wxNonOwnedWindow* top = MacGetTopLevelWindow(); + if (top) + top->Update() ; +} + +wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const +{ + wxWindowMac *iter = (wxWindowMac*)this ; + + while ( iter ) + { + if ( iter->IsTopLevel() ) + { + wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow); + if ( toplevel ) + return toplevel; +#if wxUSE_POPUPWIN + wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow); + if ( popupwin ) + return popupwin; +#endif + } + iter = iter->GetParent() ; + } + + return NULL ; +} + +const wxRect& wxWindowMac::MacGetClippedClientRect() const +{ + MacUpdateClippedRects() ; + + return m_cachedClippedClientRect ; +} + +const wxRect& wxWindowMac::MacGetClippedRect() const +{ + MacUpdateClippedRects() ; + + return m_cachedClippedRect ; +} + +const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const +{ + MacUpdateClippedRects() ; + + return m_cachedClippedRectWithOuterStructure ; +} + +const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) +{ + static wxRegion emptyrgn ; + + if ( !m_isBeingDeleted && IsShownOnScreen() ) + { + MacUpdateClippedRects() ; + if ( includeOuterStructures ) + return m_cachedClippedRegionWithOuterStructure ; + else + return m_cachedClippedRegion ; + } + else + { + return emptyrgn ; + } +} + +void wxWindowMac::MacUpdateClippedRects() const +{ +#if wxOSX_USE_CARBON + if ( m_cachedClippedRectValid ) + return ; + + // includeOuterStructures is true if we try to draw somthing like a focus ring etc. + // also a window dc uses this, in this case we only clip in the hierarchy for hard + // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having + // to add focus borders everywhere + + Rect rIncludingOuterStructures ; + + int tx,ty,tw,th; + + m_peer->GetSize( tw, th ); + m_peer->GetPosition( tx, ty ); + + Rect r = { ty,tx, ty+th, tx+tw }; + + r.left -= MacGetLeftBorderSize() ; + r.top -= MacGetTopBorderSize() ; + r.bottom += MacGetBottomBorderSize() ; + r.right += MacGetRightBorderSize() ; + + r.right -= r.left ; + r.bottom -= r.top ; + r.left = 0 ; + r.top = 0 ; + + rIncludingOuterStructures = r ; + InsetRect( &rIncludingOuterStructures , -4 , -4 ) ; + + wxRect cl = GetClientRect() ; + Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ; + + int x , y ; + wxSize size ; + const wxWindow* child = (wxWindow*) this ; + const wxWindow* parent = NULL ; + + while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL ) + { + if ( parent->MacIsChildOfClientArea(child) ) + { + size = parent->GetClientSize() ; + wxPoint origin = parent->GetClientAreaOrigin() ; + x = origin.x ; + y = origin.y ; + } + else + { + // this will be true for scrollbars, toolbars etc. + size = parent->GetSize() ; + y = parent->MacGetTopBorderSize() ; + x = parent->MacGetLeftBorderSize() ; + size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ; + size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ; + } + + parent->MacWindowToRootWindow( &x, &y ) ; + MacRootWindowToWindow( &x , &y ) ; + + Rect rparent = { y , x , y + size.y , x + size.x } ; + + // the wxwindow and client rects will always be clipped + SectRect( &r , &rparent , &r ) ; + SectRect( &rClient , &rparent , &rClient ) ; + + // the structure only at 'hard' borders + if ( parent->MacClipChildren() || + ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) ) + { + SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ; + } + + child = parent ; + } + + m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ; + m_cachedClippedClientRect = wxRect( rClient.left , rClient.top , + rClient.right - rClient.left , rClient.bottom - rClient.top ) ; + m_cachedClippedRectWithOuterStructure = wxRect( + rIncludingOuterStructures.left , rIncludingOuterStructures.top , + rIncludingOuterStructures.right - rIncludingOuterStructures.left , + rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ; + + m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ; + m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ; + m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ; + + m_cachedClippedRectValid = true ; +#endif +} + +/* + This function must not change the updatergn ! + */ +bool wxWindowMac::MacDoRedraw( void* updatergnr , long time ) +{ + bool handled = false ; +#if wxOSX_USE_CARBON + Rect updatebounds ; + RgnHandle updatergn = (RgnHandle) updatergnr ; + GetRegionBounds( updatergn , &updatebounds ) ; + + // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ; + + if ( !EmptyRgn(updatergn) ) + { + RgnHandle newupdate = NewRgn() ; + wxSize point = GetClientSize() ; + wxPoint origin = GetClientAreaOrigin() ; + SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y + point.y ) ; + SectRgn( newupdate , updatergn , newupdate ) ; + + // first send an erase event to the entire update area + { + // for the toplevel window this really is the entire area + // for all the others only their client area, otherwise they + // might be drawing with full alpha and eg put blue into + // the grow-box area of a scrolled window (scroll sample) + wxDC* dc = new wxWindowDC(this); + if ( IsTopLevel() ) + dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn))); + else + dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate))); + + wxEraseEvent eevent( GetId(), dc ); + eevent.SetEventObject( this ); + HandleWindowEvent( eevent ); + delete dc ; + } + + MacPaintGrowBox(); + + // calculate a client-origin version of the update rgn and set m_updateRegion to that + OffsetRgn( newupdate , -origin.x , -origin.y ) ; + m_updateRegion = wxRegion(HIShapeCreateWithQDRgn(newupdate)) ; + DisposeRgn( newupdate ) ; + + if ( !m_updateRegion.Empty() ) + { + // paint the window itself + + wxPaintEvent event; + event.SetTimestamp(time); + event.SetEventObject(this); + HandleWindowEvent(event); + handled = true ; + } + + // now we cannot rely on having its borders drawn by a window itself, as it does not + // get the updateRgn wide enough to always do so, so we do it from the parent + // this would also be the place to draw any custom backgrounds for native controls + // in Composited windowing + wxPoint clientOrigin = GetClientAreaOrigin() ; + + wxWindowMac *child; + int x, y, w, h; + for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) + { + child = node->GetData(); + if (child == NULL) + continue; + if (child == m_vScrollBar) + continue; + if (child == m_hScrollBar) + continue; + if (child->IsTopLevel()) + continue; + if (!child->IsShown()) + continue; + + // only draw those in the update region (add a safety margin of 10 pixels for shadow effects + + child->GetPosition( &x, &y ); + child->GetSize( &w, &h ); + Rect childRect = { y , x , y + h , x + w } ; + OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; + InsetRect( &childRect , -10 , -10) ; + + if ( RectInRgn( &childRect , updatergn ) ) + { + // paint custom borders + wxNcPaintEvent eventNc( child->GetId() ); + eventNc.SetEventObject( child ); + if ( !child->HandleWindowEvent( eventNc ) ) + { + child->MacPaintBorders(0, 0) ; + } + } + } + } +#endif + return handled ; +} + + +WXWindow wxWindowMac::MacGetTopLevelWindowRef() const +{ + wxNonOwnedWindow* tlw = MacGetTopLevelWindow(); + return tlw ? tlw->GetWXWindow() : NULL ; +} + +bool wxWindowMac::MacHasScrollBarCorner() const +{ + /* Returns whether the scroll bars in a wxScrolledWindow should be + * shortened. Scroll bars should be shortened if either: + * + * - both scroll bars are visible, or + * + * - there is a resize box in the parent frame's corner and this + * window shares the bottom and right edge with the parent + * frame. + */ + + if ( m_hScrollBar == NULL && m_vScrollBar == NULL ) + return false; + + if ( ( m_hScrollBar && m_hScrollBar->IsShown() ) + && ( m_vScrollBar && m_vScrollBar->IsShown() ) ) + { + // Both scroll bars visible + return true; + } + else + { + wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight(); + + for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() ) + { + const wxFrame *frame = wxDynamicCast( win, wxFrame ) ; + if ( frame ) + { + if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER ) + { + // Parent frame has resize handle + wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight(); + + // Note: allow for some wiggle room here as wxMac's + // window rect calculations seem to be imprecise + if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2 + && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 ) + { + // Parent frame has resize handle and shares + // right bottom corner + return true ; + } + else + { + // Parent frame has resize handle but doesn't + // share right bottom corner + return false ; + } + } + else + { + // Parent frame doesn't have resize handle + return false ; + } + } + } + + // No parent frame found + return false ; + } +} + +void wxWindowMac::MacCreateScrollBars( long style ) +{ + wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; + + if ( style & ( wxVSCROLL | wxHSCROLL ) ) + { + int scrlsize = MAC_SCROLLBAR_SIZE ; + if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) + { + scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; + } + + int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ; + int width, height ; + GetClientSize( &width , &height ) ; + + wxPoint vPoint(width - scrlsize, 0) ; + wxSize vSize(scrlsize, height - adjust) ; + wxPoint hPoint(0, height - scrlsize) ; + wxSize hSize(width - adjust, scrlsize) ; + + // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize) + if ( style & wxVSCROLL ) + { + m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL); + m_vScrollBar->SetMinSize( wxDefaultSize ); + } + + if ( style & wxHSCROLL ) + { + m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL); + m_hScrollBar->SetMinSize( wxDefaultSize ); + } + } + + // because the create does not take into account the client area origin + // we might have a real position shift + MacRepositionScrollBars() ; +} + +bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const +{ + bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar))); + + return result ; +} + +void wxWindowMac::MacRepositionScrollBars() +{ + if ( !m_hScrollBar && !m_vScrollBar ) + return ; + + int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; + int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ; + + // get real client area + int width, height ; + GetSize( &width , &height ); + + width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); + height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); + + wxPoint vPoint( width - scrlsize, 0 ) ; + wxSize vSize( scrlsize, height - adjust ) ; + wxPoint hPoint( 0 , height - scrlsize ) ; + wxSize hSize( width - adjust, scrlsize ) ; + + if ( m_vScrollBar ) + m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE ); + if ( m_hScrollBar ) + m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE ); +} + +bool wxWindowMac::AcceptsFocus() const +{ + return m_peer->CanFocus() && wxWindowBase::AcceptsFocus(); +} + +void wxWindowMac::MacSuperChangedPosition() +{ + // only window-absolute structures have to be moved i.e. controls + + m_cachedClippedRectValid = false ; + + wxWindowMac *child; + wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); + while ( node ) + { + child = node->GetData(); + child->MacSuperChangedPosition() ; + + node = node->GetNext(); + } +} + +void wxWindowMac::MacTopLevelWindowChangedPosition() +{ + // only screen-absolute structures have to be moved i.e. glcanvas + + wxWindowMac *child; + wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); + while ( node ) + { + child = node->GetData(); + child->MacTopLevelWindowChangedPosition() ; + + node = node->GetNext(); + } +} + +long wxWindowMac::MacGetLeftBorderSize() const +{ + if ( IsTopLevel() ) + return 0 ; + + SInt32 border = 0 ; + + if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER)) + { +#if wxOSX_USE_COCOA_OR_CARBON + // this metric is only the 'outset' outside the simple frame rect + GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; + border += 1; +#else + border += 2; +#endif + } + else if (HasFlag(wxSIMPLE_BORDER)) + { +#if wxOSX_USE_COCOA_OR_CARBON + // this metric is only the 'outset' outside the simple frame rect + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; + border += 1; +#else + border += 1; +#endif + } + + return border ; +} + +long wxWindowMac::MacGetRightBorderSize() const +{ + // they are all symmetric in mac themes + return MacGetLeftBorderSize() ; +} + +long wxWindowMac::MacGetTopBorderSize() const +{ + // they are all symmetric in mac themes + return MacGetLeftBorderSize() ; +} + +long wxWindowMac::MacGetBottomBorderSize() const +{ + // they are all symmetric in mac themes + return MacGetLeftBorderSize() ; +} + +long wxWindowMac::MacRemoveBordersFromStyle( long style ) +{ + return style & ~wxBORDER_MASK ; +} + +// Find the wxWindowMac at the current mouse position, returning the mouse +// position. +wxWindow * wxFindWindowAtPointer( wxPoint& pt ) +{ + pt = wxGetMousePosition(); + wxWindowMac* found = wxFindWindowAtPoint(pt); + + return (wxWindow*) found; +} + +// Get the current mouse position. +wxPoint wxGetMousePosition() +{ + int x, y; + + wxGetMousePosition( &x, &y ); + + return wxPoint(x, y); +} + +void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) +{ + if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) + { + // copied from wxGTK : CS + // VZ: shouldn't we move this to base class then? + + // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN + // except that: + // + // (a) it's a command event and so is propagated to the parent + // (b) under MSW it can be generated from kbd too + // (c) it uses screen coords (because of (a)) + wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, + this->GetId(), + this->ClientToScreen(event.GetPosition())); + evtCtx.SetEventObject(this); + if ( ! HandleWindowEvent(evtCtx) ) + event.Skip() ; + } + else + { + event.Skip() ; + } +} + +void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) ) +{ +#if wxOSX_USE_COCOA_OR_CARBON + // for native controls: call their native paint method + if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) ) + { + if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL + && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT ) + CallNextEventHandler( + (EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , + (EventRef) wxTheApp->MacGetCurrentEvent() ) ; + } +#endif +} + +void wxWindowMac::MacHandleControlClick(WXWidget WXUNUSED(control), + wxInt16 WXUNUSED(controlpart), + bool WXUNUSED(mouseStillDown)) +{ +} + +Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) +{ + int x, y, w, h ; + + window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ; + Rect bounds = { y, x, y + h, x + w }; + + return bounds ; +} + +bool wxWindowMac::HandleClicked( double timestampsec ) +{ + return false; +} + +wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event ) +{ +#if wxOSX_USE_COCOA_OR_CARBON + if ( HandleClicked( GetEventTime((EventRef)event) ) ) + return noErr; + + return eventNotHandledErr ; +#else + return 0; +#endif +} + +bool wxWindowMac::Reparent(wxWindowBase *newParentBase) +{ + wxWindowMac *newParent = (wxWindowMac *)newParentBase; + if ( !wxWindowBase::Reparent(newParent) ) + return false; + + m_peer->RemoveFromParent(); + m_peer->Embed( GetParent()->GetPeer() ); + return true; +} + +bool wxWindowMac::SetTransparent(wxByte alpha) +{ + SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); + + if ( alpha != m_macAlpha ) + { + m_macAlpha = alpha ; + Refresh() ; + } + return true ; +} + + +bool wxWindowMac::CanSetTransparent() +{ + return true ; +} + +wxByte wxWindowMac::GetTransparent() const +{ + return m_macAlpha ; +} + +bool wxWindowMac::IsShownOnScreen() const +{ + if ( m_peer && m_peer->IsOk() ) + { + bool peerVis = m_peer->IsVisible(); + bool wxVis = wxWindowBase::IsShownOnScreen(); + if( peerVis != wxVis ) + { + // CS : put a breakpoint here to investigate differences + // between native an wx visibilities + // the only place where I've encountered them until now + // are the hiding/showing sequences where the vis-changed event is + // first sent to the innermost control, while wx does things + // from the outmost control + wxVis = wxWindowBase::IsShownOnScreen(); + return wxVis; + } + + return m_peer->IsVisible(); + } + return wxWindowBase::IsShownOnScreen(); +} + +// +// wxWidgetImpl +// + +IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject ) + +wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl ) +{ + Init(); + m_isRootControl = isRootControl; + m_wxPeer = peer; +} + +wxWidgetImpl::wxWidgetImpl() +{ + Init(); +} + +wxWidgetImpl::~wxWidgetImpl() +{ +} + +void wxWidgetImpl::Init() +{ + m_isRootControl = false; + m_wxPeer = NULL; + m_needsFocusRect = false; +} + +void wxWidgetImpl::SetNeedsFocusRect( bool needs ) +{ + m_needsFocusRect = needs; +} + +bool wxWidgetImpl::NeedsFocusRect() const +{ + return m_needsFocusRect; +} + -- 2.45.2