]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/window.cpp
Tweaks for demos on MacOSX
[wxWidgets.git] / src / palmos / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/windows.cpp
3 // Purpose: wxWindow
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - more than minimal functionality
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/window.h"
29 #include "wx/accel.h"
30 #include "wx/menu.h"
31 #include "wx/dc.h"
32 #include "wx/dcclient.h"
33 #include "wx/dcmemory.h"
34 #include "wx/utils.h"
35 #include "wx/app.h"
36 #include "wx/layout.h"
37 #include "wx/dialog.h"
38 #include "wx/frame.h"
39 #include "wx/listbox.h"
40 #include "wx/button.h"
41 #include "wx/msgdlg.h"
42 #include "wx/settings.h"
43 #include "wx/statbox.h"
44 #endif
45
46 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
47 #include "wx/ownerdrw.h"
48 #endif
49
50 #include "wx/module.h"
51
52 #if wxUSE_DRAG_AND_DROP
53 #include "wx/dnd.h"
54 #endif
55
56 #if wxUSE_ACCESSIBILITY
57 #include "wx/access.h"
58 #endif
59
60 #include "wx/menuitem.h"
61 #include "wx/log.h"
62
63 #if wxUSE_TOOLTIPS
64 #include "wx/tooltip.h"
65 #endif
66
67 #if wxUSE_CARET
68 #include "wx/caret.h"
69 #endif // wxUSE_CARET
70
71 #if wxUSE_SPINCTRL
72 #include "wx/spinctrl.h"
73 #endif // wxUSE_SPINCTRL
74
75 #include "wx/intl.h"
76 #include "wx/log.h"
77
78 #include "wx/textctrl.h"
79 #include "wx/notebook.h"
80 #include "wx/listctrl.h"
81 #include "wx/window.h"
82
83 #include <Window.h>
84
85 // ---------------------------------------------------------------------------
86 // global variables
87 // ---------------------------------------------------------------------------
88
89 #if wxUSE_MENUS_NATIVE
90 wxMenu *wxCurrentPopupMenu = NULL;
91 #endif // wxUSE_MENUS_NATIVE
92
93 // ---------------------------------------------------------------------------
94 // private functions
95 // ---------------------------------------------------------------------------
96
97 // ---------------------------------------------------------------------------
98 // event tables
99 // ---------------------------------------------------------------------------
100
101 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
102 // method
103 #ifdef __WXUNIVERSAL__
104 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm, wxWindowBase)
105 #else // __WXPalm__
106 #if wxUSE_EXTENDED_RTTI
107
108 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
109 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
110 // windows with negative ids never can be recreated anyway
111
112 bool wxWindowStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & )
113 {
114 return false;
115 }
116
117 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow, wxWindowBase,"wx/window.h", wxWindowStreamingCallback)
118
119 // make wxWindowList known before the property is used
120
121 wxCOLLECTION_TYPE_INFO( wxWindow* , wxWindowList ) ;
122
123 template<> void wxCollectionToVariantArray( wxWindowList const &theList, wxxVariantArray &value)
124 {
125 wxListCollectionToVariantArray<wxWindowList::compatibility_iterator>( theList , value ) ;
126 }
127
128 WX_DEFINE_FLAGS( wxWindowStyle )
129
130 wxBEGIN_FLAGS( wxWindowStyle )
131 // new style border flags, we put them first to
132 // use them for streaming out
133
134 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
135 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
136 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
137 wxFLAGS_MEMBER(wxBORDER_RAISED)
138 wxFLAGS_MEMBER(wxBORDER_STATIC)
139 wxFLAGS_MEMBER(wxBORDER_NONE)
140
141 // old style border flags
142 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
143 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
144 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
145 wxFLAGS_MEMBER(wxRAISED_BORDER)
146 wxFLAGS_MEMBER(wxSTATIC_BORDER)
147 wxFLAGS_MEMBER(wxBORDER)
148
149 // standard window styles
150 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
151 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
152 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
153 wxFLAGS_MEMBER(wxWANTS_CHARS)
154 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
155 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
156 wxFLAGS_MEMBER(wxVSCROLL)
157 wxFLAGS_MEMBER(wxHSCROLL)
158
159 wxEND_FLAGS( wxWindowStyle )
160
161 wxBEGIN_PROPERTIES_TABLE(wxWindow)
162 wxEVENT_PROPERTY( Close , wxEVT_CLOSE_WINDOW , wxCloseEvent)
163 wxEVENT_PROPERTY( Create , wxEVT_CREATE , wxWindowCreateEvent )
164 wxEVENT_PROPERTY( Destroy , wxEVT_DESTROY , wxWindowDestroyEvent )
165 // Always constructor Properties first
166
167 wxREADONLY_PROPERTY( Parent,wxWindow*, GetParent, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
168 wxPROPERTY( Id,wxWindowID, SetId, GetId, wxID_ANY, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
169 wxPROPERTY( Position,wxPoint, SetPosition , GetPosition, wxDefaultPosition , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
170 wxPROPERTY( Size,wxSize, SetSize, GetSize, wxDefaultSize , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
171 wxPROPERTY( WindowStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
172
173 // Then all relations of the object graph
174
175 wxREADONLY_PROPERTY_COLLECTION( Children , wxWindowList , wxWindowBase* , GetWindowChildren , wxPROP_OBJECT_GRAPH /*flags*/ , wxT("Helpstring") , wxT("group"))
176
177 // and finally all other properties
178
179 wxPROPERTY( ExtraStyle , long , SetExtraStyle , GetExtraStyle , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
180 wxPROPERTY( BackgroundColour , wxColour , SetBackgroundColour , GetBackgroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
181 wxPROPERTY( ForegroundColour , wxColour , SetForegroundColour , GetForegroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
182 wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
183 wxPROPERTY( Shown , bool , Show , IsShown , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
184 #if 0
185 // possible property candidates (not in xrc) or not valid in all subclasses
186 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxT("") )
187 wxPROPERTY( Font , wxFont , SetFont , GetWindowFont , )
188 wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxT("") )
189 // MaxHeight, Width , MinHeight , Width
190 // TODO switch label to control and title to toplevels
191
192 wxPROPERTY( ThemeEnabled , bool , SetThemeEnabled , GetThemeEnabled , )
193 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
194 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
195 wxPROPERTY( AutoLayout , bool , SetAutoLayout , GetAutoLayout , )
196
197
198
199 #endif
200 wxEND_PROPERTIES_TABLE()
201
202 wxBEGIN_HANDLERS_TABLE(wxWindow)
203 wxEND_HANDLERS_TABLE()
204
205 wxCONSTRUCTOR_DUMMY(wxWindow)
206
207 #else
208 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
209 #endif
210 #endif // __WXUNIVERSAL__/__WXPalm__
211
212 BEGIN_EVENT_TABLE(wxWindowPalm, wxWindowBase)
213 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground)
214 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog)
215 END_EVENT_TABLE()
216
217 // ===========================================================================
218 // implementation
219 // ===========================================================================
220
221 // ---------------------------------------------------------------------------
222 // wxWindow utility functions
223 // ---------------------------------------------------------------------------
224
225 // Find an item given the MS Windows id
226 wxWindow *wxWindowPalm::FindItem(long id) const
227 {
228 return NULL;
229 }
230
231 // Find an item given the MS Windows handle
232 wxWindow *wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle, bool controlOnly) const
233 {
234 // TODO
235 return NULL;
236 }
237
238 // ----------------------------------------------------------------------------
239 // constructors and such
240 // ----------------------------------------------------------------------------
241
242 void wxWindowPalm::Init()
243 {
244 m_handle = 0;
245 }
246
247 // Destructor
248 wxWindowPalm::~wxWindowPalm()
249 {
250 }
251
252 // real construction (Init() must have been called before!)
253 bool wxWindowPalm::Create(wxWindow *parent,
254 wxWindowID id,
255 const wxPoint& pos,
256 const wxSize& size,
257 long style,
258 const wxString& name)
259 {
260 wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
261
262 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
263 return false;
264
265 parent->AddChild(this);
266
267 InheritAttributes();
268
269 return true;
270 }
271
272 WXFORMPTR wxWindowPalm::GetFormPtr()
273 {
274 return FrameForm;
275 }
276 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr)
277 {
278 FrameForm = FormPtr;
279 }
280
281 // ---------------------------------------------------------------------------
282 // basic operations
283 // ---------------------------------------------------------------------------
284
285 void wxWindowPalm::SetFocus()
286 {
287 }
288
289 void wxWindowPalm::SetFocusFromKbd()
290 {
291 }
292
293 // Get the window with the focus
294 wxWindow *wxWindowBase::DoFindFocus()
295 {
296 return NULL;
297 }
298
299 bool wxWindowPalm::Enable(bool enable)
300 {
301 return false;
302 }
303
304 bool wxWindowPalm::Show(bool show)
305 {
306 return false;
307 }
308
309 // Raise the window to the top of the Z order
310 void wxWindowPalm::Raise()
311 {
312 }
313
314 // Lower the window to the bottom of the Z order
315 void wxWindowPalm::Lower()
316 {
317 }
318
319 void wxWindowPalm::SetLabel( const wxString& WXUNUSED(label))
320 {
321 }
322
323 wxString wxWindowPalm::GetLabel() const
324 {
325 return wxEmptyString;
326 }
327
328 void wxWindowPalm::DoCaptureMouse()
329 {
330 }
331
332 void wxWindowPalm::DoReleaseMouse()
333 {
334 }
335
336 /* static */ wxWindow *wxWindowBase::GetCapture()
337 {
338 return NULL;
339 }
340
341 bool wxWindowPalm::SetFont(const wxFont& font)
342 {
343 return false;
344 }
345 bool wxWindowPalm::SetCursor(const wxCursor& cursor)
346 {
347 return false;
348 }
349
350 void wxWindowPalm::WarpPointer (int x, int y)
351 {
352 }
353
354 // ---------------------------------------------------------------------------
355 // scrolling stuff
356 // ---------------------------------------------------------------------------
357
358 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
359 static inline int wxDirToWinStyle(int orient)
360 {
361 return 0;
362 }
363
364 int wxWindowPalm::GetScrollPos(int orient) const
365 {
366 return 0;
367 }
368
369 // This now returns the whole range, not just the number
370 // of positions that we can scroll.
371 int wxWindowPalm::GetScrollRange(int orient) const
372 {
373 return 0;
374 }
375
376 int wxWindowPalm::GetScrollThumb(int orient) const
377 {
378 return 0;
379 }
380
381 void wxWindowPalm::SetScrollPos(int orient, int pos, bool refresh)
382 {
383 }
384
385 // New function that will replace some of the above.
386 void wxWindowPalm::SetScrollbar(int orient,
387 int pos,
388 int pageSize,
389 int range,
390 bool refresh)
391 {
392 }
393
394 void wxWindowPalm::ScrollWindow(int dx, int dy, const wxRect *prect)
395 {
396 }
397
398 bool wxWindowPalm::ScrollLines(int lines)
399 {
400 return false;
401 }
402
403 bool wxWindowPalm::ScrollPages(int pages)
404 {
405 return false;
406 }
407
408 // ----------------------------------------------------------------------------
409 // Style handling
410 // ----------------------------------------------------------------------------
411
412 WXDWORD wxWindowPalm::PalmGetStyle(long flags, WXDWORD *exstyle) const
413 {
414 return 0;
415 }
416
417 // Setup background and foreground colours correctly
418 void wxWindowPalm::SetupColours()
419 {
420 }
421
422 void wxWindowPalm::OnInternalIdle()
423 {
424 }
425
426 // Set this window to be the child of 'parent'.
427 bool wxWindowPalm::Reparent(wxWindowBase *parent)
428 {
429 return false;
430 }
431
432 void wxWindowPalm::Freeze()
433 {
434 }
435
436 void wxWindowPalm::Thaw()
437 {
438 }
439
440 void wxWindowPalm::Refresh(bool eraseBack, const wxRect *rect)
441 {
442 WinHandle handle = (WinHandle)GetWinHandle();
443 if(handle)
444 {
445 if(rect)
446 {
447 RectangleType dirtyRect;
448 dirtyRect.topLeft.x = rect->GetX() - 1;
449 dirtyRect.topLeft.y = rect->GetY() - 1;
450 dirtyRect.extent.x = rect->GetWidth() + 1;
451 dirtyRect.extent.y = rect->GetHeight() + 1;
452 WinInvalidateRect(handle, &dirtyRect);
453 }
454 else
455 {
456 WinInvalidateWindow(handle);
457 }
458 }
459 }
460
461 void wxWindowPalm::Update()
462 {
463 }
464
465 // ---------------------------------------------------------------------------
466 // drag and drop
467 // ---------------------------------------------------------------------------
468
469
470 #if wxUSE_DRAG_AND_DROP
471 void wxWindowPalm::SetDropTarget(wxDropTarget *pDropTarget)
472 {
473 }
474 #endif // wxUSE_DRAG_AND_DROP
475
476 // old style file-manager drag&drop support: we retain the old-style
477 // DragAcceptFiles in parallel with SetDropTarget.
478 void wxWindowPalm::DragAcceptFiles(bool accept)
479 {
480 }
481
482 // ----------------------------------------------------------------------------
483 // tooltips
484 // ----------------------------------------------------------------------------
485
486 #if wxUSE_TOOLTIPS
487
488 void wxWindowPalm::DoSetToolTip(wxToolTip *tooltip)
489 {
490 }
491
492 #endif // wxUSE_TOOLTIPS
493
494 // ---------------------------------------------------------------------------
495 // moving and resizing
496 // ---------------------------------------------------------------------------
497
498 // Get total size
499 void wxWindowPalm::DoGetSize(int *x, int *y) const
500 {
501 }
502
503 // Get size *available for subwindows* i.e. excluding menu bar etc.
504 void wxWindowPalm::DoGetClientSize(int *x, int *y) const
505 {
506 }
507
508 void wxWindowPalm::DoGetPosition(int *x, int *y) const
509 {
510 if(x)
511 *x = 0;
512 if(y)
513 *y = 0;
514 }
515
516 void wxWindowPalm::DoScreenToClient(int *x, int *y) const
517 {
518 }
519
520 void wxWindowPalm::DoClientToScreen(int *x, int *y) const
521 {
522 }
523
524 void wxWindowPalm::DoMoveWindow(int x, int y, int width, int height)
525 {
526 }
527
528 // set the size of the window: if the dimensions are positive, just use them,
529 // but if any of them is equal to -1, it means that we must find the value for
530 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
531 // which case -1 is a valid value for x and y)
532 //
533 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
534 // the width/height to best suit our contents, otherwise we reuse the current
535 // width/height
536 void wxWindowPalm::DoSetSize(int x, int y, int width, int height, int sizeFlags)
537 {
538 // get the current size and position...
539 int currentX, currentY;
540 GetPosition(&currentX, &currentY);
541 int currentW,currentH;
542 GetSize(&currentW, &currentH);
543
544 // ... and don't do anything (avoiding flicker) if it's already ok
545 if ( x == currentX && y == currentY &&
546 width == currentW && height == currentH )
547 {
548 return;
549 }
550
551 if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
552 x = currentX;
553 if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
554 y = currentY;
555
556 AdjustForParentClientOrigin(x, y, sizeFlags);
557
558 wxSize size = wxDefaultSize;
559 if ( width == wxDefaultCoord )
560 {
561 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
562 {
563 size = DoGetBestSize();
564 width = size.x;
565 }
566 else
567 {
568 // just take the current one
569 width = currentW;
570 }
571 }
572
573 if ( height == wxDefaultCoord )
574 {
575 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
576 {
577 if ( size.x == wxDefaultCoord )
578 {
579 size = DoGetBestSize();
580 }
581 //else: already called DoGetBestSize() above
582
583 height = size.y;
584 }
585 else
586 {
587 // just take the current one
588 height = currentH;
589 }
590 }
591
592 DoMoveWindow(x, y, width, height);
593 }
594
595 void wxWindowPalm::DoSetClientSize(int width, int height)
596 {
597 }
598
599 // ---------------------------------------------------------------------------
600 // text metrics
601 // ---------------------------------------------------------------------------
602
603 int wxWindowPalm::GetCharHeight() const
604 {
605 return 0;
606 }
607
608 int wxWindowPalm::GetCharWidth() const
609 {
610 return 0;
611 }
612
613 void wxWindowPalm::GetTextExtent(const wxString& string,
614 int *x, int *y,
615 int *descent, int *externalLeading,
616 const wxFont *theFont) const
617 {
618 }
619
620 // ---------------------------------------------------------------------------
621 // popup menu
622 // ---------------------------------------------------------------------------
623
624 #if wxUSE_MENUS_NATIVE
625
626 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
627 // immediately, without waiting for the next event loop iteration
628 //
629 // NB: this function should probably be made public later as it can almost
630 // surely replace wxYield() elsewhere as well
631 static void wxYieldForCommandsOnly()
632 {
633 }
634
635 bool wxWindowPalm::DoPopupMenu(wxMenu *menu, int x, int y)
636 {
637 return false;
638 }
639
640 #endif // wxUSE_MENUS_NATIVE
641
642 // ----------------------------------------------------------------------------
643 // wxWindow <-> HWND map
644 // ----------------------------------------------------------------------------
645
646 wxWinHashTable *wxWinHandleHash = NULL;
647
648 wxWindow *wxFindWinFromWinHandle(WXWINHANDLE handle)
649 {
650 // TODO
651 return NULL;
652 }
653
654 void wxRemoveHandleAssociation(wxWindowPalm *win)
655 {
656 }
657
658 // ----------------------------------------------------------------------------
659 // various Palm specific class dependent functions
660 // ----------------------------------------------------------------------------
661
662 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint& pos,
663 const wxSize& size,
664 int& x, int& y,
665 int& w, int& h) const
666 {
667 return false;
668 }
669
670 bool wxWindowPalm::PalmCreate(const wxChar *wclass,
671 const wxChar *title,
672 const wxPoint& pos,
673 const wxSize& size,
674 WXDWORD style,
675 WXDWORD extendedStyle)
676 {
677 return false;
678 }
679
680 // ===========================================================================
681 // Palm message handlers
682 // ===========================================================================
683
684 // ---------------------------------------------------------------------------
685 // painting
686 // ---------------------------------------------------------------------------
687
688 // Can be called from an application's OnPaint handler
689 void wxWindowPalm::OnPaint(wxPaintEvent& event)
690 {
691 }
692
693 void wxWindowPalm::OnEraseBackground(wxEraseEvent& event)
694 {
695 }
696
697 // ---------------------------------------------------------------------------
698 // moving and resizing
699 // ---------------------------------------------------------------------------
700
701 bool wxWindowPalm::HandleMove(int x, int y)
702 {
703 return false;
704 }
705
706 bool wxWindowPalm::HandleMoving(wxRect& rect)
707 {
708 return false;
709 }
710
711 // ---------------------------------------------------------------------------
712 // joystick
713 // ---------------------------------------------------------------------------
714
715 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
716 {
717 return false;
718 }
719
720 // ---------------------------------------------------------------------------
721 // scrolling
722 // ---------------------------------------------------------------------------
723
724 bool wxWindowPalm::PalmOnScroll(int orientation, WXWORD wParam,
725 WXWORD pos, WXWINHANDLE control)
726 {
727 // TODO
728 return false;
729 }
730
731 // ===========================================================================
732 // global functions
733 // ===========================================================================
734
735 void wxGetCharSize(WXWINHANDLE wnd, int *x, int *y, const wxFont *the_font)
736 {
737 // TODO
738 }
739
740 #if wxUSE_HOTKEY
741
742 bool wxWindowPalm::RegisterHotKey(int hotkeyId, int modifiers, int keycode)
743 {
744 return false;
745 }
746
747 bool wxWindowPalm::UnregisterHotKey(int hotkeyId)
748 {
749 return false;
750 }
751
752 #endif // wxUSE_HOTKEY