]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/window.mm
more Unicode fixes
[wxWidgets.git] / src / cocoa / window.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/window.mm
3 // Purpose: wxWindowCocoa
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2002/12/26
7 // RCS-ID: $Id:
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/window.h"
13 #include "wx/log.h"
14
15 #include "wx/cocoa/autorelease.h"
16
17 #import <Appkit/NSView.h>
18 #import <AppKit/NSEvent.h>
19 #import <AppKit/NSScrollView.h>
20 #import <AppKit/NSColor.h>
21 #import <AppKit/NSClipView.h>
22
23 // ========================================================================
24 // wxWindowCocoaHider
25 // ========================================================================
26 class wxWindowCocoaHider: protected wxCocoaNSView
27 {
28 DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
29 public:
30 wxWindowCocoaHider(wxWindow *owner);
31 virtual ~wxWindowCocoaHider();
32 inline WX_NSView GetNSView() { return m_dummyNSView; }
33 protected:
34 wxWindowCocoa *m_owner;
35 WX_NSView m_dummyNSView;
36 virtual void Cocoa_FrameChanged(void);
37 private:
38 wxWindowCocoaHider();
39 };
40
41 // ========================================================================
42 // wxWindowCocoaScroller
43 // ========================================================================
44 class wxWindowCocoaScroller: protected wxCocoaNSView
45 {
46 DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
47 public:
48 wxWindowCocoaScroller(wxWindow *owner);
49 virtual ~wxWindowCocoaScroller();
50 inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
51 void ClientSizeToSize(int &width, int &height);
52 void DoGetClientSize(int *x, int *y) const;
53 void Encapsulate();
54 void Unencapsulate();
55 protected:
56 wxWindowCocoa *m_owner;
57 WX_NSScrollView m_cocoaNSScrollView;
58 virtual void Cocoa_FrameChanged(void);
59 private:
60 wxWindowCocoaScroller();
61 };
62
63 // ========================================================================
64 // wxWindowCocoaHider
65 // ========================================================================
66 wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
67 : m_owner(owner)
68 {
69 wxASSERT(owner);
70 wxASSERT(owner->GetNSViewForHiding());
71 m_dummyNSView = [[NSView alloc]
72 initWithFrame:[owner->GetNSViewForHiding() frame]];
73 AssociateNSView(m_dummyNSView);
74 }
75
76 wxWindowCocoaHider::~wxWindowCocoaHider()
77 {
78 DisassociateNSView(m_dummyNSView);
79 [m_dummyNSView release];
80 }
81
82 void wxWindowCocoaHider::Cocoa_FrameChanged(void)
83 {
84 // Keep the real window in synch with the dummy
85 wxASSERT(m_dummyNSView);
86 [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
87 }
88
89 // ========================================================================
90 // wxFlippedNSClipView
91 // ========================================================================
92 @interface wxFlippedNSClipView : NSClipView
93 - (BOOL)isFlipped;
94 @end
95
96 @implementation wxFlippedNSClipView : NSClipView
97 - (BOOL)isFlipped
98 {
99 return YES;
100 }
101
102 @end
103
104 // ========================================================================
105 // wxWindowCocoaScroller
106 // ========================================================================
107 wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
108 : m_owner(owner)
109 {
110 wxASSERT(owner);
111 wxASSERT(owner->GetNSView());
112 m_cocoaNSScrollView = [[NSScrollView alloc]
113 initWithFrame:[owner->GetNSView() frame]];
114 AssociateNSView(m_cocoaNSScrollView);
115
116 /* Replace the default NSClipView with a flipped one. This ensures
117 scrolling is "pinned" to the top-left instead of bottom-right. */
118 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
119 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
120 [m_cocoaNSScrollView setContentView:flippedClip];
121 [flippedClip release];
122
123 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
124 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
125 [m_cocoaNSScrollView setHasVerticalScroller: YES];
126 Encapsulate();
127 }
128
129 void wxWindowCocoaScroller::Encapsulate()
130 {
131 // NOTE: replaceSubView will cause m_cocaNSView to be released
132 // except when it hasn't been added into an NSView hierarchy in which
133 // case it doesn't need to be and this should work out to a no-op
134 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
135 // The NSView is still retained by owner
136 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
137 // Now it's also retained by the NSScrollView
138 }
139
140 void wxWindowCocoaScroller::Unencapsulate()
141 {
142 [m_cocoaNSScrollView setDocumentView: nil];
143 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
144 }
145
146 wxWindowCocoaScroller::~wxWindowCocoaScroller()
147 {
148 DisassociateNSView(m_cocoaNSScrollView);
149 [m_cocoaNSScrollView release];
150 }
151
152 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
153 {
154 NSSize frameSize = [NSScrollView
155 frameSizeForContentSize: NSMakeSize(width,height)
156 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
157 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
158 borderType: [m_cocoaNSScrollView borderType]];
159 width = frameSize.width;
160 height = frameSize.height;
161 }
162
163 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
164 {
165 NSSize nssize = [m_cocoaNSScrollView contentSize];
166 if(x)
167 *x = nssize.width;
168 if(y)
169 *y = nssize.height;
170 }
171
172 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
173 {
174 wxLogDebug("Cocoa_FrameChanged");
175 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
176 event.SetEventObject(m_owner);
177 m_owner->GetEventHandler()->ProcessEvent(event);
178 }
179
180 // ========================================================================
181 // wxWindowCocoa
182 // ========================================================================
183 // normally the base classes aren't included, but wxWindow is special
184 #ifdef __WXUNIVERSAL__
185 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
186 #else
187 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
188 #endif
189
190 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
191 END_EVENT_TABLE()
192
193 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
194
195 // Constructor
196 void wxWindowCocoa::Init()
197 {
198 InitBase();
199
200 m_cocoaNSView = NULL;
201 m_cocoaHider = NULL;
202 m_cocoaScroller = NULL;
203 m_isBeingDeleted = FALSE;
204 m_isInPaint = FALSE;
205 m_shouldBeEnabled = true;
206 }
207
208 // Constructor
209 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
210 const wxPoint& pos,
211 const wxSize& size,
212 long style,
213 const wxString& name)
214 {
215 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
216 return false;
217
218 // TODO: create the window
219 m_cocoaNSView = NULL;
220 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
221 [m_cocoaNSView release];
222
223 if (m_parent)
224 {
225 m_parent->AddChild(this);
226 m_parent->CocoaAddChild(this);
227 }
228 SetInitialFrameRect(pos,size);
229
230 return TRUE;
231 }
232
233 // Destructor
234 wxWindow::~wxWindow()
235 {
236 wxAutoNSAutoreleasePool pool;
237 DestroyChildren();
238
239 if(m_parent)
240 m_parent->RemoveChild(this);
241
242 CocoaRemoveFromParent();
243 delete m_cocoaHider;
244 delete m_cocoaScroller;
245 SetNSView(NULL);
246 }
247
248 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
249 {
250 NSView *childView = child->GetNSViewForSuperview();
251
252 wxASSERT(childView);
253 [m_cocoaNSView addSubview: childView];
254 child->m_isShown = !m_cocoaHider;
255 }
256
257 void wxWindowCocoa::CocoaRemoveFromParent(void)
258 {
259 [GetNSViewForSuperview() removeFromSuperview];
260 }
261
262 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
263 {
264 bool need_debug = cocoaNSView || m_cocoaNSView;
265 if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d",this,m_cocoaNSView,[m_cocoaNSView retainCount]);
266 DisassociateNSView(m_cocoaNSView);
267 [cocoaNSView retain];
268 [m_cocoaNSView release];
269 m_cocoaNSView = cocoaNSView;
270 AssociateNSView(m_cocoaNSView);
271 if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d",this,cocoaNSView,[cocoaNSView retainCount]);
272 }
273
274 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
275 {
276 return m_cocoaHider
277 ? m_cocoaHider->GetNSView()
278 : m_cocoaScroller
279 ? m_cocoaScroller->GetNSScrollView()
280 : m_cocoaNSView;
281 }
282
283 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
284 {
285 return m_cocoaScroller
286 ? m_cocoaScroller->GetNSScrollView()
287 : m_cocoaNSView;
288 }
289
290 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
291 {
292 wxLogDebug("Cocoa_drawRect");
293 // Recursion can happen if the event loop runs from within the paint
294 // handler. For instance, if an assertion dialog is shown.
295 // FIXME: This seems less than ideal.
296 if(m_isInPaint)
297 {
298 wxLogDebug("Paint event recursion!");
299 return false;
300 }
301 //FIXME: should probably turn that rect into the update region
302 m_isInPaint = TRUE;
303 wxPaintEvent event(m_windowId);
304 event.SetEventObject(this);
305 bool ret = GetEventHandler()->ProcessEvent(event);
306 m_isInPaint = FALSE;
307 return ret;
308 }
309
310 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
311 {
312 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],"Mouse event for different NSWindow");
313 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
314 NSRect cocoaRect = [m_cocoaNSView frame];
315 const wxPoint &clientorigin = GetClientAreaOrigin();
316 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
317 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
318
319 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
320 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
321 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
322 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
323
324 // TODO: set timestamp?
325 event.SetEventObject(this);
326 event.SetId(GetId());
327 }
328
329 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
330 {
331 wxMouseEvent event(wxEVT_MOTION);
332 InitMouseEvent(event,theEvent);
333 wxLogDebug("Mouse Drag @%d,%d",event.m_x,event.m_y);
334 return GetEventHandler()->ProcessEvent(event);
335 }
336
337 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
338 {
339 return false;
340 }
341
342 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
343 {
344 return false;
345 }
346
347 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
348 {
349 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
350 InitMouseEvent(event,theEvent);
351 wxLogDebug("Mouse Down @%d,%d num clicks=%d",event.m_x,event.m_y,[theEvent clickCount]);
352 return GetEventHandler()->ProcessEvent(event);
353 }
354
355 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
356 {
357 wxMouseEvent event(wxEVT_MOTION);
358 InitMouseEvent(event,theEvent);
359 event.m_leftDown = true;
360 wxLogDebug("Mouse Drag @%d,%d",event.m_x,event.m_y);
361 return GetEventHandler()->ProcessEvent(event);
362 }
363
364 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
365 {
366 wxMouseEvent event(wxEVT_LEFT_UP);
367 InitMouseEvent(event,theEvent);
368 wxLogDebug("Mouse Up @%d,%d",event.m_x,event.m_y);
369 return GetEventHandler()->ProcessEvent(event);
370 }
371
372 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
373 {
374 return false;
375 }
376
377 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
378 {
379 return false;
380 }
381
382 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
383 {
384 return false;
385 }
386
387 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
388 {
389 return false;
390 }
391
392 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
393 {
394 return false;
395 }
396
397 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
398 {
399 return false;
400 }
401
402 void wxWindowCocoa::Cocoa_FrameChanged(void)
403 {
404 wxLogDebug("Cocoa_FrameChanged");
405 wxSizeEvent event(GetSize(), m_windowId);
406 event.SetEventObject(this);
407 GetEventHandler()->ProcessEvent(event);
408 }
409
410 bool wxWindow::Close(bool force)
411 {
412 return false;
413 }
414
415 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
416 {
417 [[oldView superview] replaceSubview:oldView with:newView];
418 }
419
420 bool wxWindow::EnableSelfAndChildren(bool enable)
421 {
422 // If the state isn't changing, don't do anything
423 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
424 return false;
425 // Set the state of the Cocoa window
426 CocoaSetEnabled(m_isEnabled);
427 // Disable all children or (if enabling) return them to their proper state
428 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
429 node; node = node->GetNext())
430 {
431 node->GetData()->EnableSelfAndChildren(enable);
432 }
433 return true;
434 }
435
436 bool wxWindow::Enable(bool enable)
437 {
438 // Keep track of what the window SHOULD be doing
439 m_shouldBeEnabled = enable;
440 // If the parent is disabled for any reason, then this window will be too.
441 if(!IsTopLevel() && GetParent())
442 {
443 enable = enable && GetParent()->IsEnabled();
444 }
445 return EnableSelfAndChildren(enable);
446 }
447
448 bool wxWindow::Show(bool show)
449 {
450 wxAutoNSAutoreleasePool pool;
451 // If the window is marked as visible, then it shouldn't have a dummy view
452 // If the window is marked hidden, then it should have a dummy view
453 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
454 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),"wxWindow: m_isShown does not agree with m_dummyNSView");
455 // Return false if there isn't a window to show or hide
456 NSView *cocoaView = GetNSViewForHiding();
457 if(!cocoaView)
458 return false;
459 if(show)
460 {
461 // If state isn't changing, return false
462 if(!m_cocoaHider)
463 return false;
464 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
465 wxASSERT(![m_cocoaHider->GetNSView() superview]);
466 delete m_cocoaHider;
467 m_cocoaHider = NULL;
468 wxASSERT([cocoaView superview]);
469 }
470 else
471 {
472 // If state isn't changing, return false
473 if(m_cocoaHider)
474 return false;
475 m_cocoaHider = new wxWindowCocoaHider(this);
476 // NOTE: replaceSubview:with will cause m_cocaNSView to be
477 // (auto)released which balances out addSubview
478 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
479 // m_coocaNSView is now only retained by us
480 wxASSERT([m_cocoaHider->GetNSView() superview]);
481 wxASSERT(![cocoaView superview]);
482 }
483 m_isShown = show;
484 return true;
485 }
486
487 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
488 {
489 // wxLogDebug("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":".");
490 int currentX, currentY;
491 int currentW, currentH;
492 DoGetPosition(&currentX, &currentY);
493 DoGetSize(&currentW, &currentH);
494 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
495 x=currentX;
496 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
497 y=currentY;
498
499 AdjustForParentClientOrigin(x,y,sizeFlags);
500
501 wxSize size(-1,-1);
502
503 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
504 {
505 if(sizeFlags&wxSIZE_AUTO_WIDTH)
506 {
507 size=DoGetBestSize();
508 width=size.x;
509 }
510 else
511 width=currentW;
512 }
513 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
514 {
515 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
516 {
517 if(size.x==-1)
518 size=DoGetBestSize();
519 height=size.y;
520 }
521 else
522 height=currentH;
523 }
524 DoMoveWindow(x,y,width,height);
525 }
526
527 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
528 {
529 // wxLogDebug("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)",this,x,y,width,height);
530
531 NSView *nsview = GetNSViewForSuperview();
532 NSView *superview = [nsview superview];
533 wxCHECK_RET(superview,"NSView does not have a superview");
534 NSRect parentRect = [superview bounds];
535
536 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
537 [nsview setFrame: cocoaRect];
538 // Be sure to redraw the parent to reflect the changed position
539 [superview setNeedsDisplay:YES];
540 }
541
542 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
543 {
544 NSView *nsview = GetNSViewForSuperview();
545 NSView *superview = [nsview superview];
546 wxCHECK_RET(superview,"NSView does not have a superview");
547 NSRect parentRect = [superview bounds];
548 NSRect frameRect = [nsview frame];
549 if(size.x!=-1)
550 frameRect.size.width = size.x;
551 if(size.y!=-1)
552 frameRect.size.height = size.y;
553 frameRect.origin.x = pos.x;
554 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
555 [nsview setFrame: frameRect];
556 // Tell Cocoa to change the margin between the bottom of the superview
557 // and the bottom of the control. Keeps the control pinned to the top
558 // of its superview so that its position in the wxWindows coordinate
559 // system doesn't change.
560 if(![superview isFlipped])
561 [nsview setAutoresizingMask: NSViewMinYMargin];
562 }
563
564 // Get total size
565 void wxWindow::DoGetSize(int *w, int *h) const
566 {
567 NSRect cocoaRect = [GetNSViewForSuperview() frame];
568 if(w)
569 *w=(int)cocoaRect.size.width;
570 if(h)
571 *h=(int)cocoaRect.size.height;
572 // wxLogDebug("wxWindow=%p::DoGetSize = (%d,%d)",this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
573 }
574
575 void wxWindow::DoGetPosition(int *x, int *y) const
576 {
577 NSView *nsview = GetNSViewForSuperview();
578 NSView *superview = [nsview superview];
579 wxCHECK_RET(superview,"NSView does not have a superview");
580 NSRect parentRect = [superview bounds];
581
582 NSRect cocoaRect = [nsview frame];
583 if(x)
584 *x=(int)cocoaRect.origin.x;
585 if(y)
586 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
587 // wxLogDebug("wxWindow=%p::DoGetPosition = (%d,%d)",this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
588 }
589
590 WXWidget wxWindow::GetHandle() const
591 {
592 return m_cocoaNSView;
593 }
594
595 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
596 {
597 [m_cocoaNSView setNeedsDisplay:YES];
598 }
599
600 void wxWindow::SetFocus()
601 {
602 // TODO
603 }
604
605 void wxWindow::DoCaptureMouse()
606 {
607 // TODO
608 sm_capturedWindow = this;
609 }
610
611 void wxWindow::DoReleaseMouse()
612 {
613 // TODO
614 sm_capturedWindow = NULL;
615 }
616
617 void wxWindow::DoScreenToClient(int *x, int *y) const
618 {
619 // TODO
620 }
621
622 void wxWindow::DoClientToScreen(int *x, int *y) const
623 {
624 // TODO
625 }
626
627 // Get size *available for subwindows* i.e. excluding menu bar etc.
628 void wxWindow::DoGetClientSize(int *x, int *y) const
629 {
630 wxLogDebug("DoGetClientSize:");
631 if(m_cocoaScroller)
632 m_cocoaScroller->DoGetClientSize(x,y);
633 else
634 wxWindowCocoa::DoGetSize(x,y);
635 }
636
637 void wxWindow::DoSetClientSize(int width, int height)
638 {
639 wxLogDebug("DoSetClientSize=(%d,%d)",width,height);
640 if(m_cocoaScroller)
641 m_cocoaScroller->ClientSizeToSize(width,height);
642 CocoaSetWxWindowSize(width,height);
643 }
644
645 void wxWindow::CocoaSetWxWindowSize(int width, int height)
646 {
647 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
648 }
649
650 int wxWindow::GetCharHeight() const
651 {
652 // TODO
653 return 0;
654 }
655
656 int wxWindow::GetCharWidth() const
657 {
658 // TODO
659 return 0;
660 }
661
662 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
663 int *descent, int *externalLeading, const wxFont *theFont) const
664 {
665 // TODO
666 }
667
668 // Coordinates relative to the window
669 void wxWindow::WarpPointer (int x_pos, int y_pos)
670 {
671 // TODO
672 }
673
674 int wxWindow::GetScrollPos(int orient) const
675 {
676 // TODO
677 return 0;
678 }
679
680 // This now returns the whole range, not just the number
681 // of positions that we can scroll.
682 int wxWindow::GetScrollRange(int orient) const
683 {
684 // TODO
685 return 0;
686 }
687
688 int wxWindow::GetScrollThumb(int orient) const
689 {
690 // TODO
691 return 0;
692 }
693
694 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
695 {
696 // TODO
697 }
698
699 void wxWindow::CocoaCreateNSScrollView()
700 {
701 if(!m_cocoaScroller)
702 {
703 m_cocoaScroller = new wxWindowCocoaScroller(this);
704 }
705 }
706
707 // New function that will replace some of the above.
708 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
709 int range, bool refresh)
710 {
711 CocoaCreateNSScrollView();
712 // TODO
713 }
714
715 // Does a physical scroll
716 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
717 {
718 // TODO
719 }
720
721 void wxWindow::DoSetVirtualSize( int x, int y )
722 {
723 wxWindowBase::DoSetVirtualSize(x,y);
724 CocoaCreateNSScrollView();
725 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
726 }
727
728 bool wxWindow::SetFont(const wxFont& font)
729 {
730 // TODO
731 return TRUE;
732 }
733
734 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
735 {
736 // first should be ordered higher
737 if(first==target)
738 return NSOrderedDescending;
739 // second should be ordered higher
740 if(second==target)
741 return NSOrderedAscending;
742 return NSOrderedSame;
743 }
744
745 // Raise the window to the top of the Z order
746 void wxWindow::Raise()
747 {
748 // wxAutoNSAutoreleasePool pool;
749 NSView *nsview = GetNSViewForSuperview();
750 [[nsview superview] sortSubviewsUsingFunction:
751 CocoaRaiseWindowCompareFunction
752 context: nsview];
753 }
754
755 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
756 {
757 // first should be ordered lower
758 if(first==target)
759 return NSOrderedAscending;
760 // second should be ordered lower
761 if(second==target)
762 return NSOrderedDescending;
763 return NSOrderedSame;
764 }
765
766 // Lower the window to the bottom of the Z order
767 void wxWindow::Lower()
768 {
769 NSView *nsview = GetNSViewForSuperview();
770 [[nsview superview] sortSubviewsUsingFunction:
771 CocoaLowerWindowCompareFunction
772 context: nsview];
773 }
774
775 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
776 {
777 return FALSE;
778 }
779
780 // Get the window with the focus
781 wxWindow *wxWindowBase::FindFocus()
782 {
783 // TODO
784 return NULL;
785 }
786
787 /* static */ wxWindow *wxWindowBase::GetCapture()
788 {
789 // TODO
790 return wxWindowCocoa::sm_capturedWindow;
791 }
792
793 wxWindow *wxGetActiveWindow()
794 {
795 // TODO
796 return NULL;
797 }
798
799 wxPoint wxGetMousePosition()
800 {
801 // TODO
802 return wxDefaultPosition;
803 }
804
805 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
806 {
807 pt = wxGetMousePosition();
808 return NULL;
809 }
810