A bit more DnD and clipbrd updates
wxTextCtrl now hides the vertical until required git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -106,14 +106,17 @@ class wxTextCtrl: public wxControl, public streambuf
|
||||
|
||||
// implementation
|
||||
|
||||
GtkWidget* GetConnectWidget(void);
|
||||
GtkWidget* GetConnectWidget();
|
||||
bool IsOwnGtkWindow( GdkWindow *window );
|
||||
void ApplyWidgetStyle();
|
||||
void CalculateScrollbar();
|
||||
|
||||
private:
|
||||
|
||||
bool m_modified;
|
||||
GtkWidget *m_text;
|
||||
GtkWidget *m_vScrollbar;
|
||||
bool m_vScrollbarVisible;
|
||||
};
|
||||
|
||||
#endif // __GTKTEXTCTRLH__
|
||||
|
@@ -106,14 +106,17 @@ class wxTextCtrl: public wxControl, public streambuf
|
||||
|
||||
// implementation
|
||||
|
||||
GtkWidget* GetConnectWidget(void);
|
||||
GtkWidget* GetConnectWidget();
|
||||
bool IsOwnGtkWindow( GdkWindow *window );
|
||||
void ApplyWidgetStyle();
|
||||
void CalculateScrollbar();
|
||||
|
||||
private:
|
||||
|
||||
bool m_modified;
|
||||
GtkWidget *m_text;
|
||||
GtkWidget *m_vScrollbar;
|
||||
bool m_vScrollbarVisible;
|
||||
};
|
||||
|
||||
#endif // __GTKTEXTCTRLH__
|
||||
|
@@ -78,7 +78,6 @@ class MyPanel: public wxPanel
|
||||
void OnSpinUpdate( wxSpinEvent &event );
|
||||
void OnPasteFromClipboard( wxCommandEvent &event );
|
||||
void OnCopyToClipboard( wxCommandEvent &event );
|
||||
void OnCutToClipboard( wxCommandEvent &event );
|
||||
|
||||
wxListBox *m_listbox;
|
||||
wxChoice *m_choice;
|
||||
@@ -189,7 +188,6 @@ const int ID_COMBO_ENABLE = 147;
|
||||
const int ID_TEXT = 150;
|
||||
const int ID_PASTE_TEXT = 151;
|
||||
const int ID_COPY_TEXT = 152;
|
||||
const int ID_CUT_TEXT = 153;
|
||||
|
||||
const int ID_RADIOBOX = 160;
|
||||
const int ID_RADIOBOX_SEL_NUM = 161;
|
||||
@@ -245,7 +243,6 @@ BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
||||
EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
|
||||
EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
|
||||
EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
|
||||
EVT_BUTTON (ID_CUT_TEXT, MyPanel::OnCutToClipboard)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
|
||||
@@ -355,9 +352,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
|
||||
(*m_multitext) << " More text.";
|
||||
// m_multitext->SetBackgroundColour("wheat");
|
||||
(void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) );
|
||||
(void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,70), wxSize(110,30) );
|
||||
(void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,110), wxSize(110,30) );
|
||||
(void)new wxButton( panel, ID_CUT_TEXT, "Cut line 1", wxPoint(370,150), wxSize(110,30) );
|
||||
(void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,80), wxSize(110,30) );
|
||||
(void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,140), wxSize(110,30) );
|
||||
m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text);
|
||||
|
||||
wxString choices2[] =
|
||||
@@ -490,10 +486,6 @@ void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
|
||||
#endif
|
||||
}
|
||||
|
||||
void MyPanel::OnCutToClipboard( wxCommandEvent &WXUNUSED(event) )
|
||||
{
|
||||
}
|
||||
|
||||
void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
|
||||
{
|
||||
int x = 0;
|
||||
|
@@ -307,6 +307,22 @@ bool wxClipboard::SetData( wxDataObject *data )
|
||||
{
|
||||
wxCHECK_MSG( data, FALSE, "data is invalid" );
|
||||
|
||||
wxNode *node = m_dataObjects.First();
|
||||
|
||||
while (node)
|
||||
{
|
||||
wxDataObject *d = (wxDataObject*)node->Data();
|
||||
|
||||
if (d->GetFormat() == data->GetFormat())
|
||||
{
|
||||
m_dataObjects.DeleteNode( node );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
m_dataObjects.Append( data );
|
||||
|
||||
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
|
||||
|
@@ -245,7 +245,7 @@ void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int heigh
|
||||
|
||||
void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) )
|
||||
{
|
||||
wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
|
||||
wxASSERT_MSG( (m_widget != NULL), "invalid dialog" );
|
||||
|
||||
if (GetAutoLayout())
|
||||
{
|
||||
|
@@ -642,10 +642,12 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
||||
|
||||
wxString text = text_object->GetText();
|
||||
|
||||
char *s = WXSTRINGCAST text;
|
||||
|
||||
gtk_widget_dnd_data_set( widget,
|
||||
event,
|
||||
(unsigned char*) text.c_str,
|
||||
(int) text.Length() );
|
||||
(unsigned char*) s,
|
||||
(int) text.Length()+1 );
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -656,10 +658,12 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
||||
|
||||
wxString text = file_object->GetFiles();
|
||||
|
||||
char *s = WXSTRINGCAST text;
|
||||
|
||||
gtk_widget_dnd_data_set( widget,
|
||||
event,
|
||||
(unsigned char*) text.c_str,
|
||||
(int) text.Length() );
|
||||
(unsigned char*) s,
|
||||
(int) text.Length()+1 );
|
||||
|
||||
break;
|
||||
}
|
||||
|
@@ -24,10 +24,13 @@
|
||||
// "changed"
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
|
||||
static void
|
||||
gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
|
||||
{
|
||||
win->SetModified();
|
||||
|
||||
win->CalculateScrollbar();
|
||||
|
||||
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->m_windowId );
|
||||
wxString val( win->GetValue() );
|
||||
if (!val.IsNull()) event.m_commandString = WXSTRINGCAST val;
|
||||
@@ -35,6 +38,17 @@ static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *
|
||||
win->GetEventHandler()->ProcessEvent( event );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// "size_allocate"
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
gtk_text_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* WXUNUSED(alloc), wxTextCtrl *win )
|
||||
{
|
||||
win->CalculateScrollbar();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxTextCtrl
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -72,6 +86,8 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
|
||||
SetValidator( validator );
|
||||
|
||||
m_vScrollbarVisible = TRUE;
|
||||
|
||||
bool multi_line = (style & wxTE_MULTILINE) != 0;
|
||||
if ( multi_line )
|
||||
{
|
||||
@@ -101,12 +117,15 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
}
|
||||
|
||||
// finally, put the vertical scrollbar in the upper right corner
|
||||
GtkWidget *vscrollbar = gtk_vscrollbar_new(GTK_TEXT(m_text)->vadj);
|
||||
gtk_table_attach(GTK_TABLE(m_widget), vscrollbar, 1, 2, 0, 1,
|
||||
m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
|
||||
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( vscrollbar );
|
||||
gtk_widget_show( m_vScrollbar );
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
|
||||
GTK_SIGNAL_FUNC(gtk_text_size_callback), (gpointer)this );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -169,6 +188,32 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxTextCtrl::CalculateScrollbar()
|
||||
{
|
||||
if ((m_windowStyle & wxTE_MULTILINE) == 0) return;
|
||||
|
||||
GtkAdjustment *adj = GTK_TEXT(m_text)->vadj;
|
||||
|
||||
if (adj->upper - adj->page_size < 0.8)
|
||||
{
|
||||
if (m_vScrollbarVisible)
|
||||
{
|
||||
gtk_widget_hide( m_vScrollbar );
|
||||
|
||||
m_vScrollbarVisible = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_vScrollbarVisible)
|
||||
{
|
||||
gtk_widget_show( m_vScrollbar );
|
||||
|
||||
m_vScrollbarVisible = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxString wxTextCtrl::GetValue() const
|
||||
{
|
||||
wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" );
|
||||
@@ -386,12 +431,12 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
||||
|
||||
long wxTextCtrl::XYToPosition(long x, long y ) const
|
||||
{
|
||||
if (!(m_windowStyle & wxTE_MULTILINE))
|
||||
return 0;
|
||||
if (!(m_windowStyle & wxTE_MULTILINE)) return 0;
|
||||
|
||||
long pos=0;
|
||||
|
||||
for(int i=1;i<y;i++)
|
||||
pos +=GetLineLength(i);
|
||||
for( int i=1; i<y; i++ ) pos += GetLineLength(i);
|
||||
|
||||
pos +=x-1; // Pos start with 0
|
||||
return pos;
|
||||
}
|
||||
@@ -413,15 +458,18 @@ int wxTextCtrl::GetNumberOfLines() const
|
||||
{
|
||||
int currentLine = 0;
|
||||
for (int i = 0; i < len; i++ )
|
||||
{
|
||||
if (text[i] == '\n')
|
||||
currentLine++;
|
||||
|
||||
}
|
||||
g_free( text );
|
||||
return currentLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
@@ -448,6 +496,7 @@ void wxTextCtrl::SetInsertionPointEnd()
|
||||
pos = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||
else
|
||||
pos = GTK_ENTRY(m_text)->text_length;
|
||||
|
||||
SetInsertionPoint((pos-1)>0 ? (pos-1):0);
|
||||
}
|
||||
|
||||
@@ -489,6 +538,7 @@ long wxTextCtrl::GetLastPosition() const
|
||||
pos = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||
else
|
||||
pos = GTK_ENTRY(m_text)->text_length;
|
||||
|
||||
return (long)pos-1;
|
||||
}
|
||||
|
||||
@@ -549,6 +599,8 @@ void wxTextCtrl::Clear()
|
||||
|
||||
void wxTextCtrl::OnChar( wxKeyEvent &key_event )
|
||||
{
|
||||
wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
|
||||
|
||||
if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER))
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
|
||||
@@ -700,6 +752,7 @@ void wxTextCtrl::ApplyWidgetStyle()
|
||||
{
|
||||
if (m_windowStyle & wxTE_MULTILINE)
|
||||
{
|
||||
// how ?
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -307,6 +307,22 @@ bool wxClipboard::SetData( wxDataObject *data )
|
||||
{
|
||||
wxCHECK_MSG( data, FALSE, "data is invalid" );
|
||||
|
||||
wxNode *node = m_dataObjects.First();
|
||||
|
||||
while (node)
|
||||
{
|
||||
wxDataObject *d = (wxDataObject*)node->Data();
|
||||
|
||||
if (d->GetFormat() == data->GetFormat())
|
||||
{
|
||||
m_dataObjects.DeleteNode( node );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
m_dataObjects.Append( data );
|
||||
|
||||
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
|
||||
|
@@ -245,7 +245,7 @@ void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int heigh
|
||||
|
||||
void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) )
|
||||
{
|
||||
wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
|
||||
wxASSERT_MSG( (m_widget != NULL), "invalid dialog" );
|
||||
|
||||
if (GetAutoLayout())
|
||||
{
|
||||
|
@@ -642,10 +642,12 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
||||
|
||||
wxString text = text_object->GetText();
|
||||
|
||||
char *s = WXSTRINGCAST text;
|
||||
|
||||
gtk_widget_dnd_data_set( widget,
|
||||
event,
|
||||
(unsigned char*) text.c_str,
|
||||
(int) text.Length() );
|
||||
(unsigned char*) s,
|
||||
(int) text.Length()+1 );
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -656,10 +658,12 @@ void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source
|
||||
|
||||
wxString text = file_object->GetFiles();
|
||||
|
||||
char *s = WXSTRINGCAST text;
|
||||
|
||||
gtk_widget_dnd_data_set( widget,
|
||||
event,
|
||||
(unsigned char*) text.c_str,
|
||||
(int) text.Length() );
|
||||
(unsigned char*) s,
|
||||
(int) text.Length()+1 );
|
||||
|
||||
break;
|
||||
}
|
||||
|
@@ -24,10 +24,13 @@
|
||||
// "changed"
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
|
||||
static void
|
||||
gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
|
||||
{
|
||||
win->SetModified();
|
||||
|
||||
win->CalculateScrollbar();
|
||||
|
||||
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->m_windowId );
|
||||
wxString val( win->GetValue() );
|
||||
if (!val.IsNull()) event.m_commandString = WXSTRINGCAST val;
|
||||
@@ -35,6 +38,17 @@ static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *
|
||||
win->GetEventHandler()->ProcessEvent( event );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// "size_allocate"
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
gtk_text_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* WXUNUSED(alloc), wxTextCtrl *win )
|
||||
{
|
||||
win->CalculateScrollbar();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxTextCtrl
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -72,6 +86,8 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
|
||||
SetValidator( validator );
|
||||
|
||||
m_vScrollbarVisible = TRUE;
|
||||
|
||||
bool multi_line = (style & wxTE_MULTILINE) != 0;
|
||||
if ( multi_line )
|
||||
{
|
||||
@@ -101,12 +117,15 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
}
|
||||
|
||||
// finally, put the vertical scrollbar in the upper right corner
|
||||
GtkWidget *vscrollbar = gtk_vscrollbar_new(GTK_TEXT(m_text)->vadj);
|
||||
gtk_table_attach(GTK_TABLE(m_widget), vscrollbar, 1, 2, 0, 1,
|
||||
m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
|
||||
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( vscrollbar );
|
||||
gtk_widget_show( m_vScrollbar );
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
|
||||
GTK_SIGNAL_FUNC(gtk_text_size_callback), (gpointer)this );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -169,6 +188,32 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxTextCtrl::CalculateScrollbar()
|
||||
{
|
||||
if ((m_windowStyle & wxTE_MULTILINE) == 0) return;
|
||||
|
||||
GtkAdjustment *adj = GTK_TEXT(m_text)->vadj;
|
||||
|
||||
if (adj->upper - adj->page_size < 0.8)
|
||||
{
|
||||
if (m_vScrollbarVisible)
|
||||
{
|
||||
gtk_widget_hide( m_vScrollbar );
|
||||
|
||||
m_vScrollbarVisible = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_vScrollbarVisible)
|
||||
{
|
||||
gtk_widget_show( m_vScrollbar );
|
||||
|
||||
m_vScrollbarVisible = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxString wxTextCtrl::GetValue() const
|
||||
{
|
||||
wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" );
|
||||
@@ -386,12 +431,12 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
||||
|
||||
long wxTextCtrl::XYToPosition(long x, long y ) const
|
||||
{
|
||||
if (!(m_windowStyle & wxTE_MULTILINE))
|
||||
return 0;
|
||||
if (!(m_windowStyle & wxTE_MULTILINE)) return 0;
|
||||
|
||||
long pos=0;
|
||||
|
||||
for(int i=1;i<y;i++)
|
||||
pos +=GetLineLength(i);
|
||||
for( int i=1; i<y; i++ ) pos += GetLineLength(i);
|
||||
|
||||
pos +=x-1; // Pos start with 0
|
||||
return pos;
|
||||
}
|
||||
@@ -413,15 +458,18 @@ int wxTextCtrl::GetNumberOfLines() const
|
||||
{
|
||||
int currentLine = 0;
|
||||
for (int i = 0; i < len; i++ )
|
||||
{
|
||||
if (text[i] == '\n')
|
||||
currentLine++;
|
||||
|
||||
}
|
||||
g_free( text );
|
||||
return currentLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
@@ -448,6 +496,7 @@ void wxTextCtrl::SetInsertionPointEnd()
|
||||
pos = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||
else
|
||||
pos = GTK_ENTRY(m_text)->text_length;
|
||||
|
||||
SetInsertionPoint((pos-1)>0 ? (pos-1):0);
|
||||
}
|
||||
|
||||
@@ -489,6 +538,7 @@ long wxTextCtrl::GetLastPosition() const
|
||||
pos = gtk_text_get_length( GTK_TEXT(m_text) );
|
||||
else
|
||||
pos = GTK_ENTRY(m_text)->text_length;
|
||||
|
||||
return (long)pos-1;
|
||||
}
|
||||
|
||||
@@ -549,6 +599,8 @@ void wxTextCtrl::Clear()
|
||||
|
||||
void wxTextCtrl::OnChar( wxKeyEvent &key_event )
|
||||
{
|
||||
wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
|
||||
|
||||
if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER))
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
|
||||
@@ -700,6 +752,7 @@ void wxTextCtrl::ApplyWidgetStyle()
|
||||
{
|
||||
if (m_windowStyle & wxTE_MULTILINE)
|
||||
{
|
||||
// how ?
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user