}
-struct wxGtkIMData
-{
- GtkIMContext *context;
- GdkEventKey *lastKeyEvent;
-
- wxGtkIMData()
- {
- context = gtk_im_multicontext_new();
- lastKeyEvent = NULL;
- }
- ~wxGtkIMData()
- {
- g_object_unref (context);
- }
-};
-
namespace
{
int command = ancestor->GetAcceleratorTable()->GetCommand( event );
if (command != -1)
{
- wxCommandEvent menu_event( wxEVT_COMMAND_MENU_SELECTED, command );
+ wxCommandEvent menu_event( wxEVT_MENU, command );
ret = ancestor->HandleWindowEvent( menu_event );
if ( !ret )
// if the accelerator wasn't handled as menu event, try
// it as button click (for compatibility with other
// platforms):
- wxCommandEvent button_event( wxEVT_COMMAND_BUTTON_CLICKED, command );
+ wxCommandEvent button_event( wxEVT_BUTTON, command );
ret = ancestor->HandleWindowEvent( button_event );
}
return_after_IM = true;
}
- if (!ret && win->m_imData)
+ if ( !ret )
{
- win->m_imData->lastKeyEvent = gdk_event;
+ // Indicate that IM handling is in process by setting this pointer
+ // (which will remain valid for all the code called during IM key
+ // handling).
+ win->m_imKeyEvent = gdk_event;
// We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
// docs, if IM filter returns true, no further processing should be done.
// we should send the key_down event anyway.
- bool intercepted_by_IM =
- gtk_im_context_filter_keypress(win->m_imData->context, gdk_event) != 0;
- win->m_imData->lastKeyEvent = NULL;
- if (intercepted_by_IM)
+ const int intercepted_by_IM = win->GTKIMFilterKeypress(gdk_event);
+
+ win->m_imKeyEvent = NULL;
+
+ if ( intercepted_by_IM )
{
wxLogTrace(TRACE_KEYS, wxT("Key event intercepted by IM"));
return TRUE;
}
}
+int wxWindowGTK::GTKIMFilterKeypress(GdkEventKey* event) const
+{
+ return m_imContext ? gtk_im_context_filter_keypress(m_imContext, event)
+ : FALSE;
+}
+
extern "C" {
static void
gtk_wxwindow_commit_cb (GtkIMContext * WXUNUSED(context),
const gchar *str,
wxWindow *window)
+{
+ // Ignore the return value here, it doesn't matter for the "commit" signal.
+ window->GTKDoInsertTextFromIM(str);
+}
+}
+
+bool wxWindowGTK::GTKDoInsertTextFromIM(const char* str)
{
wxKeyEvent event( wxEVT_CHAR );
// take modifiers, cursor position, timestamp etc. from the last
// key_press_event that was fed into Input Method:
- if (window->m_imData->lastKeyEvent)
+ if ( m_imKeyEvent )
{
- wxFillOtherKeyEventFields(event,
- window, window->m_imData->lastKeyEvent);
+ wxFillOtherKeyEventFields(event, this, m_imKeyEvent);
}
else
{
- event.SetEventObject( window );
+ event.SetEventObject(this);
}
const wxString data(wxGTK_CONV_BACK_SYS(str));
if( data.empty() )
- return;
+ return false;
+ bool processed = false;
for( wxString::const_iterator pstr = data.begin(); pstr != data.end(); ++pstr )
{
#if wxUSE_UNICODE
AdjustCharEventKeyCodes(event);
- window->HandleWindowEvent(event);
+ if ( HandleWindowEvent(event) )
+ processed = true;
}
+
+ return processed;
}
+
+bool wxWindowGTK::GTKOnInsertText(const char* text)
+{
+ if ( !m_imKeyEvent )
+ {
+ // We're not inside IM key handling at all.
+ return false;
+ }
+
+ return GTKDoInsertTextFromIM(text);
}
// FIXME: Get these values from GTK or GDK
event.m_linesPerAction = 3;
+ event.m_columnsPerAction = 3;
event.m_wheelDelta = 120;
// Determine the scroll direction.
if (w < 0) w = 0;
if (h < 0) h = 0;
}
- if (win->m_oldClientWidth != w || win->m_oldClientHeight != h)
- {
- win->m_oldClientWidth = w;
- win->m_oldClientHeight = h;
+ GtkAllocation a;
+ gtk_widget_get_allocation(win->m_widget, &a);
+ // update position for widgets in native containers, such as wxToolBar
+ // (for widgets in a wxPizza, the values should already be the same)
+ win->m_x = a.x;
+ win->m_y = a.y;
+ win->m_useCachedClientSize = true;
+ if (win->m_clientWidth != w || win->m_clientHeight != h)
+ {
+ win->m_clientWidth = w;
+ win->m_clientHeight = h;
// this callback can be connected to m_wxwindow,
// so always get size from m_widget->allocation
- GtkAllocation a;
- gtk_widget_get_allocation(win->m_widget, &a);
win->m_width = a.width;
win->m_height = a.height;
if (!win->m_nativeSizeEvent)
static void style_updated(GtkWidget*, GtkStyle*, wxWindow* win)
#endif
{
- if (win->IsTopLevel())
- {
- wxSysColourChangedEvent event;
- event.SetEventObject(win);
- win->GTKProcessEvent(event);
- }
- else
- {
- // Border width could change, which will change client size.
- // Make sure size event occurs for this
- win->m_oldClientWidth = 0;
- }
+ wxSysColourChangedEvent event;
+ event.SetEventObject(win);
+ win->GTKProcessEvent(event);
}
//-----------------------------------------------------------------------------
if (IsFrozen())
DoFreeze();
- if (m_imData)
+ GdkWindow* const window = GTKGetDrawingWindow();
+
+ if (m_imContext)
{
gtk_im_context_set_client_window
(
- m_imData->context,
- m_wxwindow ? GTKGetDrawingWindow()
+ m_imContext,
+ window ? window
: gtk_widget_get_window(m_widget)
);
}
#if wxGTK_HAS_COMPOSITING_SUPPORT
if (IsTransparentBackgroundSupported())
{
- GdkWindow* const window = GTKGetDrawingWindow();
if (window)
gdk_window_set_composited(window, true);
}
}
}
-
- // We cannot set colours and fonts before the widget
- // been realized, so we do this directly after realization
- // or otherwise in idle time
-
- if (m_needsStyleChange)
+#ifndef __WXGTK3__
+ if (window && (
+ m_backgroundStyle == wxBG_STYLE_PAINT ||
+ m_backgroundStyle == wxBG_STYLE_TRANSPARENT))
{
- SetBackgroundStyle(GetBackgroundStyle());
- m_needsStyleChange = false;
+ gdk_window_set_back_pixmap(window, NULL, false);
}
+#endif
wxWindowCreateEvent event(static_cast<wxWindow*>(this));
event.SetEventObject( this );
GTKUpdateCursor(true, false);
- if (m_wxwindow &&
- (IsTopLevel() || HasFlag(wxBORDER_RAISED | wxBORDER_SUNKEN | wxBORDER_THEME)))
+ if (m_wxwindow && IsTopLevel())
{
// attaching to style changed signal after realization avoids initial
// changes we don't care about
if (m_wxwindow)
{
- if (m_imData)
- gtk_im_context_set_client_window(m_imData->context, NULL);
+ if (m_imContext)
+ gtk_im_context_set_client_window(m_imContext, NULL);
- g_signal_handlers_disconnect_by_func(
- m_wxwindow, (void*)style_updated, this);
+ if (IsTopLevel())
+ {
+ g_signal_handlers_disconnect_by_func(
+ m_wxwindow, (void*)style_updated, this);
+ }
}
}
m_scrollPos[dir] = 0;
}
- m_oldClientWidth =
- m_oldClientHeight = 0;
+ m_clientWidth =
+ m_clientHeight = 0;
+ m_useCachedClientSize = false;
m_clipPaintRegion = false;
- m_needsStyleChange = false;
-
m_cursor = *wxSTANDARD_CURSOR;
- m_imData = NULL;
+ m_imContext = NULL;
+ m_imKeyEvent = NULL;
+
m_dirtyTabOrder = false;
}
Show( false );
// delete before the widgets to avoid a crash on solaris
- delete m_imData;
- m_imData = NULL;
+ if ( m_imContext )
+ {
+ g_object_unref(m_imContext);
+ m_imContext = NULL;
+ }
// avoid problem with GTK+ 2.18 where a frozen window causes the whole
// TLW to be frozen, and if the window is then destroyed, nothing ever
}
// Create input method handler
- m_imData = new wxGtkIMData;
+ m_imContext = gtk_im_multicontext_new();
// Cannot handle drawing preedited text yet
- gtk_im_context_set_use_preedit( m_imData->context, FALSE );
+ gtk_im_context_set_use_preedit( m_imContext, FALSE );
- g_signal_connect (m_imData->context, "commit",
+ g_signal_connect (m_imContext, "commit",
G_CALLBACK (gtk_wxwindow_commit_cb), this);
}
if (!WX_IS_PIZZA(gtk_widget_get_parent(m_widget)) && !GTK_IS_WINDOW(m_widget))
gtk_widget_set_size_request(m_widget, m_width, m_height);
+ // apply any font or color changes made before creation
+ GTKApplyWidgetStyle();
+
InheritAttributes();
SetLayoutDirection(wxLayout_Default);
height = m_height;
const bool sizeChange = m_width != width || m_height != height;
+
+ if (sizeChange)
+ m_useCachedClientSize = false;
+
if (sizeChange || m_x != x || m_y != y)
{
m_x = x;
{
// update these variables to keep size_allocate handler
// from sending another size event for this change
- GetClientSize( &m_oldClientWidth, &m_oldClientHeight );
+ DoGetClientSize(&m_clientWidth, &m_clientHeight);
wxSizeEvent event( wxSize(m_width,m_height), GetId() );
event.SetEventObject( this );
{
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
+ if (m_useCachedClientSize)
+ {
+ if (width) *width = m_clientWidth;
+ if (height) *height = m_clientHeight;
+ return;
+ }
+
int w = m_width;
int h = m_height;
"handling focus_in event for %s(%p, %s)",
GetClassInfo()->GetClassName(), this, GetLabel());
- if (m_imData)
- gtk_im_context_focus_in(m_imData->context);
+ if (m_imContext)
+ gtk_im_context_focus_in(m_imContext);
gs_currentFocus = this;
gs_pendingFocus = NULL;
"handling focus_out event for %s(%p, %s)",
GetClassInfo()->GetClassName(), this, GetLabel());
- if (m_imData)
- gtk_im_context_focus_out(m_imData->context);
+ if (m_imContext)
+ gtk_im_context_focus_out(m_imContext);
if ( gs_currentFocus != this )
{
bool wxWindowGTK::SetBackgroundColour( const wxColour &colour )
{
- wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
-
if (!wxWindowBase::SetBackgroundColour(colour))
return false;
-#ifndef __WXGTK3__
- if (colour.IsOk())
+ if (m_widget)
{
- // We need the pixel value e.g. for background clearing.
- m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
- }
+#ifndef __WXGTK3__
+ if (colour.IsOk())
+ {
+ // We need the pixel value e.g. for background clearing.
+ m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
+ }
#endif
- // apply style change (forceStyle=true so that new style is applied
- // even if the bg colour changed from valid to wxNullColour)
- GTKApplyWidgetStyle(true);
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the bg colour changed from valid to wxNullColour)
+ GTKApplyWidgetStyle(true);
+ }
return true;
}
bool wxWindowGTK::SetForegroundColour( const wxColour &colour )
{
- wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
-
if (!wxWindowBase::SetForegroundColour(colour))
- {
return false;
- }
-#ifndef __WXGTK3__
- if (colour.IsOk())
+ if (m_widget)
{
- // We need the pixel value e.g. for background clearing.
- m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
- }
+#ifndef __WXGTK3__
+ if (colour.IsOk())
+ {
+ // We need the pixel value e.g. for background clearing.
+ m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
+ }
#endif
- // apply style change (forceStyle=true so that new style is applied
- // even if the bg colour changed from valid to wxNullColour):
- GTKApplyWidgetStyle(true);
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the bg colour changed from valid to wxNullColour):
+ GTKApplyWidgetStyle(true);
+ }
return true;
}
#ifndef __WXGTK3__
GdkWindow *window;
- if ( m_wxwindow )
+ if ((style == wxBG_STYLE_PAINT || style == wxBG_STYLE_TRANSPARENT) &&
+ (window = GTKGetDrawingWindow()))
{
- window = GTKGetDrawingWindow();
- }
- else
- {
- GtkWidget * const w = GetConnectWidget();
- window = w ? gtk_widget_get_window(w) : NULL;
- }
-
- bool wantNoBackPixmap = style == wxBG_STYLE_PAINT || style == wxBG_STYLE_TRANSPARENT;
-
- if ( wantNoBackPixmap )
- {
- if (window)
- {
- // Make sure GDK/X11 doesn't refresh the window
- // automatically.
- gdk_window_set_back_pixmap( window, NULL, FALSE );
- m_needsStyleChange = false;
- }
- else // window not realized yet
- {
- // Do when window is realized
- 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):
- GTKApplyWidgetStyle(true);
+ gdk_window_set_back_pixmap(window, NULL, false);
}
#endif // !__WXGTK3__
bool wxWindowGTK::SetFont( const wxFont &font )
{
- wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
-
if (!wxWindowBase::SetFont(font))
return false;
- // apply style change (forceStyle=true so that new style is applied
- // even if the font changed from valid to wxNullFont):
- GTKApplyWidgetStyle(true);
+ if (m_widget)
+ {
+ // apply style change (forceStyle=true so that new style is applied
+ // even if the font changed from valid to wxNullFont):
+ GTKApplyWidgetStyle(true);
+ }
return true;
}