]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/minifram.cpp
Found bug that skrewed up display wrt horizontal
[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
b9a535f5 99 gdk_gc_set_foreground( gc, &widget->style->white );
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
b9a535f5 143 gdk_gc_set_foreground( gc, &widget->style->white );
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{
306 style = style | wxSIMPLE_BORDER;
3017f78d 307 style = style | wxCAPTION;
b9a535f5
RR
308
309 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
310 m_miniTitle = 13;
f03fc89f 311
b2b3ccc5 312 m_miniEdge = 3;
b2b3ccc5
RR
313 m_isDragging = FALSE;
314 m_oldX = -1;
315 m_oldY = -1;
316 m_diffX = 0;
317 m_diffY = 0;
318
319 wxFrame::Create( parent, id, title, pos, size, style, name );
320
a56fcaaf
RR
321 if ((m_parent) && (GTK_IS_WINDOW(m_parent->m_widget)))
322 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
323
b9a535f5
RR
324 if ((style & wxSYSTEM_MENU) &&
325 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
326 {
5d5b3a40 327 GdkBitmap *mask = (GdkBitmap*) NULL;
8480b297 328 GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, cross_xpm );
5d5b3a40
RR
329
330 GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
331 gdk_bitmap_unref( mask );
332 gdk_pixmap_unref( pixmap );
333 gtk_widget_show( pw );
334
335 GtkWidget *close_button = gtk_button_new();
336 gtk_container_add( GTK_CONTAINER(close_button), pw );
b2b3ccc5 337
da048e3d 338 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
f03fc89f 339 close_button,
5d5b3a40 340 size.x-16, 4, 11, 11 );
b2b3ccc5 341
b9a535f5 342 gtk_widget_show( close_button );
b2b3ccc5 343
b9a535f5
RR
344 gtk_signal_connect( GTK_OBJECT(close_button), "clicked",
345 GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
346 }
b2b3ccc5 347
32a95f9f
RR
348 /* these are called when the borders are drawn */
349 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
350 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
b2b3ccc5 351
32a95f9f
RR
352 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
353 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
354
355 /* these are required for dragging the mini frame around */
356 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",
357 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
b2b3ccc5 358
32a95f9f
RR
359 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_release_event",
360 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
b2b3ccc5 361
32a95f9f
RR
362 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "motion_notify_event",
363 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
b2b3ccc5 364
32a95f9f 365 return TRUE;
b2b3ccc5 366}
dcf924a3
RR
367
368#endif