Solve copy/paste to clipboard on HtlmPort

2011-05-16
2013-04-29
  • iskraelectrica
    iskraelectrica
    2011-05-16

    -- /home/joseluis/proyectos/THtmlPort_20110108/package/htmlview.pas.org 2011-05-16 19:19:28.000000000 +0200
    +++ /home/joseluis/proyectos/THtmlPort_20110108/package/htmlview.pas 2011-05-16 19:15:23.000000000 +0200
    @@ -4371,9 +4371,10 @@
    var
       Leng: integer;
       StSrc, EnSrc: integer;
    -  HTML: string;
    +  HTML, HTML2: string;
       format : UINT;
    -
    +  etiquetas : boolean;
    +
    {$IFNDEF LCL}
       procedure copyFormatToClipBoard(const source: string; format : UINT);
    {$ELSE}  //changed to var to use with AddFormat below
    @@ -4384,9 +4385,17 @@
       var
         gMem: HGLOBAL;
         lp: pchar;
    -  begin
    +  begin
    +
    +  //The particularities of the clipboard are Operating System
    + {$IFNDEF UNIX} //las particularidades del portapapeles son del Sistema Operativo
    +   format := RegisterClipboardFormat('HTML Format');
    + {$ELSE}
    +   format := RegisterClipboardFormat('text/html');
    + {$ENDIF}
         clipboard.Open;
    -    try
    +    try
    +      clipboard.Clear;
    {$IFNDEF LCL}
           //an extra "1" for the null terminator
           gMem := globalalloc(GMEM_DDESHARE + GMEM_MOVEABLE, length(source)+1);
    @@ -4433,14 +4442,20 @@
       StartHTMLIndex := PreliminaryLength + Length(URLString);
       EndHTMLIndex := StartHTMLIndex + Length(HTML);
       StartFragmentIndex := StartHTMLIndex + Pos(StartFrag, HTML) + Length(StartFrag)-1;
    -  EndFragmentIndex := StartHTMLIndex + Pos(EndFrag, HTML)-1;
    +  EndFragmentIndex := StartHTMLIndex + Pos(EndFrag, HTML)-1;

    +  //The particularities of the clipboard are Operating System
    +  //at least ubuntu / Gnome do not need this preamble
    +  {$IFNDEF UNIX} //al menos en ubuntu/Gnome no es necesario este preambulo
       Result := Version +
         SysUtils.Format('%s%.8d', ) + #13#10 +
         SysUtils.Format('%s%.8d', ) + #13#10 +
         SysUtils.Format('%s%.8d', ) + #13#10 +
         SysUtils.Format('%s%.8d', ) + #13#10 +
         URLString + #13#10;
    +  {$ELSE}
    +    Result := ''{#13#10};
    +  {$ENDIF}
       end;

       function Truncate(const S: string): string;
    @@ -4460,19 +4475,19 @@
         L: string;
         C: char;
       begin
    -  L := Lowercase(HTML);
    -  I := Pos(Tag, L);
    -  while (I > 0) do
    -    begin
    -    Delete(HTML, I, Length(Tag));
    -    repeat
    -      if I  <= Length(HTML) then
    -        C := HTML_
    -      else C := #0;
    -      Delete(HTML, I, 1);
    -    until C in ;
         L := Lowercase(HTML);
         I := Pos(Tag, L);
    +  while (I > 0) do
    +    begin
    +      Delete(HTML, I, Length(Tag));
    +      repeat
    +        if I  <= Length(HTML) then
    +          C := HTML
    +        else C := #0;
    +          Delete(HTML, I, 1);
    +      until C in ;
    +      L := Lowercase(HTML);
    +      I := Pos(Tag, L);
         end;
       end;

    @@ -4481,14 +4496,14 @@
         I: integer;
         L: string;
       begin
    -  L := Lowercase(HTML);
    -  I := Pos(S, L);
    -  while (I > 0) do
    -    begin
    -    Delete(HTML, I, 1);
         L := Lowercase(HTML);
         I := Pos(S, L);
    -    end;
    +    while (I > 0) do
    +      begin
    +        Delete(HTML, I, 1);
    +        L := Lowercase(HTML);
    +        I := Pos(S, L);
    +      end;
       end;

       function ConvertToUTF8(const S: string): string;
    @@ -4511,7 +4526,7 @@
       SetLength(Result, Len1);
    {$ELSE}
       Result := AnsiToUtf8(S);
    -{$ENDIF} 
    +{$ENDIF}
       end;

       procedure InsertDefaultFontInfo;
    @@ -4567,16 +4582,51 @@
       HTML := Copy(HTML, 1, I);  {truncate the tags}
       end;

    +  //Snap to nearest closing tag going to the final
    +  procedure AjustarContenidoFin;
    +  var
    +    C: char;
    +    I: integer;
    +
    +    procedure GetC; begin if I-1 > StSrc then begin Dec(I); C := HTML; end else C := #0; end;
    +    procedure GetC2; begin if I+1 < EnSrc then begin Inc(I); C := HTML; end  else C := #0; end;
    +
    +  begin
    +  I := EnSrc;
    +    repeat GetC; until (C = '/') or (C = #0);
    +    repeat GetC2; until (C = '>') or (C = #0);
    +
    +  if C = #0 then {inc(I)};
    +  HTML := Copy(HTML, 1, I);
    +  end;
    +
    +  //Snap to nearest opening tag to the beginning
    +  procedure AjustarContenidoInicio;
    +   var
    +    C: char;
    +    I: integer;
    +
    +    procedure GetC; begin if I-1 > 0 then begin Dec(I); C := HTML; end else C  := #0; end;
    +
    +  begin
    +  I := StSrc;
    +    repeat GetC; until (C = '/') or (C = #0);
    +    repeat GetC; until (C = '<') or (C = #0);
    +
    +  if C = #0 then inc(I);
    +  HTML := Copy(HTML, I, Length(HTML));
    +  end;
    +
    begin
    -Leng := FSectionList.GetSelLength;
    -if Leng = 0 then
    + Leng := FSectionList.GetSelLength;
    + if Leng = 0 then
       Exit;
    -FSectionList.CopyToClipboardA(Leng+1);
    + FSectionList.CopyToClipboardA(Leng+1);

    -HTML := DocumentSource;
    -StSrc := FindSourcePos(FSectionList.SelB)+1;
    -EnSrc := FindSourcePos(FSectionList.SelE);
    -if EnSrc < 0 then    {check to see if end selection is at end of document}
    + HTML := DocumentSource;
    + StSrc := FindSourcePos(FSectionList.SelB)+1;
    + EnSrc := FindSourcePos(FSectionList.SelE);
    + if EnSrc < 0 then    {check to see if end selection is at end of document}
       begin
       EnSrc := Length(HTML);
       if HTML = '>' then
    @@ -4587,11 +4637,29 @@
       end
      else EnSrc := EnSrc + 1;
    {Truncate beyond EnSrc}
    -HTML := Copy(HTML, 1, EnSrc-1);
    +
    +HTML2 :=  Copy(HTML, StSrc, EnSrc - StSrc);
    +if (pos('<',HTML2) = 0) and
    +   (pos('>',HTML2) = 0) and
    +   (pos('/',HTML2) = 0) then etiquetas := false ;
    +
    {Also remove any tags on the end}
    -BackupToContent;
    +//BackupToContent;
    +if etiquetas then
    +  begin
    +    HTML := Copy(HTML, 1, EnSrc);
    +    AjustarContenidoFin;
    +    AjustarContenidoInicio;
    +    html := '<body><table>' + html + '</table></body>';
    +  end
    +else HTML := '<body><table>' + html2 + '</table></body>';
    +
    +HTML2 :='';
    +
    {insert the StartFrag string}
    -Insert(StartFrag, HTML, StSrc);
    +//Insert(StartFrag, HTML, StSrc);
    +HTML := StartFrag + HTML;
    +
    {Remove all Meta tags, in particular the ones that specify language, but others
      seem to cause problems also}
    RemoveTag('<meta');
    @@ -4610,12 +4678,8 @@
    {Add the header to start}
    HTML := GetHeader(HTML)+HTML;

    -{$IFNDEF LCL}
    -format := RegisterClipboardFormat('HTML Format'); {not sure this is necessary}
    -{$ELSE}
    -format := RegisterClipboardFormat('text/html');
    -{$ENDIF}
    CopyFormatToClipBoard(HTML, format);
    +html:='';
    end;

    function ThtmlViewer.GetSelTextBuf(Buffer: PWideChar; BufSize: integer): integer;
    @@ -5351,4 +5415,4 @@
    end;            
          
    end.
    -
    +
    \ No hay ningún carácter de nueva línea al final del archivo

    http://pascallibre.blog.com.es/2011/05/15/parchear-htmlport-de-lazarus-para-usar-el-portapapeles-sin-problemas-11159600/_

     
  • peeterminy
    peeterminy
    2013-01-18

    The Project is very interesting and some what providing the best tips to compete the task. I am not having complete knowledge regarding this. Could any one please produce some attachment links regarding my request?

    QR code generator
    QR codes