X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/17665a2b5c3e86e081963f9d40d45149a7aaa83e..2d2c394b59407ca3780a92a28ab12f63489c9cb1:/src/gtk/textctrl.cpp diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index bde02f7faa..f16643b0c7 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include // for fabs #include "gdk/gdk.h" #include "gtk/gtk.h" @@ -80,7 +81,6 @@ gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) // "focus_in_event" //----------------------------------------------------------------------------- -wxWindow *FindFocusedChild(wxWindow *win); extern wxWindow *g_focusWindow; extern bool g_blockEventsOnDrag; // extern bool g_isIdle; @@ -97,11 +97,9 @@ static gint gtk_text_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(ev g_focusWindow = win; - wxPanel *panel = wxDynamicCast(win->GetParent(), wxPanel); - if (panel) - { - panel->SetLastFocus(win); - } + // notify the parent that we got the focus + wxChildFocusEvent eventFocus(win); + (void)win->GetEventHandler()->ProcessEvent(eventFocus); #ifdef HAVE_XIM if (win->m_ic) @@ -124,7 +122,6 @@ static gint gtk_text_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(ev if (win->GetEventHandler()->ProcessEvent( event )) { - gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" ); return TRUE; } @@ -152,7 +149,7 @@ static gint gtk_text_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(e g_sendActivateEvent = 0; #endif - wxWindow *winFocus = FindFocusedChild(win); + wxWindow *winFocus = wxFindFocusedChild(win); if ( winFocus ) win = winFocus; @@ -179,7 +176,6 @@ static gint gtk_text_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(e if (win->GetEventHandler()->ProcessEvent( event )) { - gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_out_event" ); return TRUE; } @@ -565,19 +561,21 @@ void wxTextCtrl::AppendText( const wxString &text ) { if ( !m_defaultStyle.IsDefault() ) { - GdkFont *font = m_defaultStyle.HasFont() - ? m_defaultStyle.GetFont().GetInternalFont() - : NULL; + wxFont font = m_defaultStyle.HasFont() ? m_defaultStyle.GetFont() + : m_font; + GdkFont *fnt = font.Ok() ? font.GetInternalFont() : NULL; - GdkColor *colFg = m_defaultStyle.HasTextColour() - ? m_defaultStyle.GetTextColour().GetColor() - : NULL; + wxColour col = m_defaultStyle.HasTextColour() + ? m_defaultStyle.GetTextColour() + : m_foregroundColour; + GdkColor *colFg = col.Ok() ? col.GetColor() : NULL; - GdkColor *colBg = m_defaultStyle.HasBackgroundColour() - ? m_defaultStyle.GetBackgroundColour().GetColor() - : NULL; + col = m_defaultStyle.HasBackgroundColour() + ? m_defaultStyle.GetBackgroundColour() + : m_backgroundColour; + GdkColor *colBg = col.Ok() ? col.GetColor() : NULL; - gtk_text_insert( GTK_TEXT(m_text), font, colFg, colBg, txt, txtlen ); + gtk_text_insert( GTK_TEXT(m_text), fnt, colFg, colBg, txt, txtlen ); } else // no style { @@ -926,27 +924,6 @@ void wxTextCtrl::Paste() #endif } -bool wxTextCtrl::CanCopy() const -{ - // Can copy if there's a selection - long from, to; - GetSelection(& from, & to); - return (from != to) ; -} - -bool wxTextCtrl::CanCut() const -{ - // Can cut if there's a selection - long from, to; - GetSelection(& from, & to); - return (from != to) && (IsEditable()); -} - -bool wxTextCtrl::CanPaste() const -{ - return IsEditable() ; -} - // Undo/redo void wxTextCtrl::Undo() { @@ -1080,6 +1057,8 @@ bool wxTextCtrl::SetFont( const wxFont &font ) { m_updateFont = TRUE; + m_defaultStyle.SetFont(font); + ChangeFontGlobally(); } @@ -1096,10 +1075,10 @@ void wxTextCtrl::ChangeFontGlobally() wxString value = GetValue(); if ( !value.IsEmpty() ) { + m_updateFont = FALSE; + Clear(); AppendText(value); - - m_updateFont = FALSE; } } @@ -1124,7 +1103,8 @@ bool wxTextCtrl::SetBackgroundColour( const wxColour &colour ) { wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") ); - wxControl::SetBackgroundColour( colour ); + if ( !wxControl::SetBackgroundColour( colour ) ) + return FALSE; if (!m_widget->window) return FALSE; @@ -1312,3 +1292,81 @@ wxSize wxTextCtrl::DoGetBestSize() const wxSize ret( wxControl::DoGetBestSize() ); return wxSize(80, ret.y); } + +// ---------------------------------------------------------------------------- +// freeze/thaw +// ---------------------------------------------------------------------------- + +void wxTextCtrl::Freeze() +{ + if ( HasFlag(wxTE_MULTILINE) ) + { + gtk_text_freeze(GTK_TEXT(m_text)); + } +} + +void wxTextCtrl::Thaw() +{ + if ( HasFlag(wxTE_MULTILINE) ) + { + GTK_TEXT(m_text)->vadj->value = 0.0; + + gtk_text_thaw(GTK_TEXT(m_text)); + } +} + +// ---------------------------------------------------------------------------- +// scrolling +// ---------------------------------------------------------------------------- + +GtkAdjustment *wxTextCtrl::GetVAdj() const +{ + return HasFlag(wxTE_MULTILINE) ? GTK_TEXT(m_text)->vadj : NULL; +} + +bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff) +{ + float value = adj->value + diff; + + if ( value < 0 ) + value = 0; + + float upper = adj->upper - adj->page_size; + if ( value > upper ) + value = upper; + + // did we noticeably change the scroll position? + if ( fabs(adj->value - value) < 0.2 ) + { + // well, this is what Robert does in wxScrollBar, so it must be good... + return FALSE; + } + + adj->value = value; + + gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed"); + + return TRUE; +} + +bool wxTextCtrl::ScrollLines(int lines) +{ + GtkAdjustment *adj = GetVAdj(); + if ( !adj ) + return FALSE; + + // this is hardcoded to 10 in GTK+ 1.2 (great idea) + static const int KEY_SCROLL_PIXELS = 10; + + return DoScroll(adj, lines*KEY_SCROLL_PIXELS); +} + +bool wxTextCtrl::ScrollPages(int pages) +{ + GtkAdjustment *adj = GetVAdj(); + if ( !adj ) + return FALSE; + + return DoScroll(adj, (int)ceil(pages*adj->page_increment)); +} +