00001
00005 #ifndef __GMENU_H
00006 #define __GMENU_H
00007
00008
00009 #if defined __GTK_H__
00010 #include <GMenuImpl.h>
00011 typedef MenuClickImpl *OsSubMenu;
00012 typedef MenuItemImpl *OsMenuItem;
00013 #elif defined WIN32
00014 typedef HMENU OsSubMenu;
00015 typedef MENUITEMINFO OsMenuItem;
00016
00017 #ifndef COLOR_MENUHILIGHT
00018 #define COLOR_MENUHILIGHT 29
00019 #endif
00020 #ifndef COLOR_MENUBAR
00021 #define COLOR_MENUBAR 30
00022 #endif
00023 #elif defined BEOS
00024 typedef BMenu *OsSubMenu;
00025 typedef BMenuItem *OsMenuItem;
00026 #elif defined ATHEOS
00027 #include <gui/menu.h>
00028 typedef os::Menu *OsSubMenu;
00029 typedef os::MenuItem *OsMenuItem;
00030 #elif defined MAC
00031 typedef MenuRef OsSubMenu;
00032 typedef MenuItemIndex OsMenuItem;
00033 #else
00034 #error "Not impl."
00035 #endif
00036
00037 #include "GXmlTree.h"
00038 #include "Res.h"
00039
00041
00042 class LgiClass GMenuLoader
00043 {
00044 friend class GMenuItem;
00045 friend class GMenu;
00046 friend class GSubMenu;
00047 friend class MenuImpl;
00048 friend class SubMenuImplPrivate;
00049
00050 protected:
00051 #ifdef WIN32
00052 OsSubMenu Info;
00053 #endif
00054 List<GMenuItem> Items;
00055
00056 public:
00057 GMenuLoader()
00058 {
00059 #ifdef WIN32
00060 Info = 0;
00061 #endif
00062 }
00063
00064 bool Load( class LgiMenuRes *MenuRes,
00065 GXmlTag *Tag,
00066 ResFileFormat Format,
00067 class TagHash *TagList);
00068
00069 virtual GMenuItem *AppendItem(const char *Str, int Id, bool Enabled, int Where = -1, char *Shortcut = 0) = 0;
00070 virtual GSubMenu *AppendSub(const char *Str, int Where = -1) = 0;
00071 virtual GMenuItem *AppendSeparator(int Where = -1) = 0;
00072 };
00073
00075 class LgiClass GSubMenu :
00076 public GBase,
00077 public GTarget,
00078
00079 public GMenuLoader,
00080 public GItemContainer
00081 {
00082 friend class GMenuItem;
00083 friend class GMenu;
00084 friend class SubMenuImpl;
00085 friend class MenuItemImpl;
00086 friend class MenuImpl;
00087
00088 #if !WIN32NATIVE
00089 OsSubMenu Info;
00090 #endif
00091
00092 #if WIN32NATIVE
00093
00094 HWND TrackHandle;
00095
00096
00097 #elif defined BEOS
00098
00099 void _CopyMenu(BMenu *To, GSubMenu *From);
00100
00101 #else
00102
00103 bool OnKey(GKey &k);
00104
00105 #endif
00106
00107 protected:
00109 GMenuItem *Parent;
00111 GMenu *Menu;
00113 GViewI *Window;
00114
00115 void OnAttach(bool Attach);
00116
00117 public:
00119 GSubMenu
00120 (
00122 const char *name = "",
00124 bool Popup = true
00125 );
00126 virtual ~GSubMenu();
00127
00129 OsSubMenu Handle() { return Info; }
00130
00132 GMenuItem *AppendItem
00133 (
00146 const char *Str,
00148 int Id,
00150 bool Enabled = true,
00152 int Where = -1,
00153
00154 char *Shortcut = 0
00155 );
00156
00158 GSubMenu *AppendSub
00159 (
00161 const char *Str,
00163 int Where = -1
00164 );
00165
00167 GMenuItem *AppendSeparator(int Where = -1);
00168
00170 void Empty();
00171
00173 bool RemoveItem
00174 (
00176 int i
00177 );
00178
00180 bool RemoveItem
00181 (
00183 GMenuItem *Item
00184 );
00185
00187 int Length();
00188
00190 GMenuItem *ItemAt
00191 (
00193 int i
00194 );
00195
00197 GMenuItem *FindItem
00198 (
00200 int Id
00201 );
00202
00204 GSubMenu *FindSubMenu
00205 (
00207 int Id
00208 );
00209
00211 int Float
00212 (
00214 GView *Parent,
00216 int x,
00218 int y,
00220 bool Left = false
00221 );
00222
00224 GMenuItem *GetParent() { return Parent; }
00225
00227 GMenu *GetMenu() { return Menu; }
00228 };
00229
00231 class LgiClass GMenuItem :
00232 public GBase,
00233 public GTarget
00234
00235 {
00236 friend class GSubMenu;
00237 friend class GMenu;
00238 friend class GView;
00239 friend class LgiMenuItem;
00240 friend class SubMenuImpl;
00241 friend class MenuItemImpl;
00242 friend class MenuImpl;
00243 friend class SubMenuImplPrivate;
00244
00245 private:
00246 #ifdef WIN32
00247 bool Insert(int Pos);
00248 bool Update();
00249 #endif
00250
00251 protected:
00252 GMenu *Menu;
00253 GSubMenu *Parent;
00254 GSubMenu *Child;
00255 int Position;
00256 int _Icon;
00257
00258 OsMenuItem Info;
00259 class GMenuItemPrivate *d;
00260
00261 #if defined BEOS
00262 BMessage *Msg;
00263 #else
00264 int _Id;
00265 bool _Check;
00266 bool _Enabled;
00267 #endif
00268
00269 virtual void _Measure(GdcPt2 &Size);
00270 virtual void _Paint(GSurface *pDC, int Flags);
00271 virtual void _PaintText(GSurface *pDC, int x, int y, int Width);
00272
00273 void OnAttach(bool Attach);
00274
00275 public:
00276 GMenuItem();
00277 #if defined BEOS
00278 GMenuItem(BMenuItem *item);
00279 GMenuItem(GSubMenu *p);
00280 #else
00281 GMenuItem(GMenu *m, GSubMenu *p, int Pos, char *Shortcut = 0);
00282 #endif
00283 virtual ~GMenuItem();
00284
00286 GSubMenu *Create();
00288 bool Remove();
00290 GSubMenu *GetParent();
00292 bool ScanForAccel();
00294 OsMenuItem Handle() { return Info; }
00295
00297 void Id(int i);
00299 void Separator(bool s);
00301 void Checked(bool c);
00304 bool Name(const char *n);
00306 void Enabled(bool e);
00307 void Visible(bool v);
00308 void Focus(bool f);
00310 void Sub(GSubMenu *s);
00312 void Icon(int i);
00313
00315 int Id();
00317 char *Name();
00319 bool Separator();
00321 bool Checked();
00323 bool Enabled();
00324 bool Visible();
00325 bool Focus();
00327 GSubMenu *Sub();
00329 int Icon();
00330 };
00331
00333 class LgiClass GAccelerator
00334 {
00335 int Flags;
00336 int Key;
00337 int Id;
00338
00339 public:
00340 GAccelerator(int flags, int key, int id);
00341
00342 int GetId() { return Id; }
00343
00345 bool Match(GKey &k);
00346 };
00347
00391 class LgiClass GMenu :
00392 public GSubMenu
00393 {
00394 friend class GSubMenu;
00395 friend class GMenuItem;
00396 friend class GWindow;
00397
00398 static GFont *_Font;
00399 class GMenuPrivate *d;
00400
00401 #if defined WIN32
00402 void OnChange();
00403 #else
00404 void OnChange() {}
00405 #endif
00406
00407 protected:
00409 List<GAccelerator> Accel;
00410
00411 public:
00413 GMenu();
00414
00416 virtual ~GMenu();
00417
00419 static GFont *GetFont();
00420
00422 GViewI *WindowHandle() { return Window; }
00423
00425 bool Attach(GViewI *p);
00426
00428 bool Detach();
00429
00431 bool Load
00432 (
00434 GView *p,
00436 const char *Res,
00438 const char *Tags = 0
00439 );
00440
00443 bool OnKey
00444 (
00446 GView *v,
00448 GKey &k
00449 );
00450
00451 #if defined(WIN32)
00452 static int _OnEvent(GMessage *Msg);
00453 #elif defined(BEOS)
00454 GRect GetPos();
00455 #endif
00456 };
00457
00458 #endif
00459
00460
00461
00462