home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Basic / GridOne / setup.EXE / PRINTGRID.CLS < prev    next >
Encoding:
Visual Basic class definition  |  2001-09-09  |  21.3 KB  |  709 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "PrintBeeGrid"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"No"
  16. Attribute VB_Ext_KEY = "Collection" ,"PrintLine"
  17. Attribute VB_Ext_KEY = "Member0" ,"PrintLine"
  18. Option Explicit
  19. ' ********************************************************************************
  20. ' * Description: Open, save and keep collection of print lines.
  21. ' *
  22. ' * Methods:
  23. ' *
  24. ' * Properties:
  25. ' *
  26. ' * Associations:
  27. ' * Events:
  28. ' * Revisions:
  29. ' *  12.02.1999   fml   Added comments.
  30. ' ********************************************************************************
  31. ' Mod INTERFACES
  32. ' Mod EVENTS
  33. Public Event LoadPages(Page As Long)
  34. Public Event PrinterChange()
  35. Public Event ChengePage(Page As Long)
  36. ' Mod CONSTANTS
  37. ' Mod ENUMS
  38. ' Mod TYPES
  39. Private miDestination As sgDestination
  40.  
  41. Public Enum sgDestination
  42.    sgPreview = 1
  43.    sgPrint = 2
  44. End Enum
  45. Public Enum sgOrientation
  46.    sgPortrait = 1
  47.    sgLandscape = 2
  48. End Enum
  49.  
  50. Public Enum sgPaperSize
  51.    sgLetter = 1 'Letter, 8 1/2 x 11 in.
  52.    sgLetterSmall = 2 'Letter Small, 8 1/2 x 11 in.
  53.    sgTabloid = 3 'Tabloid, 11 x 17 in.
  54.    sgLedger = 4 'Ledger, 17 x 11 in.
  55.    sgLegal = 5 'Legal, 8 1/2 x 14 in.
  56.    sgStatement = 6 'Statement, 5 1/2 x 8 1/2 in.
  57.    sgExecutive = 7 'Executive, 7 1/2 x 10 1/2 in.
  58.    sgA3 = 8 'A3, 297 x 420 mm
  59.    sgA4 = 9 'A4, 210 x 297 mm
  60.    sgA4Small = 10 'A4 Small, 210 x 297 mm
  61.    sgA5 = 11 'A5, 148 x 210 mm
  62.    sgB4 = 12 'B4, 250 x 354 mm
  63.    sgB5 = 13 'B5, 182 x 257 mm
  64.    sgFolio = 14 'Folio, 8 1/2 x 13 in.
  65.    sgQuarto = 15 'Quarto, 215 x 275 mm
  66.    sg10x14 = 16 '10 x 14 in.
  67.    sg11x17 = 17 '11 x 17 in.
  68.    sgNote = 18 'Note, 8 1/2 x 11 in.
  69.    sgEnv9 = 19 'Envelope #9, 3 7/8 x 8 7/8 in.
  70.    sgEnv10 = 20 'Envelope #10, 4 1/8 x 9 1/2 in.
  71.    sgEnv11 = 21 'Envelope #11, 4 1/2 x 10 3/8 in.
  72.    sgEnv12 = 22 'Envelope #12, 4 1/2 x 11 in.
  73.    sgEnv14 = 23 'Envelope #14, 5 x 11 1/2 in.
  74.    sgCSheet = 24 'C size sheet
  75.    sgDSheet = 25 'D size sheet
  76.    sgESheet = 26 'E size sheet
  77.    sgEnvDL = 27 'Envelope DL, 110 x 220 mm
  78.    sgEnvC3 = 29 'Envelope C3, 324 x 458 mm
  79.    sgEnvC4 = 30 'Envelope C4, 229 x 324 mm
  80.    sgEnvC5 = 28 'Envelope C5, 162 x 229 mm
  81.    sgEnvC6 = 31 'Envelope C6, 114 x 162 mm
  82.    sgEnvC65 = 32 'Envelope C65, 114 x 229 mm
  83.    sgEnvB4 = 33 'Envelope B4, 250 x 353 mm
  84.    sgEnvB5 = 34 'Envelope B5, 176 x 250 mm
  85.    sgEnvB6 = 35 'Envelope B6, 176 x 125 mm
  86.    sgEnvItaly = 36 'Envelope, 110 x 230 mm
  87.    sgEnvMonarch = 37 'Envelope Monarch, 3 7/8 x 7 1/2 in.
  88.    sgEnvPersonal = 38 'Envelope, 3 5/8 x 6 1/2 in.
  89.    sgFanfoldUS = 39 'U.S. Standard Fanfold, 14 7/8 x 11 in.
  90.    sgFanfoldStdGerman = 40 'German Standard Fanfold, 8 1/2 x 12 in.
  91.    sgFanfoldLglGerman = 41 'German Legal Fanfold, 8 1/2 x 13 in.
  92.    sgUser = 256 'User-defined
  93. End Enum
  94. ' Mod DECLARES
  95. ' Mod VARIABLES
  96. '---BeeGrid-----------------
  97. Private mGrid As SGGrid
  98. Private mGridProps As CGrid
  99. Public hImageList As Long
  100. '---Printer-----------------
  101. Private msDeviceName As String
  102. Private miPrinterOrientation As sgOrientation
  103. '---Preview-----------------
  104. Private WithEvents mPreview As PictureBox
  105. Attribute mPreview.VB_VarHelpID = -1
  106. '---Pages-------------------
  107. Private WithEvents mPages As Pages
  108. Attribute mPages.VB_VarHelpID = -1
  109. Private mobjCurrPage As Page
  110. Private mbRecalcPages As Boolean
  111. Private mDevice As ISGDevice
  112.  
  113.  
  114.  
  115.  
  116. Private Function CreateHeading(hdc As Long) As Long
  117.    Dim rc As RECT, pt As POINTAPI
  118.    Dim row As SGRow, I%
  119.    Dim cell As SGCell
  120.    Dim sCaption As String
  121.    Dim hbr As Long, pcs As PageColumns
  122.    Dim pc As PageColumn
  123.    Dim styapp As sgStyleAppearance
  124.    
  125.    Set row = mGrid.Rows.At(0)
  126.    
  127.    Call mGridProps.GetStyleAppearance("Heading", styapp)
  128.     
  129.    hbr = CreateSolidBrush(styapp.BackColor)
  130.    Set pcs = mGridProps.GetPageColumns(mobjCurrPage.Index)
  131.          
  132.    'use font from Heading style
  133.    Call mGridProps.SetFontFromStyle(mDevice, "Heading")
  134.    
  135.    For Each pc In pcs
  136.       Set cell = row.Cells(pc.Position)
  137.       
  138.       SetCellRect rc, pc, 0, cell.Height
  139.       
  140.       FillRect hdc, rc, hbr
  141.       If styapp.GridLines Then
  142.          MoveToEx hdc, rc.Left, rc.Top, pt
  143.          DrawLine hdc, styapp.BorderColor, rc.Right, rc.Top
  144.          DrawLine hdc, styapp.BorderColor, rc.Right, rc.Bottom
  145.          DrawLine hdc, styapp.BorderColor, rc.Left, rc.Bottom
  146.          DrawLine hdc, styapp.BorderColor, rc.Left, rc.Top
  147.          MoveToEx hdc, rc.Right, rc.Top, pt
  148.          DrawLine hdc, styapp.BorderColor, rc.Right, rc.Bottom + 1
  149.       End If
  150.       If Not styapp.Flat Then
  151.          rc.Left = rc.Left + 1: rc.Top = rc.Top + 1
  152.          MoveToEx hdc, rc.Left, rc.Bottom - 1, pt
  153.          DrawLine hdc, styapp.BorderHighlight, rc.Left, rc.Top
  154.          DrawLine hdc, styapp.BorderHighlight, rc.Right, rc.Top
  155.       End If
  156.       
  157.       rc.Left = rc.Left + 1: rc.Top = rc.Top + 1
  158.       
  159.       sCaption = cell.Column.Caption
  160.       
  161.       If Len(sCaption) = 0 Then
  162.          sCaption = cell.Column.Key
  163.       End If
  164.       
  165.       DrawText hdc, sCaption, Len(sCaption), rc, pc.HeaderTextAlignment
  166.    Next
  167.    
  168.    CreateHeading = rc.Right
  169.    Call DeleteObject(hbr)
  170.    'delete fonts
  171.    mGridProps.DeleteFont hdc
  172. End Function
  173.  
  174. Private Sub GetPrinterProps()
  175.  
  176.    On Error Resume Next
  177.  
  178.    If Printer Is Nothing Then Exit Sub
  179.    
  180.    Printer.ScaleMode = 3 'twips
  181.    Printer.Orientation = miPrinterOrientation
  182.    
  183.    If Printer.PaperSize = sgUser Then
  184.       If miPrinterOrientation = sgPortrait Then
  185.          Printer.Width = PrinterWidth
  186.          Printer.Height = PrinterHeight
  187.       Else
  188.          Printer.Height = PrinterWidth
  189.          Printer.Width = PrinterHeight
  190.       End If
  191.    Else
  192.       If miPrinterOrientation = sgPortrait Then
  193.          PrinterWidth = Printer.Width
  194.          PrinterHeight = Printer.Height
  195.       Else
  196.          PrinterWidth = Printer.Height
  197.          PrinterHeight = Printer.Width
  198.       End If
  199.    End If
  200.    
  201.    If Not mPreview Is Nothing Then
  202.       mPreview.Width = PrinterWidth
  203.       mPreview.Height = PrinterHeight
  204.    End If
  205.    
  206.    msDeviceName = Printer.DeviceName
  207.    
  208.    mbRecalcPages = True
  209. End Sub
  210.  
  211. '********************************************************************************
  212. '* Name: Printing
  213. '* Description: Print the grid to the particular DC
  214. '*
  215. '* Parameters: hdc - printer or picture box DC
  216. '* Created: Goran Borevkovic 04.12.2000 12:41:03
  217. '********************************************************************************
  218. Friend Sub Printing(hdc As Long)
  219.    Dim rc As RECT, rcImg As RECT, pt As POINTAPI
  220.    Dim cell As SGCell, row As SGRow, sCaption$
  221.    Dim lTop As Long, lOldTop As Long
  222.    Dim lBorderColor As Long, lBorder3D As Long
  223.    Dim iHeadingCol As Integer
  224.    Dim lWidth As Long, lHeight As Long
  225.    Dim I As Long, j As Integer
  226.    Dim pc As PageColumn, pcs As PageColumns
  227.    Dim lForeColor As Long
  228.    Dim styapp As sgStyleAppearance
  229.    Dim stygrp As sgStyleAppearance
  230.    Dim hbr As Long, lPadding As Long
  231.    Dim clsPicture As New CCellPicture
  232.    
  233.    If mGrid Is Nothing Then Exit Sub
  234.    
  235.    On Error GoTo PrintingError
  236.    'remove col heading
  237.    clsPicture.Destination = Destination
  238.    mGrid.RedrawEnabled = False
  239.    iHeadingCol = mGrid.HeadingColCount
  240.    mGrid.HeadingColCount = 0
  241.    'print header
  242.    lWidth = CreateHeading(hdc)
  243.    'use font from Normal style
  244.    Call mGridProps.SetFontFromStyle(mDevice, "Normal")
  245.    'get border color
  246.    lBorderColor = GetSysColor(COLOR_BTNFACE)
  247.    
  248.    lOldTop = mGridProps.CalculateHeight(mGrid.Rows.At(I).Height)
  249.    Call mGridProps.GetStyleAppearance("Normal", styapp)
  250.    
  251.    Set pcs = mGridProps.GetPageColumns(mobjCurrPage.Index)
  252.    clsPicture.ImageList = hImageList
  253.    
  254.    For I = mobjCurrPage.FirstRow To mobjCurrPage.LastRow
  255.       Set row = mGrid.Rows.At(I)
  256.       rc.Left = mPages.Margins.Left / mDevice.TwipsPerPixelX
  257.       rc.Top = ((lOldTop + mPages.Margins.Top) / mDevice.TwipsPerPixelY)
  258.       lHeight = mGridProps.CalculateHeight(row.Cells(0).Height)
  259.       rc.Right = lWidth: rc.Bottom = (lHeight / mDevice.TwipsPerPixelY) + rc.Top
  260.       
  261.       Select Case row.Type
  262.          Case sgSimpleRow
  263.             rc.Top = rc.Top - 1
  264.             If styapp.GridLines Then
  265.                MoveToEx hdc, rc.Right, rc.Top, pt
  266.                DrawLine hdc, lBorderColor, rc.Right, rc.Bottom
  267.                DrawLine hdc, lBorderColor, rc.Left, rc.Bottom
  268.                DrawLine hdc, lBorderColor, rc.Left, rc.Top
  269.             End If
  270.             
  271.             For Each pc In pcs
  272.                Set cell = row.Cells(pc.Position)
  273.                SetCellRect rc, pc, lOldTop, lHeight
  274.                
  275.                If styapp.GridLines Then
  276.                   MoveToEx hdc, rc.Right, rc.Top, pt
  277.                   DrawLine hdc, lBorderColor, rc.Right, rc.Bottom + 1
  278.                End If
  279.                
  280.                If cell.Style.DisplayType = sgDisplayPicture Or _
  281.                      cell.Style.DisplayType = sgDisplayTextAndPicture Then
  282.                   clsPicture.PictureAlignment = pc.PictureAlignment
  283.                   clsPicture.DrawPicture hdc, cell, rc.Left, rc.Top, rc.Right, rc.Bottom
  284.                   rc.Left = clsPicture.TextLeft
  285.                   rc.Right = clsPicture.TextRight
  286.                End If
  287.                
  288.                If cell.Style.DisplayType = sgDisplayText Or _
  289.                   cell.Style.DisplayType = sgDisplayTextAndPicture Then
  290.                   If Not IsNull(cell.Value) Then
  291.                      lPadding = pc.Padding / mDevice.TwipsPerPixelX
  292.                      rc.Left = rc.Left + lPadding: rc.Top = rc.Top + lPadding
  293.                      rc.Right = rc.Right - lPadding: rc.Bottom = rc.Bottom - lPadding
  294.                      sCaption = cell.Value
  295.                      DrawText hdc, sCaption, Len(sCaption), rc, pc.TextAlignment
  296.                   End If
  297.                End If
  298.             Next
  299.          Case sgGroupHeader, sgGroupFooter
  300.                If styapp.GridLines Then
  301.                   MoveToEx hdc, rc.Right, rc.Top, pt
  302.                   DrawLine hdc, lBorderColor, rc.Right, rc.Bottom
  303.                   DrawLine hdc, lBorderColor, rc.Left, rc.Bottom
  304.                   DrawLine hdc, lBorderColor, rc.Left, rc.Top
  305.                End If
  306.                mGridProps.DeleteFont hdc
  307.                If row.Type = sgGroupHeader Then
  308.                   Call mGridProps.SetFontFromStyle(mDevice, "GroupHeader")
  309.                   Call mGridProps.GetStyleAppearance("GroupHeader", stygrp)
  310.                Else
  311.                   Call mGridProps.SetFontFromStyle(mDevice, "GroupFooter")
  312.                   Call mGridProps.GetStyleAppearance("GroupFooter", stygrp)
  313.                End If
  314.                
  315.                If stygrp.BackColor <> vbWhite Then
  316.                   hbr = CreateSolidBrush(stygrp.BackColor)
  317.                   FillRect hdc, rc, hbr
  318.                   Call DeleteObject(hbr)
  319.                End If
  320.                
  321.                sCaption = row.Cells(0).Value
  322.                rc.Left = rc.Left + 2
  323.                rc.Top = rc.Top + 2
  324.                DrawText hdc, sCaption, Len(sCaption), rc, 0
  325.                
  326.                mGridProps.DeleteFont hdc
  327.                Call mGridProps.SetFontFromStyle(mDevice, "Normal")
  328.       End Select
  329.       lOldTop = lOldTop + lHeight
  330.    Next
  331.    
  332.    mGrid.HeadingColCount = iHeadingCol
  333.    mGrid.RedrawEnabled = True
  334.    'delete fonts
  335.    mGridProps.DeleteFont hdc
  336.    Exit Sub
  337. PrintingError:
  338.    'MsgBox VBA.Error
  339.    'Debug.Print "Printing: " & VBA.Error
  340.    Resume Next
  341. End Sub
  342.  
  343. Private Sub DrawLine(hdc As Long, clr As Long, x As Long, Y As Long)
  344.    Dim hPen As Long
  345.    Dim hOldPen As Long
  346.    ' Create pen
  347.    hPen = CreatePen(0, 1, clr)
  348.    hOldPen = SelectObject(hdc, hPen)
  349.    LineTo hdc, x, Y
  350.    ' Release pen
  351.    SelectObject hdc, hOldPen
  352.    DeleteObject hPen
  353. End Sub
  354.  
  355. '********************************************************************************
  356. '* Name: PrintGrid
  357. '* Description:
  358. '*
  359. '* Parameters:
  360. '* Created: Goran Borevkovic 11.12.2000 13:22:01
  361. '********************************************************************************
  362. Public Sub PrintGrid()
  363.    Dim hdc As Long
  364.    Dim lpdi As DOCINFO
  365.    Dim I As Long
  366.    
  367.    On Error Resume Next
  368.       
  369.    RecalcPages
  370.    
  371.    If mPages.Count = 0 Then Exit Sub
  372.    
  373.    Select Case miDestination
  374.       Case sgPreview
  375.          Set mDevice = New CPreview
  376.          Set mDevice.Destination = mPreview
  377.       Case sgPrint
  378.          Set mDevice = New CPrinter
  379.    End Select
  380.    
  381.    Set mobjCurrPage = mPages(1)
  382.    
  383.    Set mDevice.PrintGrid = Me
  384.    
  385.    mDevice.PrintReport
  386.    
  387. End Sub
  388.  
  389. Private Sub SetCellRect(rc As RECT, pc As PageColumn, lTop As Long, lHeight As Long)
  390.    
  391.    rc.Left = ((pc.Left + mPages.Margins.Left) / mDevice.TwipsPerPixelX)
  392.    rc.Top = ((lTop + mPages.Margins.Top) / mDevice.TwipsPerPixelY)
  393.    
  394.    rc.Right = (pc.Width / mDevice.TwipsPerPixelX) + rc.Left
  395.    rc.Bottom = (lHeight / mDevice.TwipsPerPixelY) + rc.Top
  396.    
  397. End Sub
  398. Friend Sub PreviewPage(direction As String)
  399.    
  400.    Select Case direction
  401.       Case S_CMD_FIRST
  402.          mPages.CurrentPage = 1
  403.       Case S_CMD_PREV
  404.          If mobjCurrPage.Index > 1 Then _
  405.             mPages.CurrentPage = mobjCurrPage.Index - 1
  406.       Case S_CMD_NEXT
  407.          If mobjCurrPage.Index < mPages.Count Then _
  408.             mPages.CurrentPage = mobjCurrPage.Index + 1
  409.       Case S_CMD_LAST
  410.          mPages.CurrentPage = mPages.Count
  411.    End Select
  412.    
  413. End Sub
  414.  
  415. Private Sub SetPrinterProp()
  416.    On Error Resume Next
  417.  
  418.    Exit Sub
  419.    '---Set printer-----
  420.    If Len(msDeviceName) = 0 Then
  421.       msDeviceName = Printer.DeviceName
  422.    Else
  423.       If Printer.DeviceName <> msDeviceName Then
  424.          Dim oPrinter As Printer
  425.          
  426.          For Each oPrinter In Printers
  427.             If oPrinter.DeviceName = msDeviceName Then
  428.                Set Printer = oPrinter
  429.                Exit For
  430.             End If
  431.          Next
  432.       End If
  433.    End If
  434.  
  435.    If Printer.PaperSize = vbPRPSUser Then  'User-defined
  436.       Printer.Width = mPages.PrinterWidth
  437.       Printer.Height = mPages.PrinterHeight
  438.    End If
  439.    
  440.    Printer.Orientation = miPrinterOrientation
  441. End Sub
  442.  
  443.  
  444.  
  445. Private Sub Class_Initialize()
  446.    Set mPages = New Pages
  447.             
  448.    miDestination = sgPrint
  449.    miPrinterOrientation = Printer.Orientation
  450.    GetPrinterProps
  451. End Sub
  452.  
  453. Private Sub Class_Terminate()
  454.  
  455.    Set mDevice = Nothing
  456.    '---del controls----------
  457.    Set mPreview = Nothing
  458.    '---del print items
  459.    Set mGridProps = Nothing
  460.    Set mGrid = Nothing
  461.    Set mobjCurrPage = Nothing
  462.    Set mPages = Nothing
  463. End Sub
  464.  
  465.  
  466.  
  467.  
  468. Public Property Get PrinterWidth() As Single
  469.    PrinterWidth = mPages.PrinterWidth
  470. End Property
  471.  
  472. Public Property Let PrinterWidth(ByVal vNewValue As Single)
  473.    mPages.PrinterWidth = vNewValue
  474.    If Printer.PaperSize = sgUser Then
  475.       GetPrinterProps
  476.    End If
  477. End Property
  478.  
  479. Public Property Get PrinterHeight() As Single
  480.    PrinterHeight = mPages.PrinterHeight
  481. End Property
  482.  
  483. Public Property Let PrinterHeight(ByVal vNewValue As Single)
  484.    mPages.PrinterHeight = vNewValue
  485.    If Printer.PaperSize = sgUser Then
  486.       GetPrinterProps
  487.    End If
  488. End Property
  489.  
  490.  
  491.  
  492.  
  493.  
  494. Private Sub mPages_Change()
  495.    If mPages Is Nothing Then Exit Sub
  496.  
  497.    On Error Resume Next
  498.    
  499.    Set mobjCurrPage = mPages(mPages.CurrentPage)
  500.  
  501.    If mobjCurrPage Is Nothing Then Exit Sub
  502.  
  503.    mDevice.PrintReport
  504.    mPreview.Refresh
  505.    
  506.    RaiseEvent ChengePage(mobjCurrPage.Index)
  507. End Sub
  508.  
  509. Private Sub mPages_Refresh()
  510.    mbRecalcPages = True
  511. End Sub
  512.  
  513. Private Sub mPreview_Paint()
  514.    If mDevice Is Nothing Then Exit Sub
  515.  
  516.    mDevice.Paint
  517. End Sub
  518.  
  519. Public Property Get DeviceName() As String
  520.    DeviceName = msDeviceName
  521. End Property
  522.  
  523. Public Property Let DeviceName(ByVal vNewValue As String)
  524.    msDeviceName = vNewValue
  525. End Property
  526.  
  527.  
  528. Public Property Get PrinterOrientation() As sgOrientation
  529.    PrinterOrientation = miPrinterOrientation
  530. End Property
  531.  
  532. Public Property Let PrinterOrientation(ByVal vNewValue As sgOrientation)
  533.    miPrinterOrientation = vNewValue
  534.    GetPrinterProps
  535. End Property
  536.  
  537. Public Property Get PaperSize() As sgPaperSize
  538.    PaperSize = Printer.PaperSize
  539. End Property
  540.  
  541. Public Property Let PaperSize(ByVal vNewValue As sgPaperSize)
  542.    On Error GoTo PaperSizeError
  543.  
  544.    Printer.PaperSize = vNewValue
  545.    GetPrinterProps
  546.    
  547.    Exit Property
  548. PaperSizeError:
  549.    MsgBox VBA.Error, vbExclamation
  550.    Exit Property
  551. End Property
  552.  
  553.  
  554.  
  555.  
  556.  
  557. Public Property Get Grid() As Object
  558.    Set Grid = mGrid
  559. End Property
  560.  
  561. Public Property Set Grid(ByVal vNewValue As Object)
  562.    Set mGrid = vNewValue
  563.    Set mGridProps = New CGrid
  564.    Set mGridProps.Grid = mGrid
  565. End Property
  566.  
  567. '********************************************************************************
  568. '* Name: RecalcPages
  569. '* Description:
  570. '*
  571. '* Parameters:
  572. '* Created: Goran Borevkovic 04.12.2000 12:42:48
  573. '********************************************************************************
  574. Friend Sub RecalcPages()
  575.    Dim cell As SGCell, row As SGRow
  576.    Dim col As SGColumn, iLastCol As Integer, lLastRow As Long
  577.    Dim lTop As Long, lOldTop As Long
  578.    Dim lWidth As Long, lHeight As Long
  579.    Dim iHeadingCol As Integer, iHeadingRow%, I&
  580.    Dim colPage As New Collection
  581.    Dim pg As Page, lCurrLeft As Long
  582.    Dim pgcols As PageColumns, lPage As Long
  583.    Dim pgcol As PageColumn
  584.    
  585.    On Error GoTo RecalcPagesError
  586.  
  587.    If Not mbRecalcPages Then Exit Sub
  588.    
  589.    If mGrid Is Nothing Then Exit Sub
  590.    
  591.    mGrid.RedrawEnabled = False
  592.    iHeadingCol = mGrid.HeadingColCount
  593.    iHeadingRow = mGrid.HeadingRowCount
  594.    mGrid.HeadingColCount = 0
  595.    
  596.    mGridProps.ClearPageCols
  597.    mPages.Clear
  598.    Set pgcols = mGridProps.AddPageColumns
  599.    
  600.    For I = 0 To mGrid.Columns.Count - 1
  601.       Set col = mGrid.Columns.At(I)
  602.       If Not col.Hidden Then
  603.          lWidth = lWidth + mGridProps.CalculateWidth(col.Width)
  604.          If lWidth >= mPages.ScaleWidth Then
  605.             colPage.Add mPages.Add(iLastCol, I - 1)
  606.             iLastCol = I: lCurrLeft = 0
  607.             lWidth = mGridProps.CalculateWidth(col.Width)
  608.             Set pgcols = mGridProps.AddPageColumns
  609.          End If
  610.          Set pgcol = pgcols.Add(CInt(I), lCurrLeft, mGridProps.CalculateWidth(col.Width))
  611.          pgcol.TextAlignment = mGridProps.GetColAlignment(col)
  612.          pgcol.HeaderTextAlignment = mGridProps.GetColAlignment(col, True)
  613.          pgcol.Padding = mGridProps.GetPadding(col)
  614.          pgcol.PictureAlignment = mGridProps.GetPictureAlignment(col)
  615.          lCurrLeft = lCurrLeft + mGridProps.CalculateWidth(col.Width)
  616.       End If
  617.    Next
  618.    
  619.    colPage.Add mPages.Add(iLastCol, mGrid.Columns.Count - 1)
  620.    lHeight = mGridProps.CalculateHeight(mGrid.Rows.At(0).Height)
  621.    
  622.    For I = iHeadingRow To mGrid.Rows.Count - 1
  623.       Set row = mGrid.Rows.At(I)
  624.       lHeight = lHeight + mGridProps.CalculateHeight(row.Height)
  625.       If lHeight >= mPages.ScaleHeight Then
  626.          If lLastRow = 0 Then
  627.             For Each pg In mPages
  628.                pg.FirstRow = iHeadingRow: pg.LastRow = I - 1
  629.                lPage = lPage + 1
  630.                RaiseEvent LoadPages(lPage)
  631.             Next
  632.          Else
  633.             For Each pg In colPage
  634.                Call mPages.Add(pg.FirstColumn, pg.LastColumn, lLastRow, I - 1)
  635.                lPage = lPage + 1
  636.                RaiseEvent LoadPages(lPage)
  637.             Next
  638.          End If
  639.          lHeight = mGridProps.CalculateHeight(mGrid.Rows.At(0).Height)
  640.          lHeight = lHeight + mGridProps.CalculateHeight(row.Height)
  641.          lLastRow = I
  642.       End If
  643.    Next
  644.    
  645.    If lLastRow <> mGrid.Rows.Count - 1 Then
  646.          If lLastRow = 0 Then
  647.             For Each pg In mPages
  648.                pg.FirstRow = iHeadingRow: pg.LastRow = mGrid.Rows.Count - 1
  649.                lPage = lPage + 1
  650.                RaiseEvent LoadPages(lPage)
  651.             Next
  652.          Else
  653.             For Each pg In colPage
  654.                Call mPages.Add(pg.FirstColumn, _
  655.                   pg.LastColumn, lLastRow, mGrid.Rows.Count - 1)
  656.                lPage = lPage + 1
  657.                RaiseEvent LoadPages(lPage)
  658.             Next
  659.          End If
  660.    End If
  661.    
  662.    mGrid.HeadingColCount = iHeadingCol
  663.    mGrid.RedrawEnabled = True
  664.    mbRecalcPages = False
  665.    Exit Sub
  666. RecalcPagesError:
  667.    MsgBox VBA.Error, vbExclamation
  668.    Exit Sub
  669. End Sub
  670.  
  671.  
  672. Public Property Get Pages() As Pages
  673.    Set Pages = mPages
  674. End Property
  675.  
  676. Public Property Set Pages(ByVal vNewValue As Pages)
  677.    Set mPages = Pages
  678. End Property
  679.  
  680.  
  681.  
  682.  
  683. Friend Property Get Container() As PictureBox
  684.    Set Container = mPreview
  685. End Property
  686.  
  687. Friend Property Set Container(ByVal vNewValue As PictureBox)
  688.    Set mPreview = vNewValue
  689.     
  690.    mPreview.Width = PrinterWidth
  691.    mPreview.Height = PrinterHeight
  692. End Property
  693.  
  694. Friend Property Get Destination() As sgDestination
  695.    Destination = miDestination
  696. End Property
  697.  
  698. Friend Property Let Destination(ByVal vNewValue As sgDestination)
  699.    miDestination = vNewValue
  700. End Property
  701.  
  702. Friend Property Get SelectedPage() As Page
  703.    Set SelectedPage = mobjCurrPage
  704. End Property
  705.  
  706. Friend Property Set SelectedPage(ByVal vNewValue As Page)
  707.    Set mobjCurrPage = vNewValue
  708. End Property
  709.