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