1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/minifram.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #include "wx/minifram.h"
17 #include "wx/dcscreen.h"
21 #include "wx/dcclient.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
)))
93 dc
.SetFont( *wxSMALL_FONT
);
94 int height
= dc
.GetCharHeight();
96 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
97 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
98 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
106 static_cast<wxClientDCImpl
*>(dc
.GetImpl())->m_window
= pizza
->bin_window
;
107 dc
.SetTextForeground( *wxWHITE
);
108 dc
.DrawText( win
->GetTitle(), 6, 3 );
113 //-----------------------------------------------------------------------------
114 // "draw" of m_mainWidget
115 //-----------------------------------------------------------------------------
118 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
120 if (g_isIdle
) wxapp_install_idle_handler();
122 if (!win
->m_hasVMT
) return;
124 GtkPizza
*pizza
= GTK_PIZZA(widget
);
126 gtk_draw_shadow( widget
->style
,
131 win
->m_width
, win
->m_height
);
133 if (!win
->GetTitle().empty() &&
134 ((win
->GetWindowStyle() & wxCAPTION
) ||
135 (win
->GetWindowStyle() & wxTINY_CAPTION
)))
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 static_cast<wxClientDCImpl
*>(dc
.GetImpl())->m_window
= pizza
->bin_window
;
152 dc
.SetTextForeground( *wxWHITE
);
153 dc
.DrawText( win
->GetTitle(), 6, 3 );
158 //-----------------------------------------------------------------------------
159 // "button_press_event" of m_mainWidget
160 //-----------------------------------------------------------------------------
163 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
165 if (g_isIdle
) wxapp_install_idle_handler();
167 if (!win
->m_hasVMT
) return FALSE
;
168 if (g_blockEventsOnDrag
) return TRUE
;
169 if (g_blockEventsOnScroll
) return TRUE
;
171 if (win
->m_isDragging
) return TRUE
;
173 GtkPizza
*pizza
= GTK_PIZZA(widget
);
174 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
177 dc
.SetFont( *wxSMALL_FONT
);
178 int height
= dc
.GetCharHeight() + 1;
180 if (gdk_event
->y
> height
) return TRUE
;
182 gdk_window_raise( win
->m_widget
->window
);
184 gdk_pointer_grab( widget
->window
, FALSE
,
186 (GDK_BUTTON_PRESS_MASK
|
187 GDK_BUTTON_RELEASE_MASK
|
188 GDK_POINTER_MOTION_MASK
|
189 GDK_POINTER_MOTION_HINT_MASK
|
190 GDK_BUTTON_MOTION_MASK
|
191 GDK_BUTTON1_MOTION_MASK
),
194 (unsigned int) GDK_CURRENT_TIME
);
196 win
->m_diffX
= (int)gdk_event
->x
;
197 win
->m_diffY
= (int)gdk_event
->y
;
198 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
202 win
->m_isDragging
= true;
208 //-----------------------------------------------------------------------------
209 // "button_release_event" of m_mainWidget
210 //-----------------------------------------------------------------------------
213 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
215 if (g_isIdle
) wxapp_install_idle_handler();
217 if (!win
->m_hasVMT
) return FALSE
;
218 if (g_blockEventsOnDrag
) return TRUE
;
219 if (g_blockEventsOnScroll
) return TRUE
;
221 if (!win
->m_isDragging
) return TRUE
;
223 win
->m_isDragging
= false;
225 int x
= (int)gdk_event
->x
;
226 int y
= (int)gdk_event
->y
;
228 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
229 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
232 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
233 x
+= org_x
- win
->m_diffX
;
234 y
+= org_y
- win
->m_diffY
;
237 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
243 //-----------------------------------------------------------------------------
244 // "motion_notify_event" of m_mainWidget
245 //-----------------------------------------------------------------------------
248 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
250 if (g_isIdle
) wxapp_install_idle_handler();
252 if (!win
->m_hasVMT
) return FALSE
;
253 if (g_blockEventsOnDrag
) return TRUE
;
254 if (g_blockEventsOnScroll
) return TRUE
;
256 if (!win
->m_isDragging
) return TRUE
;
258 if (gdk_event
->is_hint
)
262 GdkModifierType state
;
263 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
266 gdk_event
->state
= state
;
269 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
270 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
271 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
272 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
278 //-----------------------------------------------------------------------------
279 // "clicked" of X system button
280 //-----------------------------------------------------------------------------
283 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
285 if (g_isIdle
) wxapp_install_idle_handler();
291 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
295 static const char *cross_xpm
[] = {
296 /* columns rows colors chars-per-pixel */
322 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
324 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
325 const wxPoint
&pos
, const wxSize
&size
,
326 long style
, const wxString
&name
)
328 style
= style
| wxCAPTION
;
330 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION
))
334 m_isDragging
= false;
340 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
342 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
344 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
347 if ((style
& wxSYSTEM_MENU
) &&
348 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION
)))
350 GdkBitmap
*mask
= NULL
;
351 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
353 wxGetRootWindow()->window
,
359 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
360 gdk_bitmap_unref( mask
);
361 gdk_pixmap_unref( pixmap
);
362 gtk_widget_show( pw
);
364 GtkWidget
*close_button
= gtk_button_new();
365 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
367 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
369 size
.x
-16, 4, 11, 11 );
371 gtk_widget_show( close_button
);
373 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
374 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
377 /* these are called when the borders are drawn */
378 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
379 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
381 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
382 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
384 /* these are required for dragging the mini frame around */
385 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
386 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
388 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
389 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
391 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
392 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
397 void wxMiniFrame::SetTitle( const wxString
&title
)
399 wxFrame::SetTitle( title
);
401 gtk_widget_draw( m_mainWidget
, NULL
);
404 #endif // wxUSE_MINIFRAME