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