]> git.saurik.com Git - wxWidgets.git/blob - src/os2/window.cpp
replaced T() makro with wxT() due to namespace probs, _T() exists, too
[wxWidgets.git] / src / os2 / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #ifndef WX_PRECOMP
17 #define INCL_DOS
18 #define INCL_PM
19 #include <os2.h>
20 #include "wx/window.h"
21 #include "wx/accel.h"
22 #include "wx/setup.h"
23 #include "wx/menu.h"
24 #include "wx/dc.h"
25 #include "wx/dcclient.h"
26 #include "wx/utils.h"
27 #include "wx/app.h"
28 #include "wx/panel.h"
29 #include "wx/layout.h"
30 #include "wx/dialog.h"
31 #include "wx/frame.h"
32 #include "wx/listbox.h"
33 #include "wx/button.h"
34 #include "wx/msgdlg.h"
35
36 #include <stdio.h>
37 #endif
38
39 #if wxUSE_OWNER_DRAWN
40 #include "wx/ownerdrw.h"
41 #endif
42
43 #if wxUSE_DRAG_AND_DROP
44 #include "wx/dnd.h"
45 #endif
46
47 #include "wx/menuitem.h"
48 #include "wx/log.h"
49
50 #if wxUSE_TOOLTIPS
51 #include "wx/tooltip.h"
52 #endif
53
54 #if wxUSE_CARET
55 #include "wx/caret.h"
56 #endif // wxUSE_CARET
57
58 #include "wx/intl.h"
59 #include "wx/log.h"
60
61
62 #include "wx/textctrl.h"
63
64 #include <string.h>
65
66 // place compiler, OS specific includes here
67
68
69 // standard macros -- these are for OS/2 PM, but most GUI's have something similar
70 #ifndef GET_X_LPARAM
71 // SHORT1FROMMP -- LOWORD
72 #define GET_X_LPARAM(mp) ((unsigned short)(unsigned long)(mp))
73 // SHORT2FROMMP -- HIWORD
74 #define GET_Y_LPARAM(mp) ((unsigned short)(unsigned long)(mp >> 16))
75 #endif // GET_X_LPARAM
76
77 // ---------------------------------------------------------------------------
78 // global variables
79 // ---------------------------------------------------------------------------
80
81 // the last Windows message we got (MT-UNSAFE)
82 extern WXMSGID s_currentMsg;
83 extern wxList WXDLLEXPORT wxPendingDelete;
84 extern wxChar wxCanvasClassName[];
85
86 wxMenu *wxCurrentPopupMenu = NULL;
87 wxList *wxWinHandleList = NULL;
88
89 // ---------------------------------------------------------------------------
90 // private functions
91 // ---------------------------------------------------------------------------
92 // the window proc for all our windows; most gui's have something similar
93 MRESULT wxWndProc( HWND hWnd
94 ,ULONG message
95 ,MPARAM mp1
96 ,MPARAM mp2
97 );
98 void wxRemoveHandleAssociation(wxWindow *win);
99 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
100 wxWindow *wxFindWinFromHandle(WXHWND hWnd);
101
102 // ---------------------------------------------------------------------------
103 // event tables
104 // ---------------------------------------------------------------------------
105
106 #if !USE_SHARED_LIBRARY
107 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
108 #endif
109
110 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
111 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
112 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
113 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
114 EVT_IDLE(wxWindow::OnIdle)
115 END_EVENT_TABLE()
116
117 // ===========================================================================
118 // implementation
119 // ===========================================================================
120
121 void wxWindow::Init()
122 {
123 // generic
124 InitBase();
125
126 // PM specific
127 m_winCaptured = FALSE;
128 m_isBeingDeleted = FALSE;
129 m_mouseInWindow = FALSE;
130 m_backgroundTransparent = FALSE;
131
132 // wxWnd
133 m_hMenu = 0;
134
135 m_hWnd = 0;
136
137 // pass WM_GETDLGCODE to DefWindowProc()
138 m_lDlgCode = 0;
139
140 m_xThumbSize = 0;
141 m_yThumbSize = 0;
142
143 // as all windows are created with WS_VISIBLE style...
144 m_isShown = TRUE;
145
146 }
147
148 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
149 const wxPoint& pos,
150 const wxSize& size,
151 long style,
152 const wxString& name)
153 {
154 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
155
156 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
157 return FALSE;
158
159 // TODO: PM Specific initialization
160 parent->AddChild(this);
161 return TRUE;
162 }
163
164 // Destructor
165 wxWindow::~wxWindow()
166 {
167 m_isBeingDeleted = TRUE;
168
169 PMDetachWindowMenu();
170 // delete handlers?
171 if (m_parent)
172 m_parent->RemoveChild(this);
173 DestroyChildren();
174 if (m_hWnd)
175 {
176 if(!WinDestroyWindow(GetHWND()))
177 wxLogLastError(wxT("DestroyWindow"));
178 // remove hWnd <-> wxWindow association
179 wxRemoveHandleAssociation(this);
180 }
181 }
182
183 // ---------------------------------------------------------------------------
184 // basic operations
185 // ---------------------------------------------------------------------------
186
187 void wxWindow::Raise()
188 {
189 // TODO:
190 }
191
192 void wxWindow::Lower()
193 {
194 // TODO:
195 }
196
197 void wxWindow::SetFocus()
198 {
199 // TODO:
200 }
201
202 void wxWindow::WarpPointer(int x_pos, int y_pos)
203 {
204 // TODO:
205 }
206
207 void wxWindow::CaptureMouse()
208 {
209 // TODO:
210 }
211
212 void wxWindow::ReleaseMouse()
213 {
214 // TODO:
215 }
216
217 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
218 {
219 // TODO:
220 }
221
222 void wxWindow::Clear()
223 {
224 // TODO:
225 }
226
227 bool wxWindow::SetFont(const wxFont& f)
228 {
229 // TODO:
230 return(TRUE);
231 }
232
233 int wxWindow::GetCharHeight() const
234 {
235 // TODO:
236 return(1);
237 }
238
239 int wxWindow::GetCharWidth() const
240 {
241 // TODO:
242 return(1);
243 }
244
245 void wxWindow::GetTextExtent( const wxString& string
246 ,int* x
247 ,int* y
248 ,int* descent
249 ,int* externalLeading
250 ,const wxFont* theFont
251 ) const
252 {
253 // TODO:
254 }
255
256 void wxWindow::SetScrollbar( int orient
257 ,int pos
258 ,int thumbVisible
259 ,int range
260 ,bool refresh
261 )
262 {
263 // TODO:
264 }
265
266 void wxWindow::SetScrollPos( int orient
267 ,int pos
268 ,bool refresh
269 )
270 {
271 // TODO:
272 }
273
274 int wxWindow::GetScrollPos(int orient) const
275 {
276 // TODO:
277 return(1);
278 }
279
280 int wxWindow::GetScrollRange(int orient) const
281 {
282 // TODO:
283 return(1);
284 }
285
286 int wxWindow::GetScrollThumb(int orient) const
287 {
288 // TODO:
289 return(1);
290 }
291
292 void wxWindow::ScrollWindow( int dx
293 ,int dy
294 ,const wxRect* rect
295 )
296 {
297 // TODO:
298 }
299
300 #if wxUSE_DRAG_AND_DROP
301 void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
302 {
303 // TODO:
304 }
305 #endif
306
307 void wxWindow::DoClientToScreen( int *x, int *y ) const
308 {
309 // TODO:
310 }
311
312 void wxWindow::DoScreenToClient( int *x, int *y ) const
313 {
314 // TODO:
315 }
316
317 void wxWindow::DoGetPosition( int *x, int *y ) const
318 {
319 // TODO:
320 }
321
322 void wxWindow::DoGetSize( int *width, int *height ) const
323 {
324 // TODO:
325 }
326
327 void wxWindow::DoGetClientSize( int *width, int *height ) const
328 {
329 // TODO:
330 }
331
332 void wxWindow::DoSetSize(int x, int y,
333 int width, int height,
334 int sizeFlags)
335 {
336 // TODO:
337 }
338
339 void wxWindow::DoSetClientSize(int width, int height)
340 {
341 // TODO:
342 }
343
344 bool wxWindow::DoPopupMenu( wxMenu *menu, int x, int y )
345 {
346 // TODO:
347 return(TRUE);
348 }
349
350 void wxWindow::Fit()
351 {
352 // TODO:
353 }
354
355 bool wxWindow::Show(bool show) // check if base implementation is OK
356 {
357 // TODO:
358 return(TRUE);
359 }
360
361 bool wxWindow::Enable(bool enable) // check if base implementation is OK
362 {
363 // TODO:
364 return(TRUE);
365 }
366
367 bool wxWindow::SetCursor(const wxCursor& cursor) // check if base implementation is OK
368 {
369 // TODO:
370 return(TRUE);
371 }
372
373 bool wxWindow::Validate()
374 {
375 // TODO:
376 return(TRUE);
377 }
378
379 wxWindow* wxWindow::FindFocus()
380 {
381 wxWindow* window = NULL;
382 // TODO:
383 return(window);
384 }
385
386 void wxWindow::DragAcceptFiles(bool accept)
387 {
388 // TODO:
389 }
390
391 #if wxUSE_CARET && WXWIN_COMPATIBILITY
392 void wxWindow::CreateCaret(int w, int h)
393 {
394 // TODO:
395 }
396
397 void wxWindow::CreateCaret(const wxBitmap *bitmap)
398 {
399 // TODO:
400 }
401
402 void wxWindow::DestroyCaret()
403 {
404 // TODO:
405 }
406
407 void wxWindow::ShowCaret(bool show)
408 {
409 // TODO:
410 }
411
412 void wxWindow::SetCaretPos(int x, int y)
413 {
414 // TODO:
415 }
416
417 void wxWindow::GetCaretPos(int *x, int *y) const
418 {
419 // TODO:
420 }
421
422 #endif
423
424 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
425 {
426 // TODO:
427 }
428
429 void wxWindow::OnDefaultAction(wxControl *initiatingItem)
430 {
431 // TODO:
432 }
433
434 void wxWindow::OnEraseBackground(wxEraseEvent& event)
435 {
436 // TODO:
437 }
438
439 void wxWindow::OnChar(wxKeyEvent& event)
440 {
441 // TODO:
442 }
443
444 void wxWindow::OnKeyDown(wxKeyEvent& event)
445 {
446 // TODO:
447 }
448
449 void wxWindow::OnKeyUp(wxKeyEvent& event)
450 {
451 // TODO:
452 }
453
454 void wxWindow::OnPaint(wxPaintEvent& event)
455 {
456 // TODO:
457 }
458
459 void wxWindow::OnIdle(wxIdleEvent& event)
460 {
461 // TODO:
462 }
463
464 void wxWindow::OnInitDialog(wxInitDialogEvent& event)
465 {
466 // TODO:
467 }
468
469
470 wxPoint wxWindow::GetClientAreaOrigin() const
471 {
472 // TODO:
473 return wxPoint(0, 0);
474 }
475
476 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
477 {
478 // TODO:
479 }
480
481 long wxWindow::Default()
482 {
483 // TODO:
484 return(1);
485 }
486
487 void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
488 {
489 // TODO:
490 }
491
492 wxObject* wxWindow::GetChild(int number) const
493 {
494 // TODO:
495 return((wxObject*)this);
496 }
497
498 void wxWindow::PMDetachWindowMenu()
499 {
500 if ( m_hMenu )
501 {
502 HMENU hMenu = (HMENU)m_hMenu;
503
504 int N = (int)WinSendMsg(hMenu, MM_QUERYITEMCOUNT, 0, 0);
505 int i;
506 for (i = 0; i < N; i++)
507 {
508 wxChar buf[100];
509 int chars = (int)WinSendMsg(hMenu, MM_QUERYITEMTEXT, MPFROM2SHORT(i, N), buf);
510 if ( !chars )
511 {
512 wxLogLastError(wxT("GetMenuString"));
513
514 continue;
515 }
516
517 if ( wxStrcmp(buf, wxT("&Window")) == 0 )
518 {
519 WinSendMsg(hMenu, MM_DELETEITEM, MPFROM2SHORT(i, TRUE), 0);
520 break;
521 }
522 }
523 }
524 }
525
526 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
527 {
528 // adding NULL hWnd is (first) surely a result of an error and
529 // (secondly) breaks menu command processing
530 wxCHECK_RET( hWnd != (HWND)NULL,
531 wxT("attempt to add a NULL hWnd to window list ignored") );
532
533 if ( !wxWinHandleList->Find((long)hWnd) )
534 wxWinHandleList->Append((long)hWnd, win);
535 }
536
537 wxWindow *wxFindWinFromHandle(WXHWND hWnd)
538 {
539 wxNode *node = wxWinHandleList->Find((long)hWnd);
540 if ( !node )
541 return NULL;
542 return (wxWindow *)node->Data();
543 }
544
545 void wxRemoveHandleAssociation(wxWindow *win)
546 {
547 wxWinHandleList->DeleteObject(win);
548 }
549
550 void wxWindow::SubclassWin(WXHWND hWnd)
551 {
552 wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") );
553
554 HWND hwnd = (HWND)hWnd;
555 /*
556 * TODO: implement something like this:
557 * wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") );
558 *
559 * wxAssociateWinWithHandle(hwnd, this);
560 *
561 * m_oldWndProc = (WXFARPROC) GetWindowLong(hwnd, GWL_WNDPROC);
562 * SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
563 */
564 }
565
566 void wxWindow::UnsubclassWin()
567 {
568 /*
569 * TODO:
570
571 wxRemoveHandleAssociation(this);
572
573 // Restore old Window proc
574 HWND hwnd = GetHwnd();
575 if ( hwnd )
576 {
577 m_hWnd = 0;
578
579 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") );
580
581 FARPROC farProc = (FARPROC) GetWindowLong(hwnd, GWL_WNDPROC);
582 if ( (m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc) )
583 {
584 SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc);
585 m_oldWndProc = 0;
586 }
587 }
588 */
589 }
590
591 WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle,
592 bool *want3D) const
593 {
594 DWORD exStyle; // remove after implementation doe
595 /* TODO: this ought to be fun
596 *
597 // If matches certain criteria, then assume no 3D effects
598 // unless specifically requested (dealt with in MakeExtendedStyle)
599 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) )
600 {
601 *want3D = FALSE;
602 return MakeExtendedStyle(m_windowStyle, FALSE);
603 }
604
605 // Determine whether we should be using 3D effects or not.
606 bool nativeBorder = FALSE; // by default, we don't want a Win95 effect
607
608 // 1) App can specify global 3D effects
609 *want3D = wxTheApp->GetAuto3D();
610
611 // 2) If the parent is being drawn with user colours, or simple border specified,
612 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
613 if ( GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER) )
614 *want3D = FALSE;
615
616 // 3) Control can override this global setting by defining
617 // a border style, e.g. wxSUNKEN_BORDER
618 if ( m_windowStyle & wxSUNKEN_BORDER )
619 *want3D = TRUE;
620
621 // 4) If it's a special border, CTL3D can't cope so we want a native border
622 if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
623 (m_windowStyle & wxSTATIC_BORDER) )
624 {
625 *want3D = TRUE;
626 nativeBorder = TRUE;
627 }
628
629 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
630 // effects from extended style
631 #if wxUSE_CTL3D
632 if ( *want3D )
633 nativeBorder = FALSE;
634 #endif
635
636 DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder);
637
638 // If we want 3D, but haven't specified a border here,
639 // apply the default border style specified.
640 // TODO what about non-Win95 WIN32? Does it have borders?
641 #if defined(__WIN95__) && !wxUSE_CTL3D
642 if ( defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
643 (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) ))
644 exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE;
645 #endif
646 */
647 return exStyle;
648 }
649