1
0

svc_objectdir.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #ifndef _SVC_OBJECTDIR_H
  2. #define _SVC_OBJECTDIR_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/string/StringW.h>
  5. #include <api/service/services.h>
  6. #include <api/syscb/callbacks/runlevelcb.h>
  7. // there is class ObjectDir in bfc/wnds, you should derive from it
  8. // also class ContextCmdObjDir
  9. typedef size_t ObjectHandle;
  10. #define INVALID_OBJECT_HANDLE ((ObjectHandle)0)
  11. #define DD_OBJECTDIR L"service:svc_objectDir"
  12. class ifc_window;
  13. class ifc_dependent;
  14. class BaseCanvas;
  15. class svc_objectDir : public Dispatchable
  16. {
  17. public:
  18. static int getServiceType() { return WaSvc::OBJECTDIR; }
  19. static const wchar_t *dragitem_getDatatype() { return DD_OBJECTDIR; }
  20. static const GUID *depend_getClassGuid() {
  21. // {2364D110-0F12-40d4-BBAE-D2DA174751B5}
  22. static const GUID ret =
  23. { 0x2364d110, 0xf12, 0x40d4, { 0xbb, 0xae, 0xd2, 0xda, 0x17, 0x47, 0x51, 0xb5 } };
  24. return &ret;
  25. }
  26. api_dependent *getDependencyPtr();
  27. const wchar_t *getDirType();
  28. int getNumObjects();
  29. ObjectHandle enumObject(int n);
  30. void *getObject(ObjectHandle handle);
  31. const wchar_t *getObjectLabel(ObjectHandle handle);
  32. int setObjectLabel(ObjectHandle handle, const wchar_t *newlabel);
  33. ObjectHandle insertObject(const wchar_t *parameter=NULL, const wchar_t *label=NULL, const wchar_t *path=NULL);
  34. int removeObject(ObjectHandle handle);
  35. void clearAll();
  36. const wchar_t *getObjectPath(ObjectHandle handle);
  37. const wchar_t *getObjectDisplayGroup(ObjectHandle handle);
  38. const wchar_t *getObjectIcon(ObjectHandle handle);
  39. int getObjectSelectable(ObjectHandle handle);
  40. int getObjectSortOrder(ObjectHandle handle); // -32767..32767
  41. // tagging
  42. int tagObject(const wchar_t *tag, ObjectHandle handle, int exclusive=FALSE);
  43. int untagObject(const wchar_t *tag, ObjectHandle handle);
  44. ObjectHandle enumObjectByTag(const wchar_t *tag, int n);
  45. int isTagged(const wchar_t *tag, ObjectHandle handle);
  46. int onAction(int action, ifc_window *from, const wchar_t *target, ObjectHandle handle);
  47. enum {
  48. ODACTION_SELECTED=100,
  49. ODACTION_DESELECTED=200,
  50. ODACTION_CONTEXTMENU=300,
  51. };
  52. int contextMenu(ifc_window *from, int x, int y, ObjectHandle handle);
  53. void onPrerender(ObjectHandle handle, const RECT *r, BaseCanvas *c, int style);
  54. void onPostrender(ObjectHandle handle, const RECT *r, BaseCanvas *c, int style);
  55. // render styles
  56. enum {
  57. RENDERSTYLE_TREEWND=10,
  58. };
  59. // dependency events, param is handle of object in question
  60. enum {
  61. Event_OBJECT_ADDED=100,
  62. Event_OBJECT_REMOVED=110,
  63. Event_OBJECT_LABELCHANGE=200,
  64. Event_OBJECT_ICONCHANGE=300,
  65. Event_OBJECT_PATHCHANGE=400,
  66. Event_OBJECT_SELECTABLECHANGE=500,
  67. Event_OBJECT_SORTORDERCHANGE=600,
  68. Event_OBJECT_TAGCHANGE=700,
  69. };
  70. // dispatchable codes
  71. enum {
  72. GETDEPENDENCYPTR=100,
  73. GETNUMOBJECTS=200,
  74. ENUMOBJECT=300,
  75. GETOBJECT=400,
  76. GETOBJECTLABEL=500,
  77. SETOBJECTLABEL=510,
  78. INSERTOBJECT=600,
  79. REMOVEOBJECT=610,
  80. CLEARALL=700,
  81. GETDIRTYPE=800,
  82. ONACTION=900,
  83. ONPRERENDER=1000,
  84. ONPOSTRENDER=1010,
  85. GETOBJECTPATH=1100,
  86. GETOBJECTDISPLAYGROUP=1200,
  87. GETOBJECTICON=1300,
  88. GETOBJECTSELECTABLE=1400,
  89. GETOBJECTSORTORDER=1500,
  90. TAGOBJECT=1600,
  91. UNTAGOBJECT=1700,
  92. ENUMOBJECTBYTAG=1800,
  93. ISTAGGED=1900,
  94. CONTEXTMENU=3000,
  95. };
  96. };
  97. inline
  98. api_dependent *svc_objectDir::getDependencyPtr() {
  99. return _call(GETDEPENDENCYPTR, (api_dependent*)NULL);
  100. }
  101. inline
  102. const wchar_t *svc_objectDir::getDirType() {
  103. return _call(GETDIRTYPE, (const wchar_t *)NULL);
  104. }
  105. inline
  106. int svc_objectDir::getNumObjects() {
  107. return _call(GETNUMOBJECTS, 0);
  108. }
  109. inline
  110. ObjectHandle svc_objectDir::enumObject(int n) {
  111. return _call(ENUMOBJECT, INVALID_OBJECT_HANDLE, n);
  112. }
  113. inline
  114. void *svc_objectDir::getObject(ObjectHandle handle) {
  115. return _call(GETOBJECT, (void*)NULL, handle);
  116. }
  117. inline
  118. const wchar_t *svc_objectDir::getObjectLabel(ObjectHandle handle) {
  119. return _call(GETOBJECTLABEL, (const wchar_t *)NULL, handle);
  120. }
  121. inline
  122. int svc_objectDir::setObjectLabel(ObjectHandle handle, const wchar_t *newlabel) {
  123. return _call(SETOBJECTLABEL, 0, handle, newlabel);
  124. }
  125. inline
  126. ObjectHandle svc_objectDir::insertObject(const wchar_t *parameter, const wchar_t *label, const wchar_t *path) {
  127. return _call(INSERTOBJECT, INVALID_OBJECT_HANDLE, parameter, label, path);
  128. }
  129. inline
  130. int svc_objectDir::removeObject(ObjectHandle handle) {
  131. return _call(REMOVEOBJECT, 0, handle);
  132. }
  133. inline
  134. void svc_objectDir::clearAll() {
  135. _voidcall(CLEARALL);
  136. }
  137. inline
  138. const wchar_t *svc_objectDir::getObjectPath(ObjectHandle handle) {
  139. return _call(GETOBJECTPATH, (const wchar_t *)NULL, handle);
  140. }
  141. inline
  142. const wchar_t *svc_objectDir::getObjectDisplayGroup(ObjectHandle handle) {
  143. return _call(GETOBJECTDISPLAYGROUP, L"", handle);
  144. }
  145. inline
  146. const wchar_t *svc_objectDir::getObjectIcon(ObjectHandle handle) {
  147. return _call(GETOBJECTICON, (const wchar_t *)NULL, handle);
  148. }
  149. inline
  150. int svc_objectDir::getObjectSelectable(ObjectHandle handle) {
  151. return _call(GETOBJECTSELECTABLE, TRUE, handle);
  152. }
  153. inline
  154. int svc_objectDir::getObjectSortOrder(ObjectHandle handle) {
  155. return _call(GETOBJECTSORTORDER, 0, handle);
  156. }
  157. inline
  158. int svc_objectDir::tagObject(const wchar_t *tag, ObjectHandle handle, int exclusive) {
  159. return _call(TAGOBJECT, 0, tag, handle, exclusive);
  160. }
  161. inline
  162. int svc_objectDir::untagObject(const wchar_t *tag, ObjectHandle handle) {
  163. return _call(UNTAGOBJECT, 0, tag, handle);
  164. }
  165. inline
  166. ObjectHandle svc_objectDir::enumObjectByTag(const wchar_t *tag, int n) {
  167. return _call(ENUMOBJECTBYTAG, INVALID_OBJECT_HANDLE, tag, n);
  168. }
  169. inline
  170. int svc_objectDir::isTagged(const wchar_t *tag, ObjectHandle handle) {
  171. return _call(ISTAGGED, 0, tag, handle);
  172. }
  173. inline
  174. int svc_objectDir::onAction(int action, ifc_window *from, const wchar_t *target, ObjectHandle handle) {
  175. return _call(ONACTION, 0, action, from, target, handle);
  176. }
  177. inline
  178. int svc_objectDir::contextMenu(ifc_window *from, int x, int y, ObjectHandle handle) {
  179. return _call(CONTEXTMENU, 0, from, x, y, handle);
  180. }
  181. inline
  182. void svc_objectDir::onPrerender(ObjectHandle handle, const RECT *r, BaseCanvas *c, int style) {
  183. _voidcall(ONPRERENDER, handle, r, c, style);
  184. }
  185. inline
  186. void svc_objectDir::onPostrender(ObjectHandle handle, const RECT *r, BaseCanvas *c, int style) {
  187. _voidcall(ONPOSTRENDER, handle, r, c, style);
  188. }
  189. /**
  190. Service implementation. Usually you'll derive from ObjectDir, not this.
  191. You can still derive from this if you want to fully implement the interface yourself for some reason though.
  192. @see ObjectDir
  193. */
  194. class svc_objectDirI : public svc_objectDir {
  195. public:
  196. virtual api_dependent *getDependencyPtr()=0;
  197. virtual const wchar_t *getDirType()=0;
  198. virtual int getNumObjects()=0;
  199. virtual ObjectHandle enumObject(int n)=0;
  200. virtual void *getObject(ObjectHandle handle)=0;
  201. virtual const wchar_t *getObjectLabel(ObjectHandle handle)=0;
  202. virtual int setObjectLabel(ObjectHandle handle, const wchar_t *newlabel)=0;
  203. virtual ObjectHandle insertObject(const wchar_t *parameter=NULL, const wchar_t *label=NULL, const wchar_t *path=NULL)=0;
  204. virtual int removeObject(ObjectHandle handle)=0;
  205. virtual void clearAll()=0;
  206. virtual const wchar_t *getObjectPath(ObjectHandle handle)=0;
  207. virtual const wchar_t *getObjectDisplayGroup(ObjectHandle handle)=0;
  208. virtual const wchar_t *getObjectIcon(ObjectHandle handle)=0;
  209. virtual int getObjectSelectable(ObjectHandle handle)=0;
  210. virtual int getObjectSortOrder(ObjectHandle handle)=0;
  211. virtual int tagObject(const wchar_t *tag, ObjectHandle handle, int exclusive=FALSE)=0;
  212. virtual int untagObject(const wchar_t *tag, ObjectHandle handle)=0;
  213. virtual ObjectHandle enumObjectByTag(const wchar_t *tag, int n)=0;
  214. virtual int isTagged(const wchar_t *tag, ObjectHandle handle)=0;
  215. virtual int onAction(int action, ifc_window *from, const wchar_t *target, ObjectHandle handle)=0;
  216. // return -1 to request renaming the item, 0 normally
  217. virtual int contextMenu(ifc_window *from, int x, int y, ObjectHandle handle)=0;
  218. virtual void onPrerender(ObjectHandle handle, const RECT *r, BaseCanvas *c, int style) { }
  219. virtual void onPostrender(ObjectHandle handle, const RECT *r, BaseCanvas *c, int style) { }
  220. protected:
  221. RECVS_DISPATCH;
  222. };
  223. #include <api/service/servicei.h>
  224. template <class T>
  225. class ObjectDirCreator : public waServiceFactoryTSingle<svc_objectDir, T> { };
  226. #include <api/service/svc_enum.h>
  227. class ObjectDirEnum : public SvcEnumT<svc_objectDir> {
  228. public:
  229. ObjectDirEnum(const wchar_t *_name) : name(_name) {}
  230. virtual int testService(svc_objectDir *svc) {
  231. return !WCSICMP(svc->getDirType(), name);
  232. }
  233. private:
  234. StringW name;
  235. };
  236. #endif