#include "wx/settings.h"
#include "wx/brush.h"
#include "wx/utils.h"
+ #include "wx/intl.h"
#include "wx/log.h"
+ #include "wx/app.h"
#endif
#if wxUSE_CLIPBOARD
- #include "wx/app.h"
#include "wx/clipbrd.h"
#endif
# include <fstream>
#endif
-#if wxUSE_RICHEDIT && !defined(__GNUWIN32__)
+#if wxUSE_RICHEDIT
#include <richedit.h>
#endif
const wxString& name)
{
// base initialization
- if ( !CreateBase(parent, id, pos, size, style, name) )
+ if ( !CreateBase(parent, id, pos, size, style, validator, name) )
return FALSE;
- SetValidator(validator);
if ( parent )
parent->AddChild(this);
if ( m_windowStyle & wxTE_MULTILINE )
{
wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
- _T("wxTE_PROCESS_ENTER style is ignored for multiline "
- "text controls (they always process it)") );
+ wxT("wxTE_PROCESS_ENTER style is ignored for multiline "
+ "text controls (they always process it)") );
- msStyle |= ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL;
+ msStyle |= ES_MULTILINE | ES_WANTRETURN;
+ if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
+ msStyle |= WS_VSCROLL;
m_windowStyle |= wxTE_PROCESS_ENTER;
}
else
msStyle |= ES_AUTOHSCROLL;
+ if (m_windowStyle & wxHSCROLL)
+ msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
+
if (m_windowStyle & wxTE_READONLY)
msStyle |= ES_READONLY;
m_lDlgCode |= DLGC_WANTTAB;
// do create the control - either an EDIT or RICHEDIT
- const wxChar *windowClass = _T("EDIT");
+ const wxChar *windowClass = wxT("EDIT");
#if wxUSE_RICHEDIT
- // multiline edit controls are RICHEDITs except for those which have a
- // simple border (VZ: why??)
- if ( (m_windowStyle & wxTE_MULTILINE) &&
- !(m_windowStyle & wxSIMPLE_BORDER) )
+ if ( m_windowStyle & wxTE_RICH )
{
- msStyle |= ES_AUTOVSCROLL;
- m_isRich = TRUE;
- windowClass = _T("RICHEDIT");
+ static bool s_errorGiven = FALSE; // MT-FIXME
+
+ // only give the error msg once if the DLL can't be loaded
+ if ( !s_errorGiven )
+ {
+ // first try to load the RichEdit DLL (will do nothing if already
+ // done)
+ if ( !wxTheApp->InitRichEdit() )
+ {
+ wxLogError(_("Impossible to create a rich edit control, "
+ "using simple text control instead."));
+
+ s_errorGiven = TRUE;
+ }
+ }
+
+ if ( s_errorGiven )
+ {
+ m_isRich = FALSE;
+ }
+ else
+ {
+ msStyle |= ES_AUTOVSCROLL;
+ m_isRich = TRUE;
+ windowClass = wxT("RICHEDIT");
+ }
}
else
m_isRich = FALSE;
wxGetInstance(),
NULL);
- wxCHECK_MSG( m_hWnd, FALSE, _T("Failed to create text ctrl") );
+ wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create text ctrl") );
#if wxUSE_CTL3D
if ( want3D )
GetClassName(hWnd, buf, WXSIZEOF(buf));
- if ( wxStricmp(buf, _T("EDIT")) == 0 )
+ if ( wxStricmp(buf, wxT("EDIT")) == 0 )
m_isRich = FALSE;
else
m_isRich = TRUE;
{
wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
- SetWindowText(GetHwnd(), valueDos);
+ if ( valueDos != GetValue() )
+ {
+ SetWindowText(GetHwnd(), valueDos);
- AdjustSpaceLimit();
+ AdjustSpaceLimit();
+ }
}
void wxTextCtrl::WriteText(const wxString& value)
void wxTextCtrl::Clear()
{
- SetWindowText(GetHwnd(), _T(""));
+ SetWindowText(GetHwnd(), wxT(""));
}
// ----------------------------------------------------------------------------
return (long)(x + charIndex);
}
-void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
+bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
{
HWND hWnd = GetHwnd();
// This gets the line number containing the character
- int lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0);
+ int lineNo;
+#if wxUSE_RICHEDIT
+ if ( m_isRich )
+ {
+ lineNo = (int)SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)pos);
+ }
+ else
+#endif // wxUSE_RICHEDIT
+ lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
+
+ if ( lineNo == -1 )
+ {
+ // no such line
+ return FALSE;
+ }
+
// This gets the char index for the _beginning_ of this line
int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
+ if ( charIndex == -1 )
+ {
+ return FALSE;
+ }
+
// The X position must therefore be the different between pos and charIndex
- *x = (long)(pos - charIndex);
- *y = (long)lineNo;
+ if ( x )
+ *x = (long)(pos - charIndex);
+ if ( y )
+ *y = (long)lineNo;
+
+ return TRUE;
}
void wxTextCtrl::ShowPosition(long pos)
}
}
-WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
- WXUINT message, WXWPARAM wParam,
- WXLPARAM lParam)
-{
-#if wxUSE_CTL3D
- if ( m_useCtl3D )
- {
- HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
- return (WXHBRUSH) hbrush;
- }
-#endif
-
- HDC hdc = (HDC)pDC;
- SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
- : OPAQUE);
-
- ::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
- ::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
-
- wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
-
- return (WXHBRUSH) backgroundBrush->GetResourceHandle();
-}
-
void wxTextCtrl::OnChar(wxKeyEvent& event)
{
switch ( event.KeyCode() )
return IsEditable() && wxControl::AcceptsFocus();
}
-wxSize wxTextCtrl::DoGetBestSize()
+wxSize wxTextCtrl::DoGetBestSize() const
{
int cx, cy;
wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());