1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/window.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - more than minimal functionality
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
33 #include "wx/dcclient.h"
34 #include "wx/dcmemory.h"
37 #include "wx/layout.h"
38 #include "wx/dialog.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"
47 #include "wx/textctrl.h"
48 #include "wx/menuitem.h"
49 #include "wx/module.h"
52 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
53 #include "wx/ownerdrw.h"
56 #if wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/tooltip.h"
73 #include "wx/spinctrl.h"
74 #endif // wxUSE_SPINCTRL
76 #include "wx/notebook.h"
77 #include "wx/listctrl.h"
79 #ifndef __WXUNIVERSAL__
82 // ---------------------------------------------------------------------------
84 // ---------------------------------------------------------------------------
86 #if wxUSE_MENUS_NATIVE
87 wxMenu
*wxCurrentPopupMenu
= NULL
;
88 #endif // wxUSE_MENUS_NATIVE
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 // ---------------------------------------------------------------------------
96 // ---------------------------------------------------------------------------
98 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
100 #ifdef __WXUNIVERSAL__
101 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
103 #if wxUSE_EXTENDED_RTTI
105 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
106 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
107 // windows with negative ids never can be recreated anyway
109 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
114 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
116 // make wxWindowList known before the property is used
118 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
120 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
122 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
125 WX_DEFINE_FLAGS( wxWindowStyle
)
127 wxBEGIN_FLAGS( wxWindowStyle
)
128 // new style border flags, we put them first to
129 // use them for streaming out
131 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
132 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
133 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
134 wxFLAGS_MEMBER(wxBORDER_RAISED
)
135 wxFLAGS_MEMBER(wxBORDER_STATIC
)
136 wxFLAGS_MEMBER(wxBORDER_NONE
)
138 // old style border flags
139 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
140 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
141 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
142 wxFLAGS_MEMBER(wxRAISED_BORDER
)
143 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
144 wxFLAGS_MEMBER(wxBORDER
)
146 // standard window styles
147 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
148 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
149 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
150 wxFLAGS_MEMBER(wxWANTS_CHARS
)
151 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
152 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
153 wxFLAGS_MEMBER(wxVSCROLL
)
154 wxFLAGS_MEMBER(wxHSCROLL
)
156 wxEND_FLAGS( wxWindowStyle
)
158 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
159 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
160 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
161 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
162 // Always constructor Properties first
164 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
165 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
166 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
167 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
168 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
170 // Then all relations of the object graph
172 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
174 // and finally all other properties
176 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
177 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
178 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
179 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
180 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
182 // possible property candidates (not in xrc) or not valid in all subclasses
183 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
184 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
185 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
186 // MaxHeight, Width , MinHeight , Width
187 // TODO switch label to control and title to toplevels
189 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
190 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
191 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
192 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
197 wxEND_PROPERTIES_TABLE()
199 wxBEGIN_HANDLERS_TABLE(wxWindow
)
200 wxEND_HANDLERS_TABLE()
202 wxCONSTRUCTOR_DUMMY(wxWindow
)
205 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
207 #endif // __WXUNIVERSAL__/__WXPalm__
209 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
210 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
211 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
214 // ===========================================================================
216 // ===========================================================================
218 // ---------------------------------------------------------------------------
219 // wxWindow utility functions
220 // ---------------------------------------------------------------------------
222 // Find an item given the MS Windows id
223 wxWindow
*wxWindowPalm::FindItem(long id
) const
228 // Find an item given the MS Windows handle
229 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
235 bool wxGetKeyState(wxKeyCode key
)
237 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
238 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
245 // ----------------------------------------------------------------------------
246 // constructors and such
247 // ----------------------------------------------------------------------------
249 void wxWindowPalm::Init()
255 wxWindowPalm::~wxWindowPalm()
259 // real construction (Init() must have been called before!)
260 bool wxWindowPalm::Create(wxWindow
*parent
,
265 const wxString
& name
)
267 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
269 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
272 parent
->AddChild(this);
279 WXFORMPTR
wxWindowPalm::GetFormPtr()
283 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
288 // ---------------------------------------------------------------------------
290 // ---------------------------------------------------------------------------
292 void wxWindowPalm::SetFocus()
296 void wxWindowPalm::SetFocusFromKbd()
300 // Get the window with the focus
301 wxWindow
*wxWindowBase::DoFindFocus()
306 bool wxWindowPalm::Enable(bool enable
)
311 bool wxWindowPalm::Show(bool show
)
316 // Raise the window to the top of the Z order
317 void wxWindowPalm::Raise()
321 // Lower the window to the bottom of the Z order
322 void wxWindowPalm::Lower()
326 void wxWindowPalm::SetLabel( const wxString
& WXUNUSED(label
))
330 wxString
wxWindowPalm::GetLabel() const
332 return wxEmptyString
;
335 void wxWindowPalm::DoCaptureMouse()
339 void wxWindowPalm::DoReleaseMouse()
343 /* static */ wxWindow
*wxWindowBase::GetCapture()
348 bool wxWindowPalm::SetFont(const wxFont
& font
)
352 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
357 void wxWindowPalm::WarpPointer (int x
, int y
)
361 // ---------------------------------------------------------------------------
363 // ---------------------------------------------------------------------------
365 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
366 static inline int wxDirToWinStyle(int orient
)
371 int wxWindowPalm::GetScrollPos(int orient
) const
376 // This now returns the whole range, not just the number
377 // of positions that we can scroll.
378 int wxWindowPalm::GetScrollRange(int orient
) const
383 int wxWindowPalm::GetScrollThumb(int orient
) const
388 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
392 // New function that will replace some of the above.
393 void wxWindowPalm::SetScrollbar(int orient
,
401 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
405 bool wxWindowPalm::ScrollLines(int lines
)
410 bool wxWindowPalm::ScrollPages(int pages
)
415 // ----------------------------------------------------------------------------
417 // ----------------------------------------------------------------------------
419 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
424 // Setup background and foreground colours correctly
425 void wxWindowPalm::SetupColours()
429 void wxWindowPalm::OnInternalIdle()
433 // Set this window to be the child of 'parent'.
434 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
439 void wxWindowPalm::Freeze()
443 void wxWindowPalm::Thaw()
447 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
449 WinHandle handle
= (WinHandle
)GetHWND();
454 RectangleType dirtyRect
;
455 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
456 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
457 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
458 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
459 WinInvalidateRect(handle
, &dirtyRect
);
463 WinInvalidateWindow(handle
);
468 void wxWindowPalm::Update()
472 // ---------------------------------------------------------------------------
474 // ---------------------------------------------------------------------------
477 #if wxUSE_DRAG_AND_DROP
478 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
481 #endif // wxUSE_DRAG_AND_DROP
483 // old style file-manager drag&drop support: we retain the old-style
484 // DragAcceptFiles in parallel with SetDropTarget.
485 void wxWindowPalm::DragAcceptFiles(bool accept
)
489 // ----------------------------------------------------------------------------
491 // ----------------------------------------------------------------------------
495 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
499 #endif // wxUSE_TOOLTIPS
501 // ---------------------------------------------------------------------------
502 // moving and resizing
503 // ---------------------------------------------------------------------------
506 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
510 // Get size *available for subwindows* i.e. excluding menu bar etc.
511 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
515 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
523 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
527 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
531 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
535 // set the size of the window: if the dimensions are positive, just use them,
536 // but if any of them is equal to -1, it means that we must find the value for
537 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
538 // which case -1 is a valid value for x and y)
540 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
541 // the width/height to best suit our contents, otherwise we reuse the current
543 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
545 // get the current size and position...
546 int currentX
, currentY
;
547 GetPosition(¤tX
, ¤tY
);
548 int currentW
,currentH
;
549 GetSize(¤tW
, ¤tH
);
551 // ... and don't do anything (avoiding flicker) if it's already ok
552 if ( x
== currentX
&& y
== currentY
&&
553 width
== currentW
&& height
== currentH
)
558 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
560 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
563 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
565 wxSize size
= wxDefaultSize
;
566 if ( width
== wxDefaultCoord
)
568 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
570 size
= DoGetBestSize();
575 // just take the current one
580 if ( height
== wxDefaultCoord
)
582 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
584 if ( size
.x
== wxDefaultCoord
)
586 size
= DoGetBestSize();
588 //else: already called DoGetBestSize() above
594 // just take the current one
599 DoMoveWindow(x
, y
, width
, height
);
602 void wxWindowPalm::DoSetClientSize(int width
, int height
)
606 // ---------------------------------------------------------------------------
608 // ---------------------------------------------------------------------------
610 int wxWindowPalm::GetCharHeight() const
615 int wxWindowPalm::GetCharWidth() const
620 void wxWindowPalm::GetTextExtent(const wxString
& string
,
622 int *descent
, int *externalLeading
,
623 const wxFont
*theFont
) const
627 // ---------------------------------------------------------------------------
629 // ---------------------------------------------------------------------------
631 #if wxUSE_MENUS_NATIVE
633 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
634 // immediately, without waiting for the next event loop iteration
636 // NB: this function should probably be made public later as it can almost
637 // surely replace wxYield() elsewhere as well
638 static void wxYieldForCommandsOnly()
642 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
647 #endif // wxUSE_MENUS_NATIVE
649 // ----------------------------------------------------------------------------
650 // wxWindow <-> HWND map
651 // ----------------------------------------------------------------------------
653 wxWinHashTable
*wxWinHandleHash
= NULL
;
655 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
661 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
665 // ----------------------------------------------------------------------------
666 // various Palm specific class dependent functions
667 // ----------------------------------------------------------------------------
669 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
672 int& w
, int& h
) const
677 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
682 WXDWORD extendedStyle
)
687 // ===========================================================================
688 // Palm message handlers
689 // ===========================================================================
691 // ---------------------------------------------------------------------------
693 // ---------------------------------------------------------------------------
695 // Can be called from an application's OnPaint handler
696 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
700 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
704 // ---------------------------------------------------------------------------
705 // moving and resizing
706 // ---------------------------------------------------------------------------
708 bool wxWindowPalm::HandleMove(int x
, int y
)
713 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
718 // ---------------------------------------------------------------------------
720 // ---------------------------------------------------------------------------
722 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
727 // ---------------------------------------------------------------------------
729 // ---------------------------------------------------------------------------
731 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
732 WXWORD pos
, WXWINHANDLE control
)
738 // ===========================================================================
740 // ===========================================================================
742 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
749 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
754 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
758 #endif // # __WXUNIVERSAL__
759 #endif // wxUSE_HOTKEY