00001
00005 #ifndef __GMENU_H
00006 #define __GMENU_H
00007
00008
00009 #if defined WIN32
00010 typedef HMENU OsSubMenu;
00011 typedef MENUITEMINFO OsMenuItem;
00012 #elif defined BEOS
00013 typedef BMenu *OsSubMenu;
00014 typedef BMenuItem *OsMenuItem;
00015 #elif defined ATHEOS
00016 #include <gui/menu.h>
00017 typedef os::Menu *OsSubMenu;
00018 typedef os::MenuItem *OsMenuItem;
00019 #elif defined XWIN
00020 #include <GMenuImpl.h>
00021 typedef MenuClickImpl *OsSubMenu;
00022 typedef MenuItemImpl *OsMenuItem;
00023 #endif
00024
00025 #include "GXmlTree.h"
00026 #include "Res.h"
00027
00029
00030 class LgiClass GMenuLoader
00031 {
00032 friend class GMenuItem;
00033 friend class GMenu;
00034 friend class GSubMenu;
00035 friend class MenuImpl;
00036 friend class SubMenuImplPrivate;
00037
00038 protected:
00039 #ifdef WIN32
00040 OsSubMenu Info;
00041 #endif
00042 List<GMenuItem> Items;
00043
00044 public:
00045 GMenuLoader()
00046 {
00047 #ifdef WIN32
00048 Info = 0;
00049 #endif
00050 }
00051
00052 bool Load( class LgiMenuRes *MenuRes,
00053 GXmlTag *Tag,
00054 ResFileFormat Format,
00055 GHashTable &TagList);
00056
00057 virtual GMenuItem *AppendItem(char *Str, int Id, bool Enabled, int Where = -1) = 0;
00058 virtual GSubMenu *AppendSub(char *Str, int Where = -1) = 0;
00059 virtual GMenuItem *AppendSeparator(int Where = -1) = 0;
00060 };
00061
00063 class LgiClass GSubMenu :
00064 public GObject,
00065 public GTarget,
00066 public GFlags,
00067 public GMenuLoader,
00068 public GItemContainer
00069 {
00070 friend class GMenuItem;
00071 friend class GMenu;
00072 friend class SubMenuImpl;
00073 friend class MenuItemImpl;
00074 friend class MenuImpl;
00075
00076 #ifndef WIN32
00077 OsSubMenu Info;
00078 #endif
00079
00080 #if defined WIN32
00081
00082 HWND TrackHandle;
00083
00084
00085 #elif defined BEOS
00086
00087 void _CopyMenu(BMenu *To, GSubMenu *From);
00088
00089 #else
00090
00091 bool OnKey(GKey &k);
00092
00093 #endif
00094
00095 protected:
00097 GMenuItem *Parent;
00099 GMenu *Menu;
00101 GView *Window;
00102
00103 public:
00105 GSubMenu
00106 (
00108 char *name = (char*)"",
00110 bool Popup = true
00111 );
00112 virtual ~GSubMenu();
00113
00115 OsSubMenu Handle() { return Info; }
00116
00118 GMenuItem *AppendItem
00119 (
00132 char *Str,
00134 int Id,
00136 bool Enabled,
00138 int Where = -1
00139 );
00140
00142 GSubMenu *AppendSub
00143 (
00145 char *Str,
00147 int Where = -1
00148 );
00149
00151 GMenuItem *AppendSeparator(int Where = -1);
00152
00154 void Empty();
00155
00157 bool RemoveItem
00158 (
00160 int i
00161 );
00162
00164 bool RemoveItem
00165 (
00167 GMenuItem *Item
00168 );
00169
00171 GMenuItem *ItemAt
00172 (
00174 int i
00175 );
00176
00178 GMenuItem *FindItem
00179 (
00181 int Id
00182 );
00183
00185 GSubMenu *FindSubMenu
00186 (
00188 int Id
00189 );
00190
00192 int Float
00193 (
00195 GView *Parent,
00197 int x,
00199 int y,
00201 bool Left = false
00202 );
00203
00205 GMenuItem *GetParent() { return Parent; }
00206
00208 GMenu *GetMenu() { return Menu; }
00209 };
00210
00212 class LgiClass GMenuItem :
00213 public GObject,
00214 public GTarget,
00215 public GFlags
00216 {
00217 friend class GSubMenu;
00218 friend class GMenu;
00219 friend class GView;
00220 friend class LgiMenuItem;
00221 friend class SubMenuImpl;
00222 friend class MenuItemImpl;
00223 friend class MenuImpl;
00224 friend class SubMenuImplPrivate;
00225
00226 private:
00227 #ifdef WIN32
00228 bool Insert(int Pos);
00229 bool Update();
00230 #endif
00231
00232 protected:
00233 GMenu *Menu;
00234 GSubMenu *Parent;
00235 GSubMenu *Child;
00236 int Position;
00237 int _Icon;
00238
00239 OsMenuItem Info;
00240 class GMenuItemPrivate *d;
00241
00242 #if defined BEOS
00243
00244 BMessage *Msg;
00245
00246 #else
00247
00248 int _Id;
00249 bool _Check;
00250
00251 #endif
00252
00253 virtual void _Measure(GdcPt2 &Size);
00254 virtual void _Paint(GSurface *pDC, int Flags);
00255 virtual void _PaintText(GSurface *pDC, int x, int y, int Width);
00256
00257 public:
00258 GMenuItem();
00259 #if defined BEOS
00260 GMenuItem(BMenuItem *item);
00261 GMenuItem(GSubMenu *p);
00262 #else
00263 GMenuItem(GMenu *m, GSubMenu *p, int Pos);
00264 #endif
00265 virtual ~GMenuItem();
00266
00268 GSubMenu *Create();
00270 bool Remove();
00272 GSubMenu *GetParent();
00274 bool ScanForAccel();
00276 OsMenuItem Handle() { return Info; }
00277
00279 void Id(int i);
00281 void Separator(bool s);
00283 void Checked(bool c);
00286 bool Name(char *n);
00288 void Enabled(bool e);
00289 void Visible(bool v);
00290 void Focus(bool f);
00292 void Sub(GSubMenu *s);
00294 void Icon(int i);
00295
00297 int Id();
00299 char *Name();
00301 bool Separator();
00303 bool Checked();
00305 bool Enabled();
00306 bool Visible();
00307 bool Focus();
00309 GSubMenu *Sub();
00311 int Icon();
00312 };
00313
00315 class LgiClass GAccelerator
00316 {
00317 int Flags;
00318 int Key;
00319 int Id;
00320
00321 public:
00322 GAccelerator(int flags, int key, int id);
00323
00324 int GetId() { return Id; }
00325
00327 bool Match(GKey &k);
00328 };
00329
00373 class LgiClass GMenu :
00374 public GSubMenu
00375 {
00376 friend class GSubMenu;
00377 friend class GMenuItem;
00378 friend class GWindow;
00379
00380 static GFont *_Font;
00381 class GMenuPrivate *d;
00382
00383 #if defined WIN32
00384 void OnChange();
00385 #else
00386 void OnChange() {}
00387 #endif
00388
00389 protected:
00391 List<GAccelerator> Accel;
00392
00393 public:
00395 GMenu();
00396
00398 virtual ~GMenu();
00399
00401 static GFont *GetFont();
00402
00404 GView *WindowHandle() { return Window; }
00405
00407 bool Attach(GView *p);
00408
00410 bool Detach();
00411
00413 bool Load
00414 (
00416 GView *p,
00418 char *Res,
00420 char *Tags = 0
00421 );
00422
00425 bool OnKey
00426 (
00428 GView *v,
00430 GKey &k
00431 );
00432
00433 #if defined(WIN32)
00434 static int _OnEvent(GMessage *Msg);
00435 #elif defined(BEOS)
00436 GRect GetPos();
00437 #endif
00438 };
00439
00440 #endif
00441
00442
00443
00444