Further work on wxTextCtrl.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15001 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
MOBILE_SUBDIRS=@MOBILE_SUBDIRS@
|
MOBILE_SUBDIRS=@MOBILE_SUBDIRS@
|
||||||
|
|
||||||
all:
|
all:
|
||||||
@for d in $(SAMPLES_SUBDIRS); do (cd $$d && $(MAKE)); done
|
@for d in $(MOBILE_SUBDIRS); do (cd $$d && $(MAKE)); done
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@for d in $(SAMPLES_SUBDIRS); do (cd $$d && $(MAKE) clean); done
|
@for d in $(MOBILE_SUBDIRS); do (cd $$d && $(MAKE) clean); done
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/filename.h"
|
||||||
|
|
||||||
// Include private headers
|
// Include private headers
|
||||||
#include "wxedit.h"
|
#include "wxedit.h"
|
||||||
|
|
||||||
@@ -74,7 +76,39 @@ void MyFrame::OnOpen( wxCommandEvent &event )
|
|||||||
"Text file (*.txt)|*.txt|"
|
"Text file (*.txt)|*.txt|"
|
||||||
"Any file (*)|*",
|
"Any file (*)|*",
|
||||||
wxOPEN|wxFILE_MUST_EXIST );
|
wxOPEN|wxFILE_MUST_EXIST );
|
||||||
dialog.ShowModal();
|
if (dialog.ShowModal() == wxID_OK)
|
||||||
|
{
|
||||||
|
m_text->Clear();
|
||||||
|
|
||||||
|
#ifdef __WXX11__
|
||||||
|
wxFileName fname( dialog.GetPath() );
|
||||||
|
if ((fname.GetExt() == "cpp") ||
|
||||||
|
(fname.GetExt() == "c") ||
|
||||||
|
(fname.GetExt() == "h") ||
|
||||||
|
(fname.GetExt() == "cxx") ||
|
||||||
|
(fname.GetExt() == "hxx"))
|
||||||
|
{
|
||||||
|
m_text->SetLanguage( wxSOURCE_LANG_CPP );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (fname.GetExt() == "py")
|
||||||
|
{
|
||||||
|
m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if ((fname.GetExt() == "pl") ||
|
||||||
|
(fname.GetExt() == "pm"))
|
||||||
|
{
|
||||||
|
m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_text->SetLanguage( wxSOURCE_LANG_NONE );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_text->LoadFile( dialog.GetPath() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnSave( wxCommandEvent &event )
|
void MyFrame::OnSave( wxCommandEvent &event )
|
||||||
|
@@ -221,6 +221,8 @@ bool wxTextCtrl::Create( wxWindow *parent,
|
|||||||
|
|
||||||
SetCursor( wxCursor( wxCURSOR_IBEAM ) );
|
SetCursor( wxCursor( wxCURSOR_IBEAM ) );
|
||||||
|
|
||||||
|
m_editable = ((m_windowStyle & wxTE_READONLY) == 0);
|
||||||
|
|
||||||
if (HasFlag(wxTE_PASSWORD))
|
if (HasFlag(wxTE_PASSWORD))
|
||||||
m_sourceFont = wxFont( 12, wxMODERN, wxNORMAL, wxNORMAL );
|
m_sourceFont = wxFont( 12, wxMODERN, wxNORMAL, wxNORMAL );
|
||||||
else
|
else
|
||||||
@@ -983,7 +985,20 @@ bool wxTextCtrl::Enable( bool enable )
|
|||||||
|
|
||||||
bool wxTextCtrl::SetFont(const wxFont& font)
|
bool wxTextCtrl::SetFont(const wxFont& font)
|
||||||
{
|
{
|
||||||
return FALSE;
|
wxTextCtrlBase::SetFont( font );
|
||||||
|
|
||||||
|
m_sourceFont = font;
|
||||||
|
|
||||||
|
wxClientDC dc(this);
|
||||||
|
dc.SetFont( m_sourceFont );
|
||||||
|
m_lineHeight = dc.GetCharHeight();
|
||||||
|
m_charWidth = dc.GetCharWidth();
|
||||||
|
|
||||||
|
// TODO: recalc longest lines
|
||||||
|
|
||||||
|
MyAdjustScrollbars();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
|
bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
|
||||||
@@ -1816,13 +1831,18 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event )
|
|||||||
int scroll_y = 0;
|
int scroll_y = 0;
|
||||||
GetViewStart( NULL, &scroll_y );
|
GetViewStart( NULL, &scroll_y );
|
||||||
|
|
||||||
|
// We have a inner border of two pixels
|
||||||
|
// around the text, so scroll units do
|
||||||
|
// not correspond to lines.
|
||||||
|
if (scroll_y > 0) scroll_y--;
|
||||||
|
|
||||||
int size_x = 0;
|
int size_x = 0;
|
||||||
int size_y = 0;
|
int size_y = 0;
|
||||||
GetClientSize( &size_x, &size_y );
|
GetClientSize( &size_x, &size_y );
|
||||||
|
|
||||||
dc.SetPen( *wxTRANSPARENT_PEN );
|
dc.SetPen( *wxTRANSPARENT_PEN );
|
||||||
dc.SetBrush( wxBrush( wxTHEME_COLOUR(HIGHLIGHT), wxSOLID ) );
|
dc.SetBrush( wxBrush( wxTHEME_COLOUR(HIGHLIGHT), wxSOLID ) );
|
||||||
int upper = wxMin( (int)m_lines.GetCount(), scroll_y+(size_y/m_lineHeight)+1 );
|
int upper = wxMin( (int)m_lines.GetCount(), scroll_y+(size_y/m_lineHeight)+2 );
|
||||||
for (int i = scroll_y; i < upper; i++)
|
for (int i = scroll_y; i < upper; i++)
|
||||||
{
|
{
|
||||||
int x = 0+2;
|
int x = 0+2;
|
||||||
@@ -1834,10 +1854,13 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event )
|
|||||||
DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i );
|
DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.SetBrush( *wxRED_BRUSH );
|
if (m_editable)
|
||||||
// int xx = m_cursorX*m_charWidth;
|
{
|
||||||
int xx = PosToPixel( m_cursorY, m_cursorX );
|
dc.SetBrush( *wxRED_BRUSH );
|
||||||
dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight );
|
// int xx = m_cursorX*m_charWidth;
|
||||||
|
int xx = PosToPixel( m_cursorY, m_cursorX );
|
||||||
|
dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTextCtrl::OnMouse( wxMouseEvent &event )
|
void wxTextCtrl::OnMouse( wxMouseEvent &event )
|
||||||
@@ -1891,6 +1914,8 @@ void wxTextCtrl::OnChar( wxKeyEvent &event )
|
|||||||
{
|
{
|
||||||
if (m_lines.GetCount() == 0) return;
|
if (m_lines.GetCount() == 0) return;
|
||||||
|
|
||||||
|
if (!m_editable) return;
|
||||||
|
|
||||||
int size_x = 0;
|
int size_x = 0;
|
||||||
int size_y = 0;
|
int size_y = 0;
|
||||||
GetClientSize( &size_x, &size_y );
|
GetClientSize( &size_x, &size_y );
|
||||||
@@ -2183,7 +2208,9 @@ void wxTextCtrl::RefreshDown( int n )
|
|||||||
|
|
||||||
void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre )
|
void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre )
|
||||||
{
|
{
|
||||||
// if (IsSingleLine())
|
if (!m_editable) return;
|
||||||
|
|
||||||
|
// if (IsSingleLine() || (m_lang == wxSOURCE_LANG_NONE))
|
||||||
{
|
{
|
||||||
if (new_x > m_lines[new_y].m_text.Len())
|
if (new_x > m_lines[new_y].m_text.Len())
|
||||||
new_x = m_lines[new_y].m_text.Len();
|
new_x = m_lines[new_y].m_text.Len();
|
||||||
|
Reference in New Issue
Block a user