home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / PopUps / Docs / ExampleSrc / h / Server < prev    next >
Encoding:
Text File  |  1993-05-24  |  8.7 KB  |  272 lines

  1. /*  File:     Server.h
  2.  *  Purpose:  Definitions for the PopUp Server and satellite PopUp handlers
  3.  *  Author:   © Copyright 1993 Jason Williams
  4.  *            All rights reserved
  5.  */
  6.  
  7. /*  NOTES
  8.  *  See the end of this file for information on global functions which you
  9.  *  are allowed to call from within PopUp handlers.
  10.  */
  11.  
  12. #ifndef __pu_server_h
  13. #define __pu_server_h
  14.  
  15. #ifndef __dl_wimp_h
  16. #include "DeskLib:Wimp.h"
  17. #endif
  18.  
  19.  
  20. /*  Maximum number of handlers, Maximum number of open PopUp windows at any
  21.  *  time. NOTE that to increase these numbers you may also need to change
  22.  *  the PopUpManager module
  23.  */
  24.  
  25. #define MAX_HANDLERS       20
  26. #define MAX_INSTANTIATIONS 32
  27.  
  28.  
  29. typedef enum
  30. {
  31.   REASON_OPEN     = 0,
  32.   REASON_CLOSE,
  33.   REASON_EVENT,
  34.  
  35.   REASON_FONTON,
  36.   REASON_FONTOFF
  37. } popup_reasoncodes;
  38.  
  39.  
  40. typedef struct
  41. {
  42.   event_pollmask pollmask;
  43.   window_handle  basewindow;
  44.   task_handle    clienttask;
  45.   int            openx, openy;
  46.   char           appflags;
  47. } ctrl_block;
  48.  
  49.  
  50. typedef struct
  51. {
  52.   int        handle;                  /* PopUp handle for this instantiation */
  53.   int        appflags;                /* Application flags                   */
  54.   int        handlerindex;            /* Index of owning handler in htable   */
  55.   void       *workspace;              /* Pointer to its instantiation wspace */
  56.   ctrl_block ctrlblock;               /* Control block                       */
  57. } instantdata;
  58.  
  59.  
  60. typedef int (*handler_proc)(int reasoncode,
  61.                             ctrl_block *ctrl,
  62.                             void *privateworkspace,
  63.                             event_pollblock *pollblock);
  64.  
  65. typedef struct
  66. {
  67.   char         name[12];
  68.   int          flags;
  69.   handler_proc proc;
  70.   int          workspacesize;
  71. } handler_info;
  72.  
  73.  
  74.  
  75. typedef struct
  76. {
  77.   int  popuphandle;
  78.   char popupname[12];
  79.   int  openx, openy;
  80.   char appflags, res1, res2, res3;
  81.  
  82.   char popupdata[208];                   /* Individual PopUp data goes here */
  83. } msg_popupopen;
  84.  
  85.  
  86. typedef struct
  87. {
  88.   int  popuphandle;
  89. } msg_popupclose;
  90.  
  91. typedef enum
  92. {
  93. /*  message_POPUPRQ    = 0x46D40,    - defined in DeskLib:Wimp.h */
  94. /*  message_POPUPSTATE,                                          */
  95. /*  message_POPUPCLOSED,                                         */
  96.   message_POPUPOPEN    = 0x46D43,
  97.   message_POPUPCLOSE
  98. } popup_messages;
  99.  
  100.  
  101. typedef enum
  102. {
  103.   SWI_PopUp_Open         = 0x46D40,
  104.   SWI_PopUp_Close,
  105.   SWI_PopUp_Register,
  106.   SWI_PopUp_Deregister,
  107.   SWI_PopUp_Kill
  108. } popup_swinumbers;
  109.  
  110.  
  111. #define APPFLAGS_ISLEAF   (0x01)
  112. #define APPFLAGS_ISSTATIC (0x02)
  113.  
  114.  
  115. /*
  116.  *  Global server variables
  117.  */
  118.  
  119. extern handler_info    *handlertable[];
  120. extern char            eventdata[];
  121. extern event_pollblock *event;
  122. extern task_handle     servertask;
  123.  
  124.  
  125. /*
  126.  *  Prototypes for functions defined in c.Server:
  127.  *  User PopUp handlers SHOULD NOT call any of these functions
  128.  */
  129.  
  130. extern void InstallPopUps(void);
  131. extern void DeinstallPopUps(void);
  132. extern int  NewInstantiation(int popuphandle, int handlerindex, int appflags);
  133. extern void LoseInstantiation(int popuphandle);
  134. extern int  CallHandler(int popuphandle, int reasoncode, BOOL handleishandle);
  135. extern BOOL PopUp_Open(task_handle client, msg_popupopen *m);
  136. extern void PopUp_Close(int popuphandle, BOOL killmenu);
  137. extern BOOL HandleWimpEvent(void);
  138. extern int  CalculateMask(int basemask);
  139. extern void TaskDying(int taskhandle);
  140. extern void Template_RMAInit(void);
  141. extern void Template_RMAFree(void);
  142.  
  143.  
  144.  
  145.  
  146.   /*  ------------------------------------------------------------------------
  147.    *  Prototypes for USER functions defined in c.Server:
  148.    *  User PopUp handlers may call any of the following functions if they wish
  149.    */
  150.  
  151.   /*  SendState
  152.    *  Packages the given PopUp-specific data section of the application params
  153.    *  into a message_PopUpState, and sends it back to the client task.
  154.    */
  155. extern void SendState(void *statedata, int statesize);
  156.  
  157.  
  158.   /*  ImDragging
  159.    *  If you wish to start a drag operation in your handler, you MUST call
  160.    *  this function as you do so - this tells the server that you are the
  161.    *  handler to call back when the drag finishes - if you do not call this
  162.    *  then the server will not call you (and will fail to process the drag
  163.    *  finish event)
  164.    */
  165. extern void ImDragging(void);
  166.  
  167.  
  168.   /*  SetIconText
  169.    *  Equivalent to DeskLib's Icon_SetText, with one VERY IMPORTANT difference
  170.    *  - it handles strings terminated with CR (13) instead of NUL (0), which
  171.    *  may be passed in from BASIC and assembler client tasks.
  172.    *  You therefore MUST use this version instead of Icon_SetText!!!
  173.    */
  174. extern void SetIconText(window_handle w, icon_handle i, char *text);
  175. #define Icon_SetText SetIconText
  176.  
  177.  
  178.   /*  ShowStaticPopUp
  179.    *  If you are providing a static PopUp, you will need to open it at
  180.    *  the x and y position requested by the user. To make this easier,
  181.    *  and help to share such code, this function is provided, which simply
  182.    *  opens the given window at the given top-left position.
  183.    *
  184.    *  This function also repels your window about 64 OS units from the
  185.    *  edges of the screen (as is automatically done for standalone MENU
  186.    *  popups) - Please use this to retain consistency.
  187.    */
  188. extern void ShowStaticPopUp(window_handle window, int openx, int openy);
  189.  
  190.  
  191.   /*  KillMe
  192.    *  Will kill off the current PopUp 
  193.    *  If a PopUp wishes to let everyone know that it has closed, then
  194.    *  it MUST call KillMe(). This should only be necessary on event_CLOSE
  195.    *  Wimp events, or if a 'cancel' button is clicked, etc.
  196.    *  (You do not need to call this function if you are told to close with
  197.    *  a REASON_CLOSE)
  198.    *
  199.    *  If you do not call this function, then you will continue to recieve
  200.    *  WIMP events, and will tie up one static-instantiation slot. (bad)
  201.    *
  202.    *  VERY IMPORTANT NOTE:
  203.    *  This call removes your PopUp instantiation information, which means
  204.    *  after the call you cannot rely on the passed-in ctrl block and
  205.    *  private workspace any more. (The former may have been changed and the
  206.    *  latter WILL have been deallocated). This should therefore be the very
  207.    *  last thing in your code before you return control for the last time.
  208.    */
  209. extern void KillMe(void);
  210.  
  211.  
  212.   /*  Template_RMAFind
  213.    *  The same as Template_Find
  214.    *  However it actually clones into malloc() and RMA static memory chunks
  215.    *  so that the indirected data is always paged in.
  216.    *  THIS SHOULD ONLY be called if your PopUp is to be shown as a menu LEAF
  217.    *  (because otherwise you will most likely be overwriting/overwritten by
  218.    *  another PopUp in these static memory areas)
  219.    *  i.e. only use it:
  220.    *    if ((ctrl->appflags & APPFLAGS_ISLEAF) != 0)
  221.    *  If this is not the case, or if it is a Static PopUp, then use the normal
  222.    *  Template_Find or Template_Clone.
  223.    *
  224.    *  NOTE: Only 1024 bytes of RMA space are available for your indirected
  225.    *  data (this does not include the window definition block). If you need
  226.    *  more memory than this for your indirected strings (shame on you!) then
  227.    *  you will need to change the constant at the top of Template.c
  228.    */
  229. extern window_block *Template_RMAFind(char *name);
  230.  
  231.  
  232.   /*  ReportMessage
  233.    *  Uses the 'Report' PopUp to report a message.
  234.    *  'flags' should be one of the #defined values below, and affects
  235.    *  what buttons will appear on the report window.
  236.    *  'ok' and 'cancel' are the strings (< 12 chars) to place into the buttons
  237.    *  'msg' is the message to report.
  238.    *  This is used by SaveAs to report the 'Drag to a directory' error.
  239.    *
  240.    *  NOTE that this is a MENU PopUp, and will therefore kill any existing
  241.    *  Menu PopUp! If calling from a static PopUp, take care.
  242.    */
  243. extern BOOL ReportMessage(int flags, char *ok, char *cancel, char *msg);
  244.  
  245. #define reportflag_CANCELONLY  1
  246. #define reportflag_OKONLY      2
  247. #define reportflag_OKANDCANCEL 3
  248.  
  249.  
  250.   /*  For REASON_OPEN, the pollblock contains a PopUpOpen message.
  251.    *  The definition of this includes the message header, the PopUp handle,
  252.    *  then the application parameter block header, followed (at offset 48 into
  253.    *  the complete WIMP message) by the PopUp-specific data.
  254.    *  Note that the pollblock includes a word at the front (event type), so
  255.    *  this shifts our data to offset 52 within the passed pollblock,
  256.    *  i.e. ((int) pollblock)+52 is the base address of the PopUp specific data
  257.    */
  258. #define POPUP_DATA_OFFSET 52
  259.  
  260.   /*  wimpversion
  261.    *  If you ever need to know which WIMP version you are running under,
  262.    *  check this variable - Numbers < 300 indicate RISC OS 2.
  263.    *  NOTE this will not be necessary very often, as two template files
  264.    *  are used, so you can define most OS-dependant stuff differently for
  265.    *  the 2 versions of the windows.
  266.    *  SaveAs uses this value to correct for RISC OS 2 not returning the 'drag'
  267.    *  button event properly.
  268.    */
  269. extern unsigned int wimpversion;
  270.  
  271. #endif
  272.