Module cWinReport2.pkg
1// cWinReport2.pkg
2
3// defines support for new Winprint2 cWinReport2 class
4
5
6Use DFRpt.pkg // BasicReport RO Class for VDF
7Use WinPrint2.pkg // WinPrint2 engine
8Use Winprint_Commands.pkg // commands used by this class
9
10{ HelpTopic=cWinReport2 }
11Class cWinReport2 is a BasicReport
12
13 Procedure Construct_Object
14 Forward send construct_object
15
16 Date Today
17 Sysdate Today
18
19 // should use built in DF function CurrentDateTime()
20 { Visibility=Private Obsolete=True }
21 Property Date RptToday Today
22
23 Object RptTotal is an Array
24 End_Object
25
26 // If true, report is output upon completion. Either preview
27 // or printer depending on output_device_mode
28 { Category=Report }
29 Property Boolean AutoOutput_State True
30
31 // When a new page is created (DFNew_Page) and the number
32 // of columns is not passed, this is used.
33 { Visibility=Private Obsolete=True }
34 Property Integer Print_Columns 0
35
36 // This determines if a DFNew_Page should be executed when the
37 // report starts. In some rare cases, you would not want this to
38 // occur until a subheader
39 { Category=Report }
40 Property Boolean AutoNew_Page_State True
41
42 // Output device (print or preview). Normally this is delegated to
43 // the report view.
44 //
45
46 { Visibility=Private }
47 Property Integer Private.Output_Device_Mode PRINT_TO_UNDEFINED
48
49 { Category=Report }
50 Property Handle phoWinPrint ghoWinPrint2 // the report engine to use.
51
52 // JJT: For now this is for testing.
53 { Visibility=Private }
54 Property boolean pbModalViewer False
55
56 { Category=Report }
57 Property boolean pbMultiReports False
58
59 { Visibility=Private }
60 Property boolean pbFirstPagePrinted false
61
62 End_Procedure
63
64 // returns the current status of Winprint Document object. dsNotStarted, dsStarted, dsFinished
65 // note that the status can reflect a status from a different report. The winprint object is global.
66 Function DocumentStatus returns Boolean
67 integer iStatus
68 Get DocumentStatus of (phoWinprint(self)) to iStatus
69 function_return iStatus
70 End_function
71
72 Function IsViewerActive Returns Boolean
73 Boolean bIsActive
74 Get IsViewerActive of (phoWinPrint(Self)) to bIsActive
75 Function_Return bIsActive
76 End_Function
77
78 Function IsPrinterValid Returns Boolean
79 Function_Return (WP_IsPrinterValid()<>0)
80 End_Function
81
82 Function ArePrintersInstalled Returns Boolean
83 Function_Return (WP_ArePrintersInstalled()<>0)
84 End_Function
85
86
87 // All subtotal commands use the outer main report. This makes it easier to keep
88 // track of these numbers
89
90 Procedure Add_SubTotal Integer iCounter Number nData
91 Number nValue
92 Integer iObj
93 Move (RptTotal(Main_Report_Id(Self))) to iObj
94 Get Number_Value of iObj iCounter To nValue
95 Add nData To nValue
96 Set Array_Value of iObj iCounter To nValue
97 End_Procedure
98
99 Procedure Clr_SubTotal Integer iCounter
100 Set Array_Value of (RptTotal(Main_Report_Id(Self))) iCounter To 0
101 End_Procedure
102
103 Procedure Clr_AllSubTotals
104 Send Delete_Data of (RptTotal(Main_Report_Id(Self)))
105 End_Procedure
106
107 Function Sum_SubTotal Integer iTotal Returns Number
108 Number nRetVal
109 Get Number_Value of (RptTotal(Main_Report_Id(Self))) iTotal To nRetVal
110 Function_Return nRetVal
111 End_Function
112
113 //Return sub-total and clear accumulator
114 //
115 Function SubTotal Integer iTotal Returns Number
116 Number nRetVal
117 Get Sum_SubTotal iTotal to nRetVal
118 Send Clr_SubTotal iTotal
119 Function_Return nRetVal
120 End_Function
121
122
123 // Note: Cols is optional. If no argument is passed it will use
124 // the object's property Print_Columns (0 by default)
125 //
126 Procedure DFNew_Page Integer Cols
127 Integer PageNumber Columns
128 Boolean bFirstPagePrinted
129 // If no args passed used default setting
130 If (Num_Arguments=0) ;
131 Move (Print_Columns(Main_Report_id(Self))) to Columns
132 Else ;
133 Move Cols to Columns
134 Set Page_Feed to -2 // No FormFeed
135 If (Child_Rpt_State(self)) ;
136 Send DFNew_Page of (Main_Report_Id(Self)) Columns
137 Else Begin
138 // we only want to print report_header once. When report starts
139 // this is set true, after the first print it is false. You can set
140 // this to true before and explicit dfNew_page to force a header
141 Get pbFirstPagePrinted to bFirstPagePrinted
142 Get DFNewPage of (phoWinPrint(self)) Columns To PageNumber
143 If (PageNumber<>0) begin // if 0, it failed
144 Set No_PageCheck_State to True
145
146 //Top section
147 Send Page_Top
148 If Not bFirstPagePrinted Send Report_Header
149 Send Page_Header
150 Send Page_Title
151
152 Set New_Page_State to False
153 Set Page_End_State to False
154 Set No_PageCheck_State to False // No longer Paging
155 Set pbFirstPagePrinted to True
156 End
157 End
158
159 // Footer section
160 //
161 // DO NOT CHANGE THE ORDER OF BOTTOM SECTIONS !!!!!
162 //
163
164 Send Page_Bottom
165
166 // in WinPrint it is not possible to replace Page_Footer
167 // with Report_Footer. If you use Report_Footer you will
168 // have both Page_Footer and Report_Footer
169 //
170 //If LastTime eq 0 Send Page_Footer
171 //else Send Report_Footer
172
173 Send Page_Footer
174 Send Page_Total
175 End_Procedure
176
177 { MethodType=Event NoDoc=True }
178 Procedure Ending_Main_Report
179 Boolean bCancel bMultiReports
180
181 Get Cancelled_state to bCancel
182 Get pbMultiReports to bMultiReports
183
184 Forward Send Ending_Main_Report
185
186 If bCancel Begin
187 Send DFEndDocument
188 Send DFClearDoc // this will also close the previewer
189 end
190 Else Begin
191 Send Report_Footer
192
193 // if multi-reports, we don't do an end of report yet. The programmer must
194 // manually end the report by sending EndMultiReport
195 If (not(bMultiReports)) begin
196 Send EndWinPrintReport
197 end
198
199 end
200
201 End_Procedure
202
203 // This must get called when you are running multiple reports (pbMultiReport).
204 // Send this when the last report is complete.
205 Procedure EndMultiReport
206 Send EndWinPrintReport
207 End_procedure
208
209
210 { Visibility=Private }
211 Procedure EndWinPrintReport
212 Boolean bAutoOutput
213 integer iStatus eMode
214 Get DocumentStatus to iStatus
215 If (iStatus<>dsStarted) procedure_return
216
217 // this tells winprint that the report is complete
218 Send DFEndDocument
219 // if auto-output we print or display automatically.
220 // for winprint2, if in preview mode you must do this so the previewer can enter
221 // a modal state (which it may or may not need to do).
222 Get AutoOutput_state to bAutoOutput
223 Get Output_device_mode to eMode
224 If (bAutoOutput or eMode=PRINT_TO_WINDOW) begin
225 Send PrintReport
226 // if auto output, we assume that you are done when it is all over
227 // we only can do this with the modal viewer
228 If (bAutoOutput and pbModalViewer(self)) begin
229 Send DFClearDoc
230 end
231 end
232
233 End_Procedure
234
235
236 { Visibility=Private }
237 Function Setup_Report Returns Integer
238 Integer iErr iStatus eMode
239 Boolean bActiveViewer bChildReport bMultiReports bOk
240
241 Get Child_rpt_state to bChildReport
242
243 If not bChildReport Begin
244
245 // This makes sure that we are pointing to the new winprint2 engine object.
246 // normally this will be the new winprint, but it can be redirected
247 Get phoWinPrint to WinPrintID
248
249 // winprint must have installed printer. If not installed, generate error and stop the report
250 Get ArePrintersInstalled to bOk
251 If not bOk Begin
252 Error DFERR_WINPRINT C_$NoInstalledPrinters
253 Function_Return 1
254 End
255
256 // check if selected printer is valid. If not, generate error and stop the report
257 Get IsPrinterValid to bOk
258 If not bOk Begin
259 Error DFERR_WINPRINT DFPrintError936 // Could not select a valid printer
260 Function_Return 1
261 End
262
263 // make sure it is ok to start a new report but try to be smart about it.
264 // if a report is active (dsstarted or dsFinished) check to see if it is
265 // finished w/ no viewer. If so, assume the user closed the report and is done
266 // so just clear the report. If a viewer is present, declare an error.
267 Get DocumentStatus to iStatus
268 Get pbMultiReports to bMultiReports
269 // multi-report only in-progress is multi and it is started
270 Move (bMultiReports and iStatus=dsStarted) to bMultiReports
271 If not bMultiReports Begin
272 If (iStatus<>dsNotStarted) Begin
273 Get IsViewerActive to bActiveViewer
274 If (iStatus=dsFinished and not(bActiveViewer)) Begin
275 Send DfClearDoc
276 End
277 Else Begin
278 Error DFERR_WINPRINT DFPrintError967
279 Function_Return 1
280 End
281 End
282
283 // all new reports by default allow printing from viewer and they have the print job set up when you select print
284 // if you need to change these defaults, you can change these inside of Starting_main_report
285 // We only do this with non-multi-reports.
286 Send DFSetPrintDlgInPreview True
287 Send DFSetEnablePrintFromPreview True
288
289 End
290
291 // In the new winprint, this message is not needed and is a stub. For
292 // now it is in here for compatibility purposes
293 //You MUST always start a new report with this procedure
294 Send DFZeroCounters of (phoWinPrint(Self))
295 Send Clr_AllSubTotals
296
297 End
298
299 Forward Get Setup_report to iErr
300
301 If (iErr=0) Begin
302 If not bChildReport Begin
303 // if part of a multi-report we don't do a new doc
304 If not bMultiReports Begin
305 Get Output_Device_Mode to eMode
306 Send DFNewDoc of (phoWinPrint(Self)) (eMode = PRINT_TO_WINDOW) // pass True of display while printing
307 End
308 // Do new page if not part of a multi-report and we say don't do a new page
309 If (not(bMultiReports) or AutoNew_Page_State(Self)) Begin
310 Set pbFirstPagePrinted to False // tells new page that this is the first time for this report
311 Send DFNew_page
312 End
313 End
314 End
315 Function_Return iErr
316 End_Function
317
318
319
320 // Cancel RO behavior - there is no device to close
321 //
322 { Visibility=Private }
323 Procedure Close_Output_Device
324 End_Procedure
325
326 // Cancel RO Behavior
327 //
328 { Visibility=Private }
329 Procedure Initialize_Output_Device
330 End_procedure
331
332
333 { MethodType=Property }
334 Function Output_Device_Mode Returns Integer
335 Integer hoId
336 String DevMode
337 Get Private.Output_Device_Mode to DevMode
338 If (DevMode=PRINT_TO_UNDEFINED) Begin
339 Get Report_View_Id to hoId
340 If hoID ;
341 Get OutPut_Device_Mode of hoID to DevMode
342 If (DevMode=PRINT_TO_UNDEFINED) ;
343 Move PRINT_TO_WINDOW to DevMode
344 End
345 Function_Return DevMode
346 End_Function // Output_Destination
347
348 { MethodType=Property }
349 { EnumList="Deferred_Print_To_Window, Print_To_Printer, Print_To_Undefined, Print_To_Window, Print_To_Printer_No_Dialog" }
350 { InitialValue=Print_To_Undefined }
351 { Category=Report }
352 Procedure Set Output_Device_Mode Integer DevMode
353 Set Private.Output_Device_Mode to DevMode
354 End_Procedure // Set Output_Device
355
356 // displays a metric ruler in .5 increments. This can be
357 // sent to make it easy to see how fields and labels should
358 // be moved for alignment.
359 //
360 Procedure ShowRuler
361 integer i
362 number n
363 for i from 0 to 30
364 Send DFWritePos of (phoWinPrint(self)) (String(i)) FONT_DEFAULT i -1 0
365 Move (i+.5) to n
366 Send DFWritePos of (phoWinPrint(self)) "." FONT_DEFAULT n -1 0
367 Loop
368 Send DFWriteln of (phoWinPrint(self)) '' FONT_DEFAULT FONT_DEFAULT -1
369 End_procedure
370
371 // status panel related agumentations to handle the auto-previewer
372
373 Procedure Update_Status string sVal
374 Integer eMode
375 Get Output_device_mode to eMode
376 If (eMode=PRINT_TO_WINDOW) Begin
377 Send SetProgressCaption of (phoWinPrint(self)) sVal
378 End
379 Else Begin
380 forward Send Update_Status sVal
381 end
382 End_Procedure
383
384 { Visibility=Private }
385 Procedure Start_Status
386 Integer eMode
387 string sTitle sCaption
388 Get Output_device_mode to eMode
389 If (eMode=PRINT_TO_WINDOW) Begin
390 Get Report_Caption to sCaption
391 Get Report_Title to sTitle
392 If (sTitle<>"" and sCaption<>"") begin
393 Move ( sCaption- ":" * sTitle) to sTitle
394 end
395 else begin
396 Move (sCaption - sTitle) to sTitle
397 end
398 Send SetReportTitle of (phoWinPrint(self)) sTitle
399 End
400 Else Begin
401 forward Send Start_status
402 end
403 End_Procedure
404
405 { Visibility=Private }
406 Procedure Resume_Status
407 Integer eMode
408 Get Output_device_mode to eMode
409 If (eMode=PRINT_TO_WINDOW) Begin
410 Send DfPreviewNoWait of (phoWinPrint(self))
411 End
412 Else Begin
413 forward Send Resume_Status
414 end
415 End_Procedure
416
417 { Visibility=Private }
418 Procedure End_Status
419 Integer eMode
420 Get Output_device_mode to eMode
421 If (error_processing_state(self)) Begin
422 Send DFClosePreview
423 end
424 If (eMode=PRINT_TO_WINDOW) Begin
425 End
426 Else Begin
427 forward Send End_Status
428 end
429 End_Procedure
430
431 { MethodType=Event Nodoc=True }
432 Function Report_Interrupt Returns Integer
433 integer eStat
434 String sMess
435 Boolean bActiveViewer
436 Get IsViewerActive to bActiveViewer
437 If (Error_Check_State(self)) begin
438 Move C_$AnErrorWishToCancel to sMess
439 end
440 Else begin
441 Move C_$CancelThisReport to sMess
442 end
443 If bActiveViewer Begin
444 Get PreviewYesNoBox of (phoWinPrint(self)) C_$ReportInterrupt sMess to eStat
445 end
446 Else Begin
447 Get YesNo_Box sMess C_$ReportInterrupt to eStat
448 End
449
450 Function_Return (eStat=MBR_YES)
451
452 End_Function
453
454 { Visibility=Private }
455 Function Test_KeyPressed Returns Integer
456 Boolean bStop bError bActiveViewer
457 integer eMode
458 // winreport will do this also, but this makes sure that this gets called
459 // for each body loop -- even if the body loop prints nothing
460 Send PumpMsgQueue of (phoWinPrint(self)) // permit painting
461 Get IsViewerActive to bActiveViewer
462 Get Output_device_mode to eMode
463 If bActiveViewer Begin
464 Get ViewerWantsToClose of (phoWinPrint(self)) to bStop
465 Get Error_Check_State to bError
466 if (bStop or bError) begin
467 Get Report_Interrupt to bStop
468 end
469 end
470 Else Begin
471 Forward Get Test_KeyPressed to bStop
472 If (eMode=PRINT_TO_WINDOW and not(bStop)) Begin
473 Send DfPreviewNoWait
474 end
475 End
476
477 Function_Return bStop
478 End_Function
479
480 { Visibility=Private }
481 Procedure OnClosingView
482 Send DFClearDoc
483 end_procedure
484
485
486 // Attempt to make this as intuitive as possible. You cannot invoke this when a
487 // report is active. If a report is not finished, you cannot do this.
488 // If a report is finsihed it may or may not have a viewer present.
489 // If a viewer is not present, we will clear the exising report (making the assumption
490 // that a modeless viewer was closed and the report will not be invoked again). If a viewer
491 // is active, we will pass this through to the winprint object which will show an error
492
493 Function DFPrintSetupDialog Returns Boolean// invoke printer setup dialog
494 Integer iStatus
495 Boolean bActiveViewer bOk
496 // we must have printers installed for this to work
497 Get ArePrintersInstalled to bOk
498 If not bOk Begin
499 Error DFERR_WINPRINT C_$NoInstalledPrinters
500 End
501 Else Begin
502 Get DocumentStatus to iStatus
503 If (iStatus=dsFinished) Begin
504 Get IsViewerActive to bActiveViewer
505 If not bActiveViewer Begin
506 Send DfClearDoc
507 End
508 End
509 // the winprint object will generate an error if the status is not dsNotStarted.
510 // we want those errors
511 Get DFPrintSetupDialog of (phoWinPrint(Self)) to bOk
512 End
513 Function_Return bOk
514 End_Procedure
515
516 // It is better to use DFPrintSetupDialog which tells you if the dialog was canceled
517 { Obsolete=True }
518 Procedure DFPrintSetup // invoke printer setup dialog
519 Boolean bOk
520 Get DFPrintSetupDialog to bOk
521 End_Procedure
522
523 Procedure DFClearDoc // clear document, remove viewer
524 Send DFClearDoc of (phoWinPrint(self))
525 end_procedure
526
527 Procedure DFEndDocument // tell winprint that the report is complete
528 Send DfEndDocument of (phoWinPrint(self))
529 end_procedure
530
531 Procedure DFClosePreview //close the previewer, does not clear the document
532 Send DfClosePreview of (phoWinPrint(self))
533 end_procedure
534
535 Procedure DFPrintDialog // popup print job dialog
536 Send DFPrintDialog of (phoWinPrint(self))
537 End_procedure
538
539 Procedure DFPrint // print with printer dialog
540 Send DFPrint of (phoWinPrint(self))
541 End_procedure
542
543 Procedure DFPrintDoc // print without printer dialog
544 Send DFPrintDoc of (phoWinPrint(self))
545 End_Procedure
546
547 Procedure DFPreviewWait // invoke previewer in modal mode
548 Send DFPreviewWait of (phoWinPrint(self))
549 End_Procedure
550
551 Procedure DFPreviewNoWait // invoke previwer in modeless mode
552 Send DFPreviewNoWait of (phoWinPrint(self))
553 End_Procedure
554
555 Procedure DFPreview // invokde previewer based on pbModalViewer property
556 Boolean bModalViewer
557 Get pbModalViewer to bModalViewer
558 If bModalViewer Begin
559 Send DFPreviewWait
560 end
561 else Begin
562 Send DFPreviewNoWait
563 end
564 End_Procedure
565
566 // Print report to appropriate device (printer, preview) based
567 // on output_device_mode
568 //
569 Procedure PrintReport
570 Integer eMode
571 Get OutPut_Device_Mode to eMode
572 If ((eMode=PRINT_TO_WINDOW) or (eMode=DEFERRED_PRINT_TO_WINDOW)) Begin
573 Send DFPreview
574 end
575 Else If (eMode=PRINT_TO_PRINTER_NO_DIALOG) Begin
576 Send DFPrintDoc // print, no print job dialog
577 end
578 Else Begin // (eMode=PRINT_TO_PRINTER)
579 Send DFPrint // print with print job dialog
580 end
581 End_Procedure
582
583
584 Procedure DFSetPrinterPaper integer ePaperType
585 Send DFSetPrinterPaper of (phoWinPrint(self)) ePaperType
586 End_Procedure
587
588 Function DFGetPrinterPaper returns integer //ePaperType
589 integer ePaperType
590 Get DFGetPrinterPaper of (phoWinPrint(self)) to ePaperType
591 Function_return ePaperType
592 end_function
593
594
595 Procedure DFSetPrinterBin integer eBinType
596 Send DFSetPrinterBin of (phoWinPrint(self)) eBinType
597 End_Procedure
598
599 Function DFGetPrinterBin returns integer //eBinType
600 integer eBinType
601 Get DFGetPrinterBin of (phoWinPrint(self)) to eBinType
602 Function_return eBinType
603 end_function
604
605
606 Procedure DFSetPrinterResolution integer eResType
607 Send DFSetPrinterResolution of (phoWinPrint(self)) eResType
608 End_Procedure
609
610 Function DFGetPrinterResolution returns integer //eResType
611 Boolean eResType
612 Get DFGetPrinterResolution of (phoWinPrint(self)) to eResType
613 Function_return eResType
614 end_function
615
616
617 Procedure DFSetLandscape boolean bIsLandscape
618 Send DFSetLandscape of (phoWinPrint(self)) bIsLandscape
619 End_Procedure
620
621 Function DFGetLandscape returns boolean // bIsLandscape
622 Boolean bIsLandscape
623 Get DFGetLandscape of (phoWinPrint(self)) to bIsLandscape
624 Function_return bIsLandscape
625 end_function
626
627 Procedure DFSetMetrics integer eType
628 Send DFSetMetrics of (phoWinPrint(self)) eType
629 End_Procedure
630
631 Function DFGetMetrics returns integer
632 integer eType
633 Get DFGetMetrics of (phoWinPrint(self)) to eType
634 Function_return eType
635 end_function
636
637
638 Procedure DFSetPrintDlgInPreview boolean bShowDialog
639 Set PrintDlgInPreview of (phoWinPrint(self)) to bShowDialog
640 End_Procedure
641
642 Function DFGetPrintDlgInPreview returns boolean
643 boolean bShowDialog
644 Get PrintDlgInPreview of (phoWinPrint(self)) to bShowDialog
645 Function_return bShowDialog
646 end_function
647
648
649 Procedure DFSetEnablePrintFromPreview boolean bEnablePrint
650 Set EnablePrintFromPreview of (phoWinPrint(self)) to bEnablePrint
651 End_Procedure
652
653 Function DFGetEnablePrintFromPreview returns boolean
654 boolean bEnablePrint
655 Get EnablePrintFromPreview of (phoWinPrint(self)) to bEnablePrint
656 Function_return bEnablePrint
657 end_function
658
659
660
661 Procedure DFSetMargins number nLeft number nTop number nRight number nBottom
662 Send DFSetMargins of (phoWinPrint(self)) nLeft nTop nRight nBottom
663 End_Procedure
664
665 Procedure DFSetTopBottom number nTop number nBottom Boolean bAllPages
666 Send DFSetTopBottom of (phoWinPrint(self)) nTop nBottom bAllPages
667 End_Procedure
668
669
670 Procedure DFSetDevice string sPrinterName
671 Send DFSetDevice of (phoWinPrint(self)) sPrinterName
672 End_Procedure
673
674 Function DFGetCurrentDevice returns string // sPrinterName
675 String sPrinterName
676 Get DFGetCurrentDevice of (phoWinPrint(self)) to sPrinterName
677 Function_return sPrinterName
678 end_function
679
680
681 Procedure DFSetUserDefinedPapersize number nLength number nWidth
682 Send DFSetUserDefinedPapersize of (phoWinPrint(self)) nLength nWidth
683 End_Procedure
684
685 Function DFGetUserDefinedLength returns number
686 number nSize
687 Get DFGetUserDefinedLength of (phoWinPrint(self)) to nSize
688 Function_return nSize
689 end_function
690
691 Function DFGetUserDefinedWidth returns number
692 number nSize
693 Get DFGetUserDefinedWidth of (phoWinPrint(self)) to nSize
694 Function_return nSize
695 end_function
696
697
698 Procedure DFSetNumberOfCopies integer iCopies
699 Send DFSetNumberOfCopies of (phoWinPrint(self)) iCopies
700 End_Procedure
701
702 Procedure DFPrinterBinFirstPage integer eBinType
703 Send DFPrinterBinFirstPage of (phoWinPrint(self)) eBinType
704 End_Procedure
705
706 Procedure DFClearPrinter
707 Send DFClearPrinter of (phoWinPrint(self))
708 End_Procedure
709
710 Function DFGetDFColor integer iRed integer iGreen integer iBlue returns integer
711 integer iWPColor
712 Get DFGetDFColor of (phoWinPrint(self)) iRed iGreen iBlue to iWPColor
713 Function_return iWPColor
714 end_function
715
716 Function RGBToWPColor integer iRgb returns integer
717 integer iWPColor
718 Get RGBToWPColor of (phoWinPrint(self)) iRGB to iWPColor
719 Function_return iWPColor
720 end_function
721
722
723End_Class
724