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"
13 #include "wx/minifram.h"
17 #include "wx/dcscreen.h"
20 #include "wx/gtk1/win_gtk.h"
21 #include "wx/gtk1/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().empty() &&
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 //-----------------------------------------------------------------------------
116 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxFrame
*win
)
118 if (g_isIdle
) wxapp_install_idle_handler();
120 if (!win
->m_hasVMT
) return;
122 GtkPizza
*pizza
= GTK_PIZZA(widget
);
124 gtk_draw_shadow( widget
->style
,
129 win
->m_width
, win
->m_height
);
131 if (!win
->GetTitle().empty() &&
132 ((win
->GetWindowStyle() & wxCAPTION
) ||
133 (win
->GetWindowStyle() & wxTINY_CAPTION_HORIZ
) ||
134 (win
->GetWindowStyle() & wxTINY_CAPTION_VERT
)))
137 dc
.SetFont( *wxSMALL_FONT
);
138 int height
= dc
.GetCharHeight();
140 GdkGC
*gc
= gdk_gc_new( pizza
->bin_window
);
141 gdk_gc_set_foreground( gc
, &widget
->style
->bg
[GTK_STATE_SELECTED
] );
142 gdk_draw_rectangle( pizza
->bin_window
, gc
, TRUE
,
150 dc
.m_window
= pizza
->bin_window
;
151 dc
.SetTextForeground( *wxWHITE
);
152 dc
.DrawText( win
->GetTitle(), 6, 3 );
157 //-----------------------------------------------------------------------------
158 // "button_press_event" of m_mainWidget
159 //-----------------------------------------------------------------------------
162 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
164 if (g_isIdle
) wxapp_install_idle_handler();
166 if (!win
->m_hasVMT
) return FALSE
;
167 if (g_blockEventsOnDrag
) return TRUE
;
168 if (g_blockEventsOnScroll
) return TRUE
;
170 if (win
->m_isDragging
) return TRUE
;
172 GtkPizza
*pizza
= GTK_PIZZA(widget
);
173 if (gdk_event
->window
!= pizza
->bin_window
) return TRUE
;
176 dc
.SetFont( *wxSMALL_FONT
);
177 int height
= dc
.GetCharHeight() + 1;
179 if (gdk_event
->y
> height
) return TRUE
;
181 gdk_window_raise( win
->m_widget
->window
);
183 gdk_pointer_grab( widget
->window
, FALSE
,
185 (GDK_BUTTON_PRESS_MASK
|
186 GDK_BUTTON_RELEASE_MASK
|
187 GDK_POINTER_MOTION_MASK
|
188 GDK_POINTER_MOTION_HINT_MASK
|
189 GDK_BUTTON_MOTION_MASK
|
190 GDK_BUTTON1_MOTION_MASK
),
193 (unsigned int) GDK_CURRENT_TIME
);
195 win
->m_diffX
= (int)gdk_event
->x
;
196 win
->m_diffY
= (int)gdk_event
->y
;
197 DrawFrame( widget
, 0, 0, win
->m_width
, win
->m_height
);
201 win
->m_isDragging
= true;
207 //-----------------------------------------------------------------------------
208 // "button_release_event" of m_mainWidget
209 //-----------------------------------------------------------------------------
212 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxMiniFrame
*win
)
214 if (g_isIdle
) wxapp_install_idle_handler();
216 if (!win
->m_hasVMT
) return FALSE
;
217 if (g_blockEventsOnDrag
) return TRUE
;
218 if (g_blockEventsOnScroll
) return TRUE
;
220 if (!win
->m_isDragging
) return TRUE
;
222 win
->m_isDragging
= FALSE
;
224 int x
= (int)gdk_event
->x
;
225 int y
= (int)gdk_event
->y
;
227 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
228 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
231 gdk_window_get_origin( widget
->window
, &org_x
, &org_y
);
232 x
+= org_x
- win
->m_diffX
;
233 y
+= org_y
- win
->m_diffY
;
236 gtk_widget_set_uposition( win
->m_widget
, x
, y
);
242 //-----------------------------------------------------------------------------
243 // "motion_notify_event" of m_mainWidget
244 //-----------------------------------------------------------------------------
247 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxMiniFrame
*win
)
249 if (g_isIdle
) wxapp_install_idle_handler();
251 if (!win
->m_hasVMT
) return FALSE
;
252 if (g_blockEventsOnDrag
) return TRUE
;
253 if (g_blockEventsOnScroll
) return TRUE
;
255 if (!win
->m_isDragging
) return TRUE
;
257 if (gdk_event
->is_hint
)
261 GdkModifierType state
;
262 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
265 gdk_event
->state
= state
;
268 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
269 win
->m_oldX
= (int)gdk_event
->x
- win
->m_diffX
;
270 win
->m_oldY
= (int)gdk_event
->y
- win
->m_diffY
;
271 DrawFrame( widget
, win
->m_oldX
, win
->m_oldY
, win
->m_width
, win
->m_height
);
277 //-----------------------------------------------------------------------------
278 // "clicked" of X system button
279 //-----------------------------------------------------------------------------
282 static void gtk_button_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxMiniFrame
*mf
)
284 if (g_isIdle
) wxapp_install_idle_handler();
290 //-----------------------------------------------------------------------------
292 //-----------------------------------------------------------------------------
294 static const char *cross_xpm
[] = {
295 /* columns rows colors chars-per-pixel */
321 IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame
,wxFrame
)
323 bool wxMiniFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
324 const wxPoint
&pos
, const wxSize
&size
,
325 long style
, const wxString
&name
)
327 style
= style
| wxCAPTION
;
329 if ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
))
333 m_isDragging
= false;
339 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
341 if (m_parent
&& (GTK_IS_WINDOW(m_parent
->m_widget
)))
343 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(m_parent
->m_widget
) );
346 if ((style
& wxSYSTEM_MENU
) &&
347 ((style
& wxCAPTION
) || (style
& wxTINY_CAPTION_HORIZ
) || (style
& wxTINY_CAPTION_VERT
)))
349 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
350 GdkPixmap
*pixmap
= gdk_pixmap_create_from_xpm_d
352 wxGetRootWindow()->window
,
358 GtkWidget
*pw
= gtk_pixmap_new( pixmap
, mask
);
359 gdk_bitmap_unref( mask
);
360 gdk_pixmap_unref( pixmap
);
361 gtk_widget_show( pw
);
363 GtkWidget
*close_button
= gtk_button_new();
364 gtk_container_add( GTK_CONTAINER(close_button
), pw
);
366 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
368 size
.x
-16, 4, 11, 11 );
370 gtk_widget_show( close_button
);
372 gtk_signal_connect( GTK_OBJECT(close_button
), "clicked",
373 GTK_SIGNAL_FUNC(gtk_button_clicked_callback
), (gpointer
*)this );
376 /* these are called when the borders are drawn */
377 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "expose_event",
378 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
380 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "draw",
381 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
383 /* these are required for dragging the mini frame around */
384 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_press_event",
385 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
387 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "button_release_event",
388 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
390 gtk_signal_connect( GTK_OBJECT(m_mainWidget
), "motion_notify_event",
391 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
396 void wxMiniFrame::SetTitle( const wxString
&title
)
398 wxFrame::SetTitle( title
);
400 gtk_widget_draw( m_mainWidget
, (GdkRectangle
*) NULL
);