]>
Commit | Line | Data |
---|---|---|
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 | ||
31 | extern void wxapp_install_idle_handler(); | |
32 | extern bool g_isIdle; | |
33 | ||
32a95f9f RR |
34 | //----------------------------------------------------------------------------- |
35 | // data | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
8480b297 RR |
38 | extern bool g_blockEventsOnDrag; |
39 | extern bool g_blockEventsOnScroll; | |
c2fa61e8 | 40 | extern GtkWidget *wxGetRootWindow(); |
32a95f9f | 41 | |
b2b3ccc5 | 42 | //----------------------------------------------------------------------------- |
32a95f9f RR |
43 | // local functions |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | /* draw XOR rectangle when moving mine frame around */ | |
47 | ||
48 | static 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 | 68 | extern "C" { |
32a95f9f RR |
69 | static 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 | 116 | extern "C" { |
32a95f9f RR |
117 | static 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 | 166 | extern "C" { |
32a95f9f RR |
167 | static 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; | |
a2053b27 | 191 | gtk_widget_set_uposition( 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 | 201 | extern "C" { |
32a95f9f RR |
202 | static 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 | 236 | extern "C" { |
b2b3ccc5 RR |
237 | static 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 | 249 | static const char *cross_xpm[] = { |
5d5b3a40 RR |
250 | /* columns rows colors chars-per-pixel */ |
251 | "5 5 16 1", | |
252 | " c Gray0", | |
253 | ". c #bf0000", | |
254 | "X c #00bf00", | |
255 | "o c #bfbf00", | |
256 | "O c #0000bf", | |
257 | "+ c #bf00bf", | |
258 | "@ c #00bfbf", | |
259 | "# c None", | |
260 | "$ c #808080", | |
261 | "% c Red", | |
262 | "& c Green", | |
263 | "* c Yellow", | |
264 | "= c Blue", | |
265 | "- c Magenta", | |
266 | "; c Cyan", | |
267 | ": c Gray100", | |
268 | /* pixels */ | |
269 | " ### ", | |
270 | "# # #", | |
271 | "## ##", | |
272 | "# # #", | |
273 | " ### ", | |
274 | }; | |
275 | ||
b2b3ccc5 RR |
276 | IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame,wxFrame) |
277 | ||
278 | bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, | |
279 | const wxPoint &pos, const wxSize &size, | |
280 | long style, const wxString &name ) | |
281 | { | |
2c990ec0 | 282 | style = style | wxCAPTION; |
b9a535f5 RR |
283 | |
284 | if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)) | |
285 | m_miniTitle = 13; | |
c2fa61e8 | 286 | |
b2b3ccc5 | 287 | m_miniEdge = 3; |
340bfb43 | 288 | m_isDragging = false; |
b2b3ccc5 RR |
289 | m_oldX = -1; |
290 | m_oldY = -1; | |
291 | m_diffX = 0; | |
292 | m_diffY = 0; | |
c2fa61e8 | 293 | |
b2b3ccc5 RR |
294 | wxFrame::Create( parent, id, title, pos, size, style, name ); |
295 | ||
2c990ec0 RR |
296 | if (m_parent && (GTK_IS_WINDOW(m_parent->m_widget))) |
297 | { | |
298 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) ); | |
299 | } | |
340bfb43 | 300 | |
b9a535f5 RR |
301 | if ((style & wxSYSTEM_MENU) && |
302 | ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))) | |
303 | { | |
5d5b3a40 | 304 | GdkBitmap *mask = (GdkBitmap*) NULL; |
90350682 VZ |
305 | GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d |
306 | ( | |
307 | wxGetRootWindow()->window, | |
308 | &mask, | |
309 | NULL, | |
310 | (char **)cross_xpm | |
311 | ); | |
c2fa61e8 | 312 | |
5d5b3a40 RR |
313 | GtkWidget *pw = gtk_pixmap_new( pixmap, mask ); |
314 | gdk_bitmap_unref( mask ); | |
315 | gdk_pixmap_unref( pixmap ); | |
316 | gtk_widget_show( pw ); | |
c2fa61e8 | 317 | |
5d5b3a40 RR |
318 | GtkWidget *close_button = gtk_button_new(); |
319 | gtk_container_add( GTK_CONTAINER(close_button), pw ); | |
c2fa61e8 RD |
320 | |
321 | gtk_pizza_put( GTK_PIZZA(m_mainWidget), | |
322 | close_button, | |
5d5b3a40 | 323 | size.x-16, 4, 11, 11 ); |
c2fa61e8 | 324 | |
b9a535f5 | 325 | gtk_widget_show( close_button ); |
c2fa61e8 | 326 | |
9fa72bd2 MR |
327 | g_signal_connect (close_button, "clicked", |
328 | G_CALLBACK (gtk_button_clicked_callback), | |
329 | this); | |
b9a535f5 | 330 | } |
c2fa61e8 | 331 | |
32a95f9f | 332 | /* these are called when the borders are drawn */ |
9fa72bd2 MR |
333 | g_signal_connect (m_mainWidget, "expose_event", |
334 | G_CALLBACK (gtk_window_own_expose_callback), this ); | |
b2b3ccc5 | 335 | |
32a95f9f | 336 | /* these are required for dragging the mini frame around */ |
9fa72bd2 MR |
337 | g_signal_connect (m_mainWidget, "button_press_event", |
338 | G_CALLBACK (gtk_window_button_press_callback), this); | |
339 | g_signal_connect (m_mainWidget, "button_release_event", | |
340 | G_CALLBACK (gtk_window_button_release_callback), this); | |
341 | g_signal_connect (m_mainWidget, "motion_notify_event", | |
342 | G_CALLBACK (gtk_window_motion_notify_callback), this); | |
b2b3ccc5 | 343 | |
340bfb43 | 344 | return true; |
b2b3ccc5 | 345 | } |
dcf924a3 | 346 | |
400be137 RR |
347 | void wxMiniFrame::SetTitle( const wxString &title ) |
348 | { | |
349 | wxFrame::SetTitle( title ); | |
340bfb43 | 350 | |
400be137 | 351 | gdk_window_invalidate_rect( GTK_PIZZA(m_mainWidget)->bin_window, NULL, true ); |
400be137 RR |
352 | } |
353 | ||
dcf924a3 | 354 | #endif |