]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/minifram.cpp
Added chapter on collection and container classes to contents
[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;
40extern GtkWidget *wxRootWindow;
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{
50 int org_x = 0;
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 );
59
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
RR
73 if (gdk_event->count > 0) return;
74
da048e3d 75 GtkPizza *pizza = GTK_PIZZA(widget);
54517652 76
32a95f9f 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() &&
f03fc89f
VZ
85 ((win->GetWindowStyle() & wxCAPTION) ||
86 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
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);
f03fc89f 91
b9a535f5 92 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
da048e3d 93 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
f03fc89f 94 3,
5d5b3a40
RR
95 3,
96 win->m_width - 7,
f03fc89f
VZ
97 font->ascent + font->descent+1 );
98
08abd69b 99 gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
da048e3d 100 gdk_draw_string( pizza->bin_window, font, gc,
5d5b3a40 101 6,
f03fc89f
VZ
102 3+font->ascent,
103 win->m_title.mb_str() );
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;
32a95f9f 118
da048e3d 119 GtkPizza *pizza = GTK_PIZZA(widget);
54517652 120
32a95f9f 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 );
f03fc89f 127
b9a535f5 128 if (!win->m_title.IsEmpty() &&
f03fc89f
VZ
129 ((win->GetWindowStyle() & wxCAPTION) ||
130 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
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);
f03fc89f 135
b9a535f5 136 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
da048e3d 137 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
f03fc89f 138 3,
5d5b3a40
RR
139 3,
140 win->m_width - 7,
f03fc89f
VZ
141 font->ascent + font->descent+1 );
142
08abd69b 143 gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
da048e3d 144 gdk_draw_string( pizza->bin_window, font, gc,
5d5b3a40 145 6,
f03fc89f
VZ
146 3+font->ascent,
147 win->m_title.mb_str() );
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
4dcaf11a
RR
167 gdk_window_raise( win->m_widget->window );
168
32a95f9f
RR
169 gdk_pointer_grab( widget->window, FALSE,
170 (GdkEventMask)
171 (GDK_BUTTON_PRESS_MASK |
172 GDK_BUTTON_RELEASE_MASK |
f03fc89f 173 GDK_POINTER_MOTION_MASK |
32a95f9f 174 GDK_POINTER_MOTION_HINT_MASK |
f03fc89f 175 GDK_BUTTON_MOTION_MASK |
32a95f9f
RR
176 GDK_BUTTON1_MOTION_MASK),
177 (GdkWindow *) NULL,
178 (GdkCursor *) NULL,
7941ba11 179 (unsigned int) GDK_CURRENT_TIME );
f03fc89f 180
32a95f9f
RR
181 win->m_diffX = (int)gdk_event->x;
182 win->m_diffY = (int)gdk_event->y;
a2053b27 183 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
32a95f9f
RR
184 win->m_oldX = 0;
185 win->m_oldY = 0;
186
187 win->m_isDragging = TRUE;
188
189 return TRUE;
190}
191
192//-----------------------------------------------------------------------------
193// "button_release_event" of m_mainWidget
194//-----------------------------------------------------------------------------
195
196static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
197{
acfd422a
RR
198 if (g_isIdle) wxapp_install_idle_handler();
199
a2053b27 200 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
201 if (g_blockEventsOnDrag) return TRUE;
202 if (g_blockEventsOnScroll) return TRUE;
203
204 if (!win->m_isDragging) return TRUE;
205
206 win->m_isDragging = FALSE;
207
208 int x = (int)gdk_event->x;
209 int y = (int)gdk_event->y;
210
a2053b27 211 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
13111b2a 212 gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
32a95f9f
RR
213 int org_x = 0;
214 int org_y = 0;
215 gdk_window_get_origin( widget->window, &org_x, &org_y );
216 x += org_x - win->m_diffX;
217 y += org_y - win->m_diffY;
121a3581
RR
218 win->m_x = x;
219 win->m_y = y;
a2053b27 220 gtk_widget_set_uposition( win->m_widget, x, y );
32a95f9f
RR
221
222 return TRUE;
223}
224
225//-----------------------------------------------------------------------------
226// "motion_notify_event" of m_mainWidget
227//-----------------------------------------------------------------------------
228
229static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
230{
acfd422a
RR
231 if (g_isIdle) wxapp_install_idle_handler();
232
a2053b27 233 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
234 if (g_blockEventsOnDrag) return TRUE;
235 if (g_blockEventsOnScroll) return TRUE;
236
237 if (!win->m_isDragging) return TRUE;
238
239 if (gdk_event->is_hint)
240 {
241 int x = 0;
242 int y = 0;
243 GdkModifierType state;
244 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
245 gdk_event->x = x;
246 gdk_event->y = y;
247 gdk_event->state = state;
248 }
249
a2053b27 250 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
251 win->m_oldX = (int)gdk_event->x - win->m_diffX;
252 win->m_oldY = (int)gdk_event->y - win->m_diffY;
a2053b27 253 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
254
255 return TRUE;
256}
257
258//-----------------------------------------------------------------------------
259// "clicked" of X system button
b2b3ccc5
RR
260//-----------------------------------------------------------------------------
261
262static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
263{
acfd422a
RR
264 if (g_isIdle) wxapp_install_idle_handler();
265
b2b3ccc5
RR
266 mf->Close();
267}
268
269//-----------------------------------------------------------------------------
270// wxMiniFrame
271//-----------------------------------------------------------------------------
272
5d5b3a40
RR
273static char *cross_xpm[] = {
274/* columns rows colors chars-per-pixel */
275"5 5 16 1",
276" c Gray0",
277". c #bf0000",
278"X c #00bf00",
279"o c #bfbf00",
280"O c #0000bf",
281"+ c #bf00bf",
282"@ c #00bfbf",
283"# c None",
284"$ c #808080",
285"% c Red",
286"& c Green",
287"* c Yellow",
288"= c Blue",
289"- c Magenta",
290"; c Cyan",
291": c Gray100",
292/* pixels */
293" ### ",
294"# # #",
295"## ##",
296"# # #",
297" ### ",
298};
299
b2b3ccc5
RR
300IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
301
302bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
303 const wxPoint &pos, const wxSize &size,
304 long style, const wxString &name )
305{
80629c8b 306 style = style | wxCAPTION | wxFRAME_FLOAT_ON_PARENT;
b9a535f5
RR
307
308 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
309 m_miniTitle = 13;
f03fc89f 310
b2b3ccc5 311 m_miniEdge = 3;
b2b3ccc5
RR
312 m_isDragging = FALSE;
313 m_oldX = -1;
314 m_oldY = -1;
315 m_diffX = 0;
316 m_diffY = 0;
317
318 wxFrame::Create( parent, id, title, pos, size, style, name );
319
b9a535f5
RR
320 if ((style & wxSYSTEM_MENU) &&
321 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
322 {
5d5b3a40 323 GdkBitmap *mask = (GdkBitmap*) NULL;
8480b297 324 GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, cross_xpm );
5d5b3a40
RR
325
326 GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
327 gdk_bitmap_unref( mask );
328 gdk_pixmap_unref( pixmap );
329 gtk_widget_show( pw );
330
331 GtkWidget *close_button = gtk_button_new();
332 gtk_container_add( GTK_CONTAINER(close_button), pw );
b2b3ccc5 333
da048e3d 334 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
f03fc89f 335 close_button,
5d5b3a40 336 size.x-16, 4, 11, 11 );
b2b3ccc5 337
b9a535f5 338 gtk_widget_show( close_button );
b2b3ccc5 339
b9a535f5
RR
340 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
341 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
342 }
b2b3ccc5 343
32a95f9f
RR
344 /* these are called when the borders are drawn */
345 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
346 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
b2b3ccc5 347
32a95f9f
RR
348 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
349 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
350
351 /* these are required for dragging the mini frame around */
352 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",
353 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
b2b3ccc5 354
32a95f9f
RR
355 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
356 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
b2b3ccc5 357
32a95f9f
RR
358 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
359 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
b2b3ccc5 360
32a95f9f 361 return TRUE;
b2b3ccc5 362}
dcf924a3
RR
363
364#endif