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 // 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"
49 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
50 #include "wx/ownerdrw.h"
53 #include "wx/module.h"
55 #if wxUSE_DRAG_AND_DROP
59 #if wxUSE_ACCESSIBILITY
60 #include "wx/access.h"
63 #include "wx/menuitem.h"
66 #include "wx/tooltip.h"
74 #include "wx/spinctrl.h"
75 #endif // wxUSE_SPINCTRL
77 #include "wx/textctrl.h"
78 #include "wx/notebook.h"
79 #include "wx/listctrl.h"
80 #include "wx/window.h"
84 // ---------------------------------------------------------------------------
86 // ---------------------------------------------------------------------------
88 #if wxUSE_MENUS_NATIVE
89 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 #endif // wxUSE_MENUS_NATIVE
92 // ---------------------------------------------------------------------------
94 // ---------------------------------------------------------------------------
96 // ---------------------------------------------------------------------------
98 // ---------------------------------------------------------------------------
100 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
102 #ifdef __WXUNIVERSAL__
103 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
105 #if wxUSE_EXTENDED_RTTI
107 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
108 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
109 // windows with negative ids never can be recreated anyway
111 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
116 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
118 // make wxWindowList known before the property is used
120 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
122 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
124 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
127 WX_DEFINE_FLAGS( wxWindowStyle
)
129 wxBEGIN_FLAGS( wxWindowStyle
)
130 // new style border flags, we put them first to
131 // use them for streaming out
133 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
134 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
135 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
136 wxFLAGS_MEMBER(wxBORDER_RAISED
)
137 wxFLAGS_MEMBER(wxBORDER_STATIC
)
138 wxFLAGS_MEMBER(wxBORDER_NONE
)
140 // old style border flags
141 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
142 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
143 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
144 wxFLAGS_MEMBER(wxRAISED_BORDER
)
145 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
146 wxFLAGS_MEMBER(wxBORDER
)
148 // standard window styles
149 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
150 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
151 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
152 wxFLAGS_MEMBER(wxWANTS_CHARS
)
153 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
154 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
155 wxFLAGS_MEMBER(wxVSCROLL
)
156 wxFLAGS_MEMBER(wxHSCROLL
)
158 wxEND_FLAGS( wxWindowStyle
)
160 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
161 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
162 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
163 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
164 // Always constructor Properties first
166 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
167 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
168 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
169 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
170 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
172 // Then all relations of the object graph
174 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
176 // and finally all other properties
178 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
179 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
180 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
181 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
182 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
184 // possible property candidates (not in xrc) or not valid in all subclasses
185 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
186 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
187 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
188 // MaxHeight, Width , MinHeight , Width
189 // TODO switch label to control and title to toplevels
191 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
192 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
193 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
194 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
199 wxEND_PROPERTIES_TABLE()
201 wxBEGIN_HANDLERS_TABLE(wxWindow
)
202 wxEND_HANDLERS_TABLE()
204 wxCONSTRUCTOR_DUMMY(wxWindow
)
207 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
209 #endif // __WXUNIVERSAL__/__WXPalm__
211 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
212 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
213 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
216 // ===========================================================================
218 // ===========================================================================
220 // ---------------------------------------------------------------------------
221 // wxWindow utility functions
222 // ---------------------------------------------------------------------------
224 // Find an item given the MS Windows id
225 wxWindow
*wxWindowPalm::FindItem(long id
) const
230 // Find an item given the MS Windows handle
231 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
237 // ----------------------------------------------------------------------------
238 // constructors and such
239 // ----------------------------------------------------------------------------
241 void wxWindowPalm::Init()
247 wxWindowPalm::~wxWindowPalm()
251 // real construction (Init() must have been called before!)
252 bool wxWindowPalm::Create(wxWindow
*parent
,
257 const wxString
& name
)
259 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
261 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
264 parent
->AddChild(this);
271 WXFORMPTR
wxWindowPalm::GetFormPtr()
275 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
280 // ---------------------------------------------------------------------------
282 // ---------------------------------------------------------------------------
284 void wxWindowPalm::SetFocus()
288 void wxWindowPalm::SetFocusFromKbd()
292 // Get the window with the focus
293 wxWindow
*wxWindowBase::DoFindFocus()
298 bool wxWindowPalm::Enable(bool enable
)
303 bool wxWindowPalm::Show(bool show
)
308 // Raise the window to the top of the Z order
309 void wxWindowPalm::Raise()
313 // Lower the window to the bottom of the Z order
314 void wxWindowPalm::Lower()
318 void wxWindowPalm::SetLabel( const wxString
& WXUNUSED(label
))
322 wxString
wxWindowPalm::GetLabel() const
324 return wxEmptyString
;
327 void wxWindowPalm::DoCaptureMouse()
331 void wxWindowPalm::DoReleaseMouse()
335 /* static */ wxWindow
*wxWindowBase::GetCapture()
340 bool wxWindowPalm::SetFont(const wxFont
& font
)
344 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
349 void wxWindowPalm::WarpPointer (int x
, int y
)
353 // ---------------------------------------------------------------------------
355 // ---------------------------------------------------------------------------
357 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
358 static inline int wxDirToWinStyle(int orient
)
363 int wxWindowPalm::GetScrollPos(int orient
) const
368 // This now returns the whole range, not just the number
369 // of positions that we can scroll.
370 int wxWindowPalm::GetScrollRange(int orient
) const
375 int wxWindowPalm::GetScrollThumb(int orient
) const
380 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
384 // New function that will replace some of the above.
385 void wxWindowPalm::SetScrollbar(int orient
,
393 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
397 bool wxWindowPalm::ScrollLines(int lines
)
402 bool wxWindowPalm::ScrollPages(int pages
)
407 // ----------------------------------------------------------------------------
409 // ----------------------------------------------------------------------------
411 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
416 // Setup background and foreground colours correctly
417 void wxWindowPalm::SetupColours()
421 void wxWindowPalm::OnInternalIdle()
425 // Set this window to be the child of 'parent'.
426 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
431 void wxWindowPalm::Freeze()
435 void wxWindowPalm::Thaw()
439 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
441 WinHandle handle
= (WinHandle
)GetWinHandle();
446 RectangleType dirtyRect
;
447 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
448 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
449 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
450 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
451 WinInvalidateRect(handle
, &dirtyRect
);
455 WinInvalidateWindow(handle
);
460 void wxWindowPalm::Update()
464 // ---------------------------------------------------------------------------
466 // ---------------------------------------------------------------------------
469 #if wxUSE_DRAG_AND_DROP
470 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
473 #endif // wxUSE_DRAG_AND_DROP
475 // old style file-manager drag&drop support: we retain the old-style
476 // DragAcceptFiles in parallel with SetDropTarget.
477 void wxWindowPalm::DragAcceptFiles(bool accept
)
481 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
487 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
491 #endif // wxUSE_TOOLTIPS
493 // ---------------------------------------------------------------------------
494 // moving and resizing
495 // ---------------------------------------------------------------------------
498 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
502 // Get size *available for subwindows* i.e. excluding menu bar etc.
503 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
507 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
515 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
519 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
523 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
527 // set the size of the window: if the dimensions are positive, just use them,
528 // but if any of them is equal to -1, it means that we must find the value for
529 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
530 // which case -1 is a valid value for x and y)
532 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
533 // the width/height to best suit our contents, otherwise we reuse the current
535 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
537 // get the current size and position...
538 int currentX
, currentY
;
539 GetPosition(¤tX
, ¤tY
);
540 int currentW
,currentH
;
541 GetSize(¤tW
, ¤tH
);
543 // ... and don't do anything (avoiding flicker) if it's already ok
544 if ( x
== currentX
&& y
== currentY
&&
545 width
== currentW
&& height
== currentH
)
550 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
552 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
555 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
557 wxSize size
= wxDefaultSize
;
558 if ( width
== wxDefaultCoord
)
560 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
562 size
= DoGetBestSize();
567 // just take the current one
572 if ( height
== wxDefaultCoord
)
574 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
576 if ( size
.x
== wxDefaultCoord
)
578 size
= DoGetBestSize();
580 //else: already called DoGetBestSize() above
586 // just take the current one
591 DoMoveWindow(x
, y
, width
, height
);
594 void wxWindowPalm::DoSetClientSize(int width
, int height
)
598 // ---------------------------------------------------------------------------
600 // ---------------------------------------------------------------------------
602 int wxWindowPalm::GetCharHeight() const
607 int wxWindowPalm::GetCharWidth() const
612 void wxWindowPalm::GetTextExtent(const wxString
& string
,
614 int *descent
, int *externalLeading
,
615 const wxFont
*theFont
) const
619 // ---------------------------------------------------------------------------
621 // ---------------------------------------------------------------------------
623 #if wxUSE_MENUS_NATIVE
625 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
626 // immediately, without waiting for the next event loop iteration
628 // NB: this function should probably be made public later as it can almost
629 // surely replace wxYield() elsewhere as well
630 static void wxYieldForCommandsOnly()
634 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
639 #endif // wxUSE_MENUS_NATIVE
641 // ----------------------------------------------------------------------------
642 // wxWindow <-> HWND map
643 // ----------------------------------------------------------------------------
645 wxWinHashTable
*wxWinHandleHash
= NULL
;
647 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
653 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
657 // ----------------------------------------------------------------------------
658 // various Palm specific class dependent functions
659 // ----------------------------------------------------------------------------
661 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
664 int& w
, int& h
) const
669 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
674 WXDWORD extendedStyle
)
679 // ===========================================================================
680 // Palm message handlers
681 // ===========================================================================
683 // ---------------------------------------------------------------------------
685 // ---------------------------------------------------------------------------
687 // Can be called from an application's OnPaint handler
688 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
692 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
696 // ---------------------------------------------------------------------------
697 // moving and resizing
698 // ---------------------------------------------------------------------------
700 bool wxWindowPalm::HandleMove(int x
, int y
)
705 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
710 // ---------------------------------------------------------------------------
712 // ---------------------------------------------------------------------------
714 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
719 // ---------------------------------------------------------------------------
721 // ---------------------------------------------------------------------------
723 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
724 WXWORD pos
, WXWINHANDLE control
)
730 // ===========================================================================
732 // ===========================================================================
734 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
741 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
746 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
751 #endif // wxUSE_HOTKEY