LightWrap++
AC++wrapperfortheLightWave3DSDK
contextmenu.h
Go to the documentation of this file.
1 
6 #ifndef LWPP_CONTEXMENU_H
7 #define LWPP_CONTEXMENU_H
8 #include <lwpp/wrapper.h>
9 #include <lwpp/utility.h>
10 #include <lwpp/panel.h>
11 #include <lwpanel.h>
12 #include <list>
13 #ifdef _DEBUG
14 #include "lwpp/debug.h"
15 #endif
16 
17 namespace lwpp
18 {
22  class ContextMenu : protected GlobalBase<ContextMenuFuncs>
23  {
24  private:
25  LWContextMenuID menu;
26  LWPanPopupDesc description;
27  public:
29  : menu(0)
30  {
31  ;
32  }
34 
40  ContextMenu(int width, size_t (*countFn)(void *), char *(*nameFn)(void *, int),void *userdata)
41  : menu(0)
42  {
43  Create(width, countFn, nameFn, userdata);
44  }
47  {
48  if ((menu) && available()) globPtr->cmenuDestroy(menu);
49  }
50  void Create (void *userdata)
51  {
52  if ( available() )
53  {
54  if (menu) globPtr->cmenuDestroy(menu);
55  menu = globPtr->cmenuCreate(&description, userdata);
56  }
57  }
58  void Create(int width, size_t (*countFn)(void *), char *(*nameFn)(void *, int), void *userdata)
59  {
60  if ( available() )
61  {
62  if (menu) globPtr->cmenuDestroy(menu);
63  description.type = LWT_POPUP;
64  description.width = width;
65  description.countFn = (int (*)(void *))countFn;
66  description.nameFn = nameFn;
67  menu = globPtr->cmenuCreate(&description, userdata);
68  }
69  }
71 
76  int Deploy(LWPanelID panel, int select)
77  {
78  if ((menu) && available())
79  {
80 #ifdef _DEBUG
81  lwpp::dostream dout;
82  std::hex(dout);
83  dout << "Deploy Context Menu: 0x" << menu << "\n";
84  dout << " Panel: 0x" << panel << "\n";
85  dout << " Global: 0x" << globPtr << "\n";
86  dout << " Function: 0x" << globPtr->cmenuDeploy << "\n";
87  dout.flush();
88 #endif
89  return globPtr->cmenuDeploy( menu, panel, select);
90  }
91  else
92  {
93  return -1;
94  }
95  }
96  };
97 
101  {
102  private:
103  ContextMenu menu;
104  size_t num_entries;
105  const char **entries;
106  virtual size_t count(void)
107  {
108  return num_entries;
109  };
110  virtual const char *name(int n)
111  {
112  return entries[n];
113  };
114  public:
115  SimpleContextMenu (const char **_entries, int width) : entries(_entries), num_entries(0)
116  {
117  while (_entries[num_entries]) num_entries++;
119  }
120  int Deploy(LWPanelID panel, int select)
121  {
122  return menu.Deploy(panel, select);
123  }
124  };
125 
129  {
130  private:
131 
132  class menuEntry
133  {
134  public:
135  unsigned int id;
136  std::string name;
137  menuEntry(const char *_title, unsigned int _id) : name(_title), id(_id) {}
138  menuEntry(std::string _title, unsigned int _id) : name(_title), id(_id) {}
139  const char *getName(void) const {return name.c_str();}
140  const int getID(void) const {return id;}
141  };
142 
143  std::vector<menuEntry> Entries;
144  ContextMenu menu;
145  protected:
146  size_t count(void);
147  const char *name(int n);
148  public:
149  DynamicContextMenu (int _width);
150  int Deploy(LWPanelID panel, int select);
151  int Deploy(LWPanel &panel, int select);
153  void AddEntry (const char *entry, unsigned int id);
154  void AddEntry (std::string entry, unsigned int id);
155  };
156 }
157 #endif // LWPP_CONTEXMENU_H