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