#include <pango/pangox.h>
#endif
-#ifdef __WXGTK20__
- #define SET_CONTAINER_FOCUS(w, d) gtk_widget_child_focus((w), (d))
-#else
- #define SET_CONTAINER_FOCUS(w, d) gtk_container_focus(GTK_CONTAINER(w), (d))
-#endif
#ifdef __WXGTK20__
#ifdef HAVE_XIM
#ifndef __WXUNIVERSAL__
GtkPizza *pizza = GTK_PIZZA (widget);
- if (win->GetThemeEnabled())
+ if (win->GetThemeEnabled() && win->GetBackgroundStyle() == wxBG_STYLE_SYSTEM)
{
wxWindow *parent = win->GetParent();
while (parent && !parent->IsTopLevel())
return ks < 256;
}
+static void wxFillOtherKeyEventFields(wxKeyEvent& event,
+ wxWindowGTK *win,
+ GdkEventKey *gdk_event)
+{
+ int x = 0;
+ int y = 0;
+ GdkModifierType state;
+ if (gdk_event->window)
+ gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
+
+ event.SetTimestamp( gdk_event->time );
+ event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0;
+ event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0;
+ event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0;
+ event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK) != 0;
+ event.m_scanCode = gdk_event->keyval;
+ event.m_rawCode = (wxUint32) gdk_event->keyval;
+ event.m_rawFlags = 0;
+ event.m_x = x;
+ event.m_y = y;
+ event.SetEventObject( win );
+}
+
+
static bool
wxTranslateGTKKeyEventToWx(wxKeyEvent& event,
wxWindowGTK *win,
return FALSE;
// now fill all the other fields
- int x = 0;
- int y = 0;
- GdkModifierType state;
- if (gdk_event->window)
- gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
-
- event.SetTimestamp( gdk_event->time );
- event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0;
- event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0;
- event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0;
- event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK) != 0;
+ wxFillOtherKeyEventFields(event, win, gdk_event);
+
event.m_keyCode = key_code;
- event.m_scanCode = gdk_event->keyval;
- event.m_rawCode = (wxUint32) gdk_event->keyval;
- event.m_rawFlags = 0;
- event.m_x = x;
- event.m_y = y;
- event.SetEventObject( win );
return TRUE;
}
+#ifdef __WXGTK20__
+struct wxGtkIMData
+{
+ GtkIMContext *context;
+ GdkEventKey *lastKeyEvent;
+
+ wxGtkIMData()
+ {
+ context = gtk_im_multicontext_new();
+ lastKeyEvent = NULL;
+ }
+ ~wxGtkIMData()
+ {
+ g_object_unref(context);
+ }
+};
+#endif
+
static gint gtk_window_key_press_callback( GtkWidget *widget,
GdkEventKey *gdk_event,
wxWindow *win )
return FALSE;
if (g_blockEventsOnDrag)
return FALSE;
-
+
#ifdef __WXGTK20__
- if (win->m_imContext)
- {
- // In GTK 2.0, we need to hand over the key event to an input method
- // and the IM will emit a "commit" event containing the actual utf8
- // character. In that case the EVT_CHAR events will be sent from
- // there.
- if ( gtk_im_context_filter_keypress(win->m_imContext, gdk_event) )
- return TRUE;
- }
+ // We have to pass key press events through GTK+'s Input Method context
+ // object in order to get correct characters. By doing so, we loose the
+ // ability to let other GTK+'s handlers (namely, widgets' default signal
+ // handlers) handle the signal by returning false from this callback.
+ // Because GTK+ sends the events to parent widgets as well, we can't
+ // afford loosing it, otherwise native widgets inserted into wxPanel
+ // would break in subtle ways (e.g. spacebar would no longer toggle
+ // wxCheckButton's state). Therefore, we only pass the event to IM if it
+ // originated in this window's widget, which we detect by checking if we've
+ // seen the same event before (no events from children are lost this way,
+ // because gtk_window_key_press_callback is installed for native controls
+ // as well and the wxKeyEvent it creates propagates upwards).
+ static GdkEventKey s_lastEvent;
+
+ bool useIM = (win->m_imData != NULL) &&
+ memcmp(gdk_event, &s_lastEvent, sizeof(GdkEventKey)) != 0;
+
+ s_lastEvent = *gdk_event;
#endif
-
+
wxKeyEvent event( wxEVT_KEY_DOWN );
if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) )
{
// unknown key pressed, ignore (the event would be useless anyhow)
+#ifdef __WXGTK20__
+ if ( useIM )
+ {
+ // it may be useful for the input method, though:
+ win->m_imData->lastKeyEvent = gdk_event;
+ bool ret = gtk_im_context_filter_keypress(win->m_imData->context,
+ gdk_event);
+ win->m_imData->lastKeyEvent = NULL;
+ return ret;
+ }
+#endif
return FALSE;
}
// will only be sent if it is not in an accelerator table.
if (!ret)
{
+#ifdef __WXGTK20__
+ if (useIM)
+ {
+ // In GTK 2.0, we need to hand over the key event to an input method
+ // and the IM will emit a "commit" event containing the actual utf8
+ // character. In that case the EVT_CHAR events will be sent from
+ // there.
+ win->m_imData->lastKeyEvent = gdk_event;
+ if ( gtk_im_context_filter_keypress(win->m_imData->context,
+ gdk_event) )
+ {
+ win->m_imData->lastKeyEvent = NULL;
+ wxLogTrace(TRACE_KEYS, _T("Key event intercepted by IM"));
+ return TRUE;
+ }
+ else
+ win->m_imData->lastKeyEvent = NULL;
+ }
+#endif
+
long key_code;
KeySym keysym = gdk_event->keyval;
// Find key code for EVT_CHAR and EVT_CHAR_HOOK events
const gchar *str,
wxWindow *window)
{
- bool ret = FALSE;
-
wxKeyEvent event( wxEVT_KEY_DOWN );
-#if wxUSE_UNICODE
- event.m_uniChar = g_utf8_get_char( str );
+ // take modifiers, cursor position, timestamp etc. from the last
+ // key_press_event that was fed into Input Method:
+ if (window->m_imData->lastKeyEvent)
+ {
+ wxFillOtherKeyEventFields(event,
+ window, window->m_imData->lastKeyEvent);
+ }
- // Backward compatible for ISO-8859
- if (event.m_uniChar < 256)
- event.m_keyCode = event.m_uniChar;
+#if wxUSE_UNICODE
+ const wxWCharBuffer data = wxConvUTF8.cMB2WC( (char*)str );
#else
- wchar_t unistr[2];
- unistr[0] = g_utf8_get_char(str);
- unistr[1] = 0;
- wxCharBuffer ansistr(wxConvLocal.cWC2MB(unistr));
- // We cannot handle characters that cannot be represented in
- // current locale's charset in non-Unicode mode:
- if (ansistr.data() == NULL) return;
-
- event.m_keyCode = ansistr[0u];
-#endif
-
-
- // TODO: We still need to set all the extra attributes of the
- // event, modifiers and such...
+ const wxWCharBuffer wdata = wxConvUTF8.cMB2WC( (char*)str );
+ const wxCharBuffer data = wxConvLocal.cWC2MB( wdata );
+#endif // wxUSE_UNICODE
+ if( !(const wxChar*)data )
+ return;
+ bool ret = false;
// Implement OnCharHook by checking ancestor top level windows
wxWindow *parent = window;
while (parent && !parent->IsTopLevel())
parent = parent->GetParent();
- if (parent)
- {
- event.SetEventType( wxEVT_CHAR_HOOK );
- ret = parent->GetEventHandler()->ProcessEvent( event );
- }
- if (!ret)
+ for( const wxChar* pstr = data; *pstr; pstr++ )
{
- event.SetEventType(wxEVT_CHAR);
- ret = window->GetEventHandler()->ProcessEvent( event );
+#if wxUSE_UNICODE
+ event.m_uniChar = *pstr;
+ // Backward compatible for ISO-8859
+ event.m_keyCode = *pstr < 256 ? event.m_uniChar : 0;
+ wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), event.m_uniChar);
+#else
+ event.m_keyCode = *pstr;
+#endif // wxUSE_UNICODE
+ if (parent)
+ {
+ event.SetEventType( wxEVT_CHAR_HOOK );
+ ret = parent->GetEventHandler()->ProcessEvent( event );
+ }
+
+ if (!ret)
+ {
+ event.SetEventType(wxEVT_CHAR);
+ ret = window->GetEventHandler()->ProcessEvent( event );
+ }
}
}
#endif
if (event.GetEventType() == wxEVT_MOUSEWHEEL)
{
event.m_linesPerAction = 3;
+ event.m_wheelDelta = 120;
if (((GdkEventButton*)gdk_event)->button == 4)
event.m_wheelRotation = 120;
else if (((GdkEventButton*)gdk_event)->button == 5)
// a chance to correct this
win->FixUpMouseEvent(widget, event.m_x, event.m_y);
+ if ( event_type == wxEVT_RIGHT_DOWN )
+ {
+ // generate a "context menu" event: this is similar to right mouse
+ // click under many GUIs except that it is generated differently
+ // (right up under MSW, ctrl-click under Mac, right down here) and
+ //
+ // (a) it's a command event and so is propagated to the parent
+ // (b) under MSW it can be generated from kbd too
+ // (c) it uses screen coords (because of (a))
+ wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
+ win->GetId(),
+ win->ClientToScreen(event.GetPosition()));
+ (void)win->GetEventHandler()->ProcessEvent(evtCtx);
+ }
+
// find the correct window to send the event too: it may be a different one
// from the one which got it at GTK+ level because some control don't have
// their own X window and thus cannot get any events.
gs_timeLastClick = gdk_event->time;
-/*
- wxPrintf( wxT("2) OnButtonPress from ") );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- wxPrintf( win->GetClassInfo()->GetClassName() );
- wxPrintf( wxT(".\n") );
-*/
-
#ifndef __WXGTK20__
if (event_type == wxEVT_LEFT_DCLICK)
{
// same wxListBox hack as above
win->FixUpMouseEvent(widget, event.m_x, event.m_y);
- if ( event_type == wxEVT_RIGHT_UP )
- {
- // generate a "context menu" event: this is similar to wxEVT_RIGHT_UP
- // except that:
- //
- // (a) it's a command event and so is propagated to the parent
- // (b) under MSW it can be generated from kbd too
- // (c) it uses screen coords (because of (a))
- wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
- win->GetId(),
- win->ClientToScreen(event.GetPosition()));
- (void)win->GetEventHandler()->ProcessEvent(evtCtx);
- }
-
if ( !g_captureWindow )
win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
event.m_linesPerAction = 3;
+ event.m_wheelDelta = 120;
if (gdk_event->direction == GDK_SCROLL_UP)
event.m_wheelRotation = 120;
else
if (g_isIdle)
wxapp_install_idle_handler();
+#ifdef __WXGTK20__
+ if (win->m_imData)
+ gtk_im_context_focus_in(win->m_imData->context);
+#endif
+
if (!win->m_hasVMT) return FALSE;
if (g_blockEventsOnDrag) return FALSE;
if (g_isIdle)
wxapp_install_idle_handler();
+#ifdef __WXGTK20__
+ if (win->m_imData)
+ gtk_im_context_focus_out(win->m_imData->context);
+#endif
+
if (!win->m_hasVMT) return FALSE;
if (g_blockEventsOnDrag) return FALSE;
wxapp_install_idle_handler();
#ifdef __WXGTK20__
- if (win->m_imContext)
+ if (win->m_imData)
{
GtkPizza *pizza = GTK_PIZZA( m_widget );
- gtk_im_context_set_client_window( win->m_imContext, pizza->bin_window );
+ gtk_im_context_set_client_window( win->m_imData->context,
+ pizza->bin_window );
}
#endif
m_clipPaintRegion = FALSE;
+ m_needsStyleChange = false;
+
m_cursor = *wxSTANDARD_CURSOR;
#ifdef __WXGTK20__
- m_imContext = NULL;
+ m_imData = NULL;
m_x11Context = NULL;
+ m_dirtyTabOrder = false;
#else
#ifdef HAVE_XIM
m_ic = (GdkIC*) NULL;
gtk_widget_destroy( m_widget );
m_widget = (GtkWidget*) NULL;
}
+
+#ifdef __WXGTK20__
+ delete m_imData;
+#endif
}
bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size )
#ifdef __WXGTK20__
// Create input method handler
- m_imContext = gtk_im_multicontext_new();
+ m_imData = new wxGtkIMData;
// Cannot handle drawing preedited text yet
- gtk_im_context_set_use_preedit( m_imContext, FALSE );
+ gtk_im_context_set_use_preedit( m_imData->context, FALSE );
- g_signal_connect (G_OBJECT (m_imContext), "commit",
+ g_signal_connect (G_OBJECT (m_imData->context), "commit",
G_CALLBACK (gtk_wxwindow_commit_cb), this);
#endif
(gpointer) this );
}
+ InheritAttributes();
+
m_hasVMT = TRUE;
// unless the window was created initially hidden (i.e. Hide() had been
void wxWindowGTK::OnInternalIdle()
{
+#ifdef __WXGTK20__
+ if ( m_dirtyTabOrder )
+ RealizeTabOrder();
+#endif
+ // Update style if the window was not yet realized
+ // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
+ if (m_needsStyleChange)
+ {
+ SetBackgroundStyle(GetBackgroundStyle());
+ m_needsStyleChange = false;
+ }
+
// Update invalidated regions.
GtkUpdate();
g_object_unref( G_OBJECT( layout ) );
- return (int) (rect.height / PANGO_SCALE);
+ return (int) PANGO_PIXELS(rect.height);
#else
GdkFont *gfont = font.GetInternalFont( 1.0 );
g_object_unref( G_OBJECT( layout ) );
- return (int) (rect.width / PANGO_SCALE);
+ return (int) PANGO_PIXELS(rect.width);
#else
GdkFont *gfont = font.GetInternalFont( 1.0 );
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);
+ pango_layout_get_extents(layout, NULL, &rect);
- if (x) (*x) = (wxCoord) (rect.width / PANGO_SCALE);
- if (y) (*y) = (wxCoord) (rect.height / PANGO_SCALE);
+ if (x) (*x) = (wxCoord) PANGO_PIXELS(rect.width);
+ if (y) (*y) = (wxCoord) PANGO_PIXELS(rect.height);
if (descent)
{
- // Do something about metrics here
- (*descent) = 0;
+ 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; // ??
void wxWindowGTK::SetFocus()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
-
if ( m_hasFocus )
{
// don't do anything if we already have focus
}
else if (m_widget)
{
+#ifdef __WXGTK20__
+ if (GTK_IS_CONTAINER(m_widget))
+ {
+ gtk_widget_child_focus( m_widget, GTK_DIR_TAB_FORWARD );
+ }
+ else
+#endif
if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) )
{
+
if (!GTK_WIDGET_REALIZED(m_widget))
{
// we can't set the focus to the widget now so we remember that
gtk_widget_grab_focus (m_widget);
}
}
- else if (GTK_IS_CONTAINER(m_widget))
+ else
+#ifndef __WXGTK20__
+ if (GTK_IS_CONTAINER(m_widget))
{
- SET_CONTAINER_FOCUS( m_widget, GTK_DIR_TAB_FORWARD );
+ gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD );
}
else
+#endif
{
wxLogTrace(TRACE_FOCUS,
_T("Can't set focus to %s(%s)"),
(*m_insertCallback)(this, child);
}
+#ifdef __WXGTK20__
+
+void wxWindowGTK::AddChild(wxWindowBase *child)
+{
+ wxWindowBase::AddChild(child);
+ m_dirtyTabOrder = true;
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+}
+
+void wxWindowGTK::RemoveChild(wxWindowBase *child)
+{
+ wxWindowBase::RemoveChild(child);
+ m_dirtyTabOrder = true;
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+}
+
+void wxWindowGTK::DoMoveInTabOrder(wxWindow *win, MoveKind move)
+{
+ wxWindowBase::DoMoveInTabOrder(win, move);
+ m_dirtyTabOrder = true;
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+}
+
+void wxWindowGTK::RealizeTabOrder()
+{
+ if (m_wxwindow)
+ {
+ if (m_children.size() > 0)
+ {
+ GList *chain = NULL;
+
+ for (wxWindowList::const_iterator i = m_children.begin();
+ i != m_children.end(); ++i)
+ {
+ chain = g_list_prepend(chain, (*i)->m_widget);
+ }
+
+ chain = g_list_reverse(chain);
+
+ gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow), chain);
+ g_list_free(chain);
+ }
+ else
+ {
+ gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow));
+ }
+ }
+
+ m_dirtyTabOrder = false;
+}
+
+#endif // __WXGTK20__
+
void wxWindowGTK::Raise()
{
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
// widget to draw on
GtkPizza *pizza = GTK_PIZZA (m_wxwindow);
- if (GetThemeEnabled())
+ if (GetThemeEnabled() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM)
{
// find ancestor from which to steal background
wxWindow *parent = GetParent();
wxEraseEvent erase_event( GetId(), &dc );
erase_event.SetEventObject( this );
- if (!GetEventHandler()->ProcessEvent(erase_event))
+ if (!GetEventHandler()->ProcessEvent(erase_event) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM)
{
if (!g_eraseGC)
{
}
// apply style change (forceStyle=true so that new style is applied
- // even if the bg colour changed from valid to wxNullColour):
- ApplyWidgetStyle(true);
+ // even if the bg colour changed from valid to wxNullColour)
+ if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM)
+ ApplyWidgetStyle(true);
return true;
}
DoApplyWidgetStyle(style);
gtk_rc_style_unref(style);
}
+
+ // Style change may affect GTK+'s size calculation:
+ InvalidateBestSize();
}
void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style)
{
if (m_wxwindow)
- // should we also do m_widget in this case?
gtk_widget_modify_style(m_wxwindow, style);
- else
- gtk_widget_modify_style(m_widget, style);
+ gtk_widget_modify_style(m_widget, style);
}
+bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style)
+{
+ wxWindowBase::SetBackgroundStyle(style);
+
+ if (style == wxBG_STYLE_CUSTOM)
+ {
+ GdkWindow *window = (GdkWindow*) NULL;
+ if (m_wxwindow)
+ window = GTK_PIZZA(m_wxwindow)->bin_window;
+ else
+ window = GetConnectWidget()->window;
+
+ if (window)
+ {
+ // Make sure GDK/X11 doesn't refresh the window
+ // automatically.
+ gdk_window_set_back_pixmap( window, None, False );
+#ifdef __X__
+ Display* display = GDK_WINDOW_DISPLAY(window);
+ XFlush(display);
+#endif
+ m_needsStyleChange = false;
+ }
+ else
+ // Do in OnIdle, because the window is not yet available
+ m_needsStyleChange = true;
+
+ // Don't apply widget style, or we get a grey background
+ }
+ else
+ {
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the bg colour changed from valid to wxNullColour):
+ ApplyWidgetStyle(true);
+ }
+ return true;
+}
//-----------------------------------------------------------------------------
// Pop-up menu stuff
bool is_waiting = true;
- gtk_signal_connect( GTK_OBJECT(menu->m_menu),
- "hide",
- GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
- (gpointer)&is_waiting );
+ gulong handler = gtk_signal_connect( GTK_OBJECT(menu->m_menu),
+ "hide",
+ GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
+ (gpointer)&is_waiting );
wxPoint pos;
gpointer userdata;
gtk_main_iteration();
}
+ gtk_signal_disconnect(GTK_OBJECT(menu->m_menu), handler);
+
return true;
}