test for setting caret size and more changes (details are hazy; should have been committed a couple of months ago)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20869 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -62,6 +62,7 @@ public:
|
|||||||
wxChar& CharAt(int x, int y) { return *(m_text + x + m_xChars * y); }
|
wxChar& CharAt(int x, int y) { return *(m_text + x + m_xChars * y); }
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
|
void SetFontSize(int fontSize);
|
||||||
void CreateCaret();
|
void CreateCaret();
|
||||||
void MoveCaret(int x, int y);
|
void MoveCaret(int x, int y);
|
||||||
|
|
||||||
@@ -84,6 +85,9 @@ private:
|
|||||||
// move the caret to m_xCaret, m_yCaret
|
// move the caret to m_xCaret, m_yCaret
|
||||||
void DoMoveCaret();
|
void DoMoveCaret();
|
||||||
|
|
||||||
|
// update the geometry
|
||||||
|
void ChangeSize();
|
||||||
|
|
||||||
wxFont m_font;
|
wxFont m_font;
|
||||||
|
|
||||||
// the margin around the text (looks nicer)
|
// the margin around the text (looks nicer)
|
||||||
@@ -117,6 +121,7 @@ public:
|
|||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
void OnSetBlinkTime(wxCommandEvent& event);
|
void OnSetBlinkTime(wxCommandEvent& event);
|
||||||
|
void OnSetFontSize(wxCommandEvent& event);
|
||||||
void OnCaretMove(wxCommandEvent& event);
|
void OnCaretMove(wxCommandEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -137,6 +142,7 @@ enum
|
|||||||
Caret_Quit = 1,
|
Caret_Quit = 1,
|
||||||
Caret_About,
|
Caret_About,
|
||||||
Caret_SetBlinkTime,
|
Caret_SetBlinkTime,
|
||||||
|
Caret_SetFontSize,
|
||||||
Caret_Move,
|
Caret_Move,
|
||||||
|
|
||||||
// controls start here (the numbers are, of course, arbitrary)
|
// controls start here (the numbers are, of course, arbitrary)
|
||||||
@@ -154,6 +160,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(Caret_Quit, MyFrame::OnQuit)
|
EVT_MENU(Caret_Quit, MyFrame::OnQuit)
|
||||||
EVT_MENU(Caret_About, MyFrame::OnAbout)
|
EVT_MENU(Caret_About, MyFrame::OnAbout)
|
||||||
EVT_MENU(Caret_SetBlinkTime, MyFrame::OnSetBlinkTime)
|
EVT_MENU(Caret_SetBlinkTime, MyFrame::OnSetBlinkTime)
|
||||||
|
EVT_MENU(Caret_SetFontSize, MyFrame::OnSetFontSize)
|
||||||
EVT_MENU(Caret_Move, MyFrame::OnCaretMove)
|
EVT_MENU(Caret_Move, MyFrame::OnCaretMove)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
@@ -202,6 +209,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
|
|
||||||
menuFile->Append(Caret_SetBlinkTime, _T("&Blink time...\tCtrl-B"));
|
menuFile->Append(Caret_SetBlinkTime, _T("&Blink time...\tCtrl-B"));
|
||||||
|
menuFile->Append(Caret_SetFontSize, _T("&Font size...\tCtrl-S"));
|
||||||
menuFile->Append(Caret_Move, _T("&Move caret\tCtrl-C"));
|
menuFile->Append(Caret_Move, _T("&Move caret\tCtrl-C"));
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(Caret_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
menuFile->Append(Caret_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
||||||
@@ -260,6 +268,24 @@ void MyFrame::OnSetBlinkTime(wxCommandEvent& WXUNUSED(event))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnSetFontSize(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
long fontSize = wxGetNumberFromUser
|
||||||
|
(
|
||||||
|
_T("The font size also determines the caret size so\n"
|
||||||
|
"this demonstrates resizing the caret."),
|
||||||
|
_T("Font size (in points):"),
|
||||||
|
_T("wxCaret sample"),
|
||||||
|
12, 1, 100,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( fontSize != -1 )
|
||||||
|
{
|
||||||
|
m_canvas->SetFontSize((int)fontSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MyCanvas
|
// MyCanvas
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -281,8 +307,7 @@ MyCanvas::MyCanvas( wxWindow *parent )
|
|||||||
|
|
||||||
SetBackgroundColour(*wxWHITE);
|
SetBackgroundColour(*wxWHITE);
|
||||||
|
|
||||||
m_font = wxFont(12, wxFONTFAMILY_TELETYPE,
|
SetFontSize(12);
|
||||||
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
||||||
|
|
||||||
m_xCaret = m_yCaret =
|
m_xCaret = m_yCaret =
|
||||||
m_xChars = m_yChars = 0;
|
m_xChars = m_yChars = 0;
|
||||||
@@ -299,11 +324,6 @@ MyCanvas::~MyCanvas()
|
|||||||
|
|
||||||
void MyCanvas::CreateCaret()
|
void MyCanvas::CreateCaret()
|
||||||
{
|
{
|
||||||
wxClientDC dc(this);
|
|
||||||
dc.SetFont(m_font);
|
|
||||||
m_heightChar = dc.GetCharHeight();
|
|
||||||
m_widthChar = dc.GetCharWidth();
|
|
||||||
|
|
||||||
wxCaret *caret = new wxCaret(this, m_widthChar, m_heightChar);
|
wxCaret *caret = new wxCaret(this, m_widthChar, m_heightChar);
|
||||||
SetCaret(caret);
|
SetCaret(caret);
|
||||||
|
|
||||||
@@ -311,6 +331,25 @@ void MyCanvas::CreateCaret()
|
|||||||
caret->Show();
|
caret->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyCanvas::SetFontSize(int fontSize)
|
||||||
|
{
|
||||||
|
m_font = wxFont(fontSize, wxFONTFAMILY_TELETYPE,
|
||||||
|
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
||||||
|
|
||||||
|
wxClientDC dc(this);
|
||||||
|
dc.SetFont(m_font);
|
||||||
|
m_heightChar = dc.GetCharHeight();
|
||||||
|
m_widthChar = dc.GetCharWidth();
|
||||||
|
|
||||||
|
wxCaret *caret = GetCaret();
|
||||||
|
if ( caret )
|
||||||
|
{
|
||||||
|
caret->SetSize(m_widthChar, m_heightChar);
|
||||||
|
|
||||||
|
ChangeSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MyCanvas::MoveCaret(int x, int y)
|
void MyCanvas::MoveCaret(int x, int y)
|
||||||
{
|
{
|
||||||
m_xCaret = x;
|
m_xCaret = x;
|
||||||
@@ -327,10 +366,18 @@ void MyCanvas::DoMoveCaret()
|
|||||||
m_yMargin + m_yCaret * m_heightChar);
|
m_yMargin + m_yCaret * m_heightChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyCanvas::OnSize( wxSizeEvent &event )
|
void MyCanvas::OnSize(wxSizeEvent& event)
|
||||||
{
|
{
|
||||||
m_xChars = (event.GetSize().x - 2*m_xMargin) / m_widthChar;
|
ChangeSize();
|
||||||
m_yChars = (event.GetSize().y - 2*m_yMargin) / m_heightChar;
|
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyCanvas::ChangeSize()
|
||||||
|
{
|
||||||
|
wxSize size = GetClientSize();
|
||||||
|
m_xChars = (size.x - 2*m_xMargin) / m_widthChar;
|
||||||
|
m_yChars = (size.y - 2*m_yMargin) / m_heightChar;
|
||||||
if ( !m_xChars )
|
if ( !m_xChars )
|
||||||
m_xChars = 1;
|
m_xChars = 1;
|
||||||
if ( !m_yChars )
|
if ( !m_yChars )
|
||||||
@@ -348,8 +395,6 @@ void MyCanvas::OnSize( wxSizeEvent &event )
|
|||||||
|
|
||||||
frame->SetStatusText(msg, 1);
|
frame->SetStatusText(msg, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Skip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: this method is horrible inefficient especially because the caret
|
// NB: this method is horrible inefficient especially because the caret
|
||||||
|
Reference in New Issue
Block a user