]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/window.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"
47 #include "wx/textctrl.h"
48 #include "wx/menuitem.h"
49 #include "wx/module.h"
52 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
53 #include "wx/ownerdrw.h"
56 #if wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/tooltip.h"
73 #include "wx/spinctrl.h"
74 #endif // wxUSE_SPINCTRL
76 #include "wx/notebook.h"
77 #include "wx/listctrl.h"
79 #ifndef __WXUNIVERSAL__
82 // ---------------------------------------------------------------------------
84 // ---------------------------------------------------------------------------
86 // ---------------------------------------------------------------------------
88 // ---------------------------------------------------------------------------
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 // in wxUniv/Palm this class is abstract because it doesn't have DoPopupMenu()
96 #ifdef __WXUNIVERSAL__
97 IMPLEMENT_ABSTRACT_CLASS(wxWindowPalm
, wxWindowBase
)
98 #endif // __WXUNIVERSAL__
100 BEGIN_EVENT_TABLE(wxWindowPalm
, wxWindowBase
)
101 EVT_ERASE_BACKGROUND(wxWindowPalm::OnEraseBackground
)
102 EVT_INIT_DIALOG(wxWindowPalm::OnInitDialog
)
105 // ===========================================================================
107 // ===========================================================================
109 // ---------------------------------------------------------------------------
110 // wxWindow utility functions
111 // ---------------------------------------------------------------------------
113 // Find an item given the MS Windows id
114 wxWindow
*wxWindowPalm::FindItem(long id
) const
119 // Find an item given the MS Windows handle
120 wxWindow
*wxWindowPalm::FindItemByWinHandle(WXWINHANDLE handle
, bool controlOnly
) const
126 bool wxGetKeyState(wxKeyCode key
)
128 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
129 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
136 // ----------------------------------------------------------------------------
137 // constructors and such
138 // ----------------------------------------------------------------------------
140 void wxWindowPalm::Init()
146 wxWindowPalm::~wxWindowPalm()
150 // real construction (Init() must have been called before!)
151 bool wxWindowPalm::Create(wxWindow
*parent
,
156 const wxString
& name
)
158 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
160 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
163 parent
->AddChild(this);
170 WXFORMPTR
wxWindowPalm::GetFormPtr()
174 void wxWindowPalm::SetFormPtr(WXFORMPTR FormPtr
)
179 // ---------------------------------------------------------------------------
181 // ---------------------------------------------------------------------------
183 void wxWindowPalm::SetFocus()
187 void wxWindowPalm::SetFocusFromKbd()
191 // Get the window with the focus
192 wxWindow
*wxWindowBase::DoFindFocus()
197 bool wxWindowPalm::Enable(bool enable
)
202 bool wxWindowPalm::Show(bool show
)
207 // Raise the window to the top of the Z order
208 void wxWindowPalm::Raise()
212 // Lower the window to the bottom of the Z order
213 void wxWindowPalm::Lower()
217 void wxWindowPalm::SetLabel( const wxString
& WXUNUSED(label
))
221 wxString
wxWindowPalm::GetLabel() const
223 return wxEmptyString
;
226 void wxWindowPalm::DoCaptureMouse()
230 void wxWindowPalm::DoReleaseMouse()
234 /* static */ wxWindow
*wxWindowBase::GetCapture()
239 bool wxWindowPalm::SetFont(const wxFont
& font
)
243 bool wxWindowPalm::SetCursor(const wxCursor
& cursor
)
248 void wxWindowPalm::WarpPointer (int x
, int y
)
252 // ---------------------------------------------------------------------------
254 // ---------------------------------------------------------------------------
256 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
257 static inline int wxDirToWinStyle(int orient
)
262 int wxWindowPalm::GetScrollPos(int orient
) const
267 // This now returns the whole range, not just the number
268 // of positions that we can scroll.
269 int wxWindowPalm::GetScrollRange(int orient
) const
274 int wxWindowPalm::GetScrollThumb(int orient
) const
279 void wxWindowPalm::SetScrollPos(int orient
, int pos
, bool refresh
)
283 // New function that will replace some of the above.
284 void wxWindowPalm::SetScrollbar(int orient
,
292 void wxWindowPalm::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
296 bool wxWindowPalm::ScrollLines(int lines
)
301 bool wxWindowPalm::ScrollPages(int pages
)
306 // ----------------------------------------------------------------------------
308 // ----------------------------------------------------------------------------
310 WXDWORD
wxWindowPalm::PalmGetStyle(long flags
, WXDWORD
*exstyle
) const
315 // Setup background and foreground colours correctly
316 void wxWindowPalm::SetupColours()
320 void wxWindowPalm::OnInternalIdle()
324 // Set this window to be the child of 'parent'.
325 bool wxWindowPalm::Reparent(wxWindowBase
*parent
)
330 void wxWindowPalm::Refresh(bool eraseBack
, const wxRect
*rect
)
332 WinHandle handle
= (WinHandle
)GetHWND();
338 RectangleType dirtyRect
;
339 dirtyRect
.topLeft
.x
= rect
->GetX() - 1;
340 dirtyRect
.topLeft
.y
= rect
->GetY() - 1;
341 dirtyRect
.extent
.x
= rect
->GetWidth() + 1;
342 dirtyRect
.extent
.y
= rect
->GetHeight() + 1;
343 WinInvalidateRect(handle
, &dirtyRect
);
347 WinInvalidateWindow(handle
);
349 #else // __WXPALMOS5__
350 WinSetActiveWindow (handle
);
356 void wxWindowPalm::Update()
360 // ---------------------------------------------------------------------------
362 // ---------------------------------------------------------------------------
365 #if wxUSE_DRAG_AND_DROP
366 void wxWindowPalm::SetDropTarget(wxDropTarget
*pDropTarget
)
369 #endif // wxUSE_DRAG_AND_DROP
371 // old style file-manager drag&drop support: we retain the old-style
372 // DragAcceptFiles in parallel with SetDropTarget.
373 void wxWindowPalm::DragAcceptFiles(bool accept
)
377 // ----------------------------------------------------------------------------
379 // ----------------------------------------------------------------------------
383 void wxWindowPalm::DoSetToolTip(wxToolTip
*tooltip
)
387 #endif // wxUSE_TOOLTIPS
389 // ---------------------------------------------------------------------------
390 // moving and resizing
391 // ---------------------------------------------------------------------------
394 void wxWindowPalm::DoGetSize(int *x
, int *y
) const
398 // Get size *available for subwindows* i.e. excluding menu bar etc.
399 void wxWindowPalm::DoGetClientSize(int *x
, int *y
) const
403 void wxWindowPalm::DoGetPosition(int *x
, int *y
) const
411 void wxWindowPalm::DoScreenToClient(int *x
, int *y
) const
415 void wxWindowPalm::DoClientToScreen(int *x
, int *y
) const
419 void wxWindowPalm::DoMoveWindow(int x
, int y
, int width
, int height
)
423 // set the size of the window: if the dimensions are positive, just use them,
424 // but if any of them is equal to -1, it means that we must find the value for
425 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
426 // which case -1 is a valid value for x and y)
428 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
429 // the width/height to best suit our contents, otherwise we reuse the current
431 void wxWindowPalm::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
433 // get the current size and position...
434 int currentX
, currentY
;
435 GetPosition(¤tX
, ¤tY
);
436 int currentW
,currentH
;
437 GetSize(¤tW
, ¤tH
);
439 // ... and don't do anything (avoiding flicker) if it's already ok
440 if ( x
== currentX
&& y
== currentY
&&
441 width
== currentW
&& height
== currentH
)
446 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
448 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
451 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
453 wxSize size
= wxDefaultSize
;
454 if ( width
== wxDefaultCoord
)
456 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
458 size
= DoGetBestSize();
463 // just take the current one
468 if ( height
== wxDefaultCoord
)
470 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
472 if ( size
.x
== wxDefaultCoord
)
474 size
= DoGetBestSize();
476 //else: already called DoGetBestSize() above
482 // just take the current one
487 DoMoveWindow(x
, y
, width
, height
);
490 void wxWindowPalm::DoSetClientSize(int width
, int height
)
494 // ---------------------------------------------------------------------------
496 // ---------------------------------------------------------------------------
498 int wxWindowPalm::GetCharHeight() const
503 int wxWindowPalm::GetCharWidth() const
508 void wxWindowPalm::DoGetTextExtent(const wxString
& string
,
511 int *externalLeading
,
512 const wxFont
*theFont
) const
516 // ---------------------------------------------------------------------------
518 // ---------------------------------------------------------------------------
520 #if wxUSE_MENUS_NATIVE
522 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
523 // immediately, without waiting for the next event loop iteration
525 // NB: this function should probably be made public later as it can almost
526 // surely replace wxYield() elsewhere as well
527 static void wxYieldForCommandsOnly()
531 bool wxWindowPalm::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
536 #endif // wxUSE_MENUS_NATIVE
538 // ----------------------------------------------------------------------------
539 // wxWindow <-> HWND map
540 // ----------------------------------------------------------------------------
542 wxWinHashTable
*wxWinHandleHash
= NULL
;
544 wxWindow
*wxFindWinFromWinHandle(WXWINHANDLE handle
)
550 void wxRemoveHandleAssociation(wxWindowPalm
*win
)
554 // ----------------------------------------------------------------------------
555 // various Palm specific class dependent functions
556 // ----------------------------------------------------------------------------
558 bool wxWindowPalm::PalmGetCreateWindowCoords(const wxPoint
& pos
,
561 int& w
, int& h
) const
566 bool wxWindowPalm::PalmCreate(const wxChar
*wclass
,
571 WXDWORD extendedStyle
)
576 // ===========================================================================
577 // Palm message handlers
578 // ===========================================================================
580 // ---------------------------------------------------------------------------
582 // ---------------------------------------------------------------------------
584 // Can be called from an application's OnPaint handler
585 void wxWindowPalm::OnPaint(wxPaintEvent
& event
)
589 void wxWindowPalm::OnEraseBackground(wxEraseEvent
& event
)
593 // ---------------------------------------------------------------------------
594 // moving and resizing
595 // ---------------------------------------------------------------------------
597 bool wxWindowPalm::HandleMove(int x
, int y
)
602 bool wxWindowPalm::HandleMoving(wxRect
& rect
)
607 // ---------------------------------------------------------------------------
609 // ---------------------------------------------------------------------------
611 bool wxWindowPalm::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
616 // ---------------------------------------------------------------------------
618 // ---------------------------------------------------------------------------
620 bool wxWindowPalm::PalmOnScroll(int orientation
, WXWORD wParam
,
621 WXWORD pos
, WXWINHANDLE control
)
627 // ===========================================================================
629 // ===========================================================================
631 void wxGetCharSize(WXWINHANDLE wnd
, int *x
, int *y
, const wxFont
*the_font
)
638 bool wxWindowPalm::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
643 bool wxWindowPalm::UnregisterHotKey(int hotkeyId
)
647 #endif // # __WXUNIVERSAL__
648 #endif // wxUSE_HOTKEY