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:
Robert Roebling 2002-04-07 20:46:55 +00:00
parent 168f4135dc
commit 40de795fb9
3 changed files with 71 additions and 10 deletions

View File

@ -5,7 +5,7 @@
MOBILE_SUBDIRS=@MOBILE_SUBDIRS@
all:
@for d in $(SAMPLES_SUBDIRS); do (cd $$d && $(MAKE)); done
@for d in $(MOBILE_SUBDIRS); do (cd $$d && $(MAKE)); done
clean:
@for d in $(SAMPLES_SUBDIRS); do (cd $$d && $(MAKE) clean); done
@for d in $(MOBILE_SUBDIRS); do (cd $$d && $(MAKE) clean); done

View File

@ -16,6 +16,8 @@
#pragma hdrstop
#endif
#include "wx/filename.h"
// Include private headers
#include "wxedit.h"
@ -74,7 +76,39 @@ void MyFrame::OnOpen( wxCommandEvent &event )
"Text file (*.txt)|*.txt|"
"Any file (*)|*",
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 )

View File

@ -221,6 +221,8 @@ bool wxTextCtrl::Create( wxWindow *parent,
SetCursor( wxCursor( wxCURSOR_IBEAM ) );
m_editable = ((m_windowStyle & wxTE_READONLY) == 0);
if (HasFlag(wxTE_PASSWORD))
m_sourceFont = wxFont( 12, wxMODERN, wxNORMAL, wxNORMAL );
else
@ -983,7 +985,20 @@ bool wxTextCtrl::Enable( bool enable )
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)
@ -1816,13 +1831,18 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event )
int scroll_y = 0;
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_y = 0;
GetClientSize( &size_x, &size_y );
dc.SetPen( *wxTRANSPARENT_PEN );
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++)
{
int x = 0+2;
@ -1834,11 +1854,14 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event )
DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i );
}
if (m_editable)
{
dc.SetBrush( *wxRED_BRUSH );
// 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 )
{
@ -1891,6 +1914,8 @@ void wxTextCtrl::OnChar( wxKeyEvent &event )
{
if (m_lines.GetCount() == 0) return;
if (!m_editable) return;
int size_x = 0;
int size_y = 0;
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 )
{
// if (IsSingleLine())
if (!m_editable) return;
// if (IsSingleLine() || (m_lang == wxSOURCE_LANG_NONE))
{
if (new_x > m_lines[new_y].m_text.Len())
new_x = m_lines[new_y].m_text.Len();