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"
81 // ---------------------------------------------------------------------------
83 // ---------------------------------------------------------------------------
85 #if wxUSE_MENUS_NATIVE
86 wxMenu
*wxCurrentPopupMenu
= NULL
;
87 #endif // wxUSE_MENUS_NATIVE
89 // ---------------------------------------------------------------------------
91 // ---------------------------------------------------------------------------
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
99 #ifdef __WXUNIVERSAL__
100 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
102 #if wxUSE_EXTENDED_RTTI
104 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
105 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
106 // windows with negative ids never can be recreated anyway
108 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
113 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
115 // make wxWindowList known before the property is used
117 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
119 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
121 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
124 WX_DEFINE_FLAGS( wxWindowStyle
)
126 wxBEGIN_FLAGS( wxWindowStyle
)
127 // new style border flags, we put them first to
128 // use them for streaming out
130 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
131 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
132 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
133 wxFLAGS_MEMBER(wxBORDER_RAISED
)
134 wxFLAGS_MEMBER(wxBORDER_STATIC
)
135 wxFLAGS_MEMBER(wxBORDER_NONE
)
137 // old style border flags
138 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
139 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
140 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
141 wxFLAGS_MEMBER(wxRAISED_BORDER
)
142 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
143 wxFLAGS_MEMBER(wxBORDER
)
145 // standard window styles
146 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
147 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
148 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
149 wxFLAGS_MEMBER(wxWANTS_CHARS
)
150 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
151 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
152 wxFLAGS_MEMBER(wxVSCROLL
)
153 wxFLAGS_MEMBER(wxHSCROLL
)
155 wxEND_FLAGS( wxWindowStyle
)
157 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
158 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
159 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
160 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
161 // Always constructor Properties first
163 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
164 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
165 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
166 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
167 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
169 // Then all relations of the object graph
171 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
173 // and finally all other properties
175 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
176 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
177 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
178 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
179 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
181 // possible property candidates (not in xrc) or not valid in all subclasses
182 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
183 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
184 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
185 // MaxHeight, Width , MinHeight , Width
186 // TODO switch label to control and title to toplevels
188 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
189 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
190 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
191 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
196 wxEND_PROPERTIES_TABLE()
198 wxBEGIN_HANDLERS_TABLE(wxWindow
)
199 wxEND_HANDLERS_TABLE()
201 wxCONSTRUCTOR_DUMMY(wxWindow
)
204 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
206 #endif // __WXUNIVERSAL__/__WXPalm__
208 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
209 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
210 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
213 // ===========================================================================
215 // ===========================================================================
217 // ---------------------------------------------------------------------------
218 // wxWindow utility functions
219 // ---------------------------------------------------------------------------
221 // Find an item given the MS Windows id
222 wxWindow
*wxWindowPalm::FindItem(long id
) const
227 // Find an item given the MS Windows handle
228 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
234 bool wxGetKeyState(wxKeyCode key
)
236 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
237 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
244 // ----------------------------------------------------------------------------
245 // constructors and such
246 // ----------------------------------------------------------------------------
248 void wxWindowPalm::Init()
254 wxWindowPalm::~wxWindowPalm()
258 // real construction (Init() must have been called before!)
259 bool wxWindowPalm::Create(wxWindow
*parent
,
264 const wxString
& name
)
266 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
268 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
271 parent
->AddChild(this);
278 WXFORMPTR
wxWindowPalm::GetFormPtr()
282 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
287 // ---------------------------------------------------------------------------
289 // ---------------------------------------------------------------------------
291 void wxWindowPalm::SetFocus()
295 void wxWindowPalm::SetFocusFromKbd()
299 // Get the window with the focus
300 wxWindow
*wxWindowBase::DoFindFocus()
305 bool wxWindowPalm::Enable(bool enable
)
310 bool wxWindowPalm::Show(bool show
)
315 // Raise the window to the top of the Z order
316 void wxWindowPalm::Raise()
320 // Lower the window to the bottom of the Z order
321 void wxWindowPalm::Lower()
325 void wxWindowPalm::SetLabel( const wxString
& WXUNUSED(label
))
329 wxString
wxWindowPalm::GetLabel() const
331 return wxEmptyString
;
334 void wxWindowPalm::DoCaptureMouse()
338 void wxWindowPalm::DoReleaseMouse()
342 /* static */ wxWindow
*wxWindowBase::GetCapture()
347 bool wxWindowPalm::SetFont(const wxFont
& font
)
351 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
356 void wxWindowPalm::WarpPointer (int x
, int y
)
360 // ---------------------------------------------------------------------------
362 // ---------------------------------------------------------------------------
364 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
365 static inline int wxDirToWinStyle(int orient
)
370 int wxWindowPalm::GetScrollPos(int orient
) const
375 // This now returns the whole range, not just the number
376 // of positions that we can scroll.
377 int wxWindowPalm::GetScrollRange(int orient
) const
382 int wxWindowPalm::GetScrollThumb(int orient
) const
387 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
391 // New function that will replace some of the above.
392 void wxWindowPalm::SetScrollbar(int orient
,
400 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
404 bool wxWindowPalm::ScrollLines(int lines
)
409 bool wxWindowPalm::ScrollPages(int pages
)
414 // ----------------------------------------------------------------------------
416 // ----------------------------------------------------------------------------
418 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
423 // Setup background and foreground colours correctly
424 void wxWindowPalm::SetupColours()
428 void wxWindowPalm::OnInternalIdle()
432 // Set this window to be the child of 'parent'.
433 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
438 void wxWindowPalm::Freeze()
442 void wxWindowPalm::Thaw()
446 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
448 WinHandle handle
= (WinHandle
)GetWinHandle();
453 RectangleType dirtyRect
;
454 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
455 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
456 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
457 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
458 WinInvalidateRect(handle
, &dirtyRect
);
462 WinInvalidateWindow(handle
);
467 void wxWindowPalm::Update()
471 // ---------------------------------------------------------------------------
473 // ---------------------------------------------------------------------------
476 #if wxUSE_DRAG_AND_DROP
477 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
480 #endif // wxUSE_DRAG_AND_DROP
482 // old style file-manager drag&drop support: we retain the old-style
483 // DragAcceptFiles in parallel with SetDropTarget.
484 void wxWindowPalm::DragAcceptFiles(bool accept
)
488 // ----------------------------------------------------------------------------
490 // ----------------------------------------------------------------------------
494 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
498 #endif // wxUSE_TOOLTIPS
500 // ---------------------------------------------------------------------------
501 // moving and resizing
502 // ---------------------------------------------------------------------------
505 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
509 // Get size *available for subwindows* i.e. excluding menu bar etc.
510 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
514 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
522 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
526 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
530 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
534 // set the size of the window: if the dimensions are positive, just use them,
535 // but if any of them is equal to -1, it means that we must find the value for
536 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
537 // which case -1 is a valid value for x and y)
539 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
540 // the width/height to best suit our contents, otherwise we reuse the current
542 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
544 // get the current size and position...
545 int currentX
, currentY
;
546 GetPosition(¤tX
, ¤tY
);
547 int currentW
,currentH
;
548 GetSize(¤tW
, ¤tH
);
550 // ... and don't do anything (avoiding flicker) if it's already ok
551 if ( x
== currentX
&& y
== currentY
&&
552 width
== currentW
&& height
== currentH
)
557 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
559 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
562 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
564 wxSize size
= wxDefaultSize
;
565 if ( width
== wxDefaultCoord
)
567 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
569 size
= DoGetBestSize();
574 // just take the current one
579 if ( height
== wxDefaultCoord
)
581 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
583 if ( size
.x
== wxDefaultCoord
)
585 size
= DoGetBestSize();
587 //else: already called DoGetBestSize() above
593 // just take the current one
598 DoMoveWindow(x
, y
, width
, height
);
601 void wxWindowPalm::DoSetClientSize(int width
, int height
)
605 // ---------------------------------------------------------------------------
607 // ---------------------------------------------------------------------------
609 int wxWindowPalm::GetCharHeight() const
614 int wxWindowPalm::GetCharWidth() const
619 void wxWindowPalm::GetTextExtent(const wxString
& string
,
621 int *descent
, int *externalLeading
,
622 const wxFont
*theFont
) const
626 // ---------------------------------------------------------------------------
628 // ---------------------------------------------------------------------------
630 #if wxUSE_MENUS_NATIVE
632 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
633 // immediately, without waiting for the next event loop iteration
635 // NB: this function should probably be made public later as it can almost
636 // surely replace wxYield() elsewhere as well
637 static void wxYieldForCommandsOnly()
641 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
646 #endif // wxUSE_MENUS_NATIVE
648 // ----------------------------------------------------------------------------
649 // wxWindow <-> HWND map
650 // ----------------------------------------------------------------------------
652 wxWinHashTable
*wxWinHandleHash
= NULL
;
654 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
660 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
664 // ----------------------------------------------------------------------------
665 // various Palm specific class dependent functions
666 // ----------------------------------------------------------------------------
668 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
671 int& w
, int& h
) const
676 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
681 WXDWORD extendedStyle
)
686 // ===========================================================================
687 // Palm message handlers
688 // ===========================================================================
690 // ---------------------------------------------------------------------------
692 // ---------------------------------------------------------------------------
694 // Can be called from an application's OnPaint handler
695 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
699 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
703 // ---------------------------------------------------------------------------
704 // moving and resizing
705 // ---------------------------------------------------------------------------
707 bool wxWindowPalm::HandleMove(int x
, int y
)
712 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
717 // ---------------------------------------------------------------------------
719 // ---------------------------------------------------------------------------
721 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
726 // ---------------------------------------------------------------------------
728 // ---------------------------------------------------------------------------
730 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
731 WXWORD pos
, WXWINHANDLE control
)
737 // ===========================================================================
739 // ===========================================================================
741 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
748 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
753 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
758 #endif // wxUSE_HOTKEY