// declarations
// ============================================================================
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "textctrl.h"
#endif
#include <windowsx.h>
#include "wx/msw/private.h"
+#include "wx/msw/winundef.h"
#include <string.h>
#include <stdlib.h>
+
+#ifndef __WXWINCE__
#include <sys/types.h>
+#endif
#if wxUSE_RICHEDIT
#include <richedit.h>
#endif
-// old mingw32 doesn't define this
-#ifndef CFM_CHARSET
- #define CFM_CHARSET 0x08000000
-#endif // CFM_CHARSET
-
-#ifndef CFM_BACKCOLOR
- #define CFM_BACKCOLOR 0x04000000
-#endif
-
-// cygwin does not have these defined for richedit
-#ifndef ENM_LINK
- #define ENM_LINK 0x04000000
-#endif
-
-#ifndef EM_AUTOURLDETECT
- #define EM_AUTOURLDETECT (WM_USER + 91)
-#endif
-
-#ifndef EN_LINK
- #define EN_LINK 0x070b
-
- typedef struct _enlink
- {
- NMHDR nmhdr;
- UINT msg;
- WPARAM wParam;
- LPARAM lParam;
- CHARRANGE chrg;
- } ENLINK;
-#endif // ENLINK
-
-#ifndef SF_UNICODE
- #define SF_UNICODE 0x0010
-#endif
-
-// Watcom C++ doesn't define this
-#ifndef SCF_ALL
- #define SCF_ALL 0x0004
-#endif
+#include "wx/msw/missing.h"
#endif // wxUSE_RICHEDIT
// event tables and other macros
// ----------------------------------------------------------------------------
+#if wxUSE_EXTENDED_RTTI
+WX_DEFINE_FLAGS( wxTextCtrlStyle )
+
+wxBEGIN_FLAGS( wxTextCtrlStyle )
+ // new style border flags, we put them first to
+ // use them for streaming out
+ wxFLAGS_MEMBER(wxBORDER_SIMPLE)
+ wxFLAGS_MEMBER(wxBORDER_SUNKEN)
+ wxFLAGS_MEMBER(wxBORDER_DOUBLE)
+ wxFLAGS_MEMBER(wxBORDER_RAISED)
+ wxFLAGS_MEMBER(wxBORDER_STATIC)
+ wxFLAGS_MEMBER(wxBORDER_NONE)
+
+ // old style border flags
+ wxFLAGS_MEMBER(wxSIMPLE_BORDER)
+ wxFLAGS_MEMBER(wxSUNKEN_BORDER)
+ wxFLAGS_MEMBER(wxDOUBLE_BORDER)
+ wxFLAGS_MEMBER(wxRAISED_BORDER)
+ wxFLAGS_MEMBER(wxSTATIC_BORDER)
+ wxFLAGS_MEMBER(wxNO_BORDER)
+
+ // standard window styles
+ wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
+ wxFLAGS_MEMBER(wxCLIP_CHILDREN)
+ wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
+ wxFLAGS_MEMBER(wxWANTS_CHARS)
+ wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE)
+ wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
+ wxFLAGS_MEMBER(wxVSCROLL)
+ wxFLAGS_MEMBER(wxHSCROLL)
+
+ wxFLAGS_MEMBER(wxTE_PROCESS_ENTER)
+ wxFLAGS_MEMBER(wxTE_PROCESS_TAB)
+ wxFLAGS_MEMBER(wxTE_MULTILINE)
+ wxFLAGS_MEMBER(wxTE_PASSWORD)
+ wxFLAGS_MEMBER(wxTE_READONLY)
+ wxFLAGS_MEMBER(wxHSCROLL)
+ wxFLAGS_MEMBER(wxTE_RICH)
+ wxFLAGS_MEMBER(wxTE_RICH2)
+ wxFLAGS_MEMBER(wxTE_AUTO_URL)
+ wxFLAGS_MEMBER(wxTE_NOHIDESEL)
+ wxFLAGS_MEMBER(wxTE_LEFT)
+ wxFLAGS_MEMBER(wxTE_CENTRE)
+ wxFLAGS_MEMBER(wxTE_RIGHT)
+ wxFLAGS_MEMBER(wxTE_DONTWRAP)
+ wxFLAGS_MEMBER(wxTE_LINEWRAP)
+ wxFLAGS_MEMBER(wxTE_WORDWRAP)
+
+wxEND_FLAGS( wxTextCtrlStyle )
+
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl, wxControl,"wx/textctrl.h")
+
+wxBEGIN_PROPERTIES_TABLE(wxTextCtrl)
+ wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
+ wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent )
+
+ wxPROPERTY( Font , wxFont , SetFont , GetFont ,, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
+ wxPROPERTY( Value , wxString , SetValue, GetValue, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+ wxPROPERTY_FLAGS( WindowStyle , wxTextCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+wxEND_PROPERTIES_TABLE()
+
+wxBEGIN_HANDLERS_TABLE(wxTextCtrl)
+wxEND_HANDLERS_TABLE()
+
+wxCONSTRUCTOR_6( wxTextCtrl , wxWindow* , Parent , wxWindowID , Id , wxString , Value , wxPoint , Position , wxSize , Size , long , WindowStyle)
+#else
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
+#endif
+
BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
EVT_CHAR(wxTextCtrl::OnChar)
#ifdef __WIN16__
EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground)
#endif
+
+ EVT_SET_FOCUS(wxTextCtrl::OnSetFocus)
END_EVENT_TABLE()
// ============================================================================
m_privateContextMenu = NULL;
m_suppressNextUpdate = FALSE;
+ m_isNativeCaretShown = true;
}
wxTextCtrl::~wxTextCtrl()
WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
{
- // default border for the text controls is the sunken one
- if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
- {
- style |= wxBORDER_SUNKEN;
- }
-
long msStyle = wxControl::MSWGetStyle(style, exstyle);
// styles which we alaways add by default
// always adjust the vertical scrollbar automatically if we have it
msStyle |= WS_VSCROLL | ES_AUTOVSCROLL;
+#if wxUSE_RICHEDIT
// we have to use this style for the rich edit controls because
// without it the vertical scrollbar never appears at all in
// richedit 3.0 because of our ECO_NOHIDESEL hack (search for it)
{
msStyle |= ES_DISABLENOSCROLL;
}
+#endif // wxUSE_RICHEDIT
}
style |= wxTE_PROCESS_ENTER;
msStyle |= ES_AUTOHSCROLL;
}
- // styles which we add depending on the specified wxWindows styles
- if ( style & wxHSCROLL )
+ // note that wxTE_DONTWRAP is the same as wxHSCROLL so if we have a horz
+ // scrollbar, there is no wrapping -- which makes sense
+ if ( style & wxTE_DONTWRAP )
{
// automatically scroll the control horizontally as necessary
- msStyle |= WS_HSCROLL;// | ES_AUTOHSCROLL;
+ msStyle |= WS_HSCROLL;
}
if ( style & wxTE_READONLY )
else if ( style & wxTE_RIGHT )
msStyle |= ES_RIGHT;
else
- msStyle |= ES_LEFT; // ES_LEFT if 0 as well but for consistency...
+ msStyle |= ES_LEFT; // ES_LEFT is 0 as well but for consistency...
return msStyle;
}
void wxTextCtrl::SetWindowStyleFlag(long style)
{
- if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
- style |= wxBORDER_SUNKEN;
-
#if wxUSE_RICHEDIT
// we have to deal with some styles separately because they can't be
// changed by simply calling SetWindowLong(GWL_STYLE) but can be changed
int len = GetWindowTextLength(GetHwnd());
if ( len > from )
{
- // alloc one extra WORD as needed by the control
- wxChar *p = str.GetWriteBuf(++len);
+ {
+ // alloc one extra WORD as needed by the control
+ wxStringBuffer tmp(str, ++len);
+ wxChar *p = tmp;
- TEXTRANGE textRange;
- textRange.chrg.cpMin = from;
- textRange.chrg.cpMax = to == -1 ? len : to;
- textRange.lpstrText = p;
+ TEXTRANGE textRange;
+ textRange.chrg.cpMin = from;
+ textRange.chrg.cpMax = to == -1 ? len : to;
+ textRange.lpstrText = p;
- (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
+ (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE,
+ 0, (LPARAM)&textRange);
- if ( m_verRichEdit > 1 )
- {
- // RichEdit 2.0 uses just CR ('\r') for the newlines which is
- // neither Unix nor Windows style - convert it to something
- // reasonable
- for ( ; *p; p++ )
+ if ( m_verRichEdit > 1 )
{
- if ( *p == _T('\r') )
- *p = _T('\n');
+ // RichEdit 2.0 uses just CR ('\r') for the
+ // newlines which is neither Unix nor Windows
+ // style - convert it to something reasonable
+ for ( ; *p; p++ )
+ {
+ if ( *p == _T('\r') )
+ *p = _T('\n');
+ }
}
}
- str.UngetWriteBuf();
-
if ( m_verRichEdit == 1 )
{
// convert to the canonical form - see comment below
{
DoWriteText(value, FALSE /* not selection only */);
}
+ else // same text
+ {
+ // still send an event for consistency
+ SendUpdateEvent();
+ }
// we should reset the modified flag even if the value didn't really change
return 0;
}
-extern long wxEncodingToCodepage(wxFontEncoding encoding); // from utils.cpp
+// from utils.cpp
+extern WXDLLIMPEXP_BASE long wxEncodingToCodepage(wxFontEncoding encoding);
#if wxUSE_UNICODE_MSLU
bool wxTextCtrl::StreamIn(const wxString& value,
void wxTextCtrl::Clear()
{
- ::SetWindowText(GetHwnd(), wxT(""));
+ ::SetWindowText(GetHwnd(), wxEmptyString);
#if wxUSE_RICHEDIT
if ( !IsRich() )
void wxTextCtrl::Remove(long from, long to)
{
- Replace(from, to, _T(""));
+ Replace(from, to, wxEmptyString);
}
bool wxTextCtrl::LoadFile(const wxString& file)
len += sizeof(WORD);
wxString str;
- wxChar *buf = str.GetWriteBuf(len);
+ {
+ wxStringBufferLength tmp(str, len);
+ wxChar *buf = tmp;
- *(WORD *)buf = (WORD)len;
- len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
- buf[len] = 0;
+ *(WORD *)buf = (WORD)len;
+ len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
+
+#if wxUSE_RICHEDIT
+ if ( IsRich() )
+ {
+ // remove the '\r' returned by the rich edit control, the user code
+ // should never see it
+ if ( buf[len - 2] == _T('\r') && buf[len - 1] == _T('\n') )
+ {
+ buf[len - 2] = _T('\n');
+ len--;
+ }
+ }
+#endif // wxUSE_RICHEDIT
+
+ // remove the '\n' at the end, if any (this is how this function is
+ // supposed to work according to the docs)
+ if ( buf[len - 1] == _T('\n') )
+ {
+ len--;
+ }
- str.UngetWriteBuf(len);
+ buf[len] = 0;
+ tmp.SetLength(len);
+ }
return str;
}
return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0;
}
+// ----------------------------------------------------------------------------
+// caret handling (Windows only)
+// ----------------------------------------------------------------------------
+
+bool wxTextCtrl::ShowNativeCaret(bool show)
+{
+ if ( show != m_isNativeCaretShown )
+ {
+ if ( !(show ? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) )
+ {
+ // not an error, may simply indicate that it's not shown/hidden
+ // yet (i.e. it had been hidden/showh 2 times before)
+ return false;
+ }
+
+ m_isNativeCaretShown = show;
+ }
+
+ return true;
+}
+
// ----------------------------------------------------------------------------
// implemenation details
// ----------------------------------------------------------------------------
#endif // wxUSE_CTL3D
HDC hdc = (HDC)pDC;
- if (GetParent()->GetTransparentBackground())
- SetBkMode(hdc, TRANSPARENT);
- else
- SetBkMode(hdc, OPAQUE);
-
wxColour colBack = GetBackgroundColour();
if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE) == 0)
Redo();
}
-void wxTextCtrl::OnDelete(wxCommandEvent& event)
+void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event))
{
long from, to;
GetSelection(& from, & to);
Remove(from, to);
}
-void wxTextCtrl::OnSelectAll(wxCommandEvent& event)
+void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event))
{
SetSelection(-1, -1);
}
event.Skip();
}
+void wxTextCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event))
+{
+ // be sure the caret remains invisible if the user had hidden it
+ if ( !m_isNativeCaretShown )
+ {
+ ::HideCaret(GetHwnd());
+ }
+}
+
// the rest of the file only deals with the rich edit controls
#if wxUSE_RICHEDIT
}
return TRUE;
}
-
+
// not processed, leave it to the base class
return wxTextCtrlBase::MSWOnNotify(idCtrl, lParam, result);
}
// the richedit 1.0 doesn't handle setting background colour, so don't
// even try to do anything if it's the only thing we want to change
- if ( m_verRichEdit == 1 && !style.HasFont() && !style.HasTextColour() )
+ if ( m_verRichEdit == 1 && !style.HasFont() && !style.HasTextColour() &&
+ !style.HasLeftIndent() && !style.HasRightIndent() && !style.HasAlignment() &&
+ !style.HasTabs() )
{
// nothing to do: return TRUE if there was really nothing to do and
// FALSE if we failed to set bg colour
wxLogDebug(_T("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed"));
}
+ // now do the paragraph formatting
+ PARAFORMAT2 pf;
+ wxZeroMemory(pf);
+ // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
+ // PARAFORMAT in that case
+#if wxUSE_RICHEDIT2
+ if ( m_verRichEdit == 1 )
+ {
+ // this is the only thing the control is going to grok
+ pf.cbSize = sizeof(PARAFORMAT);
+ }
+ else
+#endif
+ {
+ // PARAFORMAT or PARAFORMAT2
+ pf.cbSize = sizeof(pf);
+ }
+
+ if (style.HasAlignment())
+ {
+ pf.dwMask |= PFM_ALIGNMENT;
+ if (style.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT)
+ pf.wAlignment = PFA_RIGHT;
+ else if (style.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
+ pf.wAlignment = PFA_CENTER;
+ else if (style.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED)
+ pf.wAlignment = PFA_JUSTIFY;
+ else
+ pf.wAlignment = PFA_LEFT;
+ }
+
+ if (style.HasLeftIndent())
+ {
+ pf.dwMask |= PFM_STARTINDENT;
+
+ // Convert from 1/10 mm to TWIPS
+ pf.dxStartIndent = (int) (((double) style.GetLeftIndent()) * mm2twips / 10.0) ;
+
+ // TODO: do we need to specify dxOffset?
+ }
+
+ if (style.HasRightIndent())
+ {
+ pf.dwMask |= PFM_RIGHTINDENT;
+
+ // Convert from 1/10 mm to TWIPS
+ pf.dxRightIndent = (int) (((double) style.GetRightIndent()) * mm2twips / 10.0) ;
+ }
+
+ if (style.HasTabs())
+ {
+ pf.dwMask |= PFM_TABSTOPS;
+
+ const wxArrayInt& tabs = style.GetTabs();
+
+ pf.cTabCount = wxMin(tabs.GetCount(), MAX_TAB_STOPS);
+ size_t i;
+ for (i = 0; i < (size_t) pf.cTabCount; i++)
+ {
+ // Convert from 1/10 mm to TWIPS
+ pf.rgxTabs[i] = (int) (((double) tabs[i]) * mm2twips / 10.0) ;
+ }
+ }
+
+ if (pf.dwMask != 0)
+ {
+ // do format the selection
+ bool ok = ::SendMessage(GetHwnd(), EM_SETPARAFORMAT,
+ 0, (LPARAM) &pf) != 0;
+ if ( !ok )
+ {
+ wxLogDebug(_T("SendMessage(EM_SETPARAFORMAT, 0) failed"));
+ }
+ }
+
if ( changeSel )
{
// restore the original selection
return TRUE;
}
+bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
+{
+ if ( !IsRich() )
+ {
+ // can't do it with normal text control
+ return FALSE;
+ }
+
+ // initialize CHARFORMAT struct
+#if wxUSE_RICHEDIT2
+ CHARFORMAT2 cf;
+#else
+ CHARFORMAT cf;
+#endif
+
+ wxZeroMemory(cf);
+
+ // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
+ // CHARFORMAT in that case
+#if wxUSE_RICHEDIT2
+ if ( m_verRichEdit == 1 )
+ {
+ // this is the only thing the control is going to grok
+ cf.cbSize = sizeof(CHARFORMAT);
+ }
+ else
+#endif
+ {
+ // CHARFORMAT or CHARFORMAT2
+ cf.cbSize = sizeof(cf);
+ }
+ // we can only change the format of the selection, so select the range we
+ // want and restore the old selection later
+ long startOld, endOld;
+ GetSelection(&startOld, &endOld);
+
+ // but do we really have to change the selection?
+ bool changeSel = position != startOld || position != endOld;
+
+ if ( changeSel )
+ {
+ DoSetSelection(position, position, FALSE /* don't scroll caret into view */);
+ }
+
+ // get the selection formatting
+ (void) ::SendMessage(GetHwnd(), EM_GETCHARFORMAT,
+ SCF_SELECTION, (LPARAM)&cf) ;
+
+ LOGFONT lf;
+ lf.lfHeight = cf.yHeight;
+ lf.lfWidth = 0;
+ lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset?
+ lf.lfClipPrecision = 0;
+ lf.lfEscapement = 0;
+ wxStrcpy(lf.lfFaceName, cf.szFaceName);
+ if (cf.dwEffects & CFE_ITALIC)
+ lf.lfItalic = TRUE;
+ lf.lfOrientation = 0;
+ lf.lfPitchAndFamily = cf.bPitchAndFamily;
+ lf.lfQuality = 0;
+ if (cf.dwEffects & CFE_STRIKEOUT)
+ lf.lfStrikeOut = TRUE;
+ if (cf.dwEffects & CFE_UNDERLINE)
+ lf.lfUnderline = TRUE;
+ if (cf.dwEffects & CFE_BOLD)
+ lf.lfWeight = FW_BOLD;
+
+ wxFont font = wxCreateFontFromLogFont(& lf);
+ if (font.Ok())
+ {
+ style.SetFont(font);
+ }
+ style.SetTextColour(wxColour(cf.crTextColor));
+
+#if wxUSE_RICHEDIT2
+ if ( m_verRichEdit != 1 )
+ {
+ // cf.dwMask |= CFM_BACKCOLOR;
+ style.SetBackgroundColour(wxColour(cf.crBackColor));
+ }
+#endif // wxUSE_RICHEDIT2
+
+ // now get the paragraph formatting
+ PARAFORMAT2 pf;
+ wxZeroMemory(pf);
+ // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
+ // PARAFORMAT in that case
+#if wxUSE_RICHEDIT2
+ if ( m_verRichEdit == 1 )
+ {
+ // this is the only thing the control is going to grok
+ pf.cbSize = sizeof(PARAFORMAT);
+ }
+ else
+#endif
+ {
+ // PARAFORMAT or PARAFORMAT2
+ pf.cbSize = sizeof(pf);
+ }
+
+ // do format the selection
+ (void) ::SendMessage(GetHwnd(), EM_GETPARAFORMAT, 0, (LPARAM) &pf) ;
+
+ style.SetLeftIndent( (int) ((double) pf.dxStartIndent * twips2mm * 10.0) );
+ style.SetRightIndent( (int) ((double) pf.dxRightIndent * twips2mm * 10.0) );
+
+ if (pf.wAlignment == PFA_CENTER)
+ style.SetAlignment(wxTEXT_ALIGNMENT_CENTRE);
+ else if (pf.wAlignment == PFA_RIGHT)
+ style.SetAlignment(wxTEXT_ALIGNMENT_RIGHT);
+ else if (pf.wAlignment == PFA_JUSTIFY)
+ style.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED);
+ else
+ style.SetAlignment(wxTEXT_ALIGNMENT_LEFT);
+
+ wxArrayInt tabStops;
+ size_t i;
+ for (i = 0; i < (size_t) pf.cTabCount; i++)
+ {
+ tabStops[i] = (int) ((double) (pf.rgxTabs[i] & 0xFFFF) * twips2mm * 10.0) ;
+ }
+
+ if ( changeSel )
+ {
+ // restore the original selection
+ DoSetSelection(startOld, endOld, FALSE);
+ }
+
+ return TRUE;
+}
+
#endif
// ----------------------------------------------------------------------------
if ( ms_hRichEdit[i] )
{
::FreeLibrary(ms_hRichEdit[i]);
+ ms_hRichEdit[i] = NULL;
}
}
}