FINAL CUT
fmenulist.h
1 /***********************************************************************
2 * fmenulist.h - Menu item container base class *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2015-2022 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Base class
24  * ══════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ FMenuList ▏- - - -▕ FMenuItem ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▏
29  * :1
30  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
31  * ├- - - - - - -▕ FRadioMenuItem ▏
32  * : ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
33  * :
34  * : *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
35  * └- - - - - - -▕ FCheckMenuItem ▏
36  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
37  */
38 
39 #ifndef FMENULIST_H
40 #define FMENULIST_H
41 
42 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
43  #error "Only <final/final.h> can be included directly."
44 #endif
45 
46 #include <vector>
47 
48 #include "final/fwidget.h"
49 #include "final/menu/fmenuitem.h"
50 
51 namespace finalcut
52 {
53 
54 //----------------------------------------------------------------------
55 // class FMenuList
56 //----------------------------------------------------------------------
57 
58 class FMenuList
59 {
60  public:
61  // Using-declarations
62  using FMenuItemList = std::vector<FMenuItem*>;
63 
64  // Constructor
65  FMenuList() = default;
66 
67  // Disable copy constructor
68  FMenuList (const FMenuList&) = delete;
69 
70  // Disable move constructor
71  FMenuList (FMenuList&&) noexcept = delete;
72 
73  // Destructor
74  virtual ~FMenuList();
75 
76  // Disable copy assignment operator (=)
77  auto operator = (const FMenuList&) -> FMenuList& = delete;
78 
79  // Disable move assignment operator (=)
80  auto operator = (FMenuList&&) noexcept -> FMenuList& = delete;
81 
82  // Accessors
83  virtual auto getClassName() const -> FString;
84  auto getCount() const -> std::size_t;
85  auto getItem (int) const -> FMenuItem*;
86  auto getSelectedItem() const -> FMenuItem*;
87  auto getItemList() const -> const FMenuItemList&;
88 
89  // Mutators
90  void enableItem (int);
91  void disableItem (int);
92  void setSelectedItem (FMenuItem*);
93  void unsetSelectedItem();
94 
95  // Inquiries
96  auto isSelected (int) const -> bool;
97  auto hasSelectedItem() const -> bool;
98 
99  // Methods
100  virtual void insert (FMenuItem*);
101  virtual void remove (FMenuItem*);
102  void remove (int);
103  void clear();
104  auto findFirstSelectedItem() const -> FMenuItemList::const_iterator;
105  auto findLastSelectedItem () const -> FMenuItemList::const_reverse_iterator;
106  void selectFirstItem();
107  void unselectItem();
108 
109  protected:
110  auto selectNextItem() -> bool;
111  auto selectPrevItem() -> bool;
112  virtual void selectItem_PostProcessing (FMenuItem*) = 0;
113 
114  private:
115  // Data members
116  FMenuItem* selected_item{};
117  FMenuItemList item_list{};
118 };
119 
120 
121 // FMenuList inline functions
122 //----------------------------------------------------------------------
123 inline auto FMenuList::getClassName() const -> FString
124 { return "FMenuList"; }
125 
126 //----------------------------------------------------------------------
127 inline auto FMenuList::getCount() const -> std::size_t
128 { return item_list.size(); }
129 
130 //----------------------------------------------------------------------
131 inline auto FMenuList::getItem (int index) const -> FMenuItem*
132 { return ( index > 0 ) ? item_list[uInt(index - 1)] : nullptr; }
133 
134 //----------------------------------------------------------------------
135 inline auto FMenuList::getSelectedItem() const -> FMenuItem*
136 { return selected_item; }
137 
138 //----------------------------------------------------------------------
139 inline auto FMenuList::getItemList() const -> const FMenuItemList&
140 { return item_list; }
141 
142 //----------------------------------------------------------------------
143 inline void FMenuList::enableItem (int index)
144 { item_list[uInt(index - 1)]->setEnable(); }
145 
146 //----------------------------------------------------------------------
147 inline void FMenuList::disableItem (int index)
148 { item_list[uInt(index - 1)]->unsetEnable(); }
149 
150 //----------------------------------------------------------------------
151 inline void FMenuList::setSelectedItem (FMenuItem* menuitem)
152 { selected_item = menuitem; }
153 
154 //----------------------------------------------------------------------
155 inline void FMenuList::unsetSelectedItem()
156 { selected_item = nullptr; }
157 
158 //----------------------------------------------------------------------
159 inline auto FMenuList::isSelected(int index) const -> bool
160 { return ( index > 0 ) ? item_list[uInt(index - 1)]->isSelected() : false; }
161 
162 //----------------------------------------------------------------------
163 inline auto FMenuList::hasSelectedItem() const -> bool
164 { return selected_item; }
165 
166 } // namespace finalcut
167 
168 #endif // FMENULIST_H
Definition: fmenulist.h:58
Definition: class_template.cpp:25
Definition: fmenuitem.h:68
Definition: fstring.h:79