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