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/dcclient.h"
23 #include "wx/gtk1/win_gtk.h"
24 #include "wx/gtk1/private.h"
25 #include "wx/gtk1/dcclient.h"
28 #include <gdk/gdkprivate.h>
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern void wxapp_install_idle_handler();
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern bool g_blockEventsOnDrag
;
43 extern bool g_blockEventsOnScroll
;
44 extern GtkWidget
*wxGetRootWindow();
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 /* draw XOR rectangle when moving mine frame around */
52 static void DrawFrame( GtkWidget
*widget
, int x
, int y
, int w
, int h
)
56 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
60 GdkGC
*gc
= gdk_gc_new( GDK_ROOT_PARENT() );
61 gdk_gc_set_subwindow( gc
, GDK_INCLUDE_INFERIORS
);
62 gdk_gc_set_function( gc
, GDK_INVERT
);
64 gdk_draw_rectangle( GDK_ROOT_PARENT(), gc
, FALSE
, x
, y
, w
, h
);
68 //-----------------------------------------------------------------------------
69 // "expose_event" of m_mainWidget
70 //-----------------------------------------------------------------------------
73 static void gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxFrame
*win
)
75 if (g_isIdle
) wxapp_install_idle_handler();
77 if (!win
->m_hasVMT
) return;
78 if (gdk_event
->count
> 0) return;
80 GtkPizza
*pizza
= GTK_PIZZA(widget
);
82 gtk_draw_shadow( widget
->style
,
87 win
->m_width
, win
->m_height
);
89 if (!win
->GetTitle().empty() &&
90 ((win
->GetWindowStyle() & wxCAPTION
) ||
91 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
92 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
95 dc
.SetFont( *wxSMALL_FONT
);
96 int height
= dc
.GetCharHeight();
98 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
99 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
100 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
108 static_cast<wxClientDCImpl
*>(dc
.GetImpl())->m_window
= pizza
->bin_window
;
109 dc
.SetTextForeground( *wxWHITE
);
110 dc
.DrawText( win
->GetTitle(), 6, 3 );
115 //-----------------------------------------------------------------------------
116 // "draw" of m_mainWidget
117 //-----------------------------------------------------------------------------
120 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
122 if (g_isIdle
) wxapp_install_idle_handler();
124 if (!win
->m_hasVMT
) return;
126 GtkPizza
*pizza
= GTK_PIZZA(widget
);
128 gtk_draw_shadow( widget
->style
,
133 win
->m_width
, win
->m_height
);
135 if (!win
->GetTitle().empty() &&
136 ((win
->GetWindowStyle() & wxCAPTION
) ||
137 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
138 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
141 dc
.SetFont( *wxSMALL_FONT
);
142 int height
= dc
.GetCharHeight();
144 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
145 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
146 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
154 static_cast<wxClientDCImpl
*>(dc
.GetImpl())->m_window
= pizza
->bin_window
;
155 dc
.SetTextForeground( *wxWHITE
);
156 dc
.DrawText( win
->GetTitle(), 6, 3 );
161 //-----------------------------------------------------------------------------
162 // "button_press_event" of m_mainWidget
163 //-----------------------------------------------------------------------------
166 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
168 if (g_isIdle
) wxapp_install_idle_handler();
170 if (!win
->m_hasVMT
) return FALSE
;
171 if (g_blockEventsOnDrag
) return TRUE
;
172 if (g_blockEventsOnScroll
) return TRUE
;
174 if (win
->m_isDragging
) return TRUE
;
176 GtkPizza
*pizza
= GTK_PIZZA(widget
);
177 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
180 dc
.SetFont( *wxSMALL_FONT
);
181 int height
= dc
.GetCharHeight() + 1;
183 if (gdk_event
->y
> height
) return TRUE
;
185 gdk_window_raise( win
->m_widget
->window
);
187 gdk_pointer_grab( widget
->window
, FALSE
,
189 (GDK_BUTTON_PRESS_MASK
|
190 GDK_BUTTON_RELEASE_MASK
|
191 GDK_POINTER_MOTION_MASK
|
192 GDK_POINTER_MOTION_HINT_MASK
|
193 GDK_BUTTON_MOTION_MASK
|
194 GDK_BUTTON1_MOTION_MASK
),
197 (unsigned int) GDK_CURRENT_TIME
);
199 win
->m_diffX
= (int)gdk_event
->x
;
200 win
->m_diffY
= (int)gdk_event
->y
;
201 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
205 win
->m_isDragging
= true;
211 //-----------------------------------------------------------------------------
212 // "button_release_event" of m_mainWidget
213 //-----------------------------------------------------------------------------
216 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
218 if (g_isIdle
) wxapp_install_idle_handler();
220 if (!win
->m_hasVMT
) return FALSE
;
221 if (g_blockEventsOnDrag
) return TRUE
;
222 if (g_blockEventsOnScroll
) return TRUE
;
224 if (!win
->m_isDragging
) return TRUE
;
226 win
->m_isDragging
= false;
228 int x
= (int)gdk_event
->x
;
229 int y
= (int)gdk_event
->y
;
231 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
232 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
235 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
236 x
+= org_x
- win
->m_diffX
;
237 y
+= org_y
- win
->m_diffY
;
240 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
246 //-----------------------------------------------------------------------------
247 // "motion_notify_event" of m_mainWidget
248 //-----------------------------------------------------------------------------
251 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
253 if (g_isIdle
) wxapp_install_idle_handler();
255 if (!win
->m_hasVMT
) return FALSE
;
256 if (g_blockEventsOnDrag
) return TRUE
;
257 if (g_blockEventsOnScroll
) return TRUE
;
259 if (!win
->m_isDragging
) return TRUE
;
261 if (gdk_event
->is_hint
)
265 GdkModifierType state
;
266 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
269 gdk_event
->state
= state
;
272 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
273 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
274 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
275 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
281 //-----------------------------------------------------------------------------
282 // "clicked" of X system button
283 //-----------------------------------------------------------------------------
286 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
288 if (g_isIdle
) wxapp_install_idle_handler();
294 //-----------------------------------------------------------------------------
296 //-----------------------------------------------------------------------------
298 static const char *cross_xpm
[] = {
299 /* columns rows colors chars-per-pixel */
325 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
327 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
328 const wxPoint
&pos
, const wxSize
&size
,
329 long style
, const wxString
&name
)
331 style
= style
| wxCAPTION
;
333 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
337 m_isDragging
= false;
343 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
345 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
347 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
350 if ((style
& wxSYSTEM_MENU
) &&
351 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
353 GdkBitmap
*mask
= NULL
;
354 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
356 wxGetRootWindow()->window
,
362 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
363 gdk_bitmap_unref( mask
);
364 gdk_pixmap_unref( pixmap
);
365 gtk_widget_show( pw
);
367 GtkWidget
*close_button
= gtk_button_new();
368 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
370 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
372 size
.x
-16, 4, 11, 11 );
374 gtk_widget_show( close_button
);
376 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
377 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
380 /* these are called when the borders are drawn */
381 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
382 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
384 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
385 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
);
404 gtk_widget_draw( m_mainWidget
, NULL
);
407 #endif // wxUSE_MINIFRAME