]>
Commit | Line | Data |
---|---|---|
ffecfa5a JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/palmos/window.h | |
3 | // Purpose: wxWindow class | |
e1d63b79 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
db101bd3 | 5 | // Modified by: Wlodzimierz ABX Skiba - more than minimal functionality |
ffecfa5a | 6 | // Created: 10/13/04 |
e1d63b79 | 7 | // RCS-ID: $Id$ |
db101bd3 | 8 | // Copyright: (c) William Osborne, Wlodzimierz Skiba |
ffecfa5a JS |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_WINDOW_H_ | |
13 | #define _WX_WINDOW_H_ | |
14 | ||
ffecfa5a JS |
15 | // --------------------------------------------------------------------------- |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
20 | #pragma interface "window.h" | |
21 | #endif | |
22 | ||
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 | |
25 | // define below to 1 | |
26 | // | |
27 | // a better solution should be found later... | |
28 | #define wxUSE_MOUSEEVENT_HACK 0 | |
29 | ||
ffecfa5a JS |
30 | // --------------------------------------------------------------------------- |
31 | // wxWindow declaration for Palm | |
32 | // --------------------------------------------------------------------------- | |
33 | ||
34 | class WXDLLEXPORT wxWindowPalm : public wxWindowBase | |
35 | { | |
36 | public: | |
37 | wxWindowPalm() { Init(); } | |
38 | ||
39 | wxWindowPalm(wxWindow *parent, | |
40 | wxWindowID id, | |
41 | const wxPoint& pos = wxDefaultPosition, | |
42 | const wxSize& size = wxDefaultSize, | |
43 | long style = 0, | |
44 | const wxString& name = wxPanelNameStr) | |
45 | { | |
46 | Init(); | |
47 | Create(parent, id, pos, size, style, name); | |
48 | } | |
49 | ||
50 | virtual ~wxWindowPalm(); | |
51 | ||
52 | bool Create(wxWindow *parent, | |
53 | wxWindowID id, | |
54 | const wxPoint& pos = wxDefaultPosition, | |
55 | const wxSize& size = wxDefaultSize, | |
56 | long style = 0, | |
57 | const wxString& name = wxPanelNameStr); | |
58 | ||
59 | // implement base class pure virtuals | |
60 | virtual void SetTitle( const wxString& title); | |
61 | virtual wxString GetTitle() const; | |
62 | ||
63 | virtual void Raise(); | |
64 | virtual void Lower(); | |
65 | ||
e951b8e4 WS |
66 | virtual bool Show( bool show = true ); |
67 | virtual bool Enable( bool enable = true ); | |
ffecfa5a JS |
68 | |
69 | virtual void SetFocus(); | |
70 | virtual void SetFocusFromKbd(); | |
71 | ||
72 | virtual bool Reparent(wxWindowBase *newParent); | |
73 | ||
74 | virtual void WarpPointer(int x, int y); | |
75 | ||
e951b8e4 | 76 | virtual void Refresh( bool eraseBackground = true, |
ffecfa5a JS |
77 | const wxRect *rect = (const wxRect *) NULL ); |
78 | virtual void Update(); | |
79 | virtual void Freeze(); | |
80 | virtual void Thaw(); | |
81 | ||
82 | virtual void SetWindowStyleFlag( long style ); | |
83 | virtual bool SetCursor( const wxCursor &cursor ); | |
84 | virtual bool SetFont( const wxFont &font ); | |
85 | ||
86 | virtual int GetCharHeight() const; | |
87 | virtual int GetCharWidth() const; | |
88 | virtual void GetTextExtent(const wxString& string, | |
89 | int *x, int *y, | |
90 | int *descent = (int *) NULL, | |
91 | int *externalLeading = (int *) NULL, | |
92 | const wxFont *theFont = (const wxFont *) NULL) | |
93 | const; | |
94 | ||
95 | #if wxUSE_MENUS_NATIVE | |
96 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); | |
97 | #endif // wxUSE_MENUS_NATIVE | |
98 | ||
99 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, | |
e951b8e4 WS |
100 | int range, bool refresh = true ); |
101 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ); | |
ffecfa5a JS |
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 ); | |
107 | ||
108 | virtual bool ScrollLines(int lines); | |
109 | virtual bool ScrollPages(int pages); | |
110 | ||
111 | #if wxUSE_DRAG_AND_DROP | |
112 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
113 | #endif // wxUSE_DRAG_AND_DROP | |
114 | ||
115 | // Accept files for dragging | |
116 | virtual void DragAcceptFiles(bool accept); | |
117 | ||
ffecfa5a JS |
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__ | |
126 | ||
127 | #if wxUSE_HOTKEY | |
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 | |
132 | ||
133 | // implementation from now on | |
134 | // -------------------------- | |
135 | ||
136 | // simple accessors | |
137 | // ---------------- | |
138 | ||
139 | WXHWND GetHWND() const { return m_hWnd; } | |
140 | void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; } | |
141 | virtual WXWidget GetHandle() const { return GetHWND(); } | |
142 | ||
143 | // event handlers | |
144 | // -------------- | |
145 | ||
146 | void OnEraseBackground(wxEraseEvent& event); | |
147 | void OnPaint(wxPaintEvent& event); | |
148 | ||
149 | public: | |
150 | // For implementation purposes - sometimes decorations make the client area | |
151 | // smaller | |
152 | virtual wxPoint GetClientAreaOrigin() const; | |
153 | ||
154 | // Windows subclassing | |
155 | void SubclassWin(WXHWND hWnd); | |
156 | void UnsubclassWin(); | |
157 | ||
158 | WXFARPROC PalmGetOldWndProc() const { return m_oldWndProc; } | |
159 | void PalmSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; } | |
160 | ||
e951b8e4 | 161 | // return true if the window is of a standard (i.e. not wxWidgets') class |
ffecfa5a JS |
162 | // |
163 | // to understand why does it work, look at SubclassWin() code and comments | |
164 | bool IsOfStandardClass() const { return m_oldWndProc != NULL; } | |
165 | ||
166 | wxWindow *FindItem(long id) const; | |
e951b8e4 | 167 | wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const; |
ffecfa5a | 168 | |
e951b8e4 WS |
169 | // Palm only: true if this control is part of the main control |
170 | virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; }; | |
ffecfa5a JS |
171 | |
172 | // translate wxWidgets style flags for this control into the Windows style | |
173 | // and optional extended style for the corresponding native control | |
174 | // | |
175 | // this is the function that should be overridden in the derived classes, | |
176 | // but you will mostly use PalmGetCreateWindowFlags() below | |
177 | virtual WXDWORD PalmGetStyle(long flags, WXDWORD *exstyle = NULL) const ; | |
178 | ||
179 | // get the Palm window flags corresponding to wxWidgets ones | |
180 | // | |
181 | // the functions returns the flags (WS_XXX) directly and puts the ext | |
182 | // (WS_EX_XXX) flags into the provided pointer if not NULL | |
183 | WXDWORD PalmGetCreateWindowFlags(WXDWORD *exflags = NULL) const | |
184 | { return PalmGetStyle(GetWindowStyle(), exflags); } | |
185 | ||
186 | // translate wxWidgets coords into Windows ones suitable to be passed to | |
187 | // ::CreateWindow() | |
188 | // | |
e951b8e4 | 189 | // returns true if non default coords are returned, false otherwise |
ffecfa5a JS |
190 | bool PalmGetCreateWindowCoords(const wxPoint& pos, |
191 | const wxSize& size, | |
192 | int& x, int& y, | |
193 | int& w, int& h) const; | |
194 | ||
195 | // get the HWND to be used as parent of this window with CreateWindow() | |
196 | virtual WXHWND PalmGetParent() const; | |
197 | ||
198 | // creates the window of specified Windows class with given style, extended | |
199 | // style, title and geometry (default values | |
200 | // | |
e951b8e4 | 201 | // returns true if the window has been created, false if creation failed |
ffecfa5a JS |
202 | bool PalmCreate(const wxChar *wclass, |
203 | const wxChar *title = NULL, | |
204 | const wxPoint& pos = wxDefaultPosition, | |
205 | const wxSize& size = wxDefaultSize, | |
206 | WXDWORD style = 0, | |
207 | WXDWORD exendedStyle = 0); | |
208 | ||
209 | virtual bool PalmCommand(WXUINT param, WXWORD id); | |
210 | ||
211 | #ifndef __WXUNIVERSAL__ | |
212 | // Create an appropriate wxWindow from a HWND | |
213 | virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd); | |
214 | ||
215 | // Make sure the window style reflects the HWND style (roughly) | |
216 | virtual void AdoptAttributesFromHWND(); | |
217 | #endif // __WXUNIVERSAL__ | |
218 | ||
219 | // Setup background and foreground colours correctly | |
220 | virtual void SetupColours(); | |
221 | ||
222 | // ------------------------------------------------------------------------ | |
223 | // helpers for message handlers: these perform the same function as the | |
224 | // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into | |
225 | // the correct parameters | |
226 | // ------------------------------------------------------------------------ | |
227 | ||
228 | void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, | |
229 | WXWORD *id, WXHWND *hwnd, WXWORD *cmd); | |
230 | void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, | |
231 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd); | |
232 | void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, | |
233 | WXWORD *code, WXWORD *pos, WXHWND *hwnd); | |
234 | void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, | |
235 | WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd); | |
236 | void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, | |
237 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu); | |
238 | ||
239 | // ------------------------------------------------------------------------ | |
240 | // internal handlers for Palm messages: all handlers return a boolean value: | |
e951b8e4 | 241 | // true means that the handler processed the event and false that it didn't |
ffecfa5a JS |
242 | // ------------------------------------------------------------------------ |
243 | ||
244 | // there are several cases where we have virtual functions for Windows | |
245 | // message processing: this is because these messages often require to be | |
246 | // processed in a different manner in the derived classes. For all other | |
247 | // messages, however, we do *not* have corresponding PalmOnXXX() function | |
248 | // and if the derived class wants to process them, it should override | |
249 | // PalmWindowProc() directly. | |
250 | ||
251 | // scroll event (both horizontal and vertical) | |
252 | virtual bool PalmOnScroll(int orientation, WXWORD nSBCode, | |
253 | WXWORD pos, WXHWND control); | |
254 | ||
ffecfa5a JS |
255 | // owner-drawn controls need to process these messages |
256 | virtual bool PalmOnDrawItem(int id, WXDRAWITEMSTRUCT *item); | |
257 | virtual bool PalmOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item); | |
258 | ||
259 | // the rest are not virtual | |
260 | bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate); | |
261 | bool HandleInitDialog(WXHWND hWndFocus); | |
262 | bool HandleDestroy(); | |
263 | ||
264 | bool HandlePaint(); | |
265 | bool HandleEraseBkgnd(WXHDC pDC); | |
266 | ||
267 | bool HandleMinimize(); | |
268 | bool HandleMaximize(); | |
269 | bool HandleSize(int x, int y, WXUINT flag); | |
270 | bool HandleSizing(wxRect& rect); | |
271 | bool HandleGetMinMaxInfo(void *mmInfo); | |
272 | ||
273 | bool HandleShow(bool show, int status); | |
274 | bool HandleActivate(int flag, bool minimized, WXHWND activate); | |
275 | ||
276 | bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); | |
277 | ||
278 | bool HandleCtlColor(WXHBRUSH *hBrush, | |
279 | WXHDC hdc, | |
280 | WXHWND hWnd, | |
281 | WXUINT nCtlColor, | |
282 | WXUINT message, | |
283 | WXWPARAM wParam, | |
284 | WXLPARAM lParam); | |
285 | ||
286 | bool HandlePaletteChanged(WXHWND hWndPalChange); | |
287 | bool HandleQueryNewPalette(); | |
288 | bool HandleSysColorChange(); | |
289 | bool HandleDisplayChange(); | |
290 | bool HandleCaptureChanged(WXHWND gainedCapture); | |
291 | ||
292 | bool HandleQueryEndSession(long logOff, bool *mayEnd); | |
293 | bool HandleEndSession(bool endSession, long logOff); | |
294 | ||
295 | bool HandleSetFocus(WXHWND wnd); | |
296 | bool HandleKillFocus(WXHWND wnd); | |
297 | ||
298 | bool HandleDropFiles(WXWPARAM wParam); | |
299 | ||
300 | bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags); | |
301 | bool HandleMouseMove(int x, int y, WXUINT flags); | |
302 | bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam); | |
303 | ||
e951b8e4 | 304 | bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false); |
ffecfa5a JS |
305 | bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam); |
306 | bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam); | |
307 | #if wxUSE_ACCEL | |
308 | bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam); | |
309 | #endif | |
ffecfa5a JS |
310 | |
311 | bool HandleQueryDragIcon(WXHICON *hIcon); | |
312 | ||
313 | bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg); | |
314 | ||
315 | // Window procedure | |
316 | virtual WXLRESULT PalmWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
317 | ||
318 | // Calls an appropriate default window procedure | |
319 | virtual WXLRESULT PalmDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
320 | ||
321 | // message processing helpers | |
322 | ||
e951b8e4 | 323 | // return false if the message shouldn't be translated/preprocessed but |
ffecfa5a JS |
324 | // dispatched normally |
325 | virtual bool PalmShouldPreProcessMessage(WXMSG* pMsg); | |
326 | ||
e951b8e4 | 327 | // return true if the message was preprocessed and shouldn't be dispatched |
ffecfa5a JS |
328 | virtual bool PalmProcessMessage(WXMSG* pMsg); |
329 | ||
e951b8e4 | 330 | // return true if the message was translated and shouldn't be dispatched |
ffecfa5a JS |
331 | virtual bool PalmTranslateMessage(WXMSG* pMsg); |
332 | ||
333 | // called when the window is about to be destroyed | |
334 | virtual void PalmDestroyWindow(); | |
335 | ||
336 | // this function should return the brush to paint the window background | |
337 | // with or 0 for the default brush | |
338 | virtual WXHBRUSH OnCtlColor(WXHDC hDC, | |
339 | WXHWND hWnd, | |
340 | WXUINT nCtlColor, | |
341 | WXUINT message, | |
342 | WXWPARAM wParam, | |
343 | WXLPARAM lParam); | |
344 | ||
345 | // Responds to colour changes: passes event on to children. | |
346 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
347 | ||
348 | // initialize various fields of wxMouseEvent (common part of PalmOnMouseXXX) | |
349 | void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags); | |
350 | ||
351 | // check if mouse is in the window | |
352 | bool IsMouseInWindow() const; | |
353 | ||
354 | // virtual function for implementing internal idle | |
355 | // behaviour | |
356 | virtual void OnInternalIdle() ; | |
357 | ||
358 | protected: | |
359 | // the window handle | |
360 | WXHWND m_hWnd; | |
361 | FormType *FrameForm; | |
e951b8e4 | 362 | |
ffecfa5a JS |
363 | FormType *GetFormPtr(); |
364 | void SetFormPtr(FormType *FormPtr); | |
365 | ||
366 | // the old window proc (we subclass all windows) | |
367 | WXFARPROC m_oldWndProc; | |
368 | ||
369 | // additional (Palm specific) flags | |
370 | bool m_mouseInWindow:1; | |
371 | bool m_lastKeydownProcessed:1; | |
372 | ||
373 | // the size of one page for scrolling | |
374 | int m_xThumbSize; | |
375 | int m_yThumbSize; | |
376 | ||
377 | #if wxUSE_MOUSEEVENT_HACK | |
378 | // the coordinates of the last mouse event and the type of it | |
379 | long m_lastMouseX, | |
380 | m_lastMouseY; | |
381 | int m_lastMouseEvent; | |
382 | #endif // wxUSE_MOUSEEVENT_HACK | |
383 | ||
384 | WXHMENU m_hMenu; // Menu, if any | |
385 | ||
386 | // implement the base class pure virtuals | |
387 | virtual void DoClientToScreen( int *x, int *y ) const; | |
388 | virtual void DoScreenToClient( int *x, int *y ) const; | |
389 | virtual void DoGetPosition( int *x, int *y ) const; | |
390 | virtual void DoGetSize( int *width, int *height ) const; | |
391 | virtual void DoGetClientSize( int *width, int *height ) const; | |
392 | virtual void DoSetSize(int x, int y, | |
393 | int width, int height, | |
394 | int sizeFlags = wxSIZE_AUTO); | |
395 | virtual void DoSetClientSize(int width, int height); | |
396 | ||
397 | virtual void DoCaptureMouse(); | |
398 | virtual void DoReleaseMouse(); | |
399 | ||
400 | // move the window to the specified location and resize it: this is called | |
401 | // from both DoSetSize() and DoSetClientSize() and would usually just call | |
402 | // ::MoveWindow() except for composite controls which will want to arrange | |
403 | // themselves inside the given rectangle | |
404 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
405 | ||
406 | #if wxUSE_TOOLTIPS | |
407 | virtual void DoSetToolTip( wxToolTip *tip ); | |
408 | ||
409 | // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in | |
410 | // comctl32.dll in our code -- see the function body for more info) | |
411 | bool HandleTooltipNotify(WXUINT code, | |
412 | WXLPARAM lParam, | |
413 | const wxString& ttip); | |
414 | #endif // wxUSE_TOOLTIPS | |
415 | ||
416 | // the helper functions used by HandleChar/KeyXXX methods | |
417 | wxKeyEvent CreateKeyEvent(wxEventType evType, int id, | |
418 | WXLPARAM lParam = 0, WXWPARAM wParam = 0) const; | |
419 | ||
420 | private: | |
421 | // common part of all ctors | |
422 | void Init(); | |
423 | ||
424 | // the (non-virtual) handlers for the events | |
425 | bool HandleMove(int x, int y); | |
426 | bool HandleMoving(wxRect& rect); | |
427 | bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); | |
428 | ||
ffecfa5a JS |
429 | // list of disabled children before last call to our Disable() |
430 | wxWindowList *m_childrenDisabled; | |
431 | ||
432 | // number of calls to Freeze() minus number of calls to Thaw() | |
433 | unsigned int m_frozenness; | |
434 | ||
435 | DECLARE_DYNAMIC_CLASS(wxWindowPalm) | |
436 | DECLARE_NO_COPY_CLASS(wxWindowPalm) | |
437 | DECLARE_EVENT_TABLE() | |
438 | }; | |
439 | ||
ffecfa5a JS |
440 | // --------------------------------------------------------------------------- |
441 | // global functions | |
442 | // --------------------------------------------------------------------------- | |
443 | ||
444 | // kbd code translation | |
445 | WXDLLEXPORT int wxCharCodePalmToWX(int keySym, WXLPARAM lParam = 0); | |
446 | WXDLLEXPORT int wxCharCodeWXToPalm(int id, bool *IsVirtual); | |
447 | ||
448 | // window creation helper class: before creating a new HWND, instantiate an | |
449 | // object of this class on stack - this allows to process the messages sent to | |
450 | // the window even before CreateWindow() returns | |
451 | class wxWindowCreationHook | |
452 | { | |
453 | public: | |
454 | wxWindowCreationHook(wxWindowPalm *winBeingCreated); | |
455 | ~wxWindowCreationHook(); | |
456 | }; | |
457 | ||
458 | // ---------------------------------------------------------------------------- | |
459 | // global objects | |
460 | // ---------------------------------------------------------------------------- | |
461 | ||
462 | // notice that this hash must be defined after wxWindow declaration as it | |
463 | // needs to "see" its dtor and not just forward declaration | |
464 | #include "wx/hash.h" | |
465 | ||
466 | // pseudo-template HWND <-> wxWindow hash table | |
ffecfa5a | 467 | WX_DECLARE_HASH(wxWindowPalm, wxWindowList, wxWinHashTable); |
ffecfa5a JS |
468 | |
469 | extern wxWinHashTable *wxWinHandleHash; | |
470 | ||
471 | #endif | |
472 | // _WX_WINDOW_H_ |