home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Dialog / c / CreatDstry next >
Encoding:
Text File  |  1993-07-09  |  2.4 KB  |  89 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:    Dialog.CreatDstry.c
  12.     Author:  Copyright © 1993 Tim Browse and Jason Williams
  13.     Version: 1.00 (10 Jul 1993)
  14.     Purpose: Very high level window (dialogue) handling -
  15.              Creating and destroying dialogues
  16. */
  17.  
  18. #include <stdlib.h>
  19.  
  20. #include "DeskLib:Wimp.h"
  21. #include "DeskLib:WimpSWIs.h"
  22.  
  23. #include "DeskLib:Dialog.h"
  24. #include "DeskLib:Event.h"
  25. #include "DeskLib:Window.h"
  26.  
  27.  
  28. static BOOL EventHandler(event_pollblock *event, void *reference)
  29. {
  30.   dialog_record *dbox = (dialog_record *) reference;
  31.  
  32.   switch (event->type)
  33.   {
  34.     case event_CLOSE:
  35.       /*  User has clicked on close icon - We just close the window, as
  36.        *  Dialog_WaitForClick will notice this and take appropriate action
  37.        */
  38.       Window_Hide(dbox->window);
  39.       return(TRUE);
  40.  
  41.     case event_CLICK:
  42.       dbox->lastclicked   = event->data.mouse.icon;
  43.       dbox->state.persist = event->data.mouse.button.data.adjust;
  44.       return(TRUE);
  45.   }
  46.  
  47.   return(FALSE);          /* Allow other event handlers to handle this event */
  48. }
  49.  
  50.  
  51. extern dialog Dialog_Create(char *template_name, int maxtitlesize)
  52. /*  Returns a pointer to a dialog record, or NULL if it fails */
  53. {
  54.   window_handle window;
  55.   dialog d;
  56.  
  57.   window = Window_Create(template_name, maxtitlesize);
  58.   if (window == NULL) return(NULL);
  59.  
  60.   d = (dialog) malloc(sizeof(dialog_record));
  61.   if (d == NULL) return(NULL);
  62.  
  63.   d->window         = window;
  64.   d->lastclicked    = dialog_NOCHOICE;
  65.   d->state.persist  = TRUE;
  66.   d->state.isstatic = d->state.stillopen = FALSE;
  67.  
  68.   /* Attach the event handler */
  69.   Event_Claim(event_ANY, window, event_ANY, EventHandler, d);
  70.  
  71.   return(d);
  72. }
  73.  
  74.  
  75. extern void Dialog_Destroy(dialog dbox)
  76. {
  77.   if (dbox != NULL)
  78.   {
  79.     /* Remove event handler */
  80.     Event_Release(event_ANY, dbox->window, event_ANY, EventHandler, dbox);
  81.  
  82.     if (!dbox->state.isstatic)
  83.       Wimp_CreateMenu((menu_block *) -1, 0, 0);
  84.  
  85.     Window_Delete(dbox->window);
  86.     free(dbox);
  87.   }
  88. }
  89.