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