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"
83 // ---------------------------------------------------------------------------
85 // ---------------------------------------------------------------------------
87 #if wxUSE_MENUS_NATIVE
88 wxMenu
*wxCurrentPopupMenu
= NULL
;
89 #endif // wxUSE_MENUS_NATIVE
91 // ---------------------------------------------------------------------------
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // ---------------------------------------------------------------------------
99 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
101 #ifdef __WXUNIVERSAL__
102 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
104 #if wxUSE_EXTENDED_RTTI
106 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
107 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
108 // windows with negative ids never can be recreated anyway
110 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
115 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
117 // make wxWindowList known before the property is used
119 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
121 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
123 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
126 WX_DEFINE_FLAGS( wxWindowStyle
)
128 wxBEGIN_FLAGS( wxWindowStyle
)
129 // new style border flags, we put them first to
130 // use them for streaming out
132 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
133 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
134 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
135 wxFLAGS_MEMBER(wxBORDER_RAISED
)
136 wxFLAGS_MEMBER(wxBORDER_STATIC
)
137 wxFLAGS_MEMBER(wxBORDER_NONE
)
139 // old style border flags
140 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
141 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
142 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
143 wxFLAGS_MEMBER(wxRAISED_BORDER
)
144 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
145 wxFLAGS_MEMBER(wxBORDER
)
147 // standard window styles
148 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
149 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
150 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
151 wxFLAGS_MEMBER(wxWANTS_CHARS
)
152 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
153 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
154 wxFLAGS_MEMBER(wxVSCROLL
)
155 wxFLAGS_MEMBER(wxHSCROLL
)
157 wxEND_FLAGS( wxWindowStyle
)
159 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
160 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
161 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
162 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
163 // Always constructor Properties first
165 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
166 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
167 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
168 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
169 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
171 // Then all relations of the object graph
173 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
175 // and finally all other properties
177 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
178 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
179 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
180 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
181 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
183 // possible property candidates (not in xrc) or not valid in all subclasses
184 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
185 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
186 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
187 // MaxHeight, Width , MinHeight , Width
188 // TODO switch label to control and title to toplevels
190 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
191 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
192 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
193 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
198 wxEND_PROPERTIES_TABLE()
200 wxBEGIN_HANDLERS_TABLE(wxWindow
)
201 wxEND_HANDLERS_TABLE()
203 wxCONSTRUCTOR_DUMMY(wxWindow
)
206 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
208 #endif // __WXUNIVERSAL__/__WXPalm__
210 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
211 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
212 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
215 // ===========================================================================
217 // ===========================================================================
219 // ---------------------------------------------------------------------------
220 // wxWindow utility functions
221 // ---------------------------------------------------------------------------
223 // Find an item given the MS Windows id
224 wxWindow
*wxWindowPalm::FindItem(long id
) const
229 // Find an item given the MS Windows handle
230 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
236 bool wxGetKeyState(wxKeyCode key
)
238 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
239 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
246 // ----------------------------------------------------------------------------
247 // constructors and such
248 // ----------------------------------------------------------------------------
250 void wxWindowPalm::Init()
256 wxWindowPalm::~wxWindowPalm()
260 // real construction (Init() must have been called before!)
261 bool wxWindowPalm::Create(wxWindow
*parent
,
266 const wxString
& name
)
268 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
270 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
273 parent
->AddChild(this);
280 WXFORMPTR
wxWindowPalm::GetFormPtr()
284 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
289 // ---------------------------------------------------------------------------
291 // ---------------------------------------------------------------------------
293 void wxWindowPalm::SetFocus()
297 void wxWindowPalm::SetFocusFromKbd()
301 // Get the window with the focus
302 wxWindow
*wxWindowBase::DoFindFocus()
307 bool wxWindowPalm::Enable(bool enable
)
312 bool wxWindowPalm::Show(bool show
)
317 // Raise the window to the top of the Z order
318 void wxWindowPalm::Raise()
322 // Lower the window to the bottom of the Z order
323 void wxWindowPalm::Lower()
327 void wxWindowPalm::SetLabel( const wxString
& WXUNUSED(label
))
331 wxString
wxWindowPalm::GetLabel() const
333 return wxEmptyString
;
336 void wxWindowPalm::DoCaptureMouse()
340 void wxWindowPalm::DoReleaseMouse()
344 /* static */ wxWindow
*wxWindowBase::GetCapture()
349 bool wxWindowPalm::SetFont(const wxFont
& font
)
353 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
358 void wxWindowPalm::WarpPointer (int x
, int y
)
362 // ---------------------------------------------------------------------------
364 // ---------------------------------------------------------------------------
366 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
367 static inline int wxDirToWinStyle(int orient
)
372 int wxWindowPalm::GetScrollPos(int orient
) const
377 // This now returns the whole range, not just the number
378 // of positions that we can scroll.
379 int wxWindowPalm::GetScrollRange(int orient
) const
384 int wxWindowPalm::GetScrollThumb(int orient
) const
389 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
393 // New function that will replace some of the above.
394 void wxWindowPalm::SetScrollbar(int orient
,
402 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
406 bool wxWindowPalm::ScrollLines(int lines
)
411 bool wxWindowPalm::ScrollPages(int pages
)
416 // ----------------------------------------------------------------------------
418 // ----------------------------------------------------------------------------
420 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
425 // Setup background and foreground colours correctly
426 void wxWindowPalm::SetupColours()
430 void wxWindowPalm::OnInternalIdle()
434 // Set this window to be the child of 'parent'.
435 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
440 void wxWindowPalm::Freeze()
444 void wxWindowPalm::Thaw()
448 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
450 WinHandle handle
= (WinHandle
)GetWinHandle();
455 RectangleType dirtyRect
;
456 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
457 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
458 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
459 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
460 WinInvalidateRect(handle
, &dirtyRect
);
464 WinInvalidateWindow(handle
);
469 void wxWindowPalm::Update()
473 // ---------------------------------------------------------------------------
475 // ---------------------------------------------------------------------------
478 #if wxUSE_DRAG_AND_DROP
479 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
482 #endif // wxUSE_DRAG_AND_DROP
484 // old style file-manager drag&drop support: we retain the old-style
485 // DragAcceptFiles in parallel with SetDropTarget.
486 void wxWindowPalm::DragAcceptFiles(bool accept
)
490 // ----------------------------------------------------------------------------
492 // ----------------------------------------------------------------------------
496 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
500 #endif // wxUSE_TOOLTIPS
502 // ---------------------------------------------------------------------------
503 // moving and resizing
504 // ---------------------------------------------------------------------------
507 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
511 // Get size *available for subwindows* i.e. excluding menu bar etc.
512 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
516 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
524 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
528 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
532 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
536 // set the size of the window: if the dimensions are positive, just use them,
537 // but if any of them is equal to -1, it means that we must find the value for
538 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
539 // which case -1 is a valid value for x and y)
541 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
542 // the width/height to best suit our contents, otherwise we reuse the current
544 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
546 // get the current size and position...
547 int currentX
, currentY
;
548 GetPosition(¤tX
, ¤tY
);
549 int currentW
,currentH
;
550 GetSize(¤tW
, ¤tH
);
552 // ... and don't do anything (avoiding flicker) if it's already ok
553 if ( x
== currentX
&& y
== currentY
&&
554 width
== currentW
&& height
== currentH
)
559 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
561 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
564 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
566 wxSize size
= wxDefaultSize
;
567 if ( width
== wxDefaultCoord
)
569 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
571 size
= DoGetBestSize();
576 // just take the current one
581 if ( height
== wxDefaultCoord
)
583 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
585 if ( size
.x
== wxDefaultCoord
)
587 size
= DoGetBestSize();
589 //else: already called DoGetBestSize() above
595 // just take the current one
600 DoMoveWindow(x
, y
, width
, height
);
603 void wxWindowPalm::DoSetClientSize(int width
, int height
)
607 // ---------------------------------------------------------------------------
609 // ---------------------------------------------------------------------------
611 int wxWindowPalm::GetCharHeight() const
616 int wxWindowPalm::GetCharWidth() const
621 void wxWindowPalm::GetTextExtent(const wxString
& string
,
623 int *descent
, int *externalLeading
,
624 const wxFont
*theFont
) const
628 // ---------------------------------------------------------------------------
630 // ---------------------------------------------------------------------------
632 #if wxUSE_MENUS_NATIVE
634 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
635 // immediately, without waiting for the next event loop iteration
637 // NB: this function should probably be made public later as it can almost
638 // surely replace wxYield() elsewhere as well
639 static void wxYieldForCommandsOnly()
643 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
648 #endif // wxUSE_MENUS_NATIVE
650 // ----------------------------------------------------------------------------
651 // wxWindow <-> HWND map
652 // ----------------------------------------------------------------------------
654 wxWinHashTable
*wxWinHandleHash
= NULL
;
656 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
662 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
666 // ----------------------------------------------------------------------------
667 // various Palm specific class dependent functions
668 // ----------------------------------------------------------------------------
670 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
673 int& w
, int& h
) const
678 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
683 WXDWORD extendedStyle
)
688 // ===========================================================================
689 // Palm message handlers
690 // ===========================================================================
692 // ---------------------------------------------------------------------------
694 // ---------------------------------------------------------------------------
696 // Can be called from an application's OnPaint handler
697 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
701 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
705 // ---------------------------------------------------------------------------
706 // moving and resizing
707 // ---------------------------------------------------------------------------
709 bool wxWindowPalm::HandleMove(int x
, int y
)
714 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
719 // ---------------------------------------------------------------------------
721 // ---------------------------------------------------------------------------
723 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
728 // ---------------------------------------------------------------------------
730 // ---------------------------------------------------------------------------
732 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
733 WXWORD pos
, WXWINHANDLE control
)
739 // ===========================================================================
741 // ===========================================================================
743 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
750 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
755 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
760 #endif // wxUSE_HOTKEY