#include "wx/intl.h"
#include "wx/settings.h"
#include "wx/log.h"
+#include "wx/fontutil.h"
#ifdef __WXDEBUG__
#include "wx/thread.h"
#endif
#include <math.h>
+#include <ctype.h>
#include "wx/gtk/private.h"
#include <gdk/gdkprivate.h>
if (g_isIdle)
wxapp_install_idle_handler();
+#ifdef __WXGTK20__
+ // This callback gets called in drawing-idle time under
+ // GTK 2.0, so we don't need to defer anything to idle
+ // time anymore.
+
+ GtkPizza *pizza = GTK_PIZZA( widget );
+ if (gdk_event->window != pizza->bin_window) return FALSE;
+
#if 0
if (win->GetName())
{
}
#endif
+ win->GetUpdateRegion() = wxRegion( gdk_event->region );
+
+ win->GtkSendPaintEvents();
+
+ // Let parent window draw window less widgets
+ (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event);
+#else
+ // This gets called immediately after an expose event
+ // under GTK 1.2 so we collect the calls and wait for
+ // the idle handler to pick things up.
+
win->GetUpdateRegion().Union( gdk_event->area.x,
gdk_event->area.y,
gdk_event->area.width,
gdk_event->area.height );
// Actual redrawing takes place in idle time.
- win->GtkUpdate();
-
-#ifdef __WXGTK20__
-
- (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event);
-
+ // win->GtkUpdate();
#endif
- return TRUE;
+ return FALSE;
}
//-----------------------------------------------------------------------------
(char *)"base",
0, 0, -1, -1);
}
-
-
- if (!(GTK_WIDGET_APP_PAINTABLE (widget)) &&
- (pizza->clear_on_draw))
- {
- gdk_window_clear_area( pizza->bin_window,
- rect->x, rect->y, rect->width, rect->height);
- }
#endif
+ win->m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height );
win->GetUpdateRegion().Union( rect->x, rect->y, rect->width, rect->height );
- // Actual redrawing takes place in idle time.
-
+ // Update immediately, not in idle time.
win->GtkUpdate();
#ifndef __WXUNIVERSAL__
KeySym keysym = gdk_event->keyval;
- wxLogTrace(TRACE_KEYS, _T("Key %s event: keysym = %d"),
+ wxLogTrace(TRACE_KEYS, _T("Key %s event: keysym = %ld"),
event.GetEventType() == wxEVT_KEY_UP ? _T("release")
: _T("press"),
keysym);
}
}
- wxLogTrace(TRACE_KEYS, _T("\t-> wxKeyCode %d"), key_code);
+ wxLogTrace(TRACE_KEYS, _T("\t-> wxKeyCode %ld"), key_code);
// sending unknown key events doesn't really make sense
if ( !key_code )
if ( !ret &&
(gdk_event->keyval == GDK_Escape) )
{
- wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
- new_event.SetEventObject( win );
- ret = win->GetEventHandler()->ProcessEvent( new_event );
+ // however only do it if we have a Cancel button in the dialog,
+ // otherwise the user code may get confused by the events from a
+ // non-existing button and, worse, a wxButton might get button event
+ // from another button which is not really expected
+ wxWindow *winForCancel = win,
+ *btnCancel = NULL;
+ while ( winForCancel )
+ {
+ btnCancel = winForCancel->FindWindow(wxID_CANCEL);
+ if ( btnCancel )
+ {
+ // found a cancel button
+ break;
+ }
+
+ if ( winForCancel->IsTopLevel() )
+ {
+ // no need to look further
+ break;
+ }
+
+ // maybe our parent has a cancel button?
+ winForCancel = winForCancel->GetParent();
+ }
+
+ if ( btnCancel )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
+ event.SetEventObject(btnCancel);
+ ret = btnCancel->GetEventHandler()->ProcessEvent(event);
+ }
}
// Doesn't work.
// ----------------------------------------------------------------------------
// init wxMouseEvent with the info from gdk_event
-#define InitMouseEvent(win, event, gdk_event) \
- { \
- event.SetTimestamp( gdk_event->time ); \
- event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); \
- event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); \
- event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); \
- event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); \
- event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); \
- event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); \
- event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); \
-\
- wxPoint pt = win->GetClientAreaOrigin(); \
- event.m_x = (wxCoord)gdk_event->x - pt.x; \
- event.m_y = (wxCoord)gdk_event->y - pt.y; \
- }
+//
+// NB: this has to be a macro as gdk_event type is different for different
+// events we're used with
+#define InitMouseEvent(/* wxWindowGTK * */ win, \
+ /* wxMouseEvent& */ event, \
+ /* GdkEventXXX * */ gdk_event) \
+{ \
+ event.SetTimestamp( gdk_event->time ); \
+ event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); \
+ event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); \
+ event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); \
+ event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); \
+ event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); \
+ event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); \
+ event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); \
+ \
+ wxPoint pt = win->GetClientAreaOrigin(); \
+ event.m_x = (wxCoord)gdk_event->x - pt.x; \
+ event.m_y = (wxCoord)gdk_event->y - pt.y; \
+ \
+ event.SetEventObject( win ); \
+ event.SetId( win->GetId() ); \
+ event.SetTimestamp( gdk_event->time ); \
+} \
static void AdjustEventButtonState(wxMouseEvent& event)
{
if ( !g_captureWindow )
win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
- event.SetEventObject( win );
-
gs_timeLastClick = gdk_event->time;
/*
if ( !g_captureWindow )
win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
- event.SetEventObject( win );
-
if (win->GetEventHandler()->ProcessEvent( event ))
{
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" );
win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
}
- event.SetEventObject( win );
-
if (win->GetEventHandler()->ProcessEvent( event ))
{
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" );
// always) and makes using Mahogany quite annoying
#if 0
wxASSERT_MSG( wxGetTopLevelParent(win) == g_activeFrame,
- wxT("unfocusing window that hasn't gained focus properly") )
+ wxT("unfocusing window that hasn't gained focus properly") );
#endif // 0
g_activeFrameLostFocus = TRUE;
// "enter_notify_event"
//-----------------------------------------------------------------------------
-static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindowGTK *win )
+static
+gint gtk_window_enter_callback( GtkWidget *widget,
+ GdkEventCrossing *gdk_event,
+ wxWindowGTK *win )
{
DEBUG_MAIN_THREAD
if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
- wxMouseEvent event( wxEVT_ENTER_WINDOW );
- event.SetTimestamp( gdk_event->time );
- event.SetEventObject( win );
-
int x = 0;
int y = 0;
GdkModifierType state = (GdkModifierType)0;
gdk_window_get_pointer( widget->window, &x, &y, &state );
+ wxMouseEvent event( wxEVT_ENTER_WINDOW );
InitMouseEvent(win, event, gdk_event);
wxPoint pt = win->GetClientAreaOrigin();
event.m_x = x + pt.x;
win->m_oldVerticalPos = adjust->value;
+#ifndef __WXGTK20__
GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(win->m_widget);
+#endif
wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->vscrollbar));
int value = (int)(adjust->value+0.5);
float diff = adjust->value - win->m_oldHorizontalPos;
if (fabs(diff) < 0.2) return;
+#ifndef __WXGTK20__
GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(win->m_widget);
+#endif
wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->hscrollbar));
win->m_oldHorizontalPos = adjust->value;
{
wxCHECK_MSG( !m_needParent || parent, FALSE, wxT("Need complete parent.") );
- /* this turns -1 into 20 so that a minimal window is
- visible even although -1,-1 has been given as the
- size of the window. the same trick is used in other
- ports and should make debugging easier */
- m_width = WidthDefault(size.x);
+ // This turns -1 into 30 so that a minimal window is
+ // visible even although -1,-1 has been given as the
+ // size of the window. the same trick is used in other
+ // ports and should make debugging easier.
+ m_width = WidthDefault(size.x) ;
m_height = HeightDefault(size.y);
m_x = (int)pos.x;
m_y = (int)pos.y;
- /* some reasonable defaults */
+ // some reasonable defaults
if (!parent)
{
if (m_x == -1)
{
if (x != -1) m_x = x + pizza->xoffset;
if (y != -1) m_y = y + pizza->yoffset;
- if (width != -1) m_width = width;
- if (height != -1) m_height = height;
}
else
{
m_x = x + pizza->xoffset;
m_y = y + pizza->yoffset;
- m_width = width;
- m_height = height;
}
+ if (width != -1) m_width = width;
+ if (height != -1) m_height = height;
if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
{
if (theFont) fontToUse = *theFont;
wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
+
+ if (string.IsEmpty())
+ {
+ if (x) (*x) = 0;
+ if (y) (*y) = 0;
+ return;
+ }
+#ifdef __WXGTK20__
+ PangoContext *context = NULL;
+ if (m_widget)
+ 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);
+ {
+#if wxUSE_UNICODE
+ const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
+ pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
+#else
+ const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
+ const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
+ pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
+#endif
+ }
+ PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
+
+ PangoRectangle rect;
+ pango_layout_line_get_extents(line, NULL, &rect);
+
+ if (x) (*x) = (wxCoord) (rect.width / PANGO_SCALE);
+ if (y) (*y) = (wxCoord) (rect.height / PANGO_SCALE);
+ if (descent)
+ {
+ // Do something about metrics here
+ (*descent) = 0;
+ }
+ if (externalLeading) (*externalLeading) = 0; // ??
+
+ g_object_unref( G_OBJECT( layout ) );
+#else
GdkFont *font = fontToUse.GetInternalFont( 1.0 );
- if (x) (*x) = gdk_string_width( font, string.mbc_str() );
+ if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) );
if (y) (*y) = font->ascent + font->descent;
if (descent) (*descent) = font->descent;
if (externalLeading) (*externalLeading) = 0; // ??
+#endif
}
void wxWindowGTK::SetFocus()
gdk_window_warp_pointer( window, x, y );
}
+
void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
{
if (!m_widget) return;
if (!m_widget->window) return;
-
+
#ifndef __WXGTK20__
if (g_isIdle)
wxapp_install_idle_handler();
#ifdef __WXGTK20__
if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window)
gdk_window_process_updates( GTK_PIZZA(m_wxwindow)->bin_window, FALSE );
-#endif
-
+#else
if (!m_updateRegion.IsEmpty())
GtkSendPaintEvents();
+#endif
}
void wxWindowGTK::GtkSendPaintEvents()
{
if (!m_wxwindow)
{
+#ifndef __WXGTK20__
m_clearRegion.Clear();
+#endif
m_updateRegion.Clear();
return;
}
+ // Clip to paint region in wxClientDC
+ m_clipPaintRegion = TRUE;
+
+#ifndef __WXGTK20__
// widget to draw on
GtkPizza *pizza = GTK_PIZZA (m_wxwindow);
- // Clip to paint region in wxClientDC
- m_clipPaintRegion = TRUE;
-
+ // later for GTK 2.0, too.
if (GetThemeEnabled())
{
// find ancestor from which to steal background
}
}
else
- // if (!m_clearRegion.IsEmpty()) // always send an erase event
+#endif
+
+#ifdef __WXGTK20__
+ {
+ wxWindowDC dc( (wxWindow*)this );
+ dc.SetClippingRegion( m_updateRegion );
+
+ wxEraseEvent erase_event( GetId(), &dc );
+ erase_event.SetEventObject( this );
+
+ GetEventHandler()->ProcessEvent(erase_event);
+ }
+#else
+ // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
{
wxWindowDC dc( (wxWindow*)this );
- dc.SetClippingRegion( m_clearRegion );
+ if (m_clearRegion.IsEmpty())
+ dc.SetClippingRegion( m_updateRegion );
+ else
+ dc.SetClippingRegion( m_clearRegion );
wxEraseEvent erase_event( GetId(), &dc );
erase_event.SetEventObject( this );
}
m_clearRegion.Clear();
}
+#endif
wxNcPaintEvent nc_paint_event( GetId() );
nc_paint_event.SetEventObject( this );
{
wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
+#ifndef __WXGTK20__
if (m_wxwindow && m_wxwindow->window)
{
m_clearRegion.Clear();
// Better do this in idle?
GtkUpdate();
}
+#endif
}
#if wxUSE_TOOLTIPS
GetClientSize( &cw, &ch );
m_clearRegion.Intersect( 0, 0, cw, ch );
}
+#endif
+
m_clipPaintRegion = TRUE;
gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy );
m_clipPaintRegion = FALSE;
-#else
-
- gdk_window_scroll( GTK_PIZZA(m_wxwindow)->bin_window, dx, dy );
-
- GTK_PIZZA(m_wxwindow)->xoffset += dx;
- GTK_PIZZA(m_wxwindow)->yoffset += dy;
-
-#endif
-
}