1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "minifram.h"
14 #include "wx/minifram.h"
18 #include "wx/dcscreen.h"
21 #include "wx/gtk/win_gtk.h"
22 #include "wx/gtk/private.h"
25 #include <gdk/gdkprivate.h>
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern void wxapp_install_idle_handler();
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern bool g_blockEventsOnDrag
;
40 extern bool g_blockEventsOnScroll
;
41 extern GtkWidget
*wxGetRootWindow();
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 /* draw XOR rectangle when moving mine frame around */
49 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
53 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
57 GdkGC
*gc
= gdk_gc_new( GDK_ROOT_PARENT() );
58 gdk_gc_set_subwindow( gc
, GDK_INCLUDE_INFERIORS
);
59 gdk_gc_set_function( gc
, GDK_INVERT
);
61 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
65 //-----------------------------------------------------------------------------
66 // "expose_event" of m_mainWidget
67 //-----------------------------------------------------------------------------
69 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
71 if (g_isIdle
) wxapp_install_idle_handler();
73 if (!win
->m_hasVMT
) return;
74 if (gdk_event
->count
> 0) return;
76 GtkPizza
*pizza
= GTK_PIZZA(widget
);
78 gtk_draw_shadow( widget
->style
,
83 win
->m_width
, win
->m_height
);
85 if (!win
->m_title
.IsEmpty() &&
86 ((win
->GetWindowStyle() & wxCAPTION
) ||
87 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
88 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
90 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
91 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
93 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
94 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
98 font
->ascent
+ font
->descent
+1 );
100 gdk_gc_set_foreground( gc
, &widget
->style
->fg
[GTK_STATE_SELECTED
] );
101 gdk_draw_string( pizza
->bin_window
, font
, gc
,
104 wxGTK_CONV( win
->m_title
) );
110 //-----------------------------------------------------------------------------
111 // "draw" of m_mainWidget
112 //-----------------------------------------------------------------------------
114 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
116 if (g_isIdle
) wxapp_install_idle_handler();
118 if (!win
->m_hasVMT
) return;
120 GtkPizza
*pizza
= GTK_PIZZA(widget
);
122 gtk_draw_shadow( widget
->style
,
127 win
->m_width
, win
->m_height
);
129 if (!win
->m_title
.IsEmpty() &&
130 ((win
->GetWindowStyle() & wxCAPTION
) ||
131 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
132 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
134 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
135 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
137 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
138 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
142 font
->ascent
+ font
->descent
+1 );
144 gdk_gc_set_foreground( gc
, &widget
->style
->fg
[GTK_STATE_SELECTED
] );
145 gdk_draw_string( pizza
->bin_window
, font
, gc
,
148 wxGTK_CONV( win
->m_title
) );
154 //-----------------------------------------------------------------------------
155 // "button_press_event" of m_mainWidget
156 //-----------------------------------------------------------------------------
158 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
160 if (g_isIdle
) wxapp_install_idle_handler();
162 if (!win
->m_hasVMT
) return FALSE
;
163 if (g_blockEventsOnDrag
) return TRUE
;
164 if (g_blockEventsOnScroll
) return TRUE
;
166 if (win
->m_isDragging
) return TRUE
;
168 GtkPizza
*pizza
= GTK_PIZZA(widget
);
169 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
171 GdkFont
*font
= wxSMALL_FONT
->GetInternalFont(1.0);
172 int height
= font
->ascent
+ font
->descent
+1;
173 if (gdk_event
->y
> height
) return TRUE
;
175 gdk_window_raise( win
->m_widget
->window
);
177 gdk_pointer_grab( widget
->window
, FALSE
,
179 (GDK_BUTTON_PRESS_MASK
|
180 GDK_BUTTON_RELEASE_MASK
|
181 GDK_POINTER_MOTION_MASK
|
182 GDK_POINTER_MOTION_HINT_MASK
|
183 GDK_BUTTON_MOTION_MASK
|
184 GDK_BUTTON1_MOTION_MASK
),
187 (unsigned int) GDK_CURRENT_TIME
);
189 win
->m_diffX
= (int)gdk_event
->x
;
190 win
->m_diffY
= (int)gdk_event
->y
;
191 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
195 win
->m_isDragging
= TRUE
;
200 //-----------------------------------------------------------------------------
201 // "button_release_event" of m_mainWidget
202 //-----------------------------------------------------------------------------
204 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
206 if (g_isIdle
) wxapp_install_idle_handler();
208 if (!win
->m_hasVMT
) return FALSE
;
209 if (g_blockEventsOnDrag
) return TRUE
;
210 if (g_blockEventsOnScroll
) return TRUE
;
212 if (!win
->m_isDragging
) return TRUE
;
214 win
->m_isDragging
= FALSE
;
216 int x
= (int)gdk_event
->x
;
217 int y
= (int)gdk_event
->y
;
219 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
220 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
223 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
224 x
+= org_x
- win
->m_diffX
;
225 y
+= org_y
- win
->m_diffY
;
228 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
233 //-----------------------------------------------------------------------------
234 // "motion_notify_event" of m_mainWidget
235 //-----------------------------------------------------------------------------
237 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
239 if (g_isIdle
) wxapp_install_idle_handler();
241 if (!win
->m_hasVMT
) return FALSE
;
242 if (g_blockEventsOnDrag
) return TRUE
;
243 if (g_blockEventsOnScroll
) return TRUE
;
245 if (!win
->m_isDragging
) return TRUE
;
247 if (gdk_event
->is_hint
)
251 GdkModifierType state
;
252 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
255 gdk_event
->state
= state
;
258 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
259 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
260 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
261 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
266 //-----------------------------------------------------------------------------
267 // "clicked" of X system button
268 //-----------------------------------------------------------------------------
270 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
272 if (g_isIdle
) wxapp_install_idle_handler();
277 //-----------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------
281 static const char *cross_xpm
[] = {
282 /* columns rows colors chars-per-pixel */
308 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
310 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
311 const wxPoint
&pos
, const wxSize
&size
,
312 long style
, const wxString
&name
)
314 style
= style
| wxCAPTION
;
316 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
320 m_isDragging
= FALSE
;
326 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
328 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
330 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
333 if ((style
& wxSYSTEM_MENU
) &&
334 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
336 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
337 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
339 wxGetRootWindow()->window
,
345 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
346 gdk_bitmap_unref( mask
);
347 gdk_pixmap_unref( pixmap
);
348 gtk_widget_show( pw
);
350 GtkWidget
*close_button
= gtk_button_new();
351 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
353 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
355 size
.x
-16, 4, 11, 11 );
357 gtk_widget_show( close_button
);
359 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
360 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
363 /* these are called when the borders are drawn */
364 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
365 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
367 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
368 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
370 /* these are required for dragging the mini frame around */
371 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
372 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
374 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
375 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
377 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
378 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );