#include "wx/spinbutt.h"
#include "wx/clipbrd.h"
+#ifdef __WXGTK__
+#include "wx/tooltip.h"
+#endif
+
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#define USE_XPM
#endif
bool OnInit(void);
};
+// a text ctrl which allows to call different wxTextCtrl functions
+// interactively by pressing function keys in it
+class MyTextCtrl : public wxTextCtrl
+{
+public:
+ MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
+ const wxPoint &pos, const wxSize &size, int style = 0)
+ : wxTextCtrl(parent, id, value, pos, size, style) { }
+
+ void OnChar(wxKeyEvent& event);
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
class MyPanel: public wxPanel
{
public:
void OnSpinUpdate( wxSpinEvent &event );
void OnPasteFromClipboard( wxCommandEvent &event );
void OnCopyToClipboard( wxCommandEvent &event );
+ void OnMoveToEndOfText( wxCommandEvent &event );
+ void OnMoveToEndOfEntry( wxCommandEvent &event );
wxListBox *m_listbox;
wxChoice *m_choice;
wxButton *m_fontButton;
wxSpinButton *m_spinbutton;
wxTextCtrl *m_spintext;
- wxTextCtrl *m_multitext;
+ MyTextCtrl *m_multitext;
+ MyTextCtrl *m_textentry;
wxCheckBox *m_checkbox;
wxTextCtrl *m_text;
// main()
//----------------------------------------------------------------------
-IMPLEMENT_APP (MyApp)
+IMPLEMENT_APP(MyApp)
//----------------------------------------------------------------------
// MyApp
return TRUE;
}
+//----------------------------------------------------------------------
+// MyTextCtrl
+//----------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
+ EVT_CHAR(MyTextCtrl::OnChar)
+END_EVENT_TABLE()
+
+void MyTextCtrl::OnChar(wxKeyEvent& event)
+{
+ switch ( event.KeyCode() )
+ {
+ case WXK_F1:
+ // show current position and text length
+ {
+ long line, column, pos = GetInsertionPoint();
+ PositionToXY(pos, &column, &line);
+
+ wxLogMessage("Current position: %ld\n"
+ "Current line, column: (%ld, %ld)\n"
+ "Number of lines: %ld\n"
+ "Current line length: %ld\n"
+ "Total text length: %ld",
+ pos,
+ line, column,
+ GetNumberOfLines(),
+ GetLineLength(line),
+ GetLastPosition());
+ }
+ break;
+
+ case WXK_F2:
+ // go to the end
+ SetInsertionPointEnd();
+ break;
+
+ case WXK_F3:
+ // go to position 10
+ SetInsertionPoint(10);
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
//----------------------------------------------------------------------
// MyPanel
//----------------------------------------------------------------------
const int ID_TEXT = 150;
const int ID_PASTE_TEXT = 151;
const int ID_COPY_TEXT = 152;
+const int ID_MOVE_END_ENTRY = 153;
+const int ID_MOVE_END_ZONE = 154;
const int ID_RADIOBOX = 160;
const int ID_RADIOBOX_SEL_NUM = 161;
const int ID_SPIN = 182;
-
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_SIZE ( MyPanel::OnSize)
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons)
EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons)
EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons)
- EVT_CHOICE (ID_COMBO, MyPanel::OnCombo)
+ EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo)
EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons)
EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons)
EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
+ EVT_BUTTON (ID_MOVE_END_ZONE, MyPanel::OnMoveToEndOfText)
+ EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry)
END_EVENT_TABLE()
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
// panel->SetBackgroundColour("cadet blue");
// panel->SetForegroundColour("blue");
m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices );
+#ifdef __WXGTK__
+ m_listbox->SetToolTip( "This is a list box" );
+#endif
// m_listbox->SetBackgroundColour("wheat");
(void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
(void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) );
(void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) );
button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) );
+#ifdef __WXGTK__
+ button->SetToolTip( "Press here to set italic font" );
+#endif
+
// button->SetForegroundColour( "red" );
m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) );
m_checkbox->SetValue(FALSE);
+#ifdef __WXGTK__
+ m_checkbox->SetToolTip( "Click here to disable the listbox" );
+#endif
m_notebook->AddPage(panel, "wxList", TRUE, Image_List);
panel = new wxPanel(m_notebook);
panel = new wxPanel(m_notebook);
// panel->SetBackgroundColour("cadet blue");
// panel->SetForegroundColour("blue");
- wxTextCtrl *tc = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
- (*tc) << " More text.";
-// tc->SetBackgroundColour("wheat");
- m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
- (*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,80), wxSize(110,30) );
- (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,140), wxSize(110,30) );
+ m_textentry = new MyTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
+ (*m_textentry) << " More text.";
+// m_textentry->SetBackgroundColour("wheat");
+ m_multitext = new MyTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
+ (*m_multitext) << " More text."
+ << "\nPress Fn keys to test different wxTextCtrl functions";
+// m_multitext->SetBackgroundColour("wheat");
+ (void)new wxStaticBox( panel, -1, "Move cursor to the end of:",
+ wxPoint(345, 0), wxSize(160, 100) );
+ (void)new wxButton(panel, ID_MOVE_END_ENTRY, "Text entry",
+ wxPoint(370, 20), wxSize(110, 30));
+ (void)new wxButton(panel, ID_MOVE_END_ZONE, "Text zone",
+ wxPoint(370, 60), wxSize(110, 30));
+ (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,120), wxSize(160,100) );
+ (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,140), wxSize(110,30) );
+ (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,180), wxSize(110,30) );
m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text);
wxString choices2[] =
// panel->SetForegroundColour("blue");
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_SPECIFY_ROWS );
// m_radio->SetBackgroundColour("wheat");
- m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_SPECIFY_COLS );
+ m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 2, wxRA_SPECIFY_COLS );
// m_radio->SetBackgroundColour("wheat");
(void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
*m_text << "Successfully opened the clipboard." << "\n";
}
- wxTextDataObject *data = new wxTextDataObject();
+ wxTextDataObject data;
- if (wxTheClipboard->GetData( data ))
+ if (wxTheClipboard->IsSupported( data ))
{
- *m_text << "Successfully retrieved data from the clipboard." << "\n";
- *m_multitext << data->GetText() << "\n";
+ *m_text << "Clipboard supports requested format." << "\n";
+
+ if (wxTheClipboard->GetData( data ))
+ {
+ *m_text << "Successfully retrieved data from the clipboard." << "\n";
+ *m_multitext << data.GetText() << "\n";
+ }
+ else
+ {
+ *m_text << "Error getting data from the clipboard." << "\n";
+ }
}
else
{
- *m_text << "Error getting data from the clipboard." << "\n";
+ *m_text << "Clipboard doesn't support requested format." << "\n";
}
wxTheClipboard->Close();
*m_text << "Closed the clipboard." << "\n";
- delete data;
-
#endif
}
}
wxTextDataObject *data = new wxTextDataObject( text );
- wxDataBroker *broker = new wxDataBroker();
- broker->Add( data );
- if (!wxTheClipboard->SetData( broker ))
+ if (!wxTheClipboard->SetData( data ))
{
*m_text << "Error while copying to the clipboard." << "\n";
}
#endif
}
+void MyPanel::OnMoveToEndOfText( wxCommandEvent &event )
+{
+ m_multitext->SetInsertionPointEnd();
+ m_multitext->SetFocus();
+}
+
+void MyPanel::OnMoveToEndOfEntry( wxCommandEvent &event )
+{
+ m_textentry->SetInsertionPointEnd();
+ m_textentry->SetFocus();
+}
+
void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) )
{
int x = 0;