Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

BListbox.h

Go to the documentation of this file.
00001 /* This is -*- C -*-)
00002 
00003    BListbox.h   
00004    \author: Bjoern Giesler <bjoern@giesler.de>
00005    
00006    
00007    
00008    $Author: giesler $
00009    $Locker$
00010    $Revision$
00011    $Date: 2002-08-19 10:41:28 +0200 (Mon, 19 Aug 2002) $
00012  */
00013 
00014 #ifndef BLISTBOX_H
00015 #define BLISTBOX_H
00016 
00017 /* system includes */
00018 #include <string>
00019 #include <deque>
00020 
00021 /* my includes */
00022 #include "BScrollable.h"
00023 #include "BFont.h"
00024 
00025 class BListbox: public BScrollable {
00026  public:
00027   typedef struct {
00028     std::string title;
00029     u16 color;
00030     int tag;
00031   } Entry;
00032 
00033   class Delegate {
00034   public:
00035     virtual ~Delegate() {};
00036     virtual void onEntryClick(BListbox *box, Entry &entry) {};
00037     virtual void onEntryDoubleClick(BListbox *box, Entry &entry) {};
00038   };
00039 
00040   BListbox(BWidget* parent, const BRect &frame);
00041 
00042   void setDelegate(Delegate* deleg);
00043   Delegate* delegate() { return _deleg; }
00044   
00045   void addEntry(const Entry &entry);
00052   void addEntry(const std::string &title,
00053                 u16 color = 0,
00054                 int tag = 0)
00055   {
00056     Entry entry; entry.title = title; entry.color = color; entry.tag = tag;
00057     addEntry(entry);
00058   }
00059 
00060   void clear();
00061 
00062   virtual void setEntrySpacing(int spacing);
00063   virtual int entrySpacing();
00064 
00065   // from BWidget
00066   virtual void draw(BImage &img);
00067   
00068   // from BScrollable
00069   virtual void updateScroller(BScroller *scroller);
00070   virtual void scrollToPosition(BScroller *scroller,
00071                                 unsigned int position);
00072 
00073   void handleEvent(const BEvent& event);
00074 
00075   const Entry& selectedEntry();
00076 
00077   void selectEntry(const std::string& name);
00078   void selectEntry(int index);
00079   void selectEntryWithTag(int tag);
00080 
00081   bool drawsSelection() { return _drawsSelection; }
00082   void setDrawsSelection(bool draws) {
00083     _drawsSelection = draws;
00084     setNeedsRedraw(true);
00085   }
00086 
00087  private:
00088   std::deque<Entry> _entries;
00089   unsigned int _firstIndex;
00090   unsigned int _selectedIndex;
00091   int _spacing;
00092   bool _drawsSelection;
00093   Delegate* _deleg;
00094 };
00095 
00096 #endif /* BLISTBOX_H */

Generated on Sat Dec 29 09:59:23 2007 for DSGUI by doxygen1.3-rc3