aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/service/svcs/svc_contextCmd.h
blob: 06a0aff5099076a2c406f01fad37531e2b394071 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef _SVC_CONTEXTCMD_H
#define _SVC_CONTEXTCMD_H

#include <bfc/dispatch.h>
#include <api/service/services.h>

namespace ContextCmdSortVal {
  enum ContextCmdSortVal {
    BEGINNING = 0,
    MIDDLE = 32767,
    END = 65535,
  };
};

class DragItem;

class NOVTABLE svc_contextCmd : public Dispatchable {
protected:
  svc_contextCmd() {}
  ~svc_contextCmd() {}
public:
  static FOURCC getServiceType() { return WaSvc::CONTEXTCMD; }

  int testItem(DragItem *item, const wchar_t *menu_path);

  int getSubMenu(DragItem *item, const wchar_t *menu_path);
  const wchar_t *getSubMenuText(const wchar_t *menu_path);

  const wchar_t *getCommand(DragItem *item, int n);

  int getEnabled(DragItem *item, int n);
  int getChecked(DragItem *item, int n);
  int getSortVal(DragItem *item, int n);

  void onCommand(DragItem *item, int n);

protected:
  enum {
    TESTITEM,
    GETSUBMENU,
    GETSUBMENUTEXT,
    GETCOMMAND,
    GETENABLED,
    GETCHECKED,
    GETSORTVAL,
    ONCOMMAND,
  };
};

inline int svc_contextCmd::testItem(DragItem *item, const wchar_t *menu_path) {
  return _call(TESTITEM, 0, item, menu_path);
}

inline
int svc_contextCmd::getSubMenu(DragItem *item, const wchar_t *menu_path) {
  return _call(GETSUBMENU, 0, item, menu_path);
}

inline
const wchar_t *svc_contextCmd::getSubMenuText(const wchar_t *menu_path) {
  return _call(GETSUBMENUTEXT, (const wchar_t *)NULL, menu_path);
}

inline const wchar_t *svc_contextCmd::getCommand(DragItem *item, int n) {
  return _call(GETCOMMAND, (const wchar_t *)0, item, n);
}

inline int svc_contextCmd::getEnabled(DragItem *item, int n) {
  return _call(GETENABLED, TRUE, item, n);
}

inline int svc_contextCmd::getChecked(DragItem *item, int n) {
  return _call(GETCHECKED, FALSE, item, n);
}

inline int svc_contextCmd::getSortVal(DragItem *item, int n) {
  return _call(GETSORTVAL, ContextCmdSortVal::MIDDLE, item, n);
}

inline void svc_contextCmd::onCommand(DragItem *item, int n) {
  _voidcall(ONCOMMAND, item, n);
}

class NOVTABLE svc_contextCmdI : public svc_contextCmd {
public:
  virtual int testItem(DragItem *item, const wchar_t *menu_path)=0;

  virtual int getSubMenu(DragItem *item, const wchar_t *menu_path) { return 0; }
  virtual const wchar_t *getSubMenuText(const wchar_t *menu_path) { return NULL; }

  virtual const wchar_t *getCommand(DragItem *item, int n)=0;

  // override these as needed
  virtual int getEnabled(DragItem *item, int n) { return TRUE; }
  virtual int getChecked(DragItem *item, int n) { return FALSE; }
  virtual int getSortVal(DragItem *item, int n) { return ContextCmdSortVal::MIDDLE; }

  virtual void onCommand(DragItem *item, int n)=0;

protected:
  RECVS_DISPATCH;
};

#include <api/service/servicei.h>

template <class T>
class ContextCmdCreator : public waServiceFactoryT<svc_contextCmd, T> { };

#include <api/service/svc_enum.h>
#include <bfc/string/stringW.h>

class ContextCmdEnum : public SvcEnumT<svc_contextCmd> {
public:
  ContextCmdEnum(DragItem *_item, const wchar_t *_menu_path)
    : item(_item), menu_path(_menu_path) {}

protected:
  virtual int testService(svc_contextCmd *svc) {
    return svc->testItem(item, menu_path);
  }

private:
  DragItem *item;
  StringW menu_path;
};

#endif