Attribute VB_Name = "ModuloGestioneToolBar"
Option Explicit

Public Const ID_TB__NEW = 50001
Public Const ID_TB_EDIT = 50002
Public Const ID_TB_SAVE = 50003
Public Const ID_TB__DEL = 50004
Public Const ID_TB_PRIN = 50005
Public Const ID_TB_DUPL = 50006
Public Const ID_TB_PREW = 50007
Public Const ID_TB_NEXT = 50008
Public Const ID_TB_FIND = 50009
Public Const ID_TB_CLOS = 50010
Public Const ID_TB_EXIT = 50011

Public gNumImgTB2 As Long 'Numero Immagini ToolBar2
'Public gNumImgWdg As Integer 'Numero Immagini per i Widget

Public Const ID_STATBAR_LOGO = 1
Public Const ID_STATBAR_IDNOVISOFT = 2
Public Const ID_STATBAR_SCAD_MANUTENZ = 3 'data Scadenza della Manutenzione
Public Const ID_STATBAR_AZIENDA = 4
Public Const ID_STATBAR_UTENTE = 5
Public Const ID_STATBAR_DATA = 6
Public Const ID_STATBAR_ALERT_ATTIVITA = 7 'ICONA CALENDARIO PER PROBLEMA ATTIVITą CON OPERATORI O RISORSE NON COERENTI CON CODICE PLANNING (PROBLEMA LEAGTO ALL'INTRODUZIONE DEL MULTIPLANNING RELEASE 2.2)
Public Const ID_STATBAR_PRGBAR = 8 'Progress Bar
Public Const ID_STATBAR_PUSH = 9 'Animazione per l'arrivo di richieste di prenotazione dall'APP
Public Const ID_STATBAR_TXTPUSH = 10
Public Const ID_STATBAR_WEB = 11 'Animazione per l'arrivo di richieste di prenotazione dal WEB
Public Const ID_STATBAR_TXTWEB = 12
Public Const ID_STATBAR_INTERNET = 13 'Stato Connessione ad Internet (Pallini colorati)
Public Const ID_STATBAR_SMS = 14  'Stato Disponibilitą SMS (Pallini colorati)
 

Public Function FindPane(Id As Long) As StatusBarPane
   Set FindPane = MDIForm1.StatusBarMDI.FindPane(Id)
End Function

Public Sub CreaMenuMDI()
   
   'Loads an xcb file created by the designer
   With MDIForm1.CommandBars
      .LoadDesignerBars App.path & "\Files\Mnu\PrimoVMenu.xcb"
      '.Options.LargeIcons = True
      '.Options.ShowTextBelowIcons = True
   End With
   
   'Call VerificaVociMenuExtra(True)
   
End Sub
   

Public Sub MdiToolBar_Dinamico(frmForm As Form, NomeForm As String, _
                               Optional pEdit As Boolean, Optional pNew As Boolean, Optional pSave As Boolean, _
                               Optional pDel As Boolean, Optional pPrint As Boolean, Optional pDupl As Boolean, _
                               Optional pPrew As Boolean, Optional pNext As Boolean, Optional pFind As Boolean)
   
   'If gTerminaAPP Then Exit Sub
   
   Dim i As Byte
   
'QUESTA IMPOSTAZIONE SI PUO' USARE SOLO DOVE NON CI PUO' ESSERE UN RITORNO DI SELEZIONE DELLA FORM: _
 ES: LA FormCALEND_EVENTO

   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
         Case ID_TB_EDIT: MDIForm1.CommandBars(2).Controls(i).Enabled = pEdit
         Case ID_TB__NEW: MDIForm1.CommandBars(2).Controls(i).Enabled = pNew
         Case ID_TB_SAVE: MDIForm1.CommandBars(2).Controls(i).Enabled = pSave
         Case ID_TB__DEL: MDIForm1.CommandBars(2).Controls(i).Enabled = pDel
         Case ID_TB_PRIN: MDIForm1.CommandBars(2).Controls(i).Enabled = pPrint
         Case ID_TB_DUPL: MDIForm1.CommandBars(2).Controls(i).Enabled = pDupl
         Case ID_TB_PREW: MDIForm1.CommandBars(2).Controls(i).Enabled = pPrew
         Case ID_TB_NEXT: MDIForm1.CommandBars(2).Controls(i).Enabled = pNext
         Case ID_TB_FIND: MDIForm1.CommandBars(2).Controls(i).Enabled = pFind
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   'Call SalvaSituazioneFORM(NomeForm, "DINAMICA")

End Sub

Public Sub MdiToolBar_SPENTO()
   If gTerminaAPP Then Exit Sub
   
   Dim i As Byte
      
   
   'Impostazione richiamata dal MdiForm1_Activate. _
    Disabilito tutti i tasti perche' disabilitati sono antiestetici. _
    Comunque non avranno nessun effetto fino a che non si aprira' un Form
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

End Sub

Public Sub MdiToolBar_START()
   If gTerminaAPP Then Exit Sub
   
   Dim i As Byte
   
   'Impostazione richiamata dal MdiForm1_Activate (tutti i tasti sono disabilitati)
   
                     'MDIForm1.CommandBars(2).TextOrientation = xtpBarTextHorizontal
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
         Case ID_TB_EDIT: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB__NEW: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_SAVE: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB__DEL: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_PRIN: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_DUPL: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_PREW: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_NEXT: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_FIND: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = False
      End Select
   Next i

End Sub


Public Sub MdiToolBar_Interroga(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub
   
   Dim i As Byte
   
      frmForm.Caption = frmForm.Tag & " \ Interroga"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "")

End Sub


Public Sub MdiToolBar_Modifica(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   frmForm.Caption = frmForm.Tag & " \ Modifica"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "MODIFICA")

End Sub


Public Sub MdiToolBar_Carica(frmForm As Form, NomeForm As String, Optional BloccaTutto As Boolean)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   frmForm.Caption = frmForm.Tag & " \ Carica"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
         Case ID_TB_EDIT: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB__NEW: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_SAVE
            If BloccaTutto = False Then
               MDIForm1.CommandBars(2).Controls(i).Enabled = True
            Else
               MDIForm1.CommandBars(2).Controls(i).Enabled = False
            End If
         Case ID_TB__DEL: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_PRIN: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_PREW: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_NEXT: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_FIND: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "CARICA")

End Sub

Public Sub MdiToolBar_Stampa(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   frmForm.Caption = frmForm.Tag & " \ Stampa"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
         Case ID_TB_EDIT: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB__NEW: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_SAVE: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB__DEL: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_PRIN: MDIForm1.CommandBars(2).Controls(i).Enabled = True
         Case ID_TB_PREW: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_NEXT: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_FIND: MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "STAMPA")

End Sub


Public Sub MdiToolBar_ElementoTrovato(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   frmForm.Caption = frmForm.Tag & " \ Interroga"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "TROVATO")
   
End Sub


Public Sub MdiToolBar_Salva_Scorri(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   'frmForm.Caption = frmForm.Tag & " \ Interroga"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "SALVA/SCORRI")
   
End Sub

Public Sub MdiToolBar_Salva_Stampa_Scorri(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   'frmForm.Caption = frmForm.Tag & " \ Interroga"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "SALVA/SCORRI")
   
End Sub

Public Sub MdiToolBar_Stampa_Scorri(frmForm As Form, NomeForm As String)
   If gTerminaAPP Then Exit Sub

   Dim i As Byte
   
   'frmForm.Caption = frmForm.Tag & " \ Interroga"
   
   For i = 1 To MDIForm1.CommandBars(2).Controls.Count - 1
      Select Case MDIForm1.CommandBars(2).Controls(i).Id
      Case ID_TB_EDIT
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__NEW
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_SAVE
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB__DEL
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
      Case ID_TB_PRIN
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_PREW
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_NEXT
         MDIForm1.CommandBars(2).Controls(i).Enabled = True
      Case ID_TB_FIND
         MDIForm1.CommandBars(2).Controls(i).Enabled = False
         Case ID_TB_CLOS: MDIForm1.CommandBars(2).Controls(i).Enabled = True
      End Select
   Next i

   Call SalvaSituazioneFORM(NomeForm, "SALVA/SCORRI")
   
End Sub


Private Sub SalvaSituazioneFORM(NomeForm As String, Situazione As String)
   'Nel primo WriteIni imposto la situzione del form passato come Parametro "NomeForm" _
    mentre nel secondo WriteIni imposto l'ultima impostazione attribuita alla ToolBar _
    in modo da evitare chiamate ricorsive se gia' si presente nell stato in cui interessa _
    il Form che acquista il Fuoco.
   
   If Len(Trim(Situazione)) > 0 Then
      Call WriteINI("TOOLBAR", NomeForm, Situazione, IniPath)
      Call WriteINI("TOOLBAR", "ULTIMA_POSIZIONE_TOOLBAR", Situazione, IniPath)
   Else
      Call WriteINI("TOOLBAR", NomeForm, vbNullString, IniPath)
      Call WriteINI("TOOLBAR", "ULTIMA_POSIZIONE_TOOLBAR", vbNullString, IniPath)
   End If
   
End Sub



Public Function fAddButtonCmdBars(Controls As CommandBarControls, ControlType As XTPControlType, Id As Long, Caption As String, _
                           Optional pIconID As Long, Optional pChecked As Boolean, Optional pDisabled As Boolean, _
                           Optional BeginGroup As Boolean = False, Optional DescriptionText As String = "", Optional pHeight As Integer, _
                           Optional ButtonStyle As XTPButtonStyle = xtpButtonAutomatic, Optional Category As String = "Controls", _
                           Optional pParameter As String = "") As CommandBarControl
                           
   Dim Control As CommandBarControl
   Set Control = Controls.Add(ControlType, Id, Caption)
    
   Control.BeginGroup = BeginGroup
   Control.DescriptionText = DescriptionText
   Control.Style = ButtonStyle
   Control.Category = Category
   Control.Checked = pChecked
   Control.Enabled = Not pDisabled
   Control.IconId = pIconID
   Control.Height = pHeight
   Control.Parameter = Trim(pParameter) 'x ulteriori parametri (tipo Tag)
   
      'Control.Width = 200
   
'   If pIconSize > 0 Then
'      Control.SetIconSize pIconSize, pIconSize
'   End If
   
   Set fAddButtonCmdBars = Control
End Function



Public Sub CaricaBarPersIcone()
   Dim vPathImg As String
   Dim i As Long
   'Dim vTipo As String

    'Loads an xcb file created by the designer
   With MDIForm1.ImageManager


'ICONE PER TOOLBAR PRINCIPALE
   vPathImg = App.path & "\Files\Images\Toolbar\"
      'QUESTE SONO LE ICONE DELLA TOOLBAR2
      For i = 50001 To 50011
         .Icons.LoadBitmap vPathImg & i & ".png", i, xtpImageNormal
      Next i


'ICONE PER TOOLBAR TASTI RAPIDI
   vPathImg = App.path & "\Files\Images\Toolbar\Toolbar2\"
      gNumImgTB2 = 42 + 10000 'ContaFileFolder(vPathImg) + 10000  '10087
      
      'QUESTE SONO LE ICONE DELLA TOOLBAR2
      For i = 10001 To gNumImgTB2
         .Icons.LoadBitmap vPathImg & i & ".png", i, xtpImageNormal
      Next i
      
      
'Associo ALLA COMMAND BARS
      MDIForm1.CommandBars.Icons = .Icons
   End With
   
End Sub
