svc_contextCmd.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef _SVC_CONTEXTCMD_H
  2. #define _SVC_CONTEXTCMD_H
  3. #include <bfc/dispatch.h>
  4. #include <api/service/services.h>
  5. namespace ContextCmdSortVal {
  6. enum ContextCmdSortVal {
  7. BEGINNING = 0,
  8. MIDDLE = 32767,
  9. END = 65535,
  10. };
  11. };
  12. class DragItem;
  13. class NOVTABLE svc_contextCmd : public Dispatchable {
  14. protected:
  15. svc_contextCmd() {}
  16. ~svc_contextCmd() {}
  17. public:
  18. static FOURCC getServiceType() { return WaSvc::CONTEXTCMD; }
  19. int testItem(DragItem *item, const wchar_t *menu_path);
  20. int getSubMenu(DragItem *item, const wchar_t *menu_path);
  21. const wchar_t *getSubMenuText(const wchar_t *menu_path);
  22. const wchar_t *getCommand(DragItem *item, int n);
  23. int getEnabled(DragItem *item, int n);
  24. int getChecked(DragItem *item, int n);
  25. int getSortVal(DragItem *item, int n);
  26. void onCommand(DragItem *item, int n);
  27. protected:
  28. enum {
  29. TESTITEM,
  30. GETSUBMENU,
  31. GETSUBMENUTEXT,
  32. GETCOMMAND,
  33. GETENABLED,
  34. GETCHECKED,
  35. GETSORTVAL,
  36. ONCOMMAND,
  37. };
  38. };
  39. inline int svc_contextCmd::testItem(DragItem *item, const wchar_t *menu_path) {
  40. return _call(TESTITEM, 0, item, menu_path);
  41. }
  42. inline
  43. int svc_contextCmd::getSubMenu(DragItem *item, const wchar_t *menu_path) {
  44. return _call(GETSUBMENU, 0, item, menu_path);
  45. }
  46. inline
  47. const wchar_t *svc_contextCmd::getSubMenuText(const wchar_t *menu_path) {
  48. return _call(GETSUBMENUTEXT, (const wchar_t *)NULL, menu_path);
  49. }
  50. inline const wchar_t *svc_contextCmd::getCommand(DragItem *item, int n) {
  51. return _call(GETCOMMAND, (const wchar_t *)0, item, n);
  52. }
  53. inline int svc_contextCmd::getEnabled(DragItem *item, int n) {
  54. return _call(GETENABLED, TRUE, item, n);
  55. }
  56. inline int svc_contextCmd::getChecked(DragItem *item, int n) {
  57. return _call(GETCHECKED, FALSE, item, n);
  58. }
  59. inline int svc_contextCmd::getSortVal(DragItem *item, int n) {
  60. return _call(GETSORTVAL, ContextCmdSortVal::MIDDLE, item, n);
  61. }
  62. inline void svc_contextCmd::onCommand(DragItem *item, int n) {
  63. _voidcall(ONCOMMAND, item, n);
  64. }
  65. class NOVTABLE svc_contextCmdI : public svc_contextCmd {
  66. public:
  67. virtual int testItem(DragItem *item, const wchar_t *menu_path)=0;
  68. virtual int getSubMenu(DragItem *item, const wchar_t *menu_path) { return 0; }
  69. virtual const wchar_t *getSubMenuText(const wchar_t *menu_path) { return NULL; }
  70. virtual const wchar_t *getCommand(DragItem *item, int n)=0;
  71. // override these as needed
  72. virtual int getEnabled(DragItem *item, int n) { return TRUE; }
  73. virtual int getChecked(DragItem *item, int n) { return FALSE; }
  74. virtual int getSortVal(DragItem *item, int n) { return ContextCmdSortVal::MIDDLE; }
  75. virtual void onCommand(DragItem *item, int n)=0;
  76. protected:
  77. RECVS_DISPATCH;
  78. };
  79. #include <api/service/servicei.h>
  80. template <class T>
  81. class ContextCmdCreator : public waServiceFactoryT<svc_contextCmd, T> { };
  82. #include <api/service/svc_enum.h>
  83. #include <bfc/string/stringW.h>
  84. class ContextCmdEnum : public SvcEnumT<svc_contextCmd> {
  85. public:
  86. ContextCmdEnum(DragItem *_item, const wchar_t *_menu_path)
  87. : item(_item), menu_path(_menu_path) {}
  88. protected:
  89. virtual int testService(svc_contextCmd *svc) {
  90. return svc->testItem(item, menu_path);
  91. }
  92. private:
  93. DragItem *item;
  94. StringW menu_path;
  95. };
  96. #endif