From da9be87c615519b096cae3362897c21b55409596 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Wed, 17 Jun 2009 06:07:10 +0000 Subject: [PATCH] * finished getstylerange win32 implementation (yet, too slow) * fixed getstylerange test git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@851 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../richmemo/samples/testsimple/project1.lpi | 176 +++++++++--------- .../richmemo/samples/testsimple/unit1.lfm | 16 +- .../richmemo/samples/testsimple/unit1.lrs | 45 ++--- .../richmemo/samples/testsimple/unit1.pas | 2 +- .../richmemo/win32/win32richmemoproc.pas | 50 ++++- 5 files changed, 168 insertions(+), 121 deletions(-) diff --git a/components/richmemo/samples/testsimple/project1.lpi b/components/richmemo/samples/testsimple/project1.lpi index 04f617c3c..c67f0c692 100644 --- a/components/richmemo/samples/testsimple/project1.lpi +++ b/components/richmemo/samples/testsimple/project1.lpi @@ -6,7 +6,7 @@ - + @@ -32,14 +32,16 @@ - + - - - + + + + + @@ -47,10 +49,10 @@ - - + + - + @@ -135,7 +137,7 @@ - + @@ -190,7 +192,7 @@ - + @@ -238,17 +240,17 @@ - - + + - - - + + + @@ -292,7 +294,7 @@ - + @@ -317,19 +319,19 @@ - - - - + + + + - - - - + + + + @@ -338,10 +340,10 @@ - - - - + + + + @@ -351,147 +353,149 @@ - - + + - - - - + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + diff --git a/components/richmemo/samples/testsimple/unit1.lfm b/components/richmemo/samples/testsimple/unit1.lfm index 90070bc92..4954267d4 100644 --- a/components/richmemo/samples/testsimple/unit1.lfm +++ b/components/richmemo/samples/testsimple/unit1.lfm @@ -10,8 +10,8 @@ object Form1: TForm1 OnCreate = FormCreate LCLVersion = '0.9.27' object RichMemo1: TRichMemo - Left = 16 - Height = 366 + Left = 15 + Height = 358 Top = 16 Width = 619 Anchors = [akTop, akLeft, akRight, akBottom] @@ -34,6 +34,7 @@ object Form1: TForm1 Caption = 'Make Bold and Red' OnClick = Button1Click TabOrder = 1 + TabStop = False end object Button2: TButton Left = 192 @@ -44,6 +45,7 @@ object Form1: TForm1 Caption = 'Get Attribs' OnClick = Button2Click TabOrder = 2 + TabStop = False end object Button3: TButton Left = 304 @@ -54,6 +56,7 @@ object Form1: TForm1 Caption = 'Select Font' OnClick = Button3Click TabOrder = 3 + TabStop = False end object Button4: TButton Left = 528 @@ -64,6 +67,7 @@ object Form1: TForm1 Caption = 'Save RTF' OnClick = Button4Click TabOrder = 4 + TabStop = False end object Button5: TButton Left = 440 @@ -74,6 +78,7 @@ object Form1: TForm1 Caption = 'Load RTF' OnClick = Button5Click TabOrder = 5 + TabStop = False end object Button6: TButton Left = 24 @@ -84,24 +89,25 @@ object Form1: TForm1 Caption = 'Next Style Range' OnClick = Button6Click TabOrder = 6 + TabStop = False end object FontDialog1: TFontDialog MinFontSize = 0 MaxFontSize = 0 left = 352 - top = 552 + top = 429 end object SaveDialog1: TSaveDialog DefaultExt = '.rtf' Filter = 'RichText file (*.rtf)|*.rtf' Options = [ofOverwritePrompt, ofEnableSizing, ofViewDetail] left = 280 - top = 552 + top = 429 end object OpenDialog1: TOpenDialog DefaultExt = '.rtf' Filter = 'RichText file (*.rtf)|*.rtf' left = 208 - top = 552 + top = 429 end end diff --git a/components/richmemo/samples/testsimple/unit1.lrs b/components/richmemo/samples/testsimple/unit1.lrs index 31459c3ed..eb58f889a 100644 --- a/components/richmemo/samples/testsimple/unit1.lrs +++ b/components/richmemo/samples/testsimple/unit1.lrs @@ -4,31 +4,32 @@ LazarusResources.Add('TForm1','FORMDATA',[ 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#196#0#6'Height'#3#201#1#3'Top'#3#181#0#5 +'Width'#3'z'#2#13'ActiveControl'#7#9'RichMemo1'#7'Caption'#6#5'Form1'#12'Cli' +'entHeight'#3#201#1#11'ClientWidth'#3'z'#2#8'OnCreate'#7#10'FormCreate'#10'L' - +'CLVersion'#6#6'0.9.27'#0#9'TRichMemo'#9'RichMemo1'#4'Left'#2#16#6'Height'#3 - +'n'#1#3'Top'#2#16#5'Width'#3'k'#2#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight' + +'CLVersion'#6#6'0.9.27'#0#9'TRichMemo'#9'RichMemo1'#4'Left'#2#15#6'Height'#3 + +'f'#1#3'Top'#2#16#5'Width'#3'k'#2#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight' +#8'akBottom'#0#11'Font.Height'#2#243#9'Font.Name'#6#6'Tahoma'#13'HideSelecti' +'on'#8#13'Lines.Strings'#1#6#9'RichMemo1'#0#10'ParentFont'#8#10'ScrollBars'#7 +#10'ssVertical'#8'TabOrder'#2#0#0#0#7'TButton'#7'Button1'#4'Left'#2#24#6'Hei' +'ght'#2#25#3'Top'#3'~'#1#5'Width'#3#160#0#7'Anchors'#11#6'akLeft'#8'akBottom' +#0#7'Caption'#6#17'Make Bold and Red'#7'OnClick'#7#12'Button1Click'#8'TabOrd' - +'er'#2#1#0#0#7'TButton'#7'Button2'#4'Left'#3#192#0#6'Height'#2#25#3'Top'#3'~' - +#1#5'Width'#2'a'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#11'Get A' - +'ttribs'#7'OnClick'#7#12'Button2Click'#8'TabOrder'#2#2#0#0#7'TButton'#7'Butt' - +'on3'#4'Left'#3'0'#1#6'Height'#2#25#3'Top'#3'~'#1#5'Width'#2'`'#7'Anchors'#11 - +#6'akLeft'#8'akBottom'#0#7'Caption'#6#11'Select Font'#7'OnClick'#7#12'Button' - +'3Click'#8'TabOrder'#2#3#0#0#7'TButton'#7'Button4'#4'Left'#3#16#2#6'Height'#2 - +#25#3'Top'#3'~'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Capt' - +'ion'#6#8'Save RTF'#7'OnClick'#7#12'Button4Click'#8'TabOrder'#2#4#0#0#7'TBut' - +'ton'#7'Button5'#4'Left'#3#184#1#6'Height'#2#25#3'Top'#3'~'#1#5'Width'#2'K'#7 - +'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#8'Load RTF'#7'OnClick'#7#12 - +'Button5Click'#8'TabOrder'#2#5#0#0#7'TButton'#7'Button6'#4'Left'#2#24#6'Heig' - +'ht'#2#25#3'Top'#3#159#1#5'Width'#3#160#0#7'Anchors'#11#6'akLeft'#8'akBottom' - +#0#7'Caption'#6#16'Next Style Range'#7'OnClick'#7#12'Button6Click'#8'TabOrde' - +'r'#2#6#0#0#11'TFontDialog'#11'FontDialog1'#11'MinFontSize'#2#0#11'MaxFontSi' - +'ze'#2#0#4'left'#3'`'#1#3'top'#3'('#2#0#0#11'TSaveDialog'#11'SaveDialog1'#10 - +'DefaultExt'#6#4'.rtf'#6'Filter'#6#27'RichText file (*.rtf)|*.rtf'#7'Options' - +#11#17'ofOverwritePrompt'#14'ofEnableSizing'#12'ofViewDetail'#0#4'left'#3#24 - +#1#3'top'#3'('#2#0#0#11'TOpenDialog'#11'OpenDialog1'#10'DefaultExt'#6#4'.rtf' - +#6'Filter'#6#27'RichText file (*.rtf)|*.rtf'#4'left'#3#208#0#3'top'#3'('#2#0 - +#0#0 + +'er'#2#1#7'TabStop'#8#0#0#7'TButton'#7'Button2'#4'Left'#3#192#0#6'Height'#2 + +#25#3'Top'#3'~'#1#5'Width'#2'a'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Capt' + +'ion'#6#11'Get Attribs'#7'OnClick'#7#12'Button2Click'#8'TabOrder'#2#2#7'TabS' + +'top'#8#0#0#7'TButton'#7'Button3'#4'Left'#3'0'#1#6'Height'#2#25#3'Top'#3'~'#1 + +#5'Width'#2'`'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#11'Select ' + +'Font'#7'OnClick'#7#12'Button3Click'#8'TabOrder'#2#3#7'TabStop'#8#0#0#7'TBut' + +'ton'#7'Button4'#4'Left'#3#16#2#6'Height'#2#25#3'Top'#3'~'#1#5'Width'#2'K'#7 + +'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#8'Save RTF'#7'OnClick'#7#12 + +'Button4Click'#8'TabOrder'#2#4#7'TabStop'#8#0#0#7'TButton'#7'Button5'#4'Left' + +#3#184#1#6'Height'#2#25#3'Top'#3'~'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8 + +'akBottom'#0#7'Caption'#6#8'Load RTF'#7'OnClick'#7#12'Button5Click'#8'TabOrd' + +'er'#2#5#7'TabStop'#8#0#0#7'TButton'#7'Button6'#4'Left'#2#24#6'Height'#2#25#3 + +'Top'#3#159#1#5'Width'#3#160#0#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Capti' + +'on'#6#16'Next Style Range'#7'OnClick'#7#12'Button6Click'#8'TabOrder'#2#6#7 + +'TabStop'#8#0#0#11'TFontDialog'#11'FontDialog1'#11'MinFontSize'#2#0#11'MaxFo' + +'ntSize'#2#0#4'left'#3'`'#1#3'top'#3#173#1#0#0#11'TSaveDialog'#11'SaveDialog' + +'1'#10'DefaultExt'#6#4'.rtf'#6'Filter'#6#27'RichText file (*.rtf)|*.rtf'#7'O' + +'ptions'#11#17'ofOverwritePrompt'#14'ofEnableSizing'#12'ofViewDetail'#0#4'le' + +'ft'#3#24#1#3'top'#3#173#1#0#0#11'TOpenDialog'#11'OpenDialog1'#10'DefaultExt' + +#6#4'.rtf'#6'Filter'#6#27'RichText file (*.rtf)|*.rtf'#4'left'#3#208#0#3'top' + +#3#173#1#0#0#0 ]); diff --git a/components/richmemo/samples/testsimple/unit1.pas b/components/richmemo/samples/testsimple/unit1.pas index c34fdcf3f..d6122f695 100644 --- a/components/richmemo/samples/testsimple/unit1.pas +++ b/components/richmemo/samples/testsimple/unit1.pas @@ -113,7 +113,7 @@ var begin RichMemo1.GetStyleRange( RichMemo1.SelStart, ofs, len ); if (ofs = RichMEmo1.SelStart) and (len = RichMemo1.SelLength) then begin - ofs := ofs + len + 1; + ofs := ofs + len; RichMemo1.GetStyleRange( ofs, ofs, len ); end; RichMemo1.SelStart := ofs; diff --git a/components/richmemo/win32/win32richmemoproc.pas b/components/richmemo/win32/win32richmemoproc.pas index 2428b32db..321f77e35 100644 --- a/components/richmemo/win32/win32richmemoproc.pas +++ b/components/richmemo/win32/win32richmemoproc.pas @@ -172,8 +172,8 @@ var mask : LongWord; textlen : TGETTEXTEX; sel : TCHARRANGE; - rngend : Integer; d : Integer; + last : Integer; const CP_UNICODE = 1200; ALL_MASK = CFM_BOLD or CFM_ITALIC or CFM_STRIKEOUT or CFM_UNDERLINE or @@ -185,6 +185,8 @@ begin textlen.flags := GTL_DEFAULT or GTL_NUMCHARS; textlen.codepage := CP_UNICODE; len := SendMessage(RichEditWnd, EM_GETTEXTLENGTHEX, WPARAM(@textlen), 0); + writeln('TextStart = ', TextStart); + writeln('TextLength = ', len); sel.cpMin := TextStart; sel.cpMax := len; @@ -192,13 +194,31 @@ begin FillChar(fmt, sizeof(fmt), 0); fmt.cbSize := sizeof(fmt); - SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); + + //todo: BOOST PERFORMANCE!!! + sel.cpMax := TextStart; + repeat + inc(sel.cpMax); + SendMessage(RichEditWnd, EM_EXSETSEL, 0, LPARAM(@sel)); + SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); + until (sel.cpMax > len) or ((fmt.dwMask and ALL_MASK) <> ALL_MASK); + + last := sel.cpMax; + sel.cpMin := TextStart; + sel.cpMax := TextStart+1; + repeat + dec(sel.cpMin); + SendMessage(RichEditWnd, EM_EXSETSEL, 0, LPARAM(@sel)); + SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); + until ((fmt.dwMask and ALL_MASK) <> ALL_MASK) or (sel.cpMin < 0); + inc(sel.cpMin); + +{ SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); if fmt.dwMask and ALL_MASK <> ALL_MASK then begin - rngend := len; - d := rngend - sel.cpMin; - sel.cpMax := sel.cpMin + d div 2; + d := (len - sel.cpMin) div 2; + sel.cpMax := sel.cpMin + d; while d > 1 do begin SendMessage(RichEditWnd, EM_EXSETSEL, 0, LPARAM(@sel)); SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); @@ -208,10 +228,26 @@ begin else sel.cpMax := sel.cpMax - d; end; - end; + + if (fmt.dwMask and ALL_MASK) = ALL_MASK then begin + repeat + inc(sel.cpMax); + SendMessage(RichEditWnd, EM_EXSETSEL, 0, LPARAM(@sel)); + SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); + writeln(sel.cpMax, ' ', (fmt.dwMask and ALL_MASK) <> ALL_MASK); + until (sel.cpMax = len) or ((fmt.dwMask and ALL_MASK) <> ALL_MASK); + end else begin + repeat + dec(sel.cpMax); + SendMessage(RichEditWnd, EM_EXSETSEL, 0, LPARAM(@sel)); + SendMessage(RichEditWnd, EM_GETCHARFORMAT, SCF_SELECTION, PtrInt(@fmt)); + until (sel.cpMax <= sel.cpMin) or ((fmt.dwMask and ALL_MASK) = ALL_MASK); + end; + end;} RangeStart := sel.cpMin; - RangeLen := sel.cpMax - sel.cpMin; + RangeLen := last - sel.cpMin - 1; + writeln('Range Start = ', RangeStart, ' Len = ', RangeLen); Result := true; end;