1
0

popup.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. // PopupMenu NONPORTABLE, NewPopupMenu portable
  2. #ifndef _POPUP_H
  3. #define _POPUP_H
  4. #include <wasabicfg.h>
  5. #include <bfc/string/StringW.h>
  6. #include <bfc/PtrList.h>
  7. #include <api/locales/xlatstr.h>
  8. //#define WANT_NEW_POPUPMENU
  9. class PopupMenu;
  10. class PopupMenuCallback
  11. {
  12. public:
  13. virtual PopupMenu *popupMenuCallback(PopupMenu *parent, intptr_t param) = 0; // returns the new popupmenu to be displayed
  14. };
  15. enum { POPUP_ANCHOR_UL, POPUP_ANCHOR_LL, POPUP_ANCHOR_UR, POPUP_ANCHOR_LR };
  16. #ifndef WASABI_WANT_FF_POPUP
  17. class PopupMenuEntry
  18. {
  19. public:
  20. PopupMenuEntry(const wchar_t *txt, int cmd, PopupMenu *_submenu, int _checked, int _disabled, PopupMenuCallback *cb = NULL, int cbparam = 0) : text(_(txt)), command(cmd), submenu(_submenu), checked(_checked), disabled(_disabled), callback(cb), callbackparam(cbparam) {} // txt = null for separators and menus, cmd = -1 for separators and submenus, if submenu == null && cmd == -1 and text == NULL then it's a separator
  21. virtual ~PopupMenuEntry() {}
  22. int getCommand() { return command; }
  23. const wchar_t *getText() { return text; }
  24. PopupMenu *getSubmenu() { return submenu; }
  25. int getChecked() { return checked; }
  26. int getDisabled() { return disabled; }
  27. int isSeparator() { return command == -1 && submenu == NULL && text == NULL; }
  28. int isSubmenu() { return (command == -1 && submenu != NULL) || callback; }
  29. void setChecked(int check) { checked = check; }
  30. void setDisabled(int disable) { disabled = disable; }
  31. PopupMenuCallback *getCallback() { return callback; }
  32. int getCallbackParam() { return callbackparam; }
  33. private:
  34. StringW text;
  35. int command;
  36. PopupMenu *submenu;
  37. int checked;
  38. int disabled;
  39. PopupMenuCallback *callback;
  40. int callbackparam;
  41. };
  42. class SortMenuEntries
  43. {
  44. public:
  45. static int compareItem(PopupMenuEntry *p1, PopupMenuEntry *p2)
  46. {
  47. if (p1->getCommand() < p2->getCommand()) return -1;
  48. if (p1->getCommand() > p2->getCommand()) return 1;
  49. return 0;
  50. }
  51. static int compareAttrib(const wchar_t *attrib, PopupMenuEntry *item)
  52. {
  53. int c = *(int *)attrib;
  54. if (c < item->getCommand()) return -1;
  55. if (c > item->getCommand()) return 1;
  56. return 0;
  57. }
  58. };
  59. class PopupMenu
  60. {
  61. public:
  62. PopupMenu();
  63. PopupMenu(ifc_window *parent);
  64. PopupMenu(PopupMenu *parent);
  65. ~PopupMenu();
  66. virtual void addSubMenu(PopupMenu *menu, const wchar_t *text, int disabled = FALSE);
  67. virtual void addSubMenuCallback(const wchar_t *text, PopupMenuCallback *cb, int param);
  68. virtual void addCommand(const wchar_t *text, int command, int checked = 0, int disabled = 0, int addpos = -1);
  69. virtual void addSeparator(int addpos = -1);
  70. virtual void checkCommand(int cmd, int check);
  71. virtual void disableCommand(int cmd, int disable);
  72. virtual int popAtXY(int x, int y, int native = 0);
  73. virtual int popAnchored(int type = POPUP_ANCHOR_LL); // dropped off the sourceWnd given above
  74. virtual int popAtMouse();
  75. virtual int getNumCommands();
  76. virtual const wchar_t *getCommandText(int command);
  77. OSMENUHANDLE getOSMenuHandle();
  78. virtual void abort();
  79. private:
  80. void rebuildMenu();
  81. void invalidateMenu(); // no virtual please (it's called in the destructor)
  82. ifc_window *getParent() { return parent; }
  83. PtrList<PopupMenuEntry> entries;
  84. PtrListQuickSorted<PopupMenuEntry, SortMenuEntries> sortedentries;
  85. OSMENUHANDLE hmenu;
  86. ifc_window *parent;
  87. };
  88. #else // WASABI_WANT_FF_POPUP
  89. #include "../bfc/basewnd.h"
  90. #include "../bfc/ptrlist.h"
  91. #include <tataki/bitmap/autobitmap.h>
  92. #include "../studio/skincb.h"
  93. #define POPUP_TIMERID 1171
  94. class PopupMenu;
  95. class ButtonWnd;
  96. class MenuButtonSurface;
  97. class _PopupMenu
  98. {
  99. public:
  100. virtual ~_PopupMenu() {}
  101. virtual void addSubMenu(PopupMenu *menu, const wchar_t *text, int disabled = FALSE) = 0;
  102. virtual void addSubMenuImage(PopupMenu *menu, const wchar_t *bitmap, const wchar_t *pushedbitmap = 0, const wchar_t *highlightbitmap = 0) = 0;
  103. virtual void addSubMenuCallback(const wchar_t *text, PopupMenuCallback *cb, int param) = 0;
  104. virtual void addCommand(const char *text, int command, int checked = 0, int disabled = 0, int addpos = -1) = 0;
  105. virtual void addCommandImage(const wchar_t *bitmap, const wchar_t *pushedbitmap, const wchar_t *highlightbitmap, int command, int checked, int disabled, int addpos = -1) = 0;
  106. virtual void addSeparator(int addpos = -1) = 0;
  107. virtual void checkCommand(int cmd, int check) = 0;
  108. virtual void disableCommand(int cmd, int disable) = 0;
  109. virtual int popAtXY(int x, int y) = 0;
  110. virtual int popAnchored(int type = POPUP_ANCHOR_LL) = 0; // dropped off the sourceWnd given above
  111. virtual int popAtMouse() = 0;
  112. virtual void showAtXY(int x, int y, int *rc, int revside = 0, int parentW = 0) = 0;
  113. virtual int getNumCommands() = 0;
  114. virtual const wchar_t *getCommandText(int command) = 0;
  115. virtual void onPostPop(intptr_t result) = 0;
  116. virtual void selectFirst() = 0;
  117. };
  118. #ifndef WANT_NEW_POPUPMENU
  119. #define POPUPMENU_PARENT BaseWnd
  120. class PopupMenu : public _PopupMenu, public POPUPMENU_PARENT, public SkinCallbackI
  121. {
  122. public:
  123. PopupMenu(ifc_window *sourceWnd);
  124. PopupMenu(HWND sourceWnd);
  125. PopupMenu(PopupMenu *sourceWnd);
  126. PopupMenu();
  127. virtual ~PopupMenu();
  128. void addSubMenu(PopupMenu *menu, const wchar_t *text, int disabled = FALSE);
  129. void addSubMenuImage(PopupMenu *menu, const wchar_t *bitmap, const wchar_t *pushedbitmap = 0, const wchar_t *highlightbitmap = 0);
  130. void addSubMenuCallback(const wchar_t *text, PopupMenuCallback *cb, int param);
  131. void addCommand(const wchar_t *text, int command, int checked = 0, int disabled = 0, int addpos = -1);
  132. void addCommandImage(const wchar_t *bitmap, const wchar_t *pushedbitmap, const wchar_t *highlightbitmap, int command, int checked, int disabled, int addpos = -1);
  133. void addSeparator(int addpos = -1);
  134. void checkCommand(int cmd, int check);
  135. void disableCommand(int cmd, int disable);
  136. int popAtXY(int x, int y);
  137. int popAnchored(int type = POPUP_ANCHOR_LL); // dropped off the sourceWnd given above
  138. int popAtMouse();
  139. int getNumCommands();
  140. virtual int bypassModal() { return 1; }
  141. const wchar_t *getCommandText(int command);
  142. virtual int onPaint(Canvas *canvas);
  143. virtual int childNotify(ifc_window *child, int msg, intptr_t param1 = 0, intptr_t param2 = 0);
  144. virtual int onLeftButtonDown(int x, int y);
  145. virtual int onRightButtonDown(int x, int y);
  146. virtual int onMouseMove(int x, int y); // only called when mouse captured
  147. virtual int onLeftButtonUp(int x, int y);
  148. virtual int onRightButtonUp(int x, int y);
  149. virtual void timerCallback(int id);
  150. virtual int onKillFocus();
  151. virtual int skincb_onCheckPreventSwitch(const char *skinname);
  152. virtual int onKeyDown(int code);
  153. virtual void navigate(int p, int f = 0); // 1 = next, -1 = previous, 0 = self (open submenu or run action)
  154. virtual void onSetVisible(int p);
  155. virtual void selectFirst();
  156. virtual int onSysKeyDown(int code, int d);
  157. virtual void abort();
  158. virtual void setFriendlyId(const wchar_t *id);
  159. virtual MenuButtonSurface *getNextFriend() { return chainmenu; }
  160. protected:
  161. virtual int onInit();
  162. void invalidateItem(int i);
  163. String translateButtonText(const wchar_t *text);
  164. virtual void onPostPop(intptr_t result) {}
  165. // used internally, as well as by parent Popups.
  166. void showAtXY(int x, int y, int *rc, int revside = 0, int parentW = 0);
  167. void hide();
  168. int isMine(int x, int y);
  169. private:
  170. int getWhichItem(POINT &p);
  171. void onButtonUp(int wb, int x, int y);
  172. void onButtonDown(int wb, int x, int y);
  173. void resetTimer(int p);
  174. void initMenuCallback(int item);
  175. int bdown;
  176. int lastitem;
  177. int rcode;
  178. int *rcp;
  179. typedef struct
  180. {
  181. int cmd;
  182. ButtonWnd *butt;
  183. PopupMenu *menu;
  184. PopupMenuCallback *cb;
  185. int issep;
  186. int cbparam;
  187. }
  188. ItemT;
  189. PtrList<ItemT> items;
  190. ifc_window *parentRootWnd;
  191. HWND parentWnd;
  192. AutoSkinBitmap tex, ful, fur, fll, flr, fl, fr, ft, fb, sr, sl, sc;
  193. int openmenuid;
  194. int timerset;
  195. int timeritem;
  196. int popupdelay;
  197. int reverse_side;
  198. ifc_window *init_with;
  199. int disable_autopop;
  200. int kbdhooked;
  201. int toplevelmenu;
  202. POINT lastxy;
  203. int keyctrl;
  204. String friendid;
  205. MenuButtonSurface *chainmenu;
  206. #ifdef WASABI_COMPILE_SKIN
  207. String switchskinto;
  208. #endif
  209. };
  210. #else
  211. #include "guiobjwnd.h"
  212. #include "script/c_script/c_grouplist.h"
  213. #include "../bfc/popexitcb.h"
  214. #include "../bfc/notifmsg.h"
  215. #define POPUPMENU_PARENT GuiObjectWnd
  216. enum {
  217. POPUPITEM_TYPE_TEXT = 0,
  218. POPUPITEM_TYPE_IMAGE,
  219. POPUPITEM_TYPE_SEPARATOR,
  220. };
  221. typedef struct
  222. {
  223. int type;
  224. int cmd;
  225. PopupMenu *menu;
  226. PopupMenuCallback *cb;
  227. String txt;
  228. int checked;
  229. int disabled;
  230. int cbparam;
  231. }
  232. ItemT;
  233. class PopupMenu : public _PopupMenu, public POPUPMENU_PARENT, public PopupExitCallbackI
  234. {
  235. public:
  236. PopupMenu(ifc_window *sourceWnd);
  237. // PopupMenu(HWND sourceWnd);
  238. PopupMenu(PopupMenu *sourceWnd);
  239. PopupMenu();
  240. virtual ~PopupMenu();
  241. virtual void addSubMenu(PopupMenu *menu, const wchar_t *text, int disabled = FALSE);
  242. virtual void addSubMenuImage(PopupMenu *menu, const wchar_t *bitmap, const wchar_t *pushedbitmap = 0, const wchar_t *highlightbitmap = 0) {}
  243. virtual void addSubMenuCallback(const wchar_t *text, PopupMenuCallback *cb, int param);
  244. virtual void addCommand(const wchar_t *text, int command, int checked = 0, int disabled = 0, int addpos = -1);
  245. virtual void addCommandImage(const wchar_t *bitmap, const wchar_t *pushedbitmap, const wchar_t *highlightbitmap, int command, int checked, int disabled, int addpos = -1) {}
  246. virtual void addSeparator(int addpos = -1) {}
  247. virtual void checkCommand(int cmd, int check) {}
  248. virtual void disableCommand(int cmd, int disable) {}
  249. virtual int popAtXY(int x, int y);
  250. virtual int popAnchored(int type = POPUP_ANCHOR_LL);
  251. virtual int popAtMouse();
  252. virtual void showAtXY(int x, int y, int *rc, int revside = 0, int parentW = 0);
  253. virtual int getNumCommands() { return 0;}
  254. virtual const wchar_t *getCommandText(int command) { return NULL; }
  255. virtual void onPostPop(intptr_t result) {}
  256. virtual int onInit();
  257. virtual void onNewContent();
  258. virtual int popupexitcb_onExitPopup();
  259. virtual ifc_dependent *popupexit_getDependencyPtr() { return getDependencyPtr(); }
  260. private:
  261. virtual int bypassModal() { return 1; }
  262. String translateButtonText(const wchar_t *text);
  263. void fillContent();
  264. void addItem(ItemT *item);
  265. void initMenuCallback(int item);
  266. void myInit();
  267. int reverse_side;
  268. int rcode;
  269. PtrList<ItemT> items;
  270. int menuchecks;
  271. int submenus;
  272. C_GroupList *c_grouplist;
  273. int totalheight, totalwidth;
  274. };
  275. #endif
  276. #endif // WASABI_WANT_FF_POPUP
  277. #endif