home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / desklib / !DeskSrc / FN / Libraries / DeskMem / Dialog / c / CreatDstry next >
Encoding:
Text File  |  1996-05-13  |  3.3 KB  |  103 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, Jason Williams, Julian Smith.
  13.     Version: 1.02 (14 Nov 1995)
  14.     Purpose: Very high level window (dialogue) handling -
  15.              Creating and destroying dialogues
  16.     History: 1.01 (02 Mar 1993) TB and JW
  17.              1.02 (14 Nov 1995) JS Made SDLS compatible
  18. */
  19.  
  20. #include <stdlib.h>
  21.  
  22. #include "Desk.Wimp.h"
  23. #include "Desk.WimpSWIs.h"
  24. #include "Desk.DeskMem.h"
  25.  
  26. #include "Desk.Dialog.h"
  27. #include "Desk.Event.h"
  28. #include "Desk.Window.h"
  29.  
  30. Desk_SDLS_PtrFn(
  31.     static,
  32.     Desk_bool,
  33.     Desk_Dialog__EventHandler(Desk_event_pollblock *event, void *reference)
  34.     )
  35. /*static Desk_bool EventHandler(Desk_event_pollblock *event, void *reference)*/
  36. {
  37.   Desk_dialog_record *dbox = (Desk_dialog_record *) reference;
  38.  
  39.   switch (event->type)
  40.   {
  41.      case Desk_event_CLOSE:
  42.       /*  User has clicked on close icon - We just close the window, as
  43.        *  Desk_Dialog_WaitForClick will notice this and take appropriate action
  44.        */
  45.       Desk_Window_Hide(dbox->window);
  46.       return(Desk_bool_TRUE);
  47.  
  48.     case Desk_event_CLICK:
  49.       /* Ignore work-area click events */
  50.       if (event->data.mouse.icon >= 0)
  51.       {
  52.           dbox->lastclicked   = event->data.mouse.icon;
  53.           dbox->button.value  = event->data.mouse.button.value;
  54.           dbox->state.persist = event->data.mouse.button.data.adjust;
  55.           return(Desk_bool_TRUE);
  56.       }
  57.       break;
  58.   }
  59.  
  60.   return(Desk_bool_FALSE);          /* Allow other event handlers to handle this event */
  61. }
  62.  
  63.  
  64. extern dialog Desk_Dialog_Create(char *Desk_template_name, int maxtitlesize)
  65. /*  Returns a pointer to a dialog record, or NULL if it fails */
  66. {
  67.   Desk_window_handle window;
  68.   dialog d;
  69.  
  70.   window = Desk_Window_Create(Desk_template_name, maxtitlesize);
  71.   if (window == NULL) return(NULL);
  72.  
  73.   d = (dialog) Desk_DeskMem_Malloc(sizeof(Desk_dialog_record));
  74.  
  75.   d->window         = window;
  76.   d->lastclicked    = Desk_dialog_NOCHOICE;
  77.   d->state.persist  = Desk_bool_TRUE;
  78.   d->state.isstatic = d->state.stillopen = Desk_bool_FALSE;
  79.  
  80.   /* Attach the event handler */
  81.   Desk_Event_Claim(Desk_event_NULL, Desk_event_ANY, Desk_event_ANY, Desk_SDLS_dllEntry( Desk_Dialog__EventHandler), d);
  82.   Desk_Event_Claim(Desk_event_ANY, window, Desk_event_ANY, Desk_SDLS_dllEntry( Desk_Dialog__EventHandler), d);
  83.  
  84.   return(d);
  85. }
  86.  
  87.  
  88. extern void Desk_Dialog_Destroy(dialog dbox)
  89. {
  90.   if (dbox != NULL)
  91.   {
  92.     Desk_Event_Poll();     /* for RO3 bug */
  93.  
  94.     /* Remove event handler */
  95.     Desk_Event_Release(Desk_event_NULL, Desk_event_ANY, Desk_event_ANY, Desk_SDLS_dllEntry( Desk_Dialog__EventHandler), dbox);
  96.     Desk_Event_Release(Desk_event_ANY, dbox->window, Desk_event_ANY, Desk_SDLS_dllEntry( Desk_Dialog__EventHandler), dbox);
  97.  
  98.     Desk_Dialog_Hide(dbox);
  99.     Desk_Window_Delete(dbox->window);
  100.     Desk_DeskMem_Free(dbox);
  101.   }
  102. }
  103.