#if wxUSE_RICHEDIT
if ( m_isRich )
{
- int len = GetWindowTextLength(GetHwnd()) + 1;
-
wxString str;
- wxChar *p = str.GetWriteBuf(len);
- TEXTRANGE textRange;
- textRange.chrg.cpMin = 0;
- textRange.chrg.cpMax = -1;
- textRange.lpstrText = p;
+ int len = GetWindowTextLength(GetHwnd());
+ if ( len )
+ {
+ // alloc one extra WORD as needed by the control
+ wxChar *p = str.GetWriteBuf(++len);
- (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
+ TEXTRANGE textRange;
+ textRange.chrg.cpMin = 0;
+ textRange.chrg.cpMax = -1;
+ textRange.lpstrText = p;
- // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for the
- // newlines which is neither Unix nor Windows style (Win95 with
- // riched20.dll shows this behaviour) - convert it to something
- // reasonable
- for ( ; *p; p++ )
- {
- if ( *p == _T('\r') )
- *p = _T('\n');
- }
+ (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
- str.UngetWriteBuf();
+ // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for
+ // the newlines which is neither Unix nor Windows style (Win95 with
+ // riched20.dll shows this behaviour) - convert it to something
+ // reasonable
+ for ( ; *p; p++ )
+ {
+ if ( *p == _T('\r') )
+ *p = _T('\n');
+ }
+
+ str.UngetWriteBuf();
+ }
+ //else: no text at all, leave the string empty
return str;
}
// Can copy if there's a selection
long from, to;
GetSelection(& from, & to);
- return (from != to);
+ return (from != to) ;
}
bool wxTextCtrl::CanCut() const
// Can cut if there's a selection
long from, to;
GetSelection(& from, & to);
- return (from != to);
+ return (from != to) && (IsEditable());
}
bool wxTextCtrl::CanPaste() const
int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if ( m_windowStyle & wxTE_MULTILINE )
{
- hText *= wxMin(GetNumberOfLines(), 5);
+ hText *= wxMax(GetNumberOfLines(), 5);
}
//else: for single line control everything is ok