|
OWLNext
7.0
Borland's Object Windows Library for the modern age
|
Go to the documentation of this file.
12 #if defined(__BORLANDC__)
13 # pragma option -w-ccc // Disable "Condition is always true/false"
33 # if defined(MSFTEDIT_CLASS)
34 # define OWL_USERICHEDIT41
39 #if defined(OWL_USERICHEDIT41)
40 const tchar RichEdit41DllName[] =
_T(
"Msftedit.dll");
57 memset(
this, 0,
sizeof(CHARFORMAT2));
59 cbSize =
sizeof(::CHARFORMAT);
60 if(TRichEditDll::Dll()->GetVersion() >= 2)
61 cbSize =
sizeof(CHARFORMAT2);
64 edit.GetCharFormat(*
this, selection);
71 TCharFormat::EnableBold(
bool flag)
75 dwEffects |= CFE_BOLD;
77 dwEffects &= ~CFE_BOLD;
84 TCharFormat::EnableItalic(
bool flag)
88 dwEffects |= CFE_ITALIC;
90 dwEffects &= ~CFE_ITALIC;
97 TCharFormat::EnableUnderline(
bool flag)
99 dwMask |= CFM_UNDERLINE;
101 dwEffects |= CFE_UNDERLINE;
103 dwEffects &= ~CFE_UNDERLINE;
110 TCharFormat::EnableStrikeOut(
bool flag)
112 dwMask |= CFM_STRIKEOUT;
114 dwEffects |= CFE_STRIKEOUT;
116 dwEffects &= ~CFE_STRIKEOUT;
123 TCharFormat::EnableProtected(
bool flag)
125 dwMask |= CFM_PROTECTED;
127 dwEffects |= CFE_PROTECTED;
129 dwEffects &= ~CFE_PROTECTED;
138 TCharFormat::GetTextColor()
const
140 if ((dwMask & CFM_COLOR) && !(dwEffects & CFE_AUTOCOLOR))
141 return TColor(crTextColor);
142 return TColor::SysWindowText;
151 TCharFormat::SetTextColor(
const TColor& color)
154 if (color == TColor::None)
155 dwEffects |= CFE_AUTOCOLOR;
157 dwEffects &= ~CFE_AUTOCOLOR;
168 TCharFormat::SetFaceName(LPCTSTR name)
171 szFaceName[0] =
_T(
'\0');
172 ::_tcsncat(szFaceName, name, LF_FACESIZE - 1);
180 TCharFormat::SetCharSet(
uint8 charSet)
195 TCharFormat::SetPitchAndFamily(
uint8 pitchFam)
197 bPitchAndFamily = pitchFam;
204 TCharFormat::SetHeight(
long height)
215 TCharFormat::SetOffset(
long offset)
217 dwMask |= CFM_OFFSET;
228 TCharFormat::SetFontInfo(LOGFONT& lf)
const
230 memset(&lf, 0,
sizeof(LOGFONT));
232 if (dwMask & CFM_SIZE)
233 lf.lfHeight = yHeight/-20;
235 if (dwMask & CFM_BOLD)
236 lf.lfWeight = dwEffects & CFE_BOLD ? FW_BOLD : FW_NORMAL;
238 if (dwMask & CFM_ITALIC)
239 lf.lfItalic = (
uint8)(dwEffects & CFE_ITALIC ? TRUE : FALSE);
241 if (dwMask & CFM_UNDERLINE)
242 lf.lfUnderline = (
uint8)(dwEffects & CFE_UNDERLINE ? TRUE : FALSE);
244 if (dwMask & CFM_FACE) {
245 lf.lfPitchAndFamily = bPitchAndFamily;
246 lf.lfFaceName[0] =
_T(
'\0');
247 ::_tcsncat(lf.lfFaceName, szFaceName, LF_FACESIZE - 1);
250 lf.lfCharSet = DEFAULT_CHARSET;
251 lf.lfQuality = DEFAULT_QUALITY;
259 TCharFormat::GetFontInfo(
const LOGFONT& lf)
261 dwMask = (CFM_SIZE | CFM_BOLD | CFM_ITALIC | CFM_OFFSET|
262 CFM_STRIKEOUT | CFM_UNDERLINE | CFM_FACE);
264 yHeight = lf.lfHeight * -20;
266 if (FW_BOLD == lf.lfWeight)
267 dwEffects |= CFE_BOLD;
269 dwEffects |= CFE_ITALIC;
271 dwEffects |= CFE_STRIKEOUT;
273 dwEffects |= CFE_UNDERLINE;
275 bPitchAndFamily = lf.lfPitchAndFamily;
276 szFaceName[0] =
_T(
'\0');
277 ::_tcsncat(szFaceName, lf.lfFaceName, LF_FACESIZE - 1);
286 dwMask |= CFM_WEIGHT;
294 TCharFormat::SetSpacing(
int16 spacing)
296 dwMask |= CFM_SPACING;
305 TCharFormat::GetBkColor()
const
307 if ((dwMask & CFM_BACKCOLOR)&& !(dwEffects & CFE_AUTOBACKCOLOR))
308 return TColor(crBackColor);
309 return TColor::SysWindow;
316 TCharFormat::SetBkColor(
const TColor& clr)
318 dwMask |= CFM_BACKCOLOR;
319 if (clr == TColor::None)
320 dwEffects |= CFE_AUTOBACKCOLOR;
322 dwEffects &= ~CFE_AUTOBACKCOLOR;
331 TCharFormat::SetLCID(LCID _lcid)
361 TCharFormat::SetUnderlineType(
uint8 utype)
363 dwMask |= CFM_UNDERLINETYPE;
364 bUnderlineType = utype;
371 TCharFormat::SetAnimation(
uint8 anim)
373 dwMask |= CFM_ANIMATION;
381 TCharFormat::SetRevAuthor(
uint8 revav)
383 dwMask |= CFM_REVAUTHOR;
394 TFormatRange::TFormatRange(HDC renderDC, HDC devDC,
const TRect& renderArea,
397 SetRenderDC(renderDC);
399 SetRenderRect(renderArea);
400 SetPageRect(entireArea);
408 TFormatRange::SetRenderDC(HDC renderDC)
417 TFormatRange::SetTargetDC(HDC targetDC)
419 hdcTarget = targetDC;
427 TFormatRange::SetRenderRect(
const TRect& renderRect)
437 TFormatRange::SetPageRect(
const TRect& pgRect)
455 TFormatRange::SetRange(
long start,
long end)
465 TParaFormat::TParaFormat(
ulong mask)
467 memset(
this, 0,
sizeof(PARAFORMAT2));
469 cbSize =
sizeof(PARAFORMAT);
470 if(TRichEditDll::Dll()->GetVersion() >= 2)
471 cbSize =
sizeof(PARAFORMAT2);
484 memset(
this, 0,
sizeof(PARAFORMAT2));
486 cbSize =
sizeof(PARAFORMAT);
487 if(TRichEditDll::Dll()->GetVersion() >= 2)
488 cbSize =
sizeof(PARAFORMAT2);
491 edit.GetParaFormat(*
this);
499 TParaFormat::ToggleMaskBit(
ulong flag)
512 dwMask |= PFM_NUMBERING;
523 TParaFormat::SetStartIndent(
long start,
bool relative)
525 dwMask |= PFM_STARTINDENT;
527 dwMask |= PFM_OFFSETINDENT;
529 dwMask &= ~PFM_OFFSETINDENT;
531 dxStartIndent = start;
538 TParaFormat::SetRightIndent(
long indent)
540 dwMask |= PFM_RIGHTINDENT;
541 dxRightIndent = indent;
550 TParaFormat::SetOffset(
long offset)
552 dwMask |= PFM_OFFSET;
565 dwMask |= PFM_ALIGNMENT;
573 TParaFormat::SetTabCount(
short cnt,
long* tabs)
577 dwMask |= PFM_TABSTOPS;
579 for (
int i=0; i<cnt; i++)
580 rgxTabs[i] = *tabs++;
587 TParaFormat::SetSpaceBefore(
long space)
589 dwMask |= PFM_SPACEBEFORE;
590 dySpaceBefore = space;
597 TParaFormat::SetSpaceAfter(
long space)
599 dwMask |= PFM_SPACEAFTER;
600 dySpaceAfter = space;
607 TParaFormat::SetLineSpacing(
long space,
uint8 rule)
609 dwMask |= PFM_LINESPACING;
610 dyLineSpacing = space;
611 bLineSpacingRule = rule;
631 dwMask |= PFM_SHADING;
632 wShadingWeight = wight;
633 wShadingStyle = style;
642 dwMask |= PFM_NUMBERINGSTART;
643 wNumberingStart = start;
652 dwMask |= PFM_NUMBERINGSTYLE;
653 wNumberingStyle = style;
662 dwMask |= PFM_NUMBERINGTAB;
672 dwMask |= PFM_BORDER;
673 wBorderSpace = space;
674 wBorderWidth = width;
710 int x,
int y,
int w,
int h,
714 TEditFile(parent, id, text, x, y, w, h, fileName, module)
730 ModifyStyle(ES_LOWERCASE|ES_PASSWORD|ES_OEMCONVERT|ES_UPPERCASE|ES_AUTOHSCROLL,
731 ES_LEFT|WS_BORDER|WS_TABSTOP);
741 int x,
int y,
int w,
int h,
745 :
TEditFile(parent, id, text, x, y, w, h, fileName, module)
761 ModifyStyle(ES_LOWERCASE|ES_PASSWORD|ES_OEMCONVERT|ES_UPPERCASE|ES_AUTOHSCROLL,
762 ES_LEFT|WS_BORDER|WS_TABSTOP);
775 TEditFile(parent, resourceId, module ? *module : *parent->GetModule())
792 TParam1 a1 = selection ? SCF_SELECTION : 0;
860 if (cf.dwMask & mask) {
861 if (cf.dwEffects & effects)
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;
931 WARN(
true,
_T(
"TRichEdit::GetSelRange is deprecated. Use GetSelection instead."));
951 WARN(
true,
_T(
"TRichEdit::SetSelRange is deprecated. Use SetSelection instead."));
995 gtl.flags = GTL_DEFAULT;
1001 gtl.codepage = CP_ACP;
1019 WARN(
true,
_T(
"TRichEdit::GetTextRange(TTextRange&) is deprecated. Use GetTextRange(const TRange&) instead."));
1030 WARN(
true,
_T(
"TRichEdit::GetTextRange(const TCharRange&, LPTSTR) is deprecated. Use GetTextRange(const TRange&) instead."));
1038 struct TRichEditGetTextRange
1044 int operator()(LPTSTR buf,
int)
1046 TTextRange tr(range, buf);
1047 return (
int)
CONST_CAST(TRichEdit*, &edit)->SendMessage(EM_GETTEXTRANGE, 0,
TParam2(&tr));
1068 const int begin = r.
cpMin;
1078 if (begin == 0 && end == -1)
1082 else if (begin < 0 || end < 0)
1084 WARN(
true,
_T(
"Arguments out of range"));
1087 else if (begin == end)
1089 WARN(
true,
_T(
"Empty range"));
1092 else if (begin > end)
1094 WARN(
true,
_T(
"Inverted range"));
1106 end = std::min(end, n);
1107 const int range_length = end - begin;
1112 CHECK(begin >= 0 && end >= 0 && begin < n && end <= n);
1114 return CopyText(range_length, TRichEditGetTextRange(*
this, adjusted_range));
1124 WARN(
true,
_T(
"TRichEdit::GetSubText is deprecated. Use GetTextRange instead."));
1135 WARN(
true,
_T(
"TRichEdit::GetSelectedText(LPTSTR) is deprecated. Use GetSelectedText() instead."));
1142 struct TRichEditGetSelectedText
1145 TRichEditGetSelectedText(
const TRichEdit& e) : edit(e){}
1147 int operator()(LPTSTR buf,
int)
1148 {
return (
int)
CONST_CAST(TRichEdit*, &edit)->SendMessage(EM_GETSELTEXT, 0,
TParam2(buf));}
1158 return (n > 0) ?
CopyText(n, TRichEditGetSelectedText(*
this)) :
tstring();
1205 bool wholeWord,
bool up)
1207 if (!text || !text[0])
1210 if (startPos == -1) {
1213 startPos = up ? sBeg : sEnd;
1221 uint flags = (caseSensitive ? FR_MATCHCASE : 0) |
1222 (wholeWord ? FR_WHOLEWORD : 0) |
1224 int index =
FindText(flags, findText);
1232 if (!IsRepresentable<int>(end))
1300 static_cast<int>(
SendMessage(EM_GETIMECOMPMODE)) :
1321 static_cast<int>(
SendMessage(EM_GETLANGOPTIONS)) :
1334 if(mode & TM_PLAINTEXT)
1336 else if(mode & TM_RICHTEXT)
1348 IsRTF() ? TM_RICHTEXT : TM_PLAINTEXT;
1565 0,
TParam2((
void * *)&pInterface)) != 0;
1671 commandHandler.
Enable(sPos != ePos);
1736 #if defined(OWL_USERICHEDIT41)
1812 #if defined(UNICODE)
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);
1818 is.read(
reinterpret_cast<char*
>(pbBuff), cb);
1819 LONG n =
static_cast<LONG
>(is.gcount());
1841 streampos pCnt = os.tellp();
1843 #if defined(UNICODE)
1845 ::MultiByteToWideChar(CP_ACP, 0, (
char*)pbBuff, cb, tempBuff, cb);
1846 os.write(tempBuff, cb);
1849 os.write((
char*)pbBuff, cb);
1854 *pcb = (LONG)(os.tellp() - pCnt);
1887 DWORD_PTR cookie =
reinterpret_cast<DWORD_PTR
>(&is);
1890 return edStrm.dwError == 0;
1915 DWORD_PTR cookie =
reinterpret_cast<DWORD_PTR
>(&os);
1918 return edStrm.dwError == 0;
1983 #if OWL_PERSISTENT_STREAMS
1997 TRichEdit::Streamer::Write(opstream& os)
const
2009 #if defined(OWL_USERICHEDIT41)
2010 GetVersion() >= 4 ? RichEdit41DllName :
2021 static int CheckREVersion()
2023 TErrorMode loadMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
2025 #if defined(OWL_USERICHEDIT41)
2026 HINSTANCE Handle41 = ::LoadLibrary(RichEdit41DllName);
2027 if (Handle41 > HINSTANCE(HINSTANCE_ERROR))
2029 ::FreeLibrary(Handle41);
2035 if (Handle <= HINSTANCE(HINSTANCE_ERROR))
2037 ::FreeLibrary(Handle);
2046 static int REVersion = force_old ? 1 : CheckREVersion();
2050 #if defined(_BUILDOWLDLL)
auto SetSelection(int startPos, int endPos) -> bool override
Selects a range of characters in the rich edit control.
uint32 MkUint32(uint16 lo, uint16 hi)
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.
void CeHasSelect(TCommandEnabler &commandHandler)
int GetNumLines() const
Return the number of lines in the associated edit control.
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
void SetFilter(LPCTSTR filter=0)
Makes a copy of the filter list used to display the file names.
int GetLineLength(int lineNumber) const
Return the length of line number "lineNumber".
static const TColor None
not-a-color
const tchar RichEditDllName[]
auto PosFromChar(uint charIndex) -> uint32 override
#define END_RESPONSE_TABLE
void ClearModify()
Resets the change flag of the edit control causing IsModified to return false.
void PasteSpecial(uint format)
void SetupWindow() override
Updates the list of filters describing files which can be opened by the rich edit control.
bool ChangeCharPointSize(int pointSizeDelta)
Increases or decreases (using a positive or negative value respectively) the point size of the curren...
ulong GetSelectionType() const
Returns the selection type of the rich edit control.
void Clear() override
Override TStatic virtual member functions.
auto Search(int startPos, LPCTSTR text, bool caseSensitive=false, bool wholeWord=false, bool up=false) -> int override
void LimitText(int maxValue) override
Sets an upper limit to the amount of text in the richedit control.
void SetupWindow() override
Creates the edit window's Editor edit control by calling TEditFile::SetupWindow().
int CountClipboardFormats() const
Returns a count of the number of types of data formats the Clipboard can use.
uint HasCharAttribute(ulong mask, uint32 effects)
Function returns whether or not the current selection has a particular attribute.
@ Partly
Part of the selection has the attribute.
int FindText(uint flags, const TFindText &)
Finds text within the rich edit control.
void CeEditUndo(TCommandEnabler &commandHandler)
uint EvGetDlgCode(const MSG *)
WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
virtual void Enable(bool enable=true)
Enables or disables the command sender.
IMPLEMENT_STREAMABLE1(TApplication, TModule)
LPARAM TParam2
Second parameter type.
auto CharFromPos(int16 x, int16 y) -> uint32 override
static bool IsAvailable()
Load the dll on demand, returning true if it was loaded OK.
HWND GetHandle() const
Returns the handle of the window.
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
void SetLangOptions(int options)
ulong SetEventMask(ulong msk)
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
tstring GetSelectedText() const
String-aware overload.
ulong GetCharFormat(TCharFormat &, bool selection=false) const
Retrieves the current character formatting in an edit control.
bool SetParaFormat(const TParaFormat &)
Sets the paragraph formatting of the current selection of the rich edit control.
TEditStream encapsulates the EDITSTREAM structure, which contains information about a data stream use...
int GetTextRange(TTextRange &) const
Retrieves a specified range of text from the rich edit control.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
void GetSelRange(TCharRange &) const
Retrieves the starting and ending character positions of the selection of the richedit control.
TDllLoader<> provides an easy way to load one instance of a DLL on demand.
void Undo()
Undoes the last edit.
DWORD CALLBACK RichEditStrmInWithIStream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
static int GetVersion(bool force_old=false)
void GetSubText(TCHAR *textBuf, int startPos, int endPos) const override
Retrieves a specified range of text from the rich edit control.
void EvKillFocus(HWND hWndGetFocus)
Handle WM_KILLFOCUS so that we can have a parent window hold onto our Handle and possibly restore foc...
TEditFile is a file-editing window.
void SetUndoLimit(int maxnum)
TRange GetSelection() const
Functional style overload.
LPCTSTR GetFileName() const
Return the filename for this buffer.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
int FindWordBreak(uint code, int start)
@ Yes
The attribute is absent from the selection.
auto GetWindowClassName() -> TWindowClassName override
Returns name of predefined Windows edit class.
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
auto Write(LPCTSTR fileName=nullptr) -> bool override
< String-aware overload
Simple encapsulation of the SetErrorMode call.
ulong StreamOut(uint format, TEditStream &)
static void Raise()
Constructs a TXCommCtrl exception from scratch, and throws it.
ulong GetEventMask() const
bool SetTargetDevice(HDC, int lineWidth)
void EvKeyDown(uint key, uint repeatCount, uint flags)
WM_GETDLGCODE handler to bypass TEdit's handler (which caters to validators).
ulong GetParaFormat(TParaFormat &) const
Retrieves the paragraph formatting of the current selection of the rich edit control.
bool EnableAutoURL(bool enable=true)
bool CanUndo() const
Returns true if it is possible to undo the last edit.
TOpenSaveDialog::TData & GetFileData()
Return the FileData data member used for the common dialogs.
TColor SetBkgndColor(const TColor &=TColor::None)
Sets the background color of the rich edit control.
bool HasSelection() const
Returns true if the rich edit control has an active selection.
auto GetLineFromPos(int charPos) const -> int override
void HideSelection(bool hide, bool changeStyle)
Shows or hides the selection in the rich edit control.
void SetTextMode(int mode)
int GetLangOptions() const
bool GetOleInterface(IRichEditOle *&) const
ulong StreamIn(uint format, TEditStream &)
#define PRECONDITION(condition)
uint EvGetDlgCode(const MSG *msg)
The default message handler for WM_GETDLGCODE.
#define CONST_CAST(targetType, object)
bool ReadFromStream(tistream &, uint format=SF_RTF)
< String-aware overload
void CeEditPaste(TCommandEnabler &commandHandler)
tstring LoadString(uint id) const
TCharRange encapsulates the CHARRANGE structure, which specifies a range of characters in a rich edit...
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Class wrapper for management of color values.
Represents a half-open range of positions in the edit control, e.g.
bool IsClipboardFormatAvailable(uint format) const
Indicates if the format specified in format exists for use in the Clipboard.
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
TFindText encapsulates the FINDTEXT structure, which contains information about text to search for in...
DWORD CALLBACK RichEditStrmOutWithOstream(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
auto Transfer(void *buffer, TTransferDirection) -> uint override
TRichEdit encapsulates a rich edit control, a window in which a user can enter, edit and format text.
bool DisplayBand(TRect &)
Object Windows Library (OWLNext Core)
bool SetCharFormat(const TCharFormat &, uint flags=SCF_SELECTION)
Sets the character formatting of a rich edit control.
bool ToggleCharAttribute(ulong mask, uint32 effects)
Toggles a set of character attributes.
int GetWindowTextLength() const
Returns the length, in characters, of the specified window's title.
WPARAM TParam1
First parameter type.
void CeEditClear(TCommandEnabler &commandHandler)
@ No
The whole selection has the attribute.
void EvChar(uint key, uint repeatCount, uint flags)
WM_CHAR handler to bypass TEdit's handler (which caters to validators).
auto Read(LPCTSTR fileName=nullptr) -> bool override
bool SetOleInterface(IRichEditOleCallback *)
void EvKillFocus(HWND hWndGetFocus)
WM_KILLFOCUS handler to bypass TEdit's handler (which caters to validators).
int SetSelRange(const TCharRange &)
Selects a range of characters in the rich edit control.
TTextRange encapsulates the TEXTRANGE structure, which contains information about a range of text in ...
void EvSetFocus(HWND hWndLostFocus)
WM_SETFOCUS handler to bypass TEdit's handler (which caters to validators).
void WriteBaseObject(Base *base, opstream &out)
#define EV_COMMAND_ENABLE(id, method)
Response table entry for enabling a command.
void ReadBaseObject(Base *base, ipstream &in)
#define WARN(condition, message)
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
HWND THandle
TWindow encapsulates an HWND.
bool WriteToStream(tostream &, uint format=SF_RTF)
The clipboard class encapsulates the methods for the clipboard object of Windows.
const tchar RichEdit20DllName[]
int GetTextLength() const
bool CanPaste(uint format) const
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
TRect is a mathematical class derived from tagRect.