home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / !DeskLib / h / PopUp < prev    next >
Encoding:
Text File  |  1993-07-26  |  9.5 KB  |  316 lines

  1. /*
  2.  *  ####             #    #     # #
  3.  *  #   #            #    #       #          The FreeWare C library for
  4.  *  #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.  *  #   # #  # #     # #  #     # #  #   ___________________________________
  6.  *  #   # ####  ###  ##   #     # #  #
  7.  *  #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.  *  ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.  *  ________________________________________________________________________
  10.  *
  11.  *  File:    PopUp.h
  12.  *  Author:  Copyright © 1993 Jason Williams
  13.  *  Version: 1.00 (20 May 1993)
  14.  *  Purpose: Low and high-level veneers, typedefs for the PopUp system.
  15.  *
  16.  *  NOTE:
  17.  *  The PopUp system requires support of 2 Wimp message numbers. These
  18.  *  should be integrated into Wimp.h so that you can use:
  19.  *    event->data.message.popupxxx. ...
  20.  *
  21.  *  However, to do this requires permanent wiring of the folowing typedefs
  22.  *  into Wimp.h, which is undesirable if you aren't using PopUps in every
  23.  *  .c file, as it will have a bad effect on compile time/memory use.
  24.  *
  25.  *  Thus, I recommend that you simply #include this file as needed, and
  26.  *  cast the generic message data type from Wimp.h into the specific type
  27.  *  of the message as necessary, e.g.
  28.  *
  29.  *  case message_POPUPSTATE:
  30.  *  {
  31.  *    message_popupstate *state;
  32.  *    state = (message_popupstate *) &event->data.message.data;
  33.  *    switch (state->handle) ...
  34.  */
  35.  
  36.  
  37. #ifndef __dl_popup_h
  38. #define __dl_popup_h
  39.  
  40. #ifndef __dl_wimp_h
  41. #include "Wimp.h"
  42. #endif
  43.  
  44.  
  45. typedef int popup_handle;
  46.  
  47.  
  48. /*  The following are defined in Wimp.h
  49.  *    message_POPUPRQ      0x46D40
  50.  *    message_POPUPREQUEST 0x46D40
  51.  *    message_POPUPSTATE   0x46D41
  52.  *    message_POPUPCLOSED  0x46D42
  53.  */
  54.  
  55. /*
  56.  *  PopUp flag byte: Values of flag bits
  57.  *  Preferably, use the 'all inclusive' values below instead
  58.  */
  59. #define popup_ISLEAF   (0x01)
  60. #define popup_ISSTATIC (0x02)
  61.  
  62.  
  63. /*
  64.  *  All-inclusive PopUp flag byte values
  65.  */
  66. #define popup_STANDALONE (0x00)
  67. #define popup_MENULEAF   (0x01)
  68. #define popup_STATIC     (0x02)
  69.  
  70. /*
  71.  *  PopUp-specific data for SWI PopUp_Open and Message_PopUpState blocks...
  72.  *  See the PopUp documents for details.
  73.  */
  74. typedef struct
  75. {
  76.   int mul, div;
  77.   int minmul, maxmul;
  78.   int mindiv, maxdiv;
  79. } popup_magnify;
  80.  
  81. typedef struct
  82. {
  83.   char appname[32];
  84.   char purpose[32];
  85.   char author[32];
  86.   char version[32];
  87. } popup_proginfo;
  88.  
  89. typedef struct
  90. {
  91.   struct
  92.   {
  93.     unsigned int cancel     : 1;    /* Has cancel button / cancel was chosen */
  94.     unsigned int ok         : 1;    /* Has OK button     / OK was chosen     */
  95.     unsigned int reserved   : 6;
  96.     unsigned int userhandle : 24;   /* Put anything you find useful here     */
  97.   } flags;
  98.   char oktext[12];                  /* Text for OK button (if any)           */
  99.   char canceltext[12];              /* Text for cancel button (if any)       */
  100.   char appname[12];                 /* Application name for window titlebar  */
  101.   char message[188];                /* Text message to report to the user    */
  102. } popup_report;
  103.  
  104. typedef struct
  105. {
  106.   char iconsprite[12];              /* Save As file icon's Iconsprite name   */
  107.   char filename[212];               /* Default text to put into writable icn */
  108. } popup_saveas;                     /* NOTE a different block is RETURNED... */
  109.  
  110. typedef struct
  111. {
  112.   struct
  113.   {                                /* If TRUE:           | If FALSE:         */
  114.     unsigned int wasdragged : 1;   /* File was dragged   | OK was 'pressed'  */
  115.     unsigned int shiftdown  : 1;   /* SHIFT key was down | SHIFT key wasn't  */
  116.     unsigned int reserved   : 30;
  117.   } flags;
  118.  
  119.   int  reserved;
  120.   char filename[212];              /* if (wasdragged) this is a leafname,
  121.                                     * else            this is a full pathname
  122.                                     */
  123. } popup_saveasreturn;
  124.  
  125. typedef struct
  126. {
  127.   char colour;                     /* Colour 0..15 */
  128. } popup_wimpcolour;
  129.  
  130.  
  131. typedef struct
  132. {
  133.   unsigned int transparency : 8;
  134.   unsigned int red          : 8;
  135.   unsigned int green        : 8;
  136.   unsigned int blue         : 8;
  137. } colour_rgb;
  138.  
  139. typedef struct
  140. {
  141.   unsigned int value        : 8;    /* 0..255 */
  142.   unsigned int saturation   : 8;    /* 0..255 */
  143.   unsigned int hue          : 16;   /* 0..359 */
  144. } colour_hsv;
  145.  
  146. typedef struct
  147. {
  148.   unsigned int key          : 8;
  149.   unsigned int yellow       : 8;
  150.   unsigned int magenta      : 8;
  151.   unsigned int cyan         : 8;
  152. } colour_cmyk;
  153.  
  154. /*
  155.  *  Colour model numbers. See below for examples of use
  156.  */
  157. #define popuptc_RGB  0
  158. #define popuptc_HSV  1
  159. #define popuptc_CMYK 2
  160.  
  161. /*  Values to OR in to flag value for no transparency, 1 transparency value
  162.  *  ('none' option) and full transparency (256 transparency levels)
  163.  */
  164. #define popuptc_TRANSPARENT0   0x00000
  165. #define popuptc_TRANSPARENT1   0x10000
  166. #define popuptc_TRANSPARENT256 0x20000
  167.  
  168. /*  Examples:
  169.  *  'Draw' style colour:   colourmodel  = popuptc_RGB | popuptc_TRANSPARENT1;
  170.  *  Full transparency HSV: colour model = popuptc_HSV | popuptc_TRANSPARENT256;
  171.  */
  172.  
  173. typedef struct
  174. {
  175.   int colourmodel;                /* eg: popuptc_RGB + popuptc_TRANSPARENCY1 */
  176.   union
  177.   {
  178.     colour_rgb  rgb;
  179.     colour_hsv  hsv;
  180.     colour_cmyk cmyk;
  181.   } colour;
  182.   
  183.   int transparency;                 /* 0..255 */
  184. } popup_truecolour;
  185.  
  186.  
  187. typedef struct
  188. {
  189.   char       name[12];              /* PopUp type name, eg "SaveAs"          */
  190.   wimp_point openpos;               /* Position (top left) to open window at */
  191.   char       flags;                 /* menuleaf/standalone/static popup?     */
  192.   char       reserved1, reserved2, reserved3;
  193. } popup_header;
  194.  
  195.  
  196. typedef union
  197. {
  198.   popup_magnify    magnify;
  199.   popup_proginfo   proginfo;
  200.   popup_report     report;
  201.   popup_saveas     saveas;
  202.   popup_wimpcolour wimpcolour;
  203.   popup_truecolour truecolour;
  204. } popup_data;                               /* Data to send to popup manager */
  205.  
  206.  
  207. typedef struct
  208. {
  209.   popup_magnify    magnify;
  210.   popup_report     report;
  211.   popup_saveas     saveasreturn;
  212.   popup_wimpcolour wimpcolour;
  213.   popup_truecolour truecolour;
  214. } popup_returndata;                     /* Data recieved in a PopUpState msg */
  215.  
  216.  
  217. typedef struct
  218. {
  219.   window_handle window;                /* Pass this data directly to         */
  220.   wimp_point    openpos;               /* Wimp_CreateSubMenu. Do not pass GO */
  221. } message_popuprequest;
  222.  
  223.  
  224. typedef struct
  225. {
  226.   popup_handle     handle;                /* PopUp handle                    */
  227.   char             name[12];              /* PopUp type nam, e.g. "ProgInfo" */
  228.   popup_returndata data;                  /* Returned state data             */
  229. } message_popupstate;
  230.  
  231.  
  232. typedef struct
  233. {
  234.   popup_header header;
  235.   popup_data   data;
  236. } popup_block;                                /* Block to send to PopUp_Open */
  237.  
  238.  
  239.  
  240. /* --------------------------------------------------------------------------
  241.  *  Functions
  242.  * --------------------------------------------------------------------------
  243.  */
  244.  
  245.   /*  PopUp_Open
  246.    *  Straight SWI veneer for PopUp_Open swi.
  247.    *  (You shouldn't have to call this function - use PopUpShowXXXX, below)
  248.    */
  249. extern popup_handle PopUp_Open(popup_block *params);
  250.  
  251.  
  252.   /*  PopUp_Close
  253.    *  Straight SWI veneer for PopUp_Close swi.
  254.    *  This will close any PopUp, given the handle as returned by other
  255.    *  PopUp calls (PopUp_Open, PopUp_Show)
  256.    *  Note that this is only necessary for STATIC PopUps, and that illegal
  257.    *  calls (popup isn't open, etc) will be ignored.
  258.    */
  259. extern void PopUp_Close(popup_handle handle);
  260.  
  261.  
  262.  /*  PopUp_ShowMenuLeaf
  263.   *  Higher level interface to PopUp_Open, which will show a MENU-LEAF PopUp
  264.   *  given the PopUp type name and popup-specific data, plus the "menuwarn"
  265.   *  message that induced your desire to open the PopUp in the first place.
  266.   *
  267.   *  'name'       is the PopUp type name (e.g. "FontSelect")
  268.   *  'definition' is the popup-specific description.
  269.   *
  270.   *  Hypothetical example of use:
  271.   *  case message_MENUWARN:
  272.   *    switch(event->data.message.data.menuwarn.selection[0])
  273.   *    {
  274.   *      case 3: |* Save => menu item *|
  275.   *      {
  276.   *        popup_data pud;
  277.   *
  278.   *        strcpy(pud.saveas.iconsprite, "file_aff");   |* iconsprite name   *|
  279.   *        strcpy(pud.saveas.filename, "DrawFile");     |* Default file name *|
  280.   *        PopUp_ShowMenuLeaf("SaveAs", &pud,
  281.   *                            &event->data.message.datamenuwarn);
  282.   */
  283. extern popup_handle PopUp_ShowMenuLeaf(char *name, popup_data *definition,
  284.                                        message_menuwarn *msg);
  285.  
  286.  
  287.  /*  PopUp_ShowPtr
  288.   *  Higher level interface to PopUp_Open, which will open a STANDALONE MENU
  289.   *  or STATIC PopUp by filling in the position to open at (over the pointer)
  290.   *  and other header data for you, and open the PopUp as defined by the
  291.   *  passed in "popup_data" block.
  292.   *
  293.   *  'name'       is the PopUp type name (e.g. "FontSelect")
  294.   *  'isstatic'   indicates if the PopUp should be a static or menu PopUp.
  295.   *  'definition' is the popup-specific description.
  296.   *
  297.   *  Rather than calling ShowPtr directly, use the macros that follow...
  298.   */
  299. extern popup_handle PopUp_ShowPtr(char *name, BOOL isstatic,
  300.                                   popup_data *definition);
  301.  
  302.  
  303. /*  Show macros
  304.  *  These macros simply make PopUp_ShowPtr nicer to use without causing more
  305.  *  code bulk. They are used to show a standalone-menu or a static (permanent
  306.  *  window) PopUp respectively. Prototypes:
  307.  *
  308.  *  popup_handle PopUp_ShowStandalone(char *name, popup_data *definition);
  309.  *  popup_handle PopUp_ShowStatic(char *name, popup_data *definition);
  310.  */
  311.  
  312. #define PopUp_ShowStandalone(N, D) PopUp_ShowPtr(N, 0, D)
  313. #define PopUp_ShowStatic(N, D) PopUp_ShowPtr(N, 1, D)
  314.  
  315. #endif
  316.