]> git.saurik.com Git - wxWidgets.git/blob - include/wx/palmos/window.h
compilation fix for raw bitmaps (can't include wx/rawbmp.h from wx/bitmap.h as the...
[wxWidgets.git] / 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
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
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
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
66 virtual bool Show( bool show = true );
67 virtual bool Enable( bool enable = true );
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
76 virtual void Refresh( bool eraseBackground = true,
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,
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 );
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
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 // Windows subclassing
151 void SubclassWin(WXHWND hWnd);
152 void UnsubclassWin();
153
154 WXFARPROC PalmGetOldWndProc() const { return m_oldWndProc; }
155 void PalmSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
156
157 // return true if the window is of a standard (i.e. not wxWidgets') class
158 //
159 // to understand why does it work, look at SubclassWin() code and comments
160 bool IsOfStandardClass() const { return m_oldWndProc != NULL; }
161
162 wxWindow *FindItem(long id) const;
163 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
164
165 // Palm only: true if this control is part of the main control
166 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; };
167
168 // translate wxWidgets style flags for this control into the Windows style
169 // and optional extended style for the corresponding native control
170 //
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 ;
174
175 // get the Palm window flags corresponding to wxWidgets ones
176 //
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); }
181
182 // translate wxWidgets coords into Windows ones suitable to be passed to
183 // ::CreateWindow()
184 //
185 // returns true if non default coords are returned, false otherwise
186 bool PalmGetCreateWindowCoords(const wxPoint& pos,
187 const wxSize& size,
188 int& x, int& y,
189 int& w, int& h) const;
190
191 // get the HWND to be used as parent of this window with CreateWindow()
192 virtual WXHWND PalmGetParent() const;
193
194 // creates the window of specified Windows class with given style, extended
195 // style, title and geometry (default values
196 //
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,
202 WXDWORD style = 0,
203 WXDWORD exendedStyle = 0);
204
205 virtual bool PalmCommand(WXUINT param, WXWORD id);
206
207 #ifndef __WXUNIVERSAL__
208 // Create an appropriate wxWindow from a HWND
209 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
210
211 // Make sure the window style reflects the HWND style (roughly)
212 virtual void AdoptAttributesFromHWND();
213 #endif // __WXUNIVERSAL__
214
215 // Setup background and foreground colours correctly
216 virtual void SetupColours();
217
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 // ------------------------------------------------------------------------
223
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);
234
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 // ------------------------------------------------------------------------
239
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.
246
247 // scroll event (both horizontal and vertical)
248 virtual bool PalmOnScroll(int orientation, WXWORD nSBCode,
249 WXWORD pos, WXHWND control);
250
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);
254
255 // the rest are not virtual
256 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
257 bool HandleInitDialog(WXHWND hWndFocus);
258 bool HandleDestroy();
259
260 bool HandlePaint();
261 bool HandleEraseBkgnd(WXHDC pDC);
262
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);
268
269 bool HandleShow(bool show, int status);
270 bool HandleActivate(int flag, bool minimized, WXHWND activate);
271
272 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
273
274 bool HandleCtlColor(WXHBRUSH *hBrush,
275 WXHDC hdc,
276 WXHWND hWnd,
277 WXUINT nCtlColor,
278 WXUINT message,
279 WXWPARAM wParam,
280 WXLPARAM lParam);
281
282 bool HandlePaletteChanged(WXHWND hWndPalChange);
283 bool HandleQueryNewPalette();
284 bool HandleSysColorChange();
285 bool HandleDisplayChange();
286 bool HandleCaptureChanged(WXHWND gainedCapture);
287
288 bool HandleQueryEndSession(long logOff, bool *mayEnd);
289 bool HandleEndSession(bool endSession, long logOff);
290
291 bool HandleSetFocus(WXHWND wnd);
292 bool HandleKillFocus(WXHWND wnd);
293
294 bool HandleDropFiles(WXWPARAM wParam);
295
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);
299
300 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false);
301 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
302 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
303 #if wxUSE_ACCEL
304 bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
305 #endif
306
307 bool HandleQueryDragIcon(WXHICON *hIcon);
308
309 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
310
311 // Window procedure
312 virtual WXLRESULT PalmWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
313
314 // Calls an appropriate default window procedure
315 virtual WXLRESULT PalmDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
316
317 // message processing helpers
318
319 // return false if the message shouldn't be translated/preprocessed but
320 // dispatched normally
321 virtual bool PalmShouldPreProcessMessage(WXMSG* pMsg);
322
323 // return true if the message was preprocessed and shouldn't be dispatched
324 virtual bool PalmProcessMessage(WXMSG* pMsg);
325
326 // return true if the message was translated and shouldn't be dispatched
327 virtual bool PalmTranslateMessage(WXMSG* pMsg);
328
329 // called when the window is about to be destroyed
330 virtual void PalmDestroyWindow();
331
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,
335 WXHWND hWnd,
336 WXUINT nCtlColor,
337 WXUINT message,
338 WXWPARAM wParam,
339 WXLPARAM lParam);
340
341 // Responds to colour changes: passes event on to children.
342 void OnSysColourChanged(wxSysColourChangedEvent& event);
343
344 // initialize various fields of wxMouseEvent (common part of PalmOnMouseXXX)
345 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
346
347 // check if mouse is in the window
348 bool IsMouseInWindow() const;
349
350 // virtual function for implementing internal idle
351 // behaviour
352 virtual void OnInternalIdle() ;
353
354 protected:
355 // the window handle
356 WXHWND m_hWnd;
357 FormType *FrameForm;
358
359 FormType *GetFormPtr();
360 void SetFormPtr(FormType *FormPtr);
361
362 // the old window proc (we subclass all windows)
363 WXFARPROC m_oldWndProc;
364
365 // additional (Palm specific) flags
366 bool m_mouseInWindow:1;
367 bool m_lastKeydownProcessed:1;
368
369 // the size of one page for scrolling
370 int m_xThumbSize;
371 int m_yThumbSize;
372
373 #if wxUSE_MOUSEEVENT_HACK
374 // the coordinates of the last mouse event and the type of it
375 long m_lastMouseX,
376 m_lastMouseY;
377 int m_lastMouseEvent;
378 #endif // wxUSE_MOUSEEVENT_HACK
379
380 WXHMENU m_hMenu; // Menu, if any
381
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);
392
393 virtual void DoCaptureMouse();
394 virtual void DoReleaseMouse();
395
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);
401
402 #if wxUSE_TOOLTIPS
403 virtual void DoSetToolTip( wxToolTip *tip );
404
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,
408 WXLPARAM lParam,
409 const wxString& ttip);
410 #endif // wxUSE_TOOLTIPS
411
412 // the helper functions used by HandleChar/KeyXXX methods
413 wxKeyEvent CreateKeyEvent(wxEventType evType, int id,
414 WXLPARAM lParam = 0, WXWPARAM wParam = 0) const;
415
416 private:
417 // common part of all ctors
418 void Init();
419
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);
424
425 // list of disabled children before last call to our Disable()
426 wxWindowList *m_childrenDisabled;
427
428 // number of calls to Freeze() minus number of calls to Thaw()
429 unsigned int m_frozenness;
430
431 DECLARE_DYNAMIC_CLASS(wxWindowPalm)
432 DECLARE_NO_COPY_CLASS(wxWindowPalm)
433 DECLARE_EVENT_TABLE()
434 };
435
436 // ---------------------------------------------------------------------------
437 // global functions
438 // ---------------------------------------------------------------------------
439
440 // kbd code translation
441 WXDLLEXPORT int wxCharCodePalmToWX(int keySym, WXLPARAM lParam = 0);
442 WXDLLEXPORT int wxCharCodeWXToPalm(int id, bool *IsVirtual);
443
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
448 {
449 public:
450 wxWindowCreationHook(wxWindowPalm *winBeingCreated);
451 ~wxWindowCreationHook();
452 };
453
454 // ----------------------------------------------------------------------------
455 // global objects
456 // ----------------------------------------------------------------------------
457
458 // notice that this hash must be defined after wxWindow declaration as it
459 // needs to "see" its dtor and not just forward declaration
460 #include "wx/hash.h"
461
462 // pseudo-template HWND <-> wxWindow hash table
463 WX_DECLARE_HASH(wxWindowPalm, wxWindowList, wxWinHashTable);
464
465 extern wxWinHashTable *wxWinHandleHash;
466
467 #endif
468 // _WX_WINDOW_H_