X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/828f655fd31ac19d83cf7ec14d0b207e9b254977..9d2f3c71d83c52fc4db6c8041de533562816b1d6:/src/gtk/textctrl.cpp diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 7c6817aa3e..96070607d3 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -37,24 +37,25 @@ extern bool g_blockEventsOnDrag; static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { - win->SetModified(); + if (!win->m_hasVMT) return; - win->CalculateScrollbar(); + win->SetModified(); wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->m_windowId ); - event.SetString( copystring(win->GetValue()) ); + event.SetString( win->GetValue() ); event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( event ); - delete[] event.GetString(); } //----------------------------------------------------------------------------- -// "size_allocate" +// "changed" from vertical scrollbar //----------------------------------------------------------------------------- static void -gtk_text_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* WXUNUSED(alloc), wxTextCtrl *win ) +gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) { + if (!win->m_hasVMT) return; + win->CalculateScrollbar(); } @@ -66,6 +67,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_CHAR(wxTextCtrl::OnChar) + + EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) + EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) + EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) + EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) + EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) + + EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) END_EVENT_TABLE() #ifndef NO_TEXT_WINDOW_STREAM @@ -113,19 +126,19 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, SetValidator( validator ); - m_vScrollbarVisible = TRUE; + m_vScrollbarVisible = FALSE; bool multi_line = (style & wxTE_MULTILINE) != 0; if ( multi_line ) { - // a multi-line edit control: create a vertical scrollbar by default and - // horizontal if requested + /* a multi-line edit control: create a vertical scrollbar by default and + horizontal if requested */ bool bHasHScrollbar = (style & wxHSCROLL) != 0; - // create our control... + /* create our control ... */ m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); - // ... and put into the upper left hand corner of the table + /* ... and put into the upper left hand corner of the table */ m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); @@ -134,7 +147,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 0); - // put the horizontal scrollbar in the lower left hand corner + /* put the horizontal scrollbar in the lower left hand corner */ if (bHasHScrollbar) { GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj); @@ -147,22 +160,13 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, gtk_widget_show(hscrollbar); } - // finally, put the vertical scrollbar in the upper right corner - m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj ); - GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS ); - - gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1, - GTK_FILL, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK), - 0, 0); - gtk_widget_show( m_vScrollbar ); + /* we create the vertical scrollbar on demand */ + m_vScrollbar = (GtkWidget*) NULL; - gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_text_size_callback), (gpointer)this ); } else { - // a single-line text control: no need for scrollbars + /* a single-line text control: no need for scrollbars */ m_widget = m_text = gtk_entry_new(); } @@ -184,7 +188,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, gtk_widget_show(m_text); } - // we want to be notified about text changes + /* we want to be notified about text changes */ gtk_signal_connect( GTK_OBJECT(m_text), "changed", GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); @@ -217,11 +221,17 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, if (multi_line) gtk_text_set_editable( GTK_TEXT(m_text), 1 ); } + + SetBackgroundColour( parent->GetBackgroundColour() ); + SetForegroundColour( parent->GetForegroundColour() ); Show( TRUE ); - SetBackgroundColour( parent->GetBackgroundColour() ); - SetForegroundColour( parent->GetForegroundColour() ); + if (multi_line) + { + gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed", + (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this ); + } return TRUE; } @@ -236,18 +246,30 @@ void wxTextCtrl::CalculateScrollbar() { if (m_vScrollbarVisible) { - gtk_widget_hide( m_vScrollbar ); + gtk_widget_hide( m_vScrollbar ); - m_vScrollbarVisible = FALSE; + m_vScrollbarVisible = FALSE; } } else { if (!m_vScrollbarVisible) { - gtk_widget_show( m_vScrollbar ); + if (!m_vScrollbar) + { + /* finally, put the vertical scrollbar in the upper right corner */ + m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj ); + GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS ); + + gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1, + GTK_FILL, + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK), + 0, 0); + } + + gtk_widget_show( m_vScrollbar ); - m_vScrollbarVisible = TRUE; + m_vScrollbarVisible = TRUE; } } } @@ -675,7 +697,7 @@ void wxTextCtrl::Cut() { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); -#if (GTK_MINOR_VERSION == 1) +#if (GTK_MINOR_VERSION > 0) gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 ); @@ -686,7 +708,7 @@ void wxTextCtrl::Copy() { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); -#if (GTK_MINOR_VERSION == 1) +#if (GTK_MINOR_VERSION > 0) gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 ); @@ -697,13 +719,78 @@ void wxTextCtrl::Paste() { wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); -#if (GTK_MINOR_VERSION == 1) +#if (GTK_MINOR_VERSION > 0) gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 ); #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) ; +} + +bool wxTextCtrl::CanPaste() const +{ + return IsEditable() ; +} + +// Undo/redo +void wxTextCtrl::Undo() +{ + // TODO + wxFAIL_MSG( "wxTextCtrl::Undo not implemented" ); +} + +void wxTextCtrl::Redo() +{ + // TODO + wxFAIL_MSG( "wxTextCtrl::Redo not implemented" ); +} + +bool wxTextCtrl::CanUndo() const +{ + // TODO + wxFAIL_MSG( "wxTextCtrl::CanUndo not implemented" ); + return FALSE; +} + +bool wxTextCtrl::CanRedo() const +{ + // TODO + wxFAIL_MSG( "wxTextCtrl::CanRedo not implemented" ); + return FALSE; +} + +// If the return values from and to are the same, there is no +// selection. +void wxTextCtrl::GetSelection(long* from, long* to) const +{ + // TODO + *from = 0; + *to = 0; + wxFAIL_MSG( "wxTextCtrl::GetSelection not implemented" ); +} + +bool wxTextCtrl::IsEditable() const +{ + // TODO + wxFAIL_MSG( "wxTextCtrl::IsEditable not implemented" ); + return FALSE; +} + void wxTextCtrl::Clear() { SetValue( "" ); @@ -867,3 +954,52 @@ void wxTextCtrl::ApplyWidgetStyle() } } +void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) +{ + Cut(); +} + +void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) +{ + Copy(); +} + +void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) +{ + Paste(); +} + +void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) +{ + Undo(); +} + +void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) +{ + Redo(); +} + +void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) +{ + event.Enable( CanCut() ); +} + +void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) +{ + event.Enable( CanCopy() ); +} + +void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) +{ + event.Enable( CanPaste() ); +} + +void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); +}