1 /////////////////////////////////////////////////////////////////////////////
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_draw_shadow( widget
->style
,
83 win
->m_width
, win
->m_height
);
85 if (!win
->GetTitle().IsEmpty() &&
86 ((win
->GetWindowStyle() & wxCAPTION
) ||
87 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
88 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
91 dc
.SetFont( *wxSMALL_FONT
);
92 int height
= dc
.GetCharHeight();
94 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
95 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
96 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
104 dc
.m_window
= pizza
->bin_window
;
105 dc
.SetTextForeground( *wxWHITE
);
106 dc
.DrawText( win
->GetTitle(), 6, 3 );
111 //-----------------------------------------------------------------------------
112 // "draw" of m_mainWidget
113 //-----------------------------------------------------------------------------
117 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
119 if (g_isIdle
) wxapp_install_idle_handler();
121 if (!win
->m_hasVMT
) return;
123 GtkPizza
*pizza
= GTK_PIZZA(widget
);
125 gtk_draw_shadow( widget
->style
,
130 win
->m_width
, win
->m_height
);
132 if (!win
->m_title
.IsEmpty() &&
133 ((win
->GetWindowStyle() & wxCAPTION
) ||
134 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
135 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
138 dc
.SetFont( *wxSMALL_FONT
);
139 int height
= dc
.GetCharHeight();
141 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
142 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
143 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
151 dc
.m_window
= pizza
->bin_window
;
152 dc
.SetTextForeground( *wxWHITE
);
153 dc
.DrawText( win
->GetTitle(), 6, 3 );
159 //-----------------------------------------------------------------------------
160 // "button_press_event" of m_mainWidget
161 //-----------------------------------------------------------------------------
164 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
166 if (g_isIdle
) wxapp_install_idle_handler();
168 if (!win
->m_hasVMT
) return FALSE
;
169 if (g_blockEventsOnDrag
) return TRUE
;
170 if (g_blockEventsOnScroll
) return TRUE
;
172 if (win
->m_isDragging
) return TRUE
;
174 GtkPizza
*pizza
= GTK_PIZZA(widget
);
175 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
178 dc
.SetFont( *wxSMALL_FONT
);
179 int height
= dc
.GetCharHeight() + 1;
181 if (gdk_event
->y
> height
) return TRUE
;
183 gdk_window_raise( win
->m_widget
->window
);
185 gdk_pointer_grab( widget
->window
, FALSE
,
187 (GDK_BUTTON_PRESS_MASK
|
188 GDK_BUTTON_RELEASE_MASK
|
189 GDK_POINTER_MOTION_MASK
|
190 GDK_POINTER_MOTION_HINT_MASK
|
191 GDK_BUTTON_MOTION_MASK
|
192 GDK_BUTTON1_MOTION_MASK
),
195 (unsigned int) GDK_CURRENT_TIME
);
197 win
->m_diffX
= (int)gdk_event
->x
;
198 win
->m_diffY
= (int)gdk_event
->y
;
199 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
203 win
->m_isDragging
= TRUE
;
209 //-----------------------------------------------------------------------------
210 // "button_release_event" of m_mainWidget
211 //-----------------------------------------------------------------------------
214 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
216 if (g_isIdle
) wxapp_install_idle_handler();
218 if (!win
->m_hasVMT
) return FALSE
;
219 if (g_blockEventsOnDrag
) return TRUE
;
220 if (g_blockEventsOnScroll
) return TRUE
;
222 if (!win
->m_isDragging
) return TRUE
;
224 win
->m_isDragging
= FALSE
;
226 int x
= (int)gdk_event
->x
;
227 int y
= (int)gdk_event
->y
;
229 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
230 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
233 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
234 x
+= org_x
- win
->m_diffX
;
235 y
+= org_y
- win
->m_diffY
;
238 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
244 //-----------------------------------------------------------------------------
245 // "motion_notify_event" of m_mainWidget
246 //-----------------------------------------------------------------------------
249 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
251 if (g_isIdle
) wxapp_install_idle_handler();
253 if (!win
->m_hasVMT
) return FALSE
;
254 if (g_blockEventsOnDrag
) return TRUE
;
255 if (g_blockEventsOnScroll
) return TRUE
;
257 if (!win
->m_isDragging
) return TRUE
;
259 if (gdk_event
->is_hint
)
263 GdkModifierType state
;
264 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
267 gdk_event
->state
= state
;
270 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
271 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
272 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
273 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
279 //-----------------------------------------------------------------------------
280 // "clicked" of X system button
281 //-----------------------------------------------------------------------------
284 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
286 if (g_isIdle
) wxapp_install_idle_handler();
292 //-----------------------------------------------------------------------------
294 //-----------------------------------------------------------------------------
296 static const char *cross_xpm
[] = {
297 /* columns rows colors chars-per-pixel */
323 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
325 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
326 const wxPoint
&pos
, const wxSize
&size
,
327 long style
, const wxString
&name
)
329 style
= style
| wxCAPTION
;
331 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
335 m_isDragging
= FALSE
;
341 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
343 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
345 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
348 if ((style
& wxSYSTEM_MENU
) &&
349 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
351 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
352 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
354 wxGetRootWindow()->window
,
360 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
361 gdk_bitmap_unref( mask
);
362 gdk_pixmap_unref( pixmap
);
363 gtk_widget_show( pw
);
365 GtkWidget
*close_button
= gtk_button_new();
366 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
368 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
370 size
.x
-16, 4, 11, 11 );
372 gtk_widget_show( close_button
);
374 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
375 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
378 /* these are called when the borders are drawn */
379 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
380 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
383 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
384 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
387 /* these are required for dragging the mini frame around */
388 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
389 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
391 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
392 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
394 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
395 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
400 void wxMiniFrame::SetTitle( const wxString
&title
)
402 wxFrame::SetTitle( title
);
405 gdk_window_invalidate_rect( GTK_PIZZA(m_mainWidget
)->bin_window
, NULL
, true );
407 gtk_widget_draw( m_mainWidget
, (GdkRectangle
*) NULL
);