Pour griser le bouton, c'est tout de suite lorsque tu cré le bouton.
Pour le rendre actif c'est dès que tu cré une fiche ou que tu charge un fichier de fiche
Code : Tout sélectionner
Enumeration
#Window_0
#Window_1
#window_2
EndEnumeration
Enumeration
#ListIcon_0
#Button_Ajoutet
#Button_Effacee
#Button_Fiche
#Text_Titre
#Frame3D_0
#Frame3D_ajoute
#Text_NomS
#String_NomS
#Text_NomT
#editor_NomT
#Text_Matos
#Editor_matos
#Text_date
#String_date
#Text_Heure
#String_heure
#Text_Lieux
#Editor_Lieux
#Button_ajoute
#button_ajou
EndEnumeration
Enumeration
#menu_Charger
#menu_Save
#menu_Quitter
#menu_Vider
#menu_info
EndEnumeration
Enumeration
#menu_Effacec
#menu_Annuler
EndEnumeration
; Fonts
Global FontID1
FontID1 = LoadFont(1, "Arial", 11, #PB_Font_Bold)
Global FontID2
FontID2 = LoadFont(2, "Arial", 12, #PB_Font_Bold)
Global FontID3
FontID3 = LoadFont(3, "Arial", 10, #PB_Font_Bold)
Global FontID4
FontID4 = LoadFont(4, "Arial", 26, #PB_Font_Bold)
; creation d'un element
Structure Tour_struct
Nom.s
ListeT.s
Matos.s
Date.s
Heure.s
Lieux.s
EndStructure
NewList Items.Tour_struct()
; procedure de gestion des items
Procedure.b item_clear()
ClearList(Items())
ProcedureReturn 1
EndProcedure
; ajouter un element dans la liste
Procedure.b item_add()
If AddElement(Items())
Items()\Nom = GetGadgetText(#String_NomS)
Items()\ListeT = GetGadgetText(#Editor_NomT)
Items()\Matos = GetGadgetText(#Editor_matos)
Items()\date = GetGadgetText(#String_Date)
Items()\Heure = GetGadgetText(#String_heure)
Items()\Lieux = GetGadgetText( #Editor_Lieux)
AddGadgetItem(#ListIcon_0, -1, Items()\Nom) ; on affiche le nom dans le ListIconGadget
EndIf
; on teste ici si la liste est vide et si non, on active le bouton
If CountGadgetItems(#ListIcon_0)
DisableGadget(#Button_Fiche, 0)
EndIf
ProcedureReturn 1
EndProcedure
Procedure Empty()
Item_Clear()
ClearGadgetItemList(#ListIcon_0)
EndProcedure
Procedure.l Item_Load(fichier.s)
If OpenPreferences(fichier)
Repeat
i + 1
If PreferenceGroup("Item." + Str(i))
AddElement(Items())
Items()\Nom = ReadPreferenceString("Nom du spectacle", "")
Items()\ListeT = ReadPreferenceString("Liste des tours", "")
Items()\Matos = ReadPreferenceString("Materiel", "")
Items()\Date = ReadPreferenceString("date", "")
Items()\heure = ReadPreferenceString("Heure", "")
Items()\Lieux = ReadPreferenceString("Lieux", "")
Else
Break
EndIf
ForEver
ClosePreferences()
ProcedureReturn i
EndIf
EndProcedure
Procedure.l Item_Save(fichier.s)
If CreatePreferences(fichier)
ForEach Items()
i + 1
PreferenceGroup("Item." + Str(i))
WritePreferenceString("Nom du spectacle", Items()\Nom)
WritePreferenceString("Nom du spectacle", Items()\ListeT)
WritePreferenceString("Materiel", Items()\Matos)
WritePreferenceString("Date", Items()\Date)
WritePreferenceString("Heure", Items()\heure)
WritePreferenceString("Lieux", Items()\Lieux)
Next
ClosePreferences()
ProcedureReturn i
EndIf
EndProcedure
Procedure Open(append.b)
;- Ouvre un fichier
fichier.s = OpenFileRequester("Ouvrir", "fichier.ini", "ini | *.ini", 0)
If fichier <> ""
If append
ClearGadgetItemList(#ListIcon_0)
Else
Item_Clear()
EndIf
Item_Load(fichier)
ClearGadgetItemList(#listIcon_0) ; on efface les éléments de la listicon
ForEach Items()
AddGadgetItem(#listIcon_0, -1, Items()\Nom)
Items()\Nom
Next
EndIf
; on teste ici si la liste est vide et si non, on active le bouton
If CountGadgetItems(#ListIcon_0)
DisableGadget(#Button_Fiche, 0)
EndIf
EndProcedure
Procedure SaveAs()
;- Enregistre sous...
fichier.s = SaveFileRequester("Enregistrer sous", "*.ini", "ini | ini", 0)
If fichier <> ""
Item_Save(fichier)
EndIf
EndProcedure
Procedure RemoveGadget()
i = 0
If GetGadgetItemState(#ListIcon_0, i) & #PB_ListIcon_Checked ; Si l'item est marqué
RemoveGadgetItem(#ListIcon_0, i) ; on le retire
EndIf
; comme la listicon est vide, on grise le bouton
If CountGadgetItems(#ListIcon_0) = 0
DisableGadget(#Button_Fiche, 1)
EndIf
EndProcedure
Procedure effacer()
SetGadgetText(#String_NomS, "")
SetGadgetText(#editor_NomT, "")
SetGadgetText(#Editor_matos, "")
SetGadgetText(#String_Date, "")
SetGadgetText(#String_Heure, "")
SetGadgetText(#Editor_lieux, "")
ActivateGadget(#String_NomS)
EndProcedure
Procedure info()
MessageRequester("Information sur Merlin ", "Merlin Version 01 " + Chr(10) + "par Williamm" + Chr(10) + "Copyright 2004 ", #MB_OK | #MB_ICONINFORMATION)
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 18, 13, 955, 675, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar, "Merlin le Gestionnaire de Prestation copyright 2004 ")
If CreateMenu(0, WindowID())
MenuTitle( "Fichier")
MenuItem(#menu_Charger, "Charger la liste")
MenuItem(#menu_Save, "Sauvegarder la liste")
MenuItem(#menu_Quitter, "Quitter ")
MenuTitle("Edition")
MenuItem(#menu_vider, " Vider la liste ")
MenuTitle ("Information")
MenuItem(#menu_info, " A propos de ")
EndIf
If CreateGadgetList(WindowID())
ListIconGadget(#ListIcon_0, 20, 20, 700, 630, "Nom du spectacle ", 696, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines)
SetGadgetFont(#ListIcon_0, FontID1)
ButtonGadget(#Button_Ajoutet, 740, 40, 190, 50, "AJOUTER")
GadgetToolTip(#Button_Ajoutet, "Ajoute un spectacle a la liste ")
SetGadgetFont(#Button_Ajoutet, FontID2)
ButtonGadget(#Button_Effacee, 740, 220, 190, 50, "EFFACER")
GadgetToolTip(#Button_Effacee, "Efface un spectacle de la liste en cochant la case ")
SetGadgetFont(#Button_Effacee, FontID2)
ButtonGadget(#Button_Fiche, 740, 120, 190, 50, "VOIR LA FICHE ")
GadgetToolTip(#Button_Fiche, "Voir la fiche en cochant la case ")
SetGadgetFont(#Button_Fiche, FontID2)
; ici on grise le bouton de lecture fiche
DisableGadget(#Button_Fiche, 1)
TextGadget(#Text_Titre, 750, 460, 180, 100, "Merlin Version 01 ", #PB_Text_Center)
SetGadgetFont(#Text_Titre, FontID4)
Frame3DGadget(#Frame3D_0, 730, 20, 210, 600, "")
EndIf
EndIf
EndProcedure
Procedure Open_Window_1()
If OpenWindow(#Window_1, 255, 7, 678, 724, #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered, "Creation d'une nouvelle fiche ")
If CreateMenu(1, WindowID())
MenuTitle( "Edition")
MenuItem(#menu_Effacec, " Effacer les Renseignement ")
MenuItem(#menu_Annuler, " Annuler la fiche ")
EndIf
If CreateGadgetList(WindowID())
Frame3DGadget(#Frame3D_ajoute, 10, 10, 660, 710, "")
TextGadget(#Text_NomS, 20, 40, 150, 30, "Nom du spectacle :", #PB_Text_Center)
SetGadgetFont(#Text_NomS, FontID2)
StringGadget(#String_NomS, 180, 40, 480, 28, "")
SetGadgetFont(#String_NomS, FontID3)
TextGadget(#Text_NomT, 20, 110, 150, 30, "Listes des tours : ", #PB_Text_Center)
SetGadgetFont(#Text_NomT, FontID2)
EditorGadget(#editor_NomT, 180, 110, 480, 100, "")
SetGadgetFont(#editor_NomT, FontID3)
TextGadget(#Text_Matos, 20, 280, 130, 30, "Materiel : ", #PB_Text_Center)
SetGadgetFont(#Text_Matos, FontID2)
EditorGadget(#Editor_matos, 180, 280, 480, 130)
SetGadgetFont(#Editor_matos, FontID3)
TextGadget(#Text_date, 30, 460, 110, 30, "Date :", #PB_Text_Center)
SetGadgetFont(#Text_date, FontID2)
StringGadget(#String_date, 140, 460, 120, 30, "")
SetGadgetFont(#String_date, FontID3)
TextGadget(#Text_Heure, 360, 460, 110, 20, "Heure :", #PB_Text_Center)
SetGadgetFont(#Text_Heure, FontID2)
StringGadget(#String_heure, 480, 460, 130, 25, "")
SetGadgetFont(#String_heure, FontID3)
TextGadget(#Text_Lieux, 160, 520, 80, 20, "Lieux: ", #PB_Text_Center)
SetGadgetFont(#Text_Lieux, FontID2)
EditorGadget(#Editor_Lieux, 270, 510, 380, 80)
SetGadgetFont(#Editor_Lieux, FontID3)
ButtonGadget(#Button_ajoute, 200, 620, 290, 50, "Ajouter un nouveau spectacle ")
GadgetToolTip(#Button_ajoute, "Ajoute une prestation a la liste ")
SetGadgetFont(#Button_ajoute, FontID2)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_EventMenu
Select EventMenuID()
Case#menu_Effacec : effacer()
Case #menu_Annuler : Fermer_Window_1 = 1
EndSelect
Case #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #Button_Ajoute
item_add()
Fermer_Window_1 = 1
EndIf
EndSelect
Until Fermer_Window_1 = 1
CloseWindow(#Window_1)
While WindowEvent() : Wend
EndIf
EndIf
EndProcedure
Procedure Open_Window_2(Index)
If OpenWindow(#window_2, 255, 7, 678, 724, #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered, "Fiche du spectacle ")
If CreateGadgetList(WindowID())
Frame3DGadget(#Frame3D_ajoute, 10, 10, 660, 710, "")
TextGadget(#Text_NomS, 20, 40, 150, 30, "Nom du spectacle :", #PB_Text_Center)
SetGadgetFont(#Text_NomS, FontID2)
StringGadget(#String_NomS, 180, 40, 480, 28, "")
SetGadgetFont(#String_NomS, FontID3)
TextGadget(#Text_NomT, 20, 110, 150, 30, "Listes des tours : ", #PB_Text_Center)
SetGadgetFont(#Text_NomT, FontID2)
EditorGadget(#editor_NomT, 180, 110, 480, 100, "")
SetGadgetFont(#editor_NomT, FontID3)
TextGadget(#Text_Matos, 20, 280, 130, 30, "Materiel : ", #PB_Text_Center)
SetGadgetFont(#Text_Matos, FontID2)
EditorGadget(#Editor_matos, 180, 280, 480, 130)
SetGadgetFont(#Editor_matos, FontID3)
TextGadget(#Text_date, 30, 460, 110, 30, "Date :", #PB_Text_Center)
SetGadgetFont(#Text_date, FontID2)
StringGadget(#String_date, 140, 460, 120, 30, "")
SetGadgetFont(#String_date, FontID3)
TextGadget(#Text_Heure, 360, 460, 110, 20, "Heure :", #PB_Text_Center)
SetGadgetFont(#Text_Heure, FontID2)
StringGadget(#String_heure, 480, 460, 130, 25, "")
SetGadgetFont(#String_heure, FontID3)
TextGadget(#Text_Lieux, 160, 520, 80, 20, "Lieux: ", #PB_Text_Center)
SetGadgetFont(#Text_Lieux, FontID2)
EditorGadget(#Editor_Lieux, 270, 510, 380, 80)
SetGadgetFont(#Editor_Lieux, FontID3)
ButtonGadget(#Button_ajoute, 200, 620, 290, 50, " Quitter la fiche ")
SetGadgetFont(#Button_ajoute, FontID2)
; comme l'index représente le même numéro que l'élément de la liste chaînée
; il suffit de faire
SelectElement(Items(), Index)
SetGadgetText(#String_NomS, Items()\Nom)
SetGadgetText(#Editor_Nomt, Items()\ListeT)
SetGadgetText(#Editor_matos, Items()\Matos)
SetGadgetText(#String_date, Items()\Date)
SetGadgetText(#String_heure, Items()\Heure)
SetGadgetText(#Editor_Lieux, Items()\Lieux)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_EventCloseWindow
Fermer_Window_2 = 1
Case #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #Button_ajoute
Fermer_Window_2 = 1
EndIf
EndSelect
Until Fermer_Window_2 = 1
CloseWindow(#window_2)
EndIf
EndIf
EndProcedure
;- - Debut du program principal
Open_Window_0()
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_EventMenu
Select EventMenuID()
Case#menu_Charger
open (#false)
Case#menu_save
saveas()
Case #menu_Info
info()
Case#menu_vider
Empty()
Case#menu_Quitter
fermer_window_0 = 1
EndSelect
Case #PB_EventGadget
Select EventGadgetID()
Case #Button_ajoutet
open_window_1()
Case#button_Fiche
i = 0
If CountGadgetItems(#ListIcon_0)
For i = 0 To CountGadgetItems(#ListIcon_0)
If GetGadgetItemState(#ListIcon_0, i) & #PB_ListIcon_Checked = #PB_ListIcon_Checked
Open_Window_2(i)
Break
EndIf
Next i
EndIf
Case #Button_Effacee
RemoveGadget()
EndSelect
Case #PB_EventCloseWindow
fermer_window_0 = 1
EndSelect
Until fermer_window_0 = 1
End