]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: window.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
c67d8618 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Julian Smart |
5e0aa05a | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "window.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/defs.h" | |
16 | #include "wx/window.h" | |
17 | #include "wx/dc.h" | |
18 | #include "wx/frame.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/layout.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/dialog.h" | |
23 | #include "wx/msgdlg.h" | |
24 | #include "wx/dcclient.h" | |
25 | #include "wx/dnd.h" | |
30dea054 | 26 | #include "wx/menu.h" |
d4c99d6f | 27 | #include "wx/statusbr.h" |
b4071e91 | 28 | #include "wx/intl.h" |
3bc755fc | 29 | #include "wx/settings.h" |
c801d85f | 30 | #include "gdk/gdkprivate.h" |
b4071e91 RR |
31 | #include "gdk/gdkkeysyms.h" |
32 | ||
33 | #include <math.h> | |
c801d85f | 34 | |
868a2826 RR |
35 | //----------------------------------------------------------------------------- |
36 | // documentation on internals | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
39 | /* | |
40 | I have been asked several times about writing some documentation about | |
41 | the GTK port of wxWindows, especially its internal structures. Obviously, | |
42 | you cannot understand wxGTK without knowing a little about the GTK, but | |
47d67540 | 43 | some more information about what the wxWindow, which is the base class |
868a2826 | 44 | for all other window classes, does seems required as well. |
47d67540 | 45 | |
868a2826 | 46 | What does wxWindow do? It contains the common interface for the following |
e380f72b | 47 | jobs of its descendants: |
47d67540 | 48 | |
868a2826 | 49 | 1) Define the rudimentary behaviour common to all window classes, such as |
e380f72b RR |
50 | resizing, intercepting user input (so as to make it possible to use these |
51 | events for special purposes in a derived class), window names etc. | |
868a2826 RR |
52 | |
53 | 2) Provide the possibility to contain and manage children, if the derived | |
54 | class is allowed to contain children, which holds true for those window | |
e380f72b | 55 | classes which do not display a native GTK widget. To name them, these |
868a2826 | 56 | classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame- |
47d67540 | 57 | work classes are a special case and are handled a bit differently from |
e380f72b | 58 | the rest. The same holds true for the wxNotebook class. |
47d67540 | 59 | |
868a2826 RR |
60 | 3) Provide the possibility to draw into a client area of a window. This, |
61 | too, only holds true for classes that do not display a native GTK widget | |
62 | as above. | |
47d67540 | 63 | |
e380f72b RR |
64 | 4) Provide the entire mechanism for scrolling widgets. This actual inter- |
65 | face for this is usually in wxScrolledWindow, but the GTK implementation | |
868a2826 | 66 | is in this class. |
47d67540 | 67 | |
868a2826 RR |
68 | 5) A multitude of helper or extra methods for special purposes, such as |
69 | Drag'n'Drop, managing validators etc. | |
47d67540 | 70 | |
e380f72b RR |
71 | Normally one might expect, that one wxWindows window would always correspond |
72 | to one GTK widget. Under GTK, there is no such allround widget that has all | |
868a2826 RR |
73 | the functionality. Moreover, the GTK defines a client area as a different |
74 | widget from the actual widget you are handling. Last but not least some | |
75 | special classes (e.g. wxFrame) handle different categories of widgets and | |
76 | still have the possibility to draw something in the client area. | |
77 | It was therefore required to write a special purpose GTK widget, that would | |
78 | represent a client area in the sense of wxWindows capable to do the jobs | |
79 | 2), 3) and 4). I have written this class and it resides in win_gtk.c of | |
80 | this directory. | |
47d67540 | 81 | |
868a2826 | 82 | All windows must have a widget, with which they interact with other under- |
e380f72b | 83 | lying GTK widgets. It is this widget, e.g. that has to be resized etc and |
868a2826 | 84 | thw wxWindow class has a member variable called m_widget which holds a |
e380f72b RR |
85 | pointer to this widget. When the window class represents a GTK native widget, |
86 | this is (in most cases) the only GTK widget the class manages. E.g. the | |
87 | wxStatitText class handles only a GtkLabel widget a pointer to which you | |
88 | can find in m_widget (defined in wxWindow) | |
89 | ||
90 | When the class has a client area for drawing into and for containing children | |
91 | it has to handle the client area widget (of the type GtkMyFixed, defined in | |
92 | win_gtk.c), but there could be any number of widgets, handled by a class | |
93 | The common rule for all windows is only, that the widget that interacts with | |
94 | the rest of GTK must be referenced in m_widget and all other widgets must be | |
95 | children of this widget on the GTK level. The top-most widget, which also | |
96 | represents the client area, must be in the m_wxwindow field and must be of | |
97 | the type GtkMyFixed. | |
47d67540 | 98 | |
868a2826 RR |
99 | As I said, the window classes that display a GTK native widget only have |
100 | one widget, so in the case of e.g. the wxButton class m_widget holds a | |
101 | pointer to a GtkButton widget. But windows with client areas (for drawing | |
102 | and children) have a m_widget field that is a pointer to a GtkScrolled- | |
103 | Window and a m_wxwindow field that is pointer to a GtkMyFixed and this | |
104 | one is (in the GTK sense) a child of the GtkScrolledWindow. | |
47d67540 | 105 | |
868a2826 RR |
106 | If the m_wxwindow field is set, then all input to this widget is inter- |
107 | cepted and sent to the wxWindows class. If not, all input to the widget | |
108 | that gets pointed to by m_widget gets intercepted and sent to the class. | |
109 | ||
110 | */ | |
111 | ||
38c7b3d3 RR |
112 | //------------------------------------------------------------------------- |
113 | // conditional compilation | |
114 | //------------------------------------------------------------------------- | |
115 | ||
116 | #if (GTK_MINOR_VERSION == 1) | |
117 | #if (GTK_MICRO_VERSION >= 5) | |
118 | #define NEW_GTK_SCROLL_CODE | |
119 | #endif | |
120 | #endif | |
121 | ||
c801d85f KB |
122 | //----------------------------------------------------------------------------- |
123 | // data | |
124 | //----------------------------------------------------------------------------- | |
125 | ||
126 | extern wxList wxPendingDelete; | |
127 | extern wxList wxTopLevelWindows; | |
128 | extern bool g_blockEventsOnDrag; | |
47d67540 VZ |
129 | static bool g_capturing = FALSE; |
130 | ||
131 | // hack: we need something to pass to gtk_menu_popup, so we store the time of | |
132 | // the last click here | |
133 | static guint32 gs_timeLastClick = 0; | |
c801d85f KB |
134 | |
135 | //----------------------------------------------------------------------------- | |
2f2aa628 | 136 | // "expose_event" (of m_wxwindow, not of m_widget) |
c801d85f KB |
137 | //----------------------------------------------------------------------------- |
138 | ||
2f2aa628 | 139 | static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win ) |
47d67540 | 140 | { |
f5e27805 RR |
141 | if (!win->HasVMT()) return; |
142 | if (g_blockEventsOnDrag) return; | |
47d67540 | 143 | |
f5e27805 RR |
144 | win->m_updateRegion.Union( gdk_event->area.x, |
145 | gdk_event->area.y, | |
146 | gdk_event->area.width, | |
147 | gdk_event->area.height ); | |
47d67540 | 148 | |
f5e27805 | 149 | if (gdk_event->count > 0) return; |
c801d85f | 150 | |
d8c83875 | 151 | /* |
f5e27805 RR |
152 | printf( "OnExpose from " ); |
153 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
154 | printf( win->GetClassInfo()->GetClassName() ); | |
155 | printf( ".\n" ); | |
d8c83875 RR |
156 | */ |
157 | ||
f5e27805 RR |
158 | wxPaintEvent event( win->GetId() ); |
159 | event.SetEventObject( win ); | |
160 | win->GetEventHandler()->ProcessEvent( event ); | |
47d67540 | 161 | |
f5e27805 | 162 | win->m_updateRegion.Clear(); |
362c6693 | 163 | } |
c801d85f KB |
164 | |
165 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
166 | // "draw" (of m_wxwindow, not of m_widget) |
167 | //----------------------------------------------------------------------------- | |
c801d85f | 168 | |
2f2aa628 | 169 | static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win ) |
47d67540 | 170 | { |
f5e27805 RR |
171 | if (!win->HasVMT()) return; |
172 | if (g_blockEventsOnDrag) return; | |
47d67540 | 173 | |
f5e27805 | 174 | win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); |
47d67540 | 175 | |
f5e27805 RR |
176 | wxPaintEvent event( win->GetId() ); |
177 | event.SetEventObject( win ); | |
178 | win->GetEventHandler()->ProcessEvent( event ); | |
47d67540 | 179 | |
f5e27805 | 180 | win->m_updateRegion.Clear(); |
362c6693 | 181 | } |
c801d85f KB |
182 | |
183 | //----------------------------------------------------------------------------- | |
2f2aa628 | 184 | // "key_press_event" |
c801d85f | 185 | //----------------------------------------------------------------------------- |
c801d85f | 186 | |
2f2aa628 | 187 | static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) |
47d67540 | 188 | { |
f5e27805 RR |
189 | if (!win->HasVMT()) return FALSE; |
190 | if (g_blockEventsOnDrag) return FALSE; | |
c801d85f KB |
191 | |
192 | /* | |
f5e27805 RR |
193 | printf( "OnKeyPress from " ); |
194 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
195 | printf( win->GetClassInfo()->GetClassName() ); | |
196 | printf( ".\n" ); | |
c801d85f KB |
197 | */ |
198 | ||
f5e27805 RR |
199 | long key_code = 0; |
200 | switch (gdk_event->keyval) | |
c801d85f | 201 | { |
f5e27805 RR |
202 | case GDK_BackSpace: key_code = WXK_BACK; break; |
203 | case GDK_Tab: key_code = WXK_TAB; break; | |
204 | case GDK_Linefeed: key_code = WXK_RETURN; break; | |
205 | case GDK_Clear: key_code = WXK_CLEAR; break; | |
206 | case GDK_Return: key_code = WXK_RETURN; break; | |
207 | case GDK_Pause: key_code = WXK_PAUSE; break; | |
208 | case GDK_Scroll_Lock: key_code = WXK_SCROLL; break; | |
209 | case GDK_Escape: key_code = WXK_ESCAPE; break; | |
210 | case GDK_Delete: key_code = WXK_DELETE; break; | |
211 | case GDK_Home: key_code = WXK_HOME; break; | |
212 | case GDK_Left: key_code = WXK_LEFT; break; | |
213 | case GDK_Up: key_code = WXK_UP; break; | |
214 | case GDK_Right: key_code = WXK_RIGHT; break; | |
215 | case GDK_Down: key_code = WXK_DOWN; break; | |
216 | case GDK_Prior: key_code = WXK_PRIOR; break; | |
217 | // case GDK_Page_Up: key_code = WXK_PAGEUP; break; | |
218 | case GDK_Next: key_code = WXK_NEXT; break; | |
219 | // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break; | |
220 | case GDK_End: key_code = WXK_END; break; | |
221 | case GDK_Begin: key_code = WXK_HOME; break; | |
222 | case GDK_Select: key_code = WXK_SELECT; break; | |
223 | case GDK_Print: key_code = WXK_PRINT; break; | |
224 | case GDK_Execute: key_code = WXK_EXECUTE; break; | |
225 | case GDK_Insert: key_code = WXK_INSERT; break; | |
226 | case GDK_Num_Lock: key_code = WXK_NUMLOCK; break; | |
227 | case GDK_KP_Tab: key_code = WXK_TAB; break; | |
228 | case GDK_KP_Enter: key_code = WXK_RETURN; break; | |
229 | case GDK_KP_Home: key_code = WXK_HOME; break; | |
230 | case GDK_KP_Left: key_code = WXK_LEFT; break; | |
231 | case GDK_KP_Up: key_code = WXK_UP; break; | |
232 | case GDK_KP_Right: key_code = WXK_RIGHT; break; | |
233 | case GDK_KP_Down: key_code = WXK_DOWN; break; | |
234 | case GDK_KP_Prior: key_code = WXK_PRIOR; break; | |
235 | // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break; | |
236 | case GDK_KP_Next: key_code = WXK_NEXT; break; | |
237 | // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break; | |
238 | case GDK_KP_End: key_code = WXK_END; break; | |
239 | case GDK_KP_Begin: key_code = WXK_HOME; break; | |
240 | case GDK_KP_Insert: key_code = WXK_INSERT; break; | |
241 | case GDK_KP_Delete: key_code = WXK_DELETE; break; | |
242 | case GDK_KP_Multiply: key_code = WXK_MULTIPLY; break; | |
243 | case GDK_KP_Add: key_code = WXK_ADD; break; | |
244 | case GDK_KP_Separator: key_code = WXK_SEPARATOR; break; | |
245 | case GDK_KP_Subtract: key_code = WXK_SUBTRACT; break; | |
246 | case GDK_KP_Decimal: key_code = WXK_DECIMAL; break; | |
247 | case GDK_KP_Divide: key_code = WXK_DIVIDE; break; | |
248 | case GDK_KP_0: key_code = WXK_NUMPAD0; break; | |
249 | case GDK_KP_1: key_code = WXK_NUMPAD1; break; | |
250 | case GDK_KP_2: key_code = WXK_NUMPAD2; break; | |
251 | case GDK_KP_3: key_code = WXK_NUMPAD3; break; | |
252 | case GDK_KP_4: key_code = WXK_NUMPAD4; break; | |
253 | case GDK_KP_5: key_code = WXK_NUMPAD5; break; | |
254 | case GDK_KP_6: key_code = WXK_NUMPAD6; break; | |
255 | case GDK_KP_7: key_code = WXK_NUMPAD7; break; | |
256 | case GDK_KP_8: key_code = WXK_NUMPAD7; break; | |
257 | case GDK_KP_9: key_code = WXK_NUMPAD9; break; | |
258 | case GDK_F1: key_code = WXK_F1; break; | |
259 | case GDK_F2: key_code = WXK_F2; break; | |
260 | case GDK_F3: key_code = WXK_F3; break; | |
261 | case GDK_F4: key_code = WXK_F4; break; | |
262 | case GDK_F5: key_code = WXK_F5; break; | |
263 | case GDK_F6: key_code = WXK_F6; break; | |
264 | case GDK_F7: key_code = WXK_F7; break; | |
265 | case GDK_F8: key_code = WXK_F8; break; | |
266 | case GDK_F9: key_code = WXK_F9; break; | |
267 | case GDK_F10: key_code = WXK_F10; break; | |
268 | case GDK_F11: key_code = WXK_F11; break; | |
269 | case GDK_F12: key_code = WXK_F12; break; | |
270 | default: | |
271 | { | |
272 | if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF)) | |
273 | key_code = gdk_event->keyval; | |
274 | } | |
362c6693 | 275 | } |
c801d85f | 276 | |
f5e27805 | 277 | if (!key_code) return FALSE; |
47d67540 | 278 | |
f5e27805 RR |
279 | wxKeyEvent event( wxEVT_CHAR ); |
280 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); | |
281 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
282 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
283 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
284 | event.m_keyCode = key_code; | |
285 | event.m_x = 0; | |
286 | event.m_y = 0; | |
287 | event.SetEventObject( win ); | |
47d67540 | 288 | |
f5e27805 | 289 | bool ret = win->GetEventHandler()->ProcessEvent( event ); |
47d67540 | 290 | |
f5e27805 | 291 | if (!ret) |
47d67540 | 292 | { |
f5e27805 RR |
293 | wxWindow *ancestor = win; |
294 | while (ancestor) | |
295 | { | |
296 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
297 | if (command != -1) | |
298 | { | |
299 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
300 | ret = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
301 | break; | |
302 | } | |
303 | ancestor = ancestor->GetParent(); | |
304 | } | |
bcf1fa6b | 305 | } |
47d67540 | 306 | |
f5e27805 RR |
307 | if (ret) |
308 | { | |
309 | if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF)) | |
310 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); | |
311 | } | |
47d67540 | 312 | |
f5e27805 | 313 | return ret; |
362c6693 | 314 | } |
c801d85f KB |
315 | |
316 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
317 | // "button_press_event" |
318 | //----------------------------------------------------------------------------- | |
c801d85f | 319 | |
2f2aa628 | 320 | static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) |
903f689b | 321 | { |
f5e27805 | 322 | if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; |
47d67540 | 323 | |
f5e27805 | 324 | if (g_blockEventsOnDrag) return TRUE; |
c801d85f | 325 | |
f5e27805 | 326 | if (win->m_wxwindow) |
c801d85f | 327 | { |
f5e27805 RR |
328 | if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) ) |
329 | { | |
330 | gtk_widget_grab_focus (win->m_wxwindow); | |
47d67540 | 331 | |
c801d85f | 332 | /* |
f5e27805 RR |
333 | printf( "GrabFocus from " ); |
334 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
335 | printf( win->GetClassInfo()->GetClassName() ); | |
336 | printf( ".\n" ); | |
c801d85f | 337 | */ |
47d67540 | 338 | |
f5e27805 | 339 | } |
362c6693 | 340 | } |
47d67540 | 341 | |
f5e27805 | 342 | if (!win->HasVMT()) return TRUE; |
97b3455a | 343 | |
8429bec1 | 344 | /* |
f5e27805 RR |
345 | printf( "OnButtonPress from " ); |
346 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
347 | printf( win->GetClassInfo()->GetClassName() ); | |
348 | printf( ".\n" ); | |
8429bec1 | 349 | */ |
30dea054 | 350 | |
f5e27805 | 351 | wxEventType event_type = wxEVT_LEFT_DOWN; |
47d67540 | 352 | |
f5e27805 | 353 | if (gdk_event->button == 1) |
c801d85f | 354 | { |
f5e27805 RR |
355 | switch (gdk_event->type) |
356 | { | |
357 | case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break; | |
358 | case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break; | |
359 | default: break; | |
360 | } | |
362c6693 | 361 | } |
f5e27805 | 362 | else if (gdk_event->button == 2) |
c801d85f | 363 | { |
f5e27805 RR |
364 | switch (gdk_event->type) |
365 | { | |
366 | case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break; | |
367 | case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break; | |
368 | default: break; | |
369 | } | |
362c6693 | 370 | } |
f5e27805 | 371 | else if (gdk_event->button == 3) |
c801d85f | 372 | { |
f5e27805 RR |
373 | switch (gdk_event->type) |
374 | { | |
375 | case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break; | |
376 | case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break; | |
377 | default: break; | |
378 | } | |
362c6693 | 379 | } |
47d67540 | 380 | |
f5e27805 RR |
381 | wxMouseEvent event( event_type ); |
382 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); | |
383 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
384 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
385 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
386 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); | |
387 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); | |
388 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); | |
47d67540 | 389 | |
f5e27805 RR |
390 | event.m_x = (long)gdk_event->x; |
391 | event.m_y = (long)gdk_event->y; | |
47d67540 | 392 | |
f5e27805 RR |
393 | // Some control don't have their own X window and thus cannot get |
394 | // any events. | |
47d67540 | 395 | |
f5e27805 | 396 | if (!g_capturing) |
2f2aa628 | 397 | { |
f5e27805 RR |
398 | wxNode *node = win->GetChildren()->First(); |
399 | while (node) | |
400 | { | |
401 | wxWindow *child = (wxWindow*)node->Data(); | |
402 | if ((child->m_x <= event.m_x) && | |
403 | (child->m_y <= event.m_y) && | |
404 | (child->m_x+child->m_width >= event.m_x) && | |
405 | (child->m_y+child->m_height >= event.m_y)) | |
406 | { | |
407 | win = child; | |
408 | event.m_x -= child->m_x; | |
409 | event.m_y -= child->m_y; | |
410 | break; | |
411 | } | |
412 | node = node->Next(); | |
413 | } | |
2f2aa628 | 414 | } |
47d67540 | 415 | |
f5e27805 | 416 | event.SetEventObject( win ); |
47d67540 | 417 | |
f5e27805 | 418 | gs_timeLastClick = gdk_event->time; |
47d67540 | 419 | |
f5e27805 RR |
420 | if (win->GetEventHandler()->ProcessEvent( event )) |
421 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" ); | |
47d67540 | 422 | |
f5e27805 | 423 | return TRUE; |
362c6693 | 424 | } |
c801d85f KB |
425 | |
426 | //----------------------------------------------------------------------------- | |
97b3455a | 427 | // "button_release_event" |
2f2aa628 | 428 | //----------------------------------------------------------------------------- |
c801d85f | 429 | |
2f2aa628 | 430 | static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) |
47d67540 | 431 | { |
f5e27805 | 432 | if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; |
47d67540 | 433 | |
f5e27805 | 434 | if (g_blockEventsOnDrag) return TRUE; |
c801d85f | 435 | |
f5e27805 | 436 | if (!win->HasVMT()) return TRUE; |
47d67540 | 437 | |
c801d85f | 438 | /* |
f5e27805 RR |
439 | printf( "OnButtonRelease from " ); |
440 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
441 | printf( win->GetClassInfo()->GetClassName() ); | |
442 | printf( ".\n" ); | |
c801d85f | 443 | */ |
47d67540 | 444 | |
f5e27805 | 445 | wxEventType event_type = wxEVT_NULL; |
47d67540 | 446 | |
f5e27805 RR |
447 | switch (gdk_event->button) |
448 | { | |
449 | case 1: event_type = wxEVT_LEFT_UP; break; | |
450 | case 2: event_type = wxEVT_MIDDLE_UP; break; | |
451 | case 3: event_type = wxEVT_RIGHT_UP; break; | |
452 | } | |
47d67540 | 453 | |
f5e27805 RR |
454 | wxMouseEvent event( event_type ); |
455 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); | |
456 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
457 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
458 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
459 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); | |
460 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); | |
461 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); | |
462 | event.m_x = (long)gdk_event->x; | |
463 | event.m_y = (long)gdk_event->y; | |
464 | ||
465 | // Some control don't have their own X window and thus cannot get | |
466 | // any events. | |
467 | ||
468 | if (!g_capturing) | |
2f2aa628 | 469 | { |
f5e27805 RR |
470 | wxNode *node = win->GetChildren()->First(); |
471 | while (node) | |
472 | { | |
473 | wxWindow *child = (wxWindow*)node->Data(); | |
474 | if ((child->m_x <= event.m_x) && | |
475 | (child->m_y <= event.m_y) && | |
476 | (child->m_x+child->m_width >= event.m_x) && | |
477 | (child->m_y+child->m_height >= event.m_y)) | |
478 | { | |
479 | win = child; | |
480 | event.m_x -= child->m_x; | |
481 | event.m_y -= child->m_y; | |
482 | break; | |
483 | } | |
484 | node = node->Next(); | |
485 | } | |
2f2aa628 | 486 | } |
47d67540 | 487 | |
f5e27805 | 488 | event.SetEventObject( win ); |
47d67540 | 489 | |
f5e27805 RR |
490 | if (win->GetEventHandler()->ProcessEvent( event )) |
491 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" ); | |
47d67540 | 492 | |
f5e27805 | 493 | return TRUE; |
362c6693 | 494 | } |
c801d85f KB |
495 | |
496 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
497 | // "motion_notify_event" |
498 | //----------------------------------------------------------------------------- | |
c801d85f | 499 | |
2f2aa628 | 500 | static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win ) |
47d67540 | 501 | { |
e380f72b | 502 | if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE; |
47d67540 | 503 | |
e380f72b | 504 | if (g_blockEventsOnDrag) return TRUE; |
c801d85f | 505 | |
e380f72b | 506 | if (!win->HasVMT()) return TRUE; |
47d67540 | 507 | |
c801d85f | 508 | /* |
e380f72b RR |
509 | printf( "OnMotion from " ); |
510 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
511 | printf( win->GetClassInfo()->GetClassName() ); | |
512 | printf( ".\n" ); | |
c801d85f | 513 | */ |
47d67540 | 514 | |
e380f72b RR |
515 | wxMouseEvent event( wxEVT_MOTION ); |
516 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); | |
517 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
518 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
519 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
520 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); | |
521 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); | |
522 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); | |
523 | ||
524 | event.m_x = (long)gdk_event->x; | |
525 | event.m_y = (long)gdk_event->y; | |
526 | ||
527 | // Some control don't have their own X window and thus cannot get | |
528 | // any events. | |
529 | ||
530 | if (!g_capturing) | |
2f2aa628 | 531 | { |
e380f72b RR |
532 | wxNode *node = win->GetChildren()->First(); |
533 | while (node) | |
534 | { | |
535 | wxWindow *child = (wxWindow*)node->Data(); | |
536 | if ((child->m_x <= event.m_x) && | |
537 | (child->m_y <= event.m_y) && | |
538 | (child->m_x+child->m_width >= event.m_x) && | |
539 | (child->m_y+child->m_height >= event.m_y)) | |
540 | { | |
541 | win = child; | |
542 | event.m_x -= child->m_x; | |
543 | event.m_y -= child->m_y; | |
544 | break; | |
545 | } | |
546 | node = node->Next(); | |
547 | } | |
2f2aa628 | 548 | } |
47d67540 | 549 | |
e380f72b | 550 | event.SetEventObject( win ); |
47d67540 | 551 | |
e380f72b RR |
552 | if (win->GetEventHandler()->ProcessEvent( event )) |
553 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" ); | |
47d67540 | 554 | |
e380f72b | 555 | return TRUE; |
362c6693 | 556 | } |
c801d85f KB |
557 | |
558 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
559 | // "focus_in_event" |
560 | //----------------------------------------------------------------------------- | |
c801d85f | 561 | |
2f2aa628 | 562 | static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) |
c801d85f | 563 | { |
e380f72b RR |
564 | if (g_blockEventsOnDrag) return TRUE; |
565 | if (win->m_wxwindow) | |
c801d85f | 566 | { |
e380f72b RR |
567 | if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) |
568 | { | |
569 | GTK_WIDGET_SET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS); | |
47d67540 | 570 | /* |
e380f72b RR |
571 | printf( "SetFocus flag from " ); |
572 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
573 | printf( win->GetClassInfo()->GetClassName() ); | |
574 | printf( ".\n" ); | |
c801d85f | 575 | */ |
e380f72b | 576 | } |
362c6693 | 577 | } |
47d67540 | 578 | |
e380f72b | 579 | if (!win->HasVMT()) return TRUE; |
47d67540 | 580 | |
c801d85f | 581 | /* |
e380f72b RR |
582 | printf( "OnSetFocus from " ); |
583 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
584 | printf( win->GetClassInfo()->GetClassName() ); | |
585 | printf( " " ); | |
586 | printf( WXSTRINGCAST win->GetLabel() ); | |
587 | printf( ".\n" ); | |
c801d85f | 588 | */ |
47d67540 | 589 | |
e380f72b RR |
590 | wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); |
591 | event.SetEventObject( win ); | |
47d67540 | 592 | |
e380f72b RR |
593 | if (win->GetEventHandler()->ProcessEvent( event )) |
594 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" ); | |
47d67540 | 595 | |
e380f72b | 596 | return TRUE; |
362c6693 | 597 | } |
c801d85f KB |
598 | |
599 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
600 | // "focus_out_event" |
601 | //----------------------------------------------------------------------------- | |
c801d85f | 602 | |
2f2aa628 | 603 | static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) |
c801d85f | 604 | { |
e380f72b RR |
605 | if (g_blockEventsOnDrag) return TRUE; |
606 | if (win->m_wxwindow) | |
607 | { | |
608 | if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) | |
609 | GTK_WIDGET_UNSET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS); | |
610 | } | |
47d67540 | 611 | |
e380f72b | 612 | if (!win->HasVMT()) return TRUE; |
47d67540 | 613 | |
c801d85f | 614 | /* |
e380f72b RR |
615 | printf( "OnKillFocus from " ); |
616 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
617 | printf( win->GetClassInfo()->GetClassName() ); | |
618 | printf( ".\n" ); | |
c801d85f | 619 | */ |
47d67540 | 620 | |
e380f72b RR |
621 | wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); |
622 | event.SetEventObject( win ); | |
47d67540 | 623 | |
e380f72b RR |
624 | if (win->GetEventHandler()->ProcessEvent( event )) |
625 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_out_event" ); | |
2f2aa628 | 626 | |
e380f72b | 627 | return TRUE; |
362c6693 | 628 | } |
c801d85f | 629 | |
b4071e91 RR |
630 | //----------------------------------------------------------------------------- |
631 | // "enter_notify_event" | |
632 | //----------------------------------------------------------------------------- | |
633 | ||
634 | static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) | |
635 | { | |
e380f72b | 636 | if (widget->window != gdk_event->window) return TRUE; |
47d67540 | 637 | |
e380f72b | 638 | if (g_blockEventsOnDrag) return TRUE; |
47d67540 | 639 | |
e380f72b | 640 | if (!win->HasVMT()) return TRUE; |
47d67540 | 641 | |
d8c83875 | 642 | /* |
e380f72b RR |
643 | printf( "OnEnter from " ); |
644 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
645 | printf( win->GetClassInfo()->GetClassName() ); | |
646 | printf( ".\n" ); | |
d8c83875 | 647 | */ |
47d67540 | 648 | |
e380f72b RR |
649 | if ((widget->window) && (win->m_cursor)) |
650 | gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() ); | |
47d67540 | 651 | |
e380f72b RR |
652 | wxMouseEvent event( wxEVT_ENTER_WINDOW ); |
653 | event.SetEventObject( win ); | |
47d67540 | 654 | |
e380f72b RR |
655 | if (win->GetEventHandler()->ProcessEvent( event )) |
656 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" ); | |
47d67540 | 657 | |
e380f72b | 658 | return TRUE; |
b4071e91 | 659 | } |
47d67540 | 660 | |
b4071e91 RR |
661 | //----------------------------------------------------------------------------- |
662 | // "leave_notify_event" | |
663 | //----------------------------------------------------------------------------- | |
664 | ||
665 | static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) | |
666 | { | |
e380f72b | 667 | if (widget->window != gdk_event->window) return TRUE; |
47d67540 | 668 | |
e380f72b | 669 | if (g_blockEventsOnDrag) return TRUE; |
47d67540 | 670 | |
e380f72b | 671 | if (!win->HasVMT()) return TRUE; |
47d67540 | 672 | |
d8c83875 | 673 | /* |
e380f72b RR |
674 | printf( "OnLeave from " ); |
675 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
676 | printf( win->GetClassInfo()->GetClassName() ); | |
677 | printf( ".\n" ); | |
d8c83875 | 678 | */ |
47d67540 | 679 | |
e380f72b RR |
680 | if ((widget->window) && (win->m_cursor)) |
681 | gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() ); | |
47d67540 | 682 | |
e380f72b RR |
683 | wxMouseEvent event( wxEVT_LEAVE_WINDOW ); |
684 | event.SetEventObject( win ); | |
47d67540 | 685 | |
e380f72b RR |
686 | if (win->GetEventHandler()->ProcessEvent( event )) |
687 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" ); | |
47d67540 | 688 | |
e380f72b | 689 | return TRUE; |
b4071e91 | 690 | } |
47d67540 | 691 | |
c801d85f | 692 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
693 | // "value_changed" from m_vAdjust |
694 | //----------------------------------------------------------------------------- | |
c801d85f | 695 | |
2f2aa628 | 696 | static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
c801d85f | 697 | { |
e380f72b | 698 | if (g_blockEventsOnDrag) return; |
c801d85f KB |
699 | |
700 | /* | |
e380f72b RR |
701 | printf( "OnVScroll from " ); |
702 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
703 | printf( win->GetClassInfo()->GetClassName() ); | |
704 | printf( ".\n" ); | |
c801d85f | 705 | */ |
47d67540 | 706 | |
e380f72b | 707 | if (!win->HasVMT()) return; |
47d67540 | 708 | |
e380f72b RR |
709 | float diff = win->m_vAdjust->value - win->m_oldVerticalPos; |
710 | if (fabs(diff) < 0.2) return; | |
47d67540 | 711 | |
e380f72b | 712 | wxEventType command = wxEVT_NULL; |
47d67540 | 713 | |
e380f72b RR |
714 | float line_step = win->m_vAdjust->step_increment; |
715 | float page_step = win->m_vAdjust->page_increment; | |
47d67540 | 716 | |
3bc755fc RR |
717 | if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM; |
718 | else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP; | |
719 | else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; | |
e380f72b RR |
720 | else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; |
721 | else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; | |
722 | else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; | |
723 | else command = wxEVT_SCROLL_THUMBTRACK; | |
47d67540 | 724 | |
e380f72b | 725 | int value = (int)(win->m_vAdjust->value+0.5); |
c801d85f | 726 | |
e380f72b RR |
727 | wxScrollEvent event( command, win->GetId(), value, wxVERTICAL ); |
728 | event.SetEventObject( win ); | |
729 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 730 | } |
c801d85f KB |
731 | |
732 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
733 | // "value_changed" from m_hAdjust |
734 | //----------------------------------------------------------------------------- | |
c801d85f | 735 | |
2f2aa628 | 736 | static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
47d67540 | 737 | { |
e380f72b | 738 | if (g_blockEventsOnDrag) return; |
47d67540 | 739 | |
c801d85f | 740 | /* |
e380f72b RR |
741 | printf( "OnHScroll from " ); |
742 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
743 | printf( win->GetClassInfo()->GetClassName() ); | |
744 | printf( ".\n" ); | |
c801d85f | 745 | */ |
47d67540 | 746 | |
e380f72b | 747 | if (!win->HasVMT()) return; |
47d67540 | 748 | |
e380f72b RR |
749 | float diff = win->m_hAdjust->value - win->m_oldHorizontalPos; |
750 | if (fabs(diff) < 0.2) return; | |
47d67540 | 751 | |
e380f72b | 752 | wxEventType command = wxEVT_NULL; |
47d67540 | 753 | |
e380f72b RR |
754 | float line_step = win->m_hAdjust->step_increment; |
755 | float page_step = win->m_hAdjust->page_increment; | |
3bc755fc RR |
756 | |
757 | if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM; | |
758 | else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP; | |
759 | else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN; | |
e380f72b RR |
760 | else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP; |
761 | else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN; | |
762 | else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP; | |
763 | else command = wxEVT_SCROLL_THUMBTRACK; | |
c801d85f | 764 | |
e380f72b | 765 | int value = (int)(win->m_hAdjust->value+0.5); |
47d67540 | 766 | |
e380f72b RR |
767 | wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL ); |
768 | event.SetEventObject( win ); | |
769 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 770 | } |
c801d85f KB |
771 | |
772 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
773 | // "changed" from m_vAdjust |
774 | //----------------------------------------------------------------------------- | |
c801d85f | 775 | |
2f2aa628 | 776 | static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
c801d85f | 777 | { |
e380f72b | 778 | if (g_blockEventsOnDrag) return; |
c801d85f KB |
779 | |
780 | /* | |
e380f72b RR |
781 | printf( "OnVScroll change from " ); |
782 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
783 | printf( win->GetClassInfo()->GetClassName() ); | |
784 | printf( ".\n" ); | |
c801d85f | 785 | */ |
47d67540 | 786 | |
e380f72b | 787 | if (!win->HasVMT()) return; |
47d67540 | 788 | |
e380f72b RR |
789 | wxEventType command = wxEVT_SCROLL_THUMBTRACK; |
790 | int value = (int)(win->m_vAdjust->value+0.5); | |
c801d85f | 791 | |
e380f72b RR |
792 | wxScrollEvent event( command, win->GetId(), value, wxVERTICAL ); |
793 | event.SetEventObject( win ); | |
794 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 795 | } |
c801d85f KB |
796 | |
797 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
798 | // "changed" from m_hAdjust |
799 | //----------------------------------------------------------------------------- | |
c801d85f | 800 | |
2f2aa628 | 801 | static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
47d67540 | 802 | { |
e380f72b | 803 | if (g_blockEventsOnDrag) return; |
47d67540 | 804 | |
c801d85f | 805 | /* |
e380f72b RR |
806 | printf( "OnHScroll change from " ); |
807 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
808 | printf( win->GetClassInfo()->GetClassName() ); | |
809 | printf( ".\n" ); | |
c801d85f | 810 | */ |
47d67540 | 811 | |
e380f72b | 812 | if (!win->HasVMT()) return; |
47d67540 | 813 | |
e380f72b RR |
814 | wxEventType command = wxEVT_SCROLL_THUMBTRACK; |
815 | int value = (int)(win->m_hAdjust->value+0.5); | |
47d67540 | 816 | |
e380f72b RR |
817 | wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL ); |
818 | event.SetEventObject( win ); | |
819 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 820 | } |
c801d85f | 821 | |
cb43b372 RR |
822 | //----------------------------------------------------------------------------- |
823 | // "button_press_event" from scrollbar | |
824 | //----------------------------------------------------------------------------- | |
825 | ||
826 | static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win ) | |
827 | { | |
e380f72b | 828 | if (gdk_event->window != widget->slider) return FALSE; |
84efdbf1 | 829 | |
e380f72b | 830 | win->m_isScrolling = TRUE; |
47d67540 | 831 | |
e380f72b | 832 | return FALSE; |
cb43b372 RR |
833 | } |
834 | ||
835 | //----------------------------------------------------------------------------- | |
836 | // "button_release_event" from scrollbar | |
837 | //----------------------------------------------------------------------------- | |
838 | ||
839 | static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win ) | |
840 | { | |
e380f72b | 841 | if (gdk_event->window != widget->slider) return FALSE; |
cb43b372 | 842 | |
e380f72b | 843 | GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(win->m_widget); |
47d67540 | 844 | |
e380f72b RR |
845 | if (widget == GTK_RANGE(s_window->vscrollbar)) |
846 | gtk_signal_emit_by_name( GTK_OBJECT(win->m_hAdjust), "value_changed" ); | |
847 | else | |
848 | gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" ); | |
47d67540 | 849 | |
e380f72b | 850 | win->m_isScrolling = FALSE; |
47d67540 | 851 | |
e380f72b | 852 | return FALSE; |
cb43b372 RR |
853 | } |
854 | ||
6ca41e57 RR |
855 | //----------------------------------------------------------------------------- |
856 | // InsertChild for wxWindow. | |
857 | //----------------------------------------------------------------------------- | |
858 | ||
859 | // Callback for wxWindow. This very strange beast has to be used because | |
860 | // C++ has no virtual methods in a constructor. We have to emulate a | |
861 | // virtual function here as wxNotebook requires a different way to insert | |
862 | // a child in it. I had opted for creating a wxNotebookPage window class | |
863 | // which would have made this superflouus (such in the MDI window system), | |
864 | // but no-one is listening to me... | |
865 | ||
866 | static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child ) | |
867 | { | |
f5e27805 RR |
868 | gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), |
869 | GTK_WIDGET(child->m_widget), | |
870 | child->m_x, | |
871 | child->m_y ); | |
6ca41e57 | 872 | |
f5e27805 RR |
873 | gtk_widget_set_usize( GTK_WIDGET(child->m_widget), |
874 | child->m_width, | |
875 | child->m_height ); | |
6ca41e57 RR |
876 | } |
877 | ||
c801d85f | 878 | //----------------------------------------------------------------------------- |
2f2aa628 | 879 | // wxWindow |
c801d85f KB |
880 | //----------------------------------------------------------------------------- |
881 | ||
882 | IMPLEMENT_DYNAMIC_CLASS(wxWindow,wxEvtHandler) | |
883 | ||
884 | BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) | |
e380f72b RR |
885 | EVT_SIZE(wxWindow::OnSize) |
886 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) | |
887 | EVT_INIT_DIALOG(wxWindow::OnInitDialog) | |
888 | EVT_IDLE(wxWindow::OnIdle) | |
c801d85f KB |
889 | END_EVENT_TABLE() |
890 | ||
891 | wxWindow::wxWindow() | |
892 | { | |
e380f72b RR |
893 | m_widget = (GtkWidget *) NULL; |
894 | m_wxwindow = (GtkWidget *) NULL; | |
895 | m_parent = (wxWindow *) NULL; | |
896 | m_children.DeleteContents( FALSE ); | |
f5e27805 | 897 | |
e380f72b RR |
898 | m_x = 0; |
899 | m_y = 0; | |
900 | m_width = 0; | |
901 | m_height = 0; | |
902 | m_minWidth = -1; | |
903 | m_minHeight = -1; | |
904 | m_maxWidth = -1; | |
905 | m_maxHeight = -1; | |
f5e27805 | 906 | |
e380f72b | 907 | m_retCode = 0; |
f5e27805 | 908 | |
e380f72b RR |
909 | m_eventHandler = this; |
910 | m_windowValidator = (wxValidator *) NULL; | |
f5e27805 | 911 | |
e380f72b | 912 | m_windowId = -1; |
f5e27805 | 913 | |
e380f72b RR |
914 | m_cursor = (wxCursor *) NULL; |
915 | m_font = *wxSWISS_FONT; | |
916 | m_windowStyle = 0; | |
917 | m_windowName = "noname"; | |
f5e27805 | 918 | |
e380f72b RR |
919 | m_constraints = (wxLayoutConstraints *) NULL; |
920 | m_constraintsInvolvedIn = (wxList *) NULL; | |
921 | m_windowSizer = (wxSizer *) NULL; | |
922 | m_sizerParent = (wxWindow *) NULL; | |
923 | m_autoLayout = FALSE; | |
f5e27805 | 924 | |
e380f72b RR |
925 | m_sizeSet = FALSE; |
926 | m_hasVMT = FALSE; | |
927 | m_needParent = TRUE; | |
f5e27805 | 928 | |
e380f72b RR |
929 | m_hasScrolling = FALSE; |
930 | m_isScrolling = FALSE; | |
931 | m_hAdjust = (GtkAdjustment*) NULL; | |
932 | m_vAdjust = (GtkAdjustment*) NULL; | |
933 | m_oldHorizontalPos = 0.0; | |
934 | m_oldVerticalPos = 0.0; | |
f5e27805 | 935 | |
e380f72b RR |
936 | m_isShown = FALSE; |
937 | m_isEnabled = TRUE; | |
f5e27805 | 938 | |
e380f72b RR |
939 | m_dropTarget = (wxDropTarget*) NULL; |
940 | m_resizing = FALSE; | |
941 | m_scrollGC = (GdkGC*) NULL; | |
942 | m_widgetStyle = (GtkStyle*) NULL; | |
f5e27805 | 943 | |
e380f72b | 944 | m_insertCallback = wxInsertChildInWindow; |
f5e27805 | 945 | |
e380f72b RR |
946 | m_clientObject = (wxClientData*) NULL; |
947 | m_clientData = NULL; | |
362c6693 | 948 | } |
c801d85f | 949 | |
6ca41e57 | 950 | wxWindow::wxWindow( wxWindow *parent, wxWindowID id, |
e380f72b RR |
951 | const wxPoint &pos, const wxSize &size, |
952 | long style, const wxString &name ) | |
6ca41e57 | 953 | { |
e380f72b RR |
954 | m_insertCallback = wxInsertChildInWindow; |
955 | Create( parent, id, pos, size, style, name ); | |
6ca41e57 RR |
956 | } |
957 | ||
debe6624 | 958 | bool wxWindow::Create( wxWindow *parent, wxWindowID id, |
e380f72b RR |
959 | const wxPoint &pos, const wxSize &size, |
960 | long style, const wxString &name ) | |
c801d85f | 961 | { |
e380f72b RR |
962 | m_isShown = FALSE; |
963 | m_isEnabled = TRUE; | |
964 | m_needParent = TRUE; | |
47d67540 | 965 | |
e380f72b | 966 | PreCreation( parent, id, pos, size, style, name ); |
47d67540 | 967 | |
e380f72b | 968 | m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); |
38c7b3d3 | 969 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
47d67540 | 970 | |
e380f72b | 971 | GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); |
47d67540 | 972 | |
e380f72b | 973 | gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_press_event", |
cb43b372 RR |
974 | (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); |
975 | ||
e380f72b | 976 | gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_press_event", |
84efdbf1 RR |
977 | (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); |
978 | ||
e380f72b | 979 | gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_release_event", |
84efdbf1 RR |
980 | (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); |
981 | ||
e380f72b | 982 | gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_release_event", |
cb43b372 RR |
983 | (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); |
984 | ||
e380f72b RR |
985 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); |
986 | scroll_class->scrollbar_spacing = 0; | |
47d67540 | 987 | |
e380f72b | 988 | gtk_scrolled_window_set_policy( s_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); |
47d67540 | 989 | |
e380f72b RR |
990 | m_oldHorizontalPos = 0.0; |
991 | m_oldVerticalPos = 0.0; | |
47d67540 | 992 | |
e380f72b RR |
993 | m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->hscrollbar) ); |
994 | m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->vscrollbar) ); | |
47d67540 | 995 | |
e380f72b | 996 | gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", |
5e0aa05a | 997 | (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); |
e380f72b | 998 | gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", |
5e0aa05a | 999 | (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); |
47d67540 | 1000 | |
e380f72b | 1001 | gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed", |
5e0aa05a | 1002 | (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this ); |
e380f72b | 1003 | gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed", |
5e0aa05a | 1004 | (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this ); |
47d67540 | 1005 | |
38c7b3d3 RR |
1006 | m_wxwindow = gtk_myfixed_new(); |
1007 | ||
1008 | #ifdef NEW_GTK_SCROLL_CODE | |
1009 | gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow ); | |
1010 | GtkViewport *viewport = GTK_VIEWPORT(s_window->child); | |
1011 | #else | |
1012 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); | |
e380f72b | 1013 | GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport); |
38c7b3d3 | 1014 | #endif |
47d67540 | 1015 | |
e380f72b RR |
1016 | if (m_windowStyle & wxRAISED_BORDER) |
1017 | { | |
1018 | gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT ); | |
1019 | } | |
1020 | else if (m_windowStyle & wxSUNKEN_BORDER) | |
1021 | { | |
1022 | gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN ); | |
1023 | } | |
1024 | else | |
1025 | { | |
1026 | gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE ); | |
1027 | } | |
47d67540 | 1028 | |
e380f72b RR |
1029 | if (m_windowStyle & wxTAB_TRAVERSAL == wxTAB_TRAVERSAL) |
1030 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
1031 | else | |
1032 | GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
1033 | ||
e380f72b RR |
1034 | // shut the viewport up |
1035 | gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); | |
1036 | gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); | |
1037 | ||
1038 | // I _really_ don't want scrollbars in the beginning | |
1039 | m_vAdjust->lower = 0.0; | |
1040 | m_vAdjust->upper = 1.0; | |
1041 | m_vAdjust->value = 0.0; | |
1042 | m_vAdjust->step_increment = 1.0; | |
1043 | m_vAdjust->page_increment = 1.0; | |
1044 | m_vAdjust->page_size = 5.0; | |
1045 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); | |
1046 | m_hAdjust->lower = 0.0; | |
1047 | m_hAdjust->upper = 1.0; | |
1048 | m_hAdjust->value = 0.0; | |
1049 | m_hAdjust->step_increment = 1.0; | |
1050 | m_hAdjust->page_increment = 1.0; | |
1051 | m_hAdjust->page_size = 5.0; | |
1052 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); | |
1053 | ||
1054 | gtk_widget_show( m_wxwindow ); | |
6ca41e57 | 1055 | |
e380f72b | 1056 | if (m_parent) m_parent->AddChild( this ); |
47d67540 | 1057 | |
e380f72b | 1058 | (m_parent->m_insertCallback)( m_parent, this ); |
6ca41e57 | 1059 | |
e380f72b | 1060 | PostCreation(); |
32e9da8b | 1061 | |
e380f72b | 1062 | Show( TRUE ); |
c801d85f | 1063 | |
e380f72b | 1064 | return TRUE; |
362c6693 | 1065 | } |
c801d85f | 1066 | |
68dda785 | 1067 | wxWindow::~wxWindow() |
c801d85f | 1068 | { |
43a18898 | 1069 | m_hasVMT = FALSE; |
47d67540 | 1070 | |
43a18898 | 1071 | if (m_dropTarget) delete m_dropTarget; |
47d67540 | 1072 | |
43a18898 RR |
1073 | if (m_parent) m_parent->RemoveChild( this ); |
1074 | if (m_widget) Show( FALSE ); | |
c801d85f | 1075 | |
43a18898 | 1076 | DestroyChildren(); |
47d67540 | 1077 | |
43a18898 | 1078 | if (m_widgetStyle) gtk_style_unref( m_widgetStyle ); |
a81258be | 1079 | |
43a18898 | 1080 | if (m_scrollGC) gdk_gc_unref( m_scrollGC ); |
32e9da8b | 1081 | |
43a18898 | 1082 | if (m_wxwindow) gtk_widget_destroy( m_wxwindow ); |
47d67540 | 1083 | |
43a18898 | 1084 | if (m_widget) gtk_widget_destroy( m_widget ); |
47d67540 | 1085 | |
43a18898 | 1086 | if (m_cursor) delete m_cursor; |
c801d85f | 1087 | |
43a18898 RR |
1088 | DeleteRelatedConstraints(); |
1089 | if (m_constraints) | |
1090 | { | |
1091 | // This removes any dangling pointers to this window | |
1092 | // in other windows' constraintsInvolvedIn lists. | |
1093 | UnsetConstraints(m_constraints); | |
1094 | delete m_constraints; | |
1095 | m_constraints = (wxLayoutConstraints *) NULL; | |
1096 | } | |
1097 | if (m_windowSizer) | |
1098 | { | |
1099 | delete m_windowSizer; | |
1100 | m_windowSizer = (wxSizer *) NULL; | |
1101 | } | |
1102 | // If this is a child of a sizer, remove self from parent | |
1103 | if (m_sizerParent) m_sizerParent->RemoveChild((wxWindow *)this); | |
c801d85f | 1104 | |
43a18898 RR |
1105 | // Just in case the window has been Closed, but |
1106 | // we're then deleting immediately: don't leave | |
1107 | // dangling pointers. | |
1108 | wxPendingDelete.DeleteObject(this); | |
c801d85f | 1109 | |
43a18898 RR |
1110 | // Just in case we've loaded a top-level window via |
1111 | // wxWindow::LoadNativeDialog but we weren't a dialog | |
1112 | // class | |
1113 | wxTopLevelWindows.DeleteObject(this); | |
47d67540 | 1114 | |
43a18898 | 1115 | if (m_windowValidator) delete m_windowValidator; |
f5e27805 | 1116 | |
43a18898 | 1117 | if (m_clientObject) delete m_clientObject; |
362c6693 | 1118 | } |
c801d85f | 1119 | |
debe6624 JS |
1120 | void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, |
1121 | const wxPoint &pos, const wxSize &size, | |
1122 | long style, const wxString &name ) | |
c801d85f | 1123 | { |
43a18898 RR |
1124 | if (m_needParent && (parent == NULL)) |
1125 | wxFatalError( "Need complete parent.", name ); | |
6ca41e57 | 1126 | |
43a18898 RR |
1127 | m_widget = (GtkWidget*) NULL; |
1128 | m_wxwindow = (GtkWidget*) NULL; | |
1129 | m_hasVMT = FALSE; | |
1130 | m_parent = parent; | |
1131 | m_children.DeleteContents( FALSE ); | |
6ca41e57 | 1132 | |
43a18898 RR |
1133 | m_width = size.x; |
1134 | if (m_width == -1) m_width = 20; | |
1135 | m_height = size.y; | |
1136 | if (m_height == -1) m_height = 20; | |
6ca41e57 | 1137 | |
43a18898 RR |
1138 | m_x = (int)pos.x; |
1139 | m_y = (int)pos.y; | |
6ca41e57 | 1140 | |
43a18898 | 1141 | if (!m_needParent) // some reasonable defaults |
6ca41e57 | 1142 | { |
43a18898 RR |
1143 | if (m_x == -1) |
1144 | { | |
1145 | m_x = (gdk_screen_width () - m_width) / 2; | |
1146 | if (m_x < 10) m_x = 10; | |
1147 | } | |
1148 | if (m_y == -1) | |
1149 | { | |
1150 | m_y = (gdk_screen_height () - m_height) / 2; | |
1151 | if (m_y < 10) m_y = 10; | |
1152 | } | |
6ca41e57 | 1153 | } |
6ca41e57 | 1154 | |
43a18898 RR |
1155 | m_minWidth = -1; |
1156 | m_minHeight = -1; | |
1157 | m_maxWidth = -1; | |
1158 | m_maxHeight = -1; | |
f5e27805 | 1159 | |
43a18898 | 1160 | m_retCode = 0; |
f5e27805 | 1161 | |
43a18898 | 1162 | m_eventHandler = this; |
f5e27805 | 1163 | |
43a18898 | 1164 | m_windowId = id; |
f5e27805 | 1165 | |
43a18898 | 1166 | m_sizeSet = FALSE; |
f5e27805 | 1167 | |
43a18898 RR |
1168 | m_cursor = new wxCursor( wxCURSOR_ARROW ); |
1169 | m_font = *wxSWISS_FONT; | |
fc54776e | 1170 | // m_backgroundColour = wxWHITE; |
58614078 | 1171 | // m_foregroundColour = wxBLACK; |
43a18898 RR |
1172 | m_windowStyle = style; |
1173 | m_windowName = name; | |
f5e27805 | 1174 | |
43a18898 RR |
1175 | m_constraints = (wxLayoutConstraints *) NULL; |
1176 | m_constraintsInvolvedIn = (wxList *) NULL; | |
1177 | m_windowSizer = (wxSizer *) NULL; | |
1178 | m_sizerParent = (wxWindow *) NULL; | |
1179 | m_autoLayout = FALSE; | |
f5e27805 | 1180 | |
43a18898 RR |
1181 | m_hasScrolling = FALSE; |
1182 | m_isScrolling = FALSE; | |
1183 | m_hAdjust = (GtkAdjustment *) NULL; | |
1184 | m_vAdjust = (GtkAdjustment *) NULL; | |
1185 | m_oldHorizontalPos = 0.0; | |
1186 | m_oldVerticalPos = 0.0; | |
f5e27805 | 1187 | |
43a18898 RR |
1188 | m_isShown = FALSE; |
1189 | m_isEnabled = TRUE; | |
f5e27805 | 1190 | |
43a18898 RR |
1191 | m_dropTarget = (wxDropTarget *) NULL; |
1192 | m_resizing = FALSE; | |
1193 | m_windowValidator = (wxValidator *) NULL; | |
1194 | m_scrollGC = (GdkGC*) NULL; | |
1195 | m_widgetStyle = (GtkStyle*) NULL; | |
f5e27805 | 1196 | |
43a18898 RR |
1197 | m_clientObject = (wxClientData*)NULL; |
1198 | m_clientData = NULL; | |
c801d85f KB |
1199 | } |
1200 | ||
68dda785 | 1201 | void wxWindow::PostCreation() |
c801d85f | 1202 | { |
43a18898 RR |
1203 | if (m_wxwindow) |
1204 | { | |
1205 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", | |
1206 | GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this ); | |
47d67540 | 1207 | |
43a18898 RR |
1208 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", |
1209 | GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this ); | |
1210 | } | |
47d67540 | 1211 | |
43a18898 | 1212 | ConnectWidget( GetConnectWidget() ); |
47d67540 | 1213 | |
43a18898 | 1214 | if (m_widget && m_parent) gtk_widget_realize( m_widget ); |
47d67540 | 1215 | |
43a18898 | 1216 | if (m_wxwindow) gtk_widget_realize( m_wxwindow ); |
47d67540 | 1217 | |
43a18898 | 1218 | SetCursor( *wxSTANDARD_CURSOR ); |
47d67540 | 1219 | |
43a18898 | 1220 | m_hasVMT = TRUE; |
b4071e91 RR |
1221 | } |
1222 | ||
1223 | void wxWindow::ConnectWidget( GtkWidget *widget ) | |
1224 | { | |
43a18898 RR |
1225 | gtk_signal_connect( GTK_OBJECT(widget), "key_press_event", |
1226 | GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this ); | |
c801d85f | 1227 | |
43a18898 RR |
1228 | gtk_signal_connect( GTK_OBJECT(widget), "button_press_event", |
1229 | GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this ); | |
47d67540 | 1230 | |
43a18898 RR |
1231 | gtk_signal_connect( GTK_OBJECT(widget), "button_release_event", |
1232 | GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this ); | |
47d67540 | 1233 | |
43a18898 RR |
1234 | gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event", |
1235 | GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this ); | |
47d67540 | 1236 | |
43a18898 RR |
1237 | gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", |
1238 | GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this ); | |
c801d85f | 1239 | |
43a18898 RR |
1240 | gtk_signal_connect( GTK_OBJECT(widget), "focus_out_event", |
1241 | GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this ); | |
c801d85f | 1242 | |
43a18898 RR |
1243 | gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event", |
1244 | GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this ); | |
47d67540 | 1245 | |
43a18898 RR |
1246 | gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event", |
1247 | GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this ); | |
362c6693 | 1248 | } |
c801d85f | 1249 | |
68dda785 | 1250 | bool wxWindow::HasVMT() |
c801d85f | 1251 | { |
43a18898 | 1252 | return m_hasVMT; |
362c6693 | 1253 | } |
c801d85f | 1254 | |
debe6624 | 1255 | bool wxWindow::Close( bool force ) |
c801d85f | 1256 | { |
43a18898 | 1257 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1258 | |
43a18898 RR |
1259 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); |
1260 | event.SetEventObject(this); | |
1261 | event.SetForce(force); | |
c801d85f | 1262 | |
43a18898 | 1263 | return GetEventHandler()->ProcessEvent(event); |
362c6693 | 1264 | } |
c801d85f | 1265 | |
68dda785 | 1266 | bool wxWindow::Destroy() |
c801d85f | 1267 | { |
43a18898 | 1268 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1269 | |
43a18898 RR |
1270 | m_hasVMT = FALSE; |
1271 | delete this; | |
1272 | return TRUE; | |
362c6693 | 1273 | } |
c801d85f | 1274 | |
68dda785 | 1275 | bool wxWindow::DestroyChildren() |
c801d85f | 1276 | { |
43a18898 | 1277 | if (GetChildren()) |
c801d85f | 1278 | { |
43a18898 RR |
1279 | wxNode *node; |
1280 | while ((node = GetChildren()->First()) != (wxNode *)NULL) | |
1281 | { | |
1282 | wxWindow *child; | |
1283 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) | |
1284 | { | |
1285 | delete child; | |
1286 | if (GetChildren()->Member(child)) delete node; | |
1287 | } | |
1288 | } | |
362c6693 | 1289 | } |
43a18898 | 1290 | return TRUE; |
362c6693 | 1291 | } |
c801d85f KB |
1292 | |
1293 | void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) ) | |
1294 | { | |
43a18898 | 1295 | // are we to set fonts here ? |
362c6693 | 1296 | } |
c801d85f | 1297 | |
6ca41e57 RR |
1298 | wxPoint wxWindow::GetClientAreaOrigin() const |
1299 | { | |
43a18898 | 1300 | return wxPoint(0,0); |
6ca41e57 RR |
1301 | } |
1302 | ||
1303 | void wxWindow::AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ) | |
1304 | { | |
43a18898 RR |
1305 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) |
1306 | { | |
1307 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
1308 | x += pt.x; | |
1309 | y += pt.y; | |
1310 | } | |
6ca41e57 RR |
1311 | } |
1312 | ||
debe6624 | 1313 | void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags ) |
c801d85f | 1314 | { |
fb1585ae RR |
1315 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
1316 | wxASSERT_MSG( (m_parent != NULL), "wxWindow::SetSize requires parent.\n" ); | |
1317 | ||
1318 | // Don't do anything for children of wxNotebook | |
1319 | if (m_parent->m_wxwindow == NULL) return; | |
47d67540 | 1320 | |
fb1585ae RR |
1321 | if (m_resizing) return; // I don't like recursions |
1322 | m_resizing = TRUE; | |
47d67540 | 1323 | |
fb1585ae RR |
1324 | int old_width = m_width; |
1325 | int old_height = m_height; | |
1326 | ||
1327 | if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) | |
1328 | { | |
1329 | if (x != -1) m_x = x; | |
1330 | if (y != -1) m_y = y; | |
1331 | if (width != -1) m_width = width; | |
1332 | if (height != -1) m_height = height; | |
1333 | } | |
1334 | else | |
1335 | { | |
1336 | m_x = x; | |
1337 | m_y = y; | |
1338 | m_width = width; | |
1339 | m_height = height; | |
1340 | } | |
47d67540 | 1341 | |
fb1585ae RR |
1342 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) |
1343 | { | |
1344 | if (width == -1) m_width = 80; | |
1345 | } | |
47d67540 | 1346 | |
fb1585ae RR |
1347 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) |
1348 | { | |
1349 | if (height == -1) m_height = 26; | |
1350 | } | |
1351 | ||
1352 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
1353 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
1354 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; | |
1355 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; | |
47d67540 | 1356 | |
fb1585ae RR |
1357 | wxPoint pt( m_parent->GetClientAreaOrigin() ); |
1358 | gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y ); | |
6ca41e57 | 1359 | |
fb1585ae RR |
1360 | if ((old_width != m_width) || (old_height != m_height)) |
1361 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
6ca41e57 | 1362 | |
fb1585ae | 1363 | m_sizeSet = TRUE; |
47d67540 | 1364 | |
fb1585ae RR |
1365 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
1366 | event.SetEventObject( this ); | |
1367 | ProcessEvent( event ); | |
47d67540 | 1368 | |
fb1585ae | 1369 | m_resizing = FALSE; |
362c6693 | 1370 | } |
c801d85f | 1371 | |
debe6624 | 1372 | void wxWindow::SetSize( int width, int height ) |
c801d85f | 1373 | { |
fb1585ae | 1374 | SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); |
362c6693 | 1375 | } |
c801d85f | 1376 | |
debe6624 | 1377 | void wxWindow::Move( int x, int y ) |
c801d85f | 1378 | { |
fb1585ae | 1379 | SetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); |
362c6693 | 1380 | } |
c801d85f KB |
1381 | |
1382 | void wxWindow::GetSize( int *width, int *height ) const | |
1383 | { | |
fb1585ae | 1384 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1385 | |
fb1585ae RR |
1386 | if (width) (*width) = m_width; |
1387 | if (height) (*height) = m_height; | |
362c6693 | 1388 | } |
c801d85f | 1389 | |
debe6624 | 1390 | void wxWindow::SetClientSize( int width, int height ) |
c801d85f | 1391 | { |
e55ad60e | 1392 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1393 | |
c801d85f KB |
1394 | if (!m_wxwindow) |
1395 | { | |
1396 | SetSize( width, height ); | |
1397 | } | |
1398 | else | |
1399 | { | |
1400 | int dw = 0; | |
1401 | int dh = 0; | |
47d67540 | 1402 | |
c801d85f KB |
1403 | if (!m_hasScrolling) |
1404 | { | |
1405 | /* | |
1406 | do we have sunken dialogs ? | |
47d67540 | 1407 | |
c801d85f | 1408 | GtkStyleClass *window_class = m_wxwindow->style->klass; |
47d67540 | 1409 | |
c801d85f KB |
1410 | dw += 2 * window_class->xthickness; |
1411 | dh += 2 * window_class->ythickness; | |
1412 | */ | |
1413 | } | |
1414 | else | |
1415 | { | |
1416 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); | |
1417 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); | |
47d67540 | 1418 | |
38c7b3d3 RR |
1419 | #ifdef NEW_GTK_SCROLL_CODE |
1420 | GtkWidget *viewport = scroll_window->child; | |
1421 | #else | |
c801d85f | 1422 | GtkWidget *viewport = scroll_window->viewport; |
38c7b3d3 RR |
1423 | #endif |
1424 | ||
c801d85f | 1425 | GtkStyleClass *viewport_class = viewport->style->klass; |
47d67540 | 1426 | |
c801d85f KB |
1427 | GtkWidget *hscrollbar = scroll_window->hscrollbar; |
1428 | GtkWidget *vscrollbar = scroll_window->vscrollbar; | |
47d67540 | 1429 | |
c801d85f | 1430 | if ((m_windowStyle & wxRAISED_BORDER) || |
2f2aa628 | 1431 | (m_windowStyle & wxSUNKEN_BORDER)) |
c801d85f KB |
1432 | { |
1433 | dw += 2 * viewport_class->xthickness; | |
1434 | dh += 2 * viewport_class->ythickness; | |
362c6693 | 1435 | } |
47d67540 | 1436 | |
c801d85f KB |
1437 | if (GTK_WIDGET_VISIBLE(vscrollbar)) |
1438 | { | |
1439 | dw += vscrollbar->allocation.width; | |
1440 | dw += scroll_class->scrollbar_spacing; | |
362c6693 | 1441 | } |
47d67540 | 1442 | |
c801d85f KB |
1443 | if (GTK_WIDGET_VISIBLE(hscrollbar)) |
1444 | { | |
1445 | dh += hscrollbar->allocation.height; | |
1446 | dw += scroll_class->scrollbar_spacing; | |
362c6693 RR |
1447 | } |
1448 | } | |
47d67540 | 1449 | |
c801d85f | 1450 | SetSize( width+dw, height+dh ); |
362c6693 RR |
1451 | } |
1452 | } | |
c801d85f KB |
1453 | |
1454 | void wxWindow::GetClientSize( int *width, int *height ) const | |
1455 | { | |
e55ad60e | 1456 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1457 | |
c801d85f KB |
1458 | if (!m_wxwindow) |
1459 | { | |
1460 | if (width) (*width) = m_width; | |
1461 | if (height) (*height) = m_height; | |
1462 | } | |
1463 | else | |
1464 | { | |
1465 | int dw = 0; | |
1466 | int dh = 0; | |
47d67540 | 1467 | |
c801d85f KB |
1468 | if (!m_hasScrolling) |
1469 | { | |
1470 | /* | |
1471 | do we have sunken dialogs ? | |
47d67540 | 1472 | |
c801d85f | 1473 | GtkStyleClass *window_class = m_wxwindow->style->klass; |
47d67540 | 1474 | |
c801d85f KB |
1475 | dw += 2 * window_class->xthickness; |
1476 | dh += 2 * window_class->ythickness; | |
1477 | */ | |
1478 | } | |
1479 | else | |
1480 | { | |
1481 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); | |
1482 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); | |
47d67540 | 1483 | |
38c7b3d3 RR |
1484 | #ifdef NEW_GTK_SCROLL_CODE |
1485 | GtkWidget *viewport = scroll_window->child; | |
1486 | #else | |
c801d85f | 1487 | GtkWidget *viewport = scroll_window->viewport; |
38c7b3d3 RR |
1488 | #endif |
1489 | ||
c801d85f | 1490 | GtkStyleClass *viewport_class = viewport->style->klass; |
47d67540 | 1491 | |
c801d85f KB |
1492 | GtkWidget *hscrollbar = scroll_window->hscrollbar; |
1493 | GtkWidget *vscrollbar = scroll_window->vscrollbar; | |
47d67540 | 1494 | |
c801d85f | 1495 | if ((m_windowStyle & wxRAISED_BORDER) || |
2f2aa628 | 1496 | (m_windowStyle & wxSUNKEN_BORDER)) |
c801d85f KB |
1497 | { |
1498 | dw += 2 * viewport_class->xthickness; | |
1499 | dh += 2 * viewport_class->ythickness; | |
362c6693 | 1500 | } |
47d67540 | 1501 | |
c801d85f KB |
1502 | if (GTK_WIDGET_VISIBLE(vscrollbar)) |
1503 | { | |
1504 | // dw += vscrollbar->allocation.width; | |
1505 | dw += 15; // range.slider_width = 11 + 2*2pts edge | |
1506 | dw += scroll_class->scrollbar_spacing; | |
362c6693 | 1507 | } |
47d67540 | 1508 | |
c801d85f KB |
1509 | if (GTK_WIDGET_VISIBLE(hscrollbar)) |
1510 | { | |
1511 | // dh += hscrollbar->allocation.height; | |
1512 | dh += 15; | |
1513 | dh += scroll_class->scrollbar_spacing; | |
362c6693 RR |
1514 | } |
1515 | } | |
47d67540 | 1516 | |
c801d85f KB |
1517 | if (width) (*width) = m_width - dw; |
1518 | if (height) (*height) = m_height - dh; | |
362c6693 RR |
1519 | } |
1520 | } | |
c801d85f KB |
1521 | |
1522 | void wxWindow::GetPosition( int *x, int *y ) const | |
1523 | { | |
43a18898 | 1524 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1525 | |
43a18898 RR |
1526 | if (x) (*x) = m_x; |
1527 | if (y) (*y) = m_y; | |
362c6693 | 1528 | } |
c801d85f KB |
1529 | |
1530 | void wxWindow::ClientToScreen( int *x, int *y ) | |
1531 | { | |
43a18898 | 1532 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1533 | |
43a18898 RR |
1534 | GdkWindow *source = (GdkWindow *) NULL; |
1535 | if (m_wxwindow) | |
1536 | source = m_wxwindow->window; | |
1537 | else | |
1538 | source = m_widget->window; | |
47d67540 | 1539 | |
43a18898 RR |
1540 | int org_x = 0; |
1541 | int org_y = 0; | |
1542 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 1543 | |
43a18898 | 1544 | if (!m_wxwindow) |
c801d85f | 1545 | { |
43a18898 RR |
1546 | if (GTK_WIDGET_NO_WINDOW (m_widget)) |
1547 | { | |
1548 | org_x += m_widget->allocation.x; | |
1549 | org_y += m_widget->allocation.y; | |
1550 | } | |
362c6693 | 1551 | } |
47d67540 | 1552 | |
43a18898 RR |
1553 | wxPoint pt(GetClientAreaOrigin()); |
1554 | org_x += pt.x; | |
1555 | org_y += pt.y; | |
6ca41e57 | 1556 | |
43a18898 RR |
1557 | if (x) *x += org_x; |
1558 | if (y) *y += org_y; | |
362c6693 | 1559 | } |
c801d85f KB |
1560 | |
1561 | void wxWindow::ScreenToClient( int *x, int *y ) | |
1562 | { | |
e55ad60e | 1563 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1564 | |
c67daf87 | 1565 | GdkWindow *source = (GdkWindow *) NULL; |
c801d85f KB |
1566 | if (m_wxwindow) |
1567 | source = m_wxwindow->window; | |
1568 | else | |
1569 | source = m_widget->window; | |
47d67540 | 1570 | |
c801d85f KB |
1571 | int org_x = 0; |
1572 | int org_y = 0; | |
1573 | gdk_window_get_origin( source, &org_x, &org_y ); | |
1574 | ||
1575 | if (!m_wxwindow) | |
47d67540 | 1576 | { |
c801d85f KB |
1577 | if (GTK_WIDGET_NO_WINDOW (m_widget)) |
1578 | { | |
1579 | org_x += m_widget->allocation.x; | |
1580 | org_y += m_widget->allocation.y; | |
362c6693 RR |
1581 | } |
1582 | } | |
47d67540 | 1583 | |
6ca41e57 RR |
1584 | wxPoint pt(GetClientAreaOrigin()); |
1585 | org_x -= pt.x; | |
1586 | org_y -= pt.y; | |
1587 | ||
47d67540 VZ |
1588 | if (x) *x -= org_x; |
1589 | if (y) *y -= org_y; | |
362c6693 | 1590 | } |
c801d85f | 1591 | |
debe6624 | 1592 | void wxWindow::Centre( int direction ) |
c801d85f | 1593 | { |
e55ad60e | 1594 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1595 | |
fb1585ae RR |
1596 | int x = m_x; |
1597 | int y = m_y; | |
1598 | ||
1599 | if (m_parent) | |
c801d85f | 1600 | { |
c801d85f KB |
1601 | int p_w = 0; |
1602 | int p_h = 0; | |
1603 | m_parent->GetSize( &p_w, &p_h ); | |
fb1585ae RR |
1604 | if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (p_w - m_width) / 2; |
1605 | if (direction & wxVERTICAL == wxVERTICAL) y = (p_h - m_height) / 2; | |
1606 | } | |
1607 | else | |
1608 | { | |
1609 | if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; | |
1610 | if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
c801d85f | 1611 | } |
fb1585ae RR |
1612 | |
1613 | Move( x, y ); | |
362c6693 | 1614 | } |
c801d85f | 1615 | |
68dda785 | 1616 | void wxWindow::Fit() |
c801d85f | 1617 | { |
e55ad60e | 1618 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1619 | |
5e0aa05a VZ |
1620 | int maxX = 0; |
1621 | int maxY = 0; | |
1622 | wxNode *node = GetChildren()->First(); | |
1623 | while ( node ) | |
1624 | { | |
1625 | wxWindow *win = (wxWindow *)node->Data(); | |
1626 | int wx, wy, ww, wh; | |
1627 | win->GetPosition(&wx, &wy); | |
1628 | win->GetSize(&ww, &wh); | |
1629 | if ( wx + ww > maxX ) | |
1630 | maxX = wx + ww; | |
1631 | if ( wy + wh > maxY ) | |
1632 | maxY = wy + wh; | |
1633 | ||
1634 | node = node->Next(); | |
1635 | } | |
47908e25 | 1636 | SetClientSize(maxX + 5, maxY + 10); |
362c6693 | 1637 | } |
c801d85f | 1638 | |
2f2aa628 RR |
1639 | void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH) ) |
1640 | { | |
e55ad60e | 1641 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1642 | |
2f2aa628 RR |
1643 | m_minWidth = minW; |
1644 | m_minHeight = minH; | |
1645 | m_maxWidth = maxW; | |
1646 | m_maxHeight = maxH; | |
1647 | } | |
1648 | ||
c801d85f KB |
1649 | void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) |
1650 | { | |
da7f8ac4 | 1651 | //if (GetAutoLayout()) Layout(); |
362c6693 | 1652 | } |
c801d85f | 1653 | |
debe6624 | 1654 | bool wxWindow::Show( bool show ) |
c801d85f | 1655 | { |
e55ad60e | 1656 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1657 | |
c801d85f KB |
1658 | if (show) |
1659 | gtk_widget_show( m_widget ); | |
1660 | else | |
1661 | gtk_widget_hide( m_widget ); | |
47d67540 | 1662 | m_isShown = show; |
c801d85f | 1663 | return TRUE; |
362c6693 | 1664 | } |
c801d85f | 1665 | |
debe6624 | 1666 | void wxWindow::Enable( bool enable ) |
c801d85f | 1667 | { |
e55ad60e | 1668 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1669 | |
c801d85f KB |
1670 | m_isEnabled = enable; |
1671 | gtk_widget_set_sensitive( m_widget, enable ); | |
1672 | if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable ); | |
362c6693 | 1673 | } |
c801d85f | 1674 | |
68dda785 | 1675 | int wxWindow::GetCharHeight() const |
c33c4050 | 1676 | { |
e55ad60e | 1677 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1678 | |
e55ad60e RR |
1679 | if (!m_font.Ok()) |
1680 | { | |
1681 | wxFAIL_MSG( "invalid font" ); | |
1682 | return -1; | |
1683 | } | |
47d67540 | 1684 | |
c33c4050 RR |
1685 | GdkFont *font = m_font.GetInternalFont( 1.0 ); |
1686 | return font->ascent + font->descent; | |
1687 | } | |
1688 | ||
68dda785 | 1689 | int wxWindow::GetCharWidth() const |
c33c4050 | 1690 | { |
e55ad60e | 1691 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1692 | |
e55ad60e RR |
1693 | if (!m_font.Ok()) |
1694 | { | |
1695 | wxFAIL_MSG( "invalid font" ); | |
1696 | return -1; | |
1697 | } | |
47d67540 | 1698 | |
c33c4050 RR |
1699 | GdkFont *font = m_font.GetInternalFont( 1.0 ); |
1700 | return gdk_string_width( font, "H" ); | |
1701 | } | |
1702 | ||
1703 | void wxWindow::GetTextExtent( const wxString& string, int *x, int *y, | |
1704 | int *descent, int *externalLeading, const wxFont *theFont, bool WXUNUSED(use16) ) const | |
1705 | { | |
e55ad60e | 1706 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1707 | |
c33c4050 RR |
1708 | wxFont fontToUse = m_font; |
1709 | if (theFont) fontToUse = *theFont; | |
47d67540 | 1710 | |
e55ad60e RR |
1711 | if (!fontToUse.Ok()) |
1712 | { | |
1713 | wxFAIL_MSG( "invalid font" ); | |
1714 | return; | |
1715 | } | |
1716 | wxASSERT_MSG( (m_font.Ok()), "invalid font" ); | |
47d67540 | 1717 | |
c33c4050 | 1718 | GdkFont *font = fontToUse.GetInternalFont( 1.0 ); |
66c135f3 | 1719 | if (x) (*x) = gdk_string_width( font, string ); |
c33c4050 RR |
1720 | if (y) (*y) = font->ascent + font->descent; |
1721 | if (descent) (*descent) = font->descent; | |
1722 | if (externalLeading) (*externalLeading) = 0; // ?? | |
1723 | } | |
1724 | ||
debe6624 | 1725 | void wxWindow::MakeModal( bool modal ) |
c801d85f KB |
1726 | { |
1727 | return; | |
1728 | // Disable all other windows | |
1729 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
1730 | { | |
1731 | wxNode *node = wxTopLevelWindows.First(); | |
1732 | while (node) | |
1733 | { | |
1734 | wxWindow *win = (wxWindow *)node->Data(); | |
1735 | if (win != this) | |
1736 | win->Enable(!modal); | |
1737 | ||
1738 | node = node->Next(); | |
1739 | } | |
1740 | } | |
1741 | } | |
1742 | ||
68dda785 | 1743 | void wxWindow::SetFocus() |
c801d85f | 1744 | { |
e55ad60e | 1745 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1746 | |
30dea054 | 1747 | GtkWidget *connect_widget = GetConnectWidget(); |
c801d85f KB |
1748 | if (connect_widget) |
1749 | { | |
1750 | if (GTK_WIDGET_CAN_FOCUS(connect_widget) && !GTK_WIDGET_HAS_FOCUS (connect_widget) ) | |
1751 | { | |
1752 | gtk_widget_grab_focus (connect_widget); | |
362c6693 RR |
1753 | } |
1754 | } | |
1755 | } | |
c801d85f | 1756 | |
68dda785 | 1757 | bool wxWindow::OnClose() |
c801d85f | 1758 | { |
c801d85f | 1759 | return TRUE; |
362c6693 | 1760 | } |
c801d85f KB |
1761 | |
1762 | void wxWindow::AddChild( wxWindow *child ) | |
1763 | { | |
e55ad60e | 1764 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
e55ad60e | 1765 | wxASSERT_MSG( (child != NULL), "invalid child" ); |
47d67540 | 1766 | |
46dc76ba | 1767 | m_children.Append( child ); |
362c6693 | 1768 | } |
c801d85f | 1769 | |
68dda785 | 1770 | wxList *wxWindow::GetChildren() |
c801d85f KB |
1771 | { |
1772 | return (&m_children); | |
362c6693 | 1773 | } |
c801d85f KB |
1774 | |
1775 | void wxWindow::RemoveChild( wxWindow *child ) | |
1776 | { | |
6ca41e57 | 1777 | if (GetChildren()) GetChildren()->DeleteObject( child ); |
c67daf87 | 1778 | child->m_parent = (wxWindow *) NULL; |
362c6693 | 1779 | } |
c801d85f KB |
1780 | |
1781 | void wxWindow::SetReturnCode( int retCode ) | |
1782 | { | |
1783 | m_retCode = retCode; | |
362c6693 | 1784 | } |
c801d85f | 1785 | |
68dda785 | 1786 | int wxWindow::GetReturnCode() |
c801d85f KB |
1787 | { |
1788 | return m_retCode; | |
362c6693 | 1789 | } |
c801d85f | 1790 | |
68dda785 | 1791 | void wxWindow::Raise() |
362c6693 | 1792 | { |
e55ad60e | 1793 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1794 | |
362c6693 RR |
1795 | if (m_widget) gdk_window_raise( m_widget->window ); |
1796 | } | |
1797 | ||
68dda785 | 1798 | void wxWindow::Lower() |
362c6693 | 1799 | { |
e55ad60e | 1800 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1801 | |
362c6693 RR |
1802 | if (m_widget) gdk_window_lower( m_widget->window ); |
1803 | } | |
c801d85f | 1804 | |
68dda785 | 1805 | wxEvtHandler *wxWindow::GetEventHandler() |
c801d85f KB |
1806 | { |
1807 | return m_eventHandler; | |
362c6693 | 1808 | } |
c801d85f | 1809 | |
86b29a61 | 1810 | void wxWindow::SetEventHandler( wxEvtHandler *handler ) |
c801d85f KB |
1811 | { |
1812 | m_eventHandler = handler; | |
362c6693 | 1813 | } |
c801d85f | 1814 | |
86b29a61 RR |
1815 | void wxWindow::PushEventHandler(wxEvtHandler *handler) |
1816 | { | |
e55ad60e RR |
1817 | handler->SetNextHandler(GetEventHandler()); |
1818 | SetEventHandler(handler); | |
86b29a61 RR |
1819 | } |
1820 | ||
1821 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) | |
1822 | { | |
e55ad60e RR |
1823 | if (GetEventHandler()) |
1824 | { | |
1825 | wxEvtHandler *handlerA = GetEventHandler(); | |
1826 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
1827 | handlerA->SetNextHandler((wxEvtHandler *) NULL); | |
1828 | SetEventHandler(handlerB); | |
1829 | if (deleteHandler) | |
1830 | { | |
1831 | delete handlerA; | |
1832 | return (wxEvtHandler*) NULL; | |
1833 | } | |
1834 | else | |
1835 | return handlerA; | |
1836 | } | |
1837 | else | |
1838 | return (wxEvtHandler *) NULL; | |
86b29a61 RR |
1839 | } |
1840 | ||
68dda785 | 1841 | wxValidator *wxWindow::GetValidator() |
c801d85f KB |
1842 | { |
1843 | return m_windowValidator; | |
362c6693 | 1844 | } |
c801d85f | 1845 | |
6de97a3b | 1846 | void wxWindow::SetValidator( const wxValidator& validator ) |
c801d85f | 1847 | { |
6de97a3b RR |
1848 | if (m_windowValidator) delete m_windowValidator; |
1849 | m_windowValidator = validator.Clone(); | |
1850 | if (m_windowValidator) m_windowValidator->SetWindow(this); | |
362c6693 | 1851 | } |
c801d85f | 1852 | |
fd0eed64 RR |
1853 | void wxWindow::SetClientObject( wxClientData *data ) |
1854 | { | |
f5e27805 RR |
1855 | if (m_clientObject) delete m_clientObject; |
1856 | m_clientObject = data; | |
fd0eed64 RR |
1857 | } |
1858 | ||
1859 | wxClientData *wxWindow::GetClientObject() | |
1860 | { | |
f5e27805 | 1861 | return m_clientObject; |
fd0eed64 RR |
1862 | } |
1863 | ||
1864 | void wxWindow::SetClientData( void *data ) | |
1865 | { | |
f5e27805 | 1866 | m_clientData = data; |
fd0eed64 RR |
1867 | } |
1868 | ||
1869 | void *wxWindow::GetClientData() | |
1870 | { | |
f5e27805 | 1871 | return m_clientData; |
fd0eed64 RR |
1872 | } |
1873 | ||
68dda785 | 1874 | bool wxWindow::IsBeingDeleted() |
c801d85f KB |
1875 | { |
1876 | return FALSE; | |
362c6693 | 1877 | } |
c801d85f KB |
1878 | |
1879 | void wxWindow::SetId( wxWindowID id ) | |
1880 | { | |
1881 | m_windowId = id; | |
362c6693 | 1882 | } |
c801d85f | 1883 | |
68dda785 | 1884 | wxWindowID wxWindow::GetId() |
c801d85f KB |
1885 | { |
1886 | return m_windowId; | |
362c6693 | 1887 | } |
c801d85f KB |
1888 | |
1889 | void wxWindow::SetCursor( const wxCursor &cursor ) | |
1890 | { | |
e55ad60e | 1891 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1892 | |
d8c83875 RR |
1893 | if (m_cursor == NULL) |
1894 | { | |
1895 | wxFAIL_MSG( "wxWindow::SetCursor m_cursor == NULL" ); | |
1896 | m_cursor = new wxCursor( wxCURSOR_ARROW ); | |
1897 | } | |
47d67540 | 1898 | |
d8c83875 RR |
1899 | if (cursor.Ok()) |
1900 | { | |
1901 | if (*((wxCursor*)&cursor) == m_cursor) return; | |
1902 | *m_cursor = cursor; | |
1903 | } | |
1904 | else | |
1905 | { | |
1906 | *m_cursor = *wxSTANDARD_CURSOR; | |
1907 | } | |
a3622daa | 1908 | |
d8c83875 | 1909 | if ((m_widget) && (m_widget->window)) |
c801d85f | 1910 | gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); |
47d67540 | 1911 | |
d8c83875 | 1912 | if ((m_wxwindow) && (m_wxwindow->window)) |
c801d85f | 1913 | gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() ); |
362c6693 | 1914 | } |
c801d85f | 1915 | |
debe6624 | 1916 | void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) |
c801d85f | 1917 | { |
e55ad60e | 1918 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 1919 | |
c801d85f KB |
1920 | if (eraseBackground && m_wxwindow && m_wxwindow->window) |
1921 | { | |
1922 | if (rect) | |
47d67540 VZ |
1923 | gdk_window_clear_area( m_wxwindow->window, |
1924 | rect->x, | |
1925 | rect->y, | |
1926 | rect->width, | |
d4c99d6f | 1927 | rect->height ); |
c801d85f | 1928 | else |
47d67540 | 1929 | Clear(); |
362c6693 | 1930 | } |
c801d85f KB |
1931 | if (!rect) |
1932 | { | |
1933 | if (m_wxwindow) | |
1934 | { | |
c801d85f KB |
1935 | int w = 0; |
1936 | int h = 0; | |
1937 | GetClientSize( &w, &h ); | |
47d67540 | 1938 | |
c801d85f | 1939 | GdkRectangle gdk_rect; |
11026f7b RR |
1940 | gdk_rect.x = 0; |
1941 | gdk_rect.y = 0; | |
c801d85f KB |
1942 | gdk_rect.width = w; |
1943 | gdk_rect.height = h; | |
1944 | gtk_widget_draw( m_wxwindow, &gdk_rect ); | |
362c6693 | 1945 | } |
c801d85f KB |
1946 | } |
1947 | else | |
1948 | { | |
1949 | GdkRectangle gdk_rect; | |
1950 | gdk_rect.x = rect->x; | |
1951 | gdk_rect.y = rect->y; | |
1952 | gdk_rect.width = rect->width; | |
1953 | gdk_rect.height = rect->height; | |
47d67540 | 1954 | |
c801d85f KB |
1955 | if (m_wxwindow) |
1956 | gtk_widget_draw( m_wxwindow, &gdk_rect ); | |
1957 | else | |
1958 | gtk_widget_draw( m_widget, &gdk_rect ); | |
362c6693 RR |
1959 | } |
1960 | } | |
c801d85f | 1961 | |
8429bec1 RR |
1962 | wxRegion wxWindow::GetUpdateRegion() const |
1963 | { | |
1964 | return m_updateRegion; | |
1965 | } | |
1966 | ||
1967 | bool wxWindow::IsExposed( int x, int y) const | |
c801d85f KB |
1968 | { |
1969 | return (m_updateRegion.Contains( x, y ) != wxOutRegion ); | |
362c6693 | 1970 | } |
c801d85f | 1971 | |
8429bec1 RR |
1972 | bool wxWindow::IsExposed( int x, int y, int w, int h ) const |
1973 | { | |
1974 | return (m_updateRegion.Contains( x, y, w, h ) != wxOutRegion ); | |
1975 | } | |
1976 | ||
1977 | bool wxWindow::IsExposed( const wxPoint& pt ) const | |
1978 | { | |
1979 | return (m_updateRegion.Contains( pt.x, pt.y ) != wxOutRegion ); | |
1980 | } | |
1981 | ||
1982 | bool wxWindow::IsExposed( const wxRect& rect ) const | |
c801d85f | 1983 | { |
8429bec1 | 1984 | return (m_updateRegion.Contains( rect.x, rect.y, rect.width, rect.height ) != wxOutRegion ); |
362c6693 | 1985 | } |
c801d85f | 1986 | |
68dda785 | 1987 | void wxWindow::Clear() |
c801d85f | 1988 | { |
3bc755fc | 1989 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 1990 | |
3bc755fc | 1991 | if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); |
362c6693 | 1992 | } |
c801d85f | 1993 | |
68dda785 | 1994 | wxColour wxWindow::GetBackgroundColour() const |
c801d85f | 1995 | { |
3bc755fc | 1996 | return m_backgroundColour; |
362c6693 | 1997 | } |
c801d85f KB |
1998 | |
1999 | void wxWindow::SetBackgroundColour( const wxColour &colour ) | |
2000 | { | |
3bc755fc | 2001 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 2002 | |
3bc755fc RR |
2003 | if (m_backgroundColour == colour) return; |
2004 | ||
2005 | if (!m_backgroundColour.Ok()) | |
2006 | if (wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) == colour) return; | |
fc54776e | 2007 | |
3bc755fc RR |
2008 | m_backgroundColour = colour; |
2009 | if (!m_backgroundColour.Ok()) return; | |
58614078 | 2010 | |
3bc755fc RR |
2011 | if (m_wxwindow) |
2012 | { | |
2013 | GdkWindow *window = m_wxwindow->window; | |
2014 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); | |
2015 | gdk_window_set_background( window, m_backgroundColour.GetColor() ); | |
2016 | gdk_window_clear( window ); | |
2017 | } | |
2018 | ||
2019 | ApplyWidgetStyle(); | |
362c6693 | 2020 | } |
c801d85f | 2021 | |
68dda785 | 2022 | wxColour wxWindow::GetForegroundColour() const |
6de97a3b | 2023 | { |
3bc755fc | 2024 | return m_foregroundColour; |
6de97a3b RR |
2025 | } |
2026 | ||
2027 | void wxWindow::SetForegroundColour( const wxColour &colour ) | |
2028 | { | |
3bc755fc | 2029 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
a81258be | 2030 | |
3bc755fc RR |
2031 | if (m_foregroundColour == colour) return; |
2032 | ||
2033 | m_foregroundColour = colour; | |
2034 | if (!m_foregroundColour.Ok()) return; | |
a81258be | 2035 | |
3bc755fc | 2036 | ApplyWidgetStyle(); |
58614078 RR |
2037 | } |
2038 | ||
2039 | GtkStyle *wxWindow::GetWidgetStyle() | |
2040 | { | |
2041 | if (m_widgetStyle) gtk_style_unref( m_widgetStyle ); | |
2042 | ||
2043 | m_widgetStyle = | |
2044 | gtk_style_copy( | |
2045 | gtk_widget_get_style( m_widget ) ); | |
2046 | ||
2047 | return m_widgetStyle; | |
2048 | } | |
2049 | ||
2050 | void wxWindow::SetWidgetStyle() | |
2051 | { | |
2052 | GtkStyle *style = GetWidgetStyle(); | |
2053 | ||
2054 | gdk_font_unref( style->font ); | |
2055 | style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); | |
2056 | ||
2057 | if (m_foregroundColour.Ok()) | |
a81258be | 2058 | { |
a81258be RR |
2059 | m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) ); |
2060 | style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); | |
2061 | style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); | |
2062 | style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); | |
2063 | } | |
58614078 RR |
2064 | |
2065 | if (m_backgroundColour.Ok()) | |
2066 | { | |
2067 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) ); | |
2068 | style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); | |
2069 | style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); | |
2070 | style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); | |
2071 | style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); | |
2072 | style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); | |
2073 | style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); | |
2074 | style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); | |
2075 | style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); | |
2076 | } | |
a81258be RR |
2077 | } |
2078 | ||
58614078 | 2079 | void wxWindow::ApplyWidgetStyle() |
a81258be | 2080 | { |
6de97a3b RR |
2081 | } |
2082 | ||
68dda785 | 2083 | bool wxWindow::Validate() |
c801d85f | 2084 | { |
fc54776e | 2085 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); |
47d67540 | 2086 | |
c801d85f KB |
2087 | wxNode *node = GetChildren()->First(); |
2088 | while (node) | |
2089 | { | |
2090 | wxWindow *child = (wxWindow *)node->Data(); | |
47d67540 | 2091 | if (child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this)) |
c801d85f KB |
2092 | { return FALSE; } |
2093 | node = node->Next(); | |
362c6693 | 2094 | } |
c801d85f | 2095 | return TRUE; |
362c6693 | 2096 | } |
c801d85f | 2097 | |
68dda785 | 2098 | bool wxWindow::TransferDataToWindow() |
c801d85f | 2099 | { |
fc54776e | 2100 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); |
47d67540 | 2101 | |
c801d85f KB |
2102 | wxNode *node = GetChildren()->First(); |
2103 | while (node) | |
2104 | { | |
2105 | wxWindow *child = (wxWindow *)node->Data(); | |
2106 | if (child->GetValidator() && /* child->GetValidator()->Ok() && */ | |
5e0aa05a | 2107 | !child->GetValidator()->TransferToWindow() ) |
c801d85f | 2108 | { |
1a5a8367 | 2109 | wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK|wxICON_EXCLAMATION ); |
c801d85f | 2110 | return FALSE; |
362c6693 | 2111 | } |
c801d85f | 2112 | node = node->Next(); |
362c6693 | 2113 | } |
c801d85f | 2114 | return TRUE; |
362c6693 | 2115 | } |
c801d85f | 2116 | |
68dda785 | 2117 | bool wxWindow::TransferDataFromWindow() |
c801d85f | 2118 | { |
e55ad60e | 2119 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2120 | |
c801d85f KB |
2121 | wxNode *node = GetChildren()->First(); |
2122 | while (node) | |
2123 | { | |
2124 | wxWindow *child = (wxWindow *)node->Data(); | |
2125 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() ) | |
2126 | { return FALSE; } | |
2127 | node = node->Next(); | |
2128 | } | |
2129 | return TRUE; | |
362c6693 | 2130 | } |
c801d85f | 2131 | |
bcf1fa6b RR |
2132 | void wxWindow::SetAcceleratorTable( const wxAcceleratorTable& accel ) |
2133 | { | |
2134 | m_acceleratorTable = accel; | |
2135 | } | |
2136 | ||
c801d85f KB |
2137 | void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) |
2138 | { | |
2139 | TransferDataToWindow(); | |
362c6693 | 2140 | } |
c801d85f | 2141 | |
68dda785 | 2142 | void wxWindow::InitDialog() |
c801d85f | 2143 | { |
c67d8618 | 2144 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 2145 | |
c801d85f KB |
2146 | wxInitDialogEvent event(GetId()); |
2147 | event.SetEventObject( this ); | |
2148 | GetEventHandler()->ProcessEvent(event); | |
362c6693 | 2149 | } |
c801d85f | 2150 | |
30dea054 RR |
2151 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
2152 | { | |
2153 | menu->SetInvokingWindow( win ); | |
2154 | wxNode *node = menu->m_items.First(); | |
2155 | while (node) | |
2156 | { | |
2157 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
2158 | if (menuitem->IsSubMenu()) | |
2159 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
2160 | node = node->Next(); | |
362c6693 RR |
2161 | } |
2162 | } | |
30dea054 RR |
2163 | |
2164 | bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) ) | |
2165 | { | |
c67d8618 | 2166 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" ); |
47d67540 | 2167 | |
c67d8618 RR |
2168 | wxCHECK_MSG( menu != NULL, FALSE, "invalid popup-menu" ); |
2169 | ||
30dea054 | 2170 | SetInvokingWindow( menu, this ); |
47d67540 VZ |
2171 | gtk_menu_popup( |
2172 | GTK_MENU(menu->m_menu), | |
2173 | (GtkWidget *)NULL, // parent menu shell | |
2174 | (GtkWidget *)NULL, // parent menu item | |
2175 | (GtkMenuPositionFunc)NULL, | |
2176 | NULL, // client data | |
2177 | 0, // button used to activate it | |
2178 | 0//gs_timeLastClick // the time of activation | |
2179 | ); | |
30dea054 RR |
2180 | return TRUE; |
2181 | } | |
2182 | ||
c801d85f KB |
2183 | void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) |
2184 | { | |
c67d8618 | 2185 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 2186 | |
30dea054 | 2187 | GtkWidget *dnd_widget = GetConnectWidget(); |
47d67540 | 2188 | |
33a5bc52 | 2189 | if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget ); |
47d67540 | 2190 | |
fd0eed64 RR |
2191 | if (m_dropTarget) delete m_dropTarget; |
2192 | m_dropTarget = dropTarget; | |
47d67540 | 2193 | |
33a5bc52 | 2194 | if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget ); |
362c6693 | 2195 | } |
c801d85f KB |
2196 | |
2197 | wxDropTarget *wxWindow::GetDropTarget() const | |
2198 | { | |
fd0eed64 | 2199 | return m_dropTarget; |
362c6693 | 2200 | } |
c801d85f | 2201 | |
68dda785 | 2202 | GtkWidget* wxWindow::GetConnectWidget() |
e3e65dac RR |
2203 | { |
2204 | GtkWidget *connect_widget = m_widget; | |
2205 | if (m_wxwindow) connect_widget = m_wxwindow; | |
47d67540 | 2206 | |
e3e65dac RR |
2207 | return connect_widget; |
2208 | } | |
47d67540 | 2209 | |
903f689b RR |
2210 | bool wxWindow::IsOwnGtkWindow( GdkWindow *window ) |
2211 | { | |
2212 | if (m_wxwindow) return (window == m_wxwindow->window); | |
2213 | return (window == m_widget->window); | |
2214 | } | |
2215 | ||
c801d85f KB |
2216 | void wxWindow::SetFont( const wxFont &font ) |
2217 | { | |
c67d8618 | 2218 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 2219 | |
3f659fd6 | 2220 | if (((wxFont*)&font)->Ok()) |
560b92f5 JS |
2221 | m_font = font; |
2222 | else | |
2223 | m_font = *wxSWISS_FONT; | |
58614078 RR |
2224 | |
2225 | ApplyWidgetStyle(); | |
362c6693 | 2226 | } |
c801d85f | 2227 | |
68dda785 | 2228 | wxFont *wxWindow::GetFont() |
c801d85f KB |
2229 | { |
2230 | return &m_font; | |
362c6693 | 2231 | } |
c801d85f KB |
2232 | |
2233 | void wxWindow::SetWindowStyleFlag( long flag ) | |
2234 | { | |
2235 | m_windowStyle = flag; | |
362c6693 | 2236 | } |
c801d85f | 2237 | |
68dda785 | 2238 | long wxWindow::GetWindowStyleFlag() const |
c801d85f KB |
2239 | { |
2240 | return m_windowStyle; | |
362c6693 | 2241 | } |
c801d85f | 2242 | |
68dda785 | 2243 | void wxWindow::CaptureMouse() |
c801d85f | 2244 | { |
c67d8618 | 2245 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 2246 | |
c67d8618 | 2247 | wxCHECK_RET( g_capturing == FALSE, "CaptureMouse called twice" ); |
47d67540 | 2248 | |
30dea054 | 2249 | GtkWidget *connect_widget = GetConnectWidget(); |
c801d85f KB |
2250 | gtk_grab_add( connect_widget ); |
2251 | gdk_pointer_grab ( connect_widget->window, FALSE, | |
2252 | (GdkEventMask) | |
47d67540 | 2253 | (GDK_BUTTON_PRESS_MASK | |
5e0aa05a | 2254 | GDK_BUTTON_RELEASE_MASK | |
47d67540 | 2255 | GDK_POINTER_MOTION_MASK), |
c67daf87 | 2256 | (GdkWindow *) NULL, (GdkCursor *) NULL, GDK_CURRENT_TIME ); |
6987a6c3 | 2257 | g_capturing = TRUE; |
362c6693 | 2258 | } |
c801d85f | 2259 | |
68dda785 | 2260 | void wxWindow::ReleaseMouse() |
c801d85f | 2261 | { |
c67d8618 | 2262 | wxCHECK_RET( m_widget != NULL, "invalid window" ); |
47d67540 | 2263 | |
c67d8618 | 2264 | wxCHECK_RET( g_capturing == TRUE, "ReleaseMouse called twice" ); |
47d67540 | 2265 | |
30dea054 | 2266 | GtkWidget *connect_widget = GetConnectWidget(); |
c801d85f KB |
2267 | gtk_grab_remove( connect_widget ); |
2268 | gdk_pointer_ungrab ( GDK_CURRENT_TIME ); | |
6987a6c3 | 2269 | g_capturing = FALSE; |
362c6693 | 2270 | } |
c801d85f KB |
2271 | |
2272 | void wxWindow::SetTitle( const wxString &WXUNUSED(title) ) | |
2273 | { | |
362c6693 | 2274 | } |
c801d85f | 2275 | |
68dda785 | 2276 | wxString wxWindow::GetTitle() const |
c801d85f KB |
2277 | { |
2278 | return (wxString&)m_windowName; | |
362c6693 | 2279 | } |
c801d85f | 2280 | |
68dda785 | 2281 | wxString wxWindow::GetLabel() const |
c801d85f KB |
2282 | { |
2283 | return GetTitle(); | |
362c6693 | 2284 | } |
c801d85f KB |
2285 | |
2286 | void wxWindow::SetName( const wxString &name ) | |
2287 | { | |
2288 | m_windowName = name; | |
362c6693 | 2289 | } |
c801d85f | 2290 | |
68dda785 | 2291 | wxString wxWindow::GetName() const |
c801d85f KB |
2292 | { |
2293 | return (wxString&)m_windowName; | |
362c6693 | 2294 | } |
c801d85f | 2295 | |
68dda785 | 2296 | bool wxWindow::IsShown() const |
c801d85f KB |
2297 | { |
2298 | return m_isShown; | |
362c6693 | 2299 | } |
c801d85f | 2300 | |
68dda785 | 2301 | bool wxWindow::IsRetained() |
c801d85f KB |
2302 | { |
2303 | return FALSE; | |
362c6693 | 2304 | } |
c801d85f | 2305 | |
debe6624 | 2306 | wxWindow *wxWindow::FindWindow( long id ) |
c801d85f KB |
2307 | { |
2308 | if (id == m_windowId) return this; | |
2309 | wxNode *node = m_children.First(); | |
2310 | while (node) | |
2311 | { | |
2312 | wxWindow *child = (wxWindow*)node->Data(); | |
2313 | wxWindow *res = child->FindWindow( id ); | |
2314 | if (res) return res; | |
2315 | node = node->Next(); | |
362c6693 | 2316 | } |
c67daf87 | 2317 | return (wxWindow *) NULL; |
362c6693 | 2318 | } |
c801d85f KB |
2319 | |
2320 | wxWindow *wxWindow::FindWindow( const wxString& name ) | |
2321 | { | |
2322 | if (name == m_windowName) return this; | |
2323 | wxNode *node = m_children.First(); | |
2324 | while (node) | |
2325 | { | |
2326 | wxWindow *child = (wxWindow*)node->Data(); | |
2327 | wxWindow *res = child->FindWindow( name ); | |
2328 | if (res) return res; | |
2329 | node = node->Next(); | |
362c6693 | 2330 | } |
c67daf87 | 2331 | return (wxWindow *) NULL; |
362c6693 | 2332 | } |
c801d85f | 2333 | |
debe6624 | 2334 | void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, |
cb43b372 | 2335 | int range, bool refresh ) |
c801d85f | 2336 | { |
e55ad60e | 2337 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2338 | |
e55ad60e | 2339 | wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); |
47d67540 | 2340 | |
c801d85f | 2341 | if (!m_wxwindow) return; |
33a5bc52 RR |
2342 | |
2343 | m_hasScrolling = TRUE; | |
c801d85f KB |
2344 | |
2345 | if (orient == wxHORIZONTAL) | |
2346 | { | |
2347 | float fpos = (float)pos; | |
c801d85f KB |
2348 | float frange = (float)range; |
2349 | float fthumb = (float)thumbVisible; | |
47d67540 | 2350 | |
cb43b372 RR |
2351 | if ((fabs(frange-m_hAdjust->upper) < 0.2) && |
2352 | (fabs(fthumb-m_hAdjust->page_size) < 0.2)) | |
2353 | { | |
2354 | SetScrollPos( orient, pos, refresh ); | |
c801d85f | 2355 | return; |
cb43b372 | 2356 | } |
47d67540 | 2357 | |
cb43b372 | 2358 | m_oldHorizontalPos = fpos; |
47d67540 | 2359 | |
c801d85f KB |
2360 | m_hAdjust->lower = 0.0; |
2361 | m_hAdjust->upper = frange; | |
2362 | m_hAdjust->value = fpos; | |
2363 | m_hAdjust->step_increment = 1.0; | |
84efdbf1 | 2364 | m_hAdjust->page_increment = (float)(wxMax(fthumb,0)); |
c801d85f KB |
2365 | m_hAdjust->page_size = fthumb; |
2366 | } | |
2367 | else | |
2368 | { | |
2369 | float fpos = (float)pos; | |
c801d85f KB |
2370 | float frange = (float)range; |
2371 | float fthumb = (float)thumbVisible; | |
47d67540 | 2372 | |
cb43b372 RR |
2373 | if ((fabs(frange-m_vAdjust->upper) < 0.2) && |
2374 | (fabs(fthumb-m_vAdjust->page_size) < 0.2)) | |
2375 | { | |
2376 | SetScrollPos( orient, pos, refresh ); | |
c801d85f | 2377 | return; |
cb43b372 | 2378 | } |
47d67540 | 2379 | |
cb43b372 | 2380 | m_oldVerticalPos = fpos; |
47d67540 | 2381 | |
c801d85f KB |
2382 | m_vAdjust->lower = 0.0; |
2383 | m_vAdjust->upper = frange; | |
2384 | m_vAdjust->value = fpos; | |
2385 | m_vAdjust->step_increment = 1.0; | |
84efdbf1 | 2386 | m_vAdjust->page_increment = (float)(wxMax(fthumb,0)); |
c801d85f | 2387 | m_vAdjust->page_size = fthumb; |
362c6693 | 2388 | } |
47d67540 | 2389 | |
c801d85f | 2390 | if (m_wxwindow->window) |
d4c99d6f | 2391 | { |
c801d85f KB |
2392 | if (orient == wxHORIZONTAL) |
2393 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); | |
d4c99d6f | 2394 | else |
c801d85f | 2395 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); |
47d67540 | 2396 | |
401ec7b6 | 2397 | gtk_widget_set_usize( m_widget, m_width, m_height ); |
362c6693 RR |
2398 | } |
2399 | } | |
c801d85f | 2400 | |
debe6624 | 2401 | void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) |
c801d85f | 2402 | { |
e55ad60e | 2403 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2404 | |
e55ad60e | 2405 | wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); |
47d67540 | 2406 | |
c801d85f | 2407 | if (!m_wxwindow) return; |
47d67540 | 2408 | |
c801d85f KB |
2409 | if (orient == wxHORIZONTAL) |
2410 | { | |
2411 | float fpos = (float)pos; | |
2412 | m_oldHorizontalPos = fpos; | |
2413 | ||
2414 | if (fabs(fpos-m_hAdjust->value) < 0.2) return; | |
2415 | m_hAdjust->value = fpos; | |
2416 | } | |
2417 | else | |
2418 | { | |
2419 | float fpos = (float)pos; | |
2420 | m_oldVerticalPos = fpos; | |
2421 | if (fabs(fpos-m_vAdjust->value) < 0.2) return; | |
2422 | m_vAdjust->value = fpos; | |
362c6693 | 2423 | } |
47d67540 | 2424 | |
cb43b372 RR |
2425 | if (!m_isScrolling) |
2426 | { | |
2427 | if (m_wxwindow->window) | |
47d67540 | 2428 | { |
cb43b372 RR |
2429 | if (orient == wxHORIZONTAL) |
2430 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); | |
47d67540 | 2431 | else |
cb43b372 RR |
2432 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); |
2433 | } | |
362c6693 RR |
2434 | } |
2435 | } | |
c801d85f | 2436 | |
debe6624 | 2437 | int wxWindow::GetScrollThumb( int orient ) const |
c801d85f | 2438 | { |
e55ad60e | 2439 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2440 | |
e55ad60e | 2441 | wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); |
47d67540 | 2442 | |
c801d85f KB |
2443 | if (!m_wxwindow) return 0; |
2444 | ||
2445 | if (orient == wxHORIZONTAL) | |
2446 | return (int)(m_hAdjust->page_size+0.5); | |
2447 | else | |
2448 | return (int)(m_vAdjust->page_size+0.5); | |
362c6693 | 2449 | } |
c801d85f | 2450 | |
debe6624 | 2451 | int wxWindow::GetScrollPos( int orient ) const |
c801d85f | 2452 | { |
e55ad60e | 2453 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2454 | |
e55ad60e | 2455 | wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); |
47d67540 | 2456 | |
c801d85f KB |
2457 | if (!m_wxwindow) return 0; |
2458 | ||
2459 | if (orient == wxHORIZONTAL) | |
2460 | return (int)(m_hAdjust->value+0.5); | |
2461 | else | |
2462 | return (int)(m_vAdjust->value+0.5); | |
362c6693 | 2463 | } |
c801d85f | 2464 | |
debe6624 | 2465 | int wxWindow::GetScrollRange( int orient ) const |
c801d85f | 2466 | { |
e55ad60e | 2467 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2468 | |
e55ad60e | 2469 | wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); |
47d67540 | 2470 | |
c801d85f KB |
2471 | if (!m_wxwindow) return 0; |
2472 | ||
2473 | if (orient == wxHORIZONTAL) | |
2474 | return (int)(m_hAdjust->upper+0.5); | |
2475 | else | |
2476 | return (int)(m_vAdjust->upper+0.5); | |
362c6693 | 2477 | } |
c801d85f | 2478 | |
debe6624 | 2479 | void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) |
c801d85f | 2480 | { |
e55ad60e | 2481 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
47d67540 | 2482 | |
e55ad60e | 2483 | wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); |
47d67540 | 2484 | |
e55ad60e | 2485 | if (!m_wxwindow) return; |
c801d85f KB |
2486 | |
2487 | int cw = 0; | |
2488 | int ch = 0; | |
2489 | GetClientSize( &cw, &ch ); | |
47d67540 | 2490 | |
c801d85f KB |
2491 | int w = cw - abs(dx); |
2492 | int h = ch - abs(dy); | |
2493 | if ((h < 0) || (w < 0)) | |
2494 | { | |
2495 | Refresh(); | |
2496 | return; | |
362c6693 | 2497 | } |
c801d85f KB |
2498 | int s_x = 0; |
2499 | int s_y = 0; | |
2500 | if (dx < 0) s_x = -dx; | |
2501 | if (dy < 0) s_y = -dy; | |
2502 | int d_x = 0; | |
2503 | int d_y = 0; | |
2504 | if (dx > 0) d_x = dx; | |
2505 | if (dy > 0) d_y = dy; | |
32e9da8b RR |
2506 | |
2507 | if (!m_scrollGC) | |
2508 | { | |
2509 | m_scrollGC = gdk_gc_new( m_wxwindow->window ); | |
2510 | gdk_gc_set_exposures( m_scrollGC, TRUE ); | |
2511 | } | |
2512 | ||
2513 | gdk_window_copy_area( m_wxwindow->window, m_scrollGC, d_x, d_y, | |
c801d85f | 2514 | m_wxwindow->window, s_x, s_y, w, h ); |
47d67540 | 2515 | |
c801d85f KB |
2516 | wxRect rect; |
2517 | if (dx < 0) rect.x = cw+dx; else rect.x = 0; | |
2518 | if (dy < 0) rect.y = ch+dy; else rect.y = 0; | |
2519 | if (dy != 0) rect.width = cw; else rect.width = abs(dx); | |
2520 | if (dx != 0) rect.height = ch; else rect.height = abs(dy); | |
47d67540 | 2521 | |
c801d85f | 2522 | Refresh( TRUE, &rect ); |
362c6693 | 2523 | } |
c801d85f KB |
2524 | |
2525 | //------------------------------------------------------------------------------------- | |
2526 | // Layout | |
2527 | //------------------------------------------------------------------------------------- | |
2528 | ||
68dda785 | 2529 | wxLayoutConstraints *wxWindow::GetConstraints() const |
c801d85f KB |
2530 | { |
2531 | return m_constraints; | |
362c6693 | 2532 | } |
c801d85f KB |
2533 | |
2534 | void wxWindow::SetConstraints( wxLayoutConstraints *constraints ) | |
2535 | { | |
2536 | if (m_constraints) | |
2537 | { | |
2538 | UnsetConstraints(m_constraints); | |
2539 | delete m_constraints; | |
2540 | } | |
2541 | m_constraints = constraints; | |
2542 | if (m_constraints) | |
2543 | { | |
2544 | // Make sure other windows know they're part of a 'meaningful relationship' | |
2545 | if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this)) | |
2546 | m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2547 | if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this)) | |
2548 | m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2549 | if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this)) | |
2550 | m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2551 | if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this)) | |
2552 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2553 | if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this)) | |
2554 | m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2555 | if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this)) | |
2556 | m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2557 | if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this)) | |
2558 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2559 | if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) | |
2560 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
2561 | } | |
2562 | ; | |
2563 | } | |
2564 | ; | |
2565 | ||
debe6624 | 2566 | void wxWindow::SetAutoLayout( bool autoLayout ) |
c801d85f KB |
2567 | { |
2568 | m_autoLayout = autoLayout; | |
362c6693 | 2569 | } |
c801d85f | 2570 | |
68dda785 | 2571 | bool wxWindow::GetAutoLayout() const |
c801d85f KB |
2572 | { |
2573 | return m_autoLayout; | |
362c6693 | 2574 | } |
c801d85f | 2575 | |
68dda785 | 2576 | wxSizer *wxWindow::GetSizer() const |
c801d85f KB |
2577 | { |
2578 | return m_windowSizer; | |
362c6693 | 2579 | } |
c801d85f KB |
2580 | |
2581 | void wxWindow::SetSizerParent( wxWindow *win ) | |
2582 | { | |
2583 | m_sizerParent = win; | |
362c6693 | 2584 | } |
c801d85f | 2585 | |
68dda785 | 2586 | wxWindow *wxWindow::GetSizerParent() const |
c801d85f KB |
2587 | { |
2588 | return m_sizerParent; | |
362c6693 | 2589 | } |
c801d85f KB |
2590 | |
2591 | // This removes any dangling pointers to this window | |
2592 | // in other windows' constraintsInvolvedIn lists. | |
2593 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) | |
2594 | { | |
2595 | if (c) | |
2596 | { | |
2597 | if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
2598 | c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2599 | if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
2600 | c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2601 | if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this)) | |
2602 | c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2603 | if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this)) | |
2604 | c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2605 | if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this)) | |
2606 | c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2607 | if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this)) | |
2608 | c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2609 | if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this)) | |
2610 | c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2611 | if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this)) | |
2612 | c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
2613 | } | |
2614 | } | |
2615 | ||
2616 | // Back-pointer to other windows we're involved with, so if we delete | |
2617 | // this window, we must delete any constraints we're involved with. | |
2618 | void wxWindow::AddConstraintReference(wxWindow *otherWin) | |
2619 | { | |
2620 | if (!m_constraintsInvolvedIn) | |
2621 | m_constraintsInvolvedIn = new wxList; | |
2622 | if (!m_constraintsInvolvedIn->Member(otherWin)) | |
2623 | m_constraintsInvolvedIn->Append(otherWin); | |
2624 | } | |
2625 | ||
2626 | // REMOVE back-pointer to other windows we're involved with. | |
2627 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
2628 | { | |
2629 | if (m_constraintsInvolvedIn) | |
2630 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
2631 | } | |
2632 | ||
2633 | // Reset any constraints that mention this window | |
68dda785 | 2634 | void wxWindow::DeleteRelatedConstraints() |
c801d85f KB |
2635 | { |
2636 | if (m_constraintsInvolvedIn) | |
2637 | { | |
2638 | wxNode *node = m_constraintsInvolvedIn->First(); | |
2639 | while (node) | |
2640 | { | |
2641 | wxWindow *win = (wxWindow *)node->Data(); | |
2642 | wxNode *next = node->Next(); | |
2643 | wxLayoutConstraints *constr = win->GetConstraints(); | |
2644 | ||
2645 | // Reset any constraints involving this window | |
2646 | if (constr) | |
2647 | { | |
2648 | constr->left.ResetIfWin((wxWindow *)this); | |
2649 | constr->top.ResetIfWin((wxWindow *)this); | |
2650 | constr->right.ResetIfWin((wxWindow *)this); | |
2651 | constr->bottom.ResetIfWin((wxWindow *)this); | |
2652 | constr->width.ResetIfWin((wxWindow *)this); | |
2653 | constr->height.ResetIfWin((wxWindow *)this); | |
2654 | constr->centreX.ResetIfWin((wxWindow *)this); | |
2655 | constr->centreY.ResetIfWin((wxWindow *)this); | |
2656 | } | |
2657 | delete node; | |
2658 | node = next; | |
2659 | } | |
2660 | delete m_constraintsInvolvedIn; | |
c67daf87 | 2661 | m_constraintsInvolvedIn = (wxList *) NULL; |
c801d85f KB |
2662 | } |
2663 | } | |
2664 | ||
2665 | void wxWindow::SetSizer(wxSizer *sizer) | |
2666 | { | |
2667 | m_windowSizer = sizer; | |
2668 | if (sizer) | |
2669 | sizer->SetSizerParent((wxWindow *)this); | |
2670 | } | |
2671 | ||
2672 | /* | |
2673 | * New version | |
2674 | */ | |
2675 | ||
68dda785 | 2676 | bool wxWindow::Layout() |
c801d85f KB |
2677 | { |
2678 | if (GetConstraints()) | |
2679 | { | |
2680 | int w, h; | |
2681 | GetClientSize(&w, &h); | |
2682 | GetConstraints()->width.SetValue(w); | |
2683 | GetConstraints()->height.SetValue(h); | |
2684 | } | |
47d67540 | 2685 | |
c801d85f KB |
2686 | // If top level (one sizer), evaluate the sizer's constraints. |
2687 | if (GetSizer()) | |
2688 | { | |
2689 | int noChanges; | |
2690 | GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated | |
2691 | GetSizer()->LayoutPhase1(&noChanges); | |
2692 | GetSizer()->LayoutPhase2(&noChanges); | |
2693 | GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes | |
2694 | return TRUE; | |
2695 | } | |
2696 | else | |
2697 | { | |
2698 | // Otherwise, evaluate child constraints | |
2699 | ResetConstraints(); // Mark all constraints as unevaluated | |
2700 | DoPhase(1); // Just one phase need if no sizers involved | |
2701 | DoPhase(2); | |
2702 | SetConstraintSizes(); // Recursively set the real window sizes | |
2703 | } | |
2704 | return TRUE; | |
2705 | } | |
2706 | ||
2707 | ||
2708 | // Do a phase of evaluating constraints: | |
2709 | // the default behaviour. wxSizers may do a similar | |
2710 | // thing, but also impose their own 'constraints' | |
2711 | // and order the evaluation differently. | |
2712 | bool wxWindow::LayoutPhase1(int *noChanges) | |
2713 | { | |
2714 | wxLayoutConstraints *constr = GetConstraints(); | |
2715 | if (constr) | |
2716 | { | |
2717 | return constr->SatisfyConstraints((wxWindow *)this, noChanges); | |
2718 | } | |
2719 | else | |
2720 | return TRUE; | |
2721 | } | |
2722 | ||
2723 | bool wxWindow::LayoutPhase2(int *noChanges) | |
2724 | { | |
2725 | *noChanges = 0; | |
47d67540 | 2726 | |
c801d85f KB |
2727 | // Layout children |
2728 | DoPhase(1); | |
2729 | DoPhase(2); | |
2730 | return TRUE; | |
2731 | } | |
2732 | ||
2733 | // Do a phase of evaluating child constraints | |
debe6624 | 2734 | bool wxWindow::DoPhase(int phase) |
c801d85f KB |
2735 | { |
2736 | int noIterations = 0; | |
2737 | int maxIterations = 500; | |
2738 | int noChanges = 1; | |
2739 | int noFailures = 0; | |
2740 | wxList succeeded; | |
2741 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
2742 | { | |
2743 | noChanges = 0; | |
2744 | noFailures = 0; | |
2745 | wxNode *node = GetChildren()->First(); | |
2746 | while (node) | |
2747 | { | |
2748 | wxWindow *child = (wxWindow *)node->Data(); | |
2749 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog))) | |
2750 | { | |
2751 | wxLayoutConstraints *constr = child->GetConstraints(); | |
2752 | if (constr) | |
2753 | { | |
2754 | if (succeeded.Member(child)) | |
2755 | { | |
2756 | } | |
2757 | else | |
2758 | { | |
2759 | int tempNoChanges = 0; | |
2760 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
2761 | noChanges += tempNoChanges; | |
2762 | if (success) | |
2763 | { | |
2764 | succeeded.Append(child); | |
2765 | } | |
2766 | } | |
2767 | } | |
2768 | } | |
2769 | node = node->Next(); | |
2770 | } | |
2771 | noIterations ++; | |
2772 | } | |
2773 | return TRUE; | |
2774 | } | |
2775 | ||
68dda785 | 2776 | void wxWindow::ResetConstraints() |
c801d85f KB |
2777 | { |
2778 | wxLayoutConstraints *constr = GetConstraints(); | |
2779 | if (constr) | |
2780 | { | |
2781 | constr->left.SetDone(FALSE); | |
2782 | constr->top.SetDone(FALSE); | |
2783 | constr->right.SetDone(FALSE); | |
2784 | constr->bottom.SetDone(FALSE); | |
2785 | constr->width.SetDone(FALSE); | |
2786 | constr->height.SetDone(FALSE); | |
2787 | constr->centreX.SetDone(FALSE); | |
2788 | constr->centreY.SetDone(FALSE); | |
2789 | } | |
2790 | wxNode *node = GetChildren()->First(); | |
2791 | while (node) | |
2792 | { | |
2793 | wxWindow *win = (wxWindow *)node->Data(); | |
2794 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
2795 | win->ResetConstraints(); | |
2796 | node = node->Next(); | |
2797 | } | |
2798 | } | |
2799 | ||
2800 | // Need to distinguish between setting the 'fake' size for | |
2801 | // windows and sizers, and setting the real values. | |
debe6624 | 2802 | void wxWindow::SetConstraintSizes(bool recurse) |
c801d85f KB |
2803 | { |
2804 | wxLayoutConstraints *constr = GetConstraints(); | |
2805 | if (constr && constr->left.GetDone() && constr->right.GetDone() && | |
2806 | constr->width.GetDone() && constr->height.GetDone()) | |
2807 | { | |
2808 | int x = constr->left.GetValue(); | |
2809 | int y = constr->top.GetValue(); | |
2810 | int w = constr->width.GetValue(); | |
2811 | int h = constr->height.GetValue(); | |
2812 | ||
2813 | // If we don't want to resize this window, just move it... | |
2814 | if ((constr->width.GetRelationship() != wxAsIs) || | |
2815 | (constr->height.GetRelationship() != wxAsIs)) | |
2816 | { | |
2817 | // Calls Layout() recursively. AAAGH. How can we stop that. | |
2818 | // Simply take Layout() out of non-top level OnSizes. | |
2819 | SizerSetSize(x, y, w, h); | |
2820 | } | |
2821 | else | |
2822 | { | |
2823 | SizerMove(x, y); | |
2824 | } | |
2825 | } | |
2826 | else if (constr) | |
2827 | { | |
2828 | char *windowClass = this->GetClassInfo()->GetClassName(); | |
2829 | ||
2830 | wxString winName; | |
5e0aa05a | 2831 | if (GetName() == "") |
1a5a8367 | 2832 | winName = _("unnamed"); |
5e0aa05a VZ |
2833 | else |
2834 | winName = GetName(); | |
1a5a8367 | 2835 | wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass, (const char *)winName); |
c801d85f | 2836 | if (!constr->left.GetDone()) |
1a5a8367 | 2837 | wxDebugMsg(_(" unsatisfied 'left' constraint.\n")); |
c801d85f | 2838 | if (!constr->right.GetDone()) |
1a5a8367 | 2839 | wxDebugMsg(_(" unsatisfied 'right' constraint.\n")); |
c801d85f | 2840 | if (!constr->width.GetDone()) |
1a5a8367 | 2841 | wxDebugMsg(_(" unsatisfied 'width' constraint.\n")); |
c801d85f | 2842 | if (!constr->height.GetDone()) |
1a5a8367 DP |
2843 | wxDebugMsg(_(" unsatisfied 'height' constraint.\n")); |
2844 | wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n")); | |
c801d85f KB |
2845 | } |
2846 | ||
2847 | if (recurse) | |
2848 | { | |
2849 | wxNode *node = GetChildren()->First(); | |
2850 | while (node) | |
2851 | { | |
2852 | wxWindow *win = (wxWindow *)node->Data(); | |
2853 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
2854 | win->SetConstraintSizes(); | |
2855 | node = node->Next(); | |
2856 | } | |
2857 | } | |
2858 | } | |
2859 | ||
2860 | // This assumes that all sizers are 'on' the same | |
2861 | // window, i.e. the parent of this window. | |
2862 | void wxWindow::TransformSizerToActual(int *x, int *y) const | |
2863 | { | |
2864 | if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || | |
5e0aa05a | 2865 | m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) |
c801d85f | 2866 | return; |
47d67540 | 2867 | |
c801d85f KB |
2868 | int xp, yp; |
2869 | m_sizerParent->GetPosition(&xp, &yp); | |
2870 | m_sizerParent->TransformSizerToActual(&xp, &yp); | |
2871 | *x += xp; | |
2872 | *y += yp; | |
2873 | } | |
2874 | ||
debe6624 | 2875 | void wxWindow::SizerSetSize(int x, int y, int w, int h) |
c801d85f | 2876 | { |
5e0aa05a VZ |
2877 | int xx = x; |
2878 | int yy = y; | |
c801d85f KB |
2879 | TransformSizerToActual(&xx, &yy); |
2880 | SetSize(xx, yy, w, h); | |
2881 | } | |
2882 | ||
debe6624 | 2883 | void wxWindow::SizerMove(int x, int y) |
c801d85f | 2884 | { |
5e0aa05a VZ |
2885 | int xx = x; |
2886 | int yy = y; | |
c801d85f KB |
2887 | TransformSizerToActual(&xx, &yy); |
2888 | Move(xx, yy); | |
2889 | } | |
2890 | ||
2891 | // Only set the size/position of the constraint (if any) | |
debe6624 | 2892 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) |
c801d85f KB |
2893 | { |
2894 | wxLayoutConstraints *constr = GetConstraints(); | |
2895 | if (constr) | |
2896 | { | |
2897 | if (x != -1) | |
2898 | { | |
2899 | constr->left.SetValue(x); | |
2900 | constr->left.SetDone(TRUE); | |
2901 | } | |
2902 | if (y != -1) | |
2903 | { | |
2904 | constr->top.SetValue(y); | |
2905 | constr->top.SetDone(TRUE); | |
2906 | } | |
2907 | if (w != -1) | |
2908 | { | |
2909 | constr->width.SetValue(w); | |
2910 | constr->width.SetDone(TRUE); | |
2911 | } | |
2912 | if (h != -1) | |
2913 | { | |
2914 | constr->height.SetValue(h); | |
2915 | constr->height.SetDone(TRUE); | |
2916 | } | |
2917 | } | |
2918 | } | |
2919 | ||
debe6624 | 2920 | void wxWindow::MoveConstraint(int x, int y) |
c801d85f KB |
2921 | { |
2922 | wxLayoutConstraints *constr = GetConstraints(); | |
2923 | if (constr) | |
2924 | { | |
2925 | if (x != -1) | |
2926 | { | |
2927 | constr->left.SetValue(x); | |
2928 | constr->left.SetDone(TRUE); | |
2929 | } | |
2930 | if (y != -1) | |
2931 | { | |
2932 | constr->top.SetValue(y); | |
2933 | constr->top.SetDone(TRUE); | |
2934 | } | |
2935 | } | |
2936 | } | |
2937 | ||
2938 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
2939 | { | |
2940 | wxLayoutConstraints *constr = GetConstraints(); | |
2941 | if (constr) | |
2942 | { | |
2943 | *w = constr->width.GetValue(); | |
2944 | *h = constr->height.GetValue(); | |
2945 | } | |
2946 | else | |
2947 | GetSize(w, h); | |
2948 | } | |
2949 | ||
2950 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
2951 | { | |
2952 | wxLayoutConstraints *constr = GetConstraints(); | |
2953 | if (constr) | |
2954 | { | |
2955 | *w = constr->width.GetValue(); | |
2956 | *h = constr->height.GetValue(); | |
2957 | } | |
2958 | else | |
2959 | GetClientSize(w, h); | |
2960 | } | |
2961 | ||
2962 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
2963 | { | |
2964 | wxLayoutConstraints *constr = GetConstraints(); | |
2965 | if (constr) | |
2966 | { | |
2967 | *x = constr->left.GetValue(); | |
2968 | *y = constr->top.GetValue(); | |
2969 | } | |
2970 | else | |
2971 | GetPosition(x, y); | |
2972 | } | |
2973 | ||
7fd1d163 | 2974 | bool wxWindow::AcceptsFocus() const |
0abbe297 VZ |
2975 | { |
2976 | return IsEnabled() && IsShown(); | |
2977 | } | |
5e0aa05a | 2978 | |
e3e65dac | 2979 | void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) ) |
5e0aa05a VZ |
2980 | { |
2981 | UpdateWindowUI(); | |
2982 | } |