X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1b806b98241ab649c169aaa1f134df85e80fb8b..cd15bcaf50ead53ccf9d50965312f0dc754affb4:/samples/text/text.cpp diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 624770bc0e..c8cff2e88a 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -45,7 +45,7 @@ #include "wx/numdlg.h" #include "wx/tokenzr.h" -#ifndef __WXMSW__ +#ifndef wxHAS_IMAGES_IN_RESOURCES #include "../sample.xpm" #endif @@ -128,6 +128,7 @@ public: void DoSelectText(); void DoMoveToEndOfText(); void DoMoveToEndOfEntry(); + void DoGetWindowCoordinates(); // return true if currently text control has any selection bool HasSelection() const @@ -217,6 +218,10 @@ public: void OnMoveToEndOfText( wxCommandEvent& WXUNUSED(event) ) { m_panel->DoMoveToEndOfText(); } + + void OnGetWindowCoordinates( wxCommandEvent& WXUNUSED(event) ) + { m_panel->DoGetWindowCoordinates(); } + void OnMoveToEndOfEntry( wxCommandEvent& WXUNUSED(event) ) { m_panel->DoMoveToEndOfEntry(); } @@ -415,6 +420,7 @@ enum TEXT_ADD_FREEZE, TEXT_ADD_LINE, TEXT_MOVE_ENDTEXT, + TEXT_GET_WINDOW_COORD, TEXT_MOVE_ENDENTRY, TEXT_SET_EDITABLE, TEXT_SET_ENABLED, @@ -513,6 +519,7 @@ bool MyApp::OnInit() menuText->Append(TEXT_LINE_UP, wxT("Scroll text one line up")); menuText->Append(TEXT_PAGE_DOWN, wxT("Scroll text one page down")); menuText->Append(TEXT_PAGE_UP, wxT("Scroll text one page up")); + menuText->Append(TEXT_GET_WINDOW_COORD, wxT("Get window coordinates")); menuText->AppendSeparator(); menuText->Append(TEXT_GET_LINE, wxT("Get the text of a line of the tabbed multiline")); menuText->Append(TEXT_GET_LINELENGTH, wxT("Get the length of a line of the tabbed multiline")); @@ -733,10 +740,27 @@ static wxString GetMouseEventDesc(const wxMouseEvent& ev) dbl = ev.RightDClick(); up = ev.RightUp(); } + else if ( ev.Aux1Down() || ev.Aux1Up() || ev.Aux1DClick() ) + { + button = wxT("Aux1"); + dbl = ev.Aux1DClick(); + up = ev.Aux1Up(); + } + else if ( ev.Aux2Down() || ev.Aux2Up() || ev.Aux2DClick() ) + { + button = wxT("Aux2"); + dbl = ev.Aux2DClick(); + up = ev.Aux2Up(); + } + else if ( ev.GetWheelRotation() ) + { + return wxString::Format("Wheel rotation %+d", ev.GetWheelRotation()); + } else { return wxT("Unknown mouse event"); } + wxASSERT(!(dbl && up)); return wxString::Format(wxT("%s mouse button %s"), button.c_str(), @@ -780,6 +804,8 @@ void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev) << GetChar( ev.LeftIsDown(), wxT('1') ) << GetChar( ev.MiddleIsDown(), wxT('2') ) << GetChar( ev.RightIsDown(), wxT('3') ) + << GetChar( ev.Aux1IsDown(), wxT('x') ) + << GetChar( ev.Aux2IsDown(), wxT('X') ) << GetChar( ev.ControlDown(), wxT('C') ) << GetChar( ev.AltDown(), wxT('A') ) << GetChar( ev.ShiftDown(), wxT('S') ) @@ -1048,15 +1074,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_password = new MyTextCtrl( this, wxID_ANY, wxT(""), wxPoint(10,50), wxSize(140,wxDefaultCoord), wxTE_PASSWORD ); - m_readonly = new MyTextCtrl( this, wxID_ANY, wxT("Read only"), - wxPoint(10,90), wxSize(140,wxDefaultCoord), wxTE_READONLY ); - - m_limited = new MyTextCtrl(this, wxID_ANY, wxT("Max 8 ch"), - wxPoint(10, 130), wxSize(140, wxDefaultCoord)); + m_limited = new MyTextCtrl(this, wxID_ANY, "", + wxPoint(10, 90), wxDefaultSize); + m_limited->SetHint("Max 8 ch"); m_limited->SetMaxLength(8); + wxSize size2 = m_limited->GetSizeFromTextSize(m_limited->GetTextExtent("WWWWWWWW")); + m_limited->SetSizeHints(size2, size2); // multi line text controls + wxString string3L("Read only\nMultiline\nFitted size"); + m_readonly = new MyTextCtrl( this, wxID_ANY, string3L, + wxPoint(10, 120), wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY ); + wxWindowDC dc(m_readonly); + size2 = m_readonly->GetSizeFromTextSize(dc.GetMultiLineTextExtent(string3L)); + m_readonly->SetMinSize(size2); + m_horizontal = new MyTextCtrl( this, wxID_ANY, wxT("Multiline text control with a horizontal scrollbar.\n"), wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL); @@ -1110,7 +1143,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) #endif m_tab = new MyTextCtrl( this, 100, wxT("Multiline, allow processing."), - wxPoint(180,90), wxSize(200,70), wxTE_MULTILINE | wxTE_PROCESS_TAB ); + wxPoint(180,90), wxDefaultSize, wxTE_MULTILINE | wxTE_PROCESS_TAB ); m_tab->SetClientData((void *)wxT("tab")); m_enter = new MyTextCtrl( this, 100, wxT("Multiline, allow processing."), @@ -1146,13 +1179,13 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) wxBoxSizer *column1 = new wxBoxSizer(wxVERTICAL); column1->Add( m_text, 0, wxALL | wxEXPAND, 10 ); column1->Add( m_password, 0, wxALL | wxEXPAND, 10 ); - column1->Add( m_readonly, 0, wxALL | wxEXPAND, 10 ); - column1->Add( m_limited, 0, wxALL | wxEXPAND, 10 ); + column1->Add( m_readonly, 0, wxALL, 10 ); + column1->Add( m_limited, 0, wxALL, 10 ); column1->Add( m_horizontal, 1, wxALL | wxEXPAND, 10 ); wxBoxSizer *column2 = new wxBoxSizer(wxVERTICAL); column2->Add( m_multitext, 1, wxALL | wxEXPAND, 10 ); - column2->Add( m_tab, 1, wxALL | wxEXPAND, 10 ); + column2->Add( m_tab, 0, wxALL | wxEXPAND, 10 ); column2->Add( m_enter, 1, wxALL | wxEXPAND, 10 ); wxBoxSizer *row1 = new wxBoxSizer(wxHORIZONTAL); @@ -1299,6 +1332,18 @@ void MyPanel::DoMoveToEndOfText() m_multitext->SetFocus(); } +void MyPanel::DoGetWindowCoordinates() +{ + wxTextCtrl * const text = GetFocusedText(); + + const wxPoint pt0 = text->PositionToCoords(0); + const wxPoint ptCur = text->PositionToCoords(text->GetInsertionPoint()); + *m_log << "Current position coordinates: " + "(" << ptCur.x << ", " << ptCur.y << "), " + "first position coordinates: " + "(" << pt0.x << ", " << pt0.y << ")\n"; +} + void MyPanel::DoMoveToEndOfEntry() { m_text->SetInsertionPointEnd(); @@ -1361,6 +1406,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEXT_ADD_FREEZE, MyFrame::OnAddTextFreeze) EVT_MENU(TEXT_ADD_LINE, MyFrame::OnAddTextLine) EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText) + EVT_MENU(TEXT_GET_WINDOW_COORD, MyFrame::OnGetWindowCoordinates) EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry) EVT_MENU(TEXT_SET_EDITABLE, MyFrame::OnSetEditable)