1. PositionToXY() off-by-2 (!) bug corrected
2. controls sample dumps info about text control when F1 is pressed git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1507 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
2829d9e3e8
commit
6085b116d6
@ -57,6 +57,21 @@ class MyApp: public wxApp
|
|||||||
bool OnInit(void);
|
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
|
class MyPanel: public wxPanel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -92,8 +107,8 @@ class MyPanel: public wxPanel
|
|||||||
wxButton *m_fontButton;
|
wxButton *m_fontButton;
|
||||||
wxSpinButton *m_spinbutton;
|
wxSpinButton *m_spinbutton;
|
||||||
wxTextCtrl *m_spintext;
|
wxTextCtrl *m_spintext;
|
||||||
wxTextCtrl *m_multitext;
|
MyTextCtrl *m_multitext;
|
||||||
wxTextCtrl *m_textentry;
|
MyTextCtrl *m_textentry;
|
||||||
wxCheckBox *m_checkbox;
|
wxCheckBox *m_checkbox;
|
||||||
|
|
||||||
wxTextCtrl *m_text;
|
wxTextCtrl *m_text;
|
||||||
@ -159,6 +174,52 @@ bool MyApp::OnInit(void)
|
|||||||
return TRUE;
|
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
|
// MyPanel
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
@ -214,7 +275,6 @@ const int ID_SLIDER = 181;
|
|||||||
|
|
||||||
const int ID_SPIN = 182;
|
const int ID_SPIN = 182;
|
||||||
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
||||||
EVT_SIZE ( MyPanel::OnSize)
|
EVT_SIZE ( MyPanel::OnSize)
|
||||||
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
|
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyPanel::OnPageChanged)
|
||||||
@ -393,11 +453,12 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
|
|||||||
panel = new wxPanel(m_notebook);
|
panel = new wxPanel(m_notebook);
|
||||||
// panel->SetBackgroundColour("cadet blue");
|
// panel->SetBackgroundColour("cadet blue");
|
||||||
// panel->SetForegroundColour("blue");
|
// panel->SetForegroundColour("blue");
|
||||||
m_textentry = new wxTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
|
m_textentry = new MyTextCtrl( panel, ID_TEXT, "Write text here.", wxPoint(10,10), wxSize(320,28));
|
||||||
(*m_textentry) << " More text.";
|
(*m_textentry) << " More text.";
|
||||||
// m_textentry->SetBackgroundColour("wheat");
|
// m_textentry->SetBackgroundColour("wheat");
|
||||||
m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
|
m_multitext = new MyTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE );
|
||||||
(*m_multitext) << " More text.";
|
(*m_multitext) << " More text."
|
||||||
|
<< "\nPress Fn keys to test different wxTextCtrl functions";
|
||||||
// m_multitext->SetBackgroundColour("wheat");
|
// m_multitext->SetBackgroundColour("wheat");
|
||||||
(void)new wxStaticBox( panel, -1, "Move cursor to the end of:",
|
(void)new wxStaticBox( panel, -1, "Move cursor to the end of:",
|
||||||
wxPoint(345, 0), wxSize(160, 100) );
|
wxPoint(345, 0), wxSize(160, 100) );
|
||||||
|
@ -445,8 +445,8 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
|||||||
if (pos == 0)
|
if (pos == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
const char* stop = text.c_str() + pos + 1;
|
const char* stop = text.c_str() + pos;
|
||||||
for ( const char *p = text.c_str(); p <= stop; p++ )
|
for ( const char *p = text.c_str(); p < stop; p++ )
|
||||||
{
|
{
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
{
|
{
|
||||||
|
@ -445,8 +445,8 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
|||||||
if (pos == 0)
|
if (pos == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
const char* stop = text.c_str() + pos + 1;
|
const char* stop = text.c_str() + pos;
|
||||||
for ( const char *p = text.c_str(); p <= stop; p++ )
|
for ( const char *p = text.c_str(); p < stop; p++ )
|
||||||
{
|
{
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user