1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "minifram.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
17 #include "wx/minifram.h"
21 #include "wx/dcscreen.h"
24 #include "wx/gtk/win_gtk.h"
25 #include "wx/gtk/private.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 //-----------------------------------------------------------------------------
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().IsEmpty() &&
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 dc
.m_window
= pizza
->bin_window
;
108 dc
.SetTextForeground( *wxWHITE
);
109 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
->m_title
.IsEmpty() &&
134 ((win
->GetWindowStyle() & wxCAPTION
) ||
135 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
136 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
139 dc
.SetFont( *wxSMALL_FONT
);
140 int height
= dc
.GetCharHeight();
142 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
143 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
144 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
152 dc
.m_window
= pizza
->bin_window
;
153 dc
.SetTextForeground( *wxWHITE
);
154 dc
.DrawText( win
->GetTitle(), 6, 3 );
159 //-----------------------------------------------------------------------------
160 // "button_press_event" of m_mainWidget
161 //-----------------------------------------------------------------------------
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
;
207 //-----------------------------------------------------------------------------
208 // "button_release_event" of m_mainWidget
209 //-----------------------------------------------------------------------------
211 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
213 if (g_isIdle
) wxapp_install_idle_handler();
215 if (!win
->m_hasVMT
) return FALSE
;
216 if (g_blockEventsOnDrag
) return TRUE
;
217 if (g_blockEventsOnScroll
) return TRUE
;
219 if (!win
->m_isDragging
) return TRUE
;
221 win
->m_isDragging
= FALSE
;
223 int x
= (int)gdk_event
->x
;
224 int y
= (int)gdk_event
->y
;
226 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
227 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
230 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
231 x
+= org_x
- win
->m_diffX
;
232 y
+= org_y
- win
->m_diffY
;
235 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
240 //-----------------------------------------------------------------------------
241 // "motion_notify_event" of m_mainWidget
242 //-----------------------------------------------------------------------------
244 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
246 if (g_isIdle
) wxapp_install_idle_handler();
248 if (!win
->m_hasVMT
) return FALSE
;
249 if (g_blockEventsOnDrag
) return TRUE
;
250 if (g_blockEventsOnScroll
) return TRUE
;
252 if (!win
->m_isDragging
) return TRUE
;
254 if (gdk_event
->is_hint
)
258 GdkModifierType state
;
259 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
262 gdk_event
->state
= state
;
265 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
266 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
267 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
268 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
273 //-----------------------------------------------------------------------------
274 // "clicked" of X system button
275 //-----------------------------------------------------------------------------
277 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
279 if (g_isIdle
) wxapp_install_idle_handler();
284 //-----------------------------------------------------------------------------
286 //-----------------------------------------------------------------------------
288 static const char *cross_xpm
[] = {
289 /* columns rows colors chars-per-pixel */
315 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
317 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
318 const wxPoint
&pos
, const wxSize
&size
,
319 long style
, const wxString
&name
)
321 style
= style
| wxCAPTION
;
323 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
327 m_isDragging
= FALSE
;
333 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
335 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
337 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
340 if ((style
& wxSYSTEM_MENU
) &&
341 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
343 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
344 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
346 wxGetRootWindow()->window
,
352 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
353 gdk_bitmap_unref( mask
);
354 gdk_pixmap_unref( pixmap
);
355 gtk_widget_show( pw
);
357 GtkWidget
*close_button
= gtk_button_new();
358 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
360 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
362 size
.x
-16, 4, 11, 11 );
364 gtk_widget_show( close_button
);
366 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
367 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
370 /* these are called when the borders are drawn */
371 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
372 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
375 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
376 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
379 /* these are required for dragging the mini frame around */
380 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
381 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
383 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
384 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
386 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
387 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
392 void wxMiniFrame::SetTitle( const wxString
&title
)
394 wxFrame::SetTitle( title
);
397 gdk_window_invalidate_rect( GTK_PIZZA(m_mainWidget
)->bin_window
, NULL
, true );
399 gtk_widget_draw( m_mainWidget
, (GdkRectangle
*) NULL
);