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"
28 #include "wx/window.h"
32 #include "wx/dcclient.h"
33 #include "wx/dcmemory.h"
36 #include "wx/layout.h"
37 #include "wx/dialog.h"
39 #include "wx/listbox.h"
40 #include "wx/button.h"
41 #include "wx/msgdlg.h"
42 #include "wx/settings.h"
43 #include "wx/statbox.h"
46 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
47 #include "wx/ownerdrw.h"
50 #include "wx/module.h"
52 #if wxUSE_DRAG_AND_DROP
56 #if wxUSE_ACCESSIBILITY
57 #include "wx/access.h"
60 #include "wx/menuitem.h"
64 #include "wx/tooltip.h"
72 #include "wx/spinctrl.h"
73 #endif // wxUSE_SPINCTRL
78 #include "wx/textctrl.h"
79 #include "wx/notebook.h"
80 #include "wx/listctrl.h"
81 #include "wx/window.h"
85 // ---------------------------------------------------------------------------
87 // ---------------------------------------------------------------------------
89 #if wxUSE_MENUS_NATIVE
90 wxMenu
*wxCurrentPopupMenu
= NULL
;
91 #endif // wxUSE_MENUS_NATIVE
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // ---------------------------------------------------------------------------
99 // ---------------------------------------------------------------------------
101 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
103 #ifdef __WXUNIVERSAL__
104 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
106 #if wxUSE_EXTENDED_RTTI
108 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
109 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
110 // windows with negative ids never can be recreated anyway
112 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
117 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
119 // make wxWindowList known before the property is used
121 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
123 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
125 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
128 WX_DEFINE_FLAGS( wxWindowStyle
)
130 wxBEGIN_FLAGS( wxWindowStyle
)
131 // new style border flags, we put them first to
132 // use them for streaming out
134 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
135 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
136 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
137 wxFLAGS_MEMBER(wxBORDER_RAISED
)
138 wxFLAGS_MEMBER(wxBORDER_STATIC
)
139 wxFLAGS_MEMBER(wxBORDER_NONE
)
141 // old style border flags
142 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
143 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
144 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
145 wxFLAGS_MEMBER(wxRAISED_BORDER
)
146 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
147 wxFLAGS_MEMBER(wxBORDER
)
149 // standard window styles
150 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
151 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
152 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
153 wxFLAGS_MEMBER(wxWANTS_CHARS
)
154 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
155 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
156 wxFLAGS_MEMBER(wxVSCROLL
)
157 wxFLAGS_MEMBER(wxHSCROLL
)
159 wxEND_FLAGS( wxWindowStyle
)
161 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
162 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
163 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
164 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
165 // Always constructor Properties first
167 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
168 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
169 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
170 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
171 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
173 // Then all relations of the object graph
175 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
177 // and finally all other properties
179 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
180 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
181 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
182 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
183 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
185 // possible property candidates (not in xrc) or not valid in all subclasses
186 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
187 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
188 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
189 // MaxHeight, Width , MinHeight , Width
190 // TODO switch label to control and title to toplevels
192 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
193 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
194 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
195 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
200 wxEND_PROPERTIES_TABLE()
202 wxBEGIN_HANDLERS_TABLE(wxWindow
)
203 wxEND_HANDLERS_TABLE()
205 wxCONSTRUCTOR_DUMMY(wxWindow
)
208 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
210 #endif // __WXUNIVERSAL__/__WXPalm__
212 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
213 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
214 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
217 // ===========================================================================
219 // ===========================================================================
221 // ---------------------------------------------------------------------------
222 // wxWindow utility functions
223 // ---------------------------------------------------------------------------
225 // Find an item given the MS Windows id
226 wxWindow
*wxWindowPalm::FindItem(long id
) const
231 // Find an item given the MS Windows handle
232 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
238 // ----------------------------------------------------------------------------
239 // constructors and such
240 // ----------------------------------------------------------------------------
242 void wxWindowPalm::Init()
248 wxWindowPalm::~wxWindowPalm()
252 // real construction (Init() must have been called before!)
253 bool wxWindowPalm::Create(wxWindow
*parent
,
258 const wxString
& name
)
260 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
262 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
265 parent
->AddChild(this);
272 WXFORMPTR
wxWindowPalm::GetFormPtr()
276 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
281 // ---------------------------------------------------------------------------
283 // ---------------------------------------------------------------------------
285 void wxWindowPalm::SetFocus()
289 void wxWindowPalm::SetFocusFromKbd()
293 // Get the window with the focus
294 wxWindow
*wxWindowBase::DoFindFocus()
299 bool wxWindowPalm::Enable(bool enable
)
304 bool wxWindowPalm::Show(bool show
)
309 // Raise the window to the top of the Z order
310 void wxWindowPalm::Raise()
314 // Lower the window to the bottom of the Z order
315 void wxWindowPalm::Lower()
319 void wxWindowPalm::SetLabel( const wxString
& WXUNUSED(label
))
323 wxString
wxWindowPalm::GetLabel() const
325 return wxEmptyString
;
328 void wxWindowPalm::DoCaptureMouse()
332 void wxWindowPalm::DoReleaseMouse()
336 /* static */ wxWindow
*wxWindowBase::GetCapture()
341 bool wxWindowPalm::SetFont(const wxFont
& font
)
345 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
350 void wxWindowPalm::WarpPointer (int x
, int y
)
354 // ---------------------------------------------------------------------------
356 // ---------------------------------------------------------------------------
358 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
359 static inline int wxDirToWinStyle(int orient
)
364 int wxWindowPalm::GetScrollPos(int orient
) const
369 // This now returns the whole range, not just the number
370 // of positions that we can scroll.
371 int wxWindowPalm::GetScrollRange(int orient
) const
376 int wxWindowPalm::GetScrollThumb(int orient
) const
381 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
385 // New function that will replace some of the above.
386 void wxWindowPalm::SetScrollbar(int orient
,
394 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
398 bool wxWindowPalm::ScrollLines(int lines
)
403 bool wxWindowPalm::ScrollPages(int pages
)
408 // ----------------------------------------------------------------------------
410 // ----------------------------------------------------------------------------
412 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
417 // Setup background and foreground colours correctly
418 void wxWindowPalm::SetupColours()
422 void wxWindowPalm::OnInternalIdle()
426 // Set this window to be the child of 'parent'.
427 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
432 void wxWindowPalm::Freeze()
436 void wxWindowPalm::Thaw()
440 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
442 WinHandle handle
= (WinHandle
)GetWinHandle();
447 RectangleType dirtyRect
;
448 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
449 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
450 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
451 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
452 WinInvalidateRect(handle
, &dirtyRect
);
456 WinInvalidateWindow(handle
);
461 void wxWindowPalm::Update()
465 // ---------------------------------------------------------------------------
467 // ---------------------------------------------------------------------------
470 #if wxUSE_DRAG_AND_DROP
471 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
474 #endif // wxUSE_DRAG_AND_DROP
476 // old style file-manager drag&drop support: we retain the old-style
477 // DragAcceptFiles in parallel with SetDropTarget.
478 void wxWindowPalm::DragAcceptFiles(bool accept
)
482 // ----------------------------------------------------------------------------
484 // ----------------------------------------------------------------------------
488 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
492 #endif // wxUSE_TOOLTIPS
494 // ---------------------------------------------------------------------------
495 // moving and resizing
496 // ---------------------------------------------------------------------------
499 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
503 // Get size *available for subwindows* i.e. excluding menu bar etc.
504 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
508 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
516 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
520 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
524 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
528 // set the size of the window: if the dimensions are positive, just use them,
529 // but if any of them is equal to -1, it means that we must find the value for
530 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
531 // which case -1 is a valid value for x and y)
533 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
534 // the width/height to best suit our contents, otherwise we reuse the current
536 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
538 // get the current size and position...
539 int currentX
, currentY
;
540 GetPosition(¤tX
, ¤tY
);
541 int currentW
,currentH
;
542 GetSize(¤tW
, ¤tH
);
544 // ... and don't do anything (avoiding flicker) if it's already ok
545 if ( x
== currentX
&& y
== currentY
&&
546 width
== currentW
&& height
== currentH
)
551 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
553 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
556 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
558 wxSize size
= wxDefaultSize
;
559 if ( width
== wxDefaultCoord
)
561 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
563 size
= DoGetBestSize();
568 // just take the current one
573 if ( height
== wxDefaultCoord
)
575 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
577 if ( size
.x
== wxDefaultCoord
)
579 size
= DoGetBestSize();
581 //else: already called DoGetBestSize() above
587 // just take the current one
592 DoMoveWindow(x
, y
, width
, height
);
595 void wxWindowPalm::DoSetClientSize(int width
, int height
)
599 // ---------------------------------------------------------------------------
601 // ---------------------------------------------------------------------------
603 int wxWindowPalm::GetCharHeight() const
608 int wxWindowPalm::GetCharWidth() const
613 void wxWindowPalm::GetTextExtent(const wxString
& string
,
615 int *descent
, int *externalLeading
,
616 const wxFont
*theFont
) const
620 // ---------------------------------------------------------------------------
622 // ---------------------------------------------------------------------------
624 #if wxUSE_MENUS_NATIVE
626 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
627 // immediately, without waiting for the next event loop iteration
629 // NB: this function should probably be made public later as it can almost
630 // surely replace wxYield() elsewhere as well
631 static void wxYieldForCommandsOnly()
635 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
640 #endif // wxUSE_MENUS_NATIVE
642 // ----------------------------------------------------------------------------
643 // wxWindow <-> HWND map
644 // ----------------------------------------------------------------------------
646 wxWinHashTable
*wxWinHandleHash
= NULL
;
648 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
654 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
658 // ----------------------------------------------------------------------------
659 // various Palm specific class dependent functions
660 // ----------------------------------------------------------------------------
662 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
665 int& w
, int& h
) const
670 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
675 WXDWORD extendedStyle
)
680 // ===========================================================================
681 // Palm message handlers
682 // ===========================================================================
684 // ---------------------------------------------------------------------------
686 // ---------------------------------------------------------------------------
688 // Can be called from an application's OnPaint handler
689 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
693 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
697 // ---------------------------------------------------------------------------
698 // moving and resizing
699 // ---------------------------------------------------------------------------
701 bool wxWindowPalm::HandleMove(int x
, int y
)
706 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
711 // ---------------------------------------------------------------------------
713 // ---------------------------------------------------------------------------
715 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
720 // ---------------------------------------------------------------------------
722 // ---------------------------------------------------------------------------
724 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
725 WXWORD pos
, WXWINHANDLE control
)
731 // ===========================================================================
733 // ===========================================================================
735 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
742 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
747 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
752 #endif // wxUSE_HOTKEY