-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPNCODE.BAS
More file actions
2422 lines (1997 loc) · 85.7 KB
/
PNCODE.BAS
File metadata and controls
2422 lines (1997 loc) · 85.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "PrintCode"
Option Explicit
' The Print Module !!
'
' Pages (in order): 1) Form Icon (if applicable) Flags: .chkIcon
' (per module) 2) Controls (if applicable) .chkControlNames
' 3) Declaration/Procedures .chkCode
'
' Additional pages: a) Project Information .chkProject
' b) Form icons .chkFormIcons
' c) Index .chkIndex
'
' Printer order: a, b, 1, 2, 3, c
'
' -----------------------------------------------------
' See PnCommon.bas for support procedures and variables
' -----------------------------------------------------
Dim nPage As Integer ' Page number
Dim nMdlIndex As Integer ' Let the module know which file is being processed (using array element number)
Dim lp As Integer ' Layout() pointer (element reference number)
Dim WrapText() As String ' Used for the text-only wrapping procedures
Dim nWrapLines As Integer ' Number of lines in text-only wrapped text
Dim bNextPage As Boolean ' Next line should go to next page
Dim bFinalPage As Boolean ' True if final page is done (used for preview)
Dim nFontRatio As Double ' Used to scale fonts in preview picturebox (used in sample view)
Sub PrintJob()
Dim i As Integer, j As Integer, n As Integer, nIndex As Integer, _
nFinalIndex As Integer, nFinalProc As Integer
Dim nSize As Long
Dim sString As String, sUpper As String
Dim H As Single, W As Single, nPointY As Single
bFinalPage = False
nPage = 0
Erase Idx.ControlIndex
Erase Idx.DeclareIndex
Erase Idx.ProcIndex
Idx.CICount = -1
Idx.DIcount = -1
Idx.PIcount = -1
' Find the last module array element selected
nFinalIndex = MdCount
For i = MdCount To 1 Step -1
If Mdl(i).Selected <> vbUnchecked Then
nFinalIndex = i
Exit For
End If
Next
' Max height needs some attention
If frmMain.chkHeader = vbChecked Then
If Page.Output = OUT_PORT Then
nYHeight = GetHeight - (2 + IIf(frmMain.chkFooter = vbChecked, 3, 0))
Else
FontSet FONT_HEADER, False
H = GetTextHeight() + 4
If frmMain.chkFooter = vbChecked Then
FontSet FONT_FOOTER, False
H = H + (2 * GetTextHeight(frmMain.txtOwner(0) + frmMain.txtOwner(1))) + 4
End If
nYHeight = GetHeight - H
End If
Else
nYHeight = GetHeight
End If
' Height available. This one is easy: by setting it to -1, the header will be forced to be printed.
nYAvailable = -1
' Prep it.
PrintStartDoc
If UserAbort Then GoTo PrintAbort
' General project information ----------------------------------------------------------------
If frmMain.chkProject = vbChecked Then
If frmMain.chkResetPage = vbChecked Then nPage = 0
PrintProjectPage
If Page.Cancelled Then GoTo PrintAbort
End If
' Form icons (only to driver) ----------------------------------------------------------------
If Page.Output = OUT_DRIVER Then
If frmMain.chkFormIcons = vbChecked Then
If frmMain.chkResetPage = vbChecked Then nPage = 0
PrintProjectIcons
If Page.Cancelled Then GoTo PrintAbort
End If
End If
' Procedures (code) --------------------------------------------------------------------------
If Not InDevelopmentMode Then
On Error GoTo PrintError
End If
For i = 1 To MdCount
If UserAbort Then Exit For
If Mdl(i).Selected <> vbUnchecked Then
' Reset pagenumber if user wants it.
If frmMain.chkResetPage = vbChecked Then nPage = 0
' Tell the rest of module which module is being processed
nMdlIndex = i
' Initialise
nYAvailable = -1 ' Force header to print on first line to be printed
bNextPage = True
' Does the user wants to abort?
If UserAbort Then Exit For
' Icon (only to driver) -----------------------------------------------------------------
If Page.Output = OUT_DRIVER And frmMain.chkIcon = vbChecked Then
' Icon print - Not available in text mode
If Not EmptyString(Mdl(nMdlIndex).IconData) Then
If PrintFormIcon(nMdlIndex, "(Icono Formulario)", 8) Then
If frmMain.chkControlPage = vbChecked Then
bNextPage = True
Else
FeedLine
SeperatorPrint
End If
End If
End If
End If
' Controls ------------------------------------------------------------------------------
If frmMain.chkControlNames = vbChecked And Mdl(nMdlIndex).CtrlSelect Then
PrintFormControls
End If
If UserAbort Then Exit For
' Declaration/Procedures (Code) ---------------------------------------------------------
If frmMain.chkCode = vbChecked And Mdl(nMdlIndex).ProcCount > 0 Then
' Get the last procedure
nFinalProc = Mdl(nMdlIndex).ProcCount
For n = Mdl(nMdlIndex).ProcCount To 1 Step -1
If Mdl(nMdlIndex).Proc(n).Selected = vbChecked Then
nFinalProc = n
Exit For
End If
Next n
CheckAreaPrint
For n = 1 To Mdl(nMdlIndex).ProcCount
If UserAbort Then Exit For
If Mdl(nMdlIndex).Proc(n).Selected = vbChecked Then
If frmMain.chkProcNames = vbChecked Then ' Procedure names only...
If Mdl(nMdlIndex).Proc(n).Type <> PT_DECLARE Then ' Declarations not allowed
FontSet FONT_PROCS ' FontSet() ignores output to port (so let this call it)
LinePrint Mdl(nMdlIndex).Proc(n).Syntax
If frmMain.chkIndex = vbChecked Then ' INDEX - Update index-page reference
Idx.PIcount = Idx.PIcount + 1
ReDim Preserve Idx.ProcIndex(0 To Idx.PIcount)
Idx.ProcIndex(Idx.PIcount).File = Mdl(nMdlIndex).File
Idx.ProcIndex(Idx.PIcount).Page = nPage
Idx.ProcIndex(Idx.PIcount).Procedure.Name = Mdl(nMdlIndex).Proc(n).IndexName
Idx.ProcIndex(Idx.PIcount).Procedure.Type = ProcType(nMdlIndex, n)
End If
If n < nFinalProc Then
If frmMain.chkProcPage = vbChecked Then
bNextPage = True
ElseIf frmMain.chkSeparator = vbChecked Then
SeperatorPrint
End If
End If
End If
Else ' All code
CheckAreaPrint
If Mdl(nMdlIndex).Proc(n).Type = PT_DECLARE Then
FontSet FONT_PROCS
LinePrint "(Declaraciones)"
FeedLine
If frmMain.chkIndex = vbChecked Then ' INDEX - Update index-page reference
Idx.DIcount = Idx.DIcount + 1
ReDim Preserve Idx.DeclareIndex(0 To Idx.DIcount)
Idx.DeclareIndex(Idx.DIcount).File = Mdl(nMdlIndex).File
Idx.DeclareIndex(Idx.DIcount).Page = nPage
End If
End If
For j = 1 To Mdl(nMdlIndex).Proc(n).Lines
sString = Mdl(nMdlIndex).Proc(n).Code(j)
sUpper = UCase$(Trim$(sString))
If MatchString(sUpper, "'") Then ' Comments
FontSet FONT_COMMENTS
LinePrint sString
ElseIf MatchString(sUpper, "#") Then ' Compiler directive
FontSet FONT_DIRECTIVE
LinePrint sString
ElseIf IsProcedure(sUpper) Then ' Only happens once (I hope) - and not in declaration section
FontSet FONT_PROCS
LinePrint sString
If frmMain.chkIndex = vbChecked Then ' INDEX - Update index-page reference
Idx.PIcount = Idx.PIcount + 1
ReDim Preserve Idx.ProcIndex(0 To Idx.PIcount)
Idx.ProcIndex(Idx.PIcount).File = Mdl(nMdlIndex).File
Idx.ProcIndex(Idx.PIcount).Page = nPage
Idx.ProcIndex(Idx.PIcount).Procedure.Name = Mdl(nMdlIndex).Proc(n).IndexName
Idx.ProcIndex(Idx.PIcount).Procedure.Type = ProcType(nMdlIndex, n)
End If
Else ' Just some code or space
FontSet FONT_CODE ' Don't worry about repetitive font sets - PrintFont() is intelligent (it won't duplicate).
LinePrint sString
End If
Next j ' Code lines
If n < nFinalProc Then
If frmMain.chkProcPage = vbChecked Then
bNextPage = True
ElseIf frmMain.chkSeparator = vbChecked Then
SeperatorPrint
End If
End If
End If ' frmMain.chkProcNames = vbChecked
End If ' Mdl(nMdlIndex).Proc(n).Selected = vbChecked
Next n ' Procedures
End If ' frmMain.chkCode = vbChecked And Mdl(nMdlIndex).ProcCount > 0
If UserAbort Then Exit For
' ----------------------------------------------------------------------------------------
If i = nFinalIndex And frmMain.chkIndex = vbUnchecked Then bFinalPage = True
If nYAvailable > -1 Then FooterPrint
End If ' Mdl(i).Selected <> vbUnchecked
Next i ' i = 1 To MdCount [Cycle thru the files]
If Page.Cancelled Then GoTo PrintAbort
' Index page(s) ------------------------------------------------------------------------------
If frmMain.chkIndex = vbChecked Then
' Print the index page
If frmMain.chkResetPage = vbChecked Then nPage = 0
PrintIndexPage
If Page.Cancelled Then GoTo PrintAbort
End If
' --------------------------------------------------------------------------------------------
On Error Resume Next
Erase Idx.ControlIndex ' Regain resources/memory
Erase Idx.DeclareIndex
Erase Idx.ProcIndex
PrintEndDoc
Exit Sub
PrintError:
MsgBox "Problema al imprimir." & vbCrLf & "Error #" & Err.Number & ": " & Err.Description, vbCritical
PrintAbort:
On Error Resume Next
PrintKillDoc ' Job is aborted - how about killing the print buffer
Erase Idx.ControlIndex
Erase Idx.DeclareIndex
Erase Idx.ProcIndex
End Sub
' (just a brainstorm which never continued, but left in the code just in case I change my mind) ----------
' Prints the module (file).
' Provide Procedure index: -1 for whole file
' 0 for form controls (if available)
' 1 > for procedures (1 is mostly declaration)
'
' Index array update only available when whole file is printed
'
'Function PrintModule(nMIndex As Integer, nPIndex As Integer) As Boolean
' If frmMain.chkResetPage = vbChecked Then nPage = 0
' nMdlIndex = nMIndex
'End Function
' --------------------------------------------------------------------------------------------------------
Sub FontSet(nIndex As Integer, Optional bSaveFont)
If Page.Output = OUT_PORT Then Exit Sub
If IsMissing(bSaveFont) Then bSaveFont = True
SetFontName frmMain.lblFont(nIndex).FontName
SetFontSize frmMain.lblFont(nIndex).FONTSIZE
SetFontColor frmMain.lblFont(nIndex).ForeColor
SetFontBold frmMain.lblFont(nIndex).FontBold
SetFontItalic frmMain.lblFont(nIndex).FontItalic
SetFontStrikethru frmMain.lblFont(nIndex).FontStrikethru
SetFontUnderline frmMain.lblFont(nIndex).FontUnderline
If bSaveFont Then PrintFont
End Sub
' ------------------------------------------------------------------------------------------
' This routine is a SOB...
Private Sub LinePrint(sString As String, Optional bCrLf)
Dim nLines As Integer, i As Integer
Dim nTextHeight As Single
Dim sText As String
Dim WrapLine() As String
' Remove trailing spaces
sString = RTrim(sString)
If IsMissing(bCrLf) Then bCrLf = True
' Place line into textbox - frmMain.txtWrap
SetWrapObject sString
SaveWrap WrapLine, nLines
If Not bNextPage Then
' No forced pagebreak - check if there's enough room for the this string
nTextHeight = nLines * GetTextHeight
' If the page height is smaller than then string height just "page wrap" it.
If GetHeight > nTextHeight Then
' It will fit on one page - but is there still enough room for it?
If nYAvailable < nTextHeight Then
' No - force page break
bNextPage = True
End If
End If
End If
For i = 1 To nLines
sText = WrapLine(i)
If Not bNextPage Then
If nYAvailable < GetTextHeight(sText) Then
' There's not enough page height to accomodate this text - go to next page
bNextPage = True
End If
End If
If bNextPage Then
If Len(sText) = 0 Then GoTo EndOfLinePrint ' Do not allow empty lines in top of page
If nYAvailable > -1 Then ' Footer not printed yet...
FooterPrint
If Page.Cancelled Then Exit For
End If
HeaderPrint ' Now print the header
If Page.Cancelled Then Exit For
End If
' Finally print the string
If i > 1 Then
If Page.Output = OUT_PORT Then
PrintPrint ">> " & sText, bCrLf
Else
' Turn attributes off for marker - but keep fontname, size and colour
PushFont
SetFontBold False
SetFontItalic False
SetFontStrikethru False
SetFontUnderline False
PrintFont
PrintPrint ">> ", False ' Print marker.
' Put it back to how it was
PopFont
PrintFont
PrintPrint sText, bCrLf
End If
Else
PrintPrint sText, bCrLf
End If
If bCrLf Then
If Page.Output = OUT_RTF Then LayoutMode LYO_EOL
ReduceHeight GetTextHeight(sText)
End If
EndOfLinePrint:
Next
End Sub
Private Sub FeedLine(Optional nFont, Optional nLines)
If bNextPage Then Exit Sub
' Only process line if a new pages isn't forced
PushFont
If IsMissing(nFont) Then
FontSet FONT_CODE, False
Else
FontSet CInt(nFont), False
End If
If IsMissing(nLines) Then nLines = 1
Dim nHeight As Single
nHeight = GetTextHeight() * nLines
If nYAvailable < nHeight Then
' No room - force new page
bNextPage = True
Else
' Just process it - increment Y and deduct available height
PrintPSet 0, GetCurrentY + nHeight
ReduceHeight nHeight
If Page.Output = OUT_RTF Then
Dim p As Integer
For p = 1 To nLines
LayoutMode LYO_EOL
Next
End If
End If
PopFont
End Sub
' -----------------------------------------------------------------------------------
' 56.7 twips per logical millimeter
'
Private Sub SetWrapObject(sText As String, Optional nLength)
If Page.Ruler = RULER_CHAR Then
If IsMissing(nLength) Then
nLength = GetWidth
Else
nLength = CInt(nLength)
End If
sText = RTrim$(sText)
nWrapLines = 1
ReDim WrapText(1 To 1)
WrapText(1) = ""
If Len(sText) <= nLength Then
' No wrap required... great!
WrapText(1) = sText
Exit Sub
End If
' Text must be wrapped (or warped, like my mind)... oh, no..
Dim nSize As Integer, nMark As Integer, nSymbol As Integer
Dim sNextLine As String, sMarker As String
' nLength = nLength + 1
nSymbol = 0
sMarker = " "
Do
nSize = Len(sNextLine)
nMark = InStr(sText, sMarker)
If nMark Then
If nSize + nMark <= nLength Then
sNextLine = sNextLine & Left$(sText, nMark)
sText = Mid$(sText, nMark + 1)
ElseIf nMark > nLength Then
'sBuffer = sBuffer & vbCrLf & Left$(sText, nLength)
nWrapLines = nWrapLines + 1
ReDim Preserve WrapText(1 To nWrapLines)
WrapText(nWrapLines) = Left$(sText, nLength)
sText = Mid$(sText, nLength + 1)
Else
'sBuffer = sBuffer & sNextLine & vbCrLf
WrapText(nWrapLines) = WrapText(nWrapLines) & sNextLine
nWrapLines = nWrapLines + 1
ReDim Preserve WrapText(1 To nWrapLines)
WrapText(nWrapLines) = ""
sNextLine = ""
End If
Else
If Len(sText) > nLength Then
If nSymbol < 4 Then nSymbol = nSymbol + 1
Select Case nSymbol
Case 1
sMarker = ","
Case 2
sMarker = "="
Case 3
sMarker = "\"
Case 4
sMarker = "("
Case Else
sMarker = " "
' We got a problem: No marker-character to wrap and text is too long - Cut if off.
If nSize Then
WrapText(nWrapLines) = WrapText(nWrapLines) & sNextLine
sNextLine = ""
nWrapLines = nWrapLines + 1
ReDim Preserve WrapText(1 To nWrapLines)
WrapText(nWrapLines) = ""
End If
sNextLine = Left(sText, nLength)
sText = Mid$(sText, nLength + 1)
If Len(WrapText(nWrapLines) & sNextLine) > nLength Then
nWrapLines = nWrapLines + 1
ReDim Preserve WrapText(1 To nWrapLines)
End If
WrapText(nWrapLines) = sNextLine
sNextLine = ""
End Select
ElseIf nSize Then
If nSize + Len(sText) > nLength Then
'sBuffer = sBuffer & sNextLine & vbCrLf & sText & vbCrLf
WrapText(nWrapLines) = WrapText(nWrapLines) & sNextLine
nWrapLines = nWrapLines + 1
ReDim Preserve WrapText(1 To nWrapLines)
WrapText(nWrapLines) = sText
Else
'sBuffer = sBuffer & sNextLine & sText & vbCrLf
WrapText(nWrapLines) = WrapText(nWrapLines) & sNextLine & sText
End If
Exit Do
Else
'sBuffer = sBuffer & sText & vbCrLf
If Len(WrapText(nWrapLines) & sText) > nLength Then
nWrapLines = nWrapLines + 1
ReDim Preserve WrapText(1 To nWrapLines)
WrapText(nWrapLines) = ""
End If
WrapText(nWrapLines) = WrapText(nWrapLines) & sText
Exit Do
End If
End If
Loop
If nWrapLines > 1 Then
' Subtract any empty lines in the bottom
For nMark = nWrapLines To 2 Step -1
If Not EmptyString(WrapText(nMark)) Then
nWrapLines = nMark
Exit For
End If
Next
End If
Else
If IsMissing(nLength) Then
nLength = GetWidth
Else
nLength = CSng(nLength)
End If
' Set the size (scale 1:1)
frmMain.txtWrap.Width = nLength * 56.7
frmMain.txtWrap.Height = GetHeight * 56.7
' Set the font
CloneFont frmMain.txtWrap
' Set the text
frmMain.txtWrap.Text = sText
End If
End Sub
Private Function GetWrapLines() As Integer
If Page.Ruler = RULER_CHAR Then
GetWrapLines = nWrapLines
Else
GetWrapLines = SendMessageBynum(frmMain.txtWrap.hWnd, EM_GETLINECOUNT, 0, 0&)
End If
End Function
Private Function GetWrapText(nGetLine As Integer) As String
If Page.Ruler = RULER_CHAR Then
If nWrapLines = 0 Or nGetLine < 1 Or nGetLine > nWrapLines Then
GetWrapText = ""
Exit Function
End If
GetWrapText = WrapText(nGetLine)
Else
Dim nCharOffset As Long, nLineSize As Long
Dim sLineBuffer As String
' Find out the character offset to the first character in the specified line
nCharOffset = SendMessageBynum(frmMain.txtWrap.hWnd, EM_LINEINDEX, nGetLine - 1, 0&)
' The character offset is used to determine the length of the line
' containing that character.
nLineSize = SendMessageBynum(frmMain.txtWrap.hWnd, EM_LINELENGTH, nCharOffset, 0&) + 1
' Now allocate a string long enough to hold the result
sLineBuffer = String$(nLineSize + 2, 0)
Mid$(sLineBuffer, 1, 1) = Chr$(nLineSize And &HFF)
Mid$(sLineBuffer, 2, 1) = Chr$(nLineSize \ 256)
' Now get the line
nLineSize = SendMessageByString(frmMain.txtWrap.hWnd, EM_GETLINE, nGetLine - 1, sLineBuffer)
GetWrapText = Left$(sLineBuffer, nLineSize)
End If
End Function
Private Sub SaveWrap(ByRef TextHolder, ByRef TextLines)
Dim i As Integer
If Page.Ruler = RULER_CHAR Then
TextLines = nWrapLines
Else
TextLines = GetWrapLines
End If
ReDim TextHolder(1 To TextLines)
For i = 1 To TextLines
TextHolder(i) = RTrim(GetWrapText(i))
Next
End Sub
' -----------------------------------------------------------------------------------
' Check if there's enough room to print the sub line with some code (at least 2 lines of code)
'
Private Sub CheckAreaPrint(Optional nExtra)
Dim H As Single
If Page.Ruler = RULER_CHAR Then
H = 1
Else
PushFont
FontSet FONT_PROCS, False
H = GetTextHeight()
FontSet FONT_CODE, False
H = H + (GetTextHeight() * 2)
PopFont
End If
If Not IsMissing(nExtra) Then H = H + nExtra
If nYAvailable < H Then bNextPage = True
End Sub
Private Sub SeperatorPrint(Optional nOffset, Optional nStyle)
' Prevent line at bottom of page without any text below it.
If Page.Ruler = RULER_CHAR Then
CheckAreaPrint
Else
CheckAreaPrint 2
End If
If bNextPage Then Exit Sub
If IsMissing(nOffset) Then nOffset = 0
If IsMissing(nStyle) Then nStyle = vbSolid
Dim nCurY As Single
nCurY = GetCurrentY
If Page.Ruler = RULER_CHAR Then
PrintLine CSng(nOffset), nCurY, , , , CInt(nStyle)
PrintPSet 0, (nCurY + 1)
ReduceHeight 1
Else
PrintLine CSng(nOffset), nCurY + 1, , , , CInt(nStyle)
PrintPSet 0, (nCurY + 2)
ReduceHeight 2
End If
End Sub
Private Sub ReduceHeight(nUnits As Single)
nYAvailable = nYAvailable - nUnits
PrintProgress
End Sub
Private Sub HeaderPrint()
Dim H As Single, nCurX As Single
Dim sText As String, sPg As String
nCurX = GetCurrentX
PushFont
nPage = nPage + 1
If Page.Show Then PrintDialog "Formateando pagina " & nPage
If frmMain.chkHeader = vbChecked Then
sPg = "Pagina " & IIf(Page.Sample, "999", nPage)
If Page.Sample Then
sText = "Archivo (Formulario/Modulo/Clase/Control)"
ElseIf nMdlIndex = -1 Then
sText = ExtractFileName(frmMain.txtProject) & " (Proyecto)"
ElseIf nMdlIndex = -2 Then
sText = "Indice"
ElseIf nMdlIndex = -3 Then
sText = "Iconos"
Else
sText = Mdl(nMdlIndex).File
If Mdl(nMdlIndex).Type = MT_MODULE Then
sText = sText & " (Modulo - " & Mdl(nMdlIndex).Name & ")"
ElseIf Mdl(nMdlIndex).Type = MT_CLASS Then
sText = sText & " (Clase - " & Mdl(nMdlIndex).Name & ")"
ElseIf Mdl(nMdlIndex).Type = MT_CONTROL Then
sText = sText & " (Control de Usuario - " & Mdl(nMdlIndex).Name & ")"
ElseIf Mdl(nMdlIndex).Type = MT_PROPERTY Then
sText = sText & " (Pagina de Propiedades - " & Mdl(nMdlIndex).Name & ")"
ElseIf Mdl(nMdlIndex).Type = MT_DOCUMENT Then
sText = sText & " (Documento de Usuario - " & Mdl(nMdlIndex).Name & ")"
Else
sText = sText & " (Formulario - " & Mdl(nMdlIndex).Name & ")"
End If
End If
If Page.Output = OUT_PORT Then
If frmMain.optPagePos(0) And frmMain.chkPageNumbers = vbChecked Then
SetWrapObject sText, (GetWidth - (1 + Len(sPg)))
sText = Pad(RTrim(GetWrapText(1)), GetWidth - (1 + Len(sPg))) & " " & sPg
Else
SetWrapObject sText
sText = RTrim(GetWrapText(1))
End If
PrintAt 0, 0, sText
PrintLine 0, 1 ' Print the line
PrintPSet 0, 2
' Page number?
' If frmMain.optPagePos(0) And frmMain.chkPageNumbers = vbChecked Then
' PrintAt (GetWidth - Len(sPg)), 0, sPg
' End If
ElseIf Page.Output = OUT_RTF Then
FontSet FONT_HEADER
H = GetTextHeight(sText)
LayoutMode LYO_PAGE
If frmMain.optPagePos(0) And frmMain.chkPageNumbers = vbChecked Then
lp = AddLayout(LYO_TABS, 1, 0)
ReDim Layout(lp).Tabs(0 To 0)
Layout(lp).Tabs(0) = (GetWidth - (GetTextWidth(sPg) + 2.5)) * 56.7
SetWrapObject sText, (GetWidth - (GetTextWidth(sPg) + 5))
Else
SetWrapObject sText
End If
sText = RTrim(GetWrapText(1))
PrintPSet 1, 1
PrintPrint sText
If frmMain.optPagePos(0) And frmMain.chkPageNumbers = vbChecked Then
LayoutMode LYO_TAB
PrintAt (GetWidth - (GetTextWidth(sPg) + 2.5)), 1, sPg
End If
LayoutMode LYO_EOL
PrintLine 0, H + 2
H = H + 4
PrintPSet 0, H
Else
FontSet FONT_HEADER
H = GetTextHeight(sText)
' Print box first, so that the boxfill will not erase the text print
PrintBox 0, 0, GetWidth - 0.1, H + 2
If frmMain.optPagePos(0) And frmMain.chkPageNumbers = vbChecked Then
SetWrapObject sText, (GetWidth - (GetTextWidth(sPg) + 5))
Else
SetWrapObject sText
End If
sText = RTrim(GetWrapText(1))
PrintPSet 1, 1
PrintPrint sText
If frmMain.optPagePos(0) And frmMain.chkPageNumbers = vbChecked Then
PrintAt (GetWidth - (GetTextWidth(sPg) + 2.5)), 1, sPg
End If
H = H + 4
PrintPSet 0, H
End If
Else
PrintPSet 0, 0
End If
nYAvailable = nYHeight ' Reset available height
PrintProgress
bNextPage = False
PopFont
PrintFont
SetCurrentX nCurX
End Sub
Private Sub FooterPrint()
If Page.Cancelled Then Exit Sub
Dim sText As String, sPg As String
Dim nCurX As Single, H As Single
Dim nSize As Integer
nCurX = GetCurrentX
PushFont
If frmMain.chkFooter = vbChecked Then
If Page.Output = OUT_PORT Then
PrintLine 0, GetHeight - 3
Else
FontSet FONT_FOOTER
H = 2 * GetTextHeight(frmMain.txtOwner(0) + frmMain.txtOwner(1))
If Page.Output = OUT_RTF Then
' "Pad" lines to end
nYAvailable = nYAvailable - (H + 4)
FontSet FONT_CODE, False
If nYAvailable >= GetTextHeight Then
Dim i As Integer
FontSet FONT_CODE
nSize = Int(nYAvailable / GetTextHeight)
For i = 1 To nSize
LayoutMode LYO_EOL
Next
FontSet FONT_FOOTER
End If
PrintLine 0, GetHeight - (H + 2)
Else
PrintLine 0, GetHeight - (H + 2)
PrintLine 0, GetHeight - (H + 1.5)
End If
End If
sText = ""
If frmMain.chkDate = vbChecked Then
sText = Format(Now, "Medium Date")
If frmMain.chkTime = vbChecked Then
sText = sText & " - " & Format(Now, "Medium Time")
End If
ElseIf frmMain.chkTime = vbChecked Then
sText = Format(Now, "Medium Time")
End If
sPg = "Pagina " & IIf(Page.Sample, "999", nPage)
If Page.Output = OUT_PORT Then
If Len(Trim(sText)) > 0 Then
nSize = GetWidth - (Len(sText) + 1)
SetWrapObject frmMain.txtOwner(0), nSize
sText = Pad(GetWrapText(1), nSize) & " " & sText
Else
SetWrapObject frmMain.txtOwner(0)
sText = GetWrapText(1)
End If
PrintAt 0, GetHeight - 2, sText
If frmMain.optPagePos(1) And frmMain.chkPageNumbers = vbChecked Then
nSize = GetWidth - (Len(sPg) + 1)
SetWrapObject frmMain.txtOwner(1), nSize
sText = Pad(GetWrapText(1), nSize) & " " & sPg
Else
SetWrapObject frmMain.txtOwner(1)
sText = GetWrapText(1)
End If
PrintAt 0, GetHeight - 1, sText
ElseIf Page.Output = OUT_RTF Then
If Len(Trim(sText)) > 0 Then
lp = AddLayout(LYO_TABS, 1, 0)
ReDim Layout(lp).Tabs(0 To 0)
Layout(lp).Tabs(0) = (GetWidth - (GetTextWidth(sText) + 0.1)) * 56.7
SetWrapObject frmMain.txtOwner(0), (GetWidth - (GetTextWidth(sText) + 5))
Else
SetWrapObject frmMain.txtOwner(0)
End If
PrintAt 0, GetHeight - H, RTrim(GetWrapText(1))
If Len(Trim(sText)) > 0 Then
LayoutMode LYO_TAB
PrintAt GetWidth - (GetTextWidth(sText) + 0.1), GetHeight - H, sText
End If
LayoutMode LYO_EOL
If frmMain.optPagePos(1) And frmMain.chkPageNumbers = vbChecked Then
lp = AddLayout(LYO_TABS, 1, 0)
ReDim Layout(lp).Tabs(0 To 0)
Layout(lp).Tabs(0) = (GetWidth - (GetTextWidth(sPg) + 0.1)) * 56.7
SetWrapObject frmMain.txtOwner(1), (GetWidth - (GetTextWidth(sPg) + 2.5))
Else
SetWrapObject frmMain.txtOwner(1)
End If
sText = RTrim(GetWrapText(1))
PrintAt 0, GetHeight - GetTextHeight(sText), sText
If frmMain.optPagePos(1) And frmMain.chkPageNumbers = vbChecked Then
LayoutMode LYO_TAB
PrintAt (GetWidth - (GetTextWidth(sPg) + 0.1)), GetHeight - GetTextHeight(sPg), sPg
End If
LayoutMode LYO_EOL
Else
If Len(Trim(sText)) > 0 Then
PrintAt GetWidth - (GetTextWidth(sText) + 0.1), GetHeight - H, sText
SetWrapObject frmMain.txtOwner(0), (GetWidth - (GetTextWidth(sText) + 5))
Else
SetWrapObject frmMain.txtOwner(0)
End If
sText = RTrim(GetWrapText(1))
PrintAt 0, GetHeight - H, sText
If frmMain.optPagePos(1) And frmMain.chkPageNumbers = vbChecked Then
SetWrapObject frmMain.txtOwner(1), (GetWidth - (GetTextWidth(sPg) + 2.5))
PrintAt (GetWidth - (GetTextWidth(sPg) + 0.1)), GetHeight - GetTextHeight(sPg), sPg
Else
SetWrapObject frmMain.txtOwner(1)
End If
sText = RTrim(GetWrapText(1))
PrintAt 0, GetHeight - GetTextHeight(sText), sText
End If
End If
' Just for updating progress-bar (so that bar will give 100%)
nYAvailable = 0
PrintProgress
' Once footer is requested, do not let any printing occur on this page
nYAvailable = -1
PrintNewPage
If Page.Sample Then Page.Cancelled = True ' The end of the sample print...
PopFont
PrintFont
SetCurrentX nCurX
End Sub
' --------------------------------------------------------------------------------------------------------
Private Sub PrintProjectPage()
Dim i As Integer, n As Integer, nMax As Integer, _
nFileLines As Integer, nNameLines As Integer
Dim FileWrap() As String, NameWrap() As String
Dim sString As String
Dim nTextOffset As Single, nNameOffset As Single, _
nTextLength As Single, nNameLength As Single
Dim Pj As ProjectState
Dim bBold As Boolean
If Page.Cancelled Then Exit Sub
PrintDialog "Analizando " & ExtractFileName(frmMain.txtProject)
Pj = AnalyseVBP(frmMain.txtProject, Page.Form)
If Not Pj.Loaded Then Exit Sub
PrintDialog "Formateando"
' ----------------------------------------------------------------------------------
If Not InDevelopmentMode Then
On Error GoTo ProjectPrintError
End If
nMdlIndex = -1 ' It's a project.
nYAvailable = -1 ' Force header to print on first line to be printed
bNextPage = True ' Force new page
' PrintPSet 0, 0
' Print the information...
If Page.Output = OUT_DRIVER And Pj.IconPoint > -1 Then