#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)
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 );
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;
}