PrecedenteIndiceSuccessiva

74 - Planner - Stampa

REM  *****  BASIC  *****


Option Explicit


Const RighePerPagina = 16



Sub Display (elements() as Object)
  Dim iI As Integer
  For iI = LBound (elements) to UBound (elements)
    msgbox "Nome " & iI & " di " & UBound (elements) & " = " & elements(iI)
  next iI

End Sub


Sub Stampa (fronti As Boolean)
  ' 1 = Ok;0 = Annulla
  Dim iDialogResult     As Integer
  Dim oDialogDesc       As Object
  Dim oDialog           As Object
  Dim oDialogModel      As Object
  Dim sNome       As String
  Dim oRange        As Object
  Dim oControl      As Object
  Dim oDimensioni     As Object
  Dim iNumPages     As Integer
  Dim iPrima        As Integer
  Dim iUltima       As Integer
  Dim oPageStyles     As Object
  Dim oDefPage      As Object
  Dim oDocument       As Object
  Dim oDispatcher     As Object
  Dim bErrori       As Boolean

  Dim iLeftMargin     As Integer
  Dim oLeftMarginRange  As Object
  

  if fronti then
    sNome = "Stampa Fronti"

    oRange = ThisComponent.NamedRanges.GetByName("Fronte").ReferredCells
    oLeftMarginRange = ThisComponent.NamedRanges.GetByName("Sinistra_Fronti").ReferredCells

  else

    sNome = "Stampa Retri"
    oRange = ThisComponent.NamedRanges.GetByName("Retro").ReferredCells

    oLeftMarginRange = ThisComponent.NamedRanges.GetByName("Sinistra_Retri").ReferredCells
  endif



  iLeftMargin = getLeftMargin (oLeftMarginRange(1,1).getValue(), fronti)
  ' msgBox iLeftMargin



  oDimensioni = oRange.getRangeAddress()
  iNumPages = (oDimensioni.EndRow - oDimensioni.StartRow) / RighePerPagina



  ' Get dialog description from the dialog library
  DialogLibraries.LoadLibrary("Standard")
  oDialogDesc                =  DialogLibraries.Standard.PrintDialog



  ' create the dialog
  oDialog             =  CreateUnoDialog( oDialogDesc )
  oDialogModel        =  oDialog.Model



  Rem Dimensiona il dialog per contenere i campi e i pulsanti 
  oDialogModel.Width = 129
  oDialogModel.Height = 55

  

  oDialog.setTitle (sNome)


  ' msgbox oControl.Dbg_Methods
  ' msgbox oControl.Dbg_Properties

  Rem imposta i campi con il range  
  oControl    = oDialog.getControl("DaPagina")
  oControl.Max  = iNumPages + 1

  oControl    = oDialog.getControl("APagina")
  oControl.Max  = iNumPages + 1
  oControl    = oDialog.getControl("LeftMargin")
  oControl.Value  = iLeftMargin

  Do

    bErrori = False
    Rem Reimposta i limiti
    oControl    = oDialog.getControl("DaPagina")
    oControl.Value  = 1

    oControl    = oDialog.getControl("APagina")
    oControl.Value  = iNumPages
    ' start the dialog
    iDialogResult              =  oDialog.Execute()
    oControl    = oDialog.getControl("DaPagina")
    iPrima = oControl.Value

    oControl    = oDialog.getControl("APagina")
    iUltima = oControl.Value
    oControl    = oDialog.getControl("LeftMargin")
    iLeftMargin = getLeftMargin (oControl.Value, fronti)
    if iDialogResult = 1 then
      if iPrima > iUltima then
        msgBox "L'ultima pagina non deve essere minore della prima"

        bErrori = True
      endIf

      if iPrima < 1 then
        msgBox "La prima pagina deve essere compresa tra 1 e " & iNumPages

        bErrori = True
      endif

      if iUltima > iNumPages then
        msgBox "L'ultima pagina deve essere compresa tra 1 e " {amp} iNumPages

        bErrori = True
      endif

    endIf

  Loop While bErrori



  oDialog.Dispose()
  

  ' msgbox "Risultato = " {amp} iDialogResult {amp} " Da pagina " {amp} iPrima {amp} " A pagina " {amp} iUltima


  if iDialogResult = 1 then
    oLeftMarginRange(1,1).setValue(iLeftMargin)
    Rem Imposta le caratteristiche della pagina

    oPageStyles = ThisComponent.StyleFamilies.PageStyles ' getByName("PageStyles")
    ' msgbox oPageStyles.Dbg_Methods ' Dbg_Properties ' Dbg_Methods

    ' Display (oPageStyles.ElementNames)
    ' oDefPage = oPageStyles.getByName("TAB_Planner")
    ' Stili: (Stndard) Default Report TAB_Planner TAB_Database Date TAB_Database impegni
    oDefPage = oPageStyles.TAB_Planner ' Report ' Standard  ' TAB_Planner

    oDefPage.IsLandscape = TRUE
    oDefPage.LeftMargin = iLeftMargin
    oDefPage.RightMargin = 1000

    oDefPage.CenterHorizontally = FALSE
    oDefPage.CenterVertically = TRUE
    oDefPage.HeaderIsOn = FALSE

    oDefPage.FooterIsOn = FALSE
    oDefPage.PrintAnnotations = FALSE
    oDefPage.PrintGrid = FALSE

    oDefPage.PrintHeaders = FALSE
    oDefPage.PrintCharts = FALSE
    oDefPage.PrintObjects = FALSE

    oDefPage.PrintDrawing = TRUE
    oDefPage.PrintDownFirst = TRUE
    oDefPage.PrintFormulas = FALSE

    oDefPage.PrintZeroValues = FALSE
    Rem Ripristina i nuovi valori
    ' oPageStyles.insertByName ("Pippo", oDefPage)
    

    ThisComponent.enableAutomaticCalculation(False)
    ThisComponent.LockControllers




    rem get access to the document
    oDocument   = ThisComponent.CurrentController.Frame
    oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")



    Rem Ridimensiona il range in base alle scelte del dialog precednte
    oRange = oRange.getCellRangeByPosition (0,(iPrima - 1) * RighePerPagina, _

      oDimensioni.EndColumn - oDimensioni.StartColumn, iUltima * RighePerPagina - 1)
    Rem Seleziona le celle da stampare
    ThisComponent.CurrentController.Select(oRange)



    Rem Imposta l'area di stampa
    oDispatcher.executeDispatch(oDocument, ".uno:DefinePrintArea", "", 0, Array())



    rem Si riposiziona all'inizio per eliminare la selezione
    dim aArgs(0) as new com.sun.star.beans.PropertyValue
    aArgs(0).Name = "ToPoint"

    aArgs(0).Value = "$A$1"
    oDispatcher.executeDispatch(oDocument, ".uno:GoToCell", "", 0, aArgs())



    dim aPrintProperties(0) as new com.sun.star.beans.PropertyValue
    aPrintProperties(0).Name = "Pages"

    aPrintProperties(0).Value = iPrima & "-" & iUltima
    ThisComponent.print (Array()) ' aPrintProperties ())



    ThisComponent.UnlockControllers

    ThisComponent.enableAutomaticCalculation(true)
  endif

End Sub


Function getLeftMargin (proposed as Integer, Fronti As Boolean)
  if (proposed < 1000) then
    if fronti then
      Rem Aggiusta i bordi per i fronti

      Rem Oo 2.0 -{gt} 680
      Rem NeoOficeJ -{gt} 645
      if GetSolarVersion () = 680 then ' OpenOffice 2.0

        proposed = 1700
      else  ' NeoOfficeJ
        proposed = 1500
      endif


    else

      Rem Aggiusta i bordi per i retri
      if GetSolarVersion () = 680 then ' OpenOffice 2.0

        proposed = 2600
      else  ' NeoOfficeJ
        proposed = 2000
      endif


    endif

  endif

  getLeftMargin = proposed
end Function



Sub Main


End Sub

Le macro - Stampa

© Ing. Stefano Salvi - released under FDL licence

Valid XHTML 1.0! Valid CSS!