1
0

dispatch_ifc.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * dispatch_ifc.m
  3. *
  4. * defines a function interface for dispatchable messaging
  5. * define DISPATCH before loading if you are a message reciever
  6. *
  7. * @author mpdeimos
  8. * @date 2008/10/25
  9. * @version 0.1
  10. */
  11. #ifndef included
  12. #error This script can only be compiled as a #include
  13. #endif
  14. Function initDispatcher(); // Call this function on startup to set the parent layout as dispatcher
  15. Function setDispatcher(GuiObject dispatcher); // Call this function instead if you want to define a custom
  16. #ifndef DISPATCH
  17. // Sends a message to the parent layout
  18. Function int sendMessage(int message, int i0, int i1, int i2, String s0, String s1, GuiObject obj);
  19. Function int sendMessageI(int message, int i0);
  20. Function int sendMessageI2(int message, int i0, int i1);
  21. Function int sendMessageS(int message, String s0);
  22. Function int sendMessageO(int message, GuiObject obj);
  23. Function int sendMessageV(int message);
  24. #endif
  25. #ifdef DISPATCH
  26. // Recieves Messages
  27. Function int onMessage(int message, int i0, int i1, int i2, String s0, String s1, GuiObject obj);
  28. int onMessage(int message, int i0, int i1, int i2, String s0, String s1, GuiObject obj) {} // STUB! Implement this in your code
  29. #endif
  30. ///
  31. /// IMPLEMENTATION
  32. ///
  33. Global GuiObject dispatcher;
  34. initDispatcher()
  35. {
  36. dispatcher = getScriptGroup().getParentLayout();
  37. }
  38. setDispatcher(GuiObject go)
  39. {
  40. dispatcher = go;
  41. }
  42. #ifndef DISPATCH
  43. int sendMessage(int message, int i0, int i1, int i2, String s0, String s1, GuiObject obj)
  44. {
  45. return dispatcher.onAction (s0, s1, message, i0, i1, i2, obj);
  46. }
  47. int sendMessageI(int message, int i0)
  48. {
  49. GuiObject obj = NULL;
  50. return sendMessage(message, i0, i1, 0, "", "", obj);
  51. }
  52. int sendMessageI2(int message, int i0, int i1)
  53. {
  54. GuiObject obj = NULL;
  55. return sendMessage(message, i0, 0, 0, "", "", obj);
  56. }
  57. int sendMessageS(int message, String s0)
  58. {
  59. GuiObject obj = NULL;
  60. return sendMessage(message, 0, 0, 0, s0, "", obj);
  61. }
  62. int sendMessageO(int message, GuiObject obj)
  63. {
  64. return sendMessage(message, 0, 0, 0, "", "", obj);
  65. }
  66. int sendMessageV(int messagej)
  67. {
  68. GuiObject obj = NULL;
  69. return sendMessage(message, 0, 0, 0, "", "", obj);
  70. }
  71. #endif
  72. #ifdef DISPATCH
  73. dispatcher.onAction(String action, String param, Int message, int y, int p1, int p2, GuiObject source)
  74. {
  75. return onMessage(message, y, p1, p2, action, param, source);
  76. }
  77. #endif