Article View: borland.public.cppbuilder.nativeapi
Article #15436TRichEdit.. RichEdit... WordBreaks, EM_SETWORDBREAKPROC, and the rest....
From: ferran
Date: Sun, 06 Jul 2003 14:14
Date: Sun, 06 Jul 2003 14:14
104 lines
4244 bytes
4244 bytes
I'm creating a TRichEdit descendant that needs a better wordbreak
handler, this is for when the user double clicks a word more than
wrapping. I got so far the next code, but it works quite weird, for
example I'm never able to get selected the first word of the first
line on double click. Does any body see any problem in this code?
and/or has successfully implemented a working version of the Callback?
I know about the two MSDN examples but both are wrong (I already tried
them and found other people seen that they are wrong), I found the
example for Delphi in Borland's website, but is just a basic example
with no word selection at all based on delimiters, etc.
I'm sure you may think is easy, but give it a try, you'll be surprise
how strange works this callback.
//------------------------------------------------------------------------------
// Callback Declaration
int CALLBACK WordBreak(LPTSTR Source, int Index, int TotalChars, int Action);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Description: Replace the Richedit built in Wordbreak function
for ours
// Parameters: none
// Return: none
//------------------------------------------------------------------------------
void __fastcall TRichEditEx::CreateWnd()
{
TRichEdit::CreateWnd();
this->Perform(EM_SETWORDBREAKPROC,0,(LPARAM)(EDITWORDBREAKPROC)WordBreak);
}
//-----------------------------------------------------------------------------
// Description: WordBreak Richedit Callback
// Parameters: Source - Pointer to the text of the edit control
// Index - Scan start point
// TotalChars - Total number of characters in the control
// Action - Action requested by the callback
// Return: See Win32 docoumentation
//------------------------------------------------------------------------------
int CALLBACK WordBreak(LPTSTR Source, int Index, int TotalChars, int
Action)
{
const char* ccDelimiters = " +-*/()[]{}=><\t\n\r\0";
switch (Action)
{
case WB_ISDELIMITER:
return IsDelimiter(ccDelimiters, Source, Index);
case WB_CLASSIFY:
if (IsDelimiter(" \t", Source, Index) == true)
return WBF_ISWHITE;
if (IsDelimiter("\r\n", Source, Index) == true)
return WBF_BREAKLINE + 1;
if (IsDelimiter(ccDelimiters, Source, Index) == true)
return WBF_BREAKAFTER + 1;
break;
case WB_LEFT:
case WB_LEFTBREAK:
case WB_MOVEWORDLEFT:
Index--;
for (;Index >= 0; Index--)
{
if (AnsiStrScan(ccDelimiters, Source [Index - 1]) != NULL)
break;
}
if (Index > TotalChars)
Index = TotalChars;
if (Index <= 0)
Index = 0;
return Index;
case WB_RIGHT:
case WB_RIGHTBREAK:
case WB_MOVEWORDRIGHT:
for (; Index <= TotalChars; Index++)
{
if (AnsiStrScan(ccDelimiters, Source [Index + 1]) != NULL)
break;
}
if (Index > TotalChars)
Index = TotalChars;
if (Index <= 0)
Index = 0;
return Index;
}
return 0;
}
Technical Details
Message-ID:
<53c5c460.0307060614.562d02a6@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,f38c05a5eab08856,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-06 07:14:20 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: ferran9@yahoo.com (ferran) Newsgroups: borland.public.cppbuilder.nativeapi Subject: TRichEdit.. RichEdit... WordBreaks, EM_SETWORDBREAKPROC, and the rest.... Date: 6 Jul 2003 07:14:19 -0700 Organization: http://groups.google.com/ Lines: 104 Message-ID: <53c5c460.0307060614.562d02a6@posting.google.com> NNTP-Posting-Host: 62.30.183.191 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1057500859 17534 127.0.0.1 (6 Jul 2003 14:14:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 6 Jul 2003 14:14:19 GMT