1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/windows.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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "window.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/window.h"
37 #include "wx/dcclient.h"
38 #include "wx/dcmemory.h"
41 #include "wx/layout.h"
42 #include "wx/dialog.h"
44 #include "wx/listbox.h"
45 #include "wx/button.h"
46 #include "wx/msgdlg.h"
47 #include "wx/settings.h"
48 #include "wx/statbox.h"
51 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
52 #include "wx/ownerdrw.h"
55 #include "wx/module.h"
57 #if wxUSE_DRAG_AND_DROP
61 #if wxUSE_ACCESSIBILITY
62 #include "wx/access.h"
65 #include "wx/menuitem.h"
69 #include "wx/tooltip.h"
77 #include "wx/spinctrl.h"
78 #endif // wxUSE_SPINCTRL
83 #include "wx/textctrl.h"
84 #include "wx/notebook.h"
85 #include "wx/listctrl.h"
86 #include "wx/window.h"
88 // ---------------------------------------------------------------------------
90 // ---------------------------------------------------------------------------
92 #if wxUSE_MENUS_NATIVE
93 wxMenu
*wxCurrentPopupMenu
= NULL
;
94 #endif // wxUSE_MENUS_NATIVE
96 // ---------------------------------------------------------------------------
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
106 #ifdef __WXUNIVERSAL__
107 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
109 #if wxUSE_EXTENDED_RTTI
111 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
112 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
113 // windows with negative ids never can be recreated anyway
115 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
120 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
122 // make wxWindowList known before the property is used
124 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
126 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
128 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
131 WX_DEFINE_FLAGS( wxWindowStyle
)
133 wxBEGIN_FLAGS( wxWindowStyle
)
134 // new style border flags, we put them first to
135 // use them for streaming out
137 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
138 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
139 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
140 wxFLAGS_MEMBER(wxBORDER_RAISED
)
141 wxFLAGS_MEMBER(wxBORDER_STATIC
)
142 wxFLAGS_MEMBER(wxBORDER_NONE
)
144 // old style border flags
145 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
146 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
147 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
148 wxFLAGS_MEMBER(wxRAISED_BORDER
)
149 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
150 wxFLAGS_MEMBER(wxBORDER
)
152 // standard window styles
153 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
154 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
155 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
156 wxFLAGS_MEMBER(wxWANTS_CHARS
)
157 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
158 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
159 wxFLAGS_MEMBER(wxVSCROLL
)
160 wxFLAGS_MEMBER(wxHSCROLL
)
162 wxEND_FLAGS( wxWindowStyle
)
164 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
165 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
166 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
167 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
168 // Always constructor Properties first
170 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
171 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
172 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
173 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
174 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
176 // Then all relations of the object graph
178 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
180 // and finally all other properties
182 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
183 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
184 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
185 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
186 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
188 // possible property candidates (not in xrc) or not valid in all subclasses
189 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
190 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
191 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
192 // MaxHeight, Width , MinHeight , Width
193 // TODO switch label to control and title to toplevels
195 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
196 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
197 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
198 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
203 wxEND_PROPERTIES_TABLE()
205 wxBEGIN_HANDLERS_TABLE(wxWindow
)
206 wxEND_HANDLERS_TABLE()
208 wxCONSTRUCTOR_DUMMY(wxWindow
)
211 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
213 #endif // __WXUNIVERSAL__/__WXPalm__
215 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
216 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
217 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
220 // ===========================================================================
222 // ===========================================================================
224 // ---------------------------------------------------------------------------
225 // wxWindow utility functions
226 // ---------------------------------------------------------------------------
228 // Find an item given the MS Windows id
229 wxWindow
*wxWindowPalm::FindItem(long id
) const
234 // Find an item given the MS Windows handle
235 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
241 // ----------------------------------------------------------------------------
242 // constructors and such
243 // ----------------------------------------------------------------------------
245 void wxWindowPalm::Init()
251 wxWindowPalm::~wxWindowPalm()
255 // real construction (Init() must have been called before!)
256 bool wxWindowPalm::Create(wxWindow
*parent
,
261 const wxString
& name
)
263 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
265 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
268 parent
->AddChild(this);
275 FormType
*wxWindowPalm::GetFormPtr()
279 void wxWindowPalm::SetFormPtr(FormType
*FormPtr
)
284 // ---------------------------------------------------------------------------
286 // ---------------------------------------------------------------------------
288 void wxWindowPalm::SetFocus()
292 void wxWindowPalm::SetFocusFromKbd()
296 // Get the window with the focus
297 wxWindow
*wxWindowBase::DoFindFocus()
302 bool wxWindowPalm::Enable(bool enable
)
307 bool wxWindowPalm::Show(bool show
)
312 // Raise the window to the top of the Z order
313 void wxWindowPalm::Raise()
317 // Lower the window to the bottom of the Z order
318 void wxWindowPalm::Lower()
322 void wxWindowPalm::SetTitle( const wxString
& title
)
326 wxString
wxWindowPalm::GetTitle() const
328 return wxEmptyString
;
331 void wxWindowPalm::DoCaptureMouse()
335 void wxWindowPalm::DoReleaseMouse()
339 /* static */ wxWindow
*wxWindowBase::GetCapture()
344 bool wxWindowPalm::SetFont(const wxFont
& font
)
348 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
353 void wxWindowPalm::WarpPointer (int x
, int y
)
357 // ---------------------------------------------------------------------------
359 // ---------------------------------------------------------------------------
361 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
362 static inline int wxDirToWinStyle(int orient
)
367 int wxWindowPalm::GetScrollPos(int orient
) const
372 // This now returns the whole range, not just the number
373 // of positions that we can scroll.
374 int wxWindowPalm::GetScrollRange(int orient
) const
379 int wxWindowPalm::GetScrollThumb(int orient
) const
384 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
388 // New function that will replace some of the above.
389 void wxWindowPalm::SetScrollbar(int orient
,
397 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
401 bool wxWindowPalm::ScrollLines(int lines
)
406 bool wxWindowPalm::ScrollPages(int pages
)
411 // ----------------------------------------------------------------------------
413 // ----------------------------------------------------------------------------
415 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
420 // Setup background and foreground colours correctly
421 void wxWindowPalm::SetupColours()
425 void wxWindowPalm::OnInternalIdle()
429 // Set this window to be the child of 'parent'.
430 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
435 void wxWindowPalm::Freeze()
439 void wxWindowPalm::Thaw()
443 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
445 WinHandle handle
= GetWinHandle();
450 RectangleType dirtyRect
;
451 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
452 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
453 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
454 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
455 WinInvalidateRect(handle
, &dirtyRect
);
459 WinInvalidateWindow(handle
);
464 void wxWindowPalm::Update()
468 // ---------------------------------------------------------------------------
470 // ---------------------------------------------------------------------------
473 #if wxUSE_DRAG_AND_DROP
474 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
477 #endif // wxUSE_DRAG_AND_DROP
479 // old style file-manager drag&drop support: we retain the old-style
480 // DragAcceptFiles in parallel with SetDropTarget.
481 void wxWindowPalm::DragAcceptFiles(bool accept
)
485 // ----------------------------------------------------------------------------
487 // ----------------------------------------------------------------------------
491 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
495 #endif // wxUSE_TOOLTIPS
497 // ---------------------------------------------------------------------------
498 // moving and resizing
499 // ---------------------------------------------------------------------------
502 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
506 // Get size *available for subwindows* i.e. excluding menu bar etc.
507 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
511 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
519 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
523 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
527 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
531 // set the size of the window: if the dimensions are positive, just use them,
532 // but if any of them is equal to -1, it means that we must find the value for
533 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
534 // which case -1 is a valid value for x and y)
536 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
537 // the width/height to best suit our contents, otherwise we reuse the current
539 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
541 // get the current size and position...
542 int currentX
, currentY
;
543 GetPosition(¤tX
, ¤tY
);
544 int currentW
,currentH
;
545 GetSize(¤tW
, ¤tH
);
547 // ... and don't do anything (avoiding flicker) if it's already ok
548 if ( x
== currentX
&& y
== currentY
&&
549 width
== currentW
&& height
== currentH
)
554 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
556 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
559 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
561 wxSize size
= wxDefaultSize
;
562 if ( width
== wxDefaultCoord
)
564 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
566 size
= DoGetBestSize();
571 // just take the current one
576 if ( height
== wxDefaultCoord
)
578 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
580 if ( size
.x
== wxDefaultCoord
)
582 size
= DoGetBestSize();
584 //else: already called DoGetBestSize() above
590 // just take the current one
595 DoMoveWindow(x
, y
, width
, height
);
598 void wxWindowPalm::DoSetClientSize(int width
, int height
)
602 // ---------------------------------------------------------------------------
604 // ---------------------------------------------------------------------------
606 int wxWindowPalm::GetCharHeight() const
611 int wxWindowPalm::GetCharWidth() const
616 void wxWindowPalm::GetTextExtent(const wxString
& string
,
618 int *descent
, int *externalLeading
,
619 const wxFont
*theFont
) const
623 // ---------------------------------------------------------------------------
625 // ---------------------------------------------------------------------------
627 #if wxUSE_MENUS_NATIVE
629 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
630 // immediately, without waiting for the next event loop iteration
632 // NB: this function should probably be made public later as it can almost
633 // surely replace wxYield() elsewhere as well
634 static void wxYieldForCommandsOnly()
638 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
643 #endif // wxUSE_MENUS_NATIVE
645 // ----------------------------------------------------------------------------
646 // wxWindow <-> HWND map
647 // ----------------------------------------------------------------------------
649 wxWinHashTable
*wxWinHandleHash
= NULL
;
651 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
657 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
661 // ----------------------------------------------------------------------------
662 // various Palm specific class dependent functions
663 // ----------------------------------------------------------------------------
665 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
668 int& w
, int& h
) const
673 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
678 WXDWORD extendedStyle
)
683 // ===========================================================================
684 // Palm message handlers
685 // ===========================================================================
687 // ---------------------------------------------------------------------------
689 // ---------------------------------------------------------------------------
691 // Can be called from an application's OnPaint handler
692 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
696 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
700 // ---------------------------------------------------------------------------
701 // moving and resizing
702 // ---------------------------------------------------------------------------
704 bool wxWindowPalm::HandleMove(int x
, int y
)
709 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
714 // ---------------------------------------------------------------------------
716 // ---------------------------------------------------------------------------
718 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
723 // ---------------------------------------------------------------------------
725 // ---------------------------------------------------------------------------
727 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
728 WXWORD pos
, WXWINHANDLE control
)
734 // ===========================================================================
736 // ===========================================================================
738 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
745 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
750 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
755 #endif // wxUSE_HOTKEY