]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/minifram.cpp
wx_gtk_vmsjackets.c seems to not be used by anything these days. Delete on both wxGTK...
[wxWidgets.git] / src / gtk / minifram.cpp
CommitLineData
b2b3ccc5 1/////////////////////////////////////////////////////////////////////////////
340bfb43 2// Name: src/gtk/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
b2b3ccc5 13#include "wx/minifram.h"
dcf924a3
RR
14
15#if wxUSE_MINIFRAME
16
b2b3ccc5
RR
17#include "wx/dcscreen.h"
18
83624f79
RR
19#include "gtk/gtk.h"
20#include "wx/gtk/win_gtk.h"
fab591c5 21#include "wx/gtk/private.h"
83624f79 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
865bb325 68extern "C" {
32a95f9f
RR
69static 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 77
67b73b9a
MR
78 gtk_paint_shadow (widget->style,
79 pizza->bin_window,
80 GTK_STATE_NORMAL,
81 GTK_SHADOW_OUT,
82 NULL, NULL, NULL, // FIXME: No clipping?
83 0, 0,
84 win->m_width, win->m_height);
b9a535f5 85
340bfb43 86 if (!win->GetTitle().empty() &&
c2fa61e8
RD
87 ((win->GetWindowStyle() & wxCAPTION) ||
88 (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
f03fc89f 89 (win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
b9a535f5 90 {
ba718523
RR
91 wxClientDC dc(win);
92 dc.SetFont( *wxSMALL_FONT );
93 int height = dc.GetCharHeight();
340bfb43 94
da048e3d 95 GdkGC *gc = gdk_gc_new( pizza->bin_window );
b9a535f5 96 gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
c2fa61e8
RD
97 gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
98 3,
99 3,
5d5b3a40 100 win->m_width - 7,
ba718523 101 height+1 );
b9a535f5 102 gdk_gc_unref( gc );
ba718523
RR
103
104 // Hack alert
105 dc.m_window = pizza->bin_window;
106 dc.SetTextForeground( *wxWHITE );
107 dc.DrawText( win->GetTitle(), 6, 3 );
b9a535f5 108 }
32a95f9f 109}
865bb325 110}
32a95f9f 111
32a95f9f
RR
112//-----------------------------------------------------------------------------
113// "button_press_event" of m_mainWidget
114//-----------------------------------------------------------------------------
115
865bb325 116extern "C" {
32a95f9f
RR
117static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
118{
acfd422a
RR
119 if (g_isIdle) wxapp_install_idle_handler();
120
a2053b27 121 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
122 if (g_blockEventsOnDrag) return TRUE;
123 if (g_blockEventsOnScroll) return TRUE;
124
125 if (win->m_isDragging) return TRUE;
126
2c990ec0
RR
127 GtkPizza *pizza = GTK_PIZZA(widget);
128 if (gdk_event->window != pizza->bin_window) return TRUE;
ba718523
RR
129
130 wxClientDC dc(win);
131 dc.SetFont( *wxSMALL_FONT );
132 int height = dc.GetCharHeight() + 1;
340bfb43 133
2c990ec0 134 if (gdk_event->y > height) return TRUE;
340bfb43 135
4dcaf11a 136 gdk_window_raise( win->m_widget->window );
c2fa61e8 137
32a95f9f
RR
138 gdk_pointer_grab( widget->window, FALSE,
139 (GdkEventMask)
140 (GDK_BUTTON_PRESS_MASK |
141 GDK_BUTTON_RELEASE_MASK |
f03fc89f 142 GDK_POINTER_MOTION_MASK |
32a95f9f 143 GDK_POINTER_MOTION_HINT_MASK |
f03fc89f 144 GDK_BUTTON_MOTION_MASK |
32a95f9f
RR
145 GDK_BUTTON1_MOTION_MASK),
146 (GdkWindow *) NULL,
147 (GdkCursor *) NULL,
7941ba11 148 (unsigned int) GDK_CURRENT_TIME );
c2fa61e8 149
32a95f9f
RR
150 win->m_diffX = (int)gdk_event->x;
151 win->m_diffY = (int)gdk_event->y;
a2053b27 152 DrawFrame( widget, 0, 0, win->m_width, win->m_height );
32a95f9f
RR
153 win->m_oldX = 0;
154 win->m_oldY = 0;
c2fa61e8 155
340bfb43 156 win->m_isDragging = true;
32a95f9f
RR
157
158 return TRUE;
159}
865bb325 160}
32a95f9f
RR
161
162//-----------------------------------------------------------------------------
163// "button_release_event" of m_mainWidget
164//-----------------------------------------------------------------------------
165
865bb325 166extern "C" {
32a95f9f
RR
167static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxMiniFrame *win )
168{
acfd422a
RR
169 if (g_isIdle) wxapp_install_idle_handler();
170
a2053b27 171 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
172 if (g_blockEventsOnDrag) return TRUE;
173 if (g_blockEventsOnScroll) return TRUE;
174
175 if (!win->m_isDragging) return TRUE;
c2fa61e8 176
32a95f9f 177 win->m_isDragging = FALSE;
c2fa61e8 178
32a95f9f
RR
179 int x = (int)gdk_event->x;
180 int y = (int)gdk_event->y;
c2fa61e8 181
a2053b27 182 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
13111b2a 183 gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
c2fa61e8 184 int org_x = 0;
32a95f9f
RR
185 int org_y = 0;
186 gdk_window_get_origin( widget->window, &org_x, &org_y );
187 x += org_x - win->m_diffX;
188 y += org_y - win->m_diffY;
121a3581
RR
189 win->m_x = x;
190 win->m_y = y;
9adb9063 191 gtk_window_move( GTK_WINDOW(win->m_widget), x, y );
32a95f9f
RR
192
193 return TRUE;
194}
865bb325 195}
32a95f9f
RR
196
197//-----------------------------------------------------------------------------
198// "motion_notify_event" of m_mainWidget
199//-----------------------------------------------------------------------------
200
865bb325 201extern "C" {
32a95f9f
RR
202static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxMiniFrame *win )
203{
acfd422a
RR
204 if (g_isIdle) wxapp_install_idle_handler();
205
a2053b27 206 if (!win->m_hasVMT) return FALSE;
32a95f9f
RR
207 if (g_blockEventsOnDrag) return TRUE;
208 if (g_blockEventsOnScroll) return TRUE;
209
210 if (!win->m_isDragging) return TRUE;
c2fa61e8 211
32a95f9f
RR
212 if (gdk_event->is_hint)
213 {
214 int x = 0;
215 int y = 0;
216 GdkModifierType state;
217 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
218 gdk_event->x = x;
219 gdk_event->y = y;
220 gdk_event->state = state;
221 }
222
a2053b27 223 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
32a95f9f
RR
224 win->m_oldX = (int)gdk_event->x - win->m_diffX;
225 win->m_oldY = (int)gdk_event->y - win->m_diffY;
a2053b27 226 DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height );
c2fa61e8 227
32a95f9f
RR
228 return TRUE;
229}
865bb325 230}
32a95f9f
RR
231
232//-----------------------------------------------------------------------------
233// "clicked" of X system button
b2b3ccc5
RR
234//-----------------------------------------------------------------------------
235
865bb325 236extern "C" {
b2b3ccc5
RR
237static void gtk_button_clicked_callback( GtkWidget *WXUNUSED(widget), wxMiniFrame *mf )
238{
acfd422a
RR
239 if (g_isIdle) wxapp_install_idle_handler();
240
b2b3ccc5
RR
241 mf->Close();
242}
865bb325 243}
b2b3ccc5
RR
244
245//-----------------------------------------------------------------------------
246// wxMiniFrame
247//-----------------------------------------------------------------------------
248
90350682 249static const char *cross_xpm[] = {
5d5b3a40 250/* columns rows colors chars-per-pixel */
07d04e37
MR
251"5 5 2 1",
252"# c Gray0",
253" c None",
5d5b3a40 254/* pixels */
07d04e37
MR
255"# #",
256" # # ",
257" # ",
258" # # ",
259"# #",
5d5b3a40
RR
260};
261
b2b3ccc5
RR
262IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame)
263
264bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
265 const wxPoint &pos, const wxSize &size,
266 long style, const wxString &name )
267{
2c990ec0 268 style = style | wxCAPTION;
b9a535f5
RR
269
270 if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))
271 m_miniTitle = 13;
c2fa61e8 272
b2b3ccc5 273 m_miniEdge = 3;
340bfb43 274 m_isDragging = false;
b2b3ccc5
RR
275 m_oldX = -1;
276 m_oldY = -1;
277 m_diffX = 0;
278 m_diffY = 0;
c2fa61e8 279
b2b3ccc5
RR
280 wxFrame::Create( parent, id, title, pos, size, style, name );
281
2c990ec0
RR
282 if (m_parent && (GTK_IS_WINDOW(m_parent->m_widget)))
283 {
284 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
285 }
340bfb43 286
b9a535f5
RR
287 if ((style & wxSYSTEM_MENU) &&
288 ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)))
289 {
5d5b3a40 290 GdkBitmap *mask = (GdkBitmap*) NULL;
90350682
VZ
291 GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d
292 (
293 wxGetRootWindow()->window,
294 &mask,
295 NULL,
296 (char **)cross_xpm
297 );
c2fa61e8 298
5d5b3a40
RR
299 GtkWidget *pw = gtk_pixmap_new( pixmap, mask );
300 gdk_bitmap_unref( mask );
301 gdk_pixmap_unref( pixmap );
302 gtk_widget_show( pw );
c2fa61e8 303
5d5b3a40 304 GtkWidget *close_button = gtk_button_new();
1d13cff3
MR
305#ifdef __WXGTK24__
306 if (!gtk_check_version(2,4,0))
307 gtk_button_set_focus_on_click( GTK_BUTTON(close_button), FALSE );
308#endif
5d5b3a40 309 gtk_container_add( GTK_CONTAINER(close_button), pw );
c2fa61e8
RD
310
311 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
312 close_button,
5d5b3a40 313 size.x-16, 4, 11, 11 );
c2fa61e8 314
b9a535f5 315 gtk_widget_show( close_button );
c2fa61e8 316
9fa72bd2
MR
317 g_signal_connect (close_button, "clicked",
318 G_CALLBACK (gtk_button_clicked_callback),
319 this);
b9a535f5 320 }
c2fa61e8 321
32a95f9f 322 /* these are called when the borders are drawn */
9fa72bd2
MR
323 g_signal_connect (m_mainWidget, "expose_event",
324 G_CALLBACK (gtk_window_own_expose_callback), this );
b2b3ccc5 325
32a95f9f 326 /* these are required for dragging the mini frame around */
9fa72bd2
MR
327 g_signal_connect (m_mainWidget, "button_press_event",
328 G_CALLBACK (gtk_window_button_press_callback), this);
329 g_signal_connect (m_mainWidget, "button_release_event",
330 G_CALLBACK (gtk_window_button_release_callback), this);
331 g_signal_connect (m_mainWidget, "motion_notify_event",
332 G_CALLBACK (gtk_window_motion_notify_callback), this);
b2b3ccc5 333
340bfb43 334 return true;
b2b3ccc5 335}
dcf924a3 336
400be137
RR
337void wxMiniFrame::SetTitle( const wxString &title )
338{
339 wxFrame::SetTitle( title );
340bfb43 340
400be137 341 gdk_window_invalidate_rect( GTK_PIZZA(m_mainWidget)->bin_window, NULL, true );
400be137
RR
342}
343
dcf924a3 344#endif