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