]> git.saurik.com Git - wxWidgets.git/commitdiff
Further work on wxTextCtrl.
authorRobert Roebling <robert@roebling.de>
Sun, 7 Apr 2002 20:46:55 +0000 (20:46 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 7 Apr 2002 20:46:55 +0000 (20:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15001 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

mobile/Makefile.in
mobile/wxedit/wxedit.cpp
src/x11/textctrl.cpp

index 8ef3b38439a787c5e8ae2c98dc3324f78ae50f37..98b2df0eaef058652304c6a288f6971d4e74a705 100644 (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
index c27370b10e6c629ffb999f0e576c8c5efa82a49a..98c5d0bbee2d3e6cd54309c348ba47ec143d8f54 100644 (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 )
index 9a0718f33c28571edf9040472e3ad75ad32d305e..073f79466c557c2cac8baaa81f0df7473d25ca24 100644 (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,10 +1854,13 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event )
             DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i );
     }
     
-    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 );
+    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();