summaryrefslogtreecommitdiffstats
path: root/fltk/fltk/ItemGroup.h
blob: 715bc1811e4d415761a0b0be19796e42ddf9c07b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// "$Id: ItemGroup.h 5575 2007-01-02 17:31:40Z spitzak $"
//
// Widget designed to be a nested list in a menu or browser. This
// copies the drawing and style code from Item. I did not modify the
// base Menu class this way because the style inheritance would mess
// up the styles of MenuButton and MenuBar. Code is in Item.cxx
//
// Copyright 1998-2006 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//

#ifndef fltk_ItemGroup_h
#define fltk_ItemGroup_h

#include "Menu.h"

namespace fltk {

class FL_API ItemGroup : public Menu {
public:
  void draw();
  void layout();
  int handle(int);
  ItemGroup(const char* label = 0, bool begin=false);
  ItemGroup(const char* label, const Symbol*, bool begin=false);
};

/** \class MenuSection
  This class will elegantly facilitate dynamic (& hand-made) menu code writing
  by creating and calling begin() on an ItemGroup in the constructor and
  calling end() in the destructor:
  \code
  mymenu->begin();
  new Item("in main menu");
  {MenuSection g("submenu title");
    new Item("in submenu");
    new Item("also in submenu");
  } // destructor ends the submenu
  \endcode
*/
class FL_API MenuSection {
  ItemGroup* group_;
public:
  //! build a typical submenu group section, then call begin()
  MenuSection(const char* label = 0) { group_ = new ItemGroup(label,true); }

  MenuSection(const char* label, const Symbol* i) { group_ = new ItemGroup(label,i,true); }

  //! call end() at destruction
  ~MenuSection() {group_->end();}

  //! The ItemGroup created by this.
  ItemGroup* group() const {return group_;}
};

}

#endif