#include "wx/gtk/private/gtk2-compat.h"
#include "wx/gtk/private/event.h"
#include "wx/gtk/private/win_gtk.h"
+#include "wx/private/textmeasure.h"
using namespace wxGTKImpl;
#ifdef GDK_WINDOWING_X11
// the trace mask used for the focus debugging messages
#define TRACE_FOCUS wxT("focus")
+// A handy function to run from under gdb to show information about the given
+// GtkWidget. Right now it only shows its type, we could enhance it to show
+// more information later but this is already pretty useful.
+const char* wxDumpGtkWidget(GtkWidget* w)
+{
+ static wxString s;
+ s.Printf("GtkWidget %p, type \"%s\"", w, G_OBJECT_TYPE_NAME(w));
+
+ return s.c_str();
+}
+
//-----------------------------------------------------------------------------
// "expose_event"/"draw" from m_wxwindow
//-----------------------------------------------------------------------------
GdkEventKey *gdk_event,
wxWindow *win )
{
- if (!win->m_hasVMT)
- return FALSE;
if (g_blockEventsOnDrag)
return FALSE;
GdkEventKey *gdk_event,
wxWindowGTK *win )
{
- if (!win->m_hasVMT)
- return FALSE;
-
if (g_blockEventsOnDrag)
return FALSE;
bool wxWindowGTK::GTKShouldIgnoreEvent() const
{
- return !m_hasVMT || g_blockEventsOnDrag;
+ return g_blockEventsOnDrag;
}
int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny *event) const
{
- if (!m_hasVMT)
- return FALSE;
if (g_blockEventsOnDrag)
return TRUE;
if (g_blockEventsOnScroll)
}
//-----------------------------------------------------------------------------
-// "unrealize" from m_wxwindow
+// "unrealize"
//-----------------------------------------------------------------------------
static void unrealize(GtkWidget*, wxWindow* win)
{
- if (win->m_imData)
- gtk_im_context_set_client_window(win->m_imData->context, NULL);
-
- g_signal_handlers_disconnect_by_func(
- win->m_wxwindow, (void*)style_updated, win);
+ win->GTKHandleUnrealize();
}
} // extern "C"
void wxWindowGTK::GTKHandleRealized()
{
+ if (IsFrozen())
+ DoFreeze();
+
if (m_imData)
{
gtk_im_context_set_client_window
}
}
+void wxWindowGTK::GTKHandleUnrealize()
+{
+ // unrealizing a frozen window seems to have some lingering effect
+ // preventing updates to the affected area
+ if (IsFrozen())
+ DoThaw();
+
+ if (m_wxwindow)
+ {
+ if (m_imData)
+ gtk_im_context_set_client_window(m_imData->context, NULL);
+
+ g_signal_handlers_disconnect_by_func(
+ m_wxwindow, (void*)style_updated, this);
+ }
+}
+
// ----------------------------------------------------------------------------
// this wxWindowBase function is implemented here (in platform-specific file)
// because it is static and so couldn't be made virtual
m_width = 0;
m_height = 0;
- m_hasVMT = false;
-
m_showOnIdle = false;
m_noExpose = false;
return true;
}
+void wxWindowGTK::GTKDisconnect(void* instance)
+{
+ g_signal_handlers_disconnect_matched(instance,
+ GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, this);
+}
+
wxWindowGTK::~wxWindowGTK()
{
SendDestroyEvent();
if ( gs_deferredFocusOut == this )
gs_deferredFocusOut = NULL;
- m_hasVMT = false;
+ if (m_widget)
+ GTKDisconnect(m_widget);
+ if (m_wxwindow && m_wxwindow != m_widget)
+ GTKDisconnect(m_wxwindow);
// destroy children before destroying this window itself
DestroyChildren();
- // unhook focus handlers to prevent stray events being
- // propagated to this (soon to be) dead object
- if (m_focusWidget != NULL)
- {
- g_signal_handlers_disconnect_by_func (m_focusWidget,
- (gpointer) gtk_window_focus_in_callback,
- this);
- g_signal_handlers_disconnect_by_func (m_focusWidget,
- (gpointer) gtk_window_focus_out_callback,
- this);
- }
-
if (m_widget)
Show( false );
g_signal_connect (m_imData->context, "commit",
G_CALLBACK (gtk_wxwindow_commit_cb), this);
- g_signal_connect(m_wxwindow, "unrealize", G_CALLBACK(unrealize), this);
}
// focus handling
// was in fact realized already.
if ( gtk_widget_get_realized(connect_widget) )
{
- gtk_window_realized_callback(connect_widget, this);
+ GTKHandleRealized();
}
else
{
g_signal_connect (connect_widget, "realize",
G_CALLBACK (gtk_window_realized_callback), this);
}
+ g_signal_connect(connect_widget, "unrealize", G_CALLBACK(unrealize), this);
if (!IsTopLevel())
{
InheritAttributes();
- m_hasVMT = true;
-
SetLayoutDirection(wxLayout_Default);
// unless the window was created initially hidden (i.e. Hide() had been
G_CALLBACK (gtk_window_leave_callback), this);
}
-bool wxWindowGTK::Destroy()
-{
- m_hasVMT = false;
-
- return wxWindowBase::Destroy();
-}
-
static GSList* gs_queueResizeList;
extern "C" {
int *externalLeading,
const wxFont *theFont ) const
{
- wxFont fontToUse = theFont ? *theFont : GetFont();
+ // ensure we work with a valid font
+ wxFont fontToUse;
+ if ( !theFont || !theFont->IsOk() )
+ fontToUse = GetFont();
+ else
+ fontToUse = *theFont;
wxCHECK_RET( fontToUse.IsOk(), wxT("invalid font") );
- if (string.empty())
- {
- if (x) (*x) = 0;
- if (y) (*y) = 0;
- return;
- }
-
- PangoContext *context = NULL;
- if (m_widget)
- context = gtk_widget_get_pango_context( m_widget );
-
- if (!context)
- {
- if (x) (*x) = 0;
- if (y) (*y) = 0;
- return;
- }
-
- PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
- PangoLayout *layout = pango_layout_new(context);
- pango_layout_set_font_description(layout, desc);
- {
- const wxCharBuffer data = wxGTK_CONV( string );
- if ( data )
- pango_layout_set_text(layout, data, strlen(data));
- }
-
- PangoRectangle rect;
- pango_layout_get_extents(layout, NULL, &rect);
-
- if (x) (*x) = (wxCoord) PANGO_PIXELS(rect.width);
- if (y) (*y) = (wxCoord) PANGO_PIXELS(rect.height);
- if (descent)
- {
- PangoLayoutIter *iter = pango_layout_get_iter(layout);
- int baseline = pango_layout_iter_get_baseline(iter);
- pango_layout_iter_free(iter);
- *descent = *y - PANGO_PIXELS(baseline);
- }
- if (externalLeading) (*externalLeading) = 0; // ??
-
- g_object_unref (layout);
+ const wxWindow* win = static_cast<const wxWindow*>(this);
+ wxTextMeasure txm(win, &fontToUse);
+ txm.GetTextExtent(string, x, y, descent, externalLeading);
}
void wxWindowGTK::GTKDisableFocusOutEvent()
// update current position
m_scrollPos[barIndex] = value;
// If event should be ignored, or integral position has not changed
- if (!m_hasVMT || g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos))
+ if (g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos))
{
return wxEVT_NULL;
}
// freeze/thaw
// ----------------------------------------------------------------------------
-extern "C"
-{
-
-// this is called if we attempted to freeze unrealized widget when it finally
-// is realized (and so can be frozen):
-static void wx_frozen_widget_realize(GtkWidget* w, wxWindowGTK* win)
-{
- wxASSERT( w && gtk_widget_get_has_window(w) );
- wxASSERT( gtk_widget_get_realized(w) );
-
- g_signal_handlers_disconnect_by_func
- (
- w,
- (void*)wx_frozen_widget_realize,
- win
- );
-
- GdkWindow* window;
- if (w == win->m_wxwindow)
- window = win->GTKGetDrawingWindow();
- else
- window = gtk_widget_get_window(w);
- gdk_window_freeze_updates(window);
-}
-
-} // extern "C"
-
-void wxWindowGTK::GTKFreezeWidget(GtkWidget *w)
+void wxWindowGTK::GTKFreezeWidget(GtkWidget* widget)
{
- if ( !w || !gtk_widget_get_has_window(w) )
- return; // window-less widget, cannot be frozen
-
- GdkWindow* window = gtk_widget_get_window(w);
- if (window == NULL)
+ if (widget && gtk_widget_get_has_window(widget))
{
- // we can't thaw unrealized widgets because they don't have GdkWindow,
- // so set it up to be done immediately after realization:
- g_signal_connect_after
- (
- w,
- "realize",
- G_CALLBACK(wx_frozen_widget_realize),
- this
- );
- return;
+ GdkWindow* window = gtk_widget_get_window(widget);
+ if (window)
+ gdk_window_freeze_updates(window);
}
-
- if (w == m_wxwindow)
- window = GTKGetDrawingWindow();
- gdk_window_freeze_updates(window);
}
-void wxWindowGTK::GTKThawWidget(GtkWidget *w)
+void wxWindowGTK::GTKThawWidget(GtkWidget* widget)
{
- if ( !w || !gtk_widget_get_has_window(w) )
- return; // window-less widget, cannot be frozen
-
- GdkWindow* window = gtk_widget_get_window(w);
- if (window == NULL)
+ if (widget && gtk_widget_get_has_window(widget))
{
- // the widget wasn't realized yet, no need to thaw
- g_signal_handlers_disconnect_by_func
- (
- w,
- (void*)wx_frozen_widget_realize,
- this
- );
- return;
+ GdkWindow* window = gtk_widget_get_window(widget);
+ if (window)
+ gdk_window_thaw_updates(window);
}
-
- if (w == m_wxwindow)
- window = GTKGetDrawingWindow();
- gdk_window_thaw_updates(window);
}
void wxWindowGTK::DoFreeze()
{
- GTKFreezeWidget(m_widget);
- if ( m_wxwindow && m_widget != m_wxwindow )
- GTKFreezeWidget(m_wxwindow);
+ GtkWidget* widget = m_wxwindow;
+ if (widget == NULL)
+ widget = m_widget;
+ GTKFreezeWidget(widget);
}
void wxWindowGTK::DoThaw()
{
- GTKThawWidget(m_widget);
- if ( m_wxwindow && m_widget != m_wxwindow )
- GTKThawWidget(m_wxwindow);
+ GtkWidget* widget = m_wxwindow;
+ if (widget == NULL)
+ widget = m_widget;
+ GTKThawWidget(widget);
}