BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
EVT_CHAR(wxTextCtrl::OnChar)
+ EVT_KEY_DOWN(wxTextCtrl::OnKeyDown)
EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
#if wxUSE_RICHEDIT
valueWin = value;
}
+ // suppress events sent during control creation: we're called either from
+ // the ctor and then we shouldn't generate any events for compatibility
+ // with the other ports, or from SetWindowStyleFlag() and then we shouldn't
+ // generate the events because our text doesn't really change, the fact
+ // that we (sometimes) need to recreate the control is just an
+ // implementation detail
+ m_updatesCount = -2;
+
if ( !MSWCreateControl(windowClass.wx_str(), msStyle, pos, size, valueWin) )
return false;
+ m_updatesCount = -1;
+
#if wxUSE_RICHEDIT
if (IsRich())
{
encoding = font.GetEncoding();
}
+#if wxUSE_INTL
if ( encoding == wxFONTENCODING_SYSTEM )
{
encoding = wxLocale::GetSystemEncoding();
}
+#endif // wxUSE_INTL
if ( encoding == wxFONTENCODING_SYSTEM )
{
const size_t len = conv.MB2WC(NULL, value.mb_str(), value.length());
+ if (len == wxCONV_FAILED)
+ return false;
+
#if wxUSE_WCHAR_T
wxWCharBuffer wchBuf(len);
wchar_t *wpc = wchBuf.data();
// conversion but what else can we do)
wxCSConv conv(encoding);
size_t lenNeeded = conv.WC2MB(NULL, wchBuf, 0);
- if ( lenNeeded++ )
+
+ if ( lenNeeded != wxCONV_FAILED && lenNeeded++ )
{
conv.WC2MB(wxStringBuffer(out, lenNeeded), wchBuf, lenNeeded);
}
#if wxUSE_RICHEDIT
if ( IsRich() )
{
+ // if from and to are both -1, it means (in wxWidgets) that all text
+ // should be selected, translate this into Windows convention
+ if ( (from == -1) && (to == -1) )
+ {
+ from = 0;
+ }
+
CHARRANGE range;
range.cpMin = from;
range.cpMax = to;
else
#endif // wxUSE_RICHEDIT
{
- ::SendMessage(hWnd, EM_SETSEL, from, to);
+ wxTextEntry::DoSetSelection(from, to, flags);
}
if ( (flags & SetSel_Scroll) && !IsFrozen() )
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
InitCommandEvent(event);
event.SetString(GetValue());
- if ( GetEventHandler()->ProcessEvent(event) )
+ if ( HandleWindowEvent(event) )
if ( !HasFlag(wxTE_MULTILINE) )
return;
//else: multiline controls need Enter for themselves
event.Skip();
}
+void wxTextCtrl::OnKeyDown(wxKeyEvent& event)
+{
+ // richedit control doesn't send WM_PASTE, WM_CUT and WM_COPY messages
+ // when Ctrl-V, X or C is pressed and this prevents wxClipboardTextEvent
+ // from working. So we work around it by intercepting these shortcuts
+ // ourselves and emitting clipboard events (which richedit will handle,
+ // so everything works as before, including pasting of rich text):
+ if ( event.GetModifiers() == wxMOD_CONTROL && IsRich() )
+ {
+ switch ( event.GetKeyCode() )
+ {
+ case 'C':
+ Copy();
+ return;
+ case 'X':
+ Cut();
+ return;
+ case 'V':
+ Paste();
+ return;
+ default:
+ break;
+ }
+ }
+
+ // no, we didn't process it
+ event.Skip();
+}
+
WXLRESULT wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
WXLRESULT lRc = wxTextCtrlBase::MSWWindowProc(nMsg, wParam, lParam);
}
}
break;
-
- case WM_CUT:
- case WM_COPY:
- case WM_PASTE:
- if ( HandleClipboardEvent(nMsg) )
- lRc = 0;
- break;
}
return lRc;
{
switch ( param )
{
- case EN_SETFOCUS:
- case EN_KILLFOCUS:
- {
- wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
- : wxEVT_SET_FOCUS,
- m_windowId);
- event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event);
- }
- break;
-
case EN_CHANGE:
SendUpdateEvent();
break;
}
break;
- // the other edit notification messages are not processed
+ // the other edit notification messages are not processed (or, in
+ // the case of EN_{SET/KILL}FOCUS were already handled at WM_SET/
+ // KILLFOCUS level)
default:
return false;
}
void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event))
{
- long from, to;
- GetSelection(& from, & to);
- if (from != -1 && to != -1)
- Remove(from, to);
+ RemoveSelection();
}
void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event))
{
- SetSelection(-1, -1);
+ SelectAll();
}
void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event)
{
- long from, to;
- GetSelection(& from, & to);
- event.Enable(from != -1 && to != -1 && from != to && IsEditable()) ;
+ event.Enable( HasSelection() && IsEditable() );
}
void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
{
- event.Enable(GetLastPosition() > 0);
+ event.Enable( !IsEmpty() );
}
void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
event.Skip();
}
-void wxTextCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event))
+void wxTextCtrl::OnSetFocus(wxFocusEvent& event)
{
// be sure the caret remains invisible if the user had hidden it
if ( !m_isNativeCaretShown )
{
::HideCaret(GetHwnd());
}
+
+ event.Skip();
}
// ----------------------------------------------------------------------------
// the real height in twips and not the negative number which
// wxFillLogFont() returns (this is correct in general and works with
// the Windows font mapper, but not here)
+
+ wxFont font(style.GetFont());
+
LOGFONT lf;
- wxFillLogFont(&lf, &style.GetFont());
- cf.yHeight = 20*style.GetFont().GetPointSize(); // 1 pt = 20 twips
+ wxFillLogFont(&lf, &font);
+ cf.yHeight = 20*font.GetPointSize(); // 1 pt = 20 twips
cf.bCharSet = lf.lfCharSet;
cf.bPitchAndFamily = lf.lfPitchAndFamily;
wxStrncpy( cf.szFaceName, lf.lfFaceName, WXSIZEOF(cf.szFaceName) );