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