X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/605c9c8318875c590fce53cd2ce5d5aabcc92564..e487524e492809638b7e335937c41fd432458a54:/src/gtk1/textctrl.cpp diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 7373c0ad2c..e99ff0e8b7 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -71,8 +71,8 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, SetValidator( validator ); - bool bMultiLine = (style & wxTE_MULTILINE) != 0; - if ( bMultiLine ) + 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 @@ -83,17 +83,17 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, // ... and put into the upper left hand corner of the table m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE); - gtk_table_attach(GTK_TABLE(m_widget), m_text, 0, 1, 0, 1, - GTK_FILL | GTK_EXPAND, - GTK_FILL | GTK_EXPAND | GTK_SHRINK, - 0, 0); + gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1, + (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), + (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), + 0, 0); // put the horizontal scrollbar in the lower left hand corner if (bHasHScrollbar) { GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj); gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0); gtk_widget_show(hscrollbar); @@ -103,7 +103,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, GtkWidget *vscrollbar = gtk_vscrollbar_new(GTK_TEXT(m_text)->vadj); gtk_table_attach(GTK_TABLE(m_widget), vscrollbar, 1, 2, 0, 1, GTK_FILL, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK), 0, 0); gtk_widget_show( vscrollbar ); } @@ -125,7 +125,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, PostCreation(); - if (bMultiLine) + if (multi_line) { gtk_widget_realize(m_text); gtk_widget_show(m_text); @@ -143,12 +143,20 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, SetInsertionPointEnd(); } - if (style & wxTE_READONLY) + if (style & wxTE_PASSWORD) { + if (!multi_line) + gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE ); + } + + if (style & wxTE_READONLY) + { + if (!multi_line) + gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE ); } else { - if (bMultiLine) + if (multi_line) gtk_text_set_editable( GTK_TEXT(m_text), 1 ); } @@ -348,18 +356,43 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) ) wxFAIL_MSG( "wxTextCtrl::OnDropFiles not implemented" ); } -long wxTextCtrl::PositionToXY( long WXUNUSED(pos), long *WXUNUSED(x), long *WXUNUSED(y) ) const +long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const { - wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" ); + if (!(m_windowStyle & wxTE_MULTILINE)) + return 0; + gint len = gtk_text_get_length( GTK_TEXT(m_text) ); + char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); + if(!text) + return 0; + if( pos >= len) + return pos=len-1; - return 0; + *x=1; // Col 1 + *y=1; // Line 1 + for (int i = 0; i < pos; i++ ) + { + if (text[i] == '\n') + { + (*y)++; + *x=1; + } + else + (*x)++; + } + g_free( text ); + return 1; } -long wxTextCtrl::XYToPosition( long WXUNUSED(x), long WXUNUSED(y) ) const +long wxTextCtrl::XYToPosition(long x, long y ) const { - wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" ); + if (!(m_windowStyle & wxTE_MULTILINE)) + return 0; + long pos=0; - return 0; + for(int i=1;i