1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "window.h"
16 #include "wx/window.h"
20 #include "wx/layout.h"
22 #include "wx/dialog.h"
23 #include "wx/msgdlg.h"
25 #if wxUSE_DRAG_AND_DROP
30 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
36 #include "wx/settings.h"
43 #include "gdk/gdkprivate.h"
44 #include "gdk/gdkkeysyms.h"
45 #include "wx/gtk/win_gtk.h"
49 //-----------------------------------------------------------------------------
50 // documentation on internals
51 //-----------------------------------------------------------------------------
54 I have been asked several times about writing some documentation about
55 the GTK port of wxWindows, especially its internal structures. Obviously,
56 you cannot understand wxGTK without knowing a little about the GTK, but
57 some more information about what the wxWindow, which is the base class
58 for all other window classes, does seems required as well.
62 What does wxWindow do? It contains the common interface for the following
63 jobs of its descendants:
65 1) Define the rudimentary behaviour common to all window classes, such as
66 resizing, intercepting user input (so as to make it possible to use these
67 events for special purposes in a derived class), window names etc.
69 2) Provide the possibility to contain and manage children, if the derived
70 class is allowed to contain children, which holds true for those window
71 classes which do not display a native GTK widget. To name them, these
72 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
73 work classes are a special case and are handled a bit differently from
74 the rest. The same holds true for the wxNotebook class.
76 3) Provide the possibility to draw into a client area of a window. This,
77 too, only holds true for classes that do not display a native GTK widget
80 4) Provide the entire mechanism for scrolling widgets. This actual inter-
81 face for this is usually in wxScrolledWindow, but the GTK implementation
84 5) A multitude of helper or extra methods for special purposes, such as
85 Drag'n'Drop, managing validators etc.
87 6) Display a border (sunken, raised, simple or none).
89 Normally one might expect, that one wxWindows window would always correspond
90 to one GTK widget. Under GTK, there is no such allround widget that has all
91 the functionality. Moreover, the GTK defines a client area as a different
92 widget from the actual widget you are handling. Last but not least some
93 special classes (e.g. wxFrame) handle different categories of widgets and
94 still have the possibility to draw something in the client area.
95 It was therefore required to write a special purpose GTK widget, that would
96 represent a client area in the sense of wxWindows capable to do the jobs
97 2), 3) and 4). I have written this class and it resides in win_gtk.c of
100 All windows must have a widget, with which they interact with other under-
101 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
102 thw wxWindow class has a member variable called m_widget which holds a
103 pointer to this widget. When the window class represents a GTK native widget,
104 this is (in most cases) the only GTK widget the class manages. E.g. the
105 wxStatitText class handles only a GtkLabel widget a pointer to which you
106 can find in m_widget (defined in wxWindow)
108 When the class has a client area for drawing into and for containing children
109 it has to handle the client area widget (of the type GtkMyFixed, defined in
110 win_gtk.c), but there could be any number of widgets, handled by a class
111 The common rule for all windows is only, that the widget that interacts with
112 the rest of GTK must be referenced in m_widget and all other widgets must be
113 children of this widget on the GTK level. The top-most widget, which also
114 represents the client area, must be in the m_wxwindow field and must be of
117 As I said, the window classes that display a GTK native widget only have
118 one widget, so in the case of e.g. the wxButton class m_widget holds a
119 pointer to a GtkButton widget. But windows with client areas (for drawing
120 and children) have a m_widget field that is a pointer to a GtkScrolled-
121 Window and a m_wxwindow field that is pointer to a GtkMyFixed and this
122 one is (in the GTK sense) a child of the GtkScrolledWindow.
124 If the m_wxwindow field is set, then all input to this widget is inter-
125 cepted and sent to the wxWindows class. If not, all input to the widget
126 that gets pointed to by m_widget gets intercepted and sent to the class.
130 The design of scrolling in wxWindows is markedly different from that offered
131 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
132 clicking on a scrollbar belonging to scrolled window will inevitably move
133 the window. In wxWindows, the scrollbar will only emit an event, send this
134 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
135 which actually moves the window and its subchildren. Note that GtkMyFixed
136 memorizes how much it has been scrolled but that wxWindows forgets this
137 so that the two coordinates systems have to be kept in synch. This is done
138 in various places using the myfixed->xoffset and myfixed->yoffset values.
142 Singularily the most broken code in GTK is the code that is supposes to
143 inform subwindows (child windows) about new positions. Very often, duplicate
144 events are sent without changes in size or position, equally often no
145 events are sent at all (All this is due to a bug in the GtkContainer code
146 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
147 GTK's own system and it simply waits for size events for toplevel windows
148 and then iterates down the respective size events to all window. This has
149 the disadvantage, that windows might get size events before the GTK widget
150 actually has the reported size. This doesn't normally pose any problem, but
151 the OpenGl drawing routines rely on correct behaviour. Therefore, I have
152 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
153 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
154 window that is used for OpenGl output really has that size (as reported by
159 If someone at some point of time feels the immense desire to have a look at,
160 change or attempt to optimse the Refresh() logic, this person will need an
161 intimate understanding of what a "draw" and what an "expose" events are and
162 what there are used for, in particular when used in connection with GTK's
163 own windowless widgets. Beware.
167 Cursors, too, have been a constant source of pleasure. The main difficulty
168 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
169 for the parent. To prevent this from doing too much harm, I use idle time
170 to set the cursor over and over again, starting from the toplevel windows
171 and ending with the youngest generation (speaking of parent and child windows).
172 Also don't forget that cursors (like much else) are connected to GdkWindows,
173 not GtkWidgets and that the "window" field of a GtkWidget might very well
174 point to the GdkWindow of the parent widget (-> "window less widget") and
175 that the two obviously have very different meanings.
179 //-----------------------------------------------------------------------------
181 //-----------------------------------------------------------------------------
183 extern wxList wxPendingDelete
;
184 extern bool g_blockEventsOnDrag
;
185 extern bool g_blockEventsOnScroll
;
186 extern wxCursor g_globalCursor
;
187 static wxWindow
*g_captureWindow
= (wxWindow
*) NULL
;
188 wxWindow
*g_focusWindow
= (wxWindow
*) NULL
;
190 /* hack: we need something to pass to gtk_menu_popup, so we store the time of
191 the last click here */
192 static guint32 gs_timeLastClick
= 0;
194 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
200 static gint
gtk_debug_focus_in_callback( GtkWidget
*WXUNUSED(widget
),
201 GdkEvent
*WXUNUSED(event
),
202 const wxChar
*WXUNUSED(name
) )
205 static bool s_done = FALSE;
208 wxLog::AddTraceMask("focus");
211 wxLogTrace(wxT("FOCUS NOW AT: %s"), name);
217 void debug_focus_in( GtkWidget
* widget
, const wxChar
* name
, const wxChar
*window
)
220 tmp
+= wxT(" FROM ");
223 wxChar
*s
= new wxChar
[tmp
.Length()+1];
227 gtk_signal_connect( GTK_OBJECT(widget
), "focus_in_event",
228 GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback
), (gpointer
)s
);
233 //-----------------------------------------------------------------------------
234 // missing gdk functions
235 //-----------------------------------------------------------------------------
238 gdk_window_warp_pointer (GdkWindow
*window
,
242 GdkWindowPrivate
*priv
;
245 window
= (GdkWindow
*) &gdk_root_parent
;
247 priv
= (GdkWindowPrivate
*) window
;
249 if (!priv
->destroyed
)
251 XWarpPointer (priv
->xdisplay
,
252 None
, /* not source window -> move from anywhere */
253 priv
->xwindow
, /* dest window */
254 0, 0, 0, 0, /* not source window -> move from anywhere */
259 //-----------------------------------------------------------------------------
261 //-----------------------------------------------------------------------------
263 extern void wxapp_install_idle_handler();
264 extern bool g_isIdle
;
266 //-----------------------------------------------------------------------------
267 // local code (see below)
268 //-----------------------------------------------------------------------------
270 #if (GTK_MINOR_VERSION > 0)
272 static void draw_frame( GtkWidget
*widget
, wxWindow
*win
)
280 if (win
->HasScrolling())
282 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
283 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(widget
)->klass
);
286 GtkWidget *hscrollbar = scroll_window->hscrollbar;
287 GtkWidget *vscrollbar = scroll_window->vscrollbar;
289 we use this instead: range.slider_width = 11 + 2*2pts edge
292 if (scroll_window
->vscrollbar_visible
)
294 dw
+= 15; /* dw += vscrollbar->allocation.width; */
295 dw
+= scroll_class
->scrollbar_spacing
;
298 if (scroll_window
->hscrollbar_visible
)
300 dh
+= 15; /* dh += hscrollbar->allocation.height; */
301 dh
+= scroll_class
->scrollbar_spacing
;
307 if (GTK_WIDGET_NO_WINDOW (widget
))
309 dx
+= widget
->allocation
.x
;
310 dy
+= widget
->allocation
.y
;
313 if (win
->HasFlag(wxRAISED_BORDER
))
315 gtk_draw_shadow( widget
->style
,
320 win
->m_width
-dw
, win
->m_height
-dh
);
324 if (win
->HasFlag(wxSUNKEN_BORDER
))
326 gtk_draw_shadow( widget
->style
,
331 win
->m_width
-dw
, win
->m_height
-dh
);
335 if (win
->HasFlag(wxSIMPLE_BORDER
))
338 gc
= gdk_gc_new( widget
->window
);
339 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
340 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
342 win
->m_width
-dw
-1, win
->m_height
-dh
-1 );
348 //-----------------------------------------------------------------------------
349 // "expose_event" of m_widget
350 //-----------------------------------------------------------------------------
352 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindow
*win
)
354 if (gdk_event
->count
> 0) return;
355 draw_frame( widget
, win
);
358 //-----------------------------------------------------------------------------
359 // "draw" of m_widget
360 //-----------------------------------------------------------------------------
362 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindow
*win
)
364 draw_frame( widget
, win
);
367 #endif // GTK_MINOR_VERSION > 0
369 //-----------------------------------------------------------------------------
370 // key event conversion routines
371 //-----------------------------------------------------------------------------
373 #if (GTK_MINOR_VERSION == 0)
374 /* these functions are copied verbatim from GTK 1.2 */
376 gdkx_XConvertCase (KeySym symbol
,
380 register KeySym sym
= symbol
;
382 g_return_if_fail (lower
!= NULL
);
383 g_return_if_fail (upper
!= NULL
);
390 #if defined (GDK_A) && defined (GDK_Ooblique)
391 case 0: /* Latin 1 */
392 if ((sym
>= GDK_A
) && (sym
<= GDK_Z
))
393 *lower
+= (GDK_a
- GDK_A
);
394 else if ((sym
>= GDK_a
) && (sym
<= GDK_z
))
395 *upper
-= (GDK_a
- GDK_A
);
396 else if ((sym
>= GDK_Agrave
) && (sym
<= GDK_Odiaeresis
))
397 *lower
+= (GDK_agrave
- GDK_Agrave
);
398 else if ((sym
>= GDK_agrave
) && (sym
<= GDK_odiaeresis
))
399 *upper
-= (GDK_agrave
- GDK_Agrave
);
400 else if ((sym
>= GDK_Ooblique
) && (sym
<= GDK_Thorn
))
401 *lower
+= (GDK_oslash
- GDK_Ooblique
);
402 else if ((sym
>= GDK_oslash
) && (sym
<= GDK_thorn
))
403 *upper
-= (GDK_oslash
- GDK_Ooblique
);
407 #if defined (GDK_Aogonek) && defined (GDK_tcedilla)
408 case 1: /* Latin 2 */
409 /* Assume the KeySym is a legal value (ignore discontinuities) */
410 if (sym
== GDK_Aogonek
)
411 *lower
= GDK_aogonek
;
412 else if (sym
>= GDK_Lstroke
&& sym
<= GDK_Sacute
)
413 *lower
+= (GDK_lstroke
- GDK_Lstroke
);
414 else if (sym
>= GDK_Scaron
&& sym
<= GDK_Zacute
)
415 *lower
+= (GDK_scaron
- GDK_Scaron
);
416 else if (sym
>= GDK_Zcaron
&& sym
<= GDK_Zabovedot
)
417 *lower
+= (GDK_zcaron
- GDK_Zcaron
);
418 else if (sym
== GDK_aogonek
)
419 *upper
= GDK_Aogonek
;
420 else if (sym
>= GDK_lstroke
&& sym
<= GDK_sacute
)
421 *upper
-= (GDK_lstroke
- GDK_Lstroke
);
422 else if (sym
>= GDK_scaron
&& sym
<= GDK_zacute
)
423 *upper
-= (GDK_scaron
- GDK_Scaron
);
424 else if (sym
>= GDK_zcaron
&& sym
<= GDK_zabovedot
)
425 *upper
-= (GDK_zcaron
- GDK_Zcaron
);
426 else if (sym
>= GDK_Racute
&& sym
<= GDK_Tcedilla
)
427 *lower
+= (GDK_racute
- GDK_Racute
);
428 else if (sym
>= GDK_racute
&& sym
<= GDK_tcedilla
)
429 *upper
-= (GDK_racute
- GDK_Racute
);
433 #if defined (GDK_Hstroke) && defined (GDK_Cabovedot)
434 case 2: /* Latin 3 */
435 /* Assume the KeySym is a legal value (ignore discontinuities) */
436 if (sym
>= GDK_Hstroke
&& sym
<= GDK_Hcircumflex
)
437 *lower
+= (GDK_hstroke
- GDK_Hstroke
);
438 else if (sym
>= GDK_Gbreve
&& sym
<= GDK_Jcircumflex
)
439 *lower
+= (GDK_gbreve
- GDK_Gbreve
);
440 else if (sym
>= GDK_hstroke
&& sym
<= GDK_hcircumflex
)
441 *upper
-= (GDK_hstroke
- GDK_Hstroke
);
442 else if (sym
>= GDK_gbreve
&& sym
<= GDK_jcircumflex
)
443 *upper
-= (GDK_gbreve
- GDK_Gbreve
);
444 else if (sym
>= GDK_Cabovedot
&& sym
<= GDK_Scircumflex
)
445 *lower
+= (GDK_cabovedot
- GDK_Cabovedot
);
446 else if (sym
>= GDK_cabovedot
&& sym
<= GDK_scircumflex
)
447 *upper
-= (GDK_cabovedot
- GDK_Cabovedot
);
451 #if defined (GDK_Rcedilla) && defined (GDK_Amacron)
452 case 3: /* Latin 4 */
453 /* Assume the KeySym is a legal value (ignore discontinuities) */
454 if (sym
>= GDK_Rcedilla
&& sym
<= GDK_Tslash
)
455 *lower
+= (GDK_rcedilla
- GDK_Rcedilla
);
456 else if (sym
>= GDK_rcedilla
&& sym
<= GDK_tslash
)
457 *upper
-= (GDK_rcedilla
- GDK_Rcedilla
);
458 else if (sym
== GDK_ENG
)
460 else if (sym
== GDK_eng
)
462 else if (sym
>= GDK_Amacron
&& sym
<= GDK_Umacron
)
463 *lower
+= (GDK_amacron
- GDK_Amacron
);
464 else if (sym
>= GDK_amacron
&& sym
<= GDK_umacron
)
465 *upper
-= (GDK_amacron
- GDK_Amacron
);
469 #if defined (GDK_Serbian_DJE) && defined (GDK_Cyrillic_yu)
470 case 6: /* Cyrillic */
471 /* Assume the KeySym is a legal value (ignore discontinuities) */
472 if (sym
>= GDK_Serbian_DJE
&& sym
<= GDK_Serbian_DZE
)
473 *lower
-= (GDK_Serbian_DJE
- GDK_Serbian_dje
);
474 else if (sym
>= GDK_Serbian_dje
&& sym
<= GDK_Serbian_dze
)
475 *upper
+= (GDK_Serbian_DJE
- GDK_Serbian_dje
);
476 else if (sym
>= GDK_Cyrillic_YU
&& sym
<= GDK_Cyrillic_HARDSIGN
)
477 *lower
-= (GDK_Cyrillic_YU
- GDK_Cyrillic_yu
);
478 else if (sym
>= GDK_Cyrillic_yu
&& sym
<= GDK_Cyrillic_hardsign
)
479 *upper
+= (GDK_Cyrillic_YU
- GDK_Cyrillic_yu
);
481 #endif /* CYRILLIC */
483 #if defined (GDK_Greek_ALPHAaccent) && defined (GDK_Greek_finalsmallsigma)
485 /* Assume the KeySym is a legal value (ignore discontinuities) */
486 if (sym
>= GDK_Greek_ALPHAaccent
&& sym
<= GDK_Greek_OMEGAaccent
)
487 *lower
+= (GDK_Greek_alphaaccent
- GDK_Greek_ALPHAaccent
);
488 else if (sym
>= GDK_Greek_alphaaccent
&& sym
<= GDK_Greek_omegaaccent
&&
489 sym
!= GDK_Greek_iotaaccentdieresis
&&
490 sym
!= GDK_Greek_upsilonaccentdieresis
)
491 *upper
-= (GDK_Greek_alphaaccent
- GDK_Greek_ALPHAaccent
);
492 else if (sym
>= GDK_Greek_ALPHA
&& sym
<= GDK_Greek_OMEGA
)
493 *lower
+= (GDK_Greek_alpha
- GDK_Greek_ALPHA
);
494 else if (sym
>= GDK_Greek_alpha
&& sym
<= GDK_Greek_omega
&&
495 sym
!= GDK_Greek_finalsmallsigma
)
496 *upper
-= (GDK_Greek_alpha
- GDK_Greek_ALPHA
);
503 gdk_keyval_to_upper (guint keyval
)
507 KeySym lower_val
= 0;
508 KeySym upper_val
= 0;
510 gdkx_XConvertCase (keyval
, &lower_val
, &upper_val
);
517 static long map_to_unmodified_wx_keysym( KeySym keysym
)
524 case GDK_Shift_R
: key_code
= WXK_SHIFT
; break;
526 case GDK_Control_R
: key_code
= WXK_CONTROL
; break;
532 case GDK_Super_R
: key_code
= WXK_ALT
; break;
533 case GDK_Menu
: key_code
= WXK_MENU
; break;
534 case GDK_Help
: key_code
= WXK_HELP
; break;
535 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
536 case GDK_ISO_Left_Tab
:
537 case GDK_Tab
: key_code
= WXK_TAB
; break;
538 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
539 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
540 case GDK_Return
: key_code
= WXK_RETURN
; break;
541 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
542 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
543 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
544 case GDK_Delete
: key_code
= WXK_DELETE
; break;
545 case GDK_Home
: key_code
= WXK_HOME
; break;
546 case GDK_Left
: key_code
= WXK_LEFT
; break;
547 case GDK_Up
: key_code
= WXK_UP
; break;
548 case GDK_Right
: key_code
= WXK_RIGHT
; break;
549 case GDK_Down
: key_code
= WXK_DOWN
; break;
550 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
551 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
552 case GDK_Next
: key_code
= WXK_NEXT
; break;
553 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
554 case GDK_End
: key_code
= WXK_END
; break;
555 case GDK_Begin
: key_code
= WXK_HOME
; break;
556 case GDK_Select
: key_code
= WXK_SELECT
; break;
557 case GDK_Print
: key_code
= WXK_PRINT
; break;
558 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
559 case GDK_Insert
: key_code
= WXK_INSERT
; break;
560 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
562 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
563 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
564 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
565 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
566 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
567 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
568 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
569 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
570 case GDK_KP_8
: key_code
= WXK_NUMPAD8
; break;
571 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
572 case GDK_KP_Space
: key_code
= WXK_NUMPAD_SPACE
; break;
573 case GDK_KP_Tab
: key_code
= WXK_NUMPAD_TAB
; break;
574 case GDK_KP_Enter
: key_code
= WXK_NUMPAD_ENTER
; break;
575 case GDK_KP_F1
: key_code
= WXK_NUMPAD_F1
; break;
576 case GDK_KP_F2
: key_code
= WXK_NUMPAD_F2
; break;
577 case GDK_KP_F3
: key_code
= WXK_NUMPAD_F3
; break;
578 case GDK_KP_F4
: key_code
= WXK_NUMPAD_F4
; break;
579 case GDK_KP_Home
: key_code
= WXK_NUMPAD_HOME
; break;
580 case GDK_KP_Left
: key_code
= WXK_NUMPAD_LEFT
; break;
581 case GDK_KP_Up
: key_code
= WXK_NUMPAD_UP
; break;
582 case GDK_KP_Right
: key_code
= WXK_NUMPAD_RIGHT
; break;
583 case GDK_KP_Down
: key_code
= WXK_NUMPAD_DOWN
; break;
584 case GDK_KP_Prior
: key_code
= WXK_NUMPAD_PRIOR
; break;
585 // case GDK_KP_Page_Up: key_code = WXK_NUMPAD_PAGEUP; break;
586 case GDK_KP_Next
: key_code
= WXK_NUMPAD_NEXT
; break;
587 // case GDK_KP_Page_Down: key_code = WXK_NUMPAD_PAGEDOWN; break;
588 case GDK_KP_End
: key_code
= WXK_NUMPAD_END
; break;
589 case GDK_KP_Begin
: key_code
= WXK_NUMPAD_BEGIN
; break;
590 case GDK_KP_Insert
: key_code
= WXK_NUMPAD_INSERT
; break;
591 case GDK_KP_Delete
: key_code
= WXK_NUMPAD_DELETE
; break;
592 case GDK_KP_Equal
: key_code
= WXK_NUMPAD_EQUAL
; break;
593 case GDK_KP_Multiply
: key_code
= WXK_NUMPAD_MULTIPLY
; break;
594 case GDK_KP_Add
: key_code
= WXK_NUMPAD_ADD
; break;
595 case GDK_KP_Separator
: key_code
= WXK_NUMPAD_SEPARATOR
; break;
596 case GDK_KP_Subtract
: key_code
= WXK_NUMPAD_SUBTRACT
; break;
597 case GDK_KP_Decimal
: key_code
= WXK_NUMPAD_DECIMAL
; break;
598 case GDK_KP_Divide
: key_code
= WXK_NUMPAD_DIVIDE
; break;
600 case GDK_F1
: key_code
= WXK_F1
; break;
601 case GDK_F2
: key_code
= WXK_F2
; break;
602 case GDK_F3
: key_code
= WXK_F3
; break;
603 case GDK_F4
: key_code
= WXK_F4
; break;
604 case GDK_F5
: key_code
= WXK_F5
; break;
605 case GDK_F6
: key_code
= WXK_F6
; break;
606 case GDK_F7
: key_code
= WXK_F7
; break;
607 case GDK_F8
: key_code
= WXK_F8
; break;
608 case GDK_F9
: key_code
= WXK_F9
; break;
609 case GDK_F10
: key_code
= WXK_F10
; break;
610 case GDK_F11
: key_code
= WXK_F11
; break;
611 case GDK_F12
: key_code
= WXK_F12
; break;
616 guint upper
= gdk_keyval_to_upper( keysym
);
617 keysym
= (upper
!= 0 ? upper
: keysym
); /* to be MSW compatible */
626 static long map_to_wx_keysym( KeySym keysym
)
632 case GDK_Menu
: key_code
= WXK_MENU
; break;
633 case GDK_Help
: key_code
= WXK_HELP
; break;
634 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
635 case GDK_ISO_Left_Tab
:
636 case GDK_Tab
: key_code
= WXK_TAB
; break;
637 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
638 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
639 case GDK_Return
: key_code
= WXK_RETURN
; break;
640 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
641 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
642 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
643 case GDK_Delete
: key_code
= WXK_DELETE
; break;
644 case GDK_Home
: key_code
= WXK_HOME
; break;
645 case GDK_Left
: key_code
= WXK_LEFT
; break;
646 case GDK_Up
: key_code
= WXK_UP
; break;
647 case GDK_Right
: key_code
= WXK_RIGHT
; break;
648 case GDK_Down
: key_code
= WXK_DOWN
; break;
649 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
650 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
651 case GDK_Next
: key_code
= WXK_NEXT
; break;
652 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
653 case GDK_End
: key_code
= WXK_END
; break;
654 case GDK_Begin
: key_code
= WXK_HOME
; break;
655 case GDK_Select
: key_code
= WXK_SELECT
; break;
656 case GDK_Print
: key_code
= WXK_PRINT
; break;
657 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
658 case GDK_Insert
: key_code
= WXK_INSERT
; break;
659 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
661 case GDK_KP_0
: key_code
= '0'; break;
662 case GDK_KP_1
: key_code
= '1'; break;
663 case GDK_KP_2
: key_code
= '2'; break;
664 case GDK_KP_3
: key_code
= '3'; break;
665 case GDK_KP_4
: key_code
= '4'; break;
666 case GDK_KP_5
: key_code
= '5'; break;
667 case GDK_KP_6
: key_code
= '6'; break;
668 case GDK_KP_7
: key_code
= '7'; break;
669 case GDK_KP_8
: key_code
= '8'; break;
670 case GDK_KP_9
: key_code
= '9'; break;
671 case GDK_KP_Space
: key_code
= ' '; break;
672 case GDK_KP_Tab
: key_code
= WXK_TAB
; break; /* or '\t' ??? */
673 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break; /* or '\r' ??? */
674 case GDK_KP_F1
: key_code
= WXK_NUMPAD_F1
; break;
675 case GDK_KP_F2
: key_code
= WXK_NUMPAD_F2
; break;
676 case GDK_KP_F3
: key_code
= WXK_NUMPAD_F3
; break;
677 case GDK_KP_F4
: key_code
= WXK_NUMPAD_F4
; break;
678 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
679 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
680 case GDK_KP_Up
: key_code
= WXK_UP
; break;
681 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
682 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
683 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
684 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
685 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
686 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
687 case GDK_KP_End
: key_code
= WXK_END
; break;
688 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
689 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
690 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
691 case GDK_KP_Equal
: key_code
= '='; break;
692 case GDK_KP_Multiply
: key_code
= '*'; break;
693 case GDK_KP_Add
: key_code
= '+'; break;
694 case GDK_KP_Separator
: key_code
= ','; break;
695 case GDK_KP_Subtract
: key_code
= '-'; break;
696 case GDK_KP_Decimal
: key_code
= '.'; break;
697 case GDK_KP_Divide
: key_code
= '/'; break;
699 case GDK_F1
: key_code
= WXK_F1
; break;
700 case GDK_F2
: key_code
= WXK_F2
; break;
701 case GDK_F3
: key_code
= WXK_F3
; break;
702 case GDK_F4
: key_code
= WXK_F4
; break;
703 case GDK_F5
: key_code
= WXK_F5
; break;
704 case GDK_F6
: key_code
= WXK_F6
; break;
705 case GDK_F7
: key_code
= WXK_F7
; break;
706 case GDK_F8
: key_code
= WXK_F8
; break;
707 case GDK_F9
: key_code
= WXK_F9
; break;
708 case GDK_F10
: key_code
= WXK_F10
; break;
709 case GDK_F11
: key_code
= WXK_F11
; break;
710 case GDK_F12
: key_code
= WXK_F12
; break;
723 //-----------------------------------------------------------------------------
724 // "expose_event" of m_wxwindow
725 //-----------------------------------------------------------------------------
727 static void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
732 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
734 gdk_event
->area
.width
,
735 gdk_event
->area
.height
);
737 if (gdk_event
->count
> 0)
741 wxPrintf( "OnExpose from " );
742 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
743 wxPrintf( win->GetClassInfo()->GetClassName() );
744 wxPrintf( " %d %d %d %d\n", (int)gdk_event->area.x,
745 (int)gdk_event->area.y,
746 (int)gdk_event->area.width,
747 (int)gdk_event->area.height );
750 wxEraseEvent
eevent( win
->GetId() );
751 eevent
.SetEventObject( win
);
752 win
->GetEventHandler()->ProcessEvent(eevent
);
754 wxPaintEvent
event( win
->GetId() );
755 event
.SetEventObject( win
);
756 win
->GetEventHandler()->ProcessEvent( event
);
758 win
->GetUpdateRegion().Clear();
761 //-----------------------------------------------------------------------------
762 // "draw" of m_wxwindow
763 //-----------------------------------------------------------------------------
765 static void gtk_window_draw_callback( GtkWidget
*widget
, GdkRectangle
*rect
, wxWindow
*win
)
768 wxapp_install_idle_handler();
773 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
,
774 rect
->width
, rect
->height
);
777 wxPrintf( "OnDraw from " );
778 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
779 printf( win->GetClassInfo()->GetClassName() );
780 wxPrintf( " %d %d %d %d\n", (int)rect->x,
786 wxEraseEvent
eevent( win
->GetId() );
787 eevent
.SetEventObject( win
);
788 win
->GetEventHandler()->ProcessEvent(eevent
);
790 wxPaintEvent
event( win
->GetId() );
791 event
.SetEventObject( win
);
792 win
->GetEventHandler()->ProcessEvent( event
);
794 win
->GetUpdateRegion().Clear();
797 //-----------------------------------------------------------------------------
798 // "key_press_event" from any window
799 //-----------------------------------------------------------------------------
801 static gint
gtk_window_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxWindow
*win
)
804 wxapp_install_idle_handler();
806 if (!win
->m_hasVMT
) return FALSE
;
807 if (g_blockEventsOnDrag
) return FALSE
;
810 printf( "KeyDown-ScanCode is: %d.\n", gdk_event->keyval );
811 if (gdk_event->state & GDK_SHIFT_MASK)
812 printf( "ShiftDown.\n" );
814 printf( "ShiftUp.\n" );
815 if (gdk_event->state & GDK_CONTROL_MASK)
816 printf( "ControlDown.\n" );
818 printf( "ControlUp.\n" );
823 GdkModifierType state
;
824 if (gdk_event
->window
) gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
828 long key_code
= map_to_unmodified_wx_keysym( gdk_event
->keyval
);
829 /* sending unknown key events doesn't really make sense */
830 if (key_code
== 0) return FALSE
;
832 wxKeyEvent
event( wxEVT_KEY_DOWN
);
833 event
.SetTimestamp( gdk_event
->time
);
834 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
835 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
836 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
837 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
838 event
.m_keyCode
= key_code
;
839 event
.m_scanCode
= gdk_event
->keyval
;
842 event
.SetEventObject( win
);
843 ret
= win
->GetEventHandler()->ProcessEvent( event
);
848 wxWindow
*ancestor
= win
;
851 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
854 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
855 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
858 ancestor
= ancestor
->GetParent();
861 #endif // wxUSE_ACCEL
863 /* wxMSW doesn't send char events with Alt pressed */
864 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
865 will only be sent if it is not in an accelerator table. */
866 key_code
= map_to_wx_keysym( gdk_event
->keyval
);
871 wxKeyEvent
event2( wxEVT_CHAR
);
872 event2
.SetTimestamp( gdk_event
->time
);
873 event2
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
874 event2
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
875 event2
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
876 event2
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
877 event2
.m_keyCode
= key_code
;
878 event2
.m_scanCode
= gdk_event
->keyval
;
881 event2
.SetEventObject( win
);
882 ret
= win
->GetEventHandler()->ProcessEvent( event2
);
885 /* win is a control: tab can be propagated up */
887 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
888 (win
->HasFlag(wxTE_PROCESS_TAB
) == 0))
890 wxNavigationKeyEvent new_event
;
891 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
892 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
893 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
894 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
895 new_event
.SetCurrentFocus( win
);
896 ret
= win
->GetEventHandler()->ProcessEvent( new_event
);
899 /* generate wxID_CANCEL if <esc> has been pressed (typically in dialogs) */
901 (gdk_event
->keyval
== GDK_Escape
) )
903 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
904 new_event
.SetEventObject( win
);
905 ret
= win
->GetEventHandler()->ProcessEvent( new_event
);
908 #if (GTK_MINOR_VERSION > 0)
909 /* pressing F10 will activate the menu bar of the top frame */
912 (gdk_event->keyval == GDK_F10) )
914 wxWindow *ancestor = win;
917 if (wxIsKindOf(ancestor,wxFrame))
919 wxFrame *frame = (wxFrame*) ancestor;
920 wxMenuBar *menubar = frame->GetMenuBar();
923 wxNode *node = menubar->GetMenus().First();
926 wxMenu *firstMenu = (wxMenu*) node->Data();
927 gtk_menu_item_select( GTK_MENU_ITEM(firstMenu->m_owner) );
933 ancestor = ancestor->GetParent();
940 Damn, I forgot why this didn't work, but it didn't work.
942 // win is a panel: up can be propagated to the panel
943 if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) &&
944 (gdk_event->keyval == GDK_Up))
946 win->m_parent->SetFocus();
950 // win is a panel: left/right can be propagated to the panel
951 if ((!ret) && (win->m_wxwindow) &&
952 ((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) ||
953 (gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down)))
955 wxNavigationKeyEvent new_event;
956 new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) );
957 new_event.SetCurrentFocus( win );
958 ret = win->GetEventHandler()->ProcessEvent( new_event );
964 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
971 //-----------------------------------------------------------------------------
972 // "key_release_event" from any window
973 //-----------------------------------------------------------------------------
975 static gint
gtk_window_key_release_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxWindow
*win
)
978 wxapp_install_idle_handler();
980 if (!win
->m_hasVMT
) return FALSE
;
981 if (g_blockEventsOnDrag
) return FALSE
;
984 printf( "KeyUp-ScanCode is: %d.\n", gdk_event->keyval );
985 if (gdk_event->state & GDK_SHIFT_MASK)
986 printf( "ShiftDown.\n" );
988 printf( "ShiftUp.\n" );
989 if (gdk_event->state & GDK_CONTROL_MASK)
990 printf( "ControlDown.\n" );
992 printf( "ControlUp.\n" );
996 long key_code
= map_to_unmodified_wx_keysym( gdk_event
->keyval
);
998 /* sending unknown key events doesn't really make sense */
999 if (key_code
== 0) return FALSE
;
1003 GdkModifierType state
;
1004 if (gdk_event
->window
) gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1006 wxKeyEvent
event( wxEVT_KEY_UP
);
1007 event
.SetTimestamp( gdk_event
->time
);
1008 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1009 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1010 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1011 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1012 event
.m_keyCode
= key_code
;
1013 event
.m_scanCode
= gdk_event
->keyval
;
1016 event
.SetEventObject( win
);
1018 if (win
->GetEventHandler()->ProcessEvent( event
))
1020 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1027 //-----------------------------------------------------------------------------
1028 // "button_press_event"
1029 //-----------------------------------------------------------------------------
1031 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
1034 wxapp_install_idle_handler();
1037 wxPrintf( wxT("1) OnButtonPress from ") );
1038 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1039 wxPrintf( win->GetClassInfo()->GetClassName() );
1040 wxPrintf( wxT(".\n") );
1042 if (!win
->m_hasVMT
) return FALSE
;
1043 if (g_blockEventsOnDrag
) return TRUE
;
1044 if (g_blockEventsOnScroll
) return TRUE
;
1046 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1048 if (win
->m_wxwindow
)
1050 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
1052 gtk_widget_grab_focus (win
->m_wxwindow
);
1055 wxPrintf( wxT("GrabFocus from ") );
1056 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1057 wxPrintf( win->GetClassInfo()->GetClassName() );
1058 wxPrintf( wxT(".\n") );
1065 wxPrintf( wxT("2) OnButtonPress from ") );
1066 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1067 wxPrintf( win->GetClassInfo()->GetClassName() );
1068 wxPrintf( wxT(".\n") );
1071 wxEventType event_type
= wxEVT_LEFT_DOWN
;
1073 if (gdk_event
->button
== 1)
1075 switch (gdk_event
->type
)
1077 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
1078 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
1082 else if (gdk_event
->button
== 2)
1084 switch (gdk_event
->type
)
1086 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
1087 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
1091 else if (gdk_event
->button
== 3)
1093 switch (gdk_event
->type
)
1095 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
1096 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
1101 wxMouseEvent
event( event_type
);
1102 event
.SetTimestamp( gdk_event
->time
);
1103 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1104 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1105 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1106 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1107 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1108 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1109 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1111 event
.m_x
= (long)gdk_event
->x
;
1112 event
.m_y
= (long)gdk_event
->y
;
1114 // Some control don't have their own X window and thus cannot get
1117 if (!g_captureWindow
)
1119 wxNode
*node
= win
->GetChildren().First();
1122 wxWindow
*child
= (wxWindow
*)node
->Data();
1124 if (child
->m_isStaticBox
)
1126 // wxStaticBox is transparent in the box itself
1129 int xx1
= child
->m_x
;
1130 int yy1
= child
->m_y
;
1131 int xx2
= child
->m_x
+ child
->m_width
;
1132 int yy2
= child
->m_x
+ child
->m_height
;
1135 if (((x
>= xx1
) && (x
<= xx1
+10) && (y
>= yy1
) && (y
<= yy2
)) ||
1137 ((x
>= xx2
-10) && (x
<= xx2
) && (y
>= yy1
) && (y
<= yy2
)) ||
1139 ((x
>= xx1
) && (x
<= xx2
) && (y
>= yy1
) && (y
<= yy1
+10)) ||
1141 ((x
>= xx1
) && (x
<= xx2
) && (y
>= yy2
-1) && (y
<= yy2
)))
1144 event
.m_x
-= child
->m_x
;
1145 event
.m_y
-= child
->m_y
;
1152 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1153 (child
->m_x
<= event
.m_x
) &&
1154 (child
->m_y
<= event
.m_y
) &&
1155 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
1156 (child
->m_y
+child
->m_height
>= event
.m_y
))
1159 event
.m_x
-= child
->m_x
;
1160 event
.m_y
-= child
->m_y
;
1164 node
= node
->Next();
1168 event
.SetEventObject( win
);
1170 gs_timeLastClick
= gdk_event
->time
;
1172 if (win
->GetEventHandler()->ProcessEvent( event
))
1174 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1181 //-----------------------------------------------------------------------------
1182 // "button_release_event"
1183 //-----------------------------------------------------------------------------
1185 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
1188 wxapp_install_idle_handler();
1190 if (!win
->m_hasVMT
) return FALSE
;
1191 if (g_blockEventsOnDrag
) return FALSE
;
1192 if (g_blockEventsOnScroll
) return FALSE
;
1194 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1197 printf( "OnButtonRelease from " );
1198 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1199 printf( win->GetClassInfo()->GetClassName() );
1203 wxEventType event_type
= wxEVT_NULL
;
1205 switch (gdk_event
->button
)
1207 case 1: event_type
= wxEVT_LEFT_UP
; break;
1208 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
1209 case 3: event_type
= wxEVT_RIGHT_UP
; break;
1212 wxMouseEvent
event( event_type
);
1213 event
.SetTimestamp( gdk_event
->time
);
1214 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1215 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1216 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1217 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1218 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1219 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1220 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1221 event
.m_x
= (long)gdk_event
->x
;
1222 event
.m_y
= (long)gdk_event
->y
;
1224 // Some control don't have their own X window and thus cannot get
1227 if (!g_captureWindow
)
1229 wxNode
*node
= win
->GetChildren().First();
1232 wxWindow
*child
= (wxWindow
*)node
->Data();
1234 if (child
->m_isStaticBox
)
1236 // wxStaticBox is transparent in the box itself
1239 int xx1
= child
->m_x
;
1240 int yy1
= child
->m_y
;
1241 int xx2
= child
->m_x
+ child
->m_width
;
1242 int yy2
= child
->m_x
+ child
->m_height
;
1245 if (((x
>= xx1
) && (x
<= xx1
+10) && (y
>= yy1
) && (y
<= yy2
)) ||
1247 ((x
>= xx2
-10) && (x
<= xx2
) && (y
>= yy1
) && (y
<= yy2
)) ||
1249 ((x
>= xx1
) && (x
<= xx2
) && (y
>= yy1
) && (y
<= yy1
+10)) ||
1251 ((x
>= xx1
) && (x
<= xx2
) && (y
>= yy2
-1) && (y
<= yy2
)))
1254 event
.m_x
-= child
->m_x
;
1255 event
.m_y
-= child
->m_y
;
1262 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1263 (child
->m_x
<= event
.m_x
) &&
1264 (child
->m_y
<= event
.m_y
) &&
1265 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
1266 (child
->m_y
+child
->m_height
>= event
.m_y
))
1269 event
.m_x
-= child
->m_x
;
1270 event
.m_y
-= child
->m_y
;
1274 node
= node
->Next();
1278 event
.SetEventObject( win
);
1280 if (win
->GetEventHandler()->ProcessEvent( event
))
1282 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1289 //-----------------------------------------------------------------------------
1290 // "motion_notify_event"
1291 //-----------------------------------------------------------------------------
1293 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
1296 wxapp_install_idle_handler();
1298 if (!win
->m_hasVMT
) return FALSE
;
1299 if (g_blockEventsOnDrag
) return FALSE
;
1300 if (g_blockEventsOnScroll
) return FALSE
;
1302 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1304 if (gdk_event
->is_hint
)
1308 GdkModifierType state
;
1309 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1315 printf( "OnMotion from " );
1316 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1317 printf( win->GetClassInfo()->GetClassName() );
1321 wxMouseEvent
event( wxEVT_MOTION
);
1322 event
.SetTimestamp( gdk_event
->time
);
1323 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1324 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1325 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1326 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1327 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1328 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1329 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1331 event
.m_x
= (long)gdk_event
->x
;
1332 event
.m_y
= (long)gdk_event
->y
;
1334 // Some control don't have their own X window and thus cannot get
1337 if (!g_captureWindow
)
1339 wxNode
*node
= win
->GetChildren().First();
1342 wxWindow
*child
= (wxWindow
*)node
->Data();
1344 if (child
->m_isStaticBox
)
1346 // wxStaticBox is transparent in the box itself
1349 int xx1
= child
->m_x
;
1350 int yy1
= child
->m_y
;
1351 int xx2
= child
->m_x
+ child
->m_width
;
1352 int yy2
= child
->m_x
+ child
->m_height
;
1355 if (((x
>= xx1
) && (x
<= xx1
+10) && (y
>= yy1
) && (y
<= yy2
)) ||
1357 ((x
>= xx2
-10) && (x
<= xx2
) && (y
>= yy1
) && (y
<= yy2
)) ||
1359 ((x
>= xx1
) && (x
<= xx2
) && (y
>= yy1
) && (y
<= yy1
+10)) ||
1361 ((x
>= xx1
) && (x
<= xx2
) && (y
>= yy2
-1) && (y
<= yy2
)))
1364 event
.m_x
-= child
->m_x
;
1365 event
.m_y
-= child
->m_y
;
1372 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1373 (child
->m_x
<= event
.m_x
) &&
1374 (child
->m_y
<= event
.m_y
) &&
1375 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
1376 (child
->m_y
+child
->m_height
>= event
.m_y
))
1379 event
.m_x
-= child
->m_x
;
1380 event
.m_y
-= child
->m_y
;
1384 node
= node
->Next();
1388 event
.SetEventObject( win
);
1390 if (win
->GetEventHandler()->ProcessEvent( event
))
1392 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1399 //-----------------------------------------------------------------------------
1401 //-----------------------------------------------------------------------------
1403 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
, GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
1406 wxapp_install_idle_handler();
1408 if (!win
->m_hasVMT
) return FALSE
;
1409 if (g_blockEventsOnDrag
) return FALSE
;
1411 g_focusWindow
= win
;
1413 if (win
->m_wxwindow
)
1415 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
1417 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
1419 printf( "SetFocus flag from " );
1420 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1421 printf( win->GetClassInfo()->GetClassName() );
1429 printf( "OnSetFocus from " );
1430 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1431 printf( win->GetClassInfo()->GetClassName() );
1433 printf( WXSTRINGCAST win->GetLabel() );
1437 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
1438 event
.SetEventObject( win
);
1440 if (win
->GetEventHandler()->ProcessEvent( event
))
1442 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
1449 //-----------------------------------------------------------------------------
1450 // "focus_out_event"
1451 //-----------------------------------------------------------------------------
1453 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
1456 wxapp_install_idle_handler();
1458 if (!win
->m_hasVMT
) return FALSE
;
1459 if (g_blockEventsOnDrag
) return FALSE
;
1461 if (win
->m_wxwindow
)
1463 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
1464 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
1468 printf( "OnKillFocus from " );
1469 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1470 printf( win->GetClassInfo()->GetClassName() );
1474 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1475 event
.SetEventObject( win
);
1477 if (win
->GetEventHandler()->ProcessEvent( event
))
1479 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_out_event" );
1486 //-----------------------------------------------------------------------------
1487 // "enter_notify_event"
1488 //-----------------------------------------------------------------------------
1490 static gint
gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
1493 wxapp_install_idle_handler();
1495 if (!win
->m_hasVMT
) return FALSE
;
1496 if (g_blockEventsOnDrag
) return FALSE
;
1498 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1500 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1501 #if (GTK_MINOR_VERSION > 0)
1502 event
.SetTimestamp( gdk_event
->time
);
1504 event
.SetEventObject( win
);
1508 GdkModifierType state
= (GdkModifierType
)0;
1510 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1512 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
);
1513 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
);
1514 event
.m_altDown
= (state
& GDK_MOD1_MASK
);
1515 event
.m_metaDown
= (state
& GDK_MOD2_MASK
);
1516 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
);
1517 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
);
1518 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
);
1520 event
.m_x
= (long)x
;
1521 event
.m_y
= (long)y
;
1523 if (win
->GetEventHandler()->ProcessEvent( event
))
1525 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
1532 //-----------------------------------------------------------------------------
1533 // "leave_notify_event"
1534 //-----------------------------------------------------------------------------
1536 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
1539 wxapp_install_idle_handler();
1541 if (!win
->m_hasVMT
) return FALSE
;
1542 if (g_blockEventsOnDrag
) return FALSE
;
1544 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1546 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1547 #if (GTK_MINOR_VERSION > 0)
1548 event
.SetTimestamp( gdk_event
->time
);
1550 event
.SetEventObject( win
);
1554 GdkModifierType state
= (GdkModifierType
)0;
1556 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1558 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
);
1559 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
);
1560 event
.m_altDown
= (state
& GDK_MOD1_MASK
);
1561 event
.m_metaDown
= (state
& GDK_MOD2_MASK
);
1562 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
);
1563 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
);
1564 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
);
1566 event
.m_x
= (long)x
;
1567 event
.m_y
= (long)y
;
1569 if (win
->GetEventHandler()->ProcessEvent( event
))
1571 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
1578 //-----------------------------------------------------------------------------
1579 // "value_changed" from m_vAdjust
1580 //-----------------------------------------------------------------------------
1582 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
, wxWindow
*win
)
1585 wxapp_install_idle_handler();
1587 if (g_blockEventsOnDrag
) return;
1589 if (!win
->m_hasVMT
) return;
1591 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
1592 if (fabs(diff
) < 0.2) return;
1594 win
->m_oldVerticalPos
= adjust
->value
;
1596 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
1597 GtkRange
*range
= GTK_RANGE( scrolledWindow
->vscrollbar
);
1599 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
1600 if (range
->scroll_type
== GTK_SCROLL_STEP_BACKWARD
) command
= wxEVT_SCROLLWIN_LINEUP
;
1601 else if (range
->scroll_type
== GTK_SCROLL_STEP_FORWARD
) command
= wxEVT_SCROLLWIN_LINEDOWN
;
1602 else if (range
->scroll_type
== GTK_SCROLL_PAGE_BACKWARD
) command
= wxEVT_SCROLLWIN_PAGEUP
;
1603 else if (range
->scroll_type
== GTK_SCROLL_PAGE_FORWARD
) command
= wxEVT_SCROLLWIN_PAGEDOWN
;
1605 int value
= (int)(adjust
->value
+0.5);
1607 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
1608 event
.SetEventObject( win
);
1609 win
->GetEventHandler()->ProcessEvent( event
);
1612 //-----------------------------------------------------------------------------
1613 // "value_changed" from m_hAdjust
1614 //-----------------------------------------------------------------------------
1616 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
, wxWindow
*win
)
1619 wxapp_install_idle_handler();
1621 if (g_blockEventsOnDrag
) return;
1622 if (!win
->m_hasVMT
) return;
1624 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
1625 if (fabs(diff
) < 0.2) return;
1627 win
->m_oldHorizontalPos
= adjust
->value
;
1629 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
1630 GtkRange
*range
= GTK_RANGE( scrolledWindow
->hscrollbar
);
1632 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
1633 if (range
->scroll_type
== GTK_SCROLL_STEP_BACKWARD
) command
= wxEVT_SCROLLWIN_LINEUP
;
1634 else if (range
->scroll_type
== GTK_SCROLL_STEP_FORWARD
) command
= wxEVT_SCROLLWIN_LINEDOWN
;
1635 else if (range
->scroll_type
== GTK_SCROLL_PAGE_BACKWARD
) command
= wxEVT_SCROLLWIN_PAGEUP
;
1636 else if (range
->scroll_type
== GTK_SCROLL_PAGE_FORWARD
) command
= wxEVT_SCROLLWIN_PAGEDOWN
;
1638 int value
= (int)(adjust
->value
+0.5);
1640 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
1641 event
.SetEventObject( win
);
1642 win
->GetEventHandler()->ProcessEvent( event
);
1645 //-----------------------------------------------------------------------------
1646 // "changed" from m_vAdjust
1647 //-----------------------------------------------------------------------------
1649 static void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
1652 wxapp_install_idle_handler();
1654 if (g_blockEventsOnDrag
) return;
1655 if (!win
->m_hasVMT
) return;
1657 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
1658 int value
= (int)(win
->m_vAdjust
->value
+0.5);
1660 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
1661 event
.SetEventObject( win
);
1662 win
->GetEventHandler()->ProcessEvent( event
);
1665 //-----------------------------------------------------------------------------
1666 // "changed" from m_hAdjust
1667 //-----------------------------------------------------------------------------
1669 static void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
1672 wxapp_install_idle_handler();
1674 if (g_blockEventsOnDrag
) return;
1675 if (!win
->m_hasVMT
) return;
1677 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
1678 int value
= (int)(win
->m_hAdjust
->value
+0.5);
1680 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
1681 event
.SetEventObject( win
);
1682 win
->GetEventHandler()->ProcessEvent( event
);
1685 //-----------------------------------------------------------------------------
1686 // "button_press_event" from scrollbar
1687 //-----------------------------------------------------------------------------
1689 static gint
gtk_scrollbar_button_press_callback( GtkRange
*WXUNUSED(widget
),
1690 GdkEventButton
*WXUNUSED(gdk_event
),
1694 wxapp_install_idle_handler();
1696 // don't test here as we can release the mouse while being over
1697 // a different window than the slider
1699 // if (gdk_event->window != widget->slider) return FALSE;
1701 win
->SetScrolling( TRUE
);
1706 //-----------------------------------------------------------------------------
1707 // "button_release_event" from scrollbar
1708 //-----------------------------------------------------------------------------
1710 static gint
gtk_scrollbar_button_release_callback( GtkRange
*WXUNUSED(widget
),
1711 GdkEventButton
*WXUNUSED(gdk_event
),
1715 // don't test here as we can release the mouse while being over
1716 // a different window than the slider
1718 // if (gdk_event->window != widget->slider) return FALSE;
1720 win
->SetScrolling( FALSE
);
1725 // ----------------------------------------------------------------------------
1726 // this wxWindowBase function is implemented here (in platform-specific file)
1727 // because it is static and so couldn't be made virtual
1728 // ----------------------------------------------------------------------------
1730 wxWindow
*wxWindowBase::FindFocus()
1732 return g_focusWindow
;
1735 //-----------------------------------------------------------------------------
1736 // "realize" from m_widget
1737 //-----------------------------------------------------------------------------
1739 /* we cannot set colours and fonts before the widget has
1740 been realized, so we do this directly after realization */
1743 gtk_window_realized_callback( GtkWidget
* WXUNUSED(widget
), wxWindow
*win
)
1746 wxapp_install_idle_handler();
1748 if (win
->m_delayedFont
)
1749 win
->SetFont( win
->GetFont() );
1751 if (win
->m_delayedBackgroundColour
)
1752 win
->SetBackgroundColour( win
->GetBackgroundColour() );
1754 if (win
->m_delayedForegroundColour
)
1755 win
->SetForegroundColour( win
->GetForegroundColour() );
1757 wxWindowCreateEvent
event( win
);
1758 event
.SetEventObject( win
);
1759 win
->GetEventHandler()->ProcessEvent( event
);
1764 //-----------------------------------------------------------------------------
1765 // InsertChild for wxWindow.
1766 //-----------------------------------------------------------------------------
1768 /* Callback for wxWindow. This very strange beast has to be used because
1769 * C++ has no virtual methods in a constructor. We have to emulate a
1770 * virtual function here as wxNotebook requires a different way to insert
1771 * a child in it. I had opted for creating a wxNotebookPage window class
1772 * which would have made this superfluous (such in the MDI window system),
1773 * but no-one was listening to me... */
1775 static void wxInsertChildInWindow( wxWindow
* parent
, wxWindow
* child
)
1777 /* the window might have been scrolled already, do we
1778 have to adapt the position */
1779 GtkMyFixed
*myfixed
= GTK_MYFIXED(parent
->m_wxwindow
);
1780 child
->m_x
+= myfixed
->xoffset
;
1781 child
->m_y
+= myfixed
->yoffset
;
1783 gtk_myfixed_put( GTK_MYFIXED(parent
->m_wxwindow
),
1784 GTK_WIDGET(child
->m_widget
),
1790 if (parent
->HasFlag(wxTAB_TRAVERSAL
))
1792 /* we now allow a window to get the focus as long as it
1793 doesn't have any children. */
1794 GTK_WIDGET_UNSET_FLAGS( parent
->m_wxwindow
, GTK_CAN_FOCUS
);
1798 //-----------------------------------------------------------------------------
1800 //-----------------------------------------------------------------------------
1802 wxWindow
* wxGetActiveWindow()
1804 return g_focusWindow
;
1807 //-----------------------------------------------------------------------------
1809 //-----------------------------------------------------------------------------
1811 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
1813 void wxWindow::Init()
1819 m_widget
= (GtkWidget
*) NULL
;
1820 m_wxwindow
= (GtkWidget
*) NULL
;
1830 m_needParent
= TRUE
;
1831 m_isBeingDeleted
= FALSE
;
1834 m_nativeSizeEvent
= FALSE
;
1836 m_hasScrolling
= FALSE
;
1837 m_isScrolling
= FALSE
;
1839 m_hAdjust
= (GtkAdjustment
*) NULL
;
1840 m_vAdjust
= (GtkAdjustment
*) NULL
;
1841 m_oldHorizontalPos
= 0.0;
1842 m_oldVerticalPos
= 0.0;
1845 m_widgetStyle
= (GtkStyle
*) NULL
;
1847 m_insertCallback
= (wxInsertChildFunction
) NULL
;
1849 m_isStaticBox
= FALSE
;
1850 m_isRadioButton
= FALSE
;
1852 m_acceptsFocus
= FALSE
;
1854 m_cursor
= *wxSTANDARD_CURSOR
;
1857 wxWindow::wxWindow()
1862 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
1863 const wxPoint
&pos
, const wxSize
&size
,
1864 long style
, const wxString
&name
)
1868 Create( parent
, id
, pos
, size
, style
, name
);
1871 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
1872 const wxPoint
&pos
, const wxSize
&size
,
1873 long style
, const wxString
&name
)
1875 if (!PreCreation( parent
, pos
, size
) ||
1876 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
1878 wxFAIL_MSG( wxT("wxWindow creation failed") );
1882 m_insertCallback
= wxInsertChildInWindow
;
1884 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
1885 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
1888 debug_focus_in( m_widget
, wxT("wxWindow::m_widget"), name
);
1891 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
1894 debug_focus_in( scrolledWindow
->hscrollbar
, wxT("wxWindow::hsrcollbar"), name
);
1895 debug_focus_in( scrolledWindow
->vscrollbar
, wxT("wxWindow::vsrcollbar"), name
);
1898 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1899 scroll_class
->scrollbar_spacing
= 0;
1901 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
1903 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
1904 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
1906 m_wxwindow
= gtk_myfixed_new();
1909 debug_focus_in( m_wxwindow
, wxT("wxWindow::m_wxwindow"), name
);
1912 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
1914 #if (GTK_MINOR_VERSION > 0)
1915 GtkMyFixed
*myfixed
= GTK_MYFIXED(m_wxwindow
);
1917 if (HasFlag(wxRAISED_BORDER
))
1919 gtk_myfixed_set_shadow_type( myfixed
, GTK_MYSHADOW_OUT
);
1921 else if (HasFlag(wxSUNKEN_BORDER
))
1923 gtk_myfixed_set_shadow_type( myfixed
, GTK_MYSHADOW_IN
);
1925 else if (HasFlag(wxSIMPLE_BORDER
))
1927 gtk_myfixed_set_shadow_type( myfixed
, GTK_MYSHADOW_THIN
);
1931 gtk_myfixed_set_shadow_type( myfixed
, GTK_MYSHADOW_NONE
);
1933 #else // GTK_MINOR_VERSION == 0
1934 GtkViewport
*viewport
= GTK_VIEWPORT(scrolledWindow
->viewport
);
1936 if (HasFlag(wxRAISED_BORDER
))
1938 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
1940 else if (HasFlag(wxSUNKEN_BORDER
))
1942 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
1946 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
1948 #endif // GTK_MINOR_VERSION
1950 if (HasFlag(wxTAB_TRAVERSAL
))
1952 /* we now allow a window to get the focus as long as it
1953 doesn't have any children. */
1954 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
1955 m_acceptsFocus
= FALSE
;
1959 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
1960 m_acceptsFocus
= TRUE
;
1963 #if (GTK_MINOR_VERSION == 0)
1964 // shut the viewport up
1965 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1966 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1967 #endif // GTK_MINOR_VERSION == 0
1969 // I _really_ don't want scrollbars in the beginning
1970 m_vAdjust
->lower
= 0.0;
1971 m_vAdjust
->upper
= 1.0;
1972 m_vAdjust
->value
= 0.0;
1973 m_vAdjust
->step_increment
= 1.0;
1974 m_vAdjust
->page_increment
= 1.0;
1975 m_vAdjust
->page_size
= 5.0;
1976 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1977 m_hAdjust
->lower
= 0.0;
1978 m_hAdjust
->upper
= 1.0;
1979 m_hAdjust
->value
= 0.0;
1980 m_hAdjust
->step_increment
= 1.0;
1981 m_hAdjust
->page_increment
= 1.0;
1982 m_hAdjust
->page_size
= 5.0;
1983 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1985 // these handlers block mouse events to any window during scrolling such as
1986 // motion events and prevent GTK and wxWindows from fighting over where the
1989 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
1990 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
1992 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
1993 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
1995 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
1996 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
1998 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
1999 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2001 // these handlers get notified when screen updates are required either when
2002 // scrolling or when the window size (and therefore scrollbar configuration)
2005 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2006 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2007 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2008 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2010 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "changed",
2011 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
2012 gtk_signal_connect(GTK_OBJECT(m_vAdjust
), "changed",
2013 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
2015 gtk_widget_show( m_wxwindow
);
2018 m_parent
->DoAddChild( this );
2027 wxWindow::~wxWindow()
2029 m_isBeingDeleted
= TRUE
;
2038 m_parent
->RemoveChild( this );
2042 gtk_style_unref( m_widgetStyle
);
2043 m_widgetStyle
= (GtkStyle
*) NULL
;
2048 gtk_widget_destroy( m_wxwindow
);
2049 m_wxwindow
= (GtkWidget
*) NULL
;
2054 gtk_widget_destroy( m_widget
);
2055 m_widget
= (GtkWidget
*) NULL
;
2059 bool wxWindow::PreCreation( wxWindow
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2061 wxCHECK_MSG( !m_needParent
|| parent
, FALSE
, wxT("Need complete parent.") );
2063 /* this turns -1 into 20 so that a minimal window is
2064 visible even although -1,-1 has been given as the
2065 size of the window. the same trick is used in other
2066 ports and should make debugging easier */
2067 m_width
= WidthDefault(size
.x
);
2068 m_height
= HeightDefault(size
.y
);
2073 /* some reasonable defaults */
2078 m_x
= (gdk_screen_width () - m_width
) / 2;
2079 if (m_x
< 10) m_x
= 10;
2083 m_y
= (gdk_screen_height () - m_height
) / 2;
2084 if (m_y
< 10) m_y
= 10;
2091 void wxWindow::PostCreation()
2093 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2099 /* these get reported to wxWindows -> wxPaintEvent */
2100 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2101 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2103 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2104 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2107 #if (GTK_MINOR_VERSION > 0)
2108 /* these are called when the "sunken" or "raised" borders are drawn */
2109 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2110 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2112 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2113 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2117 GtkWidget
*connect_widget
= GetConnectWidget();
2119 ConnectWidget( connect_widget
);
2121 /* we cannot set colours, fonts and cursors before the widget has
2122 been realized, so we do this directly after realization */
2123 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
2124 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
2129 void wxWindow::ConnectWidget( GtkWidget
*widget
)
2131 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
2132 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
2134 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
2135 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
2137 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
2138 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
2140 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
2141 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
2143 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
2144 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
2146 gtk_signal_connect( GTK_OBJECT(widget
), "focus_in_event",
2147 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2149 gtk_signal_connect( GTK_OBJECT(widget
), "focus_out_event",
2150 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
2152 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
2153 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
2155 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
2156 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
2159 bool wxWindow::Destroy()
2161 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2165 return wxWindowBase::Destroy();
2168 void wxWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2170 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2171 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindow::SetSize requires parent.\n") );
2173 if (m_resizing
) return; /* I don't like recursions */
2176 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
2178 /* don't set the size for children of wxNotebook, just take the values. */
2186 GtkMyFixed
*myfixed
= GTK_MYFIXED(m_parent
->m_wxwindow
);
2188 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2190 if (x
!= -1) m_x
= x
+ myfixed
->xoffset
;
2191 if (y
!= -1) m_y
= y
+ myfixed
->yoffset
;
2192 if (width
!= -1) m_width
= width
;
2193 if (height
!= -1) m_height
= height
;
2197 m_x
= x
+ myfixed
->xoffset
;
2198 m_y
= y
+ myfixed
->yoffset
;
2203 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
2205 if (width
== -1) m_width
= 80;
2208 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
2210 if (height
== -1) m_height
= 26;
2213 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
2214 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
2215 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_maxWidth
;
2216 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_maxHeight
;
2219 int bottom_border
= 0;
2221 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2223 /* the default button has a border around it */
2228 gtk_myfixed_set_size( GTK_MYFIXED(m_parent
->m_wxwindow
),
2233 m_height
+border
+bottom_border
);
2237 wxPrintf( "OnSize sent from " );
2238 if (GetClassInfo() && GetClassInfo()->GetClassName())
2239 wxPrintf( GetClassInfo()->GetClassName() );
2240 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2243 if (!m_nativeSizeEvent
)
2245 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2246 event
.SetEventObject( this );
2247 GetEventHandler()->ProcessEvent( event
);
2253 void wxWindow::OnInternalIdle()
2255 wxCursor cursor
= m_cursor
;
2256 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2260 /* I now set the cursor anew in every OnInternalIdle call
2261 as setting the cursor in a parent window also effects the
2262 windows above so that checking for the current cursor is
2267 GdkWindow
*window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
2269 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2271 if (!g_globalCursor
.Ok())
2272 cursor
= *wxSTANDARD_CURSOR
;
2274 window
= m_widget
->window
;
2275 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2276 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2282 GdkWindow
*window
= m_widget
->window
;
2283 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2284 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2292 void wxWindow::DoGetSize( int *width
, int *height
) const
2294 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2296 if (width
) (*width
) = m_width
;
2297 if (height
) (*height
) = m_height
;
2300 void wxWindow::DoSetClientSize( int width
, int height
)
2302 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2306 SetSize( width
, height
);
2313 #if (GTK_MINOR_VERSION == 0)
2314 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2318 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2319 #if 0 // unused - if this is ok, just remove this line (VZ)
2320 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
2323 GtkWidget
*viewport
= scroll_window
->viewport
;
2324 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
2326 dw
+= 2 * viewport_class
->xthickness
;
2327 dh
+= 2 * viewport_class
->ythickness
;
2331 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2333 /* when using GTK 1.2 we set the shadow border size to 2 */
2337 if (HasFlag(wxSIMPLE_BORDER
))
2339 /* when using GTK 1.2 we set the simple border size to 1 */
2348 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2349 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2351 we use this instead: range.slider_width = 11 + 2*2pts edge
2354 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2355 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
2357 if (scroll_window
->vscrollbar_visible
)
2359 dw
+= 15; /* dw += vscrollbar->allocation.width; */
2360 dw
+= scroll_class
->scrollbar_spacing
;
2363 if (scroll_window
->hscrollbar_visible
)
2365 dh
+= 15; /* dh += hscrollbar->allocation.height; */
2366 dh
+= scroll_class
->scrollbar_spacing
;
2370 SetSize( width
+dw
, height
+dh
);
2374 void wxWindow::DoGetClientSize( int *width
, int *height
) const
2376 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2380 if (width
) (*width
) = m_width
;
2381 if (height
) (*height
) = m_height
;
2388 #if (GTK_MINOR_VERSION == 0)
2389 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2393 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2394 #if 0 // unused - if this is ok, just remove this line (VZ)
2395 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
2398 GtkWidget
*viewport
= scroll_window
->viewport
;
2399 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
2401 dw
+= 2 * viewport_class
->xthickness
;
2402 dh
+= 2 * viewport_class
->ythickness
;
2406 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2408 /* when using GTK 1.2 we set the shadow border size to 2 */
2412 if (HasFlag(wxSIMPLE_BORDER
))
2414 /* when using GTK 1.2 we set the simple border size to 1 */
2422 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2423 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2425 we use this instead: range.slider_width = 11 + 2*2pts edge
2428 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2429 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
2431 if (scroll_window
->vscrollbar_visible
)
2433 dw
+= 15; /* dw += vscrollbar->allocation.width; */
2434 dw
+= scroll_class
->scrollbar_spacing
;
2437 if (scroll_window
->hscrollbar_visible
)
2439 dh
+= 15; /* dh += hscrollbar->allocation.height; */
2440 dh
+= scroll_class
->scrollbar_spacing
;
2444 if (width
) (*width
) = m_width
- dw
;
2445 if (height
) (*height
) = m_height
- dh
;
2449 void wxWindow::DoGetPosition( int *x
, int *y
) const
2451 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2455 if (m_parent
&& m_parent
->m_wxwindow
)
2457 GtkMyFixed
*myfixed
= GTK_MYFIXED(m_parent
->m_wxwindow
);
2458 dx
= myfixed
->xoffset
;
2459 dy
= myfixed
->yoffset
;
2462 if (x
) (*x
) = m_x
- dx
;
2463 if (y
) (*y
) = m_y
- dy
;
2466 void wxWindow::DoClientToScreen( int *x
, int *y
) const
2468 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2470 if (!m_widget
->window
) return;
2472 GdkWindow
*source
= (GdkWindow
*) NULL
;
2474 source
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
2476 source
= m_widget
->window
;
2480 gdk_window_get_origin( source
, &org_x
, &org_y
);
2484 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2486 org_x
+= m_widget
->allocation
.x
;
2487 org_y
+= m_widget
->allocation
.y
;
2495 void wxWindow::DoScreenToClient( int *x
, int *y
) const
2497 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2499 if (!m_widget
->window
) return;
2501 GdkWindow
*source
= (GdkWindow
*) NULL
;
2503 source
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
2505 source
= m_widget
->window
;
2509 gdk_window_get_origin( source
, &org_x
, &org_y
);
2513 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2515 org_x
+= m_widget
->allocation
.x
;
2516 org_y
+= m_widget
->allocation
.y
;
2524 bool wxWindow::Show( bool show
)
2526 wxCHECK_MSG( (m_widget
!= NULL
), FALSE
, wxT("invalid window") );
2528 if (!wxWindowBase::Show(show
))
2535 gtk_widget_show( m_widget
);
2537 gtk_widget_hide( m_widget
);
2542 bool wxWindow::Enable( bool enable
)
2544 wxCHECK_MSG( (m_widget
!= NULL
), FALSE
, wxT("invalid window") );
2546 if (!wxWindowBase::Enable(enable
))
2552 gtk_widget_set_sensitive( m_widget
, enable
);
2554 gtk_widget_set_sensitive( m_wxwindow
, enable
);
2559 int wxWindow::GetCharHeight() const
2561 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
2563 wxCHECK_MSG( m_font
.Ok(), 12, wxT("invalid font") );
2565 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
2567 return font
->ascent
+ font
->descent
;
2570 int wxWindow::GetCharWidth() const
2572 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
2574 wxCHECK_MSG( m_font
.Ok(), 8, wxT("invalid font") );
2576 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
2578 return gdk_string_width( font
, "H" );
2581 void wxWindow::GetTextExtent( const wxString
& string
,
2585 int *externalLeading
,
2586 const wxFont
*theFont
) const
2588 wxFont fontToUse
= m_font
;
2589 if (theFont
) fontToUse
= *theFont
;
2591 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
2593 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
2594 if (x
) (*x
) = gdk_string_width( font
, string
.mbc_str() );
2595 if (y
) (*y
) = font
->ascent
+ font
->descent
;
2596 if (descent
) (*descent
) = font
->descent
;
2597 if (externalLeading
) (*externalLeading
) = 0; // ??
2600 void wxWindow::SetFocus()
2602 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2604 GtkWidget
*connect_widget
= GetConnectWidget();
2607 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
2609 gtk_widget_grab_focus (connect_widget
);
2611 else if (GTK_IS_CONTAINER(connect_widget
))
2613 gtk_container_focus( GTK_CONTAINER(connect_widget
), GTK_DIR_TAB_FORWARD
);
2621 bool wxWindow::AcceptsFocus() const
2623 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
2626 bool wxWindow::Reparent( wxWindowBase
*newParentBase
)
2628 wxCHECK_MSG( (m_widget
!= NULL
), FALSE
, wxT("invalid window") );
2630 wxWindow
*oldParent
= m_parent
,
2631 *newParent
= (wxWindow
*)newParentBase
;
2633 wxASSERT( GTK_IS_WIDGET(m_widget
) );
2635 if ( !wxWindowBase::Reparent(newParent
) )
2638 wxASSERT( GTK_IS_WIDGET(m_widget
) );
2640 /* prevent GTK from deleting the widget arbitrarily */
2641 gtk_widget_ref( m_widget
);
2645 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
2648 wxASSERT( GTK_IS_WIDGET(m_widget
) );
2652 /* insert GTK representation */
2653 (*(newParent
->m_insertCallback
))(newParent
, this);
2656 /* reverse: prevent GTK from deleting the widget arbitrarily */
2657 gtk_widget_unref( m_widget
);
2662 void wxWindow::DoAddChild(wxWindow
*child
)
2664 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2666 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
2668 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
2673 /* insert GTK representation */
2674 (*m_insertCallback
)(this, child
);
2677 void wxWindow::Raise()
2679 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2681 if (!m_widget
->window
) return;
2683 gdk_window_raise( m_widget
->window
);
2686 void wxWindow::Lower()
2688 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2690 if (!m_widget
->window
) return;
2692 gdk_window_lower( m_widget
->window
);
2695 bool wxWindow::SetCursor( const wxCursor
&cursor
)
2697 wxCHECK_MSG( (m_widget
!= NULL
), FALSE
, wxT("invalid window") );
2699 return wxWindowBase::SetCursor( cursor
);
2702 void wxWindow::WarpPointer( int x
, int y
)
2704 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2706 /* we provide this function ourselves as it is
2707 missing in GDK (top of this file) */
2709 GdkWindow
*window
= (GdkWindow
*) NULL
;
2711 window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
2713 window
= GetConnectWidget()->window
;
2716 gdk_window_warp_pointer( window
, x
, y
);
2719 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
2721 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2723 if (!m_widget
->window
) return;
2725 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
2729 gdk_window_clear_area( GTK_MYFIXED(m_wxwindow
)->bin_window
,
2731 rect
->width
, rect
->height
);
2735 gdk_window_clear( GTK_MYFIXED(m_wxwindow
)->bin_window
);
2739 /* there is no GTK equivalent of "draw only, don't clear" so we
2740 invent our own in the GtkMyFixed widget */
2746 GtkMyFixed
*myfixed
= GTK_MYFIXED(m_wxwindow
);
2747 gboolean old_clear
= myfixed
->clear_on_draw
;
2748 gtk_my_fixed_set_clear( myfixed
, FALSE
);
2750 gtk_widget_draw( m_wxwindow
, (GdkRectangle
*) NULL
);
2752 gtk_my_fixed_set_clear( myfixed
, old_clear
);
2755 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
2759 GdkRectangle gdk_rect
;
2760 gdk_rect
.x
= rect
->x
;
2761 gdk_rect
.y
= rect
->y
;
2762 gdk_rect
.width
= rect
->width
;
2763 gdk_rect
.height
= rect
->height
;
2767 GtkMyFixed
*myfixed
= GTK_MYFIXED(m_wxwindow
);
2768 gboolean old_clear
= myfixed
->clear_on_draw
;
2769 gtk_my_fixed_set_clear( myfixed
, FALSE
);
2771 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
2773 gtk_my_fixed_set_clear( myfixed
, old_clear
);
2776 gtk_widget_draw( m_widget
, &gdk_rect
);
2780 void wxWindow::Clear()
2782 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
2784 if (!m_widget
->window
) return;
2786 if (m_wxwindow
&& m_wxwindow
->window
)
2788 gdk_window_clear( m_wxwindow
->window
);
2793 void wxWindow::DoSetToolTip( wxToolTip
*tip
)
2795 wxWindowBase::DoSetToolTip(tip
);
2798 m_tooltip
->Apply( this );
2801 void wxWindow::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
2803 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
2805 #endif // wxUSE_TOOLTIPS
2807 bool wxWindow::SetBackgroundColour( const wxColour
&colour
)
2809 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid window") );
2811 if (!wxWindowBase::SetBackgroundColour(colour
))
2813 // don't leave if the GTK widget has just
2815 if (!m_delayedBackgroundColour
) return FALSE
;
2818 GdkWindow
*window
= (GdkWindow
*) NULL
;
2820 window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
2822 window
= GetConnectWidget()->window
;
2826 // indicate that a new style has been set
2827 // but it couldn't get applied as the
2828 // widget hasn't been realized yet.
2829 m_delayedBackgroundColour
= TRUE
;
2831 // pretend we have done something
2837 /* wxMSW doesn't clear the window here. I don't do that either to
2838 provide compatibility. call Clear() to do the job. */
2840 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
2841 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
2844 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
2845 if (sysbg
== m_backgroundColour
)
2847 m_backgroundColour
= wxNullColour
;
2849 m_backgroundColour
= sysbg
;
2859 bool wxWindow::SetForegroundColour( const wxColour
&colour
)
2861 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid window") );
2863 if (!wxWindowBase::SetForegroundColour(colour
))
2865 // don't leave if the GTK widget has just
2867 if (!m_delayedForegroundColour
) return FALSE
;
2870 GdkWindow
*window
= (GdkWindow
*) NULL
;
2872 window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
2874 window
= GetConnectWidget()->window
;
2878 // indicate that a new style has been set
2879 // but it couldn't get applied as the
2880 // widget hasn't been realized yet.
2881 m_delayedForegroundColour
= TRUE
;
2883 // pretend we have done something
2887 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
2888 if ( sysbg
== m_backgroundColour
)
2890 m_backgroundColour
= wxNullColour
;
2892 m_backgroundColour
= sysbg
;
2902 GtkStyle
*wxWindow::GetWidgetStyle()
2904 if (m_widgetStyle
) gtk_style_unref( m_widgetStyle
);
2906 m_widgetStyle
= gtk_style_copy( gtk_widget_get_style( m_widget
) );
2908 return m_widgetStyle
;
2911 void wxWindow::SetWidgetStyle()
2913 GtkStyle
*style
= GetWidgetStyle();
2915 gdk_font_unref( style
->font
);
2916 style
->font
= gdk_font_ref( m_font
.GetInternalFont( 1.0 ) );
2918 if (m_foregroundColour
.Ok())
2920 m_foregroundColour
.CalcPixel( gdk_window_get_colormap( m_widget
->window
) );
2921 style
->fg
[GTK_STATE_NORMAL
] = *m_foregroundColour
.GetColor();
2922 style
->fg
[GTK_STATE_PRELIGHT
] = *m_foregroundColour
.GetColor();
2923 style
->fg
[GTK_STATE_ACTIVE
] = *m_foregroundColour
.GetColor();
2926 if (m_backgroundColour
.Ok())
2928 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( m_widget
->window
) );
2929 style
->bg
[GTK_STATE_NORMAL
] = *m_backgroundColour
.GetColor();
2930 style
->base
[GTK_STATE_NORMAL
] = *m_backgroundColour
.GetColor();
2931 style
->bg
[GTK_STATE_PRELIGHT
] = *m_backgroundColour
.GetColor();
2932 style
->base
[GTK_STATE_PRELIGHT
] = *m_backgroundColour
.GetColor();
2933 style
->bg
[GTK_STATE_ACTIVE
] = *m_backgroundColour
.GetColor();
2934 style
->base
[GTK_STATE_ACTIVE
] = *m_backgroundColour
.GetColor();
2935 style
->bg
[GTK_STATE_INSENSITIVE
] = *m_backgroundColour
.GetColor();
2936 style
->base
[GTK_STATE_INSENSITIVE
] = *m_backgroundColour
.GetColor();
2940 void wxWindow::ApplyWidgetStyle()
2944 //-----------------------------------------------------------------------------
2945 // Pop-up menu stuff
2946 //-----------------------------------------------------------------------------
2948 static void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
2950 *is_waiting
= FALSE
;
2953 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
2955 menu
->SetInvokingWindow( win
);
2956 wxNode
*node
= menu
->GetItems().First();
2959 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
2960 if (menuitem
->IsSubMenu())
2962 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
2964 node
= node
->Next();
2968 static gint gs_pop_x
= 0;
2969 static gint gs_pop_y
= 0;
2971 static void pop_pos_callback( GtkMenu
* WXUNUSED(menu
),
2975 win
->ClientToScreen( &gs_pop_x
, &gs_pop_y
);
2980 bool wxWindow::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
2982 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid window") );
2984 wxCHECK_MSG( menu
!= NULL
, FALSE
, wxT("invalid popup-menu") );
2986 SetInvokingWindow( menu
, this );
2993 bool is_waiting
= TRUE
;
2995 gtk_signal_connect( GTK_OBJECT(menu
->m_menu
), "hide",
2996 GTK_SIGNAL_FUNC(gtk_pop_hide_callback
), (gpointer
)&is_waiting
);
2999 GTK_MENU(menu
->m_menu
),
3000 (GtkWidget
*) NULL
, // parent menu shell
3001 (GtkWidget
*) NULL
, // parent menu item
3002 (GtkMenuPositionFunc
) pop_pos_callback
,
3003 (gpointer
) this, // client data
3004 0, // button used to activate it
3005 gs_timeLastClick
// the time of activation
3010 while (gtk_events_pending())
3011 gtk_main_iteration();
3017 #if wxUSE_DRAG_AND_DROP
3019 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
3021 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3023 GtkWidget
*dnd_widget
= GetConnectWidget();
3025 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3027 if (m_dropTarget
) delete m_dropTarget
;
3028 m_dropTarget
= dropTarget
;
3030 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3033 #endif // wxUSE_DRAG_AND_DROP
3035 GtkWidget
* wxWindow::GetConnectWidget()
3037 GtkWidget
*connect_widget
= m_widget
;
3038 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3040 return connect_widget
;
3043 bool wxWindow::IsOwnGtkWindow( GdkWindow
*window
)
3046 return (window
== GTK_MYFIXED(m_wxwindow
)->bin_window
);
3048 return (window
== m_widget
->window
);
3051 bool wxWindow::SetFont( const wxFont
&font
)
3053 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid window") );
3055 if (!wxWindowBase::SetFont(font
))
3057 // don't leave if the GTK widget has just
3059 if (!m_delayedFont
) return FALSE
;
3062 GdkWindow
*window
= (GdkWindow
*) NULL
;
3064 window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
3066 window
= GetConnectWidget()->window
;
3070 // indicate that a new style has been set
3071 // but it couldn't get applied as the
3072 // widget hasn't been realized yet.
3073 m_delayedFont
= TRUE
;
3075 // pretend we have done something
3079 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
3080 if ( sysbg
== m_backgroundColour
)
3082 m_backgroundColour
= wxNullColour
;
3084 m_backgroundColour
= sysbg
;
3094 void wxWindow::CaptureMouse()
3096 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3098 wxCHECK_RET( g_captureWindow
== NULL
, wxT("CaptureMouse called twice") );
3100 GdkWindow
*window
= (GdkWindow
*) NULL
;
3102 window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
3104 window
= GetConnectWidget()->window
;
3106 if (!window
) return;
3108 gdk_pointer_grab( window
, FALSE
,
3110 (GDK_BUTTON_PRESS_MASK
|
3111 GDK_BUTTON_RELEASE_MASK
|
3112 GDK_POINTER_MOTION_HINT_MASK
|
3113 GDK_POINTER_MOTION_MASK
),
3115 m_cursor
.GetCursor(),
3117 g_captureWindow
= this;
3120 void wxWindow::ReleaseMouse()
3122 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3124 wxCHECK_RET( g_captureWindow
, wxT("ReleaseMouse called twice") );
3126 GdkWindow
*window
= (GdkWindow
*) NULL
;
3128 window
= GTK_MYFIXED(m_wxwindow
)->bin_window
;
3130 window
= GetConnectWidget()->window
;
3132 if (!window
) return;
3134 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
3135 g_captureWindow
= (wxWindow
*) NULL
;
3138 bool wxWindow::IsRetained() const
3143 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
3144 int range
, bool refresh
)
3146 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3148 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3150 m_hasScrolling
= TRUE
;
3152 if (orient
== wxHORIZONTAL
)
3154 float fpos
= (float)pos
;
3155 float frange
= (float)range
;
3156 float fthumb
= (float)thumbVisible
;
3157 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3158 if (fpos
< 0.0) fpos
= 0.0;
3160 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
3161 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
3163 SetScrollPos( orient
, pos
, refresh
);
3167 m_oldHorizontalPos
= fpos
;
3169 m_hAdjust
->lower
= 0.0;
3170 m_hAdjust
->upper
= frange
;
3171 m_hAdjust
->value
= fpos
;
3172 m_hAdjust
->step_increment
= 1.0;
3173 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
3174 m_hAdjust
->page_size
= fthumb
;
3178 float fpos
= (float)pos
;
3179 float frange
= (float)range
;
3180 float fthumb
= (float)thumbVisible
;
3181 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3182 if (fpos
< 0.0) fpos
= 0.0;
3184 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
3185 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
3187 SetScrollPos( orient
, pos
, refresh
);
3191 m_oldVerticalPos
= fpos
;
3193 m_vAdjust
->lower
= 0.0;
3194 m_vAdjust
->upper
= frange
;
3195 m_vAdjust
->value
= fpos
;
3196 m_vAdjust
->step_increment
= 1.0;
3197 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
3198 m_vAdjust
->page_size
= fthumb
;
3201 if (orient
== wxHORIZONTAL
)
3202 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
3204 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
3207 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
3209 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3211 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3213 if (orient
== wxHORIZONTAL
)
3215 float fpos
= (float)pos
;
3216 if (fpos
> m_hAdjust
->upper
- m_hAdjust
->page_size
) fpos
= m_hAdjust
->upper
- m_hAdjust
->page_size
;
3217 if (fpos
< 0.0) fpos
= 0.0;
3218 m_oldHorizontalPos
= fpos
;
3220 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
3221 m_hAdjust
->value
= fpos
;
3225 float fpos
= (float)pos
;
3226 if (fpos
> m_vAdjust
->upper
- m_vAdjust
->page_size
) fpos
= m_vAdjust
->upper
- m_vAdjust
->page_size
;
3227 if (fpos
< 0.0) fpos
= 0.0;
3228 m_oldVerticalPos
= fpos
;
3230 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
3231 m_vAdjust
->value
= fpos
;
3238 if (m_wxwindow
->window
)
3240 if (orient
== wxHORIZONTAL
)
3241 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
3243 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
3250 int wxWindow::GetScrollThumb( int orient
) const
3252 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
3254 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
3256 if (orient
== wxHORIZONTAL
)
3257 return (int)(m_hAdjust
->page_size
+0.5);
3259 return (int)(m_vAdjust
->page_size
+0.5);
3262 int wxWindow::GetScrollPos( int orient
) const
3264 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
3266 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
3268 if (orient
== wxHORIZONTAL
)
3269 return (int)(m_hAdjust
->value
+0.5);
3271 return (int)(m_vAdjust
->value
+0.5);
3274 int wxWindow::GetScrollRange( int orient
) const
3276 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
3278 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
3280 if (orient
== wxHORIZONTAL
)
3281 return (int)(m_hAdjust
->upper
+0.5);
3283 return (int)(m_vAdjust
->upper
+0.5);
3286 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
3288 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3290 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3292 gtk_myfixed_scroll( GTK_MYFIXED(m_wxwindow
), -dx
, -dy
);
3297 m_scrollGC = gdk_gc_new( m_wxwindow->window );
3298 gdk_gc_set_exposures( m_scrollGC, TRUE );
3301 wxNode *node = m_children.First();
3304 wxWindow *child = (wxWindow*) node->Data();
3307 child->GetSize( &sx, &sy );
3308 child->SetSize( child->m_x + dx, child->m_y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE );
3309 node = node->Next();
3314 GetClientSize( &cw, &ch );
3315 int w = cw - abs(dx);
3316 int h = ch - abs(dy);
3318 if ((h < 0) || (w < 0))
3326 if (dx < 0) s_x = -dx;
3327 if (dy < 0) s_y = -dy;
3330 if (dx > 0) d_x = dx;
3331 if (dy > 0) d_y = dy;
3333 gdk_window_copy_area( m_wxwindow->window, m_scrollGC, d_x, d_y,
3334 m_wxwindow->window, s_x, s_y, w, h );
3337 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
3338 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
3339 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
3340 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
3342 Refresh( TRUE, &rect );
3347 void wxWindow::SetScrolling(bool scroll
)
3349 m_isScrolling
= g_blockEventsOnScroll
= scroll
;