lwmonitor.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * LWSDK Header File
  3. * Copyright 1999, NewTek, Inc.
  4. *
  5. * LWMONITOR.H -- LightWave Progress Monitor
  6. *
  7. * Monitors are simple data structures defining an interface which the
  8. * server can use to give feedback to the host on its progress in
  9. * performing some task. They are sometimes passed servers to give
  10. * feedback on the progress of the particular operation, and can sometimes
  11. * be accessed from within a server that wants to show its progress on a
  12. * slow operation using the host's normal feedback display.
  13. */
  14. #ifndef LWSDK_MONITOR_H
  15. #define LWSDK_MONITOR_H
  16. /*
  17. * An LWMonitor struct consists of some generic data and three functions:
  18. * init, step and done. The 'init' function is called first with the
  19. * number of steps in the process to be monitored, which is computed by
  20. * the server. As the task is processed, the 'step' function is called
  21. * with the number of steps just completed (often one). These step
  22. * increments should eventually add up to the total number and then the
  23. * 'done' function is called, but 'done' may be called early if there was
  24. * a problem or the process was aborted. The 'step' function will return
  25. * one if the user requested an abort and zero otherwise.
  26. *
  27. * The server is masked from any errors in the monitor that may occur on
  28. * the host side of the interface. If there is a problem with putting up
  29. * a monitor, the functions will still return normally, since the monitor
  30. * is for user feedback and is not that critical.
  31. */
  32. typedef struct st_LWMonitor {
  33. void *data;
  34. void (*init) (void *, unsigned int);
  35. int (*step) (void *, unsigned int);
  36. void (*done) (void *);
  37. } LWMonitor;
  38. /*
  39. * Macros are provided to call a monitor which will do nothing if the
  40. * monitor pointer is null. MON_INCR is used for step sizes greater than
  41. * one and MON_STEP is used for step sizes exactly one.
  42. */
  43. #define MON_INIT(mon,count) if (mon) (*mon->init) (mon->data, count)
  44. #define MON_INCR(mon,d) (mon ? (*mon->step) (mon->data, d) : 0)
  45. #define MON_STEP(mon) MON_INCR (mon, 1)
  46. #define MON_DONE(mon) if (mon) (*mon->done) (mon->data)
  47. #define LWLMONFUNCS_GLOBAL "LWLMonFuncs"
  48. /****
  49. * create:
  50. * Creates a new monitor instance
  51. *
  52. * setup:
  53. * Configures the progress monitor
  54. * title - Monitor Title
  55. * uiflags - a bitmask of desired LMO_* flags
  56. * histfile - if given, filename where messages will also be written
  57. * uiflags - takes a bitmask of ui options
  58. *
  59. * setwinpos:
  60. * xywh - position and size of monitor window
  61. *
  62. * init:
  63. * Sets total number of steps and OOpens the monitor progress window
  64. * total - Total number of steps
  65. * msg - Initial message string for user
  66. *
  67. * step:
  68. * Increments the current step and sets the display message
  69. * incr - Increment to increase counter (0 is valid)
  70. * msg - Message string for user
  71. *
  72. * done:
  73. * Indicates the processing is complete. If review option enabled,
  74. * monitor remains open in a modal state for user review of output.
  75. * Control will not return to caller until the user dismisses the window.
  76. *
  77. * destroy:
  78. * Closes the window (if open) and destroys the instance.
  79. *
  80. ****
  81. */
  82. /* defines */
  83. /****
  84. * UI Option Flags
  85. * NOABORT:
  86. * Abort button is disabled. Default is operation can be aborted.
  87. * REVIEW:
  88. * Monitor remains open after 'done' method is called. This allows user
  89. * to review messages. Default is no review and mediately from done method
  90. * HISTAPPEND:
  91. * History file is appended with new messages. Default is overwrite.
  92. * IMMUPD:
  93. * Enables immediate update of the monitor on every step. The default
  94. * is to delay updates to avoid incurring too much overhead for rapid
  95. * step events.
  96. ****
  97. */
  98. #define LMO_NOABORT (1<<0)
  99. #define LMO_REVIEW (1<<1)
  100. #define LMO_HISTAPPEND (1<<2)
  101. #define LMO_IMMUPD (1<<3)
  102. /* TypeDefs */
  103. typedef struct st_LMONDATA *LWLMonID;
  104. typedef struct st_LWLMonFuncs {
  105. LWLMonID (*create) ( void );
  106. void (*setup) ( LWLMonID mon, char *title,
  107. unsigned int uiflags, const char *histfile );
  108. void (*setwinpos) ( LWLMonID mon, int x, int y, int w, int h );
  109. void (*init) ( LWLMonID mon, unsigned int total, const char *msg );
  110. int (*step) ( LWLMonID mon, unsigned int incr, const char *msg );
  111. void (*done) ( LWLMonID mon );
  112. void (*destroy) ( LWLMonID mon );
  113. } LWLMonFuncs;
  114. /****
  115. * Macros to simplify some common operations.
  116. ****
  117. */
  118. /* Creates a monitor instance */
  119. #define LMON_NEW(fun) ((*fun->create)())
  120. /* Initailizes a default monitor */
  121. #define LMON_DFLT(fun,mon,tot) {(*fun->setup)(mon,"Processing...",0,NULL);\
  122. (*fun->init)(mon,tot,NULL);}
  123. #define LMON_WPOS(fun,mon,x,y,w,h) ((*fun->setwinpos)(mon,x,y,w,h))
  124. #define LMON_INIT(fun,mon,tot) ((*fun->init)(mon,tot,NULL))
  125. /* The following are various incrementing macros */
  126. #define LMON_STEP(fun,mon) ((*fun->step)(mon,1,NULL))
  127. #define LMON_INCR(fun,mon,s) ((*fun->step)(mon,s,NULL))
  128. #define LMON_MSG(fun,mon,msg) ((*fun->step)(mon,0,msg))
  129. #define LMON_MSGS(fun,mon,msg) ((*fun->step)(mon,1,msg))
  130. #define LMON_MSGI(fun,mon,s,msg) ((*fun->step)(mon,s,msg))
  131. /* These finish and destroy the monitor */
  132. #define LMON_DONE(fun,mon) ((*fun->done)(mon))
  133. #define LMON_KILL(fun,mon) ((*fun->destroy)(mon))
  134. #endif