Changeset 793 for cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas
- Timestamp:
- Jun 10, 2010, 3:13:12 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas
r729 r793 14 14 15 15 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; 19 23 PtName, DOB, VisitDate, Location:string; Application : TApplication); //kt added 5-2-05 20 24 function IsHTML(Lines : TStrings): boolean; overload; 21 25 function IsHTML(Line : String): boolean; overload; 22 26 function HasHTMLTags(Text: string) : boolean; 23 procedure FixHTML(Lines : TStrings); 27 procedure FixHTML(Lines : TStrings); 24 28 function FixHTMLCRLF(Text : String) : string; 25 29 procedure SplitToArray (HTMLText: string; Lines : TStrings); … … 38 42 function ExtractDateOfNote(Lines : TStringList) : string; 39 43 Procedure ScanForSubs(Lines : TStrings); 44 Procedure InsertSubs(Lines : TStrings); 40 45 41 46 implementation … … 65 70 var 66 71 PrinterEvents : TPrinterEvents; 72 SubsFoundList : TStringList; 67 73 68 74 const CRLF = #$0D#$0A; … … 150 156 have decided to try to let the user click a button when the printer has 151 157 been selected. } 152 158 153 159 var 154 160 UseUI : OleVariant; … … 176 182 PrinterEvents.RestorePrinterTimer.Enabled := true; //launch a restore event in 30 seconds 177 183 //RestoreIEPrinting; //elh - This was omitted from below. Not sure why. 11/10/09 178 finally 184 finally 179 185 PrinterEvents.PrintingNow := false; 180 186 end; 181 187 end; 182 188 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 the196 printing will not start until after the user selects a printer and197 presses [OK]. I could not find any reliable way to determine when the198 print job had been created. I had to know this event because I need to199 restore some IE settings AFTER the printing has finished. I even tried to200 get the active windows and see if it was a print dialog. But IE print dlg201 apparently is owned by another thread than CPRS, because GetActiveWindow would202 not bring back a handle to the printer dialog window. I therefore told IE203 to print WITHOUT asking which printer via UI. In that case it prints to the204 system wide default printer. So I have to set the default printer to the205 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 it208 would return NO if in the process of currently printing. It didn't work,209 and would return OK immediately. }210 211 212 213 var214 UseUI : OleVariant;215 NewPrinterName : string;216 dlgWinPrinter : TPrintDialog;217 begin218 if PrinterEvents.RestorePrinterTimer.Enabled = false then begin219 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 printer225 NewPrinterName := GetCurrentPrinterName;226 SetDefaultPrinter(NewPrinterName); //Set global setting that IE will use.227 PrinterEvents.LastChosenPrinterName := NewPrinterName;228 try229 frmNotes.SetDisplayToHTMLvsText([vmView,vmHTML],Lines); //ActivateHtmlViewer(Lines);230 if frmNotes.HtmlViewer.WaitForDocComplete = false then begin231 ErrMsg := 'The web browser timed out trying to set up document.';232 exit;233 end;234 SetupHTMLPrinting(PtName,DOB,Location,' '); {elh 6/19/09} //kt235 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 seconds239 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} //kt242 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 *)251 189 (* 252 190 function WaitForBrowserOK(MaxSecDelay: integer; Application : TApplication) : boolean; 253 191 //Returns TRUE if can print 254 192 var 255 StartTime : TDateTime; 193 StartTime : TDateTime; 256 194 Status: OLECMDF; 257 195 MaxDelay,ElapsedTime : Double; … … 260 198 OneMin = 0.0007; //note: 0.0007 is about 1 minute 261 199 begin 262 StartTime := GetTime; 200 StartTime := GetTime; 263 201 MaxDelay := OneMin * MaxSecDelay; 264 202 repeat … … 271 209 end; 272 210 *) 273 211 274 212 Procedure ScanForSubs(Lines : TStrings); 275 213 //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; 279 218 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; 287 252 end; 288 253 end; … … 539 504 Result := AnsiReplaceText(Result,'>'+CRLF,'>'#$1F); //protect sequences we want 540 505 Result := AnsiReplaceText(Result,CRLF,'<BR>'+CRLF); //Add <BR>'s to CrLf's 541 Result := AnsiReplaceText(Result,'>'#$1F,'> <BR>'+CRLF); //Restore sequences we wanted506 Result := AnsiReplaceText(Result,'>'#$1F,'>'+CRLF); //Restore sequences we wanted 542 507 Result := AnsiReplaceText(Result,#$1E,'<NO DATA>'); //Restore sequences we wanted 543 508 end; … … 927 892 initialization 928 893 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; 930 898 931 899 finalization 932 PrinterEvents.Free; 900 PrinterEvents.Free; 901 SubsFoundList.Free; 902 933 903 end.
Note:
See TracChangeset
for help on using the changeset viewer.