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"
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 #if wxUSE_MENUS_NATIVE
95 wxMenu
*wxCurrentPopupMenu
= NULL
;
96 #endif // wxUSE_MENUS_NATIVE
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 // ---------------------------------------------------------------------------
106 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
108 #ifdef __WXUNIVERSAL__
109 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
111 #if wxUSE_EXTENDED_RTTI
113 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
114 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
115 // windows with negative ids never can be recreated anyway
117 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
122 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
124 // make wxWindowList known before the property is used
126 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
128 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
130 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
133 WX_DEFINE_FLAGS( wxWindowStyle
)
135 wxBEGIN_FLAGS( wxWindowStyle
)
136 // new style border flags, we put them first to
137 // use them for streaming out
139 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
140 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
141 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
142 wxFLAGS_MEMBER(wxBORDER_RAISED
)
143 wxFLAGS_MEMBER(wxBORDER_STATIC
)
144 wxFLAGS_MEMBER(wxBORDER_NONE
)
146 // old style border flags
147 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
148 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
149 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
150 wxFLAGS_MEMBER(wxRAISED_BORDER
)
151 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
152 wxFLAGS_MEMBER(wxBORDER
)
154 // standard window styles
155 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
156 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
157 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
158 wxFLAGS_MEMBER(wxWANTS_CHARS
)
159 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
160 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
161 wxFLAGS_MEMBER(wxVSCROLL
)
162 wxFLAGS_MEMBER(wxHSCROLL
)
164 wxEND_FLAGS( wxWindowStyle
)
166 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
167 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
168 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
169 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
170 // Always constructor Properties first
172 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
173 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, wxID_ANY
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
174 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
175 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
176 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
178 // Then all relations of the object graph
180 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
182 // and finally all other properties
184 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
185 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
186 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
187 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
188 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
190 // possible property candidates (not in xrc) or not valid in all subclasses
191 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
192 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
193 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
194 // MaxHeight, Width , MinHeight , Width
195 // TODO switch label to control and title to toplevels
197 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
198 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
199 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
200 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
205 wxEND_PROPERTIES_TABLE()
207 wxBEGIN_HANDLERS_TABLE(wxWindow
)
208 wxEND_HANDLERS_TABLE()
210 wxCONSTRUCTOR_DUMMY(wxWindow
)
213 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
215 #endif // __WXUNIVERSAL__/__WXPalm__
217 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
218 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
219 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
222 // ===========================================================================
224 // ===========================================================================
226 // ---------------------------------------------------------------------------
227 // wxWindow utility functions
228 // ---------------------------------------------------------------------------
230 // Find an item given the MS Windows id
231 wxWindow
*wxWindowPalm::FindItem(long id
) const
236 // Find an item given the MS Windows handle
237 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
243 // ----------------------------------------------------------------------------
244 // constructors and such
245 // ----------------------------------------------------------------------------
247 void wxWindowPalm::Init()
253 wxWindowPalm::~wxWindowPalm()
257 // real construction (Init() must have been called before!)
258 bool wxWindowPalm::Create(wxWindow
*parent
,
263 const wxString
& name
)
265 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
267 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
270 parent
->AddChild(this);
277 WXFORMPTR
wxWindowPalm::GetFormPtr()
281 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
286 // ---------------------------------------------------------------------------
288 // ---------------------------------------------------------------------------
290 void wxWindowPalm::SetFocus()
294 void wxWindowPalm::SetFocusFromKbd()
298 // Get the window with the focus
299 wxWindow
*wxWindowBase::DoFindFocus()
304 bool wxWindowPalm::Enable(bool enable
)
309 bool wxWindowPalm::Show(bool show
)
314 // Raise the window to the top of the Z order
315 void wxWindowPalm::Raise()
319 // Lower the window to the bottom of the Z order
320 void wxWindowPalm::Lower()
324 void wxWindowPalm::SetTitle( const wxString
& title
)
328 wxString
wxWindowPalm::GetTitle() const
330 return wxEmptyString
;
333 void wxWindowPalm::DoCaptureMouse()
337 void wxWindowPalm::DoReleaseMouse()
341 /* static */ wxWindow
*wxWindowBase::GetCapture()
346 bool wxWindowPalm::SetFont(const wxFont
& font
)
350 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
355 void wxWindowPalm::WarpPointer (int x
, int y
)
359 // ---------------------------------------------------------------------------
361 // ---------------------------------------------------------------------------
363 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
364 static inline int wxDirToWinStyle(int orient
)
369 int wxWindowPalm::GetScrollPos(int orient
) const
374 // This now returns the whole range, not just the number
375 // of positions that we can scroll.
376 int wxWindowPalm::GetScrollRange(int orient
) const
381 int wxWindowPalm::GetScrollThumb(int orient
) const
386 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
390 // New function that will replace some of the above.
391 void wxWindowPalm::SetScrollbar(int orient
,
399 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
403 bool wxWindowPalm::ScrollLines(int lines
)
408 bool wxWindowPalm::ScrollPages(int pages
)
413 // ----------------------------------------------------------------------------
415 // ----------------------------------------------------------------------------
417 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
422 // Setup background and foreground colours correctly
423 void wxWindowPalm::SetupColours()
427 void wxWindowPalm::OnInternalIdle()
431 // Set this window to be the child of 'parent'.
432 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
437 void wxWindowPalm::Freeze()
441 void wxWindowPalm::Thaw()
445 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
447 WinHandle handle
= (WinHandle
)GetWinHandle();
452 RectangleType dirtyRect
;
453 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
454 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
455 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
456 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
457 WinInvalidateRect(handle
, &dirtyRect
);
461 WinInvalidateWindow(handle
);
466 void wxWindowPalm::Update()
470 // ---------------------------------------------------------------------------
472 // ---------------------------------------------------------------------------
475 #if wxUSE_DRAG_AND_DROP
476 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
479 #endif // wxUSE_DRAG_AND_DROP
481 // old style file-manager drag&drop support: we retain the old-style
482 // DragAcceptFiles in parallel with SetDropTarget.
483 void wxWindowPalm::DragAcceptFiles(bool accept
)
487 // ----------------------------------------------------------------------------
489 // ----------------------------------------------------------------------------
493 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
497 #endif // wxUSE_TOOLTIPS
499 // ---------------------------------------------------------------------------
500 // moving and resizing
501 // ---------------------------------------------------------------------------
504 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
508 // Get size *available for subwindows* i.e. excluding menu bar etc.
509 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
513 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
521 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
525 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
529 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
533 // set the size of the window: if the dimensions are positive, just use them,
534 // but if any of them is equal to -1, it means that we must find the value for
535 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
536 // which case -1 is a valid value for x and y)
538 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
539 // the width/height to best suit our contents, otherwise we reuse the current
541 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
543 // get the current size and position...
544 int currentX
, currentY
;
545 GetPosition(¤tX
, ¤tY
);
546 int currentW
,currentH
;
547 GetSize(¤tW
, ¤tH
);
549 // ... and don't do anything (avoiding flicker) if it's already ok
550 if ( x
== currentX
&& y
== currentY
&&
551 width
== currentW
&& height
== currentH
)
556 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
558 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
561 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
563 wxSize size
= wxDefaultSize
;
564 if ( width
== wxDefaultCoord
)
566 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
568 size
= DoGetBestSize();
573 // just take the current one
578 if ( height
== wxDefaultCoord
)
580 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
582 if ( size
.x
== wxDefaultCoord
)
584 size
= DoGetBestSize();
586 //else: already called DoGetBestSize() above
592 // just take the current one
597 DoMoveWindow(x
, y
, width
, height
);
600 void wxWindowPalm::DoSetClientSize(int width
, int height
)
604 // ---------------------------------------------------------------------------
606 // ---------------------------------------------------------------------------
608 int wxWindowPalm::GetCharHeight() const
613 int wxWindowPalm::GetCharWidth() const
618 void wxWindowPalm::GetTextExtent(const wxString
& string
,
620 int *descent
, int *externalLeading
,
621 const wxFont
*theFont
) const
625 // ---------------------------------------------------------------------------
627 // ---------------------------------------------------------------------------
629 #if wxUSE_MENUS_NATIVE
631 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
632 // immediately, without waiting for the next event loop iteration
634 // NB: this function should probably be made public later as it can almost
635 // surely replace wxYield() elsewhere as well
636 static void wxYieldForCommandsOnly()
640 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
645 #endif // wxUSE_MENUS_NATIVE
647 // ----------------------------------------------------------------------------
648 // wxWindow <-> HWND map
649 // ----------------------------------------------------------------------------
651 wxWinHashTable
*wxWinHandleHash
= NULL
;
653 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
659 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
663 // ----------------------------------------------------------------------------
664 // various Palm specific class dependent functions
665 // ----------------------------------------------------------------------------
667 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
670 int& w
, int& h
) const
675 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
680 WXDWORD extendedStyle
)
685 // ===========================================================================
686 // Palm message handlers
687 // ===========================================================================
689 // ---------------------------------------------------------------------------
691 // ---------------------------------------------------------------------------
693 // Can be called from an application's OnPaint handler
694 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
698 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
702 // ---------------------------------------------------------------------------
703 // moving and resizing
704 // ---------------------------------------------------------------------------
706 bool wxWindowPalm::HandleMove(int x
, int y
)
711 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
716 // ---------------------------------------------------------------------------
718 // ---------------------------------------------------------------------------
720 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
725 // ---------------------------------------------------------------------------
727 // ---------------------------------------------------------------------------
729 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
730 WXWORD pos
, WXWINHANDLE control
)
736 // ===========================================================================
738 // ===========================================================================
740 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
747 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
752 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
757 #endif // wxUSE_HOTKEY