]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cocoa/window.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / cocoa / window.h
CommitLineData
fb896a32
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/cocoa/window.h
3// Purpose: wxWindowCocoa
4// Author: David Elliott
5// Modified by:
6// Created: 2002/12/26
fb896a32 7// Copyright: (c) 2002 David Elliott
8d8d3633 8// Licence: wxWindows licence
fb896a32
DE
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef __WX_COCOA_WINDOW_H__
12#define __WX_COCOA_WINDOW_H__
13
14#include "wx/cocoa/NSView.h"
15
d139c3a8
DE
16#ifdef __OBJC__
17 #import <Foundation/NSGeometry.h>
18#endif //def __OBJC__
19
15f37147
DE
20// We can only import Foundation/NSGeometry.h from Objective-C code but it's
21// nice to be able to use NSPoint and NSRect in the declarations of helper
22// methods so we must define them as opaque structs identically to the way
23// they are defined by the real header.
24// NOTE: We specifically use these regardless of C++ or Objective-C++ mode so
25// the compiler will complain if we got the definitions wrong. In regular
26// C++ mode there is no way to know if we got the definitons right so
27// we depend on at least one Objective-C++ file including this header.
28#if defined(__LP64__) || defined(NS_BUILD_32_LIKE_64)
29typedef struct CGPoint NSPoint;
30typedef struct CGRect NSRect;
31#else
32typedef struct _NSPoint NSPoint;
33typedef struct _NSRect NSRect;
34#endif
35
9d208085
DE
36DECLARE_WXCOCOA_OBJC_CLASS(NSAffineTransform);
37
a82b8141 38class wxWindowCocoaHider;
f298b203 39class wxWindowCocoaScrollView;
7c5a378f 40class wxCocoaTrackingRectManager;
a82b8141 41
fb896a32
DE
42// ========================================================================
43// wxWindowCocoa
44// ========================================================================
53a2db12 45class WXDLLIMPEXP_CORE wxWindowCocoa: public wxWindowBase, protected wxCocoaNSView
fb896a32
DE
46{
47 DECLARE_DYNAMIC_CLASS(wxWindowCocoa)
c0c133e1 48 wxDECLARE_NO_COPY_CLASS(wxWindowCocoa);
fb896a32 49 DECLARE_EVENT_TABLE()
b9505233 50 friend wxWindow *wxWindowBase::GetCapture();
f298b203 51 friend class wxWindowCocoaScrollView;
7c5a378f 52 friend class wxCocoaTrackingRectManager;
fb896a32
DE
53// ------------------------------------------------------------------------
54// initialization
55// ------------------------------------------------------------------------
56public:
57 wxWindowCocoa() { Init(); }
58 inline wxWindowCocoa(wxWindow *parent, wxWindowID winid,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = 0,
62 const wxString& name = wxPanelNameStr)
63 {
64 Init();
65 Create(parent, winid, pos, size, style, name);
66 }
67
68 virtual ~wxWindowCocoa();
69
70 bool Create(wxWindow *parent, wxWindowID winid,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = 0,
74 const wxString& name = wxPanelNameStr);
75protected:
76 void Init();
77// ------------------------------------------------------------------------
78// Cocoa specifics
79// ------------------------------------------------------------------------
80public:
a82b8141 81 // Returns the content NSView (where children are added, drawing performed)
fb896a32 82 inline WX_NSView GetNSView() { return m_cocoaNSView; }
a82b8141
DE
83 // Returns the NSView suitable for use as a subview
84 WX_NSView GetNSViewForSuperview() const;
85 // Returns the NSView that may be hidden/is being hidden
86 WX_NSView GetNSViewForHiding() const;
514e7b7b
DE
87 // Returns the NSView for non-client drawing
88 virtual WX_NSView GetNonClientNSView() { return GetNSViewForSuperview(); }
89 // Add/remove children
fb896a32
DE
90 void CocoaAddChild(wxWindowCocoa *child);
91 void CocoaRemoveFromParent(void);
9d208085
DE
92#ifdef __OBJC__
93 // Returns an autoreleased NSAffineTransform which can be applied
94 // to a graphics context currently using the view's coordinate system
95 // (such as the one locked when drawRect is called or after a call
96 // to [NSView lockFocus]) such that further drawing is done using
97 // the wxWidgets coordinate system.
98 WX_NSAffineTransform CocoaGetWxToBoundsTransform();
99#endif //def __OBJC__
fb896a32 100protected:
adb4816c 101 // actually enable/disable the cocoa control, overridden by subclasses
8e33de15 102 virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { }
adb4816c 103
816c52cf 104 void CocoaCreateNSScrollView();
69dbb709 105 void InitMouseEvent(wxMouseEvent &event, WX_NSEvent cocoaEvent);
f7e98dee 106 virtual wxWindow* GetWxWindow() const;
8ea5271e 107 virtual void Cocoa_FrameChanged(void);
7c5a378f 108 virtual void Cocoa_synthesizeMouseMoved(void);
8ea5271e 109 virtual bool Cocoa_drawRect(const NSRect &rect);
69dbb709
DE
110 virtual bool Cocoa_mouseDown(WX_NSEvent theEvent);
111 virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent);
112 virtual bool Cocoa_mouseUp(WX_NSEvent theEvent);
113 virtual bool Cocoa_mouseMoved(WX_NSEvent theEvent);
114 virtual bool Cocoa_mouseEntered(WX_NSEvent theEvent);
115 virtual bool Cocoa_mouseExited(WX_NSEvent theEvent);
116 virtual bool Cocoa_rightMouseDown(WX_NSEvent theEvent);
117 virtual bool Cocoa_rightMouseDragged(WX_NSEvent theEvent);
118 virtual bool Cocoa_rightMouseUp(WX_NSEvent theEvent);
119 virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent);
120 virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent);
121 virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent);
5558135c 122 virtual bool Cocoa_resetCursorRects();
7c5a378f
DE
123 virtual bool Cocoa_viewDidMoveToWindow();
124 virtual bool Cocoa_viewWillMoveToWindow(WX_NSWindow newWindow);
fb896a32
DE
125 void SetNSView(WX_NSView cocoaNSView);
126 WX_NSView m_cocoaNSView;
a82b8141 127 wxWindowCocoaHider *m_cocoaHider;
f298b203 128 wxWindowCocoaScrollView *m_wxCocoaScrollView;
55c5be5e 129 bool m_isInPaint;
7c5a378f 130 wxCocoaTrackingRectManager *m_visibleTrackingRectManager;
b9505233 131 static wxWindow *sm_capturedWindow;
a82b8141 132 virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView);
d139c3a8
DE
133 void SetInitialFrameRect(const wxPoint& pos, const wxSize& size);
134#ifdef __OBJC__
135 inline NSRect MakeDefaultNSRect(const wxSize& size)
136 {
137 // NOTE: position is 10,10 to make it "obvious" that it's out of place
138 return NSMakeRect(10.0,10.0,WidthDefault(size.x),HeightDefault(size.y));
139 }
34c9978d
DE
140 // These functions translate NSPoint or NSRect between the coordinate
141 // system of Cocoa's boudns rect and wx's coordinate system.
142 NSPoint CocoaTransformBoundsToWx(NSPoint pointBounds);
143 NSRect CocoaTransformBoundsToWx(NSRect rectBounds);
144 NSPoint CocoaTransformWxToBounds(NSPoint pointWx);
145 NSRect CocoaTransformWxToBounds(NSRect rectWx);
d139c3a8 146#endif //def __OBJC__
15f37147
DE
147 static wxPoint OriginInWxDisplayCoordinatesForRectInCocoaScreenCoordinates(NSRect windowFrame);
148 static NSPoint OriginInCocoaScreenCoordinatesForRectInWxDisplayCoordinates(wxCoord x, wxCoord y, wxCoord width, wxCoord height, bool keepOriginVisible);
fb896a32
DE
149// ------------------------------------------------------------------------
150// Implementation
151// ------------------------------------------------------------------------
152public:
153 /* Pure Virtuals */
154 // Raise the window to the top of the Z order
155 virtual void Raise();
156 // Lower the window to the bottom of the Z order
157 virtual void Lower();
158 // Set the focus to this window
159 virtual void SetFocus();
160 // Warp the pointer the given position
161 virtual void WarpPointer(int x_pos, int y_pos) ;
a8780ad5
DE
162 // Change the window's cursor
163 virtual bool SetCursor( const wxCursor &cursor );
fb896a32 164 // Send the window a refresh event
8d8d3633 165 virtual void Refresh(bool eraseBack = true, const wxRect *rect = NULL);
fb896a32
DE
166 // Set/get the window's font
167 virtual bool SetFont(const wxFont& f);
168// inline virtual wxFont& GetFont() const;
2a2d7a73
WS
169 virtual void SetLabel(const wxString& label);
170 virtual wxString GetLabel() const;
8d8d3633 171 // label handling
fb896a32
DE
172 // Get character size
173 virtual int GetCharHeight() const;
174 virtual int GetCharWidth() const;
6de70470 175 virtual void DoGetTextExtent(const wxString& string, int *x, int *y,
fb896a32
DE
176 int *descent = NULL,
177 int *externalLeading = NULL,
178 const wxFont *theFont = NULL) const;
179 // Scroll stuff
180 virtual void SetScrollbar(int orient, int pos, int thumbVisible,
8d8d3633
WS
181 int range, bool refresh = true);
182 virtual void SetScrollPos(int orient, int pos, bool refresh = true);
fb896a32
DE
183 virtual int GetScrollPos(int orient) const;
184 virtual int GetScrollThumb(int orient) const;
185 virtual int GetScrollRange(int orient) const;
186 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
816c52cf 187 virtual void DoSetVirtualSize(int x, int y);
fb896a32
DE
188 // Get the private handle (platform-dependent)
189 virtual WXWidget GetHandle() const;
190 // Convert client to screen coordinates
191 virtual void DoClientToScreen(int *x, int *y) const;
192 // Convert screen to client coordinates
193 virtual void DoScreenToClient(int *x, int *y) const;
194 // Capture/release mouse
195 virtual void DoCaptureMouse();
196 virtual void DoReleaseMouse();
197 // Get window position, relative to parent (or screen if no parent)
198 virtual void DoGetPosition(int *x, int *y) const;
199 // Get overall window size
200 virtual void DoGetSize(int *width, int *height) const;
201 // Get/set client (application-useable) size
202 virtual void DoGetClientSize(int *width, int *height) const;
203 virtual void DoSetClientSize(int width, int size);
5558135c
RN
204 // Set this window's tooltip
205 virtual void DoSetToolTip( wxToolTip *tip );
e08efb8d
DE
206 // Set the size of the wxWindow (the contentView of an NSWindow)
207 // wxTopLevelWindow will override this and set the NSWindow size
208 // such that the contentView will be this size
209 virtual void CocoaSetWxWindowSize(int width, int height);
fb896a32
DE
210 // Set overall size and position
211 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
212 virtual void DoMoveWindow(int x, int y, int width, int height);
213 // Popup a menu
214 virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
215
216 /* Other implementation */
217
218 // NOTE: typically Close() is not virtual, but we want this for Cocoa
219 virtual bool Close( bool force = false );
220 virtual bool Show( bool show = true );
47a8a4d5 221 virtual void DoEnable( bool enable );
2e992e06
VZ
222
223 virtual bool IsDoubleBuffered() const { return true; }
fb896a32
DE
224};
225
226#endif // __WX_COCOA_WINDOW_H__