X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ff805cac748d91edbf55d82a7f1b567d5d4d3cc0..fdb47e62b9f47f234bb0d34aa45dd1a44fdd1cbe:/src/gtk/textctrl.cpp diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index b44668c172..4d122f9757 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -198,14 +198,9 @@ static void wxGtkTextApplyTagsFromAttr(GtkWidget *text, wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXINDENT", start, end); // Convert indent from 1/10th of a mm into pixels - float factor; -#if GTK_CHECK_VERSION(2,2,0) - if (!gtk_check_version(2,2,0)) - factor = (float)gdk_screen_get_width(gtk_widget_get_screen(text)) / + float factor = + (float)gdk_screen_get_width(gtk_widget_get_screen(text)) / gdk_screen_get_width_mm(gtk_widget_get_screen(text)) / 10; - else -#endif - factor = (float)gdk_screen_width() / gdk_screen_width_mm() / 10; const int indent = (int)(factor * attr.GetLeftIndent()); const int subIndent = (int)(factor * attr.GetLeftSubIndent()); @@ -260,14 +255,9 @@ static void wxGtkTextApplyTagsFromAttr(GtkWidget *text, if (!tag) { // Factor to convert from 1/10th of a mm into pixels - float factor; -#if GTK_CHECK_VERSION(2,2,0) - if (!gtk_check_version(2,2,0)) - factor = (float)gdk_screen_get_width(gtk_widget_get_screen(text)) / + float factor = + (float)gdk_screen_get_width(gtk_widget_get_screen(text)) / gdk_screen_get_width_mm(gtk_widget_get_screen(text)) / 10; - else -#endif - factor = (float)gdk_screen_width() / gdk_screen_width_mm() / 10; PangoTabArray* tabArray = pango_tab_array_new(tabs.GetCount(), TRUE); for (size_t i = 0; i < tabs.GetCount(); i++) @@ -536,7 +526,7 @@ handle_text_clipboard_callback( GtkWidget *widget, wxTextCtrl *win, { wxClipboardTextEvent event( eventType, win->GetId() ); event.SetEventObject( win ); - if ( win->GetEventHandler()->ProcessEvent( event ) ) + if ( win->HandleWindowEvent( event ) ) { // don't let the default processing to take place if we did something // ourselves in the event handler @@ -624,7 +614,6 @@ void wxTextCtrl::Init() SetUpdateFont(false); m_text = NULL; - m_freezeCount = 0; m_showPositionOnThaw = NULL; m_gdkHandCursor = NULL; m_gdkXTermCursor = NULL; @@ -711,6 +700,7 @@ bool wxTextCtrl::Create( wxWindow *parent, if (style & wxNO_BORDER) g_object_set (m_text, "has-frame", FALSE, NULL); + } m_parent->DoAddChild( this ); @@ -747,9 +737,6 @@ bool wxTextCtrl::Create( wxWindow *parent, if (style & wxTE_READONLY) GTKSetEditable(); - if (style & wxTE_PROCESS_ENTER) - GTKSetActivatesDefault(); - // left justification (alignment) is the default anyhow if ( style & (wxTE_RIGHT | wxTE_CENTRE) ) GTKSetJustification(); @@ -792,6 +779,13 @@ bool wxTextCtrl::Create( wxWindow *parent, au_check_range(&start, &end); } } + else // single line + { + // do the right thing with Enter presses depending on whether we have + // wxTE_PROCESS_ENTER or not + GTKSetActivatesDefault(); + } + g_signal_connect (m_text, "copy-clipboard", G_CALLBACK (gtk_copy_clipboard_callback), this); @@ -857,17 +851,7 @@ void wxTextCtrl::GTKSetWrapMode() else if ( HasFlag( wxTE_WORDWRAP ) ) wrap = GTK_WRAP_WORD; else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0 - { - // GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4 -#ifdef __WXGTK24__ - if ( !gtk_check_version(2,4,0) ) - { - wrap = GTK_WRAP_WORD_CHAR; - } - else -#endif // __WXGTK24__ - wrap = GTK_WRAP_WORD; - } + wrap = GTK_WRAP_WORD_CHAR; gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), wrap ); } @@ -888,23 +872,16 @@ void wxTextCtrl::GTKSetJustification() } else // single line { -#ifdef __WXGTK24__ - // gtk_entry_set_alignment was introduced in gtk+-2.3.5 - if (!gtk_check_version(2,4,0)) - { - gfloat align; - if ( HasFlag(wxTE_RIGHT) ) - align = 1.0; - else if ( HasFlag(wxTE_CENTRE) ) - align = 0.5; - else // single line - align = 0.0; - - gtk_entry_set_alignment(GTK_ENTRY(m_text), align); - } -#endif // __WXGTK24__ - } + gfloat align; + if ( HasFlag(wxTE_RIGHT) ) + align = 1.0; + else if ( HasFlag(wxTE_CENTRE) ) + align = 0.5; + else // single line + align = 0.0; + gtk_entry_set_alignment(GTK_ENTRY(m_text), align); + } } void wxTextCtrl::SetWindowStyleFlag(long style) @@ -1550,7 +1527,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject(this); event.SetString(GetValue()); - if ( GetEventHandler()->ProcessEvent(event) ) + if ( HandleWindowEvent(event) ) return; } } @@ -1741,58 +1718,50 @@ wxSize wxTextCtrl::DoGetBestSize() const // freeze/thaw // ---------------------------------------------------------------------------- -void wxTextCtrl::Freeze() +void wxTextCtrl::DoFreeze() { wxCHECK_RET(m_text != NULL, wxT("invalid text ctrl")); if ( HasFlag(wxTE_MULTILINE) ) { - if (m_freezeCount++ == 0) - { - // freeze textview updates and remove buffer - g_signal_connect (m_text, "expose_event", - G_CALLBACK (gtk_text_exposed_callback), this); - g_signal_connect (m_widget, "expose_event", - G_CALLBACK (gtk_text_exposed_callback), this); - gtk_widget_set_sensitive(m_widget, false); - g_object_ref(m_buffer); - GtkTextBuffer* buf_new = gtk_text_buffer_new(NULL); - GtkTextMark* mark = GTK_TEXT_VIEW(m_text)->first_para_mark; - gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), buf_new); - // gtk_text_view_set_buffer adds its own reference - g_object_unref(buf_new); - // This mark should be deleted when the buffer is changed, - // but it's not (in GTK+ up to at least 2.10.6). - // Otherwise these anonymous marks start to build up in the buffer, - // and Freeze takes longer and longer each time it is called. - if (GTK_IS_TEXT_MARK(mark) && !gtk_text_mark_get_deleted(mark)) - gtk_text_buffer_delete_mark(m_buffer, mark); - } - } -} - -void wxTextCtrl::Thaw() + // freeze textview updates and remove buffer + g_signal_connect (m_text, "expose_event", + G_CALLBACK (gtk_text_exposed_callback), this); + g_signal_connect (m_widget, "expose_event", + G_CALLBACK (gtk_text_exposed_callback), this); + gtk_widget_set_sensitive(m_widget, false); + g_object_ref(m_buffer); + GtkTextBuffer* buf_new = gtk_text_buffer_new(NULL); + GtkTextMark* mark = GTK_TEXT_VIEW(m_text)->first_para_mark; + gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), buf_new); + // gtk_text_view_set_buffer adds its own reference + g_object_unref(buf_new); + // This mark should be deleted when the buffer is changed, + // but it's not (in GTK+ up to at least 2.10.6). + // Otherwise these anonymous marks start to build up in the buffer, + // and Freeze takes longer and longer each time it is called. + if (GTK_IS_TEXT_MARK(mark) && !gtk_text_mark_get_deleted(mark)) + gtk_text_buffer_delete_mark(m_buffer, mark); + } +} + +void wxTextCtrl::DoThaw() { if ( HasFlag(wxTE_MULTILINE) ) { - wxCHECK_RET(m_freezeCount != 0, _T("Thaw() without matching Freeze()")); - - if (--m_freezeCount == 0) + // Reattach buffer and thaw textview updates + gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), m_buffer); + g_object_unref(m_buffer); + gtk_widget_set_sensitive(m_widget, true); + g_signal_handlers_disconnect_by_func (m_widget, + (gpointer) gtk_text_exposed_callback, this); + g_signal_handlers_disconnect_by_func (m_text, + (gpointer) gtk_text_exposed_callback, this); + if (m_showPositionOnThaw != NULL) { - // Reattach buffer and thaw textview updates - gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), m_buffer); - g_object_unref(m_buffer); - gtk_widget_set_sensitive(m_widget, true); - g_signal_handlers_disconnect_by_func (m_widget, - (gpointer) gtk_text_exposed_callback, this); - g_signal_handlers_disconnect_by_func (m_text, - (gpointer) gtk_text_exposed_callback, this); - if (m_showPositionOnThaw != NULL) - { - gtk_text_view_scroll_mark_onscreen( - GTK_TEXT_VIEW(m_text), m_showPositionOnThaw); - m_showPositionOnThaw = NULL; - } + gtk_text_view_scroll_mark_onscreen( + GTK_TEXT_VIEW(m_text), m_showPositionOnThaw); + m_showPositionOnThaw = NULL; } } } @@ -1846,8 +1815,8 @@ void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent& event) InitCommandEvent(url_event); // Is that a good idea? Seems not (pleasure with gtk_text_view_start_selection_drag) - //event.Skip(!GetEventHandler()->ProcessEvent(url_event)); - GetEventHandler()->ProcessEvent(url_event); + //event.Skip(!HandleWindowEvent(url_event)); + HandleWindowEvent(url_event); } bool wxTextCtrl::GTKProcessEvent(wxEvent& event) const