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 #elif defined MAC
00024 #include "LgiOsClasses.h"
00025 #else
00026 #error "Not impl."
00027 #endif
00028
00029 #include "GXmlTree.h"
00030 #include "Res.h"
00031
00033
00034 class LgiClass GMenuLoader
00035 {
00036 friend class GMenuItem;
00037 friend class GMenu;
00038 friend class GSubMenu;
00039 friend class MenuImpl;
00040 friend class SubMenuImplPrivate;
00041
00042 protected:
00043 #ifdef WIN32
00044 OsSubMenu Info;
00045 #endif
00046 List<GMenuItem> Items;
00047
00048 public:
00049 GMenuLoader()
00050 {
00051 #ifdef WIN32
00052 Info = 0;
00053 #endif
00054 }
00055
00056 bool Load( class LgiMenuRes *MenuRes,
00057 GXmlTag *Tag,
00058 ResFileFormat Format,
00059 GHashTable &TagList);
00060
00061 virtual GMenuItem *AppendItem(char *Str, int Id, bool Enabled, int Where = -1) = 0;
00062 virtual GSubMenu *AppendSub(char *Str, int Where = -1) = 0;
00063 virtual GMenuItem *AppendSeparator(int Where = -1) = 0;
00064 };
00065
00067 class LgiClass GSubMenu :
00068 public GObject,
00069 public GTarget,
00070
00071 public GMenuLoader,
00072 public GItemContainer
00073 {
00074 friend class GMenuItem;
00075 friend class GMenu;
00076 friend class SubMenuImpl;
00077 friend class MenuItemImpl;
00078 friend class MenuImpl;
00079
00080 #ifndef WIN32
00081 OsSubMenu Info;
00082 #endif
00083
00084 #if defined WIN32
00085
00086 HWND TrackHandle;
00087
00088
00089 #elif defined BEOS
00090
00091 void _CopyMenu(BMenu *To, GSubMenu *From);
00092
00093 #else
00094
00095 bool OnKey(GKey &k);
00096
00097 #endif
00098
00099 protected:
00101 GMenuItem *Parent;
00103 GMenu *Menu;
00105 GViewI *Window;
00106
00107 public:
00109 GSubMenu
00110 (
00112 char *name = (char*)"",
00114 bool Popup = true
00115 );
00116 virtual ~GSubMenu();
00117
00119 OsSubMenu Handle() { return Info; }
00120
00122 GMenuItem *AppendItem
00123 (
00136 char *Str,
00138 int Id,
00140 bool Enabled,
00142 int Where = -1
00143 );
00144
00146 GSubMenu *AppendSub
00147 (
00149 char *Str,
00151 int Where = -1
00152 );
00153
00155 GMenuItem *AppendSeparator(int Where = -1);
00156
00158 void Empty();
00159
00161 bool RemoveItem
00162 (
00164 int i
00165 );
00166
00168 bool RemoveItem
00169 (
00171 GMenuItem *Item
00172 );
00173
00175 GMenuItem *ItemAt
00176 (
00178 int i
00179 );
00180
00182 GMenuItem *FindItem
00183 (
00185 int Id
00186 );
00187
00189 GSubMenu *FindSubMenu
00190 (
00192 int Id
00193 );
00194
00196 int Float
00197 (
00199 GView *Parent,
00201 int x,
00203 int y,
00205 bool Left = false
00206 );
00207
00209 GMenuItem *GetParent() { return Parent; }
00210
00212 GMenu *GetMenu() { return Menu; }
00213 };
00214
00216 class LgiClass GMenuItem :
00217 public GObject,
00218 public GTarget
00219
00220 {
00221 friend class GSubMenu;
00222 friend class GMenu;
00223 friend class GView;
00224 friend class LgiMenuItem;
00225 friend class SubMenuImpl;
00226 friend class MenuItemImpl;
00227 friend class MenuImpl;
00228 friend class SubMenuImplPrivate;
00229
00230 private:
00231 #ifdef WIN32
00232 bool Insert(int Pos);
00233 bool Update();
00234 #endif
00235
00236 protected:
00237 GMenu *Menu;
00238 GSubMenu *Parent;
00239 GSubMenu *Child;
00240 int Position;
00241 int _Icon;
00242
00243 OsMenuItem Info;
00244 class GMenuItemPrivate *d;
00245
00246 #if defined BEOS
00247
00248 BMessage *Msg;
00249
00250 #else
00251
00252 int _Id;
00253 bool _Check;
00254 bool _Enabled;
00255
00256 #endif
00257
00258 virtual void _Measure(GdcPt2 &Size);
00259 virtual void _Paint(GSurface *pDC, int Flags);
00260 virtual void _PaintText(GSurface *pDC, int x, int y, int Width);
00261
00262 public:
00263 GMenuItem();
00264 #if defined BEOS
00265 GMenuItem(BMenuItem *item);
00266 GMenuItem(GSubMenu *p);
00267 #else
00268 GMenuItem(GMenu *m, GSubMenu *p, int Pos);
00269 #endif
00270 virtual ~GMenuItem();
00271
00273 GSubMenu *Create();
00275 bool Remove();
00277 GSubMenu *GetParent();
00279 bool ScanForAccel();
00281 OsMenuItem Handle() { return Info; }
00282
00284 void Id(int i);
00286 void Separator(bool s);
00288 void Checked(bool c);
00291 bool Name(char *n);
00293 void Enabled(bool e);
00294 void Visible(bool v);
00295 void Focus(bool f);
00297 void Sub(GSubMenu *s);
00299 void Icon(int i);
00300
00302 int Id();
00304 char *Name();
00306 bool Separator();
00308 bool Checked();
00310 bool Enabled();
00311 bool Visible();
00312 bool Focus();
00314 GSubMenu *Sub();
00316 int Icon();
00317 };
00318
00320 class LgiClass GAccelerator
00321 {
00322 int Flags;
00323 int Key;
00324 int Id;
00325
00326 public:
00327 GAccelerator(int flags, int key, int id);
00328
00329 int GetId() { return Id; }
00330
00332 bool Match(GKey &k);
00333 };
00334
00378 class LgiClass GMenu :
00379 public GSubMenu
00380 {
00381 friend class GSubMenu;
00382 friend class GMenuItem;
00383 friend class GWindow;
00384
00385 static GFont *_Font;
00386 class GMenuPrivate *d;
00387
00388 #if defined WIN32
00389 void OnChange();
00390 #else
00391 void OnChange() {}
00392 #endif
00393
00394 protected:
00396 List<GAccelerator> Accel;
00397
00398 public:
00400 GMenu();
00401
00403 virtual ~GMenu();
00404
00406 static GFont *GetFont();
00407
00409 GViewI *WindowHandle() { return Window; }
00410
00412 bool Attach(GViewI *p);
00413
00415 bool Detach();
00416
00418 bool Load
00419 (
00421 GView *p,
00423 char *Res,
00425 char *Tags = 0
00426 );
00427
00430 bool OnKey
00431 (
00433 GView *v,
00435 GKey &k
00436 );
00437
00438 #if defined(WIN32)
00439 static int _OnEvent(GMessage *Msg);
00440 #elif defined(BEOS)
00441 GRect GetPos();
00442 #endif
00443 };
00444
00445 #endif
00446
00447
00448
00449