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