// translate wxWin style flags to MSW ones, checking for consistency while
// doing it
- long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
+ long msStyle = ES_LEFT | WS_TABSTOP;
if ( m_windowStyle & wxCLIP_SIBLINGS )
msStyle |= WS_CLIPSIBLINGS;
msStyle |= WS_VSCROLL;
m_windowStyle |= wxTE_PROCESS_ENTER;
}
- else
+ else // !multiline
+ {
+ // there is really no reason to not have this style for single line
+ // text controls
msStyle |= ES_AUTOHSCROLL;
+ }
- if (m_windowStyle & wxHSCROLL)
- msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
+ if ( m_windowStyle & wxHSCROLL )
+ msStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
- if (m_windowStyle & wxTE_READONLY)
+ if ( m_windowStyle & wxTE_READONLY )
msStyle |= ES_READONLY;
- if (m_windowStyle & wxTE_PASSWORD) // hidden input
+ if ( m_windowStyle & wxTE_PASSWORD )
msStyle |= ES_PASSWORD;
- if (m_windowStyle & wxTE_AUTO_SCROLL)
- msStyle |= ES_AUTOHSCROLL;
+ if ( m_windowStyle & wxTE_AUTO_SCROLL )
+ msStyle |= ES_AUTOHSCROLL;
+ if ( m_windowStyle & wxTE_NOHIDESEL )
+ msStyle |= ES_NOHIDESEL;
// we always want the characters and the arrows
m_lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS;
else
{
msStyle |= ES_AUTOVSCROLL;
+ // Experimental: this seems to help with the scroll problem. See messages from Jekabs Andrushaitis <j.andrusaitis@konts.lv>
+ // wx-dev list, entitled "[wx-dev] wxMSW-EVT_KEY_DOWN and wxMSW-wxTextCtrl" and "[wx-dev] TextCtrl (RichEdit)"
+ // Unfortunately, showing the selection in blue when the control doesn't have
+ // the focus is non-standard behaviour, and we need to find another workaround.
+ //msStyle |= ES_NOHIDESEL ;
m_isRich = TRUE;
int ver = wxRichEditModule::GetLoadedVersion();
m_isRich = FALSE;
#endif // wxUSE_RICHEDIT
- bool want3D;
- WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
-
- // Even with extended styles, need to combine with WS_BORDER for them to
- // look right.
- if ( want3D || wxStyleHasBorder(m_windowStyle) )
- msStyle |= WS_BORDER;
-
- // NB: don't use pos and size as CreateWindowEx arguments because they
- // might be -1 in which case we should use the default values (and
- // SetSize called below takes care of it)
- m_hWnd = (WXHWND)::CreateWindowEx(exStyle,
- windowClass.c_str(),
- NULL,
- msStyle,
- 0, 0, 0, 0,
- GetHwndOf(parent),
- (HMENU)m_windowId,
- wxGetInstance(),
- NULL);
-
- wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create text ctrl") );
-
-#if wxUSE_CTL3D
- if ( want3D )
+ // we need to turn '\n's into "\r\n"s for the multiline controls
+ wxString valueWin;
+ if ( m_windowStyle & wxTE_MULTILINE )
{
- Ctl3dSubclassCtl(GetHwnd());
- m_useCtl3D = TRUE;
+ valueWin = wxTextFile::Translate(value, wxTextFileType_Dos);
}
-#endif
+ else // single line
+ {
+ valueWin = value;
+ }
+
+ if ( !MSWCreateControl(windowClass, msStyle, pos, size, valueWin) )
+ return FALSE;
+
+ SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
#if wxUSE_RICHEDIT
if (m_isRich)
}
#endif // wxUSE_RICHEDIT
- SubclassWin(GetHWND());
-
- // set font, position, size and initial value
- wxFont& fontParent = parent->GetFont();
- if ( fontParent.Ok() )
- {
- SetFont(fontParent);
- }
- else
- {
- SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
- }
-
- // Causes a crash for Symantec C++ and WIN32 for some reason
-#if !(defined(__SC__) && defined(__WIN32__))
- if ( !value.IsEmpty() )
- {
- SetValue(value);
- }
-#endif
-
- // set colours
- SetupColours();
-
- SetSize(pos.x, pos.y, size.x, size.y);
-
return TRUE;
}
m_windowStyle |= wxTE_PROCESS_ENTER;
}
-void wxTextCtrl::SetupColours()
-{
- wxColour bkgndColour;
-// if (IsEditable() || (m_windowStyle & wxTE_MULTILINE))
- bkgndColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW);
-// else
-// bkgndColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
-
- SetBackgroundColour(bkgndColour);
- SetForegroundColour(GetParent()->GetForegroundColour());
-}
-
// ----------------------------------------------------------------------------
// set/get the controls text
// ----------------------------------------------------------------------------
SendMessage(hWnd, EM_SETSEL, 0, MAKELPARAM(pos, pos));
#endif // Win32/16
- static const wxChar *nothing = _T("");
- SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
+#if wxUSE_RICHEDIT
+ if ( !m_isRich)
+#endif
+ {
+ static const wxChar *nothing = _T("");
+ SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
+ }
}
void wxTextCtrl::SetInsertionPointEnd()
}
}
+wxString wxTextCtrl::GetStringSelection() const
+{
+ // the base class version works correctly for the rich text controls
+ // because there the lines are terminated with just '\r' which means that
+ // the string length is not changed in the result of the translations doen
+ // in GetValue() but for the normal ones when we replace "\r\n" with '\n'
+ // we break the indices
+#if wxUSE_RICHEDIT
+ if ( m_isRich )
+ return wxTextCtrlBase::GetStringSelection();
+#endif // wxUSE_RICHEDIT
+
+ long from, to;
+ GetSelection(&from, &to);
+
+ wxString str;
+ if ( from < to )
+ {
+ str = wxGetWindowText(GetHWND()).Mid(from, to - from);
+
+ // and now that we have the correct selection, convert it to the
+ // correct format
+ str = wxTextFile::Translate(str, wxTextFileType_Unix);
+ }
+
+ return str;
+}
+
bool wxTextCtrl::IsEditable() const
{
long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);