1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/minifram.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #include "wx/minifram.h"
17 #include "wx/dcscreen.h"
20 #include "wx/gtk/win_gtk.h"
21 #include "wx/gtk/private.h"
24 #include <gdk/gdkprivate.h>
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
39 extern bool g_blockEventsOnScroll
;
40 extern GtkWidget
*wxGetRootWindow();
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 /* draw XOR rectangle when moving mine frame around */
48 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
52 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
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
);
60 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
64 //-----------------------------------------------------------------------------
65 // "expose_event" of m_mainWidget
66 //-----------------------------------------------------------------------------
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_paint_shadow (widget
->style
,
82 NULL
, NULL
, NULL
, // FIXME: No clipping?
84 win
->m_width
, win
->m_height
);
86 if (!win
->GetTitle().empty() &&
87 ((win
->GetWindowStyle() & wxCAPTION
) ||
88 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
89 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
92 dc
.SetFont( *wxSMALL_FONT
);
93 int height
= dc
.GetCharHeight();
95 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
96 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
97 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
105 dc
.m_window
= pizza
->bin_window
;
106 dc
.SetTextForeground( *wxWHITE
);
107 dc
.DrawText( win
->GetTitle(), 6, 3 );
112 //-----------------------------------------------------------------------------
113 // "button_press_event" of m_mainWidget
114 //-----------------------------------------------------------------------------
117 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
119 if (g_isIdle
) wxapp_install_idle_handler();
121 if (!win
->m_hasVMT
) return FALSE
;
122 if (g_blockEventsOnDrag
) return TRUE
;
123 if (g_blockEventsOnScroll
) return TRUE
;
125 if (win
->m_isDragging
) return TRUE
;
127 GtkPizza
*pizza
= GTK_PIZZA(widget
);
128 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
131 dc
.SetFont( *wxSMALL_FONT
);
132 int height
= dc
.GetCharHeight() + 1;
134 if (gdk_event
->y
> height
) return TRUE
;
136 gdk_window_raise( win
->m_widget
->window
);
138 gdk_pointer_grab( widget
->window
, FALSE
,
140 (GDK_BUTTON_PRESS_MASK
|
141 GDK_BUTTON_RELEASE_MASK
|
142 GDK_POINTER_MOTION_MASK
|
143 GDK_POINTER_MOTION_HINT_MASK
|
144 GDK_BUTTON_MOTION_MASK
|
145 GDK_BUTTON1_MOTION_MASK
),
148 (unsigned int) GDK_CURRENT_TIME
);
150 win
->m_diffX
= (int)gdk_event
->x
;
151 win
->m_diffY
= (int)gdk_event
->y
;
152 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
156 win
->m_isDragging
= true;
162 //-----------------------------------------------------------------------------
163 // "button_release_event" of m_mainWidget
164 //-----------------------------------------------------------------------------
167 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
169 if (g_isIdle
) wxapp_install_idle_handler();
171 if (!win
->m_hasVMT
) return FALSE
;
172 if (g_blockEventsOnDrag
) return TRUE
;
173 if (g_blockEventsOnScroll
) return TRUE
;
175 if (!win
->m_isDragging
) return TRUE
;
177 win
->m_isDragging
= FALSE
;
179 int x
= (int)gdk_event
->x
;
180 int y
= (int)gdk_event
->y
;
182 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
183 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
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
;
191 gtk_window_move( GTK_WINDOW(win
->m_widget
), x
, y
);
197 //-----------------------------------------------------------------------------
198 // "motion_notify_event" of m_mainWidget
199 //-----------------------------------------------------------------------------
202 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
204 if (g_isIdle
) wxapp_install_idle_handler();
206 if (!win
->m_hasVMT
) return FALSE
;
207 if (g_blockEventsOnDrag
) return TRUE
;
208 if (g_blockEventsOnScroll
) return TRUE
;
210 if (!win
->m_isDragging
) return TRUE
;
212 if (gdk_event
->is_hint
)
216 GdkModifierType state
;
217 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
220 gdk_event
->state
= state
;
223 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
224 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
225 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
226 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
232 //-----------------------------------------------------------------------------
233 // "clicked" of X system button
234 //-----------------------------------------------------------------------------
237 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
239 if (g_isIdle
) wxapp_install_idle_handler();
245 //-----------------------------------------------------------------------------
247 //-----------------------------------------------------------------------------
249 static const char *cross_xpm
[] = {
250 /* columns rows colors chars-per-pixel */
262 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
264 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
265 const wxPoint
&pos
, const wxSize
&size
,
266 long style
, const wxString
&name
)
268 style
= style
| wxCAPTION
;
270 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
274 m_isDragging
= false;
280 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
282 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
284 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
287 if ((style
& wxSYSTEM_MENU
) &&
288 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
290 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
291 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
293 wxGetRootWindow()->window
,
299 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
300 gdk_bitmap_unref( mask
);
301 gdk_pixmap_unref( pixmap
);
302 gtk_widget_show( pw
);
304 GtkWidget
*close_button
= gtk_button_new();
306 if (!gtk_check_version(2,4,0))
307 gtk_button_set_focus_on_click( GTK_BUTTON(close_button
), FALSE
);
309 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
311 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
313 size
.x
-16, 4, 11, 11 );
315 gtk_widget_show( close_button
);
317 g_signal_connect (close_button
, "clicked",
318 G_CALLBACK (gtk_button_clicked_callback
),
322 /* these are called when the borders are drawn */
323 g_signal_connect (m_mainWidget
, "expose_event",
324 G_CALLBACK (gtk_window_own_expose_callback
), this );
326 /* these are required for dragging the mini frame around */
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);
337 void wxMiniFrame::SetTitle( const wxString
&title
)
339 wxFrame::SetTitle( title
);
341 gdk_window_invalidate_rect( GTK_PIZZA(m_mainWidget
)->bin_window
, NULL
, true );