OWLNext  7.0
Borland's Object Windows Library for the modern age
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 
16 using namespace std;
17 
18 namespace owl {
19 
21 
22 // Range of the editor's font size
23 //
24 const int MinPointSize = 6;
25 const int MaxPointSize = 128;
26 
27 // System DLL providing underlying support for RichEdit controls
28 //
29 const tchar RichEditDllName[] = _T("RICHED32.DLL");
30 const 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)
40 const 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 //
53 TCharFormat::TCharFormat(const TRichEdit& edit, bool selection, ulong mask)
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 //
70 void
71 TCharFormat::EnableBold(bool flag)
72 {
73  dwMask |= CFM_BOLD;
74  if (flag)
75  dwEffects |= CFE_BOLD;
76  else
77  dwEffects &= ~CFE_BOLD;
78 }
79 
80 //
81 /// Toggles italic character attribute based on the boolean parameter specified.
82 //
83 void
84 TCharFormat::EnableItalic(bool flag)
85 {
86  dwMask |= CFM_ITALIC;
87  if (flag)
88  dwEffects |= CFE_ITALIC;
89  else
90  dwEffects &= ~CFE_ITALIC;
91 }
92 
93 //
94 /// Toggles the underline character attribute based on the boolean parameter specified.
95 //
96 void
97 TCharFormat::EnableUnderline(bool flag)
98 {
99  dwMask |= CFM_UNDERLINE;
100  if (flag)
101  dwEffects |= CFE_UNDERLINE;
102  else
103  dwEffects &= ~CFE_UNDERLINE;
104 }
105 
106 //
107 /// Toggles the strike-out character attribute based on the boolean parameter specified.
108 //
109 void
110 TCharFormat::EnableStrikeOut(bool flag)
111 {
112  dwMask |= CFM_STRIKEOUT;
113  if (flag)
114  dwEffects |= CFE_STRIKEOUT;
115  else
116  dwEffects &= ~CFE_STRIKEOUT;
117 }
118 
119 //
120 /// Toggles the protected character attribute based on the boolean parameter specified.
121 //
122 void
123 TCharFormat::EnableProtected(bool flag)
124 {
125  dwMask |= CFM_PROTECTED;
126  if (flag)
127  dwEffects |= CFE_PROTECTED;
128  else
129  dwEffects &= ~CFE_PROTECTED;
130 }
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 //
137 TColor
138 TCharFormat::GetTextColor() const
139 {
140  if ((dwMask & CFM_COLOR) && !(dwEffects & CFE_AUTOCOLOR))
141  return TColor(crTextColor);
142  return TColor::SysWindowText;
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 //
150 void
151 TCharFormat::SetTextColor(const TColor& color)
152 {
153  dwMask |= CFM_COLOR;
154  if (color == TColor::None)
155  dwEffects |= CFE_AUTOCOLOR;
156  else {
157  dwEffects &= ~CFE_AUTOCOLOR;
158  crTextColor = color;
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 //
167 void
168 TCharFormat::SetFaceName(LPCTSTR name)
169 {
170  PRECONDITION(name);
171  szFaceName[0] = _T('\0');
172  ::_tcsncat(szFaceName, name, LF_FACESIZE - 1);
173 }
174 
175 //
176 /// Sets the character set of the font. Valid values include the following:
177 /// ANSI_CHARSET, OEM_CHARSET, and SYMBOL_CHARSET.
178 //
179 void
180 TCharFormat::SetCharSet(uint8 charSet)
181 {
182  bCharSet = charSet;
183 }
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 //
194 void
195 TCharFormat::SetPitchAndFamily(uint8 pitchFam)
196 {
197  bPitchAndFamily = pitchFam;
198 }
199 
200 //
201 /// Sets the character height.
202 //
203 void
204 TCharFormat::SetHeight(long height)
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 //
214 void
215 TCharFormat::SetOffset(long offset)
216 {
217  dwMask |= CFM_OFFSET;
218  yOffset = offset;
219 }
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 //
227 void
228 TCharFormat::SetFontInfo(LOGFONT& lf) const
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 = (uint8)(dwEffects & CFE_ITALIC ? TRUE : FALSE);
240 
241  if (dwMask & CFM_UNDERLINE)
242  lf.lfUnderline = (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 //
258 void
259 TCharFormat::GetFontInfo(const LOGFONT& lf)
260 {
261  dwMask = (CFM_SIZE | CFM_BOLD | CFM_ITALIC | CFM_OFFSET|
262  CFM_STRIKEOUT | CFM_UNDERLINE | CFM_FACE);
263 
264  yHeight = lf.lfHeight * -20;
265 
266  if (FW_BOLD == lf.lfWeight)
267  dwEffects |= CFE_BOLD;
268  if (lf.lfItalic)
269  dwEffects |= CFE_ITALIC;
270  if (lf.lfStrikeOut)
271  dwEffects |= CFE_STRIKEOUT;
272  if (lf.lfUnderline)
273  dwEffects |= CFE_UNDERLINE;
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
283 void
284 TCharFormat::SetWeight(uint16 weigh)
285 {
286  dwMask |= CFM_WEIGHT;
287  wWeight = weigh;
288 }
289 
290 //
291 /// Sets Amount to space between letters.
292 /// \note RichEdit 2.0 specific
293 void
294 TCharFormat::SetSpacing(int16 spacing)
295 {
296  dwMask |= CFM_SPACING;
297  sSpacing = spacing;
298 }
299 
300 //
301 /// Retrieves the character background color stored in the CHARFORMAT structure.
302 /// \note RichEdit 2.0 specific
303 //
304 TColor
305 TCharFormat::GetBkColor() const
306 {
307  if ((dwMask & CFM_BACKCOLOR)&& !(dwEffects & CFE_AUTOBACKCOLOR))
308  return TColor(crBackColor);
309  return TColor::SysWindow;
310 }
311 
312 //
313 /// Sets Background color.
314 /// \note RichEdit 2.0 specific
315 void
316 TCharFormat::SetBkColor(const TColor& clr)
317 {
318  dwMask |= CFM_BACKCOLOR;
319  if (clr == TColor::None)
320  dwEffects |= CFE_AUTOBACKCOLOR;
321  else {
322  dwEffects &= ~CFE_AUTOBACKCOLOR;
323  crBackColor = clr;
324  }
325 }
326 
327 //
328 // Locale ID
329 // RichEdit 2.0 specific
330 void
331 TCharFormat::SetLCID(LCID _lcid)
332 {
333  dwMask |= CFM_LCID;
334  lcid = _lcid;
335 }
336 
337 //
338 /// Sets Style handle.
339 /// \note RichEdit 2.0 specific
340 void
341 TCharFormat::SetStyle(int16 style)
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
350 void
351 TCharFormat::SetKerning(uint16 kern)
352 {
353  dwMask |= CFM_STYLE;
354  wKerning = kern;
355 }
356 
357 //
358 /// Set underline type.
359 /// \note RichEdit 2.0 specific
360 void
361 TCharFormat::SetUnderlineType(uint8 utype)
362 {
363  dwMask |= CFM_UNDERLINETYPE;
364  bUnderlineType = utype;
365 }
366 
367 //
368 /// Animated text like marching ants.
369 /// \note RichEdit 2.0 specific
370 void
371 TCharFormat::SetAnimation(uint8 anim)
372 {
373  dwMask |= CFM_ANIMATION;
374  bAnimation = anim;
375 }
376 
377 //
378 /// Sets Revision author index.
379 /// \note RichEdit 2.0 specific
380 void
381 TCharFormat::SetRevAuthor(uint8 revav)
382 {
383  dwMask |= CFM_REVAUTHOR;
384  bRevAuthor = revav;
385 }
386 
387 ////////////////////////////////////////////////////////////////////////////////
388 //
389 //
390 
391 //
392 /// Constructs a TFormatRange object initializing data members with the specified parameters.
393 //
394 TFormatRange::TFormatRange(HDC renderDC, HDC devDC, const TRect& renderArea,
395  const TRect& entireArea, const TCharRange& range)
396 {
397  SetRenderDC(renderDC);
398  SetTargetDC(devDC);
399  SetRenderRect(renderArea);
400  SetPageRect(entireArea);
401  SetRange(range);
402 }
403 
404 //
405 /// Sets the device context of the device to render to.
406 //
407 void
408 TFormatRange::SetRenderDC(HDC renderDC)
409 {
410  hdc = renderDC;
411 }
412 
413 //
414 /// Sets the device context of the target device to format for.
415 //
416 void
417 TFormatRange::SetTargetDC(HDC targetDC)
418 {
419  hdcTarget = targetDC;
420 }
421 
422 //
423 /// Sets the area to render to.
424 /// \note The specified units are in TWIPS.
425 //
426 void
427 TFormatRange::SetRenderRect(const TRect& renderRect)
428 {
429  rc = renderRect;
430 }
431 
432 //
433 /// Sets the entire area of the rendering device.
434 /// \note The specified units are in TWIPS.
435 //
436 void
437 TFormatRange::SetPageRect(const TRect& pgRect)
438 {
439  rcPage = pgRect;
440 }
441 
442 //
443 /// Sets the range of text to format.
444 //
445 void
446 TFormatRange::SetRange(const TCharRange& charRange)
447 {
448  chrg = charRange;
449 }
450 
451 //
452 /// Sets the range of text to format, specifying the starting and ending character offsets.
453 //
454 void
455 TFormatRange::SetRange(long start, long end)
456 {
457  chrg.cpMin = start;
458  chrg.cpMax = end;
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 //
463 /// Constructs a default TParaFormat structure.
464 //
465 TParaFormat::TParaFormat(ulong mask)
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 //
480 TParaFormat::TParaFormat(const TRichEdit& edit, ulong mask)
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 //
498 void
499 TParaFormat::ToggleMaskBit(ulong flag)
500 {
501  dwMask ^= flag;
502 }
503 
504 //
505 /// Sets the numbering options. The only valid parameter is '0' or PFN_BULLET.
506 //
507 void
508 TParaFormat::SetNumbering(uint16 opt)
509 {
510  PRECONDITION(opt == 0 || opt == PFN_BULLET);
511 
512  dwMask |= PFM_NUMBERING;
513  wNumbering = opt;
514 }
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 //
522 void
523 TParaFormat::SetStartIndent(long start, bool relative)
524 {
525  dwMask |= PFM_STARTINDENT;
526  if (relative)
527  dwMask |= PFM_OFFSETINDENT;
528  else
529  dwMask &= ~PFM_OFFSETINDENT;
530 
531  dxStartIndent = start;
532 }
533 
534 //
535 /// Sets the size of the right identation, relative to the right margin.
536 //
537 void
538 TParaFormat::SetRightIndent(long indent)
539 {
540  dwMask |= PFM_RIGHTINDENT;
541  dxRightIndent = indent;
542 }
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 //
549 void
550 TParaFormat::SetOffset(long offset)
551 {
552  dwMask |= PFM_OFFSET;
553  dxOffset = offset;
554 }
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 //
562 void
563 TParaFormat::SetAlignment(uint16 opt)
564 {
565  dwMask |= PFM_ALIGNMENT;
566  wAlignment = opt;
567 }
568 
569 //
570 /// Sets the number and absolute positions of the tab stops.
571 //
572 void
573 TParaFormat::SetTabCount(short cnt, long* tabs)
574 {
575  PRECONDITION(tabs || !cnt);
576 
577  dwMask |= PFM_TABSTOPS;
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
586 void
587 TParaFormat::SetSpaceBefore(long space)
588 {
589  dwMask |= PFM_SPACEBEFORE;
590  dySpaceBefore = space;
591 }
592 
593 //
594 // Vertical spacing after para
595 // RichEdit 2.0 specific
596 void
597 TParaFormat::SetSpaceAfter(long space)
598 {
599  dwMask |= PFM_SPACEAFTER;
600  dySpaceAfter = space;
601 }
602 
603 //
604 // Line spacing depending on Rule
605 // RichEdit 2.0 specific
606 void
607 TParaFormat::SetLineSpacing(long space, uint8 rule)
608 {
609  dwMask |= PFM_LINESPACING;
610  dyLineSpacing = space;
611  bLineSpacingRule = rule;
612 }
613 
614 //
615 // Style handle
616 // RichEdit 2.0 specific
617 void
618 TParaFormat::SetStyle(int16 style)
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
628 void
629 TParaFormat::SetShading(uint16 wight,uint16 style)
630 {
631  dwMask |= PFM_SHADING;
632  wShadingWeight = wight;
633  wShadingStyle = style;
634 }
635 
636 //
637 // Starting value for numbering
638 // RichEdit 2.0 specific
639 void
640 TParaFormat::SetNumStart(uint16 start)
641 {
642  dwMask |= PFM_NUMBERINGSTART;
643  wNumberingStart = start;
644 }
645 
646 //
647 // Alignment, roman/arabic, (), ), ., etc.
648 // RichEdit 2.0 specific
649 void
650 TParaFormat::SetNumStyle(uint16 style)
651 {
652  dwMask |= PFM_NUMBERINGSTYLE;
653  wNumberingStyle = style;
654 }
655 
656 //
657 // Space bet 1st indent and 1st-line text
658 // RichEdit 2.0 specific
659 void
660 TParaFormat::SetNumTab(uint16 tab)
661 {
662  dwMask |= PFM_NUMBERINGTAB;
663  wNumberingTab = tab;
664 }
665 
666 //
667 // Space between border and text (twips)
668 // RichEdit 2.0 specific
669 void
670 TParaFormat::SetBorder(uint16 space, uint16 width, uint16 border)
671 {
672  dwMask |= PFM_BORDER;
673  wBorderSpace = space;
674  wBorderWidth = width;
675  wBorders = border;
676 }
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),
689  EV_COMMAND_ENABLE(CM_EDITCUT, CeHasSelect),
690  EV_COMMAND_ENABLE(CM_EDITCOPY, CeHasSelect),
691  EV_COMMAND_ENABLE(CM_EDITDELETE, CeHasSelect),
692  EV_COMMAND_ENABLE(CM_EDITPASTE, CeEditPaste),
693  EV_COMMAND_ENABLE(CM_EDITCLEAR, CeEditClear),
694  EV_COMMAND_ENABLE(CM_EDITUNDO, CeEditUndo),
695  EV_WM_CHAR,
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 //
707 TRichEdit::TRichEdit(TWindow* parent,
708  int id,
709  LPCTSTR text,
710  int x, int y, int w, int h,
711  LPCTSTR fileName,
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  //
719  TXCommCtrl::Raise(); // !BB Do we need a richedit-specific exception
720 
721  // Default to RTF data format
722  //
723  SetFormat(SF_RTF);
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  //
730  ModifyStyle(ES_LOWERCASE|ES_PASSWORD|ES_OEMCONVERT|ES_UPPERCASE|ES_AUTOHSCROLL,
731  ES_LEFT|WS_BORDER|WS_TABSTOP);
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  //
750  TXCommCtrl::Raise(); // !BB Do we need a richedit-specific exception
751 
752  // Default to RTF data format
753  //
754  SetFormat(SF_RTF);
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  //
761  ModifyStyle(ES_LOWERCASE|ES_PASSWORD|ES_OEMCONVERT|ES_UPPERCASE|ES_AUTOHSCROLL,
762  ES_LEFT|WS_BORDER|WS_TABSTOP);
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  //
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 //
789 ulong
790 TRichEdit::GetCharFormat(TCharFormat & cf, bool selection) const
791 {
792  TParam1 a1 = selection ? SCF_SELECTION : 0;
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 //
803 ulong
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 //
820 bool
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 //
829 bool
831 {
832  return SendMessage(EM_SETPARAFORMAT, 0, TParam2(&pf)) != 0;
833 }
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 //
840 TColor
842 {
843  TParam1 p1 = bkColor == TColor::None ? true : false;
844  TParam2 p2 = bkColor == TColor::None ? 0 : (COLORREF)bkColor;
845  return TColor((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 //
856 uint
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 //
874 bool
876 {
877  TCharFormat cf(*this);
878  cf.dwMask = mask;
879  cf.ToggleEffectsBit(effects);
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 //
887 bool
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 //
904 bool
906 {
907  TRange r = GetSelection();
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 //
915 void
916 TRichEdit::GetSelection(int& startPos, int& endPos) const
917 {
918  TCharRange cr;
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 //
928 void
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 //
938 bool
939 TRichEdit::SetSelection(int startPos, int endPos)
940 {
941  TCharRange cr(startPos, endPos);
942  return SetSelRange(cr) >= 0;
943 }
944 
945 //
946 /// Selects a range of characters in the rich edit control.
947 //
948 int
950 {
951  WARN(true, _T("TRichEdit::SetSelRange is deprecated. Use SetSelection instead."));
952  return (int)SendMessage(EM_EXSETSEL, 0, TParam2(&cr));
953 }
954 
955 //
956 /// Shows or hides the selection in the rich edit control. The 'hide' parameter
957 /// specifies whether to hide or show the selection. If it is 'false' the selection
958 /// is shown. Otherwise, the selection is hidden. The 'changeStyle' parameter
959 /// specifies whether to change the control's ES_NOHIDESEL window style. If this
960 /// parameter is 'false', the selection is temporarily shown or hidden. Otherwise,
961 /// the style is changed. If this parameter is 'true' and the control has the focus,
962 /// the selection is hidden or shown as appropriate.
963 //
964 void
965 TRichEdit::HideSelection(bool hide, bool changeStyle)
966 {
967  SendMessage(EM_HIDESELECTION, TParam1(hide), TParam2(changeStyle));
968 }
969 
970 //
971 /// Returns the selection type of the rich edit control. Returns SEL_EMPTY if the
972 /// selection is empty, or one or more of the following values:
973 /// - \c \b SEL_TEXT Text
974 /// - \c \b SEL_OBJECT At least one OLE object
975 /// - \c \b SEL_MULTICHAR More than one character of text
976 /// - \c \b SEL_MULTIOBJECT More than one OLE object
977 //
978 ulong
980 {
981  return static_cast<ulong>(SendMessage(EM_SELECTIONTYPE));
982 }
983 
984 
985 //
986 // Return the lenght of the text in the richedit control
987 // for RichEdit 2.0 uses EM_GETTEXTLENGTH
988 //
989 int
991 {
992  if (TRichEditDll::Dll()->GetVersion() >= 2)
993  {
994  GETTEXTLENGTHEX gtl;
995  gtl.flags = GTL_DEFAULT;
996 
997 //Jogy ??? From MSDN: Code page used in the translation. It is CP_ACP for ANSI Code Page and 1200 for Unicode.
998 #if defined(UNICODE)
999  gtl.codepage = 1200;
1000 #else
1001  gtl.codepage = CP_ACP;
1002 #endif
1003 
1004  return static_cast<int>(SendMessage(EM_GETTEXTLENGTHEX, TParam1(&gtl), TParam2(0)));
1005  }
1006  else
1007  {
1008  return GetWindowTextLength();
1009  }
1010 }
1011 
1012 //
1013 /// Retrieves a specified range of text from the rich edit control.
1014 /// NB! Deprecated. Use GetTextRange(const TRange&) instead.
1015 //
1016 int
1018 {
1019  WARN(true, _T("TRichEdit::GetTextRange(TTextRange&) is deprecated. Use GetTextRange(const TRange&) instead."));
1020  return (int)CONST_CAST(TRichEdit*,this)->SendMessage(EM_GETTEXTRANGE, 0, TParam2(&tr));
1021 }
1022 
1023 //
1024 /// Retrieves a specified range of text from the rich edit control.
1025 /// NB! Deprecated. Use GetTextRange(const TRange&) instead.
1026 //
1027 int
1028 TRichEdit::GetTextRange(const TCharRange & cr, LPTSTR buffer) const
1029 {
1030  WARN(true, _T("TRichEdit::GetTextRange(const TCharRange&, LPTSTR) is deprecated. Use GetTextRange(const TRange&) instead."));
1031  TTextRange tr(cr, buffer);
1032  return GetTextRange(tr);
1033 }
1034 
1035 //
1036 /// For use with CopyText
1037 //
1038 struct TRichEditGetTextRange
1039 {
1040  const TRichEdit& edit;
1041  const TCharRange& range;
1042  TRichEditGetTextRange(const TRichEdit& e, const TCharRange& r) : edit(e), range(r) {}
1043 
1044  int operator()(LPTSTR buf, int)
1045  {
1046  TTextRange tr(range, buf);
1047  return (int)CONST_CAST(TRichEdit*, &edit)->SendMessage(EM_GETTEXTRANGE, 0, TParam2(&tr));
1048  }
1049 };
1050 
1051 //
1052 /// Retrieves a specified range of text from the rich edit control.
1053 /// The range is half-open; i.e. range [0,2) for "abc" returns "ab".
1054 /// An empty string is returned if either
1055 ///
1056 /// - the control is empty (no text), or
1057 /// - the range is invalid (empty or inverted), or
1058 /// - both startPos and endPos is beyond the extents of the actual text.
1059 ///
1060 /// If endPos is beyond the valid range then it is limited to the valid range.
1061 /// A special case is the range [0, -1). It will return the full text.
1062 ///
1063 /// \todo Must be tested
1064 //
1065 tstring
1067 {
1068  const int begin = r.cpMin;
1069  int end = r.cpMax; // May be adjusted.
1070  const int n = GetTextLength();
1071 
1072  // Check input arguments against EM_GETTEXTRANGE requirements.
1073  // Note that [0, -1) for an empty control is not valid for EM_GETTEXTRANGE,
1074  // but we'll ignore that, since no buffer issues are involved here.
1075  // Otherwise we reject negative positions, as well as empty and inverted ranges.
1076  // EM_GETTEXTRANGE will not null-terminate the result in these cases.
1077 
1078  if (begin == 0 && end == -1)
1079  {
1080  end = n;
1081  }
1082  else if (begin < 0 || end < 0)
1083  {
1084  WARN(true, _T("Arguments out of range"));
1085  return tstring();
1086  }
1087  else if (begin == end)
1088  {
1089  WARN(true, _T("Empty range"));
1090  return tstring();
1091  }
1092  else if (begin > end)
1093  {
1094  WARN(true, _T("Inverted range"));
1095  return tstring();
1096  }
1097 
1098  // Return empty if the entire range is outside the extents of the actual text.
1099  // This is valid for EM_GETTEXTRANGE so we wont complain.
1100 
1101  if (begin >= n)
1102  return tstring();
1103 
1104  // Limit end to the actual text and calculate the resulting range length.
1105 
1106  end = std::min(end, n);
1107  const int range_length = end - begin; // length of half-open range
1108 
1109  // Do a sanity check, in case someone changes the code, etc,
1110  // then finally copy!
1111 
1112  CHECK(begin >= 0 && end >= 0 && begin < n && end <= n);
1113  TCharRange adjusted_range(begin, end);
1114  return CopyText(range_length, TRichEditGetTextRange(*this, adjusted_range));
1115 }
1116 
1117 //
1118 /// Retrieves a specified range of text from the rich edit control.
1119 /// NB! Deprecated. Use GetTextRange instead.
1120 //
1121 void
1122 TRichEdit::GetSubText(LPTSTR str, int startPos, int endPos) const
1123 {
1124  WARN(true, _T("TRichEdit::GetSubText is deprecated. Use GetTextRange instead."));
1125  TTextRange tr(startPos, endPos, str);
1126  GetTextRange(tr);
1127 }
1128 
1129 //
1130 /// Retrieves the currently-selected text of the rich edit control.
1131 //
1132 int
1133 TRichEdit::GetSelectedText(LPTSTR buffer) const
1134 {
1135  WARN(true, _T("TRichEdit::GetSelectedText(LPTSTR) is deprecated. Use GetSelectedText() instead."));
1136  return (int)CONST_CAST(TRichEdit*,this)->SendMessage(EM_GETSELTEXT, 0, TParam2(buffer));
1137 }
1138 
1139 //
1140 /// For use with CopyText
1141 //
1142 struct TRichEditGetSelectedText
1143 {
1144  const TRichEdit& edit;
1145  TRichEditGetSelectedText(const TRichEdit& e) : edit(e){}
1146 
1147  int operator()(LPTSTR buf, int)
1148  {return (int)CONST_CAST(TRichEdit*, &edit)->SendMessage(EM_GETSELTEXT, 0, TParam2(buf));}
1149 };
1150 
1151 //
1152 /// String-aware overload
1153 //
1154 tstring
1156 {
1157  const int n = GetSelection().GetSize();
1158  return (n > 0) ? CopyText(n, TRichEditGetSelectedText(*this)) : tstring();
1159 }
1160 
1161 //
1162 /// Sets an upper limit to the amount of text in the richedit control.
1163 //
1164 void
1166 {
1167  SendMessage(EM_EXLIMITTEXT, 0, TParam2(maxValue));
1168 }
1169 
1170 //
1171 /// Finds text within the rich edit control. The 'flags' parameter can be a
1172 /// combination of the following values:
1173 /// - \c \b FT_MATCHCASE Performs a case sensitiv search.
1174 /// - \c \b FT_MATCHWORD Matches whole words.
1175 //
1176 int
1178 {
1179  return (int)SendMessage(EM_FINDTEXT, TParam1(flags), TParam2(&ft));
1180 }
1181 
1182 //
1183 /// Finds text within the rich edit control. The 'flags' parameter can be a
1184 /// combination of the following values:
1185 /// - \c \b FT_MATCHCASE Performs a case sensitiv search.
1186 /// - \c \b FT_MATCHWORD Matches whole words.
1187 //
1188 int
1189 TRichEdit::FindText(uint flags, const TCharRange & cr, LPCTSTR text)
1190 {
1191  TFindText ft(cr, text);
1192  return FindText(flags, ft);
1193 }
1194 
1195 //
1196 // Search for the specified text in the rich edit control. If found, select
1197 // the text and return the offset of the text. Otherwise, return -1.
1198 //
1199 // NOTE: If the 'startPos' is -1, it is assumed that the starting position is
1200 // the end [or beginning, depending on the direction parameter, 'up'] of the
1201 // current selection
1202 //
1203 int
1204 TRichEdit::Search(int startPos, LPCTSTR text, bool caseSensitive,
1205  bool wholeWord, bool up)
1206 {
1207  if (!text || !text[0])
1208  return -1;
1209 
1210  if (startPos == -1) {
1211  int sBeg, sEnd;
1212  GetSelection(sBeg, sEnd);
1213  startPos = up ? sBeg : sEnd;
1214  }
1215 
1216  // The current docs. mention the FT_MATCHCASE and FT_WHOLEWORD flags which
1217  // are not defined currently. I suspect they meant the FR_xxxx flags (used
1218  // in CommDlg API).
1219  // Yes it is FR_MATCHCASE and FR_WHOLEWORD
1220  TFindText findText(startPos, -1, text);
1221  uint flags = (caseSensitive ? FR_MATCHCASE : 0) |
1222  (wholeWord ? FR_WHOLEWORD : 0) |
1223  (up ? 0 : FR_DOWN);
1224  int index = FindText(flags, findText);
1225 
1226  //
1227  // If we've got a match, select the text
1228  //
1229  if (index >= 0)
1230  {
1231  size_t end = index + ::_tcslen(text);
1232  if (!IsRepresentable<int>(end))
1233  return -1;
1234  SetSelection(index, static_cast<int>(end));
1235  }
1236  return index;
1237 }
1238 
1239 //
1240 // Find the next work break before or after the specified character position,
1241 // or retrieve information about the character at that position. The 'code'
1242 // parameter can be one of the following:
1243 //
1244 // WB_CLASSIFY Returns the character class and word break flags of the
1245 // character at the specified position.
1246 // WB_ISDELIMITER Returns TRUE if the character at the specified position
1247 // is a delimiter, or FALSE otherwise.
1248 // WB_LEFT Finds the nearest character before the specified
1249 // position that begins a word.
1250 // WB_LEFTBREAK Finds the next word end before the specified position.
1251 // WB_MOVEWORDLEFT Finds the next character that begins a word before the
1252 // specified position. This value is used during CTRL+LEFT key processing.
1253 // WB_MOVEWORDRIGHT Finds the next character that begins a word after the
1254 // specified position. This value is used during
1255 // CTRL+RIGHT key processing.
1256 // WB_RIGHT Finds the next character that begins a word after the
1257 // specified position.
1258 // WB_RIGHTBREAK Finds the next end-of-word delimiter after the
1259 // specified position.
1260 //
1261 // The return value is the character index of the word break, unless the
1262 // 'code' parameter is WB_CLASSIFY or WB_ISDELIMETER
1263 int
1265 {
1266  return (int)SendMessage(EM_FINDWORDBREAK, TParam1(code), TParam2(start));
1267 }
1268 
1269 //
1270 // Determine which line contains the specified character in the richedit
1271 // control.
1272 // NOTE: The return value is zero-based.
1273 //
1274 int
1275 TRichEdit::GetLineFromPos(int charPos) const
1276 {
1277  return (int)CONST_CAST(TRichEdit*,this)->SendMessage(EM_EXLINEFROMCHAR,
1278  0, TParam2(charPos));
1279 }
1280 
1281 
1282 //
1283 // Enable/Disable Auto URL detection
1284 // RichEdit 2.0 specific
1285 bool
1287 {
1288  if(TRichEditDll::Dll()->GetVersion() >= 2)
1289  return ToBool(SendMessage(EM_AUTOURLDETECT, TParam1(enable)));
1290  return false;
1291 }
1292 
1293 //
1294 //
1295 // RichEdit 2.0 specific
1296 int
1298 {
1299  return TRichEditDll::Dll()->GetVersion() >= 2 ?
1300  static_cast<int>(SendMessage(EM_GETIMECOMPMODE)) :
1301  ICM_NOTOPEN;
1302 }
1303 
1304 //
1305 //
1306 // RichEdit 2.0 specific
1307 void
1309 {
1310  if(TRichEditDll::Dll()->GetVersion() >= 2)
1311  SendMessage(EM_SETLANGOPTIONS,0,TParam2(options));
1312 }
1313 
1314 //
1315 //
1316 // RichEdit 2.0 specific
1317 int
1319 {
1320  return TRichEditDll::Dll()->GetVersion() >= 2 ?
1321  static_cast<int>(SendMessage(EM_GETLANGOPTIONS)) :
1322  0;
1323 }
1324 
1325 //
1326 //
1327 // RichEdit 2.0 specific
1328 void
1330 {
1331  if(TRichEditDll::Dll()->GetVersion() >= 2)
1332  SendMessage(EM_SETTEXTMODE,TParam1(mode));
1333 
1334  if(mode & TM_PLAINTEXT)
1335  Format = SF_TEXT;
1336  else if(mode & TM_RICHTEXT)
1337  Format = SF_RTF;
1338 }
1339 
1340 //
1341 //
1342 // RichEdit 2.0 specific
1343 int
1345 {
1346  return TRichEditDll::Dll()->GetVersion() >= 2 ?
1347  static_cast<int>(SendMessage(EM_GETTEXTMODE)) :
1348  IsRTF() ? TM_RICHTEXT : TM_PLAINTEXT;
1349 }
1350 
1351 //
1352 //
1353 // RichEdit 2.0 specific
1354 void
1356 {
1357  if(TRichEditDll::Dll()->GetVersion() >= 2)
1358  SendMessage(EM_SETUNDOLIMIT,TParam1(maxnum));
1359 }
1360 
1361 //
1362 //
1363 // RichEdit 2.0 specific
1364 void
1366 {
1367  if(TRichEditDll::Dll()->GetVersion() >= 2)
1368  SendMessage(EM_STOPGROUPTYPING);
1369 }
1370 
1371 //
1372 // Return true if the richedit can paste the specified clipboard format, or
1373 // false otherwise.
1374 //
1375 bool
1377 {
1378  return ToBool(CONST_CAST(TRichEdit*,this)->SendMessage(EM_CANPASTE,TParam1(format)));
1379 }
1380 
1381 //
1382 // RichEdit 2.0 specific
1383 //
1384 bool
1386 {
1387  if(TRichEditDll::Dll()->GetVersion() >= 2)
1388  return ToBool(CONST_CAST(TRichEdit*,this)->SendMessage(EM_CANREDO));
1389  return CanUndo();
1390 }
1391 
1392 //
1393 // RichEdit 2.0 specific
1394 // The value returned is an UNDONAMEID enumeration
1395 int
1397 {
1398  return TRichEditDll::Dll()->GetVersion() >= 2 ?
1399  static_cast<int>(SendMessage(EM_GETUNDONAME)) :
1400  0;
1401 }
1402 
1403 //
1404 // RichEdit 2.0 specific
1405 // The value returned is an UNDONAMEID enumeration
1406 int
1408 {
1409  return TRichEditDll::Dll()->GetVersion() >= 2 ?
1410  static_cast<int>(SendMessage(EM_GETREDONAME)) :
1411  0;
1412 }
1413 
1414 //
1415 // RichEdit 2.0 specific
1416 //
1417 void
1419 {
1420  if(TRichEditDll::Dll()->GetVersion() >= 2)
1421  SendMessage(EM_REDO);
1422  else
1423  Undo();
1424 }
1425 
1426 //
1427 // Paste the specified clipboard format in the rich edit control.
1428 //
1429 void
1431 {
1432  SendMessage(EM_PASTESPECIAL, TParam1(format));
1433 }
1434 
1435 //
1436 // Paste a compatible clipboard format in the rich edit control.
1437 //
1438 void
1440 {
1441  SendMessage(WM_PASTE);
1442 // !BB //
1443 // !BB // Iterator through clipboard to locate 'pastable' format
1444 // !BB //
1445 // !BB TClipboard clip(*this);
1446 // !BB for (TClipboardFormatIterator iter(clip); iter; iter++) {
1447 // !BB if (CanPaste(iter.Current())) {
1448 // !BB PasteSpecial(iter.Current());
1449 // !BB return;
1450 // !BB }
1451 // !BB }
1452 
1453 }
1454 
1455 //
1456 // Replace the contents of the rich edit control with the specified data
1457 // stream. The 'format' parameter can be one of the following data formats,
1458 // optionally combined with the SFF_SELECTION flag:
1459 //
1460 // Value Meaning
1461 // ----- -------
1462 // SF_TEXT Text
1463 // SF_RTF Rich-text format
1464 //
1465 // If the SFF_SELECTION flag is specified, the stream replaces the contents of
1466 // the current selection. Otherwise, the stream replaces the entire contents
1467 // of the control.
1468 //
1469 ulong
1471 {
1472  return static_cast<ulong>(SendMessage(EM_STREAMIN, TParam1(format), TParam2(&es)));
1473 }
1474 
1475 //
1476 // Write the contents of the rich edit control to the specified data stream.
1477 // The 'format' parameter can be one of the following values, optionally
1478 // combined with the SFF_SELECTION flag:
1479 //
1480 // Value Meaning
1481 // ----- -------
1482 // SF_TEXT Text with spaces in place of OLE objects
1483 // SF_RTF Rich-text format (RTF)
1484 // SF_RTFNOOBJS RTF with spaces in place of OLE object.
1485 // SF_TEXTIZED Text with a text representation of OLE objects.
1486 //
1487 // NOTE: The SF_RTFNOOBJS option is useful if an application stores OLE
1488 // objects itself, as RTF representation of OLE objects is not very
1489 // compact.
1490 // If the SFF_SELECTION flag is specified, only the contents of the
1491 // current selection are streamed out. Otherwise, the entire contents of
1492 // the control are streamed out.
1493 //
1494 ulong
1496 {
1497  return static_cast<ulong>(SendMessage(EM_STREAMOUT, TParam1(format), TParam2(&es)));
1498 }
1499 
1500 //
1501 // Display a portion of the richedit control's content within the specified
1502 // rectangle.
1503 // NOTE: The content of the control must first be formatted via a call to the
1504 // 'FormatRange' method.
1505 //
1506 bool
1508 {
1509  return SendMessage(EM_DISPLAYBAND, 0, TParam2(&rc)) != 0;
1510 }
1511 
1512 //
1513 // Formats a range of text (specified via the 'chrg' member of the
1514 // specified TFormatRange) for the device(s) specified via the 'hdcTarget'
1515 // and 'hdc' members of the TFormatRange structure.
1516 //
1517 int
1518 TRichEdit::FormatRange(const TFormatRange & fr, bool render)
1519 {
1520  return (int)SendMessage(EM_FORMATRANGE, TParam1(render), TParam2(&fr));
1521 }
1522 
1523 //
1524 // Frees the Formatting information cached by the RichEdit control...
1525 //
1526 int
1528 {
1529  return (int)SendMessage(EM_FORMATRANGE, TParam1(TRUE), 0);
1530 }
1531 
1532 //
1533 // Set the target device and line width used for WYSIWYG (what you see is
1534 // what you get) formatting of the rich edit control.
1535 //
1536 bool
1537 TRichEdit::SetTargetDevice(HDC dc, int lineWidth)
1538 {
1539  return SendMessage(EM_SETTARGETDEVICE, TParam1(dc),
1540  TParam2(lineWidth)) != 0;
1541 }
1542 
1543 //
1544 // Force the rich edit control to send an EN_REQUESTRESIZE notification
1545 // message to its parent window.
1546 //
1547 // NOTE: This message is useful during WM_SIZE processing for the parent of a
1548 // bottomless rich edit control.
1549 //
1550 void
1552 {
1553  SendMessage(EM_REQUESTRESIZE);
1554 }
1555 
1556 //
1557 // Retrieve an IRichEditOle object that a client can use to access a rich edit
1558 // control's OLE functionality. Returns 'true' if successful, or false
1559 // otherwise.
1560 //
1561 bool
1562 TRichEdit::GetOleInterface(IRichEditOle * &pInterface) const
1563 {
1564  return CONST_CAST(TRichEdit*,this)->SendMessage(EM_GETOLEINTERFACE,
1565  0, TParam2((void * *)&pInterface)) != 0;
1566 }
1567 
1568 //
1569 // Set an IRichEditOleCallback object that the rich edit control uses to get
1570 // OLE-related resources and information from the client. Returns 'true' if
1571 // successful, or false otherwise.
1572 //
1573 bool
1574 TRichEdit::SetOleInterface(IRichEditOleCallback * pInterface)
1575 {
1576  // Y.B 06/16/98 MFC uses EM_SETOLECALLBACK not EM_SETOLEINTERFACE ?????
1577  // afxxmn.inl line 620. func CRichEditCtrl::SetOLECallback(...)
1578  // #define EM_SETOLECALLBACK (WM_USER + 70) // not documented !!!!!!
1579  return SendMessage(EM_SETOLECALLBACK, 0, TParam2(pInterface)) != 0;
1580 }
1581 
1582 //
1583 // Retrieve the event mask for the rich edit control. The event mask specifies
1584 // which notification messages the control sends to its parent window.
1585 //
1586 ulong
1588 {
1589  return static_cast<ulong>(SendMessage(EM_GETEVENTMASK));
1590 }
1591 
1592 //
1593 // Set the event mask for a rich edit control. The event mask specifies which
1594 // notification messages the control sends to its parent window. The 'msk'
1595 // parameter can be zero or more of the following values:
1596 //
1597 // Value Meaning
1598 // ----- -------
1599 // ENM_CHANGE Sends EN_CHANGE notifications.
1600 // ENM_CORRECTTEXT Sends EN_CORRECTTEXT notifications.
1601 // ENM_DROPFILES Sends EN_DROPFILES notifications.
1602 // ENM_KEYEVENTS Sends EN_MSGFILTER notifications for keyboard events.
1603 // ENM_MOUSEEVENTS Sends EN_MSGFILTER notifications for mouse events.
1604 // ENM_PROTECTED Sends EN_PROTECTED notifications.
1605 // ENM_RESIZEREQUEST Sends EN_REQUESTRESIZE notifications.
1606 // ENM_SCROLL Sends EN_HSCROLL notifications.
1607 // ENM_SELCHANGE Sends EN_SELCHANGE notifications.
1608 // ENM_UPDATE Sends EN_UPDATE notifications
1609 //
1610 ulong
1612 {
1613  return static_cast<ulong>(SendMessage(EM_SETEVENTMASK, 0, TParam2(msk)));
1614 }
1615 
1616 //
1617 /// WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
1618 //
1619 uint
1621 {
1622  return TWindow::EvGetDlgCode(msg);
1623 }
1624 
1625 //
1626 /// WM_CHAR handler to bypass TEdit's handler (which caters to validators).
1627 //
1628 void
1629 TRichEdit::EvChar(uint /*key*/, uint /*repeatCount*/, uint /*flags*/)
1630 {
1632 }
1633 
1634 //
1635 /// WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
1636 //
1637 void
1638 TRichEdit::EvKeyDown(uint /*key*/, uint /*repeatCount*/, uint /*flags*/)
1639 {
1641 }
1642 
1643 //
1644 /// WM_KILLFOCUS handler to bypass TEdit's handler (which caters to validators).
1645 //
1646 void
1648 {
1649  TControl::EvKillFocus(hGetFocus);
1650 }
1651 
1652 //
1653 /// WM_SETFOCUS handler to bypass TEdit's handler (which caters to validators).
1654 //
1655 void
1657 {
1659 }
1660 
1661 //
1662 // This function is called for Cut/Copy/Delete menu items to determine
1663 // whether or not the item is enabled.
1664 //
1665 void
1667 {
1668  int sPos, ePos;
1669 
1670  GetSelection(sPos, ePos);
1671  commandHandler.Enable(sPos != ePos);
1672 }
1673 
1674 //
1675 // This function is called for the Paste menu item to determine whether or
1676 // not the item is enabled.
1677 //
1678 void
1680 {
1681 /*
1682  return (CountClipboardFormats() != 0) &&
1683  (IsClipboardFormatAvailable(CF_TEXT) ||
1684  IsClipboardFormatAvailable(_oleData.cfRichTextFormat) ||
1685  IsClipboardFormatAvailable(_oleData.cfEmbedSource) ||
1686  IsClipboardFormatAvailable(_oleData.cfEmbeddedObject) ||
1687  IsClipboardFormatAvailable(_oleData.cfFileName) ||
1688  IsClipboardFormatAvailable(_oleData.cfFileNameW) ||
1689  IsClipboardFormatAvailable(CF_METAFILEPICT) ||
1690  IsClipboardFormatAvailable(CF_DIB) ||
1691  IsClipboardFormatAvailable(CF_BITMAP) ||
1692  GetRichEditCtrl().CanPaste());
1693 */
1694  TClipboard clip(*this, false);
1695  if (clip &&
1696  (clip.CountClipboardFormats()!=0) &&
1697  ( clip.IsClipboardFormatAvailable(CF_TEXT) ||
1698  clip.IsClipboardFormatAvailable(CF_OEMTEXT) ||
1699  clip.IsClipboardFormatAvailable(CF_UNICODETEXT)
1700 // || clip.IsClipboardFormatAvailable(CF_METAFILEPICT) || //?? check
1701 // clip.IsClipboardFormatAvailable(CF_ENHMETAFILE) || //??
1702 // clip.IsClipboardFormatAvailable(CF_DIB) //???
1703  )
1704  ){
1705  ce.Enable(true);
1706  }
1707  else
1708  ce.Enable(false);
1709 }
1710 
1711 //
1712 // This function is called for the Clear menu item to determine whether or
1713 // not the item is enabled.
1714 //
1715 void
1717 {
1718  commandHandler.Enable(!(GetNumLines() == 1 && GetLineLength(0) == 0));
1719 }
1720 
1721 //
1722 // This function is called for the Undo menu item to determine whether or
1723 // not the item is enabled.
1724 //
1725 void
1727 {
1728  commandHandler.Enable(CanUndo());
1729 }
1730 
1731 //
1732 /// Returns name of predefined Windows edit class.
1733 //
1735 {
1736 #if defined(OWL_USERICHEDIT41)
1737  if(TRichEditDll::Dll()->GetVersion() >= 4)
1738  return TWindowClassName{MSFTEDIT_CLASS};
1739 #endif
1740 
1741  if(TRichEditDll::Dll()->GetVersion() >= 2)
1742  return TWindowClassName{RICHEDIT_CLASS};
1743  else
1744  return TWindowClassName{_T("RICHEDIT")};
1745 }
1746 
1747 //
1748 /// Updates the list of filters describing files which can be opened by
1749 /// the rich edit control.
1750 //
1751 //
1752 void
1754 {
1756 
1757  //Load RichEdit's filter
1758  //
1759  GetFileData().SetFilter(LoadString(IDS_RICHEDITFILTER).c_str());
1760 }
1761 
1762 
1763 uint32
1765 {
1767  POINTL pt;
1768  pt.x = x;
1769  pt.y = y;
1770 
1771  return (uint32)SendMessage(EM_CHARFROMPOS, 0, TParam2(&pt));
1772 }
1773 
1774 //
1775 uint32
1777 {
1779 
1780  if (TRichEditDll::Dll()->GetVersion() == 2)
1781  return (uint32)SendMessage(EM_POSFROMCHAR, charIndex);
1782  else
1783  {
1784  POINTL pt;
1785  SendMessage(EM_POSFROMCHAR, (TParam1)&pt, charIndex);
1786  return MkUint32((uint16)pt.y, (uint16)pt.x);
1787  }
1788 }
1789 
1790 
1791 //
1792 // Callback used when reading data from a stream into a rich edit control.
1793 //
1794 DWORD CALLBACK
1795 RichEditStrmInWithIStream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
1796 {
1797  PRECONDITION(dwCookie);
1798 
1799  tistream& is = *reinterpret_cast<tistream*>(dwCookie);
1800 
1801  // Return 0 if transfer is complete.
1802  //
1803  if (is.eof())
1804  {
1805  *pcb = 0;
1806  return 0;
1807  }
1808 
1809  // Read data in buffer.
1810  // Note: We know that the gcount cannot exceed cb, so we can cast unchecked.
1811  //
1812 #if defined(UNICODE)
1813  tstring tempBuff(cb, _T('\0'));
1814  is.read(&tempBuff[0], cb);
1815  LONG n = static_cast<LONG>(is.gcount());
1816  ::WideCharToMultiByte(CP_ACP, 0, &tempBuff[0], n, reinterpret_cast<char*>(pbBuff), cb, NULL, NULL);
1817 #else
1818  is.read(reinterpret_cast<char*>(pbBuff), cb);
1819  LONG n = static_cast<LONG>(is.gcount());
1820 #endif
1821 
1822  // Indicate amount of data read.
1823  //
1824  *pcb = n;
1825  return 0;
1826 }
1827 
1828 //
1829 // Callback used when writing out the contents of a rich edit control to
1830 // a data stream.
1831 //
1832 DWORD CALLBACK
1833 RichEditStrmOutWithOstream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
1834 {
1835  PRECONDITION(dwCookie);
1836 
1837  tostream& os = *reinterpret_cast<tostream*>(dwCookie);
1838 
1839  // Save current stream location and write data to buffer
1840  //
1841  streampos pCnt = os.tellp();
1842 
1843 #if defined(UNICODE)
1844  tchar * tempBuff = new tchar[cb];
1845  ::MultiByteToWideChar(CP_ACP, 0, (char*)pbBuff, cb, tempBuff, cb);
1846  os.write(tempBuff, cb);
1847  delete[] tempBuff;
1848 #else
1849  os.write((char*)pbBuff, cb);
1850 #endif
1851 
1852  // Indicate the number of bytes written to the file
1853  //
1854  *pcb = (LONG)(os.tellp() - pCnt);
1855  return 0;
1856 }
1857 
1858 //
1859 // Overriden to bypass TEdit's 'Transfer' method.
1860 // NOTE: There's no transfer-support for rich edit controls.
1861 //
1862 uint
1863 TRichEdit::Transfer(void* /*buffer*/, TTransferDirection /*direction*/)
1864 {
1865  // NOTE: No transfer support for rich edit control
1866  //
1867  return 0;
1868 }
1869 
1870 //
1871 // Read the data from the specified stream into the rich edit control. The
1872 // 'fmt' parameter can be one of the following data formats, optionally
1873 // combined with the SFF_SELECTION flag:
1874 //
1875 // Value Meaning
1876 // ----- -------
1877 // SF_TEXT Text
1878 // SF_RTF Rich-text format
1879 //
1880 // If the SFF_SELECTION flag is specified, the stream replaces the contents of
1881 // the current selection. Otherwise, the stream replaces the entire contents
1882 // of the control.
1883 //
1884 bool
1886 {
1887  DWORD_PTR cookie = reinterpret_cast<DWORD_PTR>(&is);
1888  TEditStream edStrm(cookie, RichEditStrmInWithIStream);
1889  StreamIn(fmt, edStrm);
1890  return edStrm.dwError == 0;
1891 }
1892 
1893 //
1894 // Write the contents of the rich edit control to the specified data stream.
1895 // The 'fmt' parameter can be one of the following values, optionally
1896 // combined with the SFF_SELECTION flag:
1897 //
1898 // Value Meaning
1899 // ----- -------
1900 // SF_TEXT Text with spaces in place of OLE objects
1901 // SF_RTF Rich-text format (RTF)
1902 // SF_RTFNOOBJS RTF with spaces in place of OLE object.
1903 // SF_TEXTIZED Text with a text representation of OLE objects.
1904 //
1905 // NOTE: The SF_RTFNOOBJS option is useful if an application stores OLE
1906 // objects itself, as RTF representation of OLE objects is not very
1907 // compact.
1908 // If the SFF_SELECTION flag is specified, only the contents of the
1909 // current selection are streamed out. Otherwise, the entire contents of
1910 // the control are streamed out.
1911 //
1912 bool
1914 {
1915  DWORD_PTR cookie = reinterpret_cast<DWORD_PTR>(&os);
1916  TEditStream edStrm(cookie, RichEditStrmOutWithOstream);
1917  StreamOut(fmt, edStrm);
1918  return edStrm.dwError == 0;
1919 }
1920 
1921 //
1922 // Read the contents of the specified file in the rich edit control. Returns
1923 // 'true' if successful, or false otherwise.
1924 //
1925 bool
1926 TRichEdit::Read(LPCTSTR fileName)
1927 {
1928  if (!fileName)
1929  {
1930  if (GetFileName())
1931  fileName = GetFileName();
1932  else
1933  return false;
1934  }
1935 
1937  tifstream ifs(_W2A(fileName), ios::in|ios::binary);
1938  if (ifs) {
1939  // Could check for a valid file (eg. FileSize != 0)
1940  // before proceeding with a call to Clear() here.
1941  //
1942  Clear();
1943 
1944  // Stream in data from file
1945  //
1946  if (ReadFromStream(ifs, Format)) {
1947  ClearModify();
1948  return true;
1949  }
1950  }
1951  return false;
1952 }
1953 
1954 //
1955 // Write the contents of the edit control to the specified file. Returns
1956 // 'true' if successful, or false otherwise.
1957 //
1958 bool
1959 TRichEdit::Write(LPCTSTR fileName)
1960 {
1961  if (!fileName)
1962  {
1963  if (GetFileName())
1964  fileName = GetFileName();
1965  else
1966  return false;
1967  }
1968 
1970  tofstream ofs(_W2A(fileName), ios::out|ios::binary);
1971  if (ofs) {
1972  if (WriteToStream(ofs, Format)) {
1973  ClearModify();
1974  return true;
1975  }
1976  }
1977  return false;
1978 }
1979 
1980 
1982 
1983 #if OWL_PERSISTENT_STREAMS
1984 //
1985 //
1986 void*
1987 TRichEdit::Streamer::Read(ipstream& is, uint32 /*version*/) const
1988 {
1989  ReadBaseObject((TEditFile*)GetObject(), is);
1990  return GetObject();
1991 }
1992 
1993 //
1994 //
1995 //
1996 void
1997 TRichEdit::Streamer::Write(opstream& os) const
1998 {
1999  WriteBaseObject((TEditFile*)GetObject(), os);
2000 }
2001 
2002 #endif
2003 //
2004 // Object wrapper which loads the RichEdit DLL
2005 //
2007 :
2008  TModule(
2009 #if defined(OWL_USERICHEDIT41)
2010  GetVersion() >= 4 ? RichEdit41DllName :
2011 #endif
2012  (GetVersion() >= 2 ? RichEdit20DllName : RichEditDllName),
2013  true, true,false
2014  )
2015 {
2016 }
2017 
2018 //
2019 // check new rich edit library
2020 //
2021 static int CheckREVersion()
2022 {
2023  TErrorMode loadMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
2024 
2025 #if defined(OWL_USERICHEDIT41)
2026  HINSTANCE Handle41 = ::LoadLibrary(RichEdit41DllName);
2027  if (Handle41 > HINSTANCE(HINSTANCE_ERROR))
2028  {
2029  ::FreeLibrary(Handle41);
2030  return 4;
2031  }
2032 #endif
2033 
2034  HINSTANCE Handle = ::LoadLibrary(RichEdit20DllName);
2035  if (Handle <= HINSTANCE(HINSTANCE_ERROR))
2036  return 1;
2037  ::FreeLibrary(Handle);
2038  return 2;
2039 }
2040 
2041 //
2042 //
2043 //
2044 int TRichEditModule::GetVersion(bool force_old)
2045 {
2046  static int REVersion = force_old ? 1 : CheckREVersion();
2047  return REVersion;
2048 }
2049 
2050 #if defined(_BUILDOWLDLL)
2051 // The template instances only need to be generated when building the
2052 // ObjectWindows DLL - These instances are exported by OWL and imported
2053 // by user code.
2054 
2055  //
2056  // Export template of TDllLoader<TRichEditModule> when building ObjectWindows
2057  // DLL and provide import declaration of DLL instance for users of the class.
2058  //
2059  template class _OWLCLASS TDllLoader<TRichEditModule>;
2060 #endif
2061 
2062 } // OWL namespace
2063 /* ========================================================================== */
2064 
_USES_CONVERSION
#define _USES_CONVERSION
Definition: memory.h:217
CHECK
#define CHECK(condition)
Definition: checks.h:245
EV_WM_GETDLGCODE
#define EV_WM_GETDLGCODE
Definition: windowev.h:295
owl::TRichEdit::SetSelection
auto SetSelection(int startPos, int endPos) -> bool override
Selects a range of characters in the rich edit control.
Definition: richedit.cpp:939
OWL_DIAGINFO
#define OWL_DIAGINFO
Definition: defs.h:174
owl::MkUint32
uint32 MkUint32(uint16 lo, uint16 hi)
Definition: defs.h:262
owl::TRichEditModule::TRichEditModule
TRichEditModule()
Definition: richedit.cpp:2006
owl::TRichEdit::TRichEdit
TRichEdit(TWindow *parent, int id, LPCTSTR text, int x, int y, int w, int h, LPCTSTR fileName=0, TModule *module=0)
Constructor for a TRichEdit object.
Definition: richedit.cpp:707
owl::TRichEdit::CeHasSelect
void CeHasSelect(TCommandEnabler &commandHandler)
Definition: richedit.cpp:1666
owl::TEdit::GetNumLines
int GetNumLines() const
Return the number of lines in the associated edit control.
Definition: edit.h:409
owl::TWindow
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition: window.h:411
owl::TTransferDirection
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition: window.h:89
owl::TOpenSaveDialog::TData::SetFilter
void SetFilter(LPCTSTR filter=0)
Makes a copy of the filter list used to display the file names.
Definition: opensave.cpp:141
owl::tistream
std::istream tistream
Definition: strmdefs.h:39
owl::TEdit::TRange::cpMax
int cpMax
Definition: edit.h:54
owl::uint16
unsigned short uint16
Definition: number.h:29
owl::TEdit::GetLineLength
int GetLineLength(int lineNumber) const
Return the length of line number "lineNumber".
Definition: edit.cpp:494
owl::TColor::None
static const TColor None
not-a-color
Definition: color.h:320
owl::RichEditDllName
const tchar RichEditDllName[]
Definition: richedit.cpp:29
owl::TRichEdit::PosFromChar
auto PosFromChar(uint charIndex) -> uint32 override
Definition: richedit.cpp:1776
END_RESPONSE_TABLE
#define END_RESPONSE_TABLE
Definition: eventhan.h:466
owl::TCharFormat
TCharFormat encapsulates the CHARFORMAT2 structure which contains information about character formatt...
Definition: richedit.h:56
owl::TEdit::ClearModify
void ClearModify()
Resets the change flag of the edit control causing IsModified to return false.
Definition: edit.h:276
owl::TRichEdit::PasteSpecial
void PasteSpecial(uint format)
Definition: richedit.cpp:1430
owl::TRichEdit::SetupWindow
void SetupWindow() override
Updates the list of filters describing files which can be opened by the rich edit control.
Definition: richedit.cpp:1753
owl::uint32
unsigned long uint32
Definition: number.h:30
owl::TRichEdit::ChangeCharPointSize
bool ChangeCharPointSize(int pointSizeDelta)
Increases or decreases (using a positive or negative value respectively) the point size of the curren...
Definition: richedit.cpp:888
owl::TRichEdit::GetSelectionType
ulong GetSelectionType() const
Returns the selection type of the rich edit control.
Definition: richedit.cpp:979
EV_WM_CHAR
#define EV_WM_CHAR
Definition: windowev.h:249
owl::TRichEdit::Paste
void Paste() override
Definition: richedit.cpp:1439
owl::TEdit::Clear
void Clear() override
Override TStatic virtual member functions.
Definition: edit.cpp:421
owl::TRichEdit::Search
auto Search(int startPos, LPCTSTR text, bool caseSensitive=false, bool wholeWord=false, bool up=false) -> int override
Definition: richedit.cpp:1204
owl::TRichEdit::LimitText
void LimitText(int maxValue) override
Sets an upper limit to the amount of text in the richedit control.
Definition: richedit.cpp:1165
_tcslen
#define _tcslen
Definition: cygwin.h:74
owl::TRichEdit::Redo
void Redo()
Definition: richedit.cpp:1418
owl::TEditFile::SetupWindow
void SetupWindow() override
Creates the edit window's Editor edit control by calling TEditFile::SetupWindow().
Definition: editfile.cpp:79
owl::TClipboard::CountClipboardFormats
int CountClipboardFormats() const
Returns a count of the number of types of data formats the Clipboard can use.
Definition: clipboar.h:224
owl::TRichEdit::HasCharAttribute
uint HasCharAttribute(ulong mask, uint32 effects)
Function returns whether or not the current selection has a particular attribute.
Definition: richedit.cpp:857
owl::TRichEdit::Partly
@ Partly
Part of the selection has the attribute.
Definition: richedit.h:296
owl::TRichEdit::FindText
int FindText(uint flags, const TFindText &)
Finds text within the rich edit control.
Definition: richedit.cpp:1177
owl::TRichEdit::CeEditUndo
void CeEditUndo(TCommandEnabler &commandHandler)
Definition: richedit.cpp:1726
owl::TRichEdit::EvGetDlgCode
uint EvGetDlgCode(const MSG *)
WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
Definition: richedit.cpp:1620
owl::TCommandEnabler::Enable
virtual void Enable(bool enable=true)
Enables or disables the command sender.
Definition: window.cpp:301
owl::IMPLEMENT_STREAMABLE1
IMPLEMENT_STREAMABLE1(TApplication, TModule)
owl::TParam2
LPARAM TParam2
Second parameter type.
Definition: dispatch.h:52
owl::TRichEdit::CharFromPos
auto CharFromPos(int16 x, int16 y) -> uint32 override
Definition: richedit.cpp:1764
owl::TDllLoader::IsAvailable
static bool IsAvailable()
Load the dll on demand, returning true if it was loaded OK.
Definition: module.h:498
owl::TWindow::GetHandle
HWND GetHandle() const
Returns the handle of the window.
Definition: window.h:2017
owl::TWindow::DefaultProcessing
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition: window.cpp:853
filename.h
richedit.h
EV_COMMAND
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition: windowev.h:171
owl::TRichEdit::SetLangOptions
void SetLangOptions(int options)
Definition: richedit.cpp:1308
owl::TRichEdit::SetEventMask
ulong SetEventMask(ulong msk)
Definition: richedit.cpp:1611
owl::TModule
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition: module.h:75
owl::TRichEdit::Format
uint Format
Definition: richedit.h:442
owl::TRichEdit::GetSelectedText
tstring GetSelectedText() const
String-aware overload.
Definition: richedit.cpp:1155
owl::TRichEdit::GetCharFormat
ulong GetCharFormat(TCharFormat &, bool selection=false) const
Retrieves the current character formatting in an edit control.
Definition: richedit.cpp:790
owl::TRichEdit::SetParaFormat
bool SetParaFormat(const TParaFormat &)
Sets the paragraph formatting of the current selection of the rich edit control.
Definition: richedit.cpp:830
owl::TEditStream
TEditStream encapsulates the EDITSTREAM structure, which contains information about a data stream use...
Definition: richedit.h:181
owl::TRichEdit::GetTextRange
int GetTextRange(TTextRange &) const
Retrieves a specified range of text from the rich edit control.
Definition: richedit.cpp:1017
DEFINE_RESPONSE_TABLE1
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition: eventhan.h:492
owl::TRichEdit::GetSelRange
void GetSelRange(TCharRange &) const
Retrieves the starting and ending character positions of the selection of the richedit control.
Definition: richedit.cpp:929
owl::TDllLoader
TDllLoader<> provides an easy way to load one instance of a DLL on demand.
Definition: module.h:418
owl::tstring
std::string tstring
Definition: defs.h:80
owl::TEdit::Undo
void Undo()
Undoes the last edit.
Definition: edit.h:305
owl::RichEditStrmInWithIStream
DWORD CALLBACK RichEditStrmInWithIStream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
Definition: richedit.cpp:1795
owl::TRichEditModule::GetVersion
static int GetVersion(bool force_old=false)
Definition: richedit.cpp:2044
owl::TRichEdit::GetSubText
void GetSubText(TCHAR *textBuf, int startPos, int endPos) const override
Retrieves a specified range of text from the rich edit control.
Definition: richedit.cpp:1122
owl::TWindow::EvKillFocus
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:1612
EV_WM_KILLFOCUS
#define EV_WM_KILLFOCUS
Definition: windowev.h:311
owl::TEditFile
TEditFile is a file-editing window.
Definition: editfile.h:35
owl::TRichEdit::SetUndoLimit
void SetUndoLimit(int maxnum)
Definition: richedit.cpp:1355
owl::TEdit::GetSelection
TRange GetSelection() const
Functional style overload.
Definition: edit.cpp:980
owl::TEditFile::GetFileName
LPCTSTR GetFileName() const
Return the filename for this buffer.
Definition: editfile.h:147
owl::ipstream
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition: objstrm.h:391
owl::TRichEdit::SetFormat
void SetFormat(uint fmt)
Definition: richedit.h:707
owl::TRichEdit::FindWordBreak
int FindWordBreak(uint code, int start)
Definition: richedit.cpp:1264
owl::TRichEdit::Yes
@ Yes
The attribute is absent from the selection.
Definition: richedit.h:295
owl::TRichEdit::GetWindowClassName
auto GetWindowClassName() -> TWindowClassName override
Returns name of predefined Windows edit class.
Definition: richedit.cpp:1734
owl::tchar
char tchar
Definition: defs.h:78
owl::CopyText
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
Definition: defs.h:318
owl::TRichEdit::Write
auto Write(LPCTSTR fileName=nullptr) -> bool override
< String-aware overload
Definition: richedit.cpp:1959
owl::TErrorMode
Simple encapsulation of the SetErrorMode call.
Definition: module.h:352
owl::TRichEdit::StreamOut
ulong StreamOut(uint format, TEditStream &)
Definition: richedit.cpp:1495
owl::TEdit::TRange::cpMin
int cpMin
Definition: edit.h:54
owl::int16
signed short int16
Definition: number.h:25
owl::TXCommCtrl::Raise
static void Raise()
Constructs a TXCommCtrl exception from scratch, and throws it.
Definition: commctrl.cpp:74
owl::TRichEdit::GetEventMask
ulong GetEventMask() const
Definition: richedit.cpp:1587
owl::TRichEdit::SetTargetDevice
bool SetTargetDevice(HDC, int lineWidth)
Definition: richedit.cpp:1537
owl::TRichEdit::IsRTF
bool IsRTF() const
Definition: richedit.h:715
owl::TRichEdit::EvKeyDown
void EvKeyDown(uint key, uint repeatCount, uint flags)
WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
Definition: richedit.cpp:1638
owl::TCharFormat::ToggleEffectsBit
void ToggleEffectsBit(ulong flag)
Toggles the effect bits specified in the 'flag' parameter.
Definition: richedit.h:587
owl::TRichEdit::GetParaFormat
ulong GetParaFormat(TParaFormat &) const
Retrieves the paragraph formatting of the current selection of the rich edit control.
Definition: richedit.cpp:804
owl::TRichEdit::GetUndoName
int GetUndoName() const
Definition: richedit.cpp:1396
owl::TRichEdit::EnableAutoURL
bool EnableAutoURL(bool enable=true)
Definition: richedit.cpp:1286
owl::TEdit::CanUndo
bool CanUndo() const
Returns true if it is possible to undo the last edit.
Definition: edit.h:690
owl::TEditFile::GetFileData
TOpenSaveDialog::TData & GetFileData()
Return the FileData data member used for the common dialogs.
Definition: editfile.h:154
owl::TRichEdit::SetBkgndColor
TColor SetBkgndColor(const TColor &=TColor::None)
Sets the background color of the rich edit control.
Definition: richedit.cpp:841
owl::TRichEdit::HasSelection
bool HasSelection() const
Returns true if the rich edit control has an active selection.
Definition: richedit.cpp:905
owl::TRichEdit::GetLineFromPos
auto GetLineFromPos(int charPos) const -> int override
Definition: richedit.cpp:1275
owl::TRichEdit::CanRedo
bool CanRedo() const
Definition: richedit.cpp:1385
owl::TRichEdit::HideSelection
void HideSelection(bool hide, bool changeStyle)
Shows or hides the selection in the rich edit control.
Definition: richedit.cpp:965
owl::TRichEdit::SetTextMode
void SetTextMode(int mode)
Definition: richedit.cpp:1329
owl::TRichEdit::GetLangOptions
int GetLangOptions() const
Definition: richedit.cpp:1318
owl::TRichEdit::GetOleInterface
bool GetOleInterface(IRichEditOle *&) const
Definition: richedit.cpp:1562
EV_WM_SETFOCUS
#define EV_WM_SETFOCUS
Definition: windowev.h:374
owl::TRichEdit::StreamIn
ulong StreamIn(uint format, TEditStream &)
Definition: richedit.cpp:1470
PRECONDITION
#define PRECONDITION(condition)
Definition: checks.h:233
owl::TWindow::EvGetDlgCode
uint EvGetDlgCode(const MSG *msg)
The default message handler for WM_GETDLGCODE.
Definition: window.h:3695
owl::MinPointSize
const int MinPointSize
Definition: richedit.cpp:24
owl::TFormatRange
TFormatRange encapsulates the FORMATRANGE structure, which contains information that a rich edit cont...
Definition: richedit.h:156
owl::uint
unsigned int uint
Definition: number.h:21
_OWLCLASS
#define _OWLCLASS
Definition: defs.h:290
CONST_CAST
#define CONST_CAST(targetType, object)
Definition: defs.h:225
owl::TRichEdit::ReadFromStream
bool ReadFromStream(tistream &, uint format=SF_RTF)
< String-aware overload
Definition: richedit.cpp:1885
owl::TRichEdit::CeEditPaste
void CeEditPaste(TCommandEnabler &commandHandler)
Definition: richedit.cpp:1679
pch.h
owl::TWindow::LoadString
tstring LoadString(uint id) const
Definition: window.h:605
owl::TCharRange
TCharRange encapsulates the CHARRANGE structure, which specifies a range of characters in a rich edit...
Definition: richedit.h:105
owl::TWindowClassName
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition: module.h:47
_W2A
#define _W2A(lpw)
Definition: memory.h:219
owl::TColor
Class wrapper for management of color values.
Definition: color.h:247
owl::TEdit::TRange
Represents a half-open range of positions in the edit control, e.g.
Definition: edit.h:49
owl::TClipboard::IsClipboardFormatAvailable
bool IsClipboardFormatAvailable(uint format) const
Indicates if the format specified in format exists for use in the Clipboard.
Definition: clipboar.h:247
owl::tofstream
std::ofstream tofstream
Definition: strmdefs.h:44
owl::TWindow::ModifyStyle
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition: window.cpp:3592
owl::TFindText
TFindText encapsulates the FINDTEXT structure, which contains information about text to search for in...
Definition: richedit.h:206
owl::RichEditStrmOutWithOstream
DWORD CALLBACK RichEditStrmOutWithOstream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
Definition: richedit.cpp:1833
owl::TRichEdit::RequestResize
void RequestResize()
Definition: richedit.cpp:1551
owl::TRichEdit::GetRedoName
int GetRedoName() const
Definition: richedit.cpp:1407
owl::TRichEdit::Transfer
auto Transfer(void *buffer, TTransferDirection) -> uint override
Definition: richedit.cpp:1863
owl::TRichEdit::GetTextMode
int GetTextMode() const
Definition: richedit.cpp:1344
owl::TRichEdit
TRichEdit encapsulates a rich edit control, a window in which a user can enter, edit and format text.
Definition: richedit.h:261
owl::uint8
unsigned char uint8
Definition: number.h:28
owl::TRichEdit::FormatRange
int FormatRange()
Definition: richedit.cpp:1527
owl::TRichEdit::DisplayBand
bool DisplayBand(TRect &)
Definition: richedit.cpp:1507
owl::TParaFormat
TParaFormat encapsulates the PARAFORMAT structure, which contains information about paragraph formatt...
Definition: richedit.h:119
owl::ToBool
bool ToBool(const T &t)
Definition: defs.h:243
owl::tostream
std::ostream tostream
Definition: strmdefs.h:40
owl
Object Windows Library (OWLNext Core)
Definition: animctrl.h:22
owl::MaxPointSize
const int MaxPointSize
Definition: richedit.cpp:25
owl::TRichEdit::SetCharFormat
bool SetCharFormat(const TCharFormat &, uint flags=SCF_SELECTION)
Sets the character formatting of a rich edit control.
Definition: richedit.cpp:821
owl::TRichEdit::ToggleCharAttribute
bool ToggleCharAttribute(ulong mask, uint32 effects)
Toggles a set of character attributes.
Definition: richedit.cpp:875
owl::TWindow::GetWindowTextLength
int GetWindowTextLength() const
Returns the length, in characters, of the specified window's title.
Definition: window.h:2638
owl::ulong
unsigned long ulong
Definition: number.h:22
owl::TParam1
WPARAM TParam1
First parameter type.
Definition: dispatch.h:51
owl::TEdit::TRange::GetSize
int GetSize() const
Definition: edit.h:52
owl::TRichEdit::CeEditClear
void CeEditClear(TCommandEnabler &commandHandler)
Definition: richedit.cpp:1716
owl::TRichEdit::No
@ No
The whole selection has the attribute.
Definition: richedit.h:294
owl::TRichEdit::EvChar
void EvChar(uint key, uint repeatCount, uint flags)
WM_CHAR handler to bypass TEdit's handler (which caters to validators).
Definition: richedit.cpp:1629
owl::TRichEdit::Read
auto Read(LPCTSTR fileName=nullptr) -> bool override
Definition: richedit.cpp:1926
owl::TRichEdit::StopGroupTyping
void StopGroupTyping()
Definition: richedit.cpp:1365
owl::TRichEdit::SetOleInterface
bool SetOleInterface(IRichEditOleCallback *)
Definition: richedit.cpp:1574
owl::TRichEdit::EvKillFocus
void EvKillFocus(HWND hWndGetFocus)
WM_KILLFOCUS handler to bypass TEdit's handler (which caters to validators).
Definition: richedit.cpp:1647
owl::TRichEdit::SetSelRange
int SetSelRange(const TCharRange &)
Selects a range of characters in the rich edit control.
Definition: richedit.cpp:949
_T
#define _T(x)
Definition: cygwin.h:51
owl::TTextRange
TTextRange encapsulates the TEXTRANGE structure, which contains information about a range of text in ...
Definition: richedit.h:193
owl::TRichEdit::EvSetFocus
void EvSetFocus(HWND hWndLostFocus)
WM_SETFOCUS handler to bypass TEdit's handler (which caters to validators).
Definition: richedit.cpp:1656
owl::WriteBaseObject
void WriteBaseObject(Base *base, opstream &out)
Definition: objstrm.h:1150
EV_COMMAND_ENABLE
#define EV_COMMAND_ENABLE(id, method)
Response table entry for enabling a command.
Definition: windowev.h:193
owl::ReadBaseObject
void ReadBaseObject(Base *base, ipstream &in)
Definition: objstrm.h:1159
WARN
#define WARN(condition, message)
Definition: checks.h:279
owl::TCommandEnabler
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition: window.h:206
EV_WM_KEYDOWN
#define EV_WM_KEYDOWN
Definition: windowev.h:309
owl::tifstream
std::ifstream tifstream
Definition: strmdefs.h:43
owl::TWindow::THandle
HWND THandle
TWindow encapsulates an HWND.
Definition: window.h:415
owl::TRichEdit::GetIMEMode
int GetIMEMode() const
Definition: richedit.cpp:1297
owl::TRichEdit::WriteToStream
bool WriteToStream(tostream &, uint format=SF_RTF)
Definition: richedit.cpp:1913
owl::TClipboard
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition: clipboar.h:32
owl::RichEdit20DllName
const tchar RichEdit20DllName[]
Definition: richedit.cpp:30
owl::TRichEdit::GetTextLength
int GetTextLength() const
Definition: richedit.cpp:990
owl::TDllLoader::Dll
static T * Dll()
Definition: module.h:508
owl::TRichEdit::CanPaste
bool CanPaste(uint format) const
Definition: richedit.cpp:1376
owl::TWindow::SendMessage
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition: window.cpp:3289
owl::TRect
TRect is a mathematical class derived from tagRect.
Definition: geometry.h:308