]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/textctrl.cpp
adapted to current filelist
[wxWidgets.git] / src / msw / textctrl.cpp
index 1c2b5d02ee39c40bf66dc506e9c1894534630ae7..113994facce2382911e21a744c1624f0e183c8aa 100644 (file)
@@ -28,7 +28,7 @@
     #pragma hdrstop
 #endif
 
-#if wxUSE_TEXTCTRL
+#if wxUSE_TEXTCTRL && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
 
 #ifndef WX_PRECOMP
     #include "wx/textctrl.h"
@@ -220,15 +220,12 @@ void wxTextCtrl::Init()
     m_privateContextMenu = NULL;
     m_suppressNextUpdate = false;
     m_isNativeCaretShown = true;
+    m_isCaretAtEnd = true;
 }
 
 wxTextCtrl::~wxTextCtrl()
 {
-    if (m_privateContextMenu)
-    {
-        delete m_privateContextMenu;
-        m_privateContextMenu = NULL;
-    }
+    delete m_privateContextMenu;
 }
 
 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
@@ -346,8 +343,6 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
     if ( !MSWCreateControl(windowClass, msStyle, pos, size, valueWin) )
         return false;
 
-    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
-
 #if wxUSE_RICHEDIT
     if ( IsRich() )
     {
@@ -943,8 +938,6 @@ void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
                 SendUpdateEvent();
         }
     }
-
-    AdjustSpaceLimit();
 }
 
 void wxTextCtrl::AppendText(const wxString& text)
@@ -954,7 +947,8 @@ void wxTextCtrl::AppendText(const wxString& text)
     WriteText(text);
 
 #if wxUSE_RICHEDIT
-    if ( IsMultiLine() && GetRichVersion() > 1 )
+    // don't do this if we're frozen, saves some time
+    if ( !IsFrozen() && IsMultiLine() && GetRichVersion() > 1 )
     {
         // setting the caret to the end and showing it simply doesn't work for
         // RichEdit 2.0 -- force it to still do what we want
@@ -991,8 +985,8 @@ bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent& event)
     size_t lenOld = GetValue().length();
 
     wxUint32 code = event.GetRawKeyCode();
-    ::keybd_event(code, 0, 0 /* key press */, 0);
-    ::keybd_event(code, 0, KEYEVENTF_KEYUP, 0);
+    ::keybd_event((BYTE)code, 0, 0 /* key press */, 0);
+    ::keybd_event((BYTE)code, 0, KEYEVENTF_KEYUP, 0);
 
     // assume that any alphanumeric key changes the total number of characters
     // in the control - this should work in 99% of cases
@@ -1084,6 +1078,8 @@ void wxTextCtrl::SetEditable(bool editable)
 void wxTextCtrl::SetInsertionPoint(long pos)
 {
     DoSetSelection(pos, pos);
+
+    m_isCaretAtEnd = pos == GetLastPosition();
 }
 
 void wxTextCtrl::SetInsertionPointEnd()
@@ -1093,8 +1089,11 @@ void wxTextCtrl::SetInsertionPointEnd()
     // if it doesn't actually move the caret anywhere and so the simple fact of
     // doing it results in horrible flicker when appending big amounts of text
     // to the control in a few chunks (see DoAddText() test in the text sample)
-    if ( GetInsertionPoint() == GetLastPosition() )
+    if ( m_isCaretAtEnd || GetInsertionPoint() == GetLastPosition() )
+    {
+        m_isCaretAtEnd = true;
         return;
+    }
 
     long pos;
 
@@ -1212,7 +1211,7 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
         ::SendMessage(hWnd, EM_SETSEL, (WPARAM)from, (LPARAM)to);
     }
 
-    if ( scrollCaret )
+    if ( scrollCaret && !IsFrozen() )
     {
 #if wxUSE_RICHEDIT
         // richedit 3.0 (i.e. the version living in riched20.dll distributed
@@ -1473,6 +1472,9 @@ void wxTextCtrl::ShowPosition(long pos)
 
     if (linesToScroll != 0)
       (void)::SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
+
+    // be pessimistic
+    m_isCaretAtEnd = false;
 }
 
 long wxTextCtrl::GetLengthOfLineContainingPos(long pos) const
@@ -1549,6 +1551,9 @@ void wxTextCtrl::Undo()
     if (CanUndo())
     {
         ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+
+        // it's not necessarily at the end any more
+        m_isCaretAtEnd = false;
     }
 }
 
@@ -1563,6 +1568,9 @@ void wxTextCtrl::Redo()
 #endif
         // Same as Undo, since Undo undoes the undo, i.e. a redo.
         ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+
+        // it's not necessarily at the end any more
+        m_isCaretAtEnd = false;
     }
 }
 
@@ -2122,9 +2130,12 @@ bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
                     case WM_SETCURSOR:
                         // ok, so it is hardcoded - do we really nee to
                         // customize it?
-                        ::SetCursor(GetHcursorOf(wxCursor(wxCURSOR_HAND)));
-                        *result = TRUE;
-                        break;
+                        {
+                            wxCursor cur(wxCURSOR_HAND);
+                            ::SetCursor(GetHcursorOf(cur));
+                            *result = TRUE;
+                            break;
+                        }
 
                     case WM_MOUSEMOVE:
                     case WM_LBUTTONDOWN:
@@ -2173,6 +2184,23 @@ bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
     return wxTextCtrlBase::MSWOnNotify(idCtrl, lParam, result);
 }
 
+// ----------------------------------------------------------------------------
+// Default colors for MSW text control
+//
+// Set default background color to the native white instead of
+// the default wxSYS_COLOUR_BTNFACE (is triggered with wxNullColour). 
+// ----------------------------------------------------------------------------
+
+wxVisualAttributes wxTextCtrl::GetDefaultAttributes() const
+{
+    wxVisualAttributes attrs;
+    attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
+    attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
+    attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); //white
+
+    return attrs;
+}
+
 // ----------------------------------------------------------------------------
 // colour setting for the rich edit controls
 // ----------------------------------------------------------------------------
@@ -2403,7 +2431,7 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
 
         const wxArrayInt& tabs = style.GetTabs();
 
-        pf.cTabCount = wxMin(tabs.GetCount(), MAX_TAB_STOPS);
+        pf.cTabCount = (SHORT)wxMin(tabs.GetCount(), MAX_TAB_STOPS);
         size_t i;
         for (i = 0; i < (size_t) pf.cTabCount; i++)
         {
@@ -2437,10 +2465,13 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style)
     if ( !wxTextCtrlBase::SetDefaultStyle(style) )
         return false;
 
-    // we have to do this or the style wouldn't apply for the text typed by the
-    // user
-    long posLast = GetLastPosition();
-    SetStyle(posLast, posLast, m_defaultStyle);
+    if ( IsEditable() )
+    {
+        // we have to do this or the style wouldn't apply for the text typed by
+        // the user
+        long posLast = GetLastPosition();
+        SetStyle(posLast, posLast, m_defaultStyle);
+    }
 
     return true;
 }
@@ -2493,6 +2524,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
     (void) ::SendMessage(GetHwnd(), EM_GETCHARFORMAT,
                             SCF_SELECTION, (LPARAM)&cf) ;
 
+
     LOGFONT lf;
     lf.lfHeight = cf.yHeight;
     lf.lfWidth = 0;
@@ -2500,17 +2532,32 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
     lf.lfClipPrecision = 0;
     lf.lfEscapement = 0;
     wxStrcpy(lf.lfFaceName, cf.szFaceName);
+
+    //NOTE:  we _MUST_ set each of these values to _something_ since we
+    //do not call wxZeroMemory on the LOGFONT lf 
     if (cf.dwEffects & CFE_ITALIC)
         lf.lfItalic = TRUE;
+    else
+        lf.lfItalic = FALSE;
+
     lf.lfOrientation = 0;
     lf.lfPitchAndFamily = cf.bPitchAndFamily;
     lf.lfQuality = 0;
+
     if (cf.dwEffects & CFE_STRIKEOUT)
         lf.lfStrikeOut = TRUE;
+    else
+        lf.lfStrikeOut = FALSE;
+
     if (cf.dwEffects & CFE_UNDERLINE)
         lf.lfUnderline = TRUE;
+    else
+        lf.lfUnderline = FALSE;
+
     if (cf.dwEffects & CFE_BOLD)
         lf.lfWeight = FW_BOLD;
+    else
+        lf.lfWeight = FW_NORMAL;
 
     wxFont font = wxCreateFontFromLogFont(& lf);
     if (font.Ok())
@@ -2642,4 +2689,4 @@ bool wxRichEditModule::Load(int version)
 
 #endif // wxUSE_RICHEDIT
 
-#endif // wxUSE_TEXTCTRL
+#endif // wxUSE_TEXTCTRL && !(__SMARTPHONE__ && __WXWINCE__)