]>
Commit | Line | Data |
---|---|---|
b2b3ccc5 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: minifram.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
b2b3ccc5 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
b2b3ccc5 | 13 | #include "wx/minifram.h" |
dcf924a3 RR |
14 | |
15 | #if wxUSE_MINIFRAME | |
16 | ||
b2b3ccc5 RR |
17 | #include "wx/dcscreen.h" |
18 | ||
83624f79 RR |
19 | #include "gtk/gtk.h" |
20 | #include "wx/gtk/win_gtk.h" | |
fab591c5 | 21 | #include "wx/gtk/private.h" |
83624f79 | 22 | |
5e7e9e1b RR |
23 | #include <gdk/gdk.h> |
24 | #include <gdk/gdkprivate.h> | |
25 | #include <gdk/gdkx.h> | |
32a95f9f | 26 | |
acfd422a RR |
27 | //----------------------------------------------------------------------------- |
28 | // idle system | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | extern void wxapp_install_idle_handler(); | |
32 | extern bool g_isIdle; | |
33 | ||
32a95f9f RR |
34 | //----------------------------------------------------------------------------- |
35 | // data | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
8480b297 RR |
38 | extern bool g_blockEventsOnDrag; |
39 | extern bool g_blockEventsOnScroll; | |
c2fa61e8 | 40 | extern GtkWidget *wxGetRootWindow(); |
32a95f9f | 41 | |
b2b3ccc5 | 42 | //----------------------------------------------------------------------------- |
32a95f9f RR |
43 | // local functions |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | /* draw XOR rectangle when moving mine frame around */ | |
47 | ||
48 | static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) | |
49 | { | |
c2fa61e8 | 50 | int org_x = 0; |
32a95f9f RR |
51 | int org_y = 0; |
52 | gdk_window_get_origin( widget->window, &org_x, &org_y ); | |
53 | x += org_x; | |
54 | y += org_y; | |
55 | ||
56 | GdkGC *gc = gdk_gc_new( GDK_ROOT_PARENT() ); | |
57 | gdk_gc_set_subwindow( gc, GDK_INCLUDE_INFERIORS ); | |
58 | gdk_gc_set_function( gc, GDK_INVERT ); | |
c2fa61e8 | 59 | |
32a95f9f RR |
60 | gdk_draw_rectangle( GDK_ROOT_PARENT(), gc, FALSE, x, y, w, h ); |
61 | gdk_gc_unref( gc ); | |
62 | } | |
63 | ||
64 | //----------------------------------------------------------------------------- | |
65 | // "expose_event" of m_mainWidget | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
865bb325 | 68 | extern "C" { |
32a95f9f RR |
69 | static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxFrame *win ) |
70 | { | |
acfd422a RR |
71 | if (g_isIdle) wxapp_install_idle_handler(); |
72 | ||
a2053b27 | 73 | if (!win->m_hasVMT) return; |
32a95f9f | 74 | if (gdk_event->count > 0) return; |
c2fa61e8 | 75 | |
da048e3d | 76 | GtkPizza *pizza = GTK_PIZZA(widget); |
c2fa61e8 RD |
77 | |
78 | gtk_draw_shadow( widget->style, | |
da048e3d | 79 | pizza->bin_window, |
f03fc89f VZ |
80 | GTK_STATE_NORMAL, |
81 | GTK_SHADOW_OUT, | |
82 | 0, 0, | |
a2053b27 | 83 | win->m_width, win->m_height ); |
b9a535f5 | 84 | |
ba718523 | 85 | if (!win->GetTitle().IsEmpty() && |
c2fa61e8 RD |
86 | ((win->GetWindowStyle() & wxCAPTION) || |
87 | (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || | |
f03fc89f | 88 | (win->GetWindowStyle() & wxTINY_CAPTION_VERT))) |
b9a535f5 | 89 | { |
ba718523 RR |
90 | wxClientDC dc(win); |
91 | dc.SetFont( *wxSMALL_FONT ); | |
92 | int height = dc.GetCharHeight(); | |
93 | ||
da048e3d | 94 | GdkGC *gc = gdk_gc_new( pizza->bin_window ); |
b9a535f5 | 95 | gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] ); |
c2fa61e8 RD |
96 | gdk_draw_rectangle( pizza->bin_window, gc, TRUE, |
97 | 3, | |
98 | 3, | |
5d5b3a40 | 99 | win->m_width - 7, |
ba718523 | 100 | height+1 ); |
b9a535f5 | 101 | gdk_gc_unref( gc ); |
ba718523 RR |
102 | |
103 | // Hack alert | |
104 | dc.m_window = pizza->bin_window; | |
105 | dc.SetTextForeground( *wxWHITE ); | |
106 | dc.DrawText( win->GetTitle(), 6, 3 ); | |
b9a535f5 | 107 | } |
32a95f9f | 108 | } |
865bb325 | 109 | } |
32a95f9f RR |
110 | |
111 | //----------------------------------------------------------------------------- | |
112 | // "draw" of m_mainWidget | |
113 | //----------------------------------------------------------------------------- | |
114 | ||
ba718523 | 115 | #ifndef __WXGTK20__ |
865bb325 | 116 | extern "C" { |
32a95f9f RR |
117 | static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win ) |
118 | { | |
acfd422a RR |
119 | if (g_isIdle) wxapp_install_idle_handler(); |
120 | ||
a2053b27 | 121 | if (!win->m_hasVMT) return; |
c2fa61e8 | 122 | |
da048e3d | 123 | GtkPizza *pizza = GTK_PIZZA(widget); |
c2fa61e8 RD |
124 | |
125 | gtk_draw_shadow( widget->style, | |
da048e3d | 126 | pizza->bin_window, |
f03fc89f VZ |
127 | GTK_STATE_NORMAL, |
128 | GTK_SHADOW_OUT, | |
129 | 0, 0, | |
a2053b27 | 130 | win->m_width, win->m_height ); |
c2fa61e8 | 131 | |
b9a535f5 | 132 | if (!win->m_title.IsEmpty() && |
c2fa61e8 RD |
133 | ((win->GetWindowStyle() & wxCAPTION) || |
134 | (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || | |
f03fc89f | 135 | (win->GetWindowStyle() & wxTINY_CAPTION_VERT))) |
b9a535f5 | 136 | { |
ba718523 RR |
137 | wxClientDC dc(win); |
138 | dc.SetFont( *wxSMALL_FONT ); | |
139 | int height = dc.GetCharHeight(); | |
140 | ||
da048e3d | 141 | GdkGC *gc = gdk_gc_new( pizza->bin_window ); |
b9a535f5 | 142 | gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] ); |
c2fa61e8 RD |
143 | gdk_draw_rectangle( pizza->bin_window, gc, TRUE, |
144 | 3, | |
5d5b3a40 RR |
145 | 3, |
146 | win->m_width - 7, | |
ba718523 | 147 | height+1 ); |
b9a535f5 | 148 | gdk_gc_unref( gc ); |
ba718523 RR |
149 | |
150 | // Hack alert | |
151 | dc.m_window = pizza->bin_window; | |
152 | dc.SetTextForeground( *wxWHITE ); | |
153 | dc.DrawText( win->GetTitle(), 6, 3 ); | |
b9a535f5 | 154 | } |
32a95f9f | 155 | } |
865bb325 | 156 | } |
ba718523 | 157 | #endif |
32a95f9f RR |
158 | |
159 | //----------------------------------------------------------------------------- | |
160 | // "button_press_event" of m_mainWidget | |
161 | //----------------------------------------------------------------------------- | |
162 | ||
865bb325 | 163 | extern "C" { |
32a95f9f RR |
164 | static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) |
165 | { | |
acfd422a RR |
166 | if (g_isIdle) wxapp_install_idle_handler(); |
167 | ||
a2053b27 | 168 | if (!win->m_hasVMT) return FALSE; |
32a95f9f RR |
169 | if (g_blockEventsOnDrag) return TRUE; |
170 | if (g_blockEventsOnScroll) return TRUE; | |
171 | ||
172 | if (win->m_isDragging) return TRUE; | |
173 | ||
2c990ec0 RR |
174 | GtkPizza *pizza = GTK_PIZZA(widget); |
175 | if (gdk_event->window != pizza->bin_window) return TRUE; | |
ba718523 RR |
176 | |
177 | wxClientDC dc(win); | |
178 | dc.SetFont( *wxSMALL_FONT ); | |
179 | int height = dc.GetCharHeight() + 1; | |
2c990ec0 | 180 | |
2c990ec0 RR |
181 | if (gdk_event->y > height) return TRUE; |
182 | ||
4dcaf11a | 183 | gdk_window_raise( win->m_widget->window ); |
c2fa61e8 | 184 | |
32a95f9f RR |
185 | gdk_pointer_grab( widget->window, FALSE, |
186 | (GdkEventMask) | |
187 | (GDK_BUTTON_PRESS_MASK | | |
188 | GDK_BUTTON_RELEASE_MASK | | |
f03fc89f | 189 | GDK_POINTER_MOTION_MASK | |
32a95f9f | 190 | GDK_POINTER_MOTION_HINT_MASK | |
f03fc89f | 191 | GDK_BUTTON_MOTION_MASK | |
32a95f9f RR |
192 | GDK_BUTTON1_MOTION_MASK), |
193 | (GdkWindow *) NULL, | |
194 | (GdkCursor *) NULL, | |
7941ba11 | 195 | (unsigned int) GDK_CURRENT_TIME ); |
c2fa61e8 | 196 | |
32a95f9f RR |
197 | win->m_diffX = (int)gdk_event->x; |
198 | win->m_diffY = (int)gdk_event->y; | |
a2053b27 | 199 | DrawFrame( widget, 0, 0, win->m_width, win->m_height ); |
32a95f9f RR |
200 | win->m_oldX = 0; |
201 | win->m_oldY = 0; | |
c2fa61e8 | 202 | |
32a95f9f RR |
203 | win->m_isDragging = TRUE; |
204 | ||
205 | return TRUE; | |
206 | } | |
865bb325 | 207 | } |
32a95f9f RR |
208 | |
209 | //----------------------------------------------------------------------------- | |
210 | // "button_release_event" of m_mainWidget | |
211 | //----------------------------------------------------------------------------- | |
212 | ||
865bb325 | 213 | extern "C" { |
32a95f9f RR |
214 | static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win ) |
215 | { | |
acfd422a RR |
216 | if (g_isIdle) wxapp_install_idle_handler(); |
217 | ||
a2053b27 | 218 | if (!win->m_hasVMT) return FALSE; |
32a95f9f RR |
219 | if (g_blockEventsOnDrag) return TRUE; |
220 | if (g_blockEventsOnScroll) return TRUE; | |
221 | ||
222 | if (!win->m_isDragging) return TRUE; | |
c2fa61e8 | 223 | |
32a95f9f | 224 | win->m_isDragging = FALSE; |
c2fa61e8 | 225 | |
32a95f9f RR |
226 | int x = (int)gdk_event->x; |
227 | int y = (int)gdk_event->y; | |
c2fa61e8 | 228 | |
a2053b27 | 229 | DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); |
13111b2a | 230 | gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); |
c2fa61e8 | 231 | int org_x = 0; |
32a95f9f RR |
232 | int org_y = 0; |
233 | gdk_window_get_origin( widget->window, &org_x, &org_y ); | |
234 | x += org_x - win->m_diffX; | |
235 | y += org_y - win->m_diffY; | |
121a3581 RR |
236 | win->m_x = x; |
237 | win->m_y = y; | |
a2053b27 | 238 | gtk_widget_set_uposition( win->m_widget, x, y ); |
32a95f9f RR |
239 | |
240 | return TRUE; | |
241 | } | |
865bb325 | 242 | } |
32a95f9f RR |
243 | |
244 | //----------------------------------------------------------------------------- | |
245 | // "motion_notify_event" of m_mainWidget | |
246 | //----------------------------------------------------------------------------- | |
247 | ||
865bb325 | 248 | extern "C" { |
32a95f9f RR |
249 | static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win ) |
250 | { | |
acfd422a RR |
251 | if (g_isIdle) wxapp_install_idle_handler(); |
252 | ||
a2053b27 | 253 | if (!win->m_hasVMT) return FALSE; |
32a95f9f RR |
254 | if (g_blockEventsOnDrag) return TRUE; |
255 | if (g_blockEventsOnScroll) return TRUE; | |
256 | ||
257 | if (!win->m_isDragging) return TRUE; | |
c2fa61e8 | 258 | |
32a95f9f RR |
259 | if (gdk_event->is_hint) |
260 | { | |
261 | int x = 0; | |
262 | int y = 0; | |
263 | GdkModifierType state; | |
264 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
265 | gdk_event->x = x; | |
266 | gdk_event->y = y; | |
267 | gdk_event->state = state; | |
268 | } | |
269 | ||
a2053b27 | 270 | DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); |
32a95f9f RR |
271 | win->m_oldX = (int)gdk_event->x - win->m_diffX; |
272 | win->m_oldY = (int)gdk_event->y - win->m_diffY; | |
a2053b27 | 273 | DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); |
c2fa61e8 | 274 | |
32a95f9f RR |
275 | return TRUE; |
276 | } | |
865bb325 | 277 | } |
32a95f9f RR |
278 | |
279 | //----------------------------------------------------------------------------- | |
280 | // "clicked" of X system button | |
b2b3ccc5 RR |
281 | //----------------------------------------------------------------------------- |
282 | ||
865bb325 | 283 | extern "C" { |
b2b3ccc5 RR |
284 | static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf ) |
285 | { | |
acfd422a RR |
286 | if (g_isIdle) wxapp_install_idle_handler(); |
287 | ||
b2b3ccc5 RR |
288 | mf->Close(); |
289 | } | |
865bb325 | 290 | } |
b2b3ccc5 RR |
291 | |
292 | //----------------------------------------------------------------------------- | |
293 | // wxMiniFrame | |
294 | //----------------------------------------------------------------------------- | |
295 | ||
90350682 | 296 | static const char *cross_xpm[] = { |
5d5b3a40 RR |
297 | /* columns rows colors chars-per-pixel */ |
298 | "5 5 16 1", | |
299 | " c Gray0", | |
300 | ". c #bf0000", | |
301 | "X c #00bf00", | |
302 | "o c #bfbf00", | |
303 | "O c #0000bf", | |
304 | "+ c #bf00bf", | |
305 | "@ c #00bfbf", | |
306 | "# c None", | |
307 | "$ c #808080", | |
308 | "% c Red", | |
309 | "& c Green", | |
310 | "* c Yellow", | |
311 | "= c Blue", | |
312 | "- c Magenta", | |
313 | "; c Cyan", | |
314 | ": c Gray100", | |
315 | /* pixels */ | |
316 | " ### ", | |
317 | "# # #", | |
318 | "## ##", | |
319 | "# # #", | |
320 | " ### ", | |
321 | }; | |
322 | ||
b2b3ccc5 RR |
323 | IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame) |
324 | ||
325 | bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, | |
326 | const wxPoint &pos, const wxSize &size, | |
327 | long style, const wxString &name ) | |
328 | { | |
2c990ec0 | 329 | style = style | wxCAPTION; |
b9a535f5 RR |
330 | |
331 | if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)) | |
332 | m_miniTitle = 13; | |
c2fa61e8 | 333 | |
b2b3ccc5 | 334 | m_miniEdge = 3; |
b2b3ccc5 RR |
335 | m_isDragging = FALSE; |
336 | m_oldX = -1; | |
337 | m_oldY = -1; | |
338 | m_diffX = 0; | |
339 | m_diffY = 0; | |
c2fa61e8 | 340 | |
b2b3ccc5 RR |
341 | wxFrame::Create( parent, id, title, pos, size, style, name ); |
342 | ||
2c990ec0 RR |
343 | if (m_parent && (GTK_IS_WINDOW(m_parent->m_widget))) |
344 | { | |
345 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) ); | |
346 | } | |
347 | ||
b9a535f5 RR |
348 | if ((style & wxSYSTEM_MENU) && |
349 | ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))) | |
350 | { | |
5d5b3a40 | 351 | GdkBitmap *mask = (GdkBitmap*) NULL; |
90350682 VZ |
352 | GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d |
353 | ( | |
354 | wxGetRootWindow()->window, | |
355 | &mask, | |
356 | NULL, | |
357 | (char **)cross_xpm | |
358 | ); | |
c2fa61e8 | 359 | |
5d5b3a40 RR |
360 | GtkWidget *pw = gtk_pixmap_new( pixmap, mask ); |
361 | gdk_bitmap_unref( mask ); | |
362 | gdk_pixmap_unref( pixmap ); | |
363 | gtk_widget_show( pw ); | |
c2fa61e8 | 364 | |
5d5b3a40 RR |
365 | GtkWidget *close_button = gtk_button_new(); |
366 | gtk_container_add( GTK_CONTAINER(close_button), pw ); | |
c2fa61e8 RD |
367 | |
368 | gtk_pizza_put( GTK_PIZZA(m_mainWidget), | |
369 | close_button, | |
5d5b3a40 | 370 | size.x-16, 4, 11, 11 ); |
c2fa61e8 | 371 | |
b9a535f5 | 372 | gtk_widget_show( close_button ); |
c2fa61e8 | 373 | |
b9a535f5 RR |
374 | gtk_signal_connect( GTK_OBJECT(close_button), "clicked", |
375 | GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); | |
376 | } | |
c2fa61e8 | 377 | |
32a95f9f RR |
378 | /* these are called when the borders are drawn */ |
379 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event", | |
380 | GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this ); | |
b2b3ccc5 | 381 | |
ba718523 | 382 | #ifndef __WXGTK20__ |
32a95f9f RR |
383 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw", |
384 | GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this ); | |
ba718523 | 385 | #endif |
c2fa61e8 | 386 | |
32a95f9f RR |
387 | /* these are required for dragging the mini frame around */ |
388 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event", | |
389 | GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this ); | |
b2b3ccc5 | 390 | |
32a95f9f RR |
391 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event", |
392 | GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this ); | |
b2b3ccc5 | 393 | |
32a95f9f RR |
394 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event", |
395 | GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this ); | |
b2b3ccc5 | 396 | |
32a95f9f | 397 | return TRUE; |
b2b3ccc5 | 398 | } |
dcf924a3 | 399 | |
400be137 RR |
400 | void wxMiniFrame::SetTitle( const wxString &title ) |
401 | { | |
402 | wxFrame::SetTitle( title ); | |
403 | ||
404 | #ifdef __WXGTK20__ | |
405 | gdk_window_invalidate_rect( GTK_PIZZA(m_mainWidget)->bin_window, NULL, true ); | |
406 | #else | |
407 | gtk_widget_draw( m_mainWidget, (GdkRectangle*) NULL ); | |
408 | #endif | |
409 | } | |
410 | ||
dcf924a3 | 411 | #endif |