#include "wx/clipbrd.h"
#endif
-#if wxUSE_TOOLTIPS
- #include "wx/tooltip.h"
+#if wxUSE_FILE
+ #include "wx/file.h"
#endif
-#if defined(__WXGTK__) || defined(__WXMOTIF__)
- #include "mondrian.xpm"
+#if wxUSE_TOOLTIPS
+ #include "wx/tooltip.h"
#endif
// We test for wxUSE_DRAG_AND_DROP also, because data objects may not be
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) { }
+ : wxTextCtrl(parent, id, value, pos, size, style) { m_hasCapture = FALSE; }
void OnKeyDown(wxKeyEvent& event);
void OnKeyUp(wxKeyEvent& event);
void OnChar(wxKeyEvent& event);
+ bool m_hasCapture;
+
private:
static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); }
void LogEvent(const wxChar *name, wxKeyEvent& event) const;
void DoMoveToEndOfText();
void DoMoveToEndOfEntry();
+ void OnSize( wxSizeEvent &event );
+
MyTextCtrl *m_text;
MyTextCtrl *m_password;
MyTextCtrl *m_enter;
MyTextCtrl *m_multitext;
MyTextCtrl *m_horizontal;
+ MyTextCtrl *m_textrich;
+
wxTextCtrl *m_log;
+
+private:
+ DECLARE_EVENT_TABLE()
};
class MyFrame: public wxFrame
void OnMoveToEndOfEntry( wxCommandEvent &event )
{ m_panel->DoMoveToEndOfEntry(); }
+ void OnLogClear(wxCommandEvent& event);
+ void OnFileSave(wxCommandEvent& event);
void OnFileLoad(wxCommandEvent& event);
void OnIdle( wxIdleEvent& event );
TEXT_QUIT = 100,
TEXT_ABOUT,
TEXT_LOAD,
+ TEXT_SAVE,
+ TEXT_CLEAR,
// clipboard menu
TEXT_CLIPBOARD_COPY = 200,
{
// Create the main frame window
MyFrame *frame = new MyFrame((wxFrame *) NULL,
- "Text wxWindows App",
- 50, 50, 640, 420);
+ "Text wxWindows sample", 50, 50, 660, 420);
+ frame->SetSizeHints( 500, 400 );
wxMenu *file_menu = new wxMenu;
+ file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C",
+ "Clear the log window contents");
+ file_menu->Append(TEXT_SAVE, "&Save file\tCtrl-S",
+ "Save the text control contents to file");
file_menu->Append(TEXT_LOAD, "&Load file\tCtrl-O",
"Load the sample file into text control");
file_menu->AppendSeparator();
{
wxString key;
long keycode = event.KeyCode();
- if ( wxIsprint((int)keycode) )
- key.Printf( _T("'%c'") , (char)keycode);
- else
{
switch ( keycode )
{
case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break;
default:
- key.Printf( _T("unknown (%ld)"), keycode);
+ {
+ if ( wxIsprint((int)keycode) )
+ key.Printf( _T("'%c'") , (char)keycode);
+ else
+ key.Printf( _T("unknown (%ld)"), keycode);
+ }
}
}
{
LogEvent( _T("Char"), event);
+/* How are we supposed to test wxTE_PROCESS_TAB with this code?
+
if ( event.KeyCode() == WXK_TAB )
{
WriteText("\t");
{
event.Skip();
}
+*/
+ event.Skip();
}
void MyTextCtrl::OnKeyUp(wxKeyEvent& event)
// go to position 10
SetInsertionPoint(10);
break;
- }
- LogEvent( _("Key down"), event);
+ case WXK_F4:
+ if (!m_hasCapture)
+ {
+ wxLogDebug( wxT("Now capturing mouse and events.") );
+ m_hasCapture = TRUE;
+ CaptureMouse();
+ }
+ else
+ {
+ wxLogDebug( wxT("Stopped capturing mouse and events.") );
+ m_hasCapture = TRUE;
+ ReleaseMouse();
+ }
+ break;
+
+ case WXK_F5:
+ // insert a blank line
+ WriteText("\n");
+ break;
+
+ default:
+ LogEvent( _("Key down"), event);
+ }
event.Skip();
}
// MyPanel
//----------------------------------------------------------------------
+BEGIN_EVENT_TABLE(MyPanel, wxPanel)
+ EVT_SIZE(MyPanel::OnSize)
+END_EVENT_TABLE()
+
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
: wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
{
m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(5,260), wxSize(630,100), wxTE_MULTILINE );
- delete wxLog::SetActiveTarget(new wxLogStderr);
+ wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
+
+ delete old_log;
// single line text controls
// multi line text controls
-<<<<<<< controls.cpp
m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.",
wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
+ m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
+ FALSE, "", wxFONTENCODING_KOI8));
m_multitext = new MyTextCtrl( this, -1, "Multi line.",
-=======
- m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.",
- wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
- m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD));
-
- m_multitext = new MyTextCtrl( this, ID_TEXT, "Multi line.",
->>>>>>> 1.3
wxPoint(180,10), wxSize(240,70), wxTE_MULTILINE );
(*m_multitext) << " Appended.";
m_multitext->SetInsertionPoint(0);
m_multitext->WriteText( "Prepended. " );
#if wxUSE_TOOLTIPS
- m_multitext->SetToolTip("Press F1 here.");
+ m_multitext->SetToolTip("Press F1 here for statitics, F4 for capture and uncapture mouse.");
#endif
m_tab = new MyTextCtrl( this, -1, "Multiline, allow <TAB> processing.",
wxPoint(180,90), wxSize(240,70), wxTE_MULTILINE | wxTE_PROCESS_TAB );
-<<<<<<< controls.cpp
m_enter = new MyTextCtrl( this, -1, "Multiline, allow <ENTER> processing.",
wxPoint(180,170), wxSize(240,70), wxTE_MULTILINE);
-=======
- m_enter = new MyTextCtrl( this, -1, "Multiline, allow <ENTER> processing.",
- wxPoint(180,170), wxSize(240,70), wxTE_MULTILINE | wxTE_PROCESS_ENTER );
- wxButton *button;
-
- (void)new wxStaticBox( this, -1, "&Move cursor to the end of:", wxPoint(445, 10), wxSize(160, 100) );
- button = new wxButton( this, ID_MOVE_END_ENTRY, "&Single-line", wxPoint(470, 30), wxSize(110, 30) );
-#if wxUSE_TOOLTIPS
- button->SetToolTip("Move cursor in single-line text control to end of line.");
-#endif
- button = new wxButton( this, ID_MOVE_END_ZONE, "&Multi-line", wxPoint(470, 70), wxSize(110, 30) );
-#if wxUSE_TOOLTIPS
- button->SetToolTip("Move cursor in multi-line text control to end of first line.");
-#endif
+ m_textrich = new MyTextCtrl(this, -1, "Allows more than 30Kb of text\n"
+ "(even under broken Win9x)",
+ wxPoint(450, 10), wxSize(200, 230),
+ wxTE_RICH | wxTE_MULTILINE);
+}
- (void)new wxStaticBox( this, -1, "wx&Clipboard", wxPoint(445,130), wxSize(160,100) );
- button = new wxButton( this, ID_COPY_TEXT, "C&opy line 1", wxPoint(470,150), wxSize(110,30) );
-#if wxUSE_TOOLTIPS
- button->SetToolTip("Copy first line of the multi-line text control to the clipboard");
-#endif
- button = new wxButton( this, ID_PASTE_TEXT, "&Paste text", wxPoint(470,190), wxSize(110,30) );
-#if wxUSE_TOOLTIPS
- button->SetToolTip("Paste text from clipboard to the end of the multi-line text control.");
-#endif
->>>>>>> 1.3
+void MyPanel::OnSize( wxSizeEvent &event )
+{
+ wxSize client_area( GetClientSize() );
+ m_log->SetSize( 0, 260, client_area.x, client_area.y - 260 );
+ event.Skip();
}
#if wxUSE_CLIPBOARD
{
*m_log << "Clipboard supports requested format.\n";
- if (wxTheClipboard->GetData( &data ))
+ if (wxTheClipboard->GetData( data ))
{
*m_log << "Successfully retrieved data from the clipboard.\n";
*m_multitext << data.GetText() << "\n";
void MyPanel::DoCopyToClipboard()
{
+ // On X11, we want to get the data from the primary selection instead
+ // of the normal clipboard (which isn't normal under X11 at all). This
+ // call has no effect under MSW.
+ wxTheClipboard->UsePrimarySelection();
+
wxString text( m_multitext->GetLineText(0) );
if (text.IsEmpty())
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(TEXT_QUIT, MyFrame::OnQuit)
EVT_MENU(TEXT_ABOUT, MyFrame::OnAbout)
+ EVT_MENU(TEXT_SAVE, MyFrame::OnFileSave)
EVT_MENU(TEXT_LOAD, MyFrame::OnFileLoad)
+ EVT_MENU(TEXT_CLEAR, MyFrame::OnLogClear)
#if wxUSE_TOOLTIPS
EVT_MENU(TEXT_TOOLTIPS_SETDELAY, MyFrame::OnSetTooltipDelay)
EVT_MENU(TEXT_TOOLTIPS_ENABLE, MyFrame::OnToggleTooltips)
#endif // wxUSE_TOOLTIPS
+#if wxUSE_CLIPBOARD
EVT_MENU(TEXT_CLIPBOARD_PASTE, MyFrame::OnPasteFromClipboard)
EVT_MENU(TEXT_CLIPBOARD_COPY, MyFrame::OnCopyToClipboard)
+#endif // wxUSE_CLIPBOARD
+
EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText)
EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry)
"About Text Controls",
wxOK | wxICON_INFORMATION);
-<<<<<<< controls.cpp
-=======
- wxMessageDialog dialog(this, "This is a text control sample. It demonstrates the many different text control\n"
- "styles, the use of the clipboard, setting and handling tooltips and intercepting\n"
- "key and char events.\n"
- "\n"
- "Copyright (c) 1999, Robert Roebling, Julian Smart, Vadim Zeitlin",
- "About Text Controls", wxOK );
->>>>>>> 1.3
dialog.ShowModal();
wxEndBusyCursor();
}
#endif // tooltips
+void MyFrame::OnLogClear(wxCommandEvent& WXUNUSED(event))
+{
+ m_panel->m_log->Clear();
+}
+
+void MyFrame::OnFileSave(wxCommandEvent& event)
+{
+ if ( m_panel->m_textrich->SaveFile("dummy.txt") )
+ {
+#if wxUSE_FILE
+ // verify that the fil length is correct (it wasn't under Win95)
+ wxFile file("dummy.txt");
+ wxLogStatus(this, _T("Successfully saved file "
+ "(text len = %ld, file size = %ld)"),
+ m_panel->m_textrich->GetValue().length(),
+ file.Length());
+#endif
+ }
+ else
+ wxLogStatus(this, _T("Couldn't save the file"));
+}
+
void MyFrame::OnFileLoad(wxCommandEvent& event)
{
- m_panel->m_multitext->LoadFile("controls.cpp");
+ if ( m_panel->m_textrich->LoadFile("dummy.txt") )
+ wxLogStatus(this, _T("Successfully loaded file"));
+ else
+ wxLogStatus(this, _T("Couldn't load the file"));
}
void MyFrame::OnIdle( wxIdleEvent& event )