From e7bf85055cea56351cafc8cf3abc7b14d61ee22f Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 18 Jun 2014 16:52:20 +0000 Subject: [PATCH] removing 'old' cocoa port git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76735 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/NSApplication.h | 67 - include/wx/cocoa/NSBox.h | 25 - include/wx/cocoa/NSButton.h | 38 - include/wx/cocoa/NSControl.h | 31 - include/wx/cocoa/NSMenu.h | 48 - include/wx/cocoa/NSPanel.h | 24 - include/wx/cocoa/NSScroller.h | 40 - include/wx/cocoa/NSSlider.h | 46 - include/wx/cocoa/NSTabView.h | 35 - include/wx/cocoa/NSTableDataSource.h | 34 - include/wx/cocoa/NSTableView.h | 29 - include/wx/cocoa/NSTextField.h | 26 - include/wx/cocoa/NSView.h | 80 - include/wx/cocoa/NSWindow.h | 54 - include/wx/cocoa/ObjcAssociate.h | 77 - include/wx/cocoa/ObjcRef.h | 235 --- include/wx/cocoa/app.h | 73 - include/wx/cocoa/autorelease.h | 31 - include/wx/cocoa/bitmap.h | 164 -- include/wx/cocoa/bmpbuttn.h | 61 - include/wx/cocoa/brush.h | 69 - include/wx/cocoa/button.h | 64 - include/wx/cocoa/checkbox.h | 68 - include/wx/cocoa/checklst.h | 79 - include/wx/cocoa/chkconf.h | 21 - include/wx/cocoa/choice.h | 100 - include/wx/cocoa/clipbrd.h | 51 - include/wx/cocoa/colordlg.h | 1 - include/wx/cocoa/colour.h | 92 - include/wx/cocoa/combobox.h | 157 -- include/wx/cocoa/control.h | 77 - include/wx/cocoa/cursor.h | 64 - include/wx/cocoa/dataform.h | 50 - include/wx/cocoa/dataobj.h | 23 - include/wx/cocoa/dataobj2.h | 83 - include/wx/cocoa/dc.h | 174 -- include/wx/cocoa/dcclient.h | 69 - include/wx/cocoa/dcmemory.h | 54 - include/wx/cocoa/dcscreen.h | 31 - include/wx/cocoa/dialog.h | 80 - include/wx/cocoa/dirdlg.h | 50 - include/wx/cocoa/drawer.h | 1 - include/wx/cocoa/evtloop.h | 38 - include/wx/cocoa/filedlg.h | 52 - include/wx/cocoa/font.h | 172 -- include/wx/cocoa/fontdlg.h | 1 - include/wx/cocoa/frame.h | 106 -- include/wx/cocoa/gauge.h | 73 - include/wx/cocoa/glcanvas.h | 97 - include/wx/cocoa/icon.h | 63 - include/wx/cocoa/listbox.h | 114 -- include/wx/cocoa/log.h | 21 - include/wx/cocoa/mbarman.h | 70 - include/wx/cocoa/mdi.h | 163 -- include/wx/cocoa/menu.h | 185 -- include/wx/cocoa/menuitem.h | 99 - include/wx/cocoa/msgdlg.h | 70 - include/wx/cocoa/notebook.h | 104 - include/wx/cocoa/objc/NSMenu.h | 30 - include/wx/cocoa/objc/NSSlider.h | 36 - include/wx/cocoa/objc/NSView.h | 44 - include/wx/cocoa/objc/NSWindow.h | 39 - include/wx/cocoa/objc/objc_uniquifying.h | 364 ---- include/wx/cocoa/pen.h | 71 - include/wx/cocoa/private/fontfactory.h | 27 - include/wx/cocoa/private/scrollview.h | 128 -- include/wx/cocoa/private/timer.h | 42 - include/wx/cocoa/radiobox.h | 137 -- include/wx/cocoa/radiobut.h | 73 - include/wx/cocoa/region.h | 75 - include/wx/cocoa/scrolbar.h | 74 - include/wx/cocoa/slider.h | 107 -- include/wx/cocoa/sound.h | 51 - include/wx/cocoa/spinbutt.h | 63 - include/wx/cocoa/statbmp.h | 59 - include/wx/cocoa/statbox.h | 60 - include/wx/cocoa/statline.h | 55 - include/wx/cocoa/stattext.h | 58 - include/wx/cocoa/string.h | 52 - include/wx/cocoa/taskbar.h | 47 - include/wx/cocoa/textctrl.h | 122 -- include/wx/cocoa/toolbar.h | 120 -- include/wx/cocoa/tooltip.h | 54 - include/wx/cocoa/toplevel.h | 130 -- include/wx/cocoa/trackingrectmanager.h | 40 - include/wx/cocoa/window.h | 226 --- src/cocoa/NSBox.mm | 29 - src/cocoa/NSButton.mm | 69 - src/cocoa/NSControl.mm | 63 - src/cocoa/NSMenu.mm | 136 -- src/cocoa/NSPanel.mm | 31 - src/cocoa/NSScroller.mm | 59 - src/cocoa/NSSlider.mm | 168 -- src/cocoa/NSTabView.mm | 76 - src/cocoa/NSTableView.mm | 56 - src/cocoa/NSTextField.mm | 26 - src/cocoa/NSView.mm | 221 --- src/cocoa/NSWindow.mm | 241 --- src/cocoa/ObjcRef.mm | 24 - src/cocoa/app.mm | 511 ----- src/cocoa/bitmap.mm | 724 ------- src/cocoa/bmpbuttn.mm | 70 - src/cocoa/brush.mm | 225 --- src/cocoa/button.mm | 123 -- src/cocoa/checkbox.mm | 151 -- src/cocoa/checklst.mm | 70 - src/cocoa/choice.mm | 208 -- src/cocoa/clipbrd.mm | 67 - src/cocoa/colordlg.mm | 1 - src/cocoa/colour.mm | 91 - src/cocoa/combobox.mm | 408 ---- src/cocoa/control.mm | 112 -- src/cocoa/cursor.mm | 502 ----- src/cocoa/data.cpp | 10 - src/cocoa/dataobj.mm | 60 - src/cocoa/dc.mm | 664 ------- src/cocoa/dcclient.mm | 176 -- src/cocoa/dcmemory.mm | 219 --- src/cocoa/dcscreen.cpp | 38 - src/cocoa/dialog.mm | 173 -- src/cocoa/dirdlg.mm | 148 -- src/cocoa/display.mm | 221 --- src/cocoa/drawer.mm | 1 - src/cocoa/dummy.r | 0 src/cocoa/evtloop.mm | 152 -- src/cocoa/filedlg.mm | 240 --- src/cocoa/font.mm | 472 ----- src/cocoa/fontdlg.mm | 1 - src/cocoa/fontenum.mm | 27 - src/cocoa/fontutil.cpp | 255 --- src/cocoa/frame.mm | 288 --- src/cocoa/gauge.mm | 113 -- src/cocoa/glcanvas.mm | 73 - src/cocoa/icon.mm | 159 -- src/cocoa/listbox.mm | 354 ---- src/cocoa/main.cpp | 21 - src/cocoa/mbarman.mm | 398 ---- src/cocoa/mdi.mm | 308 --- src/cocoa/mediactrl.mm | 497 ----- src/cocoa/menu.mm | 241 --- src/cocoa/menuitem.mm | 295 --- src/cocoa/msgdlg.mm | 161 -- src/cocoa/notebook.mm | 324 ---- src/cocoa/pen.mm | 376 ---- src/cocoa/radiobox.mm | 276 --- src/cocoa/radiobut.mm | 190 -- src/cocoa/region.mm | 45 - src/cocoa/scrolbar.mm | 180 -- src/cocoa/settings.mm | 220 --- src/cocoa/slider.mm | 266 --- src/cocoa/sound.mm | 189 -- src/cocoa/spinbutt.mm | 82 - src/cocoa/statbmp.mm | 67 - src/cocoa/statbox.mm | 75 - src/cocoa/statline2.mm | 47 - src/cocoa/stattext.mm | 113 -- src/cocoa/taskbar.mm | 406 ---- src/cocoa/textctrl.mm | 262 --- src/cocoa/timer.mm | 124 -- src/cocoa/toolbar.mm | 428 ----- src/cocoa/tooltip.mm | 146 -- src/cocoa/toplevel.mm | 443 ----- src/cocoa/utils.mm | 135 -- src/cocoa/utilsexc.mm | 196 -- src/cocoa/window.mm | 2218 ---------------------- 165 files changed, 23523 deletions(-) delete mode 100644 include/wx/cocoa/NSApplication.h delete mode 100644 include/wx/cocoa/NSBox.h delete mode 100644 include/wx/cocoa/NSButton.h delete mode 100644 include/wx/cocoa/NSControl.h delete mode 100644 include/wx/cocoa/NSMenu.h delete mode 100644 include/wx/cocoa/NSPanel.h delete mode 100644 include/wx/cocoa/NSScroller.h delete mode 100644 include/wx/cocoa/NSSlider.h delete mode 100644 include/wx/cocoa/NSTabView.h delete mode 100644 include/wx/cocoa/NSTableDataSource.h delete mode 100644 include/wx/cocoa/NSTableView.h delete mode 100644 include/wx/cocoa/NSTextField.h delete mode 100644 include/wx/cocoa/NSView.h delete mode 100644 include/wx/cocoa/NSWindow.h delete mode 100644 include/wx/cocoa/ObjcAssociate.h delete mode 100644 include/wx/cocoa/ObjcRef.h delete mode 100644 include/wx/cocoa/app.h delete mode 100644 include/wx/cocoa/autorelease.h delete mode 100644 include/wx/cocoa/bitmap.h delete mode 100644 include/wx/cocoa/bmpbuttn.h delete mode 100644 include/wx/cocoa/brush.h delete mode 100644 include/wx/cocoa/button.h delete mode 100644 include/wx/cocoa/checkbox.h delete mode 100644 include/wx/cocoa/checklst.h delete mode 100644 include/wx/cocoa/chkconf.h delete mode 100644 include/wx/cocoa/choice.h delete mode 100644 include/wx/cocoa/clipbrd.h delete mode 100644 include/wx/cocoa/colordlg.h delete mode 100644 include/wx/cocoa/colour.h delete mode 100644 include/wx/cocoa/combobox.h delete mode 100644 include/wx/cocoa/control.h delete mode 100644 include/wx/cocoa/cursor.h delete mode 100644 include/wx/cocoa/dataform.h delete mode 100644 include/wx/cocoa/dataobj.h delete mode 100644 include/wx/cocoa/dataobj2.h delete mode 100644 include/wx/cocoa/dc.h delete mode 100644 include/wx/cocoa/dcclient.h delete mode 100644 include/wx/cocoa/dcmemory.h delete mode 100644 include/wx/cocoa/dcscreen.h delete mode 100644 include/wx/cocoa/dialog.h delete mode 100644 include/wx/cocoa/dirdlg.h delete mode 100644 include/wx/cocoa/drawer.h delete mode 100644 include/wx/cocoa/evtloop.h delete mode 100644 include/wx/cocoa/filedlg.h delete mode 100644 include/wx/cocoa/font.h delete mode 100644 include/wx/cocoa/fontdlg.h delete mode 100644 include/wx/cocoa/frame.h delete mode 100644 include/wx/cocoa/gauge.h delete mode 100644 include/wx/cocoa/glcanvas.h delete mode 100644 include/wx/cocoa/icon.h delete mode 100644 include/wx/cocoa/listbox.h delete mode 100644 include/wx/cocoa/log.h delete mode 100644 include/wx/cocoa/mbarman.h delete mode 100644 include/wx/cocoa/mdi.h delete mode 100644 include/wx/cocoa/menu.h delete mode 100644 include/wx/cocoa/menuitem.h delete mode 100644 include/wx/cocoa/msgdlg.h delete mode 100644 include/wx/cocoa/notebook.h delete mode 100644 include/wx/cocoa/objc/NSMenu.h delete mode 100644 include/wx/cocoa/objc/NSSlider.h delete mode 100644 include/wx/cocoa/objc/NSView.h delete mode 100644 include/wx/cocoa/objc/NSWindow.h delete mode 100644 include/wx/cocoa/objc/objc_uniquifying.h delete mode 100644 include/wx/cocoa/pen.h delete mode 100644 include/wx/cocoa/private/fontfactory.h delete mode 100644 include/wx/cocoa/private/scrollview.h delete mode 100644 include/wx/cocoa/private/timer.h delete mode 100644 include/wx/cocoa/radiobox.h delete mode 100644 include/wx/cocoa/radiobut.h delete mode 100644 include/wx/cocoa/region.h delete mode 100644 include/wx/cocoa/scrolbar.h delete mode 100644 include/wx/cocoa/slider.h delete mode 100644 include/wx/cocoa/sound.h delete mode 100644 include/wx/cocoa/spinbutt.h delete mode 100644 include/wx/cocoa/statbmp.h delete mode 100644 include/wx/cocoa/statbox.h delete mode 100644 include/wx/cocoa/statline.h delete mode 100644 include/wx/cocoa/stattext.h delete mode 100644 include/wx/cocoa/string.h delete mode 100644 include/wx/cocoa/taskbar.h delete mode 100644 include/wx/cocoa/textctrl.h delete mode 100644 include/wx/cocoa/toolbar.h delete mode 100644 include/wx/cocoa/tooltip.h delete mode 100644 include/wx/cocoa/toplevel.h delete mode 100644 include/wx/cocoa/trackingrectmanager.h delete mode 100644 include/wx/cocoa/window.h delete mode 100644 src/cocoa/NSBox.mm delete mode 100644 src/cocoa/NSButton.mm delete mode 100644 src/cocoa/NSControl.mm delete mode 100644 src/cocoa/NSMenu.mm delete mode 100644 src/cocoa/NSPanel.mm delete mode 100644 src/cocoa/NSScroller.mm delete mode 100644 src/cocoa/NSSlider.mm delete mode 100644 src/cocoa/NSTabView.mm delete mode 100644 src/cocoa/NSTableView.mm delete mode 100644 src/cocoa/NSTextField.mm delete mode 100644 src/cocoa/NSView.mm delete mode 100644 src/cocoa/NSWindow.mm delete mode 100644 src/cocoa/ObjcRef.mm delete mode 100644 src/cocoa/app.mm delete mode 100644 src/cocoa/bitmap.mm delete mode 100644 src/cocoa/bmpbuttn.mm delete mode 100644 src/cocoa/brush.mm delete mode 100644 src/cocoa/button.mm delete mode 100644 src/cocoa/checkbox.mm delete mode 100644 src/cocoa/checklst.mm delete mode 100644 src/cocoa/choice.mm delete mode 100644 src/cocoa/clipbrd.mm delete mode 100644 src/cocoa/colordlg.mm delete mode 100644 src/cocoa/colour.mm delete mode 100644 src/cocoa/combobox.mm delete mode 100644 src/cocoa/control.mm delete mode 100644 src/cocoa/cursor.mm delete mode 100644 src/cocoa/data.cpp delete mode 100644 src/cocoa/dataobj.mm delete mode 100644 src/cocoa/dc.mm delete mode 100644 src/cocoa/dcclient.mm delete mode 100644 src/cocoa/dcmemory.mm delete mode 100644 src/cocoa/dcscreen.cpp delete mode 100644 src/cocoa/dialog.mm delete mode 100644 src/cocoa/dirdlg.mm delete mode 100644 src/cocoa/display.mm delete mode 100644 src/cocoa/drawer.mm delete mode 100644 src/cocoa/dummy.r delete mode 100644 src/cocoa/evtloop.mm delete mode 100644 src/cocoa/filedlg.mm delete mode 100644 src/cocoa/font.mm delete mode 100644 src/cocoa/fontdlg.mm delete mode 100644 src/cocoa/fontenum.mm delete mode 100644 src/cocoa/fontutil.cpp delete mode 100644 src/cocoa/frame.mm delete mode 100644 src/cocoa/gauge.mm delete mode 100644 src/cocoa/glcanvas.mm delete mode 100644 src/cocoa/icon.mm delete mode 100644 src/cocoa/listbox.mm delete mode 100644 src/cocoa/main.cpp delete mode 100644 src/cocoa/mbarman.mm delete mode 100644 src/cocoa/mdi.mm delete mode 100644 src/cocoa/mediactrl.mm delete mode 100644 src/cocoa/menu.mm delete mode 100644 src/cocoa/menuitem.mm delete mode 100644 src/cocoa/msgdlg.mm delete mode 100644 src/cocoa/notebook.mm delete mode 100644 src/cocoa/pen.mm delete mode 100644 src/cocoa/radiobox.mm delete mode 100644 src/cocoa/radiobut.mm delete mode 100644 src/cocoa/region.mm delete mode 100644 src/cocoa/scrolbar.mm delete mode 100644 src/cocoa/settings.mm delete mode 100644 src/cocoa/slider.mm delete mode 100644 src/cocoa/sound.mm delete mode 100644 src/cocoa/spinbutt.mm delete mode 100644 src/cocoa/statbmp.mm delete mode 100644 src/cocoa/statbox.mm delete mode 100644 src/cocoa/statline2.mm delete mode 100644 src/cocoa/stattext.mm delete mode 100644 src/cocoa/taskbar.mm delete mode 100644 src/cocoa/textctrl.mm delete mode 100644 src/cocoa/timer.mm delete mode 100644 src/cocoa/toolbar.mm delete mode 100644 src/cocoa/tooltip.mm delete mode 100644 src/cocoa/toplevel.mm delete mode 100644 src/cocoa/utils.mm delete mode 100644 src/cocoa/utilsexc.mm delete mode 100644 src/cocoa/window.mm diff --git a/include/wx/cocoa/NSApplication.h b/include/wx/cocoa/NSApplication.h deleted file mode 100644 index 192d282782..0000000000 --- a/include/wx/cocoa/NSApplication.h +++ /dev/null @@ -1,67 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSApplication.h -// Purpose: wxNSApplicationDelegate definition -// Author: David Elliott -// Modified by: -// Created: 2004/01/26 -// Copyright: (c) 2003,2004 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_NSAPPLICATION_H__ -#define _WX_COCOA_NSAPPLICATION_H__ - -#include "wx/cocoa/objc/objc_uniquifying.h" - -// ======================================================================== -// wxNSApplicationDelegate -// ======================================================================== -/*! - @class wxNSApplicationDelegate - @discussion Implements an NSApplication delegate which can respond to messages sent by Cocoa to change Cocoa's behaviour. - - wxCocoa will set a singleton instance of this class as the NSApplication delegate upon startup unless wxWidgets is running - in a "plugin" manner in which case it would not be appropriate to do this. - - Although Cocoa will send notifications to the delegate it is also possible to register a different object to listen for - them. Because we want to support the plugin case, we use a separate notification observer object when we can. -*/ -@interface wxNSApplicationDelegate : NSObject -{ -} - -// Delegate methods -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; -@end // interface wxNSApplicationDelegate : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject) - -// ======================================================================== -// wxNSApplicationObserver -// ======================================================================== -/*! - @class wxNSApplicationObserver - @discussion Observes most notifications sent by the NSApplication singleton. - - wxCocoa will create a singleton instance of this class upon startup and register it with the default notification center to - listen for several events sent by the NSApplication singleton. - - Because there can be any number of notification observers, this method allows wxCocoa to function properly even when it is - running as a plugin of some other (most likely not wxWidgets) application. -*/ -@interface wxNSApplicationObserver : NSObject -{ -} - -// Methods defined as (but not used here) as NSApplication delegate methods. -- (void)applicationWillBecomeActive:(NSNotification *)notification; -- (void)applicationDidBecomeActive:(NSNotification *)notification; -- (void)applicationWillResignActive:(NSNotification *)notification; -- (void)applicationDidResignActive:(NSNotification *)notification; -- (void)applicationWillUpdate:(NSNotification *)notification; - -// Other notifications -- (void)controlTintChanged:(NSNotification *)notification; -@end // interface wxNSApplicationObserver : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxNSApplicationObserver,NSObject) - -#endif //ndef _WX_COCOA_NSAPPLICATION_H__ diff --git a/include/wx/cocoa/NSBox.h b/include/wx/cocoa/NSBox.h deleted file mode 100644 index 39cbe3de5f..0000000000 --- a/include/wx/cocoa/NSBox.h +++ /dev/null @@ -1,25 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSBox.h -// Purpose: wxCocoaNSBox class -// Author: David Elliott -// Modified by: -// Created: 2003/03/19 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSBOX_H__ -#define __WX_COCOA_NSBOX_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSBox); -class wxCocoaNSBox -{ - WX_DECLARE_OBJC_INTERFACE(NSBox) -protected: -// virtual void Cocoa_didChangeText(void) = 0; -}; - -#endif // _WX_COCOA_NSBOX_H_ diff --git a/include/wx/cocoa/NSButton.h b/include/wx/cocoa/NSButton.h deleted file mode 100644 index 7e32aac07d..0000000000 --- a/include/wx/cocoa/NSButton.h +++ /dev/null @@ -1,38 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSButton.h -// Purpose: wxCocoaNSButton class -// Author: David Elliott -// Modified by: -// Created: 2002/12/09 -// Copyright: (c) 2002-2004 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_NSBUTTON_H__ -#define _WX_COCOA_NSBUTTON_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" -#include "wx/cocoa/ObjcRef.h" - -WX_DECLARE_OBJC_HASHMAP(NSButton); - -class wxCocoaNSButton -{ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSButton); -public: - void AssociateNSButton(WX_NSButton cocoaNSButton); - void DisassociateNSButton(WX_NSButton cocoaNSButton) - { - if(cocoaNSButton) - sm_cocoaHash.erase(cocoaNSButton); - } - - virtual void Cocoa_wxNSButtonAction(void) = 0; - virtual ~wxCocoaNSButton() { } - -protected: - static const wxObjcAutoRefFromAlloc sm_cocoaTarget; -}; - -#endif // _WX_COCOA_NSBUTTON_H__ diff --git a/include/wx/cocoa/NSControl.h b/include/wx/cocoa/NSControl.h deleted file mode 100644 index f921c337d1..0000000000 --- a/include/wx/cocoa/NSControl.h +++ /dev/null @@ -1,31 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSControl.h -// Purpose: wxCocoaNSControl class -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSCONTROL_H__ -#define __WX_COCOA_NSCONTROL_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSControl); -class wxCocoaNSControl -{ - WX_DECLARE_OBJC_INTERFACE(NSControl) -public: - virtual void CocoaTarget_action() {} -// virtual void Cocoa_didChangeText(void) = 0; - - virtual ~wxCocoaNSControl() { } - -protected: - static struct objc_object *sm_cocoaTarget; -}; - -#endif // _WX_COCOA_NSCONTROL_H_ diff --git a/include/wx/cocoa/NSMenu.h b/include/wx/cocoa/NSMenu.h deleted file mode 100644 index a413ad45a6..0000000000 --- a/include/wx/cocoa/NSMenu.h +++ /dev/null @@ -1,48 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSMenu.h -// Purpose: wxCocoaNSMenu class -// Author: David Elliott -// Modified by: -// Created: 2002/12/09 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSMENU_H__ -#define __WX_COCOA_NSMENU_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSMenu); - -// ======================================================================== -// wxCocoaNSMenu -// ======================================================================== - -class wxCocoaNSMenu -{ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSMenu) -public: - void AssociateNSMenu(WX_NSMenu cocoaNSMenu, unsigned int flags = 0); - void DisassociateNSMenu(WX_NSMenu cocoaNSMenu); - enum - { OBSERVE_DidAddItem = 0x01 - , OBSERVE_DidChangeItem = 0x02 - , OBSERVE_DidRemoveItem = 0x04 - , OBSERVE_DidSendAction = 0x08 - , OBSERVE_WillSendAction = 0x10 - }; - virtual void Cocoa_dealloc() {} - virtual void CocoaNotification_menuDidAddItem(WX_NSNotification WXUNUSED(notification)) {} - virtual void CocoaNotification_menuDidChangeItem(WX_NSNotification WXUNUSED(notification)) {} - virtual void CocoaNotification_menuDidRemoveItem(WX_NSNotification WXUNUSED(notification)) {} - virtual void CocoaNotification_menuDidSendAction(WX_NSNotification WXUNUSED(notification)) {} - virtual void CocoaNotification_menuWillSendAction(WX_NSNotification WXUNUSED(notification)) {} - virtual ~wxCocoaNSMenu() { } - -protected: - static struct objc_object *sm_cocoaObserver; -}; - -#endif // _WX_COCOA_NSMENU_H_ diff --git a/include/wx/cocoa/NSPanel.h b/include/wx/cocoa/NSPanel.h deleted file mode 100644 index 25acf54c42..0000000000 --- a/include/wx/cocoa/NSPanel.h +++ /dev/null @@ -1,24 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSPanel.h -// Purpose: wxCocoaNSPanel class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSPANEL_H__ -#define __WX_COCOA_NSPANEL_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSPanel); - -class wxCocoaNSPanel -{ - WX_DECLARE_OBJC_INTERFACE(NSPanel) -}; - -#endif // _WX_COCOA_NSPANEL_H_ diff --git a/include/wx/cocoa/NSScroller.h b/include/wx/cocoa/NSScroller.h deleted file mode 100644 index 3cafc5815a..0000000000 --- a/include/wx/cocoa/NSScroller.h +++ /dev/null @@ -1,40 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSScroller.h -// Purpose: wxCocoaNSScroller class -// Author: David Elliott -// Modified by: -// Created: 2004/04/27 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_NSSCROLLER_H__ -#define _WX_COCOA_NSSCROLLER_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" -#include "wx/cocoa/ObjcRef.h" - -DECLARE_WXCOCOA_OBJC_CLASS(NSScroller); - -WX_DECLARE_OBJC_HASHMAP(NSScroller); - -class wxCocoaNSScroller -{ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSScroller); -public: - void AssociateNSScroller(WX_NSScroller cocoaNSScroller); - void DisassociateNSScroller(WX_NSScroller cocoaNSScroller) - { - if(cocoaNSScroller) - sm_cocoaHash.erase(cocoaNSScroller); - } - - virtual void Cocoa_wxNSScrollerAction(void) = 0; - virtual ~wxCocoaNSScroller() { } - -protected: - static const wxObjcAutoRefFromAlloc sm_cocoaTarget; -}; - -#endif // _WX_COCOA_NSSCROLLER_H__ diff --git a/include/wx/cocoa/NSSlider.h b/include/wx/cocoa/NSSlider.h deleted file mode 100644 index 0f278984ee..0000000000 --- a/include/wx/cocoa/NSSlider.h +++ /dev/null @@ -1,46 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSSlider.h -// Purpose: wxCocoaNSSlider class -// Author: Mark Oxenham -// Modified by: David Elliott -// Created: 2007/08/10 -// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WXNSSLIDER_H_ -#define _WXNSSLIDER_H_ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" -#include "wx/cocoa/ObjcRef.h" - -DECLARE_WXCOCOA_OBJC_CLASS(NSSlider); - -WX_DECLARE_OBJC_HASHMAP(NSSlider); - -// For when we're not in Objective-C mode: -typedef struct objc_selector *SEL; - -class wxCocoaNSSliderLastSelectorChanger; - -class wxCocoaNSSlider -{ - friend class wxCocoaNSSliderLastSelectorChanger; - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSSlider); -public: - void AssociateNSSlider(WX_NSSlider cocoaNSSlider); - void DisassociateNSSlider(WX_NSSlider cocoaNSSlider); - - virtual void CocoaNotification_startTracking(WX_NSNotification notification) = 0; - virtual void CocoaNotification_continueTracking(WX_NSNotification notification) = 0; - virtual void CocoaNotification_stopTracking(WX_NSNotification notification) = 0; - - static SEL GetLastResponderSelector() - { return sm_lastResponderSelector; } -protected: - virtual ~wxCocoaNSSlider() { } - static SEL sm_lastResponderSelector; -}; - -#endif diff --git a/include/wx/cocoa/NSTabView.h b/include/wx/cocoa/NSTabView.h deleted file mode 100644 index 8c4320d0ae..0000000000 --- a/include/wx/cocoa/NSTabView.h +++ /dev/null @@ -1,35 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSTabView.h -// Purpose: wxCocoaNSTabView class -// Author: David Elliott -// Modified by: -// Created: 2004/04/08 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_NSTABVIEW_H__ -#define _WX_COCOA_NSTABVIEW_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" -#include "wx/cocoa/ObjcRef.h" - -DECLARE_WXCOCOA_OBJC_CLASS(NSTabView); -DECLARE_WXCOCOA_OBJC_CLASS(NSTabViewItem); -WX_DECLARE_OBJC_HASHMAP(NSTabView); -class wxCocoaNSTabView -{ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSTabView) -public: - void AssociateNSTabView(WX_NSTabView cocoaNSTabView); - void DisassociateNSTabView(WX_NSTabView ocoaNSTabView); - virtual void CocoaDelegate_tabView_didSelectTabViewItem(WX_NSTabViewItem tabviewItem) = 0; - virtual bool CocoaDelegate_tabView_shouldSelectTabViewItem(WX_NSTabViewItem tabviewItem) = 0; - virtual ~wxCocoaNSTabView() { } - -protected: - static wxObjcAutoRefFromAlloc sm_cocoaDelegate; -}; - -#endif // _WX_COCOA_NSTABVIEW_H__ diff --git a/include/wx/cocoa/NSTableDataSource.h b/include/wx/cocoa/NSTableDataSource.h deleted file mode 100644 index 39e96a8343..0000000000 --- a/include/wx/cocoa/NSTableDataSource.h +++ /dev/null @@ -1,34 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSTableDataSource.h -// Purpose: wxCocoaNSTableDataSource Objective-C class -// Author: David Elliott -// Modified by: -// Created: 2003/08/05 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSTABLEDATASOURCE_H__ -#define __WX_COCOA_NSTABLEDATASOURCE_H__ - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import - -// ============================================================================ -// @class wxCocoaNSTableDataSource -// ============================================================================ -@interface wxCocoaNSTableDataSource : NSObject -{ -} - -// NSTableDataSource is a loosely defined protocol consisting of the -// following two message implementations -- (int)numberOfRowsInTableView: (NSTableView *)tableView; -- (id)tableView:(NSTableView *)tableView - objectValueForTableColumn: (NSTableColumn *)tableColumn - row: (int)rowIndex; -@end // wxCocoaNSTableDataSource -WX_DECLARE_GET_OBJC_CLASS(wxCocoaNSTableDataSource,NSObject) - -#endif // _WX_COCOA_NSTABLEDATASOURCE_H_ diff --git a/include/wx/cocoa/NSTableView.h b/include/wx/cocoa/NSTableView.h deleted file mode 100644 index 749a844d03..0000000000 --- a/include/wx/cocoa/NSTableView.h +++ /dev/null @@ -1,29 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSTableView.h -// Purpose: wxCocoaNSTableView class -// Author: David Elliott -// Modified by: -// Created: 2003/08/05 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSTABLEVIEW_H__ -#define __WX_COCOA_NSTABLEVIEW_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSTableView); - -class wxCocoaNSTableView -{ - WX_DECLARE_OBJC_INTERFACE(NSTableView) -public: - virtual int CocoaDataSource_numberOfRows() = 0; - virtual struct objc_object* CocoaDataSource_objectForTableColumn( - WX_NSTableColumn tableColumn, int rowIndex) = 0; - virtual ~wxCocoaNSTableView() { } -}; - -#endif // _WX_COCOA_NSTABLEVIEW_H_ diff --git a/include/wx/cocoa/NSTextField.h b/include/wx/cocoa/NSTextField.h deleted file mode 100644 index 5632318677..0000000000 --- a/include/wx/cocoa/NSTextField.h +++ /dev/null @@ -1,26 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSTextField.h -// Purpose: wxCocoaNSTextField class -// Author: David Elliott -// Modified by: -// Created: 2002/12/09 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSTEXTFIELD_H__ -#define __WX_COCOA_NSTEXTFIELD_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSTextField); -class wxCocoaNSTextField -{ - WX_DECLARE_OBJC_INTERFACE(NSTextField) -protected: - virtual void Cocoa_didChangeText(void) = 0; - virtual ~wxCocoaNSTextField() { } -}; - -#endif // _WX_COCOA_NSTEXTFIELD_H_ diff --git a/include/wx/cocoa/NSView.h b/include/wx/cocoa/NSView.h deleted file mode 100644 index 3095fb1738..0000000000 --- a/include/wx/cocoa/NSView.h +++ /dev/null @@ -1,80 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSView.h -// Purpose: wxCocoaNSView class -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSVIEW_H__ -#define __WX_COCOA_NSVIEW_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -#if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) -typedef struct CGRect NSRect; -#else -typedef struct _NSRect NSRect; -#endif - -struct objc_object; - -class wxWindow; - -WX_DECLARE_OBJC_HASHMAP(NSView); -class wxCocoaNSView -{ -/* NSView is a rather special case and requires some extra attention */ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSView) -public: - void AssociateNSView(WX_NSView cocoaNSView); - void DisassociateNSView(WX_NSView cocoaNSView); -protected: - static struct objc_object *sm_cocoaObserver; -public: - virtual wxWindow* GetWxWindow() const - { return NULL; } - virtual void Cocoa_FrameChanged(void) = 0; - virtual void Cocoa_synthesizeMouseMoved(void) = 0; - virtual bool Cocoa_acceptsFirstMouse(bool &WXUNUSED(acceptsFirstMouse), WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_drawRect(const NSRect &WXUNUSED(rect)) - { return false; } - virtual bool Cocoa_mouseDown(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_mouseDragged(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_mouseUp(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_mouseMoved(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_mouseEntered(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_mouseExited(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_rightMouseDown(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_rightMouseDragged(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_rightMouseUp(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_otherMouseDown(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_otherMouseDragged(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_otherMouseUp(WX_NSEvent WXUNUSED(theEvent)) - { return false; } - virtual bool Cocoa_resetCursorRects() - { return false; } - virtual bool Cocoa_viewDidMoveToWindow() - { return false; } - virtual bool Cocoa_viewWillMoveToWindow(WX_NSWindow WXUNUSED(newWindow)) - { return false; } - virtual ~wxCocoaNSView() { } -}; - -#endif - // __WX_COCOA_NSVIEW_H__ diff --git a/include/wx/cocoa/NSWindow.h b/include/wx/cocoa/NSWindow.h deleted file mode 100644 index 228ffe3ed0..0000000000 --- a/include/wx/cocoa/NSWindow.h +++ /dev/null @@ -1,54 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/NSWindow.h -// Purpose: wxCocoaNSWindow class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_NSWINDOW_H__ -#define __WX_COCOA_NSWINDOW_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -WX_DECLARE_OBJC_HASHMAP(NSWindow); - -class WXDLLIMPEXP_FWD_CORE wxMenuBar; -class WXDLLIMPEXP_FWD_CORE wxTopLevelWindowCocoa; - -DECLARE_WXCOCOA_OBJC_CLASS(NSMenuItem); -DECLARE_WXCOCOA_OBJC_CLASS(wxNSWindowDelegate); - -class WXDLLIMPEXP_CORE wxCocoaNSWindow -{ -/* NSWindow is a rather special case and requires some extra attention */ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSWindow) -public: - void AssociateNSWindow(WX_NSWindow cocoaNSWindow); - void DisassociateNSWindow(WX_NSWindow cocoaNSWindow); - virtual bool Cocoa_canBecomeKeyWindow(bool &WXUNUSED(canBecome)) - { return false; } - virtual bool Cocoa_canBecomeMainWindow(bool &WXUNUSED(canBecome)) - { return false; } - virtual bool CocoaDelegate_windowShouldClose(void) = 0; - virtual void CocoaDelegate_windowWillClose(void) = 0; - virtual void CocoaDelegate_windowDidBecomeKey(void) { } - virtual void CocoaDelegate_windowDidResignKey(void) { } - virtual void CocoaDelegate_windowDidBecomeMain(void) { } - virtual void CocoaDelegate_windowDidResignMain(void) { } - virtual void CocoaDelegate_wxMenuItemAction(WX_NSMenuItem menuItem) = 0; - virtual bool CocoaDelegate_validateMenuItem(WX_NSMenuItem menuItem) = 0; - virtual wxMenuBar* GetAppMenuBar(wxCocoaNSWindow *win); - inline wxTopLevelWindowCocoa* GetWxTopLevelWindowCocoa() - { return m_wxTopLevelWindowCocoa; } -protected: - wxCocoaNSWindow(wxTopLevelWindowCocoa *tlw = NULL); - virtual ~wxCocoaNSWindow(); - WX_wxNSWindowDelegate m_cocoaDelegate; - wxTopLevelWindowCocoa *m_wxTopLevelWindowCocoa; -}; - -#endif // _WX_COCOA_NSWINDOW_H_ diff --git a/include/wx/cocoa/ObjcAssociate.h b/include/wx/cocoa/ObjcAssociate.h deleted file mode 100644 index a6bf6e2ce4..0000000000 --- a/include/wx/cocoa/ObjcAssociate.h +++ /dev/null @@ -1,77 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/ObjcAssociate.h -// Purpose: Associates an Objective-C class with a C++ class -// Author: David Elliott -// Modified by: -// Created: 2002/12/03 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_OBJC_ASSOCIATE_H__ -#define __WX_COCOA_OBJC_ASSOCIATE_H__ - -/*------------------------------------------------------------------------- -Basic hashmap stuff, used by everything --------------------------------------------------------------------------*/ -#define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \ -class wxCocoa##ObjcClass; \ -WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash) - -#define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \ -public: \ - static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \ - { \ - wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \ - if(iter!=sm_cocoaHash.end()) \ - { \ - return iter->second; \ - } \ - return NULL; \ - } \ -protected: \ - static wxCocoa##ObjcClass##Hash sm_cocoaHash; - -#define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \ -wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash; - - -/*------------------------------------------------------------------------- -The entire interface, including some boilerplate stuff --------------------------------------------------------------------------*/ -#define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \ -WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \ -public: \ - inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ - { \ - if(cocoaObjcClass) \ - sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \ - } \ - inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ - { \ - if(cocoaObjcClass) \ - sm_cocoaHash.erase(cocoaObjcClass); \ - } - -#define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \ -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) - -/*------------------------------------------------------------------------- -Stuff to be used by the wxWidgets class (not the Cocoa interface) --------------------------------------------------------------------------*/ -#define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \ -public: \ - inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \ - inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \ -protected: \ - void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass); - -#define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \ -void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \ -{ \ - Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \ - Set##ObjcBase(cocoaObjcClass); \ - Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \ -} - -#endif // __WX_COCOA_OBJC_ASSOCIATE_H__ diff --git a/include/wx/cocoa/ObjcRef.h b/include/wx/cocoa/ObjcRef.h deleted file mode 100644 index d4aa6d91ec..0000000000 --- a/include/wx/cocoa/ObjcRef.h +++ /dev/null @@ -1,235 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/ObjcRef.h -// Purpose: wxObjcAutoRef template class -// Author: David Elliott -// Modified by: -// Created: 2004/03/28 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_OBJCREF_H__ -#define _WX_COCOA_OBJCREF_H__ - -// Reuse wxCFRef-related code (e.g. wxCFRetain/wxCFRelease) -#include "wx/osx/core/cfref.h" - -// NOTE WELL: We can only know whether or not GC can be used when compiling Objective-C. -// Therefore we cannot implement these functions except when compiling Objective-C. -#ifdef __OBJC__ -/*! @function wxGCSafeRetain - @templatefield Type (implicit) An Objective-C class type - @arg r Pointer to Objective-C object. May be null. - @abstract Retains the Objective-C object, even when using Apple's garbage collector - @discussion - When Apple's garbage collector is enabled, the usual [obj retain] and [obj release] messages - are ignored. Instead the collector with help from compiler-generated write-barriers tracks - reachable objects. The write-barriers are generated when setting i-vars of C++ classes but - they are ignored by the garbage collector unless the C++ object is in GC-managed memory. - - The simple solution is to use CFRetain on the Objective-C object which has been enhanced in - GC mode to forcibly retain the object. In Retain/Release (RR) mode the CFRetain function has - the same effect as [obj retain]. Note that GC vs. RR is selected at runtime. - - Take care that wxGCSafeRetain must be balanced with wxGCSafeRelease and that conversely - wxGCSafeRelease must only be called on objects to balance wxGCSafeRetain. In particular when - receiving an Objective-C object from an alloc or copy method take care that you must retain - it with wxGCSafeRetain and balance the initial alloc with a standard release. - - Example: - wxGCSafeRelease(m_obj); // release current object (if any) - NSObject *obj = [[NSObject alloc] init]; - m_obj = wxGCSafeRetain(obj); - [obj release]; - - Alternatively (same effect, perhaps less clear): - wxGCSafeRelease(m_obj); // release current object (if any) - m_obj = wxGCSafeRetain([[NSObject alloc] init]); - [m_obj release]; // balance alloc - - Consider the effect on the retain count from each statement (alloc, CFRetain, release) - In RR mode: retainCount = 1, +1, -1 - In GC mode: strongRetainCount = 0, +1, -0 - - This is a template function to ensure it is used on raw pointers and never on pointer-holder - objects via implicit conversion operators. -*/ -template -inline Type * wxGCSafeRetain(Type *r) -{ -#ifdef __OBJC_GC__ - return static_cast(wxCFRetain(r)); -#else - return [r retain]; -#endif -} - -/*! @function wxGCSafeRelease - @templatefield Type (implicit) An Objective-C class type - @arg r Pointer to Objective-C object. May be null. - @abstract Balances wxGCSafeRetain. Particularly useful with the Apple Garbage Collector. - @discussion - See the wxGCSafeRetain documentation for more details. - - Example (from wxGCSafeRetain documentation): - wxGCSafeRelease(m_obj); // release current object (if any) - m_obj = wxGCSafeRetain([[NSObject alloc] init]); - [m_obj release]; // balance alloc - - When viewed from the start, m_obj ought to start as nil. However, the second time through - the wxGCSafeRelease call becomes critical as it releases the retain from the first time - through. - - In the destructor for this C++ object with the m_obj i-var you ought to do the following: - wxGCSafeRelease(m_obj); - m_obj = nil; // Not strictly needed, but safer. - - Under no circumstances should you balance an alloc or copy with a wxGCSafeRelease. -*/ -template -inline void wxGCSafeRelease(Type *r) -{ -#ifdef __OBJC_GC__ - wxCFRelease(r); -#else - [r release]; -#endif -} -#else -// NOTE: When not compiling Objective-C, declare these functions such that they can be -// used by other inline-implemented methods. Since those methods in turn will not actually -// be used from non-ObjC code the compiler ought not emit them. If it emits an out of -// line copy of those methods then presumably it will have also emitted at least one -// out of line copy of these functions from at least one Objective-C++ translation unit. -// That means the out of line implementation will be available at link time. - -template -inline Type * wxGCSafeRetain(Type *r); - -template -inline void wxGCSafeRelease(Type *r); - -#endif //def __OBJC__ - -/* -wxObjcAutoRefFromAlloc: construct a reference to an object that was -[NSObject -alloc]'ed and thus does not need a retain -wxObjcAutoRef: construct a reference to an object that was -either autoreleased or is retained by something else. -*/ - -struct objc_object; - -// We must do any calls to Objective-C from an Objective-C++ source file -class wxObjcAutoRefBase -{ -protected: - /*! @function ObjcRetain - @abstract Simply does [p retain]. - */ - static struct objc_object* ObjcRetain(struct objc_object*); - - /*! @function ObjcRelease - @abstract Simply does [p release]. - */ - static void ObjcRelease(struct objc_object*); -}; - -/*! @class wxObjcAutoRefFromAlloc - @templatefield T The type of _pointer_ (e.g. NSString*, NSRunLoop*) - @abstract Pointer-holder for Objective-C objects - @discussion - When constructing this object from a raw pointer, the pointer is assumed to have - come from an alloc-style method. That is, once you construct this object from - the pointer you must not balance your alloc with a call to release. - - This class has been carefully designed to work with both the traditional Retain/Release - and the new Garbage Collected modes. In RR-mode it will prevent the object from being - released by managing the reference count using the retain/release semantics. In GC-mode - it will use a method (currently CFRetain/CFRelease) to ensure the object will never be - finalized until this object is destroyed. - */ - -template -class wxObjcAutoRefFromAlloc: wxObjcAutoRefBase -{ -public: - wxObjcAutoRefFromAlloc(T p = 0) - : m_ptr(p) - // NOTE: this is from alloc. Do NOT retain - { - // CFRetain - // GC: Object is strongly retained and prevented from being collected - // non-GC: Simply realizes it's an Objective-C object and calls [p retain] - wxGCSafeRetain(p); - // ObjcRelease (e.g. [p release]) - // GC: Objective-C retain/release mean nothing in GC mode - // non-GC: This is a normal release call, balancing the retain - ObjcRelease(static_cast(p)); - // The overall result: - // GC: Object is strongly retained - // non-GC: Retain count is the same as it was (retain then release) - } - wxObjcAutoRefFromAlloc(const wxObjcAutoRefFromAlloc& otherRef) - : m_ptr(otherRef.m_ptr) - { wxGCSafeRetain(m_ptr); } - ~wxObjcAutoRefFromAlloc() - { wxGCSafeRelease(m_ptr); } - wxObjcAutoRefFromAlloc& operator=(const wxObjcAutoRefFromAlloc& otherRef) - { wxGCSafeRetain(otherRef.m_ptr); - wxGCSafeRelease(m_ptr); - m_ptr = otherRef.m_ptr; - return *this; - } - operator T() const - { return static_cast(m_ptr); } - T operator->() const - { return static_cast(m_ptr); } -protected: - /*! @field m_ptr The pointer to the Objective-C object - @discussion - The pointer to the Objective-C object is typed as void* to avoid compiler-generated write - barriers as would be used for implicitly __strong object pointers and to avoid the similar - read barriers as would be used for an explicitly __weak object pointer. The write barriers - are useless unless this object is located in GC-managed heap which is highly unlikely. - - Since we guarantee strong reference via CFRetain/CFRelease the write-barriers are not needed - at all, even if this object does happen to be allocated in GC-managed heap. - */ - void *m_ptr; -}; - -/*! - @class wxObjcAutoRef - @description - A pointer holder that does retain its argument. - NOTE: It is suggest that you instead use wxObjcAutoRefFromAlloc foo([aRawPointer retain]) - */ -template -class wxObjcAutoRef: public wxObjcAutoRefFromAlloc -{ -public: - /*! @method wxObjcAutoRef - @description - Uses the underlying wxObjcAutoRefFromAlloc and simply does a typical [p retain] such that - in RR-mode the object is in effectively the same retain-count state as it would have been - coming straight from an alloc method. - */ - wxObjcAutoRef(T p = 0) - : wxObjcAutoRefFromAlloc(p) - { // NOTE: ObjcRetain is correct because in GC-mode it balances ObjcRelease in our superclass constructor - // In RR mode it does retain and the superclass does retain/release thus resulting in an overall retain. - ObjcRetain(static_cast(wxObjcAutoRefFromAlloc::m_ptr)); - } - ~wxObjcAutoRef() {} - wxObjcAutoRef(const wxObjcAutoRef& otherRef) - : wxObjcAutoRefFromAlloc(otherRef) - {} - wxObjcAutoRef(const wxObjcAutoRefFromAlloc& otherRef) - : wxObjcAutoRefFromAlloc(otherRef) - {} - wxObjcAutoRef& operator=(const wxObjcAutoRef& otherRef) - { return wxObjcAutoRefFromAlloc::operator=(otherRef); } -}; - -#endif //ndef _WX_COCOA_OBJCREF_H__ diff --git a/include/wx/cocoa/app.h b/include/wx/cocoa/app.h deleted file mode 100644 index dffb0cae63..0000000000 --- a/include/wx/cocoa/app.h +++ /dev/null @@ -1,73 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/app.h -// Purpose: wxApp class -// Author: David Elliott -// Modified by: -// Created: 2002/11/27 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_APP_H_ -#define _WX_COCOA_APP_H_ - -typedef struct __CFRunLoopObserver * CFRunLoopObserverRef; -typedef const struct __CFString * CFStringRef; - -#include "wx/osx/core/cfref.h" - -// ======================================================================== -// wxApp -// ======================================================================== -// Represents the application. Derive OnInit and declare -// a new App object to start application -class WXDLLIMPEXP_CORE wxApp: public wxAppBase -{ - DECLARE_DYNAMIC_CLASS(wxApp) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxApp(); - virtual ~wxApp(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - inline WX_NSApplication GetNSApplication() { return m_cocoaApp; } - virtual void CocoaDelegate_applicationWillBecomeActive(); - virtual void CocoaDelegate_applicationDidBecomeActive(); - virtual void CocoaDelegate_applicationWillResignActive(); - virtual void CocoaDelegate_applicationDidResignActive(); - virtual void CocoaDelegate_applicationWillUpdate(); - virtual void CF_ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, int activity); -protected: - WX_NSApplication m_cocoaApp; - struct objc_object *m_cocoaAppDelegate; - WX_NSThread m_cocoaMainThread; - wxCFRef m_cfRunLoopIdleObserver; - wxCFRef m_cfObservedRunLoopMode; - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // Implement wxAppBase pure virtuals - virtual void Exit(); - - virtual void WakeUpIdle(); - - virtual bool Initialize(int& argc, wxChar **argv); - virtual void CleanUp(); - virtual bool CallOnInit(); - - - virtual bool OnInit(); - virtual bool OnInitGui(); - - // Set true _before_ initializing wx to force embedded mode (no app delegate, etc.) - static bool sm_isEmbedded; -}; - -#endif // _WX_COCOA_APP_H_ diff --git a/include/wx/cocoa/autorelease.h b/include/wx/cocoa/autorelease.h deleted file mode 100644 index cd5f6b3e26..0000000000 --- a/include/wx/cocoa/autorelease.h +++ /dev/null @@ -1,31 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/autorelease.h -// Purpose: Automatic NSAutoreleasePool functionality -// Author: David Elliott -// Modified by: -// Created: 2003/07/11 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_AUTORELEASE_H__ -#define __WX_COCOA_AUTORELEASE_H__ - -#import - -class wxAutoNSAutoreleasePool -{ -public: - wxAutoNSAutoreleasePool() - { - m_pool = [[NSAutoreleasePool alloc] init]; - } - ~wxAutoNSAutoreleasePool() - { - [m_pool release]; - } -protected: - NSAutoreleasePool *m_pool; -}; - -#endif //__WX_COCOA_AUTORELEASE_H__ diff --git a/include/wx/cocoa/bitmap.h b/include/wx/cocoa/bitmap.h deleted file mode 100644 index 392b50b5b9..0000000000 --- a/include/wx/cocoa/bitmap.h +++ /dev/null @@ -1,164 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/bitmap.h -// Purpose: wxBitmap class -// Author: David Elliott -// Modified by: -// Created: 2003/07/19 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_BITMAP_H__ -#define __WX_COCOA_BITMAP_H__ - -#include "wx/palette.h" - -// Bitmap -class WXDLLIMPEXP_FWD_CORE wxBitmap; -class WXDLLIMPEXP_FWD_CORE wxIcon; -class WXDLLIMPEXP_FWD_CORE wxCursor; -class WXDLLIMPEXP_FWD_CORE wxImage; -class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; - -// ======================================================================== -// wxMask -// ======================================================================== - -// A mask is a 1-bit alpha bitmap used for drawing bitmaps transparently. -class WXDLLIMPEXP_CORE wxMask: public wxObject -{ - DECLARE_DYNAMIC_CLASS(wxMask) -public: - wxMask(); - - // Construct a mask from a bitmap and a colour indicating - // the transparent area - wxMask(const wxBitmap& bitmap, const wxColour& colour); - - // Construct a mask from a bitmap and a palette index indicating - // the transparent area - wxMask(const wxBitmap& bitmap, int paletteIndex); - - // Construct a mask from a mono bitmap (copies the bitmap). - wxMask(const wxBitmap& bitmap); - - // Copy constructor - wxMask(const wxMask& src); - - virtual ~wxMask(); - - bool Create(const wxBitmap& bitmap, const wxColour& colour); - bool Create(const wxBitmap& bitmap, int paletteIndex); - bool Create(const wxBitmap& bitmap); - - // wxCocoa - inline WX_NSBitmapImageRep GetNSBitmapImageRep() - { return m_cocoaNSBitmapImageRep; } -protected: - WX_NSBitmapImageRep m_cocoaNSBitmapImageRep; -}; - - -// ======================================================================== -// wxBitmap -// ======================================================================== - -class WXDLLIMPEXP_CORE wxBitmap: public wxGDIObject, - public wxBitmapHelpers -{ -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - // Platform-specific default constructor - wxBitmap(); - // Initialize with raw data. - wxBitmap(const char bits[], int width, int height, int depth = 1); - // Initialize with XPM data - wxBitmap(const char* const* bits); - // Load a file or resource - wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); - // Construct from Cocoa's NSImage - wxBitmap(NSImage* cocoaNSImage); - // Construct from Cocoa's NSBitmapImageRep - wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep); - // Constructor for generalised creation from data - wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1); - // If depth is omitted, will create a bitmap compatible with the display - wxBitmap(int width, int height, int depth = -1) - { (void)Create(width, height, depth); } - wxBitmap(const wxSize& sz, int depth = -1) - { (void)Create(sz, depth); } - // Convert from wxImage: - wxBitmap(const wxImage& image, int depth = -1) - { CreateFromImage(image, depth); } - // Convert from wxIcon - wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); } - - // destructor - virtual ~wxBitmap(); - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // Initialize from wxImage - bool CreateFromImage(const wxImage& image, int depth=-1); - - virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH); - virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) - { return Create(sz.GetWidth(), sz.GetHeight(), depth); } - - bool Create(NSImage* cocoaNSImage); - bool Create(NSBitmapImageRep* cocoaNSBitmapImageRep); - virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1); - virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); - virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; - - // copies the contents and mask of the given (colour) icon to the bitmap - virtual bool CopyFromIcon(const wxIcon& icon); - - wxImage ConvertToImage() const; - - // get the given part of bitmap - wxBitmap GetSubBitmap( const wxRect& rect ) const; - - int GetWidth() const; - int GetHeight() const; - int GetDepth() const; - int GetQuality() const; - void SetWidth(int w); - void SetHeight(int h); - void SetDepth(int d); - void SetQuality(int q); - void SetOk(bool isOk); - - // raw bitmap access support functions - void *GetRawData(wxPixelDataBase& data, int bpp); - void UngetRawData(wxPixelDataBase& data); - - wxPalette* GetPalette() const; - void SetPalette(const wxPalette& palette); - - wxMask *GetMask() const; - void SetMask(wxMask *mask) ; - - wxBitmapType GetBitmapType() const; - - // wxCocoa - WX_NSBitmapImageRep GetNSBitmapImageRep(); - void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep); - WX_NSImage GetNSImage(bool useMask) const; - - static void InitStandardHandlers() { } - static void CleanUpHandlers() { } - -protected: - wxGDIRefData *CreateGDIRefData() const; - wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; - - DECLARE_DYNAMIC_CLASS(wxBitmap) -}; - - -#endif // __WX_COCOA_BITMAP_H__ diff --git a/include/wx/cocoa/bmpbuttn.h b/include/wx/cocoa/bmpbuttn.h deleted file mode 100644 index 10a1394872..0000000000 --- a/include/wx/cocoa/bmpbuttn.h +++ /dev/null @@ -1,61 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/bmpbuttn.h -// Purpose: wxBitmapButton class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_BMPBUTTN_H__ -#define __WX_COCOA_BMPBUTTN_H__ - -#include "wx/cocoa/NSButton.h" - -// ======================================================================== -// wxBitmapButton -// ======================================================================== -class WXDLLIMPEXP_CORE wxBitmapButton : public wxBitmapButtonBase -{ - DECLARE_DYNAMIC_CLASS(wxBitmapButton) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSButton,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxBitmapButton() { } - wxBitmapButton(wxWindow *parent, wxWindowID winid, - const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr) - { - Create(parent, winid, bitmap, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); - virtual ~wxBitmapButton(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_wxNSButtonAction(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // The wxButton::DoGetBestSize is not correct for bitmap buttons - wxSize DoGetBestSize() const - { return wxButtonBase::DoGetBestSize(); } -}; - -#endif // __WX_COCOA_BMPBUTTN_H__ diff --git a/include/wx/cocoa/brush.h b/include/wx/cocoa/brush.h deleted file mode 100644 index c6e8f63995..0000000000 --- a/include/wx/cocoa/brush.h +++ /dev/null @@ -1,69 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/brush.h -// Purpose: wxBrush class -// Author: David Elliott -// Modified by: -// Created: 2003/07/03 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_BRUSH_H__ -#define __WX_COCOA_BRUSH_H__ - -#include "wx/gdicmn.h" -#include "wx/gdiobj.h" -#include "wx/bitmap.h" - -class WXDLLIMPEXP_FWD_CORE wxBrush; - -// ======================================================================== -// wxBrush -// ======================================================================== -class WXDLLIMPEXP_CORE wxBrush: public wxBrushBase -{ - DECLARE_DYNAMIC_CLASS(wxBrush) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxBrush(); - wxBrush(const wxColour& col, wxBrushStyle style = wxBRUSHSTYLE_SOLID); - wxBrush(const wxBitmap& stipple); - virtual ~wxBrush(); - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ - virtual void SetColour(const wxColour& col) ; - virtual void SetColour(unsigned char r, unsigned char g, unsigned char b) ; - virtual void SetStyle(wxBrushStyle style) ; - virtual void SetStipple(const wxBitmap& stipple) ; - - // comparison - bool operator == (const wxBrush& brush) const - { return m_refData == brush.m_refData; } - bool operator != (const wxBrush& brush) const - { return m_refData != brush.m_refData; } - - // accessors - wxColour GetColour() const; - virtual wxBrushStyle GetStyle() const; - wxBitmap *GetStipple() const; - - - wxDEPRECATED_MSG("use wxBRUSHSTYLE_XXX constants") - wxBrush(const wxColour& col, int style); - - wxDEPRECATED_MSG("use wxBRUSHSTYLE_XXX constants") - void SetStyle(int style) { SetStyle((wxBrushStyle)style); } - - // wxCocoa - WX_NSColor GetNSColor(); - -protected: - wxGDIRefData *CreateGDIRefData() const; - wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; -}; - -#endif // __WX_COCOA_BRUSH_H__ diff --git a/include/wx/cocoa/button.h b/include/wx/cocoa/button.h deleted file mode 100644 index d58d0fb6bd..0000000000 --- a/include/wx/cocoa/button.h +++ /dev/null @@ -1,64 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/button.h -// Purpose: wxButton class -// Author: David Elliott -// Modified by: -// Created: 2002/12/29 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_BUTTON_H__ -#define __WX_COCOA_BUTTON_H__ - -#include "wx/cocoa/NSButton.h" - -// ======================================================================== -// wxButton -// ======================================================================== -class WXDLLIMPEXP_CORE wxButton : public wxButtonBase, protected wxCocoaNSButton -{ - DECLARE_DYNAMIC_CLASS(wxButton) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSButton,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxButton() { } - wxButton(wxWindow *parent, wxWindowID winid, - const wxString& label = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr) - { - Create(parent, winid, label, pos, size, style, validator, name); - } - - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& label = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); - - virtual ~wxButton(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_wxNSButtonAction(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - wxString GetLabel() const; - void SetLabel(const wxString& label); - wxSize DoGetBestSize() const; -}; - -#endif - // __WX_COCOA_BUTTON_H__ diff --git a/include/wx/cocoa/checkbox.h b/include/wx/cocoa/checkbox.h deleted file mode 100644 index ba811c54e8..0000000000 --- a/include/wx/cocoa/checkbox.h +++ /dev/null @@ -1,68 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/checkbox.h -// Purpose: wxCheckBox class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_CHECKBOX_H__ -#define __WX_COCOA_CHECKBOX_H__ - -#include "wx/cocoa/NSButton.h" - -// ======================================================================== -// wxCheckBox -// ======================================================================== -class WXDLLIMPEXP_CORE wxCheckBox: public wxCheckBoxBase , protected wxCocoaNSButton -{ - DECLARE_DYNAMIC_CLASS(wxCheckBox) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSButton,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxCheckBox() { } - wxCheckBox(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxCheckBoxNameStr) - { - Create(parent, winid, label, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxCheckBoxNameStr); - virtual ~wxCheckBox(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_wxNSButtonAction(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void SetValue(bool); - virtual bool GetValue() const; - virtual void SetLabel(const wxString& label); - virtual wxString GetLabel() const; - -protected: - virtual void DoSet3StateValue(wxCheckBoxState state); - virtual wxCheckBoxState DoGet3StateValue() const; -}; - -#endif // __WX_COCOA_CHECKBOX_H__ diff --git a/include/wx/cocoa/checklst.h b/include/wx/cocoa/checklst.h deleted file mode 100644 index 8f07894342..0000000000 --- a/include/wx/cocoa/checklst.h +++ /dev/null @@ -1,79 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/checklst.h -// Purpose: wxCheckListBox class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_CHECKLST_H__ -#define __WX_COCOA_CHECKLST_H__ - -//#include "wx/cocoa/NSTableView.h" - -// ======================================================================== -// wxCheckListBox -// ======================================================================== -class WXDLLIMPEXP_CORE wxCheckListBox: public wxCheckListBoxBase //, protected wxCocoaNSTableView -{ - DECLARE_DYNAMIC_CLASS(wxCheckListBox) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSTableView,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxCheckListBox() { } - wxCheckListBox(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr) - { - Create(parent, winid, pos, size, n, choices, style, validator, name); - } - wxCheckListBox(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr) - { - Create(parent, winid, pos, size, choices, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr); - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr); - virtual ~wxCheckListBox(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // check list box specific methods - virtual bool IsChecked(unsigned int item) const; - virtual void Check(unsigned int item, bool check = true); -}; - -#endif // __WX_COCOA_CHECKLST_H__ diff --git a/include/wx/cocoa/chkconf.h b/include/wx/cocoa/chkconf.h deleted file mode 100644 index 77ccadfe68..0000000000 --- a/include/wx/cocoa/chkconf.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Name: wx/cocoa/chkconf.h - * Purpose: wxCocoa-specific config settings checks - * Author: Vadim Zeitlin - * Created: 2008-09-11 - * Copyright: (c) 2008 Vadim Zeitlin - * Licence: wxWindows licence - */ - -/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ - -#ifndef _WX_COCOA_CHKCONF_H_ -#define _WX_COCOA_CHKCONF_H_ - -/* - wxLogDialog doesn't currently work correctly in wxCocoa. - */ -#undef wxUSE_LOG_DIALOG -#define wxUSE_LOG_DIALOG 0 - -#endif /* _WX_COCOA_CHKCONF_H_ */ diff --git a/include/wx/cocoa/choice.h b/include/wx/cocoa/choice.h deleted file mode 100644 index 7fe2c06e8d..0000000000 --- a/include/wx/cocoa/choice.h +++ /dev/null @@ -1,100 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/choice.h -// Purpose: wxChoice class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_CHOICE_H__ -#define __WX_COCOA_CHOICE_H__ - -//#include "wx/cocoa/NSPopUpButton.h" -#include "wx/cocoa/NSMenu.h" - -class WXDLLIMPEXP_FWD_BASE wxSortedArrayString; - -// ======================================================================== -// wxChoice -// ======================================================================== -class WXDLLIMPEXP_CORE wxChoice: public wxChoiceBase /*, protected wxCocoaNSPopUpButton */, protected wxCocoaNSMenu -{ - DECLARE_DYNAMIC_CLASS(wxChoice) - DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSTableView,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxChoice() { Init(); } - wxChoice(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxChoiceNameStr) - { - Init(); - Create(parent, winid, pos, size, n, choices, style, validator, name); - } - wxChoice(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxChoiceNameStr) - { - Init(); - Create(parent, winid, pos, size, choices, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxChoiceNameStr); - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxChoiceNameStr); - virtual ~wxChoice(); -protected: - void Init(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - void CocoaNotification_menuDidSendAction(WX_NSNotification notification); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void DoClear(); - virtual unsigned int GetCount() const; - virtual wxString GetString(unsigned int) const; - virtual void SetString(unsigned int pos, const wxString&); - virtual int FindString(const wxString& s, bool bCase = false) const; - virtual int GetSelection() const; - virtual int DoInsertItems(const wxArrayStringsAdapter& items, - unsigned int pos, - void **clientData, wxClientDataType type); - virtual void DoDeleteOneItem(unsigned int pos); - virtual void DoSetItemClientData(unsigned int, void*); - virtual void* DoGetItemClientData(unsigned int) const; - virtual void SetSelection(int pos); -protected: - wxSortedArrayString *m_sortedStrings; - wxArrayPtrVoid m_itemsClientData; -}; - -#endif // __WX_COCOA_CHOICE_H__ diff --git a/include/wx/cocoa/clipbrd.h b/include/wx/cocoa/clipbrd.h deleted file mode 100644 index 8571f8f56d..0000000000 --- a/include/wx/cocoa/clipbrd.h +++ /dev/null @@ -1,51 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/clipbrd.h -// Purpose: wxClipboard -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_CLIPBRD_H__ -#define __WX_COCOA_CLIPBRD_H__ - -#include "wx/dataobj.h" - -//========================================================================= -// wxClipboard -//========================================================================= -class wxClipboard : public wxClipboardBase -{ - DECLARE_DYNAMIC_CLASS(wxClipboard) -public: - wxClipboard(); - virtual ~wxClipboard(); - - // open the clipboard before SetData() and GetData() - virtual bool Open(); - - // close the clipboard after SetData() and GetData() - virtual void Close(); - - // query whether the clipboard is opened - virtual bool IsOpened() const; - - // set the clipboard data. all other formats will be deleted. - virtual bool SetData( wxDataObject *data ); - - // add to the clipboard data. - virtual bool AddData( wxDataObject *data ); - - // ask if data in correct format is available - virtual bool IsSupported( const wxDataFormat& format ); - - // fill data with data on the clipboard (if available) - virtual bool GetData( wxDataObject& data ); - - // clears wxTheClipboard and the system's clipboard if possible - virtual void Clear(); -}; - -#endif //__WX_COCOA_CLIPBRD_H__ diff --git a/include/wx/cocoa/colordlg.h b/include/wx/cocoa/colordlg.h deleted file mode 100644 index 8b13789179..0000000000 --- a/include/wx/cocoa/colordlg.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/include/wx/cocoa/colour.h b/include/wx/cocoa/colour.h deleted file mode 100644 index 97593a3e3f..0000000000 --- a/include/wx/cocoa/colour.h +++ /dev/null @@ -1,92 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/colour.h -// Purpose: wxColour class -// Author: David Elliott -// Modified by: -// Created: 2003/06/17 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_COLOUR_H__ -#define __WX_COCOA_COLOUR_H__ - -#include "wx/object.h" -#include "wx/string.h" - -// ======================================================================== -// wxColour -// ======================================================================== - -class WXDLLIMPEXP_CORE wxColour : public wxColourBase -{ -public: - // constructors - // ------------ - DEFINE_STD_WXCOLOUR_CONSTRUCTORS - - // initialization using existing NSColor - wxColour( WX_NSColor aColor ); - - // copy ctors and assignment operators - wxColour( const wxColour& col ); - wxColour& operator = ( const wxColour& col ); - - virtual ~wxColour(); - - // accessors - virtual bool IsOk() const { return m_cocoaNSColor; } - WX_NSColor GetNSColor() { return m_cocoaNSColor; } - WX_NSColor GetNSColor() const { return m_cocoaNSColor; } - - unsigned char Red() const { return m_red; } - unsigned char Green() const { return m_green; } - unsigned char Blue() const { return m_blue; } - unsigned char Alpha() const { return m_alpha; } - - // comparison - bool operator == (const wxColour& colour) const - { - return m_cocoaNSColor == colour.m_cocoaNSColor || - (m_red == colour.m_red && - m_green == colour.m_green && - m_blue == colour.m_blue && - m_alpha == colour.m_alpha); - } - bool operator != (const wxColour& colour) const - { return !(*this == colour); } - - // Set() functions - void Set( WX_NSColor aColor ); - - // reroute the inherited ones - void Set(unsigned char red, - unsigned char green, - unsigned char blue, - unsigned char alpha = wxALPHA_OPAQUE) - { wxColourBase::Set(red, green, blue, alpha); } - - bool Set(const wxString &str) - { return wxColourBase::Set(str); } - - void Set(unsigned long colRGB) - { wxColourBase::Set(colRGB); } - -protected: - // puts the object in an invalid, uninitialized state - void Init(); - - virtual void - InitRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a); - -private: - WX_NSColor m_cocoaNSColor; - unsigned char m_red; - unsigned char m_green; - unsigned char m_blue; - unsigned char m_alpha; - - DECLARE_DYNAMIC_CLASS(wxColour) -}; - -#endif // __WX_COCOA_COLOUR_H__ diff --git a/include/wx/cocoa/combobox.h b/include/wx/cocoa/combobox.h deleted file mode 100644 index dc09cf216c..0000000000 --- a/include/wx/cocoa/combobox.h +++ /dev/null @@ -1,157 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/combobox.h -// Purpose: wxComboBox class -// Author: Ryan Norton -// Modified by: -// Created: 2005/02/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_COMBOBOX_H__ -#define __WX_COCOA_COMBOBOX_H__ - -//Begin NSComboBox.h - -#include "wx/hashmap.h" -#include "wx/cocoa/ObjcAssociate.h" - -#include "wx/textctrl.h" - -DECLARE_WXCOCOA_OBJC_CLASS(NSComboBox); - -WX_DECLARE_OBJC_HASHMAP(NSComboBox); -class wxCocoaNSComboBox -{ - WX_DECLARE_OBJC_INTERFACE_HASHMAP(NSComboBox) -public: - void AssociateNSComboBox(WX_NSComboBox cocoaNSComboBox); - void DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox); - - virtual void doWxEvent(int nEvent) = 0; - virtual ~wxCocoaNSComboBox() { } -}; - -//begin combobox.h - -#include "wx/dynarray.h" - -// ======================================================================== -// wxComboBox -// ======================================================================== -class WXDLLIMPEXP_CORE wxComboBox : public wxControl, public wxComboBoxBase, protected wxCocoaNSComboBox, protected wxCocoaNSTextField -{ - DECLARE_DYNAMIC_CLASS(wxComboBox) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSComboBox,NSTextField,NSView) - WX_DECLARE_COCOA_OWNER(NSTextField,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxComboBox() { } - wxComboBox(wxWindow *parent, wxWindowID winid, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxComboBoxNameStr) - { - Create(parent, winid, value, pos, size, n, choices, style, validator, name); - } - wxComboBox(wxWindow *parent, wxWindowID winid, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxComboBoxNameStr) - { - Create(parent, winid, value, pos, size, choices, style, - validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxComboBoxNameStr); - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxComboBoxNameStr); - virtual ~wxComboBox(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - wxArrayPtrVoid m_Datas; - virtual void doWxEvent(int nEvent); - - virtual void Cocoa_didChangeText() - {} -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - void Clear() // HACK - { wxComboBoxBase::Clear(); } - - // wxCombobox methods - virtual void SetSelection(int pos); - // Overlapping methods - virtual wxString GetStringSelection(); - // wxItemContainer - virtual void DoClear(); - virtual void DoDeleteOneItem(unsigned int n); - virtual unsigned int GetCount() const; - virtual wxString GetString(unsigned int) const; - virtual void SetString(unsigned int pos, const wxString&); - virtual int FindString(const wxString& s, bool bCase = false) const; - virtual int GetSelection() const; - virtual int DoInsertItems(const wxArrayStringsAdapter& items, - unsigned int pos, - void **clientData, wxClientDataType type); - virtual void DoSetItemClientData(unsigned int, void*); - virtual void* DoGetItemClientData(unsigned int) const; - virtual bool IsSorted() const { return HasFlag(wxCB_SORT); } - -// ------------------------------------------------------------------------ -// wxTextEntryBase virtual implementations: -// ------------------------------------------------------------------------ - // FIXME: This needs to be moved to some sort of common code. - virtual void WriteText(const wxString&); - virtual wxString GetValue() const; - virtual void Remove(long, long); - virtual void Cut(); - virtual void Copy(); - virtual void Paste(); - virtual void Undo(); - virtual void Redo(); - virtual bool CanUndo() const; - virtual bool CanRedo() const; - virtual void SetInsertionPoint(long pos); - virtual long GetInsertionPoint() const; - virtual wxTextPos GetLastPosition() const; - virtual void SetSelection(long from, long to); - virtual void GetSelection(long *from, long *to) const; - virtual bool IsEditable() const; - virtual void SetEditable(bool editable); - -private: - // implement wxTextEntry pure virtual method - virtual wxWindow *GetEditableWindow() { return this; } -}; - -#endif // __WX_COCOA_COMBOBOX_H__ diff --git a/include/wx/cocoa/control.h b/include/wx/cocoa/control.h deleted file mode 100644 index cb493202a6..0000000000 --- a/include/wx/cocoa/control.h +++ /dev/null @@ -1,77 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/control.h -// Purpose: wxControl class -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_CONTROL_H__ -#define __WX_COCOA_CONTROL_H__ - -#include "wx/cocoa/NSControl.h" - -// ======================================================================== -// wxControl -// ======================================================================== - -class WXDLLIMPEXP_CORE wxControl : public wxControlBase, public wxCocoaNSControl -{ - DECLARE_ABSTRACT_CLASS(wxControl) - WX_DECLARE_COCOA_OWNER(NSControl,NSView,NSView) - DECLARE_EVENT_TABLE() -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxControl() {} - wxControl(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxControlNameStr) - { - Create(parent, winid, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxControlNameStr); - virtual ~wxControl(); - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - - // implementation from now on - // -------------------------- - - void OnEraseBackground(wxEraseEvent& event); - - virtual void Command(wxCommandEvent& event) { ProcessCommand(event); } - - // Calls the callback and appropriate event handlers - bool ProcessCommand(wxCommandEvent& event); - - // Enables the control - virtual void CocoaSetEnabled(bool enable); -protected: - virtual wxSize DoGetBestSize() const; - - // Provides a common implementation of title setting which strips mnemonics - // and then calls setTitle: with the stripped string. May be implemented - // to call setTitleWithMnemonic: on OpenStep-compatible systems. Only - // intended for use by views or cells which implement at least setTitle: - // and possibly setTitleWithMnemonic: such as NSBox and NSButton or NSCell - // classes, for example as used by wxRadioBox. Not usable with classes like - // NSTextField which expect setStringValue:. - static void CocoaSetLabelForObject(const wxString& labelWithWxMnemonic, struct objc_object *anObject); -}; - -#endif - // __WX_COCOA_CONTROL_H__ diff --git a/include/wx/cocoa/cursor.h b/include/wx/cocoa/cursor.h deleted file mode 100644 index 54209f0b19..0000000000 --- a/include/wx/cocoa/cursor.h +++ /dev/null @@ -1,64 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/cursor.h -// Purpose: wxCursor class -// Author: David Elliott -// Modified by: -// Created: 2002/11/27 -// Copyright: (c) David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_CURSOR_H_ -#define _WX_COCOA_CURSOR_H_ - -#include "wx/bitmap.h" - -class WXDLLIMPEXP_CORE wxCursorRefData : public wxGDIRefData -{ -public: - wxCursorRefData(); - virtual ~wxCursorRefData(); - -protected: - int m_width, m_height; - WX_NSCursor m_hCursor; - - friend class WXDLLIMPEXP_FWD_CORE wxBitmap; - friend class WXDLLIMPEXP_FWD_CORE wxCursor; - - wxDECLARE_NO_COPY_CLASS(wxCursorRefData); -}; - -#define M_CURSORDATA ((wxCursorRefData *)m_refData) -#define M_CURSORHANDLERDATA ((wxCursorRefData *)bitmap->m_refData) - -// Cursor -class WXDLLIMPEXP_CORE wxCursor: public wxBitmap -{ -public: - wxCursor(); - - wxCursor(const wxString& name, wxBitmapType type = wxCURSOR_DEFAULT_TYPE, - int hotSpotX = 0, int hotSpotY = 0); - - wxCursor(wxStockCursor id) { InitFromStock(id); } -#if WXWIN_COMPATIBILITY_2_8 - wxCursor(int id) { InitFromStock((wxStockCursor)id); } -#endif - virtual ~wxCursor(); - - // FIXME: operator==() is wrong! - bool operator==(const wxCursor& cursor) const { return m_refData == cursor.m_refData; } - bool operator!=(const wxCursor& cursor) const { return !(*this == cursor); } - - WX_NSCursor GetNSCursor() const { return M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0; } - -private: - void InitFromStock(wxStockCursor); - DECLARE_DYNAMIC_CLASS(wxCursor) -}; - -extern WXDLLIMPEXP_CORE void wxSetCursor(const wxCursor& cursor); - -#endif - // _WX_COCOA_CURSOR_H_ diff --git a/include/wx/cocoa/dataform.h b/include/wx/cocoa/dataform.h deleted file mode 100644 index 870ddb0470..0000000000 --- a/include/wx/cocoa/dataform.h +++ /dev/null @@ -1,50 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dataform.h -// Purpose: declaration of the wxDataFormat class -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DATAFORM_H__ -#define __WX_COCOA_DATAFORM_H__ - -class wxDataFormat -{ -public: - wxDataFormat(unsigned int uFormat = wxDF_INVALID) { m_uFormat = uFormat; } - wxDataFormat(const wxString& zFormat) { SetId(zFormat); } - - wxDataFormat& operator=(unsigned int uFormat) { m_uFormat = uFormat; return(*this); } - wxDataFormat& operator=(const wxDataFormat& rFormat) {m_uFormat = rFormat.m_uFormat; return(*this); } - - // - // Comparison (must have both versions) - // - bool operator==(wxDataFormatId eFormat) const { return (m_uFormat == (unsigned int)eFormat); } - bool operator!=(wxDataFormatId eFormat) const { return (m_uFormat != (unsigned int)eFormat); } - bool operator==(const wxDataFormat& rFormat) const { return (m_uFormat == rFormat.m_uFormat); } - bool operator!=(const wxDataFormat& rFormat) const { return (m_uFormat != rFormat.m_uFormat); } - operator unsigned int(void) const { return m_uFormat; } - - unsigned int GetFormatId(void) const { return (unsigned int)m_uFormat; } - unsigned int GetType(void) const { return (unsigned int)m_uFormat; } - - bool IsStandard(void) const; - - void SetType(unsigned int uType){ m_uFormat = uType; } - - // - // String ids are used for custom types - this SetId() must be used for - // application-specific formats - // - wxString GetId(void) const; - void SetId(const wxString& WXUNUSED(pId)) { /* TODO */ } - -private: - unsigned int m_uFormat; -}; // end of CLASS wxDataFormat - -#endif // __WX_COCOA_DATAFORM_H__ diff --git a/include/wx/cocoa/dataobj.h b/include/wx/cocoa/dataobj.h deleted file mode 100644 index d525029f9c..0000000000 --- a/include/wx/cocoa/dataobj.h +++ /dev/null @@ -1,23 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dataobj.h -// Purpose: declaration of the wxDataObject -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DATAOBJ_H__ -#define __WX_COCOA_DATAOBJ_H__ - -class WXDLLIMPEXP_CORE wxDataObject : public wxDataObjectBase -{ -public: - wxDataObject(); - virtual ~wxDataObject(); - virtual bool IsSupportedFormat(const wxDataFormat& format, - Direction dir = Get) const; -}; - -#endif // __WX_COCOA_DATAOBJ_H__ diff --git a/include/wx/cocoa/dataobj2.h b/include/wx/cocoa/dataobj2.h deleted file mode 100644 index b824fe933e..0000000000 --- a/include/wx/cocoa/dataobj2.h +++ /dev/null @@ -1,83 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dataobj2.h -// Purpose: declaration of standard wxDataObjectSimple-derived classes -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DATAOBJ2_H__ -#define __WX_COCOA_DATAOBJ2_H__ - -//========================================================================= -// wxBitmapDataObject is a specialization of wxDataObject for bitmaps -//========================================================================= -class WXDLLIMPEXP_CORE wxBitmapDataObject : public wxBitmapDataObjectBase -{ -public: - // ctors - wxBitmapDataObject(); - wxBitmapDataObject(const wxBitmap& bitmap); - - // destr - virtual ~wxBitmapDataObject(); - - // override base class virtual to update PNG data too - virtual void SetBitmap(const wxBitmap& bitmap); - - // implement base class pure virtuals - // ---------------------------------- - - virtual size_t GetDataSize() const { return m_pngSize; } - virtual bool GetDataHere(void *buf) const; - virtual bool SetData(size_t len, const void *buf); - -protected: - void Init() { m_pngData = NULL; m_pngSize = 0; } - void Clear() { free(m_pngData); } - void ClearAll() { Clear(); Init(); } - - size_t m_pngSize; - void *m_pngData; - - void DoConvertToPng(); - -private: - // virtual function hiding supression - size_t GetDataSize(const wxDataFormat& format) const - { return(wxDataObjectSimple::GetDataSize(format)); } - bool GetDataHere(const wxDataFormat& format, void* pBuf) const - { return(wxDataObjectSimple::GetDataHere(format, pBuf)); } - bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf) - { return(wxDataObjectSimple::SetData(format, nLen, pBuf)); } -}; - -//========================================================================= -// wxFileDataObject is a specialization of wxDataObject for file names -//========================================================================= - -class WXDLLIMPEXP_CORE wxFileDataObject : public wxFileDataObjectBase -{ -public: - // implement base class pure virtuals - // ---------------------------------- - - void AddFile( const wxString &filename ); - - virtual size_t GetDataSize() const; - virtual bool GetDataHere(void *buf) const; - virtual bool SetData(size_t len, const void *buf); - -private: - // virtual function hiding supression - size_t GetDataSize(const wxDataFormat& format) const - { return(wxDataObjectSimple::GetDataSize(format)); } - bool GetDataHere(const wxDataFormat& format, void* pBuf) const - { return(wxDataObjectSimple::GetDataHere(format, pBuf)); } - bool SetData(const wxDataFormat& format, size_t nLen, const void* pBuf) - { return(wxDataObjectSimple::SetData(format, nLen, pBuf)); } -}; - -#endif //__WX_COCOA_DATAOBJ2_H__ diff --git a/include/wx/cocoa/dc.h b/include/wx/cocoa/dc.h deleted file mode 100644 index 0d4fec2065..0000000000 --- a/include/wx/cocoa/dc.h +++ /dev/null @@ -1,174 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dc.h -// Purpose: wxDC -// Author: David Elliott -// Modified by: -// Created: 2003/04/01 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DC_H__ -#define __WX_COCOA_DC_H__ - -DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform); - -#include "wx/dc.h" - -class WXDLLIMPEXP_FWD_CORE wxCocoaDCImpl; -WX_DECLARE_LIST(wxCocoaDCImpl, wxCocoaDCStack); - -//========================================================================= -// wxDC -//========================================================================= -class WXDLLIMPEXP_CORE wxCocoaDCImpl: public wxDCImpl -{ - DECLARE_ABSTRACT_CLASS(wxCocoaDCImpl) - wxDECLARE_NO_COPY_CLASS(wxCocoaDCImpl); -//------------------------------------------------------------------------- -// Initialization -//------------------------------------------------------------------------- -public: - wxCocoaDCImpl(wxDC *owner); - virtual ~wxCocoaDCImpl(); - -//------------------------------------------------------------------------- -// wxCocoa specifics -//------------------------------------------------------------------------- -public: - static void CocoaInitializeTextSystem(); - static void CocoaShutdownTextSystem(); - static WX_NSTextStorage sm_cocoaNSTextStorage; - static WX_NSLayoutManager sm_cocoaNSLayoutManager; - static WX_NSTextContainer sm_cocoaNSTextContainer; - // Create a simple Wx to Bounds transform (just flip the coordinate system) - static WX_NSAffineTransform CocoaGetWxToBoundsTransform(bool isFlipped, float height); -protected: -// DC stack - static wxCocoaDCStack sm_cocoaDCStack; - virtual bool CocoaLockFocus(); - virtual bool CocoaUnlockFocus(); - bool CocoaUnwindStackAndTakeFocus(); - inline bool CocoaTakeFocus() - { - wxCocoaDCStack::compatibility_iterator node = sm_cocoaDCStack.GetFirst(); - if(node && (node->GetData() == this)) - return true; - return CocoaUnwindStackAndTakeFocus(); - } - void CocoaUnwindStackAndLoseFocus(); -// DC flipping/transformation - void CocoaApplyTransformations(); - void CocoaUnapplyTransformations(); - WX_NSAffineTransform m_cocoaWxToBoundsTransform; -// Get bounds rect (for Clear()) - // note: we use void * to mean NSRect * so that we can avoid - // putting NSRect in the headers. - virtual bool CocoaGetBounds(void *rectData); -// Blitting - virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, - wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, - wxRasterOperationMode logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask); -//------------------------------------------------------------------------- -// Implementation -//------------------------------------------------------------------------- -public: - // implement base class pure virtuals - // ---------------------------------- - - virtual void Clear(); - - virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; } - virtual void EndDoc(void) {} - - virtual void StartPage(void) {} - virtual void EndPage(void) {} - - virtual void SetFont(const wxFont& font); - virtual void SetPen(const wxPen& pen); - virtual void SetBrush(const wxBrush& brush); - virtual void SetBackground(const wxBrush& brush); - virtual void SetBackgroundMode(int mode) { m_backgroundMode = mode; } - virtual void SetPalette(const wxPalette& palette); - - virtual void DestroyClippingRegion(); - - virtual wxCoord GetCharHeight() const; - virtual wxCoord GetCharWidth() const; - virtual void DoGetTextExtent(const wxString& string, - wxCoord *x, wxCoord *y, - wxCoord *descent = NULL, - wxCoord *externalLeading = NULL, - const wxFont *theFont = NULL) const; - - virtual bool CanDrawBitmap() const; - virtual bool CanGetTextExtent() const; - virtual int GetDepth() const; - virtual wxSize GetPPI() const; - - virtual void SetMapMode(wxMappingMode mode); - virtual void SetUserScale(double x, double y); - - virtual void SetLogicalScale(double x, double y); - virtual void SetLogicalOrigin(wxCoord x, wxCoord y); - virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); - virtual void SetLogicalFunction(wxRasterOperationMode function); - - virtual void SetTextForeground(const wxColour& colour) ; - virtual void SetTextBackground(const wxColour& colour) ; - - virtual void ComputeScaleAndOrigin(); -protected: - virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, - wxFloodFillStyle style = wxFLOOD_SURFACE); - - virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; - - virtual void DoDrawPoint(wxCoord x, wxCoord y); - virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); - - virtual void DoDrawArc(wxCoord x1, wxCoord y1, - wxCoord x2, wxCoord y2, - wxCoord xc, wxCoord yc); - - virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, - double sa, double ea); - - virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); - virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, - wxCoord width, wxCoord height, - double radius); - virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); - - virtual void DoCrossHair(wxCoord x, wxCoord y); - - virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); - virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, - bool useMask = false); - - virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); - virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, - double angle); - - virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, - wxDC *source, wxCoord xsrc, wxCoord ysrc, - int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); - - // this is gnarly - we can't even call this function DoSetClippingRegion() - // because of virtual function hiding - virtual void DoSetDeviceClippingRegion(const wxRegion& region); - virtual void DoSetClippingRegion(wxCoord x, wxCoord y, - wxCoord width, wxCoord height); - - virtual void DoGetSize(int *width, int *height) const; - virtual void DoGetSizeMM(int* width, int* height) const; - - virtual void DoDrawLines(int n, const wxPoint points[], - wxCoord xoffset, wxCoord yoffset); - virtual void DoDrawPolygon(int n, const wxPoint points[], - wxCoord xoffset, wxCoord yoffset, - wxPolygonFillMode fillStyle = wxODDEVEN_RULE); -}; - -#endif // __WX_COCOA_DC_H__ diff --git a/include/wx/cocoa/dcclient.h b/include/wx/cocoa/dcclient.h deleted file mode 100644 index 631c6ffd33..0000000000 --- a/include/wx/cocoa/dcclient.h +++ /dev/null @@ -1,69 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dcclient.h -// Purpose: wxClientDCImpl, wxPaintDCImpl and wxWindowDCImpl classes -// Author: David Elliott -// Modified by: -// Created: 2003/04/01 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DCCLIENT_H__ -#define __WX_COCOA_DCCLIENT_H__ - -#include "wx/cocoa/dc.h" - -// DFE: A while ago I stumbled upon the fact that retrieving the parent -// NSView of the content view seems to return the entire window rectangle -// (including decorations). Of course, that is not at all part of the -// Cocoa or OpenStep APIs, but it might be a neat hack. -class WXDLLIMPEXP_CORE wxWindowDCImpl: public wxCocoaDCImpl -{ - DECLARE_DYNAMIC_CLASS(wxWindowDCImpl) -public: - wxWindowDCImpl(wxDC *owner); - // Create a DC corresponding to a window - wxWindowDCImpl(wxDC *owner, wxWindow *win); - virtual ~wxWindowDCImpl(void); - -protected: - wxWindow *m_window; - WX_NSView m_lockedNSView; -// DC stack - virtual bool CocoaLockFocus(); - virtual bool CocoaUnlockFocus(); - bool CocoaLockFocusOnNSView(WX_NSView nsview); - bool CocoaUnlockFocusOnNSView(); - virtual bool CocoaGetBounds(void *rectData); -}; - -class WXDLLIMPEXP_CORE wxClientDCImpl: public wxWindowDCImpl -{ - DECLARE_DYNAMIC_CLASS(wxClientDCImpl) -public: - wxClientDCImpl(wxDC *owner); - // Create a DC corresponding to a window - wxClientDCImpl(wxDC *owner, wxWindow *win); - virtual ~wxClientDCImpl(void); -protected: -// DC stack - virtual bool CocoaLockFocus(); - virtual bool CocoaUnlockFocus(); -}; - -class WXDLLIMPEXP_CORE wxPaintDCImpl: public wxWindowDCImpl -{ - DECLARE_DYNAMIC_CLASS(wxPaintDCImpl) -public: - wxPaintDCImpl(wxDC *owner); - // Create a DC corresponding to a window - wxPaintDCImpl(wxDC *owner, wxWindow *win); - virtual ~wxPaintDCImpl(void); -protected: -// DC stack - virtual bool CocoaLockFocus(); - virtual bool CocoaUnlockFocus(); -}; - -#endif - // __WX_COCOA_DCCLIENT_H__ diff --git a/include/wx/cocoa/dcmemory.h b/include/wx/cocoa/dcmemory.h deleted file mode 100644 index 33846293c3..0000000000 --- a/include/wx/cocoa/dcmemory.h +++ /dev/null @@ -1,54 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dcmemory.h -// Purpose: wxMemoryDCImpl class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DCMEMORY_H__ -#define __WX_COCOA_DCMEMORY_H__ - -#include "wx/cocoa/dc.h" - -#include "wx/dcmemory.h" - -class WXDLLIMPEXP_CORE wxMemoryDCImpl: public wxCocoaDCImpl -{ - DECLARE_DYNAMIC_CLASS(wxMemoryDCImpl) - -public: - wxMemoryDCImpl(wxMemoryDC *owner) - : wxCocoaDCImpl(owner) - { Init(); } - wxMemoryDCImpl(wxMemoryDC *owner, wxBitmap& bitmap) - : wxCocoaDCImpl(owner) - { Init(); - owner->SelectObject(bitmap); - } - wxMemoryDCImpl(wxMemoryDC *owner, wxDC *dc ); // Create compatible DC - virtual ~wxMemoryDCImpl(void); - - virtual void DoGetSize(int *width, int *height) const; - virtual void DoSelect(const wxBitmap& bitmap); - -protected: - wxBitmap m_selectedBitmap; - WX_NSImage m_cocoaNSImage; -// DC stack - virtual bool CocoaLockFocus(); - virtual bool CocoaUnlockFocus(); - virtual bool CocoaGetBounds(void *rectData); -// Blitting - virtual bool CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, - wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, - wxRasterOperationMode logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask); - -private: - void Init(); -}; - -#endif - // __WX_COCOA_DCMEMORY_H__ diff --git a/include/wx/cocoa/dcscreen.h b/include/wx/cocoa/dcscreen.h deleted file mode 100644 index af7d4ee54e..0000000000 --- a/include/wx/cocoa/dcscreen.h +++ /dev/null @@ -1,31 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dcscreen.h -// Purpose: wxScreenDCImpl class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_DCSCREEN_H__ -#define __WX_COCOA_DCSCREEN_H__ - -#include "wx/dcscreen.h" -#include "wx/cocoa/dc.h" - -class WXDLLIMPEXP_CORE wxScreenDCImpl: public wxCocoaDCImpl -{ - DECLARE_DYNAMIC_CLASS(wxScreenDCImpl) -public: - wxScreenDCImpl(wxScreenDC *owner); - wxScreenDCImpl(wxScreenDC *owner, wxDC *dc ); // Create compatible DC - virtual ~wxScreenDCImpl(void); - - // Compatibility with X's requirements for drawing on top of all windows - static bool StartDrawingOnTop(wxWindow* WXUNUSED(window)) { return true; } - static bool StartDrawingOnTop(wxRect* WXUNUSED(rect) = NULL) { return true; } - static bool EndDrawingOnTop() { return true; } -}; - -#endif // __WX_COCOA_DCSCREEN_H__ diff --git a/include/wx/cocoa/dialog.h b/include/wx/cocoa/dialog.h deleted file mode 100644 index f27cccb080..0000000000 --- a/include/wx/cocoa/dialog.h +++ /dev/null @@ -1,80 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dialog.h -// Purpose: wxDialog class -// Author: David Elliott -// Modified by: -// Created: 2002/12/15 -// Copyright: David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_DIALOG_H_ -#define _WX_COCOA_DIALOG_H_ - -#include "wx/defs.h" -// NOTE: we don't need panel.h, but other things expect it to be included -#include "wx/panel.h" -#include "wx/cocoa/NSPanel.h" - -// ======================================================================== -// wxDialog -// ======================================================================== -class WXDLLIMPEXP_CORE wxDialog : public wxDialogBase, protected wxCocoaNSPanel -{ - DECLARE_DYNAMIC_CLASS(wxDialog) - WX_DECLARE_COCOA_OWNER(NSPanel,NSWindow,NSWindow) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxDialog() { Init(); } - - // Constructor with no modal flag - the new convention. - wxDialog(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_DIALOG_STYLE, - const wxString& name = wxDialogNameStr) - { - Init(); - Create(parent, winid, title, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_DIALOG_STYLE, - const wxString& name = wxDialogNameStr); - - virtual ~wxDialog(); -protected: - void Init(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -protected: - virtual void CocoaDelegate_windowWillClose(void); - virtual bool Cocoa_canBecomeMainWindow(bool &canBecome) - { canBecome = true; return true; } - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual bool Show(bool show = true); - - void SetModal(bool flag); - virtual bool IsModal() const { return m_isModal; } - bool m_isModal; - - // For now, same as Show(true) but returns return code - virtual int ShowModal(); - - // may be called to terminate the dialog with the given return code - virtual void EndModal(int retCode); -}; - -#endif // _WX_COCOA_DIALOG_H_ diff --git a/include/wx/cocoa/dirdlg.h b/include/wx/cocoa/dirdlg.h deleted file mode 100644 index 207f79baac..0000000000 --- a/include/wx/cocoa/dirdlg.h +++ /dev/null @@ -1,50 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/dirdlg.h -// Purpose: wxDirDialog class -// Author: Ryan Norton -// Modified by: Hiroyuki Nakamura(maloninc) -// Created: 2006-01-10 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_DIRDLG_H_ -#define _WX_COCOA_DIRDLG_H_ - -DECLARE_WXCOCOA_OBJC_CLASS(NSSavePanel); - -#define wxDirDialog wxCocoaDirDialog -//------------------------------------------------------------------------- -// wxDirDialog -//------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxDirDialog: public wxDirDialogBase -{ - DECLARE_DYNAMIC_CLASS(wxDirDialog) - wxDECLARE_NO_COPY_CLASS(wxDirDialog); -public: - wxDirDialog(wxWindow *parent, - const wxString& message = wxDirSelectorPromptStr, - const wxString& defaultPath = wxT(""), - long style = wxDD_DEFAULT_STYLE, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const wxString& name = wxDirDialogNameStr); - virtual ~wxDirDialog(); - - virtual int ShowModal(); - - inline WX_NSSavePanel GetNSSavePanel() - { return (WX_NSSavePanel)m_cocoaNSWindow; } - -protected: - wxString m_dir; - wxWindow * m_parent; - wxString m_fileName; - -private: - wxArrayString m_fileNames; -}; - -#endif // _WX_DIRDLG_H_ - diff --git a/include/wx/cocoa/drawer.h b/include/wx/cocoa/drawer.h deleted file mode 100644 index 8b13789179..0000000000 --- a/include/wx/cocoa/drawer.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/include/wx/cocoa/evtloop.h b/include/wx/cocoa/evtloop.h deleted file mode 100644 index 2196ce41e3..0000000000 --- a/include/wx/cocoa/evtloop.h +++ /dev/null @@ -1,38 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/evtloop.h -// Purpose: declaration of wxGUIEventLoop for wxCocoa -// Author: Vadim Zeitlin -// Created: 2008-12-28 -// Copyright: (c) 2008 Vadim Zeitlin -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_EVTLOOP_H_ -#define _WX_COCOA_EVTLOOP_H_ - -// ---------------------------------------------------------------------------- -// wxGUIEventLoop for wxCocoa -// ---------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase -{ -public: - wxGUIEventLoop() { m_exitcode = 0; } - - virtual void ScheduleExit(int rc = 0); - virtual bool Pending() const; - virtual bool Dispatch(); - virtual int DispatchTimeout(unsigned long timeout); - virtual void WakeUp() { } - -protected: - virtual int DoRun(); - virtual void DoYieldFor(long eventsToProcess); - - int m_exitcode; - - wxDECLARE_NO_COPY_CLASS(wxGUIEventLoop); -}; - -#endif // _WX_COCOA_EVTLOOP_H_ - diff --git a/include/wx/cocoa/filedlg.h b/include/wx/cocoa/filedlg.h deleted file mode 100644 index b888be18e7..0000000000 --- a/include/wx/cocoa/filedlg.h +++ /dev/null @@ -1,52 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/filedlg.h -// Purpose: wxFileDialog class -// Author: Ryan Norton -// Modified by: -// Created: 2004-10-02 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_FILEDLG_H_ -#define _WX_COCOA_FILEDLG_H_ - -DECLARE_WXCOCOA_OBJC_CLASS(NSSavePanel); - -#define wxFileDialog wxCocoaFileDialog -//------------------------------------------------------------------------- -// wxFileDialog -//------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxFileDialog: public wxFileDialogBase -{ - DECLARE_DYNAMIC_CLASS(wxFileDialog) - wxDECLARE_NO_COPY_CLASS(wxFileDialog); -public: - wxFileDialog(wxWindow *parent, - const wxString& message = wxFileSelectorPromptStr, - const wxString& defaultDir = wxEmptyString, - const wxString& defaultFile = wxEmptyString, - const wxString& wildCard = wxFileSelectorDefaultWildcardStr, - long style = wxFD_DEFAULT_STYLE, - const wxPoint& pos = wxDefaultPosition, - const wxSize& sz = wxDefaultSize, - const wxString& name = wxFileDialogNameStr); - virtual ~wxFileDialog(); - - virtual void SetPath(const wxString& path); - virtual void GetPaths(wxArrayString& paths) const; - virtual void GetFilenames(wxArrayString& files) const; - - virtual int ShowModal(); - - inline WX_NSSavePanel GetNSSavePanel() - { return (WX_NSSavePanel)m_cocoaNSWindow; } - -private: - WX_NSMutableArray m_wildcards; - wxArrayString m_fileNames; -}; - -#endif // _WX_FILEDLG_H_ - diff --git a/include/wx/cocoa/font.h b/include/wx/cocoa/font.h deleted file mode 100644 index 3a203c5fbb..0000000000 --- a/include/wx/cocoa/font.h +++ /dev/null @@ -1,172 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/font.h -// Purpose: wxFont class -// Author: Julian Smart -// Modified by: -// Created: 01/02/97 -// Copyright: (c) Julian Smart -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_FONT_H_ -#define _WX_FONT_H_ - -// ---------------------------------------------------------------------------- -// wxFont -// ---------------------------------------------------------------------------- - -DECLARE_WXCOCOA_OBJC_CLASS(NSFont); - -// Internal class that bridges us with code like wxSystemSettings -class wxCocoaFontFactory; -// We have c-tors/methods taking pointers of these -class wxFontRefData; - -/*! @discussion - wxCocoa's implementation of wxFont is very incomplete. In particular, - a lot of work needs to be done on wxNativeFontInfo which is currently - using the totally generic implementation. - - See the documentation in src/cocoa/font.mm for more implementatoin details. - */ -class WXDLLIMPEXP_CORE wxFont : public wxFontBase -{ - friend class wxCocoaFontFactory; -public: - /*! @abstract Default construction of invalid font for 2-step construct then Create process. - */ - wxFont() { } - - wxFont(const wxFontInfo& info) - { - Create(info.GetPointSize(), - info.GetFamily(), - info.GetStyle(), - info.GetWeight(), - info.IsUnderlined(), - info.GetFaceName(), - info.GetEncoding()); - - if ( info.IsUsingSizeInPixels() ) - SetPixelSize(info.GetPixelSize()); - } - - /*! @abstract Platform-independent construction with individual properties - */ - wxFont(int size, - wxFontFamily family, - wxFontStyle style, - wxFontWeight weight, - bool underlined = FALSE, - const wxString& face = wxEmptyString, - wxFontEncoding encoding = wxFONTENCODING_DEFAULT) - { - (void)Create(size, family, style, weight, underlined, face, encoding); - } - - wxFont(const wxSize& pixelSize, - wxFontFamily family, - wxFontStyle style, - wxFontWeight weight, - bool underlined = false, - const wxString& face = wxEmptyString, - wxFontEncoding encoding = wxFONTENCODING_DEFAULT) - { - Create(10, family, style, weight, underlined, face, encoding); - SetPixelSize(pixelSize); - } - - /*! @abstract Construction with opaque wxNativeFontInfo - */ - wxFont(const wxNativeFontInfo& info) - { - (void)Create(info); - } - - /*! @abstract Construction with platform-dependent font descriptor string. - @param fontDesc Usually the result of wxNativeFontInfo::ToUserString() - */ - wxFont(const wxString& fontDesc); - - // NOTE: Copy c-tor and assignment from wxObject is fine - - bool Create(int size, - wxFontFamily family, - wxFontStyle style, - wxFontWeight weight, - bool underlined = FALSE, - const wxString& face = wxEmptyString, - wxFontEncoding encoding = wxFONTENCODING_DEFAULT); - - bool Create(const wxNativeFontInfo& info); - - virtual ~wxFont(); - - // implement base class pure virtuals - virtual int GetPointSize() const; - virtual wxFontStyle GetStyle() const; - virtual wxFontWeight GetWeight() const; - virtual bool GetUnderlined() const; - virtual wxString GetFaceName() const; - virtual wxFontEncoding GetEncoding() const; - virtual const wxNativeFontInfo *GetNativeFontInfo() const; - - virtual void SetPointSize(int pointSize); - virtual void SetFamily(wxFontFamily family); - virtual void SetStyle(wxFontStyle style); - virtual void SetWeight(wxFontWeight weight); - virtual bool SetFaceName(const wxString& faceName); - virtual void SetUnderlined(bool underlined); - virtual void SetEncoding(wxFontEncoding encoding); - - wxDECLARE_COMMON_FONT_METHODS(); - - - wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants") - wxFont(int size, - int family, - int style, - int weight, - bool underlined = FALSE, - const wxString& face = wxEmptyString, - wxFontEncoding encoding = wxFONTENCODING_DEFAULT) - { - (void)Create(size, (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding); - } - - // implementation only from now on - // ------------------------------- - - /*! @abstract Defined on some ports (not including this one) in wxGDIObject - @discussion - The intention here I suppose is to allow one to create a wxFont without yet - creating the underlying native object. There's no point not to create the - NSFont immediately in wxCocoa so this is useless. - This method came from the stub code copied in the early days of wxCocoa. - FIXME(1): Remove this in trunk. FIXME(2): Is it really a good idea for this to - be part of the public API for wxGDIObject? - */ - virtual bool RealizeResource(); - -protected: - /*! @abstract Internal constructor with ref data - @discussion - Takes ownership of @a refData. That is, it is assumed that refData has either just been - created using new (which initializes its m_refCount to 1) or if you are sharing a ref that - you have called IncRef on it before passing it to this method. - */ - explicit wxFont(wxFontRefData *refData) - { Create(refData); } - bool Create(wxFontRefData *refData); - - virtual wxGDIRefData *CreateGDIRefData() const; - virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; - - virtual wxFontFamily DoGetFamily() const; - -private: - DECLARE_DYNAMIC_CLASS(wxFont) -}; - -#endif - // _WX_FONT_H_ diff --git a/include/wx/cocoa/fontdlg.h b/include/wx/cocoa/fontdlg.h deleted file mode 100644 index 8b13789179..0000000000 --- a/include/wx/cocoa/fontdlg.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/include/wx/cocoa/frame.h b/include/wx/cocoa/frame.h deleted file mode 100644 index ebdb56ed34..0000000000 --- a/include/wx/cocoa/frame.h +++ /dev/null @@ -1,106 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/frame.h -// Purpose: wxFrame class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_FRAME_H_ -#define _WX_COCOA_FRAME_H_ - -class WXDLLIMPEXP_FWD_CORE wxMenuBar; -class WXDLLIMPEXP_FWD_CORE wxStatusBar; - -class WXDLLIMPEXP_CORE wxFrame: public wxFrameBase -{ - DECLARE_EVENT_TABLE() - DECLARE_DYNAMIC_CLASS(wxFrame) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxFrame() { Init(); } - wxFrame(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr) - { - Init(); - Create(parent, winid, title, pos, size, style, name); - } - - virtual ~wxFrame(); - - bool Create(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr); -protected: - void Init(); -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - virtual wxMenuBar* GetAppMenuBar(wxCocoaNSWindow *win); - // Returns the NSView for non-client drawing - virtual WX_NSView GetNonClientNSView(); - - // Helper function to position status/tool bars - // Also called by native toolbar to force a size update - void UpdateFrameNSView(); - - virtual void CocoaDelegate_wxMenuItemAction(WX_NSMenuItem menuItem); - virtual bool CocoaDelegate_validateMenuItem(WX_NSMenuItem menuItem); -protected: - virtual void CocoaSetWxWindowSize(int width, int height); - - virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView); - // frameNSView is used whenever a statusbar/generic toolbar are present - WX_NSView m_frameNSView; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void AttachMenuBar(wxMenuBar *mbar); - virtual void DetachMenuBar(); - virtual void SetMenuBar(wxMenuBar *menubar); - - // implementation only from now on - // ------------------------------- - - // override some more virtuals - - // get the origin of the client area (which may be different from (0, 0) - // if the frame has a toolbar) in client coordinates - virtual wxPoint GetClientAreaOrigin() const; - - // create the main status bar by calling OnCreateStatusBar() - virtual wxStatusBar* CreateStatusBar(int number = 1, - long style = wxSTB_DEFAULT_STYLE, - wxWindowID winid = 0, - const wxString& name = - wxStatusLineNameStr); - // sets the main status bar - void SetStatusBar(wxStatusBar *statBar); -#if wxUSE_TOOLBAR - // create main toolbar bycalling OnCreateToolBar() - virtual wxToolBar* CreateToolBar(long style = -1, - wxWindowID winid = wxID_ANY, - const wxString& name = wxToolBarNameStr); - // sets the main tool bar - virtual void SetToolBar(wxToolBar *toolbar); -#endif //wxUSE_TOOLBAR -protected: - void PositionStatusBar(); -}; - -#endif // _WX_COCOA_FRAME_H_ diff --git a/include/wx/cocoa/gauge.h b/include/wx/cocoa/gauge.h deleted file mode 100644 index ffadb1c27b..0000000000 --- a/include/wx/cocoa/gauge.h +++ /dev/null @@ -1,73 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/gauge.h -// Purpose: wxGauge class -// Author: David Elliott -// Modified by: -// Created: 2003/07/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_GAUGE_H__ -#define __WX_COCOA_GAUGE_H__ - -// #include "wx/cocoa/NSProgressIndicator.h" - -DECLARE_WXCOCOA_OBJC_CLASS(NSProgressIndicator); - -// ======================================================================== -// wxGauge -// ======================================================================== -class WXDLLIMPEXP_CORE wxGauge: public wxGaugeBase// , protected wxCocoaNSProgressIndicator -{ - DECLARE_DYNAMIC_CLASS(wxGauge) - DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSProgressIndicator,NSView,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxGauge() { } - wxGauge(wxWindow *parent, wxWindowID winid, int range, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxGA_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxGaugeNameStr) - { - Create(parent, winid, range, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, int range, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxGA_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxGaugeNameStr); - virtual ~wxGauge(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -public: - inline WX_NSProgressIndicator GetNSProgressIndicator() const { return (WX_NSProgressIndicator)m_cocoaNSView; } -protected: - // NSProgressIndicator cannot be enabled/disabled - virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { } -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // Pure Virtuals - virtual int GetValue() const; - virtual void SetValue(int value); - - // retrieve/change the range - virtual void SetRange(int maxValue); - int GetRange(void) const; -protected: - virtual wxSize DoGetBestSize() const; -}; - -#endif - // __WX_COCOA_GAUGE_H__ diff --git a/include/wx/cocoa/glcanvas.h b/include/wx/cocoa/glcanvas.h deleted file mode 100644 index 927c3e05ee..0000000000 --- a/include/wx/cocoa/glcanvas.h +++ /dev/null @@ -1,97 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/glcanvas.h -// Purpose: wxGLCanvas class -// Author: David Elliott -// Modified by: -// Created: 2004/09/29 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_GLCANVAS_H__ -#define _WX_COCOA_GLCANVAS_H__ - -#include "wx/window.h" - -// #include "wx/cocoa/NSOpenGLView.h" -// Include gl.h from the OpenGL framework -#include - -class WXDLLIMPEXP_FWD_GL wxGLCanvas; -DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLContext); -DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLView); - -// ======================================================================== -// wxGLContext -// ======================================================================== - -class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase -{ -public: - wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL); - - virtual ~wxGLContext(); - - virtual void SetCurrent(const wxGLCanvas& win) const; - - WX_NSOpenGLContext GetNSOpenGLContext() const - { return m_cocoaNSOpenGLContext; } - -private: - WX_NSOpenGLContext m_cocoaNSOpenGLContext; -}; - -// ======================================================================== -// wxGLCanvas -// ======================================================================== - -class WXDLLIMPEXP_GL wxGLCanvas : public wxGLCanvasBase - // , protected wxCocoaNSOpenGLView -{ - DECLARE_DYNAMIC_CLASS(wxGLCanvas) -// WX_DECLARE_COCOA_OWNER(NSOpenGLView,NSView,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxGLCanvas(wxWindow *parent, - wxWindowID id = wxID_ANY, - const int *attribList = NULL, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxGLCanvasName, - const wxPalette& palette = wxNullPalette) - { - Create(parent, id, pos, size, style, name, attribList, palette); - } - - bool Create(wxWindow *parent, - wxWindowID id = wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxGLCanvasName, - const int *attribList = NULL, - const wxPalette& palette = wxNullPalette); - - virtual ~wxGLCanvas(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - // NSOpenGLView cannot be enabled/disabled - virtual void CocoaSetEnabled(bool enable) { } -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void SwapBuffers(); - - - NSOpenGLView *GetNSOpenGLView() const - { return (NSOpenGLView *)m_cocoaNSView; } -}; - -#endif //ndef _WX_COCOA_GLCANVAS_H__ diff --git a/include/wx/cocoa/icon.h b/include/wx/cocoa/icon.h deleted file mode 100644 index ac041ba354..0000000000 --- a/include/wx/cocoa/icon.h +++ /dev/null @@ -1,63 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/icon.h -// Purpose: wxIcon class -// Author: David Elliott -// Modified by: -// Created: 2003/08/11 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_ICON_H__ -#define _WX_COCOA_ICON_H__ - -#include "wx/gdicmn.h" -#include "wx/gdiobj.h" - -// ======================================================================== -// wxIcon -// ======================================================================== -class WXDLLIMPEXP_CORE wxIcon : public wxGDIObject -{ -public: - wxIcon(); - - wxIcon(const char* const* data) { CreateFromXpm(data); } - wxIcon(const char bits[], int width , int height ); - wxIcon(const wxString& name, int flags = wxICON_DEFAULT_TYPE, - int desiredWidth = -1, int desiredHeight = -1); - wxIcon(const wxIconLocation& loc) - { - LoadFile(loc.GetFileName(), wxBITMAP_TYPE_ICON); - } - virtual ~wxIcon(); - - bool LoadFile(const wxString& name, wxBitmapType flags = wxICON_DEFAULT_TYPE, - int desiredWidth=-1, int desiredHeight=-1); - - bool operator==(const wxIcon& icon) const - { return m_refData == icon.m_refData; } - bool operator!=(const wxIcon& icon) const { return !(*this == icon); } - - // create from bitmap (which should have a mask unless it's monochrome): - // there shouldn't be any implicit bitmap -> icon conversion (i.e. no - // ctors, assignment operators...), but it's ok to have such function - void CopyFromBitmap(const wxBitmap& bmp); - - int GetWidth() const; - int GetHeight() const; - - wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); } - - WX_NSImage GetNSImage() const; - bool CreateFromXpm(const char* const* bits); - -protected: - virtual wxGDIRefData *CreateGDIRefData() const; - virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; - -private: - DECLARE_DYNAMIC_CLASS(wxIcon) -}; - -#endif // _WX_COCOA_ICON_H__ diff --git a/include/wx/cocoa/listbox.h b/include/wx/cocoa/listbox.h deleted file mode 100644 index a9f233aa8a..0000000000 --- a/include/wx/cocoa/listbox.h +++ /dev/null @@ -1,114 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/listbox.h -// Purpose: wxListBox class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_LISTBOX_H__ -#define __WX_COCOA_LISTBOX_H__ - -#include "wx/cocoa/NSTableView.h" - -#include "wx/dynarray.h" - -// ======================================================================== -// wxListBox -// ======================================================================== -class WXDLLIMPEXP_CORE wxListBox: public wxListBoxBase, protected wxCocoaNSTableView -{ - DECLARE_DYNAMIC_CLASS(wxListBox) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSTableView,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxListBox() { m_cocoaItems = NULL; m_cocoaDataSource = NULL; } - wxListBox(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr) - { - Create(parent, winid, pos, size, n, choices, style, validator, name); - } - wxListBox(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr) - { - Create(parent, winid, pos, size, choices, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr); - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxListBoxNameStr); - virtual ~wxListBox(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual int CocoaDataSource_numberOfRows(); - virtual struct objc_object* CocoaDataSource_objectForTableColumn( - WX_NSTableColumn tableColumn, int rowIndex); - WX_NSMutableArray m_cocoaItems; - wxArrayPtrVoid m_itemClientData; - struct objc_object *m_cocoaDataSource; - bool m_needsUpdate; - inline bool _WxCocoa_GetNeedsUpdate(); - inline void _WxCocoa_SetNeedsUpdate(bool needsUpdate); - virtual void OnInternalIdle(); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual wxSize DoGetBestSize() const; -// pure virtuals from wxListBoxBase - virtual bool IsSelected(int n) const; - virtual int GetSelections(wxArrayInt& aSelections) const; -protected: - virtual void DoSetFirstItem(int n); - virtual void DoSetSelection(int n, bool select); - -// pure virtuals from wxItemContainer -public: - // deleting items - virtual void DoClear(); - virtual void DoDeleteOneItem(unsigned int n); - // accessing strings - virtual unsigned int GetCount() const; - virtual wxString GetString(unsigned int n) const; - virtual void SetString(unsigned int n, const wxString& s); - virtual int FindString(const wxString& s, bool bCase = false) const; - // selection - virtual int GetSelection() const; -protected: - virtual int DoInsertItems(const wxArrayStringsAdapter& items, - unsigned int pos, - void **clientData, wxClientDataType type); - virtual void DoSetItemClientData(unsigned int n, void* clientData); - virtual void* DoGetItemClientData(unsigned int n) const; -}; - -#endif // __WX_COCOA_LISTBOX_H__ diff --git a/include/wx/cocoa/log.h b/include/wx/cocoa/log.h deleted file mode 100644 index 82f9319a48..0000000000 --- a/include/wx/cocoa/log.h +++ /dev/null @@ -1,21 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/log.h -// Purpose: Declare wxCocoa-specific trace masks -// Author: David Elliott -// Modified by: -// Created: 2004/02/07 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_LOG_H__ -#define _WX_COCOA_LOG_H__ - -// General tracing (in lieu of wxLogDebug) -#define wxTRACE_COCOA wxT("COCOA") -// Specific tracing -#define wxTRACE_COCOA_RetainRelease wxT("COCOA_RetainRelease") -#define wxTRACE_COCOA_TopLevelWindow_Size wxT("COCOA_TopLevelWindow_Size") -#define wxTRACE_COCOA_Window_Size wxT("COCOA_Window_Size") - -#endif //ndef _WX_COCOA_LOG_H__ diff --git a/include/wx/cocoa/mbarman.h b/include/wx/cocoa/mbarman.h deleted file mode 100644 index 0223cb5c74..0000000000 --- a/include/wx/cocoa/mbarman.h +++ /dev/null @@ -1,70 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/mbarman.h -// Purpose: wxMenuBarManager class -// Author: David Elliott -// Modified by: -// Created: 2003/09/04 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_MBARMAN_H__ -#define __WX_COCOA_MBARMAN_H__ - -#if wxUSE_MENUS - -#include "wx/toplevel.h" - -DECLARE_WXCOCOA_OBJC_CLASS(wxMenuBarManagerObserver); - -// ======================================================================== -// wxMenuBarManager -// ======================================================================== -class WXDLLIMPEXP_CORE wxMenuBarManager : public wxObject -{ -// ------------------------------------------------------------------------ -// initialization/destruction -// ------------------------------------------------------------------------ -public: - wxMenuBarManager(); - virtual ~wxMenuBarManager(); -// ------------------------------------------------------------------------ -// Single instance -// ------------------------------------------------------------------------ -public: - static wxMenuBarManager *GetInstance() { return sm_mbarmanInstance; } - static void CreateInstance(); - static void DestroyInstance(); -protected: - static wxMenuBarManager *sm_mbarmanInstance; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - void SetMainMenuBar(wxMenuBar* menubar); - void WindowDidBecomeKey(NSNotification *notification); -#if 0 - void WindowDidResignKey(NSNotification *notification); - void WindowDidBecomeMain(NSNotification *notification); - void WindowDidResignMain(NSNotification *notification); - void WindowWillClose(NSNotification *notification); -#endif // 0 - void UpdateMenuBar(); -protected: - void SetMenuBar(wxMenuBar* menubar); - void InstallMenuBarForWindow(wxCocoaNSWindow *win); - void InstallMainMenu(); - WX_NSMenu m_menuApp; - WX_NSMenu m_menuServices; - WX_NSMenu m_menuWindows; - WX_NSMenu m_menuMain; - // Is main menu bar the current one - bool m_mainMenuBarInstalled; - // Main menu (if app provides one) - wxMenuBar *m_mainMenuBar; - wxMenuBarManagerObserver *m_observer; - WX_NSWindow m_currentNSWindow; -}; - -#endif // wxUSE_MENUS -#endif // _WX_COCOA_MBARMAN_H_ diff --git a/include/wx/cocoa/mdi.h b/include/wx/cocoa/mdi.h deleted file mode 100644 index 6cef55caf2..0000000000 --- a/include/wx/cocoa/mdi.h +++ /dev/null @@ -1,163 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/mdi.h -// Purpose: wxMDIParentFrame, wxMDIChildFrame, wxMDIClientWindow -// Author: David Elliott -// Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes -// Created: 2003/09/08 -// Copyright: (c) 2003 David Elliott -// (c) 2008 Vadim Zeitlin -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_MDI_H__ -#define __WX_COCOA_MDI_H__ - -#include "wx/frame.h" - -DECLARE_WXCOCOA_OBJC_CLASS(wxMDIParentFrameObserver); - -class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame; -class WXDLLIMPEXP_FWD_CORE wxMDIClientWindow; - -WX_DECLARE_EXPORTED_LIST(wxMDIChildFrame, wxCocoaMDIChildFrameList); - -// ======================================================================== -// wxMDIParentFrame -// ======================================================================== -class WXDLLIMPEXP_CORE wxMDIParentFrame : public wxMDIParentFrameBase -{ - friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame; - DECLARE_EVENT_TABLE() - DECLARE_DYNAMIC_CLASS(wxMDIParentFrame) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxMDIParentFrame() { Init(); } - wxMDIParentFrame(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr) - { - Init(); - Create(parent, winid, title, pos, size, style, name); - } - - virtual ~wxMDIParentFrame(); - - bool Create(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr); -protected: - void Init(); -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - void WindowDidBecomeMain(NSNotification *notification); -protected: - virtual void CocoaDelegate_windowDidBecomeKey(void); - virtual void CocoaDelegate_windowDidResignKey(void); - virtual bool Cocoa_canBecomeMainWindow(bool &canBecome); - virtual wxMenuBar* GetAppMenuBar(wxCocoaNSWindow *win); - - void AddMDIChild(wxMDIChildFrame *child); - void RemoveMDIChild(wxMDIChildFrame *child); - - wxMDIParentFrameObserver *m_observer; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - void SetActiveChild(wxMDIChildFrame *child); - - // implement base class pure virtuals - // ---------------------------------- - - static bool IsTDI() { return false; } - - virtual void ActivateNext() { /* TODO */ } - virtual void ActivatePrevious() { /* TODO */ } - -protected: - wxMDIClientWindow *m_clientWindow; - wxMDIChildFrame *m_currentChild; - wxCocoaMDIChildFrameList m_mdiChildren; -}; - -// ======================================================================== -// wxMDIChildFrame -// ======================================================================== -class WXDLLIMPEXP_CORE wxMDIChildFrame: public wxFrame -{ - friend class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame; - DECLARE_EVENT_TABLE() - DECLARE_DYNAMIC_CLASS(wxMDIChildFrame) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxMDIChildFrame() { Init(); } - wxMDIChildFrame(wxMDIParentFrame *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr) - { - Init(); - Create(parent, winid, title, pos, size, style, name); - } - - virtual ~wxMDIChildFrame(); - - bool Create(wxMDIParentFrame *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr); -protected: - void Init(); -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: -protected: - virtual void CocoaDelegate_windowDidBecomeKey(void); - virtual void CocoaDelegate_windowDidBecomeMain(void); - virtual void CocoaDelegate_windowDidResignKey(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void Activate(); - virtual bool Destroy(); -protected: - wxMDIParentFrame *m_mdiParent; -}; - -// ======================================================================== -// wxMDIClientWindow -// ======================================================================== -class wxMDIClientWindow : public wxMDIClientWindowBase -{ -public: - wxMDIClientWindow() { } - - virtual bool CreateClient(wxMDIParentFrame *parent, - long style = wxHSCROLL | wxVSCROLL); - - DECLARE_DYNAMIC_CLASS(wxMDIClientWindow) -}; - -#endif // __WX_COCOA_MDI_H__ diff --git a/include/wx/cocoa/menu.h b/include/wx/cocoa/menu.h deleted file mode 100644 index 0cb304126f..0000000000 --- a/include/wx/cocoa/menu.h +++ /dev/null @@ -1,185 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/menu.h -// Purpose: wxMenu and wxMenuBar classes -// Author: David Elliott -// Modified by: -// Created: 2002/12/09 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_MENU_H__ -#define __WX_COCOA_MENU_H__ - -#include "wx/cocoa/NSMenu.h" - -#if wxUSE_ACCEL - #include "wx/accel.h" -#endif // wxUSE_ACCEL - -// ======================================================================== -// wxMenu -// ======================================================================== - -class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase, public wxCocoaNSMenu -{ -public: - // ctors and dtor - wxMenu(const wxString& title, long style = 0) - : wxMenuBase(title, style) - , m_cocoaDeletes(false) - { Create(title,style); } - bool Create(const wxString& title, long style = 0); - - wxMenu(long style = 0) : wxMenuBase(style) { Create(wxEmptyString, style); } - - virtual ~wxMenu(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - inline WX_NSMenu GetNSMenu() { return m_cocoaNSMenu; } - void SetCocoaDeletes(bool cocoaDeletes); - virtual void Cocoa_dealloc(); -protected: - WX_NSMenu m_cocoaNSMenu; - bool m_cocoaDeletes; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -protected: - // implement base class virtuals - virtual wxMenuItem* DoAppend(wxMenuItem *item); - virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); - virtual wxMenuItem* DoRemove(wxMenuItem *item); - -#if wxUSE_ACCEL - // add/remove accel for the given menu item - void AddAccelFor(wxMenuItem *item); - void RemoveAccelFor(wxMenuItem *item); -#endif // wxUSE_ACCEL - -private: -#if wxUSE_ACCEL - // the accel table for this menu - wxAcceleratorTable m_accelTable; -#endif // wxUSE_ACCEL - - DECLARE_DYNAMIC_CLASS(wxMenu) -}; - -// ======================================================================== -// wxMenuBar -// ======================================================================== -class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase -{ -public: - // ctors and dtor - wxMenuBar(long style = 0) { Create(style); } - wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); - bool Create(long style = 0); - virtual ~wxMenuBar(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - inline WX_NSMenu GetNSMenu() { return m_cocoaNSMenu; } -protected: - WX_NSMenu m_cocoaNSMenu; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // implement base class virtuals - virtual bool Append(wxMenu *menu, const wxString &title); - virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); - virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); - virtual wxMenu *Remove(size_t pos); - - virtual void EnableTop(size_t pos, bool enable); - virtual bool IsEnabledTop(size_t pos) const; - - virtual void SetMenuLabel(size_t pos, const wxString& label); - virtual wxString GetMenuLabel(size_t pos) const; - - virtual void Attach(wxFrame *frame); - virtual void Detach(); - - // get the next item for the givan accel letter (used by wxFrame), return - // -1 if none - // - // if unique is not NULL, filled with TRUE if there is only one item with - // this accel, FALSE if two or more - int FindNextItemForAccel(int idxStart, - int keycode, - bool *unique = NULL) const; - - // called by wxFrame to set focus to or open the given menu - void SelectMenu(size_t pos); - -#if wxUSE_ACCEL - // find the item for the given accel and generate an event if found - bool ProcessAccelEvent(const wxKeyEvent& event); -#endif // wxUSE_ACCEL - -protected: - // event handlers - void OnLeftDown(wxMouseEvent& event); - void OnMouseMove(wxMouseEvent& event); - void OnKeyDown(wxKeyEvent& event); - void OnKillFocus(wxFocusEvent& event); - - // process the mouse move event, return TRUE if we did, FALSE to continue - // processing as usual - // - // the coordinates are client coordinates of menubar, convert if necessary - bool ProcessMouseEvent(const wxPoint& pt); - - // menubar geometry - virtual wxSize DoGetBestClientSize() const; - - // has the menubar been created already? - bool IsCreated() const { return m_frameLast != NULL; } - - // get the (total) width of the specified menu - wxCoord GetItemWidth(size_t pos) const; - - // get the rect of the item - wxRect GetItemRect(size_t pos) const; - - // get the menu from the given point or -1 if none - int GetMenuFromPoint(const wxPoint& pos) const; - - // refresh the given item - void RefreshItem(size_t pos); - - // refresh all items after this one (including it) - void RefreshAllItemsAfter(size_t pos); - - // do we show a menu currently? - bool IsShowingMenu() const { return m_menuShown != 0; } - - // we don't want to have focus except while selecting from menu - void GiveAwayFocus(); - - // the current item (only used when menubar has focus) - int m_current; - -private: - // the last frame to which we were attached, NULL initially - wxFrame *m_frameLast; - - // the currently shown menu or NULL - wxMenu *m_menuShown; - - // should be showing the menu? this is subtly different from m_menuShown != - // NULL as the menu which should be shown may be disabled in which case we - // don't show it - but will do as soon as the focus shifts to another menu - bool m_shouldShowMenu; - - DECLARE_DYNAMIC_CLASS(wxMenuBar) -}; - -#endif // _WX_COCOA_MENU_H_ diff --git a/include/wx/cocoa/menuitem.h b/include/wx/cocoa/menuitem.h deleted file mode 100644 index 23983171bb..0000000000 --- a/include/wx/cocoa/menuitem.h +++ /dev/null @@ -1,99 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/menuitem.h -// Purpose: wxMenuItem class -// Author: David Elliott -// Modified by: -// Created: 2002/12/13 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_MENUITEM_H_ -#define _WX_COCOA_MENUITEM_H_ - -#include "wx/hashmap.h" -#include "wx/bitmap.h" - -#include "wx/cocoa/ObjcRef.h" - -// ======================================================================== -// wxMenuItem -// ======================================================================== - -#define wxMenuItemCocoa wxMenuItem -class wxMenuItemCocoa; -WX_DECLARE_HASH_MAP(WX_NSMenuItem,wxMenuItem*,wxPointerHash,wxPointerEqual,wxMenuItemCocoaHash); - -class WXDLLIMPEXP_CORE wxMenuItemCocoa : public wxMenuItemBase -{ -public: -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ - wxMenuItemCocoa(wxMenu *parentMenu = NULL, - int id = wxID_SEPARATOR, - const wxString& name = wxEmptyString, - const wxString& help = wxEmptyString, - wxItemKind kind = wxITEM_NORMAL, - wxMenu *subMenu = NULL); - virtual ~wxMenuItemCocoa(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - inline WX_NSMenuItem GetNSMenuItem() { return m_cocoaNSMenuItem; } - static inline wxMenuItem* GetFromCocoa(WX_NSMenuItem cocoaNSMenuItem) - { - wxMenuItemCocoaHash::iterator iter=sm_cocoaHash.find(cocoaNSMenuItem); - if(iter!=sm_cocoaHash.end()) - return iter->second; - return NULL; - } - void CocoaItemSelected(); - bool Cocoa_validateMenuItem(); -protected: - void CocoaSetKeyEquivalent(); - WX_NSMenuItem m_cocoaNSMenuItem; - static wxMenuItemCocoaHash sm_cocoaHash; - static wxObjcAutoRefFromAlloc sm_cocoaTarget; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // override base class virtuals to update the item appearance on screen - virtual void SetItemLabel(const wxString& text); - virtual void SetCheckable(bool checkable); - - virtual void Enable(bool enable = TRUE); - virtual void Check(bool check = TRUE); - - // we add some extra functions which are also available under MSW from - // wxOwnerDrawn class - they will be moved to wxMenuItemBase later - // hopefully - void SetBitmaps(const wxBitmap& bmpChecked, - const wxBitmap& bmpUnchecked = wxNullBitmap); - void SetBitmap(const wxBitmap& bmp) { SetBitmaps(bmp); } - const wxBitmap& GetBitmap(bool checked = TRUE) const - { return checked ? m_bmpChecked : m_bmpUnchecked; } - -protected: - // notify the menu about the change in this item - inline void NotifyMenu(); - - // set the accel index and string from text - void UpdateAccelInfo(); - - // the bitmaps (may be invalid, then they're not used) - wxBitmap m_bmpChecked, - m_bmpUnchecked; - - // the accel string (i.e. "Ctrl-Q" or "Alt-F1") - wxString m_strAccel; - -private: - DECLARE_DYNAMIC_CLASS(wxMenuItem) -}; - -#endif // _WX_COCOA_MENUITEM_H_ - diff --git a/include/wx/cocoa/msgdlg.h b/include/wx/cocoa/msgdlg.h deleted file mode 100644 index 4a313c44af..0000000000 --- a/include/wx/cocoa/msgdlg.h +++ /dev/null @@ -1,70 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/msgdlg.h -// Purpose: wxMessageDialog class -// Author: Gareth Simpson -// Created: 2007-10-29 -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_MSGDLG_H_ -#define _WX_COCOA_MSGDLG_H_ - -#include "wx/msgdlg.h" - -DECLARE_WXCOCOA_OBJC_CLASS(NSAlert); - -#ifndef wxUSE_COCOA_NATIVE_MSGDLG -// trunk: Always use Cocoa dialog -// 2.8: Only use Cocoa dialog if ABI incompatible features is on -// Build both on both branches (there was no wxCocoaMessageDialog class so it's not an ABI issue) - #if 1/* wxUSE_ABI_INCOMPATIBLE_FEATURES */ - #define wxUSE_COCOA_NATIVE_MSGDLG 1 - #else - #define wxUSE_COCOA_NATIVE_MSGDLG 0 - #endif -#endif - -#if wxUSE_COCOA_NATIVE_MSGDLG - #define wxMessageDialog wxCocoaMessageDialog -#else - #include "wx/generic/msgdlgg.h" - - #define wxMessageDialog wxGenericMessageDialog -#endif - -// ---------------------------------------------------------------------------- -// wxCocoaMessageDialog -// ---------------------------------------------------------------------------- - - -class WXDLLIMPEXP_CORE wxCocoaMessageDialog - : public wxMessageDialogWithCustomLabels -{ -public: - wxCocoaMessageDialog(wxWindow *parent, - const wxString& message, - const wxString& caption = wxMessageBoxCaptionStr, - long style = wxOK|wxCENTRE, - const wxPoint& pos = wxDefaultPosition); - - virtual int ShowModal(); - -protected: - // not supported for message dialog - virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y), - int WXUNUSED(width), int WXUNUSED(height), - int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {} - - // override wxMessageDialogWithCustomLabels method to get rid of - // accelerators in the custom label strings - // - // VZ: I have no idea _why_ do we do this but the old version did and - // I didn't want to change the existing behaviour - virtual void DoSetCustomLabel(wxString& var, const ButtonLabel& label); - - DECLARE_DYNAMIC_CLASS(wxCocoaMessageDialog) - wxDECLARE_NO_COPY_CLASS(wxCocoaMessageDialog); -}; - -#endif // _WX_MSGDLG_H_ - diff --git a/include/wx/cocoa/notebook.h b/include/wx/cocoa/notebook.h deleted file mode 100644 index 0fe99e91a1..0000000000 --- a/include/wx/cocoa/notebook.h +++ /dev/null @@ -1,104 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/notebook.h -// Purpose: wxNotebook class -// Author: David Elliott -// Modified by: -// Created: 2004/04/08 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_NOTEBOOK_H__ -#define _WX_COCOA_NOTEBOOK_H__ - -#include "wx/cocoa/NSTabView.h" - -// ======================================================================== -// wxNotebook -// ======================================================================== -class WXDLLIMPEXP_CORE wxNotebook: public wxNotebookBase, protected wxCocoaNSTabView -{ - DECLARE_DYNAMIC_CLASS(wxNotebook) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSTabView,NSView,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxNotebook() { } - wxNotebook(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxNotebookNameStr) - { - Create(parent, winid, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxNotebookNameStr); - virtual ~wxNotebook(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - // Notebooks cannot be enabled/disabled - virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { } - virtual void CocoaDelegate_tabView_didSelectTabViewItem(WX_NSTabViewItem tabviewItem); - virtual bool CocoaDelegate_tabView_shouldSelectTabViewItem(WX_NSTabViewItem tabviewItem); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // set the currently selected page, return the index of the previously - // selected one (or wxNOT_FOUND on error) - int SetSelection(size_t nPage); - // get the currently selected page - int GetSelection() const; - - // changes selected page without sending events - int ChangeSelection(size_t nPage); - - // set/get the title of a page - bool SetPageText(size_t nPage, const wxString& strText); - wxString GetPageText(size_t nPage) const; - - // sets/returns item's image index in the current image list - int GetPageImage(size_t nPage) const; - bool SetPageImage(size_t nPage, int nImage); - - // set the size (the same for all pages) - void SetPageSize(const wxSize& size); - - // SetPadding and SetTabSize aren't possible to implement - void SetPadding(const wxSize& padding); - void SetTabSize(const wxSize& sz); - - //----------------------- - // adding/removing pages - - // remove one page from the notebook, without deleting - virtual wxNotebookPage *DoRemovePage(size_t nPage); - - // remove one page from the notebook - bool DeletePage(size_t nPage); - // remove all pages - bool DeleteAllPages(); - - // adds a new page to the notebook (it will be deleted ny the notebook, - // don't delete it yourself). If bSelect, this page becomes active. - // the same as AddPage(), but adds it at the specified position - bool InsertPage( size_t position, - wxNotebookPage *win, - const wxString& strText, - bool bSelect = false, - int imageId = NO_IMAGE ); - -protected: -}; - -#endif //ndef _WX_COCOA_NOTEBOOK_H__ diff --git a/include/wx/cocoa/objc/NSMenu.h b/include/wx/cocoa/objc/NSMenu.h deleted file mode 100644 index 780d306058..0000000000 --- a/include/wx/cocoa/objc/NSMenu.h +++ /dev/null @@ -1,30 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/objc/NSMenu.h -// Purpose: WXNSMenu class -// Author: David Elliott -// Modified by: -// Created: 2007/04/20 (move from NSMenu.mm) -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_OBJC_NSMENU_H__ -#define __WX_COCOA_OBJC_NSMENU_H__ - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import - -// ============================================================================ -// @class WXNSMenu -// ============================================================================ -@interface WXNSMenu : NSMenu -{ -} - -- (void)dealloc; - -@end // WXNSMenu -WX_DECLARE_GET_OBJC_CLASS(WXNSMenu,NSMenu) - -#endif //ndef __WX_COCOA_OBJC_NSMENU_H__ diff --git a/include/wx/cocoa/objc/NSSlider.h b/include/wx/cocoa/objc/NSSlider.h deleted file mode 100644 index 3534d8576f..0000000000 --- a/include/wx/cocoa/objc/NSSlider.h +++ /dev/null @@ -1,36 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/objc/NSSlider.h -// Purpose: WXNSSlider class -// Author: David Elliott -// Modified by: -// Created: 2007/08/10 (move from NSSlider.mm) -// Copyright: (c) 2007 Software 2000 Ltd. -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_OBJC_NSSLIDER_H__ -#define __WX_COCOA_OBJC_NSSLIDER_H__ - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import - -// ============================================================================ -// @class WXNSSlider -// ============================================================================ - -@interface WXNSSlider : NSSlider -@end - -WX_DECLARE_GET_OBJC_CLASS(WXNSSlider,NSSlider) - -// ============================================================================ -// @class WXNSSliderCell -// ============================================================================ - -@interface WXNSSliderCell : NSSliderCell -@end - -WX_DECLARE_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell) - -#endif //ndef __WX_COCOA_OBJC_NSSLIDER_H__ diff --git a/include/wx/cocoa/objc/NSView.h b/include/wx/cocoa/objc/NSView.h deleted file mode 100644 index f4c5f04ebf..0000000000 --- a/include/wx/cocoa/objc/NSView.h +++ /dev/null @@ -1,44 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/objc/NSView.h -// Purpose: WXNSView class -// Author: David Elliott -// Modified by: -// Created: 2007/04/20 (move from NSView.mm) -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_OBJC_NSVIEW_H__ -#define __WX_COCOA_OBJC_NSVIEW_H__ - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import - -// ============================================================================ -// @class WXNSView -// ============================================================================ -@interface WXNSView : NSView -{ -} - -- (void)drawRect: (NSRect)rect; -- (void)mouseDown:(NSEvent *)theEvent; -- (void)mouseDragged:(NSEvent *)theEvent; -- (void)mouseUp:(NSEvent *)theEvent; -- (void)mouseMoved:(NSEvent *)theEvent; -- (void)mouseEntered:(NSEvent *)theEvent; -- (void)mouseExited:(NSEvent *)theEvent; -- (void)rightMouseDown:(NSEvent *)theEvent; -- (void)rightMouseDragged:(NSEvent *)theEvent; -- (void)rightMouseUp:(NSEvent *)theEvent; -- (void)otherMouseDown:(NSEvent *)theEvent; -- (void)otherMouseDragged:(NSEvent *)theEvent; -- (void)otherMouseUp:(NSEvent *)theEvent; -- (void)resetCursorRects; -- (void)viewDidMoveToWindow; -- (void)viewWillMoveToWindow:(NSWindow *)newWindow; -@end // WXNSView -WX_DECLARE_GET_OBJC_CLASS(WXNSView,NSView) - -#endif //ndef __WX_COCOA_OBJC_NSVIEW_H__ diff --git a/include/wx/cocoa/objc/NSWindow.h b/include/wx/cocoa/objc/NSWindow.h deleted file mode 100644 index bed9e59838..0000000000 --- a/include/wx/cocoa/objc/NSWindow.h +++ /dev/null @@ -1,39 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/objc/NSWindow.h -// Purpose: WXNSWindow class -// Author: David Elliott -// Modified by: -// Created: 2007/04/20 (move from NSWindow.mm) -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#import -#import - -#include "wx/cocoa/objc/objc_uniquifying.h" - -// ============================================================================ -// @class WXNSWindow -// ============================================================================ -@interface WXNSWindow : NSWindow -{ -} - -- (BOOL)canBecomeKeyWindow; -- (BOOL)canBecomeMainWindow; -@end // WXNSWindow -WX_DECLARE_GET_OBJC_CLASS(WXNSWindow,NSWindow) - -// ============================================================================ -// @class WXNSPanel -// ============================================================================ -@interface WXNSPanel : NSPanel -{ -} - -- (BOOL)canBecomeKeyWindow; -- (BOOL)canBecomeMainWindow; -@end // WXNSPanel -WX_DECLARE_GET_OBJC_CLASS(WXNSPanel,NSPanel) - diff --git a/include/wx/cocoa/objc/objc_uniquifying.h b/include/wx/cocoa/objc/objc_uniquifying.h deleted file mode 100644 index bedbf44677..0000000000 --- a/include/wx/cocoa/objc/objc_uniquifying.h +++ /dev/null @@ -1,364 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/objc/objc_uniquifying.h -// Purpose: Allows wxWidgets code to get a direct pointer to a compiled -// Objective-C class and provides a method to fix up the -// name to include a unique identifier (currently the address -// of the objc_class structure). -// Author: David Elliott -// Modified by: -// Created: 2007/05/15 -// Copyright: (c) 2007 Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_OBJC_CLASS_H__ -#define __WX_COCOA_OBJC_CLASS_H__ - -/* A note about this header: -Nothing in here is guaranteed to exist in future versions of wxCocoa. There -are other ways of adding Objective-C classes at runtime and a future wxCocoa -might use these instead of this ugly hack. You may use this header file in -your own wxCocoa code if you need your own Objective-C classes to be -unqiuified. - -You cannot turn this on for 64-bit mode. It will not compile due to opaque -Objective-C data structures and it is not needed because it is a workaround -for a bug that does not exist in the 64-bit runtime. - -You should not use this when wxCocoa is built as a dynamic library. This has -only been tested for the case when wxCocoa is built as a static library and -statically linked to user code to form a loadable bundle (e.g. a Cocoa plugin). -It forces each plugin (when multiple wxCocoa-using plugins are used) to use -its own internal Objective-C classes which is desirable when wxCocoa is -statically linked to the rest of the code. - -Do not use uniquifying on your principal class. That one should be named -differently for different bundles. - */ - -#if wxUSE_OBJC_UNIQUIFYING - -// objc_getClass and stuff -#include - -////////////// Objective-C uniquifying implementation ////////////// - -template -class wxObjcClassInitializer; - -template -class UniquifiedName; - -template -class wxObjcCompilerInformation -{ - friend class wxObjcClassInitializer; - friend class UniquifiedName; -private: - // GetCompiledClass must be partially specialized for an ObjcType - // If you're not using it, implement an inline returning NULL - inline static struct objc_class * GetCompiledClass(); - - // sm_theClassName must be partially specialized for each type - static const char sm_theClassName[]; - - // GetSuperclass must be specialized. Typically one of two ways: - // 1. objc_getClass("SomeRealClassName") - // 2. wxGetObjcClass_SomeWxClassName(); - inline static struct objc_class *GetSuperclass(); -}; - - -template -struct UniquifiedName -{ - // We're going for OriginalClassName@ClassStructureAddress - // Therefore our size is the sizeof the original class name constant string (which includes the terminating NULL) - // plus the sizeof a pointer to struct objc_class times two (two hex digits for each byte) plus 3 for "@0x" - typedef char Type[sizeof(wxObjcCompilerInformation::sm_theClassName) + (sizeof(struct objc_class*)<<1) + 3]; - static void Init(Type m_theString, const objc_class *aClass) - { - snprintf(const_cast(m_theString), sizeof(Type), "%s@%p", wxObjcCompilerInformation::sm_theClassName, aClass); - } -}; - -/*! @function HidePointerFromGC - @abstract Returns an l-value whose location the compiler cannot know. - @discussion - The compiler-generated Objective-C class structures are located in the static data area. - They are by design Objective-C objects in their own right which makes the compiler issue - write barriers as if they were located in the GC-managed heap as most Objective-C objects. - - By accepting and returning a reference to any pointer type we can set any i-var of an - Objective-C object that is a pointer to another Objective-C object without the compiler - generating an objc_assign_ivar write barrier. It will instad generate an - objc_assign_strongCast write barrier which is the appropriate write-barrier when assigning - pointers to Objective-C objects located in unknown memory. - - For instance: - Class *someClass = ...; - HidePointerFromGC(someClass->isa) = ...; - */ -template -inline ObjcType * & HidePointerFromGC(ObjcType * &p) __attribute__((always_inline)); - -template -inline ObjcType * & HidePointerFromGC(ObjcType * &p) -{ - return p; -} - -template -class wxObjcClassInitializer -{ -public: - static struct objc_class* Get() - { - static wxObjcClassInitializer s_theInstance; - s_theInstance.noop(); // Make the compiler think we need this instance - return wxObjcCompilerInformation::GetCompiledClass(); - } -private: - void noop() - {} - // This "constructor" operates solely on static data - // It exists so that we can take advantage of a function-static - // "instance" of this class to do the static data initialization. - wxObjcClassInitializer() - { - // Objective-C class initialization occurs before C++ static initialization because the - // libobjc.dylib gets notified directly by dyld on Tiger. - // Therefore, even though we change the name, the class is still registered with the - // original name. We unfortunately can't change that. - - // The first time the class is loaded, Objective-C will already have fixed up the super_class - // and isa->isa and isa->super_class variables so much of this won't do anything. But - // the next time the class is loaded, Objective-C will ignore it and thus we need to - // initialize the data structures appropriately. - - // Ideally we'd have some sort of lock here, but we depend on the fact that we get called - // just before the first time someone wants to send a class message so it should be - // reasonably safe to do this without any locks. - - struct objc_class &theClassData = *wxObjcCompilerInformation::GetCompiledClass(); - // Initialize the uniquified class name - UniquifiedName::Init(sm_theUniquifiedClassName, &theClassData); - - //////// Class Initialization //////// - // Use objc_getClass to fix up the superclass pointer - theClassData.super_class = wxObjcCompilerInformation::GetSuperclass(); - // Fix up the compiler generated class struct to use the new name - theClassData.name = sm_theUniquifiedClassName; - - //////// Meta-Class Initialization //////// - // theClassData.isa is the metaclass pointer - // Globals on Darwin use PC-relative access (slow) so it's quicker to use theClassData.isa - - // In any object hierarchy a metaclass's metaclass is always the root class's metaclass - // Therefore, our superclass's metaclass's metaclass should already be the root class's metaclass - HidePointerFromGC(theClassData.isa->isa) = theClassData.super_class->isa->isa; - // A metaclass's superclass is always the superclass's metaclass. - HidePointerFromGC(theClassData.isa->super_class) = theClassData.super_class->isa; - // Fix up the compiler generated metaclass struct to use the new name - theClassData.isa->name = sm_theUniquifiedClassName; - - // We need to set the initialized flag because after we change the name, Objective-C can't - // look us up by name because we're only registered with the original name. - theClassData.isa->info |= CLS_INITIALIZED; - } - wxObjcClassInitializer(const wxObjcClassInitializer&); // NO COPY - wxObjcClassInitializer& operator =(const wxObjcClassInitializer&); // NO ASSIGN - static typename UniquifiedName::Type sm_theUniquifiedClassName; -}; - -template -typename UniquifiedName::Type wxObjcClassInitializer::sm_theUniquifiedClassName; - -// WX_DECLARE_GET_OBJC_CLASS -// Declares a function to get a direct pointer to an objective-C class. -// The class is guaranteed to be usable. -// When wxCocoa is built into a Mach-O bundle this function allows the wxCocoa -// code to get a reference to the Objective-C class structure located in the -// same bundle. This allows a static wxCocoa library to be built into -// two different Mach-O bundles without having one bundle's Objective-C -// classes trample on the other's. -// Right now we toss the ObjcSuperClass parameter, but we might use it later. -#define WX_DECLARE_GET_OBJC_CLASS(ObjcClass,ObjcSuperClass) \ -struct objc_class* wx_GetObjcClass_ ## ObjcClass(); - -// WX_IMPLEMENT_OBJC_GET_COMPILED_CLASS(ObjcClass) -// Provides an architecture-dependent way to get the direct pointer to the -// objc_class structure in the __OBJC segment. -// This takes advantage of the fact that the Objective-C compiler uses guessable -// local assembler labels for the class structures. -// Those class structures are only available on the Objective-C file containing the -// @implementation block. - -#if 1 -// Generic implementation - Tested on i386 and PPC. Should work in all cases. -// This is a hack that depends on GCC asm symbol names. -// The static variable winds up being initialized with a direct reference to the appropriate -// L_OBJC_CLASS and no global symbol reference is generated because nothing uses the global symbol -// except for the static initializer which does it directly. -// The generated assembler for s_objc_class_ptr is basically like this: -// _s_objc_class_ptr_ObjcClass: -// .long L_OBJC_CLASS_ObjcClass -// Once that static symbol is defined, the function implementation is easy for GCC to generate. -// Do note that return &s_objc_class_data_ObjcClass won't work. The code is wrong in this case. -#define WX_IMPLEMENT_OBJC_GET_COMPILED_CLASS(ObjcClass) \ -extern "C" objc_class s_objc_class_data_ ## ObjcClass asm("L_OBJC_CLASS_" #ObjcClass); \ -static objc_class * s_objc_class_ptr_ ## ObjcClass = &s_objc_class_data_ ## ObjcClass; \ -template<> \ -inline objc_class * wxObjcCompilerInformation::GetCompiledClass() \ -{ \ - return s_objc_class_ptr_## ObjcClass; \ -} - -#elif defined(__i386__) -// Not used because the generic implementation seems to work fine. -// But this is here since it was written beforehand and it also works. - -// This is based on the code GCC generates for accessing file-static data on i386. -// The i386 PC-relative addressing happens in this manner -// 1. The program counter is placed into ecx using the code that GCC should have -// already generated. -// 2. A label is placed directly after the call to get the program counter. -// 3. The Load Effective Address instruction is used to add the offset of the -// local assembler label we're interested in minus the local assembler label -// from step 2 to the program counter register in ecx and place the result -// into the result register (typically eax if not inlined). -#define WX_IMPLEMENT_OBJC_GET_COMPILED_CLASS(ObjcClass) \ -template<> \ -inline objc_class * wxObjcCompilerInformation::GetCompiledClass() \ -{ \ - register struct objc_class *retval; \ - asm \ - ( "call ___i686.get_pc_thunk.cx\n" \ - "\"LPC_FOR_GET_CLASS_" #ObjcClass "\":\n\t" \ - "leal L_OBJC_CLASS_" #ObjcClass "-\"LPC_FOR_GET_CLASS_" #ObjcClass "\"(%%ecx), %0" \ - : "=r"(retval) \ - : \ - : "ecx" \ - ); \ - return retval; \ -} - -#elif defined(__ppc__) -// Not used because the generic implementation seems to work fine. -// But this is here since it was written beforehand and it also works. - -// This is based on the code GCC generates for accessing file-static data on PPC. -// The PowerPC PC-relative addressing happens in this manner -// 1. The link register is saved (mflr) to a temporary (we re-use the output register for this) -// 2. An unconditional branch instruction (bcl) "branches" to the following address (labeled) -// 3. The link register (filled in by bcl) is saved to r10 (a temporary) -// 4. The previous link register is restored (mtlr) (from the output register we were using as a temporary) -// 5. The address of the LPC label as executed is added to the high 16 bits of the offset between that label and the static data we want -// and stored in a temporary register (r2) -// 6. That temporary register plus the low 16 bits of the offset are stored into the result register. -#define WX_IMPLEMENT_OBJC_GET_COMPILED_CLASS(ObjcClass) \ -template<> \ -inline objc_class * wxObjcCompilerInformation::GetCompiledClass() \ -{ \ - register struct objc_class *retval; \ - asm \ - ( "mflr %0" \ - "\n\tbcl 20, 31, \"LPC_FOR_GET_CLASS_" #ObjcClass "\"" \ - "\n\"LPC_FOR_GET_CLASS_" #ObjcClass "\":" \ - "\n\tmflr r10" \ - "\n\tmtlr %0" \ - "\n\taddis r2,r10,ha16(L_OBJC_CLASS_" #ObjcClass "-\"LPC_FOR_GET_CLASS_" #ObjcClass "\")" \ - "\n\tla %0,lo16(L_OBJC_CLASS_" #ObjcClass "-\"LPC_FOR_GET_CLASS_" #ObjcClass "\")(r2)" \ - : "=r" (retval) \ - : \ - : "r10","r2" \ - ); \ - return retval; \ -} - -// TODO: __x86_64__, __ppc64__ -#else // Can't write inline asm to bust into __OBJC segment -// This won't be used since the generic implementation takes precedence. - -#warning "Don't know how to implement wxObjcCompilerInformation::GetCompiledClass on this platform" - -#endif // platforms - -// The WX_IMPLEMENT_OBJC_GET_SUPERCLASS macro implements the template specialization -// to get the superclass. This only works if it's a real superclass. If you are -// deriving from a class that's already being uniquified then you'd need to -// implement the specialization to call the appropriate get method instead. -#define WX_IMPLEMENT_OBJC_GET_SUPERCLASS(ObjcClass,ObjcSuperClass) \ - template <> \ - inline objc_class* wxObjcCompilerInformation::GetSuperclass() \ - { \ - return objc_getClass(#ObjcSuperClass); \ - } - -// The WX_IMPLEMENT_OBJC_GET_UNIQUIFIED_SUPERCLASS macro implements the template -// specialization to get the superclass when the superclass is another uniquified -// Objective-C class. -#define WX_IMPLEMENT_OBJC_GET_UNIQUIFIED_SUPERCLASS(ObjcClass,ObjcSuperClass) \ - template <> \ - inline objc_class* wxObjcCompilerInformation::GetSuperclass() \ - { \ - return wx_GetObjcClass_ ## ObjcSuperClass(); \ - } - -// The WX_IMPLEMENT_OBJC_CLASS_NAME macro implements the template specialization -// of the sm_theClassName constant. As soon as this specialization is in place -// sizeof(sm_theClassName) will return the number of bytes at compile time. -#define WX_IMPLEMENT_OBJC_CLASS_NAME(ObjcClass) \ - template <> \ - const char wxObjcCompilerInformation::sm_theClassName[] = #ObjcClass; - -// The WX_IMPLEMENT_OBJC_GET_OBJC_CLASS macro is the final one that actually provides -// the wx_GetObjcClass_XXX function that will be called in lieu of asking the Objective-C -// runtime for the class. All the others are really machinery to make this happen. -#define WX_IMPLEMENT_OBJC_GET_OBJC_CLASS(ObjcClass) \ - objc_class* wx_GetObjcClass_ ## ObjcClass() \ - { \ - return wxObjcClassInitializer::Get(); \ - } - -// The WX_IMPLEMENT_GET_OBJC_CLASS macro combines all of these together -// for the case when the superclass is a non-uniquified class. -#define WX_IMPLEMENT_GET_OBJC_CLASS(ObjcClass,ObjcSuperClass) \ - WX_IMPLEMENT_OBJC_GET_COMPILED_CLASS(ObjcClass) \ - WX_IMPLEMENT_OBJC_GET_SUPERCLASS(ObjcClass,ObjcSuperClass) \ - WX_IMPLEMENT_OBJC_CLASS_NAME(ObjcClass) \ - WX_IMPLEMENT_OBJC_GET_OBJC_CLASS(ObjcClass) - -// The WX_IMPLEMENT_GET_OBJC_CLASS_WITH_UNIQUIFIED_SUPERCLASS macro combines all -// of these together for the case when the superclass is another uniquified class. -#define WX_IMPLEMENT_GET_OBJC_CLASS_WITH_UNIQUIFIED_SUPERCLASS(ObjcClass,ObjcSuperClass) \ - WX_IMPLEMENT_OBJC_GET_COMPILED_CLASS(ObjcClass) \ - WX_IMPLEMENT_OBJC_GET_UNIQUIFIED_SUPERCLASS(ObjcClass,ObjcSuperClass) \ - WX_IMPLEMENT_OBJC_CLASS_NAME(ObjcClass) \ - WX_IMPLEMENT_OBJC_GET_OBJC_CLASS(ObjcClass) - -// The WX_GET_OBJC_CLASS macro is intended to wrap the class name when the class -// is used as a message receiver (e.g. for calling class methods). When -// class name uniquifying is used, this calls the global function implemented -// in the Objective-C file containing the class @implementation. -#define WX_GET_OBJC_CLASS(ObjcClass) wx_GetObjcClass_ ## ObjcClass() - -#else // wxUSE_OBJC_UNIQUIFYING - -// Define WX_DECLARE_GET_OBJC_CLASS as nothing -#define WX_DECLARE_GET_OBJC_CLASS(ObjcClass,ObjcSuperClass) -// Define WX_IMPLEMENT_GET_OBJC_CLASS as nothing -#define WX_IMPLEMENT_GET_OBJC_CLASS(ObjcClass,ObjcSuperClass) -// Define WX_IMPLEMENT_GET_OBJC_CLASS_WITH_UNIQUIFIED_SUPERCLASS as nothing -#define WX_IMPLEMENT_GET_OBJC_CLASS_WITH_UNIQUIFIED_SUPERCLASS(ObjcClass,ObjcSuperClass) - -// Define WX_GET_OBJC_CLASS macro to output the class name and let the compiler do the normal thing -// The WX_GET_OBJC_CLASS macro is intended to wrap the class name when the class -// is used as a message receiver (e.g. for calling class methods). When -// class name uniquifying is not used, this is simply defined to be the class -// name which will allow the compiler to do the normal thing. -#define WX_GET_OBJC_CLASS(ObjcClass) ObjcClass - -#endif // wxUSE_OBJC_UNIQUIFYING - -#endif //ndef __WX_COCOA_OBJC_CLASS_H__ diff --git a/include/wx/cocoa/pen.h b/include/wx/cocoa/pen.h deleted file mode 100644 index af54be931a..0000000000 --- a/include/wx/cocoa/pen.h +++ /dev/null @@ -1,71 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/pen.h -// Purpose: wxPen class -// Author: David Elliott -// Modified by: -// Created: 2003/08/02 (stubs from 22.03.2003) -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_PEN_H__ -#define __WX_COCOA_PEN_H__ - -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -class WXDLLIMPEXP_FWD_CORE wxColour; -class WXDLLIMPEXP_FWD_CORE wxBitmap; - -// ======================================================================== -// wxPen -// ======================================================================== -class WXDLLIMPEXP_CORE wxPen: public wxGDIObject -{ -public: - wxPen(); - wxPen(const wxColour& col, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID); - wxPen(const wxBitmap& stipple, int width); - virtual ~wxPen(); - - // FIXME: operator==() is wrong - bool operator==(const wxPen& pen) const { return m_refData == pen.m_refData; } - bool operator!=(const wxPen& pen) const { return !(*this == pen); } - - void SetColour(const wxColour& col) ; - void SetColour(unsigned char r, unsigned char g, unsigned char b) ; - - void SetWidth(int width); - void SetStyle(wxPenStyle style); - void SetStipple(const wxBitmap& stipple); - void SetDashes(int nb_dashes, const wxDash *dash); - void SetJoin(wxPenJoin join); - void SetCap(wxPenCap cap); - - wxColour GetColour() const; - int GetWidth() const; - wxPenStyle GetStyle() const; - wxPenJoin GetJoin() const; - wxPenCap GetCap() const; - int GetDashes(wxDash **ptr) const; - wxBitmap *GetStipple() const; - - - wxDEPRECATED_MSG("use wxPENSTYLE_XXX constants") - wxPen(const wxColour& col, int width, int style); - - wxDEPRECATED_MSG("use wxPENSTYLE_XXX constants") - void SetStyle(int style) { SetStyle((wxPenStyle)style); } - - // Cocoa-specific - WX_NSColor GetNSColor(); - int GetCocoaLineDash(const CGFloat **pattern); - -protected: - wxGDIRefData *CreateGDIRefData() const; - wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; - - DECLARE_DYNAMIC_CLASS(wxPen) -}; - -#endif // __WX_COCOA_PEN_H__ diff --git a/include/wx/cocoa/private/fontfactory.h b/include/wx/cocoa/private/fontfactory.h deleted file mode 100644 index 7cbfcfe0d1..0000000000 --- a/include/wx/cocoa/private/fontfactory.h +++ /dev/null @@ -1,27 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/private/fontfactory.h -// Purpose: wxFontFactory class -// Author: David Elliott -// Modified by: -// Created: 2007-10-13 -// Copyright: 2007 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_FONTFACTORY_H_ -#define _WX_COCOA_FONTFACTORY_H_ - -/*! @discussion - This class exists so that wxFont need not know about wxSettings - The implementation, however, is in the font.mm file because the - implementation needs to have knowledge of wxFontRefData. - */ -class wxCocoaFontFactory -{ -public: - /*! @abstract Create an instance with the specified NSFont and underline flag. - */ - static wxFont InstanceForNSFont(WX_NSFont cocoaFont, bool underlined = false); -}; - -#endif //_WX_COCOA_FONTFACTORY_H_ diff --git a/include/wx/cocoa/private/scrollview.h b/include/wx/cocoa/private/scrollview.h deleted file mode 100644 index fe07ff9fa1..0000000000 --- a/include/wx/cocoa/private/scrollview.h +++ /dev/null @@ -1,128 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/private/scrollview.h -// Purpose: wxWindowCocoaScrollView -// Author: David Elliott -// Modified by: -// Created: 2008/02/14 -// Copyright: (c) 2003- David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_SCROLLVIEW_H__ -#define _WX_COCOA_SCROLLVIEW_H__ - -@class NSScroller; - -// ======================================================================== -// wxWindowCocoaScrollView -// ======================================================================== -class wxWindowCocoaScrollView: protected wxCocoaNSView -{ - wxDECLARE_NO_COPY_CLASS(wxWindowCocoaScrollView); -public: - wxWindowCocoaScrollView(wxWindow *owner); - virtual ~wxWindowCocoaScrollView(); - inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; } - void ClientSizeToSize(int &width, int &height); - void DoGetClientSize(int *x, int *y) const; - void Encapsulate(); - void Unencapsulate(); - - // wxWindow calls this to do the work. Note that we don't have the refresh parameter - // because wxWindow handles that itself. - void SetScrollbar(int orientation, int position, int thumbSize, int range); - int GetScrollPos(wxOrientation orient); - void SetScrollPos(wxOrientation orient, int position); - int GetScrollRange(wxOrientation orient); - int GetScrollThumb(wxOrientation orient); - void ScrollWindow(int dx, int dy, const wxRect*); - void UpdateSizes(); - - void _wx_doScroller(NSScroller *sender); - -protected: - wxWindowCocoa *m_owner; - WX_NSScrollView m_cocoaNSScrollView; - virtual void Cocoa_FrameChanged(void); - virtual void Cocoa_synthesizeMouseMoved(void) {} - /*! - Flag as to whether we're scrolling for a native view or a custom - wxWindow. This controls the scrolling behaviour. When providing - scrolling for a native view we don't catch scroller action messages - and thus don't send scroll events and we don't actually scroll the - window when the application calls ScrollWindow. - - When providing scrolling for a custom wxWindow, we make the NSScroller - send their action messages to us which we in turn package as wx window - scrolling events. At this point, the window will not physically be - scrolled. The application will most likely handle the event by calling - ScrollWindow which will do the real scrolling. On the other hand, - the application may instead not call ScrollWindow until some threshold - is reached. This causes the window to only scroll in steps which is - what, for instance, wxScrolledWindow does. - */ - bool m_isNativeView; - /*! - The range as the application code wishes to see it. That is, the - range from the last SetScrollbar call for the appropriate dimension. - The horizontal dimension is the first [0] element and the vertical - dimension the second [1] element. - - In wxMSW, a SCROLLINFO with nMin=0 and nMax=range-1 is used which - gives exactly range possible positions so long as nPage (which is - the thumb size) is less than or equal to 1. - */ - int m_scrollRange[2]; - /*! - The thumb size is intended to reflect the size of the visible portion - of the scrolled document. As the document size increases, the thumb - visible thumb size decreases. As document size decreases, the visible - thumb size increases. However, the thumb size on wx is defined in - terms of scroll units (which are effectively defined by the scroll - range) and so increasing the number of scroll units to reflect increased - document size will have the effect of decreasing the visible thumb - size even though the number doesn't change. - - It's also important to note that subtracting the thumb size from the - full range gives you the real range that can be used. Microsoft - defines nPos (the current scrolling position) to be within the range - from nMin to nMax - max(nPage - 1, 0). We know that wxMSW code always - sets nMin = 0 and nMax = range -1. So let's algebraically reduce the - definition of the maximum allowed position: - - Begin: - = nMax - max(nPage - 1, 0) - Substitute (range - 1) for nMax and thumbSize for nPage: - = range - 1 - max(thumbSize - 1, 0) - Add one inside the max conditional and subtract one outside of it: - = range - 1 - (max(thumbSize - 1 + 1, 1) - 1) - Reduce some constants: - = range - 1 - (max(thumbSize, 1) - 1) - Distribute the negative across the parenthesis: - = range - 1 - max(thumbSize, 1) + 1 - Reduce the constants: - = range - max(thumbSize, 1) - - Also keep in mind that thumbSize may never be greater than range but - can be equal to it. Thus for the smallest possible thumbSize there - are exactly range possible scroll positions (numbered from 0 to - range - 1) and for the largest possible thumbSize there is exactly - one possible scroll position (numbered 0). - */ - int m_scrollThumb[2]; - - /*! - The origin of the virtual coordinate space expressed in terms of client - coordinates. Starts at (0,0) and each call to ScrollWindow accumulates - into it. Thus if the user scrolls the window right (thus causing the - contents to move left with respect to the client origin, the - application code (typically wxScrolledWindow) will be called with - dx of -something, for example -20. This is added to m_virtualOrigin - and thus m_virtualOrigin will be (-20,0) in this example. - */ - wxPoint m_virtualOrigin; -private: - wxWindowCocoaScrollView(); -}; - -#endif //ndef _WX_COCOA_SCROLLVIEW_H__ diff --git a/include/wx/cocoa/private/timer.h b/include/wx/cocoa/private/timer.h deleted file mode 100644 index 1dec2cf7fb..0000000000 --- a/include/wx/cocoa/private/timer.h +++ /dev/null @@ -1,42 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/private/timer.h -// Purpose: Cocoa wxTimer class -// Author: Ryan Norton -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_PRIVATE_TIMER_H_ -#define _WX_COCOA_PRIVATE_TIMER_H_ - -#include "wx/private/timer.h" - -#include "wx/cocoa/ObjcRef.h" - -//----------------------------------------------------------------------------- -// wxTimer -//----------------------------------------------------------------------------- - -DECLARE_WXCOCOA_OBJC_CLASS(NSTimer); - -class WXDLLIMPEXP_CORE wxCocoaTimerImpl : public wxTimerImpl -{ -public: - wxCocoaTimerImpl(wxTimer* timer) : wxTimerImpl(timer) { Init(); } - virtual ~wxCocoaTimerImpl(); - - virtual bool Start(int millisecs = -1, bool oneShot = false); - virtual void Stop(); - - virtual bool IsRunning() const; - - WX_NSTimer GetNSTimer() { return m_cocoaNSTimer; } - -protected: - void Init(); - -private: - WX_NSTimer m_cocoaNSTimer; -}; - -#endif // _WX_COCOA_PRIVATE_TIMER_H_ diff --git a/include/wx/cocoa/radiobox.h b/include/wx/cocoa/radiobox.h deleted file mode 100644 index a56a0c654b..0000000000 --- a/include/wx/cocoa/radiobox.h +++ /dev/null @@ -1,137 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/radiobox.h -// Purpose: wxRadioBox class -// Author: David Elliott -// Modified by: -// Created: 2003/03/18 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_RADIOBOX_H__ -#define __WX_COCOA_RADIOBOX_H__ - -// #include "wx/cocoa/NSButton.h" -DECLARE_WXCOCOA_OBJC_CLASS(NSMatrix); - -// ======================================================================== -// wxRadioBox -// ======================================================================== -class WXDLLIMPEXP_CORE wxRadioBox: public wxControl, public wxRadioBoxBase// , protected wxCocoaNSButton -{ - DECLARE_DYNAMIC_CLASS(wxRadioBox) - DECLARE_EVENT_TABLE() - // NOTE: We explicitly skip NSControl because our primary cocoa view is - // the NSBox but we want to receive action messages from the NSMatrix. - WX_DECLARE_COCOA_OWNER(NSBox,NSView,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxRadioBox() { } - wxRadioBox(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - int majorDim = 0, - long style = 0, const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxRadioBoxNameStr) - { - Create(parent, winid, title, pos, size, n, choices, majorDim, style, validator, name); - } - wxRadioBox(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - int majorDim = 0, - long style = 0, const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxRadioBoxNameStr) - { - Create(parent, winid, title, pos, size, choices, majorDim, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - int majorDim = 0, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxRadioBoxNameStr); - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - int majorDim = 0, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxRadioBoxNameStr); - virtual ~wxRadioBox(); - - // Enabling - virtual bool Enable(unsigned int n, bool enable = true); - virtual bool IsItemEnabled(unsigned int WXUNUSED(n)) const - { - /* TODO */ - return true; - } - - // Showing - virtual bool Show(unsigned int n, bool show = true); - virtual bool IsItemShown(unsigned int WXUNUSED(n)) const - { - /* TODO */ - return true; - } - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - // Radio boxes cannot be enabled/disabled - virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { } - virtual void CocoaTarget_action(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: -// Pure virtuals - // selection - virtual void SetSelection(int n); - virtual int GetSelection() const; - // string access - virtual unsigned int GetCount() const; - virtual wxString GetString(unsigned int n) const; - virtual void SetString(unsigned int n, const wxString& label); - // change the individual radio button state -protected: - // We don't want the typical wxCocoaNSBox behaviour because our real - // implementation is by using an NSMatrix as the NSBox's contentView. - WX_NSMatrix GetNSMatrix() const; - void AssociateNSBox(WX_NSBox theBox); - void DisassociateNSBox(WX_NSBox theBox); - - virtual wxSize DoGetBestSize() const; - - int GetRowForIndex(int n) const - { - if(m_windowStyle & wxRA_SPECIFY_COLS) - return n / GetMajorDim(); - else - return n % GetMajorDim(); - } - - int GetColumnForIndex(int n) const - { - if(m_windowStyle & wxRA_SPECIFY_COLS) - return n % GetMajorDim(); - else - return n / GetMajorDim(); - } -}; - -#endif // __WX_COCOA_RADIOBOX_H__ diff --git a/include/wx/cocoa/radiobut.h b/include/wx/cocoa/radiobut.h deleted file mode 100644 index 4a78b617c2..0000000000 --- a/include/wx/cocoa/radiobut.h +++ /dev/null @@ -1,73 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/radiobut.h -// Purpose: wxRadioButton class -// Author: David Elliott -// Modified by: -// Created: 2003/03/18 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_RADIOBUT_H__ -#define __WX_COCOA_RADIOBUT_H__ - -#include "wx/cocoa/NSButton.h" - -class WXDLLIMPEXP_FWD_CORE wxRadioButton; - -WX_DECLARE_EXPORTED_LIST(wxRadioButton, wxRadioButtonList); - -// ======================================================================== -// wxRadioButton -// ======================================================================== -class WXDLLIMPEXP_CORE wxRadioButton: public wxControl, protected wxCocoaNSButton -{ - DECLARE_DYNAMIC_CLASS(wxRadioButton) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSButton,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxRadioButton() { m_radioMaster = NULL; } - wxRadioButton(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxRadioButtonNameStr) - { - Create(parent, winid, label, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxRadioButtonNameStr); - virtual ~wxRadioButton(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_wxNSButtonAction(void); -private: - void Cocoa_DeselectOtherButtonsInTheGroup(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void SetValue(bool); - virtual bool GetValue() const; - virtual void SetLabel(const wxString& label); - virtual wxString GetLabel() const; -protected: - wxRadioButtonList m_radioSlaves; - wxRadioButton *m_radioMaster; -}; - -#endif // __WX_COCOA_RADIOBUT_H__ diff --git a/include/wx/cocoa/region.h b/include/wx/cocoa/region.h deleted file mode 100644 index c9aed9592d..0000000000 --- a/include/wx/cocoa/region.h +++ /dev/null @@ -1,75 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/region.h -// Purpose: wxRegion class -// Author: David Elliott -// Modified by: -// Created: 2004/04/12 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_REGION_H__ -#define _WX_COCOA_REGION_H__ - -#include "wx/generic/region.h" - -#if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) -typedef struct CGRect NSRect; -#else -typedef struct _NSRect NSRect; -#endif - -class WXDLLIMPEXP_CORE wxRegion : public wxRegionGeneric -{ -public: - wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) - : wxRegionGeneric(x,y,w,h) - {} - wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight) - : wxRegionGeneric(topLeft, bottomRight) - {} - wxRegion(const wxRect& rect) - : wxRegionGeneric(rect) - {} - wxRegion() {} - wxRegion(const wxBitmap& bmp) - : wxRegionGeneric() - { Union(bmp); } - wxRegion(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0) - : wxRegionGeneric() - { Union(bmp, transColour, tolerance); } - virtual ~wxRegion() {} - wxRegion(const wxRegion& r) - : wxRegionGeneric(r) - {} - wxRegion& operator= (const wxRegion& r) - { return *(wxRegion*)&(this->wxRegionGeneric::operator=(r)); } - - // Cocoa-specific creation - wxRegion(const NSRect& rect); - wxRegion(const NSRect *rects, int count); - -private: - DECLARE_DYNAMIC_CLASS(wxRegion); -}; - -class WXDLLIMPEXP_CORE wxRegionIterator : public wxRegionIteratorGeneric -{ -// DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric); -public: - wxRegionIterator() {} - wxRegionIterator(const wxRegion& region) - : wxRegionIteratorGeneric(region) - {} - wxRegionIterator(const wxRegionIterator& iterator) - : wxRegionIteratorGeneric(iterator) - {} - virtual ~wxRegionIterator() {} - - wxRegionIterator& operator=(const wxRegionIterator& iter) - { return *(wxRegionIterator*)&(this->wxRegionIteratorGeneric::operator=(iter)); } -}; - -#endif - //ndef _WX_COCOA_REGION_H__ diff --git a/include/wx/cocoa/scrolbar.h b/include/wx/cocoa/scrolbar.h deleted file mode 100644 index a051896ef7..0000000000 --- a/include/wx/cocoa/scrolbar.h +++ /dev/null @@ -1,74 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/scrolbar.h -// Purpose: wxScrollBar class -// Author: David Elliott -// Modified by: -// Created: 2004/04/25 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_SCROLBAR_H__ -#define _WX_COCOA_SCROLBAR_H__ - -#include "wx/cocoa/NSScroller.h" - -// ======================================================================== -// wxScrollBar -// ======================================================================== -class WXDLLIMPEXP_CORE wxScrollBar: public wxScrollBarBase, protected wxCocoaNSScroller -{ - DECLARE_DYNAMIC_CLASS(wxScrollBar) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSScroller,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxScrollBar() { } - wxScrollBar(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSB_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxScrollBarNameStr) - { - Create(parent, winid, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSB_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxScrollBarNameStr); - virtual ~wxScrollBar(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_wxNSScrollerAction(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // accessors - virtual int GetThumbPosition() const; - virtual int GetThumbSize() const { return m_thumbSize; } - virtual int GetPageSize() const { return m_pageSize; } - virtual int GetRange() const { return m_range; } - - // operations - virtual void SetThumbPosition(int viewStart); - virtual void SetScrollbar(int position, int thumbSize, - int range, int pageSize, - bool refresh = TRUE); -protected: - int m_range; - int m_thumbSize; - int m_pageSize; -}; - -#endif - // _WX_COCOA_SCROLBAR_H__ diff --git a/include/wx/cocoa/slider.h b/include/wx/cocoa/slider.h deleted file mode 100644 index 5e73aa1796..0000000000 --- a/include/wx/cocoa/slider.h +++ /dev/null @@ -1,107 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/slider.h -// Purpose: wxSlider class -// Author: David Elliott -// Mark Oxenham -// Modified by: -// Created: 2003/06/19 -// Copyright: (c) 2003 David Elliott -// (c) 2007 Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_SLIDER_H__ -#define __WX_COCOA_SLIDER_H__ - -#include "wx/cocoa/NSSlider.h" - -// ======================================================================== -// wxSlider -// ======================================================================== -class WXDLLIMPEXP_CORE wxSlider: public wxSliderBase, protected wxCocoaNSSlider -{ - DECLARE_DYNAMIC_CLASS(wxSlider) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSSlider,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxSlider() { } - wxSlider(wxWindow *parent, wxWindowID winid, - int value, int minValue, int maxValue, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSL_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxSliderNameStr) - { - Create(parent, winid, value, minValue, maxValue, - pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - int value, int minValue, int maxValue, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSL_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxSliderNameStr); - virtual ~wxSlider(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - // Override this so we can use wxCocoaNSControl's target - void AssociateNSSlider(WX_NSSlider theSlider); - - // Helper method to do the real work - virtual void ProcessEventType(wxEventType commandType); - - // from wxCocoaNSControl: - virtual void CocoaTarget_action(); - - // from wxCocoaNSSlider: - virtual void CocoaNotification_startTracking(WX_NSNotification notification); - virtual void CocoaNotification_continueTracking(WX_NSNotification notification); - virtual void CocoaNotification_stopTracking(WX_NSNotification notification); - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // Pure Virtuals - virtual int GetValue() const; - virtual void SetValue(int value); - - // retrieve/change the range - virtual void SetRange(int minValue, int maxValue); - virtual int GetMin() const; - virtual int GetMax() const; - - // the line/page size is the increment by which the slider moves when - // cursor arrow key/page up or down are pressed (clicking the mouse is like - // pressing PageUp/Down) and are by default set to 1 and 1/10 of the range - virtual void SetLineSize(int lineSize); - virtual void SetPageSize(int pageSize); - virtual int GetLineSize() const; - virtual int GetPageSize() const; - - // these methods get/set the length of the slider pointer in pixels - virtual void SetThumbLength(int lenPixels); - virtual int GetThumbLength() const; - - // copied from (wxSliderCocoa.h) - virtual int GetTickFreq() const; - virtual void ClearTicks() { SetTickFreq(0); } - - virtual void SetTickPos(int pos); - -protected: - // Platform-specific implementation of SetTickFreq - virtual void DoSetTickFreq(int freq); -}; - -#endif - // __WX_COCOA_SLIDER_H__ diff --git a/include/wx/cocoa/sound.h b/include/wx/cocoa/sound.h deleted file mode 100644 index 362e2e288d..0000000000 --- a/include/wx/cocoa/sound.h +++ /dev/null @@ -1,51 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/sound.h -// Purpose: wxSound class (loads and plays short Windows .wav files). -// Optional on non-Windows platforms. -// Authors: David Elliott, Ryan Norton -// Modified by: -// Created: 2004-10-02 -// Copyright: (c) 2004 David Elliott, Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_SOUND_H_ -#define _WX_COCOA_SOUND_H_ - -#include "wx/object.h" -#include "wx/cocoa/ObjcRef.h" - -class WXDLLIMPEXP_ADV wxSound : public wxSoundBase -{ -public: - wxSound() - : m_cocoaNSSound(NULL) - {} - wxSound(const wxString& fileName, bool isResource = false) - : m_cocoaNSSound(NULL) - { Create(fileName, isResource); } - wxSound(size_t size, const void* data) - : m_cocoaNSSound(NULL) - { LoadWAV(data,size,true); } - wxSound(const wxSound& sound); // why not? - virtual ~wxSound(); - -public: - bool Create(const wxString& fileName, bool isResource = false); - bool IsOk() const - { return m_cocoaNSSound; } - static void Stop(); - static bool IsPlaying(); - - void SetNSSound(WX_NSSound cocoaNSSound); - inline WX_NSSound GetNSSound() - { return m_cocoaNSSound; } -protected: - bool DoPlay(unsigned flags) const; - bool LoadWAV(const void* data, size_t length, bool copyData); -private: - WX_NSSound m_cocoaNSSound; - static const wxObjcAutoRefFromAlloc sm_cocoaDelegate; -}; - -#endif //ndef _WX_COCOA_SOUND_H_ diff --git a/include/wx/cocoa/spinbutt.h b/include/wx/cocoa/spinbutt.h deleted file mode 100644 index d4dc80dfc0..0000000000 --- a/include/wx/cocoa/spinbutt.h +++ /dev/null @@ -1,63 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/spinbutt.h -// Purpose: wxSpinButton class -// Author: David Elliott -// Modified by: -// Created: 2003/07/14 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_SPINBUTT_H__ -#define __WX_COCOA_SPINBUTT_H__ - -// #include "wx/cocoa/NSStepper.h" - -// ======================================================================== -// wxSpinButton -// ======================================================================== -class WXDLLIMPEXP_CORE wxSpinButton: public wxSpinButtonBase// , protected wxCocoaNSStepper -{ - DECLARE_DYNAMIC_CLASS(wxSpinButton) - DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSStepper,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxSpinButton() { } - wxSpinButton(wxWindow *parent, wxWindowID winid = wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, - const wxString& name = wxSPIN_BUTTON_NAME) - { - Create(parent, winid, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid = wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_HORIZONTAL, - const wxString& name = wxSPIN_BUTTON_NAME); - virtual ~wxSpinButton(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - virtual void CocoaTarget_action(); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // Pure Virtuals - virtual int GetValue() const; - virtual void SetValue(int value); - - // retrieve/change the range - virtual void SetRange(int minValue, int maxValue); -}; - -#endif - // __WX_COCOA_SPINBUTT_H__ diff --git a/include/wx/cocoa/statbmp.h b/include/wx/cocoa/statbmp.h deleted file mode 100644 index f06b129d9f..0000000000 --- a/include/wx/cocoa/statbmp.h +++ /dev/null @@ -1,59 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/statbmp.h -// Purpose: wxStaticBitmap class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_STATBMP_H__ -#define __WX_COCOA_STATBMP_H__ - -DECLARE_WXCOCOA_OBJC_CLASS(NSImageView); - -// ======================================================================== -// wxStaticBitmap -// ======================================================================== -class WXDLLIMPEXP_CORE wxStaticBitmap : public wxStaticBitmapBase //, protected wxCocoaNSxxx -{ - DECLARE_DYNAMIC_CLASS(wxStaticBitmap) - DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSxxx,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxStaticBitmap() {} - wxStaticBitmap(wxWindow *parent, wxWindowID winid, - const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxStaticBitmapNameStr) - { - Create(parent, winid, bitmap, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxBitmap& bitmap, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxStaticBitmapNameStr); - virtual ~wxStaticBitmap(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ - WX_NSImageView GetNSImageView() { return (WX_NSImageView)m_cocoaNSView; } - wxBitmap m_bitmap; - -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ - virtual void SetIcon(const wxIcon& icon); - virtual void SetBitmap(const wxBitmap& bitmap); - virtual wxBitmap GetBitmap() const; -}; - -#endif // __WX_COCOA_STATBMP_H__ diff --git a/include/wx/cocoa/statbox.h b/include/wx/cocoa/statbox.h deleted file mode 100644 index f19579850c..0000000000 --- a/include/wx/cocoa/statbox.h +++ /dev/null @@ -1,60 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/statbox.h -// Purpose: wxStaticBox class -// Author: David Elliott -// Modified by: -// Created: 2003/03/18 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_STATBOX_H__ -#define __WX_COCOA_STATBOX_H__ - -#include "wx/cocoa/NSBox.h" - -// ======================================================================== -// wxStaticBox -// ======================================================================== -class WXDLLIMPEXP_CORE wxStaticBox: public wxStaticBoxBase, protected wxCocoaNSBox -{ - DECLARE_DYNAMIC_CLASS(wxStaticBox) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSBox,NSView,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxStaticBox() { } - wxStaticBox(wxWindow *parent, wxWindowID winid, const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = wxStaticBoxNameStr) - { - Create(parent, winid, title, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = wxStaticBoxNameStr); - virtual ~wxStaticBox(); - - virtual void SetLabel(const wxString& label); - virtual wxString GetLabel() const; - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - // Static boxes cannot be enabled/disabled - virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { } -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void GetBordersForSizer(int *borderTop, int *borderOther) const; -protected: -}; - -#endif // __WX_COCOA_STATBOX_H__ diff --git a/include/wx/cocoa/statline.h b/include/wx/cocoa/statline.h deleted file mode 100644 index 3834a37637..0000000000 --- a/include/wx/cocoa/statline.h +++ /dev/null @@ -1,55 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/statline.h -// Purpose: wxStaticLine class -// Author: David Elliott -// Modified by: -// Created: 2003/03/18 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_STATLINE_H__ -#define __WX_COCOA_STATLINE_H__ - -// #include "wx/cocoa/NSButton.h" - -// ======================================================================== -// wxStaticLine -// ======================================================================== -class WXDLLIMPEXP_CORE wxStaticLine: public wxStaticLineBase// , protected wxCocoaNSButton -{ - DECLARE_DYNAMIC_CLASS(wxStaticLine) - DECLARE_EVENT_TABLE() -// WX_DECLARE_COCOA_OWNER(NSButton,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxStaticLine() { } - wxStaticLine(wxWindow *parent, wxWindowID winid = wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = wxStaticLineNameStr) - { - Create(parent, winid, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid = wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = wxStaticLineNameStr); - virtual ~wxStaticLine(); - -// ------------------------------------------------------------------------ -// Cocoa callbacks -// ------------------------------------------------------------------------ -protected: - // Static lines cannot be enabled/disabled - virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { } -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: -}; - -#endif // __WX_COCOA_STATLINE_H__ diff --git a/include/wx/cocoa/stattext.h b/include/wx/cocoa/stattext.h deleted file mode 100644 index 176d53a0be..0000000000 --- a/include/wx/cocoa/stattext.h +++ /dev/null @@ -1,58 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/stattext.h -// Purpose: wxStaticText class -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_STATTEXT_H__ -#define __WX_COCOA_STATTEXT_H__ - -#include "wx/cocoa/NSTextField.h" - -// ======================================================================== -// wxStaticText -// ======================================================================== -class WXDLLIMPEXP_CORE wxStaticText : public wxStaticTextBase, protected wxCocoaNSTextField -{ - DECLARE_DYNAMIC_CLASS(wxStaticText) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSTextField,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxStaticText() {} - wxStaticText(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxStaticTextNameStr) - { - Create(parent, winid, label, pos, size, style, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxStaticTextNameStr); - virtual ~wxStaticText(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_didChangeText(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual void SetLabel(const wxString& label); - virtual wxString GetLabel() const; -}; - -#endif // __WX_COCOA_STATTEXT_H__ diff --git a/include/wx/cocoa/string.h b/include/wx/cocoa/string.h deleted file mode 100644 index 65112a053a..0000000000 --- a/include/wx/cocoa/string.h +++ /dev/null @@ -1,52 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/string.h -// Purpose: String conversion methods -// Author: David Elliott -// Modified by: -// Created: 2003/04/13 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_STRING_H__ -#define __WX_COCOA_STRING_H__ - -#import -#include "wx/string.h" - -// FIXME: In unicode mode we are doing the conversion twice. wxString -// converts to UTF-8 and NSString converts from UTF-8. -// One possible optimization is to convert to the wxString internal -// representation which is an unsigned short (unichar) but unfortunately -// there is little documentation on which encoding it uses by default. - -// Return an autoreleased NSString -inline NSString* wxNSStringWithWxString(const wxString &wxstring) -{ -#if wxUSE_UNICODE - return [NSString stringWithUTF8String: wxstring.utf8_str()]; -#else - return [NSString stringWithCString: wxstring.c_str() length:wxstring.Len()]; -#endif // wxUSE_UNICODE -} - -// Intialize an NSString which has already been allocated -inline NSString* wxInitNSStringWithWxString(NSString *nsstring, const wxString &wxstring) -{ -#if wxUSE_UNICODE - return [nsstring initWithUTF8String: wxstring.utf8_str()]; -#else - return [nsstring initWithCString: wxstring.c_str() length:wxstring.Len()]; -#endif // wxUSE_UNICODE -} - -inline wxString wxStringWithNSString(NSString *nsstring) -{ -#if wxUSE_UNICODE - return wxString::FromUTF8Unchecked([nsstring UTF8String]); -#else - return wxString([nsstring lossyCString]); -#endif // wxUSE_UNICODE -} - -#endif // __WX_COCOA_STRING_H__ diff --git a/include/wx/cocoa/taskbar.h b/include/wx/cocoa/taskbar.h deleted file mode 100644 index 9c52bfc6c8..0000000000 --- a/include/wx/cocoa/taskbar.h +++ /dev/null @@ -1,47 +0,0 @@ -///////////////////////////////////////////////////////////////////////// -// File: wx/cocoa/taskbar.h -// Purpose: Defines wxTaskBarIcon class -// Author: David Elliott -// Modified by: -// Created: 2004/01/24 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_TASKBAR_H__ -#define _WX_COCOA_TASKBAR_H__ - -#include "wx/icon.h" - -class WXDLLIMPEXP_FWD_CORE wxIcon; -class WXDLLIMPEXP_FWD_CORE wxMenu; - -class wxTaskBarIconCocoaImpl; - -class WXDLLIMPEXP_ADV wxTaskBarIcon : public wxTaskBarIconBase -{ - friend class wxTaskBarIconCocoaImpl; - DECLARE_DYNAMIC_CLASS_NO_COPY(wxTaskBarIcon) -public: - //type of taskbar item to create (currently only DOCK is implemented) - enum wxTaskBarIconType - { DOCK - , CUSTOM_STATUSITEM -// , STATUSITEM // TODO: Implement using NSStatusItem w/o custom NSView -// , MENUEXTRA // Menu extras require undocumented hacks - , DEFAULT_TYPE = CUSTOM_STATUSITEM - }; - - // Only one wxTaskBarIcon can be of the Dock type so by default - // create NSStatusItem for maximum source compatibility. - wxTaskBarIcon(wxTaskBarIconType iconType = DEFAULT_TYPE); - virtual ~wxTaskBarIcon(); - - bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString); - bool RemoveIcon(); - bool PopupMenu(wxMenu *menu); //, int x, int y); -protected: - wxTaskBarIconCocoaImpl *m_impl; -}; - -#endif // _WX_COCOA_TASKBAR_H__ diff --git a/include/wx/cocoa/textctrl.h b/include/wx/cocoa/textctrl.h deleted file mode 100644 index d7b8c0aa7c..0000000000 --- a/include/wx/cocoa/textctrl.h +++ /dev/null @@ -1,122 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/textctrl.h -// Purpose: wxTextCtrl class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_TEXTCTRL_H__ -#define __WX_COCOA_TEXTCTRL_H__ - -#include "wx/cocoa/NSTextField.h" - -// ======================================================================== -// wxTextCtrl -// ======================================================================== -class WXDLLIMPEXP_CORE wxTextCtrl : public wxTextCtrlBase, protected wxCocoaNSTextField -{ - DECLARE_DYNAMIC_CLASS(wxTextCtrl) - DECLARE_EVENT_TABLE() - WX_DECLARE_COCOA_OWNER(NSTextField,NSControl,NSView) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxTextCtrl() {} - wxTextCtrl(wxWindow *parent, wxWindowID winid, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxTextCtrlNameStr) - { - Create(parent, winid, value, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID winid, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxTextCtrlNameStr); - virtual ~wxTextCtrl(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -protected: - virtual void Cocoa_didChangeText(void); - virtual void CocoaTarget_action(void); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual wxString GetValue() const; - - virtual int GetLineLength(long lineNo) const; - virtual wxString GetLineText(long lineNo) const; - virtual int GetNumberOfLines() const; - - virtual bool IsModified() const; - virtual bool IsEditable() const; - - // If the return values from and to are the same, there is no selection. - virtual void GetSelection(long* from, long* to) const; - - // operations - // ---------- - - // editing - virtual void Clear(); - virtual void Replace(long from, long to, const wxString& value); - virtual void Remove(long from, long to); - - // clears the dirty flag - virtual void MarkDirty(); - virtual void DiscardEdits(); - - // writing text inserts it at the current position, appending always - // inserts it at the end - virtual void WriteText(const wxString& text); - virtual void AppendText(const wxString& text); - - // translate between the position (which is just an index in the text ctrl - // considering all its contents as a single strings) and (x, y) coordinates - // which represent column and line. - virtual long XYToPosition(long x, long y) const; - virtual bool PositionToXY(long pos, long *x, long *y) const; - - virtual void ShowPosition(long pos); - - // Clipboard operations - virtual void Copy(); - virtual void Cut(); - virtual void Paste(); - - // Undo/redo - virtual void Undo(); - virtual void Redo(); - - virtual bool CanUndo() const; - virtual bool CanRedo() const; - - // Insertion point - virtual void SetInsertionPoint(long pos); - virtual void SetInsertionPointEnd(); - virtual long GetInsertionPoint() const; - virtual wxTextPos GetLastPosition() const; - - virtual void SetSelection(long from, long to); -// virtual void SelectAll(); - virtual void SetEditable(bool editable); - -protected: - virtual wxSize DoGetBestSize() const; - - virtual void DoSetValue(const wxString& value, int flags = 0); -}; - -#endif // __WX_COCOA_TEXTCTRL_H__ diff --git a/include/wx/cocoa/toolbar.h b/include/wx/cocoa/toolbar.h deleted file mode 100644 index ce57dee03f..0000000000 --- a/include/wx/cocoa/toolbar.h +++ /dev/null @@ -1,120 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/toolbar.h -// Purpose: wxToolBar -// Author: David Elliott -// Modified by: -// Created: 2003/08/17 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_TOOLBAR_H__ -#define __WX_COCOA_TOOLBAR_H__ - -#if wxUSE_TOOLBAR - -// ======================================================================== -// wxToolBar -// ======================================================================== -#if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) -typedef struct CGPoint NSPoint; -#else -typedef struct _NSPoint NSPoint; -#endif - -class wxToolBarTool; - -class WXDLLIMPEXP_CORE wxToolBar : public wxToolBarBase -{ - DECLARE_DYNAMIC_CLASS(wxToolBar) -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxToolBar() { Init(); } - wxToolBar( wxWindow *parent, - wxWindowID toolid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxToolBarNameStr ) - { - Init(); - - Create(parent, toolid, pos, size, style, name); - } - - bool Create( wxWindow *parent, - wxWindowID toolid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxToolBarNameStr ); - - virtual ~wxToolBar(); - -protected: - // common part of all ctors - void Init(); - -// ------------------------------------------------------------------------ -// Cocoa -// ------------------------------------------------------------------------ -protected: - virtual bool Cocoa_acceptsFirstMouse(bool &acceptsFirstMouse, WX_NSEvent theEvent); - virtual bool Cocoa_drawRect(const NSRect &rect); - virtual bool Cocoa_mouseDown(WX_NSEvent theEvent); - virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent); - wxToolBarTool *CocoaFindToolForPosition(const NSPoint& pos) const; - void CocoaToolClickEnded(); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - // override base class virtuals - virtual void SetMargins(int x, int y); - virtual void SetToolSeparation(int separation); - - virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const; - - virtual void SetToolShortHelp(int toolid, const wxString& helpString); - - virtual void SetWindowStyleFlag( long style ); - - // implementation from now on - // -------------------------- - - void OnInternalIdle(); - virtual bool Realize(); - virtual wxSize DoGetBestSize() const; - - void SetOwningFrame(wxFrame *owningFrame) - { m_owningFrame = owningFrame; } -protected: - // implement base class pure virtuals - virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool); - virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool); - - virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable); - virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle); - virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle); - - virtual wxToolBarToolBase *CreateTool(int toolid, - const wxString& label, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, - wxItemKind kind, - wxObject *clientData, - const wxString& shortHelpString, - const wxString& longHelpString); - virtual wxToolBarToolBase *CreateTool(wxControl *control, - const wxString& label); - - wxSize m_bestSize; - wxFrame *m_owningFrame; - wxToolBarTool *m_mouseDownTool; -}; - -#endif // wxUSE_TOOLBAR - -#endif // __WX_COCOA_TOOLBAR_H__ diff --git a/include/wx/cocoa/tooltip.h b/include/wx/cocoa/tooltip.h deleted file mode 100644 index a096a54236..0000000000 --- a/include/wx/cocoa/tooltip.h +++ /dev/null @@ -1,54 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/tooltip.h -// Purpose: wxToolTip class - tooltip control -// Author: Ryan Norton -// Modified by: -// Created: 31.01.99 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_COCOA_TOOLTIP_H_ -#define _WX_COCOA_TOOLTIP_H_ - -#include "wx/object.h" - -class wxWindow; - -class wxToolTip : public wxObject -{ -public: - // ctor & dtor - wxToolTip(const wxString &tip); - virtual ~wxToolTip(); - - // accessors - // tip text - void SetTip(const wxString& tip); - const wxString& GetTip() const; - - // the window we're associated with - wxWindow *GetWindow() const; - - // controlling tooltip behaviour: globally change tooltip parameters - // enable or disable the tooltips globally - static void Enable(bool flag); - // set the delay after which the tooltip appears - static void SetDelay(long milliseconds); - // set the delay after which the tooltip disappears or how long the tooltip remains visible - static void SetAutoPop(long milliseconds); - // set the delay between subsequent tooltips to appear - static void SetReshow(long milliseconds); - -private: - void SetWindow(wxWindow* window); - - friend class wxWindow; - - wxString m_text; // tooltip text - wxWindow *m_window; // window we're associated with - - DECLARE_ABSTRACT_CLASS(wxToolTip) -}; - -#endif // _WX_COCOA_TOOLTIP_H_ diff --git a/include/wx/cocoa/toplevel.h b/include/wx/cocoa/toplevel.h deleted file mode 100644 index d0768294d3..0000000000 --- a/include/wx/cocoa/toplevel.h +++ /dev/null @@ -1,130 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/toplevel.h -// Purpose: wxTopLevelWindowCocoa is the Cocoa implementation of wxTLW -// Author: David Elliott -// Modified by: -// Created: 2002/12/08 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_TOPLEVEL_H__ -#define __WX_COCOA_TOPLEVEL_H__ - -#include "wx/hashmap.h" -#include "wx/cocoa/NSWindow.h" - -class WXDLLIMPEXP_FWD_CORE wxMenuBar; - -// ======================================================================== -// wxTopLevelWindowCocoa -// ======================================================================== -class WXDLLIMPEXP_CORE wxTopLevelWindowCocoa : public wxTopLevelWindowBase, protected wxCocoaNSWindow -{ - DECLARE_EVENT_TABLE(); - DECLARE_NO_COPY_CLASS(wxTopLevelWindowCocoa); -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - inline wxTopLevelWindowCocoa() - : wxCocoaNSWindow(this) - { Init(); } - - inline wxTopLevelWindowCocoa(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr) - : wxCocoaNSWindow(this) - { - Init(); - Create(parent, winid, title, pos, size, style, name); - } - - bool Create(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr); - - virtual ~wxTopLevelWindowCocoa(); - -protected: - // common part of all ctors - void Init(); - -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - inline WX_NSWindow GetNSWindow() { return m_cocoaNSWindow; } - virtual void CocoaDelegate_windowWillClose(void); - virtual bool CocoaDelegate_windowShouldClose(void); - virtual void CocoaDelegate_windowDidBecomeKey(void); - virtual void CocoaDelegate_windowDidResignKey(void); - virtual void CocoaDelegate_windowDidBecomeMain(void); - virtual void CocoaDelegate_windowDidResignMain(void); - virtual void CocoaDelegate_wxMenuItemAction(WX_NSMenuItem sender); - virtual bool CocoaDelegate_validateMenuItem(WX_NSMenuItem sender); - virtual wxMenuBar* GetAppMenuBar(wxCocoaNSWindow *win); - static void DeactivatePendingWindow(); -protected: - void SetNSWindow(WX_NSWindow cocoaNSWindow); - WX_NSWindow m_cocoaNSWindow; - static wxCocoaNSWindowHash sm_cocoaHash; - virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView); - static unsigned int NSWindowStyleForWxStyle(long style); - static NSRect MakeInitialNSWindowContentRect(const wxPoint& pos, const wxSize& size, unsigned int cocoaStyleMask); - - static wxTopLevelWindowCocoa *sm_cocoaDeactivateWindow; -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - virtual bool Destroy(); - // Pure virtuals - virtual void Maximize(bool maximize = true); - virtual bool IsMaximized() const; - virtual void Iconize(bool iconize = true); - virtual bool IsIconized() const; - virtual void Restore(); - virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL); - virtual bool IsFullScreen() const; - // other - virtual bool Show( bool show = true ); - virtual bool Close( bool force = false ); - virtual void OnCloseWindow(wxCloseEvent& event); - virtual void CocoaSetWxWindowSize(int width, int height); - virtual void DoMoveWindow(int x, int y, int width, int height); - virtual void DoGetSize(int *width, int *height) const; - virtual void DoGetPosition(int *x, int *y) const; - virtual void SetTitle( const wxString& title); - virtual wxString GetTitle() const; - - // Default button (item) - wxWindow *SetDefaultItem(wxWindow *win); - -// Things I may/may not do -// virtual void SetIcons(const wxIconBundle& icons); -// virtual void Clear() ; -// virtual void Raise(); -// virtual void Lower(); -protected: - // is the frame currently iconized? - bool m_iconized; - // has the frame been closed - bool m_closed; - // should the frame be maximized when it will be shown? set by Maximize() - // when it is called while the frame is hidden - bool m_maximizeOnShow; -}; - -// list of all frames and modeless dialogs -extern WXDLLIMPEXP_DATA_CORE(wxWindowList) wxModelessWindows; - -#endif // __WX_COCOA_TOPLEVEL_H__ diff --git a/include/wx/cocoa/trackingrectmanager.h b/include/wx/cocoa/trackingrectmanager.h deleted file mode 100644 index eac59b07b4..0000000000 --- a/include/wx/cocoa/trackingrectmanager.h +++ /dev/null @@ -1,40 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/trackingrectmanager.h -// Purpose: wxCocoaTrackingRectManager -// Notes: Source in window.mm -// Author: David Elliott -// Modified by: -// Created: 2007/05/02 -// Copyright: (c) 2007 Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// -#ifndef __WX_COCOA_TRACKINGRECTMANAGER_H__ -#define __WX_COCOA_TRACKINGRECTMANAGER_H__ - -#include - -#define wxTRACE_COCOA_TrackingRect wxT("COCOA_TrackingRect") - -class wxCocoaTrackingRectManager -{ - wxDECLARE_NO_COPY_CLASS(wxCocoaTrackingRectManager); -public: - wxCocoaTrackingRectManager(wxWindow *window); - void ClearTrackingRect(); - void BuildTrackingRect(); - void RebuildTrackingRectIfNeeded(); - void RebuildTrackingRect(); - bool IsOwnerOfEvent(NSEvent *anEvent); - ~wxCocoaTrackingRectManager(); - void BeginSynthesizingEvents(); - void StopSynthesizingEvents(); -protected: - wxWindow *m_window; - bool m_isTrackingRectActive; - NSInteger m_trackingRectTag; - NSRect m_trackingRectInWindowCoordinates; -private: - wxCocoaTrackingRectManager(); -}; - -#endif // ndef __WX_COCOA_TRACKINGRECTMANAGER_H__ diff --git a/include/wx/cocoa/window.h b/include/wx/cocoa/window.h deleted file mode 100644 index a060f37892..0000000000 --- a/include/wx/cocoa/window.h +++ /dev/null @@ -1,226 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/cocoa/window.h -// Purpose: wxWindowCocoa -// Author: David Elliott -// Modified by: -// Created: 2002/12/26 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __WX_COCOA_WINDOW_H__ -#define __WX_COCOA_WINDOW_H__ - -#include "wx/cocoa/NSView.h" - -#ifdef __OBJC__ - #import -#endif //def __OBJC__ - -// We can only import Foundation/NSGeometry.h from Objective-C code but it's -// nice to be able to use NSPoint and NSRect in the declarations of helper -// methods so we must define them as opaque structs identically to the way -// they are defined by the real header. -// NOTE: We specifically use these regardless of C++ or Objective-C++ mode so -// the compiler will complain if we got the definitions wrong. In regular -// C++ mode there is no way to know if we got the definitons right so -// we depend on at least one Objective-C++ file including this header. -#if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64) -typedef struct CGPoint NSPoint; -typedef struct CGRect NSRect; -#else -typedef struct _NSPoint NSPoint; -typedef struct _NSRect NSRect; -#endif - -DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform); - -class wxWindowCocoaHider; -class wxWindowCocoaScrollView; -class wxCocoaTrackingRectManager; - -// ======================================================================== -// wxWindowCocoa -// ======================================================================== -class WXDLLIMPEXP_CORE wxWindowCocoa: public wxWindowBase, protected wxCocoaNSView -{ - DECLARE_DYNAMIC_CLASS(wxWindowCocoa) - wxDECLARE_NO_COPY_CLASS(wxWindowCocoa); - DECLARE_EVENT_TABLE() - friend wxWindow *wxWindowBase::GetCapture(); - friend class wxWindowCocoaScrollView; - friend class wxCocoaTrackingRectManager; -// ------------------------------------------------------------------------ -// initialization -// ------------------------------------------------------------------------ -public: - wxWindowCocoa() { Init(); } - inline wxWindowCocoa(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxPanelNameStr) - { - Init(); - Create(parent, winid, pos, size, style, name); - } - - virtual ~wxWindowCocoa(); - - bool Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxString& name = wxPanelNameStr); -protected: - void Init(); -// ------------------------------------------------------------------------ -// Cocoa specifics -// ------------------------------------------------------------------------ -public: - // Returns the content NSView (where children are added, drawing performed) - inline WX_NSView GetNSView() { return m_cocoaNSView; } - // Returns the NSView suitable for use as a subview - WX_NSView GetNSViewForSuperview() const; - // Returns the NSView that may be hidden/is being hidden - WX_NSView GetNSViewForHiding() const; - // Returns the NSView for non-client drawing - virtual WX_NSView GetNonClientNSView() { return GetNSViewForSuperview(); } - // Add/remove children - void CocoaAddChild(wxWindowCocoa *child); - void CocoaRemoveFromParent(void); -#ifdef __OBJC__ - // Returns an autoreleased NSAffineTransform which can be applied - // to a graphics context currently using the view's coordinate system - // (such as the one locked when drawRect is called or after a call - // to [NSView lockFocus]) such that further drawing is done using - // the wxWidgets coordinate system. - WX_NSAffineTransform CocoaGetWxToBoundsTransform(); -#endif //def __OBJC__ -protected: - // actually enable/disable the cocoa control, overridden by subclasses - virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { } - - void CocoaCreateNSScrollView(); - void InitMouseEvent(wxMouseEvent &event, WX_NSEvent cocoaEvent); - virtual wxWindow* GetWxWindow() const; - virtual void Cocoa_FrameChanged(void); - virtual void Cocoa_synthesizeMouseMoved(void); - virtual bool Cocoa_drawRect(const NSRect &rect); - virtual bool Cocoa_mouseDown(WX_NSEvent theEvent); - virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent); - virtual bool Cocoa_mouseUp(WX_NSEvent theEvent); - virtual bool Cocoa_mouseMoved(WX_NSEvent theEvent); - virtual bool Cocoa_mouseEntered(WX_NSEvent theEvent); - virtual bool Cocoa_mouseExited(WX_NSEvent theEvent); - virtual bool Cocoa_rightMouseDown(WX_NSEvent theEvent); - virtual bool Cocoa_rightMouseDragged(WX_NSEvent theEvent); - virtual bool Cocoa_rightMouseUp(WX_NSEvent theEvent); - virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent); - virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent); - virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent); - virtual bool Cocoa_resetCursorRects(); - virtual bool Cocoa_viewDidMoveToWindow(); - virtual bool Cocoa_viewWillMoveToWindow(WX_NSWindow newWindow); - void SetNSView(WX_NSView cocoaNSView); - WX_NSView m_cocoaNSView; - wxWindowCocoaHider *m_cocoaHider; - wxWindowCocoaScrollView *m_wxCocoaScrollView; - bool m_isInPaint; - wxCocoaTrackingRectManager *m_visibleTrackingRectManager; - static wxWindow *sm_capturedWindow; - virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView); - void SetInitialFrameRect(const wxPoint& pos, const wxSize& size); -#ifdef __OBJC__ - inline NSRect MakeDefaultNSRect(const wxSize& size) - { - // NOTE: position is 10,10 to make it "obvious" that it's out of place - return NSMakeRect(10.0,10.0,WidthDefault(size.x),HeightDefault(size.y)); - } - // These functions translate NSPoint or NSRect between the coordinate - // system of Cocoa's boudns rect and wx's coordinate system. - NSPoint CocoaTransformBoundsToWx(NSPoint pointBounds); - NSRect CocoaTransformBoundsToWx(NSRect rectBounds); - NSPoint CocoaTransformWxToBounds(NSPoint pointWx); - NSRect CocoaTransformWxToBounds(NSRect rectWx); -#endif //def __OBJC__ - static wxPoint OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(NSRect windowFrame); - static NSPoint OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(wxCoord x, wxCoord y, wxCoord width, wxCoord height, bool keepOriginVisible); -// ------------------------------------------------------------------------ -// Implementation -// ------------------------------------------------------------------------ -public: - /* Pure Virtuals */ - // Raise the window to the top of the Z order - virtual void Raise(); - // Lower the window to the bottom of the Z order - virtual void Lower(); - // Set the focus to this window - virtual void SetFocus(); - // Warp the pointer the given position - virtual void WarpPointer(int x_pos, int y_pos) ; - // Change the window's cursor - virtual bool SetCursor( const wxCursor &cursor ); - // Send the window a refresh event - virtual void Refresh(bool eraseBack = true, const wxRect *rect = NULL); - // Set/get the window's font - virtual bool SetFont(const wxFont& f); -// inline virtual wxFont& GetFont() const; - virtual void SetLabel(const wxString& label); - virtual wxString GetLabel() const; - // label handling - // Get character size - virtual int GetCharHeight() const; - virtual int GetCharWidth() const; - virtual void DoGetTextExtent(const wxString& string, int *x, int *y, - int *descent = NULL, - int *externalLeading = NULL, - const wxFont *theFont = NULL) const; - // Scroll stuff - virtual void SetScrollbar(int orient, int pos, int thumbVisible, - int range, bool refresh = true); - virtual void SetScrollPos(int orient, int pos, bool refresh = true); - virtual int GetScrollPos(int orient) const; - virtual int GetScrollThumb(int orient) const; - virtual int GetScrollRange(int orient) const; - virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); - virtual void DoSetVirtualSize(int x, int y); - // Get the private handle (platform-dependent) - virtual WXWidget GetHandle() const; - // Convert client to screen coordinates - virtual void DoClientToScreen(int *x, int *y) const; - // Convert screen to client coordinates - virtual void DoScreenToClient(int *x, int *y) const; - // Capture/release mouse - virtual void DoCaptureMouse(); - virtual void DoReleaseMouse(); - // Get window position, relative to parent (or screen if no parent) - virtual void DoGetPosition(int *x, int *y) const; - // Get overall window size - virtual void DoGetSize(int *width, int *height) const; - // Get/set client (application-useable) size - virtual void DoGetClientSize(int *width, int *height) const; - virtual void DoSetClientSize(int width, int size); - // Set this window's tooltip - virtual void DoSetToolTip( wxToolTip *tip ); - // Set the size of the wxWindow (the contentView of an NSWindow) - // wxTopLevelWindow will override this and set the NSWindow size - // such that the contentView will be this size - virtual void CocoaSetWxWindowSize(int width, int height); - // Set overall size and position - virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); - virtual void DoMoveWindow(int x, int y, int width, int height); - // Popup a menu - virtual bool DoPopupMenu(wxMenu *menu, int x, int y); - - /* Other implementation */ - - // NOTE: typically Close() is not virtual, but we want this for Cocoa - virtual bool Close( bool force = false ); - virtual bool Show( bool show = true ); - virtual void DoEnable( bool enable ); - - virtual bool IsDoubleBuffered() const { return true; } -}; - -#endif // __WX_COCOA_WINDOW_H__ diff --git a/src/cocoa/NSBox.mm b/src/cocoa/NSBox.mm deleted file mode 100644 index 504ec538e7..0000000000 --- a/src/cocoa/NSBox.mm +++ /dev/null @@ -1,29 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSBox.mm -// Purpose: wxCocoaNSBox -// Author: David Elliott -// Modified by: -// Created: 2003/03/19 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP -#endif // WX_PRECOMP - -#include "wx/cocoa/NSBox.h" - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- -WX_IMPLEMENT_OBJC_INTERFACE(NSBox) - diff --git a/src/cocoa/NSButton.mm b/src/cocoa/NSButton.mm deleted file mode 100644 index 3e0b3ed6fe..0000000000 --- a/src/cocoa/NSButton.mm +++ /dev/null @@ -1,69 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSButton.mm -// Purpose: wxCocoaNSButton -// Author: David Elliott -// Modified by: -// Created: 2003/01/31 -// Copyright: (c) 2003-2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/objc/objc_uniquifying.h" -#include "wx/cocoa/NSButton.h" -#import - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSButton) - -// ============================================================================ -// @class wxNSButtonTarget -// ============================================================================ -@interface wxNSButtonTarget : NSObject -{ -} - -- (void)wxNSButtonAction: (id)sender; -@end // wxNSButtonTarget -WX_DECLARE_GET_OBJC_CLASS(wxNSButtonTarget,NSObject) - -@implementation wxNSButtonTarget : NSObject -- (void)wxNSButtonAction: (id)sender -{ - wxCocoaNSButton *button = wxCocoaNSButton::GetFromCocoa(sender); - wxCHECK_RET(button,wxT("wxNSButtonAction received without associated wx object")); - button->Cocoa_wxNSButtonAction(); -} - -@end // implementation wxNSButtonTarget -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSButtonTarget,NSObject) - -// ============================================================================ -// class wxCocoaNSButton -// ============================================================================ -const wxObjcAutoRefFromAlloc wxCocoaNSButton::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSButtonTarget) alloc] init]; - -void wxCocoaNSButton::AssociateNSButton(WX_NSButton cocoaNSButton) -{ - if(cocoaNSButton) - { - sm_cocoaHash.insert(wxCocoaNSButtonHash::value_type(cocoaNSButton,this)); - [cocoaNSButton setTarget: sm_cocoaTarget]; - [cocoaNSButton setAction: @selector(wxNSButtonAction:)]; - } -} - diff --git a/src/cocoa/NSControl.mm b/src/cocoa/NSControl.mm deleted file mode 100644 index 94fc785a9c..0000000000 --- a/src/cocoa/NSControl.mm +++ /dev/null @@ -1,63 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSControl.mm -// Purpose: wxCocoaNSControl -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/objc/objc_uniquifying.h" -#include "wx/cocoa/ObjcRef.h" -#include "wx/cocoa/NSControl.h" - -#import - -// ============================================================================ -// @class wxNSControlTarget -// ============================================================================ -@interface wxNSControlTarget : NSObject -{ -} - -- (void)wxNSControlAction: (id)sender; -@end //interface wxNSControlTarget -WX_DECLARE_GET_OBJC_CLASS(wxNSControlTarget,NSObject) - -@implementation wxNSControlTarget : NSObject - -- (void)wxNSControlAction: (id)sender -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxNSControlAction")); - wxCocoaNSControl *wxcontrol = wxCocoaNSControl::GetFromCocoa(sender); - wxCHECK_RET(wxcontrol,wxT("wxNSControlAction received but no wxCocoaNSControl exists!")); - wxcontrol->CocoaTarget_action(); -} - -@end //implementation wxNSControlTarget -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSControlTarget,NSObject) - -// ============================================================================ -// wxNSControl -// ============================================================================ -WX_IMPLEMENT_OBJC_INTERFACE(NSControl) - -// New CF-retained observer (this should have been using wxObjcAutoRefFromAlloc to begin with) -wxObjcAutoRefFromAlloc s_cocoaNSControlTarget = [[WX_GET_OBJC_CLASS(wxNSControlTarget) alloc] init]; -// For compatibility with old code -struct objc_object *wxCocoaNSControl::sm_cocoaTarget = s_cocoaNSControlTarget; - diff --git a/src/cocoa/NSMenu.mm b/src/cocoa/NSMenu.mm deleted file mode 100644 index fae4e995a2..0000000000 --- a/src/cocoa/NSMenu.mm +++ /dev/null @@ -1,136 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSMenu.mm -// Purpose: wxCocoaNSMenu implementation -// Author: David Elliott -// Modified by: -// Created: 2002/12/09 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#if wxUSE_MENUS -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/ObjcRef.h" -#include "wx/cocoa/NSMenu.h" - -#import -#include "wx/cocoa/objc/NSMenu.h" - -// ============================================================================ -// @class WXNSMenu -// ============================================================================ - -@implementation WXNSMenu : NSMenu - -- (void)dealloc -{ - wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa(self); - if(menu) - menu->Cocoa_dealloc(); - [super dealloc]; -} - -@end // WXNSMenu -WX_IMPLEMENT_GET_OBJC_CLASS(WXNSMenu,NSMenu) - -// ============================================================================ -// @class wxNSMenuNotificationObserver -// ============================================================================ -@interface wxNSMenuNotificationObserver : NSObject -{ -} - -- (void)menuDidAddItem: (NSNotification *)notification; -- (void)menuDidChangeItem: (NSNotification *)notification; -- (void)menuDidRemoveItem: (NSNotification *)notification; -- (void)menuDidSendAction: (NSNotification *)notification; -- (void)menuWillSendAction: (NSNotification *)notification; -@end // interface wxNSMenuNotificationObserver -WX_DECLARE_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject) - -@implementation wxNSMenuNotificationObserver : NSObject - -- (void)menuDidAddItem: (NSNotification *)notification -{ - wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]); - wxCHECK_RET(menu,wxT("menuDidAddItem received but no wxMenu exists")); - menu->CocoaNotification_menuDidAddItem(notification); -} - -- (void)menuDidChangeItem: (NSNotification *)notification -{ - wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]); - wxCHECK_RET(menu,wxT("menuDidChangeItem received but no wxMenu exists")); - menu->CocoaNotification_menuDidChangeItem(notification); -} - -- (void)menuDidRemoveItem: (NSNotification *)notification -{ - wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]); - wxCHECK_RET(menu,wxT("menuDidRemoveItem received but no wxMenu exists")); - menu->CocoaNotification_menuDidRemoveItem(notification); -} - -- (void)menuDidSendAction: (NSNotification *)notification -{ - wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]); - wxCHECK_RET(menu,wxT("menuDidSendAction received but no wxMenu exists")); - menu->CocoaNotification_menuDidSendAction(notification); -} - -- (void)menuWillSendAction: (NSNotification *)notification -{ - wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]); - wxCHECK_RET(menu,wxT("menuWillSendAction received but no wxMenu exists")); - menu->CocoaNotification_menuWillSendAction(notification); -} - -@end // implementation wxNSMenuNotificationObserver -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject) - -// ======================================================================== -// wxCocoaNSMenu -// ======================================================================== -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSMenu) - -// New CF-retained observer (this should have been using wxObjcAutoRefFromAlloc to begin with) -static wxObjcAutoRefFromAlloc s_cocoaNSMenuObserver([[WX_GET_OBJC_CLASS(wxNSMenuNotificationObserver) alloc] init]); -// For compatibility with old code -struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = s_cocoaNSMenuObserver; - -void wxCocoaNSMenu::AssociateNSMenu(WX_NSMenu cocoaNSMenu, unsigned int flags) -{ - if(cocoaNSMenu) - { - sm_cocoaHash.insert(wxCocoaNSMenuHash::value_type(cocoaNSMenu,this)); - if(flags&OBSERVE_DidAddItem) - [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(menuDidAddItem:) name:NSMenuDidAddItemNotification object:cocoaNSMenu]; - if(flags&OBSERVE_DidChangeItem) - [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(menuDidChangeItem:) name:NSMenuDidChangeItemNotification object:cocoaNSMenu]; - if(flags&OBSERVE_DidRemoveItem) - [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(menuDidRemoveItem:) name:NSMenuDidRemoveItemNotification object:cocoaNSMenu]; - if(flags&OBSERVE_DidSendAction) - [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(menuDidSendAction:) name:NSMenuDidSendActionNotification object:cocoaNSMenu]; - if(flags&OBSERVE_WillSendAction) - [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(menuWillSendAction:) name:NSMenuWillSendActionNotification object:cocoaNSMenu]; - } -} - -void wxCocoaNSMenu::DisassociateNSMenu(WX_NSMenu cocoaNSMenu) -{ - if(cocoaNSMenu) - { - sm_cocoaHash.erase(cocoaNSMenu); - [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:NSMenuDidAddItemNotification object:cocoaNSMenu]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:NSMenuDidChangeItemNotification object:cocoaNSMenu]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:NSMenuDidRemoveItemNotification object:cocoaNSMenu]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:NSMenuDidSendActionNotification object:cocoaNSMenu]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:NSMenuWillSendActionNotification object:cocoaNSMenu]; - } -} - -#endif // wxUSE_MENUS diff --git a/src/cocoa/NSPanel.mm b/src/cocoa/NSPanel.mm deleted file mode 100644 index fad9d60b22..0000000000 --- a/src/cocoa/NSPanel.mm +++ /dev/null @@ -1,31 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSPanel.mm -// Purpose: wxCocoaNSPanel -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/NSPanel.h" - -#import - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSPanel) diff --git a/src/cocoa/NSScroller.mm b/src/cocoa/NSScroller.mm deleted file mode 100644 index ec9c61a2bc..0000000000 --- a/src/cocoa/NSScroller.mm +++ /dev/null @@ -1,59 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSScroller.mm -// Purpose: wxCocoaNSScroller -// Author: David Elliott -// Modified by: -// Created: 2004/04/27 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#include "wx/cocoa/NSScroller.h" -#import - -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSScroller) - -// ============================================================================ -// @class wxNSScrollerTarget -// ============================================================================ -@interface wxNSScrollerTarget : NSObject -{ -} - -- (void)wxNSScrollerAction: (id)sender; -@end // wxNSScrollerTarget -WX_DECLARE_GET_OBJC_CLASS(wxNSScrollerTarget,NSObject) - -@implementation wxNSScrollerTarget : NSObject -- (void)wxNSScrollerAction: (id)sender -{ - wxCocoaNSScroller *scroller = wxCocoaNSScroller::GetFromCocoa(sender); - wxCHECK_RET(scroller,wxT("wxNSScrollerAction received without associated wx object")); - scroller->Cocoa_wxNSScrollerAction(); -} - -@end // implementation wxNSScrollerTarget -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSScrollerTarget,NSObject) - -// ============================================================================ -// class wxCocoaNSScroller -// ============================================================================ -const wxObjcAutoRefFromAlloc wxCocoaNSScroller::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSScrollerTarget) alloc] init]; - -void wxCocoaNSScroller::AssociateNSScroller(WX_NSScroller cocoaNSScroller) -{ - if(cocoaNSScroller) - { - sm_cocoaHash.insert(wxCocoaNSScrollerHash::value_type(cocoaNSScroller,this)); - [cocoaNSScroller setTarget: sm_cocoaTarget]; - [cocoaNSScroller setAction: @selector(wxNSScrollerAction:)]; - } -} - diff --git a/src/cocoa/NSSlider.mm b/src/cocoa/NSSlider.mm deleted file mode 100644 index 5ff6ac1bc6..0000000000 --- a/src/cocoa/NSSlider.mm +++ /dev/null @@ -1,168 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSSlider.mm -// Purpose: wxCocoaNSSlider class -// Author: Mark Oxenham -// Modified by: David Elliott -// Created: 2007/08/10 -// Copyright: (c) 2007 Software 2000 Ltd. All rights reserved. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/NSSlider.h" - -#import -#import -#import -#include "wx/cocoa/objc/NSSlider.h" - -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSSlider) - -class wxCocoaNSSliderLastSelectorChanger -{ -public: - wxCocoaNSSliderLastSelectorChanger(SEL newSelector) - { - m_savedResponderSelector = wxCocoaNSSlider::sm_lastResponderSelector; - wxCocoaNSSlider::sm_lastResponderSelector = newSelector; - } - ~wxCocoaNSSliderLastSelectorChanger() - { - wxCocoaNSSlider::sm_lastResponderSelector = m_savedResponderSelector; - } -private: - SEL m_savedResponderSelector; -// Don't allow any default or copy construction - wxCocoaNSSliderLastSelectorChanger(); - wxCocoaNSSliderLastSelectorChanger(const wxCocoaNSSliderLastSelectorChanger&); - void operator=(const wxCocoaNSSliderLastSelectorChanger&); -}; - -// ============================================================================ -// @class WXNSSlider -// ============================================================================ - -@implementation WXNSSlider : NSSlider - -// Override to ensure that WXNSSlider gets created with a WXNSSliderCell -+ (Class)cellClass -{ - return [WX_GET_OBJC_CLASS(WXNSSliderCell) class]; -} - -// The following methods are all NSResponder methods which NSSlider responds -// to in order to change its state and send the action message. We override -// them simply to record which one was called. This allows code listening -// only for the action message to determine what caused the action. -// Note that this is perfectly fine being a global because Cocoa processes -// events synchronously and only in the main thread. - -- (void)keyDown:(NSEvent *)theEvent -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super keyDown:theEvent]; -} - -- (void)moveUp:(id)sender -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super moveUp:sender]; -} - -- (void)moveDown:(id)sender -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super moveDown:sender]; -} - -- (void)moveLeft:(id)sender -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super moveLeft:sender]; -} - -- (void)moveRight:(id)sender -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super moveRight:sender]; -} - -- (void)pageUp:(id)sender -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super pageUp:sender]; -} - -- (void)pageDown:(id)sender -{ - wxCocoaNSSliderLastSelectorChanger savedSelector(_cmd); - [super pageDown:sender]; -} - -@end -WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSlider,NSSlider) - -// ============================================================================ -// @class WXNSSliderCell -// ============================================================================ - -@implementation WXNSSliderCell : NSSliderCell -- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView -{ - BOOL result = [super startTrackingAt:startPoint inView:controlView]; - - wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView); - if(slider) - slider->CocoaNotification_startTracking(NULL); - - return result; -} - -- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView -{ - BOOL result = [super continueTracking:lastPoint at:currentPoint inView:controlView]; - - wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView); - if(slider) - slider->CocoaNotification_continueTracking(NULL); - - return result; -} - -- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag -{ - [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag]; - - wxCocoaNSSlider *slider = wxCocoaNSSlider::GetFromCocoa(controlView); - if(slider) - slider->CocoaNotification_stopTracking(NULL); -} -@end -WX_IMPLEMENT_GET_OBJC_CLASS(WXNSSliderCell,NSSliderCell) - -// ============================================================================ -// class wxCocoaNSSlider -// ============================================================================ - -SEL wxCocoaNSSlider::sm_lastResponderSelector; - -void wxCocoaNSSlider::AssociateNSSlider(WX_NSSlider cocoaNSSlider) -{ - if(cocoaNSSlider) - { - sm_cocoaHash.insert(wxCocoaNSSliderHash::value_type(cocoaNSSlider,this)); - } -} - -void wxCocoaNSSlider::DisassociateNSSlider(WX_NSSlider cocoaNSSlider) -{ - if(cocoaNSSlider) - { - sm_cocoaHash.erase(cocoaNSSlider); - } -} diff --git a/src/cocoa/NSTabView.mm b/src/cocoa/NSTabView.mm deleted file mode 100644 index 16e1ff3f4a..0000000000 --- a/src/cocoa/NSTabView.mm +++ /dev/null @@ -1,76 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSTabView.mm -// Purpose: wxCocoaNSTabView -// Author: David Elliott -// Modified by: -// Created: 2004/04/08 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP -#endif // WX_PRECOMP - -#include "wx/cocoa/NSTabView.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#include - -// ============================================================================ -// @class wxNSTabViewDelegate -// ============================================================================ -@interface wxNSTabViewDelegate : NSObject -{ -} - -- (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem; -- (BOOL)tabView:(NSTabView*)tabView shouldSelectTabViewItem:(NSTabViewItem*)tabViewItem; -@end // interface wxNSTabViewDelegate : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxNSTabViewDelegate,NSObject) - -@implementation wxNSTabViewDelegate : NSObject -- (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(NSTabViewItem*)tabViewItem -{ - wxCocoaNSTabView *notebook = wxCocoaNSTabView::GetFromCocoa(tabView); - wxCHECK_RET(notebook, wxT("This delegate is for use only with wxCocoa NSTabViews")); - notebook->CocoaDelegate_tabView_didSelectTabViewItem(tabViewItem); - -} - -- (BOOL)tabView:(NSTabView*)tabView shouldSelectTabViewItem:(NSTabViewItem*)tabViewItem -{ - wxCocoaNSTabView *notebook = wxCocoaNSTabView::GetFromCocoa(tabView); - wxCHECK_MSG(notebook, true, wxT("This delegate is for use only with wxCocoa NSTabViews")); - return notebook->CocoaDelegate_tabView_shouldSelectTabViewItem(tabViewItem); -} - -@end // implementation wxNSTabViewDelegate : NSObject -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSTabViewDelegate,NSObject) - -// ============================================================================ -// class wxCocoaNSTabView -// ============================================================================ -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSTabView) - -wxObjcAutoRefFromAlloc wxCocoaNSTabView::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSTabViewDelegate) alloc] init]; - -void wxCocoaNSTabView::AssociateNSTabView(WX_NSTabView cocoaNSTabView) -{ - if(cocoaNSTabView) - { - sm_cocoaHash.insert(wxCocoaNSTabViewHash::value_type(cocoaNSTabView,this)); - [cocoaNSTabView setDelegate: sm_cocoaDelegate]; - } -} - -void wxCocoaNSTabView::DisassociateNSTabView(WX_NSTabView cocoaNSTabView) -{ - if(cocoaNSTabView) - { - [cocoaNSTabView setDelegate: nil]; - sm_cocoaHash.erase(cocoaNSTabView); - } -} - diff --git a/src/cocoa/NSTableView.mm b/src/cocoa/NSTableView.mm deleted file mode 100644 index 1a19dc4d71..0000000000 --- a/src/cocoa/NSTableView.mm +++ /dev/null @@ -1,56 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSTableView.mm -// Purpose: wxCocoaNSTableView / wxCocoaNSTableDataSource -// Author: David Elliott -// Modified by: -// Created: 2003/08/05 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/NSTableDataSource.h" -#include "wx/cocoa/NSTableView.h" -#import - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSTableView) - -// ============================================================================ -// @class wxCocoaNSTableDataSource -// ============================================================================ -@implementation wxCocoaNSTableDataSource : NSObject - -- (int)numberOfRowsInTableView: (NSTableView *)tableView -{ - wxCocoaNSTableView *wxView = wxCocoaNSTableView::GetFromCocoa(tableView); - wxCHECK_MSG(wxView, 0, wxT("No associated wx object")); - return wxView->CocoaDataSource_numberOfRows(); -} - -- (id)tableView:(NSTableView *)tableView - objectValueForTableColumn: (NSTableColumn *)tableColumn - row: (int)rowIndex -{ - wxCocoaNSTableView *wxView = wxCocoaNSTableView::GetFromCocoa(tableView); - wxCHECK_MSG(wxView, nil, wxT("No associated wx object")); - return wxView->CocoaDataSource_objectForTableColumn(tableColumn,rowIndex); -} - -@end // implementation wxCocoaNSTableDataSource -WX_IMPLEMENT_GET_OBJC_CLASS(wxCocoaNSTableDataSource,NSObject) - diff --git a/src/cocoa/NSTextField.mm b/src/cocoa/NSTextField.mm deleted file mode 100644 index 989491ff50..0000000000 --- a/src/cocoa/NSTextField.mm +++ /dev/null @@ -1,26 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSTextField.mm -// Purpose: wxCocoaNSTextField -// Author: David Elliott -// Modified by: -// Created: 2003/01/31 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP -#endif // WX_PRECOMP - -#include "wx/cocoa/NSTextField.h" - -WX_IMPLEMENT_OBJC_INTERFACE(NSTextField) - diff --git a/src/cocoa/NSView.mm b/src/cocoa/NSView.mm deleted file mode 100644 index 5852a8575c..0000000000 --- a/src/cocoa/NSView.mm +++ /dev/null @@ -1,221 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSView.mm -// Purpose: wxCocoaNSView -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/window.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/objc/objc_uniquifying.h" -#include "wx/cocoa/NSView.h" - -#import -#import -#include "wx/cocoa/objc/NSView.h" -#include "wx/cocoa/ObjcRef.h" - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSView) - -void wxCocoaNSView::AssociateNSView(WX_NSView cocoaNSView) -{ - if(cocoaNSView) - { - sm_cocoaHash.insert(wxCocoaNSViewHash::value_type(cocoaNSView,this)); - [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(notificationFrameChanged:) name:@"NSViewFrameDidChangeNotification" object:cocoaNSView]; - [cocoaNSView setPostsFrameChangedNotifications: YES]; - } -} - -void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView) -{ - if(cocoaNSView) - { - sm_cocoaHash.erase(cocoaNSView); - [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView]; - } -} - -// ============================================================================ -// @class WXNSView -// ============================================================================ - -@implementation WXNSView : NSView - -- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent -{ - bool acceptsFirstMouse = false; - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if(!win || !win->Cocoa_acceptsFirstMouse(acceptsFirstMouse, theEvent)) - acceptsFirstMouse = [super acceptsFirstMouse:theEvent]; - return acceptsFirstMouse; -} - -- (void)drawRect: (NSRect)rect -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_drawRect(rect) ) - [super drawRect:rect]; -} - -- (void)mouseDown:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_mouseDown(theEvent) ) - [super mouseDown:theEvent]; -} - -- (void)mouseDragged:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_mouseDragged(theEvent) ) - [super mouseDragged:theEvent]; -} - -- (void)mouseUp:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_mouseUp(theEvent) ) - [super mouseUp:theEvent]; -} - -- (void)mouseMoved:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_mouseMoved(theEvent) ) - [super mouseMoved:theEvent]; -} - -- (void)mouseEntered:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_mouseEntered(theEvent) ) - [super mouseEntered:theEvent]; -} - -- (void)mouseExited:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_mouseExited(theEvent) ) - [super mouseExited:theEvent]; -} - -- (void)rightMouseDown:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_rightMouseDown(theEvent) ) - [super rightMouseDown:theEvent]; -} - -- (void)rightMouseDragged:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_rightMouseDragged(theEvent) ) - [super rightMouseDragged:theEvent]; -} - -- (void)rightMouseUp:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_rightMouseUp(theEvent) ) - [super rightMouseUp:theEvent]; -} - -- (void)otherMouseDown:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_otherMouseDown(theEvent) ) - [super otherMouseDown:theEvent]; -} - -- (void)otherMouseDragged:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_otherMouseDragged(theEvent) ) - [super otherMouseDragged:theEvent]; -} - -- (void)otherMouseUp:(NSEvent *)theEvent -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_otherMouseUp(theEvent) ) - [super otherMouseUp:theEvent]; -} - -- (void)resetCursorRects -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_resetCursorRects() ) - [super resetCursorRects]; -} - -- (void)viewDidMoveToWindow -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_viewDidMoveToWindow() ) - [super viewDidMoveToWindow]; -} - -- (void)viewWillMoveToWindow:(NSWindow *)newWindow -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); - if( !win || !win->Cocoa_viewWillMoveToWindow(newWindow) ) - [super viewWillMoveToWindow:newWindow]; -} - -@end // implementation WXNSView -WX_IMPLEMENT_GET_OBJC_CLASS(WXNSView,NSView) - -// ============================================================================ -// @class wxNSViewNotificationObserver -// ============================================================================ - -@interface wxNSViewNotificationObserver : NSObject -{ -} - -- (void)notificationFrameChanged: (NSNotification *)notification; -- (void)synthesizeMouseMovedForView: (NSView *)theView; -@end // interface wxNSViewNotificationObserver -WX_DECLARE_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject) - -@implementation wxNSViewNotificationObserver : NSObject - -- (void)notificationFrameChanged: (NSNotification *)notification; -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([notification object]); - wxCHECK_RET(win,wxT("notificationFrameChanged received but no wxWindow exists")); - win->Cocoa_FrameChanged(); -} - -- (void)synthesizeMouseMovedForView: (NSView *)theView -{ - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(theView); - wxCHECK_RET(win,wxT("synthesizeMouseMovedForView received but no wxWindow exists")); - win->Cocoa_synthesizeMouseMoved(); -} - -@end // implementation wxNSViewNotificationObserver -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject) - -// New CF-retained observer (this should have been using wxObjcAutoRefFromAlloc to begin with) -wxObjcAutoRefFromAlloc s_cocoaNSViewObserver([[WX_GET_OBJC_CLASS(wxNSViewNotificationObserver) alloc] init]); -// For compatibility with old code -id wxCocoaNSView::sm_cocoaObserver = s_cocoaNSViewObserver; diff --git a/src/cocoa/NSWindow.mm b/src/cocoa/NSWindow.mm deleted file mode 100644 index 514a35cade..0000000000 --- a/src/cocoa/NSWindow.mm +++ /dev/null @@ -1,241 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/NSWindow.mm -// Purpose: wxCocoaNSWindow -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/menuitem.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/NSWindow.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import -#import -#include "wx/cocoa/objc/NSWindow.h" - -// ============================================================================ -// @class wxNSWindowDelegate -// ============================================================================ -@interface wxNSWindowDelegate : NSObject -{ - wxCocoaNSWindow *m_wxCocoaInterface; -} - -- (id)init; -- (void)setWxCocoaInterface: (wxCocoaNSWindow *)wxCocoaInterface; -- (wxCocoaNSWindow *)wxCocoaInterface; - -// Delegate message handlers -- (void)windowDidBecomeKey: (NSNotification *)notification; -- (void)windowDidResignKey: (NSNotification *)notification; -- (void)windowDidBecomeMain: (NSNotification *)notification; -- (void)windowDidResignMain: (NSNotification *)notification; -- (BOOL)windowShouldClose: (id)sender; -- (void)windowWillClose: (NSNotification *)notification; - -// Menu item handlers -- (void)wxMenuItemAction: (NSMenuItem *)menuItem; -- (BOOL)validateMenuItem: (NSMenuItem *)menuItem; -@end //interface wxNSWindowDelegate -WX_DECLARE_GET_OBJC_CLASS(wxNSWindowDelegate,NSObject) - -@implementation wxNSWindowDelegate : NSObject - -- (id)init -{ - m_wxCocoaInterface = NULL; - return [super init]; -} - -- (void)setWxCocoaInterface: (wxCocoaNSWindow *)wxCocoaInterface -{ - m_wxCocoaInterface = wxCocoaInterface; -} - -- (wxCocoaNSWindow *)wxCocoaInterface -{ - return m_wxCocoaInterface; -} - -// Delegate message handlers -- (void)windowDidBecomeKey: (NSNotification *)notification -{ - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); - wxASSERT(win==m_wxCocoaInterface); - wxCHECK_RET(win,wxT("notificationDidBecomeKey received but no wxWindow exists")); - win->CocoaDelegate_windowDidBecomeKey(); -} - -- (void)windowDidResignKey: (NSNotification *)notification -{ - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); - wxASSERT(win==m_wxCocoaInterface); - wxCHECK_RET(win,wxT("notificationDidResignKey received but no wxWindow exists")); - win->CocoaDelegate_windowDidResignKey(); -} - -- (void)windowDidBecomeMain: (NSNotification *)notification -{ - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); - wxASSERT(win==m_wxCocoaInterface); - wxCHECK_RET(win,wxT("notificationDidBecomeMain received but no wxWindow exists")); - win->CocoaDelegate_windowDidBecomeMain(); -} - -- (void)windowDidResignMain: (NSNotification *)notification -{ - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); - wxASSERT(win==m_wxCocoaInterface); - wxCHECK_RET(win,wxT("notificationDidResignMain received but no wxWindow exists")); - win->CocoaDelegate_windowDidResignMain(); -} - -- (BOOL)windowShouldClose: (id)sender -{ - wxLogTrace(wxTRACE_COCOA,wxT("windowShouldClose")); - wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender); - wxASSERT(tlw==m_wxCocoaInterface); - if(tlw && !tlw->CocoaDelegate_windowShouldClose()) - { - wxLogTrace(wxTRACE_COCOA,wxT("Window will not be closed")); - return NO; - } - wxLogTrace(wxTRACE_COCOA,wxT("Window will be closed")); - return YES; -} - -- (void)windowWillClose: (NSNotification *)notification -{ - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); - wxASSERT(win==m_wxCocoaInterface); - wxCHECK_RET(win,wxT("windowWillClose received but no wxWindow exists")); - win->CocoaDelegate_windowWillClose(); -} - -// Menu item handlers -- (void)wxMenuItemAction: (NSMenuItem *)sender -{ - wxASSERT(m_wxCocoaInterface); - m_wxCocoaInterface->CocoaDelegate_wxMenuItemAction(sender); -} - -- (BOOL)validateMenuItem: (NSMenuItem *)sender -{ - wxASSERT(m_wxCocoaInterface); - return m_wxCocoaInterface->CocoaDelegate_validateMenuItem(sender); -} - -@end //implementation wxNSWindowDelegate -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSWindowDelegate,NSObject) - -// ============================================================================ -// class wxCocoaNSWindow -// ============================================================================ - -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow) - -wxCocoaNSWindow::wxCocoaNSWindow(wxTopLevelWindowCocoa *tlw) -: m_wxTopLevelWindowCocoa(tlw) -{ - m_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSWindowDelegate) alloc] init]; - [m_cocoaDelegate setWxCocoaInterface: this]; -} - -wxCocoaNSWindow::~wxCocoaNSWindow() -{ - [m_cocoaDelegate setWxCocoaInterface: NULL]; - [m_cocoaDelegate release]; -} - -void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow) -{ - if(cocoaNSWindow) - { - [cocoaNSWindow setReleasedWhenClosed: NO]; - sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this)); - [cocoaNSWindow setDelegate: m_cocoaDelegate]; - } -} - -void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow) -{ - if(cocoaNSWindow) - { - [cocoaNSWindow setDelegate: nil]; - sm_cocoaHash.erase(cocoaNSWindow); - } -} - -wxMenuBar* wxCocoaNSWindow::GetAppMenuBar(wxCocoaNSWindow *win) -{ - return NULL; -} - -// ============================================================================ -// @class WXNSWindow -// ============================================================================ -@implementation WXNSWindow : NSWindow - -- (BOOL)canBecomeKeyWindow -{ - bool canBecome = false; - wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); - if(!tlw || !tlw->Cocoa_canBecomeKeyWindow(canBecome)) - canBecome = [super canBecomeKeyWindow]; - return canBecome; -} - -- (BOOL)canBecomeMainWindow -{ - bool canBecome = false; - wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); - if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome)) - canBecome = [super canBecomeMainWindow]; - return canBecome; -} - -@end // implementation WXNSWindow -WX_IMPLEMENT_GET_OBJC_CLASS(WXNSWindow,NSWindow) - -// ============================================================================ -// @class WXNSPanel -// ============================================================================ -@implementation WXNSPanel : NSPanel - -- (BOOL)canBecomeKeyWindow -{ - bool canBecome = false; - wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); - if(!tlw || !tlw->Cocoa_canBecomeKeyWindow(canBecome)) - canBecome = [super canBecomeKeyWindow]; - return canBecome; -} - -- (BOOL)canBecomeMainWindow -{ - bool canBecome = false; - wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); - if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome)) - canBecome = [super canBecomeMainWindow]; - return canBecome; -} - -@end // implementation WXNSPanel -WX_IMPLEMENT_GET_OBJC_CLASS(WXNSPanel,NSPanel) diff --git a/src/cocoa/ObjcRef.mm b/src/cocoa/ObjcRef.mm deleted file mode 100644 index 0d0815b2eb..0000000000 --- a/src/cocoa/ObjcRef.mm +++ /dev/null @@ -1,24 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/ObjcRef.mm -// Purpose: wxObjcAutoRefBase implementation -// Author: David Elliott -// Modified by: -// Created: 2004/03/28 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/cocoa/ObjcRef.h" - -#include - -/*static*/ struct objc_object* wxObjcAutoRefBase::ObjcRetain(struct objc_object* obj) -{ - return [obj retain]; -} - -/*static*/ void wxObjcAutoRefBase::ObjcRelease(struct objc_object* obj) -{ - [obj release]; -} - diff --git a/src/cocoa/app.mm b/src/cocoa/app.mm deleted file mode 100644 index c61ee29f06..0000000000 --- a/src/cocoa/app.mm +++ /dev/null @@ -1,511 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/app.mm -// Purpose: wxApp -// Author: David Elliott -// Modified by: -// Created: 2002/11/27 -// Copyright: (c) David Elliott -// Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/app.h" - -#ifndef WX_PRECOMP - #include "wx/intl.h" - #include "wx/log.h" - #include "wx/module.h" -#endif - -#include "wx/cocoa/ObjcRef.h" -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/mbarman.h" -#include "wx/cocoa/NSApplication.h" - -#include "wx/cocoa/dc.h" - -#import -#import -#import -#import -#import -#import -#import - -bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin - -// wxNSApplicationObserver singleton. -static wxObjcAutoRefFromAlloc sg_cocoaAppObserver = [[WX_GET_OBJC_CLASS(wxNSApplicationObserver) alloc] init]; - -// ======================================================================== -// wxNSApplicationDelegate -// ======================================================================== -@implementation wxNSApplicationDelegate : NSObject - -// NOTE: Terminate means that the event loop does NOT return and thus -// cleanup code doesn't properly execute. Furthermore, wxWidgets has its -// own exit on frame delete mechanism. -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication -{ - return NO; -} - -@end // implementation wxNSApplicationDelegate : NSObject -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationDelegate,NSObject) - -// ======================================================================== -// wxNSApplicationObserver -// ======================================================================== -@implementation wxNSApplicationObserver : NSObject - -- (void)applicationWillBecomeActive:(NSNotification *)notification -{ - wxTheApp->CocoaDelegate_applicationWillBecomeActive(); -} - -- (void)applicationDidBecomeActive:(NSNotification *)notification -{ - wxTheApp->CocoaDelegate_applicationDidBecomeActive(); -} - -- (void)applicationWillResignActive:(NSNotification *)notification -{ - wxTheApp->CocoaDelegate_applicationWillResignActive(); -} - -- (void)applicationDidResignActive:(NSNotification *)notification -{ - wxTheApp->CocoaDelegate_applicationDidResignActive(); -} - -- (void)applicationWillUpdate:(NSNotification *)notification; -{ - wxTheApp->CocoaDelegate_applicationWillUpdate(); -} - -- (void)controlTintChanged:(NSNotification *)notification -{ - wxLogDebug(wxT("TODO: send EVT_SYS_COLOUR_CHANGED as appropriate")); -} - -@end // implementation wxNSApplicationObserver : NSObject -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSApplicationObserver,NSObject) - -// ======================================================================== -// wxApp -// ======================================================================== - -// ---------------------------------------------------------------------------- -// wxApp Static member initialization -// ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) - -// ---------------------------------------------------------------------------- -// wxApp initialization/cleanup -// ---------------------------------------------------------------------------- -bool wxApp::Initialize(int& argc, wxChar **argv) -{ - wxAutoNSAutoreleasePool pool; - m_cocoaMainThread = [NSThread currentThread]; - // Mac OS X passes a process serial number command line argument when - // the application is launched from the Finder. This argument must be - // removed from the command line arguments before being handled by the - // application (otherwise applications would need to handle it) - if ( argc > 1 ) - { - static const wxChar *ARG_PSN = wxT("-psn_"); - if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 ) - { - // remove this argument - --argc; - memmove(argv + 1, argv + 2, argc * sizeof(wxChar *)); - } - } - - /* - Cocoa supports -Key value options which set the user defaults key "Key" - to the value "value" Some of them are very handy for debugging like - -NSShowAllViews YES. Cocoa picks these up from the real argv so - our removal of them from the wx copy of it does not affect Cocoa's - ability to see them. - - We basically just assume that any "-NS" option and its following - argument needs to be removed from argv. We hope that user code does - not expect to see -NS options and indeed it's probably a safe bet - since most user code accepting options is probably using the - double-dash GNU-style syntax. - */ - for(int i=1; i < argc; ++i) - { - static const wxChar *ARG_NS = wxT("-NS"); - static const int ARG_NS_LEN = wxStrlen(ARG_NS); - if( wxStrncmp(argv[i], ARG_NS, ARG_NS_LEN) == 0 ) - { - // Only eat this option if it has an argument - if( (i + 1) < argc ) - { - argc -= 2; - memmove(argv + i, argv + i + 2, argc * sizeof(wxChar*)); - // drop back one position so the next run through the loop - // reprocesses the argument at our current index. - --i; - } - } - } - - return wxAppBase::Initialize(argc, argv); -} - -void wxApp::CleanUp() -{ - wxAutoNSAutoreleasePool pool; - - wxCocoaDCImpl::CocoaShutdownTextSystem(); - wxMenuBarManager::DestroyInstance(); - - [[NSNotificationCenter defaultCenter] removeObserver:sg_cocoaAppObserver]; - if(!sm_isEmbedded) - { - [m_cocoaApp setDelegate:nil]; - [m_cocoaAppDelegate release]; - m_cocoaAppDelegate = NULL; - } - - wxAppBase::CleanUp(); -} - -// ---------------------------------------------------------------------------- -// wxApp creation -// ---------------------------------------------------------------------------- -wxApp::wxApp() -{ - m_topWindow = NULL; - - argc = 0; -#if !wxUSE_UNICODE - argv = NULL; -#endif - m_cocoaApp = NULL; - m_cocoaAppDelegate = NULL; -} - -void wxApp::CocoaDelegate_applicationWillBecomeActive() -{ -} - -void wxApp::CocoaDelegate_applicationDidBecomeActive() -{ -} - -void wxApp::CocoaDelegate_applicationWillResignActive() -{ - wxTopLevelWindowCocoa::DeactivatePendingWindow(); -} - -void wxApp::CocoaDelegate_applicationDidResignActive() -{ -} - -bool wxApp::OnInitGui() -{ - wxAutoNSAutoreleasePool pool; - if(!wxAppBase::OnInitGui()) - return false; - - // Create the app using the sharedApplication method - m_cocoaApp = [NSApplication sharedApplication]; - - if(!sm_isEmbedded) - { - // Enable response to application delegate messages - m_cocoaAppDelegate = [[WX_GET_OBJC_CLASS(wxNSApplicationDelegate) alloc] init]; - [m_cocoaApp setDelegate:m_cocoaAppDelegate]; - } - - // Enable response to "delegate" messages on the notification observer - [[NSNotificationCenter defaultCenter] addObserver:sg_cocoaAppObserver - selector:@selector(applicationWillBecomeActive:) - name:NSApplicationWillBecomeActiveNotification object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:sg_cocoaAppObserver - selector:@selector(applicationDidBecomeActive:) - name:NSApplicationDidBecomeActiveNotification object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:sg_cocoaAppObserver - selector:@selector(applicationWillResignActive:) - name:NSApplicationWillResignActiveNotification object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:sg_cocoaAppObserver - selector:@selector(applicationDidResignActive:) - name:NSApplicationDidResignActiveNotification object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:sg_cocoaAppObserver - selector:@selector(applicationWillUpdate:) - name:NSApplicationWillUpdateNotification object:nil]; - - // Enable response to system notifications - [[NSNotificationCenter defaultCenter] addObserver:sg_cocoaAppObserver - selector:@selector(controlTintChanged:) - name:NSControlTintDidChangeNotification object:nil]; - - if(!sm_isEmbedded) - wxMenuBarManager::CreateInstance(); - - wxCocoaDCImpl::CocoaInitializeTextSystem(); - return true; -} - -wxApp::~wxApp() -{ - if(m_cfRunLoopIdleObserver != NULL) - { - // Invalidate the observer which also removes it from the run loop. - CFRunLoopObserverInvalidate(m_cfRunLoopIdleObserver); - // Release the ref as we don't need it anymore. - m_cfRunLoopIdleObserver.reset(); - } -} - -bool wxApp::CallOnInit() -{ -// wxAutoNSAutoreleasePool pool; - return OnInit(); -} - -bool wxApp::OnInit() -{ - if(!wxAppBase::OnInit()) - return false; - - return true; -} - -void wxApp::Exit() -{ - wxApp::CleanUp(); - - wxAppConsole::Exit(); -} - -void wxApp::WakeUpIdle() -{ - /* When called from the main thread the NSAutoreleasePool managed by - the [NSApplication run] method would ordinarily be in place and so - one would think a pool here would be unnecessary. - - However, when called from a different thread there is usually no - NSAutoreleasePool in place because wxThread has no knowledge of - wxCocoa. The pool here is generally only ever going to contain - the NSEvent we create with the factory method. As soon as we add - it to the main event queue with postEvent:atStart: it is retained - and so safe for our pool to release. - */ - wxAutoNSAutoreleasePool pool; - /* NOTE: This is a little heavy handed. What this does is cause an - AppKit NSEvent to be added to NSApplication's queue (which is always - on the main thread). This will cause the main thread runloop to - exit which returns control to nextEventMatchingMask which returns - the event which is then sent with sendEvent: and essentially dropped - since it's not for a window (windowNumber 0) and NSApplication - certainly doesn't understand it. - - With the exception of wxEventLoop::Exit which uses us to cause the - runloop to exit and return to the NSApplication event loop, most - callers only need wx idle to happen, or more specifically only really - need to ensure that ProcessPendingEvents is called which is currently - done without exiting the runloop. - - Be careful if you decide to change the implementation of this method - as wxEventLoop::Exit depends on the current behaviour. - */ - [m_cocoaApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined - location:NSZeroPoint modifierFlags:NSAnyEventMask - timestamp:0 windowNumber:0 context:nil - subtype:0 data1:0 data2:0] atStart:NO]; -} - -extern "C" static void ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info); -extern "C" static void ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) -{ - static_cast(info)->CF_ObserveMainRunLoopBeforeWaiting(observer, activity); -} - -#if 0 -static int sg_cApplicationWillUpdate = 0; -#endif - -/*! - Invoked from the applicationWillUpdate notification observer. See the - NSApplication documentation for the official statement on when this - will be called. Since it can be hard to understand for a Cocoa newbie - I'll try to explain it here as it relates to wxCocoa. - - Basically, we get called from within nextEventMatchingMask if and only - if any user code told the application to send the update notification - (sort of like a request for idle events). However, unlike wx idle events, - this notification is sent quite often, nearly every time through the loop - because nearly every control tells the application to send it. - - Because wx idle events are only supposed to be sent when the event loop - is about to block we instead schedule a function to be called just - before the run loop waits and send the idle events from there. - - It also has the desirable effect of only sending the wx idle events when - the event loop is actually going to block. If the event loop is being - pumped manualy (e.g. like a PeekMessage) then the kCFRunLoopBeforeWaiting - observer never fires. Our Yield() method depends on this because sending - idle events from within Yield would be bad. - - Normally you might think that we could just set the observer up once and - leave it attached. However, this is problematic because our run loop - observer calls user code (the idle handlers) which can actually display - modal dialogs. Displaying a modal dialog causes reentry of the event - loop, usually in a different run loop mode than the main loop (e.g. in - modal-dialog mode instead of default mode). Because we only register the - observer with the run loop mode at the time of this call, it won't be - called from a modal loop. - - We want it to be called and thus we need a new observer. - */ -void wxApp::CocoaDelegate_applicationWillUpdate() -{ - wxLogTrace(wxTRACE_COCOA,wxT("applicationWillUpdate")); - -// CFRunLoopRef cfRunLoop = [[NSRunLoop currentRunLoop] getCFRunLoop]; - CFRunLoopRef cfRunLoop = CFRunLoopGetCurrent(); - wxCFRef cfRunLoopMode(CFRunLoopCopyCurrentMode(cfRunLoop)); - - /* If we have an observer and that observer is for the wrong run loop - mode then invalidate it and release it. - */ - if(m_cfRunLoopIdleObserver != NULL && m_cfObservedRunLoopMode != cfRunLoopMode) - { - CFRunLoopObserverInvalidate(m_cfRunLoopIdleObserver); - m_cfRunLoopIdleObserver.reset(); - } -#if 0 - ++sg_cApplicationWillUpdate; -#endif - /* This will be true either on the first call or when the above code has - invalidated and released the exisiting observer. - */ - if(m_cfRunLoopIdleObserver == NULL) - { - // Enable idle event handling - CFRunLoopObserverContext observerContext = - { 0 - , this - , NULL - , NULL - , NULL - }; - /* NOTE: I can't recall why we don't just let the observer repeat - instead of invalidating itself each time it fires thus requiring - it to be recreated for each shot but there was if I remember - some good (but very obscure) reason for it. - - On the other hand, I could be wrong so don't take that as gospel. - */ - m_cfRunLoopIdleObserver.reset(CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, /*repeats*/FALSE, /*priority*/0, ObserveMainRunLoopBeforeWaiting, &observerContext)); - m_cfObservedRunLoopMode = cfRunLoopMode; - CFRunLoopAddObserver(cfRunLoop, m_cfRunLoopIdleObserver, m_cfObservedRunLoopMode); - } -} - -static inline bool FakeNeedMoreIdle() -{ -#if 0 -// Return true on every 10th call. - static int idleCount = 0; - return ++idleCount % 10; -#else - return false; -#endif -} - -/*! - Called by CFRunLoop just before waiting. This is the appropriate time to - send idle events. Unlike other ports, we don't peek the queue for events - and stop idling if there is one. Instead, if the user requests more idle - events we tell Cocoa to send us an applicationWillUpdate notification - which will cause our observer of that notification to tell CFRunLoop to - call us before waiting which will cause us to be fired again but only - after exhausting the event queue. - - The reason we do it this way is that peeking for an event causes CFRunLoop - to reenter and fire off its timers, observers, and sources which we're - better off avoiding. Doing it this way, we basically let CFRunLoop do the - work of peeking for the next event which is much nicer. - */ -void wxApp::CF_ObserveMainRunLoopBeforeWaiting(CFRunLoopObserverRef observer, int activity) -{ - // Ensure that CocoaDelegate_applicationWillUpdate will recreate us. - // We've already been invalidated by CFRunLoop because we are one-shot. - m_cfRunLoopIdleObserver.reset(); -#if 0 - wxLogTrace(wxTRACE_COCOA,wxT("Idle BEGIN (%d)"), sg_cApplicationWillUpdate); - sg_cApplicationWillUpdate = 0; -#else - wxLogTrace(wxTRACE_COCOA,wxT("Idle BEGIN")); -#endif - if( ProcessIdle() || FakeNeedMoreIdle() ) - { - wxLogTrace(wxTRACE_COCOA, wxT("Idle REQUEST MORE")); - [NSApp setWindowsNeedUpdate:YES]; - } - else - { - wxLogTrace(wxTRACE_COCOA, wxT("Idle END")); - } -} - -/* A note about Cocoa's event loops vs. run loops: - - It's important to understand that Cocoa has a two-level event loop. The - outer level is run by NSApplication and can only ever happen on the main - thread. The nextEventMatchingMask:untilDate:inMode:dequeue: method returns - the next event which is then given to sendEvent: to send it. These - methods are defined in NSApplication and are thus part of AppKit. - - Events (NSEvent) are only sent due to actual user actions like clicking - the mouse or moving the mouse or pressing a key and so on. There are no - paint events; there are no timer events; there are no socket events; there - are no idle events. - - All of those types of "events" have nothing to do with the GUI at all. - That is why Cocoa's AppKit doesn't implement them. Instead, they are - implemented in Foundation's NSRunLoop which on OS X uses CFRunLoop - to do the actual work. - - How NSApplication uses NSRunLoop is rather interesting. Basically, it - interacts with NSRunLoop only from within the nextEventMatchingMask - method. It passes its inMode: argument almost directly to NSRunLoop - and thus CFRunLoop. The run loop then runs (e.g. loops) until it - is told to exit. The run loop calls the callout functions directly. - From within those callout functions the run loop is considered to - be running. Presumably, the AppKit installs a run loop source to - receive messages from the window server over the mach port (like a - socket). For some messages (e.g. need to paint) the AppKit will - call application code like drawRect: without exiting the run loop. - For other messages (ones that can be encapsulated in an NSEvent) - the AppKit tells the run loop to exit which returns control to - the nextEventMatchingMask method which then returns the NSEvent - object. It's important to note that once the runloop has exited - it is no longer considered running and thus if you ask it which - mode it is running in it will return nil. - - When manually pumping the event loop care should be taken to - tell it to run in the correct mode. For instance, if you are - using it to run a modal dialog then you want to run it in - the modal panel run loop mode. AppKit presumably has sources - or timers or observers that specifically don't listen on this - mode. Another interesting mode is the connection reply mode. - This allows Cocoa to wait for a response from a distributed - objects message without firing off user code that may result - in a DO call being made thus recursing. So basically, the - mode is a way for Cocoa to attempt to avoid run loop recursion - but to allow it under certain circumstances. - */ - diff --git a/src/cocoa/bitmap.mm b/src/cocoa/bitmap.mm deleted file mode 100644 index 3ec4e42e8f..0000000000 --- a/src/cocoa/bitmap.mm +++ /dev/null @@ -1,724 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/bitmap.mm -// Purpose: wxBitmap -// Author: David Elliott -// Modified by: -// Created: 2003/07/19 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/bitmap.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/utils.h" - #include "wx/palette.h" - #include "wx/icon.h" - #include "wx/colour.h" - #include "wx/image.h" -#endif //WX_PRECOMP - -#include "wx/xpmdecod.h" -#include "wx/rawbmp.h" - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/ObjcRef.h" - -#import -#import -#import -#import - -IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxBitmapHandlerBase) - -// ======================================================================== -// wxBitmapRefData -// ======================================================================== - -class wxBitmapRefData: public wxGDIRefData -{ - friend class wxBitmap; -public: - wxBitmapRefData(); - wxBitmapRefData( const wxBitmapRefData& data ); - virtual ~wxBitmapRefData(); - - virtual bool IsOk() const { return m_ok; } - -protected: - int m_width; - int m_height; - int m_depth; - bool m_ok; - int m_numColors; - wxPalette m_bitmapPalette; - int m_quality; - WX_NSBitmapImageRep m_cocoaNSBitmapImageRep; - wxMask *m_bitmapMask; // Optional mask -}; - -wxBitmapRefData::wxBitmapRefData() -{ - m_ok = FALSE; - m_width = 0; - m_height = 0; - m_depth = 0; - m_quality = 0; - m_numColors = 0; - m_cocoaNSBitmapImageRep = nil; - m_bitmapMask = NULL; -} - -wxBitmapRefData::wxBitmapRefData( const wxBitmapRefData& data) -{ - wxAutoNSAutoreleasePool pool; - - m_width = data.m_width; - m_height = data.m_height; - m_depth = data.m_depth; - m_ok = data.m_ok; - m_numColors = data.m_numColors; - m_bitmapPalette = data.m_bitmapPalette; - m_quality = data.m_quality; - m_cocoaNSBitmapImageRep = wxGCSafeRetain([[data.m_cocoaNSBitmapImageRep copyWithZone:nil] autorelease]); - m_bitmapMask = data.m_bitmapMask?new wxMask(*data.m_bitmapMask):NULL; -} - -wxBitmapRefData::~wxBitmapRefData() -{ - wxGCSafeRelease(m_cocoaNSBitmapImageRep); - m_cocoaNSBitmapImageRep = NULL; - - delete m_bitmapMask; - m_bitmapMask = NULL; -} - -// ======================================================================== -// wxBitmap -// ======================================================================== - -#define M_BITMAPDATA ((wxBitmapRefData *)m_refData) - -IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) - -wxBitmap::wxBitmap() -{ - m_refData = NULL; -} - -wxBitmap::~wxBitmap() -{ -} - -wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits) -{ - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_width = the_width ; - M_BITMAPDATA->m_height = the_height ; - M_BITMAPDATA->m_depth = no_bits ; - M_BITMAPDATA->m_numColors = 0; - - /* TODO: create the bitmap from data */ -} - -wxBitmap::wxBitmap(NSImage* cocoaNSImage) -{ - (void) Create(cocoaNSImage); -} - -wxBitmap::wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep) -{ - (void) Create(cocoaNSBitmapImageRep); -} - -wxBitmap::wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth) -{ - (void) Create(data, type, width, height, depth); -} - -wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) -{ - LoadFile(filename, type); -} - -wxGDIRefData *wxBitmap::CreateGDIRefData() const -{ - return new wxBitmapRefData; -} - -wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const -{ - return new wxBitmapRefData(*(wxBitmapRefData*)data); -} - -WX_NSBitmapImageRep wxBitmap::GetNSBitmapImageRep() -{ - if(!M_BITMAPDATA) - return NULL; - return M_BITMAPDATA->m_cocoaNSBitmapImageRep; -} - -WX_NSImage wxBitmap::GetNSImage(bool useMask) const -{ - if(!IsOk()) - return nil; - NSImage *nsimage = [[[NSImage alloc] - initWithSize:NSMakeSize(GetWidth(), GetHeight())] autorelease]; - if(!nsimage) - return nil; - [nsimage addRepresentation: M_BITMAPDATA->m_cocoaNSBitmapImageRep]; - if(useMask && GetMask()) - { - // Show before/after to prove that the bitmap itself is not changed - // even though we just composited onto the NSImage - wxLogTrace(wxTRACE_COCOA,wxT("Before: bpp=%d"),[M_BITMAPDATA->m_cocoaNSBitmapImageRep bitsPerPixel]); - NSImage *maskImage = [[NSImage alloc] - initWithSize:NSMakeSize(GetWidth(), GetHeight())]; - [maskImage addRepresentation: GetMask()->GetNSBitmapImageRep()]; - [nsimage lockFocus]; - [maskImage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationIn]; - [nsimage unlockFocus]; - [maskImage release]; - wxLogTrace(wxTRACE_COCOA,wxT("After: bpp=%d"),[M_BITMAPDATA->m_cocoaNSBitmapImageRep bitsPerPixel]); - } - return nsimage; -} - -void wxBitmap::SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep) -{ - if(!M_BITMAPDATA) - return; - // NOTE: No checking is done to make sure width/height agree - wxGCSafeRetain(bitmapImageRep); - wxGCSafeRelease(M_BITMAPDATA->m_cocoaNSBitmapImageRep); - M_BITMAPDATA->m_cocoaNSBitmapImageRep = bitmapImageRep; -} - -void wxBitmap::SetWidth(int w) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_width = w; -} - -void wxBitmap::SetHeight(int h) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_height = h; -} - -void wxBitmap::SetDepth(int d) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_depth = d; -} - -void wxBitmap::SetQuality(int q) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_quality = q; -} - -void wxBitmap::SetOk(bool isOk) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_ok = isOk; -} - -void wxBitmap::SetPalette(const wxPalette& palette) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_bitmapPalette = palette ; -} - -void wxBitmap::SetMask(wxMask *mask) -{ - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_bitmapMask = mask ; -} - -wxPalette* wxBitmap::GetPalette() const -{ - if(!m_refData) - return NULL; - return &M_BITMAPDATA->m_bitmapPalette; -} - -wxMask* wxBitmap::GetMask() const -{ - if(!m_refData) - return NULL; - return M_BITMAPDATA->m_bitmapMask; -} - -int wxBitmap::GetDepth() const -{ - if(!m_refData) - return 0; - return M_BITMAPDATA->m_depth; -} - -int wxBitmap::GetWidth() const -{ - if(!m_refData) - return 0; - return M_BITMAPDATA->m_width; -} - -int wxBitmap::GetHeight() const -{ - if(!m_refData) - return 0; - return M_BITMAPDATA->m_height; -} - -bool wxBitmap::Create(int w, int h, int d) -{ - wxAutoNSAutoreleasePool pool; - - UnRef(); - - m_refData = new wxBitmapRefData; - - M_BITMAPDATA->m_width = w; - M_BITMAPDATA->m_height = h; - M_BITMAPDATA->m_depth = d; - - /* TODO: create new bitmap */ - M_BITMAPDATA->m_cocoaNSBitmapImageRep = wxGCSafeRetain([[[NSBitmapImageRep alloc] - initWithBitmapDataPlanes: NULL - pixelsWide: w - pixelsHigh: h - bitsPerSample: 8 - samplesPerPixel: 3 - hasAlpha: NO - isPlanar: NO - colorSpaceName: NSCalibratedRGBColorSpace - bytesPerRow: 0 // NOTE: Contrary to Apple documentation Mac OS - // 10.4 will add padding bytes when 0 is used here - bitsPerPixel: 0] autorelease]); - - wxLogTrace(wxTRACE_COCOA,wxT("M_BITMAPDATA=%p NSBitmapImageRep bitmapData=%p"), M_BITMAPDATA, [M_BITMAPDATA->m_cocoaNSBitmapImageRep bitmapData]); - M_BITMAPDATA->m_ok = true; - M_BITMAPDATA->m_numColors = 0; - M_BITMAPDATA->m_quality = 0; - M_BITMAPDATA->m_bitmapMask = NULL; - - return M_BITMAPDATA->m_ok; -} - -bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type) -{ - wxAutoNSAutoreleasePool pool; - UnRef(); - - m_refData = new wxBitmapRefData; - - NSBitmapImageRep *imageRep = [NSBitmapImageRep - imageRepWithContentsOfFile:wxNSStringWithWxString(filename)]; - - if(imageRep) - { - M_BITMAPDATA->m_width = [imageRep pixelsWide]; - M_BITMAPDATA->m_height = [imageRep pixelsHigh]; - M_BITMAPDATA->m_depth = 24; // FIXME - M_BITMAPDATA->m_ok = true; - M_BITMAPDATA->m_numColors = 0; - M_BITMAPDATA->m_quality = 0; - M_BITMAPDATA->m_cocoaNSBitmapImageRep = wxGCSafeRetain(imageRep); - M_BITMAPDATA->m_bitmapMask = NULL; - return true; - } - wxImage image; - if(!image.LoadFile(filename,type)) - return false; - if(!image.IsOk()) - return false; - *this = wxBitmap(image); - return true; -} - -bool wxBitmap::Create(NSImage* cocoaNSImage) -{ - wxAutoNSAutoreleasePool pool; - NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData:[cocoaNSImage TIFFRepresentation]]; - return Create(bitmapImageRep); -} - -bool wxBitmap::Create(NSBitmapImageRep *imageRep) -{ - UnRef(); - m_refData = new wxBitmapRefData; - if(imageRep != nil) - { - M_BITMAPDATA->m_width = [imageRep pixelsWide]; - M_BITMAPDATA->m_height = [imageRep pixelsHigh]; - M_BITMAPDATA->m_depth = [imageRep bitsPerPixel]; - M_BITMAPDATA->m_ok = true; - M_BITMAPDATA->m_numColors = 0; - M_BITMAPDATA->m_quality = 0; - M_BITMAPDATA->m_cocoaNSBitmapImageRep = wxGCSafeRetain(imageRep); - M_BITMAPDATA->m_bitmapMask = NULL; - return true; - } - else - return false; -} - -bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height, int depth) -{ - UnRef(); - - m_refData = new wxBitmapRefData; - - return false; -} - -bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const -{ - return false; -} - -bool wxBitmap::CopyFromIcon(const wxIcon& icon) -{ - // Pool here due to lack of one during wx init phase - wxAutoNSAutoreleasePool pool; - - UnRef(); - if(!icon.GetNSImage()); - [icon.GetNSImage() lockFocus]; - NSRect imageRect; - imageRect.origin.x = imageRect.origin.y = 0.0; - imageRect.size = [icon.GetNSImage() size]; - NSBitmapImageRep *newBitmapRep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect] autorelease]; - [icon.GetNSImage() unlockFocus]; - if(!newBitmapRep) - return false; - m_refData = new wxBitmapRefData; - M_BITMAPDATA->m_cocoaNSBitmapImageRep = wxGCSafeRetain(newBitmapRep); - M_BITMAPDATA->m_width = [newBitmapRep pixelsWide]; - M_BITMAPDATA->m_height = [newBitmapRep pixelsHigh]; - M_BITMAPDATA->m_depth = [newBitmapRep bitsPerSample]*[newBitmapRep samplesPerPixel]; - M_BITMAPDATA->m_ok = true; - M_BITMAPDATA->m_numColors = 0; - M_BITMAPDATA->m_quality = 0; - M_BITMAPDATA->m_bitmapMask = NULL; - return true; -} - -wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const -{ - wxAutoNSAutoreleasePool pool; - if(!IsOk()) - return wxNullBitmap; - NSImage *nsimage = GetNSImage(false); - - [nsimage lockFocus]; - NSRect imageRect = {{0,0}, [nsimage size]}; - imageRect.origin.x = imageRect.size.width * rect.x / GetWidth(); - imageRect.origin.y = imageRect.size.height * rect.y / GetHeight(); - imageRect.size.width *= static_cast(rect.width) / GetWidth(); - imageRect.size.height *= static_cast(rect.height) / GetHeight(); - - NSBitmapImageRep *newBitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect]; - [nsimage unlockFocus]; - - wxBitmap newBitmap(newBitmapRep); - - return (newBitmap); -} - -wxImage wxBitmap::ConvertToImage() const -{ - wxAutoNSAutoreleasePool pool; - if(!IsOk()) - return /*wxImage(5,5)*/wxNullImage; - NSImage *nsimage = GetNSImage(false /* don't use mask */); - wxImage newImage(M_BITMAPDATA->m_width,M_BITMAPDATA->m_height); - [nsimage lockFocus]; - for(int i=0; i < M_BITMAPDATA->m_width; i++) - { - // Don't let the pool get too big as you'll notice we're creating - // two autoreleased NSColor objects with every iteration. - wxAutoNSAutoreleasePool loopPool; - for(int j=0; j < M_BITMAPDATA->m_height; j++) - { - NSColor *pixelColor = NSReadPixel(NSMakePoint(i,M_BITMAPDATA->m_height - j - 1)); - NSColor *color = [pixelColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - newImage.SetRGB(i,j,int([color redComponent]*255.0), int([color greenComponent]*255.0), int([color blueComponent]*255.0)); - } - } - [nsimage unlockFocus]; - return newImage; -} - -bool wxBitmap::CreateFromImage(const wxImage& image, int depth) -{ - wxAutoNSAutoreleasePool pool; - UnRef(); - - wxCHECK_MSG(image.IsOk(), false, wxT("invalid image")); - wxCHECK_MSG(depth == -1 || depth == 1, false, wxT("invalid bitmap depth")); - - m_refData = new wxBitmapRefData(); - - M_BITMAPDATA->m_width = image.GetWidth(); - M_BITMAPDATA->m_height = image.GetHeight(); - NSBitmapImageRep *bitmapImage = [[[NSBitmapImageRep alloc] - initWithBitmapDataPlanes: NULL - pixelsWide: image.GetWidth() - pixelsHigh: image.GetHeight() - bitsPerSample: 8 - samplesPerPixel: 3 - hasAlpha: NO - isPlanar: NO - colorSpaceName: NSCalibratedRGBColorSpace - bytesPerRow: image.GetWidth()*3 - bitsPerPixel: 0] autorelease]; - - // TODO: Specify bytesPerRow:0 and then use [bitmapImage bytesPerRow] - // so that the rows are aligned suitably for altivec by the OS (Tiger) - const int numBytes = image.GetWidth()*image.GetHeight()*3; - memcpy([bitmapImage bitmapData], image.GetData(), numBytes); - // TODO: Alpha and convert to desired depth - M_BITMAPDATA->m_depth = 24; - M_BITMAPDATA->m_ok = true; - M_BITMAPDATA->m_numColors = 0; - M_BITMAPDATA->m_quality = 0; - M_BITMAPDATA->m_cocoaNSBitmapImageRep = wxGCSafeRetain(bitmapImage); - M_BITMAPDATA->m_bitmapMask = new wxMask(*this,wxColour(image.GetMaskRed(),image.GetMaskGreen(),image.GetMaskBlue())); - return true; -} - -void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) -{ - if(!IsOk()) - return NULL; - - NSBitmapImageRep *bitmapRep = M_BITMAPDATA->m_cocoaNSBitmapImageRep; - if(!bitmapRep) - return NULL; - - if([bitmapRep bitsPerPixel]!=bpp) - { - wxFAIL_MSG( wxT("incorrect bitmap type in wxBitmap::GetRawData()") ); - return NULL; - } - data.m_width = [bitmapRep pixelsWide]; - data.m_height = [bitmapRep pixelsHigh]; - data.m_stride = [bitmapRep bytesPerRow]; - return [bitmapRep bitmapData]; - - // NOTE: It is up to the user to make sure they used the proper - // pixel format class that details what is actually inside the pixels - // We can only check to make sure that the total number of bits per - // pixel are being iterated over properly - // NSBitmapImageRep can contain grayscale or CMYK data and - // wxPixelDataBase doesn't really define the color format -} - -void wxBitmap::UngetRawData(wxPixelDataBase& data) -{ // TODO -} - -// ======================================================================== -// wxMask -// ======================================================================== - -IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) - -wxMask::wxMask() -{ - m_cocoaNSBitmapImageRep = nil; -} - -// Construct a mask from a bitmap and a colour indicating -// the transparent area -wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) -{ - m_cocoaNSBitmapImageRep = nil; - Create(bitmap, colour); -} - -// Construct a mask from a bitmap and a palette index indicating -// the transparent area -wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex) -{ - m_cocoaNSBitmapImageRep = nil; - - Create(bitmap, paletteIndex); -} - -// Construct a mask from a mono bitmap (copies the bitmap). -wxMask::wxMask(const wxBitmap& bitmap) -{ - m_cocoaNSBitmapImageRep = nil; - - Create(bitmap); -} - -// Copy constructor -wxMask::wxMask(const wxMask& src) -: wxObject(src) -, m_cocoaNSBitmapImageRep(wxGCSafeRetain(src.m_cocoaNSBitmapImageRep)) -{ -} - -wxMask::~wxMask() -{ - wxGCSafeRelease(m_cocoaNSBitmapImageRep); -} - -// Create a mask from a mono bitmap (copies the bitmap). -bool wxMask::Create(const wxBitmap& bitmap) -{ -// TODO - wxLogDebug(wxT("Cannot yet create a mask from a mono bitmap")); - return FALSE; -} - -// Create a mask from a bitmap and a palette index indicating -// the transparent area -bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) -{ -// TODO - wxLogDebug(wxT("Cannot yet create a mask from a palette bitmap")); - return FALSE; -} - -template -static bool wxMask_CreateFromBitmapData(PixelData srcData, const wxColour& colour, unsigned char *dstData) -{ - wxCHECK_MSG(dstData,false,wxT("Couldn't access mask data")); - typename PixelData::Iterator p(srcData); - const int nRows = srcData.GetHeight(); - const int nCols = srcData.GetWidth(); - // Total number of bytes per destination column - const int dstRowLength = (nCols+7)/8; - // Number of source columns that fit into a byte in the destination - const int width_aligned = nCols/8*8; - for(int y=0; y0) - *dstByte = 0; - for(int j=0; j<(nCols%8); ++j, ++p) - { - *dstByte += - ( p.Red()!=colour.Red() - || p.Green()!=colour.Green() - || p.Blue()!=colour.Blue() - ) << (7-j); - } - p = rowStart; - p.OffsetY(srcData,1); - } - return true; -} - -// Create a mask from a bitmap and a colour indicating -// the transparent area -bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) -{ - wxAutoNSAutoreleasePool pool; - if(!bitmap.IsOk()) - return false; - int bmpWidth = bitmap.GetWidth(); - int bmpHeight = bitmap.GetHeight(); - int dstRowLength = (bmpWidth+7)/8; - - // Create a bitmap image rep with 1-bit per pixel data representing - // the alpha channel padded such that rows end on byte boundaries - // Since NSBitmapImageRep doesn't have any sort of NSNullColorSpace - // we must have at least one channel of non-alpha data. In order to - // make our life easy, we use planar data which results in two - // separate arrays. We don't need to touch the first because it - // should never be used. The second is the 1-bit "alpha" data. - NSBitmapImageRep *maskRep = [[[NSBitmapImageRep alloc] - initWithBitmapDataPlanes:NULL pixelsWide:bmpWidth - pixelsHigh:bmpHeight bitsPerSample:1 - samplesPerPixel:2 hasAlpha:YES isPlanar:YES - colorSpaceName:NSCalibratedWhiteColorSpace - bytesPerRow:dstRowLength bitsPerPixel:1] autorelease]; - wxCHECK(maskRep,false); - - // We need the source NSBitmapImageRep to detemine its pixel format - NSBitmapImageRep *srcBitmapRep = const_cast(bitmap).GetNSBitmapImageRep(); - wxCHECK_MSG(srcBitmapRep,false,wxT("Can't create mask for an uninitialized bitmap")); - - // Get a pointer to the destination data - unsigned char *dstPlanes[5] = {NULL,NULL,NULL,NULL,NULL}; - [maskRep getBitmapDataPlanes:dstPlanes]; - unsigned char *dstData = dstPlanes[1]; - // The wxImage format (which we use whenever we imported from wxImage) - if([srcBitmapRep bitsPerPixel]==24 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==3 && [srcBitmapRep hasAlpha]==NO) - { - wxPixelData pixelData(const_cast(bitmap)); - wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData), - false, wxT("Unable to access raw data")); - } - // 32-bpp RGBx (x=throw away, no alpha) - else if([srcBitmapRep bitsPerPixel]==32 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==3 && [srcBitmapRep hasAlpha]==NO) - { - typedef wxPixelFormat PixelFormat; - wxPixelData pixelData(const_cast(bitmap)); - wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData), - false, wxT("Unable to access raw data")); - } - // 32-bpp RGBA - else if([srcBitmapRep bitsPerPixel]==32 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==4 && [srcBitmapRep hasAlpha]==YES) - { - wxPixelData pixelData(const_cast(bitmap)); - wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData), - false, wxT("Unable to access raw data")); - } - else if([srcBitmapRep bitsPerPixel]==8 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==1 && [srcBitmapRep hasAlpha]==NO) - // 8-bpp Grayscale, no alpha - { // Force all RGB to access the same grayscale component - typedef wxPixelFormat PixelFormat; - wxPixelData pixelData(const_cast(bitmap)); - wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData), - false, wxT("Unable to access raw data")); - } - else - { wxCHECK_MSG(false,false,wxT("Unimplemented pixel format")); } - - // maskRep was autoreleased in case we had to exit quickly - m_cocoaNSBitmapImageRep = wxGCSafeRetain(maskRep); - return true; -} diff --git a/src/cocoa/bmpbuttn.mm b/src/cocoa/bmpbuttn.mm deleted file mode 100644 index 99e9cbd4b7..0000000000 --- a/src/cocoa/bmpbuttn.mm +++ /dev/null @@ -1,70 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/bmpbuttn.mm -// Purpose: wxBitmapButton -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_BMPBUTTON - -#include "wx/bmpbuttn.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif - -#include "wx/cocoa/autorelease.h" - -#import -#import - -BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxBitmapButton,NSButton,NSControl,NSView) - -bool wxBitmapButton::Create(wxWindow *parent, wxWindowID winid, - const wxBitmap& bitmap, const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid); - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId()); - m_cocoaNSView = NULL; - SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); - // NOTE: YES we want to release this (to match the alloc). - // DoAddChild(this) will retain us again since addSubView doesn't. - [m_cocoaNSView release]; - - [GetNSButton() setBezelStyle: NSRegularSquareBezelStyle]; - [GetNSButton() setImage:bitmap.GetNSImage(true)]; - [GetNSControl() sizeToFit]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxBitmapButton::~wxBitmapButton() -{ - DisassociateNSButton(GetNSButton()); -} - -void wxBitmapButton::Cocoa_wxNSButtonAction(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("YAY!")); - wxCommandEvent event(wxEVT_BUTTON, GetId()); - InitCommandEvent(event); // event.SetEventObject(this); - Command(event); -} - -#endif diff --git a/src/cocoa/brush.mm b/src/cocoa/brush.mm deleted file mode 100644 index b6eb6063b9..0000000000 --- a/src/cocoa/brush.mm +++ /dev/null @@ -1,225 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/brush.mm -// Purpose: wxBrush -// Author: David Elliott -// Modified by: -// Created: 2003/07/03 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/brush.h" - -#ifndef WX_PRECOMP - #include "wx/utils.h" - #include "wx/colour.h" -#endif //WX_PRECOMP - -#import - -class WXDLLEXPORT wxBrushRefData: public wxGDIRefData -{ -public: - wxBrushRefData(const wxColour& colour = wxNullColour, - wxBrushStyle style = wxBRUSHSTYLE_SOLID); - wxBrushRefData(const wxBitmap& stipple); - wxBrushRefData(const wxBrushRefData& data); - virtual ~wxBrushRefData(); - - WX_NSColor GetNSColor(); - void Free(); - - bool operator==(const wxBrushRefData& data) const; - - // accessors - const wxColour& GetColour() const { return m_colour; } - wxBrushStyle GetStyle() const { return m_style; } - wxBitmap *GetStipple() { return &m_stipple; } - - void SetColour(const wxColour& colour) { Free(); m_colour = colour; } - void SetStyle(wxBrushStyle style) { Free(); m_style = style; } - void SetStipple(const wxBitmap& stipple) { Free(); DoSetStipple(stipple); } - -private: - void DoSetStipple(const wxBitmap& stipple); - - WX_NSColor m_cocoaNSColor; - wxBrushStyle m_style; - wxBitmap m_stipple; - wxColour m_colour; - - // no assignment operator, the objects of this class are shared and never - // assigned after being created once - wxBrushRefData& operator=(const wxBrushRefData&); -}; - -#define M_BRUSHDATA ((wxBrushRefData *)m_refData) -IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) - -wxBrushRefData::wxBrushRefData(const wxColour& colour, wxBrushStyle style) -{ - m_cocoaNSColor = NULL; - m_style = style; - m_colour = colour; -} - -wxBrushRefData::wxBrushRefData(const wxBitmap& stipple) -{ - m_cocoaNSColor = NULL; - DoSetStipple(stipple); -} - -wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) -{ - m_cocoaNSColor = data.m_cocoaNSColor; - [m_cocoaNSColor retain]; - m_style = data.m_style; - m_stipple = data.m_stipple; - m_colour = data.m_colour; -} - -wxBrushRefData::~wxBrushRefData() -{ - Free(); -} - -void wxBrushRefData::Free() -{ - [m_cocoaNSColor release]; - m_cocoaNSColor = NULL; -} - -bool wxBrushRefData::operator==(const wxBrushRefData& data) const -{ - // don't compare our NSColor - return m_style == data.m_style && - m_colour == data.m_colour && - m_stipple.IsSameAs(data.m_stipple); -} - -void wxBrushRefData::DoSetStipple(const wxBitmap& stipple) -{ - m_stipple = stipple; - m_style = stipple.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE - : wxBRUSHSTYLE_STIPPLE; -} - -WX_NSColor wxBrushRefData::GetNSColor() -{ - if(!m_cocoaNSColor) - { - switch( m_style ) - { - case wxTRANSPARENT: - m_cocoaNSColor = [[NSColor clearColor] retain]; - break; - case wxSTIPPLE: -// wxBitmap isn't implemented yet -// m_cocoaNSColor = [[NSColor colorWithPatternImage: m_stipple.GetNSImage()] retain]; -// break; - case wxSTIPPLE_MASK_OPAQUE: - // This should be easy when wxBitmap works. -// break; - // The hatch brushes are going to be tricky - case wxBDIAGONAL_HATCH: - case wxCROSSDIAG_HATCH: - case wxFDIAGONAL_HATCH: - case wxCROSS_HATCH: - case wxHORIZONTAL_HATCH: - case wxVERTICAL_HATCH: - default: - case wxSOLID: - NSColor *colour_NSColor = m_colour.GetNSColor(); - if(!colour_NSColor) - colour_NSColor = [NSColor clearColor]; - m_cocoaNSColor = [colour_NSColor copyWithZone:nil]; - break; - } - } - return m_cocoaNSColor; -} - -// Brushes -wxBrush::wxBrush() -{ -} - -wxBrush::~wxBrush() -{ -} - -wxBrush::wxBrush(const wxColour& col, wxBrushStyle style) -{ - m_refData = new wxBrushRefData(col, style); -} - -wxBrush::wxBrush(const wxColour& col, int style) -{ - m_refData = new wxBrushRefData(col, (wxBrushStyle)style); -} - -wxBrush::wxBrush(const wxBitmap& stipple) -{ - m_refData = new wxBrushRefData(stipple); -} - -wxGDIRefData *wxBrush::CreateGDIRefData() const -{ - return new wxBrushRefData; -} - -wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const -{ - return new wxBrushRefData(*(wxBrushRefData *)data); -} - -void wxBrush::SetColour(const wxColour& col) -{ - AllocExclusive(); - M_BRUSHDATA->SetColour(col); -} - -void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) -{ - AllocExclusive(); - M_BRUSHDATA->SetColour(wxColour(r,g,b)); -} - -void wxBrush::SetStyle(wxBrushStyle style) -{ - AllocExclusive(); - M_BRUSHDATA->SetStyle(style); -} - -void wxBrush::SetStipple(const wxBitmap& stipple) -{ - AllocExclusive(); - M_BRUSHDATA->SetStipple(stipple); -} - -wxColour wxBrush::GetColour() const -{ - wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") ); - return M_BRUSHDATA->GetColour(); -} - -wxBrushStyle wxBrush::GetStyle() const -{ - wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") ); - return M_BRUSHDATA->GetStyle(); -} - -wxBitmap *wxBrush::GetStipple() const -{ - wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") ); - return M_BRUSHDATA->GetStipple(); -} - -WX_NSColor wxBrush::GetNSColor() -{ - if(!m_refData) - return [NSColor clearColor]; - return M_BRUSHDATA->GetNSColor(); -} diff --git a/src/cocoa/button.mm b/src/cocoa/button.mm deleted file mode 100644 index ab68639c6e..0000000000 --- a/src/cocoa/button.mm +++ /dev/null @@ -1,123 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/button.mm -// Purpose: wxButton -// Author: David Elliott -// Modified by: -// Created: 2002/12/30 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/button.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif - -#include "wx/stockitem.h" -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import - -IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) -BEGIN_EVENT_TABLE(wxButton, wxButtonBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxButton,NSButton,NSControl,NSView) - -bool wxButton::Create(wxWindow *parent, wxWindowID winid, - const wxString& lbl, const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, const wxString& name) -{ - wxString label((lbl.empty() && wxIsStockID(winid))?wxGetStockLabel(winid):lbl); - - wxAutoNSAutoreleasePool pool; - wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid); - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId()); - m_cocoaNSView = NULL; - SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); - // NOTE: YES we want to release this (to match the alloc). - // DoAddChild(this) will retain us again since addSubView doesn't. - [m_cocoaNSView release]; - - [GetNSButton() setBezelStyle:NSRoundedBezelStyle]; - CocoaSetLabelForObject(label, GetNSButton()); - - do - { - NSTextAlignment mode; - if ((style & wxBU_LEFT) && !(style & wxBU_RIGHT)) - mode = NSLeftTextAlignment; - else if ((style & wxBU_RIGHT) && !(style & wxBU_LEFT)) - mode = NSRightTextAlignment; - else - break; - [GetNSControl() setAlignment:mode]; - } while(0); - - [GetNSControl() sizeToFit]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxButton::~wxButton() -{ - DisassociateNSButton(GetNSButton()); -} - -void wxButton::Cocoa_wxNSButtonAction(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("YAY!")); - wxCommandEvent event(wxEVT_BUTTON, GetId()); - InitCommandEvent(event); // event.SetEventObject(this); - Command(event); -} - -wxString wxButton::GetLabel() const -{ - return wxStringWithNSString([GetNSButton() title]); -} - -void wxButton::SetLabel(const wxString& label) -{ - CocoaSetLabelForObject(label, GetNSButton()); -} - -wxSize wxButton::DoGetBestSize() const -{ - wxSize size = wxButtonBase::DoGetBestSize(); - if(!HasFlag(wxBU_EXACTFIT)) - { - if(size.x<68) - size.x = 68; - } - return size; -} - -static NSRect MakeNSButtonDefaultRect() -{ - // create at (10.0,10.0) with size 20.0x20.0 (just bogus values) - wxObjcAutoRefFromAlloc defaultButton = [[NSButton alloc] - initWithFrame:NSMakeRect(10.0,10.0,20.0,20.0)]; - [static_cast(defaultButton) setBezelStyle:NSRoundedBezelStyle]; - [static_cast(defaultButton) setTitle:@""]; - [static_cast(defaultButton) sizeToFit]; - return [static_cast(defaultButton) frame]; -} - -wxSize wxButtonBase::GetDefaultSize() -{ - static NSRect cocoaRect = MakeNSButtonDefaultRect(); - // Apple HIG says OK/Cancel buttons have default width of 68. - return wxSize(68,(int)ceil(cocoaRect.size.height)); -} diff --git a/src/cocoa/checkbox.mm b/src/cocoa/checkbox.mm deleted file mode 100644 index 603d7362d1..0000000000 --- a/src/cocoa/checkbox.mm +++ /dev/null @@ -1,151 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/checkbox.mm -// Purpose: wxCheckBox -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_CHECKBOX - -#include "wx/checkbox.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import - -BEGIN_EVENT_TABLE(wxCheckBox, wxCheckBoxBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxCheckBox,NSButton,NSControl,NSView) - -bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - m_cocoaNSView = NULL; - SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [GetNSButton() setButtonType: NSSwitchButton]; - [GetNSButton() setAllowsMixedState: Is3State()]; - CocoaSetLabelForObject(label, GetNSButton()); - [GetNSControl() sizeToFit]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxCheckBox::~wxCheckBox() -{ - DisassociateNSButton(GetNSButton()); -} - -void wxCheckBox::SetValue(bool value) -{ - [GetNSButton() setState: value?NSOnState:NSOffState]; -} - -void wxCheckBox::DoSet3StateValue(wxCheckBoxState state) -{ - int cocoaState; - switch(state) - { - case wxCHK_UNCHECKED: - cocoaState = NSOffState; - break; - case wxCHK_CHECKED: - cocoaState = NSOnState; - break; - case wxCHK_UNDETERMINED: - // Base class would have already set state to wxCHK_UNCHECKED -// wxASSERT_MSG(Is3State(),"Use the wxCHK_3STATE style flag"); - cocoaState = NSMixedState; - break; - default: - wxFAIL_MSG(wxT("Invalid state in wxCheckBox::DoSet3StateValue")); - return; - } - [GetNSButton() setState:cocoaState]; -} - -bool wxCheckBox::GetValue() const -{ - int state = [GetNSButton() state]; - wxASSERT_MSG(state!=NSMixedState || Is3State(), - wxT("NSMixedState returned from a 2-state checkbox")); - return state!=NSOffState; -} - -wxCheckBoxState wxCheckBox::DoGet3StateValue() const -{ - switch([GetNSButton() state]) - { - case NSOffState: - return wxCHK_UNCHECKED; - case NSOnState: - return wxCHK_CHECKED; - default: - wxFAIL_MSG(wxT("[NSButton -state] returned an invalid state!")); - case NSMixedState: - // Base class handles this assertion for us -// wxASSERT_MSG(Is3State(),wxT("NSMixedState returned from a 2-state checkbox")); - return wxCHK_UNDETERMINED; - } -} - -void wxCheckBox::Cocoa_wxNSButtonAction(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("Checkbox")); - // What we really want to do is override [NSCell -nextState] to return - // NSOnState in lieu of NSMixedState but this works (aside from the - // very slightly noticeable drawing of - and then a check) -DE - - // Cocoa always allows a 3-state button to transition into - // the mixed/undetermined state by clicking, we don't - if ( !Is3rdStateAllowedForUser() - && [GetNSButton() state] == NSMixedState ) - { - // Cocoa's sequence is on/off/mixed - // skip mixed, go right back to on - [GetNSButton() setState: NSOnState]; - } - wxCommandEvent event(wxEVT_CHECKBOX, GetId()); - InitCommandEvent(event); // event.SetEventObject(this); - event.SetInt(Get3StateValue()); - Command(event); -} - -void wxCheckBox::SetLabel(const wxString& s) -{ - wxAutoNSAutoreleasePool pool; - CocoaSetLabelForObject(s, GetNSButton()); -} - -wxString wxCheckBox::GetLabel() const -{ - wxAutoNSAutoreleasePool pool; - return wxStringWithNSString([GetNSButton() title]); - -} - -#endif // wxUSE_CHECKBOX diff --git a/src/cocoa/checklst.mm b/src/cocoa/checklst.mm deleted file mode 100644 index 2514ffa362..0000000000 --- a/src/cocoa/checklst.mm +++ /dev/null @@ -1,70 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/checklst.mm -// Purpose: wxCheckListBox -// Author: David Elliott -// Modified by: -// Created: 2003/03/18 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_CHECKLISTBOX - -#include "wx/checklst.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" -#endif //WX_PRECOMP - -BEGIN_EVENT_TABLE(wxCheckListBox, wxCheckListBoxBase) -END_EVENT_TABLE() -// WX_IMPLEMENT_COCOA_OWNER(wxCheckListBox,NSButton,NSControl,NSView) - -bool wxCheckListBox::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxCArrayString chs(choices); - - return Create(parent, winid, pos, size, chs.GetCount(), chs.GetStrings(), - style, validator, name); -} - -bool wxCheckListBox::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - int n, const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name) -{ - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - - if(m_parent) - m_parent->CocoaAddChild(this); - return true; -} - -wxCheckListBox::~wxCheckListBox() -{ -} - -bool wxCheckListBox::IsChecked(unsigned int item) const -{ - return false; -} - - -void wxCheckListBox::Check(unsigned int item, bool check) -{ -} - -#endif diff --git a/src/cocoa/choice.mm b/src/cocoa/choice.mm deleted file mode 100644 index 21486ef300..0000000000 --- a/src/cocoa/choice.mm +++ /dev/null @@ -1,208 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/choice.mm -// Purpose: wxChoice -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_CHOICE - -#include "wx/choice.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" - #include "wx/arrstr.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/string.h" -#include "wx/cocoa/autorelease.h" - -#import -#import -#import -#import - -BEGIN_EVENT_TABLE(wxChoice, wxChoiceBase) -END_EVENT_TABLE() -// WX_IMPLEMENT_COCOA_OWNER(wxChoice,NSButton,NSControl,NSView) - -void wxChoice::Init() -{ - m_sortedStrings = NULL; -} - -bool wxChoice::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxCArrayString chs(choices); - - return Create(parent, winid, pos, size, chs.GetCount(), chs.GetStrings(), - style, validator, name); -} - -bool wxChoice::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - int n, const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - - SetNSView([[NSPopUpButton alloc] initWithFrame:MakeDefaultNSRect(size) - pullsDown: NO]); - [m_cocoaNSView release]; - - NSMenu *nsmenu = [(NSPopUpButton*)m_cocoaNSView menu]; - AssociateNSMenu(nsmenu, OBSERVE_DidSendAction); - - if(style&wxCB_SORT) - { - m_sortedStrings = new wxSortedArrayString; - for(int i=0; iAdd(choices[i]); - } - for(unsigned int i=0; i < m_sortedStrings->GetCount(); i++) - { - [nsmenu addItemWithTitle:wxNSStringWithWxString( - m_sortedStrings->Item(i)) - action: nil keyEquivalent:@""]; - } - } - else - { - for(int i=0; iCocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxChoice::~wxChoice() -{ - DisassociateNSMenu([(NSPopUpButton*)m_cocoaNSView menu]); - - Clear(); -} - -void wxChoice::CocoaNotification_menuDidSendAction(WX_NSNotification notification) -{ - NSDictionary *userInfo = [notification userInfo]; - NSMenuItem *menuitem = [userInfo objectForKey:@"MenuItem"]; - int index = [[(NSPopUpButton*)m_cocoaNSView menu] indexOfItem: menuitem]; - int selectedItem = [(NSPopUpButton*)m_cocoaNSView indexOfSelectedItem]; - wxLogTrace(wxTRACE_COCOA,wxT("menuDidSendAction, index=%d, selectedItem=%d"), index, selectedItem); - wxCommandEvent event(wxEVT_CHOICE, m_windowId); - event.SetInt(index); - event.SetEventObject(this); - event.SetString(GetStringSelection()); - HandleWindowEvent(event); -} - -void wxChoice::DoClear() -{ - if(m_sortedStrings) - m_sortedStrings->Clear(); - m_itemsClientData.Clear(); - [(NSPopUpButton*)m_cocoaNSView removeAllItems]; -} - -void wxChoice::DoDeleteOneItem(unsigned int n) -{ - if(m_sortedStrings) - m_sortedStrings->RemoveAt(n); - m_itemsClientData.RemoveAt(n); - [(NSPopUpButton*)m_cocoaNSView removeItemAtIndex:n]; -} - -unsigned int wxChoice::GetCount() const -{ - return (unsigned int)[(NSPopUpButton*)m_cocoaNSView numberOfItems]; -} - -wxString wxChoice::GetString(unsigned int n) const -{ - wxAutoNSAutoreleasePool pool; - return wxStringWithNSString([(NSPopUpButton*)m_cocoaNSView itemTitleAtIndex:n]); -} - -void wxChoice::SetString(unsigned int n, const wxString& title) -{ - NSMenuItem *item = [(NSPopUpButton*)m_cocoaNSView itemAtIndex:n]; - [item setTitle:wxNSStringWithWxString(title)]; -} - -int wxChoice::FindString(const wxString& title, bool bCase) const -{ - // FIXME: use wxItemContainerImmutable::FindString for bCase parameter - return [(NSPopUpButton*)m_cocoaNSView indexOfItemWithTitle: - wxNSStringWithWxString(title)]; -} - -int wxChoice::GetSelection() const -{ - return [(NSPopUpButton*)m_cocoaNSView indexOfSelectedItem]; -} - -int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, - unsigned int pos, - void **clientData, wxClientDataType type) -{ - NSMenu *nsmenu = [(NSPopUpButton*)m_cocoaNSView menu]; - NSMenuItem *item = NULL; - - unsigned int numItems = items.GetCount(); - for ( unsigned int i = 0; i < numItems; ++i, ++pos ) - { - const wxString& str = items[i]; - int idx = m_sortedStrings ? m_sortedStrings->Add(str) : pos; - - item = [nsmenu insertItemWithTitle:wxNSStringWithWxString(str) - action: nil keyEquivalent:@"" atIndex:idx]; - m_itemsClientData.Insert(NULL, idx); - AssignNewItemClientData(idx, clientData, i, type); - } - return [nsmenu indexOfItem:item]; -} - -void wxChoice::DoSetItemClientData(unsigned int n, void *data) -{ - m_itemsClientData[n] = data; -} - -void* wxChoice::DoGetItemClientData(unsigned int n) const -{ - return m_itemsClientData[n]; -} - -void wxChoice::SetSelection(int n) -{ - wxAutoNSAutoreleasePool pool; - [(NSPopUpButton*)m_cocoaNSView selectItemAtIndex:n]; -} - -#endif // wxUSE_CHOICE diff --git a/src/cocoa/clipbrd.mm b/src/cocoa/clipbrd.mm deleted file mode 100644 index c874fdd493..0000000000 --- a/src/cocoa/clipbrd.mm +++ /dev/null @@ -1,67 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/clipbrd.mm -// Purpose: wxClipboard -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_CLIPBOARD - -#ifndef WX_PRECOMP -#endif //WX_PRECOMP -#include "wx/clipbrd.h" - -IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) - -wxClipboard::wxClipboard() -{ -} - -wxClipboard::~wxClipboard() -{ -} - -bool wxClipboard::Open() -{ - return false; -} - -void wxClipboard::Close() -{ -} - -bool wxClipboard::IsOpened() const -{ - return false; -} - -bool wxClipboard::SetData(wxDataObject *data) -{ - return false; -} - -bool wxClipboard::AddData(wxDataObject *data) -{ - return false; -} - -bool wxClipboard::IsSupported(const wxDataFormat& format) -{ - return false; -} - -bool wxClipboard::GetData(wxDataObject& data) -{ - return false; -} - -void wxClipboard::Clear() -{ -} - -#endif //wxUSE_CLIPBOARD diff --git a/src/cocoa/colordlg.mm b/src/cocoa/colordlg.mm deleted file mode 100644 index 8b13789179..0000000000 --- a/src/cocoa/colordlg.mm +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/cocoa/colour.mm b/src/cocoa/colour.mm deleted file mode 100644 index d7607a70d7..0000000000 --- a/src/cocoa/colour.mm +++ /dev/null @@ -1,91 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/colour.mm -// Purpose: wxColour class -// Author: David Elliott -// Modified by: -// Created: 2003/06/17 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/colour.h" - -#ifndef WX_PRECOMP - #include "wx/gdicmn.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/ObjcRef.h" - -#import - -void wxColour::Init() -{ - m_cocoaNSColor = NULL; - m_red = - m_blue = - m_green = 0; -} - -wxColour::wxColour (const wxColour& col) -: m_cocoaNSColor(col.m_cocoaNSColor) -, m_red(col.m_red) -, m_green(col.m_green) -, m_blue(col.m_blue) -, m_alpha(col.m_alpha) -{ - wxGCSafeRetain(m_cocoaNSColor); -} - -wxColour::wxColour( WX_NSColor aColor ) -: m_cocoaNSColor(nil) -{ - Set(aColor); -} - -wxColour& wxColour::operator =(const wxColour& col) -{ - m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor); - m_red = col.m_red; - m_green = col.m_green; - m_blue = col.m_blue; - m_alpha = col.m_alpha; - return *this; -} - -wxColour::~wxColour () -{ - wxGCSafeRelease(m_cocoaNSColor); -} - -void wxColour::InitRGBA(unsigned char r, - unsigned char g, - unsigned char b, - unsigned char a) -{ - wxAutoNSAutoreleasePool pool; - wxGCSafeRelease(m_cocoaNSColor); - m_cocoaNSColor = wxGCSafeRetain([NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0]); - m_red = r; - m_green = g; - m_blue = b; - m_alpha = a; -} - -void wxColour::Set( WX_NSColor aColor ) -{ - wxGCSafeRetain(aColor); - wxGCSafeRelease(m_cocoaNSColor); - m_cocoaNSColor = aColor; - - /* Make a temporary color in RGB format and get the values. Note that - unless the color was actually RGB to begin with it's likely that - these will be fairly bogus. Particulary if the color is a pattern. */ - NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - m_red = (wxUint8) ([rgbColor redComponent] * 255.0); - m_green = (wxUint8) ([rgbColor greenComponent] * 255.0); - m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0); - m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0); -} diff --git a/src/cocoa/combobox.mm b/src/cocoa/combobox.mm deleted file mode 100644 index 9830122661..0000000000 --- a/src/cocoa/combobox.mm +++ /dev/null @@ -1,408 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/combobox.mm -// Purpose: wxComboBox -// Author: Ryan Norton -// Modified by: -// Created: 2005/02/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// -// Impl notes: -// There is no custom data source because doing so unnecessarily sacrifices -// some native autocompletion behaviour (we would have to make our own - -// the SimpleComboBox sample does so in the developer folder that -// comes with OSX). One reason you might want this would be to have -// only one array or be able to display numbers returned by an NSNumber -// from the methods. -// -// One problem though is that wxCB_SORT isn't implemented... -// -// Also, not sure if it is correctly getting text field events since -// I'm using SetNSComboBox instead of SetNSTextField -// -// doWxEvent is really hackish... but since there's only one event... -// -// Ideas for future improvement - other notes: -// Combox w/o wxCB_DROPDOWN doesn't seem to be implementable -//wxCB_READONLY Same as wxCB_DROPDOWN but only the strings specified as the combobox choices can be selected, it is impossible to select (even from a program) a string which is not in the choices list. -//wxCB_SORT is possible with data source -// -// setIntercellSpacing:/setItemHeight: to autoadjust to number of inserted items? -// -/* - //example of autocompletion from SimpleComboBox Example - // ========================================================== -// Combo box data source methods -// ========================================================== - -- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox { - return [genres count]; -} -- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index { - return [genres objectAtIndex:index]; -} -- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)string { - return [genres indexOfObject: string]; -} - -- (NSString *) firstGenreMatchingPrefix:(NSString *)prefix { - NSString *string = nil; - NSString *lowercasePrefix = [prefix lowercaseString]; - NSEnumerator *stringEnum = [genres objectEnumerator]; - while ((string = [stringEnum nextObject])) { - if ([[string lowercaseString] hasPrefix: lowercasePrefix]) return string; - } - return nil; -} - -- (NSString *)comboBox:(NSComboBox *)aComboBox completedString:(NSString *)inputString { - // This method is received after each character typed by the user, because we have checked the "completes" flag for genreComboBox in IB. - // Given the inputString the user has typed, see if we can find a genre with the prefix, and return it as the suggested complete string. - NSString *candidate = [self firstGenreMatchingPrefix: inputString]; - return (candidate ? candidate : inputString); -} -*/ - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" - -#if wxUSE_COMBOBOX - -#include "wx/combobox.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#ifndef WX_PRECOMP - #include "wx/window.h" - #include "wx/log.h" - #include "wx/app.h" -#endif // WX_PRECOMP - -#import -#import -#import - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- -WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSComboBox) - -void wxCocoaNSComboBox::AssociateNSComboBox(WX_NSComboBox cocoaNSComboBox) -{ - if(cocoaNSComboBox) - { - sm_cocoaHash.insert(wxCocoaNSComboBoxHash::value_type(cocoaNSComboBox,this)); - - [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxSelectionDidChangeNotification" object:cocoaNSComboBox]; - [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxSelectionIsChangingNotification" object:cocoaNSComboBox]; - [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxWillDismissNotification" object:cocoaNSComboBox]; - [[NSNotificationCenter defaultCenter] addObserver:(id)cocoaNSComboBox selector:@selector(comboBoxSelectionDidChange:) name:@"NSComboBoxWillPopUpNotification" object:cocoaNSComboBox]; - } -} - -void wxCocoaNSComboBox::DisassociateNSComboBox(WX_NSComboBox cocoaNSComboBox) -{ - if(cocoaNSComboBox) - { - sm_cocoaHash.erase(cocoaNSComboBox); - [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxSelectionDidChangeNotification" object:cocoaNSComboBox]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxSelectionIsChangingNotification" object:cocoaNSComboBox]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxWillDismissNotification" object:cocoaNSComboBox]; - [[NSNotificationCenter defaultCenter] removeObserver:(id)cocoaNSComboBox name:@"NSComboBoxWillPopUpNotification" object:cocoaNSComboBox]; - } -} - -// ============================================================================ -// @class wxPoserNSComboBox -// ============================================================================ -@interface wxPoserNSComboBox : NSComboBox -{ -} - -- (void)comboBoxSelectionDidChange:(NSNotification *)notification; -- (void)comboBoxSelectionIsChanging:(NSNotification *)notification; -- (void)comboBoxWillDismiss:(NSNotification *)notification; -- (void)comboBoxWillPopUp:(NSNotification *)notification; -@end // wxPoserNSComboBox -WX_DECLARE_GET_OBJC_CLASS(wxPoserNSComboBox,NSComboBox) - -//WX_IMPLEMENT_POSER(wxPoserNSComboBox); -@implementation wxPoserNSComboBox : NSComboBox - -- (void)comboBoxSelectionDidChange:(NSNotification *)notification -{ - wxCocoaNSComboBox *win = wxCocoaNSComboBox::GetFromCocoa(self); - win->doWxEvent(wxEVT_COMBOBOX); -} - -- (void)comboBoxSelectionIsChanging:(NSNotification *)notification -{ - //... -} - -- (void)comboBoxWillDismiss:(NSNotification *)notification -{ - //... -} - -- (void)comboBoxWillPopUp:(NSNotification *)notification -{ - //... -} - -@end // implementation wxPoserNSComboBox -WX_IMPLEMENT_GET_OBJC_CLASS(wxPoserNSComboBox,NSComboBox) - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import - -BEGIN_EVENT_TABLE(wxComboBox, wxControl) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxComboBox,NSComboBox,NSTextField,NSView) -WX_IMPLEMENT_COCOA_OWNER(wxComboBox,NSTextField,NSControl,NSView) - -bool wxComboBox::Create(wxWindow *parent, wxWindowID winid, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxCArrayString chs(choices); - - return Create(parent, winid, value, pos, size, chs.GetCount(), - chs.GetStrings(), style, validator, name); -} - -bool wxComboBox::Create(wxWindow *parent, wxWindowID winid, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - int n, const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - - m_cocoaNSView = NULL; - SetNSComboBox([[WX_GET_OBJC_CLASS(wxPoserNSComboBox) alloc] initWithFrame:MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [GetNSTextField() setStringValue:wxNSStringWithWxString(value.c_str())]; - [GetNSControl() sizeToFit]; - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - wxComboBox::Append(n, choices); - - [GetNSComboBox() setCompletes:true]; //autocomplete :) - - return true; -} - -wxComboBox::~wxComboBox() -{ - DisassociateNSComboBox(GetNSComboBox()); -} - -void wxComboBox::doWxEvent(int nEvent) -{ - wxCommandEvent event2(wxEVT_COMBOBOX, GetId() ); - event2.SetInt(GetSelection()); - event2.SetEventObject(this); - event2.SetString(GetStringSelection()); - HandleWindowEvent(event2); - - // For consistency with MSW and GTK, also send a text updated event - // After all, the text is updated when a selection is made - wxCommandEvent TextEvent( wxEVT_TEXT, GetId() ); - TextEvent.SetString( GetStringSelection() ); - TextEvent.SetEventObject( this ); - HandleWindowEvent( TextEvent ); -} - - -void wxComboBox::SetSelection(int nSelection) -{ - [GetNSComboBox() selectItemAtIndex:nSelection]; -} - -wxString wxComboBox::GetStringSelection() -{ - return wxStringWithNSString([GetNSComboBox() objectValueOfSelectedItem]); -} - -void wxComboBox::DoClear() -{ - [GetNSComboBox() removeAllItems]; - m_Datas.Clear(); -} - -void wxComboBox::DoDeleteOneItem(unsigned int n) -{ - [GetNSComboBox() removeItemAtIndex:n]; - m_Datas.RemoveAt(n); -} - -unsigned int wxComboBox::GetCount() const -{ - return (unsigned int)[GetNSComboBox() numberOfItems]; -} - -wxString wxComboBox::GetString(unsigned int nIndex) const -{ - return wxStringWithNSString([GetNSComboBox() itemObjectValueAtIndex:nIndex]); -} - -void wxComboBox::SetString(unsigned int nIndex, const wxString& szString) -{ - wxAutoNSAutoreleasePool pool; - //FIXME: There appears to be no "set item data" method - maybe - //an assignment would work? - [GetNSComboBox() removeItemAtIndex:nIndex]; - [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(szString) atIndex:nIndex]; -} - -int wxComboBox::FindString(const wxString& szItem, bool bCase) const -{ - // FIXME: use wxItemContainerImmutable::FindString for bCase parameter - return [GetNSComboBox() indexOfItemWithObjectValue:wxNSStringWithWxString(szItem)]; -} - -int wxComboBox::GetSelection() const -{ - return [GetNSComboBox() indexOfSelectedItem]; -} - -int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items, - unsigned int pos, - void **clientData, - wxClientDataType type) -{ - wxAutoNSAutoreleasePool pool; - const unsigned int numITems = items.GetCount(); - for ( unsigned int i = 0; i < numITems; ++i, ++pos ) - { - [GetNSComboBox() insertItemWithObjectValue:wxNSStringWithWxString(items[i]) atIndex:(pos)]; - m_Datas.Insert(NULL, pos); - AssignNewItemClientData(pos, clientData, i, type); - } - return pos - 1; -} - -void wxComboBox::DoSetItemClientData(unsigned int nIndex, void* pData) -{ - m_Datas[nIndex] = pData; -} - -void* wxComboBox::DoGetItemClientData(unsigned int nIndex) const -{ - return m_Datas[nIndex]; -} - -///////////////////////////////////////////////////////////////////////////// -// wxTextEntry virtual implementations: - -void wxComboBox::WriteText(wxString const&) -{ -} - -wxString wxComboBox::GetValue() const -{ - wxAutoNSAutoreleasePool pool; - return wxStringWithNSString([GetNSTextField() stringValue]); -} - -void wxComboBox::Remove(long, long) -{ -} - -void wxComboBox::Cut() -{ -} - -void wxComboBox::Copy() -{ -} - -void wxComboBox::Paste() -{ -} - -void wxComboBox::Undo() -{ -} - -void wxComboBox::Redo() -{ -} - -bool wxComboBox::CanUndo() const -{ - return false; -} - -bool wxComboBox::CanRedo() const -{ - return false; -} - -void wxComboBox::SetInsertionPoint(long) -{ -} - -long wxComboBox::GetInsertionPoint() const -{ - return 0; -} - -wxTextPos wxComboBox::GetLastPosition() const -{ - // working - returns the size of the wxString - return (long)(GetValue().Len()); -} - -void wxComboBox::SetSelection(long, long) -{ -} - -void wxComboBox::GetSelection(long*, long*) const -{ -} - -bool wxComboBox::IsEditable() const -{ - return [GetNSTextField() isEditable]; -} - -void wxComboBox::SetEditable(bool editable) -{ - // first ensure that the current value is stored (in case the user had not finished editing - // before SetEditable(FALSE) was called) - DoSetValue(GetValue(),1); - - [GetNSTextField() setEditable: editable]; - - // forces the focus on the textctrl to be lost - while focus is still maintained - // after SetEditable(FALSE) the user may still edit the control - // (might not the best way to do this..) - [GetNSTextField() abortEditing]; -} - -#endif // wxUSE_COMBOBOX diff --git a/src/cocoa/control.mm b/src/cocoa/control.mm deleted file mode 100644 index 32ff222d25..0000000000 --- a/src/cocoa/control.mm +++ /dev/null @@ -1,112 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/control.mm -// Purpose: wxControl class -// Author: David Elliiott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/control.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/trackingrectmanager.h" -#include "wx/cocoa/objc/objc_uniquifying.h" -#include "wx/cocoa/objc/NSView.h" - -#import -#import -#import - -#include - -IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) -BEGIN_EVENT_TABLE(wxControl, wxControlBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxControl,NSControl,NSView,NSView) - -bool wxControl::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, const wxString& name) -{ - wxLogTrace(wxTRACE_COCOA,wxT("Creating control with id=%d"),winid); - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - wxLogTrace(wxTRACE_COCOA,wxT("Created control with id=%d"),GetId()); - m_cocoaNSView = NULL; - SetNSControl([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]); - // NOTE: YES we want to release this (to match the alloc). - // DoAddChild(this) will retain us again since addSubView doesn't. - [m_cocoaNSView release]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - // Controls should have a viewable-area tracking rect by default - m_visibleTrackingRectManager = new wxCocoaTrackingRectManager(this); - - return true; -} - -wxControl::~wxControl() -{ - DisassociateNSControl(GetNSControl()); -} - -wxSize wxControl::DoGetBestSize() const -{ - wxAutoNSAutoreleasePool pool; - wxASSERT(GetNSControl()); - /* We can ask single-celled controls for their cell and get its size */ - NSCell *cell = nil; - if([GetNSControl() respondsToSelector:@selector(cell)]) - cell = [GetNSControl() cell]; - if(cell) - { - NSSize cellSize = [cell cellSize]; - wxSize size((int)ceil(cellSize.width),(int)ceil(cellSize.height)); - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxControl=%p::DoGetBestSize()==(%d,%d) from NSCell"),this,size.x,size.y); - return size; - } - - /* multi-celled control? size to fit, get the size, then set it back */ - if([GetNSControl() respondsToSelector:@selector(sizeToFit)]) - { - NSRect storedRect = [m_cocoaNSView frame]; - [GetNSControl() sizeToFit]; - NSRect cocoaRect = [m_cocoaNSView frame]; - wxSize size((int)ceil(cocoaRect.size.width),(int)ceil(cocoaRect.size.height)); - [m_cocoaNSView setFrame: storedRect]; - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxControl=%p::DoGetBestSize()==(%d,%d) from sizeToFit"),this,size.x,size.y); - return size; - } - // Cocoa can't tell us the size, probably not an NSControl. - wxLogDebug(wxT("Class %s (or superclass still below wxControl) should implement DoGetBestSize()"),GetClassInfo()->GetClassName()); - return wxControlBase::DoGetBestSize(); -} - -bool wxControl::ProcessCommand(wxCommandEvent& event) -{ - return HandleWindowEvent(event); -} - -void wxControl::CocoaSetEnabled(bool enable) -{ - if([GetNSControl() respondsToSelector:@selector(setEnabled:)]) - [GetNSControl() setEnabled: enable]; -} - -/*static*/ void wxControl::CocoaSetLabelForObject(const wxString& label, struct objc_object *aView) -{ - [aView setTitle:wxNSStringWithWxString(GetLabelText(label))]; -} - diff --git a/src/cocoa/cursor.mm b/src/cocoa/cursor.mm deleted file mode 100644 index 66125774bb..0000000000 --- a/src/cocoa/cursor.mm +++ /dev/null @@ -1,502 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/cursor.mm -// Purpose: wxCursor class for wxCocoa -// Author: Ryan Norton -// David Elliott -// Modified by: -// Created: 2004-10-05 -// Copyright: (c) Ryan Norton -// 2007, Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/cursor.h" - -#ifndef WX_PRECOMP - #include "wx/icon.h" - #include "wx/log.h" -#endif //WX_PRECOMP - -#import -#import -#include "wx/cocoa/string.h" -#include "wx/cocoa/autorelease.h" - -IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) - -typedef struct tagClassicCursor -{ - wxUint16 bits[16]; - wxUint16 mask[16]; - wxInt16 hotspot[2]; -}ClassicCursor; - -/////////////////////////////////////////////////////////////////////////// -// This is a direct copy from src/osx/carbon/cursor.cpp and should be -// changed to use common code if we plan on keeping it this way. -// Note that this is basically an array of classic 'CURS' resources. - -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 ; - -ClassicCursor gMacCursors[kwxCursorLast+1] = -{ - -{ -{0x0000, 0x03E0, 0x0630, 0x0808, 0x1004, 0x31C6, 0x2362, 0x2222, -0x2362, 0x31C6, 0x1004, 0x0808, 0x0630, 0x03E0, 0x0000, 0x0000}, -{0x0000, 0x03E0, 0x07F0, 0x0FF8, 0x1FFC, 0x3FFE, 0x3FFE, 0x3FFE, -0x3FFE, 0x3FFE, 0x1FFC, 0x0FF8, 0x07F0, 0x03E0, 0x0000, 0x0000}, -{0x0007, 0x0008} -}, - -{ -{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, -0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, -{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, -0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, -{0x0000, 0x0000} -}, - -{ -{0x00F0, 0x0088, 0x0108, 0x0190, 0x0270, 0x0220, 0x0440, 0x0440, -0x0880, 0x0880, 0x1100, 0x1E00, 0x1C00, 0x1800, 0x1000, 0x0000}, -{0x00F0, 0x00F8, 0x01F8, 0x01F0, 0x03F0, 0x03E0, 0x07C0, 0x07C0, -0x0F80, 0x0F80, 0x1F00, 0x1E00, 0x1C00, 0x1800, 0x1000, 0x0000}, -{0x000E, 0x0003} -}, - -{ -{0x0000, 0x1E00, 0x2100, 0x4080, 0x4080, 0x4080, 0x4080, 0x2180, -0x1FC0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006, 0x0000}, -{0x3F00, 0x7F80, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0x7FC0, -0x3FE0, 0x1FF0, 0x00F8, 0x007C, 0x003E, 0x001F, 0x000F, 0x0007}, -{0x0004, 0x0004} -}, - -{ -{0x0000, 0x07E0, 0x1FF0, 0x3838, 0x3C0C, 0x6E0E, 0x6706, 0x6386, -0x61C6, 0x60E6, 0x7076, 0x303C, 0x1C1C, 0x0FF8, 0x07E0, 0x0000}, -{0x0540, 0x0FF0, 0x3FF8, 0x3C3C, 0x7E0E, 0xFF0F, 0x6F86, 0xE7C7, -0x63E6, 0xE1F7, 0x70FE, 0x707E, 0x3C3C, 0x1FFC, 0x0FF0, 0x0540}, -{0x0007, 0x0007} -}, - -{ -{0x0000, 0x0380, 0x0380, 0x0380, 0x0380, 0x0380, 0x0380, 0x0FE0, -0x1FF0, 0x1FF0, 0x0000, 0x1FF0, 0x1FF0, 0x1550, 0x1550, 0x1550}, -{0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x0FE0, 0x1FF0, -0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8, 0x3FF8}, -{0x000B, 0x0007} -}, - -{ -{0x00C0, 0x0140, 0x0640, 0x08C0, 0x3180, 0x47FE, 0x8001, 0x8001, -0x81FE, 0x8040, 0x01C0, 0x0040, 0x03C0, 0xC080, 0x3F80, 0x0000}, -{0x00C0, 0x01C0, 0x07C0, 0x0FC0, 0x3F80, 0x7FFE, 0xFFFF, 0xFFFF, -0xFFFE, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFF80, 0x3F80, 0x0000}, -{0x0006, 0x000F} -}, - -{ -{0x0100, 0x0280, 0x0260, 0x0310, 0x018C, 0x7FE3, 0x8000, 0x8000, -0x7F80, 0x0200, 0x0380, 0x0200, 0x03C0, 0x0107, 0x01F8, 0x0000}, -{0x0100, 0x0380, 0x03E0, 0x03F0, 0x01FC, 0x7FFF, 0xFFFF, 0xFFFF, -0xFFFF, 0x03FF, 0x03FF, 0x03FF, 0x03FF, 0x01FF, 0x01F8, 0x0000}, -{0x0006, 0x0000} -}, - -{ -{0x0000, 0x4078, 0x60FC, 0x71CE, 0x7986, 0x7C06, 0x7E0E, 0x7F1C, -0x7FB8, 0x7C30, 0x6C30, 0x4600, 0x0630, 0x0330, 0x0300, 0x0000}, -{0xC078, 0xE0FC, 0xF1FE, 0xFBFF, 0xFFCF, 0xFF8F, 0xFF1F, 0xFFBE, -0xFFFC, 0xFE78, 0xFF78, 0xEFF8, 0xCFF8, 0x87F8, 0x07F8, 0x0300}, -{0x0001, 0x0001} -}, - -{ -{0x0000, 0x0002, 0x0006, 0x000E, 0x001E, 0x003E, 0x007E, 0x00FE, -0x01FE, 0x003E, 0x0036, 0x0062, 0x0060, 0x00C0, 0x00C0, 0x0000}, -{0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, -0x03FF, 0x07FF, 0x007F, 0x00F7, 0x00F3, 0x01E1, 0x01E0, 0x01C0}, -{0x0001, 0x000E} -}, - -{ -{0x0000, 0x0080, 0x01C0, 0x03E0, 0x0080, 0x0080, 0x0080, 0x1FFC, -0x1FFC, 0x0080, 0x0080, 0x0080, 0x03E0, 0x01C0, 0x0080, 0x0000}, -{0x0080, 0x01C0, 0x03E0, 0x07F0, 0x0FF8, 0x01C0, 0x3FFE, 0x3FFE, -0x3FFE, 0x3FFE, 0x01C0, 0x0FF8, 0x07F0, 0x03E0, 0x01C0, 0x0080}, -{0x0007, 0x0008} -}, - -{ -{0x0000, 0x0080, 0x01C0, 0x03E0, 0x0080, 0x0888, 0x188C, 0x3FFE, -0x188C, 0x0888, 0x0080, 0x03E0, 0x01C0, 0x0080, 0x0000, 0x0000}, -{0x0080, 0x01C0, 0x03E0, 0x07F0, 0x0BE8, 0x1DDC, 0x3FFE, 0x7FFF, -0x3FFE, 0x1DDC, 0x0BE8, 0x07F0, 0x03E0, 0x01C0, 0x0080, 0x0000}, -{0x0007, 0x0008} -}, - -{ -{0x0000, 0x001E, 0x000E, 0x060E, 0x0712, 0x03A0, 0x01C0, 0x00E0, -0x0170, 0x1238, 0x1C18, 0x1C00, 0x1E00, 0x0000, 0x0000, 0x0000}, -{0x007F, 0x003F, 0x0E1F, 0x0F0F, 0x0F97, 0x07E3, 0x03E1, 0x21F0, -0x31F8, 0x3A7C, 0x3C3C, 0x3E1C, 0x3F00, 0x3F80, 0x0000, 0x0000}, -{0x0006, 0x0009} -}, - -{ -{0x0000, 0x7800, 0x7000, 0x7060, 0x48E0, 0x05C0, 0x0380, 0x0700, -0x0E80, 0x1C48, 0x1838, 0x0038, 0x0078, 0x0000, 0x0000, 0x0000}, -{0xFE00, 0xFC00, 0xF870, 0xF0F0, 0xE9F0, 0xC7E0, 0x87C0, 0x0F84, -0x1F8C, 0x3E5C, 0x3C3C, 0x387C, 0x00FC, 0x01FC, 0x0000, 0x0000}, -{0x0006, 0x0006} -}, - -{ -{0x0006, 0x000E, 0x001C, 0x0018, 0x0020, 0x0040, 0x00F8, 0x0004, -0x1FF4, 0x200C, 0x2AA8, 0x1FF0, 0x1F80, 0x3800, 0x6000, 0x8000}, -{0x000F, 0x001F, 0x003E, 0x007C, 0x0070, 0x00E0, 0x01FC, 0x3FF6, -0x7FF6, 0x7FFE, 0x7FFC, 0x7FF8, 0x3FF0, 0x7FC0, 0xF800, 0xE000}, -{0x000A, 0x0006} -}, - -} ; - -// End of data copied from src/osx/carbon/cursor.cpp -/////////////////////////////////////////////////////////////////////////// - -/* NSCursorCreateWithPrivateId - * Returns a newly allocated (i.e. retainCount == 1) NSCursor based on the - * classic Mac OS cursor data in this source file. This allows us to - * implement the "stock" wxWidgets cursors which aren't present in Cocoa. - */ -static inline NSCursor* NSCursorCreateWithPrivateId(short sIndex) -{ - ClassicCursor* pCursor = &gMacCursors[sIndex]; - - //Classic mac cursors are 1bps 16x16 black and white with a - //identical mask that is 1 for on and 0 for off - NSImage *theImage = [[NSImage alloc] initWithSize:NSMakeSize(16.0,16.0)]; - - NSBitmapImageRep *theRep = [[NSBitmapImageRep alloc] - initWithBitmapDataPlanes: NULL // Tell Cocoa to allocate the planes for us. - pixelsWide: 16 // All classic cursors are 16x16 - pixelsHigh: 16 - bitsPerSample: 1 // All classic cursors are bitmaps with bitmasks - samplesPerPixel: 2 // Sample 0:image 1:mask - hasAlpha: YES // Identify last sample as a mask - isPlanar: YES // Use a separate array for each sample - colorSpaceName: NSCalibratedWhiteColorSpace // 0.0=black 1.0=white - bytesPerRow: 2 // Rows in each plane are on 2-byte boundaries (no pad) - bitsPerPixel: 1]; // same as bitsPerSample since data is planar - // XXX: Should we use NSDeviceWhiteColorSpace? Does it matter? - - // Ensure that Cocoa allocated 2 and only 2 of the 5 possible planes - unsigned char *planes[5]; - [theRep getBitmapDataPlanes:planes]; - wxASSERT(planes[0] != NULL); - wxASSERT(planes[1] != NULL); - wxASSERT(planes[2] == NULL); - wxASSERT(planes[3] == NULL); - wxASSERT(planes[4] == NULL); - - // NOTE1: The Cursor's bits field is white=0 black=1.. thus the bitwise-not - // Why not use NSCalibratedBlackColorSpace? Because that reverses the - // sense of the alpha (mask) plane. - // NOTE2: The mask data is 0=off 1=on - // NOTE3: Cocoa asks for "premultiplied" color planes. Since we have a - // 1-bit color plane and a 1-bit alpha plane we can just do a bitwise-and - // on the two. The original cursor bitmaps have 0 (white actually) for - // any masked-off pixels. Therefore every masked-off pixel would be wrong - // since we bit-flip all of the picture bits. In practice, Cocoa doesn't - // seem to care, but we are following the documentation. - - // Fill in the color (black/white) plane - for(int i=0; i<16; ++i) - { - planes[0][2*i ] = (~pCursor->bits[i] & pCursor->mask[i]) >> 8 & 0xff; - planes[0][2*i+1] = (~pCursor->bits[i] & pCursor->mask[i]) & 0xff; - } - // Fill in the alpha (i.e. mask) plane - for(int i=0; i<16; ++i) - { - planes[1][2*i ] = pCursor->mask[i] >> 8 & 0xff; - planes[1][2*i+1] = pCursor->mask[i] & 0xff; - } - - //add the representation (data) to the image - [theImage addRepresentation:theRep]; - - //create the new cursor - NSCursor* theCursor = [[NSCursor alloc] initWithImage:theImage - hotSpot:NSMakePoint(pCursor->hotspot[1], pCursor->hotspot[0]) - ]; - - //do the usual cleanups - [theRep release]; - [theImage release]; - - //return the new cursor - return theCursor; -} - -wxCursorRefData::wxCursorRefData() : - m_width(32), m_height(32), m_hCursor(nil) -{ -} - -wxCursorRefData::~wxCursorRefData() -{ - if (m_hCursor) - [m_hCursor release]; -} - -// Cursors -wxCursor::wxCursor() -{ -} - -wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[]) -{ -} - -wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY) -{ - m_refData = new wxCursorRefData; - - //TODO: Not sure if this works or not - NSImage* theImage; - - if (flags & wxBITMAP_TYPE_MACCURSOR_RESOURCE) - { - //[NSBundle bundleForClass:[self class]]? - theImage = [[NSImage alloc] - initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:wxNSStringWithWxString(cursor_file) ofType:nil] - ]; - - } - else - theImage = [[NSImage alloc] initByReferencingFile:wxNSStringWithWxString(cursor_file) - ]; - - wxASSERT(theImage); - - M_CURSORDATA->m_hCursor = [[NSCursor alloc] initWithImage:theImage - hotSpot:NSMakePoint(hotSpotX, hotSpotY) - ]; - - [theImage release]; -} - -// Returns a system cursor given the NSCursor class method selector or -// nil if NSCursor does not respond to the message. -// For example, OS X before 10.3 won't respond to pointingHandCursor. -static inline NSCursor* GetSystemCursorWithSelector(SEL cursorSelector) -{ - if([NSCursor respondsToSelector: cursorSelector]) - return [NSCursor performSelector: cursorSelector]; - else - return nil; -} - -// Please maintain order as if this were an array keyed on wxStockCursor -static inline SEL GetCursorSelectorForStockCursor(int stock_cursor_id) -{ - switch(stock_cursor_id) - { - case wxCURSOR_ARROW: return @selector(arrowCursor); - case wxCURSOR_RIGHT_ARROW: break; - case wxCURSOR_BULLSEYE: break; - case wxCURSOR_CHAR: break; - case wxCURSOR_CROSS: return @selector(crosshairCursor); - case wxCURSOR_HAND: return @selector(pointingHandCursor); - case wxCURSOR_IBEAM: return @selector(IBeamCursor); - case wxCURSOR_LEFT_BUTTON: break; - case wxCURSOR_MAGNIFIER: break; - case wxCURSOR_MIDDLE_BUTTON: break; - case wxCURSOR_NO_ENTRY: break; - case wxCURSOR_PAINT_BRUSH: break; - case wxCURSOR_PENCIL: break; - case wxCURSOR_POINT_LEFT: break; - case wxCURSOR_POINT_RIGHT: break; - case wxCURSOR_QUESTION_ARROW: break; - case wxCURSOR_RIGHT_BUTTON: break; - case wxCURSOR_SIZENESW: break; - case wxCURSOR_SIZENS: return @selector(resizeUpDownCursor); - case wxCURSOR_SIZENWSE: break; - case wxCURSOR_SIZEWE: return @selector(resizeLeftRightCursor); - case wxCURSOR_SIZING: break; - case wxCURSOR_SPRAYCAN: break; - case wxCURSOR_WAIT: break; - case wxCURSOR_WATCH: break; - case wxCURSOR_BLANK: break; - case wxCURSOR_ARROWWAIT: break; - default: break; - } - return NULL; -} - -// Please maintain order as if this were an array keyed on wxStockCursor -static inline int GetPrivateCursorIdForStockCursor(int stock_cursor_id) -{ - switch(stock_cursor_id) - { - case wxCURSOR_ARROW: break; // NSCursor - case wxCURSOR_RIGHT_ARROW: return kwxCursorRightArrow; - case wxCURSOR_BULLSEYE: return kwxCursorBullseye; - case wxCURSOR_CHAR: break; - case wxCURSOR_CROSS: break; // NSCursor - case wxCURSOR_HAND: break; // NSCursor (OS X >= 10.3) - case wxCURSOR_IBEAM: break; // NSCursor - case wxCURSOR_LEFT_BUTTON: break; - case wxCURSOR_MAGNIFIER: return kwxCursorMagnifier; - case wxCURSOR_MIDDLE_BUTTON: break; - case wxCURSOR_NO_ENTRY: return kwxCursorNoEntry; - case wxCURSOR_PAINT_BRUSH: return kwxCursorPaintBrush; - case wxCURSOR_PENCIL: return kwxCursorPencil; - case wxCURSOR_POINT_LEFT: return kwxCursorPointLeft; - case wxCURSOR_POINT_RIGHT: return kwxCursorPointRight; - case wxCURSOR_QUESTION_ARROW: return kwxCursorQuestionArrow; - case wxCURSOR_RIGHT_BUTTON: break; - case wxCURSOR_SIZENESW: return kwxCursorSizeNESW; - case wxCURSOR_SIZENS: return kwxCursorSizeNS; // also NSCursor - case wxCURSOR_SIZENWSE: return kwxCursorSizeNWSE; - case wxCURSOR_SIZEWE: break; // NSCursor - case wxCURSOR_SIZING: return kwxCursorSize; - case wxCURSOR_SPRAYCAN: return kwxCursorRoller; - case wxCURSOR_WAIT: break; - case wxCURSOR_WATCH: break; - case wxCURSOR_BLANK: return kwxCursorBlank; - case wxCURSOR_ARROWWAIT: break; - default: break; - } - return -1; -} - -// Keep an array of stock cursors so they can share wxCursorRefData and thus -// wxObject::IsSameAs will return true. -// They will obviously be destroyed at static destruction time which should -// theoretically be fine. -static wxCursor s_stockCursors[wxCURSOR_MAX]; - -// Cursors by stock number (enum wxStockCursor) -wxCursor::wxCursor(int stock_cursor_id) -{ - // We default-constructed wxObject so our m_refData == NULL - if(stock_cursor_id >= 0 && stock_cursor_id < wxCURSOR_MAX) - { - // Attempt to reference an existing stock cursor - Ref(s_stockCursors[stock_cursor_id]); - } - // If we succeeded in getting an existing stock cursor, we're done. - if(m_refData != NULL) - return; - - m_refData = new wxCursorRefData; - - M_CURSORDATA->m_hCursor = nil; - - wxCHECK_RET( stock_cursor_id > wxCURSOR_NONE && stock_cursor_id < wxCURSOR_MAX, - wxT("invalid cursor id in wxCursor() ctor") ); - - // Stage 1: Try a system cursor - SEL cursorSelector; - if( (cursorSelector = GetCursorSelectorForStockCursor(stock_cursor_id)) != NULL) - { - M_CURSORDATA->m_hCursor = [GetSystemCursorWithSelector(cursorSelector) retain]; - } - - // TODO: Provide a pointing hand for OS X < 10.3 if desired - - // Stage 2: Try one of the 'CURS'-style cursors - if(M_CURSORDATA->m_hCursor == nil) - { - int privateId; - if( (privateId = GetPrivateCursorIdForStockCursor(stock_cursor_id)) >= 0) - { - M_CURSORDATA->m_hCursor = NSCursorCreateWithPrivateId(privateId); - } - } - - // Stage 3: Give up, complain, and use a normal arrow - if(M_CURSORDATA->m_hCursor == nil) - { - wxLogDebug(wxT("Could not find suitable cursor for wxStockCursor = %d. Using normal pointer."), stock_cursor_id); - M_CURSORDATA->m_hCursor = [[NSCursor arrowCursor] retain]; - } - - // This should never happen as the arrowCursor should always exist. - wxASSERT(M_CURSORDATA->m_hCursor != nil); - - // Store ourself as the new stock cursor for this ID so that future - // calls will share the same ref data. - if(stock_cursor_id >= 0 && stock_cursor_id < wxCURSOR_MAX) - { - s_stockCursors[stock_cursor_id] = *this; - } -} - -wxCursor::~wxCursor() -{ -} - -// Global cursor setting -void wxSetCursor(const wxCursor& cursor) -{ - if (cursor.GetNSCursor()) - [cursor.GetNSCursor() push]; -} - -static int wxBusyCursorCount = 0; - -// Set the cursor to the busy cursor for all windows -void wxBeginBusyCursor(const wxCursor *cursor) -{ - wxBusyCursorCount ++; - if (wxBusyCursorCount == 1) - { - // TODO - } - else - { - // TODO - } -} - -// Restore cursor to normal -void wxEndBusyCursor() -{ - if (wxBusyCursorCount == 0) - return; - - wxBusyCursorCount --; - if (wxBusyCursorCount == 0) - { - // TODO - } -} - -// true if we're between the above two calls -bool wxIsBusy() -{ - return (wxBusyCursorCount > 0); -} diff --git a/src/cocoa/data.cpp b/src/cocoa/data.cpp deleted file mode 100644 index 7dc625dc4d..0000000000 --- a/src/cocoa/data.cpp +++ /dev/null @@ -1,10 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/data.cpp -// Purpose: Various data -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 -// Copyright: (c) AUTHOR -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - diff --git a/src/cocoa/dataobj.mm b/src/cocoa/dataobj.mm deleted file mode 100644 index f74680330b..0000000000 --- a/src/cocoa/dataobj.mm +++ /dev/null @@ -1,60 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dataobj.mm -// Purpose: wxDataObject -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_DATAOBJ - -#include "wx/dataobj.h" - -#ifndef WX_PRECOMP -#endif //WX_PRECOMP - -wxDataObject::wxDataObject() -{ -} - -wxDataObject::~wxDataObject() -{ -} - -bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, - Direction dir) const -{ - return false; -} - -wxBitmapDataObject::wxBitmapDataObject() -{ -} - -wxBitmapDataObject::wxBitmapDataObject(const wxBitmap& bitmap) -{ -} - -wxBitmapDataObject::~wxBitmapDataObject() -{ -} - -void wxBitmapDataObject::SetBitmap(const wxBitmap& bitmap) -{ -} - -bool wxBitmapDataObject::SetData(size_t len, const void *buf) -{ - return false; -} - -bool wxBitmapDataObject::GetDataHere(void *buf) const -{ - return false; -} - -#endif //wxUSE_DATAOBJ diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm deleted file mode 100644 index 0c10821326..0000000000 --- a/src/cocoa/dc.mm +++ /dev/null @@ -1,664 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dc.mm -// Purpose: wxDC -// Author: David Elliott -// Modified by: -// Created: 2003/04/01 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/cocoa/dc.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/math.h" //math constants -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/ObjcRef.h" - -#import -#import -#import -#import -#import -#import -#import -#import -#import - -#include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxCocoaDCStack); - -IMPLEMENT_ABSTRACT_CLASS(wxCocoaDCImpl, wxDCImpl) - -WX_NSTextStorage wxCocoaDCImpl::sm_cocoaNSTextStorage = nil; -WX_NSLayoutManager wxCocoaDCImpl::sm_cocoaNSLayoutManager = nil; -WX_NSTextContainer wxCocoaDCImpl::sm_cocoaNSTextContainer = nil; -wxCocoaDCStack wxCocoaDCImpl::sm_cocoaDCStack; - -inline void CocoaSetPenForNSBezierPath(wxPen &pen, NSBezierPath *bezpath) -{ - [pen.GetNSColor() set]; - const CGFloat *pattern; - [bezpath setLineDash:pattern count:pen.GetCocoaLineDash(&pattern) phase:0.0]; - [bezpath setLineWidth:pen.GetWidth()]; - switch(pen.GetJoin()) - { - case wxJOIN_BEVEL: - [bezpath setLineJoinStyle:NSBevelLineJoinStyle]; - break; - case wxJOIN_ROUND: - [bezpath setLineJoinStyle:NSRoundLineJoinStyle]; - break; - case wxJOIN_MITER: - [bezpath setLineJoinStyle:NSMiterLineJoinStyle]; - break; - } - switch(pen.GetCap()) - { - case wxCAP_ROUND: - [bezpath setLineCapStyle:NSRoundLineCapStyle]; - break; - case wxCAP_PROJECTING: - [bezpath setLineCapStyle:NSSquareLineCapStyle]; - break; - case wxCAP_BUTT: - [bezpath setLineCapStyle:NSButtLineCapStyle]; - break; - } -} - -void wxCocoaDCImpl::CocoaInitializeTextSystem() -{ - wxAutoNSAutoreleasePool pool; - - wxASSERT_MSG(!sm_cocoaNSTextStorage && !sm_cocoaNSLayoutManager && !sm_cocoaNSTextContainer,wxT("Text system already initalized! BAD PROGRAMMER!")); - - // FIXME: Never released - sm_cocoaNSTextStorage = wxGCSafeRetain([[[NSTextStorage alloc] init] autorelease]); - - // FIXME: Never released - sm_cocoaNSLayoutManager = wxGCSafeRetain([[[NSLayoutManager alloc] init] autorelease]); - - [sm_cocoaNSTextStorage addLayoutManager:sm_cocoaNSLayoutManager]; - // NSTextStorage retains NSLayoutManager, but so do we - // [sm_cocoaNSLayoutManager release]; [sm_cocoaNSLayoutManager retain]; - - // NOTE: initWithContainerSize is the designated initializer, but the - // Apple CircleView sample gets away with just calling init, which - // is all we really need for our purposes. - // FIXME: Never released - sm_cocoaNSTextContainer = wxGCSafeRetain([[[NSTextContainer alloc] init] autorelease]); - [sm_cocoaNSLayoutManager addTextContainer:sm_cocoaNSTextContainer]; - // NSLayoutManager retains NSTextContainer, but so do we - // [sm_cocoaNSTextContainer release]; [sm_cocoaNSTextContainer retain]; -} - -void wxCocoaDCImpl::CocoaShutdownTextSystem() -{ - [sm_cocoaNSTextContainer release]; sm_cocoaNSTextContainer = nil; - [sm_cocoaNSLayoutManager release]; sm_cocoaNSLayoutManager = nil; - [sm_cocoaNSTextStorage release]; sm_cocoaNSTextStorage = nil; -} - -void wxCocoaDCImpl::CocoaUnwindStackAndLoseFocus() -{ - wxCocoaDCStack::compatibility_iterator ourNode=sm_cocoaDCStack.Find(this); - if(ourNode) - { - wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst(); - for(;node!=ourNode; node=sm_cocoaDCStack.GetFirst()) - { - wxCocoaDCImpl *dc = node->GetData(); - wxASSERT(dc); - wxASSERT(dc!=this); - if(!dc->CocoaUnlockFocus()) - { - wxFAIL_MSG(wxT("Unable to unlock focus on higher-level DC!")); - } - sm_cocoaDCStack.Erase(node); - } - wxASSERT(node==ourNode); - wxASSERT(ourNode->GetData() == this); - ourNode->GetData()->CocoaUnlockFocus(); - sm_cocoaDCStack.Erase(ourNode); - } -} - -bool wxCocoaDCImpl::CocoaUnwindStackAndTakeFocus() -{ - wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst(); - for(;node;node = sm_cocoaDCStack.GetFirst()) - { - wxCocoaDCImpl *dc = node->GetData(); - wxASSERT(dc); - // If we're on the stack, then it's unwound enough and we have focus - if(dc==this) - return true; - // If unable to unlockFocus (e.g. wxPaintDC) stop here - if(!dc->CocoaUnlockFocus()) - break; - sm_cocoaDCStack.Erase(node); - } - return CocoaLockFocus(); -} - -wxCocoaDCImpl::wxCocoaDCImpl(wxDC *owner) -: wxDCImpl(owner) -{ - m_cocoaWxToBoundsTransform = nil; - m_pen = *wxBLACK_PEN; -} - -wxCocoaDCImpl::~wxDC(void) -{ - [m_cocoaWxToBoundsTransform release]; -} - -bool wxCocoaDCImpl::CocoaLockFocus() -{ - return false; -} - -bool wxCocoaDCImpl::CocoaUnlockFocus() -{ - return false; -} - -/*static*/ WX_NSAffineTransform wxCocoaDCImpl::CocoaGetWxToBoundsTransform(bool isFlipped, float height) -{ - NSAffineTransform *transform = nil; - // This transform flips the graphics since wxDC uses top-left origin - if(!isFlipped) - { - // The transform is auto released - transform = [NSAffineTransform transform]; - /* x' = 1x + 0y + 0 - y' = 0x + -1y + window's height - */ - NSAffineTransformStruct matrix = { - 1, 0 - , 0, -1 - , 0, height - }; - [transform setTransformStruct: matrix]; - } - return transform; -} - -void wxCocoaDCImpl::CocoaApplyTransformations() -{ - [m_cocoaWxToBoundsTransform concat]; - // TODO: Apply device/logical/user position/scaling transformations -} - -void wxCocoaDCImpl::CocoaUnapplyTransformations() -{ - // NOTE: You *must* call this with focus held. - // Undo all transforms so we're back in true Cocoa coords with - // no scaling or flipping. - NSAffineTransform *invertTransform; - invertTransform = [m_cocoaWxToBoundsTransform copy]; - [invertTransform invert]; - [invertTransform concat]; - [invertTransform release]; -} - -bool wxCocoaDCImpl::CocoaGetBounds(void *rectData) -{ - // We don't know what we are so we can't return anything. - return false; -} - -void wxCocoaDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) -{ - wxAutoNSAutoreleasePool pool; - if(!CocoaTakeFocus()) return; - NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,width,height)]; - CocoaSetPenForNSBezierPath(m_pen,bezpath); - [bezpath stroke]; - [m_brush.GetNSColor() set]; - [bezpath fill]; -} - -void wxCocoaDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) -{ - wxAutoNSAutoreleasePool pool; - if(!CocoaTakeFocus()) return; - NSBezierPath *bezpath = [NSBezierPath bezierPath]; - [bezpath moveToPoint:NSMakePoint(x1,y1)]; - [bezpath lineToPoint:NSMakePoint(x2,y2)]; - - CocoaSetPenForNSBezierPath(m_pen,bezpath); - [bezpath stroke]; -} - -void wxCocoaDCImpl::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, const wxFont *theFont) const -{ - wxAutoNSAutoreleasePool pool; -// FIXME: Cache this so it can be used for DoDrawText - wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!")); - NSAttributedString *attributedString = [[NSAttributedString alloc] - initWithString:wxNSStringWithWxString(text.c_str())]; - [sm_cocoaNSTextStorage setAttributedString:attributedString]; - [attributedString release]; - - NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer]; - NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer]; - if(x) - *x=(int)usedRect.size.width; - if(y) - *y=(int)usedRect.size.height; - if(descent) - *descent=0; - if(externalLeading) - *externalLeading=0; -} - -void wxCocoaDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y) -{ - wxAutoNSAutoreleasePool pool; - if(!CocoaTakeFocus()) return; - wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!")); - NSAttributedString *attributedString = [[NSAttributedString alloc] - initWithString:wxNSStringWithWxString(text.c_str())]; - [sm_cocoaNSTextStorage setAttributedString:attributedString]; - [attributedString release]; - - // Set the color (and later font) attributes - NSColor *fgColor = m_textForegroundColour.GetNSColor(); - NSColor *bgColor = m_textBackgroundColour.GetNSColor(); - if(!fgColor) - fgColor = [NSColor clearColor]; - if(!bgColor) - bgColor = [NSColor clearColor]; - NSDictionary *attrDict = [[NSDictionary alloc] initWithObjectsAndKeys: - fgColor, NSForegroundColorAttributeName, - bgColor, NSBackgroundColorAttributeName, - nil]; - [sm_cocoaNSTextStorage addAttributes: attrDict range:NSMakeRange(0,[sm_cocoaNSTextStorage length])]; - [attrDict release]; - - NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer]; - NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer]; - // NOTE: We'll crash trying to get the location of glyphAtIndex:0 if - // there is no length or we don't start at zero - if(!glyphRange.length) - return; - wxASSERT_MSG(glyphRange.location==0,wxT("glyphRange must begin at zero")); - - NSAffineTransform *transform = [NSAffineTransform transform]; - [transform translateXBy:x yBy:y]; - - NSAffineTransform *flipTransform = [NSAffineTransform transform]; - /* x' = 1x + 0y + 0 - y' = 0x + -1y + window's height - */ - NSAffineTransformStruct matrix = { - 1, 0 - , 0, -1 - , 0, usedRect.size.height - }; - [flipTransform setTransformStruct: matrix]; - - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - [transform concat]; - [flipTransform concat]; - #if 0 - // Draw+fill a rectangle so we can see where the shit is supposed to be. - wxLogTrace(wxTRACE_COCOA,wxT("(%f,%f) (%fx%f)"),usedRect.origin.x,usedRect.origin.y,usedRect.size.width,usedRect.size.height); - NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(0,0,usedRect.size.width,usedRect.size.height)]; - [[NSColor blackColor] set]; - [bezpath stroke]; - [[NSColor blueColor] set]; - [bezpath fill]; - #endif - - NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0]; - layoutLocation.x = 0.0; - layoutLocation.y *= -1.0; - - // Save the location as is for underlining - NSPoint underlineLocation = layoutLocation; - - // Offset the location by the baseline for drawing the glyphs. - layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0]; - - if(m_backgroundMode==wxSOLID) - [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint]; - [sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation]; - - int underlineStyle = GetFont().GetUnderlined() ? NSUnderlineStyleSingle : NSUnderlineStyleNone; - NSRange lineGlyphRange; - NSRect lineRect = [sm_cocoaNSLayoutManager lineFragmentRectForGlyphAtIndex:0 effectiveRange:&lineGlyphRange]; - - [sm_cocoaNSLayoutManager underlineGlyphRange:glyphRange underlineType:underlineStyle - lineFragmentRect:lineRect lineFragmentGlyphRange:lineGlyphRange - containerOrigin:underlineLocation]; - - [context restoreGraphicsState]; -} - -/////////////////////////////////////////////////////////////////////////// -// cut here, the rest is stubs -/////////////////////////////////////////////////////////////////////////// - -//----------------------------------------------------------------------------- -// wxDC -//----------------------------------------------------------------------------- - -void wxCocoaDCImpl::DoDrawIcon( const wxIcon &WXUNUSED(icon), int WXUNUSED(x), int WXUNUSED(y) ) -{ -}; - -void wxCocoaDCImpl::DoDrawPoint( int x, int y ) -{ -}; - -void wxCocoaDCImpl::DoDrawPolygon( int, const wxPoint *, int, int, wxPolygonFillMode) -{ -}; - -void wxCocoaDCImpl::DoDrawLines( int, const wxPoint *, int, int ) -{ -} - -int wxCocoaDCImpl::GetDepth() const -{ - return 0; -} - -wxSize wxCocoaDCImpl::GetPPI() const -{ - return wxSize(0,0); -} - -bool wxCocoaDCImpl::CanGetTextExtent() const -{ - return false; -} - -wxCoord wxCocoaDCImpl::GetCharHeight() const -{ - return 0; -} - -wxCoord wxCocoaDCImpl::GetCharWidth() const -{ - return 0; -} - -bool wxCocoaDCImpl::CanDrawBitmap() const -{ - return true; -} - -bool wxCocoaDCImpl::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const -{ - return false; -} - -void wxCocoaDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc) -{ -} - -void wxCocoaDCImpl::SetFont(const wxFont& font) -{ - m_font = font; -} - -void wxCocoaDCImpl::SetPen(const wxPen& pen) -{ - m_pen = pen; -} - -void wxCocoaDCImpl::SetBrush(const wxBrush& brush) -{ - m_brush = brush; -} - -void wxCocoaDCImpl::DoSetClippingRegionAsRegion(const wxRegion& region) -{ -} - -void wxCocoaDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) -{ -} - -void wxCocoaDCImpl::DestroyClippingRegion() -{ -} - -void wxCocoaDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) -{ -} - -void wxCocoaDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) -{ -} - -void wxCocoaDCImpl::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea) -{ -} - -void wxCocoaDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) -{ -} - -void wxCocoaDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) -{ - wxAutoNSAutoreleasePool pool; - if(!CocoaTakeFocus()) return; - if(!bmp.IsOk()) - return; - -#if 0 - // Draw a rect so we can see where it's supposed to be - wxLogTrace(wxTRACE_COCOA,wxT("image at (%d,%d) size %dx%d"),x,y,bmp.GetWidth(),bmp.GetHeight()); - NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,bmp.GetWidth(),bmp.GetHeight())]; - [[NSColor blackColor] set]; - [bezpath stroke]; - [[NSColor blueColor] set]; - [bezpath fill]; -#endif // 0 - - NSAffineTransform *transform = [NSAffineTransform transform]; - [transform translateXBy:x yBy:y]; - - NSAffineTransform *flipTransform = [NSAffineTransform transform]; - /* x' = 1x + 0y + 0 - y' = 0x + -1y + window's height - */ - NSAffineTransformStruct matrix = { - 1, 0 - , 0, -1 - , 0, bmp.GetHeight() - }; - [flipTransform setTransformStruct: matrix]; - - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - [transform concat]; - [flipTransform concat]; - - NSImage *nsimage = [bmp.GetNSImage(useMask) retain]; - - [nsimage drawAtPoint: NSMakePoint(0,0) - fromRect: NSMakeRect(0.0,0.0,bmp.GetWidth(),bmp.GetHeight()) - operation: NSCompositeSourceOver - fraction: 1.0]; - - [nsimage release]; - [context restoreGraphicsState]; -} - -bool wxCocoaDCImpl::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, wxFloodFillStyle style) -{ - return false; -} - -void wxCocoaDCImpl::DoCrossHair(wxCoord x, wxCoord y) -{ -} - - -bool wxCocoaDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, wxRasterOperationMode rop, bool useMask , wxCoord xsrcMask, wxCoord ysrcMask) -{ - if(!CocoaTakeFocus()) return false; - if(!source) return false; - wxCocoaDCImpl *sourceImpl = static_cast(source->GetImpl()); - return sourceImpl->CocoaDoBlitOnFocusedDC(xdest,ydest,width,height, - xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask); -} - -bool wxCocoaDCImpl::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, - wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, - int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) -{ - return false; -} - -void wxCocoaDCImpl::DoGetSize( int* width, int* height ) const -{ - *width = m_maxX-m_minX; - *height = m_maxY-m_minY; -}; - -void wxCocoaDCImpl::DoGetSizeMM( int* width, int* height ) const -{ - int w = 0; - int h = 0; - DoGetSize( &w, &h ); -}; - -void wxCocoaDCImpl::SetTextForeground( const wxColour &col ) -{ -// if (!IsOk()) return; - m_textForegroundColour = col; -}; - -void wxCocoaDCImpl::SetTextBackground( const wxColour &col ) -{ -// if (!IsOk()) return; - m_textBackgroundColour = col; -}; - -void wxCocoaDCImpl::Clear() -{ - if(!CocoaTakeFocus()) return; - - NSRect boundsRect; - if(!CocoaGetBounds(&boundsRect)) return; - - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - - // Undo all transforms so when we draw our bounds rect we - // really overwrite our bounds rect. - CocoaUnapplyTransformations(); - - [m_backgroundBrush.GetNSColor() set]; - [NSBezierPath fillRect:boundsRect]; - - [context restoreGraphicsState]; -} - -void wxCocoaDCImpl::SetBackground(const wxBrush& brush) -{ - m_backgroundBrush = brush; -} - -void wxCocoaDCImpl::SetPalette(const wxPalette&) -{ -} - -void wxCocoaDCImpl::SetLogicalFunction(wxRasterOperationMode) -{ -} - - -void wxCocoaDCImpl::SetMapMode( wxMappingMode mode ) -{ - switch (mode) - { - case wxMM_TWIPS: - break; - case wxMM_POINTS: - break; - case wxMM_METRIC: - break; - case wxMM_LOMETRIC: - break; - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - }; - if (mode != wxMM_TEXT) - { - }; -}; - -void wxCocoaDCImpl::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -}; - -void wxCocoaDCImpl::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -}; - -void wxCocoaDCImpl::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -}; - -void wxCocoaDCImpl::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - ComputeScaleAndOrigin(); -}; - -void wxCocoaDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -}; - -void wxCocoaDCImpl::ComputeScaleAndOrigin(void) -{ - // CMB: copy scale to see if it changes - double origScaleX = m_scaleX; - double origScaleY = m_scaleY; - - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; - - // CMB: if scale has changed call SetPen to recalculate the line width - if (m_scaleX != origScaleX || m_scaleY != origScaleY) - { -#if 0 - // this is a bit artificial, but we need to force wxDC to think - // the pen has changed - const wxPen* pen = & GetPen(); - wxPen tempPen; - m_pen = tempPen; - SetPen(* pen); -#endif - } -}; diff --git a/src/cocoa/dcclient.mm b/src/cocoa/dcclient.mm deleted file mode 100644 index c8a3c4f615..0000000000 --- a/src/cocoa/dcclient.mm +++ /dev/null @@ -1,176 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dcclient.mm -// Purpose: wxWindowDCImpl, wxPaintDCImpl, and wxClientDCImpl classes -// Author: David Elliott -// Modified by: -// Created: 2003/04/01 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/window.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/dcclient.h" - -#import -#import -#import -#import -#import -#import - -/* - * wxWindowDCImpl - */ -IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxCocoaDCImpl) - -wxWindowDCImpl::wxWindowDCImpl(wxDC *owner) -: wxCocoaDCImpl(owner) -, m_window(NULL) -, m_lockedNSView(NULL) -{ -}; - -wxWindowDCImpl::wxWindowDCImpl(wxDC *owner, wxWindow *window) -: wxCocoaDCImpl(owner) -, m_window(window) -, m_lockedNSView(NULL) -{ - wxLogDebug(wxT("non-client window DC's are not supported, oh well")); -}; - -wxWindowDCImpl::~wxWindowDCImpl(void) -{ - CocoaUnwindStackAndLoseFocus(); -}; - -bool wxWindowDCImpl::CocoaLockFocusOnNSView(WX_NSView nsview) -{ - if([nsview lockFocusIfCanDraw]) - { - sm_cocoaDCStack.Insert(this); - CocoaApplyTransformations(); - m_lockedNSView = nsview; - return true; - } - wxLogDebug(wxT("focus lock failed!")); - return false; -} - -bool wxWindowDCImpl::CocoaUnlockFocusOnNSView() -{ - [[m_lockedNSView window] flushWindow]; - [m_lockedNSView unlockFocus]; - m_lockedNSView = NULL; - return true; -} - -bool wxWindowDCImpl::CocoaLockFocus() -{ - wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDCImpl=%p, NSView=%p"),this, m_window->GetNonClientNSView()); - NSAffineTransform *newTransform = CocoaGetWxToBoundsTransform([m_window->GetNonClientNSView() isFlipped], [m_window->GetNonClientNSView() bounds].size.height); - [newTransform retain]; - [m_cocoaWxToBoundsTransform release]; - m_cocoaWxToBoundsTransform = newTransform; - return CocoaLockFocusOnNSView(m_window->GetNonClientNSView()); -} - -bool wxWindowDCImpl::CocoaUnlockFocus() -{ - wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxWindowDCImpl=%p, NSView=%p"),this, m_window->GetNonClientNSView()); - return CocoaUnlockFocusOnNSView(); -} - -bool wxWindowDCImpl::CocoaGetBounds(void *rectData) -{ - if(!rectData) - return false; - if(!m_lockedNSView) - return false; - NSRect *pRect = (NSRect*)rectData; - *pRect = [m_lockedNSView bounds]; - return true; -} - -/* - * wxClientDCImpl - */ -IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) - -wxClientDCImpl::wxClientDCImpl(wxDC *owner) -: wxWindowDCImpl(owner) -{ -}; - -wxClientDCImpl::wxClientDCImpl(wxDC *owner, wxWindow *window) -: wxWindowDCImpl(owner) -{ - m_window = window; -}; - -wxClientDCImpl::~wxClientDCImpl(void) -{ - CocoaUnwindStackAndLoseFocus(); -}; - -bool wxClientDCImpl::CocoaLockFocus() -{ - wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxClientDCImpl=%p, NSView=%p"),this, m_window->GetNSView()); - NSAffineTransform *newTransform = m_window->CocoaGetWxToBoundsTransform(); - [newTransform retain]; - [m_cocoaWxToBoundsTransform release]; - m_cocoaWxToBoundsTransform = newTransform; - return CocoaLockFocusOnNSView(m_window->GetNSView()); -} - -bool wxClientDCImpl::CocoaUnlockFocus() -{ - wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxClientDCImpl=%p, NSView=%p"),this, m_window->GetNSView()); - return CocoaUnlockFocusOnNSView(); -} - -/* - * wxPaintDCImpl - */ -IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl) - -wxPaintDCImpl::wxPaintDCImpl(wxDC *owner) -: wxWindowDCImpl(owner) -{ -}; - -wxPaintDCImpl::wxPaintDCImpl(wxDC *owner, wxWindow *window) -: wxWindowDCImpl(owner) -{ - m_window = window; - wxASSERT_MSG([NSView focusView]==window->GetNSView(), wxT("PaintDC's NSView does not have focus. Please use wxPaintDCImpl only as the first DC created in a paint handler")); - sm_cocoaDCStack.Insert(this); - m_lockedNSView = window->GetNSView(); - NSAffineTransform *newTransform = window->CocoaGetWxToBoundsTransform(); - [newTransform retain]; - [m_cocoaWxToBoundsTransform release]; - m_cocoaWxToBoundsTransform = newTransform; - CocoaApplyTransformations(); -}; - -wxPaintDCImpl::~wxPaintDCImpl(void) -{ - CocoaUnwindStackAndLoseFocus(); -}; - -bool wxPaintDCImpl::CocoaLockFocus() -{ - wxFAIL_MSG(wxT("wxPaintDCImpl cannot be asked to lock focus!")); - return false; -} - -bool wxPaintDCImpl::CocoaUnlockFocus() -{ - // wxPaintDCImpl focus can never be unlocked. - return false; -} - diff --git a/src/cocoa/dcmemory.mm b/src/cocoa/dcmemory.mm deleted file mode 100644 index 1a2e1382cc..0000000000 --- a/src/cocoa/dcmemory.mm +++ /dev/null @@ -1,219 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dcmemory.mm -// Purpose: wxMemoryDCImpl class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/dcmemory.h" -#include "wx/cocoa/autorelease.h" - -#import -#import -#import -#import -#import - -//----------------------------------------------------------------------------- -// wxMemoryDCImpl -//----------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxCocoaDCImpl) - -void wxMemoryDCImpl::Init() -{ - m_cocoaNSImage = NULL; - m_ok = false; -} - -wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC *owner, wxDC *WXUNUSED(dc)) -: wxCocoaDCImpl(owner) -{ - Init(); -} - -wxMemoryDCImpl::~wxMemoryDCImpl(void) -{ - CocoaUnwindStackAndLoseFocus(); - [m_cocoaNSImage release]; -} - -bool wxMemoryDCImpl::CocoaLockFocus() -{ - if(m_cocoaNSImage) - { - [m_cocoaNSImage lockFocus]; - sm_cocoaDCStack.Insert(this); - NSAffineTransform *newTransform = CocoaGetWxToBoundsTransform([m_cocoaNSImage isFlipped], [m_cocoaNSImage size].height); - [newTransform retain]; - [m_cocoaWxToBoundsTransform release]; - m_cocoaWxToBoundsTransform = newTransform; - CocoaApplyTransformations(); - return true; - } - return false; -} - -bool wxMemoryDCImpl::CocoaUnlockFocus() -{ - [m_cocoaNSImage unlockFocus]; - return true; -} - -// NOTE: The AppKit is unable to draw onto an NSBitmapImageRep so we must -// instead copy the data to an offscreen window, then copy it back -void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) -{ - wxAutoNSAutoreleasePool pool; - if(m_selectedBitmap.IsOk()) - { - CocoaTakeFocus(); - wxASSERT(m_cocoaNSImage); - // Replace the bitmap's native data with a newly created one based on the - // NSImage that has been (potentially) drawn upon. Note that this may and - // probably will in many cases change the bitmap's format. - // There is nothing we can do about this using pure Cocoa code. Even using - // CGBitmapContext is not an option because it only supports a limited - // number of bitmap formats. Specifically, 24-bpp is not supported. - m_selectedBitmap.SetNSBitmapImageRep( - [[NSBitmapImageRep alloc] - initWithFocusedViewRect:NSMakeRect(0.0,0.0, - m_selectedBitmap.GetWidth(), - m_selectedBitmap.GetHeight())]); - } - CocoaUnwindStackAndLoseFocus(); - [m_cocoaNSImage release]; - m_cocoaNSImage = nil; - m_selectedBitmap = bitmap; - if(m_selectedBitmap.IsOk()) - { - // Create an offscreen window of the same size - m_cocoaNSImage = [[NSImage alloc] - initWithSize:NSMakeSize(m_selectedBitmap.GetWidth(), - m_selectedBitmap.GetHeight())]; - - // Now copy the data - // Pass false to GetNSImage so the mask is not applied as an alpha channel. - // Cocoa uses premultiplied alpha so applying the mask would cause all - // color information masked out to be turned black which is undesirable. - // FIXME: Currently, the mask will not be updated if any drawing occurs. - // My only suggestion is for wxCocoa users to eschew the mask in favor - // of an alpha channel or to recreate the mask after drawing. - // The only way to fix this is to draw twice, once as normal and again - // onto the mask to update it. That would require overriding every - // single drawing primitive (e.g. DoDrawLine, DoDrawRectangle, etc.) - // and would be a major undertaking. - NSImage *nsimage = [m_selectedBitmap.GetNSImage(false) retain]; - [m_cocoaNSImage lockFocus]; - [nsimage drawAtPoint: NSMakePoint(0,0) - fromRect: NSMakeRect(0.0,0.0,m_selectedBitmap.GetWidth(),m_selectedBitmap.GetHeight()) - operation: NSCompositeCopy - fraction: 1.0]; - [m_cocoaNSImage unlockFocus]; - - [nsimage release]; - } -} - -void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const -{ - if(width) - *width = m_selectedBitmap.GetWidth(); - if(height) - *height = m_selectedBitmap.GetHeight(); -} - -bool wxMemoryDCImpl::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest, - wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc, - int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) -{ - if(!m_selectedBitmap.IsOk()) - return false; - - NSAffineTransform *transform = [NSAffineTransform transform]; - [transform translateXBy:xdest yBy:ydest]; - - NSAffineTransform *flipTransform = [NSAffineTransform transform]; - /* x' = 1x + 0y + 0 - y' = 0x + -1y + window's height - */ - NSAffineTransformStruct matrix = { - 1, 0 - , 0, -1 - , 0, height - }; - [flipTransform setTransformStruct: matrix]; - - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - [transform concat]; - [flipTransform concat]; - - NSImage *sourceImage; - if(useMask) - { - sourceImage = [m_cocoaNSImage copy]; - // Apply the mask to the copied image - NSBitmapImageRep *maskRep = m_selectedBitmap.GetMask()->GetNSBitmapImageRep(); - NSImage *maskImage = [[NSImage alloc] initWithSize:[maskRep size]]; - [maskImage addRepresentation:maskRep]; - [sourceImage lockFocus]; - [maskImage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationIn]; - [sourceImage unlockFocus]; - [maskImage release]; - } - else - { // retain the m_cocoaNSImage so it has the same ownership as the copy done in the other case. - sourceImage = [m_cocoaNSImage retain]; - } - NSCompositingOperation drawingOp; - switch(logicalFunc) - { - case wxCOPY: - // Even if not using the mask, the image might have an alpha channel - // so always use NSCompositeSourceOver. If the image is fully opaque - // it works out the same as NSCompositeCopy. - drawingOp = NSCompositeSourceOver; - break; - // FIXME: implement more raster ops - default: - wxLogDebug(wxT("wxCocoa does not support blitting with raster operation %d."), logicalFunc); - // Just use the default operation. - drawingOp = NSCompositeCopy; - } - - wxLogTrace(wxTRACE_COCOA,wxT("[m_cocoaNSImage isFlipped]=%d"), [m_cocoaNSImage isFlipped]); - [sourceImage drawAtPoint: NSMakePoint(0,0) - fromRect: NSMakeRect(xsrc, - m_selectedBitmap.GetHeight()-height-ysrc, - width, height) - operation: drawingOp - fraction: 1.0]; - - [sourceImage release]; // It was either retained, copied, or allocated. - [context restoreGraphicsState]; - return false; -} - -bool wxMemoryDCImpl::CocoaGetBounds(void *rectData) -{ - if(!rectData) - return false; - if(!m_cocoaNSImage) - return false; - NSRect *pRect = (NSRect*)rectData; - pRect->origin.x = 0.0; - pRect->origin.y = 0.0; - pRect->size = [m_cocoaNSImage size]; - return true; -} - diff --git a/src/cocoa/dcscreen.cpp b/src/cocoa/dcscreen.cpp deleted file mode 100644 index bc18675ae0..0000000000 --- a/src/cocoa/dcscreen.cpp +++ /dev/null @@ -1,38 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dcscreen.cpp -// Purpose: wxScreenDCImpl class -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/cocoa/dcscreen.h" - -#ifndef WX_PRECOMP -#endif //WX_PRECOMP - -//----------------------------------------------------------------------------- -// wxMemoryDC -//----------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS(wxScreenDCImpl,wxCocoaDCImpl) - -wxScreenDCImpl::wxScreenDCImpl(wxScreenDC *owner) -: wxCocoaDCImpl(owner) -{ - m_ok = false; -} - -wxScreenDCImpl::wxScreenDCImpl(wxScreenDC *owner, wxDC *WXUNUSED(dc) ) -: wxCocoaDCImpl(owner) -{ - m_ok = false; -} - -wxScreenDCImpl::~wxScreenDCImpl(void) -{ -} diff --git a/src/cocoa/dialog.mm b/src/cocoa/dialog.mm deleted file mode 100644 index 8782dfab33..0000000000 --- a/src/cocoa/dialog.mm +++ /dev/null @@ -1,173 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dialog.mm -// Purpose: wxDialog class -// Author: David Elliott -// Modified by: -// Created: 2002/12/15 -// Copyright: 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/dialog.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" - #include "wx/settings.h" -#endif //WX_PRECOMP - -#include "wx/modalhook.h" -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import -#import -#import - -// Lists to keep track of windows, so we can disable/enable them -// for modal dialogs -static wxWindowList wxModalDialogs; - -IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) - -WX_IMPLEMENT_COCOA_OWNER(wxDialog,NSPanel,NSWindow,NSWindow) - -void wxDialog::Init() -{ - m_isModal = false; - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); -} - -bool wxDialog::Create(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - wxTopLevelWindows.Append(this); - - if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - - if (parent) - parent->AddChild(this); - - unsigned int cocoaStyle = NSWindowStyleForWxStyle(style); - - NSRect cocoaRect = MakeInitialNSWindowContentRect(pos,size,cocoaStyle); - - m_cocoaNSWindow = NULL; - SetNSPanel([[NSPanel alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]); - // NOTE: SetNSWindow has retained the Cocoa object for this object. - // Because we do not release on close, the following release matches the - // above alloc and thus the retain count will be 1. - [m_cocoaNSWindow release]; - wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxDialog m_cocoaNSWindow retainCount=%d"),[m_cocoaNSWindow retainCount]); - [m_cocoaNSWindow setTitle:wxNSStringWithWxString(title)]; - [m_cocoaNSWindow setHidesOnDeactivate:NO]; - - return true; -} - -wxDialog::~wxDialog() -{ - DisassociateNSPanel(GetNSPanel()); -} - -void wxDialog::CocoaDelegate_windowWillClose(void) -{ - m_closed = true; - /* Actually, this isn't true anymore */ - wxLogTrace(wxTRACE_COCOA,wxT("Woah: Dialogs are not generally closed")); -} - -void wxDialog::SetModal(bool flag) -{ - wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); -} - -bool wxDialog::Show(bool show) -{ - if(m_isShown == show) - return false; - - if(show) - { - wxAutoNSAutoreleasePool pool; - - if (CanDoLayoutAdaptation()) - DoLayoutAdaptation(); - - InitDialog(); - if(IsModal()) - { // ShowModal() will show the dialog - m_isShown = true; - return true; - } - } - else - { - if(IsModal()) - { // this doesn't hide the dialog, base class Show(false) does. - wxLogTrace(wxTRACE_COCOA,wxT("abortModal")); - [wxTheApp->GetNSApplication() abortModal]; - wxModalDialogs.DeleteObject(this); - m_isModal = false; - } - } - return wxTopLevelWindow::Show(show); -} - -// Shows the dialog and begins a modal event loop. When the event loop -// is stopped (via EndModal()) it returns the exit code. -int wxDialog::ShowModal() -{ - WX_HOOK_MODAL_DIALOG(); - - wxCHECK_MSG(!IsModal(),GetReturnCode(),wxT("wxDialog::ShowModal called within its own modal loop")); - - // Show(true) will set m_isShown = true - m_isShown = false; - m_isModal = true; - wxModalDialogs.Append(this); - - wxLogTrace(wxTRACE_COCOA,wxT("runModal")); - NSApplication *theNSApp = wxTheApp->GetNSApplication(); - // If the app hasn't started, flush the event queue - // If we don't do this, the Dock doesn't get the message that - // the app has started so will refuse to activate it. - if(![theNSApp isRunning]) - { - // We should only do a few iterations so one pool should be okay - wxAutoNSAutoreleasePool pool; - while(NSEvent *event = [theNSApp - nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:NSDefaultRunLoopMode - dequeue: YES]) - { - [theNSApp sendEvent: event]; - } - } - - Show(true); - do { - wxAutoNSAutoreleasePool pool; - [wxTheApp->GetNSApplication() runModalForWindow:m_cocoaNSWindow]; - } while(0); - wxLogTrace(wxTRACE_COCOA,wxT("runModal END")); - - return GetReturnCode(); -} - -void wxDialog::EndModal(int retCode) -{ - wxASSERT_MSG(IsModal(), wxT("EndModal() should only be used within ShowModal()")); - SetReturnCode(retCode); - Show(false); -} diff --git a/src/cocoa/dirdlg.mm b/src/cocoa/dirdlg.mm deleted file mode 100644 index e0a066f359..0000000000 --- a/src/cocoa/dirdlg.mm +++ /dev/null @@ -1,148 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dirdlg.mm -// Purpose: wxDirDialog for wxCocoa -// Author: Ryan Norton -// Modified by: Hiroyuki Nakamura(maloninc) -// Created: 2006-01-10 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#if wxUSE_DIRDLG - -#include "wx/dirdlg.h" - -#ifndef WX_PRECOMP - #include "wx/msgdlg.h" - #include "wx/filedlg.h" - #include "wx/app.h" -#endif - -#include "wx/filename.h" -#include "wx/modalhook.h" - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import - -#import -// ============================================================================ -// implementation -// ============================================================================ - -IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog) - -// ---------------------------------------------------------------------------- -// wxDirDialog -// ---------------------------------------------------------------------------- - -wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message, - const wxString& defaultPath, long style, const wxPoint& pos, - const wxSize& size, const wxString& name) -{ - wxTopLevelWindows.Append(this); - - m_message = message; - - SetWindowStyle(style); - m_parent = parent; - m_path = defaultPath; - - wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr)); - - if ( parent ) - parent->AddChild(this); - - m_cocoaNSWindow = nil; - m_cocoaNSView = nil; - - //If the user requests to save - use a NSSavePanel - //else use a NSOpenPanel - if (HasFlag(wxFD_SAVE)) - { - SetNSPanel([NSSavePanel savePanel]); - - [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)]; - - [GetNSSavePanel() setPrompt:@"Save"]; - [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES]; - [GetNSSavePanel() setCanSelectHiddenExtension:YES]; - } - else //m_dialogStyle & wxFD_OPEN - { - SetNSPanel([NSOpenPanel openPanel]); - [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)]; - - [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES]; - [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO]; - [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES]; - [GetNSSavePanel() setPrompt:@"Open"]; - } - - if (HasFlag(wxDD_NEW_DIR_BUTTON)) //m_dialogStyle & wxDD_NEW_DIR_BUTTON - { - [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES]; - } -} - -wxDirDialog::~wxDirDialog() -{ -} - -int wxDirDialog::ShowModal() -{ - WX_HOOK_MODAL_DIALOG(); - - wxAutoNSAutoreleasePool thePool; - - m_fileNames.Empty(); - - int nResult; - - if (HasFlag(wxFD_SAVE)) - { - nResult = [GetNSSavePanel() - runModalForDirectory:wxNSStringWithWxString(m_dir) - file:wxNSStringWithWxString(m_fileName)]; - - if (nResult == NSOKButton) - { - m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename])); - m_path = m_fileNames[0]; - } - } - else //m_dialogStyle & wxFD_OPEN - { - nResult = [(NSOpenPanel*)m_cocoaNSWindow - runModalForDirectory:wxNSStringWithWxString(m_dir) - file:wxNSStringWithWxString(m_fileName) - types:NULL]; - - if (nResult == NSOKButton) - { - for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i) - { - m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)])); - } - - m_path = m_fileNames[0]; - } - } - - return nResult == NSOKButton ? wxID_OK : wxID_CANCEL; -} - -#endif // wxUSE_DIRDLG diff --git a/src/cocoa/display.mm b/src/cocoa/display.mm deleted file mode 100644 index 721fe3b425..0000000000 --- a/src/cocoa/display.mm +++ /dev/null @@ -1,221 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/display.mm -// Purpose: Cocoa implementation of wxDisplay class -// Author: Ryan Norton -// Modified by: -// Created: 2004-10-03 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#if wxUSE_DISPLAY - -#include "wx/display.h" - -#ifndef WX_PRECOMP - #include "wx/dynarray.h" - #include "wx/string.h" - #include "wx/gdicmn.h" -#endif - -#include "wx/display_impl.h" - -#import - -// ---------------------------------------------------------------------------- -// display classes implementation -// ---------------------------------------------------------------------------- - -class wxDisplayImplMacOSX : public wxDisplayImpl -{ -public: - wxDisplayImplMacOSX(unsigned n, CGDirectDisplayID id_) - : wxDisplayImpl(n), - m_id(id_) - { - } - - virtual wxRect GetGeometry() const; - virtual wxString GetName() const { return wxString(); } - - virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const; - virtual wxVideoMode GetCurrentMode() const; - virtual bool ChangeMode(const wxVideoMode& mode); - -private: - CGDirectDisplayID m_id; - - wxDECLARE_NO_COPY_CLASS(wxDisplayImplMacOSX); -}; - -class wxDisplayFactoryMacOSX : public wxDisplayFactory -{ -public: - wxDisplayFactoryMacOSX() { } - - virtual wxDisplayImpl *CreateDisplay(unsigned n); - virtual unsigned GetCount(); - virtual int GetFromPoint(const wxPoint& pt); - -protected: - wxDECLARE_NO_COPY_CLASS(wxDisplayFactoryMacOSX); -}; - -// ============================================================================ -// wxDisplayFactoryMacOSX implementation -// ============================================================================ - -unsigned wxDisplayFactoryMacOSX::GetCount() -{ - CGDisplayCount count; - CGDisplayErr err = CGGetActiveDisplayList(0, NULL, &count); - wxCHECK_MSG( err != CGDisplayNoErr, 0, "CGGetActiveDisplayList() failed" ); - - return count; -} - -int wxDisplayFactoryMacOSX::GetFromPoint(const wxPoint& p) -{ - CGPoint thePoint = {(float)p.x, (float)p.y}; - CGDirectDisplayID theID; - CGDisplayCount theCount; - CGDisplayErr err = CGGetDisplaysWithPoint(thePoint, 1, &theID, &theCount); - wxASSERT(err == CGDisplayNoErr); - - int nWhich = wxNOT_FOUND; - - if (theCount) - { - theCount = GetCount(); - CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount]; - err = CGGetActiveDisplayList(theCount, theIDs, &theCount); - wxASSERT(err == CGDisplayNoErr); - - for (nWhich = 0; nWhich < (int) theCount; ++nWhich) - { - if (theIDs[nWhich] == theID) - break; - } - - delete [] theIDs; - - if (nWhich == (int) theCount) - { - wxFAIL_MSG(wxT("Failed to find display in display list")); - nWhich = wxNOT_FOUND; - } - } - - return nWhich; -} - -wxDisplayImpl *wxDisplayFactoryMacOSX::CreateDisplay(unsigned n) -{ - CGDisplayCount theCount = GetCount(); - CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount]; - - CGDisplayErr err = CGGetActiveDisplayList(theCount, theIDs, &theCount); - wxCHECK_MSG( err != CGDisplayNoErr, NULL, "CGGetActiveDisplayList() failed" ); - - wxASSERT( n < theCount ); - - wxDisplayImplMacOSX *display = new wxDisplayImplMacOSX(n, theIDs[n]); - - delete [] theIDs; - - return display; -} - - -wxRect wxDisplayImplMacOSX::GetGeometry() const -{ - CGRect theRect = CGDisplayBounds(m_id); - return wxRect( (int)theRect.origin.x, - (int)theRect.origin.y, - (int)theRect.size.width, - (int)theRect.size.height ); //floats -} - -static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key ) -{ - CFNumberRef value; - int num = 0; - - if ( (value = (CFNumberRef) CFDictionaryGetValue(desc, key)) == NULL ) - return 0; - CFNumberGetValue(value, kCFNumberIntType, &num); - return num; -} - -wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const -{ - wxArrayVideoModes Modes; - - CFArrayRef theArray = CGDisplayAvailableModes(m_id); - - for(CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) - { - CFDictionaryRef theValue = (CFDictionaryRef) CFArrayGetValueAtIndex(theArray, i); - - wxVideoMode theMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth), - wxCFDictKeyToInt(theValue, kCGDisplayHeight), - wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel), - wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate)); - - if (theMode.Matches(mode)) - Modes.Add(theMode); - } - - return Modes; -} - -wxVideoMode wxDisplayImplMacOSX::GetCurrentMode() const -{ - CFDictionaryRef theValue = CGDisplayCurrentMode (m_id); - - return wxVideoMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth), - wxCFDictKeyToInt(theValue, kCGDisplayHeight), - wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel), - wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate)); -} - -bool wxDisplayImplMacOSX::ChangeMode(const wxVideoMode& mode) -{ - //Changing to default mode (wxDefualtVideoMode) doesn't - //work because we don't have access to the system's 'scrn' - //resource which holds the user's mode which the system - //will return to after this app is done - boolean_t bExactMatch; - CFDictionaryRef theCGMode = CGDisplayBestModeForParametersAndRefreshRate ( - m_id, - (size_t)mode.bpp, - (size_t)mode.w, - (size_t)mode.h, - (double)mode.refresh, - &bExactMatch); - - bool bOK = bExactMatch; - - if(bOK) - bOK = CGDisplaySwitchToMode(m_id, theCGMode) == CGDisplayNoErr; - - return bOK; -} - -// ============================================================================ -// wxDisplay::CreateFactory() -// ============================================================================ - -/* static */ wxDisplayFactory *wxDisplay::CreateFactory() -{ - return new wxDisplayFactoryMacOSX; -} - -#endif // wxUSE_DISPLAY diff --git a/src/cocoa/drawer.mm b/src/cocoa/drawer.mm deleted file mode 100644 index 8b13789179..0000000000 --- a/src/cocoa/drawer.mm +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/cocoa/dummy.r b/src/cocoa/dummy.r deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/cocoa/evtloop.mm b/src/cocoa/evtloop.mm deleted file mode 100644 index 8e34eb0143..0000000000 --- a/src/cocoa/evtloop.mm +++ /dev/null @@ -1,152 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/evtloop.mm -// Purpose: implements wxEventLoop for Cocoa -// Author: David Elliott -// Created: 2003/10/02 -// Copyright: (c) 2003 David Elliott -// (c) 2013 Rob Bresalier -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/evtloop.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" -#endif //WX_PRECOMP - -#import -#import -#import - -// ======================================================================== -// wxGUIEventLoop -// ======================================================================== - -// ---------------------------------------------------------------------------- -// wxGUIEventLoop running and exiting -// ---------------------------------------------------------------------------- - -int wxGUIEventLoop::DoRun() -{ - [[NSApplication sharedApplication] run]; - - OnExit(); - - return m_exitcode; -} - -void wxGUIEventLoop::ScheduleExit(int rc) -{ - wxCHECK_RET( IsInsideRun(), wxT("can't call ScheduleExit() if not started") ); - - m_exitcode = rc; - - NSApplication *cocoaApp = [NSApplication sharedApplication]; - wxLogTrace(wxTRACE_COCOA,wxT("wxEventLoop::Exit isRunning=%d"), (int)[cocoaApp isRunning]); - wxTheApp->WakeUpIdle(); - /* Notes: - If we're being called from idle time (which occurs while checking the - queue for new events) there may or may not be any events in the queue. - In order to successfully stop the event loop, at least one event must - be processed. To ensure this always happens, WakeUpIdle is called. - - If the application was active when closed then this is unnecessary - because it would receive a deactivate event anyway. However, if the - application was not active when closed, then no events would be - added to the queue by Cocoa and thus the application would wait - indefinitely for the next event. - */ - [cocoaApp stop: cocoaApp]; -} - -// ---------------------------------------------------------------------------- -// wxEventLoop message processing dispatching -// ---------------------------------------------------------------------------- - -bool wxGUIEventLoop::Pending() const -{ - // a pointer to the event is returned if there is one, or nil if not - return [[NSApplication sharedApplication] - nextEventMatchingMask: NSAnyEventMask - untilDate: nil /* Equivalent to [NSDate distantPast] */ - inMode: NSDefaultRunLoopMode - dequeue: NO]; -} - -bool wxGUIEventLoop::Dispatch() -{ - // This check is required by wxGTK but probably not really for wxCocoa - // Keep it here to encourage developers to write cross-platform code - wxCHECK_MSG( IsRunning(), false, wxT("can't call Dispatch() if not running") ); - NSApplication *cocoaApp = [NSApplication sharedApplication]; - // Block to retrieve an event then send it - if(NSEvent *event = [cocoaApp - nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantFuture] - inMode:NSDefaultRunLoopMode - dequeue: YES]) - { - [cocoaApp sendEvent: event]; - } - - return true; -} - -int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) -{ - NSApplication *cocoaApp = [NSApplication sharedApplication]; - NSEvent *event = [cocoaApp - nextEventMatchingMask:NSAnyEventMask - untilDate:[[NSDate alloc] initWithTimeIntervalSinceNow:timeout/1000] - inMode:NSDefaultRunLoopMode - dequeue: YES]; - if ( !event ) - return -1; - - [cocoaApp sendEvent: event]; - - return true; -} - -void wxGUIEventLoop::DoYieldFor(long eventsToProcess) -{ - // Run the event loop until it is out of events - while (1) - { - // TODO: implement event filtering using the eventsToProcess mask - - wxAutoNSAutoreleasePool pool; - /* NOTE: It may be better to use something like - NSEventTrackingRunLoopMode since we don't necessarily want all - timers/sources/observers to run, only those which would - run while tracking events. However, it should be noted that - NSEventTrackingRunLoopMode is in the common set of modes - so it may not effectively make much of a difference. - */ - NSEvent *event = [GetNSApplication() - nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:NSDefaultRunLoopMode - dequeue: YES]; - if(!event) - break; - [GetNSApplication() sendEvent: event]; - } - - /* - Because we just told NSApplication to avoid blocking it will in turn - run the CFRunLoop with a timeout of 0 seconds. In that case, our - run loop observer on kCFRunLoopBeforeWaiting never fires because - no waiting occurs. Therefore, no idle events are sent. - - Believe it or not, this is actually desirable because we do not want - to process idle from here. However, we do want to process pending - events because some user code expects to do work in a thread while - the main thread waits and then notify the main thread by posting - an event. - */ - wxEventLoopBase::DoYieldFor(eventsToProcess); -} diff --git a/src/cocoa/filedlg.mm b/src/cocoa/filedlg.mm deleted file mode 100644 index 1ed7ea0182..0000000000 --- a/src/cocoa/filedlg.mm +++ /dev/null @@ -1,240 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/filedlg.mm -// Purpose: wxFileDialog for wxCocoa -// Author: Ryan Norton -// Modified by: -// Created: 2004-10-02 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#if wxUSE_FILEDLG - -#include "wx/filedlg.h" - -#ifndef WX_PRECOMP - #include "wx/msgdlg.h" - #include "wx/app.h" -#endif - -#include "wx/filename.h" - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/modalhook.h" - -#import -#import - -#import -// ============================================================================ -// implementation -// ============================================================================ - -IMPLEMENT_CLASS(wxCocoaFileDialog, wxFileDialogBase) - -// ---------------------------------------------------------------------------- -// wxFileDialog -// ---------------------------------------------------------------------------- - -wxFileDialog::wxFileDialog(wxWindow *parent, - const wxString& message, - const wxString& defaultDir, - const wxString& defaultFileName, - const wxString& wildCard, - long style, - const wxPoint& pos, - const wxSize& sz, - const wxString& name) - : wxFileDialogBase(parent, message, defaultDir, defaultFileName, - wildCard, style, pos, sz, name) -{ - wxTopLevelWindows.Append(this); - - wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr)); - - if ( parent ) - parent->AddChild(this); - - m_cocoaNSWindow = nil; - m_cocoaNSView = nil; - - //Init the wildcard array - m_wildcards = [[NSMutableArray alloc] initWithCapacity:0]; - - //If the user requests to save - use a NSSavePanel - //else use a NSOpenPanel - if (HasFlag(wxFD_SAVE)) - { - SetNSPanel([NSSavePanel savePanel]); - - [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)]; - - [GetNSSavePanel() setPrompt:@"Save"]; - [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES]; - [GetNSSavePanel() setCanSelectHiddenExtension:YES]; - -// Cached as per-app in obj-c -// [GetNSSavePanel() setExtensionHidden:YES]; - - // - // NB: Note that only Panther supports wildcards - // with save dialogs - not that wildcards in save - // dialogs are all that useful, anyway :) - // - } - else //m_dialogStyle & wxFD_OPEN - { - SetNSPanel([NSOpenPanel openPanel]); - [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)]; - - [(NSOpenPanel*)m_cocoaNSWindow setAllowsMultipleSelection:(HasFlag(wxFD_MULTIPLE))]; - [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES]; - [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:YES]; - [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:NO]; - [GetNSSavePanel() setPrompt:@"Open"]; - - //convert wildcards - open panel only takes file extensions - - //no actual wildcards here :) - size_t lastwcpos = 0; - bool bDescription = true; - size_t i; - for(i = wildCard.find('|'); - i != wxString::npos; - i = wildCard.find('|', lastwcpos+1)) - { - size_t oldi = i; - - if(!bDescription) - { - bDescription = !bDescription; - - //work backwards looking for a period - while(i != lastwcpos && wildCard[--i] != '.') {} - - if(i == lastwcpos) - { - //no extension - can't use this wildcard - lastwcpos = oldi; - continue; - } - - [m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))]; - } - else - bDescription = !bDescription; - lastwcpos = oldi; - } - - if (!bDescription) - { - //get last wildcard - size_t oldi = wildCard.length(); - i = oldi; - - //work backwards looking for a period - while(i != lastwcpos && wildCard[--i] != '.') {} - - if(i != lastwcpos) - [m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))]; - } - - if ([m_wildcards count] == 0) - { - [m_wildcards release]; - m_wildcards = nil; - } - } -} - -wxFileDialog::~wxFileDialog() -{ - [m_wildcards release]; -} - -void wxFileDialog::GetPaths(wxArrayString& paths) const -{ - paths.Empty(); - - wxString dir(m_dir); - if ( m_dir.Last() != wxT('\\') ) - dir += wxT('\\'); - - size_t count = m_fileNames.GetCount(); - for ( size_t n = 0; n < count; n++ ) - { - if (wxFileName(m_fileNames[n]).IsAbsolute()) - paths.Add(m_fileNames[n]); - else - paths.Add(dir + m_fileNames[n]); - } -} - -void wxFileDialog::GetFilenames(wxArrayString& files) const -{ - files = m_fileNames; -} - -void wxFileDialog::SetPath(const wxString& path) -{ - wxString ext; - wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext); - if ( !ext.empty() ) - m_fileName << wxT('.') << ext; -} - -int wxFileDialog::ShowModal() -{ - WX_HOOK_MODAL_DIALOG(); - - wxAutoNSAutoreleasePool thePool; - - m_fileNames.Empty(); - - int nResult; - - if (HasFlag(wxFD_SAVE)) - { - nResult = [GetNSSavePanel() - runModalForDirectory:wxNSStringWithWxString(m_dir) - file:wxNSStringWithWxString(m_fileName)]; - - if (nResult == NSOKButton) - { - m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename])); - m_path = m_fileNames[0]; - } - } - else //m_dialogStyle & wxFD_OPEN - { - nResult = [(NSOpenPanel*)m_cocoaNSWindow - runModalForDirectory:wxNSStringWithWxString(m_dir) - file:wxNSStringWithWxString(m_fileName) - types:m_wildcards]; - - if (nResult == NSOKButton) - { - for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i) - { - m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)])); - } - - m_path = m_fileNames[0]; - } - } - - return nResult == NSOKButton ? wxID_OK : wxID_CANCEL; -} - -#endif // wxUSE_FILEDLG diff --git a/src/cocoa/font.mm b/src/cocoa/font.mm deleted file mode 100644 index 946f77b4ef..0000000000 --- a/src/cocoa/font.mm +++ /dev/null @@ -1,472 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/font.mm -// Purpose: wxFont class -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 -// Copyright: (c) AUTHOR -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -/*! @file font.mm - @disucssion - Cocoa has three classes which interact to form the font system: - - NSFont: Represents a specific font (e.g. Times-Bold) at a specific size - with specific attributes. That is, it's basically like this class. - Notably, it doesn't hold an underlined flag, so this class does. - Available on all OS X versions. - - NSFontManager: Fairly broad controller class which ties together the - model (NSFont) with the view (NSFontPanel). We are ignoring NSFontPanel - in this discussion. NSFontManager is actually a little broader than just - a controller though. It's also the traditional way of mutating fonts - and asking for a font with a certain family and certain attributes. - For example, you can use NSFont's factor methods to create a font named - @"Times-Roman" then use NSFontManager to imbue attributes like italic and - bold. You might do this if, for instance, you already have times at the - Roman weight but want to make it bold. - - Alternatively, you can use NSFontManager to ask for a font in the @"Times" - family with the bold attribute. - - NSFontManager is available on all OS X versions. - - NSFontDescriptor: Added in OS X 10.3. Prior to this there was no specific - class to represent all of the attributes of a font. Instead, a regular - NSDictionary was used with a set of well-defined keys. Unfortunately, - there was no method accepting the attributes dictionary, only a method - to retrieve it from an NSFont. That meant that in order to create - a new font by imbueing certain attributes like Bold one would need - to use the specific method in NSFontManager to do so. - - The NSFontDescriptor class, on the other hand, has factory methods which - can create a new font descriptor with an attributes dictionary as well - as mutate (by copy) an existing font descriptor using attributes from - an attributes dictionary. - - In theory, most of what can be done using NSFontDescriptor can just as - well be done without it. NSFontDescriptor is basically just a shell - around an NSMutableDictionary with well-defined keys. - - - Getting back to the broad overview, font matching is one of the weaker points - in Cocoa's API and NSFontDescriptor is the easier to use solution. - - That said, it's not impossible to implement font matching without it. For instance, - if you have a family name and want to list available variants (e.g. Bold, italic, - underlined) then you can ask NSFontManager for availableMembersOfFontFamily:. - - The problem is that you can either match on family name or on font attributes - but not on both. To match both you have to do one then the other. - NSFontDescriptor allows you to get a list of fonts matching both a family name - and a particular set of attributes. Furthermore, the attributes instead of - being flags as in NSFontManager are instead well-defined keys in a dictionary. - - The only way to get that behaviour without NSFontManager is to pare down the - list as much as possible using the classic NSFontManager methods and then - to instantiate each font in the list and match on each font's afmDictionary. - - A reasonable guess is that that's probably more or less exactly what - NSFontDescriptor does internally. - */ -#include "wx/wxprec.h" - -#include "wx/font.h" - -#ifndef WX_PRECOMP - #include "wx/string.h" - #include "wx/gdicmn.h" -#endif - -#include "wx/fontutil.h" -#include "wx/encinfo.h" - -#include "wx/cocoa/string.h" -#include "wx/cocoa/private/fontfactory.h" -#include "wx/cocoa/autorelease.h" - -#include -#include - -// Helper methods for NSFont/wxNativeFontInfo -static NSFont* GetNSFontForNativeFontInfo(const wxNativeFontInfo &info); -static void UpdateNativeFontInfoWithNSFont(wxNativeFontInfo &info, NSFont *cocoaNSFont); -static wxNativeFontInfo MakeNativeFontInfoForNSFont(NSFont *cocoaNSFont, bool underlined = false); -static wxNativeFontInfo MakeNativeFontInfo(int size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding); - -/*! @discussion - Due to 2.8 ABI compatibility concerns we probably don't want to change wxNativeFontInfo - although this may be unfounded because this class is supposed to be internal as is - wxNativeFontInfo so anyone who subclassed it or created one without going through - wxFont should expect what they get (i.e. horrible breakage) - There's a concern that wxFontRefData was in the public header when 2.8 shipped so - it's possible that someone did subclass it to get better font behaviour. - - For right now, the plan is to write it strictly ABI compatible with 2.8 and eventually - to enhance it in trunk to accurately represent font attributes as Cocoa sees them. - - I'd like to let at least one 2.8 release go out the door and get feedback as to whether - this is going to be a problem or not. If so, we'll keep it strictly ABI compatible. - If not, we'll update it. - */ -class WXDLLEXPORT wxFontRefData: public wxGDIRefData -{ - friend class WXDLLIMPEXP_FWD_CORE wxFont; -public: - wxFontRefData() - : m_cocoaNSFont(nil) - , m_info(MakeNativeFontInfo(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, - wxT("Geneva"), wxFONTENCODING_DEFAULT)) - { - CreateNSFontAndUpdateInfo(); - } - - wxFontRefData(const wxFontRefData& data) - : wxGDIRefData() - , m_cocoaNSFont([data.m_cocoaNSFont retain]) - , m_info(data.m_info) - { - } - - wxFontRefData(NSFont *cocoaNSFont, bool underlined) - : wxGDIRefData() - , m_cocoaNSFont([cocoaNSFont retain]) - , m_info(MakeNativeFontInfoForNSFont(m_cocoaNSFont, underlined)) - { - } - - wxFontRefData(const wxNativeFontInfo& info) - : wxGDIRefData() - , m_cocoaNSFont(nil) - , m_info(info) - { - CreateNSFontAndUpdateInfo(); - } - - wxFontRefData(int size, - wxFontFamily family, - wxFontStyle style, - wxFontWeight weight, - bool underlined, - const wxString& faceName, - wxFontEncoding encoding) - : m_cocoaNSFont(nil) - , m_info(MakeNativeFontInfo(size, family, style, weight, underlined, faceName, encoding)) - { - CreateNSFontAndUpdateInfo(); - } - - virtual ~wxFontRefData(); -protected: - /*! @abstract common part of some ctors - @discussion - This is a leftover of sorts from the old stub code. - FIXME: Remove from trunk - */ - void Init(int size, - wxFontFamily family, - wxFontStyle style, - wxFontWeight weight, - bool underlined, - const wxString& faceName, - wxFontEncoding encoding); - - /*! @discussion - Uses the native font info to create an NSFont and then updates that info with - the attributes of the font. This is necessary because, for example, a font - can be created with an empty faceName in which case some concrete typeface must - be chosen. - We choose to handle this by first initializing the wxNativeFontInfo with the - properties as given by the user and then creating the NSFont and updating - the wxNativeFontInfo to match the NSFont. - */ - void CreateNSFontAndUpdateInfo() - { - wxAutoNSAutoreleasePool pool; - [m_cocoaNSFont release]; - m_cocoaNSFont = [GetNSFontForNativeFontInfo(m_info) retain]; - UpdateNativeFontInfoWithNSFont(m_info, m_cocoaNSFont); - } - - // font characterstics - NSFont *m_cocoaNSFont; - wxNativeFontInfo m_info; - -public: -}; - -NSString *GetFamilyName(wxFontFamily family) -{ - switch(family) - { - case wxFONTFAMILY_DEFAULT: - default: - return @"Times"; - case wxFONTFAMILY_DECORATIVE: - case wxFONTFAMILY_ROMAN: - case wxFONTFAMILY_SCRIPT: - return @"Times"; - case wxFONTFAMILY_SWISS: - return @"Lucida Grande"; - case wxFONTFAMILY_MODERN: - case wxFONTFAMILY_TELETYPE: - return @"Monaco"; - }; -} -// Returns an NSFont given the native font info -// NOTE: It is not considered alloc'd (i.e. this is a get method not an alloc/new method) -static NSFont* GetNSFontForNativeFontInfo(const wxNativeFontInfo &info) -{ - if(!info.faceName.empty()) - { - NSFont *font = [NSFont fontWithName:wxNSStringWithWxString(info.faceName) size:info.pointSize]; - // TODO: use NSFontManager to mix in the weights and whatnot - if(font != nil) - return font; - // To err or not to err? - } - // No font with that face name or no face name - - NSFontTraitMask cocoaTraits = 0; - int cocoaWeight = 5; - NSFont *font = [[NSFontManager sharedFontManager] fontWithFamily:GetFamilyName(info.family) traits:cocoaTraits weight:cocoaWeight size:info.pointSize]; - return font; -} - -/*! @discussion - Updates all fields of @a info except for underlined which is not a property of NSFont. - */ -static void UpdateNativeFontInfoWithNSFont(wxNativeFontInfo &info, NSFont *cocoaNSFont) -{ - info.pointSize = [cocoaNSFont pointSize]; - - // FIXME: We could maybe improve on this? - info.family = wxFONTFAMILY_DEFAULT; - - // FIXME: italicAngle might indicate a slanted rather than truly italic font? - info.style = [cocoaNSFont italicAngle] == 0.0?wxFONTSTYLE_NORMAL:wxFONTSTYLE_ITALIC; - - int cocoaWeight = [[NSFontManager sharedFontManager] weightOfFont:cocoaNSFont]; - if(cocoaWeight < 5) - info.weight = wxFONTWEIGHT_LIGHT; - else if(cocoaWeight < 9) - info.weight = wxFONTWEIGHT_NORMAL; - else - info.weight = wxFONTWEIGHT_BOLD; - - // FIXME: Is this right? I think so. - info.faceName = wxStringWithNSString([cocoaNSFont fontName]); - - // TODO: Translate NSStringEncoding to wxFontEncoding - info.encoding = wxFONTENCODING_SYSTEM; -} - -/*! @discussion - Creates a new generic wxNativeFontInfo from an NSFont and an underlined flag. - Uses UpdateNativeFontInfoWithNSFont to do the work and sets the underlined field - of wxNativeFontInfo to the @a underlined argument. - */ -static wxNativeFontInfo MakeNativeFontInfoForNSFont(NSFont *cocoaNSFont, bool underlined) -{ - wxNativeFontInfo info; - UpdateNativeFontInfoWithNSFont(info, cocoaNSFont); - - // NSFont are never underlined.. that's a function of the drawing system - info.underlined = underlined; - - return info; -} - -//#include "_font_test_2_8_abi_compat.h" - -static wxNativeFontInfo MakeNativeFontInfo(int size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) -{ - wxNativeFontInfo m_info; // NOTE: not an i-var despite name - m_info.pointSize = size; - m_info.family = static_cast(family); - m_info.style = static_cast(style); - m_info.weight = static_cast(weight); - m_info.underlined = underlined; - m_info.faceName = faceName; - m_info.encoding = encoding; - return m_info; -} - -void wxFontRefData::Init(int size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) -{ - m_info = MakeNativeFontInfo(size, family, style, weight, underlined, faceName, encoding); -} - -wxFontRefData::~wxFontRefData() -{ - [m_cocoaNSFont release]; - m_cocoaNSFont = nil; - // TODO: delete font data -} - -#define M_FONTDATA ((wxFontRefData*)m_refData) - -wxFont wxCocoaFontFactory::InstanceForNSFont(WX_NSFont cocoaFont, bool underlined) -{ - return wxFont(new wxFontRefData(cocoaFont, underlined)); -} - -bool wxFont::Create(wxFontRefData *refData) -{ - UnRef(); - m_refData = refData; - - return m_refData != NULL; -} - -bool wxFont::Create(const wxNativeFontInfo& nativeFontInfo) -{ - UnRef(); - m_refData = new wxFontRefData(nativeFontInfo); - - return true; -} - -wxGDIRefData *wxFont::CreateGDIRefData() const -{ - return new wxFontRefData; -} - -wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const -{ - return new wxFontRefData(*static_cast(data)); -} - -void wxFont::SetEncoding(wxFontEncoding) -{ -} - -wxFontEncoding wxFont::GetEncoding() const -{ - return wxFontEncoding(); -} - -int wxFont::GetPointSize() const -{ - wxCHECK_MSG( IsOk(), 0, wxT("invalid font") ); - return M_FONTDATA->m_info.pointSize; -} - -bool wxFont::GetUnderlined() const -{ - if(M_FONTDATA) - return M_FONTDATA->m_info.underlined; - else - return false; -} - -wxFontStyle wxFont::GetStyle() const -{ - wxCHECK_MSG( IsOk(), 0, wxT("invalid font") ); - return M_FONTDATA->m_info.style; -} - -wxFontFamily wxFont::DoGetFamily() const -{ - return M_FONTDATA->m_info.family; -} - -wxFontWeight wxFont::GetWeight() const -{ - wxCHECK_MSG( IsOk(), 0, wxT("invalid font") ); - return M_FONTDATA->m_info.weight; -} - -const wxNativeFontInfo *wxFont::GetNativeFontInfo() const -{ - wxCHECK_MSG( IsOk(), 0, wxT("invalid font") ); - return &M_FONTDATA->m_info; -} - -bool wxFont::Create(int pointSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) -{ - UnRef(); - m_refData = new wxFontRefData(pointSize, family, style, weight, underlined, faceName, encoding); - - RealizeResource(); - - return true; -} - -wxFont::~wxFont() -{ -} - -bool wxFont::RealizeResource() -{ - // TODO: create the font (if there is a native font object) - return false; -} - -void wxFont::SetPointSize(int pointSize) -{ - AllocExclusive(); - - M_FONTDATA->m_info.pointSize = pointSize; - - RealizeResource(); -} - -void wxFont::SetFamily(wxFontFamily family) -{ - AllocExclusive(); - - M_FONTDATA->m_info.family = static_cast(family); - - RealizeResource(); -} - -void wxFont::SetStyle(wxFontStyle style) -{ - AllocExclusive(); - - M_FONTDATA->m_info.style = static_cast(style); - - RealizeResource(); -} - -void wxFont::SetWeight(wxFontWeight weight) -{ - AllocExclusive(); - - M_FONTDATA->m_info.weight = static_cast(weight); - - RealizeResource(); -} - -bool wxFont::SetFaceName(const wxString& faceName) -{ - AllocExclusive(); - - M_FONTDATA->m_info.faceName = faceName; - - RealizeResource(); - - return wxFontBase::SetFaceName(faceName); -} - -void wxFont::SetUnderlined(bool underlined) -{ - AllocExclusive(); - - M_FONTDATA->m_info.underlined = underlined; - - RealizeResource(); -} - -/* New font system */ -wxString wxFont::GetFaceName() const -{ - wxString str; - if (M_FONTDATA) - str = M_FONTDATA->m_info.faceName; - return str; -} - -// vim:sts=4:sw=4:et diff --git a/src/cocoa/fontdlg.mm b/src/cocoa/fontdlg.mm deleted file mode 100644 index 8b13789179..0000000000 --- a/src/cocoa/fontdlg.mm +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/cocoa/fontenum.mm b/src/cocoa/fontenum.mm deleted file mode 100644 index 39f7b58d3f..0000000000 --- a/src/cocoa/fontenum.mm +++ /dev/null @@ -1,27 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/fontenum.mm -// Purpose: wxFontEnumerator class for Cocoa -// Author: David Elliott -// Modified by: -// Created: 2003/07/23 -// Copyright: (c) David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP -#endif - -#include "wx/fontenum.h" - -bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, - bool fixedWidthOnly) -{ - return false; -} - -bool wxFontEnumerator::EnumerateEncodings(const wxString& family) -{ - return false; -} - diff --git a/src/cocoa/fontutil.cpp b/src/cocoa/fontutil.cpp deleted file mode 100644 index 6dad697b93..0000000000 --- a/src/cocoa/fontutil.cpp +++ /dev/null @@ -1,255 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/fontutil.cpp -// Purpose: Font helper functions for X11 (GDK/X) -// Author: Vadim Zeitlin -// Modified by: -// Created: 05.11.99 -// Copyright: (c) Vadim Zeitlin -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#include "wx/fontutil.h" - -#ifndef WX_PRECOMP - #include "wx/hash.h" - #include "wx/utils.h" - #include "wx/module.h" -#endif // PCH - -#include "wx/fontmap.h" -#include "wx/tokenzr.h" -#include "wx/encinfo.h" - -#ifdef __WXGTK20__ - -#include "wx/gtk/private.h" - -// ---------------------------------------------------------------------------- -// wxNativeFontInfo -// ---------------------------------------------------------------------------- - -void wxNativeFontInfo::Init() -{ - description = NULL; -} - -int wxNativeFontInfo::GetPointSize() const -{ - return pango_font_description_get_size( description ) / PANGO_SCALE; -} - -wxFontStyle wxNativeFontInfo::GetStyle() const -{ - wxFontStyle m_style = wxFONTSTYLE_NORMAL; - - switch (pango_font_description_get_style( description )) - { - case PANGO_STYLE_NORMAL: - m_style = wxFONTSTYLE_NORMAL; - break; - case PANGO_STYLE_ITALIC: - m_style = wxFONTSTYLE_ITALIC; - break; - case PANGO_STYLE_OBLIQUE: - m_style = wxFONTSTYLE_SLANT; - break; - } - - return m_style; -} - -wxFontWeight wxNativeFontInfo::GetWeight() const -{ - wxFontWeight m_weight = wxFONTWEIGHT_NORMAL; - - switch (pango_font_description_get_weight( description )) - { - case PANGO_WEIGHT_ULTRALIGHT: - m_weight = wxFONTWEIGHT_LIGHT; - break; - case PANGO_WEIGHT_LIGHT: - m_weight = wxFONTWEIGHT_LIGHT; - break; - case PANGO_WEIGHT_NORMAL: - m_weight = wxFONTWEIGHT_NORMAL; - break; - case PANGO_WEIGHT_BOLD: - m_weight = wxFONTWEIGHT_BOLD; - break; - case PANGO_WEIGHT_ULTRABOLD: - m_weight = wxFONTWEIGHT_BOLD; - break; - case PANGO_WEIGHT_HEAVY: - m_weight = wxFONTWEIGHT_BOLD; - break; - } - - return m_weight; -} - -bool wxNativeFontInfo::GetUnderlined() const -{ - return false; -} - -wxString wxNativeFontInfo::GetFaceName() const -{ - wxString tmp = wxGTK_CONV_BACK( pango_font_description_get_family( description ) ); - - return tmp; -} - -wxFontFamily wxNativeFontInfo::GetFamily() const -{ - return wxFONTFAMILY_SWISS; -} - -wxFontEncoding wxNativeFontInfo::GetEncoding() const -{ - return wxFONTENCODING_SYSTEM; -} - -// ---------------------------------------------------------------------------- -// wxNativeEncodingInfo -// ---------------------------------------------------------------------------- - -bool wxNativeEncodingInfo::FromString(const wxString& s) -{ - return false; -} - -wxString wxNativeEncodingInfo::ToString() const -{ - return wxEmptyString; -} - -bool wxTestFontEncoding(const wxNativeEncodingInfo& info) -{ - return true; -} - -bool wxGetNativeFontEncoding(wxFontEncoding encoding, - wxNativeEncodingInfo *info) -{ - return false; -} - -#else - // __WXGTK20__ - -#ifdef __X__ - #ifdef __VMS__ - #pragma message disable nosimpint - #endif - - #include - - #ifdef __VMS__ - #pragma message enable nosimpint - #endif - -#elif defined(__WXGTK__) - // we have to declare struct tm to avoid problems with first forward - // declaring it in C code (glib.h included from gdk.h does it) and then - // defining it when time.h is included from the headers below - this is - // known not to work at least with Sun CC 6.01 - #include - - #include -#endif - - -// ---------------------------------------------------------------------------- -// private data -// ---------------------------------------------------------------------------- - -static wxHashTable *g_fontHash = NULL; - -// ---------------------------------------------------------------------------- -// private functions -// ---------------------------------------------------------------------------- - -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// wxNativeEncodingInfo -// ---------------------------------------------------------------------------- - -// convert to/from the string representation: format is -// encodingid;registry;encoding[;facename] -bool wxNativeEncodingInfo::FromString(const wxString& s) -{ -return false; -} - -wxString wxNativeEncodingInfo::ToString() const -{ -return wxEmptyString; -} - -// ---------------------------------------------------------------------------- -// common functions -// ---------------------------------------------------------------------------- - -bool wxGetNativeFontEncoding(wxFontEncoding encoding, - wxNativeEncodingInfo *info) -{ - return false; -} - -bool wxTestFontEncoding(const wxNativeEncodingInfo& info) -{ -return false; -} - -// ---------------------------------------------------------------------------- -// private functions -// ---------------------------------------------------------------------------- - -// ---------------------------------------------------------------------------- -// wxFontModule -// ---------------------------------------------------------------------------- - -class wxFontModule : public wxModule -{ -public: - bool OnInit(); - void OnExit(); - -private: - DECLARE_DYNAMIC_CLASS(wxFontModule) -}; - -IMPLEMENT_DYNAMIC_CLASS(wxFontModule, wxModule) - -bool wxFontModule::OnInit() -{ - g_fontHash = new wxHashTable( wxKEY_STRING ); - - return true; -} - -void wxFontModule::OnExit() -{ - wxDELETE(g_fontHash); -} - -#endif - // not GTK 2.0 diff --git a/src/cocoa/frame.mm b/src/cocoa/frame.mm deleted file mode 100644 index 95a6cb8bcc..0000000000 --- a/src/cocoa/frame.mm +++ /dev/null @@ -1,288 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/frame.mm -// Purpose: wxFrame -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/frame.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" - #include "wx/menu.h" - #include "wx/toolbar.h" - #include "wx/statusbr.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/mbarman.h" - -#import -#import -#import -#import - -// wxFrame - -BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) -END_EVENT_TABLE() - -void wxFrame::Init() -{ - m_frameNSView = nil; -} - -bool wxFrame::Create(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - bool rt = wxTopLevelWindow::Create(parent,winid,title,pos,size,style,name); - - return rt; -} - -wxFrame::~wxFrame() -{ - [m_frameNSView release]; -} - -// ------------------------------------------------------------------- -// Menubar -void wxFrame::AttachMenuBar(wxMenuBar *mbar) -{ - wxFrameBase::AttachMenuBar(mbar); - wxMenuBarManager::GetInstance()->UpdateMenuBar(); -} - -void wxFrame::DetachMenuBar() -{ - wxFrameBase::DetachMenuBar(); - wxMenuBarManager::GetInstance()->UpdateMenuBar(); -} - -void wxFrame::SetMenuBar(wxMenuBar *menubar) -{ - if ( menubar == GetMenuBar() ) - { - // nothing to do - return; - } - - wxFrameBase::DetachMenuBar(); - wxFrameBase::AttachMenuBar(menubar); - wxMenuBarManager::GetInstance()->UpdateMenuBar(); -} - -wxMenuBar* wxFrame::GetAppMenuBar(wxCocoaNSWindow *win) -{ - if(GetMenuBar()) - return GetMenuBar(); - return wxFrameBase::GetAppMenuBar(win); -} - -void wxFrame::CocoaDelegate_wxMenuItemAction(WX_NSMenuItem menuItem) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxFrame::wxMenuItemAction")); - wxMenuItem *item = wxMenuItem::GetFromCocoa(menuItem); - wxCHECK_RET(item,wxT("wxMenuItemAction received but no wxMenuItem exists!")); - - wxMenu *menu = item->GetMenu(); - wxCHECK_RET(menu,wxT("wxMenuItemAction received but wxMenuItem is not in a wxMenu!")); - - // Since we're handling the delegate messages there's a very good chance - // we'll receive a menu action from an item with a nil target. - wxMenuBar *menubar = menu->GetMenuBar(); - if(menubar) - { - wxFrame *frame = menubar->GetFrame(); - wxASSERT_MSG(frame==this, wxT("Received wxMenuItemAction in NSWindow delegate from a menu item attached to a different frame.")); - frame->ProcessCommand(item->GetId()); - } - else - wxLogDebug(wxT("Received wxMenuItemAction in NSWindow delegate from an unknown menu item.")); -} - -bool wxFrame::CocoaDelegate_validateMenuItem(WX_NSMenuItem menuItem) -{ - SEL itemAction = [menuItem action]; - if(itemAction == @selector(wxMenuItemAction:)) - { - wxMenuItem *item = wxMenuItem::GetFromCocoa(menuItem); - wxCHECK_MSG(item,false,wxT("validateMenuItem received but no wxMenuItem exists!")); - // TODO: do more sanity checking - return item->IsEnabled(); - } - // TODO: else if cut/copy/paste - wxLogDebug(wxT("Asked to validate an unknown menu item")); - return false; -} - -// ------------------------------------------------------------------- -// Origin/Size -wxPoint wxFrame::GetClientAreaOrigin() const -{ - return wxPoint(0,0); -} - -void wxFrame::CocoaSetWxWindowSize(int width, int height) -{ - if(m_frameStatusBar) - height += m_frameStatusBar->GetSize().y; -#if wxUSE_TOOLBAR - if(m_frameToolBar) - height += m_frameToolBar->GetSize().y; -#endif //wxUSE_TOOLBAR - wxTopLevelWindow::CocoaSetWxWindowSize(width,height); -} - -// ------------------------------------------------------------------- -WX_NSView wxFrame::GetNonClientNSView() -{ - if(m_frameNSView) - return m_frameNSView; - return GetNSViewForSuperview(); -} - -void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) -{ - // If we have the additional toolbar/statbar view, then the - // default replaceSubview will work. Otherwise, the old view - // should be the content view and should be replaced that way - if(m_frameNSView) - wxWindow::CocoaReplaceView(oldView, newView); - else - wxTopLevelWindow::CocoaReplaceView(oldView, newView); -} - -void wxFrame::UpdateFrameNSView() -{ - if(!m_frameNSView) - { // NOTE: We only need a plain NSView here since we don't associate it with ourselves. - m_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]]; - [m_cocoaNSWindow setContentView: m_frameNSView]; - [m_frameNSView addSubview:m_cocoaNSView]; - } - NSRect frameRect = [m_frameNSView frame]; - float tbarheight = 0.0; -#if wxUSE_TOOLBAR - if(m_frameToolBar) - { - NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview(); - // If the toolbar doesn't have a superview then set it to our - // content view. - if(![tbarNSView superview]) - [m_frameNSView addSubview: tbarNSView]; - // Do this after addSubView so that SetSize can work - m_frameToolBar->SetSize(m_frameToolBar->DoGetBestSize()); - NSRect tbarRect = [tbarNSView frame]; - tbarRect.size.width = frameRect.size.width; - tbarRect.origin.x = 0.0; - tbarRect.origin.y = frameRect.size.height - tbarRect.size.height; - [tbarNSView setFrame:tbarRect]; - // width expands, bottom margin expands - [tbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin]; - tbarheight = tbarRect.size.height; - } -#endif //wxUSE_TOOLBAR - float sbarheight = 0.0; - if(m_frameStatusBar) - { - NSView *sbarNSView = m_frameStatusBar->GetNSViewForSuperview(); - if(![sbarNSView superview]) - [m_frameNSView addSubview: sbarNSView]; - NSRect sbarRect = [sbarNSView frame]; - sbarRect.size.width = frameRect.size.width; - sbarRect.origin.x = 0.0; - sbarRect.origin.y = 0.0; - [sbarNSView setFrame:sbarRect]; - // width expands, top margin expands - [sbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMaxYMargin]; - sbarheight = sbarRect.size.height; - } - wxLogTrace(wxTRACE_COCOA,wxT("frame height=%f, tbar=%f, sbar=%f"),frameRect.size.height,tbarheight,sbarheight); - NSRect innerRect = [m_cocoaNSView frame]; - innerRect.size.height = frameRect.size.height - tbarheight - sbarheight; - innerRect.origin.y = sbarheight; - [m_cocoaNSView setFrame:innerRect]; - [m_cocoaNSView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable]; - // Don't let the frame get smaller than the toolbar+statusbar height - NSRect frameMinRect = [NSWindow frameRectForContentRect: - NSMakeRect(0.0,0.0,0.0,tbarheight+sbarheight) - styleMask: [m_cocoaNSWindow styleMask]]; - [m_cocoaNSWindow setMinSize:frameMinRect.size]; -} - -void wxFrame::SetStatusBar(wxStatusBar *statusbar) -{ - if(m_frameStatusBar) - { - [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview]; - [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; - if(m_frameStatusBar->GetParent()) - m_frameStatusBar->GetParent()->CocoaAddChild(m_frameStatusBar); - } - m_frameStatusBar = statusbar; - if(m_frameStatusBar) - { - m_frameStatusBar->CocoaRemoveFromParent(); - } - UpdateFrameNSView(); -} - -wxStatusBar* wxFrame::CreateStatusBar(int number, - long style, - wxWindowID winid, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - wxFrameBase::CreateStatusBar(number,style,winid,name); - if(m_frameStatusBar) - { - m_frameStatusBar->CocoaRemoveFromParent(); - } - UpdateFrameNSView(); - return m_frameStatusBar; -} - -#if wxUSE_TOOLBAR -void wxFrame::SetToolBar(wxToolBar *toolbar) -{ - if(m_frameToolBar) - { - m_frameToolBar->SetOwningFrame(NULL); - [m_frameToolBar->GetNSViewForSuperview() removeFromSuperview]; - [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; - if(m_frameToolBar->GetParent()) - m_frameToolBar->GetParent()->CocoaAddChild(m_frameToolBar); - } - m_frameToolBar = toolbar; - if(m_frameToolBar) - { - m_frameToolBar->CocoaRemoveFromParent(); - m_frameToolBar->SetOwningFrame(this); - } - UpdateFrameNSView(); -} - -wxToolBar* wxFrame::CreateToolBar(long style, - wxWindowID winid, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - return wxFrameBase::CreateToolBar(style,winid,name); -} -#endif // wxUSE_TOOLBAR - -void wxFrame::PositionStatusBar() -{ -} diff --git a/src/cocoa/gauge.mm b/src/cocoa/gauge.mm deleted file mode 100644 index b59d96d74b..0000000000 --- a/src/cocoa/gauge.mm +++ /dev/null @@ -1,113 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/gauge.mm -// Purpose: wxGauge -// Author: David Elliott -// Modified by: -// Created: 2003/07/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_GAUGE - -#include "wx/gauge.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/log.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" - -#import -#import - -#include - -BEGIN_EVENT_TABLE(wxGauge, wxGaugeBase) -END_EVENT_TABLE() -// WX_IMPLEMENT_COCOA_OWNER(wxGauge,NSProgressIndicator,NSView,NSView) - -bool wxGauge::Create(wxWindow *parent, wxWindowID winid, int range, - const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, const wxString& name) -{ - // NOTE: wxGA_SMOOTH flag is simply ignored (gauges are ALWAYS smooth) - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - SetNSView([[NSProgressIndicator alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - - // TODO: DoGetBestSize is likely totally wrong for vertical gauges but - // this actually makes the widgets sample work so it's better than nothing. - if(style & wxGA_VERTICAL) - { - wxLogDebug(wxT("wxGA_VERTICAL may not work correctly. See src/cocoa/gauge.mm")); - [m_cocoaNSView setBoundsRotation:-90.0]; - } - - [(NSProgressIndicator*)m_cocoaNSView setMaxValue:range]; - [(NSProgressIndicator*)m_cocoaNSView setIndeterminate:NO]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxGauge::~wxGauge() -{ -} - -int wxGauge::GetValue() const -{ - return (int)[(NSProgressIndicator*)m_cocoaNSView doubleValue]; -} - -void wxGauge::SetValue(int value) -{ - [(NSProgressIndicator*)m_cocoaNSView setDoubleValue:value]; -} - -int wxGauge::GetRange() const -{ - return (int)[(NSProgressIndicator*)m_cocoaNSView maxValue]; -} - -void wxGauge::SetRange(int maxValue) -{ - [(NSProgressIndicator*)m_cocoaNSView setMinValue:0.0]; - [(NSProgressIndicator*)m_cocoaNSView setMaxValue:maxValue]; -} - -// NSProgressIndicator is not an NSControl but does respond to -// sizeToFit on OS X >= 10.2 -wxSize wxGauge::DoGetBestSize() const -{ - wxAutoNSAutoreleasePool pool; - wxASSERT(GetNSProgressIndicator()); - NSRect storedRect = [m_cocoaNSView frame]; - bool didFit = false; -NS_DURING - [GetNSProgressIndicator() sizeToFit]; - didFit = true; -NS_HANDLER - // TODO: if anything other than method not implemented, re-raise -NS_ENDHANDLER - if(didFit) - { - NSRect cocoaRect = [m_cocoaNSView frame]; - wxSize size((int)ceil(cocoaRect.size.width),(int)ceil(cocoaRect.size.height)); - [m_cocoaNSView setFrame: storedRect]; - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxControl=%p::DoGetBestSize()==(%d,%d) from sizeToFit"),this,size.x,size.y); - return /*wxConstCast(this, wxControl)->m_bestSize =*/ size; - } - // Cocoa can't tell us the size - float height = NSProgressIndicatorPreferredAquaThickness; - return wxSize((int)(height*2),(int)height); -} - -#endif // wxUSE_GAUGE diff --git a/src/cocoa/glcanvas.mm b/src/cocoa/glcanvas.mm deleted file mode 100644 index 53fb87c96b..0000000000 --- a/src/cocoa/glcanvas.mm +++ /dev/null @@ -1,73 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/glcanvas.mm -// Purpose: wxGLContext, wxGLCanvas -// Author: David Elliott -// Modified by: -// Created: 2004/09/29 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_GLCANVAS - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP -#include "wx/glcanvas.h" - -#include "wx/cocoa/autorelease.h" - -#import -#import - -wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other) -{ - // TODO -} - -wxGLContext::~wxGLContext() -{ -} - -void wxGLContext::SetCurrent(const wxGLCanvas& win) const -{ - [[win.GetNSOpenGLView() openGLContext] makeCurrentContext]; -} - -IMPLEMENT_CLASS(wxGLCanvas, wxWindow) -// WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView) - -bool wxGLCanvas::Create(wxWindow *parent, - wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name, - const int *attribList, - const wxPalette& palette) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - SetNSView([[NSOpenGLView alloc] initWithFrame: MakeDefaultNSRect(size) - pixelFormat:[NSOpenGLView defaultPixelFormat]]); - [m_cocoaNSView release]; - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxGLCanvas::~wxGLCanvas() -{ -} - -void wxGLCanvas::SwapBuffers() -{ - [[GetNSOpenGLView() openGLContext] flushBuffer]; -} - -#endif // wxUSE_GLCANVAS diff --git a/src/cocoa/icon.mm b/src/cocoa/icon.mm deleted file mode 100644 index 7bc65f4ba7..0000000000 --- a/src/cocoa/icon.mm +++ /dev/null @@ -1,159 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/icon.mm -// Purpose: wxIcon class -// Author: David Elliott -// Modified by: -// Created: 2003/08/11 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/icon.h" - -#ifndef WX_PRECOMP - #include "wx/bitmap.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" - -#import - -// ======================================================================== -// wxIconRefData -// ======================================================================== -class wxIconRefData: public wxGDIRefData -{ - friend class wxIcon; -public: - wxIconRefData(); - wxIconRefData( const wxIconRefData& data ); - virtual ~wxIconRefData(); - - virtual bool IsOk() const { return m_ok; } - -protected: - int m_width; - int m_height; - int m_depth; - bool m_ok; - int m_numColors; - int m_quality; - WX_NSImage m_cocoaNSImage; -}; - -#define M_ICONDATA ((wxIconRefData *)m_refData) - -wxIconRefData::wxIconRefData() -{ - m_ok = false; - m_width = 0; - m_height = 0; - m_depth = 0; - m_quality = 0; - m_numColors = 0; - m_cocoaNSImage = nil; -} - -wxIconRefData::wxIconRefData( const wxIconRefData& data) -{ - m_width = data.m_width; - m_height = data.m_height; - m_depth = data.m_depth; - m_ok = data.m_ok; - m_numColors = data.m_numColors; - m_quality = data.m_quality; - m_cocoaNSImage = [data.m_cocoaNSImage copyWithZone:nil]; -} - -wxIconRefData::~wxIconRefData() -{ - wxAutoNSAutoreleasePool pool; - [m_cocoaNSImage release]; - m_cocoaNSImage = NULL; -} - - -// ======================================================================== -// wxIcon -// ======================================================================== -IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject) - -wxIcon::wxIcon() -{ -} - -wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height)) -{ -} - -wxIcon::wxIcon(const wxString& icon_file, int flags, - int desiredWidth, int desiredHeight) - -{ - LoadFile(icon_file, (wxBitmapType)flags, desiredWidth, desiredHeight); -} - -wxIcon::~wxIcon() -{ -} - -wxGDIRefData *wxIcon::CreateGDIRefData() const -{ - return new wxIconRefData; -} - -wxGDIRefData *wxIcon::CloneGDIRefData(const wxGDIRefData *data) const -{ - return new wxIconRefData(*static_cast(data)); -} - -bool wxIcon::CreateFromXpm(const char* const* xpm) -{ - wxBitmap bitmap(xpm); - CopyFromBitmap(bitmap); - return IsOk(); -} - -bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, - int desiredWidth, int desiredHeight) -{ - wxBitmap bitmap(filename, type); - CopyFromBitmap(bitmap); - return bitmap.IsOk(); -} - -void wxIcon::CopyFromBitmap(const wxBitmap& bitmap) -{ - UnRef(); - m_refData = new wxIconRefData; - M_ICONDATA->m_width = bitmap.GetWidth(); - M_ICONDATA->m_height = bitmap.GetHeight(); - wxAutoNSAutoreleasePool pool; - M_ICONDATA->m_cocoaNSImage = [bitmap.GetNSImage(true) retain]; - M_ICONDATA->m_ok = bitmap.IsOk(); - M_ICONDATA->m_numColors = 0; - M_ICONDATA->m_quality = 0; -} - -int wxIcon::GetWidth() const -{ - if(!m_refData) - return 0; - return M_ICONDATA->m_width; -} - -int wxIcon::GetHeight() const -{ - if(!m_refData) - return 0; - return M_ICONDATA->m_height; -} - -WX_NSImage wxIcon::GetNSImage() const -{ - if(!M_ICONDATA) - return nil; - return M_ICONDATA->m_cocoaNSImage; -} diff --git a/src/cocoa/listbox.mm b/src/cocoa/listbox.mm deleted file mode 100644 index f75f35c0ab..0000000000 --- a/src/cocoa/listbox.mm +++ /dev/null @@ -1,354 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/listbox.mm -// Purpose: wxListBox -// Author: David Elliott -// Modified by: -// Created: 2003/03/18 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_LISTBOX - -#include "wx/listbox.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/string.h" -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/ObjcRef.h" -#include "wx/cocoa/private/scrollview.h" -#include "wx/cocoa/NSTableDataSource.h" - -#import -#import -#import -#import -#import -#import - - -// ============================================================================ -// helper functions -// ============================================================================ - -static CGFloat _TableColumnMaxWidthForItems(NSTableColumn *tableColumn, NSArray *items) -{ - wxAutoNSAutoreleasePool pool; - - NSCell *dataCell = [[[tableColumn dataCell] copy] autorelease]; - CGFloat width = 0.0f; - NSEnumerator *itemEnum = [items objectEnumerator]; - NSString *item; - while( (item = [itemEnum nextObject]) != nil ) - { - [dataCell setStringValue: item]; - NSSize itemSize = [dataCell cellSize]; - CGFloat itemWidth = itemSize.width; - if(itemWidth > width) - width = itemWidth; - } - return width; -} - -static void _SetWidthOfTableColumnToFitItems(NSTableColumn *tableColumn, NSArray *items) -{ - CGFloat width = _TableColumnMaxWidthForItems(tableColumn, items); - [tableColumn setWidth:width]; - [tableColumn setMinWidth:width]; -} - -// ============================================================================ -// class wxListBox -// ============================================================================ - -BEGIN_EVENT_TABLE(wxListBox, wxListBoxBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxListBox,NSTableView,NSControl,NSView) - -bool wxListBox::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxCArrayString chs(choices); - - return Create(parent, winid, pos, size, chs.GetCount(), chs.GetStrings(), - style, validator, name); -} - -bool wxListBox::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - int n, const wxString choices[], - long style, - const wxValidator& validator, - const wxString& name) -{ -/* -wxLB_SINGLE -Single-selection list. - -wxLB_MULTIPLE -Multiple-selection list: the user can toggle multiple items on and off. - -wxLB_EXTENDED -Extended-selection list: the user can select multiple items using the SHIFT key and the mouse or special key combinations. - -wxLB_HSCROLL -Create horizontal scrollbar if contents are too wide (Windows only). - -wxLB_ALWAYS_SB -Always show a vertical scrollbar. - -wxLB_NEEDED_SB -Only create a vertical scrollbar if needed. - -wxLB_SORT -The listbox contents are sorted in alphabetical order. -*/ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - - // Provide the data - m_cocoaItems = wxGCSafeRetain([NSMutableArray arrayWithCapacity:n]); - for(int i=0; i < n; i++) - { - [m_cocoaItems addObject: wxNSStringWithWxString(choices[i])]; - } - // Remove everything - m_itemClientData.Clear(); - // Initialize n elements to NULL - m_itemClientData.SetCount(n,NULL); - - SetNSTableView([[NSTableView alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [GetNSTableView() setHeaderView: nil]; - - // Set up the data source - m_cocoaDataSource = [[WX_GET_OBJC_CLASS(wxCocoaNSTableDataSource) alloc] init]; - [GetNSTableView() setDataSource:m_cocoaDataSource]; - - // Add the single column - NSTableColumn *tableColumn = [[NSTableColumn alloc] initWithIdentifier:nil]; - [GetNSTableView() addTableColumn: tableColumn]; - // By default, entries should not be editable - [tableColumn setEditable:NO]; - [tableColumn release]; - - [GetNSTableView() sizeToFit]; - // Finish - if(m_parent) - m_parent->CocoaAddChild(this); - // NSTableView does WEIRD things with sizes. Wrapping it in an - // NSScrollView seems to be the only reasonable solution. - CocoaCreateNSScrollView(); - SetInitialFrameRect(pos,size); - - if ((style & wxLB_NEEDED_SB) || (style & wxLB_ALWAYS_SB)) - { - [m_wxCocoaScrollView->GetNSScrollView() setHasVerticalScroller: YES]; - } - - if (style & wxLB_HSCROLL) - { - [m_wxCocoaScrollView->GetNSScrollView() setHasHorizontalScroller: YES]; - } - - // We can't set auto-hiding individually for horizontal/vertical scrollers, - // so we have settled on always allowing hiding for both unless the vertical - // setting is "always show". - if (((style & wxLB_NEEDED_SB) || (style & wxLB_HSCROLL)) && !(style & wxLB_ALWAYS_SB)) - { - if ([m_wxCocoaScrollView->GetNSScrollView() respondsToSelector:@selector(setAutohidesScrollers:)]) - { - [m_wxCocoaScrollView->GetNSScrollView() setAutohidesScrollers: YES]; - } - } - - // Set up extended/multiple selection flags - if ((style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE)) - //diff is that mult requires shift down for multi selection - [GetNSTableView() setAllowsMultipleSelection:true]; - - [GetNSTableView() setAllowsColumnSelection:false]; - _SetWidthOfTableColumnToFitItems(tableColumn, m_cocoaItems); - return true; -} - -wxSize wxListBox::DoGetBestSize() const -{ - wxSize size = wxControlWithItems::DoGetBestSize(); - // Limit best size to 100x100. It can be smaller if none of the items are very - // wide or if there aren't many items, but anything bigger than 100x100 ought - // to be asked for by the programmer. The 100x100 size is based on being barely - // enough for a scroller to be usable. - if(size.GetWidth() > 100) - size.SetWidth(100); - if(size.GetHeight() > 100) - size.SetHeight(100); - return size; -} - -wxListBox::~wxListBox() -{ - [GetNSTableView() setDataSource: nil]; - [m_cocoaDataSource release]; - wxGCSafeRelease(m_cocoaItems); - m_cocoaItems = nil; - DisassociateNSTableView(GetNSTableView()); -} - -bool wxListBox::_WxCocoa_GetNeedsUpdate() -{ - return m_needsUpdate; -} - -void wxListBox::_WxCocoa_SetNeedsUpdate(bool needsUpdate) -{ - m_needsUpdate = needsUpdate; -} - -void wxListBox::OnInternalIdle() -{ - wxControlWithItems::OnInternalIdle(); - if(_WxCocoa_GetNeedsUpdate()) - { - _SetWidthOfTableColumnToFitItems([[GetNSTableView() tableColumns] objectAtIndex:0], m_cocoaItems); - [GetNSTableView() tile]; - [GetNSTableView() reloadData]; - _WxCocoa_SetNeedsUpdate(false); - } -} - -int wxListBox::CocoaDataSource_numberOfRows() -{ - return [m_cocoaItems count]; -} - -struct objc_object* wxListBox::CocoaDataSource_objectForTableColumn( - WX_NSTableColumn tableColumn, int rowIndex) -{ - return [m_cocoaItems objectAtIndex:rowIndex]; -} - -// pure virtuals from wxListBoxBase -bool wxListBox::IsSelected(int n) const -{ - return [GetNSTableView() isRowSelected: n]; -} - -void wxListBox::DoSetSelection(int n, bool select) -{ - if(select) - [GetNSTableView() selectRow: n byExtendingSelection:NO]; - else - [GetNSTableView() deselectRow: n]; -} - -int wxListBox::GetSelections(wxArrayInt& aSelections) const -{ - aSelections.Clear(); - NSEnumerator *enumerator = [GetNSTableView() selectedRowEnumerator]; - while(NSNumber *num = [enumerator nextObject]) - { - aSelections.Add([num intValue]); - } - return [GetNSTableView() numberOfSelectedRows]; -} - -int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) -{ - wxAutoNSAutoreleasePool pool; - - const unsigned int numItems = items.GetCount(); - for ( unsigned int i = 0; i < numItems; ++i, ++pos ) - { - [m_cocoaItems insertObject: wxNSStringWithWxString(items[i]) - atIndex: pos]; - m_itemClientData.Insert(NULL, pos); - AssignNewItemClientData(pos, clientData, i, type); - } - - _WxCocoa_SetNeedsUpdate(true); - return pos - 1; -} - -void wxListBox::DoSetFirstItem(int n) -{ - [m_cocoaItems exchangeObjectAtIndex:0 withObjectAtIndex:n]; - void* pOld = m_itemClientData[n]; - m_itemClientData[n] = m_itemClientData[0]; - m_itemClientData[0] = pOld; - _WxCocoa_SetNeedsUpdate(true); -} - - -// pure virtuals from wxItemContainer - // deleting items -void wxListBox::DoClear() -{ - [m_cocoaItems removeAllObjects]; - m_itemClientData.Clear(); - _WxCocoa_SetNeedsUpdate(true); -} - -void wxListBox::DoDeleteOneItem(unsigned int n) -{ - [m_cocoaItems removeObjectAtIndex:n]; - m_itemClientData.RemoveAt(n); - _WxCocoa_SetNeedsUpdate(true); -} - - // accessing strings -unsigned int wxListBox::GetCount() const -{ - return (unsigned int)[m_cocoaItems count]; -} - -wxString wxListBox::GetString(unsigned int n) const -{ - return wxStringWithNSString([m_cocoaItems objectAtIndex:n]); -} - -void wxListBox::SetString(unsigned int n, const wxString& s) -{ - wxAutoNSAutoreleasePool pool; - [m_cocoaItems removeObjectAtIndex:n]; - [m_cocoaItems insertObject: wxNSStringWithWxString(s) atIndex: n]; - _WxCocoa_SetNeedsUpdate(true); -} - -int wxListBox::FindString(const wxString& s, bool bCase) const -{ - // FIXME: use wxItemContainerImmutable::FindString for bCase parameter - wxAutoNSAutoreleasePool pool; - return [m_cocoaItems indexOfObject:wxNSStringWithWxString(s)]; -} - - // selection -int wxListBox::GetSelection() const -{ - return [GetNSTableView() selectedRow]; -} - -void wxListBox::DoSetItemClientData(unsigned int n, void* clientData) -{ - m_itemClientData[n] = clientData; -} - -void* wxListBox::DoGetItemClientData(unsigned int n) const -{ - return m_itemClientData[n]; -} - -#endif // wxUSE_LISTBOX diff --git a/src/cocoa/main.cpp b/src/cocoa/main.cpp deleted file mode 100644 index 7ecc40e67c..0000000000 --- a/src/cocoa/main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/main.cpp -// Purpose: Entry point -// Author: David Elliott -// Modified by: -// Created: 2002/11/11 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// -/* DFE: ^^^^^ Was that really necessary :-) */ - -#include "wx/wxprec.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif // WX_PRECOMP - -WXDLLEXPORT int main(int argc, char* argv[]) -{ - return wxEntry(argc, argv); -} diff --git a/src/cocoa/mbarman.mm b/src/cocoa/mbarman.mm deleted file mode 100644 index 09557f9c0e..0000000000 --- a/src/cocoa/mbarman.mm +++ /dev/null @@ -1,398 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/mbarman.mm -// Purpose: wxMenuBarManager implementation -// Author: David Elliott -// Modified by: -// Created: 2003/09/04 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#if wxUSE_MENUS -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" - #include "wx/menu.h" - #include "wx/toplevel.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/mbarman.h" -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import -#import -#import -#import -#import - -#ifndef wxUSE_FSCRIPT -#define wxUSE_FSCRIPT 0 -#endif - -#if wxUSE_FSCRIPT - #import -#endif - -// Declare setAppleMenu: in an NSApplication category since Tiger and later -// releases support it but don't declare it as it's considered deprecated. -@interface NSApplication(wxDeprecatedMethodsWeWantToUse) -- (void)setAppleMenu:(NSMenu *)menu; -@end - -// ============================================================================ -// wxMenuBarManagerObserver -// ============================================================================ -@interface wxMenuBarManagerObserver : NSObject -{ - wxMenuBarManager *m_mbarman; -} - -- (id)init; -- (id)initWithWxMenuBarManager: (wxMenuBarManager *)mbarman; -- (void)windowDidBecomeKey: (NSNotification *)notification; -#if 0 -- (void)windowDidResignKey: (NSNotification *)notification; -- (void)windowDidBecomeMain: (NSNotification *)notification; -- (void)windowDidResignMain: (NSNotification *)notification; -- (void)windowWillClose: (NSNotification *)notification; -#endif // 0 -@end // interface wxMenuBarManagerObserver : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject) - -@implementation wxMenuBarManagerObserver : NSObject -- (id)init -{ - wxFAIL_MSG(wxT("[wxMenuBarManagerObserver -init] should never be called!")); - m_mbarman = NULL; - return self; -} - -- (id)initWithWxMenuBarManager: (wxMenuBarManager *)mbarman -{ - wxASSERT(mbarman); - m_mbarman = mbarman; - return [super init]; -} - -- (void)windowDidBecomeKey: (NSNotification *)notification -{ - wxASSERT(m_mbarman); - m_mbarman->WindowDidBecomeKey(notification); -} - -#if 0 -- (void)windowDidResignKey: (NSNotification *)notification -{ - wxASSERT(m_mbarman); - m_mbarman->WindowDidResignKey(notification); -} - -- (void)windowDidBecomeMain: (NSNotification *)notification -{ - wxASSERT(m_mbarman); - m_mbarman->WindowDidBecomeMain(notification); -} - -- (void)windowDidResignMain: (NSNotification *)notification -{ - wxASSERT(m_mbarman); - m_mbarman->WindowDidResignMain(notification); -} - -- (void)windowWillClose: (NSNotification *)notification -{ - wxASSERT(m_mbarman); - m_mbarman->WindowWillClose(notification); -} -#endif // 0 - -@end // implementation wxMenuBarManagerObserver : NSObject -WX_IMPLEMENT_GET_OBJC_CLASS(wxMenuBarManagerObserver,NSObject) - -// ============================================================================ -// wxMenuBarManager -// ============================================================================ -wxMenuBarManager *wxMenuBarManager::sm_mbarmanInstance = NULL; - -static void AddFScriptItem(NSMenu *menu) -#if wxUSE_FSCRIPT -{ - NSMenuItem *item = [[FScriptMenuItem alloc] init]; - [menu addItem: item]; - [item release]; -} -#else -{} -#endif - -wxMenuBarManager::wxMenuBarManager() -{ - m_observer = [[WX_GET_OBJC_CLASS(wxMenuBarManagerObserver) alloc] - initWithWxMenuBarManager:this]; - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowDidBecomeKey:) - name:NSWindowDidBecomeKeyNotification object:nil]; - - // HACK: Reuse the same selector and eventual C++ method and make it - // check for whether the notification is to become key or main. - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowDidBecomeKey:) - name:NSWindowDidBecomeMainNotification object:nil]; -#if 0 - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowDidResignKey:) - name:NSWindowDidResignKeyNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowDidBecomeMain:) - name:NSWindowDidBecomeMainNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowDidResignMain:) - name:NSWindowDidResignMainNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowWillClose:) - name:NSWindowWillCloseNotification object:nil]; -#endif // 0 - m_menuApp = nil; - m_menuServices = nil; - m_menuWindows = nil; - m_menuMain = nil; - m_mainMenuBarInstalled = true; - m_mainMenuBar = NULL; - m_currentNSWindow = nil; - - NSApplication *theNSApplication = wxTheApp->GetNSApplication(); - // Create the services menu. - m_menuServices = [[NSMenu alloc] initWithTitle: @"Services"]; - [theNSApplication setServicesMenu:m_menuServices]; - - NSMenuItem *menuitem; - // Create the application (Apple) menu. - m_menuApp = [[NSMenu alloc] initWithTitle: @"Apple Menu"]; - -/**/[m_menuApp addItemWithTitle:@"Preferences..." action:nil keyEquivalent:@""]; -/**/[m_menuApp addItem: [NSMenuItem separatorItem]]; -/**/AddFScriptItem(m_menuApp); -/**/menuitem = [[NSMenuItem alloc] initWithTitle: @"Services" action:nil keyEquivalent:@""]; - [menuitem setSubmenu:m_menuServices]; - [m_menuApp addItem: menuitem]; - [menuitem release]; -/**/[m_menuApp addItem: [NSMenuItem separatorItem]]; -/**/menuitem = [[NSMenuItem alloc] initWithTitle:@"Hide" action:@selector(hide:) keyEquivalent:@""]; - [menuitem setTarget: theNSApplication]; - [m_menuApp addItem: menuitem]; - [menuitem release]; -/**/menuitem = [[NSMenuItem alloc] initWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@""]; - [menuitem setTarget: theNSApplication]; - [m_menuApp addItem: menuitem]; - [menuitem release]; -/**/menuitem = [[NSMenuItem alloc] initWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; - [menuitem setTarget: theNSApplication]; - [m_menuApp addItem: menuitem]; - [menuitem release]; -/**/[m_menuApp addItem: [NSMenuItem separatorItem]]; -/**/menuitem = [[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; - [menuitem setTarget: theNSApplication]; - [m_menuApp addItem: menuitem]; - [menuitem release]; - - [theNSApplication setAppleMenu:m_menuApp]; - - // Create the Windows menu - m_menuWindows = [[NSMenu alloc] initWithTitle: @"Window"]; - -/**/[m_menuWindows addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@""]; -/**/[m_menuWindows addItem: [NSMenuItem separatorItem]]; -/**/[m_menuWindows addItemWithTitle:@"Bring All to Front" action:@selector(arrangeInFront:) keyEquivalent:@""]; - - [theNSApplication setWindowsMenu:m_menuWindows]; - - // Create the main menubar - m_menuMain = [[NSMenu alloc] initWithTitle: @"wxApp Menu"]; -/**/NSMenuItem *dummyItem = [[NSMenuItem alloc] initWithTitle:@"App menu" - /* Note: title gets clobbered by app name anyway */ - action:nil keyEquivalent:@""]; - [dummyItem setSubmenu:m_menuApp]; - [m_menuMain addItem:dummyItem]; - [dummyItem release]; -/**/dummyItem = [[NSMenuItem alloc] initWithTitle:@"Window" - action:nil keyEquivalent:@""]; - [dummyItem setSubmenu:m_menuWindows]; - [m_menuMain addItem:dummyItem]; - [dummyItem release]; - - [theNSApplication setMainMenu: m_menuMain]; - -} - -wxMenuBarManager::~wxMenuBarManager() -{ - [m_observer release]; -} - -void wxMenuBarManager::CreateInstance() -{ - sm_mbarmanInstance = new wxMenuBarManager; -} - -void wxMenuBarManager::DestroyInstance() -{ - delete sm_mbarmanInstance; - sm_mbarmanInstance = NULL; -} - -void wxMenuBarManager::SetMenuBar(wxMenuBar* menubar) -{ - m_mainMenuBarInstalled = false; - if(menubar) - { - [[[wxTheApp->GetNSApplication() mainMenu] itemAtIndex:0] setSubmenu:nil]; - [[menubar->GetNSMenu() itemAtIndex:0] setSubmenu:m_menuApp]; - [wxTheApp->GetNSApplication() setMainMenu:menubar->GetNSMenu()]; - } - else - InstallMainMenu(); -} - -void wxMenuBarManager::SetMainMenuBar(wxMenuBar* menubar) -{ - m_mainMenuBar = menubar; - if(m_mainMenuBarInstalled) - InstallMainMenu(); -} - -void wxMenuBarManager::InstallMainMenu() -{ - if(m_mainMenuBar) - SetMenuBar(m_mainMenuBar); - else - { - m_mainMenuBarInstalled = true; - [[[wxTheApp->GetNSApplication() mainMenu] itemAtIndex:0] setSubmenu:nil]; - [[m_menuMain itemAtIndex:0] setSubmenu:m_menuApp]; - [wxTheApp->GetNSApplication() setMainMenu:m_menuMain]; - } -} - -void wxMenuBarManager::WindowDidBecomeKey(NSNotification *notification) -{ - /* NOTE: m_currentNSWindow might be destroyed but we only ever use it - to look it up in the hash table. Do not send messages to it. */ - - /* Update m_currentNSWindow only if we really should. For instance, - if a non-wx window is becoming key but a wx window remains main - then don't change out the menubar. However, if a non-wx window - (whether the same window or not) is main, then switch to the - generic menubar so the wx window that last installed a menubar - doesn't get menu events it doesn't expect. - - If a wx window is becoming main then check to see if the key - window is a wx window and if so do nothing because that - is what would have been done before. - - If a non-wx window is becoming main and - */ - NSString *notificationName = [notification name]; - if(NULL == notificationName) - return; - else if([NSWindowDidBecomeKeyNotification isEqualTo:notificationName]) - { // This is the only one that was handled in 2.8 as shipped - // Generally the key window can change without the main window changing. - // The user can do this simply by clicking on something in a palette window - // that needs to become key. - NSWindow *newKeyWindow = [notification object]; - wxCocoaNSWindow *theWxKeyWindow = wxCocoaNSWindow::GetFromCocoa(newKeyWindow); - if(theWxKeyWindow != NULL) - { // If the new key window is a wx window, handle it as before - // even if it has not actually changed. - m_currentNSWindow = newKeyWindow; - } - else - { // If the new key window is not wx then check the main window. - NSWindow *mainWindow = [[NSApplication sharedApplication] mainWindow]; - if(m_currentNSWindow == mainWindow) - // Don't reset if the menubar doesn't need to change. - return; - else - // This is strange because theoretically we should have picked this up - // already in the main window notification but it's possible that - // we simply haven't gotten it yet and will about as soon as we return. - // We already know that the key window isn't wx so fall back to this - // one and let the code go ahead and set the wx menubar if it is - // a wx window and set the generic one if it isn't. - m_currentNSWindow = mainWindow; - } - } - else if([NSWindowDidBecomeMainNotification isEqualTo:notificationName]) - { // Handling this is new - // Generally the main window cannot change without the key window changing - // because if the user clicks on a window that can become main then the - // window will also become key. - // However, it's possible that when it becomes main it automatically makes - // some palette the key window. - NSWindow *newMainWindow = [notification object]; - // If we already know about the window, bail. - if(newMainWindow == m_currentNSWindow) - return; - else - { - NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; - if(keyWindow == m_currentNSWindow) - // if we already know about the key window, bail - return; - else - { // As above, sort of strange. Neither one is current. Prefer key over main. - wxCocoaNSWindow *theWxMainWindow = wxCocoaNSWindow::GetFromCocoa(keyWindow); - if(theWxMainWindow != NULL) - m_currentNSWindow = keyWindow; - else - m_currentNSWindow = newMainWindow; - } - } - } - m_currentNSWindow = [notification object]; - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow); - if(win) - InstallMenuBarForWindow(win); - else - SetMenuBar(NULL); -} - -#if 0 -void wxMenuBarManager::WindowDidResignKey(NSNotification *notification) -{ -} - -void wxMenuBarManager::WindowDidBecomeMain(NSNotification *notification) -{ -} - -void wxMenuBarManager::WindowDidResignMain(NSNotification *notification) -{ -} - -void wxMenuBarManager::WindowWillClose(NSNotification *notification) -{ -} -#endif // 0 - -void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win) -{ - wxASSERT(win); - wxMenuBar *menubar = win->GetAppMenuBar(win); - wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win); - SetMenuBar(menubar); -} - -void wxMenuBarManager::UpdateMenuBar() -{ - if(m_currentNSWindow) - { - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow); - if(win) - InstallMenuBarForWindow(win); - } -} - -#endif // wxUSE_MENUS diff --git a/src/cocoa/mdi.mm b/src/cocoa/mdi.mm deleted file mode 100644 index 8bdb9e14d7..0000000000 --- a/src/cocoa/mdi.mm +++ /dev/null @@ -1,308 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/mdi.mm -// Purpose: wxMDIParentFrame, wxMDIChildFrame, wxMDIClientWindow -// Author: David Elliott -// Modified by: -// Created: 2003/09/08 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_MDI - -#include "wx/mdi.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -// #include "wx/cocoa/autorelease.h" -#include "wx/cocoa/mbarman.h" - -#import -#import -// #import -// #import - -#include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxCocoaMDIChildFrameList); - -WX_DECLARE_HASH_MAP(int, wxMDIChildFrame*, wxIntegerHash, wxIntegerEqual, wxIntMDIChildFrameHashMap); - -// ============================================================================ -// wxMDIParentFrameObserver -// ============================================================================ -@interface wxMDIParentFrameObserver : NSObject -{ - wxMDIParentFrame *m_mdiParent; -} - -- (id)init; -- (id)initWithWxMDIParentFrame: (wxMDIParentFrame *)mdiParent; -- (void)windowDidBecomeMain: (NSNotification *)notification; -@end // interface wxMDIParentFrameObserver : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxMDIParentFrameObserver,NSObject) - -@implementation wxMDIParentFrameObserver : NSObject -- (id)init -{ - wxFAIL_MSG(wxT("[wxMDIParentFrameObserver -init] should never be called!")); - m_mdiParent = NULL; - return self; -} - -- (id)initWithWxMDIParentFrame: (wxMDIParentFrame *)mdiParent -{ - wxASSERT(mdiParent); - m_mdiParent = mdiParent; - return [super init]; -} - -- (void)windowDidBecomeMain: (NSNotification *)notification -{ - wxASSERT(m_mdiParent); - m_mdiParent->WindowDidBecomeMain(notification); -} - -@end // implementation wxMDIParentFrameObserver : NSObject -WX_IMPLEMENT_GET_OBJC_CLASS(wxMDIParentFrameObserver,NSObject) - -// ======================================================================== -// wxMDIParentFrame -// ======================================================================== -IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame) -BEGIN_EVENT_TABLE(wxMDIParentFrame,wxFrame) -END_EVENT_TABLE() - -void wxMDIParentFrame::Init() -{ - m_clientWindow = NULL; - m_currentChild = NULL; - m_observer = [[WX_GET_OBJC_CLASS(wxMDIParentFrameObserver) alloc] - initWithWxMDIParentFrame:this]; - [[NSNotificationCenter defaultCenter] addObserver:m_observer - selector:@selector(windowDidBecomeMain:) - name:NSWindowDidBecomeMainNotification object:nil]; -} - -bool wxMDIParentFrame::Create(wxWindow *parent, - wxWindowID winid, const wxString& title, - const wxPoint& pos, const wxSize& size, - long style, const wxString& name) -{ - if ( !wxFrame::Create(parent,winid,title,pos,size,style,name) ) - return false; - - m_clientWindow = OnCreateClient(); - - return m_clientWindow != NULL; -} - -wxMDIParentFrame::~wxMDIParentFrame() -{ - for(wxCocoaMDIChildFrameList::compatibility_iterator node = - m_mdiChildren.GetFirst(); node; node = m_mdiChildren.GetFirst()) - { - wxMDIChildFrame *child = node->GetData(); - // Delete it NOW - delete child; - wxASSERT_MSG(!m_mdiChildren.Find(child), - wxT("MDI child didn't remove itself using RemoveMDIChild()")); - } - [m_observer release]; -} - -void wxMDIParentFrame::AddMDIChild(wxMDIChildFrame *child) -{ - m_mdiChildren.Append(child); -} - -void wxMDIParentFrame::RemoveMDIChild(wxMDIChildFrame *child) -{ - m_mdiChildren.DeleteObject(child); - if(child==m_currentChild) - SetActiveChild(NULL); -} - -void wxMDIParentFrame::SetActiveChild(wxMDIChildFrame *child) -{ - m_currentChild = child; - wxMenuBarManager::GetInstance()->UpdateMenuBar(); -} - -wxMenuBar *wxMDIParentFrame::GetAppMenuBar(wxCocoaNSWindow *win) -{ - if(m_currentChild && (win==this)) - return m_currentChild->GetAppMenuBar(win); - return wxFrame::GetAppMenuBar(win); -} - -void wxMDIParentFrame::CocoaDelegate_windowDidBecomeKey(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxMDIParentFrame=%p::CocoaDelegate_windowDidBecomeKey"),this); - if(sm_cocoaDeactivateWindow && sm_cocoaDeactivateWindow==m_currentChild) - { - sm_cocoaDeactivateWindow = NULL; - } - #if 0 - else if(sm_cocoaDeactivateWindow == this) - { - sm_cocoaDeactivateWindow = NULL; - } - #endif - else - { - if(m_currentChild) - { - NSWindow *nswin = m_currentChild->GetNSWindow(); - if(![nswin isMainWindow]) - [nswin makeMainWindow]; - } - wxFrame::CocoaDelegate_windowDidBecomeKey(); - } -} - -void wxMDIParentFrame::CocoaDelegate_windowDidResignKey(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxMDIParentFrame=%p::CocoaDelegate_windowDidResignKey"),this); - if(m_closed) - wxFrame::CocoaDelegate_windowDidResignKey(); - else - sm_cocoaDeactivateWindow = this; -} - -// We should not become the main window as we aren't a document window -// MDI "Children" should be the main window -bool wxMDIParentFrame::Cocoa_canBecomeMainWindow(bool &canBecome) -{ - canBecome = m_mdiChildren.IsEmpty(); return true; -} - -void wxMDIParentFrame::WindowDidBecomeMain(NSNotification *notification) -{ - // If we aren't the key window, we don't care - if(![m_cocoaNSWindow isKeyWindow]) - return; - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); - // If we are key and becoming main, that's great - if(win==this) - return; - // If one of our children is becoming main, also great - for(wxCocoaMDIChildFrameList::compatibility_iterator node = - m_mdiChildren.GetFirst(); node; node = node->GetNext()) - { - wxMDIChildFrame *child = node->GetData(); - if(win==child) - return; - } - // Some other window is becoming main, but we are key - // Make the new main window the key window - [[notification object] makeKeyWindow]; - if(!m_currentChild) - { - wxIntMDIChildFrameHashMap hashmap; - for(wxCocoaMDIChildFrameList::compatibility_iterator node = - m_mdiChildren.GetFirst(); node; node = node->GetNext()) - { - wxMDIChildFrame *child = node->GetData(); - hashmap.insert(wxIntMDIChildFrameHashMap::value_type([child->m_cocoaNSWindow windowNumber],child)); - } - if(!hashmap.empty()) - { - NSInteger windowCount = 0; - NSCountWindows(&windowCount); - wxASSERT(windowCount>0); - NSInteger *windowList = new NSInteger[windowCount]; - NSWindowList(windowCount, windowList); - wxIntMDIChildFrameHashMap::iterator iter = hashmap.end(); - for(int i=0; isecond; - } - } -} - -// ======================================================================== -// wxMDIChildFrame -// ======================================================================== -IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame) -BEGIN_EVENT_TABLE(wxMDIChildFrame,wxFrame) -END_EVENT_TABLE() - -void wxMDIChildFrame::Init() -{ - m_mdiParent = NULL; -} - -bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, - wxWindowID winid, const wxString& title, - const wxPoint& pos, const wxSize& size, - long style, const wxString& name) -{ - bool success = wxFrame::Create(parent,winid,title,pos,size,style,name); - if(success) - { - m_mdiParent = parent; - parent->AddMDIChild(this); - } - return success; -} - -wxMDIChildFrame::~wxMDIChildFrame() -{ - // Just in case Destroy() wasn't called - m_mdiParent->RemoveMDIChild(this); -} - -void wxMDIChildFrame::Activate() -{ -} - -void wxMDIChildFrame::CocoaDelegate_windowDidBecomeKey(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxMDIChildFrame=%p::CocoaDelegate_windowDidBecomeKey"),this); - if(sm_cocoaDeactivateWindow && sm_cocoaDeactivateWindow==m_mdiParent) - { - sm_cocoaDeactivateWindow = NULL; - if(m_mdiParent->GetActiveChild() != this) - sm_cocoaDeactivateWindow = m_mdiParent->GetActiveChild(); - } - m_mdiParent->SetActiveChild(this); - wxFrame::CocoaDelegate_windowDidBecomeKey(); -} - -void wxMDIChildFrame::CocoaDelegate_windowDidBecomeMain(void) -{ - m_mdiParent->SetActiveChild(this); - wxFrame::CocoaDelegate_windowDidBecomeMain(); -} - -void wxMDIChildFrame::CocoaDelegate_windowDidResignKey(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxMDIChildFrame=%p::CocoaDelegate_windowDidResignKey"),this); - sm_cocoaDeactivateWindow = this; -} - -bool wxMDIChildFrame::Destroy() -{ - // It's good to do this here before we are really closed - m_mdiParent->RemoveMDIChild(this); - return wxFrame::Destroy(); -} - -// ======================================================================== -// wxMDIClientWindow -// ======================================================================== -IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow) - -bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) -{ - return Create(parent, wxID_ANY, wxPoint(0, 0), wxSize(0, 0), style); -} - -#endif // wxUSE_MDI diff --git a/src/cocoa/mediactrl.mm b/src/cocoa/mediactrl.mm deleted file mode 100644 index 3e1a97a1d2..0000000000 --- a/src/cocoa/mediactrl.mm +++ /dev/null @@ -1,497 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/mediactrl.mm -// Purpose: Built-in Media Backends for Cocoa -// Author: Ryan Norton -// Modified by: -// Created: 02/03/05 -// Copyright: (c) 2004-2005 Ryan Norton, (c) 2005 David Elliot -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -//=========================================================================== -// DECLARATIONS -//=========================================================================== - -//--------------------------------------------------------------------------- -// Pre-compiled header stuff -//--------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -//--------------------------------------------------------------------------- -// Compilation guard -//--------------------------------------------------------------------------- -#if wxUSE_MEDIACTRL - -#include "wx/mediactrl.h" - -#ifndef WX_PRECOMP - #include "wx/timer.h" -#endif - -//=========================================================================== -// BACKEND DECLARATIONS -//=========================================================================== - -//--------------------------------------------------------------------------- -// -// wxQTMediaBackend -// -//--------------------------------------------------------------------------- - -//--------------------------------------------------------------------------- -// QT Includes -//--------------------------------------------------------------------------- -#include - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import - - -class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackend -{ -public: - - wxQTMediaBackend(); - ~wxQTMediaBackend(); - - virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name); - - virtual bool Play(); - virtual bool Pause(); - virtual bool Stop(); - - virtual bool Load(const wxString& fileName); - virtual bool Load(const wxURI& location); - - virtual wxMediaState GetState(); - - virtual bool SetPosition(wxLongLong where); - virtual wxLongLong GetPosition(); - virtual wxLongLong GetDuration(); - - virtual void Move(int x, int y, int w, int h); - wxSize GetVideoSize() const; - - virtual double GetPlaybackRate(); - virtual bool SetPlaybackRate(double dRate); - - void Cleanup(); - void FinishLoad(); - - wxSize m_bestSize; //Original movie size - Movie m_movie; //QT Movie handle/instance - NSMovieView* m_movieview; //NSMovieView instance - wxControl* m_ctrl; //Parent control - bool m_bVideo; //Whether or not we have video - class _wxQTTimer* m_timer; //Timer for streaming the movie - - DECLARE_DYNAMIC_CLASS(wxQTMediaBackend); -}; - - -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// -// wxQTMediaBackend -// -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend); - -//Time between timer calls -#define MOVIE_DELAY 100 - -// -------------------------------------------------------------------------- -// wxQTTimer - Handle Asyncronous Playing -// -------------------------------------------------------------------------- -class _wxQTTimer : public wxTimer -{ -public: - _wxQTTimer(Movie movie, wxQTMediaBackend* parent) : - m_movie(movie), m_bPaused(false), m_parent(parent) - { - } - - ~_wxQTTimer() - { - } - - bool GetPaused() {return m_bPaused;} - void SetPaused(bool bPaused) {m_bPaused = bPaused;} - - //----------------------------------------------------------------------- - // _wxQTTimer::Notify - // - // 1) Checks to see if the movie is done, and if not continues - // streaming the movie - // 2) Sends the wxEVT_MEDIA_STOP event if we have reached the end of - // the movie. - //----------------------------------------------------------------------- - void Notify() - { - if (!m_bPaused) - { - if(!IsMovieDone(m_movie)) - MoviesTask(m_movie, MOVIE_DELAY); - else - { - wxMediaEvent theEvent(wxEVT_MEDIA_STOP, - m_parent->m_ctrl->GetId()); - m_parent->m_ctrl->ProcessEvent(theEvent); - - if(theEvent.IsAllowed()) - { - Stop(); - m_parent->Stop(); - wxASSERT(::GetMoviesError() == noErr); - - //send the event to our child - wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED, - m_parent->m_ctrl->GetId()); - m_parent->m_ctrl->ProcessEvent(theEvent); - } - } - } - } - -protected: - Movie m_movie; //Our movie instance - bool m_bPaused; //Whether we are paused or not - wxQTMediaBackend* m_parent; //Backend pointer -}; - -//--------------------------------------------------------------------------- -// wxQTMediaBackend Constructor -// -// Sets m_timer to NULL signifying we havn't loaded anything yet -//--------------------------------------------------------------------------- -wxQTMediaBackend::wxQTMediaBackend() : m_timer(NULL) -{ -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend Destructor -// -// 1) Cleans up the QuickTime movie instance -// 2) Decrements the QuickTime reference counter - if this reaches -// 0, QuickTime shuts down -// 3) Decrements the QuickTime Windows Media Layer reference counter - -// if this reaches 0, QuickTime shuts down the Windows Media Layer -//--------------------------------------------------------------------------- -wxQTMediaBackend::~wxQTMediaBackend() -{ - if(m_timer) - Cleanup(); - - //Note that ExitMovies() is not necessary... - ExitMovies(); -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::CreateControl -// -// 1) Intializes QuickTime -// 2) Creates the control window -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::CreateControl(wxControl* inctrl, wxWindow* parent, - wxWindowID wid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - EnterMovies(); - - wxMediaCtrl* ctrl = (wxMediaCtrl*) inctrl; - - //Create the control base - wxASSERT(ctrl->CreateBase(parent,wid,pos,size,style, validator, name)); - - //Create the NSMovieView - ctrl->SetNSView(NULL); - NSMovieView* theView = [[NSMovieView alloc] initWithFrame: ctrl->MakeDefaultNSRect(size)]; - ctrl->SetNSView(theView); - [theView release]; - - if (parent) - { - parent->AddChild(ctrl); - parent->CocoaAddChild(ctrl); - ctrl->SetInitialFrameRect(pos,size); - } - - [theView showController:false adjustingSize:true]; - m_movieview = theView; - m_ctrl = ctrl; - return true; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Load (file version) -// -// Calls the URI version -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::Load(const wxString& fileName) -{ - return Load( - wxURI( - wxString( wxT("file://") ) + fileName - ) - ); -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Load (URL Version) -// -// 1) Build an escaped URI from location -// ... -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::Load(const wxURI& location) -{ - if(m_timer) - Cleanup(); - - wxString theURI = location.BuildURI(); - - [m_movieview setMovie:[[NSMovie alloc] initWithURL: [NSURL URLWithString: wxNSStringWithWxString(theURI)] - byReference: YES ] ]; - - m_movie = (Movie) [[m_movieview movie] QTMovie]; - - //preroll movie for streaming - //TODO:Async this using threads? - TimeValue timeNow; - Fixed playRate; - timeNow = GetMovieTime(m_movie, NULL); - playRate = GetMoviePreferredRate(m_movie); - PrePrerollMovie(m_movie, timeNow, playRate, NULL, NULL); - PrerollMovie(m_movie, timeNow, playRate); - SetMovieRate(m_movie, playRate); - - FinishLoad(); - - return ::GetMoviesError() == noErr; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::FinishLoad -// -// 1) Create the movie timer -// 2) Get real size of movie for GetBestSize/sizers -// 3) See if there is video in the movie, and if so then either -// SetMovieGWorld if < 10.2 or use Native CreateMovieControl -// 4) Set the movie time scale to something usable so that seeking -// etc. will work correctly -// 5) Refresh parent window -//--------------------------------------------------------------------------- -void wxQTMediaBackend::FinishLoad() -{ - m_timer = new _wxQTTimer(m_movie, (wxQTMediaBackend*) this); - wxASSERT(m_timer); - - //get the real size of the movie - Rect outRect; - ::GetMovieNaturalBoundsRect (m_movie, &outRect); - wxASSERT(::GetMoviesError() == noErr); - - m_bestSize.x = outRect.right - outRect.left; - m_bestSize.y = outRect.bottom - outRect.top; - - //we want millisecond precision - ::SetMovieTimeScale(m_movie, 1000); - wxASSERT(::GetMoviesError() == noErr); - - // - //Here, if the parent of the control has a sizer - we - //tell it to recalculate the size of this control since - //the user opened a separate media file - // - m_ctrl->InvalidateBestSize(); - m_ctrl->GetParent()->Layout(); - m_ctrl->GetParent()->Refresh(); - m_ctrl->GetParent()->Update(); -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Play -// -// 1) Start the QT movie -// 2) Start the movie loading timer -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::Play() -{ - ::StartMovie(m_movie); - m_timer->SetPaused(false); - m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); - return ::GetMoviesError() == noErr; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Pause -// -// 1) Stop the movie -// 2) Stop the movie timer -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::Pause() -{ - ::StopMovie(m_movie); - m_timer->SetPaused(true); - m_timer->Stop(); - return ::GetMoviesError() == noErr; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Stop -// -// 1) Stop the movie -// 2) Stop the movie timer -// 3) Seek to the beginning of the movie -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::Stop() -{ - m_timer->SetPaused(false); - m_timer->Stop(); - - ::StopMovie(m_movie); - if(::GetMoviesError() != noErr) - return false; - - ::GoToBeginningOfMovie(m_movie); - return ::GetMoviesError() == noErr; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::GetPlaybackRate -// -// 1) Get the movie playback rate from ::GetMovieRate -//--------------------------------------------------------------------------- -double wxQTMediaBackend::GetPlaybackRate() -{ - return ( ((double)::GetMovieRate(m_movie)) / 0x10000); -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::SetPlaybackRate -// -// 1) Convert dRate to Fixed and Set the movie rate through SetMovieRate -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::SetPlaybackRate(double dRate) -{ - ::SetMovieRate(m_movie, (Fixed) (dRate * 0x10000)); - return ::GetMoviesError() == noErr; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::SetPosition -// -// 1) Create a time record struct (TimeRecord) with appropriate values -// 2) Pass struct to SetMovieTime -//--------------------------------------------------------------------------- -bool wxQTMediaBackend::SetPosition(wxLongLong where) -{ - TimeRecord theTimeRecord; - memset(&theTimeRecord, 0, sizeof(TimeRecord)); - theTimeRecord.value.lo = where.GetValue(); - theTimeRecord.scale = ::GetMovieTimeScale(m_movie); - theTimeRecord.base = ::GetMovieTimeBase(m_movie); - ::SetMovieTime(m_movie, &theTimeRecord); - - if (::GetMoviesError() != noErr) - return false; - - return true; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::GetPosition -// -// Calls GetMovieTime -//--------------------------------------------------------------------------- -wxLongLong wxQTMediaBackend::GetPosition() -{ - return ::GetMovieTime(m_movie, NULL); -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::GetDuration -// -// Calls GetMovieDuration -//--------------------------------------------------------------------------- -wxLongLong wxQTMediaBackend::GetDuration() -{ - return ::GetMovieDuration(m_movie); -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::GetState -// -// Determines the current state - the timer keeps track of whether or not -// we are paused or stopped (if the timer is running we are playing) -//--------------------------------------------------------------------------- -wxMediaState wxQTMediaBackend::GetState() -{ - if ( !m_timer || (m_timer->IsRunning() == false && - m_timer->GetPaused() == false) ) - return wxMEDIASTATE_STOPPED; - - if( m_timer->IsRunning() == true ) - return wxMEDIASTATE_PLAYING; - else - return wxMEDIASTATE_PAUSED; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Cleanup -// -// Diposes of the movie timer, Control if native, and stops and disposes -// of the QT movie -//--------------------------------------------------------------------------- -void wxQTMediaBackend::Cleanup() -{ - delete m_timer; - m_timer = NULL; - - [[m_movieview movie] release]; - [m_movieview setMovie:NULL]; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::GetVideoSize -// -// Returns the actual size of the QT movie -//--------------------------------------------------------------------------- -wxSize wxQTMediaBackend::GetVideoSize() const -{ - return m_bestSize; -} - -//--------------------------------------------------------------------------- -// wxQTMediaBackend::Move -// -// Nothin... cocoa takes care of this for us -//--------------------------------------------------------------------------- -void wxQTMediaBackend::Move(int x, int y, int w, int h) -{ -} - - -//in source file that contains stuff you don't directly use -#include "wx/html/forcelnk.h" -FORCE_LINK_ME(basewxmediabackends); - -#endif //wxUSE_MEDIACTRL diff --git a/src/cocoa/menu.mm b/src/cocoa/menu.mm deleted file mode 100644 index 908b8ecd8c..0000000000 --- a/src/cocoa/menu.mm +++ /dev/null @@ -1,241 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/menu.mm -// Purpose: wxMenu and wxMenuBar implementation -// Author: David Elliott -// Modified by: -// Created: 2002/12/09 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" - -#include "wx/menu.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#include "wx/cocoa/objc/NSMenu.h" - -#if wxUSE_MENUS - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- - -// ============================================================================ -// wxMenu implementation -// ============================================================================ - -bool wxMenu::Create(const wxString& title, long style) -{ - wxAutoNSAutoreleasePool pool; - m_cocoaNSMenu = [[WX_GET_OBJC_CLASS(WXNSMenu) alloc] initWithTitle: wxNSStringWithWxString(title)]; - AssociateNSMenu(m_cocoaNSMenu); - return true; -} - -wxMenu::~wxMenu() -{ - DisassociateNSMenu(m_cocoaNSMenu); - if(!m_cocoaDeletes) - [m_cocoaNSMenu release]; -} - -wxMenuItem* wxMenu::DoAppend(wxMenuItem *item) -{ - wxAutoNSAutoreleasePool pool; - if(!wxMenuBase::DoAppend(item)) - return NULL; - [m_cocoaNSMenu addItem: item->GetNSMenuItem()]; - return item; -} - -wxMenuItem* wxMenu::DoInsert(unsigned long pos, wxMenuItem *item) -{ - wxAutoNSAutoreleasePool pool; - if(!wxMenuBase::DoInsert(pos,item)) - return NULL; - [m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos]; - return item; -} - -wxMenuItem* wxMenu::DoRemove(wxMenuItem *item) -{ - wxAutoNSAutoreleasePool pool; - wxMenuItem *retitem = wxMenuBase::DoRemove(item); - wxASSERT(retitem->GetNSMenuItem()); - [m_cocoaNSMenu removeItem:retitem->GetNSMenuItem()]; - return retitem; -} - -// This autoreleases the menu on the assumption that something is -// going to retain it shortly (for instance, it is going to be returned from -// an overloaded [NSStatusItem menu] or from the applicationDockMenu: -// NSApplication delegate method. -// -// It then sets a bool flag m_cocoaDeletes. When the NSMenu is dealloc'd -// (dealloc is the Cocoa destructor) we delete ourselves. In this manner we -// can be available for Cocoa calls until Cocoa is finished with us. -// -// I can see very few reasons to undo this. Nevertheless, it is implemented. -void wxMenu::SetCocoaDeletes(bool cocoaDeletes) -{ - if(m_cocoaDeletes==cocoaDeletes) - return; - m_cocoaDeletes = cocoaDeletes; - if(m_cocoaDeletes) - [m_cocoaNSMenu autorelease]; - else - [m_cocoaNSMenu retain]; -} - -void wxMenu::Cocoa_dealloc() -{ - if(m_cocoaDeletes) - delete this; -} - -// ============================================================================ -// wxMenuBar implementation -// ============================================================================ - -bool wxMenuBar::Create(long style) -{ - wxAutoNSAutoreleasePool pool; - m_cocoaNSMenu = [[NSMenu alloc] initWithTitle: @"wxMenuBar"]; - - NSMenuItem *dummyItem = [[NSMenuItem alloc] initWithTitle:@"App menu" - /* Note: title gets clobbered by app name anyway */ - action:nil keyEquivalent:@""]; - [m_cocoaNSMenu addItem:dummyItem]; - [dummyItem release]; - return true; -} - -wxMenuBar::wxMenuBar(size_t n, - wxMenu *menus[], - const wxString titles[], - long style) -{ - Create(style); - - for ( size_t i = 0; i < n; ++i ) - Append(menus[i], titles[i]); -} - -wxMenuBar::~wxMenuBar() -{ - [m_cocoaNSMenu release]; -} - -bool wxMenuBar::Append( wxMenu *menu, const wxString &title ) -{ - wxAutoNSAutoreleasePool pool; - wxLogTrace(wxTRACE_COCOA,wxT("append menu=%p, title=%s"),menu,title.c_str()); - if(!wxMenuBarBase::Append(menu,title)) - return false; - wxASSERT(menu); - wxASSERT(menu->GetNSMenu()); - NSString *menuTitle = wxInitNSStringWithWxString([NSString alloc], wxStripMenuCodes(title)); - NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""]; - [menu->GetNSMenu() setTitle:menuTitle]; - [newItem setSubmenu:menu->GetNSMenu()]; - - [m_cocoaNSMenu addItem:newItem]; - - [menuTitle release]; - [newItem release]; - return true; -} - -bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) -{ - wxAutoNSAutoreleasePool pool; - wxLogTrace(wxTRACE_COCOA,wxT("insert pos=%lu, menu=%p, title=%s"),pos,menu,title.c_str()); - // Get the current menu at this position - wxMenu *nextmenu = GetMenu(pos); - if(!wxMenuBarBase::Insert(pos,menu,title)) - return false; - wxASSERT(menu); - wxASSERT(menu->GetNSMenu()); - NSString *menuTitle = wxInitNSStringWithWxString([NSString alloc], title); - NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""]; - [menu->GetNSMenu() setTitle:menuTitle]; - [newItem setSubmenu:menu->GetNSMenu()]; - - int itemindex = [m_cocoaNSMenu indexOfItemWithSubmenu:nextmenu->GetNSMenu()]; - wxASSERT(itemindex>=0); - [m_cocoaNSMenu insertItem:newItem atIndex:itemindex]; - - [menuTitle release]; - [newItem release]; - return true; -} - -wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) -{ - return NULL; -} - -wxMenu *wxMenuBar::Remove(size_t pos) -{ - wxMenu *menu = wxMenuBarBase::Remove(pos); - wxASSERT(menu); - int itemindex = [GetNSMenu() indexOfItemWithSubmenu:menu->GetNSMenu()]; - wxASSERT(itemindex>=0); - [m_cocoaNSMenu removeItemAtIndex:itemindex]; - return menu; -} - - -void wxMenuBar::EnableTop(size_t pos, bool enable) -{ -} - -bool wxMenuBar::IsEnabledTop(size_t pos) const -{ - return false; -} - -void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label) -{ -} - -wxString wxMenuBar::GetMenuLabel(size_t pos) const -{ - wxMenu *menu = GetMenu(pos); - int itemindex = [m_cocoaNSMenu indexOfItemWithSubmenu:menu->GetNSMenu()]; - wxASSERT(itemindex>=0); - return wxStringWithNSString([[m_cocoaNSMenu itemAtIndex:itemindex] title]); -} - -void wxMenuBar::Attach(wxFrame *frame) -{ - wxMenuBarBase::Attach(frame); -} - -void wxMenuBar::Detach() -{ - wxMenuBarBase::Detach(); -} - -wxSize wxMenuBar::DoGetBestClientSize() const -{ - return wxDefaultSize; -} - -#endif // wxUSE_MENUS diff --git a/src/cocoa/menuitem.mm b/src/cocoa/menuitem.mm deleted file mode 100644 index 427a1c8559..0000000000 --- a/src/cocoa/menuitem.mm +++ /dev/null @@ -1,295 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/menuitem.mm -// Purpose: wxMenuItem implementation -// Author: David Elliott -// Modified by: -// Created: 2002/12/15 -// Copyright: 2002-2004 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#include "wx/wxprec.h" - -#if wxUSE_MENUS - -#include "wx/menuitem.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#ifndef WX_PRECOMP - #include "wx/menu.h" - #include "wx/utils.h" - #include "wx/frame.h" - #include "wx/log.h" -#endif - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import -#import -#import // NSOnState, NSOffState -#import // modifier key masks - -// ---------------------------------------------------------------------------- -// functions prototypes -// ---------------------------------------------------------------------------- - -// ============================================================================ -// @class wxNSMenuItemTarget -// ============================================================================ -@interface wxNSMenuItemTarget : NSObject -{ -} - -- (void)wxMenuItemAction: (id)sender; -- (BOOL)validateMenuItem: (id)menuItem; -@end //interface wxNSMenuItemTarget -WX_DECLARE_GET_OBJC_CLASS(wxNSMenuItemTarget,NSObject) - -@implementation wxNSMenuItemTarget : NSObject - -- (void)wxMenuItemAction: (id)sender -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxMenuItemAction")); - wxMenuItem *item = wxMenuItem::GetFromCocoa(sender); - wxCHECK_RET(item,wxT("wxMenuItemAction received but no wxMenuItem exists!")); - item->CocoaItemSelected(); -} - -- (BOOL)validateMenuItem: (id)menuItem -{ - // TODO: Do wxWidgets validation here and avoid sending during idle time - wxLogTrace(wxTRACE_COCOA,wxT("wxMenuItemAction")); - wxMenuItem *item = wxMenuItem::GetFromCocoa(menuItem); - wxCHECK_MSG(item,NO,wxT("validateMenuItem received but no wxMenuItem exists!")); - return item->Cocoa_validateMenuItem(); -} - -@end //implementation wxNSMenuItemTarget -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSMenuItemTarget,NSObject) - -// ============================================================================ -// wxMenuItemCocoa implementation -// ============================================================================ -wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash; - -wxObjcAutoRefFromAlloc wxMenuItemCocoa::sm_cocoaTarget = [[WX_GET_OBJC_CLASS(wxNSMenuItemTarget) alloc] init]; - -// ---------------------------------------------------------------------------- -// wxMenuItemBase -// ---------------------------------------------------------------------------- - -wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, - int itemid, - const wxString& name, - const wxString& help, - wxItemKind kind, - wxMenu *subMenu) -{ - return new wxMenuItem(parentMenu, itemid, name, help, kind, subMenu); -} - -void wxMenuItemCocoa::CocoaSetKeyEquivalent() -{ - wxAcceleratorEntry *accel = GetAccel(); - if(!accel) - return; - - int accelFlags = accel->GetFlags(); - int keyModifierMask = 0; - if(accelFlags & wxACCEL_ALT) - keyModifierMask |= NSAlternateKeyMask; - if(accelFlags & wxACCEL_CTRL) - keyModifierMask |= NSCommandKeyMask; - int keyCode = accel->GetKeyCode(); - if(isalpha(keyCode)) - { // For alpha characters use upper/lower rather than NSShiftKeyMask - char alphaChar; - if(accelFlags & wxACCEL_SHIFT) - alphaChar = toupper(keyCode); - else - alphaChar = tolower(keyCode); - [m_cocoaNSMenuItem setKeyEquivalent:[NSString stringWithCString:&alphaChar length:1]]; - [m_cocoaNSMenuItem setKeyEquivalentModifierMask:keyModifierMask]; - } - else - { - if(accelFlags & wxACCEL_SHIFT) - keyModifierMask |= NSShiftKeyMask; - if(keyCode < 128) // low ASCII includes backspace/tab/etc. - { char alphaChar = keyCode; - [m_cocoaNSMenuItem setKeyEquivalent:[NSString stringWithCString:&alphaChar length:1]]; - } - else - { // TODO - } - [m_cocoaNSMenuItem setKeyEquivalentModifierMask:keyModifierMask]; - } -} - -// ---------------------------------------------------------------------------- -// ctor & dtor -// ---------------------------------------------------------------------------- -wxMenuItemCocoa::wxMenuItemCocoa(wxMenu *pParentMenu, - int itemid, - const wxString& strName, - const wxString& strHelp, - wxItemKind kind, - wxMenu *pSubMenu) - : wxMenuItemBase(pParentMenu, itemid, strName, strHelp, kind, pSubMenu) -{ - wxAutoNSAutoreleasePool pool; - if(m_kind == wxITEM_SEPARATOR) - m_cocoaNSMenuItem = [[NSMenuItem separatorItem] retain]; - else - { - NSString *menuTitle = wxInitNSStringWithWxString([NSString alloc],wxStripMenuCodes(strName)); - SEL action; - if(pSubMenu) - action = nil; - else - action = @selector(wxMenuItemAction:); - m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:action keyEquivalent:@""]; - sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this)); - if(pSubMenu) - { - wxASSERT(pSubMenu->GetNSMenu()); - [pSubMenu->GetNSMenu() setTitle:menuTitle]; - [m_cocoaNSMenuItem setSubmenu:pSubMenu->GetNSMenu()]; - } - else - [m_cocoaNSMenuItem setTarget: sm_cocoaTarget]; - [menuTitle release]; - CocoaSetKeyEquivalent(); - } -} - -wxMenuItem::~wxMenuItem() -{ - sm_cocoaHash.erase(m_cocoaNSMenuItem); - [m_cocoaNSMenuItem release]; -} - -void wxMenuItem::CocoaItemSelected() -{ - wxMenu *menu = GetMenu(); - wxCHECK_RET(menu,wxT("wxMenuItemAction received but wxMenuItem is not in a wxMenu")); - wxMenuBar *menubar = menu->GetMenuBar(); - if(menubar) - { - wxFrame *frame = menubar->GetFrame(); - wxCHECK_RET(frame, wxT("wxMenuBar MUST be attached to a wxFrame!")); - frame->ProcessCommand(GetId()); - } - else - { - if(IsCheckable()) - Toggle(); - GetMenu()->SendEvent(GetId(), IsCheckable()?IsChecked():-1); - } -} - -bool wxMenuItem::Cocoa_validateMenuItem() -{ - // TODO: do more sanity checking - // TODO: Do wxWindows validation here and avoid sending during idle time - return IsEnabled(); -} - -// ---------------------------------------------------------------------------- -// misc -// ---------------------------------------------------------------------------- - -void wxMenuItem::SetBitmaps(const wxBitmap& bmpChecked, - const wxBitmap& bmpUnchecked) -{ - wxCHECK_RET(m_kind != wxITEM_SEPARATOR, wxT("Separator items do not have bitmaps.")); - wxAutoNSAutoreleasePool pool; - m_bmpChecked = bmpChecked; - m_bmpUnchecked = bmpUnchecked; - if(IsCheckable()) - { - [m_cocoaNSMenuItem setOnStateImage: bmpChecked.GetNSImage(true)]; - [m_cocoaNSMenuItem setOffStateImage: bmpUnchecked.GetNSImage(true)]; - } - else - { - wxASSERT_MSG(!bmpUnchecked.IsOk(),wxT("Normal menu items should only have one bitmap")); - [m_cocoaNSMenuItem setImage: bmpChecked.GetNSImage(true)]; - } -} - -// change item state -// ----------------- - -void wxMenuItem::Enable(bool bDoEnable) -{ - wxMenuItemBase::Enable(bDoEnable); - // NOTE: Nothing to do, we respond to validateMenuItem instead -} - -void wxMenuItem::Check(bool check) -{ - wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") ); - if(m_isChecked == check) - return; - wxAutoNSAutoreleasePool pool; - if(GetKind() == wxITEM_RADIO) - { - // it doesn't make sense to uncheck a radio item - what would this do? - if(!check) - return; - const wxMenuItemList& items = m_parentMenu->GetMenuItems(); - // First search backwards for other radio items - wxMenuItemList::compatibility_iterator radioStart = items.Find(this); - for(wxMenuItemList::compatibility_iterator prevNode = radioStart; - prevNode && (prevNode->GetData()->GetKind() == wxITEM_RADIO); - prevNode = prevNode->GetPrevious()) - { - radioStart = prevNode; - } - // Now starting there set the state of every item until we're - // out of radio items to set. - for(wxMenuItemList::compatibility_iterator node = radioStart; - node && (node->GetData()->GetKind() == wxITEM_RADIO); - node = node->GetNext()) - { - wxMenuItem *item = node->GetData(); - bool checkItem = (item == this); - item->wxMenuItemBase::Check(checkItem); - [item->m_cocoaNSMenuItem setState: checkItem?NSOnState:NSOffState]; - } - } - else // normal check (non-radio) item - { - wxMenuItemBase::Check(check); - [m_cocoaNSMenuItem setState: check?NSOnState:NSOffState]; - } -} - -void wxMenuItem::SetItemLabel(const wxString& label) -{ - wxMenuItemBase::SetItemLabel(label); - wxCHECK_RET(m_kind != wxITEM_SEPARATOR, wxT("Separator items do not have titles.")); - [m_cocoaNSMenuItem setTitle: wxNSStringWithWxString(wxStripMenuCodes(label))]; - CocoaSetKeyEquivalent(); -} - -void wxMenuItem::SetCheckable(bool checkable) -{ - wxCHECK_RET(m_kind != wxITEM_SEPARATOR, wxT("Separator items cannot be turned into normal menu items.")); - wxMenuItemBase::SetCheckable(checkable); - // NOTE: Cocoa does not discern between unchecked and normal items -} - -#endif // wxUSE_MENUS diff --git a/src/cocoa/msgdlg.mm b/src/cocoa/msgdlg.mm deleted file mode 100644 index 2ea22d8654..0000000000 --- a/src/cocoa/msgdlg.mm +++ /dev/null @@ -1,161 +0,0 @@ - ///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/dirdlg.mm -// Purpose: wxMessageDialog for wxCocoa -// Author: Gareth Simpson -// Created: 2007-10-09 -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#if wxUSE_MSGDLG - - -#include "wx/msgdlg.h" - - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif - - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/modalhook.h" - -#import -// ============================================================================ -// implementation -// ============================================================================ - -IMPLEMENT_CLASS(wxCocoaMessageDialog, wxDialog) - -// ---------------------------------------------------------------------------- -// wxDirDialog -// ---------------------------------------------------------------------------- - -wxCocoaMessageDialog::wxCocoaMessageDialog(wxWindow *parent, - const wxString& message, - const wxString& caption, - long style, - const wxPoint& pos) - : wxMessageDialogWithCustomLabels(parent, message, caption, style) -{ - - wxTopLevelWindows.Append(this); - - wxASSERT(CreateBase(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr)); - - if ( parent ) - parent->AddChild(this); - - - m_cocoaNSWindow = nil; - m_cocoaNSView = nil; -} - -void wxCocoaMessageDialog::DoSetCustomLabel(wxString& var, const ButtonLabel& value) -{ - wxMessageDialogWithCustomLabels::DoSetCustomLabel(var, value); - - var.Replace("&", ""); -} - -int wxCocoaMessageDialog::ShowModal() -{ - WX_HOOK_MODAL_DIALOG(); - - wxAutoNSAutoreleasePool thePool; - - NSAlert *alert = [[[NSAlert alloc] init] autorelease]; - - const long style = GetMessageDialogStyle(); - - NSAlertStyle nsStyle = NSInformationalAlertStyle; - - switch ( GetEffectiveIcon() ) - { - case wxICON_ERROR: - nsStyle = NSCriticalAlertStyle; - break; - - case wxICON_WARNING: - nsStyle = NSWarningAlertStyle; - break; - } - - [alert setAlertStyle:nsStyle]; - - - - - // 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 - if (m_extendedMessage.empty()) - { - [alert setMessageText:wxNSStringWithWxString(m_caption)]; - [alert setInformativeText:wxNSStringWithWxString(m_message)]; - } - else - { - [alert setMessageText:wxNSStringWithWxString(m_message)]; - [alert setInformativeText:wxNSStringWithWxString(m_extendedMessage)]; - } - - // The wxReturn value corresponding to each button - int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; - if (style & wxYES_NO) - { - if ( style & wxNO_DEFAULT ) - { - [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())]; - [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())]; - buttonId[0] = wxID_NO; - buttonId[1] = wxID_YES; - } - else - { - [alert addButtonWithTitle:wxNSStringWithWxString(GetYesLabel())]; - [alert addButtonWithTitle:wxNSStringWithWxString(GetNoLabel())]; - buttonId[0] = wxID_YES; - buttonId[1] = wxID_NO; - } - if (style & wxCANCEL) - { - [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())]; - 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 - [alert addButtonWithTitle:wxNSStringWithWxString(GetOKLabel())]; - if (style & wxCANCEL) - { - [alert addButtonWithTitle:wxNSStringWithWxString(GetCancelLabel())]; - buttonId[1] = wxID_CANCEL; - } - } - - int ret = [alert runModal]; - - - return buttonId[ret-NSAlertFirstButtonReturn]; -} - -#endif // wxUSE_DIRDLG - diff --git a/src/cocoa/notebook.mm b/src/cocoa/notebook.mm deleted file mode 100644 index c766bc4099..0000000000 --- a/src/cocoa/notebook.mm +++ /dev/null @@ -1,324 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/notebook.mm -// Purpose: wxNotebook -// Author: David Elliott -// Modified by: -// Created: 2004/04/08 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_NOTEBOOK - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP -#include "wx/notebook.h" -#include "wx/imaglist.h" - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import -#import -#import - -// testing: -#import -#import - -// ======================================================================== -// WXCTabViewImageItem -// ======================================================================== -@interface WXCTabViewImageItem : NSTabViewItem -{ - NSImage *m_image; -} - -- (id)init; -- (id)initWithIdentifier: (id)identifier; -- (void)dealloc; - -- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel; -- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect; - -- (NSImage*)image; -- (void)setImage:(NSImage*)image; -@end // interface WXCTabViewImageItem : NSTabViewItem -WX_DECLARE_GET_OBJC_CLASS(WXCTabViewImageItem,NSTabViewItem) - -@implementation WXCTabViewImageItem : NSTabViewItem -- (id)init -{ - return [self initWithIdentifier:nil]; -} - -- (id)initWithIdentifier: (id)identifier; -{ - m_image = nil; - return [super initWithIdentifier:identifier]; -} - -- (void)dealloc -{ - [m_image release]; - [super dealloc]; -} - -- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel -{ - NSSize labelSize = [super sizeOfLabel:shouldTruncateLabel]; - if(!m_image) - return labelSize; - NSSize imageSize = [m_image size]; - // scale image size - if(imageSize.height > labelSize.height) - { - imageSize.width *= labelSize.height/imageSize.height; - imageSize.height *= labelSize.height/imageSize.height; - [m_image setScalesWhenResized:YES]; - [m_image setSize: imageSize]; - } - labelSize.width += imageSize.width; - return labelSize; -} - -- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect -{ - if(m_image) - { - NSSize imageSize = [m_image size]; - [m_image compositeToPoint:NSMakePoint(tabRect.origin.x, - tabRect.origin.y+imageSize.height) - operation:NSCompositeSourceOver]; - tabRect.size.width -= imageSize.width; - tabRect.origin.x += imageSize.width; - } - [super drawLabel:shouldTruncateLabel inRect:tabRect]; -} - -- (NSImage*)image -{ - return m_image; -} - -- (void)setImage:(NSImage*)image -{ - [image retain]; - [m_image release]; - m_image = image; - if(!m_image) - return; - [[NSPasteboard generalPasteboard] - declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] - owner:nil]; - [[NSPasteboard generalPasteboard] - setData:[m_image TIFFRepresentation] - forType:NSTIFFPboardType]; -} - -@end // implementation WXCTabViewImageItem : NSTabViewItem -WX_IMPLEMENT_GET_OBJC_CLASS(WXCTabViewImageItem,NSTabViewItem) - -// ======================================================================== -// wxNotebook -// ======================================================================== - -BEGIN_EVENT_TABLE(wxNotebook, wxNotebookBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxNotebook,NSTabView,NSView,NSView) - -bool wxNotebook::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - m_cocoaNSView = NULL; - SetNSTabView([[NSTabView alloc] initWithFrame:MakeDefaultNSRect(size)]); - - do - { - NSTabViewType tabViewType; - if(style & wxNB_TOP) - tabViewType = NSTopTabsBezelBorder; - else if(style & wxNB_LEFT) - tabViewType = NSLeftTabsBezelBorder; - else if(style & wxNB_RIGHT) - tabViewType = NSRightTabsBezelBorder; - else if(style & wxNB_BOTTOM) - tabViewType = NSBottomTabsBezelBorder; - else - break; - [GetNSTabView() setTabViewType:tabViewType]; - } while(0); - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxNotebook::~wxNotebook() -{ -} - -void wxNotebook::SetPadding(const wxSize& padding) -{ // Can't do -} - -void wxNotebook::SetTabSize(const wxSize& sz) -{ // Can't do -} - -void wxNotebook::SetPageSize(const wxSize& size) -{ -} - - -wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) -{ - wxNotebookPage *page = wxNotebookBase::DoRemovePage(nPage); - if(!page) - return NULL; - NSTabViewItem *tvitem = [GetNSTabView() tabViewItemAtIndex: nPage]; - wxASSERT(tvitem); - [tvitem retain]; - [GetNSTabView() removeTabViewItem:tvitem]; - // Remove the child window as a notebook page - wxASSERT(static_cast([tvitem view]) == page->GetNSViewForSuperview()); - [tvitem setView:nil]; - [tvitem release]; - // Make it back into a normal child window - [m_cocoaNSView addSubview: page->GetNSViewForSuperview()]; - - return page; -} - -bool wxNotebook::DeletePage(size_t nPage) -{ - return wxNotebookBase::DeletePage(nPage); -} - -bool wxNotebook::InsertPage( size_t pos, - wxNotebookPage *page, const wxString& title, - bool bSelect, int imageId) -{ - wxAutoNSAutoreleasePool pool; - m_pages.Insert(page,pos); - NSTabViewItem *tvitem = [[WX_GET_OBJC_CLASS(WXCTabViewImageItem) alloc] initWithIdentifier:nil]; - [tvitem setLabel: wxNSStringWithWxString(title)]; - const wxBitmap *bmp = (imageId!=-1)?m_imageList->GetBitmapPtr(imageId):NULL; - if(bmp) - [(WXCTabViewImageItem*) tvitem setImage: bmp->GetNSImage(true)]; - - NSView *pageNSView = page->GetNSViewForSuperview(); - // Remove it as a normal child - wxASSERT(m_cocoaNSView == [pageNSView superview]); - [pageNSView removeFromSuperview]; - // And make it a notebook page - [tvitem setView: pageNSView]; - - [GetNSTabView() insertTabViewItem:tvitem atIndex:pos]; - [tvitem release]; - - return true; -} - -bool wxNotebook::DeleteAllPages() -{ - while(!m_pages.IsEmpty()) - DeletePage(0); - return true; -} - - -bool wxNotebook::SetPageText(size_t nPage, const wxString& title) -{ - NSTabViewItem *tvitem = [GetNSTabView() tabViewItemAtIndex: nPage]; - if(!tvitem) - return false; - [tvitem setLabel: wxNSStringWithWxString(title)]; - return true; -} - -wxString wxNotebook::GetPageText(size_t nPage) const -{ - return wxStringWithNSString([[GetNSTabView() tabViewItemAtIndex: nPage] label]); -} - - -int wxNotebook::GetPageImage(size_t nPage) const -{ - // To do this we'd need to keep track of this, which we don't! - return -1; -} - -bool wxNotebook::SetPageImage(size_t nPage, int nImage) -{ - const wxBitmap *bmp = nImage!=-1?m_imageList->GetBitmapPtr(nImage):NULL; - if(!bmp) - return false; - NSTabViewItem *tvitem = [GetNSTabView() tabViewItemAtIndex: nPage]; - if(!tvitem) - return false; - [(WXCTabViewImageItem*) tvitem setImage: bmp->GetNSImage(true)]; - return true; -} - -int wxNotebook::SetSelection(size_t nPage) -{ - const int pageOld = GetSelection(); - - if ( !SendPageChangingEvent(nPage) ) - return pageOld; - - int page = ChangeSelection(nPage); - if ( page != wxNOT_FOUND ) - { - SendPageChangedEvent(pageOld); - } - - return page; -} - -int wxNotebook::ChangeSelection(size_t nPage) -{ - wxAutoNSAutoreleasePool pool; - [GetNSTabView() selectTabViewItemAtIndex:nPage]; - return GetSelection(); -} - -int wxNotebook::GetSelection() const -{ - NSTabViewItem *selectedItem = [GetNSTabView() selectedTabViewItem]; - if(!selectedItem) - return wxNOT_FOUND; - return [GetNSTabView() indexOfTabViewItem:selectedItem]; -} - -void wxNotebook::CocoaDelegate_tabView_didSelectTabViewItem(WX_NSTabViewItem tabViewItem) -{ - // FIXME: oldSel probably == newSel - wxBookCtrlEvent event(wxEVT_NOTEBOOK_PAGE_CHANGED, GetId(), - [GetNSTabView() indexOfTabViewItem:tabViewItem], GetSelection()); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); -} - -bool wxNotebook::CocoaDelegate_tabView_shouldSelectTabViewItem(WX_NSTabViewItem tabViewItem) -{ - wxBookCtrlEvent event(wxEVT_NOTEBOOK_PAGE_CHANGING, GetId(), - [GetNSTabView() indexOfTabViewItem:tabViewItem], GetSelection()); - event.SetEventObject(this); - return !HandleWindowEvent(event) || event.IsAllowed(); -} - -#endif // wxUSE_NOTEBOOK diff --git a/src/cocoa/pen.mm b/src/cocoa/pen.mm deleted file mode 100644 index 139e6cc4d9..0000000000 --- a/src/cocoa/pen.mm +++ /dev/null @@ -1,376 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/pen.mm -// Purpose: wxPen -// Author: David Elliott -// Modified by: -// Created: 2003/08/02 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#ifndef WX_PRECOMP - #include "wx/pen.h" - #include "wx/bitmap.h" - #include "wx/colour.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/ObjcRef.h" - -#import - -// ======================================================================== -// wxPenRefData -// ======================================================================== -class WXDLLEXPORT wxPenRefData: public wxGDIRefData -{ -public: - wxPenRefData(const wxColour& colour = wxNullColour, - int width = 1, int style = wxSOLID, - const wxBitmap& stipple = wxNullBitmap); - wxPenRefData(const wxPenRefData& data); - ~wxPenRefData() { FreeCocoaNSColor(); FreeCocoaDash(); } - - void SetWidth(int Width) { m_width = Width; } - void SetStyle(int Style) - { FreeCocoaNSColor(); - FreeCocoaDash(); - m_style = Style; - } - void SetJoin(int Join) { m_join = Join; } - void SetCap(int Cap) { m_cap = Cap; } - void SetColour(const wxColour& col) { FreeCocoaNSColor(); m_colour = col; } - void SetDashes(int nb_dashes, const wxDash *Dash) - { - FreeCocoaDash(); - m_nbDash = nb_dashes; - m_dash = (wxDash *)Dash; - } - void SetStipple(const wxBitmap& Stipple) - { - FreeCocoaNSColor(); - m_stipple = Stipple; - m_style = wxSTIPPLE; - } - WX_NSColor GetNSColor(); - int GetCocoaLineDash(const CGFloat **pattern); -protected: - void FreeCocoaNSColor(); - void FreeCocoaDash(); - - int m_width; - int m_style; - int m_join; - int m_cap; - wxColour m_colour; - int m_nbDash; - wxDash *m_dash; - wxBitmap m_stipple; - WX_NSColor m_cocoaNSColor; - CGFloat *m_cocoaDash; - - // Predefined dash patterns - static const int scm_countDot; - static const CGFloat scm_patternDot[]; - static const int scm_countLongDash; - static const CGFloat scm_patternLongDash[]; - static const int scm_countShortDash; - static const CGFloat scm_patternShortDash[]; - static const int scm_countDotDash; - static const CGFloat scm_patternDotDash[]; - - friend class WXDLLIMPEXP_FWD_CORE wxPen; - -private: - // Don't allow assignment - wxPenRefData& operator=(const wxPenRefData& data); -}; - -const int wxPenRefData::scm_countDot = 1; -const CGFloat wxPenRefData::scm_patternDot[] = { - 1.0 -}; -const int wxPenRefData::scm_countLongDash = 1; -const CGFloat wxPenRefData::scm_patternLongDash[] = { - 10.0 -}; -const int wxPenRefData::scm_countShortDash = 1; -const CGFloat wxPenRefData::scm_patternShortDash[] = { - 5.0 -}; -const int wxPenRefData::scm_countDotDash = 4; -const CGFloat wxPenRefData::scm_patternDotDash[] = { - 1.0 -, 1.0 -, 5.0 -, 1.0 -}; - -#define M_PENDATA ((wxPenRefData *)m_refData) - -inline wxPenRefData::wxPenRefData(const wxColour& colour, - int width, int style, const wxBitmap& stipple) -{ - m_width = width; - m_style = style; - m_join = wxJOIN_ROUND; - m_cap = wxCAP_ROUND; - m_colour = colour; - m_nbDash = 0; - m_dash = 0; - m_stipple = stipple; - m_cocoaNSColor = nil; - m_cocoaDash = NULL; -} - -inline wxPenRefData::wxPenRefData(const wxPenRefData& data) -{ - m_width = data.m_width; - m_style = data.m_style; - m_join = data.m_join; - m_cap = data.m_cap; - m_colour = data.m_colour; - m_nbDash = data.m_nbDash; - m_dash = data.m_dash; - m_stipple = data.m_stipple; - m_cocoaNSColor = wxGCSafeRetain(data.m_cocoaNSColor); - m_cocoaDash = NULL; -} - -inline void wxPenRefData::FreeCocoaNSColor() -{ - wxGCSafeRelease(m_cocoaNSColor); - m_cocoaNSColor = nil; -} - -inline void wxPenRefData::FreeCocoaDash() -{ - delete m_cocoaDash; - m_cocoaDash = NULL; -} - -inline WX_NSColor wxPenRefData::GetNSColor() -{ - if(!m_cocoaNSColor) - { - switch( m_style ) - { - case wxTRANSPARENT: - m_cocoaNSColor = wxGCSafeRetain([NSColor clearColor]); - break; - case wxSTIPPLE: -// wxBitmap isn't implemented yet -// m_cocoaNSColor = [[NSColor colorWithPatternImage: m_stipple.GetNSImage()] retain]; -// break; - // The hatch brushes are going to be tricky - case wxBDIAGONAL_HATCH: - case wxCROSSDIAG_HATCH: - case wxFDIAGONAL_HATCH: - case wxCROSS_HATCH: - case wxHORIZONTAL_HATCH: - case wxVERTICAL_HATCH: - default: - // Dot/dashed pens use solid colors - case wxDOT: - case wxLONG_DASH: - case wxSHORT_DASH: - case wxDOT_DASH: - case wxUSER_DASH: - case wxSOLID: - NSColor *colour_NSColor = m_colour.GetNSColor(); - if(!colour_NSColor) - colour_NSColor = [NSColor clearColor]; - m_cocoaNSColor = [colour_NSColor copyWithZone:nil]; - [wxGCSafeRetain(m_cocoaNSColor) release]; // retain in GC. no change in RR. - break; - } - } - return m_cocoaNSColor; -} - -int wxPenRefData::GetCocoaLineDash(const CGFloat **pattern) -{ - int count; - switch( m_style ) - { - case wxDOT: - count = scm_countDot; - if(pattern) - *pattern = scm_patternDot; - break; - case wxLONG_DASH: - count = scm_countLongDash; - if(pattern) - *pattern = scm_patternLongDash; - break; - case wxSHORT_DASH: - count = scm_countShortDash; - if(pattern) - *pattern = scm_patternShortDash; - break; - case wxDOT_DASH: - count = scm_countDotDash; - if(pattern) - *pattern = scm_patternDotDash; - break; - case wxUSER_DASH: - count = m_nbDash; - if(pattern) - { - if(!m_cocoaDash) - { - m_cocoaDash = new CGFloat[count]; - for(int i=0; iSetWidth(Width); -} - -void wxPen::SetStyle(int Style) -{ - AllocExclusive(); - M_PENDATA->SetStyle(Style); -} - -void wxPen::SetJoin(int Join) -{ - AllocExclusive(); - M_PENDATA->SetJoin(Join); -} - -void wxPen::SetCap(int Cap) -{ - AllocExclusive(); - M_PENDATA->SetCap(Cap); -} - -void wxPen::SetColour(const wxColour& col) -{ - AllocExclusive(); - M_PENDATA->SetColour(col); -} - -void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b) -{ - AllocExclusive(); - M_PENDATA->SetColour(wxColour(r, g, b)); -} - -void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) -{ - AllocExclusive(); - M_PENDATA->SetDashes(nb_dashes, Dash); -} - -void wxPen::SetStipple(const wxBitmap& Stipple) -{ - AllocExclusive(); - M_PENDATA->SetStipple(Stipple); -} - -wxColour wxPen::GetColour() const -{ - return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); -} - -int wxPen::GetWidth() const -{ - return (M_PENDATA ? M_PENDATA->m_width : 0); -} - -int wxPen::GetStyle() const -{ - return (M_PENDATA ? M_PENDATA->m_style : 0); -} - -int wxPen::GetJoin() const -{ - return (M_PENDATA ? M_PENDATA->m_join : 0); -} - -int wxPen::GetCap() const -{ - return (M_PENDATA ? M_PENDATA->m_cap : 0); -} - -int wxPen::GetDashes(wxDash **ptr) const -{ - *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0); -} - -wxBitmap *wxPen::GetStipple() const -{ - return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); -} - -WX_NSColor wxPen::GetNSColor() -{ - return (M_PENDATA ? M_PENDATA->GetNSColor() : nil); -} - -int wxPen::GetCocoaLineDash(const CGFloat **pattern) -{ - if(M_PENDATA) - return M_PENDATA->GetCocoaLineDash(pattern); - if(pattern) - *pattern = NULL; - return 0; -} diff --git a/src/cocoa/radiobox.mm b/src/cocoa/radiobox.mm deleted file mode 100644 index 08045602af..0000000000 --- a/src/cocoa/radiobox.mm +++ /dev/null @@ -1,276 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/radiobox.mm -// Purpose: wxRadioBox -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// (c) 2007 Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_RADIOBOX - -#include "wx/radiobox.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/arrstr.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/string.h" -#include "wx/cocoa/autorelease.h" - -#import -#include "wx/cocoa/objc/NSView.h" -#import -#import -#import - -IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) -BEGIN_EVENT_TABLE(wxRadioBox, wxControl) -END_EVENT_TABLE() - -void wxRadioBox::AssociateNSBox(WX_NSBox cocoaObjcClass) -{ - NSMatrix *radioBox = [(WX_NSBox)cocoaObjcClass contentView]; - // Associate the NSMatrix (the NSBox's contentView) with the wxCocoaNSControl MI base class. - AssociateNSControl(radioBox); - // Set the target/action.. we don't really need to unset these - [radioBox setTarget:wxCocoaNSControl::sm_cocoaTarget]; - [radioBox setAction:@selector(wxNSControlAction:)]; -} - -void wxRadioBox::DisassociateNSBox(WX_NSBox cocoaObjcClass) -{ - DisassociateNSControl([(WX_NSBox)cocoaObjcClass contentView]); -} - -WX_IMPLEMENT_COCOA_OWNER(wxRadioBox,NSBox,NSView,NSView) - -bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - const wxArrayString& choices, - int majorDim, - long style, const wxValidator& validator, - const wxString& name) -{ - wxCArrayString chs(choices); - - return Create(parent, winid, title, pos, size, chs.GetCount(), - chs.GetStrings(), majorDim, style, validator, name); -} - -bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - int n, const wxString choices[], - int majorDim, - long style, const wxValidator& validator, - const wxString& name) -{ - // We autorelease heavily so we want our own pool - wxAutoNSAutoreleasePool pool; - - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - - majorDim = majorDim == 0 ? n : majorDim; - // TODO: Don't forget to call SetMajorDim - // We can't yet as we can't implement GetCount() until after - // we make the NSMatrix. - int minorDim = (n + majorDim - 1) / majorDim; - - - // Create a prototype cell for use with the NSMatrix build - NSCell *currCell = [[NSButtonCell alloc] initTextCell:@""]; - [(NSButtonCell*)currCell setButtonType:NSRadioButton]; - - // Build up an array of all cells plus any extra empty cells - NSMutableArray *allCells = [NSMutableArray arrayWithCapacity:n]; - for(int i=0; i 0) - SetSelection(0); - - if(m_parent) - m_parent->CocoaAddChild(this); - - // Do the sizer dance - [GetNSBox() sizeToFit]; - SetInitialFrameRect(pos, size); - - return true; -} - -wxRadioBox::~wxRadioBox() -{ - DisassociateNSBox(GetNSBox()); -} - -WX_NSMatrix wxRadioBox::GetNSMatrix() const -{ - return (NSMatrix*)[(NSBox*)m_cocoaNSView contentView]; -} - - // selection -void wxRadioBox::SetSelection(int n) -{ - int r = GetRowForIndex(n); - int c = GetColumnForIndex(n); - [GetNSMatrix() selectCellAtRow:r column:c]; -} - -int wxRadioBox::GetSelection() const -{ - NSMatrix *radioBox = GetNSMatrix(); - NSInteger r = [radioBox selectedRow]; - NSInteger c = [radioBox selectedColumn]; - if(m_windowStyle & wxRA_SPECIFY_COLS) - return r * GetMajorDim() + c; - else - return c * GetMajorDim() + r; -} - - // string access -unsigned int wxRadioBox::GetCount() const -{ - NSMatrix *radioBox = GetNSMatrix(); - NSInteger rowCount, columnCount; - [radioBox getNumberOfRows:&rowCount columns:&columnCount]; - - // FIXME: This is wrong if padding cells were made - return rowCount * columnCount; -} - -wxString wxRadioBox::GetString(unsigned int n) const -{ - int r = GetRowForIndex(n); - int c = GetColumnForIndex(n); - // FIXME: Cocoa stores the mnemonic-stripped title. - return wxStringWithNSString([[GetNSMatrix() cellAtRow:r column:c] title]); -} - -void wxRadioBox::SetString(unsigned int n, const wxString& label) -{ - int r = GetRowForIndex(n); - int c = GetColumnForIndex(n); - CocoaSetLabelForObject(label, [GetNSMatrix() cellAtRow:r column:c]); -} - - // change the individual radio button state -bool wxRadioBox::Enable(unsigned int n, bool enable) -{ - int r = GetRowForIndex(n); - int c = GetColumnForIndex(n); - NSCell *cell = [GetNSMatrix() cellAtRow:r column:c]; - if(cell == nil) - return false; - bool wasEnabled = [cell isEnabled]; - [cell setEnabled:enable]; - return (wasEnabled && !enable) || (!wasEnabled && enable); -} - -bool wxRadioBox::Show(unsigned int n, bool show) -{ - // TODO - // NOTE: Cocoa has no visible state for cells so we'd need to replace the - // cell with a dummy one to hide it or alternatively subclass NSButtonCell - // and add the behaviour. - return false; -} - -wxSize wxRadioBox::DoGetBestSize() const -{ - // The NSBox responds to sizeToFit by sending sizeToFit to its contentView - // which is the NSMatrix and does the right thing. - return wxControl::DoGetBestSize(); -} - -void wxRadioBox::CocoaTarget_action(void) -{ - wxCommandEvent event(wxEVT_RADIOBOX, GetId()); - InitCommandEvent(event); - event.SetInt(GetSelection()); // i.e. SetSelection. - Command(event); -} - -#endif diff --git a/src/cocoa/radiobut.mm b/src/cocoa/radiobut.mm deleted file mode 100644 index 523b6acb41..0000000000 --- a/src/cocoa/radiobut.mm +++ /dev/null @@ -1,190 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/radiobut.mm -// Purpose: wxRadioButton -// Author: David Elliott -// Modified by: -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_RADIOBTN - -#include "wx/radiobut.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/app.h" -#endif //WX_PRECOMP - -#import -#include "wx/cocoa/string.h" -#include "wx/cocoa/autorelease.h" - -#include "wx/listimpl.cpp" - -WX_DEFINE_LIST(wxRadioButtonList); - -// wxRadioButtonBase == wxControl -BEGIN_EVENT_TABLE(wxRadioButton, wxControl) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxRadioButton,NSButton,NSControl,NSView) - -bool wxRadioButton::Create(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - m_radioMaster = NULL; - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - if(style&wxRB_GROUP) - { - m_radioMaster = this; - m_radioSlaves.Append(this); - } - else if(style&wxRB_SINGLE) - m_radioMaster = NULL; - else - { - for(wxWindowList::compatibility_iterator siblingNode= GetParent()->GetChildren().GetLast(); - siblingNode; - siblingNode = siblingNode->GetPrevious()) - { - wxRadioButton *radioButton = wxDynamicCast(siblingNode->GetData(),wxRadioButton); - if(radioButton && radioButton!=this) - { - m_radioMaster = radioButton->m_radioMaster; - wxASSERT_MSG(m_radioMaster, - wxT("Previous radio button should be part of a group")); - // Don't crash, assume user meant wxRB_SINGLE - if(m_radioMaster) - m_radioMaster->m_radioSlaves.Append(this); - break; - } - } - } - - m_cocoaNSView = NULL; - SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [GetNSButton() setButtonType: NSRadioButton]; - CocoaSetLabelForObject(label, GetNSButton()); - // If it's the first in a group, it should be selected - if(style&wxRB_GROUP) - [GetNSButton() setState: NSOnState]; - [GetNSControl() sizeToFit]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxRadioButton::~wxRadioButton() -{ - if(m_radioMaster==this) - { - // First get rid of ourselves (we should ALWAYS be at the head) - wxRadioButtonList::compatibility_iterator slaveNode = - m_radioSlaves.GetFirst(); - wxASSERT(slaveNode); - wxASSERT(slaveNode->GetData() == this); - m_radioSlaves.Erase(slaveNode); - - // Now find the new master - wxRadioButton *newMaster = NULL; - slaveNode = m_radioSlaves.GetFirst(); - if(slaveNode) - newMaster = slaveNode->GetData(); - - // For each node (including the new master) set the master, remove - // it from this list, and add it to the new master's list - for(; slaveNode; slaveNode = m_radioSlaves.GetFirst()) - { - wxRadioButton *radioButton = slaveNode->GetData(); - wxASSERT(radioButton->m_radioMaster == this); - radioButton->m_radioMaster = newMaster; - newMaster->m_radioSlaves.Append(radioButton); - m_radioSlaves.Erase(slaveNode); - } - } - else if(m_radioMaster) - { - m_radioMaster->m_radioSlaves.DeleteObject(this); - m_radioMaster = NULL; - } - // normal stuff - DisassociateNSButton(GetNSButton()); -} - -void wxRadioButton::SetValue(bool value) -{ - if(value) - { - [GetNSButton() setState: NSOnState]; - Cocoa_DeselectOtherButtonsInTheGroup(); - } - else - [GetNSButton() setState: NSOffState]; -} - -bool wxRadioButton::GetValue() const -{ - int state = [GetNSButton() state]; - wxASSERT(state!=NSMixedState); - return state==NSOnState; -} - -void wxRadioButton::SetLabel(const wxString& label) -{ - wxAutoNSAutoreleasePool pool; - CocoaSetLabelForObject(label, GetNSButton()); -} - -wxString wxRadioButton::GetLabel() const -{ - return wxStringWithNSString([GetNSButton() title]); -} - -/** - * If this radio button is part of a group, this method turns off every other - * button in the group. If this radio button is not part of a group, this - * method does absolutely nothing. - */ -void wxRadioButton::Cocoa_DeselectOtherButtonsInTheGroup(void) -{ - if(m_radioMaster) - { - for(wxRadioButtonList::compatibility_iterator slaveNode = - m_radioMaster->m_radioSlaves.GetFirst(); - slaveNode; slaveNode = slaveNode->GetNext()) - { - wxRadioButton *radioButton = slaveNode->GetData(); - if(radioButton!=this) - radioButton->SetValue(false); - } - } -} - -void wxRadioButton::Cocoa_wxNSButtonAction(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxRadioButton")); - if([GetNSButton() state] == NSOnState) - { - Cocoa_DeselectOtherButtonsInTheGroup(); - } - wxCommandEvent event(wxEVT_RADIOBUTTON, GetId()); - InitCommandEvent(event); // event.SetEventObject(this); - event.SetInt(GetValue()); - Command(event); -} - -#endif diff --git a/src/cocoa/region.mm b/src/cocoa/region.mm deleted file mode 100644 index 27fe595ff0..0000000000 --- a/src/cocoa/region.mm +++ /dev/null @@ -1,45 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/region.mm -// Purpose: wxRegion class -// Author: David Elliott -// Modified by: -// Created: 2004/04/12 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#include "wx/region.h" - -#import - -IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject); - -inline wxRect NSRectToWxRect(const NSRect& rect) -{ - return wxRect((wxCoord)rect.origin.x, (wxCoord)rect.origin.y, - (wxCoord)rect.size.width, (wxCoord)rect.size.height); -} - -wxRegion::wxRegion(const NSRect& rect) -{ - Union(NSRectToWxRect(rect)); -} - -wxRegion::wxRegion(const NSRect *rects, int count) -{ - for(int i=0; i - -BEGIN_EVENT_TABLE(wxScrollBar, wxScrollBarBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxScrollBar,NSScroller,NSControl,NSView) - -inline NSControlSize AdjustDimension( - int &pos, - wxSize &size, - int (wxSize::*GetDimension)() const, - void (wxSize::*SetDimension)(int)) -{ - NSControlSize controlSize = NSRegularControlSize; - const int dimension = (size.*GetDimension)(); - - if ((size.GetHeight() == -1) || (size.GetWidth() == -1) || (dimension >= 15)) - { - (size.*SetDimension)(15); - } - else - { - (size.*SetDimension)(11); - controlSize = NSSmallControlSize; - } - - pos += (dimension - (size.*GetDimension)() + 1) / 2; - - return (controlSize); -} - -bool wxScrollBar::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, const wxString& name) -{ - NSControlSize controlSize = NSRegularControlSize; - wxSize adjustedSize(size); - wxPoint adjustedPos(pos); - - if ((style & wxSB_HORIZONTAL) && ((size.GetHeight() != wxDefaultCoord) || (size.GetHeight() == -1))) - { - controlSize = AdjustDimension(adjustedPos.y, adjustedSize, &wxSize::GetHeight, &wxSize::SetHeight); - } - else if ((style & wxSB_VERTICAL) && (size.GetWidth() != wxDefaultCoord || (size.GetWidth() == -1))) - { - controlSize = AdjustDimension(adjustedPos.x, adjustedSize, &wxSize::GetWidth, &wxSize::SetWidth); - } - - if(!CreateControl(parent,winid,adjustedPos,adjustedSize,style,validator,name)) - return false; - SetNSScroller([[NSScroller alloc] initWithFrame: MakeDefaultNSRect(adjustedSize)]); - [m_cocoaNSView release]; - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(adjustedPos,adjustedSize); - - BOOL nsEnabled = [GetNSScroller() isEnabled]; - - if (IsEnabled() != (nsEnabled != NO)) - { - [GetNSScroller() setEnabled: !nsEnabled]; - } - - [GetNSScroller() setControlSize: controlSize]; - - return true; -} - -wxScrollBar::~wxScrollBar() -{ - DisassociateNSScroller(GetNSScroller()); -} - -/* A word about NSScroller vs. wxScrollbar: - -NSScroller uses two float values to represent the state of the scroller. -The floatValue indicates where the knob is positioned on a scale from -0.0 to 1.0. A value of 0.0 indicates the scroller is at the top or left, -a value of 1.0 indicates the scroller is at the bottom or right. A value -of 0.5 indicates the scroller is dead center. - -wxScrollBar uses three values. The position indicates the number of -scroll units where 0 is at the top or left. The range indicates how -many scroll units there are in the entire bar and the thumb size indicates -how many scroll units the thumb takes. The scrollbar is at the bottom -or right when position == range - thumbSize. - -It may be easier to consider wx position to be the top or left of the thumb. -In Cocoa, floatValue can be considered as if it were the center of the -thumb and the range is ALWAYS (no matter what the knobProportion is) the -distance between the center point of the knob from one extreme to the other. -*/ - -int wxScrollBar::GetThumbPosition() const -{ - return (int)((m_range-m_thumbSize)*[GetNSScroller() floatValue]); -} - -void wxScrollBar::SetThumbPosition(int position) -{ - [GetNSScroller() setFloatValue:((float)position)/(m_range-m_thumbSize)]; -} - -void wxScrollBar::SetScrollbar(int position, int thumbSize, - int range, int pageSize, bool refresh) -{ - m_range = range; - m_thumbSize = thumbSize; - m_pageSize = pageSize; - [GetNSScroller() setFloatValue:((float)position)/(m_range-m_thumbSize) - knobProportion:((float)m_thumbSize)/m_range]; -} - -void wxScrollBar::Cocoa_wxNSScrollerAction() -{ - NSScrollerPart hitPart = [GetNSScroller() hitPart]; - wxEventType command; - // Note: the comments about the part that is hit are for OS X, the - // constants are sort of a leftover from NeXT. It makes more sense if - // you remember that in NeXT clicking the knob slot used to do what - // option-clicking does now. - switch(hitPart) - { - // User dragged knob - case NSScrollerKnob: - command = wxEVT_SCROLL_THUMBTRACK; - break; - // User option-clicked slot - case NSScrollerKnobSlot: - command = wxEVT_SCROLL_THUMBTRACK; - break; - // User clicked Up/Left button - case NSScrollerDecrementLine: - command = wxEVT_SCROLL_LINEUP; - break; - // User option-clicked Up/left or clicked in slot - case NSScrollerDecrementPage: - command = wxEVT_SCROLL_PAGEUP; - break; - // User clicked Down/Right button - case NSScrollerIncrementLine: - command = wxEVT_SCROLL_LINEDOWN; - break; - // User option-clicked Down/Right or clicked in slot - case NSScrollerIncrementPage: - command = wxEVT_SCROLL_PAGEDOWN; - break; - // No-op - case NSScrollerNoPart: - default: - return; - } - // TODO: When scrolling by pages, readjust the floatValue using the - // pageSize (which may be different from thumbSize). - wxScrollEvent event(command, GetId(), GetThumbPosition(), - HasFlag(wxSB_VERTICAL)?wxVERTICAL:wxHORIZONTAL); - event.SetEventObject(this); - HandleWindowEvent(event); -} - -#endif // wxUSE_SCROLLBAR diff --git a/src/cocoa/settings.mm b/src/cocoa/settings.mm deleted file mode 100644 index ea351f7831..0000000000 --- a/src/cocoa/settings.mm +++ /dev/null @@ -1,220 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/settings.mm -// Purpose: wxSettings -// Author: David Elliott -// Modified by: -// Created: 2005/01/11 -// Copyright: (c) 2005 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/settings.h" - -#ifndef WX_PRECOMP - #include "wx/utils.h" - #include "wx/gdicmn.h" -#endif - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/private/fontfactory.h" - -#import -#import - -// ---------------------------------------------------------------------------- -// wxSystemSettingsNative -// ---------------------------------------------------------------------------- - -// ---------------------------------------------------------------------------- -// colours -// ---------------------------------------------------------------------------- - -wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) -{ - wxAutoNSAutoreleasePool pool; - switch( index ) - { - case wxSYS_COLOUR_SCROLLBAR: - return wxColour([NSColor scrollBarColor]); // color of slot - case wxSYS_COLOUR_BACKGROUND: // No idea how to get desktop background - break; // break so we return an invalid colour. - case wxSYS_COLOUR_ACTIVECAPTION: // No idea how to get this - // fall through, window background is reasonable - case wxSYS_COLOUR_INACTIVECAPTION: // No idea how to get this - // fall through, window background is reasonable - case wxSYS_COLOUR_MENU: - case wxSYS_COLOUR_MENUBAR: - case wxSYS_COLOUR_WINDOW: - case wxSYS_COLOUR_WINDOWFRAME: - case wxSYS_COLOUR_ACTIVEBORDER: - case wxSYS_COLOUR_INACTIVEBORDER: - return wxColour([NSColor windowFrameColor]); - case wxSYS_COLOUR_BTNFACE: - return wxColour([NSColor knobColor]); // close enough? - case wxSYS_COLOUR_LISTBOX: - return wxColour([NSColor controlBackgroundColor]); - case wxSYS_COLOUR_BTNSHADOW: - return wxColour([NSColor controlShadowColor]); - case wxSYS_COLOUR_BTNTEXT: - case wxSYS_COLOUR_MENUTEXT: - case wxSYS_COLOUR_WINDOWTEXT: - case wxSYS_COLOUR_CAPTIONTEXT: - case wxSYS_COLOUR_INFOTEXT: - case wxSYS_COLOUR_INACTIVECAPTIONTEXT: - return wxColour([NSColor controlTextColor]); - case wxSYS_COLOUR_HIGHLIGHT: - return wxColour([NSColor selectedControlColor]); - case wxSYS_COLOUR_BTNHIGHLIGHT: - return wxColour([NSColor controlHighlightColor]); - case wxSYS_COLOUR_GRAYTEXT: - return wxColour([NSColor disabledControlTextColor]); - case wxSYS_COLOUR_3DDKSHADOW: - return wxColour([NSColor controlShadowColor]); - case wxSYS_COLOUR_3DLIGHT: - return wxColour([NSColor controlHighlightColor]); - case wxSYS_COLOUR_HIGHLIGHTTEXT: - return wxColour([NSColor selectedControlTextColor]); - case wxSYS_COLOUR_INFOBK: - // tooltip (bogus) - return wxColour([NSColor controlBackgroundColor]); - case wxSYS_COLOUR_APPWORKSPACE: - // MDI window color (bogus) - return wxColour([NSColor windowBackgroundColor]); - case wxSYS_COLOUR_HOTLIGHT: - break; // what is this? - case wxSYS_COLOUR_GRADIENTACTIVECAPTION: - case wxSYS_COLOUR_GRADIENTINACTIVECAPTION: - break; // Doesn't really apply to Cocoa. - case wxSYS_COLOUR_MENUHILIGHT: - return wxColour([NSColor selectedMenuItemColor]); - case wxSYS_COLOUR_MAX: - default: - if(index>=wxSYS_COLOUR_MAX) - { - wxFAIL_MSG(wxT("Invalid system colour index")); - return wxColour(); - } - } - wxFAIL_MSG(wxT("Unimplemented system colour index")); - return wxColour(); -} - -// ---------------------------------------------------------------------------- -// fonts -// ---------------------------------------------------------------------------- - -wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) -{ - // Return the system font for now - { wxAutoNSAutoreleasePool pool; - return wxCocoaFontFactory::InstanceForNSFont([NSFont systemFontOfSize:0.0], false); - } - switch (index) - { - case wxSYS_ANSI_VAR_FONT : - case wxSYS_SYSTEM_FONT : - case wxSYS_DEVICE_DEFAULT_FONT : - case wxSYS_DEFAULT_GUI_FONT : - { - return *wxSMALL_FONT ; - } ; - break ; - case wxSYS_OEM_FIXED_FONT : - case wxSYS_ANSI_FIXED_FONT : - case wxSYS_SYSTEM_FIXED_FONT : - default : - { - return *wxNORMAL_FONT ; - } ; - break ; - - } - return *wxNORMAL_FONT; -} - -// ---------------------------------------------------------------------------- -// system metrics/features -// ---------------------------------------------------------------------------- - -// Get a system metric, e.g. scrollbar size -int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow *WXUNUSED(win)) -{ - switch ( index) - { - case wxSYS_MOUSE_BUTTONS: - return 2; // we emulate a two button mouse (ctrl + click = right button ) - - // TODO case wxSYS_BORDER_X: - // TODO case wxSYS_BORDER_Y: - // TODO case wxSYS_CURSOR_X: - // TODO case wxSYS_CURSOR_Y: - // TODO case wxSYS_DCLICK_X: - // TODO case wxSYS_DCLICK_Y: - // TODO case wxSYS_DRAG_X: - // TODO case wxSYS_DRAG_Y: - // TODO case wxSYS_EDGE_X: - // TODO case wxSYS_EDGE_Y: - - case wxSYS_HSCROLL_ARROW_X: - return 16; - case wxSYS_HSCROLL_ARROW_Y: - return 16; - case wxSYS_HTHUMB_X: - return 16; - - // TODO case wxSYS_ICON_X: - // TODO case wxSYS_ICON_Y: - // TODO case wxSYS_ICONSPACING_X: - // TODO case wxSYS_ICONSPACING_Y: - // TODO case wxSYS_WINDOWMIN_X: - // TODO case wxSYS_WINDOWMIN_Y: - // TODO case wxSYS_SCREEN_X: - // TODO case wxSYS_SCREEN_Y: - // TODO case wxSYS_FRAMESIZE_X: - // TODO case wxSYS_FRAMESIZE_Y: - // TODO case wxSYS_SMALLICON_X: - // TODO case wxSYS_SMALLICON_Y: - - case wxSYS_HSCROLL_Y: - return 16; - case wxSYS_VSCROLL_X: - return 16; - case wxSYS_VSCROLL_ARROW_X: - return 16; - case wxSYS_VSCROLL_ARROW_Y: - return 16; - case wxSYS_VTHUMB_Y: - return 16; - - // TODO case wxSYS_CAPTION_Y: - // TODO case wxSYS_MENU_Y: - // TODO case wxSYS_NETWORK_PRESENT: - - case wxSYS_PENWINDOWS_PRESENT: - return 0; - - // TODO case wxSYS_SHOW_SOUNDS: - - case wxSYS_SWAP_BUTTONS: - return 0; - - default: - return -1; // unsupported metric - } - return 0; -} - -bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) -{ - switch (index) - { - case wxSYS_CAN_ICONIZE_FRAME: - case wxSYS_CAN_DRAW_FRAME_DECORATIONS: - return true; - - default: - return false; - } -} diff --git a/src/cocoa/slider.mm b/src/cocoa/slider.mm deleted file mode 100644 index afa3767d3f..0000000000 --- a/src/cocoa/slider.mm +++ /dev/null @@ -1,266 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/slider.mm -// Purpose: wxSlider -// Author: David Elliott -// Mark Oxenham -// Modified by: -// Created: 2003/06/19 -// Copyright: (c) 2003 David Elliott -// (c) 2007 Software 2000 Ltd. -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#if wxUSE_SLIDER - -#include "wx/slider.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP - -#import -#include "wx/cocoa/objc/NSSlider.h" -#import -#import - -BEGIN_EVENT_TABLE(wxSlider, wxSliderBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxSlider,NSSlider,NSControl,NSView) - - -inline void AdjustDimension( - bool isTicksStyle, - int &pos, - wxSize &size, - int (wxSize::*GetDimension)() const, - void (wxSize::*SetDimension)(int)) -{ - const int dimension = (size.*GetDimension)(); - const int minSize = (isTicksStyle) ? 23 : 20; - - // prevent clipping of overly "thin" sliders - if (dimension < minSize) - { - (size.*SetDimension)(minSize); - } - - // move the slider control to the middle of the dimension that is not - // being used to define its length - pos += (dimension - (size.*GetDimension)() + 1) / 2; -} - -bool wxSlider::Create(wxWindow *parent, wxWindowID winid, - int value, int minValue, int maxValue, - const wxPoint& pos, const wxSize& size, long style, - const wxValidator& validator, const wxString& name) -{ - wxSize adjustedSize(size); - wxPoint adjustedPos(pos); - const bool isTicksStyle = (style & wxSL_TICKS) != 0; - - if ((style & wxSL_HORIZONTAL) && (size.GetHeight() != wxDefaultCoord)) - { - AdjustDimension(isTicksStyle, adjustedPos.y, adjustedSize, &wxSize::GetHeight, &wxSize::SetHeight); - } - else if ((style & wxSL_VERTICAL) && (size.GetWidth() != wxDefaultCoord)) - { - AdjustDimension(isTicksStyle, adjustedPos.x, adjustedSize, &wxSize::GetWidth, &wxSize::SetWidth); - } - - if(!CreateControl(parent,winid,adjustedPos,adjustedSize,style,validator,name)) - return false; - SetNSSlider([[WX_GET_OBJC_CLASS(WXNSSlider) alloc] initWithFrame: MakeDefaultNSRect(adjustedSize)]); - [m_cocoaNSView release]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(adjustedPos,adjustedSize); - - SetRange(minValue, maxValue); - SetValue(value); - - // -1 default for wxSL_AUTOTICKS == false - int tickMarks = -1; - // minValue > maxValue not handled, tickMarks set to 0 - if ( style & wxSL_AUTOTICKS ) - tickMarks = ((maxValue - minValue >= 0) ? (maxValue - minValue) : 0); - SetTickFreq(tickMarks); - - return true; -} - -wxSlider::~wxSlider() -{ - DisassociateNSSlider(GetNSSlider()); -} - -void wxSlider::AssociateNSSlider(WX_NSSlider theSlider) -{ - wxCocoaNSSlider::AssociateNSSlider(theSlider); - // Set the target/action.. we don't really need to unset these - [theSlider setTarget:wxCocoaNSControl::sm_cocoaTarget]; - [theSlider setAction:@selector(wxNSControlAction:)]; -} - -void wxSlider::ProcessEventType(wxEventType commandType) -{ - wxScrollEvent event(commandType, GetId(), GetValue(), HasFlag(wxSL_VERTICAL)?wxVERTICAL:wxHORIZONTAL); - event.SetEventObject(this); - HandleWindowEvent(event); -} - -static inline wxEventType wxSliderEventTypeForKeyFromEvent(NSEvent *theEvent) -{ - NSString *theEventCharacters = [theEvent charactersIgnoringModifiers]; - - if ([theEventCharacters length] == 1) - { - switch ([theEventCharacters characterAtIndex:0]) - { - case NSUpArrowFunctionKey: - case NSRightArrowFunctionKey: return wxEVT_SCROLL_PAGEDOWN; - case NSDownArrowFunctionKey: - case NSLeftArrowFunctionKey: return wxEVT_SCROLL_PAGEUP; - case NSPageUpFunctionKey: return wxEVT_SCROLL_BOTTOM; - case NSPageDownFunctionKey: return wxEVT_SCROLL_TOP; - } - } - // Overload wxEVT_ANY to mean we can't determine the event type. - return wxEVT_ANY; -} - -void wxSlider::CocoaTarget_action() -{ - wxEventType sliderEventType; - SEL theSelector = wxCocoaNSSlider::GetLastResponderSelector(); - - if( theSelector == @selector(moveUp:) - || theSelector == @selector(moveRight:)) - sliderEventType = wxEVT_SCROLL_PAGEDOWN; - else if( theSelector == @selector(moveDown:) - || theSelector == @selector(moveLeft:)) - sliderEventType = wxEVT_SCROLL_PAGEUP; - else if( theSelector == @selector(pageUp:)) - sliderEventType = wxEVT_SCROLL_BOTTOM; - else if( theSelector == @selector(pageDown:)) - sliderEventType = wxEVT_SCROLL_TOP; - else if( theSelector == @selector(keyDown:)) - // This case should ideally never be reached. - sliderEventType = wxSliderEventTypeForKeyFromEvent([[GetNSSlider() window] currentEvent]); - else - // Don't generate an event. - return; - if(sliderEventType != wxEVT_ANY) - ProcessEventType(sliderEventType); -} - -void wxSlider::CocoaNotification_startTracking(WX_NSNotification notification) -{ - CocoaNotification_continueTracking(notification); -} - -void wxSlider::CocoaNotification_continueTracking(WX_NSNotification notification) -{ - const double realValue = [GetNSSlider() doubleValue]; - - if (realValue != [GetNSSlider() intValue]) - { - SetValue(rint(realValue)); - } - - ProcessEventType(wxEVT_SCROLL_THUMBTRACK); -} - -void wxSlider::CocoaNotification_stopTracking(WX_NSNotification notification) -{ - ProcessEventType(wxEVT_SCROLL_THUMBRELEASE); -} - -int wxSlider::GetValue() const -{ - return [GetNSSlider() intValue]; -} - -void wxSlider::SetValue(int value) -{ - [GetNSSlider() setIntValue:value]; -} - -void wxSlider::SetRange(int minValue, int maxValue) -{ - [GetNSSlider() setMinValue:minValue]; - [GetNSSlider() setMaxValue:maxValue]; -} - -int wxSlider::GetMin() const -{ - return [GetNSSlider() minValue]; -} - -int wxSlider::GetMax() const -{ - return [GetNSSlider() maxValue]; -} - -void wxSlider::DoSetTickFreq(int n) -{ - const int numTicks = (n > 0) ? ((GetMax() - GetMin()) / n) + 1 : 0; - [GetNSSlider() setNumberOfTickMarks:numTicks]; -} - -int wxSlider::GetTickFreq() const -{ - const int numTicks = [GetNSSlider() numberOfTickMarks]; - return ((numTicks != 0) ? (GetMax() - GetMin()) / (numTicks - 1) : 0); -} - -void wxSlider::SetTickPos(int pos) -{ - NSTickMarkPosition thePos = NSTickMarkBelow; - wxSize size = GetSize(); - - if (size.GetWidth() < size.GetHeight()) // NSSlider isVertical method can return -1 if it has not been displayed. - { - thePos = (pos != 1) ? NSTickMarkLeft : NSTickMarkRight; - } - else - { - thePos = (pos != 1) ? NSTickMarkBelow : NSTickMarkAbove; - } - - [GetNSSlider() setTickMarkPosition:thePos]; -} - -void wxSlider::SetLineSize(int lineSize) -{ - // to do -} - -void wxSlider::SetPageSize(int pageSize) -{ - // to do -} - -int wxSlider::GetLineSize() const -{ - return 1; -} - -int wxSlider::GetPageSize() const -{ - return 1; -} - -int wxSlider::GetThumbLength() const -{ - return 1; -} - -void wxSlider::SetThumbLength(int lenPixels) -{ - // to do -} - -#endif // wxUSE_SLIDER diff --git a/src/cocoa/sound.mm b/src/cocoa/sound.mm deleted file mode 100644 index 0b3a0530a3..0000000000 --- a/src/cocoa/sound.mm +++ /dev/null @@ -1,189 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/sound.mm -// Purpose: wxSound class implementation: optional -// Authors: David Elliott, Ryan Norton -// Modified by: -// Created: 2004-10-02 -// Copyright: (c) 2004 David Elliott, Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#if wxUSE_SOUND - -#ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/log.h" -#endif //ndef WX_PRECOMP -#include "wx/sound.h" -#include "wx/evtloop.h" - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/log.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import -#import - -static WX_NSSound s_currentSound = nil; -static bool s_loopCurrentSound = false; - -// ======================================================================== -// wxNSSoundDelegate -// ======================================================================== -@interface wxNSSoundDelegate : NSObject -{ -} - -// Delegate methods -- (void)sound:(NSSound *)theSound didFinishPlaying:(BOOL)finishedPlaying; -@end // interface wxNSSoundDelegate : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxNSSoundDelegate,NSObject) - -@implementation wxNSSoundDelegate : NSObject - -- (void)sound:(NSSound *)theSound didFinishPlaying:(BOOL)finishedPlaying -{ - // If s_currentSound is not us then some other sound has played. - // We can safely ignore this as s_currentSound will have been released - // before being set to a different value. - if(s_currentSound!=theSound) - return; - // If playing finished successfully and we are looping, play again. - if (finishedPlaying && s_loopCurrentSound) - [s_currentSound play]; - // Otherwise we are done, there is no more current sound playing. - else - { - if(s_currentSound) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("[wxNSSoundDelegate -sound:didFinishPlaying:] [s_currentSound=%p retainCount]=%d (about to release)"),s_currentSound,[s_currentSound retainCount]); - [s_currentSound release]; - s_currentSound = nil; - // Make sure we get out of any modal event loops immediately. - // NOTE: When the sound finishes playing Cocoa normally does have - // an event so this is probably not necessary. - wxTheApp->WakeUpIdle(); - } -} - -@end // wxNSSoundDelegate -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSSoundDelegate,NSObject) - -const wxObjcAutoRefFromAlloc wxSound::sm_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSSoundDelegate) alloc] init]; - -// ------------------------------------------------------------------ -// wxSound -// ------------------------------------------------------------------ - -wxSound::wxSound(const wxSound& sound) -: m_cocoaNSSound(sound.m_cocoaNSSound) -{ - [m_cocoaNSSound retain]; -} - -wxSound::~wxSound() -{ - SetNSSound(nil); -} - -bool wxSound::Create(const wxString& fileName, bool isResource) -{ - wxAutoNSAutoreleasePool thePool; - - if (isResource) - SetNSSound([NSSound soundNamed:wxNSStringWithWxString(fileName)]); - else - { - SetNSSound([[NSSound alloc] initWithContentsOfFile:wxNSStringWithWxString(fileName) byReference:YES]); - [m_cocoaNSSound release]; - } - - return m_cocoaNSSound; -} - -bool wxSound::LoadWAV(const wxUint8 *data, size_t length, bool copyData) -{ - NSData* theData; - if(copyData) - theData = [[NSData alloc] initWithBytes:const_cast(data) length:length]; - else - theData = [[NSData alloc] initWithBytesNoCopy:const_cast(data) length:length]; - SetNSSound([[NSSound alloc] initWithData:theData]); - [m_cocoaNSSound release]; - [theData release]; - return m_cocoaNSSound; -} - -void wxSound::SetNSSound(WX_NSSound cocoaNSSound) -{ - bool need_debug = cocoaNSSound || m_cocoaNSSound; - if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxSound=%p::SetNSSound [m_cocoaNSSound=%p retainCount]=%d (about to release)"),this,m_cocoaNSSound,[m_cocoaNSSound retainCount]); - [cocoaNSSound retain]; - [m_cocoaNSSound release]; - m_cocoaNSSound = cocoaNSSound; - [m_cocoaNSSound setDelegate:sm_cocoaDelegate]; - if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxSound=%p::SetNSSound [cocoaNSSound=%p retainCount]=%d (just retained)"),this,cocoaNSSound,[cocoaNSSound retainCount]); -} - -bool wxSound::DoPlay(unsigned flags) const -{ - Stop(); // this releases and nils s_currentSound - - // NOTE: We set s_currentSound to the current sound in all cases so that - // functions like Stop and IsPlaying can work. It is NOT necessary for - // the NSSound to be retained by us for it to continue playing. Cocoa - // retains the NSSound when it is played and relases it when finished. - - wxASSERT(!s_currentSound); - s_currentSound = [m_cocoaNSSound retain]; - wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxSound=%p::DoPlay [s_currentSound=%p retainCount]=%d (just retained)"),this,s_currentSound,[s_currentSound retainCount]); - s_loopCurrentSound = (flags & wxSOUND_LOOP) == wxSOUND_LOOP; - - if (flags & wxSOUND_ASYNC) - return [m_cocoaNSSound play]; - else - { - wxASSERT_MSG(!s_loopCurrentSound,wxT("It is silly to block waiting for a looping sound to finish. Disabling looping")); - // actually, it'd probably work although it's kind of stupid to - // block here waiting for a sound that's never going to end. - // Granted Stop() could be called somehow, but again, silly. - s_loopCurrentSound = false; - - if(![m_cocoaNSSound play]) - return false; - - // Process events until the delegate sets s_currentSound to nil - // and/or a different sound plays. - while (s_currentSound==m_cocoaNSSound) - wxEventLoop::GetActive()->Dispatch(); - return true; - } -} - -bool wxSound::IsPlaying() -{ - // Normally you can send a message to a nil object and it will return - // nil. That behaviour would probably be okay here but in general it's - // not recommended to send a message to a nil object if the return - // value is not an object. Better safe than sorry. - if(s_currentSound) - return [s_currentSound isPlaying]; - else - return false; -} - -void wxSound::Stop() -{ - // Clear the looping flag so that if the sound finishes playing before - // stop is called the sound will already be released and niled. - s_loopCurrentSound = false; - [s_currentSound stop]; - /* It's possible that sound:didFinishPlaying: was called and released - s_currentSound but it doesn't matter since it will have set it to nil */ - if(s_currentSound) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxSound::Stop [s_currentSound=%p retainCount]=%d (about to release)"),s_currentSound,[s_currentSound retainCount]); - [s_currentSound release]; - s_currentSound = nil; -} - -#endif //wxUSE_SOUND diff --git a/src/cocoa/spinbutt.mm b/src/cocoa/spinbutt.mm deleted file mode 100644 index 2c9954545c..0000000000 --- a/src/cocoa/spinbutt.mm +++ /dev/null @@ -1,82 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/spinbutt.mm -// Purpose: wxSpinButton -// Author: David Elliott -// Modified by: -// Created: 2003/07/14 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#if wxUSE_SPINBTN - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP -#include "wx/spinbutt.h" - -#import - -BEGIN_EVENT_TABLE(wxSpinButton, wxSpinButtonBase) -END_EVENT_TABLE() -// WX_IMPLEMENT_COCOA_OWNER(wxSpinButton,NSStepper,NSControl,NSView) - -bool wxSpinButton::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, const wxSize& size, long style, - const wxString& name) -{ - //bad flag checking - wxASSERT_MSG( !(style & wxSP_HORIZONTAL), wxT("Horizontal wxSpinButton not supported in cocoa")); - if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - SetNSControl([[NSStepper alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - - //flag handling - [(NSStepper*)m_cocoaNSView setValueWraps:style & wxSP_WRAP]; //default == true, evidently - - //final setup - [(NSStepper*)m_cocoaNSView setTarget: sm_cocoaTarget]; - [(NSStepper*)m_cocoaNSView setAction:@selector(wxNSControlAction:)]; - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxSpinButton::~wxSpinButton() -{ - [(NSStepper*)m_cocoaNSView setTarget: nil]; - [(NSStepper*)m_cocoaNSView setAction: nil]; -} - -int wxSpinButton::GetValue() const -{ - return [(NSStepper*)m_cocoaNSView intValue]; -} - -void wxSpinButton::SetValue(int value) -{ - [(NSStepper*)m_cocoaNSView setIntValue:value]; -} - -void wxSpinButton::SetRange(int minValue, int maxValue) -{ - [(NSStepper*)m_cocoaNSView setMinValue:minValue]; - [(NSStepper*)m_cocoaNSView setMaxValue:maxValue]; - wxSpinButtonBase::SetRange(minValue,maxValue); -} - -void wxSpinButton::CocoaTarget_action() -{ - /* TODO: up/down events */ - /* This sends the changed event (not specific on up or down) */ - wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, GetId()); - event.SetPosition(GetValue()); - event.SetEventObject(this); - HandleWindowEvent(event); -} - -#endif // wxUSE_SPINBTN diff --git a/src/cocoa/statbmp.mm b/src/cocoa/statbmp.mm deleted file mode 100644 index e59b8c03a5..0000000000 --- a/src/cocoa/statbmp.mm +++ /dev/null @@ -1,67 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/statbmp.mm -// Purpose: wxStaticBitmap -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/statbmp.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" - -#import - -BEGIN_EVENT_TABLE(wxStaticBitmap, wxControl) -END_EVENT_TABLE() -// WX_IMPLEMENT_COCOA_OWNER(wxStaticBitmap,NSTextField,NSControl,NSView) - -bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID winid, - const wxBitmap& bitmap, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - SetNSView([[NSImageView alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - - [GetNSImageView() setImage:bitmap.GetNSImage(true)]; - m_bitmap = bitmap; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxStaticBitmap::~wxStaticBitmap() -{ -} - -void wxStaticBitmap::SetIcon(const wxIcon& icon) -{ -} - -void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) -{ - [GetNSImageView() setImage:bitmap.GetNSImage(true)]; - m_bitmap = bitmap; -} - -wxBitmap wxStaticBitmap::GetBitmap() const -{ - return m_bitmap; -} diff --git a/src/cocoa/statbox.mm b/src/cocoa/statbox.mm deleted file mode 100644 index e0cec2c9b4..0000000000 --- a/src/cocoa/statbox.mm +++ /dev/null @@ -1,75 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/statbox.mm -// Purpose: wxStaticBox -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/statbox.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import -#import - -BEGIN_EVENT_TABLE(wxStaticBox, wxStaticBoxBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxStaticBox,NSBox,NSView,NSView) - -bool wxStaticBox::Create(wxWindow *parent, wxWindowID winid, - const wxString& title, const wxPoint& pos, const wxSize& size, - long style, const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - m_cocoaNSView = NULL; - SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]); - CocoaSetLabelForObject(title, GetNSBox()); - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxStaticBox::~wxStaticBox() -{ - DisassociateNSBox(GetNSBox()); -} - -void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const -{ - NSRect contentRect = [[GetNSBox() contentView] frame]; - NSRect thisRect = [m_cocoaNSView frame]; - *borderTop = (int)(thisRect.size.height - (contentRect.origin.y+contentRect.size.height)); - *borderOther = (int)(thisRect.size.width - (contentRect.origin.x+contentRect.size.width)); - int nextBorder = (int)contentRect.origin.y; - if(nextBorder > *borderOther) - *borderOther = nextBorder; - nextBorder = (int)contentRect.origin.x; - if(nextBorder > *borderOther) - *borderOther = nextBorder; -} - -void wxStaticBox::SetLabel(const wxString& label) -{ - wxAutoNSAutoreleasePool pool; - CocoaSetLabelForObject(label, GetNSBox()); -} - -wxString wxStaticBox::GetLabel() const -{ - wxAutoNSAutoreleasePool pool; - return wxStringWithNSString([GetNSBox() title]); -} diff --git a/src/cocoa/statline2.mm b/src/cocoa/statline2.mm deleted file mode 100644 index 0696c005ac..0000000000 --- a/src/cocoa/statline2.mm +++ /dev/null @@ -1,47 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/statline2.mm -// Purpose: wxStaticLine -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif //WX_PRECOMP -#include "wx/statline.h" - -#include "wx/cocoa/autorelease.h" - -#import - -BEGIN_EVENT_TABLE(wxStaticLine, wxStaticLineBase) -END_EVENT_TABLE() -// WX_IMPLEMENT_COCOA_OWNER(wxStaticLine,NSTextField,NSControl,NSView) - -bool wxStaticLine::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - SetNSView([[NSBox alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [(NSBox*)m_cocoaNSView setBoxType: NSBoxSeparator]; - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxStaticLine::~wxStaticLine() -{ -} - diff --git a/src/cocoa/stattext.mm b/src/cocoa/stattext.mm deleted file mode 100644 index 87e82d126d..0000000000 --- a/src/cocoa/stattext.mm +++ /dev/null @@ -1,113 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/stattext.mm -// Purpose: wxStaticText -// Author: David Elliott -// Modified by: -// Created: 2003/02/15 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/stattext.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/log.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/log.h" - -#import -#import -#include - -BEGIN_EVENT_TABLE(wxStaticText, wxControl) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxStaticText,NSTextField,NSControl,NSView) - -bool wxStaticText::Create(wxWindow *parent, wxWindowID winid, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - m_cocoaNSView = NULL; - SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [GetNSTextField() setStringValue:wxNSStringWithWxString(GetLabelText(label))]; -// [GetNSTextField() setBordered: NO]; - [GetNSTextField() setBezeled: NO]; - [GetNSTextField() setEditable: NO]; - [GetNSTextField() setDrawsBackground: NO]; - - NSTextAlignment alignStyle; - if (style & wxALIGN_RIGHT) - alignStyle = NSRightTextAlignment; - else if (style & wxALIGN_CENTRE) - alignStyle = NSCenterTextAlignment; - else // default to wxALIGN_LEFT because it is 0 and can't be tested - alignStyle = NSLeftTextAlignment; - [GetNSControl() setAlignment:(NSTextAlignment)alignStyle]; - - [GetNSControl() sizeToFit]; - // Round-up to next integer size - NSRect nsrect = [m_cocoaNSView frame]; - nsrect.size.width = ceil(nsrect.size.width); - [m_cocoaNSView setFrameSize: nsrect.size]; - - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - return true; -} - -wxStaticText::~wxStaticText() -{ - DisassociateNSTextField(GetNSTextField()); -} - -void wxStaticText::SetLabel(const wxString& label) -{ - [GetNSTextField() setStringValue:wxNSStringWithWxString(GetLabelText(label))]; - NSRect oldFrameRect = [GetNSTextField() frame]; - NSView *superview = [GetNSTextField() superview]; - - if(!(GetWindowStyle() & wxST_NO_AUTORESIZE)) - { - wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel Old Position: (%d,%d)"), GetPosition().x, GetPosition().y); - [GetNSTextField() sizeToFit]; - NSRect newFrameRect = [GetNSTextField() frame]; - // Ensure new size is an integer so GetSize returns valid data - newFrameRect.size.height = ceil(newFrameRect.size.height); - newFrameRect.size.width = ceil(newFrameRect.size.width); - if(![superview isFlipped]) - { - newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height; - } - [GetNSTextField() setFrame:newFrameRect]; - // New origin (wx coords) should always match old origin - wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel New Position: (%d,%d)"), GetPosition().x, GetPosition().y); - [superview setNeedsDisplayInRect:newFrameRect]; - } - - [superview setNeedsDisplayInRect:oldFrameRect]; -} - -wxString wxStaticText::GetLabel() const -{ - wxAutoNSAutoreleasePool pool; - return wxStringWithNSString([GetNSTextField() stringValue]); -} - -void wxStaticText::Cocoa_didChangeText(void) -{ -} diff --git a/src/cocoa/taskbar.mm b/src/cocoa/taskbar.mm deleted file mode 100644 index e5491905c8..0000000000 --- a/src/cocoa/taskbar.mm +++ /dev/null @@ -1,406 +0,0 @@ -///////////////////////////////////////////////////////////////////////// -// File: src/cocoa/taskbar.mm -// Purpose: Implements wxTaskBarIcon class -// Author: David Elliott -// Modified by: -// Created: 2004/01/24 -// Copyright: (c) 2004 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" -#ifdef wxHAS_TASK_BAR_ICON - -#ifndef WX_PRECOMP - #include "wx/menu.h" - #include "wx/icon.h" - #include "wx/log.h" - #include "wx/dcclient.h" -#endif - -#include "wx/taskbar.h" - -#import -#import -#import -#import -#import -#import -#import -#import -#import - -#import -#import -#import - -#include "wx/cocoa/NSApplication.h" -#include "wx/cocoa/autorelease.h" - -// A category for methods that are only present in Panther's SDK -@interface NSStatusItem(wxNSStatusItemPrePantherCompatibility) -- (void)popUpStatusItemMenu:(NSMenu *)menu; -@end - -class wxTaskBarIconWindow; - -// ============================================================================ -// wxTaskBarIconCocoaImpl -// Base class for the various Cocoa implementations. -// ============================================================================ -class wxTaskBarIconCocoaImpl -{ -public: - wxTaskBarIconCocoaImpl(wxTaskBarIcon *taskBarIcon) - : m_taskBarIcon(taskBarIcon) - , m_iconWindow(NULL) - {} - virtual bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString) = 0; - virtual bool RemoveIcon() = 0; - virtual bool PopupMenu(wxMenu *menu) = 0; - virtual ~wxTaskBarIconCocoaImpl(); - inline wxTaskBarIcon* GetTaskBarIcon() { return m_taskBarIcon; } -protected: - inline wxMenu* CreatePopupMenu() - { wxASSERT(m_taskBarIcon); - return m_taskBarIcon->CreatePopupMenu(); - } - wxTaskBarIcon *m_taskBarIcon; - wxTaskBarIconWindow *m_iconWindow; -private: - wxTaskBarIconCocoaImpl(); -}; - -// ============================================================================ -// wxTaskBarIconDockImpl -// An implementation using the Dock icon. -// ============================================================================ -class wxTaskBarIconDockImpl: public wxTaskBarIconCocoaImpl -{ -public: - wxTaskBarIconDockImpl(wxTaskBarIcon *taskBarIcon); - virtual ~wxTaskBarIconDockImpl(); - virtual bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString); - virtual bool RemoveIcon(); - virtual bool PopupMenu(wxMenu *menu); - - static WX_NSMenu CocoaGetDockNSMenu(); -protected: - WX_NSMenu CocoaDoGetDockNSMenu(); - WX_NSImage m_originalDockIcon; - // There can be only one Dock icon, so make sure we keep it that way - static wxTaskBarIconDockImpl *sm_dockIcon; -private: - wxTaskBarIconDockImpl(); -}; - -// ============================================================================ -// wxTaskBarIconCustomStatusItemImpl -// An implementation using an NSStatusItem with a custom NSView -// ============================================================================ -class wxTaskBarIconCustomStatusItemImpl: public wxTaskBarIconCocoaImpl -{ -public: - wxTaskBarIconCustomStatusItemImpl(wxTaskBarIcon *taskBarIcon); - virtual ~wxTaskBarIconCustomStatusItemImpl(); - virtual bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString); - virtual bool RemoveIcon(); - virtual bool PopupMenu(wxMenu *menu); -protected: - NSStatusItem *m_cocoaNSStatusItem; -private: - wxTaskBarIconCustomStatusItemImpl(); -}; - -// ============================================================================ -// wxTaskBarIconWindow -// Used by all implementations to forward events from the wxMenu -// ============================================================================ -class wxTaskBarIconWindow: public wxWindow -{ - DECLARE_EVENT_TABLE() -public: - wxTaskBarIconWindow(wxTaskBarIconCocoaImpl *taskBarIconImpl) - : wxWindow(NULL,-1) - , m_taskBarIconImpl(taskBarIconImpl) - { wxASSERT(m_taskBarIconImpl); } - - void OnMenuEvent(wxCommandEvent& event); -protected: - wxTaskBarIconCocoaImpl *m_taskBarIconImpl; -}; - -// ============================================================================ -// wxTaskBarIconWindowCustom -// Used by the CustomStatusIcon implementation for the custom NSView. -// ============================================================================ -class wxTaskBarIconWindowCustom: public wxTaskBarIconWindow -{ - DECLARE_EVENT_TABLE() -public: - wxTaskBarIconWindowCustom(wxTaskBarIconCocoaImpl *taskBarIconImpl) - : wxTaskBarIconWindow(taskBarIconImpl) - {} - void SetIcon(const wxIcon& icon) - { m_icon = icon; } - void OnMouseEvent(wxMouseEvent &event); - void OnPaint(wxPaintEvent &event); -protected: - wxIcon m_icon; -}; - -// ============================================================================ -// wxTaskBarIcon implementation -// The facade class. -// ============================================================================ -IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler) - -wxTaskBarIcon::wxTaskBarIcon(wxTaskBarIconType iconType) -{ - if(iconType == DOCK) - m_impl = new wxTaskBarIconDockImpl(this); - else if(iconType == CUSTOM_STATUSITEM) - m_impl = new wxTaskBarIconCustomStatusItemImpl(this); - else - { m_impl = NULL; - wxFAIL_MSG(wxT("Invalid wxTaskBarIcon type")); - } -} - -wxTaskBarIcon::~wxTaskBarIcon() -{ - delete m_impl; -} - -// Operations -bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) -{ - return m_impl->SetIcon(icon,tooltip); -} - -bool wxTaskBarIcon::RemoveIcon() -{ - return m_impl->RemoveIcon(); -} - -bool wxTaskBarIcon::PopupMenu(wxMenu *menu) -{ - return m_impl->PopupMenu(menu); -} - -// ============================================================================ -// wxTaskBarIconCocoaImpl -// ============================================================================ - -#if 0 -wxTaskBarIconCocoaImpl::wxTaskBarIconCocoaImpl(wxTaskBarIcon *taskBarIcon) -: m_taskBarIcon(taskBarIcon) -, m_iconWindow(NULL) -{ -} -#endif - -wxTaskBarIconCocoaImpl::~wxTaskBarIconCocoaImpl() -{ -// wxAutoNSAutoreleasePool pool; - delete m_iconWindow; -} - -// ============================================================================ -// wxTaskBarIconDockImpl -// ============================================================================ -wxTaskBarIconDockImpl *wxTaskBarIconDockImpl::sm_dockIcon = NULL; - -wxTaskBarIconDockImpl::wxTaskBarIconDockImpl(wxTaskBarIcon *taskBarIcon) -: wxTaskBarIconCocoaImpl(taskBarIcon) -{ - m_originalDockIcon = nil; - wxASSERT_MSG(!sm_dockIcon, wxT("You should never have more than one dock icon!")); - sm_dockIcon = this; -} - -wxTaskBarIconDockImpl::~wxTaskBarIconDockImpl() -{ -// wxAutoNSAutoreleasePool pool; - if(sm_dockIcon == this) - sm_dockIcon = NULL; -} - -WX_NSMenu wxTaskBarIconDockImpl::CocoaGetDockNSMenu() -{ - if(sm_dockIcon) - return sm_dockIcon->CocoaDoGetDockNSMenu(); - return nil; -} - -WX_NSMenu wxTaskBarIconDockImpl::CocoaDoGetDockNSMenu() -{ - wxMenu *dockMenu = CreatePopupMenu(); - if(!dockMenu) - return nil; - if(!m_iconWindow) - m_iconWindow = new wxTaskBarIconWindow(this); - dockMenu->SetInvokingWindow(m_iconWindow); - dockMenu->UpdateUI(); - dockMenu->SetCocoaDeletes(true); - return dockMenu->GetNSMenu(); -} - -bool wxTaskBarIconDockImpl::SetIcon(const wxIcon& icon, const wxString& tooltip) -{ - wxAutoNSAutoreleasePool pool; - m_originalDockIcon = [[[NSApplication sharedApplication] applicationIconImage] retain]; - [[NSApplication sharedApplication] setApplicationIconImage:icon.GetNSImage()]; - return true; -} - -bool wxTaskBarIconDockImpl::RemoveIcon() -{ - [[NSApplication sharedApplication] setApplicationIconImage:m_originalDockIcon]; - [m_originalDockIcon release]; - return true; -} - -bool wxTaskBarIconDockImpl::PopupMenu(wxMenu *menu) -{ - wxFAIL_MSG(wxT("You cannot force the Dock icon menu to popup")); - return false; -} - - -// ============================================================================ -// wxTaskBarIconCustomStatusItemImpl -// ============================================================================ -wxTaskBarIconCustomStatusItemImpl::wxTaskBarIconCustomStatusItemImpl(wxTaskBarIcon *taskBarIcon) -: wxTaskBarIconCocoaImpl(taskBarIcon) -{ - m_cocoaNSStatusItem = nil; -} - -wxTaskBarIconCustomStatusItemImpl::~wxTaskBarIconCustomStatusItemImpl() -{ -} - -bool wxTaskBarIconCustomStatusItemImpl::SetIcon(const wxIcon& icon, const wxString& tooltip) -{ - wxAutoNSAutoreleasePool pool; - if(!m_cocoaNSStatusItem) - { - m_cocoaNSStatusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; - [m_cocoaNSStatusItem retain]; - } - if(!m_iconWindow) - m_iconWindow= new wxTaskBarIconWindowCustom(this); - static_cast(m_iconWindow)->SetIcon(icon); - // FIXME: no less than 10 because most icon types don't work yet - // and this allows us to see how task bar icons would work - [m_iconWindow->GetNSView() setFrame:NSMakeRect(0.0,0.0,wxMax(10,icon.GetWidth()),[[NSStatusBar systemStatusBar] thickness])]; - [m_cocoaNSStatusItem setView:m_iconWindow->GetNSView()]; - return true; -} - -bool wxTaskBarIconCustomStatusItemImpl::RemoveIcon() -{ - [m_cocoaNSStatusItem release]; - m_cocoaNSStatusItem = nil; - delete m_iconWindow; - m_iconWindow = NULL; - return true; -} - -bool wxTaskBarIconCustomStatusItemImpl::PopupMenu(wxMenu *menu) -{ - wxCHECK_MSG(menu, false, "can't popup a NULL menu"); - - wxMenuInvokingWindowSetter setInvokingWin(*menu, m_iconWindow); - menu->UpdateUI(); - - if([m_cocoaNSStatusItem respondsToSelector:@selector(popUpStatusItemMenu:)]) - { // OS X >= 10.3 - [m_cocoaNSStatusItem popUpStatusItemMenu:menu->GetNSMenu()]; - } - else - { // pretty good fake for OS X < 10.3 - NSEvent *nsevent = [NSEvent mouseEventWithType:NSLeftMouseDown - location:NSMakePoint(-1.0,-4.0) modifierFlags:0 timestamp:0 - windowNumber:[[m_iconWindow->GetNSView() window] windowNumber] - context:[NSGraphicsContext currentContext] - eventNumber:0 clickCount:1 pressure:0.0]; - [NSMenu popUpContextMenu:menu->GetNSMenu() withEvent:nsevent forView:m_iconWindow->GetNSView()]; - } - return true; -} - -// ============================================================================ -// wxTaskBarIconWindow -// ============================================================================ -BEGIN_EVENT_TABLE(wxTaskBarIconWindow, wxWindow) - EVT_MENU(-1, wxTaskBarIconWindow::OnMenuEvent) -END_EVENT_TABLE() - -void wxTaskBarIconWindow::OnMenuEvent(wxCommandEvent &event) -{ - m_taskBarIconImpl->GetTaskBarIcon()->ProcessEvent(event); -} - -// ============================================================================ -// wxTaskBarIconWindowCustom -// ============================================================================ -BEGIN_EVENT_TABLE(wxTaskBarIconWindowCustom, wxTaskBarIconWindow) - EVT_MOUSE_EVENTS(wxTaskBarIconWindowCustom::OnMouseEvent) - EVT_PAINT(wxTaskBarIconWindowCustom::OnPaint) -END_EVENT_TABLE() - -void wxTaskBarIconWindowCustom::OnMouseEvent(wxMouseEvent &event) -{ - wxEventType tbEventType = 0; - if(event.GetEventType() == wxEVT_MOTION) - tbEventType = wxEVT_TASKBAR_MOVE; - else if(event.GetEventType() == wxEVT_LEFT_DOWN) - tbEventType = wxEVT_TASKBAR_LEFT_DOWN; - else if(event.GetEventType() == wxEVT_LEFT_UP) - tbEventType = wxEVT_TASKBAR_LEFT_UP; - else if(event.GetEventType() == wxEVT_RIGHT_DOWN) - tbEventType = wxEVT_TASKBAR_RIGHT_DOWN; - else if(event.GetEventType() == wxEVT_RIGHT_UP) - tbEventType = wxEVT_TASKBAR_RIGHT_UP; - else if(event.GetEventType() == wxEVT_LEFT_DCLICK) - tbEventType = wxEVT_TASKBAR_LEFT_DCLICK; - else if(event.GetEventType() == wxEVT_RIGHT_DCLICK) - tbEventType = wxEVT_TASKBAR_RIGHT_DCLICK; - else - return; - wxTaskBarIconEvent tbiEvent(tbEventType,m_taskBarIconImpl->GetTaskBarIcon()); - m_taskBarIconImpl->GetTaskBarIcon()->ProcessEvent(tbiEvent); -} - -void wxTaskBarIconWindowCustom::OnPaint(wxPaintEvent &event) -{ - wxPaintDC dc(this); - // FIXME: This is a temporary hack until we can see real icons - dc.SetBackground(wxBrush(*wxBLUE)); - dc.Clear(); - dc.DrawIcon(m_icon,0,0); -} - -// ============================================================================ -// wxTaskBarIconNSApplicationDelegateCategory -// ============================================================================ - -// This neatly solves the problem of DLL separation. If the wxAdvanced -// library (which this file is part of) is loaded then this category is -// defined and we get dock menu behaviour without app.mm ever having to -// know we exist. C++ did sucketh so. :-) - -@interface wxNSApplicationDelegate(wxTaskBarIconNSApplicationDelegateCategory) -- (NSMenu*)applicationDockMenu:(NSApplication *)sender; -@end - -@implementation wxNSApplicationDelegate(wxTaskBarIconNSApplicationDelegateCategory) -- (NSMenu*)applicationDockMenu:(NSApplication *)sender -{ - return wxTaskBarIconDockImpl::CocoaGetDockNSMenu(); -} -@end - -#endif //def wxHAS_TASK_BAR_ICON diff --git a/src/cocoa/textctrl.mm b/src/cocoa/textctrl.mm deleted file mode 100644 index 07df3cdae0..0000000000 --- a/src/cocoa/textctrl.mm +++ /dev/null @@ -1,262 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/textctrl.mm -// Purpose: wxTextCtrl -// Author: David Elliott -// Modified by: Mark Oxenham -// Created: 2003/03/16 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/textctrl.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" - #include "wx/log.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/string.h" - -#include "wx/cocoa/autorelease.h" - -#import -#import -#import -#import - -#include - -BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) -END_EVENT_TABLE() -WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView) - -bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - if(!CreateControl(parent,winid,pos,size,style,validator,name)) - return false; - m_cocoaNSView = NULL; - SetNSTextField([(style & wxTE_PASSWORD)?[NSSecureTextField alloc]:[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - [GetNSTextField() setStringValue:wxNSStringWithWxString(value)]; - - [GetNSControl() sizeToFit]; - NSRect currentFrame = [m_cocoaNSView frame]; - if(currentFrame.size.width < 70) - { - currentFrame.size.width = 70; - [m_cocoaNSView setFrame:currentFrame]; - } - if(m_parent) - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - - [(NSTextField*)m_cocoaNSView setTarget: sm_cocoaTarget]; - [(NSTextField*)m_cocoaNSView setAction:@selector(wxNSControlAction:)]; - - // set the text alignment option - NSTextAlignment alignStyle; - if (style & wxTE_RIGHT) - alignStyle = NSRightTextAlignment; - else if (style & wxTE_CENTRE) - alignStyle = NSCenterTextAlignment; - else // default to wxTE_LEFT because it is 0 and can't be tested - alignStyle = NSLeftTextAlignment; - [GetNSControl() setAlignment:alignStyle]; - - // if Read-only then set as such, this flag is overwritable by wxTextCtrl::SetEditable(TRUE) - if (style & wxTE_READONLY) - { - SetEditable(FALSE); - } - - return true; -} - -wxTextCtrl::~wxTextCtrl() -{ - DisassociateNSTextField(GetNSTextField()); -} - -void wxTextCtrl::Cocoa_didChangeText(void) -{ -} - -void wxTextCtrl::CocoaTarget_action(void) -{ - SendTextUpdatedEvent(); -} - -void wxTextCtrl::AppendText(wxString const&) -{ -} - -void wxTextCtrl::SetEditable(bool editable) -{ - // first ensure that the current value is stored (in case the user had not finished editing - // before SetEditable(FALSE) was called) - DoSetValue(GetValue(),1); - - [GetNSTextField() setEditable: editable]; - - // forces the focus on the textctrl to be lost - while focus is still maintained - // after SetEditable(FALSE) the user may still edit the control - // (might not the best way to do this..) - [GetNSTextField() abortEditing]; -} - -void wxTextCtrl::MarkDirty() -{ -} - -void wxTextCtrl::DiscardEdits() -{ -} - -void wxTextCtrl::SetSelection(long, long) -{ -} - -void wxTextCtrl::ShowPosition(long) -{ -} - -void wxTextCtrl::SetInsertionPoint(long) -{ -} - -void wxTextCtrl::SetInsertionPointEnd() -{ -} - -void wxTextCtrl::Cut() -{ -} - -void wxTextCtrl::Copy() -{ -} - -void wxTextCtrl::Redo() -{ -} - -void wxTextCtrl::Undo() -{ -} - -void wxTextCtrl::Clear() -{ -} - -void wxTextCtrl::Paste() -{ -} - -void wxTextCtrl::Remove(long, long) -{ -} - -void wxTextCtrl::Replace(long, long, wxString const&) -{ -} - -void wxTextCtrl::DoSetValue(wxString const& value, int flags) -{ - wxAutoNSAutoreleasePool pool; - [GetNSTextField() setStringValue: wxNSStringWithWxString(value)]; - - if ( flags & SetValue_SendEvent ) - SendTextUpdatedEvent(); -} - -void wxTextCtrl::WriteText(wxString const&) -{ -} - -bool wxTextCtrl::IsEditable() const -{ - return [GetNSTextField() isEditable]; -} - -bool wxTextCtrl::IsModified() const -{ - return false; -} - -wxString wxTextCtrl::GetLineText(long) const -{ - return wxEmptyString; -} - -void wxTextCtrl::GetSelection(long*, long*) const -{ -} - -bool wxTextCtrl::PositionToXY(long, long*, long*) const -{ - return false; -} - -long wxTextCtrl::XYToPosition(long, long) const -{ - return 0; -} - -int wxTextCtrl::GetLineLength(long) const -{ - return 0; -} - -wxTextPos wxTextCtrl::GetLastPosition() const -{ - // working - returns the size of the wxString - return (long)(GetValue().Len()); -} - -int wxTextCtrl::GetNumberOfLines() const -{ - return 0; -} - -long wxTextCtrl::GetInsertionPoint() const -{ - return 0; -} - -bool wxTextCtrl::CanRedo() const -{ - return false; -} - -bool wxTextCtrl::CanUndo() const -{ - return false; -} - -wxString wxTextCtrl::GetValue() const -{ - wxAutoNSAutoreleasePool pool; - return wxStringWithNSString([GetNSTextField() stringValue]); -} - -wxSize wxTextCtrl::DoGetBestSize() const -{ - wxAutoNSAutoreleasePool pool; - wxASSERT(GetNSControl()); - NSCell *cell = [GetNSControl() cell]; - wxASSERT(cell); - NSSize cellSize = [cell cellSize]; - wxSize size(100,(int)ceil(cellSize.height)); - - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y); - return size; -} diff --git a/src/cocoa/timer.mm b/src/cocoa/timer.mm deleted file mode 100644 index 062add4857..0000000000 --- a/src/cocoa/timer.mm +++ /dev/null @@ -1,124 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/timer.mm -// Purpose: wxTimer for wxCocoa -// Author: Ryan Norton -// Modified by: David Elliott -// Created: 2005-02-04 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#if wxUSE_TIMER - -#include "wx/cocoa/private/timer.h" -#include "wx/cocoa/autorelease.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import - -// ======================================================================== -// wxNSTimerData -// ======================================================================== -@interface wxNSTimerData : NSObject -{ - wxCocoaTimerImpl* m_timer; -} - -- (id)init; -- (id)initWithWxTimer:(wxCocoaTimerImpl*)theTimer; -- (wxCocoaTimerImpl*)timer; -- (void)onNotify:(NSTimer *)theTimer; -@end // interface wxNSTimerData : NSObject -WX_DECLARE_GET_OBJC_CLASS(wxNSTimerData,NSObject) - -@implementation wxNSTimerData : NSObject -- (id)init -{ - if(!(self = [super init])) - return nil; - m_timer = NULL; - return self; -} - -- (id)initWithWxTimer:(wxCocoaTimerImpl*)theTimer; -{ - if(!(self = [super init])) - return nil; - m_timer = theTimer; - return self; -} - -- (wxCocoaTimerImpl*)timer -{ - return m_timer; -} - -- (void)onNotify:(NSTimer *)theTimer -{ - m_timer->Notify(); -} -@end -WX_IMPLEMENT_GET_OBJC_CLASS(wxNSTimerData,NSObject) - -// ---------------------------------------------------------------------------- -// wxCocoaTimerImpl -// ---------------------------------------------------------------------------- - -wxCocoaTimerImpl::~wxCocoaTimerImpl() -{ - Stop(); -} - -void wxCocoaTimerImpl::Init() -{ - m_cocoaNSTimer = NULL; -} - -bool wxCocoaTimerImpl::Start(int millisecs, bool oneShot) -{ - Stop(); - - wxAutoNSAutoreleasePool thePool; - - wxNSTimerData *timerData = [[WX_GET_OBJC_CLASS(wxNSTimerData) alloc] initWithWxTimer:this]; - m_cocoaNSTimer = [[NSTimer - scheduledTimerWithTimeInterval: millisecs / 1000.0 //seconds - target: timerData - selector: @selector(onNotify:) - userInfo: nil - repeats: oneShot == false] retain]; - [timerData release]; - - return IsRunning(); -} - -void wxCocoaTimerImpl::Stop() -{ - if (m_cocoaNSTimer) - { - // FIXME: Is this safe to do if !isValid ? - [m_cocoaNSTimer invalidate]; - [m_cocoaNSTimer release]; - m_cocoaNSTimer = NULL; - } -} - -bool wxCocoaTimerImpl::IsRunning() const -{ - return m_cocoaNSTimer != NULL && [m_cocoaNSTimer isValid]; -} - -#endif // wxUSE_TIMER - diff --git a/src/cocoa/toolbar.mm b/src/cocoa/toolbar.mm deleted file mode 100644 index 79f5c02473..0000000000 --- a/src/cocoa/toolbar.mm +++ /dev/null @@ -1,428 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/toolbar.mm -// Purpose: wxToolBar -// Author: David Elliott -// Modified by: -// Created: 2003/08/17 -// Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#if wxUSE_TOOLBAR_NATIVE - -#include "wx/toolbar.h" - -#ifndef WX_PRECOMP - #include "wx/frame.h" - #include "wx/log.h" -#endif // WX_PRECOMP - -#include "wx/cocoa/string.h" -#include "wx/cocoa/autorelease.h" - -#import -#import -#import -#import -#import -#import -#import -#import - -#include - -// ======================================================================== -// wxToolBarTool -// ======================================================================== -class wxToolBarTool : public wxToolBarToolBase -{ -public: - wxToolBarTool(wxToolBar *tbar, int toolid, const wxString& label, - const wxBitmap& bitmap1, const wxBitmap& bitmap2, - wxItemKind kind, wxObject *clientData, - const wxString& shortHelpString, const wxString& longHelpString) - : wxToolBarToolBase(tbar, toolid, label, bitmap1, bitmap2, kind, - clientData, shortHelpString, longHelpString) - { - Init(); - CreateButtonCell(); - } - - wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) - : wxToolBarToolBase(tbar, control, label) - { - Init(); - } - ~wxToolBarTool(); - - bool CreateButtonCell(); - - // is this a radio button? - // - // unlike GetKind(), can be called for any kind of tools, not just buttons - bool IsRadio() const { return IsButton() && GetKind() == wxITEM_RADIO; } - - NSRect GetFrameRect() - { return m_frameRect; } - void SetFrameRect(NSRect frameRect) - { m_frameRect = frameRect; } - void DrawTool(NSView *nsview); - - NSButtonCell *GetNSButtonCell() - { return m_cocoaNSButtonCell; } -protected: - void Init(); - NSButtonCell *m_cocoaNSButtonCell; - NSRect m_frameRect; -}; - -// ======================================================================== -// wxToolBarTool -// ======================================================================== -void wxToolBarTool::Init() -{ - m_cocoaNSButtonCell = NULL; - m_frameRect = NSZeroRect; -} - -void wxToolBar::CocoaToolClickEnded() -{ - wxASSERT(m_mouseDownTool); - wxCommandEvent event(wxEVT_MENU, m_mouseDownTool->GetId()); - InitCommandEvent(event); - Command(event); -} - -wxToolBarTool::~wxToolBarTool() -{ - [m_cocoaNSButtonCell release]; -} - -bool wxToolBarTool::CreateButtonCell() -{ - wxAutoNSAutoreleasePool pool; - - NSImage *nsimage = [m_bmpNormal.GetNSImage(true) retain]; - m_cocoaNSButtonCell = [[NSButtonCell alloc] initTextCell:nil]; - [m_cocoaNSButtonCell setImage:nsimage]; - NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:wxNSStringWithWxString(m_label) attributes:[NSDictionary dictionaryWithObject:[NSFont labelFontOfSize:0.0] forKey:NSFontAttributeName]]; -// [m_cocoaNSButtonCell setTitle:wxNSStringWithWxString(m_label)]; - [m_cocoaNSButtonCell setAttributedTitle:[attributedTitle autorelease]]; - - // Create an alternate image in the style of NSToolBar - if(nsimage) - { - NSImage *alternateImage = [[NSImage alloc] initWithSize:[nsimage size]]; - [alternateImage lockFocus]; - // Paint the entire image with solid black at 50% transparency - NSRect imageRect = NSZeroRect; - imageRect.size = [alternateImage size]; - [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] set]; - NSRectFill(imageRect); - // Composite the original image with the alternate image - [nsimage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationAtop]; - [alternateImage unlockFocus]; - [m_cocoaNSButtonCell setAlternateImage:alternateImage]; - [alternateImage release]; - } - [nsimage release]; - - NSMutableAttributedString *alternateTitle = [[NSMutableAttributedString alloc] initWithAttributedString:[m_cocoaNSButtonCell attributedTitle]]; - [alternateTitle applyFontTraits:NSBoldFontMask range:NSMakeRange(0,[alternateTitle length])]; - [m_cocoaNSButtonCell setAttributedAlternateTitle:alternateTitle]; - [alternateTitle release]; - - // ---- - [m_cocoaNSButtonCell setImagePosition:NSImageBelow]; -// [m_cocoaNSButtonCell setBezeled:NO]; - [m_cocoaNSButtonCell setButtonType:NSMomentaryChangeButton]; - [m_cocoaNSButtonCell setBordered:NO]; -// [m_cocoaNSButtonCell setHighlightsBy:NSContentsCellMask|NSPushInCellMask]; -// [m_cocoaNSButtonCell setShowsStateBy:NSContentsCellMask|NSPushInCellMask]; - return true; -} - -void wxToolBarTool::DrawTool(NSView *nsview) -{ - [m_cocoaNSButtonCell drawWithFrame:m_frameRect inView:nsview]; -} - -// ======================================================================== -// wxToolBar -// ======================================================================== -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) - -//----------------------------------------------------------------------------- -// wxToolBar construction -//----------------------------------------------------------------------------- - -void wxToolBar::Init() -{ - m_owningFrame = NULL; - m_mouseDownTool = NULL; -} - -wxToolBar::~wxToolBar() -{ -} - -bool wxToolBar::Create( wxWindow *parent, - wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name ) -{ - // Call wxControl::Create so we get a wxNonControlNSControl - if ( !wxToolBarBase::Create(parent, winid, pos, size, style, - wxDefaultValidator, name) ) - return false; - - FixupStyle(); - - return true; -} - -wxToolBarToolBase *wxToolBar::CreateTool(int toolid, - const wxString& text, - const wxBitmap& bitmap1, - const wxBitmap& bitmap2, - wxItemKind kind, - wxObject *clientData, - const wxString& shortHelpString, - const wxString& longHelpString) -{ - return new wxToolBarTool(this, toolid, text, bitmap1, bitmap2, kind, - clientData, shortHelpString, longHelpString); -} - -wxToolBarToolBase * -wxToolBar::CreateTool(wxControl *control, const wxString& label) -{ - return new wxToolBarTool(this, control, label); -} - -void wxToolBar::SetWindowStyleFlag( long style ) -{ - wxToolBarBase::SetWindowStyleFlag(style); -} - -bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase) -{ - return true; -} - -bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) -{ - Realize(); - return true; -} - -bool wxToolBar::Cocoa_acceptsFirstMouse(bool &acceptsFirstMouse, WX_NSEvent theEvent) -{ - acceptsFirstMouse = true; return true; -} - -bool wxToolBar::Cocoa_drawRect(const NSRect &rect) -{ - wxToolBarToolsList::compatibility_iterator node; - for(node = m_tools.GetFirst(); node; node = node->GetNext()) - { - wxToolBarTool *tool = static_cast(node->GetData()); - tool->DrawTool(m_cocoaNSView); - } - return wxToolBarBase::Cocoa_drawRect(rect); -} - -static const NSSize toolPadding = { 4.0, 4.0 }; - -static NSRect AddToolPadding(NSRect toolRect) -{ - toolRect.origin.x -= toolPadding.width; - toolRect.size.width += 2.0*toolPadding.width; - toolRect.origin.y -= toolPadding.height; - toolRect.size.height += 2.0*toolPadding.height; - return toolRect; -} - -bool wxToolBar::Cocoa_mouseDragged(WX_NSEvent theEvent) -{ - if(m_mouseDownTool && [m_cocoaNSView - mouse:[m_cocoaNSView convertPoint:[theEvent locationInWindow] - fromView:nil] - inRect:AddToolPadding(m_mouseDownTool->GetFrameRect())]) - { - NSButtonCell *buttonCell = m_mouseDownTool->GetNSButtonCell(); - if(buttonCell) - { - [buttonCell retain]; - [buttonCell setHighlighted: YES]; - if([buttonCell trackMouse: theEvent - inRect:AddToolPadding(m_mouseDownTool->GetFrameRect()) ofView:m_cocoaNSView - untilMouseUp:NO]) - { - CocoaToolClickEnded(); - m_mouseDownTool = NULL; - wxLogTrace(wxTRACE_COCOA,wxT("Button was clicked after drag!")); - } - [buttonCell setHighlighted: NO]; - [buttonCell release]; - } - } - return wxToolBarBase::Cocoa_mouseDragged(theEvent); -} - -bool wxToolBar::Cocoa_mouseDown(WX_NSEvent theEvent) -{ - wxToolBarTool *tool = CocoaFindToolForPosition([m_cocoaNSView convertPoint:[theEvent locationInWindow] fromView:nil]); - if(tool) - { - NSButtonCell *buttonCell = tool->GetNSButtonCell(); - if(buttonCell) - { - [buttonCell retain]; - m_mouseDownTool = tool; - [buttonCell setHighlighted: YES]; - if([buttonCell trackMouse: theEvent - inRect:AddToolPadding(tool->GetFrameRect()) ofView:m_cocoaNSView - untilMouseUp:NO]) - { - CocoaToolClickEnded(); - m_mouseDownTool = NULL; - wxLogTrace(wxTRACE_COCOA,wxT("Button was clicked!")); - } - [buttonCell setHighlighted: NO]; - [buttonCell release]; - } - } - return wxToolBarBase::Cocoa_mouseDown(theEvent); -} - -bool wxToolBar::Realize() -{ - wxAutoNSAutoreleasePool pool; - - wxToolBarToolsList::compatibility_iterator node; - NSSize totalSize = NSZeroSize; - // This is for horizontal, TODO: vertical - for(node = m_tools.GetFirst(); node; node = node->GetNext()) - { - wxToolBarTool *tool = static_cast(node->GetData()); - if(tool->IsControl()) - { - totalSize.width = ceil(totalSize.width); - wxControl *control = tool->GetControl(); - wxSize controlSize = control->GetSize(); - control->SetPosition(wxPoint((wxCoord)totalSize.width,0)); - totalSize.width += controlSize.x; - if(controlSize.y > totalSize.height) - totalSize.height = controlSize.y; - } - else if(tool->IsSeparator()) - { - totalSize.width += 2.0; - } - else - { - NSButtonCell *buttonCell = tool->GetNSButtonCell(); - NSSize toolSize = [buttonCell cellSize]; - tool->SetFrameRect(NSMakeRect(totalSize.width+toolPadding.width,toolPadding.height,toolSize.width,toolSize.height)); - toolSize.width += 2.0*toolPadding.width; - toolSize.height += 2.0*toolPadding.height; - totalSize.width += toolSize.width; - if(toolSize.height > totalSize.height) - totalSize.height = toolSize.height; - } - } - m_bestSize = wxSize((wxCoord)ceil(totalSize.width),(wxCoord)ceil(totalSize.height)); - if(m_owningFrame) - m_owningFrame->UpdateFrameNSView(); - return true; -} - -wxSize wxToolBar::DoGetBestSize() const -{ - return m_bestSize; -} - -// ---------------------------------------------------------------------------- -// wxToolBar tools state -// ---------------------------------------------------------------------------- - -void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) -{ -} - -void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle ) -{ -} - -void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), - bool WXUNUSED(toggle)) -{ -} - -// ---------------------------------------------------------------------------- -// wxToolBar geometry -// ---------------------------------------------------------------------------- - -wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const -{ - return NULL; -} - -wxToolBarTool *wxToolBar::CocoaFindToolForPosition(const NSPoint& pos) const -{ - wxToolBarToolsList::compatibility_iterator node; - for(node = m_tools.GetFirst(); node; node = node->GetNext()) - { - wxToolBarTool *tool = static_cast(node->GetData()); - if(tool->IsControl()) - { - // TODO - } - else if(tool->IsSeparator()) - { // Do nothing - } - else - { - if([m_cocoaNSView mouse:pos inRect:AddToolPadding(tool->GetFrameRect())]) - return tool; - } - } - return NULL; -} - -void wxToolBar::SetMargins( int x, int y ) -{ -} - -void wxToolBar::SetToolSeparation( int separation ) -{ - m_toolSeparation = separation; -} - -void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) -{ -} - -// ---------------------------------------------------------------------------- -// wxToolBar idle handling -// ---------------------------------------------------------------------------- - -void wxToolBar::OnInternalIdle() -{ -} - -#endif // wxUSE_TOOLBAR_NATIVE diff --git a/src/cocoa/tooltip.mm b/src/cocoa/tooltip.mm deleted file mode 100644 index 8f00a07390..0000000000 --- a/src/cocoa/tooltip.mm +++ /dev/null @@ -1,146 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/tooltip.mm -// Purpose: Cocoa tooltips -// Author: Ryan Norton -// Modified by: -// Created: 2004-10-03 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -// =========================================================================== -// declarations -// =========================================================================== - -// --------------------------------------------------------------------------- -// headers -// --------------------------------------------------------------------------- - -#if wxUSE_TOOLTIPS - -#ifndef WX_PRECOMP - #include "wx/window.h" -#endif - -#include "wx/tooltip.h" - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" - -#import - -// -// Private object in AppKit - exists in 10.2 at least - -// most likely exists earlier too -// -@interface NSToolTipManager : NSObject -{ -/* - NSWindow *toolTipWindow; - NSMutableArray *toolTips; - double toolTipDelay; - NSDate *timeToolTipRemovedFromScreen; - struct __CFRunLoopTimer *toolTipDisplayTimer; - NSToolTip *currentDisplayedToolTip; - NSToolTip *currentFadingToolTip; - float currentFadeValue; - NSTimer *fadeTimer; - NSWindow *lastToolTipWindow; -*/ -} - -+ (id)sharedToolTipManager; -- (int)_addTrackingRect:(struct _NSRect)fp12 andStartToolTipIfNecessary:(BOOL)fp28 view:(id)fp32 owner:(id)fp32 toolTip:(id)fp36; -- (void)_checkToolTipDelay; -- (void)_removeToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16; -- (void)_removeTrackingRectForToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16; -- (int)_setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20 rect:(struct _NSRect)fp20 owner:(id)fp36 ownerIsDisplayDelegate:(BOOL)fp43 userData:(void *)fp44; -- (void)_stopTimerIfRunningForToolTip:(id)fp12; -- (void)abortToolTip; -- (void)addTrackingRectForToolTip:(id)fp12; -- (void)dealloc; -- (void)displayToolTip:(id)fp12; -- (void)fadeToolTip:(id)fp12; -- (id)init; -- (void)mouseEntered:(id)fp12; -- (void)mouseEnteredToolTip:(id)fp12 inWindow:(id)fp16 withEvent:(id)fp20; -- (void)mouseExited:(id)fp12; -- (void)orderOutToolTip; -- (void)orderOutToolTipImmediately:(BOOL)fp12; -- (void)recomputeToolTipsForView:(id)fp12 remove:(BOOL)fp16 add:(BOOL)fp20; -- (void)removeAllToolTipsForView:(id)fp12; -- (void)removeToolTipForView:(id)fp12 tag:(int)fp16; -- (void)setInitialToolTipDelay:(double)fp40; -- (void)setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20; -- (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 displayDelegate:(id)fp32 userData:(void *)fp32; -- (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 owner:(id)fp32 userData:(void *)fp32; -- (void)setToolTipWithOwner:(id)fp12 forView:(id)fp16 cell:(id)fp20; -- (void)startTimer:(float)fp40 userInfo:(id)fp16; -- (void)stopTimer; -- (id)toolTipForView:(id)fp12 cell:(id)fp16; -- (BOOL)viewHasToolTips:(id)fp12; - -@end - -//----------------------------------------------------------------------------- -// wxToolTip -//----------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject) - -wxToolTip::wxToolTip(const wxString &tip) : - m_text(tip), m_window(0) -{ -} - -wxToolTip::~wxToolTip() -{ -} - -void wxToolTip::SetTip(const wxString& tip) -{ - m_text = tip; -} - -const wxString& wxToolTip::GetTip() const -{ - return m_text; -} - -// the window we're associated with -wxWindow *wxToolTip::GetWindow() const -{ - return m_window; -} - -// enable or disable the tooltips globally -//static - void wxToolTip::Enable(bool flag) -{ - //TODO - wxFAIL_MSG(wxT("Not implemented")); -} - -// set the delay after which the tooltip appears -//static - void wxToolTip::SetDelay(long milliseconds) -{ - [[NSToolTipManager sharedToolTipManager] setInitialToolTipDelay: ((double)milliseconds) / 1000.0]; -} - -void wxToolTip::SetWindow(wxWindow* window) -{ - wxAutoNSAutoreleasePool pool; - - m_window = window; - - //set the tooltip - empty string means remove - if (m_text.empty()) - [m_window->GetNSView() setToolTip:nil]; - else - [m_window->GetNSView() setToolTip:wxNSStringWithWxString(m_text)]; -} - -#endif //wxUSE_TOOLTIPS diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm deleted file mode 100644 index 17ca72dde4..0000000000 --- a/src/cocoa/toplevel.mm +++ /dev/null @@ -1,443 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/toplevel.mm -// Purpose: implements wxTopLevelWindow for Cocoa -// Author: David Elliott -// Modified by: -// Created: 2002/11/27 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#include "wx/toplevel.h" - -#ifndef WX_PRECOMP - #include "wx/window.h" - #include "wx/menuitem.h" - #include "wx/frame.h" - #include "wx/log.h" - #include "wx/app.h" -#endif //WX_PRECOMP - -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/ObjcRef.h" - -#include "wx/cocoa/objc/NSView.h" -#include "wx/cocoa/objc/NSWindow.h" -#import -#import -#import - -// ---------------------------------------------------------------------------- -// globals -// ---------------------------------------------------------------------------- - -// list of all frames and modeless dialogs -wxWindowList wxModelessWindows; - -// ============================================================================ -// wxTopLevelWindowCocoa implementation -// ============================================================================ - -wxTopLevelWindowCocoa *wxTopLevelWindowCocoa::sm_cocoaDeactivateWindow = NULL; - -// ---------------------------------------------------------------------------- -// wxTopLevelWindowCocoa creation -// ---------------------------------------------------------------------------- -BEGIN_EVENT_TABLE(wxTopLevelWindowCocoa,wxTopLevelWindowBase) - EVT_CLOSE(wxTopLevelWindowCocoa::OnCloseWindow) -END_EVENT_TABLE() - -void wxTopLevelWindowCocoa::Init() -{ - m_iconized = - m_maximizeOnShow = - m_closed = false; -} - -unsigned int wxTopLevelWindowCocoa::NSWindowStyleForWxStyle(long style) -{ - unsigned int styleMask = 0; - if(style & wxCAPTION) - styleMask |= NSTitledWindowMask; - if(style & wxMINIMIZE_BOX) - styleMask |= NSMiniaturizableWindowMask; - #if 0 - if(style & wxMAXIMIZE_BOX) - styleMask |= NSWindowMask; - #endif - if(style & wxCLOSE_BOX) - styleMask |= NSClosableWindowMask; - if(style & wxRESIZE_BORDER) - styleMask |= NSResizableWindowMask; - if(style & wxSIMPLE_BORDER) - styleMask |= NSBorderlessWindowMask; - return styleMask; -} - -NSRect wxTopLevelWindowCocoa::MakeInitialNSWindowContentRect(const wxPoint& pos, const wxSize& size, unsigned int cocoaStyleMask) -{ - // Arbitrarily use (100,100) as the origin when default coords are given. - wxCoord x = pos.x!=wxDefaultCoord ? pos.x : 100; - wxCoord y = pos.y!=wxDefaultCoord ? pos.y : 100; - - wxCoord w = WidthDefault(size.x); - wxCoord h = HeightDefault(size.y); - - NSPoint cocoaOrigin = OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(x,y,w,h,true); - - return [NSWindow - contentRectForFrameRect:NSMakeRect(cocoaOrigin.x,cocoaOrigin.y,w,h) - styleMask:cocoaStyleMask]; - -} - -bool wxTopLevelWindowCocoa::Create(wxWindow *parent, - wxWindowID winid, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - wxAutoNSAutoreleasePool pool; - wxTopLevelWindows.Append(this); - - if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - - if ( parent ) - parent->AddChild(this); - - unsigned int cocoaStyle = NSWindowStyleForWxStyle(style); - if(style & wxFRAME_TOOL_WINDOW) - cocoaStyle |= NSUtilityWindowMask; - - NSRect cocoaRect = MakeInitialNSWindowContentRect(pos,size,cocoaStyle); - - m_cocoaNSWindow = NULL; - m_cocoaNSView = NULL; - // NOTE: We may need to deal with the contentView becoming a wx NSView as well. - NSWindow *newWindow; - // Create a WXNSPanel or a WXNSWindow depending on what type of window is desired. - if(style & wxFRAME_TOOL_WINDOW) - newWindow = [[WX_GET_OBJC_CLASS(WXNSPanel) alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; - else - newWindow = [[WX_GET_OBJC_CLASS(WXNSWindow) alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; - // Make sure the default content view is a WXNSView - [newWindow setContentView: [[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: [[newWindow contentView] frame]]]; - // Associate the window and view - SetNSWindow(newWindow); - - // NOTE: SetNSWindow has retained the Cocoa object for this object. - // Because we do not release on close, the following release matches the - // above alloc and thus the retain count will be 1. - [m_cocoaNSWindow release]; - - if(style & wxFRAME_NO_TASKBAR) - [m_cocoaNSWindow setExcludedFromWindowsMenu: YES]; - if(style & wxSTAY_ON_TOP) - [m_cocoaNSWindow setLevel:NSFloatingWindowLevel]; - [m_cocoaNSWindow setTitle:wxNSStringWithWxString(title)]; - return true; -} - -wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa() -{ - wxASSERT(sm_cocoaDeactivateWindow!=this); - wxAutoNSAutoreleasePool pool; - DestroyChildren(); - if(m_cocoaNSView) - SendDestroyEvent(); - SetNSWindow(NULL); -} - -bool wxTopLevelWindowCocoa::Destroy() -{ - if(sm_cocoaDeactivateWindow==this) - { - sm_cocoaDeactivateWindow = NULL; - wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey(); - } - return wxTopLevelWindowBase::Destroy(); -} - -// ---------------------------------------------------------------------------- -// wxTopLevelWindowCocoa Cocoa Specifics -// ---------------------------------------------------------------------------- - -wxMenuBar* wxTopLevelWindowCocoa::GetAppMenuBar(wxCocoaNSWindow *win) -{ - wxTopLevelWindowCocoa *parent = wxDynamicCast(GetParent(),wxTopLevelWindow); - if(parent) - return parent->GetAppMenuBar(win); - return NULL; -} - -void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow) -{ - bool need_debug = cocoaNSWindow || m_cocoaNSWindow; - if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxTopLevelWindowCocoa=%p::SetNSWindow [m_cocoaNSWindow=%p retainCount]=%d"),this,m_cocoaNSWindow,[m_cocoaNSWindow retainCount]); - DisassociateNSWindow(m_cocoaNSWindow); - wxGCSafeRetain(cocoaNSWindow); - wxGCSafeRelease(m_cocoaNSWindow); - m_cocoaNSWindow = cocoaNSWindow; - // NOTE: We are no longer using posing so we won't get events on the - // window's view unless it was explicitly created as the wx view class. - if(m_cocoaNSWindow) - SetNSView([m_cocoaNSWindow contentView]); - else - SetNSView(NULL); - AssociateNSWindow(m_cocoaNSWindow); - if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxTopLevelWindowCocoa=%p::SetNSWindow [cocoaNSWindow=%p retainCount]=%d"),this,cocoaNSWindow,[cocoaNSWindow retainCount]); -} - -void wxTopLevelWindowCocoa::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) -{ - if([m_cocoaNSWindow contentView] == (id)oldView) - [m_cocoaNSWindow setContentView:newView]; -} - -/*static*/ void wxTopLevelWindowCocoa::DeactivatePendingWindow() -{ - if(sm_cocoaDeactivateWindow) - sm_cocoaDeactivateWindow->wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey(); - sm_cocoaDeactivateWindow = NULL; -} - -void wxTopLevelWindowCocoa::CocoaDelegate_windowDidBecomeKey(void) -{ - DeactivatePendingWindow(); - wxLogTrace(wxTRACE_COCOA,wxT("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidBecomeKey"),this); - wxActivateEvent event(wxEVT_ACTIVATE, true, GetId()); - event.SetEventObject(this); - HandleWindowEvent(event); -} - -void wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidResignKey"),this); - wxActivateEvent event(wxEVT_ACTIVATE, false, GetId()); - event.SetEventObject(this); - HandleWindowEvent(event); -} - -void wxTopLevelWindowCocoa::CocoaDelegate_windowDidBecomeMain(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidBecomeMain"),this); -} - -void wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignMain(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidResignMain"),this); -} - -void wxTopLevelWindowCocoa::CocoaDelegate_windowWillClose(void) -{ - m_closed = true; - Destroy(); -} - -bool wxTopLevelWindowCocoa::CocoaDelegate_windowShouldClose() -{ - return wxWindowBase::Close(false); -} - -void wxTopLevelWindowCocoa::CocoaDelegate_wxMenuItemAction(WX_NSMenuItem menuItem) -{ -} - -bool wxTopLevelWindowCocoa::CocoaDelegate_validateMenuItem(WX_NSMenuItem menuItem) -{ - return false; -} - -// ---------------------------------------------------------------------------- -// wxTopLevelWindowCocoa maximize/minimize -// ---------------------------------------------------------------------------- - -void wxTopLevelWindowCocoa::Maximize(bool maximize) -{ -} - -bool wxTopLevelWindowCocoa::IsMaximized() const -{ - return false ; -} - -void wxTopLevelWindowCocoa::Iconize(bool iconize) -{ -} - -bool wxTopLevelWindowCocoa::IsIconized() const -{ - return false; -} - -void wxTopLevelWindowCocoa::Restore() -{ -} - -bool wxTopLevelWindowCocoa::Show(bool show) -{ - if(m_isShown == show) - return false; - wxAutoNSAutoreleasePool pool; - if(show) - { - // Send the window a size event because wxWidgets apps expect it - // NOTE: This should really only be done the first time a window - // is shown. I doubt this will cause any problems though. - wxSizeEvent event(GetSize(), GetId()); - event.SetEventObject(this); - HandleWindowEvent(event); - - [m_cocoaNSWindow makeKeyAndOrderFront:m_cocoaNSWindow]; - } - else - [m_cocoaNSWindow orderOut:m_cocoaNSWindow]; - m_isShown = show; - return true; -} - -bool wxTopLevelWindowCocoa::Close(bool force) -{ - if(force) - return wxWindowBase::Close(force); - // performClose will fake the user clicking the close button which - // will invoke windowShouldClose which will call the base class version - // of Close() which will NOT Destroy() the window (see below) but - // if closing is not stopped, then performClose will go ahead and - // close the window which will send the close notifications setting - // m_closed to true and Destroy()ing the window. - [m_cocoaNSWindow performClose:m_cocoaNSWindow]; - return m_closed; -} - -void wxTopLevelWindowCocoa::OnCloseWindow(wxCloseEvent& event) -{ - // If the event was forced, close the window which will Destroy() it - if(!event.CanVeto()) - [m_cocoaNSWindow close]; - // if the event was not forced, it's probably because the user clicked - // the close button, or Close(false) was called which (see above) is - // redirected to performClose and thus Cocoa itself will close the window -} - -// ---------------------------------------------------------------------------- -// wxTopLevelWindowCocoa misc -// ---------------------------------------------------------------------------- - -void wxTopLevelWindowCocoa::SetTitle(const wxString& title) -{ - [m_cocoaNSWindow setTitle:wxNSStringWithWxString(title)]; -} - -wxString wxTopLevelWindowCocoa::GetTitle() const -{ - return wxStringWithNSString([m_cocoaNSWindow title]); -} - -wxWindow* wxTopLevelWindowCocoa::SetDefaultItem(wxWindow *win) -{ - wxWindow *old = wxTopLevelWindowBase::SetDefaultItem(win); - - NSCell *newCell; - if(win != NULL) - { - NSView *newView = win->GetNSView(); - // newView does not have to be an NSControl, we only cast to NSControl* - // to silence the warning about cell not being implemented. - if(newView != nil && [newView respondsToSelector:@selector(cell)]) - newCell = [(NSControl*)newView cell]; - else - newCell = nil; - - if(newCell != nil && ![newCell isKindOfClass:[NSButtonCell class]]) - { // It's not an NSButtonCell, set the default to nil. - newCell = nil; - } - } - else - newCell = nil; - - [GetNSWindow() setDefaultButtonCell:(NSButtonCell*)newCell]; - return old; -} - -bool wxTopLevelWindowCocoa::ShowFullScreen(bool show, long style) -{ - return false; -} - -bool wxTopLevelWindowCocoa::IsFullScreen() const -{ - return false; -} - -void wxTopLevelWindowCocoa::CocoaSetWxWindowSize(int width, int height) -{ - // Set the NSView size by setting the frame size to enclose it - unsigned int styleMask = [m_cocoaNSWindow styleMask]; - NSRect oldFrameRect = [m_cocoaNSWindow frame]; - NSRect contentRect = [NSWindow - contentRectForFrameRect: oldFrameRect - styleMask: styleMask]; - contentRect.size.width = width; - contentRect.size.height = height; - NSRect newFrameRect = [NSWindow - frameRectForContentRect: contentRect - styleMask: styleMask]; - - // Cocoa uses +y is up but wxWidgets uses +y is down. We want an increase/decrease in height - // to not effect where the top of the window is placed so we set the new y origin relative the - // old one taking the height change into account. - newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height; - - [m_cocoaNSWindow setFrame: newFrameRect display: NO]; -} - -void wxTopLevelWindowCocoa::DoMoveWindow(int x, int y, int width, int height) -{ - wxLogTrace(wxTRACE_COCOA_TopLevelWindow_Size,wxT("wxTopLevelWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height); - - NSPoint cocoaOrigin = OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(x,y,width,height,false); - - NSRect cocoaRect = NSMakeRect(cocoaOrigin.x,cocoaOrigin.y,width,height); - [m_cocoaNSWindow setFrame: cocoaRect display:NO]; -} - -void wxTopLevelWindowCocoa::DoGetSize(int *w, int *h) const -{ - NSRect cocoaRect = [m_cocoaNSWindow frame]; - if(w) - *w=(int)cocoaRect.size.width; - if(h) - *h=(int)cocoaRect.size.height; - wxLogTrace(wxTRACE_COCOA_TopLevelWindow_Size,wxT("wxTopLevelWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height); -} - -void wxTopLevelWindowCocoa::DoGetPosition(int *x, int *y) const -{ - NSRect windowFrame = [m_cocoaNSWindow frame]; - - wxPoint theWxOrigin = OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(windowFrame); - - if(*x) - *x = theWxOrigin.x; - if(*y) - *y = theWxOrigin.y; - - wxLogTrace(wxTRACE_COCOA_TopLevelWindow_Size,wxT("wxTopLevelWindow=%p::DoGetPosition = (%d,%d)"),this,(int)theWxOrigin.x,(int)theWxOrigin.y); -} diff --git a/src/cocoa/utils.mm b/src/cocoa/utils.mm deleted file mode 100644 index 1388b29c1e..0000000000 --- a/src/cocoa/utils.mm +++ /dev/null @@ -1,135 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/utils.mm -// Purpose: Various utilities -// Author: David Elliott -// Created: 2003/??/?? -// Copyright: (c) wxWidgets dev team -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#include "wx/utils.h" - -#ifndef WX_PRECOMP - #include "wx/app.h" -#endif // WX_PRECOMP - -#include "wx/apptrait.h" -#include "wx/display.h" -#include "wx/evtloop.h" -#include "wx/cocoa/private/timer.h" - -#include - -#include -#include -#include -#include - -#include "wx/cocoa/string.h" - -#import -#import - -void wxDisplaySize(int *width, int *height) -{ - // TODO - if(width) - *width = 1024; - if(height) - *height = 768; -} - -void wxDisplaySizeMM(int*,int*) -{ - // TODO -} - -void wxClientDisplayRect(int *x,int *y,int *width,int *height) -{ - // TODO - if(x) - *x = 0; - if(y) - *y = 0; - if(width) - *width=1024; - if(height) - *height=768; -} - -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_COCOA; -} - -wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer* timer) -{ - return new wxCocoaTimerImpl(timer); -} - -wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() -{ - return new wxGUIEventLoop; -} - -wxWindow* wxFindWindowAtPoint(const wxPoint& pt) -{ - return wxGenericFindWindowAtPoint(pt); -} - -// Return true if we have a colour display -bool wxColourDisplay() -{ - // TODO - return true; -} - -void wxGetMousePosition( int* x, int* y ) -{ - // TODO -}; - -// Returns depth of screen -int wxDisplayDepth() -{ - // TODO - return 0; -} - -// Emit a beeeeeep -void wxBell() -{ - // TODO -} - -// Private helper method for wxLaunchDefaultBrowser -bool wxDoLaunchDefaultBrowser(const wxString& url, int flags) -{ - // NOTE: We ignore the flags - return [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:wxNSStringWithWxString(url)]] != NO; -} - -#if 0 -// DFE: These aren't even implemented by wxGTK, and no wxWidgets code calls -// them. If someone needs them, then they'll get a link error - -// Consume all events until no more left -void wxFlushEvents() -{ -} - -// Check whether this window wants to process messages, e.g. Stop button -// in long calculations. -bool wxCheckForInterrupt(wxWindow *wnd) -{ - // TODO - return false; -} - -#endif - diff --git a/src/cocoa/utilsexc.mm b/src/cocoa/utilsexc.mm deleted file mode 100644 index 88d479486c..0000000000 --- a/src/cocoa/utilsexc.mm +++ /dev/null @@ -1,196 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/utilsexec.mm -// Purpose: Execution-related utilities for wxCocoa -// Author: Ryan Norton -// Modified by: -// Created: 2004-10-05 -// Copyright: (c) Ryan Norton -// Licence: wxWindows licence -// Notes: This code may be useful on platforms other than Darwin. -// On Darwin we share the CoreFoundation code with wxMac. -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#ifndef WX_PRECOMP - #include "wx/utils.h" -#endif - -#if 0 - -#ifndef WX_PRECOMP - #if wxUSE_STREAMS - #include "wx/stream.h" - #endif // wxUSE_STREAMS -#endif //WX_PRECOMP - -#include "wx/process.h" - -#include "wx/cocoa/string.h" - -#include "wx/cocoa/objc/objc_uniquifying.h" - -#import -#import - -// -// RN: This is a prelimenary implementation - simple -// launching and process redirection works, -// but with the piping tests in the exec sample -// SIGPIPE is triggered... -// - -class wxPipeInputStream : public wxInputStream -{ -public: - wxPipeInputStream(NSPipe* thePipe) : - m_thePipe(thePipe), - m_theHandle([m_thePipe fileHandleForReading]) - { - } - - ~wxPipeInputStream() - { - [m_thePipe release]; - } - -protected: - virtual size_t OnSysRead(void *buffer, size_t size) - { - NSData* theData = [m_theHandle readDataOfLength:size]; - memcpy(buffer, [theData bytes], [theData length]); - return [theData length]; - } - - - NSPipe* m_thePipe; - NSFileHandle* m_theHandle; -}; - -class wxPipeOutputStream : public wxOutputStream -{ -public: - wxPipeOutputStream(NSPipe* thePipe) : - m_thePipe(thePipe), - m_theHandle([m_thePipe fileHandleForWriting]) - { - } - - ~wxPipeOutputStream() - { - [m_thePipe release]; - } - -protected: - - virtual size_t OnSysWrite(const void *buffer, size_t bufsize) - { - NSData* theData = [NSData dataWithBytesNoCopy:(void*)buffer - length:bufsize]; - [m_theHandle writeData:theData]; - return bufsize; - } - - NSPipe* m_thePipe; - NSFileHandle* m_theHandle; -}; - -@interface wxTaskHandler : NSObject -{ - long m_pid; - void* m_handle; -} --(id)init:(void*)handle processIdentifier:(long)pid; -- (void)termHandler:(NSNotification *)aNotification; -@end -WX_DECLARE_GET_OBJC_CLASS(wxTaskHandler,NSObject) - -@implementation wxTaskHandler : NSObject - --(id)init:(void*)handle processIdentifier:(long)pid -{ - self = [super init]; - - m_handle = handle; - m_pid = pid; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(termHandler:) - name:NSTaskDidTerminateNotification - object:nil]; - return self; -} - -- (void)termHandler:(NSNotification *)aNotification -{ - NSTask* theTask = [aNotification object]; - - if ([theTask processIdentifier] == m_pid) - { - ((wxProcess*)m_handle)->OnTerminate([theTask processIdentifier], - [theTask terminationStatus]); - - [self release]; - } -} - -@end -WX_IMPLEMENT_GET_OBJC_CLASS(wxTaskHandler,NSObject) - -long wxExecute(const wxString& command, - int sync, - wxProcess *handle, - const wxExecuteEnv *env) -{ - NSTask* theTask = [[NSTask alloc] init]; - - if (handle && handle->IsRedirected()) - { - NSPipe* theStdinPipe = [[NSPipe alloc] init]; - NSPipe* theStderrPipe = [[NSPipe alloc] init]; - NSPipe* theStdoutPipe = [[NSPipe alloc] init]; - - [theTask setStandardInput:theStdinPipe]; - [theTask setStandardError:theStderrPipe]; - [theTask setStandardOutput:theStdoutPipe]; - - handle->SetPipeStreams(new wxPipeInputStream(theStdoutPipe), - new wxPipeOutputStream(theStdinPipe), - new wxPipeInputStream(theStderrPipe) ); - } - - NSArray* theQuoteArguments = - [wxNSStringWithWxString(command) componentsSeparatedByString:@"\""]; - - NSMutableArray* theSeparatedArguments = - [NSMutableArray arrayWithCapacity:10]; - - for (unsigned i = 0; i < [theQuoteArguments count]; ++i) - { - [theSeparatedArguments addObjectsFromArray: - [[theQuoteArguments objectAtIndex:i] componentsSeparatedByString:@" "] - ]; - - if(++i < [theQuoteArguments count]) - [theSeparatedArguments addObject:[theQuoteArguments objectAtIndex:i]]; - } - - [theTask setLaunchPath:[theSeparatedArguments objectAtIndex:0]]; - [theTask setArguments:theSeparatedArguments]; - [theTask launch]; - - if(sync & wxEXEC_ASYNC) - { - [[WX_GET_OBJC_CLASS(wxTaskHandler) alloc]init:handle - processIdentifier:[theTask processIdentifier]]; - - return 0; - } - else - { - [theTask waitUntilExit]; - - return [theTask terminationStatus]; - } -} -#endif //0 diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm deleted file mode 100644 index 9463e33ee6..0000000000 --- a/src/cocoa/window.mm +++ /dev/null @@ -1,2218 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: src/cocoa/window.mm -// Purpose: wxWindowCocoa -// Author: David Elliott -// Modified by: -// Created: 2002/12/26 -// Copyright: (c) 2002 David Elliott -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#include "wx/wxprec.h" - -#ifndef WX_PRECOMP - #include "wx/log.h" - #include "wx/window.h" - #include "wx/dc.h" - #include "wx/dcclient.h" - #include "wx/utils.h" -#endif //WX_PRECOMP - -#include "wx/tooltip.h" - -#include "wx/cocoa/dc.h" -#include "wx/cocoa/autorelease.h" -#include "wx/cocoa/string.h" -#include "wx/cocoa/trackingrectmanager.h" -#include "wx/cocoa/private/scrollview.h" -#include "wx/osx/core/cfref.h" -#include "wx/cocoa/ObjcRef.h" - -#import -#import -#include "wx/cocoa/objc/NSView.h" -#import -#import -#import -#import -#import -#import -#import -#import -#import - -// Turn this on to paint green over the dummy views for debugging -#undef WXCOCOA_FILL_DUMMY_VIEW - -#ifdef WXCOCOA_FILL_DUMMY_VIEW -#import -#endif //def WXCOCOA_FILL_DUMMY_VIEW - -// STL list used by wxCocoaMouseMovedEventSynthesizer -#include - -/* NSComparisonResult is typedef'd as an enum pre-Leopard but typedef'd as - * NSInteger post-Leopard. Pre-Leopard the Cocoa toolkit expects a function - * returning int and not NSComparisonResult. Post-Leopard the Cocoa toolkit - * expects a function returning the new non-enum NSComparsionResult. - * Hence we create a typedef named CocoaWindowCompareFunctionResult. - */ -#if defined(NSINTEGER_DEFINED) -typedef NSComparisonResult CocoaWindowCompareFunctionResult; -#else -typedef int CocoaWindowCompareFunctionResult; -#endif - -// A category for methods that are only present in Panther's SDK -@interface NSView(wxNSViewPrePantherCompatibility) -- (void)getRectsBeingDrawn:(const NSRect **)rects count:(int *)count; -@end - -// ======================================================================== -// Helper functions for converting to/from wxWidgets coordinates and a -// specified NSView's coordinate system. -// ======================================================================== -NSPoint CocoaTransformNSViewBoundsToWx(NSView *nsview, NSPoint pointBounds) -{ - wxCHECK_MSG(nsview, pointBounds, wxT("Need to have a Cocoa view to do translation")); - if([nsview isFlipped]) - return pointBounds; - NSRect ourBounds = [nsview bounds]; - return NSMakePoint - ( pointBounds.x - , ourBounds.size.height - pointBounds.y - ); -} - -NSRect CocoaTransformNSViewBoundsToWx(NSView *nsview, NSRect rectBounds) -{ - wxCHECK_MSG(nsview, rectBounds, wxT("Need to have a Cocoa view to do translation")); - if([nsview isFlipped]) - return rectBounds; - NSRect ourBounds = [nsview bounds]; - return NSMakeRect - ( rectBounds.origin.x - , ourBounds.size.height - (rectBounds.origin.y + rectBounds.size.height) - , rectBounds.size.width - , rectBounds.size.height - ); -} - -NSPoint CocoaTransformNSViewWxToBounds(NSView *nsview, NSPoint pointWx) -{ - wxCHECK_MSG(nsview, pointWx, wxT("Need to have a Cocoa view to do translation")); - if([nsview isFlipped]) - return pointWx; - NSRect ourBounds = [nsview bounds]; - return NSMakePoint - ( pointWx.x - , ourBounds.size.height - pointWx.y - ); -} - -NSRect CocoaTransformNSViewWxToBounds(NSView *nsview, NSRect rectWx) -{ - wxCHECK_MSG(nsview, rectWx, wxT("Need to have a Cocoa view to do translation")); - if([nsview isFlipped]) - return rectWx; - NSRect ourBounds = [nsview bounds]; - return NSMakeRect - ( rectWx.origin.x - , ourBounds.size.height - (rectWx.origin.y + rectWx.size.height) - , rectWx.size.width - , rectWx.size.height - ); -} - -// ============================================================================ -// Screen coordinate helpers -// ============================================================================ - -/* -General observation about Cocoa screen coordinates: -It is documented that the first object of the [NSScreen screens] array is the screen with the menubar. - -It is not documented (but true as far as I can tell) that (0,0) in Cocoa screen coordinates is always -the BOTTOM-right corner of this screen. Recall that Cocoa uses cartesian coordinates so y-increase is up. - -It isn't clearly documented but visibleFrame returns a rectangle in screen coordinates, not a rectangle -relative to that screen's frame. The only real way to test this is to configure two screens one atop -the other such that the menubar screen is on top. The Dock at the bottom of the screen will then -eat into the visibleFrame of screen 1 by incrementing it's y-origin. Thus if you arrange two -1920x1200 screens top/bottom then screen 1 (the bottom screen) will have frame origin (0,-1200) and -visibleFrame origin (0,-1149) which is exactly 51 pixels higher than the full frame origin. - -In wxCocoa, we somewhat arbitrarily declare that wx (0,0) is the TOP-left of screen 0's frame (the entire screen). -However, this isn't entirely arbitrary because the Quartz Display Services (CGDisplay) uses this same scheme. -This works out nicely because wxCocoa's wxDisplay is implemented using Quartz Display Services instead of NSScreen. -*/ - -namespace { // file namespace - -class wxCocoaPrivateScreenCoordinateTransformer -{ - wxDECLARE_NO_COPY_CLASS(wxCocoaPrivateScreenCoordinateTransformer); -public: - wxCocoaPrivateScreenCoordinateTransformer(); - ~wxCocoaPrivateScreenCoordinateTransformer(); - wxPoint OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(NSRect windowFrame); - NSPoint OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(wxCoord x, wxCoord y, wxCoord width, wxCoord height, bool keepOriginVisible); - -protected: - NSScreen *m_screenZero; - NSRect m_screenZeroFrame; -}; - -// NOTE: This is intended to be a short-lived object. A future enhancment might -// make it a global and reconfigure it upon some notification that the screen layout -// has changed. -inline wxCocoaPrivateScreenCoordinateTransformer::wxCocoaPrivateScreenCoordinateTransformer() -{ - NSArray *screens = [NSScreen screens]; - - [screens retain]; - - m_screenZero = nil; - if(screens != nil && [screens count] > 0) - m_screenZero = [[screens objectAtIndex:0] retain]; - - [screens release]; - - if(m_screenZero != nil) - m_screenZeroFrame = [m_screenZero frame]; - else - { - wxLogWarning(wxT("Can't translate to/from wx screen coordinates and Cocoa screen coordinates")); - // Just blindly assume 1024x768 so that at least we can sort of flip things around into - // Cocoa coordinates. - // NOTE: Theoretically this case should never happen anyway. - m_screenZeroFrame = NSMakeRect(0,0,1024,768); - } -} - -inline wxCocoaPrivateScreenCoordinateTransformer::~wxCocoaPrivateScreenCoordinateTransformer() -{ - [m_screenZero release]; - m_screenZero = nil; -} - -inline wxPoint wxCocoaPrivateScreenCoordinateTransformer::OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(NSRect windowFrame) -{ - // x and y are in wx screen coordinates which we're going to arbitrarily define such that - // (0,0) is the TOP-left of screen 0 (the one with the menubar) - // NOTE WELL: This means that (0,0) is _NOT_ an appropriate position for a window. - - wxPoint theWxOrigin; - - // Working in Cocoa's screen coordinates we must realize that the x coordinate we want is - // the distance between the left side (origin.x) of the window's frame and the left side of - // screen zero's frame. - theWxOrigin.x = windowFrame.origin.x - m_screenZeroFrame.origin.x; - - // Working in Cocoa's screen coordinates we must realize that the y coordinate we want is - // actually the distance between the top-left of the screen zero frame and the top-left - // of the window's frame. - - theWxOrigin.y = (m_screenZeroFrame.origin.y + m_screenZeroFrame.size.height) - (windowFrame.origin.y + windowFrame.size.height); - - return theWxOrigin; -} - -inline NSPoint wxCocoaPrivateScreenCoordinateTransformer::OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(wxCoord x, wxCoord y, wxCoord width, wxCoord height, bool keepOriginVisible) -{ - NSPoint theCocoaOrigin; - - // The position is in wx screen coordinates which we're going to arbitrarily define such that - // (0,0) is the TOP-left of screen 0 (the one with the menubar) - - // NOTE: The usable rectangle is smaller and hence we have the keepOriginVisible flag - // which will move the origin downward and/or left as necessary if the origin is - // inside the screen0 rectangle (i.e. x/y >= 0 in wx coordinates) and outside the - // visible frame (i.e. x/y < the top/left of the screen0 visible frame in wx coordinates) - // We don't munge origin coordinates < 0 because it actually is possible that the menubar is on - // the top of the bottom screen and thus that origin is completely valid! - if(keepOriginVisible && (m_screenZero != nil)) - { - // Do al of this in wx coordinates because it's far simpler since we're dealing with top/left points - wxPoint visibleOrigin = OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates([m_screenZero visibleFrame]); - if(x >= 0 && x < visibleOrigin.x) - x = visibleOrigin.x; - if(y >= 0 && y < visibleOrigin.y) - y = visibleOrigin.y; - } - - // The x coordinate is simple as it's just relative to screen zero's frame - theCocoaOrigin.x = m_screenZeroFrame.origin.x + x; - // Working in Cocoa's coordinates think to start at the bottom of screen zero's frame and add - // the height of that rect which gives us the coordinate for the top of the visible rect. Now realize that - // the wx coordinates are flipped so if y is say 10 then we want to be 10 pixels down from that and thus - // we subtract y. But then we still need to take into account the size of the window which is h and subtract - // that to get the bottom-left origin of the rectangle. - theCocoaOrigin.y = m_screenZeroFrame.origin.y + m_screenZeroFrame.size.height - y - height; - - return theCocoaOrigin; -} - -} // namespace - -wxPoint wxWindowCocoa::OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(NSRect windowFrame) -{ - wxCocoaPrivateScreenCoordinateTransformer transformer; - return transformer.OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(windowFrame); -} - -NSPoint wxWindowCocoa::OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(wxCoord x, wxCoord y, wxCoord width, wxCoord height, bool keepOriginVisible) -{ - wxCocoaPrivateScreenCoordinateTransformer transformer; - return transformer.OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(x,y,width,height,keepOriginVisible); -} - -// ======================================================================== -// wxWindowCocoaHider -// ======================================================================== -class wxWindowCocoaHider: protected wxCocoaNSView -{ - wxDECLARE_NO_COPY_CLASS(wxWindowCocoaHider); -public: - wxWindowCocoaHider(wxWindow *owner); - virtual ~wxWindowCocoaHider(); - inline WX_NSView GetNSView() { return m_dummyNSView; } -protected: - wxWindowCocoa *m_owner; - WX_NSView m_dummyNSView; - virtual void Cocoa_FrameChanged(void); - virtual void Cocoa_synthesizeMouseMoved(void) {} -#ifdef WXCOCOA_FILL_DUMMY_VIEW - virtual bool Cocoa_drawRect(const NSRect& rect); -#endif //def WXCOCOA_FILL_DUMMY_VIEW -private: - wxWindowCocoaHider(); -}; - -// ======================================================================== -// wxDummyNSView -// ======================================================================== -@interface wxDummyNSView : NSView -- (NSView *)hitTest:(NSPoint)aPoint; -@end -WX_DECLARE_GET_OBJC_CLASS(wxDummyNSView,NSView) - -@implementation wxDummyNSView : NSView -- (NSView *)hitTest:(NSPoint)aPoint -{ - return nil; -} - -@end -WX_IMPLEMENT_GET_OBJC_CLASS(wxDummyNSView,NSView) - -// ======================================================================== -// wxWindowCocoaHider -// NOTE: This class and method of hiding predates setHidden: support in -// the toolkit. The hack used here is to replace the view with a stand-in -// that will be subject to the usual Cocoa resizing rules. -// When possible (i.e. when running on 10.3 or higher) we make it hidden -// mostly as an optimization so Cocoa doesn't have to consider it when -// drawing or finding key views. -// ======================================================================== -wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner) -: m_owner(owner) -{ - wxASSERT(owner); - wxASSERT(owner->GetNSViewForHiding()); - m_dummyNSView = [[WX_GET_OBJC_CLASS(wxDummyNSView) alloc] - initWithFrame:[owner->GetNSViewForHiding() frame]]; - [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]]; - AssociateNSView(m_dummyNSView); - - if([m_dummyNSView respondsToSelector:@selector(setHidden:)]) - [m_dummyNSView setHidden:YES]; -} - -wxWindowCocoaHider::~wxWindowCocoaHider() -{ - DisassociateNSView(m_dummyNSView); - [m_dummyNSView release]; -} - -void wxWindowCocoaHider::Cocoa_FrameChanged(void) -{ - // Keep the real window in synch with the dummy - wxASSERT(m_dummyNSView); - [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]]; -} - - -#ifdef WXCOCOA_FILL_DUMMY_VIEW -bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect) -{ - NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect]; - [[NSColor greenColor] set]; - [bezpath stroke]; - [bezpath fill]; - return true; -} -#endif //def WXCOCOA_FILL_DUMMY_VIEW - - -/*! @class WXManualScrollView - @abstract An NSScrollView subclass which implements wx scroll behaviour - @discussion - Overrides default behaviour of NSScrollView such that this class receives - the scroller action messages and allows the wxCocoaScrollView to act - on them accordingly. In particular, because the NSScrollView will not - receive action messages from the scroller, it will not adjust the - document view. This must be done manually using the ScrollWindow - method of wxWindow. - */ -@interface WXManualScrollView : NSScrollView -{ - /*! @field m_wxCocoaScrollView - */ - wxWindowCocoaScrollView *m_wxCocoaScrollView; -} - -// Override these to set up the target/action correctly -- (void)setHorizontalScroller:(NSScroller *)aScroller; -- (void)setVerticalScroller:(NSScroller *)aScroller; -- (void)setHasHorizontalScroller:(BOOL)flag; -- (void)setHasVerticalScroller:(BOOL)flag; - -// NOTE: _wx_ prefix means "private" method like _ that Apple (and only Apple) uses. -- (wxWindowCocoaScrollView*)_wx_wxCocoaScrollView; -- (void)_wx_setWxCocoaScrollView:(wxWindowCocoaScrollView*)theWxScrollView; - -/*! @method _wx_doScroller - @abstract Handles action messages from the scrollers - @discussion - Similar to Apple's _doScroller: method which is private and not documented. - We do not, however, call that method. Instead, we effectively override - it entirely. We don't override it by naming ourself the same thing because - the base class code may or may not call that method for other reasons we - simply cannot know about. - */ -- (void)_wx_doScroller:(id)sender; - -@end - - -@implementation WXManualScrollView : NSScrollView - -static inline void WXManualScrollView_DoSetScrollerTargetAction(WXManualScrollView *self, NSScroller *aScroller) -{ - if(aScroller != NULL && [self _wx_wxCocoaScrollView] != NULL) - { - [aScroller setTarget:self]; - [aScroller setAction:@selector(_wx_doScroller:)]; - } -} - -- (void)setHorizontalScroller:(NSScroller *)aScroller -{ - [super setHorizontalScroller:aScroller]; - WXManualScrollView_DoSetScrollerTargetAction(self, aScroller); -} - -- (void)setVerticalScroller:(NSScroller *)aScroller -{ - [super setVerticalScroller:aScroller]; - WXManualScrollView_DoSetScrollerTargetAction(self, aScroller); -} - -- (void)setHasHorizontalScroller:(BOOL)flag -{ - [super setHasHorizontalScroller:flag]; - WXManualScrollView_DoSetScrollerTargetAction(self, [self horizontalScroller]); -} - -- (void)setHasVerticalScroller:(BOOL)flag -{ - [super setHasVerticalScroller:flag]; - WXManualScrollView_DoSetScrollerTargetAction(self, [self verticalScroller]); -} - -- (wxWindowCocoaScrollView*)_wx_wxCocoaScrollView -{ return m_wxCocoaScrollView; } - -- (void)_wx_setWxCocoaScrollView:(wxWindowCocoaScrollView*)theWxScrollView -{ - m_wxCocoaScrollView = theWxScrollView; - [self setHorizontalScroller:[self horizontalScroller]]; - [self setVerticalScroller:[self verticalScroller]]; -} - -- (void)_wx_doScroller:(id)sender -{ - if(m_wxCocoaScrollView != NULL) - m_wxCocoaScrollView->_wx_doScroller(sender); - else - wxLogError(wxT("Unexpected action message received from NSScroller")); -} - -- (void)reflectScrolledClipView:(NSClipView *)aClipView -{ - struct _ScrollerBackup - { - _ScrollerBackup(NSScroller *aScroller) - : m_scroller(aScroller) - , m_floatValue(aScroller!=nil?[aScroller floatValue]:0.0) - , m_knobProportion(aScroller!=nil?[aScroller knobProportion]:1.0) - , m_isEnabled(aScroller!=nil?[aScroller isEnabled]:false) - { - } - NSScroller *m_scroller; - CGFloat m_floatValue; - CGFloat m_knobProportion; - BOOL m_isEnabled; - ~_ScrollerBackup() - { - if(m_scroller != nil) - { - [m_scroller setFloatValue:m_floatValue knobProportion:m_knobProportion]; - [m_scroller setEnabled:m_isEnabled]; - } - } - private: - _ScrollerBackup(); - _ScrollerBackup(_ScrollerBackup const&); - _ScrollerBackup& operator=(_ScrollerBackup const&); - }; - _ScrollerBackup _horizontalBackup([self horizontalScroller]); - _ScrollerBackup _verticalBackup([self verticalScroller]); - // We MUST call super's implementation or else nothing seems to work right at all. - // However, we need our scrollers not to change values due to the document window - // moving so we cheat and save/restore their values across this call. - [super reflectScrolledClipView: aClipView]; -} - -@end -WX_IMPLEMENT_GET_OBJC_CLASS(WXManualScrollView,NSScrollView) - -// ======================================================================== -// wxFlippedNSClipView -// ======================================================================== -@interface wxFlippedNSClipView : NSClipView -- (BOOL)isFlipped; -@end -WX_DECLARE_GET_OBJC_CLASS(wxFlippedNSClipView,NSClipView) - -@implementation wxFlippedNSClipView : NSClipView -- (BOOL)isFlipped -{ - return YES; -} - -@end -WX_IMPLEMENT_GET_OBJC_CLASS(wxFlippedNSClipView,NSClipView) - -// ======================================================================== -// wxWindowCocoaScrollView -// ======================================================================== -wxWindowCocoaScrollView::wxWindowCocoaScrollView(wxWindow *owner) -: m_owner(owner) -, m_cocoaNSScrollView() // nil -, m_scrollRange() // {0,0} -, m_scrollThumb() // {0,0} -, m_virtualOrigin(0,0) -{ - wxAutoNSAutoreleasePool pool; - wxASSERT(owner); - wxASSERT(owner->GetNSView()); - m_isNativeView = ![owner->GetNSView() isKindOfClass:[WX_GET_OBJC_CLASS(WXNSView) class]]; - m_cocoaNSScrollView = [(m_isNativeView?[NSScrollView alloc]:[WXManualScrollView alloc]) - initWithFrame:[owner->GetNSView() frame]]; - AssociateNSView(m_cocoaNSScrollView); - if(m_isNativeView) - { - /* Set a bezel border around the entire thing because it looks funny without it. - TODO: Be sure to undo any borders on the real view (if any) and apply them - to this view if necessary. Right now, there is no border support in wxCocoa - so this isn't an issue. - */ - [m_cocoaNSScrollView setBorderType:NSBezelBorder]; - } - else - { - [(WXManualScrollView*)m_cocoaNSScrollView _wx_setWxCocoaScrollView: this]; - // Don't set a bezel because we might be creating a scroll view due to being - // the "target window" of a wxScrolledWindow. That is to say that the user - // has absolutely no intention of scrolling the clip view used by this - // NSScrollView. - } - - /* Replace the default NSClipView with a flipped one. This ensures - scrolling is "pinned" to the top-left instead of bottom-right. */ - NSClipView *flippedClip = [[WX_GET_OBJC_CLASS(wxFlippedNSClipView) alloc] - initWithFrame: [[m_cocoaNSScrollView contentView] frame]]; - [m_cocoaNSScrollView setContentView:flippedClip]; - [flippedClip release]; - - // In all cases we must encapsulate the real NSView properly - Encapsulate(); -} - -void wxWindowCocoaScrollView::Encapsulate() -{ - // Set the scroll view autoresizingMask to match the current NSView - [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]]; - [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable]; - // NOTE: replaceSubView will cause m_cocoaNSView to be released - // except when it hasn't been added into an NSView hierarchy in which - // case it doesn't need to be and this should work out to a no-op - m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView); - // The NSView is still retained by owner - [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()]; - // Now it's also retained by the NSScrollView -} - -void wxWindowCocoaScrollView::Unencapsulate() -{ - [m_cocoaNSScrollView setDocumentView: nil]; - m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView()); - if(![[m_owner->GetNSView() superview] isFlipped]) - [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin]; -} - -wxWindowCocoaScrollView::~wxWindowCocoaScrollView() -{ - DisassociateNSView(m_cocoaNSScrollView); - if(!m_isNativeView) - { - [(WXManualScrollView*)m_cocoaNSScrollView _wx_setWxCocoaScrollView:NULL]; - } - [m_cocoaNSScrollView release]; -} - -void wxWindowCocoaScrollView::ClientSizeToSize(int &width, int &height) -{ - NSSize frameSize = [NSScrollView - frameSizeForContentSize: NSMakeSize(width,height) - hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller] - hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller] - borderType: [m_cocoaNSScrollView borderType]]; - width = (int)frameSize.width; - height = (int)frameSize.height; -} - -void wxWindowCocoaScrollView::DoGetClientSize(int *x, int *y) const -{ - NSSize nssize = [m_cocoaNSScrollView contentSize]; - if(x) - *x = (int)nssize.width; - if(y) - *y = (int)nssize.height; -} - -static inline void SetCocoaScroller(NSScroller *aScroller, int WXUNUSED(orientation), int position, int thumbSize, int range) -{ - wxCHECK_RET(aScroller != nil, wxT("Expected the NSScrollView to have a scroller")); - - // NOTE: thumbSize is already ensured to be >= 1 and <= range by our caller - // unless range = 0 in which case we shouldn't have been be called. - wxCHECK_RET(range > 0, wxT("Internal wxCocoa bug: shouldn't have been called with 0 range")); - - // Range of valid position values is from 0 to effectiveRange - // NOTE: if thumbSize == range then effectiveRange is 0. - // thumbSize is at least 1 which gives range from 0 to range - 1 inclusive - // which is exactly what we want. - int effectiveRange = range - thumbSize; - - // knobProportion is hopefully easy to understand - // Note that thumbSize is already guaranteed >= 1 by our caller. - CGFloat const knobProportion = CGFloat(thumbSize)/CGFloat(range); - - // NOTE: When effectiveRange is zero there really is no valid position - // We arbitrarily pick 0.0 which is the same as a scroller in the home position. - CGFloat const floatValue = (effectiveRange != 0)?CGFloat(position)/CGFloat(effectiveRange):0.0; - - [aScroller setFloatValue:floatValue knobProportion: knobProportion]; - // Make sure it's visibly working - [aScroller setEnabled:YES]; -} - -void wxWindowCocoaScrollView::SetScrollPos(wxOrientation orientation, int position) -{ - // NOTE: Rather than using only setFloatValue: (which we could do) we instead - // simply share the SetCocoaScroller call because all but the knobProportion - // calculations have to be done anyway. - if(orientation & wxHORIZONTAL) - { - NSScroller *aScroller = [m_cocoaNSScrollView horizontalScroller]; - if(aScroller != nil) - SetCocoaScroller(aScroller, orientation, position, m_scrollThumb[0], m_scrollRange[0]); - } - if(orientation & wxVERTICAL) - { - NSScroller *aScroller = [m_cocoaNSScrollView verticalScroller]; - if(aScroller != nil) - SetCocoaScroller(aScroller, orientation, position, m_scrollThumb[1], m_scrollRange[1]); - } -} - -void wxWindowCocoaScrollView::SetScrollbar(int orientation, int position, int thumbSize, int range) -{ - // FIXME: API assumptions: - // 1. If the user wants to remove a scroller he gives range 0. - // 2. If the user wants to disable a scroller he sets thumbSize == range - // in which case it is logically impossible to scroll. - // The scroller shall still be displayed. - - // Ensure that range is >= 0. - wxASSERT(range >= 0); - if(range < 0) - range = 0; - - // Ensure that thumbSize <= range - wxASSERT(thumbSize <= range); - // Also ensure thumbSize >= 1 but don't complain if it isn't - if(thumbSize < 1) - thumbSize = 1; - // Now make sure it's really less than range, even if we just set it to 1 - if(thumbSize > range) - thumbSize = range; - - bool needScroller = (range != 0); - - // Can potentially set both horizontal and vertical at the same time although this is - // probably not very useful. - if(orientation & wxHORIZONTAL) - { - m_scrollRange[0] = range; - m_scrollThumb[0] = thumbSize; - if(!m_isNativeView) - { - [m_cocoaNSScrollView setHasHorizontalScroller:needScroller]; - if(needScroller) - SetCocoaScroller([m_cocoaNSScrollView horizontalScroller], orientation, position, thumbSize, range); - } - } - - if(orientation & wxVERTICAL) - { - m_scrollRange[1] = range; - m_scrollThumb[1] = thumbSize; - if(!m_isNativeView) - { - [m_cocoaNSScrollView setHasVerticalScroller:needScroller]; - if(needScroller) - SetCocoaScroller([m_cocoaNSScrollView verticalScroller], orientation, position, thumbSize, range); - } - } -} - -int wxWindowCocoaScrollView::GetScrollPos(wxOrientation orient) -{ - if((orient & wxBOTH) == wxBOTH) - { - wxLogError(wxT("GetScrollPos called for wxHORIZONTAL and wxVERTICAL together which makes no sense")); - return 0; - } - int effectiveScrollRange; - NSScroller *cocoaScroller; - if(orient & wxHORIZONTAL) - { - effectiveScrollRange = m_scrollRange[0] - m_scrollThumb[0]; - cocoaScroller = [m_cocoaNSScrollView horizontalScroller]; - } - else if(orient & wxVERTICAL) - { - effectiveScrollRange = m_scrollRange[1] - m_scrollThumb[1]; - cocoaScroller = [m_cocoaNSScrollView verticalScroller]; - } - else - { - wxLogError(wxT("GetScrollPos called without an orientation which makes no sense")); - return 0; - } - if(cocoaScroller == nil) - { // Document is not scrolled - return 0; - } - /* - The effective range of a scroll bar as defined by wxWidgets is from 0 to (range - thumbSize). - That is a scroller at the left/top position is at 0 and a scroller at the bottom/right - position is at range-thumbsize. - - The range of an NSScroller is 0.0 to 1.0. Much easier! NOTE: Apple doesn't really specify - but GNUStep docs do say that 0.0 is top/left and 1.0 is bottom/right. This is actually - in contrast to NSSlider which generally has 1.0 at the TOP when it's done vertically. - */ - CGFloat cocoaScrollPos = [cocoaScroller floatValue]; - return effectiveScrollRange * cocoaScrollPos; -} - -int wxWindowCocoaScrollView::GetScrollRange(wxOrientation orient) -{ - if((orient & wxBOTH) == wxBOTH) - { - wxLogError(wxT("GetScrollRange called for wxHORIZONTAL and wxVERTICAL together which makes no sense")); - return 0; - } - if(orient & wxHORIZONTAL) - { - return m_scrollRange[0]; - } - else if(orient & wxVERTICAL) - { - return m_scrollRange[1]; - } - else - { - wxLogError(wxT("GetScrollPos called without an orientation which makes no sense")); - return 0; - } -} - -int wxWindowCocoaScrollView::GetScrollThumb(wxOrientation orient) -{ - if((orient & wxBOTH) == wxBOTH) - { - wxLogError(wxT("GetScrollThumb called for wxHORIZONTAL and wxVERTICAL together which makes no sense")); - return 0; - } - if(orient & wxHORIZONTAL) - { - return m_scrollThumb[0]; - } - else if(orient & wxVERTICAL) - { - return m_scrollThumb[1]; - } - else - { - wxLogError(wxT("GetScrollThumb called without an orientation which makes no sense")); - return 0; - } -} - -/*! - Moves the contents (all existing drawing as well as all all child wxWindow) by the specified - amount expressed in the wxWindow's own coordinate system. This is used to implement scrolling - but the usage is rather interesting. When scrolling right (e.g. increasing the value of - the scroller) you must give a negative delta x (e.g. moving the contents LEFT). Likewise, - when scrolling the window down, increasing the value of the scroller, you give a negative - delta y which moves the contents up. - - wxCocoa notes: To accomplish this trick in Cocoa we basically do what NSScrollView would - have done and that is adjust the content view's bounds origin. The content view is somewhat - confusingly the NSClipView which is more or less sort of the pImpl for NSScrollView - The real NSView with the user's content (e.g. the "virtual area" in wxWidgets parlance) - is called the document view in NSScrollView parlance. - - The bounds origin is basically the exact opposite concept. Whereas in Windows the client - coordinate system remains constant and the content must shift left/up for increases - of scrolling, in Cocoa the coordinate system is actually the virtual one. So we must - instead shift the bounds rectangle right/down to get the effect of the content moving - left/up. Basically, it's a higher level interface than that provided by wxWidgets - so essentially we're implementing the low-level move content interface in terms of - the high-level move the viewport (the bounds) over top that content (the document - view which is the virtual area to wx). - - For all intents and purposes that basically just means that we subtract the deltas - from the bounds origin and thus a negative delta actually increases the bounds origin - and a positive delta actually decreases it. This is absolutely true for the horizontal - axis but there's a catch in the vertical axis. If the content view (the clip view) is - flipped (and we do this by default) then it works exactly like the horizontal axis. - If it is not flipped (i.e. it is in postscript coordinates which are opposite to - wxWidgets) then the sense needs to be reversed. - - However, this plays hell with window positions. The frame rects of any child views - do not change origin and this is actually important because if they did, the views - would send frame changed notifications, not to mention that Cocoa just doesn't really - do scrolling that way, it does it the way we do it here. - - To fix this we implement GetPosition for child windows to not merely consult its - superview at the Cocoa level in order to do proper Cocoa->wx coordinate transform - but to actually consult is parent wxWindow because it makes a big difference if - the parent is scrolled. Argh. (FIXME: This isn't actually implemented yet) - */ -void wxWindowCocoaScrollView::ScrollWindow(int dx, int dy, const wxRect*) -{ - // Update our internal origin so we know how much the application code - // expects us to have been scrolled. - m_virtualOrigin.x += dx; - m_virtualOrigin.y += dy; - - // Scroll the window using the standard Cocoa method of adjusting the - // clip view's bounds in the opposite fashion. - NSClipView *contentView = [m_cocoaNSScrollView contentView]; - NSRect clipViewBoundsRect = [contentView bounds]; - clipViewBoundsRect.origin.x -= dx; - if([contentView isFlipped]) - clipViewBoundsRect.origin.y -= dy; - else - clipViewBoundsRect.origin.y += dy; - [contentView scrollToPoint:clipViewBoundsRect.origin]; -} - -void wxWindowCocoaScrollView::_wx_doScroller(NSScroller *sender) -{ - wxOrientation orientation; - if(sender == [m_cocoaNSScrollView horizontalScroller]) - orientation = wxHORIZONTAL; - else if(sender == [m_cocoaNSScrollView verticalScroller]) - orientation = wxVERTICAL; - else - { - wxLogDebug(wxT("Received action message from unexpected NSScroller")); - return; - } - // NOTE: Cocoa does not move the scroller for page up/down or line - // up/down events. That means the value will be the old value. - // For thumbtrack events, the value is the new value. - int scrollpos = GetScrollPos(orientation); - int commandType; - switch([sender hitPart]) - { - default: - case NSScrollerNoPart: - case NSScrollerKnob: // Drag of knob - case NSScrollerKnobSlot: // Jump directly to position - commandType = wxEVT_SCROLLWIN_THUMBTRACK; - break; - case NSScrollerDecrementPage: - commandType = wxEVT_SCROLLWIN_PAGEUP; - break; - case NSScrollerIncrementPage: - commandType = wxEVT_SCROLLWIN_PAGEDOWN; - break; - case NSScrollerDecrementLine: - commandType = wxEVT_SCROLLWIN_LINEUP; - break; - case NSScrollerIncrementLine: - commandType = wxEVT_SCROLLWIN_LINEDOWN; - break; - } - wxScrollWinEvent event(commandType, scrollpos, orientation); - event.SetEventObject(m_owner); - m_owner->HandleWindowEvent(event); -} - -void wxWindowCocoaScrollView::UpdateSizes() -{ - // Using the virtual size, figure out what the document frame size should be - // NOTE: Assume that the passed in virtualSize is already >= the client size - wxSize virtualSize = m_owner->GetVirtualSize(); - - // Get the document's current frame - NSRect documentViewFrame = [m_owner->GetNSView() frame]; - NSRect newFrame = documentViewFrame; - newFrame.size = NSMakeSize(virtualSize.x, virtualSize.y); - - if(!NSEqualRects(newFrame, documentViewFrame)) - { - [m_owner->GetNSView() setFrame:newFrame]; - } -} - -void wxWindowCocoaScrollView::Cocoa_FrameChanged(void) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxWindowCocoaScrollView=%p::Cocoa_FrameChanged for wxWindow %p"), this, m_owner); - wxSizeEvent event(m_owner->GetSize(), m_owner->GetId()); - event.SetEventObject(m_owner); - m_owner->HandleWindowEvent(event); - - /* If the view is not a native one then it's being managed by wx. In this case the control - may decide to change its virtual size and we must update the document view's size to - match. For native views the virtual size will never have been set so we do not want - to use it at all. - */ - if(!m_isNativeView) - UpdateSizes(); -} - -// ======================================================================== -// wxWindowCocoa -// ======================================================================== -// normally the base classes aren't included, but wxWindow is special -#ifdef __WXUNIVERSAL__ -IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase) -#endif - -BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase) -END_EVENT_TABLE() - -wxWindow *wxWindowCocoa::sm_capturedWindow = NULL; - -// Constructor -void wxWindowCocoa::Init() -{ - m_cocoaNSView = NULL; - m_cocoaHider = NULL; - m_wxCocoaScrollView = NULL; - m_isInPaint = false; - m_visibleTrackingRectManager = NULL; -} - -// Constructor -bool wxWindow::Create(wxWindow *parent, wxWindowID winid, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) - return false; - - // TODO: create the window - m_cocoaNSView = NULL; - SetNSView([[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: MakeDefaultNSRect(size)]); - [m_cocoaNSView release]; - - if (m_parent) - { - m_parent->AddChild(this); - m_parent->CocoaAddChild(this); - SetInitialFrameRect(pos,size); - } - - return true; -} - -// Destructor -wxWindow::~wxWindow() -{ - wxAutoNSAutoreleasePool pool; - DestroyChildren(); - - // Make sure our parent (in the wxWidgets sense) is our superview - // before we go removing from it. - if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview]) - CocoaRemoveFromParent(); - delete m_cocoaHider; - delete m_wxCocoaScrollView; - if(m_cocoaNSView) - SendDestroyEvent(); - SetNSView(NULL); -} - -void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child) -{ - // Pool here due to lack of one during wx init phase - wxAutoNSAutoreleasePool pool; - - NSView *childView = child->GetNSViewForSuperview(); - - wxASSERT(childView); - [m_cocoaNSView addSubview: childView]; -} - -void wxWindowCocoa::CocoaRemoveFromParent(void) -{ - [GetNSViewForSuperview() removeFromSuperview]; -} - -void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView) -{ - // Clear the visible area tracking rect if we have one. - delete m_visibleTrackingRectManager; - m_visibleTrackingRectManager = NULL; - - bool need_debug = cocoaNSView || m_cocoaNSView; - if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]); - DisassociateNSView(m_cocoaNSView); - wxGCSafeRetain(cocoaNSView); - wxGCSafeRelease(m_cocoaNSView); - m_cocoaNSView = cocoaNSView; - AssociateNSView(m_cocoaNSView); - if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]); -} - -WX_NSView wxWindowCocoa::GetNSViewForSuperview() const -{ - return m_cocoaHider - ? m_cocoaHider->GetNSView() - : m_wxCocoaScrollView - ? m_wxCocoaScrollView->GetNSScrollView() - : m_cocoaNSView; -} - -WX_NSView wxWindowCocoa::GetNSViewForHiding() const -{ - return m_wxCocoaScrollView - ? m_wxCocoaScrollView->GetNSScrollView() - : m_cocoaNSView; -} - -NSPoint wxWindowCocoa::CocoaTransformBoundsToWx(NSPoint pointBounds) -{ - // TODO: Handle scrolling offset - return CocoaTransformNSViewBoundsToWx(GetNSView(), pointBounds); -} - -NSRect wxWindowCocoa::CocoaTransformBoundsToWx(NSRect rectBounds) -{ - // TODO: Handle scrolling offset - return CocoaTransformNSViewBoundsToWx(GetNSView(), rectBounds); -} - -NSPoint wxWindowCocoa::CocoaTransformWxToBounds(NSPoint pointWx) -{ - // TODO: Handle scrolling offset - return CocoaTransformNSViewWxToBounds(GetNSView(), pointWx); -} - -NSRect wxWindowCocoa::CocoaTransformWxToBounds(NSRect rectWx) -{ - // TODO: Handle scrolling offset - return CocoaTransformNSViewWxToBounds(GetNSView(), rectWx); -} - -WX_NSAffineTransform wxWindowCocoa::CocoaGetWxToBoundsTransform() -{ - // TODO: Handle scrolling offset - NSAffineTransform *transform = wxCocoaDCImpl::CocoaGetWxToBoundsTransform([GetNSView() isFlipped], [GetNSView() bounds].size.height); - return transform; -} - -bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect) -{ - wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect")); - // Recursion can happen if the event loop runs from within the paint - // handler. For instance, if an assertion dialog is shown. - // FIXME: This seems less than ideal. - if(m_isInPaint) - { - wxLogDebug(wxT("Paint event recursion!")); - return false; - } - m_isInPaint = true; - - // Set m_updateRegion - const NSRect *rects = ▭ // The bounding box of the region - NSInteger countRects = 1; - // Try replacing the larger rectangle with a list of smaller ones: - if ([GetNSView() respondsToSelector:@selector(getRectsBeingDrawn:count:)]) - [GetNSView() getRectsBeingDrawn:&rects count:&countRects]; - - NSRect *transformedRects = (NSRect*)malloc(sizeof(NSRect)*countRects); - for(int i=0; iGetNSScrollView() contentView] documentVisibleRect]; - // For horizontal, simply subtract the origin. - // e.g. if the origin is at 123 and the user clicks as far left as possible then - // the coordinate that wx wants is 0. - cocoaPoint.x -= documentVisibleRect.origin.x; - if([m_cocoaNSView isFlipped]) - { - // In the flipped view case this works exactly like horizontal. - cocoaPoint.y -= documentVisibleRect.origin.y; - } - // For vertical we have to mind non-flipped (e.g. y=0 at bottom) views. - // We also need to mind the fact that we're still in Cocoa coordinates - // and not wx coordinates. The wx coordinate translation will still occur - // and that is going to be wxY = boundsH - cocoaY for non-flipped views. - - // When we consider scrolling we are truly interested in how far the top - // edge of the bounds rectangle is scrolled off the screen. - // Assuming the bounds origin is 0 (which is an assumption we make in - // wxCocoa since wxWidgets has no analog to it) then the top edge of - // the bounds rectangle is simply its height. The top edge of the - // documentVisibleRect (e.g. the client area) is its height plus - // its origin. - // Thus, we simply need add the distance between the bounds top - // and the client (docuemntVisibleRect) top. - // Or putting it another way, we subtract the distance between the - // client top and the bounds top. - else - { - NSRect bounds = [m_cocoaNSView bounds]; - CGFloat scrollYOrigin = (bounds.size.height - (documentVisibleRect.origin.y + documentVisibleRect.size.height)); - cocoaPoint.y += scrollYOrigin; - } - } - - NSPoint pointWx = CocoaTransformBoundsToWx(cocoaPoint); - // FIXME: Should we be adjusting for client area origin? - const wxPoint &clientorigin = GetClientAreaOrigin(); - event.m_x = (wxCoord)pointWx.x - clientorigin.x; - event.m_y = (wxCoord)pointWx.y - clientorigin.y; - - event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask; - event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask; - event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask; - event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask; - - // TODO: set timestamp? - event.SetEventObject(this); - event.SetId(GetId()); -} - -bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent) -{ - wxMouseEvent event(wxEVT_MOTION); - InitMouseEvent(event,theEvent); - wxLogTrace(wxTRACE_COCOA,wxT("wxWindow=%p::Cocoa_mouseMoved @%d,%d"),this,event.m_x,event.m_y); - return HandleWindowEvent(event); -} - -void wxWindowCocoa::Cocoa_synthesizeMouseMoved() -{ - wxMouseEvent event(wxEVT_MOTION); - NSWindow *window = [GetNSView() window]; - NSPoint locationInWindow = [window mouseLocationOutsideOfEventStream]; - NSPoint cocoaPoint = [m_cocoaNSView convertPoint:locationInWindow fromView:nil]; - - NSPoint pointWx = CocoaTransformBoundsToWx(cocoaPoint); - // FIXME: Should we be adjusting for client area origin? - const wxPoint &clientorigin = GetClientAreaOrigin(); - event.m_x = (wxCoord)pointWx.x - clientorigin.x; - event.m_y = (wxCoord)pointWx.y - clientorigin.y; - - // TODO: Handle shift, control, alt, meta flags - event.SetEventObject(this); - event.SetId(GetId()); - - wxLogTrace(wxTRACE_COCOA,wxT("wxwin=%p Synthesized Mouse Moved @%d,%d"),this,event.m_x,event.m_y); - HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent) -{ - if(m_visibleTrackingRectManager != NULL && m_visibleTrackingRectManager->IsOwnerOfEvent(theEvent)) - { - m_visibleTrackingRectManager->BeginSynthesizingEvents(); - - // Although we synthesize the mouse moved events we don't poll for them but rather send them only when - // some other event comes in. That other event is (guess what) mouse moved events that will be sent - // to the NSWindow which will forward them on to the first responder. We are not likely to be the - // first responder, so the mouseMoved: events are effectively discarded. - [[GetNSView() window] setAcceptsMouseMovedEvents:YES]; - - wxMouseEvent event(wxEVT_ENTER_WINDOW); - InitMouseEvent(event,theEvent); - wxLogTrace(wxTRACE_COCOA_TrackingRect,wxT("wxwin=%p Mouse Entered TR#%d @%d,%d"),this,[theEvent trackingNumber], event.m_x,event.m_y); - return HandleWindowEvent(event); - } - else - return false; -} - -bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent) -{ - if(m_visibleTrackingRectManager != NULL && m_visibleTrackingRectManager->IsOwnerOfEvent(theEvent)) - { - m_visibleTrackingRectManager->StopSynthesizingEvents(); - - wxMouseEvent event(wxEVT_LEAVE_WINDOW); - InitMouseEvent(event,theEvent); - wxLogTrace(wxTRACE_COCOA_TrackingRect,wxT("wxwin=%p Mouse Exited TR#%d @%d,%d"),this,[theEvent trackingNumber],event.m_x,event.m_y); - return HandleWindowEvent(event); - } - else - return false; -} - -bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent) -{ - wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK); - InitMouseEvent(event,theEvent); - wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]); - return HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent) -{ - wxMouseEvent event(wxEVT_MOTION); - InitMouseEvent(event,theEvent); - event.m_leftDown = true; - wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y); - return HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent) -{ - wxMouseEvent event(wxEVT_LEFT_UP); - InitMouseEvent(event,theEvent); - wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y); - return HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent) -{ - wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK); - InitMouseEvent(event,theEvent); - wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]); - return HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent) -{ - wxMouseEvent event(wxEVT_MOTION); - InitMouseEvent(event,theEvent); - event.m_rightDown = true; - wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y); - return HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent) -{ - wxMouseEvent event(wxEVT_RIGHT_UP); - InitMouseEvent(event,theEvent); - wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y); - return HandleWindowEvent(event); -} - -bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent) -{ - return false; -} - -bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent) -{ - return false; -} - -bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent) -{ - return false; -} - -void wxWindowCocoa::Cocoa_FrameChanged(void) -{ - // We always get this message for the real NSView which may have been - // enclosed in an NSScrollView. If that's the case then what we're - // effectively getting here is a notifcation that the - // virtual sized changed.. which we don't need to send on since - // wx has no concept of this whatsoever. - bool isViewForSuperview = (m_wxCocoaScrollView == NULL); - if(isViewForSuperview) - { - wxLogTrace(wxTRACE_COCOA,wxT("wxWindow=%p::Cocoa_FrameChanged"),this); - if(m_visibleTrackingRectManager != NULL) - m_visibleTrackingRectManager->RebuildTrackingRect(); - wxSizeEvent event(GetSize(), m_windowId); - event.SetEventObject(this); - HandleWindowEvent(event); - } - else - { - wxLogTrace(wxTRACE_COCOA,wxT("wxWindow=%p::Cocoa_FrameChanged ignored"),this); - } -} - -bool wxWindowCocoa::Cocoa_resetCursorRects() -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxWindow=%p::Cocoa_resetCursorRects"),this); - - // When we are called there may be a queued tracking rect event (mouse entered or exited) and - // we won't know it. A specific example is wxGenericHyperlinkCtrl changing the cursor from its - // mouse exited event. If the control happens to share the edge with its parent window which is - // also tracking mouse events then Cocoa receives two mouse exited events from the window server. - // The first one will cause wxGenericHyperlinkCtrl to call wxWindow::SetCursor which will - // invaildate the cursor rect causing Cocoa to schedule cursor rect reset with the run loop - // which willl in turn call us before exiting for the next user event. - - // If we are the parent window then rebuilding our tracking rectangle will cause us to miss - // our mouse exited event because the already queued event will have the old tracking rect - // tag. The simple solution is to only rebuild our tracking rect if we need to. - - if(m_visibleTrackingRectManager != NULL) - m_visibleTrackingRectManager->RebuildTrackingRectIfNeeded(); - - if(!m_cursor.GetNSCursor()) - return false; - - [GetNSView() addCursorRect: [GetNSView() visibleRect] cursor: m_cursor.GetNSCursor()]; - - return true; -} - -bool wxWindowCocoa::SetCursor(const wxCursor &cursor) -{ - if(!wxWindowBase::SetCursor(cursor)) - return false; - - // Set up the cursor rect so that invalidateCursorRectsForView: will destroy it. - // If we don't do this then Cocoa thinks (rightly) that we don't have any cursor - // rects and thus won't ever call resetCursorRects. - [GetNSView() addCursorRect: [GetNSView() visibleRect] cursor: m_cursor.GetNSCursor()]; - - // Invalidate the cursor rects so the cursor will change - // Note that it is not enough to remove the old one (if any) and add the new one. - // For the rects to work properly, Cocoa itself must call resetCursorRects. - [[GetNSView() window] invalidateCursorRectsForView:GetNSView()]; - return true; -} - -bool wxWindowCocoa::Cocoa_viewDidMoveToWindow() -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxWindow=%p::viewDidMoveToWindow"),this); - // Set up new tracking rects. I am reasonably sure the new window must be set before doing this. - if(m_visibleTrackingRectManager != NULL) - m_visibleTrackingRectManager->BuildTrackingRect(); - return false; -} - -bool wxWindowCocoa::Cocoa_viewWillMoveToWindow(WX_NSWindow newWindow) -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxWindow=%p::viewWillMoveToWindow:%p"),this, newWindow); - // Clear tracking rects. It is imperative this be done before the new window is set. - if(m_visibleTrackingRectManager != NULL) - m_visibleTrackingRectManager->ClearTrackingRect(); - return false; -} - -bool wxWindow::Close(bool force) -{ - // The only reason this function exists is that it is virtual and - // wxTopLevelWindowCocoa will override it. - return wxWindowBase::Close(force); -} - -void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) -{ - [[oldView superview] replaceSubview:oldView with:newView]; -} - -void wxWindow::DoEnable(bool enable) -{ - CocoaSetEnabled(enable); -} - -bool wxWindow::Show(bool show) -{ - wxAutoNSAutoreleasePool pool; - // If the window is marked as visible, then it shouldn't have a dummy view - // If the window is marked hidden, then it should have a dummy view - // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic -// wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView")); - // Return false if there isn't a window to show or hide - NSView *cocoaView = GetNSViewForHiding(); - if(!cocoaView) - return false; - if(show) - { - // If state isn't changing, return false - if(!m_cocoaHider) - return false; - - // Replace the stand-in view with the real one and destroy the dummy view - CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView); - wxASSERT(![m_cocoaHider->GetNSView() superview]); - delete m_cocoaHider; - m_cocoaHider = NULL; - wxASSERT([cocoaView superview]); - - // Schedule an update of the key view loop (NOTE: 10.4+ only.. argh) - NSWindow *window = [cocoaView window]; - if(window != nil) - { - // Delay this until returning to the event loop for a couple of reasons: - // 1. If a lot of stuff is shown/hidden we avoid recalculating needlessly - // 2. NSWindow does not seem to see the newly shown views if we do it right now. - if([window respondsToSelector:@selector(recalculateKeyViewLoop)]) - [window performSelector:@selector(recalculateKeyViewLoop) withObject:nil afterDelay:0.0]; - } - } - else - { - // If state isn't changing, return false - if(m_cocoaHider) - return false; - - // Handle the first responder - NSWindow *window = [cocoaView window]; - if(window != nil) - { - NSResponder *firstResponder = [window firstResponder]; - if([firstResponder isKindOfClass:[NSView class]] && [(NSView*)firstResponder isDescendantOf:cocoaView]) - { - BOOL didResign = [window makeFirstResponder:nil]; - // If the current first responder (one of our subviews) refuses to give - // up its status, then fail now and don't hide this view - if(didResign == NO) - return false; - } - } - - // Create a new view to stand in for the real one (via wxWindowCocoaHider) and replace - // the real one with the stand in. - m_cocoaHider = new wxWindowCocoaHider(this); - // NOTE: replaceSubview:with will cause m_cocoaNSView to be - // (auto)released which balances out addSubview - CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView()); - // m_cocoaNSView is now only retained by us - wxASSERT([m_cocoaHider->GetNSView() superview]); - wxASSERT(![cocoaView superview]); - } - m_isShown = show; - return true; -} - -void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoSetSizeWindow(%d,%d,%d,%d,Auto: %s%s)"),this,x,y,width,height,(sizeFlags&wxSIZE_AUTO_WIDTH)?"W":".",sizeFlags&wxSIZE_AUTO_HEIGHT?"H":"."); - int currentX, currentY; - int currentW, currentH; - DoGetPosition(¤tX, ¤tY); - DoGetSize(¤tW, ¤tH); - if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) - x=currentX; - if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) - y=currentY; - - AdjustForParentClientOrigin(x,y,sizeFlags); - - wxSize size(wxDefaultSize); - - if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) - { - if(sizeFlags&wxSIZE_AUTO_WIDTH) - { - size=DoGetBestSize(); - width=size.x; - } - else - width=currentW; - } - if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) - { - if(sizeFlags&wxSIZE_AUTO_HEIGHT) - { - if(size.x==-1) - size=DoGetBestSize(); - height=size.y; - } - else - height=currentH; - } - DoMoveWindow(x,y,width,height); -} - -#if wxUSE_TOOLTIPS - -void wxWindowCocoa::DoSetToolTip( wxToolTip *tip ) -{ - wxWindowBase::DoSetToolTip(tip); - - if ( m_tooltip ) - { - m_tooltip->SetWindow((wxWindow *)this); - } -} - -#endif - -void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height) -{ - wxAutoNSAutoreleasePool pool; - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height); - - NSView *nsview = GetNSViewForSuperview(); - NSView *superview = [nsview superview]; - - wxCHECK_RET(GetParent(), wxT("Window can only be placed correctly when it has a parent")); - - NSRect oldFrameRect = [nsview frame]; - NSRect newFrameRect = GetParent()->CocoaTransformWxToBounds(NSMakeRect(x,y,width,height)); - [nsview setFrame:newFrameRect]; - // Be sure to redraw the parent to reflect the changed position - [superview setNeedsDisplayInRect:oldFrameRect]; - [superview setNeedsDisplayInRect:newFrameRect]; -} - -void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size) -{ - NSView *nsview = GetNSViewForSuperview(); - NSView *superview = [nsview superview]; - wxCHECK_RET(superview,wxT("NSView does not have a superview")); - wxCHECK_RET(GetParent(), wxT("Window can only be placed correctly when it has a parent")); - NSRect frameRect = [nsview frame]; - if(size.x!=-1) - frameRect.size.width = size.x; - if(size.y!=-1) - frameRect.size.height = size.y; - frameRect.origin.x = pos.x; - frameRect.origin.y = pos.y; - // Tell Cocoa to change the margin between the bottom of the superview - // and the bottom of the control. Keeps the control pinned to the top - // of its superview so that its position in the wxWidgets coordinate - // system doesn't change. - if(![superview isFlipped]) - [nsview setAutoresizingMask: NSViewMinYMargin]; - // MUST set the mask before setFrame: which can generate a size event - // and cause a scroller to be added! - frameRect = GetParent()->CocoaTransformWxToBounds(frameRect); - [nsview setFrame: frameRect]; -} - -// Get total size -void wxWindow::DoGetSize(int *w, int *h) const -{ - NSRect cocoaRect = [GetNSViewForSuperview() frame]; - if(w) - *w=(int)cocoaRect.size.width; - if(h) - *h=(int)cocoaRect.size.height; - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height); -} - -void wxWindow::DoGetPosition(int *x, int *y) const -{ - NSView *nsview = GetNSViewForSuperview(); - - NSRect cocoaRect = [nsview frame]; - NSRect rectWx = GetParent()->CocoaTransformBoundsToWx(cocoaRect); - if(x) - *x=(int)rectWx.origin.x; - if(y) - *y=(int)rectWx.origin.y; - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y); -} - -WXWidget wxWindow::GetHandle() const -{ - return m_cocoaNSView; -} - -wxWindow* wxWindow::GetWxWindow() const -{ - return (wxWindow*) this; -} - -void wxWindow::Refresh(bool eraseBack, const wxRect *rect) -{ - [m_cocoaNSView setNeedsDisplay:YES]; -} - -void wxWindow::SetFocus() -{ - if([GetNSView() acceptsFirstResponder]) - [[GetNSView() window] makeFirstResponder: GetNSView()]; -} - -void wxWindow::DoCaptureMouse() -{ - // TODO - sm_capturedWindow = this; -} - -void wxWindow::DoReleaseMouse() -{ - // TODO - sm_capturedWindow = NULL; -} - -void wxWindow::DoScreenToClient(int *x, int *y) const -{ - // Point in cocoa screen coordinates: - NSPoint cocoaScreenPoint = OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(x!=NULL?*x:0, y!=NULL?*y:0, 0, 0, false); - NSView *clientView = const_cast(this)->GetNSView(); - NSWindow *theWindow = [clientView window]; - - // Point in window's base coordinate system: - NSPoint windowPoint = [theWindow convertScreenToBase:cocoaScreenPoint]; - // Point in view's bounds coordinate system - NSPoint boundsPoint = [clientView convertPoint:windowPoint fromView:nil]; - // Point in wx client coordinates: - NSPoint theWxClientPoint = CocoaTransformNSViewBoundsToWx(clientView, boundsPoint); - if(x!=NULL) - *x = theWxClientPoint.x; - if(y!=NULL) - *y = theWxClientPoint.y; -} - -void wxWindow::DoClientToScreen(int *x, int *y) const -{ - // Point in wx client coordinates - NSPoint theWxClientPoint = NSMakePoint(x!=NULL?*x:0, y!=NULL?*y:0); - - NSView *clientView = const_cast(this)->GetNSView(); - - // Point in the view's bounds coordinate system - NSPoint boundsPoint = CocoaTransformNSViewWxToBounds(clientView, theWxClientPoint); - - // Point in the window's base coordinate system - NSPoint windowPoint = [clientView convertPoint:boundsPoint toView:nil]; - - NSWindow *theWindow = [clientView window]; - // Point in Cocoa's screen coordinates - NSPoint screenPoint = [theWindow convertBaseToScreen:windowPoint]; - - // Act as though this was the origin of a 0x0 rectangle - NSRect screenPointRect = NSMakeRect(screenPoint.x, screenPoint.y, 0, 0); - - // Convert that rectangle to wx coordinates - wxPoint theWxScreenPoint = OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(screenPointRect); - if(*x) - *x = theWxScreenPoint.x; - if(*y) - *y = theWxScreenPoint.y; -} - -// Get size *available for subwindows* i.e. excluding menu bar etc. -void wxWindow::DoGetClientSize(int *x, int *y) const -{ - wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:")); - if(m_wxCocoaScrollView) - m_wxCocoaScrollView->DoGetClientSize(x,y); - else - wxWindowCocoa::DoGetSize(x,y); -} - -void wxWindow::DoSetClientSize(int width, int height) -{ - wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height); - if(m_wxCocoaScrollView) - m_wxCocoaScrollView->ClientSizeToSize(width,height); - CocoaSetWxWindowSize(width,height); -} - -void wxWindow::CocoaSetWxWindowSize(int width, int height) -{ - wxWindowCocoa::DoSetSize(wxDefaultCoord,wxDefaultCoord,width,height,wxSIZE_USE_EXISTING); -} - -void wxWindow::SetLabel(const wxString& WXUNUSED(label)) -{ - // Intentional no-op. -} - -wxString wxWindow::GetLabel() const -{ - // General Get/Set of labels is implemented in wxControlBase - wxLogDebug(wxT("wxWindow::GetLabel: Should be overridden if needed.")); - return wxEmptyString; -} - -int wxWindow::GetCharHeight() const -{ - // TODO - return 10; -} - -int wxWindow::GetCharWidth() const -{ - // TODO - return 5; -} - -void wxWindow::DoGetTextExtent(const wxString& string, int *outX, int *outY, - int *outDescent, int *outExternalLeading, const wxFont *inFont) const -{ - // FIXME: This obviously ignores the window's font (if any) along with any size - // transformations. However, it's better than nothing. - // We don't create a wxClientDC because we don't want to accidently be able to use - // it for drawing. - wxClientDC tmpdc(const_cast(this)); - return tmpdc.GetTextExtent(string, outX, outY, outDescent, outExternalLeading, inFont); -} - -// Coordinates relative to the window -void wxWindow::WarpPointer (int x_pos, int y_pos) -{ - // TODO -} - -int wxWindow::GetScrollPos(int orient) const -{ - if(m_wxCocoaScrollView != NULL) - return m_wxCocoaScrollView->GetScrollPos(static_cast(orient & wxBOTH)); - else - return 0; -} - -// This now returns the whole range, not just the number -// of positions that we can scroll. -int wxWindow::GetScrollRange(int orient) const -{ - if(m_wxCocoaScrollView != NULL) - return m_wxCocoaScrollView->GetScrollRange(static_cast(orient & wxBOTH)); - else - return 0; -} - -int wxWindow::GetScrollThumb(int orient) const -{ - if(m_wxCocoaScrollView != NULL) - return m_wxCocoaScrollView->GetScrollThumb(static_cast(orient & wxBOTH)); - else - return 0; -} - -void wxWindow::SetScrollPos(int orient, int pos, bool refresh) -{ - if(m_wxCocoaScrollView != NULL) - return m_wxCocoaScrollView->SetScrollPos(static_cast(orient & wxBOTH), pos); -} - -void wxWindow::CocoaCreateNSScrollView() -{ - if(!m_wxCocoaScrollView) - { - m_wxCocoaScrollView = new wxWindowCocoaScrollView(this); - } -} - -// New function that will replace some of the above. -void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, - int range, bool refresh) -{ - CocoaCreateNSScrollView(); - m_wxCocoaScrollView->SetScrollbar(orient, pos, thumbVisible, range); - // TODO: Handle refresh (if we even need to) -} - -// Does a physical scroll -void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) -{ - if(m_wxCocoaScrollView != NULL) - m_wxCocoaScrollView->ScrollWindow(dx, dy, rect); -} - -void wxWindow::DoSetVirtualSize( int x, int y ) -{ - // Call wxWindowBase method which will set m_virtualSize to the appropriate value, - // possibly not what the caller passed in. For example, the current implementation - // clamps the width and height to within the min/max virtual ranges. - // wxDefaultCoord is passed through unchanged but then GetVirtualSize() will correct - // that by returning effectively max(virtual, client) - wxWindowBase::DoSetVirtualSize(x,y); - // Create the scroll view if it hasn't been already. - CocoaCreateNSScrollView(); - - // The GetVirtualSize automatically increases the size to max(client,virtual) - m_wxCocoaScrollView->UpdateSizes(); -} - -bool wxWindow::SetFont(const wxFont& font) -{ - // FIXME: We may need to handle wx font inheritance. - return wxWindowBase::SetFont(font); -} - -#if 0 // these are used when debugging the algorithm. -static char const * const comparisonresultStrings[] = -{ "<" -, "==" -, ">" -}; -#endif - -class CocoaWindowCompareContext -{ - wxDECLARE_NO_COPY_CLASS(CocoaWindowCompareContext); -public: - CocoaWindowCompareContext(); // Not implemented - CocoaWindowCompareContext(NSView *target, NSArray *subviews) - { - m_target = target; - // Cocoa sorts subviews in-place.. make a copy - m_subviews = [subviews copy]; - } - ~CocoaWindowCompareContext() - { // release the copy - [m_subviews release]; - } - NSView* target() - { return m_target; } - NSArray* subviews() - { return m_subviews; } - /* Helper function that returns the comparison based off of the original ordering */ - CocoaWindowCompareFunctionResult CompareUsingOriginalOrdering(id first, id second) - { - NSUInteger firstI = [m_subviews indexOfObjectIdenticalTo:first]; - NSUInteger secondI = [m_subviews indexOfObjectIdenticalTo:second]; - // NOTE: If either firstI or secondI is NSNotFound then it will be NSIntegerMax and thus will - // likely compare higher than the other view which is reasonable considering the only way that - // can happen is if the subview was added after our call to subviews but before the call to - // sortSubviewsUsingFunction:context:. Thus we don't bother checking. Particularly because - // that case should never occur anyway because that would imply a multi-threaded GUI call - // which is a big no-no with Cocoa. - - // Subviews are ordered from back to front meaning one that is already lower will have an lower index. - NSComparisonResult result = (firstI < secondI) - ? NSOrderedAscending /* -1 */ - : (firstI > secondI) - ? NSOrderedDescending /* 1 */ - : NSOrderedSame /* 0 */; - -#if 0 // Enable this if you need to debug the algorithm. - NSLog(@"%@ [%d] %s %@ [%d]\n", first, firstI, comparisonresultStrings[result+1], second, secondI); -#endif - return result; - } -private: - /* The subview we are trying to Raise or Lower */ - NSView *m_target; - /* A copy of the original array of subviews */ - NSArray *m_subviews; -}; - -/* Causes Cocoa to raise the target view to the top of the Z-Order by telling the sort function that - * the target view is always higher than every other view. When comparing two views neither of - * which is the target, it returns the correct response based on the original ordering - */ -static CocoaWindowCompareFunctionResult CocoaRaiseWindowCompareFunction(id first, id second, void *ctx) -{ - CocoaWindowCompareContext *compareContext = (CocoaWindowCompareContext*)ctx; - // first should be ordered higher - if(first==compareContext->target()) - return NSOrderedDescending; - // second should be ordered higher - if(second==compareContext->target()) - return NSOrderedAscending; - return compareContext->CompareUsingOriginalOrdering(first,second); -} - -// Raise the window to the top of the Z order -void wxWindow::Raise() -{ -// wxAutoNSAutoreleasePool pool; - NSView *nsview = GetNSViewForSuperview(); - NSView *superview = [nsview superview]; - CocoaWindowCompareContext compareContext(nsview, [superview subviews]); - - [superview sortSubviewsUsingFunction: - CocoaRaiseWindowCompareFunction - context: &compareContext]; -} - -/* Causes Cocoa to lower the target view to the bottom of the Z-Order by telling the sort function that - * the target view is always lower than every other view. When comparing two views neither of - * which is the target, it returns the correct response based on the original ordering - */ -static CocoaWindowCompareFunctionResult CocoaLowerWindowCompareFunction(id first, id second, void *ctx) -{ - CocoaWindowCompareContext *compareContext = (CocoaWindowCompareContext*)ctx; - // first should be ordered lower - if(first==compareContext->target()) - return NSOrderedAscending; - // second should be ordered lower - if(second==compareContext->target()) - return NSOrderedDescending; - return compareContext->CompareUsingOriginalOrdering(first,second); -} - -// Lower the window to the bottom of the Z order -void wxWindow::Lower() -{ - NSView *nsview = GetNSViewForSuperview(); - NSView *superview = [nsview superview]; - CocoaWindowCompareContext compareContext(nsview, [superview subviews]); - -#if 0 - NSLog(@"Target:\n%@\n", nsview); - NSLog(@"Before:\n%@\n", compareContext.subviews()); -#endif - [superview sortSubviewsUsingFunction: - CocoaLowerWindowCompareFunction - context: &compareContext]; -#if 0 - NSLog(@"After:\n%@\n", [superview subviews]); -#endif -} - -bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) -{ - return false; -} - -// Get the window with the focus -wxWindow *wxWindowBase::DoFindFocus() -{ - // Basically we are somewhat emulating the responder chain here except - // we are only loking for the first responder in the key window or - // upon failing to find one if the main window is different we look - // for the first responder in the main window. - - // Note that the firstResponder doesn't necessarily have to be an - // NSView but wxCocoaNSView::GetFromCocoa() will simply return - // NULL unless it finds its argument in its hash map. - - wxCocoaNSView *win; - - NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; - win = wxCocoaNSView::GetFromCocoa(static_cast([keyWindow firstResponder])); - if(win) - return win->GetWxWindow(); - - NSWindow *mainWindow = [[NSApplication sharedApplication] keyWindow]; - if(mainWindow == keyWindow) - return NULL; - win = wxCocoaNSView::GetFromCocoa(static_cast([mainWindow firstResponder])); - if(win) - return win->GetWxWindow(); - - return NULL; -} - -/* static */ wxWindow *wxWindowBase::GetCapture() -{ - // TODO - return wxWindowCocoa::sm_capturedWindow; -} - -wxWindow *wxGetActiveWindow() -{ - // TODO - return NULL; -} - -wxPoint wxGetMousePosition() -{ - // TODO - return wxDefaultPosition; -} - -wxMouseState wxGetMouseState() -{ - wxMouseState ms; - // TODO - return ms; -} - -wxWindow* wxFindWindowAtPointer(wxPoint& pt) -{ - pt = wxGetMousePosition(); - return NULL; -} - -// ======================================================================== -// wxCocoaMouseMovedEventSynthesizer -// ======================================================================== - -#define wxTRACE_COCOA_MouseMovedSynthesizer wxT("COCOA_MouseMovedSynthesizer") - -/* This class registers one run loop observer to cover all windows registered with it. - * It will register the observer when the first view is registerd and unregister the - * observer when the last view is unregistered. - * It is instantiated as a static s_mouseMovedSynthesizer in this file although there - * is no reason it couldn't be instantiated multiple times. - */ -class wxCocoaMouseMovedEventSynthesizer -{ - wxDECLARE_NO_COPY_CLASS(wxCocoaMouseMovedEventSynthesizer); -public: - wxCocoaMouseMovedEventSynthesizer() - { m_lastScreenMouseLocation = NSZeroPoint; - } - ~wxCocoaMouseMovedEventSynthesizer(); - void RegisterWxCocoaView(wxCocoaNSView *aView); - void UnregisterWxCocoaView(wxCocoaNSView *aView); - void SynthesizeMouseMovedEvent(); - -protected: - void AddRunLoopObserver(); - void RemoveRunLoopObserver(); - wxCFRef m_runLoopObserver; - std::list m_registeredViews; - NSPoint m_lastScreenMouseLocation; - static void SynthesizeMouseMovedEvent(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info); -}; - -void wxCocoaMouseMovedEventSynthesizer::RegisterWxCocoaView(wxCocoaNSView *aView) -{ - m_registeredViews.push_back(aView); - wxLogTrace(wxTRACE_COCOA_MouseMovedSynthesizer, wxT("Registered wxCocoaNSView=%p"), aView); - - if(!m_registeredViews.empty() && m_runLoopObserver == NULL) - { - AddRunLoopObserver(); - } -} - -void wxCocoaMouseMovedEventSynthesizer::UnregisterWxCocoaView(wxCocoaNSView *aView) -{ - m_registeredViews.remove(aView); - wxLogTrace(wxTRACE_COCOA_MouseMovedSynthesizer, wxT("Unregistered wxCocoaNSView=%p"), aView); - if(m_registeredViews.empty() && m_runLoopObserver != NULL) - { - RemoveRunLoopObserver(); - } -} - -wxCocoaMouseMovedEventSynthesizer::~wxCocoaMouseMovedEventSynthesizer() -{ - if(!m_registeredViews.empty()) - { - // This means failure to clean up so we report on it as a debug message. - wxLogDebug(wxT("There are still %d wxCocoaNSView registered to receive mouse moved events at static destruction time"), m_registeredViews.size()); - m_registeredViews.clear(); - } - if(m_runLoopObserver != NULL) - { - // This should not occur unless m_registeredViews was not empty since the last object unregistered should have done this. - wxLogDebug(wxT("Removing run loop observer during static destruction time.")); - RemoveRunLoopObserver(); - } -} - -void wxCocoaMouseMovedEventSynthesizer::SynthesizeMouseMovedEvent(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) -{ - reinterpret_cast(info)->SynthesizeMouseMovedEvent(); -} - -void wxCocoaMouseMovedEventSynthesizer::AddRunLoopObserver() -{ - CFRunLoopObserverContext observerContext = - { 0 - , this - , NULL - , NULL - , NULL - }; - - // The kCFRunLoopExit observation point is used such that we hook the run loop after it has already decided that - // it is going to exit which is generally for the purpose of letting the event loop process the next Cocoa event. - - // Executing our procedure within the run loop (e.g. kCFRunLoopBeforeWaiting which was used before) results - // in our observer procedure being called before the run loop has decided that it is going to return control to - // the Cocoa event loop. One major problem is uncovered by the wxGenericHyperlinkCtrl (consider this to be "user - // code") which changes the window's cursor and thus causes the cursor rectangle's to be invalidated. - - // Cocoa implements this invalidation using a delayed notification scheme whereby the resetCursorRects method - // won't be called until the CFRunLoop gets around to it. If the CFRunLoop has not yet exited then it will get - // around to it before letting the event loop do its work. This has some very odd effects on the way the - // newly created tracking rects function. In particular, we will often miss the mouseExited: message if the - // user flicks the mouse quickly enough such that the mouse is already outside of the tracking rect by the - // time the new one is built. - - // Observing from the kCFRunLoopExit point gives Cocoa's event loop an opportunity to chew some events before it cedes - // control back to the CFRunLoop, thus causing the delayed notifications to fire at an appropriate time and - // the mouseExited: message to be sent properly. - - m_runLoopObserver.reset(CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopExit, TRUE, 0, SynthesizeMouseMovedEvent, &observerContext)); - CFRunLoopAddObserver([[NSRunLoop currentRunLoop] getCFRunLoop], m_runLoopObserver, kCFRunLoopCommonModes); - wxLogTrace(wxTRACE_COCOA_TrackingRect, wxT("Added tracking rect run loop observer")); -} - -void wxCocoaMouseMovedEventSynthesizer::RemoveRunLoopObserver() -{ - CFRunLoopRemoveObserver([[NSRunLoop currentRunLoop] getCFRunLoop], m_runLoopObserver, kCFRunLoopCommonModes); - m_runLoopObserver.reset(); - wxLogTrace(wxTRACE_COCOA_TrackingRect, wxT("Removed tracking rect run loop observer")); -} - -void wxCocoaMouseMovedEventSynthesizer::SynthesizeMouseMovedEvent() -{ - NSPoint screenMouseLocation = [NSEvent mouseLocation]; - // Checking the last mouse location is done for a few reasons: - // 1. We are observing every iteration of the event loop so we'd be sending out a lot of extraneous events - // telling the app the mouse moved when the user hit a key for instance. - // 2. When handling the mouse moved event, user code can do something to the view which will cause Cocoa to - // call resetCursorRects. Cocoa does this by using a delayed notification which means the event loop gets - // pumped once which would mean that if we didn't check the mouse location we'd get into a never-ending - // loop causing the tracking rectangles to constantly be reset. - if(screenMouseLocation.x != m_lastScreenMouseLocation.x || screenMouseLocation.y != m_lastScreenMouseLocation.y) - { - m_lastScreenMouseLocation = screenMouseLocation; - wxLogTrace(wxTRACE_COCOA_TrackingRect, wxT("Synthesizing mouse moved at screen (%f,%f)"), screenMouseLocation.x, screenMouseLocation.y); - for(std::list::iterator i = m_registeredViews.begin(); i != m_registeredViews.end(); ++i) - { - (*i)->Cocoa_synthesizeMouseMoved(); - } - } -} - -// Singleton used for all views: -static wxCocoaMouseMovedEventSynthesizer s_mouseMovedSynthesizer; - -// ======================================================================== -// wxCocoaTrackingRectManager -// ======================================================================== - -wxCocoaTrackingRectManager::wxCocoaTrackingRectManager(wxWindow *window) -: m_window(window) -{ - m_isTrackingRectActive = false; - BuildTrackingRect(); -} - -void wxCocoaTrackingRectManager::ClearTrackingRect() -{ - if(m_isTrackingRectActive) - { - [m_window->GetNSView() removeTrackingRect:m_trackingRectTag]; - m_isTrackingRectActive = false; - wxLogTrace(wxTRACE_COCOA_TrackingRect, wxT("%s@%p: Removed tracking rect #%d"), m_window->GetClassInfo()->GetClassName(), m_window, m_trackingRectTag); - } - // If we were doing periodic events we need to clear those too - StopSynthesizingEvents(); -} - -void wxCocoaTrackingRectManager::StopSynthesizingEvents() -{ - s_mouseMovedSynthesizer.UnregisterWxCocoaView(m_window); -} - -void wxCocoaTrackingRectManager::BuildTrackingRect() -{ - // Pool here due to lack of one during wx init phase - wxAutoNSAutoreleasePool pool; - - wxASSERT_MSG(!m_isTrackingRectActive, wxT("Tracking rect was not cleared")); - - NSView *theView = m_window->GetNSView(); - - if([theView window] != nil) - { - NSRect visibleRect = [theView visibleRect]; - - m_trackingRectTag = [theView addTrackingRect:visibleRect owner:theView userData:NULL assumeInside:NO]; - m_trackingRectInWindowCoordinates = [theView convertRect:visibleRect toView:nil]; - m_isTrackingRectActive = true; - - wxLogTrace(wxTRACE_COCOA_TrackingRect, wxT("%s@%p: Added tracking rect #%d"), m_window->GetClassInfo()->GetClassName(), m_window, m_trackingRectTag); - } -} - -void wxCocoaTrackingRectManager::BeginSynthesizingEvents() -{ - s_mouseMovedSynthesizer.RegisterWxCocoaView(m_window); -} - -void wxCocoaTrackingRectManager::RebuildTrackingRectIfNeeded() -{ - if(m_isTrackingRectActive) - { - NSView *theView = m_window->GetNSView(); - NSRect currentRect = [theView convertRect:[theView visibleRect] toView:nil]; - if(NSEqualRects(m_trackingRectInWindowCoordinates,currentRect)) - { - wxLogTrace(wxTRACE_COCOA_TrackingRect, wxT("Ignored request to rebuild TR#%d"), m_trackingRectTag); - return; - } - } - RebuildTrackingRect(); -} - -void wxCocoaTrackingRectManager::RebuildTrackingRect() -{ - ClearTrackingRect(); - BuildTrackingRect(); -} - -wxCocoaTrackingRectManager::~wxCocoaTrackingRectManager() -{ - ClearTrackingRect(); -} - -bool wxCocoaTrackingRectManager::IsOwnerOfEvent(NSEvent *anEvent) -{ - return m_isTrackingRectActive && (m_trackingRectTag == [anEvent trackingNumber]); -} -