home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 432b.lha / EzLib / src / window.c < prev   
C/C++ Source or Header  |  1990-11-10  |  3KB  |  120 lines

  1. #include "ezlib.h"
  2.  
  3. extern struct GfxBase *GfxBase;
  4. extern struct IntuitionBase *IntuitionBase;
  5. extern int openlibs();
  6. void *AllocMem();
  7.  
  8.  
  9. struct Window *createwindow(screen, flags, idcmp, leftedge, topedge, width, height)
  10.  struct Screen *screen;
  11.  ULONG flags, idcmp;
  12.  int leftedge, topedge, width, height;
  13. {
  14.  struct Window *OpenWindow();
  15.  int wb_height;
  16.  struct NewWindow *tempwin;
  17.  struct Window *win;
  18.  
  19.  /* some sanity checking - short and fast */
  20.  if(GfxBase == NULL || IntuitionBase == NULL)
  21.   if ( openlibs(GFX | INTUITION) == NULL)
  22.     return NULL;
  23.  
  24.  tempwin = (struct NewWindow *)AllocMem(sizeof(struct NewWindow), MEMF_CLEAR);
  25.  if (tempwin == NULL)
  26.    return NULL;
  27.  
  28.  if (width < 0)                            /* more checking */
  29.    width = GfxBase->NormalDisplayColumns;
  30.  if (height < 0)
  31.     height = 1500;
  32.  
  33.  tempwin->Flags    = flags;           tempwin->IDCMPFlags = idcmp;
  34.  tempwin->LeftEdge = (SHORT)leftedge;  tempwin->Width      = (SHORT)width;
  35.  tempwin->TopEdge  = (SHORT)topedge;   tempwin->Height     = (SHORT)height;
  36.  tempwin->MinWidth = 60;           tempwin->MinHeight  = 30;
  37.  tempwin->DetailPen= -1;           tempwin->BlockPen   = -1;
  38.  tempwin->Type       = WBENCHSCREEN;
  39.  tempwin->Screen = screen;    /* if it's null that's o.k. too */
  40.  
  41.  /* if user has a custom screen, open up on that screen */
  42.  if (screen) {
  43.    tempwin->Type = CUSTOMSCREEN;
  44.    if (leftedge + width > screen->Width)
  45.      tempwin->Width = (screen->Width - leftedge);
  46.  
  47.    if (topedge + height > screen->Height)
  48.      tempwin->Height = (screen->Height - topedge);
  49.   }
  50.  else {
  51.    if (leftedge+width > GfxBase->NormalDisplayColumns)
  52.      tempwin->Width = (GfxBase->NormalDisplayColumns - leftedge);
  53.  
  54.    /* gotta make sure to check for interlace */
  55.    wb_height = (GfxBase->NormalDisplayRows * (1 + laced_wb()) );
  56.    if (topedge + height > wb_height )
  57.      tempwin->Height = wb_height - topedge;
  58.   }
  59.  
  60.  win = OpenWindow(tempwin);
  61.  
  62.  FreeMem(tempwin, sizeof(struct NewWindow));
  63.  return win;
  64. }   /* end of makewindow() */
  65.  
  66.  
  67.  
  68. /* return TRUE (1) if wb screen is interlaced otherwise,
  69.  * we return FALSE (0) if it is NOT interlaced
  70.  */
  71. laced_wb()
  72. {
  73.  struct Preferences prefs;
  74.  
  75.  GetPrefs(&prefs, sizeof(struct Preferences));
  76.  if (prefs.LaceWB)
  77.    return 1;
  78.  else
  79.    return 0;
  80. }  /*  end of laced_wb()  */
  81.  
  82.  
  83. killwindow(window)
  84.  register struct Window *window;
  85. {
  86.  register struct IntuiMessage *msg, *GetMsg();
  87.  
  88.  if (window < 100)
  89.    return;
  90.  
  91.  /* make sure this is NULL if you have already cleared out your menus. */
  92.  if (window->MenuStrip != NULL)
  93.    ClearMenuStrip(window);
  94.  
  95.  /* make sure there aren't any junk messages hanging here */
  96.  while(window->UserPort != NULL && (msg = GetMsg(window->UserPort)) != NULL )
  97.    ReplyMsg(msg);
  98.  
  99.  /* then just close the window */
  100.  CloseWindow(window);
  101. }
  102.  
  103. /* this routine will make your standard Intuition Window.  It creates
  104.  * a window with all the standard system gadgets on it, and makes it
  105.  * the appropriate size (with sanity checking)
  106.  */
  107.  
  108. struct Window *makewindow(screen, leftedge, topedge, width, height)
  109.  struct Screen *screen;
  110.  int leftedge, topedge, width, height;
  111. {
  112.   static ULONG idcmp =    CLOSEWINDOW,        /* IDCMP  Classes    */
  113.                         /* system flags     */
  114.      flags =  WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|WINDOWSIZING|NOCAREREFRESH|SMART_REFRESH|ACTIVATE;
  115.  
  116.  return (struct Window *)createwindow(screen, flags, idcmp, leftedge, topedge, width, height);
  117. }
  118.  
  119.  
  120.