VERSION 2.00
Begin Form frmSelectStencil 
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   3  'Fixed Double
   ClientHeight    =   2760
   ClientLeft      =   1680
   ClientTop       =   2040
   ClientWidth     =   4440
   Height          =   3165
   Left            =   1620
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2760
   ScaleWidth      =   4440
   Top             =   1695
   Width           =   4560
   Begin PictureBox Picture1 
      BackColor       =   &H00C0C0C0&
      BorderStyle     =   0  'None
      Height          =   615
      Left            =   -240
      ScaleHeight     =   615
      ScaleWidth      =   5055
      TabIndex        =   3
      Top             =   2160
      Width           =   5055
      Begin CommandButton Next 
         BackColor       =   &H00C0C0C0&
         Caption         =   "&Next >"
         Default         =   -1  'True
         Height          =   375
         Left            =   3720
         TabIndex        =   7
         Top             =   120
         Width           =   855
      End
      Begin CommandButton Previous 
         Caption         =   "<"
         Height          =   375
         Left            =   3240
         TabIndex        =   6
         Top             =   120
         Width           =   495
      End
      Begin CommandButton Cancel 
         Caption         =   "&Cancel"
         Height          =   375
         Left            =   1800
         TabIndex        =   5
         Top             =   120
         Width           =   975
      End
      Begin CommandButton First 
         Caption         =   "|<<"
         Height          =   375
         Left            =   2760
         TabIndex        =   4
         Top             =   120
         Width           =   495
      End
   End
   Begin ComboBox Combo1 
      BackColor       =   &H00FFFFFF&
      ForeColor       =   &H00000000&
      Height          =   300
      Left            =   360
      Sorted          =   -1  'True
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   1320
      Width           =   3735
   End
   Begin SSFrame Frame3D1 
      Caption         =   "&Select Stencil"
      Font3D          =   0  'None
      Height          =   1095
      Left            =   120
      TabIndex        =   1
      Top             =   840
      Width           =   4215
   End
   Begin Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "Which stencil do you want to report on? Select a stencil from the list of open stencils."
      ForeColor       =   &H00404040&
      Height          =   495
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   3975
   End
End
Option Explicit

Sub Cancel_Click ()
    End
End Sub

Sub First_Click ()
    Beep
End Sub

Sub Form_Load ()
    Dim stat
    Dim doc As object
    Dim docs As object
    Dim i
    Dim template
    
    ' Make sure Visio is running.
    '
    appConnect

    ' Initialize application.
    '
    appInit

    ' Initialize form.
    '
    formInit frmSelectStencil

    ' Initialize controls.
    '
    first.Enabled = False
    previous.Enabled = False

    'Check if Visio is running in-place
    Call CheckIfInPlace

    ' Fill combo box with the list of open stencils.
    ' It is an error if there are no open stencils.
    '
    Set docs = g_appVisio.documents
    For i = 1 To docs.count
        Set doc = docs(i)
        If UCase(Right(doc.Name, 3)) = "VSS" Then
            combo1.AddItem doc.FullName
        End If
    Next
    If combo1.ListCount > 0 Then
        combo1.ListIndex = 0
    Else
        stat = appMessage(ERR_FATAL, ERR_NOSTENCILS)
    End If

    '   Create new document.
    '
    template = app.Path & "\" & app.EXEName & ".VST"
    Debug.Print "Template = " & template
    Set gDocDraw = g_appVisio.documents.Add(template)
    Set gWinDraw = g_appVisio.ActiveWindow

End Sub

Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
    End
End Sub

'   Validate form settings.
'
Function formValid ()
    Dim stencil As object
    Dim master As object
    Dim masters As object
    Dim pageSheet As object         ' background page's page sheet
    Dim masterSheet As object       ' master's page sheet

    Dim masterDrawingScale
    Dim masterPageScale
    Dim pageDrawingScale
    Dim pagePageScale
    Dim drawingScale
    Dim pageScale
    Dim pageWidth
    Dim pageHeight
    Dim stat

    formValid = True    ' default return value

    '   Get stencil name
    '
    gDoc.filename = combo1.Text

    '   Get drawing scale and page scale.
    '
    Set stencil = g_appVisio.documents(gDoc.filename)
    Set masters = stencil.masters
    If masters.count = 0 Then
        stat = appMessage(ERR_FATAL, ERR_NOMASTERS)
    End If

    '   We assume that there is at least one master and that
    '   all masters in the stencil have the same scale.
    '
    Set master = masters(1)     ' assume all masters have same scale
    Set masterSheet = master.Shapes("ThePage")

    ' Page setup for background page.
    '
    Set gPageBack = gDocDraw.Pages.Item(1)
    gPageBack.Name = STR_BACKGROUND
    gPageBack.Background = True
    
    ' Set page scale and size for background page.
    '
    Set pageSheet = gPageBack.Shapes("ThePage")
    masterDrawingScale = masterSheet.Cells("DrawingScale").formula
    masterPageScale = masterSheet.Cells("PageScale").formula
    pageDrawingScale = pageSheet.Cells("DrawingScale").formula
    pagePageScale = pageSheet.Cells("PageScale").formula

    If (masterDrawingScale <> pageDrawingScale Or masterPageScale <> pagePageScale) Then
        ' Drawing Scale = Custom
        pageSheet.Cells("DrawingScaleType").formula = 3
        pageSheet.Cells("DrawingScale").formula = masterDrawingScale
        pageSheet.Cells("PageScale").formula = masterPageScale
        ' Drawing Size = Dimensions
        drawingScale = masterSheet.Cells("DrawingScale")
        pageScale = masterSheet.Cells("PageScale")
        pageHeight = pageSheet.Cells("PageHeight")
        pageWidth = pageSheet.Cells("PageWidth")

        pageSheet.Cells("PageHeight").formula = pageHeight * drawingScale / pageScale
        pageSheet.Cells("PageWidth").formula = pageWidth * drawingScale / pageScale
    End If

End Function

Sub Next_Click ()
    If formValid() = True Then
        Hide
        frmSelectLook.Show
    End If
End Sub

Sub Previous_Click ()
    Beep
End Sub

