]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/palmos/window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/window.h
3 // Purpose: wxWindow class
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 /////////////////////////////////////////////////////////////////////////////
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "window.h"
23 // [at least] some version of Windows send extra mouse move messages after
24 // a mouse click or a key press - to temporarily fix this problem, set the
27 // a better solution should be found later...
28 #define wxUSE_MOUSEEVENT_HACK 0
30 // ---------------------------------------------------------------------------
31 // wxWindow declaration for Palm
32 // ---------------------------------------------------------------------------
34 class WXDLLEXPORT wxWindowPalm
: public wxWindowBase
37 wxWindowPalm() { Init(); }
39 wxWindowPalm(wxWindow
*parent
,
41 const wxPoint
& pos
= wxDefaultPosition
,
42 const wxSize
& size
= wxDefaultSize
,
44 const wxString
& name
= wxPanelNameStr
)
47 Create(parent
, id
, pos
, size
, style
, name
);
50 virtual ~wxWindowPalm();
52 bool Create(wxWindow
*parent
,
54 const wxPoint
& pos
= wxDefaultPosition
,
55 const wxSize
& size
= wxDefaultSize
,
57 const wxString
& name
= wxPanelNameStr
);
59 // implement base class pure virtuals
60 virtual void SetTitle( const wxString
& title
);
61 virtual wxString
GetTitle() const;
66 virtual bool Show( bool show
= true );
67 virtual bool Enable( bool enable
= true );
69 virtual void SetFocus();
70 virtual void SetFocusFromKbd();
72 virtual bool Reparent(wxWindowBase
*newParent
);
74 virtual void WarpPointer(int x
, int y
);
76 virtual void Refresh( bool eraseBackground
= true,
77 const wxRect
*rect
= (const wxRect
*) NULL
);
78 virtual void Update();
79 virtual void Freeze();
82 virtual void SetWindowStyleFlag( long style
);
83 virtual bool SetCursor( const wxCursor
&cursor
);
84 virtual bool SetFont( const wxFont
&font
);
86 virtual int GetCharHeight() const;
87 virtual int GetCharWidth() const;
88 virtual void GetTextExtent(const wxString
& string
,
90 int *descent
= (int *) NULL
,
91 int *externalLeading
= (int *) NULL
,
92 const wxFont
*theFont
= (const wxFont
*) NULL
)
95 #if wxUSE_MENUS_NATIVE
96 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
97 #endif // wxUSE_MENUS_NATIVE
99 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
100 int range
, bool refresh
= true );
101 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
102 virtual int GetScrollPos( int orient
) const;
103 virtual int GetScrollThumb( int orient
) const;
104 virtual int GetScrollRange( int orient
) const;
105 virtual void ScrollWindow( int dx
, int dy
,
106 const wxRect
* rect
= (wxRect
*) NULL
);
108 virtual bool ScrollLines(int lines
);
109 virtual bool ScrollPages(int pages
);
111 #if wxUSE_DRAG_AND_DROP
112 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
113 #endif // wxUSE_DRAG_AND_DROP
115 // Accept files for dragging
116 virtual void DragAcceptFiles(bool accept
);
118 #ifndef __WXUNIVERSAL__
119 // Native resource loading (implemented in src/Palm/nativdlg.cpp)
120 // FIXME: should they really be all virtual?
121 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
122 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
123 wxWindow
* GetWindowChild1(wxWindowID id
);
124 wxWindow
* GetWindowChild(wxWindowID id
);
125 #endif // __WXUNIVERSAL__
128 // install and deinstall a system wide hotkey
129 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
130 virtual bool UnregisterHotKey(int hotkeyId
);
131 #endif // wxUSE_HOTKEY
133 // implementation from now on
134 // --------------------------
139 WXHWND
GetHWND() const { return m_hWnd
; }
140 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
141 virtual WXWidget
GetHandle() const { return GetHWND(); }
146 void OnEraseBackground(wxEraseEvent
& event
);
147 void OnPaint(wxPaintEvent
& event
);
150 // Windows subclassing
151 void SubclassWin(WXHWND hWnd
);
152 void UnsubclassWin();
154 WXFARPROC
PalmGetOldWndProc() const { return m_oldWndProc
; }
155 void PalmSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
157 // return true if the window is of a standard (i.e. not wxWidgets') class
159 // to understand why does it work, look at SubclassWin() code and comments
160 bool IsOfStandardClass() const { return m_oldWndProc
!= NULL
; }
162 wxWindow
*FindItem(long id
) const;
163 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
165 // Palm only: true if this control is part of the main control
166 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; };
168 // translate wxWidgets style flags for this control into the Windows style
169 // and optional extended style for the corresponding native control
171 // this is the function that should be overridden in the derived classes,
172 // but you will mostly use PalmGetCreateWindowFlags() below
173 virtual WXDWORD
PalmGetStyle(long flags
, WXDWORD
*exstyle
= NULL
) const ;
175 // get the Palm window flags corresponding to wxWidgets ones
177 // the functions returns the flags (WS_XXX) directly and puts the ext
178 // (WS_EX_XXX) flags into the provided pointer if not NULL
179 WXDWORD
PalmGetCreateWindowFlags(WXDWORD
*exflags
= NULL
) const
180 { return PalmGetStyle(GetWindowStyle(), exflags
); }
182 // translate wxWidgets coords into Windows ones suitable to be passed to
185 // returns true if non default coords are returned, false otherwise
186 bool PalmGetCreateWindowCoords(const wxPoint
& pos
,
189 int& w
, int& h
) const;
191 // get the HWND to be used as parent of this window with CreateWindow()
192 virtual WXHWND
PalmGetParent() const;
194 // creates the window of specified Windows class with given style, extended
195 // style, title and geometry (default values
197 // returns true if the window has been created, false if creation failed
198 bool PalmCreate(const wxChar
*wclass
,
199 const wxChar
*title
= NULL
,
200 const wxPoint
& pos
= wxDefaultPosition
,
201 const wxSize
& size
= wxDefaultSize
,
203 WXDWORD exendedStyle
= 0);
205 virtual bool PalmCommand(WXUINT param
, WXWORD id
);
207 #ifndef __WXUNIVERSAL__
208 // Create an appropriate wxWindow from a HWND
209 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
211 // Make sure the window style reflects the HWND style (roughly)
212 virtual void AdoptAttributesFromHWND();
213 #endif // __WXUNIVERSAL__
215 // Setup background and foreground colours correctly
216 virtual void SetupColours();
218 // ------------------------------------------------------------------------
219 // helpers for message handlers: these perform the same function as the
220 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
221 // the correct parameters
222 // ------------------------------------------------------------------------
224 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
225 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
226 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
227 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
228 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
229 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
230 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
231 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
232 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
233 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
235 // ------------------------------------------------------------------------
236 // internal handlers for Palm messages: all handlers return a boolean value:
237 // true means that the handler processed the event and false that it didn't
238 // ------------------------------------------------------------------------
240 // there are several cases where we have virtual functions for Windows
241 // message processing: this is because these messages often require to be
242 // processed in a different manner in the derived classes. For all other
243 // messages, however, we do *not* have corresponding PalmOnXXX() function
244 // and if the derived class wants to process them, it should override
245 // PalmWindowProc() directly.
247 // scroll event (both horizontal and vertical)
248 virtual bool PalmOnScroll(int orientation
, WXWORD nSBCode
,
249 WXWORD pos
, WXHWND control
);
251 // owner-drawn controls need to process these messages
252 virtual bool PalmOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
253 virtual bool PalmOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
255 // the rest are not virtual
256 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
257 bool HandleInitDialog(WXHWND hWndFocus
);
258 bool HandleDestroy();
261 bool HandleEraseBkgnd(WXHDC pDC
);
263 bool HandleMinimize();
264 bool HandleMaximize();
265 bool HandleSize(int x
, int y
, WXUINT flag
);
266 bool HandleSizing(wxRect
& rect
);
267 bool HandleGetMinMaxInfo(void *mmInfo
);
269 bool HandleShow(bool show
, int status
);
270 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
272 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
274 bool HandleCtlColor(WXHBRUSH
*hBrush
,
282 bool HandlePaletteChanged(WXHWND hWndPalChange
);
283 bool HandleQueryNewPalette();
284 bool HandleSysColorChange();
285 bool HandleDisplayChange();
286 bool HandleCaptureChanged(WXHWND gainedCapture
);
288 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
289 bool HandleEndSession(bool endSession
, long logOff
);
291 bool HandleSetFocus(WXHWND wnd
);
292 bool HandleKillFocus(WXHWND wnd
);
294 bool HandleDropFiles(WXWPARAM wParam
);
296 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
297 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
298 bool HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
);
300 bool HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
= false);
301 bool HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
);
302 bool HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
);
304 bool HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
);
307 bool HandleQueryDragIcon(WXHICON
*hIcon
);
309 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
312 virtual WXLRESULT
PalmWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
314 // Calls an appropriate default window procedure
315 virtual WXLRESULT
PalmDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
317 // message processing helpers
319 // return false if the message shouldn't be translated/preprocessed but
320 // dispatched normally
321 virtual bool PalmShouldPreProcessMessage(WXMSG
* pMsg
);
323 // return true if the message was preprocessed and shouldn't be dispatched
324 virtual bool PalmProcessMessage(WXMSG
* pMsg
);
326 // return true if the message was translated and shouldn't be dispatched
327 virtual bool PalmTranslateMessage(WXMSG
* pMsg
);
329 // called when the window is about to be destroyed
330 virtual void PalmDestroyWindow();
332 // this function should return the brush to paint the window background
333 // with or 0 for the default brush
334 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
341 // Responds to colour changes: passes event on to children.
342 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
344 // initialize various fields of wxMouseEvent (common part of PalmOnMouseXXX)
345 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
347 // check if mouse is in the window
348 bool IsMouseInWindow() const;
350 // virtual function for implementing internal idle
352 virtual void OnInternalIdle() ;
359 FormType
*GetFormPtr();
360 void SetFormPtr(FormType
*FormPtr
);
362 // the old window proc (we subclass all windows)
363 WXFARPROC m_oldWndProc
;
365 // additional (Palm specific) flags
366 bool m_mouseInWindow
:1;
367 bool m_lastKeydownProcessed
:1;
369 // the size of one page for scrolling
373 #if wxUSE_MOUSEEVENT_HACK
374 // the coordinates of the last mouse event and the type of it
377 int m_lastMouseEvent
;
378 #endif // wxUSE_MOUSEEVENT_HACK
380 WXHMENU m_hMenu
; // Menu, if any
382 // implement the base class pure virtuals
383 virtual void DoClientToScreen( int *x
, int *y
) const;
384 virtual void DoScreenToClient( int *x
, int *y
) const;
385 virtual void DoGetPosition( int *x
, int *y
) const;
386 virtual void DoGetSize( int *width
, int *height
) const;
387 virtual void DoGetClientSize( int *width
, int *height
) const;
388 virtual void DoSetSize(int x
, int y
,
389 int width
, int height
,
390 int sizeFlags
= wxSIZE_AUTO
);
391 virtual void DoSetClientSize(int width
, int height
);
393 virtual void DoCaptureMouse();
394 virtual void DoReleaseMouse();
396 // move the window to the specified location and resize it: this is called
397 // from both DoSetSize() and DoSetClientSize() and would usually just call
398 // ::MoveWindow() except for composite controls which will want to arrange
399 // themselves inside the given rectangle
400 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
403 virtual void DoSetToolTip( wxToolTip
*tip
);
405 // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
406 // comctl32.dll in our code -- see the function body for more info)
407 bool HandleTooltipNotify(WXUINT code
,
409 const wxString
& ttip
);
410 #endif // wxUSE_TOOLTIPS
412 // the helper functions used by HandleChar/KeyXXX methods
413 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
,
414 WXLPARAM lParam
= 0, WXWPARAM wParam
= 0) const;
417 // common part of all ctors
420 // the (non-virtual) handlers for the events
421 bool HandleMove(int x
, int y
);
422 bool HandleMoving(wxRect
& rect
);
423 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
425 // list of disabled children before last call to our Disable()
426 wxWindowList
*m_childrenDisabled
;
428 // number of calls to Freeze() minus number of calls to Thaw()
429 unsigned int m_frozenness
;
431 DECLARE_DYNAMIC_CLASS(wxWindowPalm
)
432 DECLARE_NO_COPY_CLASS(wxWindowPalm
)
433 DECLARE_EVENT_TABLE()
436 // ---------------------------------------------------------------------------
438 // ---------------------------------------------------------------------------
440 // kbd code translation
441 WXDLLEXPORT
int wxCharCodePalmToWX(int keySym
, WXLPARAM lParam
= 0);
442 WXDLLEXPORT
int wxCharCodeWXToPalm(int id
, bool *IsVirtual
);
444 // window creation helper class: before creating a new HWND, instantiate an
445 // object of this class on stack - this allows to process the messages sent to
446 // the window even before CreateWindow() returns
447 class wxWindowCreationHook
450 wxWindowCreationHook(wxWindowPalm
*winBeingCreated
);
451 ~wxWindowCreationHook();
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 // notice that this hash must be defined after wxWindow declaration as it
459 // needs to "see" its dtor and not just forward declaration
462 // pseudo-template HWND <-> wxWindow hash table
463 WX_DECLARE_HASH(wxWindowPalm
, wxWindowList
, wxWinHashTable
);
465 extern wxWinHashTable
*wxWinHandleHash
;