87. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/18/2017 11:37:30 AM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

87.1 Files compared

# Location File Last Modified
1 OSCIF_CPRS v32 Phase 2 Build 2OR3.0405_August_2017.zip\OR_30_405V36_SRC.zip\XE8\Broker\Source XWBRich20.pas Wed Oct 11 20:08:07 2017 UTC
2 OSCIF_CPRS v32 Phase 2 Build 2OR3.0405_August_2017.zip\OR_30_405V36_SRC.zip\XE8\Broker\Source XWBRich20.pas Tue Oct 17 19:58:08 2017 UTC

87.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 3402
Changed 1 2
Inserted 0 0
Removed 0 0

87.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

87.4 Active regular expressions

No regular expressions were active.

87.5 Comparison detail

  1   { ******** ********** ********** ********** ********** ********** ****
  2           Pa ckage: XWB  - Kernel  RPCBroker
  3           Da te Created : Sept 18,  1997 (Ver sion 1.1)
  4           Si te Name: O akland, OI  Field Off ice, Dept  of Veteran  Affairs
  5           De velopers:  PI I
PII
  6           De scription:  Contains  TRPCBroker  and relat ed compone nts.
  7           Un it: XWBRic h20 provid es a RichE dit Compon ent with a bility
  8           to  recognize  a URL wit hin the Ri chEdit con trol.
  9           Cu rrent Rele ase: Versi on 1.1 Pat ch 65
  10   ********** ********** ********** ********** ********** ********** *** }
  11  
  12   { ******** ********** ********** ********** ********** **
  13     Changes  in v1.1.65  (HGW 08/0 5/2015) XW B*1.1*65
  14     1. None.
  15  
  16     Changes  in v1.1.60  (HGW 01/0 7/2014) XW B*1.1*60
  17     1. Symbo l 'AnsiLow erCaseFile Name' is d eprecated,  used Ansi LowerCase  instead
  18     2. Symbo l 'FT_WHOL EWORD' is  deprecated , used Com mDlg.FR_WH OLEWORD in stead
  19     3. Symbo l 'FT_MATC HCASE' is  deprecated , used Com mDlg.FR_MA TCHCASE in stead
  20  
  21     Changes  in v1.1.50  (JLI 09/0 1/2011) XW B*1.1*50
  22     1. None.
  23   ********** ********** ********** ********** **********  }
  24  
  25   //TODO - C urrently u ses Window s Riched20 .dll from  Windows 98  (Rich Edi t 2.0).
  26   //       U pgrade to  Msftedit.d ll (Rich E dit 4.1) t o work wit h 64-bit p latforms.
  27   //TODO - I nvestigate  assembler  code chan ges needed  to work w ith 64-bit  platforms .
  28  
  29   unit XWBRi ch20;
  30  
  31   {: Unit XW BRich20
  32      Based o n the arti cle "Detec t URLS in  the RichEd it Control " by
  33      Elias J . Ongpoy i n 'Delphi  Developer  Newsletter ', May 200 1
  34      which i ncorporate s the func tionality  of the Mic rosoft Ric h Edit
  35      Control  2.0 from  RichEd20.D LL which i ncorporate s the abil ity to
  36      recogni ze a URL w ithin the  RichEdit c ontrol.
  37   }
  38  
  39   interface
  40  
  41   uses
  42     {System}
  43     SysUtils , Classes,  UITypes,  Types,
  44     {WinApi}
  45     Messages , Windows,  RichEdit,  CommDlg,
  46     {Vcl}
  47     Controls , Forms, M enus, Grap hics, StdC trls, Tool Win, ImgLi st, ExtCtr ls, ComCtr ls;
  48  
  49   type
  50     TXWBCust omRichEdit  = class;
  51  
  52     TAttribu teType = ( atSelected , atDefaul tText);
  53     TConsist entAttribu te = (caBo ld, caColo r, caFace,  caItalic,
  54       caSize , caStrike Out, caUnd erline, ca Protected) ;
  55     TConsist entAttribu tes = set  of TConsis tentAttrib ute;
  56  
  57     TXWBText Attributes  = class(T Persistent )
  58     private
  59       RichEd it: TXWBCu stomRichEd it;
  60       FType:  TAttribut eType;
  61       proced ure GetAtt ributes(va r Format:  TCharForma t);
  62       functi on GetChar set: TFont Charset;
  63       functi on GetColo r: TColor;
  64       functi on GetCons istentAttr ibutes: TC onsistentA ttributes;
  65       functi on GetHeig ht: Intege r;
  66       functi on GetName : TFontNam e;
  67       functi on GetPitc h: TFontPi tch;
  68       functi on GetProt ected: Boo lean;
  69       functi on GetSize : Integer;
  70       functi on GetStyl e: TFontSt yles;
  71       proced ure SetAtt ributes(va r Format:  TCharForma t);
  72       proced ure SetCha rset(Value : TFontCha rset);
  73       proced ure SetCol or(Value:  TColor);
  74       proced ure SetHei ght(Value:  Integer);
  75       proced ure SetNam e(Value: T FontName);
  76       proced ure SetPit ch(Value:  TFontPitch );
  77       proced ure SetPro tected(Val ue: Boolea n);
  78       proced ure SetSiz e(Value: I nteger);
  79       proced ure SetSty le(Value:  TFontStyle s);
  80     protecte d
  81       proced ure InitFo rmat(var F ormat: TCh arFormat);
  82       proced ure Assign To(Dest: T Persistent ); overrid e;
  83     public
  84       constr uctor Crea te(AOwner:  TXWBCusto mRichEdit;  Attribute Type: TAtt ributeType );
  85       proced ure Assign (Source: T Persistent ); overrid e;
  86       proper ty Charset : TFontCha rset read  GetCharset  write Set Charset;
  87       proper ty Color:  TColor rea d GetColor  write Set Color;
  88       proper ty Consist entAttribu tes: TCons istentAttr ibutes rea d GetConsi stentAttri butes;
  89       proper ty Name: T FontName r ead GetNam e write Se tName;
  90       proper ty Pitch:  TFontPitch  read GetP itch write  SetPitch;
  91       proper ty Protect ed: Boolea n read Get Protected  write SetP rotected;
  92       proper ty Size: I nteger rea d GetSize  write SetS ize;
  93       proper ty Style:  TFontStyle s read Get Style writ e SetStyle ;
  94       proper ty Height:  Integer r ead GetHei ght write  SetHeight;
  95     end;
  96  
  97   { TParaAtt ributes }
  98  
  99     TNumberi ngStyle =  (nsNone, n sBullet);
  100  
  101     TParaAtt ributes =  class(TPer sistent)
  102     private
  103       RichEd it: TXWBCu stomRichEd it;
  104       proced ure GetAtt ributes(va r Paragrap h: TParaFo rmat);
  105       functi on GetAlig nment: TAl ignment;
  106       functi on GetFirs tIndent: L ongint;
  107       functi on GetLeft Indent: Lo ngint;
  108       functi on GetRigh tIndent: L ongint;
  109       functi on GetNumb ering: TNu mberingSty le;
  110       functi on GetTab( Index: Byt e): Longin t;
  111       functi on GetTabC ount: Inte ger;
  112       proced ure InitPa ra(var Par agraph: TP araFormat) ;
  113       proced ure SetAli gnment(Val ue: TAlign ment);
  114       proced ure SetAtt ributes(va r Paragrap h: TParaFo rmat);
  115       proced ure SetFir stIndent(V alue: Long int);
  116       proced ure SetLef tIndent(Va lue: Longi nt);
  117       proced ure SetRig htIndent(V alue: Long int);
  118       proced ure SetNum bering(Val ue: TNumbe ringStyle) ;
  119       proced ure SetTab (Index: By te; Value:  Longint);
  120       proced ure SetTab Count(Valu e: Integer );
  121     public
  122       constr uctor Crea te(AOwner:  TXWBCusto mRichEdit) ;
  123       proced ure Assign (Source: T Persistent ); overrid e;
  124       proper ty Alignme nt: TAlign ment read  GetAlignme nt write S etAlignmen t;
  125       proper ty FirstIn dent: Long int read G etFirstInd ent write  SetFirstIn dent;
  126       proper ty LeftInd ent: Longi nt read Ge tLeftInden t write Se tLeftInden t;
  127       proper ty Numberi ng: TNumbe ringStyle  read GetNu mbering wr ite SetNum bering;
  128       proper ty RightIn dent: Long int read G etRightInd ent write  SetRightIn dent;
  129       proper ty Tab[Ind ex: Byte]:  Longint r ead GetTab  write Set Tab;
  130       proper ty TabCoun t: Integer  read GetT abCount wr ite SetTab Count;
  131     end;
  132  
  133   { TXWBCust omRichEdit  }
  134  
  135     TRichEdi tResizeEve nt = proce dure(Sende r: TObject ; Rect: TR ect) of ob ject;
  136     TRichEdi tProtectCh ange = pro cedure(Sen der: TObje ct;
  137       StartP os, EndPos : Integer;  var Allow Change: Bo olean) of  object;
  138     TRichEdi tSaveClipb oard = pro cedure(Sen der: TObje ct;
  139       NumObj ects, NumC hars: Inte ger; var S aveClipboa rd: Boolea n) of obje ct;
  140     TSearchT ype = (stW holeWord,  stMatchCas e);
  141     TSearchT ypes = set  of TSearc hType;
  142  
  143     TConvers ion = clas s(TObject)
  144     public
  145       functi on Convert ReadStream (Stream: T Stream; Bu ffer: PCha r; BufSize : Integer) : Integer;  virtual;
  146       functi on Convert WriteStrea m(Stream:  TStream; B uffer: PCh ar; BufSiz e: Integer ): Integer ; virtual;
  147     end;
  148  
  149     TConvers ionClass =  class of  TConversio n;
  150  
  151     PConvers ionFormat  = ^TConver sionFormat ;
  152     TConvers ionFormat  = record
  153       Conver sionClass:  TConversi onClass;
  154       Extens ion: strin g;
  155       Next:  PConversio nFormat;
  156     end;
  157  
  158     PRichEdi tStreamInf o = ^TRich EditStream Info;
  159     TRichEdi tStreamInf o = record
  160       Conver ter: TConv ersion;
  161       Stream : TStream;
  162     end;
  163  
  164     TXWBCust omRichEdit  = class(T CustomMemo )
  165     private
  166       FHideS crollBars:  Boolean;
  167       FSelAt tributes:  TXWBTextAt tributes;
  168       FDefAt tributes:  TXWBTextAt tributes;
  169       FParag raph: TPar aAttribute s;
  170       FOldPa raAlignmen t: TAlignm ent;
  171       FScree nLogPixels : Integer;
  172       FRichE ditStrings : TStrings ;
  173       FMemSt ream: TMem oryStream;
  174       FOnSel Change: TN otifyEvent ;
  175       FHideS election:  Boolean;
  176       FURLDe tect: Bool ean;       // for URL  Detect Pr operty
  177       FModif ied: Boole an;
  178       FDefau ltConverte r: TConver sionClass;
  179       FOnRes izeRequest : TRichEdi tResizeEve nt;
  180       FOnPro tectChange : TRichEdi tProtectCh ange;
  181       FOnSav eClipboard : TRichEdi tSaveClipb oard;
  182       FPageR ect: TRect ;
  183  
  184       proced ure CMBiDi ModeChange d(var Mess age: TMess age); mess age CM_BID IMODECHANG ED;
  185       proced ure CMColo rChanged(v ar Message : TMessage ); message  CM_COLORC HANGED;
  186       proced ure CMFont Changed(va r Message:  TMessage) ; message  CM_FONTCHA NGED;
  187       proced ure CNNoti fy(var Mes sage: TWMN otify); me ssage CN_N OTIFY;
  188       functi on GetPlai nText: Boo lean;
  189       functi on Protect Change(Sta rtPos, End Pos: Integ er): Boole an;
  190       functi on SaveCli pboard(Num Obj, NumCh ars: Integ er): Boole an;
  191       proced ure SetHid eScrollBar s(Value: B oolean);
  192       proced ure SetHid eSelection (Value: Bo olean);
  193       proced ure SetURL Detect(Val ue: boolea n);
  194       proced ure SetPla inText(Val ue: Boolea n);
  195       proced ure SetRic hEditStrin gs(Value:  TStrings);
  196       proced ure SetDef Attributes (Value: TX WBTextAttr ibutes);
  197       proced ure SetSel Attributes (Value: TX WBTextAttr ibutes);
  198       proced ure WMNCDe stroy(var  Message: T WMNCDestro y); messag e WM_NCDES TROY;
  199       proced ure WMSetC ursor(var  Message: T WMSetCurso r); messag e WM_SETCU RSOR;
  200       proced ure WMPain t(var Mess age: TWMPa int); mess age WM_PAI NT;
  201       proced ure WMSetF ont(var Me ssage: TWM SetFont);  message WM _SETFONT;
  202       proced ure WMRBut tonUp(var  Message: T WMRButtonU p); messag e WM_RBUTT ONUP;
  203  
  204     protecte d
  205       proced ure Create Params(var  Params: T CreatePara ms); overr ide;
  206       proced ure Create Wnd; overr ide;
  207       proced ure Destro yWnd; over ride;
  208       proced ure Reques tSize(cons t Rect: TR ect); virt ual;
  209       proced ure Select ionChange;  dynamic;
  210       proced ure DoSetM axLength(V alue: Inte ger); over ride;
  211       functi on GetCare tPos: TPoi nt; overri de;
  212       functi on GetSelL ength: Int eger; over ride;
  213       functi on GetSelS tart: Inte ger; overr ide;
  214       functi on GetSelT ext: strin g; overrid e;
  215       proced ure SetSel Length(Val ue: Intege r); overri de;
  216       proced ure SetSel Start(Valu e: Integer ); overrid e;
  217       proper ty HideSel ection: Bo olean read  FHideSele ction writ e SetHideS election d efault Tru e;
  218       proper ty URLDete ct : boole an read FU RLDetect w rite SetUR LDetect de fault FALS E;
  219       proper ty HideScr ollBars: B oolean rea d FHideScr ollBars
  220         writ e SetHideS crollBars  default Tr ue;
  221       proper ty Lines:  TStrings r ead FRichE ditStrings  write Set RichEditSt rings;
  222       proper ty OnSaveC lipboard:  TRichEditS aveClipboa rd read FO nSaveClipb oard
  223         writ e FOnSaveC lipboard;
  224       proper ty OnSelec tionChange : TNotifyE vent read  FOnSelChan ge write F OnSelChang e;
  225       proper ty OnProte ctChange:  TRichEditP rotectChan ge read FO nProtectCh ange
  226         writ e FOnProte ctChange;
  227       proper ty OnResiz eRequest:  TRichEditR esizeEvent  read FOnR esizeReque st
  228         writ e FOnResiz eRequest;
  229       proper ty PlainTe xt: Boolea n read Get PlainText  write SetP lainText d efault Fal se;
  230  
  231     public
  232       constr uctor Crea te(AOwner:  TComponen t); overri de;
  233       destru ctor Destr oy; overri de;
  234       proced ure Clear;  override;
  235       functi on FindTex t(const Se archStr: s tring;
  236         Star tPos, Leng th: Intege r; Options : TSearchT ypes): Int eger;
  237       functi on GetSelT extBuf(Buf fer: PChar ; BufSize:  Integer):  Integer;  override;
  238       proced ure Print( const Capt ion: strin g); virtua l;
  239       class  procedure  RegisterCo nversionFo rmat(const  AExtensio n: string;
  240         ACon versionCla ss: TConve rsionClass );
  241       proper ty Default Converter:  TConversi onClass
  242         read  FDefaultC onverter w rite FDefa ultConvert er;
  243       proper ty DefAttr ibutes: TX WBTextAttr ibutes rea d FDefAttr ibutes wri te SetDefA ttributes;
  244       proper ty SelAttr ibutes: TX WBTextAttr ibutes rea d FSelAttr ibutes wri te SetSelA ttributes;
  245       proper ty PageRec t: TRect r ead FPageR ect write  FPageRect;
  246       proper ty Paragra ph: TParaA ttributes  read FPara graph;
  247     end;
  248  
  249     TXWBRich Edit = cla ss(TXWBCus tomRichEdi t)
  250     publishe d
  251       proper ty Align;
  252       proper ty Alignme nt;
  253       proper ty Anchors ;
  254       proper ty BiDiMod e;
  255       proper ty BorderS tyle;
  256       proper ty BorderW idth;
  257       proper ty Color;
  258       proper ty Ctl3D;
  259       proper ty DragCur sor;
  260       proper ty DragKin d;
  261       proper ty DragMod e;
  262       proper ty Enabled ;
  263       proper ty Font;
  264       proper ty HideSel ection;
  265       proper ty URLDete ct;             // Ne w URL Dete ct propert y
  266       proper ty HideScr ollBars;
  267       proper ty ImeMode ;
  268       proper ty ImeName ;
  269       proper ty Constra ints;
  270       proper ty Lines;
  271       proper ty MaxLeng th;
  272       proper ty ParentB iDiMode;
  273       proper ty ParentC olor;
  274       proper ty ParentC tl3D;
  275       proper ty ParentF ont;
  276       proper ty ParentS howHint;
  277       proper ty PlainTe xt;
  278       proper ty PopupMe nu;
  279       proper ty ReadOnl y;
  280       proper ty ScrollB ars;
  281       proper ty ShowHin t;
  282       proper ty TabOrde r;
  283       proper ty TabStop  default T rue;
  284  
  285       proper ty Visible ;
  286       proper ty WantTab s;
  287       proper ty WantRet urns;
  288       proper ty WordWra p;
  289       proper ty OnChang e;
  290   //    prop erty OnCon textPopup;
  291       proper ty OnDragD rop;
  292       proper ty OnDragO ver;
  293       proper ty OnEndDo ck;
  294       proper ty OnEndDr ag;
  295       proper ty OnEnter ;
  296       proper ty OnExit;
  297       proper ty OnKeyDo wn;
  298       proper ty OnKeyPr ess;
  299       proper ty OnKeyUp ;
  300       proper ty OnMouse Down;
  301       proper ty OnMouse Move;
  302       proper ty OnMouse Up;
  303       proper ty OnMouse Wheel;
  304       proper ty OnMouse WheelDown;
  305       proper ty OnMouse WheelUp;
  306       proper ty OnProte ctChange;
  307       proper ty OnResiz eRequest;
  308       proper ty OnSaveC lipboard;
  309       proper ty OnSelec tionChange ;
  310       proper ty OnStart Dock;
  311       proper ty OnStart Drag;
  312     end;
  313  
  314   implementa tion
  315  
  316   uses
  317     {WinApi}
  318     ShellAPI ,
  319     {Vcl}
  320     Printers , Consts,  ComStrs, A ctnList, S tdActns;
  321  
  322   type
  323     PFontHan dles = ^TF ontHandles ;
  324     TFontHan dles = rec ord
  325       OurFon t,
  326       StockF ont: Integ er;
  327     end;
  328  
  329     const
  330     SectionS izeArea =  8;
  331     RTFConve rsionForma t: TConver sionFormat  = (
  332       Conver sionClass:  TConversi on;
  333       Extens ion: 'rtf' ;
  334       Next:  nil);
  335     TextConv ersionForm at: TConve rsionForma t = (
  336       Conver sionClass:  TConversi on;
  337       Extens ion: 'txt' ;
  338       Next:  @RTFConver sionFormat );
  339  
  340   var
  341     Conversi onFormatLi st: PConve rsionForma t = @TextC onversionF ormat;
  342     FRichEdi tModule: T Handle;
  343  
  344   { TXWBText Attributes  }
  345  
  346   constructo r TXWBText Attributes .Create(AO wner: TXWB CustomRich Edit;
  347     Attribut eType: TAt tributeTyp e);
  348   begin
  349     inherite d Create;
  350     RichEdit  := AOwner ;
  351     FType :=  Attribute Type;
  352   end;
  353  
  354   procedure  TXWBTextAt tributes.I nitFormat( var Format : TCharFor mat);
  355   begin
  356     FillChar (Format, S izeOf(TCha rFormat),  0);
  357     Format.c bSize := S izeOf(TCha rFormat);
  358   end;
  359  
  360   function T XWBTextAtt ributes.Ge tConsisten tAttribute s: TConsis tentAttrib utes;
  361   var
  362     Format:  TCharForma t;
  363   begin
  364     Result : = [];
  365     if RichE dit.Handle Allocated  and (FType  = atSelec ted) then
  366     begin
  367       InitFo rmat(Forma t);
  368       SendMe ssage(Rich Edit.Handl e, EM_GETC HARFORMAT,
  369         WPAR AM(FType =  atSelecte d), LPARAM (@Format)) ;
  370       with F ormat do
  371       begin
  372         if ( dwMask and  CFM_BOLD)  <> 0 then  Include(R esult, caB old);
  373         if ( dwMask and  CFM_COLOR ) <> 0 the n Include( Result, ca Color);
  374         if ( dwMask and  CFM_FACE)  <> 0 then  Include(R esult, caF ace);
  375         if ( dwMask and  CFM_ITALI C) <> 0 th en Include (Result, c aItalic);
  376         if ( dwMask and  CFM_SIZE)  <> 0 then  Include(R esult, caS ize);
  377         if ( dwMask and  CFM_STRIK EOUT) <> 0  then Incl ude(Result , caStrike Out);
  378         if ( dwMask and  CFM_UNDER LINE) <> 0  then Incl ude(Result , caUnderl ine);
  379         if ( dwMask and  CFM_PROTE CTED) <> 0  then Incl ude(Result , caProtec ted);
  380       end;
  381     end;
  382   end;
  383  
  384   procedure  TXWBTextAt tributes.G etAttribut es(var For mat: TChar Format);
  385   begin
  386     InitForm at(Format) ;
  387     if RichE dit.Handle Allocated  then
  388       SendMe ssage(Rich Edit.Handl e, EM_GETC HARFORMAT,
  389         WPAR AM(FType =  atSelecte d), LPARAM (@Format)) ;
  390   end;
  391  
  392   procedure  TXWBTextAt tributes.S etAttribut es(var For mat: TChar Format);
  393   var
  394     Flag: Lo ngint;
  395   begin
  396     if FType  = atSelec ted then F lag := SCF _SELECTION
  397     else Fla g := 0;
  398     if RichE dit.Handle Allocated  then
  399       SendMe ssage(Rich Edit.Handl e, EM_SETC HARFORMAT,  Flag, LPA RAM(@Forma t))
  400   end;
  401  
  402   function T XWBTextAtt ributes.Ge tCharset:  TFontChars et;
  403   var
  404     Format:  TCharForma t;
  405   begin
  406     GetAttri butes(Form at);
  407     Result : = Format.b Charset;
  408   end;
  409  
  410   procedure  TXWBTextAt tributes.S etCharset( Value: TFo ntCharset) ;
  411   var
  412     Format:  TCharForma t;
  413   begin
  414     InitForm at(Format) ;
  415     with For mat do
  416     begin
  417       dwMask  := CFM_CH ARSET;
  418       bCharS et := Valu e;
  419     end;
  420     SetAttri butes(Form at);
  421   end;
  422  
  423   function T XWBTextAtt ributes.Ge tProtected : Boolean;
  424   var
  425     Format:  TCharForma t;
  426   begin
  427     GetAttri butes(Form at);
  428     with For mat do
  429       if (dw Effects an d CFE_PROT ECTED) <>  0 then
  430         Resu lt := True  else
  431         Resu lt := Fals e;
  432   end;
  433  
  434   procedure  TXWBTextAt tributes.S etProtecte d(Value: B oolean);
  435   var
  436     Format:  TCharForma t;
  437   begin
  438     InitForm at(Format) ;
  439     with For mat do
  440     begin
  441       dwMask  := CFM_PR OTECTED;
  442       if Val ue then dw Effects :=  CFE_PROTE CTED;
  443     end;
  444     SetAttri butes(Form at);
  445   end;
  446  
  447   function T XWBTextAtt ributes.Ge tColor: TC olor;
  448   var
  449     Format:  TCharForma t;
  450   begin
  451     GetAttri butes(Form at);
  452     with For mat do
  453       if (dw Effects an d CFE_AUTO COLOR) <>  0 then
  454         Resu lt := clWi ndowText e lse
  455         Resu lt := crTe xtColor;
  456   end;
  457  
  458   procedure  TXWBTextAt tributes.S etColor(Va lue: TColo r);
  459   var
  460     Format:  TCharForma t;
  461   begin
  462     InitForm at(Format) ;
  463     with For mat do
  464     begin
  465       dwMask  := CFM_CO LOR;
  466       if Val ue = clWin dowText th en
  467         dwEf fects := C FE_AUTOCOL OR else
  468         crTe xtColor :=  ColorToRG B(Value);
  469     end;
  470     SetAttri butes(Form at);
  471   end;
  472  
  473   function T XWBTextAtt ributes.Ge tName: TFo ntName;
  474   var
  475     Format:  TCharForma t;
  476   begin
  477     GetAttri butes(Form at);
  478     Result : = Format.s zFaceName;
  479   end;
  480  
  481   procedure  TXWBTextAt tributes.S etName(Val ue: TFontN ame);
  482   var
  483     Format:  TCharForma t;
  484   begin
  485     InitForm at(Format) ;
  486     with For mat do
  487     begin
  488       dwMask  := CFM_FA CE;
  489       StrPLC opy(szFace Name, Valu e, SizeOf( szFaceName ));
  490     end;
  491     SetAttri butes(Form at);
  492   end;
  493  
  494   function T XWBTextAtt ributes.Ge tStyle: TF ontStyles;
  495   var
  496     Format:  TCharForma t;
  497   begin
  498     Result : = [];
  499     GetAttri butes(Form at);
  500     with For mat do
  501     begin
  502       if (dw Effects an d CFE_BOLD ) <> 0 the n Include( Result, fs Bold);
  503       if (dw Effects an d CFE_ITAL IC) <> 0 t hen Includ e(Result,  fsItalic);
  504       if (dw Effects an d CFE_UNDE RLINE) <>  0 then Inc lude(Resul t, fsUnder line);
  505       if (dw Effects an d CFE_STRI KEOUT) <>  0 then Inc lude(Resul t, fsStrik eOut);
  506     end;
  507   end;
  508  
  509   procedure  TXWBTextAt tributes.S etStyle(Va lue: TFont Styles);
  510   var
  511     Format:  TCharForma t;
  512   begin
  513     InitForm at(Format) ;
  514     with For mat do
  515     begin
  516       dwMask  := CFM_BO LD or CFM_ ITALIC or  CFM_UNDERL INE or CFM _STRIKEOUT ;
  517       if fsB old in Val ue then dw Effects :=  dwEffects  or CFE_BO LD;
  518       if fsI talic in V alue then  dwEffects  := dwEffec ts or CFE_ ITALIC;
  519       if fsU nderline i n Value th en dwEffec ts := dwEf fects or C FE_UNDERLI NE;
  520       if fsS trikeOut i n Value th en dwEffec ts := dwEf fects or C FE_STRIKEO UT;
  521     end;
  522  
  523     SetAttri butes(Form at);
  524   end;
  525  
  526   function T XWBTextAtt ributes.Ge tSize: Int eger;
  527   var
  528     Format:  TCharForma t;
  529   begin
  530     GetAttri butes(Form at);
  531     Result : = Format.y Height div  20;
  532   end;
  533  
  534   procedure  TXWBTextAt tributes.S etSize(Val ue: Intege r);
  535   var
  536     Format:  TCharForma t;
  537   begin
  538     InitForm at(Format) ;
  539     with For mat do
  540     begin
  541       dwMask  := Intege r(CFM_SIZE );
  542       yHeigh t := Value  * 20;
  543     end;
  544     SetAttri butes(Form at);
  545   end;
  546  
  547   function T XWBTextAtt ributes.Ge tHeight: I nteger;
  548   begin
  549     Result : = MulDiv(S ize, RichE dit.FScree nLogPixels , 72);
  550   end;
  551  
  552   procedure  TXWBTextAt tributes.S etHeight(V alue: Inte ger);
  553   begin
  554     Size :=  MulDiv(Val ue, 72, Ri chEdit.FSc reenLogPix els);
  555   end;
  556  
  557   function T XWBTextAtt ributes.Ge tPitch: TF ontPitch;
  558   var
  559     Format:  TCharForma t;
  560   begin
  561     GetAttri butes(Form at);
  562     case (Fo rmat.bPitc hAndFamily  and $03)  of
  563       DEFAUL T_PITCH: R esult := f pDefault;
  564       VARIAB LE_PITCH:  Result :=  fpVariable ;
  565       FIXED_ PITCH: Res ult := fpF ixed;
  566     else
  567       Result  := fpDefa ult;
  568     end;
  569   end;
  570  
  571   procedure  TXWBTextAt tributes.S etPitch(Va lue: TFont Pitch);
  572   var
  573     Format:  TCharForma t;
  574   begin
  575     InitForm at(Format) ;
  576     with For mat do
  577     begin
  578       case V alue of
  579         fpVa riable: Fo rmat.bPitc hAndFamily  := VARIAB LE_PITCH;
  580         fpFi xed: Forma t.bPitchAn dFamily :=  FIXED_PIT CH;
  581       else
  582         Form at.bPitchA ndFamily : = DEFAULT_ PITCH;
  583       end;
  584     end;
  585     SetAttri butes(Form at);
  586   end;
  587  
  588   procedure  TXWBTextAt tributes.A ssign(Sour ce: TPersi stent);
  589   begin
  590     if Sourc e is TFont  then
  591     begin
  592       Color  := TFont(S ource).Col or;
  593       Name : = TFont(So urce).Name ;
  594       Charse t := TFont (Source).C harset;
  595       Style  := TFont(S ource).Sty le;
  596       Size : = TFont(So urce).Size ;
  597       Pitch  := TFont(S ource).Pit ch;
  598     end
  599     else if  Source is  TXWBTextAt tributes t hen
  600     begin
  601       Color  := TXWBTex tAttribute s(Source). Color;
  602       Name : = TXWBText Attributes (Source).N ame;
  603       Charse t := TXWBT extAttribu tes(Source ).Charset;
  604       Style  := TXWBTex tAttribute s(Source). Style;
  605       Pitch  := TXWBTex tAttribute s(Source). Pitch;
  606     end
  607     else inh erited Ass ign(Source );
  608   end;
  609  
  610   procedure  TXWBTextAt tributes.A ssignTo(De st: TPersi stent);
  611   begin
  612     if Dest  is TFont t hen
  613     begin
  614       TFont( Dest).Colo r := Color ;
  615       TFont( Dest).Name  := Name;
  616       TFont( Dest).Char set := Cha rset;
  617       TFont( Dest).Styl e := Style ;
  618       TFont( Dest).Size  := Size;
  619       TFont( Dest).Pitc h := Pitch ;
  620     end
  621     else if  Dest is TX WBTextAttr ibutes the n
  622     begin
  623       TXWBTe xtAttribut es(Dest).C olor := Co lor;
  624       TXWBTe xtAttribut es(Dest).N ame := Nam e;
  625       TXWBTe xtAttribut es(Dest).C harset :=  Charset;
  626       TXWBTe xtAttribut es(Dest).S tyle := St yle;
  627       TXWBTe xtAttribut es(Dest).P itch := Pi tch;
  628     end
  629     else inh erited Ass ignTo(Dest );
  630   end;
  631  
  632   { TParaAtt ributes }
  633  
  634   constructo r TParaAtt ributes.Cr eate(AOwne r: TXWBCus tomRichEdi t);
  635   begin
  636     inherite d Create;
  637     RichEdit  := AOwner ;
  638   end;
  639  
  640   procedure  TParaAttri butes.Init Para(var P aragraph:  TParaForma t);
  641   begin
  642     FillChar (Paragraph , SizeOf(T ParaFormat ), 0);
  643     Paragrap h.cbSize : = SizeOf(T ParaFormat );
  644   end;
  645  
  646   procedure  TParaAttri butes.GetA ttributes( var Paragr aph: TPara Format);
  647   begin
  648     InitPara (Paragraph );
  649     if RichE dit.Handle Allocated  then
  650       SendMe ssage(Rich Edit.Handl e, EM_GETP ARAFORMAT,  0, LPARAM (@Paragrap h));
  651   end;
  652  
  653   procedure  TParaAttri butes.SetA ttributes( var Paragr aph: TPara Format);
  654   begin
  655     RichEdit .HandleNee ded; { we  REALLY nee d the hand le for BiD i }
  656     if RichE dit.Handle Allocated  then
  657     begin
  658       if Ric hEdit.UseR ightToLeft Alignment  then
  659         if P aragraph.w Alignment  = PFA_LEFT  then
  660           Pa ragraph.wA lignment : = PFA_RIGH T
  661         else  if Paragr aph.wAlign ment = PFA _RIGHT the n
  662           Pa ragraph.wA lignment : = PFA_LEFT ;
  663       SendMe ssage(Rich Edit.Handl e, EM_SETP ARAFORMAT,  0, LPARAM (@Paragrap h));
  664     end;
  665   end;
  666  
  667   function T ParaAttrib utes.GetAl ignment: T Alignment;
  668   var
  669     Paragrap h: TParaFo rmat;
  670   begin
  671     GetAttri butes(Para graph);
  672     Result : = TAlignme nt(Paragra ph.wAlignm ent - 1);
  673   end;
  674  
  675   procedure  TParaAttri butes.SetA lignment(V alue: TAli gnment);
  676   var
  677     Paragrap h: TParaFo rmat;
  678   begin
  679     InitPara (Paragraph );
  680     with Par agraph do
  681     begin
  682       dwMask  := PFM_AL IGNMENT;
  683       wAlign ment := Or d(Value) +  1;
  684     end;
  685     SetAttri butes(Para graph);
  686   end;
  687  
  688   function T ParaAttrib utes.GetNu mbering: T NumberingS tyle;
  689   var
  690     Paragrap h: TParaFo rmat;
  691   begin
  692     GetAttri butes(Para graph);
  693     Result : = TNumberi ngStyle(Pa ragraph.wN umbering);
  694   end;
  695  
  696   procedure  TParaAttri butes.SetN umbering(V alue: TNum beringStyl e);
  697   var
  698     Paragrap h: TParaFo rmat;
  699   begin
  700     case Val ue of
  701       nsBull et: if Lef tIndent <  10 then Le ftIndent : = 10;
  702       nsNone : LeftInde nt := 0;
  703     end;
  704     InitPara (Paragraph );
  705     with Par agraph do
  706     begin
  707       dwMask  := PFM_NU MBERING;
  708       wNumbe ring := Or d(Value);
  709     end;
  710     SetAttri butes(Para graph);
  711   end;
  712  
  713   function T ParaAttrib utes.GetFi rstIndent:  Longint;
  714   var
  715     Paragrap h: TParaFo rmat;
  716   begin
  717     GetAttri butes(Para graph);
  718     Result : = Paragrap h.dxStartI ndent div  20
  719   end;
  720  
  721   procedure  TParaAttri butes.SetF irstIndent (Value: Lo ngint);
  722   var
  723     Paragrap h: TParaFo rmat;
  724   begin
  725     InitPara (Paragraph );
  726     with Par agraph do
  727     begin
  728       dwMask  := PFM_ST ARTINDENT;
  729       dxStar tIndent :=  Value * 2 0;
  730     end;
  731     SetAttri butes(Para graph);
  732   end;
  733  
  734   function T ParaAttrib utes.GetLe ftIndent:  Longint;
  735   var
  736     Paragrap h: TParaFo rmat;
  737   begin
  738     GetAttri butes(Para graph);
  739     Result : = Paragrap h.dxOffset  div 20;
  740   end;
  741  
  742   procedure  TParaAttri butes.SetL eftIndent( Value: Lon gint);
  743   var
  744     Paragrap h: TParaFo rmat;
  745   begin
  746     InitPara (Paragraph );
  747     with Par agraph do
  748     begin
  749       dwMask  := PFM_OF FSET;
  750       dxOffs et := Valu e * 20;
  751     end;
  752     SetAttri butes(Para graph);
  753   end;
  754  
  755   function T ParaAttrib utes.GetRi ghtIndent:  Longint;
  756   var
  757     Paragrap h: TParaFo rmat;
  758   begin
  759     GetAttri butes(Para graph);
  760     Result : = Paragrap h.dxRightI ndent div  20;
  761   end;
  762  
  763   procedure  TParaAttri butes.SetR ightIndent (Value: Lo ngint);
  764   var
  765     Paragrap h: TParaFo rmat;
  766   begin
  767     InitPara (Paragraph );
  768     with Par agraph do
  769     begin
  770       dwMask  := PFM_RI GHTINDENT;
  771       dxRigh tIndent :=  Value * 2 0;
  772     end;
  773     SetAttri butes(Para graph);
  774   end;
  775  
  776   function T ParaAttrib utes.GetTa b(Index: B yte): Long int;
  777   var
  778     Paragrap h: TParaFo rmat;
  779   begin
  780     GetAttri butes(Para graph);
  781     Result : = Paragrap h.rgxTabs[ Index] div  20;
  782   end;
  783  
  784   procedure  TParaAttri butes.SetT ab(Index:  Byte; Valu e: Longint );
  785   var
  786     Paragrap h: TParaFo rmat;
  787   begin
  788     GetAttri butes(Para graph);
  789     with Par agraph do
  790     begin
  791       rgxTab s[Index] : = Value *  20;
  792       dwMask  := PFM_TA BSTOPS;
  793       if cTa bCount < I ndex then  cTabCount  := Index;
  794       SetAtt ributes(Pa ragraph);
  795     end;
  796   end;
  797  
  798   function T ParaAttrib utes.GetTa bCount: In teger;
  799   var
  800     Paragrap h: TParaFo rmat;
  801   begin
  802     GetAttri butes(Para graph);
  803     Result : = Paragrap h.cTabCoun t;
  804   end;
  805  
  806   procedure  TParaAttri butes.SetT abCount(Va lue: Integ er);
  807   var
  808     Paragrap h: TParaFo rmat;
  809   begin
  810     GetAttri butes(Para graph);
  811     with Par agraph do
  812     begin
  813       dwMask  := PFM_TA BSTOPS;
  814       cTabCo unt := Val ue;
  815       SetAtt ributes(Pa ragraph);
  816     end;
  817   end;
  818  
  819   procedure  TParaAttri butes.Assi gn(Source:  TPersiste nt);
  820   var
  821     I: Integ er;
  822   begin
  823     if Sourc e is TPara Attributes  then
  824     begin
  825       Alignm ent := TPa raAttribut es(Source) .Alignment ;
  826       FirstI ndent := T ParaAttrib utes(Sourc e).FirstIn dent;
  827       LeftIn dent := TP araAttribu tes(Source ).LeftInde nt;
  828       RightI ndent := T ParaAttrib utes(Sourc e).RightIn dent;
  829       Number ing := TPa raAttribut es(Source) .Numbering ;
  830       for I  := 0 to MA X_TAB_STOP S - 1 do
  831         Tab[ I] := TPar aAttribute s(Source). Tab[I];
  832     end
  833     else inh erited Ass ign(Source );
  834   end;
  835  
  836   { TConvers ion }
  837  
  838   function T Conversion .ConvertRe adStream(S tream: TSt ream; Buff er: PChar;  BufSize:  Integer):  Integer;
  839   begin
  840     Result : = Stream.R ead(Buffer ^, BufSize );
  841   end;
  842  
  843   function T Conversion .ConvertWr iteStream( Stream: TS tream; Buf fer: PChar ; BufSize:  Integer):  Integer;
  844   begin
  845     Result : = Stream.W rite(Buffe r^, BufSiz e);
  846   end;
  847  
  848   { TRichEdi tStrings }
  849  
  850   const
  851     ReadErro r = $0001;
  852     WriteErr or = $0002 ;
  853     NoError  = $0000;
  854  
  855   type
  856     TSelecti on = recor d
  857       StartP os, EndPos : Integer;
  858     end;
  859  
  860     TRichEdi tStrings =  class(TSt rings)
  861     private
  862       RichEd it: TXWBCu stomRichEd it;
  863       FPlain Text: Bool ean;
  864       FConve rter: TCon version;
  865       proced ure Enable Change(con st Value:  Boolean);
  866     protecte d
  867       functi on Get(Ind ex: Intege r): string ; override ;
  868       functi on GetCoun t: Integer ; override ;
  869       proced ure Put(In dex: Integ er; const  S: string) ; override ;
  870       proced ure SetUpd ateState(U pdating: B oolean); o verride;
  871       proced ure SetTex tStr(const  Value: st ring); ove rride;
  872     public
  873       destru ctor Destr oy; overri de;
  874       proced ure Clear;  override;
  875       proced ure AddStr ings(Strin gs: TStrin gs); overr ide;
  876       proced ure Delete (Index: In teger); ov erride;
  877       proced ure Insert (Index: In teger; con st S: stri ng); overr ide;
  878       proced ure LoadFr omFile(con st FileNam e: string) ; override ;
  879       proced ure LoadFr omStream(S tream: TSt ream); ove rride;
  880       proced ure SaveTo File(const  FileName:  string);  override;
  881       proced ure SaveTo Stream(Str eam: TStre am); overr ide;
  882       proper ty PlainTe xt: Boolea n read FPl ainText wr ite FPlain Text;
  883     end;
  884  
  885   destructor  TRichEdit Strings.De stroy;
  886   begin
  887     FConvert er.Free;
  888     inherite d Destroy;
  889   end;
  890  
  891   procedure  TRichEditS trings.Add Strings(St rings: TSt rings);
  892   var
  893     SelChang e: TNotify Event;
  894   begin
  895     SelChang e := RichE dit.OnSele ctionChang e;
  896     RichEdit .OnSelecti onChange : = nil;
  897     try
  898       inheri ted AddStr ings(Strin gs);
  899     finally
  900       RichEd it.OnSelec tionChange  := SelCha nge;
  901     end;
  902   end;
  903  
  904   function T RichEditSt rings.GetC ount: Inte ger;
  905   begin
  906     Result : = SendMess age(RichEd it.Handle,  EM_GETLIN ECOUNT, 0,  0);
  907     if SendM essage(Ric hEdit.Hand le, EM_LIN ELENGTH, S endMessage (RichEdit. Handle,
  908       EM_LIN EINDEX, Re sult - 1,  0), 0) = 0  then Dec( Result);
  909   end;
  910  
  911   function T RichEditSt rings.Get( Index: Int eger): str ing;
  912   var
  913     Text: ar ray[0..409 5] of Char ;
  914     L: Integ er;
  915   begin
  916     Word((@T ext)^) :=  SizeOf(Tex t);
  917     L := Sen dMessage(R ichEdit.Ha ndle, EM_G ETLINE, In dex, Longi nt(@Text)) ;
  918     if (Text [L - 2] =  #13) and ( Text[L - 1 ] = #10) t hen Dec(L,  2);
  919     SetStrin g(Result,  Text, L);
  920   end;
  921  
  922   procedure  TRichEditS trings.Put (Index: In teger; con st S: stri ng);
  923   var
  924     Selectio n: TCharRa nge;
  925   begin
  926     if Index  >= 0 then
  927     begin
  928       Select ion.cpMin  := SendMes sage(RichE dit.Handle , EM_LINEI NDEX, Inde x, 0);
  929       if Sel ection.cpM in <> -1 t hen
  930       begin
  931         Sele ction.cpMa x := Selec tion.cpMin  +
  932           Se ndMessage( RichEdit.H andle, EM_ LINELENGTH , Selectio n.cpMin, 0 );
  933         Send Message(Ri chEdit.Han dle, EM_EX SETSEL, 0,  Longint(@ Selection) );
  934         Send Message(Ri chEdit.Han dle, EM_RE PLACESEL,  0, Longint (PChar(S)) );
  935       end;
  936     end;
  937   end;
  938  
  939   procedure  TRichEditS trings.Ins ert(Index:  Integer;  const S: s tring);
  940   var
  941     L: Integ er;
  942     Selectio n: TCharRa nge;
  943     Fmt: PCh ar;
  944     Str: str ing;
  945   begin
  946     if Index  >= 0 then
  947     begin
  948       Select ion.cpMin  := SendMes sage(RichE dit.Handle , EM_LINEI NDEX, Inde x, 0);
  949       if Sel ection.cpM in >= 0 th en Fmt :=  '%s'#13#10
  950       else b egin
  951         Sele ction.cpMi n :=
  952           Se ndMessage( RichEdit.H andle, EM_ LINEINDEX,  Index - 1 , 0);
  953         if S election.c pMin < 0 t hen Exit;
  954         L :=  SendMessa ge(RichEdi t.Handle,  EM_LINELEN GTH, Selec tion.cpMin , 0);
  955         if L  = 0 then  Exit;
  956         Inc( Selection. cpMin, L);
  957         Fmt  := #13#10' %s';
  958       end;
  959  
  960       Select ion.cpMax  := Selecti on.cpMin;
  961       SendMe ssage(Rich Edit.Handl e, EM_EXSE TSEL, 0, L ongint(@Se lection));
  962  
  963       Str :=  Format(Fm t, [S]);
  964       SendMe ssage(Rich Edit.Handl e, EM_REPL ACESEL, 0,  LongInt(P Char(Str)) );
  965   {
  966       if Ric hEdit.SelS tart <> (S election.c pMax + Len gth(Str))  then
  967         rais e EOutOfRe sources.Cr eate(sRich EditInsert Error);
  968   }
  969     end;
  970   end;
  971  
  972   procedure  TRichEditS trings.Del ete(Index:  Integer);
  973   const
  974     Empty: P Char = '';
  975   var
  976     Selectio n: TCharRa nge;
  977   begin
  978     if Index  < 0 then  Exit;
  979     Selectio n.cpMin :=  SendMessa ge(RichEdi t.Handle,  EM_LINEIND EX, Index,  0);
  980     if Selec tion.cpMin  <> -1 the n
  981     begin
  982       Select ion.cpMax  := SendMes sage(RichE dit.Handle , EM_LINEI NDEX, Inde x + 1, 0);
  983       if Sel ection.cpM ax = -1 th en
  984         Sele ction.cpMa x := Selec tion.cpMin  +
  985           Se ndMessage( RichEdit.H andle, EM_ LINELENGTH , Selectio n.cpMin, 0 );
  986       SendMe ssage(Rich Edit.Handl e, EM_EXSE TSEL, 0, L ongint(@Se lection));
  987       SendMe ssage(Rich Edit.Handl e, EM_REPL ACESEL, 0,  Longint(E mpty));
  988     end;
  989   end;
  990  
  991   procedure  TRichEditS trings.Cle ar;
  992   begin
  993     RichEdit .Clear;
  994   end;
  995  
  996   procedure  TRichEditS trings.Set UpdateStat e(Updating : Boolean) ;
  997   begin
  998     if RichE dit.Showin g then
  999       SendMe ssage(Rich Edit.Handl e, WM_SETR EDRAW, Ord (not Updat ing), 0);
  1000     if not U pdating th en begin
  1001       RichEd it.Refresh ;
  1002       RichEd it.Perform (CM_TEXTCH ANGED, 0,  0);
  1003     end;
  1004   end;
  1005  
  1006   procedure  TRichEditS trings.Ena bleChange( const Valu e: Boolean );
  1007   var
  1008     EventMas k: Longint ;
  1009   begin
  1010     with Ric hEdit do
  1011     begin
  1012       if Val ue then
  1013         Even tMask := S endMessage (Handle, E M_GETEVENT MASK, 0, 0 ) or ENM_C HANGE
  1014       else
  1015         Even tMask := S endMessage (Handle, E M_GETEVENT MASK, 0, 0 ) and not  ENM_CHANGE ;
  1016       SendMe ssage(Hand le, EM_SET EVENTMASK,  0, EventM ask);
  1017     end;
  1018   end;
  1019  
  1020   procedure  TRichEditS trings.Set TextStr(co nst Value:  string);
  1021   begin
  1022     EnableCh ange(False );
  1023     try
  1024       inheri ted SetTex tStr(Value );
  1025     finally
  1026       Enable Change(Tru e);
  1027     end;
  1028   end;
  1029  
  1030   function A djustLineB reaks(Dest , Source:  PChar): In teger; ass embler;
  1031   asm
  1032           PU SH    ESI
  1033           PU SH    EDI
  1034           MO V     EDI, EAX
  1035           MO V     ESI, EDX
  1036           MO V     EDX, EAX
  1037           CL D
  1038   @@1:    LO DSB
  1039   @@2:    OR       AL,A L
  1040           JE       @@4
  1041           CM P     AL,0 AH
  1042           JE       @@3
  1043           ST OSB
  1044           CM P     AL,0 DH
  1045           JN E     @@1
  1046           MO V     AL,0 AH
  1047           ST OSB
  1048           LO DSB
  1049           CM P     AL,0 AH
  1050           JE       @@1
  1051           JM P     @@2
  1052   @@3:    MO V     EAX, 0A0DH
  1053           ST OSW
  1054           JM P     @@1
  1055   @@4:    ST OSB
  1056           LE A     EAX, [EDI-1]
  1057           SU B     EAX, EDX
  1058           PO P     EDI
  1059           PO P     ESI
  1060   end;
  1061  
  1062   function S treamSave( dwCookie:  Longint; p bBuff: PBy te;
  1063     cb: Long int; var p cb: Longin t): Longin t; stdcall ;
  1064   var
  1065     StreamIn fo: PRichE ditStreamI nfo;
  1066   begin
  1067     Result : = NoError;
  1068     StreamIn fo := PRic hEditStrea mInfo(Poin ter(dwCook ie));
  1069     try
  1070       pcb :=  0;
  1071       if Str eamInfo^.C onverter < > nil then
  1072         pcb  := StreamI nfo^.Conve rter.Conve rtWriteStr eam(Stream Info^.Stre am, PChar( pbBuff), c b);
  1073     except
  1074       Result  := WriteE rror;
  1075     end;
  1076   end;
  1077  
  1078   function S treamLoad( dwCookie:  Longint; p bBuff: PBy te;
  1079     cb: Long int; var p cb: Longin t): Longin t; stdcall ;
  1080   var
  1081     Buffer,  pBuff: PCh ar;
  1082     StreamIn fo: PRichE ditStreamI nfo;
  1083   begin
  1084     Result : = NoError;
  1085     StreamIn fo := PRic hEditStrea mInfo(Poin ter(dwCook ie));
  1086     Buffer : = StrAlloc (cb + 1);
  1087     try
  1088       cb :=  cb div 2;
  1089       pcb :=  0;
  1090       pBuff  := Buffer  + cb;
  1091       try
  1092         if S treamInfo^ .Converter  <> nil th en
  1093           pc b := Strea mInfo^.Con verter.Con vertReadSt ream(Strea mInfo^.Str eam, pBuff , cb);
  1094         if p cb > 0 the n
  1095         begi n
  1096           pB uff[pcb] : = #0;
  1097           if  pBuff[pcb  - 1] = #1 3 then pBu ff[pcb - 1 ] := #0;
  1098           pc b := Adjus tLineBreak s(Buffer,  pBuff);
  1099           Mo ve(Buffer^ , pbBuff^,  pcb);
  1100         end;
  1101       except
  1102         Resu lt := Read Error;
  1103       end;
  1104     finally
  1105       StrDis pose(Buffe r);
  1106     end;
  1107   end;
  1108  
  1109   procedure  TRichEditS trings.Loa dFromStrea m(Stream:  TStream);
  1110   var
  1111     EditStre am: TEditS tream;
  1112     Position : Longint;
  1113     TextType : Longint;
  1114     StreamIn fo: TRichE ditStreamI nfo;
  1115     Converte r: TConver sion;
  1116   begin
  1117     StreamIn fo.Stream  := Stream;
  1118     if FConv erter <> n il then Co nverter :=  FConverte r
  1119     else Con verter :=  RichEdit.D efaultConv erter.Crea te;
  1120     StreamIn fo.Convert er := Conv erter;
  1121     try
  1122       with E ditStream  do
  1123       begin
  1124         dwCo okie := Lo ngInt(Poin ter(@Strea mInfo));
  1125         pfnC allBack :=  @StreamLo ad;
  1126         dwEr ror := 0;
  1127       end;
  1128       Positi on := Stre am.Positio n;
  1129  
  1130       if Pla inText the n TextType  := SF_TEX T
  1131       else T extType :=  SF_RTF;
  1132       SendMe ssage(Rich Edit.Handl e, EM_STRE AMIN, Text Type, Long int(@EditS tream));
  1133  
  1134       if (Te xtType = S F_RTF) and  (EditStre am.dwError  <> 0) the n
  1135       begin
  1136         Stre am.Positio n := Posit ion;
  1137         if P lainText t hen TextTy pe := SF_R TF
  1138         else  TextType  := SF_TEXT ;
  1139         Send Message(Ri chEdit.Han dle, EM_ST REAMIN, Te xtType, Lo ngint(@Edi tStream));
  1140         if E ditStream. dwError <>  0 then
  1141           ra ise EOutOf Resources. Create(sRi chEditLoad Fail);
  1142       end;
  1143  
  1144     finally
  1145       if FCo nverter =  nil then C onverter.F ree;
  1146     end;
  1147   end;
  1148  
  1149   procedure  TRichEditS trings.Sav eToStream( Stream: TS tream);
  1150   var
  1151     EditStre am: TEditS tream;
  1152     TextType : Longint;
  1153     StreamIn fo: TRichE ditStreamI nfo;
  1154     Converte r: TConver sion;
  1155   begin
  1156     if FConv erter <> n il then Co nverter :=  FConverte r
  1157     else Con verter :=  RichEdit.D efaultConv erter.Crea te;
  1158     StreamIn fo.Stream  := Stream;
  1159     StreamIn fo.Convert er := Conv erter;
  1160     try
  1161       with E ditStream  do
  1162       begin
  1163         dwCo okie := Lo ngInt(Poin ter(@Strea mInfo));
  1164         pfnC allBack :=  @StreamSa ve;
  1165         dwEr ror := 0;
  1166       end;
  1167       if Pla inText the n TextType  := SF_TEX T
  1168       else T extType :=  SF_RTF;
  1169       SendMe ssage(Rich Edit.Handl e, EM_STRE AMOUT, Tex tType, Lon gint(@Edit Stream));
  1170       if Edi tStream.dw Error <> 0  then
  1171         rais e EOutOfRe sources.Cr eate(sRich EditSaveFa il);
  1172     finally
  1173       if FCo nverter =  nil then C onverter.F ree;
  1174     end;
  1175   end;
  1176  
  1177   procedure  TRichEditS trings.Loa dFromFile( const File Name: stri ng);
  1178   var
  1179     Ext: str ing;
  1180     Convert:  PConversi onFormat;
  1181   begin
  1182     Ext := A nsiLowerCa se(Extract FileExt(Fi lename));  //p60
  1183     System.D elete(Ext,  1, 1);
  1184     Convert  := Convers ionFormatL ist;
  1185     while Co nvert <> n il do
  1186       with C onvert^ do
  1187         if E xtension < > Ext then  Convert : = Next
  1188         else  Break;
  1189     if Conve rt = nil t hen
  1190       Conver t := @Text Conversion Format;
  1191     if FConv erter = ni l then FCo nverter :=  Convert^. Conversion Class.Crea te;
  1192     try
  1193       inheri ted LoadFr omFile(Fil eName);
  1194     except
  1195       FConve rter.Free;
  1196       FConve rter := ni l;
  1197       raise;
  1198     end;
  1199     RichEdit .DoSetMaxL ength($7FF FFFF0);
  1200   end;
  1201  
  1202   procedure  TRichEditS trings.Sav eToFile(co nst FileNa me: string );
  1203   var
  1204     Ext: str ing;
  1205     Convert:  PConversi onFormat;
  1206   begin
  1207     Ext := A nsiLowerCa se(Extract FileExt(Fi lename));  //p60
  1208     System.D elete(Ext,  1, 1);
  1209     Convert  := Convers ionFormatL ist;
  1210     while Co nvert <> n il do
  1211       with C onvert^ do
  1212         if E xtension < > Ext then  Convert : = Next
  1213         else  Break;
  1214     if Conve rt = nil t hen
  1215       Conver t := @Text Conversion Format;
  1216     if FConv erter = ni l then FCo nverter :=  Convert^. Conversion Class.Crea te;
  1217     try
  1218       inheri ted SaveTo File(FileN ame);
  1219     except
  1220       FConve rter.Free;
  1221       FConve rter := ni l;
  1222       raise;
  1223     end;
  1224   end;
  1225  
  1226   { TRichEdi t }
  1227  
  1228   constructo r TXWBCust omRichEdit .Create(AO wner: TCom ponent);
  1229   var
  1230     DC: HDC;
  1231   begin
  1232     inherite d Create(A Owner);
  1233     FSelAttr ibutes :=  TXWBTextAt tributes.C reate(Self , atSelect ed);
  1234     FDefAttr ibutes :=  TXWBTextAt tributes.C reate(Self , atDefaul tText);
  1235     FParagra ph := TPar aAttribute s.Create(S elf);
  1236     FRichEdi tStrings : = TRichEdi tStrings.C reate;
  1237     TRichEdi tStrings(F RichEditSt rings).Ric hEdit := S elf;
  1238     TabStop  := True;
  1239     Width :=  185;
  1240     Height : = 89;
  1241     AutoSize  := False;
  1242     DoubleBu ffered :=  False;
  1243     FHideSel ection :=  True;
  1244     FURLDete ct:= FALSE ;
  1245     HideScro llBars :=  True;
  1246  
  1247     DC := Ge tDC(0);
  1248     FScreenL ogPixels : = GetDevic eCaps(DC,  LOGPIXELSY );
  1249     DefaultC onverter : = TConvers ion;
  1250     ReleaseD C(0, DC);
  1251     FOldPara Alignment  := Alignme nt;
  1252     Perform( CM_PARENTB IDIMODECHA NGED, 0, 0 );
  1253   end;
  1254  
  1255   destructor  TXWBCusto mRichEdit. Destroy;
  1256   begin
  1257     FSelAttr ibutes.Fre e;
  1258     FDefAttr ibutes.Fre e;
  1259     FParagra ph.Free;
  1260     FRichEdi tStrings.F ree;
  1261     FMemStre am.Free;
  1262     inherite d Destroy;
  1263   end;
  1264  
  1265   procedure  TXWBCustom RichEdit.C lear;
  1266   begin
  1267     inherite d Clear;
  1268     Modified  := False;
  1269   end;
  1270  
  1271   procedure  TXWBCustom RichEdit.C reateParam s(var Para ms: TCreat eParams);
  1272   const
  1273   // Use ver sion 2.0 o f RichEdit , previous ly RICHED3 2.DLL
  1274     RichEdit ModuleName  = 'RICHED 20.DLL';
  1275  
  1276     HideScro llBar : ar ray[Boolea n] of DWOR D = (ES_DI SABLENOSCR OLL, 0);
  1277     HideSele ctions: ar ray[Boolea n] of DWOR D = (ES_NO HIDESEL, 0 );
  1278  
  1279   begin
  1280     if FRich EditModule  = 0 then
  1281     begin
  1282       FRichE ditModule  := LoadLib rary(RichE ditModuleN ame);
  1283       if FRi chEditModu le <= HINS TANCE_ERRO R then FRi chEditModu le := 0;
  1284     end;
  1285  
  1286     inherite d CreatePa rams(Param s);
  1287  
  1288   // USE RIC HEDIT_CLAS SA use ANS I version  not Unicod e
  1289     CreateSu bClass(Par ams, RICHE DIT_CLASSA );
  1290  
  1291     with Par ams do
  1292     begin
  1293       Style  := Style o r HideScro llBar[Hide ScrollBars ] or
  1294         Hide Selections [HideSelec tion];
  1295       Window Class.styl e := Windo wClass.sty le and not  (CS_HREDR AW or CS_V REDRAW);
  1296     end;
  1297   end;
  1298  
  1299   procedure  TXWBCustom RichEdit.C reateWnd;
  1300   var
  1301     Plain, D esignMode,  WasModifi ed: Boolea n;
  1302  
  1303   begin
  1304     WasModif ied := inh erited Mod ified;
  1305  
  1306     inherite d CreateWn d;
  1307     if (SysL ocale.FarE ast) and n ot (SysLoc ale.PriLan gID = LANG _JAPANESE)  then
  1308       Font.C harset :=  GetDefFont CharSet;
  1309     SendMess age(Handle , EM_SETEV ENTMASK, 0 ,
  1310       ENM_CH ANGE or EN M_SELCHANG E or ENM_R EQUESTRESI ZE or
  1311       ENM_PR OTECTED or  ENM_LINK) ;      //  Added the  ENM_LINK t o receive  EN_LINK me ssage
  1312  
  1313     SendMess age(Handle , EM_AUTOU RLDETECT,  Ord(FURLDe tect), 0);  // Start  the URL De tect
  1314  
  1315     SendMess age(Handle , EM_SETBK GNDCOLOR,  0, ColorTo RGB(Color) );
  1316     if FMemS tream <> n il then
  1317     begin
  1318       Plain  := PlainTe xt;
  1319       FMemSt ream.ReadB uffer(Desi gnMode, si zeof(Desig nMode));
  1320       PlainT ext := Des ignMode;
  1321       try
  1322         Line s.LoadFrom Stream(FMe mStream);
  1323         FMem Stream.Fre e;
  1324         FMem Stream :=  nil;
  1325       finall y
  1326         Plai nText := P lain;
  1327       end;
  1328     end;
  1329  
  1330     Modified  := WasMod ified;
  1331   end;
  1332  
  1333   procedure  TXWBCustom RichEdit.D estroyWnd;
  1334   var
  1335     Plain, D esignMode:  Boolean;
  1336   begin
  1337     FModifie d := Modif ied;
  1338     FMemStre am := TMem oryStream. Create;
  1339     Plain :=  PlainText ;
  1340     DesignMo de := (csD esigning i n Componen tState);
  1341     PlainTex t := Desig nMode;
  1342     FMemStre am.WriteBu ffer(Desig nMode, siz eof(Design Mode));
  1343     try
  1344       Lines. SaveToStre am(FMemStr eam);
  1345       FMemSt ream.Posit ion := 0;
  1346     finally
  1347       PlainT ext := Pla in;
  1348     end;
  1349  
  1350     inherite d DestroyW nd;
  1351   end;
  1352  
  1353   procedure  TXWBCustom RichEdit.W MNCDestroy (var Messa ge: TWMNCD estroy);
  1354   begin
  1355     inherite d;
  1356   end;
  1357  
  1358   procedure  TXWBCustom RichEdit.W MSetFont(v ar Message : TWMSetFo nt);
  1359   begin
  1360     FDefAttr ibutes.Ass ign(Font);
  1361   end;
  1362  
  1363   procedure  TXWBCustom RichEdit.W MRButtonUp (var Messa ge: TWMRBu ttonUp);
  1364   begin
  1365     // RichE d20 does n ot pass th e WM_RBUTT ONUP messa ge to defw ndproc,
  1366     // so we  get no WM _CONTEXTME NU message .  Simulat e message  here.
  1367     if Win32 MajorVersi on < 5 the n
  1368       Perfor m(WM_CONTE XTMENU, Ha ndle, LPar am(PointTo SmallPoint (
  1369         Clie ntToScreen (SmallPoin tToPoint(M essage.Pos )))));
  1370     inherite d;
  1371   end;
  1372  
  1373   procedure  TXWBCustom RichEdit.C MFontChang ed(var Mes sage: TMes sage);
  1374   begin
  1375     FDefAttr ibutes.Ass ign(Font);
  1376   end;
  1377  
  1378   procedure  TXWBCustom RichEdit.D oSetMaxLen gth(Value:  Integer);
  1379   begin
  1380     SendMess age(Handle , EM_EXLIM ITTEXT, 0,  Value);
  1381   end;
  1382  
  1383   function T XWBCustomR ichEdit.Ge tCaretPos;
  1384   var
  1385     CharRang e: TCharRa nge;
  1386   begin
  1387     SendMess age(Handle , EM_EXGET SEL, 0, Lo ngInt(@Cha rRange));
  1388     Result.X  := CharRa nge.cpMax;
  1389     Result.Y  := SendMe ssage(Hand le, EM_EXL INEFROMCHA R, 0, Resu lt.X);
  1390     Result.X  := Result .X - SendM essage(Han dle, EM_LI NEINDEX, - 1, 0);
  1391   end;
  1392  
  1393   function T XWBCustomR ichEdit.Ge tSelLength : Integer;
  1394   var
  1395     CharRang e: TCharRa nge;
  1396   begin
  1397     SendMess age(Handle , EM_EXGET SEL, 0, Lo ngint(@Cha rRange));
  1398     Result : = CharRang e.cpMax -  CharRange. cpMin;
  1399   end;
  1400  
  1401   function T XWBCustomR ichEdit.Ge tSelStart:  Integer;
  1402   var
  1403     CharRang e: TCharRa nge;
  1404   begin
  1405     SendMess age(Handle , EM_EXGET SEL, 0, Lo ngint(@Cha rRange));
  1406     Result : = CharRang e.cpMin;
  1407   end;
  1408  
  1409   function T XWBCustomR ichEdit.Ge tSelTextBu f(Buffer:  PChar; Buf Size: Inte ger): Inte ger;
  1410   var
  1411     S: strin g;
  1412   begin
  1413     S := Get SelText;
  1414     Result : = Length(S );
  1415     if BufSi ze < Lengt h(S) then  Result :=  BufSize;
  1416     StrPLCop y(Buffer,  S, Result) ;
  1417   end;
  1418  
  1419   function T XWBCustomR ichEdit.Ge tSelText:  string;
  1420   var
  1421     Length:  Integer;
  1422   begin
  1423     SetLengt h(Result,  GetSelLeng th + 1);
  1424     Length : = SendMess age(Handle , EM_GETSE LTEXT, 0,  Longint(PC har(Result )));
  1425     SetLengt h(Result,  Length);
  1426   end;
  1427  
  1428   procedure  TXWBCustom RichEdit.C MBiDiModeC hanged(var  Message:  TMessage);
  1429   var
  1430     AParagra ph: TParaF ormat;
  1431   begin
  1432     HandleNe eded; { we  REALLY ne ed the han dle for Bi Di }
  1433     inherite d;
  1434     Paragrap h.GetAttri butes(APar agraph);
  1435     AParagra ph.dwMask  := PFM_ALI GNMENT;
  1436     AParagra ph.wAlignm ent := Ord (Alignment ) + 1;
  1437     Paragrap h.SetAttri butes(APar agraph);
  1438   end;
  1439  
  1440   procedure  TXWBCustom RichEdit.S etHideScro llBars(Val ue: Boolea n);
  1441   begin
  1442     if HideS crollBars  <> Value t hen
  1443     begin
  1444       FHideS crollBars  := value;
  1445       Recrea teWnd;
  1446     end;
  1447   end;
  1448  
  1449   procedure  TXWBCustom RichEdit.S etHideSele ction(Valu e: Boolean );
  1450   begin
  1451     if HideS election < > Value th en
  1452     begin
  1453       FHideS election : = Value;
  1454       SendMe ssage(Hand le, EM_HID ESELECTION , Ord(Hide Selection) , LongInt( True));
  1455     end;
  1456   end;
  1457  
  1458   procedure  TXWBCustom RichEdit.S etURLDetec t(Value: b oolean);
  1459   begin
  1460    if URLDet ect <> Val ue then
  1461     begin
  1462      FURLDet ect:= Valu e;
  1463      Recreat eWnd;
  1464     end;
  1465   end;
  1466  
  1467   procedure  TXWBCustom RichEdit.S etSelAttri butes(Valu e: TXWBTex tAttribute s);
  1468   begin
  1469     SelAttri butes.Assi gn(Value);
  1470   end;
  1471  
  1472   procedure  TXWBCustom RichEdit.S etSelLengt h(Value: I nteger);
  1473   var
  1474     CharRang e: TCharRa nge;
  1475   begin
  1476     SendMess age(Handle , EM_EXGET SEL, 0, Lo ngint(@Cha rRange));
  1477     CharRang e.cpMax :=  CharRange .cpMin + V alue;
  1478     SendMess age(Handle , EM_EXSET SEL, 0, Lo ngint(@Cha rRange));
  1479     SendMess age(Handle , EM_SCROL LCARET, 0,  0);
  1480   end;
  1481  
  1482   procedure  TXWBCustom RichEdit.S etDefAttri butes(Valu e: TXWBTex tAttribute s);
  1483   begin
  1484     DefAttri butes.Assi gn(Value);
  1485   end;
  1486  
  1487   function T XWBCustomR ichEdit.Ge tPlainText : Boolean;
  1488   begin
  1489     Result : = TRichEdi tStrings(L ines).Plai nText;
  1490   end;
  1491  
  1492   procedure  TXWBCustom RichEdit.S etPlainTex t(Value: B oolean);
  1493   begin
  1494     TRichEdi tStrings(L ines).Plai nText := V alue;
  1495   end;
  1496  
  1497   procedure  TXWBCustom RichEdit.C MColorChan ged(var Me ssage: TMe ssage);
  1498   begin
  1499     inherite d;
  1500     SendMess age(Handle , EM_SETBK GNDCOLOR,  0, ColorTo RGB(Color) )
  1501   end;
  1502  
  1503   procedure  TXWBCustom RichEdit.S etRichEdit Strings(Va lue: TStri ngs);
  1504   begin
  1505     FRichEdi tStrings.A ssign(Valu e);
  1506   end;
  1507  
  1508   procedure  TXWBCustom RichEdit.S etSelStart (Value: In teger);
  1509   var
  1510     CharRang e: TCharRa nge;
  1511   begin
  1512     CharRang e.cpMin :=  Value;
  1513     CharRang e.cpMax :=  Value;
  1514     SendMess age(Handle , EM_EXSET SEL, 0, Lo ngint(@Cha rRange));
  1515   end;
  1516  
  1517   procedure  TXWBCustom RichEdit.P rint(const  Caption:  string);
  1518   var
  1519     Range: T FormatRang e;
  1520     LastChar , MaxLen,  LogX, LogY , OldMap:  Integer;
  1521     SaveRect : TRect;
  1522   begin
  1523     FillChar (Range, Si zeOf(TForm atRange),  0);
  1524     with Pri nter, Rang e do
  1525     begin
  1526       Title  := Caption ;
  1527       BeginD oc;
  1528       hdc :=  Handle;
  1529       hdcTar get := hdc ;
  1530       LogX : = GetDevic eCaps(Hand le, LOGPIX ELSX);
  1531       LogY : = GetDevic eCaps(Hand le, LOGPIX ELSY);
  1532       if IsR ectEmpty(P ageRect) t hen
  1533       begin
  1534         rc.r ight := Pa geWidth *  1440 div L ogX;
  1535         rc.b ottom := P ageHeight  * 1440 div  LogY;
  1536       end
  1537       else b egin
  1538         rc.l eft := Pag eRect.Left  * 1440 di v LogX;
  1539         rc.t op := Page Rect.Top *  1440 div  LogY;
  1540         rc.r ight := Pa geRect.Rig ht * 1440  div LogX;
  1541         rc.b ottom := P ageRect.Bo ttom * 144 0 div LogY ;
  1542       end;
  1543       rcPage  := rc;
  1544       SaveRe ct := rc;
  1545       LastCh ar := 0;
  1546       MaxLen  := GetTex tLen;
  1547       chrg.c pMax := -1 ;
  1548       // ens ure printe r DC is in  text map  mode
  1549       OldMap  := SetMap Mode(hdc,  MM_TEXT);
  1550       SendMe ssage(Self .Handle, E M_FORMATRA NGE, 0, 0) ;    // fl ush buffer
  1551       try
  1552         repe at
  1553           rc  := SaveRe ct;
  1554           ch rg.cpMin : = LastChar ;
  1555           La stChar :=  SendMessag e(Self.Han dle, EM_FO RMATRANGE,  1, Longin t(@Range)) ;
  1556           if  (LastChar  < MaxLen)  and (Last Char <> -1 ) then New Page;
  1557         unti l (LastCha r >= MaxLe n) or (Las tChar = -1 );
  1558         EndD oc;
  1559       finall y
  1560         Send Message(Se lf.Handle,  EM_FORMAT RANGE, 0,  0);  // fl ush buffer
  1561         SetM apMode(hdc , OldMap);        //  restore pr evious map  mode
  1562       end;
  1563     end;
  1564   end;
  1565  
  1566   var
  1567     Painting : Boolean  = False;
  1568  
  1569   procedure  TXWBCustom RichEdit.W MPaint(var  Message:  TWMPaint);
  1570   var
  1571     R, R1: T Rect;
  1572   begin
  1573     if GetUp dateRect(H andle, R,  True) then
  1574     begin
  1575       with C lientRect  do R1 := R ect(Right  - 3, Top,  Right, Bot tom);
  1576       if Int ersectRect (R, R, R1)  then Inva lidateRect (Handle, @ R1, True);
  1577     end;
  1578     if Paint ing then
  1579       Invali date
  1580     else beg in
  1581       Painti ng := True ;
  1582       try
  1583         inhe rited;
  1584       finall y
  1585         Pain ting := Fa lse;
  1586       end;
  1587     end;
  1588   end;
  1589  
  1590   procedure  TXWBCustom RichEdit.W MSetCursor (var Messa ge: TWMSet Cursor);
  1591   var
  1592     P: TPoin t;
  1593   begin
  1594     inherite d;
  1595     if Messa ge.Result  = 0 then
  1596     begin
  1597       Messag e.Result : = 1;
  1598       GetCur sorPos(P);
  1599       with P ointToSmal lPoint(P)  do
  1600         case  Perform(W M_NCHITTES T, 0, Make Long(X, Y) ) of
  1601           HT VSCROLL,
  1602           HT HSCROLL:
  1603              Windows.Se tCursor(Sc reen.Curso rs[crArrow ]);
  1604           HT CLIENT:
  1605              Windows.Se tCursor(Sc reen.Curso rs[crIBeam ]);
  1606         end;
  1607     end;
  1608   end;
  1609  
  1610   procedure  TXWBCustom RichEdit.C NNotify(va r Message:  TWMNotify );
  1611   type
  1612     PENLink  = ^TENLink ;
  1613  
  1614   begin
  1615     with Mes sage do
  1616       case N MHdr^.code  of
  1617         EN_S ELCHANGE:  SelectionC hange;
  1618         EN_R EQUESTRESI ZE: Reques tSize(PReq Size(NMHdr )^.rc);
  1619         EN_S AVECLIPBOA RD:
  1620           wi th PENSave Clipboard( NMHdr)^ do
  1621              if not Sav eClipboard (cObjectCo unt, cch)  then Resul t := 1;
  1622         EN_P ROTECTED:
  1623           wi th PENProt ected(NMHd r)^.chrg d o
  1624              if not Pro tectChange (cpMin, cp Max) then  Result :=  1;
  1625  
  1626   // EN_LINK  message b eing recei ved to res pond to it
  1627         EN_L INK:
  1628          beg in
  1629           Wi ndows.SetC ursor(Scre en.Cursors [crHandPoi nt]);
  1630           if  PEnLink(N MHdr)^.msg  = WM_LBUT TONDOWN th en
  1631              begin
  1632   // set the  selection
  1633                SendMess age(Handle , EM_EXSET SEL, 0, Lo ngint(@PEn Link(NMHdr )^.chrg));
  1634   // send it  to window s to open
  1635                ShellExe cute(handl e, 'open',  PChar(Get SelText),  nil, nil,  SW_SHOWNOR MAL);
  1636              end;
  1637          end ;
  1638       end;
  1639   end;
  1640  
  1641   function T XWBCustomR ichEdit.Sa veClipboar d(NumObj,  NumChars:  Integer):  Boolean;
  1642   begin
  1643     Result : = True;
  1644     if Assig ned(OnSave Clipboard)  then OnSa veClipboar d(Self, Nu mObj, NumC hars, Resu lt);
  1645   end;
  1646  
  1647   function T XWBCustomR ichEdit.Pr otectChang e(StartPos , EndPos:  Integer):  Boolean;
  1648   begin
  1649     Result : = False;
  1650     if Assig ned(OnProt ectChange)  then OnPr otectChang e(Self, St artPos, En dPos, Resu lt);
  1651   end;
  1652  
  1653   procedure  TXWBCustom RichEdit.S electionCh ange;
  1654   begin
  1655     if Assig ned(OnSele ctionChang e) then On SelectionC hange(Self );
  1656   end;
  1657  
  1658   procedure  TXWBCustom RichEdit.R equestSize (const Rec t: TRect);
  1659   begin
  1660     if Assig ned(OnResi zeRequest)  then OnRe sizeReques t(Self, Re ct);
  1661   end;
  1662  
  1663   function T XWBCustomR ichEdit.Fi ndText(con st SearchS tr: string ;
  1664     StartPos , Length:  Integer; O ptions: TS earchTypes ): Integer ;
  1665   var
  1666     Find: TF indText;
  1667     Flags: I nteger;
  1668   begin
  1669     with Fin d.chrg do
  1670     begin
  1671       cpMin  := StartPo s;
  1672       cpMax  := cpMin +  Length;
  1673     end;
  1674     Flags :=  0;
  1675     if stWho leWord in  Options th en Flags : = Flags or  CommDlg.F R_WHOLEWOR D; //p60
  1676     if stMat chCase in  Options th en Flags : = Flags or  CommDlg.F R_MATCHCAS E; //p60
  1677     Find.lps trText :=  PChar(Sear chStr);
  1678     Result : = SendMess age(Handle , EM_FINDT EXT, Flags , LongInt( @Find));
  1679   end;
  1680  
  1681   procedure  AppendConv ersionForm at(const E xt: string ; AClass:  TConversio nClass);
  1682   var
  1683     NewRec:  PConversio nFormat;
  1684   begin
  1685     New(NewR ec);
  1686     with New Rec^ do
  1687     begin
  1688       Extens ion := Ans iLowerCase (Ext); //p 60
  1689       Conver sionClass  := AClass;
  1690       Next : = Conversi onFormatLi st;
  1691     end;
  1692     Conversi onFormatLi st := NewR ec;
  1693   end;
  1694  
  1695   class proc edure TXWB CustomRich Edit.Regis terConvers ionFormat( const AExt ension: st ring;
  1696     AConvers ionClass:  TConversio nClass);
  1697   begin
  1698     AppendCo nversionFo rmat(AExte nsion, ACo nversionCl ass);
  1699   end;
  1700  
  1701   end.
  1702