OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
richedit.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TRichEdit.
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/richedit.h>
10#include <owl/filename.h>
11
12#if defined(__BORLANDC__)
13# pragma option -w-ccc // Disable "Condition is always true/false"
14#endif
15
16using namespace std;
17
18namespace owl {
19
21
22// Range of the editor's font size
23//
24const int MinPointSize = 6;
25const int MaxPointSize = 128;
26
27// System DLL providing underlying support for RichEdit controls
28//
29const tchar RichEditDllName[] = _T("RICHED32.DLL");
30const tchar RichEdit20DllName[] = _T("RICHED20.DLL");
31
32#if defined(UNICODE)
33# if defined(MSFTEDIT_CLASS)
34# define OWL_USERICHEDIT41
35# endif
36#endif
37
38
39#if defined(OWL_USERICHEDIT41)
40const tchar RichEdit41DllName[] = _T("Msftedit.dll");
41#endif
42
43////////////////////////////////////////////////////////////////////////////////
44//
45//
46
47//
48/// Constructs a CharacterFormat structure from the current character attributes of
49/// a RICHEDIT control.
50/// \note Specifying 'true' for selection will return the attribute of the character
51/// at the current location if there are no block of data selected in the control.
52//
54{
55 PRECONDITION((HWND)edit);
56
57 memset(this, 0, sizeof(CHARFORMAT2));
58
59 cbSize = sizeof(::CHARFORMAT); //LB
60 if(TRichEditDll::Dll()->GetVersion() >= 2)
61 cbSize = sizeof(CHARFORMAT2);
62
63 dwMask = mask;
64 edit.GetCharFormat(*this, selection);
65}
66
67//
68/// Toggles the bold character attribute according to the boolean parameter specified.
69//
70void
72{
74 if (flag)
76 else
78}
79
80//
81/// Toggles italic character attribute based on the boolean parameter specified.
82//
83void
92
93//
94/// Toggles the underline character attribute based on the boolean parameter specified.
95//
96void
105
106//
107/// Toggles the strike-out character attribute based on the boolean parameter specified.
108//
109void
118
119//
120/// Toggles the protected character attribute based on the boolean parameter specified.
121//
122void
131
132//
133/// Retrieves the character color stored in the CHARFORMAT structure.
134/// \note Default to system text color if no explicit color was set in the
135/// CHARFORMAT structure.
136//
137TColor
139{
140 if ((dwMask & CFM_COLOR) && !(dwEffects & CFE_AUTOCOLOR))
141 return TColor(crTextColor);
143}
144
145//
146/// Updates the CHARFORMAT structure with the specified color.
147/// \note If 'TColor::None' is specified, enable the flag specifying that the color
148/// should default to the system text color.
149//
150void
152{
153 dwMask |= CFM_COLOR;
154 if (color == TColor::None)
156 else {
159 }
160}
161
162//
163/// Sets the face name of the font.
164///
165/// \note If the given \p name is greater or equal to `LF_FACESIZE`, the name is truncated.
166//
167void
174
175//
176/// Sets the character set of the font. Valid values include the following:
177/// ANSI_CHARSET, OEM_CHARSET, and SYMBOL_CHARSET.
178//
179void
184
185//
186/// Sets the pitch and family of the font. The two lower-bits specify the pitch of
187/// the font and can be one of the following values:
188/// DEFAULT_PITCH, FIXED_PITCH, or VARIABLE_PITCH.
189///
190/// Bits 4 through 7 of the member specify the font family and can be one of the
191/// following values:
192/// FF_DECORATIVE, FF_DONTCARE, FF_MODERN, FF_ROMAN, FF_SCRIPT or FF_SWISS.
193//
194void
199
200//
201/// Sets the character height.
202//
203void
205{
206 dwMask |= CFM_SIZE;
207 yHeight = height;
208}
209
210//
211/// Sets the character offset from the baseline. If the parameter is positive, the
212/// character is a superscript; if it is negative, the character is a subscript.
213//
214void
220
221//
222/// Transfers the information currently in the underlying CHARFORMAT structure to a
223/// LOGFONT structure. This is useful when changing the editor's font, as
224/// initialized LOGFONT structure can subsequently be used when invoking the FONT
225/// Common Dialog (i.e., TChooseFontDialog).
226//
227void
229{
230 memset(&lf, 0, sizeof(LOGFONT));
231
232 if (dwMask & CFM_SIZE) // (1 Point == 20 twips)
233 lf.lfHeight = yHeight/-20;
234
235 if (dwMask & CFM_BOLD)
236 lf.lfWeight = dwEffects & CFE_BOLD ? FW_BOLD : FW_NORMAL;
237
238 if (dwMask & CFM_ITALIC)
239 lf.lfItalic = static_cast<uint8>(dwEffects & CFE_ITALIC ? TRUE : FALSE);
240
241 if (dwMask & CFM_UNDERLINE)
242 lf.lfUnderline = static_cast<uint8>(dwEffects & CFE_UNDERLINE ? TRUE : FALSE);
243
244 if (dwMask & CFM_FACE) {
245 lf.lfPitchAndFamily = bPitchAndFamily;
246 lf.lfFaceName[0] = _T('\0');
247 ::_tcsncat(lf.lfFaceName, szFaceName, LF_FACESIZE - 1);
248 }
249
250 lf.lfCharSet = DEFAULT_CHARSET;
251 lf.lfQuality = DEFAULT_QUALITY;
252}
253
254//
255/// Initializes the underlying CHARFORMAT structure using the information stored in
256/// a LOGFONT structure.
257//
258void
260{
263
264 yHeight = lf.lfHeight * -20;
265
266 if (FW_BOLD == lf.lfWeight)
268 if (lf.lfItalic)
270 if (lf.lfStrikeOut)
272 if (lf.lfUnderline)
274
275 bPitchAndFamily = lf.lfPitchAndFamily;
276 szFaceName[0] = _T('\0');
277 ::_tcsncat(szFaceName, lf.lfFaceName, LF_FACESIZE - 1);
278}
279
280//
281/// Sets Font weight (LOGFONT value).
282/// \note RichEdit 2.0 specific
283void
289
290//
291/// Sets Amount to space between letters.
292/// \note RichEdit 2.0 specific
293void
299
300//
301/// Retrieves the character background color stored in the CHARFORMAT structure.
302/// \note RichEdit 2.0 specific
303//
304TColor
306{
308 return TColor(crBackColor);
309 return TColor::SysWindow;
310}
311
312//
313/// Sets Background color.
314/// \note RichEdit 2.0 specific
315void
326
327//
328// Locale ID
329// RichEdit 2.0 specific
330void
336
337//
338/// Sets Style handle.
339/// \note RichEdit 2.0 specific
340void
342{
343 dwMask |= CFM_STYLE;
344 sStyle = style;
345}
346
347//
348/// Twip size above which to kern char pair.
349/// \note RichEdit 2.0 specific
350void
356
357//
358/// Set underline type.
359/// \note RichEdit 2.0 specific
360void
366
367//
368/// Animated text like marching ants.
369/// \note RichEdit 2.0 specific
370void
376
377//
378/// Sets Revision author index.
379/// \note RichEdit 2.0 specific
380void
386
387////////////////////////////////////////////////////////////////////////////////
388//
389//
390
391//
392/// Constructs a TFormatRange object initializing data members with the specified parameters.
393//
403
404//
405/// Sets the device context of the device to render to.
406//
407void
412
413//
414/// Sets the device context of the target device to format for.
415//
416void
421
422//
423/// Sets the area to render to.
424/// \note The specified units are in TWIPS.
425//
426void
431
432//
433/// Sets the entire area of the rendering device.
434/// \note The specified units are in TWIPS.
435//
436void
441
442//
443/// Sets the range of text to format.
444//
445void
450
451//
452/// Sets the range of text to format, specifying the starting and ending character offsets.
453//
454void
456{
457 chrg.cpMin = start;
458 chrg.cpMax = end;
459}
460
461////////////////////////////////////////////////////////////////////////////////
462//
463/// Constructs a default TParaFormat structure.
464//
466{
467 memset(this, 0, sizeof(PARAFORMAT2));
468
469 cbSize = sizeof(PARAFORMAT);
470 if(TRichEditDll::Dll()->GetVersion() >= 2)
471 cbSize = sizeof(PARAFORMAT2);
472
473 dwMask = mask;
474}
475
476//
477/// Constructs a TParaFormat structure whose members are initialized with the
478/// paragraph formatting attributes of the current selection of a rich edit control.
479//
481{
482 PRECONDITION((HWND)edit);
483
484 memset(this, 0, sizeof(PARAFORMAT2));
485
486 cbSize = sizeof(PARAFORMAT);
487 if(TRichEditDll::Dll()->GetVersion() >= 2)
488 cbSize = sizeof(PARAFORMAT2);
489
490 dwMask = mask;
491 edit.GetParaFormat(*this);
492}
493
494//
495/// Toggles the specified flag in the member which describes which information of
496/// the PARAFORMAT structures is valid.
497//
498void
503
504//
505/// Sets the numbering options. The only valid parameter is '0' or PFN_BULLET.
506//
507void
515
516//
517/// Sets the indentation of the first line in the paragraph. If the paragraph
518/// formatting is being set and the 'relative' parameter is true, the 'start' value
519/// is treated as a relative value that is added to the starting indentation of each
520/// affected paragraph.
521//
522void
533
534//
535/// Sets the size of the right identation, relative to the right margin.
536//
537void
543
544//
545/// Sets the indentation of the second line and subsequent lines, relative to the
546/// starting indentation. The first line is indented if the 'offset' parameter is
547/// negative, or outdented if it is positive.
548//
549void
555
556//
557/// Sets the alignment option. The 'opt' parameter can be one of the following values:
558/// - \c \b PFA_LEFT Paragraphs are aligned with the left margin.
559/// - \c \b PFA_RIGHT Paragraphs are aligned with the right margin.
560/// - \c \b PFA_CENTER Paragraphs are centered.
561//
562void
568
569//
570/// Sets the number and absolute positions of the tab stops.
571//
572void
574{
575 PRECONDITION(tabs || !cnt);
576
578 cTabCount = cnt;
579 for (int i=0; i<cnt; i++)
580 rgxTabs[i] = *tabs++;
581}
582
583//
584// Vertical spacing before para
585// RichEdit 2.0 specific
586void
592
593//
594// Vertical spacing after para
595// RichEdit 2.0 specific
596void
602
603//
604// Line spacing depending on Rule
605// RichEdit 2.0 specific
606void
613
614//
615// Style handle
616// RichEdit 2.0 specific
617void
619{
620 dwMask |= PFM_STYLE;
621 sStyle = style;
622}
623
624//
625// Shading in hundredths of a per cent
626// Nibble 0: style, 1: cfpat, 2: cbpat
627// RichEdit 2.0 specific
628void
635
636//
637// Starting value for numbering
638// RichEdit 2.0 specific
639void
645
646//
647// Alignment, roman/arabic, (), ), ., etc.
648// RichEdit 2.0 specific
649void
655
656//
657// Space bet 1st indent and 1st-line text
658// RichEdit 2.0 specific
659void
665
666//
667// Space between border and text (twips)
668// RichEdit 2.0 specific
669void
677
678////////////////////////////////////////////////////////////////////////////////
679//
680//
681
683 EV_COMMAND(CM_EDITCUT, CmEditCut),
684 EV_COMMAND(CM_EDITCOPY, CmEditCopy),
685 EV_COMMAND(CM_EDITPASTE, CmEditPaste),
686 EV_COMMAND(CM_EDITDELETE, CmEditDelete),
687 EV_COMMAND(CM_EDITCLEAR, CmEditClear),
688 EV_COMMAND(CM_EDITUNDO, CmEditUndo),
701
702//
703/// Constructor for a TRichEdit object. By default, edit control has a border and
704/// its text is left-justified. Multiline edit control has horizontal vertical
705/// scroll bars.
706//
708 int id,
710 int x, int y, int w, int h,
712 TModule* module)
713:
714 TEditFile(parent, id, text, x, y, w, h, fileName, module)
715{
716 // Make sure the RichEdit DLL is available
717 //
718 if (!TRichEditDll::IsAvailable())
719 TXCommCtrl::Raise(); // !BB Do we need a richedit-specific exception
720
721 // Default to RTF data format
722 //
724 // hide stuff that RichEdit doesn't support
725 // Richedit support it now
726 //GetSearchData().Flags |= FR_HIDEUPDOWN;
727
728 // Undo the styles specific to "EDIT" controls; add richedit styles
729 //
732}
733
734//
735/// String-aware overload
736//
738 TWindow* parent,
739 int id,
740 const tstring& text,
741 int x, int y, int w, int h,
742 const tstring& fileName,
743 TModule* module
744 )
745 : TEditFile(parent, id, text, x, y, w, h, fileName, module)
746{
747 // Make sure the RichEdit DLL is available
748 //
749 if (!TRichEditDll::IsAvailable())
750 TXCommCtrl::Raise(); // !BB Do we need a richedit-specific exception
751
752 // Default to RTF data format
753 //
755 // hide stuff that RichEdit doesn't support
756 // Richedit support it now
757 //GetSearchData().Flags |= FR_HIDEUPDOWN;
758
759 // Undo the styles specific to "EDIT" controls; add richedit styles
760 //
763}
764
765//
766/// Constructor for TRichEdit associated with a MS-Windows interface element
767/// created by MS-Windows from a resource definition.
768///
769/// By default, data transfer is enabled
770//
772 int resourceId,
773 TModule* module)
774:
775 TEditFile(parent, resourceId, module ? *module : *parent->GetModule())
776{
777 // Make sure the RichEdit DLL is available
778 //
779 if (!TRichEditDll::IsAvailable())
780 TXCommCtrl::Raise(); // !BB Do we need a richedit-specific exception
781}
782
783
784//
785/// Retrieves the current character formatting in an edit control. If 'selection'
786/// parameter is 'true', the attribute of the current selection is retrieved.
787/// Otherwise, the default formatting attribute is retrieved.
788//
789ulong
791{
793 TParam2 a2 = reinterpret_cast<TParam2>(&cf);
794 return static_cast<ulong>(SendMessage(EM_GETCHARFORMAT, a1, a2));
795}
796
797//
798/// Retrieves the paragraph formatting of the current selection of the rich edit control.
799/// \note If more than one paragraph is selected, the structure receives the
800/// attributes of the first paragraph, and the dwMask member specifies which
801/// attributes are consistent throughout the entire selection.
802//
803ulong
805{
806 TParam2 a2 = reinterpret_cast<TParam2>(&pf);
807 return static_cast<ulong>(SendMessage(EM_GETPARAFORMAT, 0, a2));
808}
809
810//
811/// Sets the character formatting of a rich edit control. The 'flags' parameter can
812/// be one of the following:
813/// - \c \b SCF_SELECTION Applies the formatting to the current selection, or sets the
814/// default formatting if the selection is empty.
815/// - \c \b SCF_WORD Applies the formatting to the selected word or words. If the
816/// selection is empty but the insertion point is inside a word, the formatting is
817/// applied to the word. This value must be used in conjunction with the
818/// SCF_SELECTION value.
819//
820bool
822{
823 return SendMessage(EM_SETCHARFORMAT, TParam1(flags), TParam2(&cf)) != 0;
824}
825
826//
827/// Sets the paragraph formatting of the current selection of the rich edit control.
828//
829bool
834
835//
836/// Sets the background color of the rich edit control.
837/// \note If 'TColor::None' is specified, the color is set to the window background
838/// system color.
839//
840TColor
842{
843 TParam1 p1 = bkColor == TColor::None ? true : false;
844 TParam2 p2 = bkColor == TColor::None ? 0 : static_cast<COLORREF>(bkColor);
845 return TColor(static_cast<COLORREF>(SendMessage(EM_SETBKGNDCOLOR, p1, p2)));
846}
847
848//
849/// Function returns whether or not the current selection has a particular
850/// attribute. The 'mask' identifies the attribute of interest. The 'effects'
851/// contains the state of the attributes. The function returns
852/// - \c \b TFmtStatus::Yes : if the attribute is enabled.
853/// - \c \b TFmtStatus::No: if the attribute is absent.
854/// - \c \b TFmtStatus::Partly: if the attribute is partly present.
855//
856uint
858{
859 TCharFormat cf(*this);
860 if (cf.dwMask & mask) {
861 if (cf.dwEffects & effects)
862 return Yes;
863 else
864 return No;
865 }
866 else
867 return Partly;
868}
869
870//
871/// Toggles a set of character attributes. The 'mask' identifies the attributes of
872/// interest while 'effects' identifies the state of the attributes.
873//
874bool
876{
877 TCharFormat cf(*this);
878 cf.dwMask = mask;
880 return SetCharFormat(cf);
881}
882
883//
884/// Increases or decreases (using a positive or negative value respectively) the
885/// point size of the current selection.
886//
887bool
889{
890 TCharFormat cf(*this);
891 cf.dwMask = CFM_SIZE;
892 if (((cf.yHeight + 20*pointSizeDelta) <= (MaxPointSize*20)) &&
893 ((cf.yHeight + 20*pointSizeDelta) >= (MinPointSize*6))) {
894 cf.yHeight += 20*pointSizeDelta;
895 return SetCharFormat(cf);
896 }
897 return false;
898}
899
900//
901/// Returns true if the rich edit control has an active selection. Returns false
902/// otherwise.
903//
904bool
906{
908 return r.cpMin != r.cpMax;
909}
910
911//
912/// Retrieves the starting and ending character position of the selection in the
913/// rich edit control.
914//
915void
917{
919 CONST_CAST(TRichEdit*,this)->SendMessage(EM_EXGETSEL, 0, TParam2(&cr));
920 startPos = cr.cpMin;
921 endPos = cr.cpMax;
922}
923
924//
925/// Retrieves the starting and ending character positions of the selection of the
926/// richedit control.
927//
928void
930{
931 WARN(true, _T("TRichEdit::GetSelRange is deprecated. Use GetSelection instead."));
932 CONST_CAST(TRichEdit*,this)->SendMessage(EM_EXGETSEL, 0, TParam2(&cr));
933}
934
935//
936/// Selects a range of characters in the rich edit control.
937//
938bool
940{
942 return SetSelRange(cr) >= 0;
943}
944
945//
946/// Selects a range of characters in the rich edit control.
947//
948int
950{
951 return static_cast<int>(SendMessage(EM_EXSETSEL, 0, TParam2(&cr)));
952}
953
954//
955/// Shows or hides the selection in the rich edit control. The 'hide' parameter
956/// specifies whether to hide or show the selection. If it is 'false' the selection
957/// is shown. Otherwise, the selection is hidden. The 'changeStyle' parameter
958/// specifies whether to change the control's ES_NOHIDESEL window style. If this
959/// parameter is 'false', the selection is temporarily shown or hidden. Otherwise,
960/// the style is changed. If this parameter is 'true' and the control has the focus,
961/// the selection is hidden or shown as appropriate.
962//
963void
968
969//
970/// Returns the selection type of the rich edit control. Returns SEL_EMPTY if the
971/// selection is empty, or one or more of the following values:
972/// - \c \b SEL_TEXT Text
973/// - \c \b SEL_OBJECT At least one OLE object
974/// - \c \b SEL_MULTICHAR More than one character of text
975/// - \c \b SEL_MULTIOBJECT More than one OLE object
976//
977ulong
979{
980 return static_cast<ulong>(SendMessage(EM_SELECTIONTYPE));
981}
982
983
984//
985// Return the lenght of the text in the richedit control
986// for RichEdit 2.0 uses EM_GETTEXTLENGTH
987//
988int
990{
991 if (TRichEditDll::Dll()->GetVersion() >= 2)
992 {
994 gtl.flags = GTL_DEFAULT;
995
996//Jogy ??? From MSDN: Code page used in the translation. It is CP_ACP for ANSI Code Page and 1200 for Unicode.
997#if defined(UNICODE)
998 gtl.codepage = 1200;
999#else
1000 gtl.codepage = CP_ACP;
1001#endif
1002
1003 return static_cast<int>(SendMessage(EM_GETTEXTLENGTHEX, TParam1(&gtl), TParam2(0)));
1004 }
1005 else
1006 {
1007 return GetWindowTextLength();
1008 }
1009}
1010
1011//
1012/// Retrieves a specified range of text from the rich edit control.
1013/// NB! Deprecated. Use GetTextRange(const TRange&) instead.
1014//
1015int
1017{
1018 return static_cast<int>(CONST_CAST(TRichEdit*,this)->SendMessage(EM_GETTEXTRANGE, 0, TParam2(&tr)));
1019}
1020
1021//
1022/// Retrieves a specified range of text from the rich edit control.
1023/// NB! Deprecated. Use GetTextRange(const TRange&) instead.
1024//
1025int
1027{
1028 WARN(true, _T("TRichEdit::GetTextRange(const TCharRange&, LPTSTR) is deprecated. Use GetTextRange(const TRange&) instead."));
1030 const auto r = static_cast<int>(CONST_CAST(TRichEdit*, this)->SendMessage(EM_GETTEXTRANGE, 0, TParam2(&tr)));
1031 return r;
1032}
1033
1034//
1035/// For use with CopyText
1036//
1037struct TRichEditGetTextRange
1038{
1039 const TRichEdit& edit;
1040 const TCharRange& range;
1041 TRichEditGetTextRange(const TRichEdit& e, const TCharRange& r) : edit(e), range(r) {}
1042
1043 int operator()(LPTSTR buf, int)
1044 {
1045 TTextRange tr(range, buf);
1046 return static_cast<int>(CONST_CAST(TRichEdit*, &edit)->SendMessage(EM_GETTEXTRANGE, 0, TParam2(&tr)));
1047 }
1048};
1049
1050//
1051/// Retrieves a specified range of text from the rich edit control.
1052/// The range is half-open; i.e. range [0,2) for "abc" returns "ab".
1053/// An empty string is returned if either
1054///
1055/// - the control is empty (no text), or
1056/// - the range is invalid (empty or inverted), or
1057/// - both startPos and endPos is beyond the extents of the actual text.
1058///
1059/// If endPos is beyond the valid range then it is limited to the valid range.
1060/// A special case is the range [0, -1). It will return the full text.
1061///
1062/// \todo Must be tested
1063//
1064tstring
1066{
1067 const int begin = r.cpMin;
1068 int end = r.cpMax; // May be adjusted.
1069 const int n = GetTextLength();
1070
1071 // Check input arguments against EM_GETTEXTRANGE requirements.
1072 // Note that [0, -1) for an empty control is not valid for EM_GETTEXTRANGE,
1073 // but we'll ignore that, since no buffer issues are involved here.
1074 // Otherwise we reject negative positions, as well as empty and inverted ranges.
1075 // EM_GETTEXTRANGE will not null-terminate the result in these cases.
1076
1077 if (begin == 0 && end == -1)
1078 {
1079 end = n;
1080 }
1081 else if (begin < 0 || end < 0)
1082 {
1083 WARN(true, _T("Arguments out of range"));
1084 return tstring();
1085 }
1086 else if (begin == end)
1087 {
1088 WARN(true, _T("Empty range"));
1089 return tstring();
1090 }
1091 else if (begin > end)
1092 {
1093 WARN(true, _T("Inverted range"));
1094 return tstring();
1095 }
1096
1097 // Return empty if the entire range is outside the extents of the actual text.
1098 // This is valid for EM_GETTEXTRANGE so we wont complain.
1099
1100 if (begin >= n)
1101 return tstring();
1102
1103 // Limit end to the actual text and calculate the resulting range length.
1104
1105 end = std::min(end, n);
1106 const int range_length = end - begin; // length of half-open range
1107
1108 // Do a sanity check, in case someone changes the code, etc,
1109 // then finally copy!
1110
1111 CHECK(begin >= 0 && end >= 0 && begin < n && end <= n);
1112 TCharRange adjusted_range(begin, end);
1113 return CopyText(range_length, TRichEditGetTextRange(*this, adjusted_range));
1114}
1115
1116//
1117/// Retrieves a specified range of text from the rich edit control.
1118/// NB! Deprecated. Use GetTextRange instead.
1119//
1120void
1122{
1123 WARN(true, _T("TRichEdit::GetSubText is deprecated. Use GetTextRange instead."));
1126}
1127
1128//
1129/// Retrieves the currently-selected text of the rich edit control.
1130//
1131int
1133{
1134 return static_cast<int>(CONST_CAST(TRichEdit*,this)->SendMessage(EM_GETSELTEXT, 0, TParam2(buffer)));
1135}
1136
1137//
1138/// For use with CopyText
1139//
1140struct TRichEditGetSelectedText
1141{
1142 const TRichEdit& edit;
1143 TRichEditGetSelectedText(const TRichEdit& e) : edit(e){}
1144
1145 int operator()(LPTSTR buf, int)
1146 {return static_cast<int>(CONST_CAST(TRichEdit*, &edit)->SendMessage(EM_GETSELTEXT, 0, TParam2(buf)));}
1147};
1148
1149//
1150/// String-aware overload
1151//
1152tstring
1154{
1155 const int n = GetSelection().GetSize();
1156 return (n > 0) ? CopyText(n, TRichEditGetSelectedText(*this)) : tstring();
1157}
1158
1159//
1160/// Sets an upper limit to the amount of text in the richedit control.
1161//
1162void
1167
1168//
1169/// Finds text within the rich edit control. The 'flags' parameter can be a
1170/// combination of the following values:
1171/// - \c \b FT_MATCHCASE Performs a case sensitiv search.
1172/// - \c \b FT_MATCHWORD Matches whole words.
1173//
1174int
1176{
1177 return static_cast<int>(SendMessage(EM_FINDTEXT, TParam1(flags), TParam2(&ft)));
1178}
1179
1180//
1181/// Finds text within the rich edit control. The 'flags' parameter can be a
1182/// combination of the following values:
1183/// - \c \b FT_MATCHCASE Performs a case sensitiv search.
1184/// - \c \b FT_MATCHWORD Matches whole words.
1185//
1186int
1188{
1189 TFindText ft(cr, text);
1190 return FindText(flags, ft);
1191}
1192
1193//
1194// Search for the specified text in the rich edit control. If found, select
1195// the text and return the offset of the text. Otherwise, return -1.
1196//
1197// NOTE: If the 'startPos' is -1, it is assumed that the starting position is
1198// the end [or beginning, depending on the direction parameter, 'up'] of the
1199// current selection
1200//
1201int
1203 bool wholeWord, bool up)
1204{
1205 if (!text || !text[0])
1206 return -1;
1207
1208 if (startPos == -1) {
1209 int sBeg, sEnd;
1211 startPos = up ? sBeg : sEnd;
1212 }
1213
1214 // The current docs. mention the FT_MATCHCASE and FT_WHOLEWORD flags which
1215 // are not defined currently. I suspect they meant the FR_xxxx flags (used
1216 // in CommDlg API).
1217 // Yes it is FR_MATCHCASE and FR_WHOLEWORD
1219 uint flags = (caseSensitive ? FR_MATCHCASE : 0) |
1220 (wholeWord ? FR_WHOLEWORD : 0) |
1221 (up ? 0 : FR_DOWN);
1222 int index = FindText(flags, findText);
1223
1224 //
1225 // If we've got a match, select the text
1226 //
1227 if (index >= 0)
1228 {
1229 size_t end = index + ::_tcslen(text);
1230 if (!IsRepresentable<int>(end))
1231 return -1;
1232 SetSelection(index, static_cast<int>(end));
1233 }
1234 return index;
1235}
1236
1237//
1238// Find the next work break before or after the specified character position,
1239// or retrieve information about the character at that position. The 'code'
1240// parameter can be one of the following:
1241//
1242// WB_CLASSIFY Returns the character class and word break flags of the
1243// character at the specified position.
1244// WB_ISDELIMITER Returns TRUE if the character at the specified position
1245// is a delimiter, or FALSE otherwise.
1246// WB_LEFT Finds the nearest character before the specified
1247// position that begins a word.
1248// WB_LEFTBREAK Finds the next word end before the specified position.
1249// WB_MOVEWORDLEFT Finds the next character that begins a word before the
1250// specified position. This value is used during CTRL+LEFT key processing.
1251// WB_MOVEWORDRIGHT Finds the next character that begins a word after the
1252// specified position. This value is used during
1253// CTRL+RIGHT key processing.
1254// WB_RIGHT Finds the next character that begins a word after the
1255// specified position.
1256// WB_RIGHTBREAK Finds the next end-of-word delimiter after the
1257// specified position.
1258//
1259// The return value is the character index of the word break, unless the
1260// 'code' parameter is WB_CLASSIFY or WB_ISDELIMETER
1261int
1263{
1264 return static_cast<int>(SendMessage(EM_FINDWORDBREAK, TParam1(code), TParam2(start)));
1265}
1266
1267//
1268// Determine which line contains the specified character in the richedit
1269// control.
1270// NOTE: The return value is zero-based.
1271//
1272int
1274{
1275 return static_cast<int>(CONST_CAST(TRichEdit*,this)->SendMessage(EM_EXLINEFROMCHAR,
1276 0, TParam2(charPos)));
1277}
1278
1279
1280//
1281// Enable/Disable Auto URL detection
1282// RichEdit 2.0 specific
1283bool
1285{
1286 if(TRichEditDll::Dll()->GetVersion() >= 2)
1288 return false;
1289}
1290
1291//
1292//
1293// RichEdit 2.0 specific
1294int
1296{
1297 return TRichEditDll::Dll()->GetVersion() >= 2 ?
1298 static_cast<int>(SendMessage(EM_GETIMECOMPMODE)) :
1300}
1301
1302//
1303//
1304// RichEdit 2.0 specific
1305void
1307{
1308 if(TRichEditDll::Dll()->GetVersion() >= 2)
1310}
1311
1312//
1313//
1314// RichEdit 2.0 specific
1315int
1317{
1318 return TRichEditDll::Dll()->GetVersion() >= 2 ?
1319 static_cast<int>(SendMessage(EM_GETLANGOPTIONS)) :
1320 0;
1321}
1322
1323//
1324//
1325// RichEdit 2.0 specific
1326void
1328{
1329 if(TRichEditDll::Dll()->GetVersion() >= 2)
1331
1332 if(mode & TM_PLAINTEXT)
1333 Format = SF_TEXT;
1334 else if(mode & TM_RICHTEXT)
1335 Format = SF_RTF;
1336}
1337
1338//
1339//
1340// RichEdit 2.0 specific
1341int
1343{
1344 return TRichEditDll::Dll()->GetVersion() >= 2 ?
1345 static_cast<int>(SendMessage(EM_GETTEXTMODE)) :
1347}
1348
1349//
1350//
1351// RichEdit 2.0 specific
1352void
1354{
1355 if(TRichEditDll::Dll()->GetVersion() >= 2)
1357}
1358
1359//
1360//
1361// RichEdit 2.0 specific
1362void
1364{
1365 if(TRichEditDll::Dll()->GetVersion() >= 2)
1367}
1368
1369//
1370// Return true if the richedit can paste the specified clipboard format, or
1371// false otherwise.
1372//
1373bool
1378
1379//
1380// RichEdit 2.0 specific
1381//
1382bool
1384{
1385 if(TRichEditDll::Dll()->GetVersion() >= 2)
1387 return CanUndo();
1388}
1389
1390//
1391// RichEdit 2.0 specific
1392// The value returned is an UNDONAMEID enumeration
1393int
1395{
1396 return TRichEditDll::Dll()->GetVersion() >= 2 ?
1397 static_cast<int>(SendMessage(EM_GETUNDONAME)) :
1398 0;
1399}
1400
1401//
1402// RichEdit 2.0 specific
1403// The value returned is an UNDONAMEID enumeration
1404int
1406{
1407 return TRichEditDll::Dll()->GetVersion() >= 2 ?
1408 static_cast<int>(SendMessage(EM_GETREDONAME)) :
1409 0;
1410}
1411
1412//
1413// RichEdit 2.0 specific
1414//
1415void
1417{
1418 if(TRichEditDll::Dll()->GetVersion() >= 2)
1420 else
1421 Undo();
1422}
1423
1424//
1425// Paste the specified clipboard format in the rich edit control.
1426//
1427void
1432
1433//
1434// Paste a compatible clipboard format in the rich edit control.
1435//
1436void
1438{
1440// !BB //
1441// !BB // Iterator through clipboard to locate 'pastable' format
1442// !BB //
1443// !BB TClipboard clip(*this);
1444// !BB for (TClipboardFormatIterator iter(clip); iter; iter++) {
1445// !BB if (CanPaste(iter.Current())) {
1446// !BB PasteSpecial(iter.Current());
1447// !BB return;
1448// !BB }
1449// !BB }
1450
1451}
1452
1453//
1454// Replace the contents of the rich edit control with the specified data
1455// stream. The 'format' parameter can be one of the following data formats,
1456// optionally combined with the SFF_SELECTION flag:
1457//
1458// Value Meaning
1459// ----- -------
1460// SF_TEXT Text
1461// SF_RTF Rich-text format
1462//
1463// If the SFF_SELECTION flag is specified, the stream replaces the contents of
1464// the current selection. Otherwise, the stream replaces the entire contents
1465// of the control.
1466//
1467ulong
1472
1473//
1474// Write the contents of the rich edit control to the specified data stream.
1475// The 'format' parameter can be one of the following values, optionally
1476// combined with the SFF_SELECTION flag:
1477//
1478// Value Meaning
1479// ----- -------
1480// SF_TEXT Text with spaces in place of OLE objects
1481// SF_RTF Rich-text format (RTF)
1482// SF_RTFNOOBJS RTF with spaces in place of OLE object.
1483// SF_TEXTIZED Text with a text representation of OLE objects.
1484//
1485// NOTE: The SF_RTFNOOBJS option is useful if an application stores OLE
1486// objects itself, as RTF representation of OLE objects is not very
1487// compact.
1488// If the SFF_SELECTION flag is specified, only the contents of the
1489// current selection are streamed out. Otherwise, the entire contents of
1490// the control are streamed out.
1491//
1492ulong
1497
1498//
1499// Display a portion of the richedit control's content within the specified
1500// rectangle.
1501// NOTE: The content of the control must first be formatted via a call to the
1502// 'FormatRange' method.
1503//
1504bool
1506{
1507 return SendMessage(EM_DISPLAYBAND, 0, TParam2(&rc)) != 0;
1508}
1509
1510//
1511// Formats a range of text (specified via the 'chrg' member of the
1512// specified TFormatRange) for the device(s) specified via the 'hdcTarget'
1513// and 'hdc' members of the TFormatRange structure.
1514//
1515int
1517{
1518 return static_cast<int>(SendMessage(EM_FORMATRANGE, TParam1(render), TParam2(&fr)));
1519}
1520
1521//
1522// Frees the Formatting information cached by the RichEdit control...
1523//
1524int
1526{
1527 return static_cast<int>(SendMessage(EM_FORMATRANGE, TParam1(TRUE), 0));
1528}
1529
1530//
1531// Set the target device and line width used for WYSIWYG (what you see is
1532// what you get) formatting of the rich edit control.
1533//
1534bool
1540
1541//
1542// Force the rich edit control to send an EN_REQUESTRESIZE notification
1543// message to its parent window.
1544//
1545// NOTE: This message is useful during WM_SIZE processing for the parent of a
1546// bottomless rich edit control.
1547//
1548void
1553
1554//
1555// Retrieve an IRichEditOle object that a client can use to access a rich edit
1556// control's OLE functionality. Returns 'true' if successful, or false
1557// otherwise.
1558//
1559bool
1561{
1562 return CONST_CAST(TRichEdit*,this)->SendMessage(EM_GETOLEINTERFACE,
1563 0, TParam2((void * *)&pInterface)) != 0;
1564}
1565
1566//
1567// Set an IRichEditOleCallback object that the rich edit control uses to get
1568// OLE-related resources and information from the client. Returns 'true' if
1569// successful, or false otherwise.
1570//
1571bool
1573{
1574 // Y.B 06/16/98 MFC uses EM_SETOLECALLBACK not EM_SETOLEINTERFACE ?????
1575 // afxxmn.inl line 620. func CRichEditCtrl::SetOLECallback(...)
1576 // #define EM_SETOLECALLBACK (WM_USER + 70) // not documented !!!!!!
1578}
1579
1580//
1581// Retrieve the event mask for the rich edit control. The event mask specifies
1582// which notification messages the control sends to its parent window.
1583//
1584ulong
1586{
1587 return static_cast<ulong>(SendMessage(EM_GETEVENTMASK));
1588}
1589
1590//
1591// Set the event mask for a rich edit control. The event mask specifies which
1592// notification messages the control sends to its parent window. The 'msk'
1593// parameter can be zero or more of the following values:
1594//
1595// Value Meaning
1596// ----- -------
1597// ENM_CHANGE Sends EN_CHANGE notifications.
1598// ENM_CORRECTTEXT Sends EN_CORRECTTEXT notifications.
1599// ENM_DROPFILES Sends EN_DROPFILES notifications.
1600// ENM_KEYEVENTS Sends EN_MSGFILTER notifications for keyboard events.
1601// ENM_MOUSEEVENTS Sends EN_MSGFILTER notifications for mouse events.
1602// ENM_PROTECTED Sends EN_PROTECTED notifications.
1603// ENM_RESIZEREQUEST Sends EN_REQUESTRESIZE notifications.
1604// ENM_SCROLL Sends EN_HSCROLL notifications.
1605// ENM_SELCHANGE Sends EN_SELCHANGE notifications.
1606// ENM_UPDATE Sends EN_UPDATE notifications
1607//
1608ulong
1610{
1611 return static_cast<ulong>(SendMessage(EM_SETEVENTMASK, 0, TParam2(msk)));
1612}
1613
1614//
1615/// WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
1616//
1617uint
1619{
1620 return TWindow::EvGetDlgCode(msg);
1621}
1622
1623//
1624/// WM_CHAR handler to bypass TEdit's handler (which caters to validators).
1625//
1626void
1627TRichEdit::EvChar(uint /*key*/, uint /*repeatCount*/, uint /*flags*/)
1628{
1630}
1631
1632//
1633/// WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
1634//
1635void
1636TRichEdit::EvKeyDown(uint /*key*/, uint /*repeatCount*/, uint /*flags*/)
1637{
1639}
1640
1641//
1642/// WM_KILLFOCUS handler to bypass TEdit's handler (which caters to validators).
1643//
1644void
1649
1650//
1651/// WM_SETFOCUS handler to bypass TEdit's handler (which caters to validators).
1652//
1653void
1655{
1657}
1658
1659//
1660// This function is called for Cut/Copy/Delete menu items to determine
1661// whether or not the item is enabled.
1662//
1663void
1671
1672//
1673// This function is called for the Paste menu item to determine whether or
1674// not the item is enabled.
1675//
1676void
1678{
1679/*
1680 return (CountClipboardFormats() != 0) &&
1681 (IsClipboardFormatAvailable(CF_TEXT) ||
1682 IsClipboardFormatAvailable(_oleData.cfRichTextFormat) ||
1683 IsClipboardFormatAvailable(_oleData.cfEmbedSource) ||
1684 IsClipboardFormatAvailable(_oleData.cfEmbeddedObject) ||
1685 IsClipboardFormatAvailable(_oleData.cfFileName) ||
1686 IsClipboardFormatAvailable(_oleData.cfFileNameW) ||
1687 IsClipboardFormatAvailable(CF_METAFILEPICT) ||
1688 IsClipboardFormatAvailable(CF_DIB) ||
1689 IsClipboardFormatAvailable(CF_BITMAP) ||
1690 GetRichEditCtrl().CanPaste());
1691*/
1692 TClipboard clip(*this, false);
1693 if (clip &&
1694 (clip.CountClipboardFormats()!=0) &&
1695 ( clip.IsClipboardFormatAvailable(CF_TEXT) ||
1696 clip.IsClipboardFormatAvailable(CF_OEMTEXT) ||
1697 clip.IsClipboardFormatAvailable(CF_UNICODETEXT)
1698// || clip.IsClipboardFormatAvailable(CF_METAFILEPICT) || //?? check
1699// clip.IsClipboardFormatAvailable(CF_ENHMETAFILE) || //??
1700// clip.IsClipboardFormatAvailable(CF_DIB) //???
1701 )
1702 ){
1703 ce.Enable(true);
1704 }
1705 else
1706 ce.Enable(false);
1707}
1708
1709//
1710// This function is called for the Clear menu item to determine whether or
1711// not the item is enabled.
1712//
1713void
1718
1719//
1720// This function is called for the Undo menu item to determine whether or
1721// not the item is enabled.
1722//
1723void
1728
1729//
1730/// Returns name of predefined Windows edit class.
1731//
1733{
1734#if defined(OWL_USERICHEDIT41)
1735 if(TRichEditDll::Dll()->GetVersion() >= 4)
1737#endif
1738
1739 if(TRichEditDll::Dll()->GetVersion() >= 2)
1741 else
1742 return TWindowClassName{_T("RICHEDIT")};
1743}
1744
1745//
1746/// Updates the list of filters describing files which can be opened by
1747/// the rich edit control.
1748//
1749//
1750void
1752{
1754
1755 //Load RichEdit's filter
1756 //
1758}
1759
1760
1761uint32
1763{
1765 POINTL pt;
1766 pt.x = x;
1767 pt.y = y;
1768
1769 return static_cast<uint32>(SendMessage(EM_CHARFROMPOS, 0, TParam2(&pt)));
1770}
1771
1772//
1773uint32
1775{
1777
1778 if (TRichEditDll::Dll()->GetVersion() == 2)
1779 return static_cast<uint32>(SendMessage(EM_POSFROMCHAR, charIndex));
1780 else
1781 {
1782 POINTL pt;
1783 SendMessage(EM_POSFROMCHAR, reinterpret_cast<TParam1>(&pt), charIndex);
1784 return MkUint32(static_cast<uint16>(pt.y), static_cast<uint16>(pt.x));
1785 }
1786}
1787
1788
1789//
1790// Callback used when reading data from a stream into a rich edit control.
1791//
1794{
1796
1797 tistream& is = *reinterpret_cast<tistream*>(dwCookie);
1798
1799 // Return 0 if transfer is complete.
1800 //
1801 if (is.eof())
1802 {
1803 *pcb = 0;
1804 return 0;
1805 }
1806
1807 // Read data in buffer.
1808 // Note: We know that the gcount cannot exceed cb, so we can cast unchecked.
1809 //
1810#if defined(UNICODE)
1811 tstring tempBuff(cb, _T('\0'));
1812 is.read(&tempBuff[0], cb);
1813 LONG n = static_cast<LONG>(is.gcount());
1814 ::WideCharToMultiByte(CP_ACP, 0, &tempBuff[0], n, reinterpret_cast<char*>(pbBuff), cb, NULL, NULL);
1815#else
1816 is.read(reinterpret_cast<char*>(pbBuff), cb);
1817 LONG n = static_cast<LONG>(is.gcount());
1818#endif
1819
1820 // Indicate amount of data read.
1821 //
1822 *pcb = n;
1823 return 0;
1824}
1825
1826//
1827// Callback used when writing out the contents of a rich edit control to
1828// a data stream.
1829//
1832{
1834
1835 tostream& os = *reinterpret_cast<tostream*>(dwCookie);
1836
1837 // Save current stream location and write data to buffer
1838 //
1839 streampos pCnt = os.tellp();
1840
1841#if defined(UNICODE)
1842 tchar * tempBuff = new tchar[cb];
1844 os.write(tempBuff, cb);
1845 delete[] tempBuff;
1846#else
1847 os.write((char*)pbBuff, cb);
1848#endif
1849
1850 // Indicate the number of bytes written to the file
1851 //
1852 *pcb = static_cast<LONG>(os.tellp() - pCnt);
1853 return 0;
1854}
1855
1856//
1857// Overriden to bypass TEdit's 'Transfer' method.
1858// NOTE: There's no transfer-support for rich edit controls.
1859//
1860uint
1861TRichEdit::Transfer(void* /*buffer*/, TTransferDirection /*direction*/)
1862{
1863 // NOTE: No transfer support for rich edit control
1864 //
1865 return 0;
1866}
1867
1868//
1869// Read the data from the specified stream into the rich edit control. The
1870// 'fmt' parameter can be one of the following data formats, optionally
1871// combined with the SFF_SELECTION flag:
1872//
1873// Value Meaning
1874// ----- -------
1875// SF_TEXT Text
1876// SF_RTF Rich-text format
1877//
1878// If the SFF_SELECTION flag is specified, the stream replaces the contents of
1879// the current selection. Otherwise, the stream replaces the entire contents
1880// of the control.
1881//
1882bool
1884{
1885 DWORD_PTR cookie = reinterpret_cast<DWORD_PTR>(&is);
1888 return edStrm.dwError == 0;
1889}
1890
1891//
1892// Write the contents of the rich edit control to the specified data stream.
1893// The 'fmt' parameter can be one of the following values, optionally
1894// combined with the SFF_SELECTION flag:
1895//
1896// Value Meaning
1897// ----- -------
1898// SF_TEXT Text with spaces in place of OLE objects
1899// SF_RTF Rich-text format (RTF)
1900// SF_RTFNOOBJS RTF with spaces in place of OLE object.
1901// SF_TEXTIZED Text with a text representation of OLE objects.
1902//
1903// NOTE: The SF_RTFNOOBJS option is useful if an application stores OLE
1904// objects itself, as RTF representation of OLE objects is not very
1905// compact.
1906// If the SFF_SELECTION flag is specified, only the contents of the
1907// current selection are streamed out. Otherwise, the entire contents of
1908// the control are streamed out.
1909//
1910bool
1912{
1913 DWORD_PTR cookie = reinterpret_cast<DWORD_PTR>(&os);
1916 return edStrm.dwError == 0;
1917}
1918
1919//
1920// Read the contents of the specified file in the rich edit control. Returns
1921// 'true' if successful, or false otherwise.
1922//
1923bool
1925{
1926 if (!fileName)
1927 {
1928 if (GetFileName())
1930 else
1931 return false;
1932 }
1933
1935 tifstream ifs(_W2A(fileName), ios::in|ios::binary);
1936 if (ifs) {
1937 // Could check for a valid file (eg. FileSize != 0)
1938 // before proceeding with a call to Clear() here.
1939 //
1940 Clear();
1941
1942 // Stream in data from file
1943 //
1944 if (ReadFromStream(ifs, Format)) {
1945 ClearModify();
1946 return true;
1947 }
1948 }
1949 return false;
1950}
1951
1952//
1953// Write the contents of the edit control to the specified file. Returns
1954// 'true' if successful, or false otherwise.
1955//
1956bool
1958{
1959 if (!fileName)
1960 {
1961 if (GetFileName())
1963 else
1964 return false;
1965 }
1966
1968 tofstream ofs(_W2A(fileName), ios::out|ios::binary);
1969 if (ofs) {
1970 if (WriteToStream(ofs, Format)) {
1971 ClearModify();
1972 return true;
1973 }
1974 }
1975 return false;
1976}
1977
1978
1980
1981#if OWL_PERSISTENT_STREAMS
1982//
1983//
1984void*
1985TRichEdit::Streamer::Read(ipstream& is, uint32 /*version*/) const
1986{
1987 ReadBaseObject((TEditFile*)GetObject(), is);
1988 return GetObject();
1989}
1990
1991//
1992//
1993//
1994void
1995TRichEdit::Streamer::Write(opstream& os) const
1996{
1997 WriteBaseObject((TEditFile*)GetObject(), os);
1998}
1999
2000#endif
2001//
2002// Object wrapper which loads the RichEdit DLL
2003//
2005:
2006 TModule(
2008 GetVersion() >= 4 ? RichEdit41DllName :
2009#endif
2010 (GetVersion() >= 2 ? RichEdit20DllName : RichEditDllName),
2011 true, true,false
2012 )
2013{
2014}
2015
2016//
2017// check new rich edit library
2018//
2019static int CheckREVersion()
2020{
2022
2023#if defined(OWL_USERICHEDIT41)
2026 {
2028 return 4;
2029 }
2030#endif
2031
2033 if (Handle <= HINSTANCE(HINSTANCE_ERROR))
2034 return 1;
2035 ::FreeLibrary(Handle);
2036 return 2;
2037}
2038
2039//
2040//
2041//
2043{
2044 static int REVersion = force_old ? 1 : CheckREVersion();
2045 return REVersion;
2046}
2047
2048#if defined(_BUILDOWLDLL)
2049// The template instances only need to be generated when building the
2050// ObjectWindows DLL - These instances are exported by OWL and imported
2051// by user code.
2052
2053 //
2054 // Export template of TDllLoader<TRichEditModule> when building ObjectWindows
2055 // DLL and provide import declaration of DLL instance for users of the class.
2056 //
2058#endif
2059
2060} // OWL namespace
2061/* ========================================================================== */
2062
#define CHECK(condition)
Definition checks.h:239
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
TCharFormat encapsulates the CHARFORMAT2 structure which contains information about character formatt...
Definition richedit.h:56
void GetFontInfo(const LOGFONT &lf)
Initializes the underlying CHARFORMAT structure using the information stored in a LOGFONT structure.
Definition richedit.cpp:259
TColor GetBkColor() const
Retrieves the character background color stored in the CHARFORMAT structure.
Definition richedit.cpp:305
void EnableBold(bool=true)
Toggles the bold character attribute according to the boolean parameter specified.
Definition richedit.cpp:71
void SetPitchAndFamily(uint8)
Sets the pitch and family of the font.
Definition richedit.cpp:195
void SetTextColor(const TColor &=TColor::None)
Updates the CHARFORMAT structure with the specified color.
Definition richedit.cpp:151
void EnableStrikeOut(bool=true)
Toggles the strike-out character attribute based on the boolean parameter specified.
Definition richedit.cpp:110
void SetFontInfo(LOGFONT &lf) const
Transfers the information currently in the underlying CHARFORMAT structure to a LOGFONT structure.
Definition richedit.cpp:228
TColor GetTextColor() const
Retrieves the character color stored in the CHARFORMAT structure.
Definition richedit.cpp:138
void ToggleEffectsBit(ulong flag)
Toggles the effect bits specified in the 'flag' parameter.
Definition richedit.h:587
void EnableItalic(bool=true)
Toggles italic character attribute based on the boolean parameter specified.
Definition richedit.cpp:84
void SetWeight(uint16 weigh)
Font weight (LOGFONT value)
Definition richedit.cpp:284
void SetRevAuthor(uint8 revav)
Revision author index.
Definition richedit.cpp:381
TCharFormat(ulong mask=0)
Constructor of a 'TCharFormat' structure initialized with the specified mask.
Definition richedit.h:578
void SetBkColor(const TColor &clr)
Background color.
Definition richedit.cpp:316
void SetAnimation(uint8 anim)
Animated text like marching ants.
Definition richedit.cpp:371
void SetStyle(int16 style)
Style handle.
Definition richedit.cpp:341
void SetUnderlineType(uint8 utype)
Underline type.
Definition richedit.cpp:361
void EnableUnderline(bool=true)
Toggles the underline character attribute based on the boolean parameter specified.
Definition richedit.cpp:97
void SetKerning(uint16 kern)
Twip size above which to kern char pair.
Definition richedit.cpp:351
void SetSpacing(int16 spacing)
Amount to space between letters.
Definition richedit.cpp:294
void SetOffset(long)
Sets the character offset from the baseline.
Definition richedit.cpp:215
void SetFaceName(LPCTSTR)
Sets the face name of the font.
Definition richedit.cpp:168
void SetCharSet(uint8)
Sets the character set of the font.
Definition richedit.cpp:180
void SetLCID(LCID lcid)
Locale ID.
Definition richedit.cpp:331
void SetHeight(long)
Sets the character height.
Definition richedit.cpp:204
void EnableProtected(bool=true)
Toggles the protected character attribute based on the boolean parameter specified.
Definition richedit.cpp:123
TCharRange encapsulates the CHARRANGE structure, which specifies a range of characters in a rich edit...
Definition richedit.h:105
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition clipboar.h:32
Class wrapper for management of color values.
Definition color.h:245
static const TColor None
not-a-color
Definition color.h:318
static const TColor SysWindowText
The symbolic system color value for text in every window.
Definition color.h:332
static const TColor SysWindow
The symbolic system color value for the background of each window.
Definition color.h:329
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
TEditFile is a file-editing window.
Definition editfile.h:35
LPCTSTR GetFileName() const
Return the filename for this buffer.
Definition editfile.h:147
TOpenSaveDialog::TData & GetFileData()
Return the FileData data member used for the common dialogs.
Definition editfile.h:154
void SetupWindow() override
Creates the edit window's Editor edit control by calling TEditFile::SetupWindow().
Definition editfile.cpp:79
TEditStream encapsulates the EDITSTREAM structure, which contains information about a data stream use...
Definition richedit.h:181
Simple encapsulation of the SetErrorMode call.
Definition module.h:352
TFindText encapsulates the FINDTEXT structure, which contains information about text to search for in...
Definition richedit.h:206
TFormatRange encapsulates the FORMATRANGE structure, which contains information that a rich edit cont...
Definition richedit.h:156
void SetRange(const TCharRange &)
Sets the range of text to format.
Definition richedit.cpp:446
void SetRenderDC(HDC)
Sets the device context of the device to render to.
Definition richedit.cpp:408
void SetPageRect(const TRect &)
Sets the entire area of the rendering device.
Definition richedit.cpp:437
void SetTargetDC(HDC)
Sets the device context of the target device to format for.
Definition richedit.cpp:417
void SetRenderRect(const TRect &)
Sets the area to render to.
Definition richedit.cpp:427
TFormatRange()
Constructs a default 'TFormatRange' object with all members initialized to zero.
Definition richedit.h:658
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
void SetFilter(LPCTSTR filter=nullptr)
Makes a copy of the filter list used to display the file names.
Definition opensave.cpp:141
TParaFormat encapsulates the PARAFORMAT structure, which contains information about paragraph formatt...
Definition richedit.h:119
void SetLineSpacing(long space, uint8 rule)
Line spacing depending on Rule.
Definition richedit.cpp:607
void SetNumStyle(uint16 style)
Alignment, roman/arabic, (), ), ., etc.
Definition richedit.cpp:650
void SetSpaceAfter(long space)
Vertical spacing after para.
Definition richedit.cpp:597
void ToggleMaskBit(ulong flag)
Toggles the specified flag in the member which describes which information of the PARAFORMAT structur...
Definition richedit.cpp:499
void SetRightIndent(long)
Sets the size of the right identation, relative to the right margin.
Definition richedit.cpp:538
TParaFormat(ulong mask=0)
Constructs a default TParaFormat structure.
Definition richedit.cpp:465
void SetStartIndent(long, bool relative=false)
Sets the indentation of the first line in the paragraph.
Definition richedit.cpp:523
void SetSpaceBefore(long space)
Vertical spacing before para.
Definition richedit.cpp:587
void SetOffset(long)
Sets the indentation of the second line and subsequent lines, relative to the starting indentation.
Definition richedit.cpp:550
void SetBorder(uint16 spac, uint16 width, uint16 border)
Definition richedit.cpp:670
void SetShading(uint16 wight, uint16 style)
Shading in hundredths of a per cent Nibble 0: style, 1: cfpat, 2: cbpat.
Definition richedit.cpp:629
void SetTabCount(short, long *)
Sets the number and absolute positions of the tab stops.
Definition richedit.cpp:573
void SetNumbering(uint16)
Sets the numbering options. The only valid parameter is '0' or PFN_BULLET.
Definition richedit.cpp:508
void SetAlignment(uint16)
Sets the alignment option.
Definition richedit.cpp:563
void SetNumStart(uint16 start)
Starting value for numbering.
Definition richedit.cpp:640
void SetStyle(int16 style)
Style handle.
Definition richedit.cpp:618
void SetNumTab(uint16 tab)
Space bet 1st indent and 1st-line text.
Definition richedit.cpp:660
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TRichEdit encapsulates a rich edit control, a window in which a user can enter, edit and format text.
Definition richedit.h:261
bool ToggleCharAttribute(ulong mask, uint32 effects)
Toggles a set of character attributes.
Definition richedit.cpp:875
bool DisplayBand(TRect &)
bool ReadFromStream(tistream &, uint format=SF_RTF)
< String-aware overload
ulong StreamOut(uint format, TEditStream &)
bool SetCharFormat(const TCharFormat &, uint flags=SCF_SELECTION)
Sets the character formatting of a rich edit control.
Definition richedit.cpp:821
void RequestResize()
bool WriteToStream(tostream &, uint format=SF_RTF)
int GetTextRange(TTextRange &) const
Retrieves a specified range of text from the rich edit control.
auto GetLineFromPos(int charPos) const -> int override
void Paste() override
void CeEditClear(TCommandEnabler &commandHandler)
ulong GetSelectionType() const
Returns the selection type of the rich edit control.
Definition richedit.cpp:978
void CeHasSelect(TCommandEnabler &commandHandler)
void EvKillFocus(HWND hWndGetFocus)
WM_KILLFOCUS handler to bypass TEdit's handler (which caters to validators).
int GetLangOptions() const
auto SetSelection(int startPos, int endPos) -> bool override
Selects a range of characters in the rich edit control.
Definition richedit.cpp:939
int GetRedoName() const
void GetSelRange(TCharRange &) const
Retrieves the starting and ending character positions of the selection of the richedit control.
Definition richedit.cpp:929
int GetUndoName() const
void CeEditPaste(TCommandEnabler &commandHandler)
auto Read(LPCTSTR fileName=nullptr) -> bool override
void CeEditUndo(TCommandEnabler &commandHandler)
@ Partly
Part of the selection has the attribute.
Definition richedit.h:296
@ Yes
The attribute is absent from the selection.
Definition richedit.h:295
@ No
The whole selection has the attribute.
Definition richedit.h:294
void LimitText(int maxValue) override
Sets an upper limit to the amount of text in the richedit control.
bool SetParaFormat(const TParaFormat &)
Sets the paragraph formatting of the current selection of the rich edit control.
Definition richedit.cpp:830
void StopGroupTyping()
tstring GetSelectedText() const
String-aware overload.
auto Write(LPCTSTR fileName=nullptr) -> bool override
< String-aware overload
bool IsRTF() const
Definition richedit.h:715
auto PosFromChar(uint charIndex) -> uint32 override
int SetSelRange(const TCharRange &)
Selects a range of characters in the rich edit control.
Definition richedit.cpp:949
ulong GetParaFormat(TParaFormat &) const
Retrieves the paragraph formatting of the current selection of the rich edit control.
Definition richedit.cpp:804
ulong GetEventMask() const
void SetTextMode(int mode)
int GetTextLength() const
Definition richedit.cpp:989
bool SetTargetDevice(HDC, int lineWidth)
void PasteSpecial(uint format)
bool EnableAutoURL(bool enable=true)
bool ChangeCharPointSize(int pointSizeDelta)
Increases or decreases (using a positive or negative value respectively) the point size of the curren...
Definition richedit.cpp:888
auto Transfer(void *buffer, TTransferDirection) -> uint override
void HideSelection(bool hide, bool changeStyle)
Shows or hides the selection in the rich edit control.
Definition richedit.cpp:964
int GetTextMode() const
void GetSubText(TCHAR *textBuf, int startPos, int endPos) const override
Retrieves a specified range of text from the rich edit control.
TColor SetBkgndColor(const TColor &=TColor::None)
Sets the background color of the rich edit control.
Definition richedit.cpp:841
void EvSetFocus(HWND hWndLostFocus)
WM_SETFOCUS handler to bypass TEdit's handler (which caters to validators).
auto GetWindowClassName() -> TWindowClassName override
Returns name of predefined Windows edit class.
int FindWordBreak(uint code, int start)
uint HasCharAttribute(ulong mask, uint32 effects)
Function returns whether or not the current selection has a particular attribute.
Definition richedit.cpp:857
bool SetOleInterface(IRichEditOleCallback *)
bool HasSelection() const
Returns true if the rich edit control has an active selection.
Definition richedit.cpp:905
void SetUndoLimit(int maxnum)
void EvKeyDown(uint key, uint repeatCount, uint flags)
WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
TRichEdit(TWindow *parent, int id, LPCTSTR text, int x, int y, int w, int h, LPCTSTR fileName=nullptr, TModule *module=nullptr)
Constructor for a TRichEdit object.
Definition richedit.cpp:707
int FindText(uint flags, const TFindText &)
Finds text within the rich edit control.
void SetupWindow() override
Updates the list of filters describing files which can be opened by the rich edit control.
void EvChar(uint key, uint repeatCount, uint flags)
WM_CHAR handler to bypass TEdit's handler (which caters to validators).
bool CanRedo() const
auto CharFromPos(int16 x, int16 y) -> uint32 override
uint EvGetDlgCode(const MSG *)
WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
void SetFormat(uint fmt)
Definition richedit.h:707
auto Search(int startPos, LPCTSTR text, bool caseSensitive=false, bool wholeWord=false, bool up=false) -> int override
ulong StreamIn(uint format, TEditStream &)
int GetIMEMode() const
ulong SetEventMask(ulong msk)
ulong GetCharFormat(TCharFormat &, bool selection=false) const
Retrieves the current character formatting in an edit control.
Definition richedit.cpp:790
bool CanPaste(uint format) const
void SetLangOptions(int options)
bool GetOleInterface(IRichEditOle *&) const
static int GetVersion(bool force_old=false)
TTextRange encapsulates the TEXTRANGE structure, which contains information about a range of text in ...
Definition richedit.h:193
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
tstring LoadString(uint id) const
Definition window.h:608
uint EvGetDlgCode(const MSG *msg)
The default message handler for WM_GETDLGCODE.
Definition window.h:3698
void EvKillFocus(HWND hWndGetFocus)
Handle WM_KILLFOCUS so that we can have a parent window hold onto our Handle and possibly restore foc...
Definition window.cpp:1611
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition window.cpp:3591
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
int GetWindowTextLength() const
Returns the length, in characters, of the specified window's title.
Definition window.h:2641
static void Raise()
Constructs a TXCommCtrl exception from scratch, and throws it.
Definition commctrl.cpp:74
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _tcslen
Definition cygwin.h:74
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
int GetSize() const
Definition edit.h:52
void ClearModify()
Resets the change flag of the edit control causing IsModified to return false.
Definition edit.h:276
bool CanUndo() const
Returns true if it is possible to undo the last edit.
Definition edit.h:690
int GetLineLength(int lineNumber) const
Return the length of line number "lineNumber".
Definition edit.cpp:494
void Undo()
Undoes the last edit.
Definition edit.h:305
int GetNumLines() const
Return the number of lines in the associated edit control.
Definition edit.h:409
void Clear() override
Override TStatic virtual member functions.
Definition edit.cpp:421
TRange GetSelection() const
Functional style overload.
Definition edit.cpp:979
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
#define _W2A(lpw)
Definition memory.h:219
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
std::ofstream tofstream
Definition strmdefs.h:44
const int MinPointSize
Definition richedit.cpp:24
unsigned long ulong
Definition number.h:26
const tchar RichEdit20DllName[]
Definition richedit.cpp:30
EV_WM_CHAR
Definition checklst.cpp:196
EV_WM_KILLFOCUS
Definition edit.cpp:85
uint32 MkUint32(uint16 lo, uint16 hi)
Definition defs.h:261
EV_WM_KEYDOWN
Definition edit.cpp:82
unsigned char uint8
Definition number.h:32
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
Definition defs.h:317
bool ToBool(const T &t)
Definition defs.h:291
DWORD CALLBACK RichEditStrmOutWithOstream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
std::ifstream tifstream
Definition strmdefs.h:43
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
const int MaxPointSize
Definition richedit.cpp:25
OWL_DIAGINFO
Definition animctrl.cpp:14
EV_WM_SETFOCUS
Definition edit.cpp:84
END_RESPONSE_TABLE
Definition button.cpp:26
std::istream tistream
Definition strmdefs.h:39
const tchar RichEditDllName[]
Definition richedit.cpp:29
std::string tstring
Definition defs.h:79
EV_WM_GETDLGCODE
Definition button.cpp:24
unsigned int uint
Definition number.h:25
std::ostream tostream
Definition strmdefs.h:40
DWORD CALLBACK RichEditStrmInWithIStream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
#define CONST_CAST(targetType, object)
Definition defs.h:273
#define _OWLCLASS
Definition defs.h:338
Definition of class TRichEdit.
Represents a half-open range of positions in the edit control, e.g.
Definition edit.h:49
#define EV_COMMAND_ENABLE(id, method)
Response table entry for enabling a command.
Definition windowev.h:193
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition windowev.h:171