1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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"
15 #include "wx/minifram.h"
18 #include "wx/dcscreen.h"
22 #include "wx/gtk1/win_gtk.h"
23 #include "wx/gtk1/private.h"
24 #include "wx/gtk1/dcclient.h"
27 #include <gdk/gdkprivate.h>
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 extern void wxapp_install_idle_handler();
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 extern bool g_blockEventsOnDrag
;
42 extern bool g_blockEventsOnScroll
;
43 extern GtkWidget
*wxGetRootWindow();
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 /* draw XOR rectangle when moving mine frame around */
51 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
55 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
59 GdkGC
*gc
= gdk_gc_new( GDK_ROOT_PARENT() );
60 gdk_gc_set_subwindow( gc
, GDK_INCLUDE_INFERIORS
);
61 gdk_gc_set_function( gc
, GDK_INVERT
);
63 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
67 //-----------------------------------------------------------------------------
68 // "expose_event" of m_mainWidget
69 //-----------------------------------------------------------------------------
72 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
74 if (g_isIdle
) wxapp_install_idle_handler();
76 if (!win
->m_hasVMT
) return;
77 if (gdk_event
->count
> 0) return;
79 GtkPizza
*pizza
= GTK_PIZZA(widget
);
81 gtk_draw_shadow( widget
->style
,
86 win
->m_width
, win
->m_height
);
88 if (!win
->GetTitle().empty() &&
89 ((win
->GetWindowStyle() & wxCAPTION
) ||
90 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
91 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
94 dc
.SetFont( *wxSMALL_FONT
);
95 int height
= dc
.GetCharHeight();
97 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
98 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
99 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
107 wx_static_cast(wxClientDCImpl
*, dc
.GetImpl())->m_window
= pizza
->bin_window
;
108 dc
.SetTextForeground( *wxWHITE
);
109 dc
.DrawText( win
->GetTitle(), 6, 3 );
114 //-----------------------------------------------------------------------------
115 // "draw" of m_mainWidget
116 //-----------------------------------------------------------------------------
119 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
121 if (g_isIdle
) wxapp_install_idle_handler();
123 if (!win
->m_hasVMT
) return;
125 GtkPizza
*pizza
= GTK_PIZZA(widget
);
127 gtk_draw_shadow( widget
->style
,
132 win
->m_width
, win
->m_height
);
134 if (!win
->GetTitle().empty() &&
135 ((win
->GetWindowStyle() & wxCAPTION
) ||
136 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
137 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
140 dc
.SetFont( *wxSMALL_FONT
);
141 int height
= dc
.GetCharHeight();
143 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
144 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
145 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
153 wx_static_cast(wxClientDCImpl
*, dc
.GetImpl())->m_window
= pizza
->bin_window
;
154 dc
.SetTextForeground( *wxWHITE
);
155 dc
.DrawText( win
->GetTitle(), 6, 3 );
160 //-----------------------------------------------------------------------------
161 // "button_press_event" of m_mainWidget
162 //-----------------------------------------------------------------------------
165 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
167 if (g_isIdle
) wxapp_install_idle_handler();
169 if (!win
->m_hasVMT
) return FALSE
;
170 if (g_blockEventsOnDrag
) return TRUE
;
171 if (g_blockEventsOnScroll
) return TRUE
;
173 if (win
->m_isDragging
) return TRUE
;
175 GtkPizza
*pizza
= GTK_PIZZA(widget
);
176 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
179 dc
.SetFont( *wxSMALL_FONT
);
180 int height
= dc
.GetCharHeight() + 1;
182 if (gdk_event
->y
> height
) return TRUE
;
184 gdk_window_raise( win
->m_widget
->window
);
186 gdk_pointer_grab( widget
->window
, FALSE
,
188 (GDK_BUTTON_PRESS_MASK
|
189 GDK_BUTTON_RELEASE_MASK
|
190 GDK_POINTER_MOTION_MASK
|
191 GDK_POINTER_MOTION_HINT_MASK
|
192 GDK_BUTTON_MOTION_MASK
|
193 GDK_BUTTON1_MOTION_MASK
),
196 (unsigned int) GDK_CURRENT_TIME
);
198 win
->m_diffX
= (int)gdk_event
->x
;
199 win
->m_diffY
= (int)gdk_event
->y
;
200 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
204 win
->m_isDragging
= true;
210 //-----------------------------------------------------------------------------
211 // "button_release_event" of m_mainWidget
212 //-----------------------------------------------------------------------------
215 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
217 if (g_isIdle
) wxapp_install_idle_handler();
219 if (!win
->m_hasVMT
) return FALSE
;
220 if (g_blockEventsOnDrag
) return TRUE
;
221 if (g_blockEventsOnScroll
) return TRUE
;
223 if (!win
->m_isDragging
) return TRUE
;
225 win
->m_isDragging
= false;
227 int x
= (int)gdk_event
->x
;
228 int y
= (int)gdk_event
->y
;
230 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
231 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
234 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
235 x
+= org_x
- win
->m_diffX
;
236 y
+= org_y
- win
->m_diffY
;
239 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
245 //-----------------------------------------------------------------------------
246 // "motion_notify_event" of m_mainWidget
247 //-----------------------------------------------------------------------------
250 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
252 if (g_isIdle
) wxapp_install_idle_handler();
254 if (!win
->m_hasVMT
) return FALSE
;
255 if (g_blockEventsOnDrag
) return TRUE
;
256 if (g_blockEventsOnScroll
) return TRUE
;
258 if (!win
->m_isDragging
) return TRUE
;
260 if (gdk_event
->is_hint
)
264 GdkModifierType state
;
265 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
268 gdk_event
->state
= state
;
271 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
272 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
273 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
274 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
280 //-----------------------------------------------------------------------------
281 // "clicked" of X system button
282 //-----------------------------------------------------------------------------
285 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
287 if (g_isIdle
) wxapp_install_idle_handler();
293 //-----------------------------------------------------------------------------
295 //-----------------------------------------------------------------------------
297 static const char *cross_xpm
[] = {
298 /* columns rows colors chars-per-pixel */
324 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
326 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
327 const wxPoint
&pos
, const wxSize
&size
,
328 long style
, const wxString
&name
)
330 style
= style
| wxCAPTION
;
332 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
336 m_isDragging
= false;
342 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
344 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
346 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
349 if ((style
& wxSYSTEM_MENU
) &&
350 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
352 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
353 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
355 wxGetRootWindow()->window
,
361 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
362 gdk_bitmap_unref( mask
);
363 gdk_pixmap_unref( pixmap
);
364 gtk_widget_show( pw
);
366 GtkWidget
*close_button
= gtk_button_new();
367 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
369 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
371 size
.x
-16, 4, 11, 11 );
373 gtk_widget_show( close_button
);
375 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
376 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
379 /* these are called when the borders are drawn */
380 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
381 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 );
386 /* these are required for dragging the mini frame around */
387 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
388 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
390 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
391 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
393 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
394 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
399 void wxMiniFrame::SetTitle( const wxString
&title
)
401 wxFrame::SetTitle( title
);
403 gtk_widget_draw( m_mainWidget
, (GdkRectangle
*) NULL
);
406 #endif // wxUSE_MINIFRAME