Ignore:
Timestamp:
Jun 10, 2010, 3:13:12 PM (14 years ago)
Author:
Kevin Toppenberg
Message:

update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas

    r729 r793  
    1414
    1515  var
    16     DesiredHTMLFontSize : byte;       
    17      
    18   procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string;
     16    DesiredHTMLFontSize : byte;
     17    CPRSDir : string;
     18    URL_CPRSDir : string;  //This is CPRSDir, but all '\'s are converted to '/'s
     19
     20  CONST ALT_IMG_TAG_CONVERT = 'alt="convert to $CPRSDIR$"';
     21
     22  procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string;
    1923                            PtName, DOB, VisitDate, Location:string; Application : TApplication);  //kt added 5-2-05
    2024  function  IsHTML(Lines : TStrings): boolean; overload;
    2125  function  IsHTML(Line : String): boolean; overload;
    2226  function  HasHTMLTags(Text: string) : boolean;
    23   procedure FixHTML(Lines : TStrings); 
     27  procedure FixHTML(Lines : TStrings);
    2428  function  FixHTMLCRLF(Text : String) : string;
    2529  procedure SplitToArray (HTMLText: string; Lines : TStrings);
     
    3842  function ExtractDateOfNote(Lines : TStringList) : string;
    3943  Procedure ScanForSubs(Lines : TStrings);
     44  Procedure InsertSubs(Lines : TStrings);
    4045
    4146implementation
     
    6570  var
    6671    PrinterEvents : TPrinterEvents;
     72    SubsFoundList : TStringList;
    6773
    6874  const CRLF = #$0D#$0A;
     
    150156       have decided to try to let the user click a button when the printer has
    151157       been selected.                                         }   
    152  
     158
    153159  var
    154160    UseUI          : OleVariant;   
     
    176182      PrinterEvents.RestorePrinterTimer.Enabled := true; //launch a restore event in 30 seconds
    177183      //RestoreIEPrinting;  //elh - This was omitted from below. Not sure why.  11/10/09
    178     finally 
     184    finally
    179185      PrinterEvents.PrintingNow := false;
    180186    end;
    181187  end;
    182188
    183 (*
    184   Safe copy of above.  Delete later...
    185    
    186   procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string;
    187                             PtName, DOB, Location:string;
    188                             Application : TApplication);
    189   //      Web browser printing options:
    190   //        OLECMDEXECOPT_DODEFAULT       Use the default behavior, whether prompting the user for input or not.
    191   //        OLECMDEXECOPT_PROMPTUSER      Execute the command after obtaining user input.
    192   //        OLECMDEXECOPT_DONTPROMPTUSER  Execute the command without prompting the user.
    193 
    194   {Notice:  When IE is asked to print, it immediately returns from the function,
    195            but the printing has not yet occured.  If UI is requested, then the
    196           printing will not start until after the user selects a printer and
    197          presses [OK].  I could not find any reliable way to determine when the
    198         print job had been created.  I had to know this event because I need to
    199        restore some IE settings AFTER the printing has finished.  I even tried to
    200       get the active windows and see if it was a print dialog.  But IE print dlg
    201      apparently is owned by another thread than CPRS, because GetActiveWindow would
    202      not bring back a handle to the printer dialog window.  I therefore told IE
    203      to print WITHOUT asking which printer via UI.  In that case it prints to the
    204      system wide default printer.  So I have to set the default printer to the
    205      user's choice, and then change it back again.  This is bit of a kludge,
    206      but I couldn't figure out any other way after hours of trial and error.
    207      NOTE: I tried to query IE to see if it was able to print, thinking that it
    208      would return NO if in the process of currently printing.  It didn't work,
    209      and would return OK immediately.                                               }   
    210  
    211 
    212 
    213   var
    214     UseUI          : OleVariant;   
    215     NewPrinterName : string;   
    216     dlgWinPrinter  : TPrintDialog;
    217   begin
    218     if PrinterEvents.RestorePrinterTimer.Enabled = false then begin
    219       PrinterEvents.SavedDefaultPrinter := GetCurrentPrinterName;
    220     end; 
    221     dlgWinPrinter := TPrintDialog.Create(nil);
    222     frmTMGPrinting.Show;
    223     //FIX: get printer name for the one used last time somehow...
    224     if dlgWinPrinter.Execute then begin  //only sets a local printer
    225       NewPrinterName := GetCurrentPrinterName; 
    226       SetDefaultPrinter(NewPrinterName); //Set global setting that IE will use.
    227       PrinterEvents.LastChosenPrinterName := NewPrinterName;
    228       try
    229         frmNotes.SetDisplayToHTMLvsText([vmView,vmHTML],Lines);  //ActivateHtmlViewer(Lines);
    230         if frmNotes.HtmlViewer.WaitForDocComplete = false then begin
    231           ErrMsg := 'The web browser timed out trying to set up document.';
    232           exit;
    233         end;
    234         SetupHTMLPrinting(PtName,DOB,Location,' ');  {elh 6/19/09} //kt
    235         frmNotes.HtmlViewer.PrintFinished := false;               
    236         UseUI := false;  //UseUI := true;
    237         frmNotes.HtmlViewer.PrintDocument(UseUI);   //Returns immediately, not after printing done.
    238         PrinterEvents.RestorePrinterTimer.Enabled := true; //launch a restore event in 30 seconds
    239         Wait(4,Application);
    240         //WaitForBrowserOK(10, Application); //wait up to 10 seconds  //Note: this doesn't do what I want.  Status is immediately OK.
    241         //RestoreIEPrinting;   {elh 6/19/09}  //kt
    242       finally   //any needed final code goes here.
    243         //SetDefaultPrinter(DefaultPrinter);
    244         //beep;
    245       end;
    246     end;
    247     dlgWinPrinter.Free;
    248     frmTMGPrinting.Hide;       
    249   end;
    250 *) 
    251189  (*
    252190  function WaitForBrowserOK(MaxSecDelay: integer; Application : TApplication) : boolean;
    253191  //Returns TRUE if can print
    254192  var
    255     StartTime : TDateTime; 
     193    StartTime : TDateTime;
    256194    Status: OLECMDF;
    257195    MaxDelay,ElapsedTime : Double;
     
    260198    OneMin = 0.0007;  //note: 0.0007 is about 1 minute
    261199  begin
    262     StartTime := GetTime; 
     200    StartTime := GetTime;
    263201    MaxDelay := OneMin * MaxSecDelay;
    264202    repeat
     
    271209  end;
    272210  *)
    273  
     211
    274212  Procedure ScanForSubs(Lines : TStrings);
    275213  //Purpose: To scan note for constant $CPRS$ and replace with CPRS's actual directory
    276   var i : integer;
    277       CPRSDir : string;
    278   begin
     214  var i,p,p2 : integer;
     215      tempS : String;
     216  begin
     217    SubsFoundList.Clear;
    279218    for i := 0 to Lines.Count-1 do begin
    280       if Pos('$CPRSDIR$',Lines.Strings[i])>0 then begin
    281         CPRSDir := ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
    282         Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],'$CPRSDIR$',CPRSDir);
    283         //Ensure images are downloaded before passing page to web browser       
    284         frmImages.timLoadImagesTimer(nil);
    285         //NOTE: This often doesn't get the job completed before passing to browser
    286         //      ?? check for completion?
     219      p := Pos('$CPRSDIR$',Lines.Strings[i]);
     220      if p>0 then begin
     221        p := p + Length('$CPRSDIR$\Cache\');
     222        p2 := PosEx('"',Lines.Strings[i],p);
     223        tempS := MidStr(Lines.Strings[i],p,(p2-p));
     224        SubsFoundList.Add(tempS);
     225        if Pos('file:///',Lines.Strings[i]) > 0 then begin
     226          Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],'$CPRSDIR$',URL_CPRSDir);
     227        end else begin
     228          Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],'$CPRSDIR$',CPRSDir);
     229        end;
     230        //Ensure images are downloaded before passing page to web browser
     231      end;
     232    end;
     233    frmImages.EnsureImagesDownloaded(SubsFoundList);
     234  end;
     235
     236
     237  Procedure InsertSubs(Lines : TStrings);
     238  //Purpose: To scan a edited note images, and replace references to CPRS's
     239  //         actual local directory with $CPRS$
     240  var i,p : integer;
     241     TempS: string;
     242
     243  begin
     244    for i := 0 to Lines.Count-1 do begin
     245      Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],URL_CPRSDir,'$CPRSDIR$');
     246      Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],ALT_IMG_TAG_CONVERT,'IMAGE'); //Remove signal
     247      p := pos(ALT_IMG_TAG_CONVERT,Lines.Strings[i]);
     248      if p > 0 then begin
     249        TempS := MidStr(Lines.Strings[i],1,p-1);
     250        TempS := TempS + MidStr(Lines.Strings[i],p+length(ALT_IMG_TAG_CONVERT),length(Lines.Strings[i])+1);
     251        Lines.Strings[i] := TempS;
    287252      end;
    288253    end;
     
    539504    Result := AnsiReplaceText(Result,'>'+CRLF,'>'#$1F); //protect sequences we want
    540505    Result := AnsiReplaceText(Result,CRLF,'<BR>'+CRLF); //Add <BR>'s to CrLf's
    541     Result := AnsiReplaceText(Result,'>'#$1F,'><BR>'+CRLF); //Restore sequences we wanted
     506    Result := AnsiReplaceText(Result,'>'#$1F,'>'+CRLF); //Restore sequences we wanted
    542507    Result := AnsiReplaceText(Result,#$1E,'<NO DATA>'); //Restore sequences we wanted
    543508  end;
     
    927892initialization
    928893  DesiredHTMLFontSize := 2; //probably overwritten in fNotes initialization
    929   PrinterEvents := TPrinterEvents.Create; 
     894  PrinterEvents := TPrinterEvents.Create;
     895  CPRSDir := ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
     896  URL_CPRSDir := AnsiReplaceStr(CPRSDir,'\','/');
     897  SubsFoundList := TStringList.Create;
    930898
    931899finalization
    932   PrinterEvents.Free;   
     900  PrinterEvents.Free;
     901  SubsFoundList.Free;
     902
    933903end.
Note: See TracChangeset for help on using the changeset viewer.