]> git.saurik.com Git - wxWidgets.git/blame - src/osx/nonownedwnd_osx.cpp
Removed wxTE_READONLY style from multi-line wxTextCtrls in combo and propgrid samples...
[wxWidgets.git] / src / osx / nonownedwnd_osx.cpp
CommitLineData
3ccc5735
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/nonownedwnd_osx.cpp
3// Purpose: implementation of wxNonOwnedWindow
4// Author: Stefan Csomor
5// Created: 2008-03-24
6// RCS-ID: $Id: nonownedwnd.cpp 50329 2007-11-29 17:00:58Z VS $
7// Copyright: (c) Stefan Csomor 2008
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifndef WX_PRECOMP
15 #include "wx/app.h"
e1f833da 16 #include "wx/log.h"
3ccc5735
SC
17#endif // WX_PRECOMP
18
19#include "wx/hashmap.h"
20#include "wx/evtloop.h"
21#include "wx/tooltip.h"
22#include "wx/nonownedwnd.h"
23
24#include "wx/osx/private.h"
25#include "wx/settings.h"
26#include "wx/frame.h"
27
28#if wxUSE_SYSTEM_OPTIONS
29 #include "wx/sysopt.h"
30#endif
31
32// ----------------------------------------------------------------------------
33// constants
34// ----------------------------------------------------------------------------
35
36// trace mask for activation tracing messages
37#define TRACE_ACTIVATE "activation"
38
39wxWindow* g_MacLastWindow = NULL ;
40
41// unified title and toolbar constant - not in Tiger headers, so we duplicate it here
42#define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
43
44// ---------------------------------------------------------------------------
45// wxWindowMac utility functions
46// ---------------------------------------------------------------------------
47
48// Find an item given the Macintosh Window Reference
49
50WX_DECLARE_HASH_MAP(WXWindow, wxNonOwnedWindow*, wxPointerHash, wxPointerEqual, MacWindowMap);
51
52static MacWindowMap wxWinMacWindowList;
53
54wxNonOwnedWindow *wxFindWindowFromWXWindow(WXWindow inWindowRef)
55{
56 MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
57
58 return (node == wxWinMacWindowList.end()) ? NULL : node->second;
59}
60
61void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) ;
62void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win)
63{
64 // adding NULL WindowRef is (first) surely a result of an error and
65 // nothing else :-)
66 wxCHECK_RET( inWindowRef != (WXWindow) NULL, wxT("attempt to add a NULL WindowRef to window list") );
67
68 wxWinMacWindowList[inWindowRef] = win;
69}
70
71void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) ;
72void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win)
73{
74 MacWindowMap::iterator it;
75 for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
76 {
77 if ( it->second == win )
78 {
79 wxWinMacWindowList.erase(it);
80 break;
81 }
82 }
83}
84
85wxNonOwnedWindow* wxNonOwnedWindow::GetFromWXWindow( WXWindow win )
86{
87 return wxFindWindowFromWXWindow( win );
88}
89
90// ----------------------------------------------------------------------------
91// wxNonOwnedWindow creation
92// ----------------------------------------------------------------------------
93
94IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl , wxObject )
95
96wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL;
97
98void wxNonOwnedWindow::Init()
99{
100 m_nowpeer = NULL;
101}
102
103bool wxNonOwnedWindow::Create(wxWindow *parent,
104 wxWindowID id,
105 const wxPoint& pos,
106 const wxSize& size,
107 long style,
108 const wxString& name)
109{
110 // init our fields
111 Init();
112
113 m_windowStyle = style;
114
115 SetName( name );
116
117 m_windowId = id == -1 ? NewControlId() : id;
118 m_windowStyle = style;
119 m_isShown = false;
120
121 // create frame.
122 int x = (int)pos.x;
123 int y = (int)pos.y;
124
125 wxRect display = wxGetClientDisplayRect() ;
126
127 if ( x == wxDefaultPosition.x )
128 x = display.x ;
129
130 if ( y == wxDefaultPosition.y )
131 y = display.y ;
132
133 int w = WidthDefault(size.x);
134 int h = HeightDefault(size.y);
135
524c47aa 136 m_nowpeer = wxNonOwnedWindowImpl::CreateNonOwnedWindow(this, parent, wxPoint(x,y) , wxSize(w,h) , style , GetExtraStyle(), name );
3ccc5735 137 wxAssociateWindowWithWXWindow( m_nowpeer->GetWXWindow() , this ) ;
3ccc5735 138 m_peer = wxWidgetImpl::CreateContentView(this);
3ccc5735
SC
139
140 DoSetWindowVariant( m_windowVariant ) ;
141
142 wxWindowCreateEvent event(this);
143 HandleWindowEvent(event);
144
145 SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ));
146
147 if ( parent )
148 parent->AddChild(this);
149
150 return true;
151}
152
153wxNonOwnedWindow::~wxNonOwnedWindow()
154{
c6212a0c 155 SendDestroyEvent();
03647350 156
3ccc5735 157 wxRemoveWXWindowAssociation( this ) ;
03647350 158
524c47aa 159 DestroyChildren();
03647350 160
524c47aa 161 delete m_nowpeer;
3ccc5735
SC
162
163 // avoid dangling refs
164 if ( s_macDeactivateWindow == this )
165 s_macDeactivateWindow = NULL;
166}
167
168// ----------------------------------------------------------------------------
169// wxNonOwnedWindow misc
170// ----------------------------------------------------------------------------
171
ab9a0b84
VZ
172bool wxNonOwnedWindow::OSXShowWithEffect(bool show,
173 wxShowEffect effect,
174 unsigned timeout)
03647350 175{
ab9a0b84
VZ
176 // Cocoa code needs to manage window visibility on its own and so calls
177 // wxWindow::Show() as needed but if we already changed the internal
178 // visibility flag here, Show() would do nothing, so avoid doing it
179#if wxOSX_USE_CARBON
180 if ( !wxWindow::Show(show) )
3ccc5735 181 return false;
ab9a0b84 182#endif // Carbon
3ccc5735 183
ab9a0b84
VZ
184 if ( effect == wxSHOW_EFFECT_NONE ||
185 !m_nowpeer || !m_nowpeer->ShowWithEffect(show, effect, timeout) )
186 return Show(show);
3ccc5735 187
ab9a0b84
VZ
188 if ( show )
189 {
190 // as apps expect a size event to occur when the window is shown,
191 // generate one when it is shown with effect too
192 wxSizeEvent event(GetSize(), m_windowId);
193 event.SetEventObject(this);
194 HandleWindowEvent(event);
195 }
3ccc5735 196
ab9a0b84 197 return true;
3ccc5735
SC
198}
199
200wxPoint wxNonOwnedWindow::GetClientAreaOrigin() const
201{
202 int left, top, width, height;
203 m_nowpeer->GetContentArea(left, top, width, height);
204 return wxPoint(left, top);
205}
206
207bool wxNonOwnedWindow::SetBackgroundColour(const wxColour& c )
03647350 208{
3ccc5735
SC
209 if ( !wxWindow::SetBackgroundColour(c) && m_hasBgCol )
210 return false ;
03647350 211
3ccc5735
SC
212 if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM )
213 {
524c47aa
SC
214 if ( m_nowpeer )
215 return m_nowpeer->SetBackgroundColour(c);
3ccc5735
SC
216 }
217 return true;
03647350 218}
3ccc5735
SC
219
220// Raise the window to the top of the Z order
221void wxNonOwnedWindow::Raise()
222{
223 m_nowpeer->Raise();
224}
225
226// Lower the window to the bottom of the Z order
227void wxNonOwnedWindow::Lower()
228{
229 m_nowpeer->Lower();
230}
231
232void wxNonOwnedWindow::HandleActivated( double timestampsec, bool didActivate )
233{
234 MacActivate( (int) (timestampsec * 1000) , didActivate);
235 wxActivateEvent wxevent(wxEVT_ACTIVATE, didActivate , GetId());
236 wxevent.SetTimestamp( (int) (timestampsec * 1000) );
237 wxevent.SetEventObject(this);
238 HandleWindowEvent(wxevent);
239}
240
241void wxNonOwnedWindow::HandleResized( double timestampsec )
242{
243 wxSizeEvent wxevent( GetSize() , GetId());
244 wxevent.SetTimestamp( (int) (timestampsec * 1000) );
245 wxevent.SetEventObject( this );
246 HandleWindowEvent(wxevent);
247 // we have to inform some controls that have to reset things
248 // relative to the toplevel window (e.g. OpenGL buffers)
249 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
250}
251
0faf03bf 252void wxNonOwnedWindow::HandleResizing( double WXUNUSED(timestampsec), wxRect* rect )
3ccc5735
SC
253{
254 wxRect r = *rect ;
255
256 // this is a EVT_SIZING not a EVT_SIZE type !
257 wxSizeEvent wxevent( r , GetId() ) ;
258 wxevent.SetEventObject( this ) ;
259 if ( HandleWindowEvent(wxevent) )
260 r = wxevent.GetRect() ;
261
262 if ( GetMaxWidth() != -1 && r.GetWidth() > GetMaxWidth() )
263 r.SetWidth( GetMaxWidth() ) ;
264 if ( GetMaxHeight() != -1 && r.GetHeight() > GetMaxHeight() )
265 r.SetHeight( GetMaxHeight() ) ;
266 if ( GetMinWidth() != -1 && r.GetWidth() < GetMinWidth() )
267 r.SetWidth( GetMinWidth() ) ;
268 if ( GetMinHeight() != -1 && r.GetHeight() < GetMinHeight() )
269 r.SetHeight( GetMinHeight() ) ;
270
271 *rect = r;
272 // TODO actuall this is too early, in case the window extents are adjusted
273 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
274}
275
276void wxNonOwnedWindow::HandleMoved( double timestampsec )
277{
278 wxMoveEvent wxevent( GetPosition() , GetId());
279 wxevent.SetTimestamp( (int) (timestampsec * 1000) );
280 wxevent.SetEventObject( this );
281 HandleWindowEvent(wxevent);
282}
283
284void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp)
285{
286 if (s_macDeactivateWindow)
287 {
288 wxLogTrace(TRACE_ACTIVATE,
289 wxT("Doing delayed deactivation of %p"),
290 s_macDeactivateWindow);
291
292 s_macDeactivateWindow->MacActivate(timestamp, false);
293 }
294}
295
296void wxNonOwnedWindow::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) )
297{
298 wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this);
299
300 if (s_macDeactivateWindow == this)
301 s_macDeactivateWindow = NULL;
302
303 MacDelayedDeactivation(timestamp);
304}
305
306bool wxNonOwnedWindow::Show(bool show)
307{
308 if ( !wxWindow::Show(show) )
309 return false;
310
311 if ( m_nowpeer )
312 m_nowpeer->Show(show);
03647350 313
3ccc5735
SC
314 if ( show )
315 {
316 // because apps expect a size event to occur at this moment
317 wxSizeEvent event(GetSize() , m_windowId);
318 event.SetEventObject(this);
319 HandleWindowEvent(event);
320 }
03647350 321
3ccc5735
SC
322 return true ;
323}
324
325bool wxNonOwnedWindow::SetTransparent(wxByte alpha)
326{
327 return m_nowpeer->SetTransparent(alpha);
328}
329
330
331bool wxNonOwnedWindow::CanSetTransparent()
332{
333 return m_nowpeer->CanSetTransparent();
334}
335
336
337void wxNonOwnedWindow::SetExtraStyle(long exStyle)
338{
339 if ( GetExtraStyle() == exStyle )
340 return ;
341
342 wxWindow::SetExtraStyle( exStyle ) ;
343
344 if ( m_nowpeer )
345 m_nowpeer->SetExtraStyle(exStyle);
346}
347
348bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style)
349{
350 if ( !wxWindow::SetBackgroundStyle(style) )
351 return false ;
03647350 352
4d949e7f 353 return m_nowpeer ? m_nowpeer->SetBackgroundStyle(style) : true;
3ccc5735
SC
354}
355
356void wxNonOwnedWindow::DoMoveWindow(int x, int y, int width, int height)
357{
b8afff01
SC
358 if ( m_nowpeer == NULL )
359 return;
360
3ccc5735
SC
361 m_cachedClippedRectValid = false ;
362
363 m_nowpeer->MoveWindow(x, y, width, height);
364 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
365}
366
367void wxNonOwnedWindow::DoGetPosition( int *x, int *y ) const
368{
b8afff01
SC
369 if ( m_nowpeer == NULL )
370 return;
371
3ccc5735
SC
372 int x1,y1 ;
373 m_nowpeer->GetPosition(x1, y1);
374
375 if (x)
376 *x = x1 ;
377 if (y)
378 *y = y1 ;
379}
380
381void wxNonOwnedWindow::DoGetSize( int *width, int *height ) const
382{
b8afff01
SC
383 if ( m_nowpeer == NULL )
384 return;
03647350 385
3ccc5735 386 int w,h;
03647350 387
3ccc5735
SC
388 m_nowpeer->GetSize(w, h);
389
390 if (width)
391 *width = w ;
392 if (height)
393 *height = h ;
394}
395
396void wxNonOwnedWindow::DoGetClientSize( int *width, int *height ) const
397{
b8afff01
SC
398 if ( m_nowpeer == NULL )
399 return;
400
3ccc5735
SC
401 int left, top, w, h;
402 m_nowpeer->GetContentArea(left, top, w, h);
403
404 if (width)
405 *width = w ;
406 if (height)
407 *height = h ;
408}
409
410
411void wxNonOwnedWindow::Update()
412{
413 m_nowpeer->Update();
414}
415
416WXWindow wxNonOwnedWindow::GetWXWindow() const
417{
418 return m_nowpeer ? m_nowpeer->GetWXWindow() : NULL;
419}
420
421// ---------------------------------------------------------------------------
422// Shape implementation
423// ---------------------------------------------------------------------------
424
425
8e88e984 426bool wxNonOwnedWindow::DoSetShape(const wxRegion& region)
3ccc5735
SC
427{
428 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
9a83f860 429 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
3ccc5735
SC
430
431 // The empty region signifies that the shape
432 // should be removed from the window.
433 if ( region.IsEmpty() )
434 {
435 wxSize sz = GetClientSize();
436 wxRegion rgn(0, 0, sz.x, sz.y);
437 if ( rgn.IsEmpty() )
438 return false ;
439 else
8e88e984 440 return DoSetShape(rgn);
3ccc5735
SC
441 }
442
443 return m_nowpeer->SetShape(region);
444}