home *** CD-ROM | disk | FTP | other *** search
/ Freelog 17 / Freelog017.iso / BeOS / ababelone / Sources / MenuDynamique.cpp < prev    next >
C/C++ Source or Header  |  2000-11-21  |  4KB  |  121 lines

  1. /*
  2.     Copyright (C) 2000 by Herv├⌐ PHILIPPE <rv@bemail.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public
  15.     License along with this library; if not, write to the Free
  16.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. #include "MenuDynamique.h"
  20.  
  21.   /////////////////////////////////////
  22.  // CONSTRUCTEUR de "MenuDynamique" //
  23. /////////////////////////////////////-----------------------------------------
  24. //----------------------------------------------------------------------------------------
  25. MenuDynamique::MenuDynamique(BMenu* menu, const char* chaine_repertoire, uint32 numero_premier_message)
  26. // 3 PARAMETRES :            ENTREE/SORTIE                ENTREE                        ENTREE
  27.     : m_ConstanteMessage(numero_premier_message)
  28. {
  29.     BPath chemin;
  30.     BEntry entree;
  31.     app_info infos_application;
  32.     char chaine_nom_fichier[B_FILE_NAME_LENGTH];
  33.     BMenuItem* item;
  34.     bool fin = false;
  35.     uint8 i = 1;
  36.  
  37.     m_NumeroFichier = 0;
  38.     m_Menu = menu;
  39.  
  40.     be_app->GetAppInfo(&infos_application);
  41.     chemin.SetTo(&(infos_application.ref));
  42.     chemin.GetParent(&chemin);
  43.     chemin.Append(chaine_repertoire);
  44.     m_Repertoire.SetTo(chemin.Path());
  45.     m_Repertoire.Rewind();
  46.     do {
  47.         if (m_Repertoire.GetNextEntry(&entree) != B_OK || entree.GetName(chaine_nom_fichier) != B_OK)
  48.             fin = true;
  49.         else {
  50.             m_Menu->AddItem(item=new BMenuItem(chaine_nom_fichier,new BMessage(m_ConstanteMessage+i)));
  51.             if (i == 255)
  52.                 fin = true;
  53.             else
  54.                 i++;
  55.         }
  56.     } while (fin == false);
  57. }
  58.  
  59.   ////////////////////////////////////
  60.  // DESTRUCTEUR de "MenuDynamique" //
  61. ////////////////////////////////////-------
  62. //-----------------------------------------------------
  63. MenuDynamique::~MenuDynamique()
  64. // AUCUN PARAMETRE
  65. {
  66. }
  67.  
  68.   ////////////////////////////////////
  69.  // FONCTION "SelectionnerFichier" //
  70. ////////////////////////////////////---------------
  71. //--------------------------------------------
  72. BEntry        // VALEUR DE RETOUR
  73. MenuDynamique::SelectionnerFichier(uint8 numero_du_fichier)
  74. // 1 PARAMETRE :                            ENTREE
  75. {
  76.     uint8 i;
  77.     status_t statut = B_OK; 
  78.  
  79.     if (numero_du_fichier == 0 || numero_du_fichier == m_NumeroFichier)
  80.         return m_EntreeFichier;
  81.  
  82.     m_Repertoire.Rewind();
  83.     for (i = 0; i < numero_du_fichier && statut == B_OK; i++)
  84.         statut = m_Repertoire.GetNextEntry(&m_EntreeFichier);
  85.  
  86.     if (m_NumeroFichier != 0)
  87.         (m_Menu->ItemAt(m_NumeroFichier-1))->SetMarked(false);
  88.     if (statut != B_OK)
  89.         m_NumeroFichier = 0;        
  90.     else {        
  91.         m_NumeroFichier = numero_du_fichier;        
  92.         (m_Menu->ItemAt(m_NumeroFichier-1))->SetMarked(true);
  93.     }
  94.     return m_EntreeFichier;
  95. }
  96.  
  97.   ///////////////////////
  98.  // FONCTION "Active" //
  99. ///////////////////////-------------------
  100. // Renvoie "vrai" si le menu est activ├⌐ --
  101. //----------------------------------------
  102. bool        // VALEUR DE RETOUR
  103. MenuDynamique::Active(uint32 numero_message)
  104. // 1 PARAMETRE :            ENTREE
  105. {
  106.     return (numero_message > m_ConstanteMessage
  107.             && numero_message < m_ConstanteMessage+256
  108.             && (numero_message-m_ConstanteMessage) != m_NumeroFichier);
  109. }
  110.  
  111.   //////////////////////////////
  112.  // FONCTION "NumeroFichier" //
  113. //////////////////////////////-------------------------
  114. // Renvoie le num├⌐ro du fichier actuellement utilis├⌐ --
  115. //-----------------------------------------------------
  116. uint8        // VALEUR DE RETOUR
  117. MenuDynamique::NumeroFichier()
  118. {
  119.     return m_NumeroFichier;
  120. }
  121.