OpendTect-6_4  6.4
menuhandler.h
Go to the documentation of this file.
1 #ifndef menuhandler_h
2 #define menuhandler_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: N. Hemstra
9  Date: May 2003
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "refcount.h"
17 #include "position.h"
18 #include "callback.h"
19 #include "bufstring.h"
20 #include "uistring.h"
21 
22 class BufferStringSet;
23 class MenuItem;
24 class MenuHandler;
25 
27 {
28 public:
30  virtual ~MenuItemHolder();
34  virtual void addItem(MenuItem*,bool manage=false);
45  void removeItems();
46  int nrItems() const;
47 
48  const MenuItem* getItem(int idx) const;
49  MenuItem* getItem(int idx);
50  int itemIndex(const MenuItem*) const;
51  int itemIndex(int id) const;
52  MenuItem* findItem(int id);
53  const MenuItem* findItem(int id) const;
54  MenuItem* findItem(const char*);
56  const MenuItem* findItem(const char*) const;
58 
59  const ObjectSet<MenuItem>& getItems() const;
60 
61 protected:
62  friend class MenuHandler;
63  void itemIsDeletedCB(CallBacker*);
64  virtual void assignItemID(MenuItem&);
68 
69 private:
72 };
73 
77 {
78 public:
79  MenuItem(const uiString&
80  text=uiString::emptyString(),
81  int placement=-1);
82  MenuItem(const uiString& text,
83  CallBack cb,int placement=-1);
84  MenuItem(const uiString& text,
85  const char* iconnm,
86  const char* tooltip,
87  CallBack cb=CallBack(),
88  int placement=-1);
89  void createItems(const BufferStringSet&);
90  void createItems(const uiStringSet&);
91 
93  /*< The text that should be on the item. */
94  int placement;
99  int id;
101  bool checkable;
103  bool checked;
106  bool enabled;
110  //*!< Icon identifier
112  //*!< Tooltip if item is used in toolbar
114  //*!< Callback function to be called
115 };
116 
117 
120 public:
121  SeparatorItem(int plmnt=-1)
122  : MenuItem(tr("Separator"),plmnt) {}
123 };
124 
125 
189 public:
190  MenuHandler( int id );
191 
192  virtual bool executeMenu() = 0;
193 
194  int menuID() const { return id_; }
195  /*<Each menu has an unique id where the
196  that identifies it. */
197  void setMenuID( int newid ) { id_=newid; }
198 
202  bool isHandled() const;
208  void setIsHandled(bool);
215  int queueID() const { return queueid_; }
219 protected:
220  void assignItemID(MenuItem&);
221  void executeQueue();
222 
223  int id_;
225  int queueid_;
226 };
227 
228 
237 {
238 public:
240  const CallBack&,const char* parenttxt=0,
241  int placement=-1);
242  ~MenuItemHandler();
243  bool doadd_;
253  void setIcon(const char* fnm);
254 
255 protected:
256 
257  virtual void createMenuCB(CallBacker*);
258  virtual void handleMenuCB(CallBacker*);
259 
260  virtual bool shouldAddMenu() const { return true; }
261  virtual bool shouldBeEnabled() const { return true;}
262  virtual bool shouldBeChecked() const { return false;}
263 
268 };
269 
270 
271 
272 #define mResetMenuItem( item ) \
273 { \
274  (item)->enabled = true; \
275  (item)->checked = false; \
276  (item)->id = -1; \
277  (item)->removeItems(); \
278 }
279 
280 #define mAddMenuItemWithManageFlag( parent, item, manage, enab, check ) \
281 { \
282  MenuItem* _item = item; \
283  MenuItemHolder* _parent = parent; \
284  if ( _parent && (_parent)->itemIndex(_item)==-1 ) \
285  (_parent)->addItem( _item ); \
286  \
287  (_item)->enabled = (enab); \
288  (_item)->checked = (check); \
289 }
290 
291 #define mAddMenuItem( parent, item, enab, check ) \
292 mAddMenuItemWithManageFlag( parent, item, false, enab, check )
293 
294 
295 #define mAddManagedMenuItem( parent, item, enab, check ) \
296 mAddMenuItemWithManageFlag( parent, item, true, enab, check )
297 
298 
299 #define mAddMenuItemCond( menu, item, enab, check, cond ) { \
300  if ( menu && cond ) \
301  mAddMenuItem( menu, item, enab, check ) \
302  else \
303  mResetMenuItem( item ) } \
304 
305 //Macro that can poplulate both a toolbar and a menu.
306 #define mAddMenuOrTBItem( istoolbar, tbparent, popupparent, item, enab, check )\
307  mAddMenuItem( \
308  istoolbar?(MenuItemHolder*)(tbparent):(MenuItemHolder*)(popupparent), \
309  item, enab, check )
310 
311 #endif
#define mRefCountImpl(ClassName)
Macro to setup a class with destructor for reference counting.
Definition: refcount.h:163
#define mExpClass(module)
Definition: commondefs.h:160
bool checked
Definition: menuhandler.h:103
bool checkable
Definition: menuhandler.h:101
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
int menuID() const
Definition: menuhandler.h:194
bool ishandled_
Definition: menuhandler.h:224
Definition: menuhandler.h:187
MenuItem * findItem(int id)
void assignItemID(MenuItem &)
void itemIsDeletedCB(CallBacker *)
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
virtual void addItem(MenuItem *, bool manage=false)
ObjectSet< MenuItem > items_
Definition: menuhandler.h:70
MenuItem menuitem_
Definition: menuhandler.h:264
Definition: menuhandler.h:236
BufferString parenttext_
Definition: menuhandler.h:267
bool isHandled() const
virtual ~MenuItemHolder()
bool ischecked_
Definition: menuhandler.h:249
static const uiString & emptyString()
Definition: uistring.h:109
int id_
Definition: menuhandler.h:223
Definition: uistring.h:89
virtual bool shouldBeChecked() const
Definition: menuhandler.h:262
Set of BufferString objects.
Definition: bufstringset.h:28
bool doadd_
Definition: menuhandler.h:243
int itemIndex(const MenuItem *) const
SeparatorItem(int plmnt=-1)
Definition: menuhandler.h:121
bool isenabled_
Definition: menuhandler.h:246
MenuHandler(int id)
MenuHandler & menuhandler_
Definition: menuhandler.h:265
BoolTypeSet manageitems_
Definition: menuhandler.h:71
void setMenuID(int newid)
Definition: menuhandler.h:197
void removeItems()
Definition: menuhandler.h:76
Definition: menuhandler.h:118
int placement
Definition: menuhandler.h:94
BufferString tooltip
Definition: menuhandler.h:111
int id
Definition: menuhandler.h:99
BufferString iconfnm
Definition: menuhandler.h:109
CNotifier< MenuHandler, int > handlenotifier
Definition: menuhandler.h:201
void executeQueue()
CallBack cb
Definition: menuhandler.h:113
MenuItemHolder * parent_
Definition: menuhandler.h:67
int nrItems() const
Notifier< MenuHandler > initnotifier
Definition: menuhandler.h:199
bool enabled
Definition: menuhandler.h:106
Notifier< MenuHandler > createnotifier
Definition: menuhandler.h:200
virtual bool executeMenu()=0
CallBack cb_
Definition: menuhandler.h:266
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Definition: menuhandler.h:26
virtual bool shouldBeEnabled() const
Definition: menuhandler.h:261
const ObjectSet< MenuItem > & getItems() const
Definition: uistring.h:218
virtual bool shouldAddMenu() const
Definition: menuhandler.h:260
uiString text
Definition: menuhandler.h:92
void setIsHandled(bool)
CallBacks object-oriented (object + method).
Definition: callback.h:57
const MenuItem * getItem(int idx) const
int queueid_
Definition: menuhandler.h:225
int queueID() const
Definition: menuhandler.h:215
Notifier< MenuItemHolder > removal
Definition: menuhandler.h:31

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019