/* include not needed for Aztec C using provided makefile */
#include "sb:sb.h"
extern int level;
extern void PrWindow2(), PrWindow3();


void PrWindow(string, window) char *string; struct Window *window;
{
static struct StructData structdata[] = {
     { " NextWindow",   "struct Window *",     5, PTRSIZE },
     { "-LeftEdge",     "SHORT",               2, INTSIZE },
     { "-TopEdge",      "SHORT",               2, INTSIZE },
     { "-Width",        "SHORT",               2, INTSIZE },
     { "-Height",       "SHORT",               2, INTSIZE },
     { "-MouseY",       "SHORT",               2, INTSIZE },
     { "-MouseX",       "SHORT",               2, INTSIZE },
     { "-MinWidth",     "SHORT",               2, INTSIZE },
     { "-MinHeight",    "SHORT",               2, INTSIZE },
     { "-MaxWidth",     "SHORT",               2, INTSIZE },
     { "-MaxHeight",    "SHORT",               2, INTSIZE },
     { " Flags",        "ULONG",              11, PTRSIZE },
     { "(MenuStrip",    "struct Menu *)",      5, PTRSIZE },
     { " Title",        "UBYTE *",             4, PTRSIZE },
     { "(FirstRequest", "struct Requester *)", 5, PTRSIZE },
     { "(DMRequest",    "struct Requester *)", 5, PTRSIZE }
  };
static char *flagnames[32] = {
     "WINDOWSIZING",    "WINDOWDRAG",   "WINDOWDEPTH",    "WINDOWCLOSE",
     "SIZEBRIGHT",      "SIZEBOTTOM",   "SIMPLE_REFRESH", "OTHER_REFRESH",
     "BACKDROP",        "REPORTMOUSE",  "GIMMEZEROZERO",  "BORDERLESS",
     "ACTIVATE",        "WINDOWACTIVE", "INREQUEST",      "MENUSTATE",
     "RMBTRAP",         "NOCAREREFRESH", NULL,            NULL,
     NULL,              NULL,            NULL,            NULL,
     "WINDOWREFRESH",   "WBENCHWINDOW",  "WINDOWTICKED"
  };
int sum, choice = -1;
ULONG bits;
  level++;
  while (choice) {
    sum = SetOptionText(string, structdata, (APTR)window, DATASIZE, 0);
    switch (choice = GetChoice(MAXGADG + 1)) {
      case 1:
        if (window->NextWindow)
          PrWindow("The next window in Intuition's list", window->NextWindow);
        break;
      case 12:
        bits = window->Flags & ~SUPER_UNUSED;
        switch ((bits & REFRESHBITS) >> 6) {
          case 0:
            flagnames[6] = "SMART_REFRESH";
            bits |= 0x40;
            break;
          case 1:
            flagnames[6] = "SIMPLE_REFRESH";
            break;
          case 2:
            flagnames[7] = "SUPER_BITMAP";
            break;
          case 3:
            flagnames[7] = "OTHER_REFRESH";
            bits ^= 0x40;
            break;
        }
        FlagPrint("Flags set in this window", flagnames, bits);
        break;
      case 14:
        PrString("The Window's Title", window->Title);
        break;
      case MOREGADG:
        PrWindow2("Window menbers (page 2)", window, sum);
        break;
    }
  }
  level--;
}


void PrWindow2(string, window, offset)
char *string; struct Window *window; int offset;
{
static struct StructData structdata[] = {
     { "-ReqCount",     "SHORT",               2, INTSIZE  },
     { " WScreen",      "struct Screen *",     5, PTRSIZE  },
     { " RPort",        "struct RastPort *",   5, PTRSIZE  },
     { "-BorderLeft",   "BYTE",                3, BYTESIZE },
     { "-BorderTop",    "BYTE",                3, BYTESIZE },
     { "-BorderRight",  "BYTE",                3, BYTESIZE },
     { "-BorderBottom", "BYTE",                3, BYTESIZE },
     { " BorderRPort",  "struct RastPort *",   5, PTRSIZE  },
     { " FirstGadget",  "struct Gadget *",     5, PTRSIZE  },
     { " Parent",       "struct Window *",     5, PTRSIZE  },
     { " Descendant",   "struct Window *",     5, PTRSIZE  },
     { "(Pointer",      "USHORT *",            5, PTRSIZE  },
     { "-PtrHeight",    "BYTE",                3, BYTESIZE },
     { "-PtrWidth",     "BYTE",                3, BYTESIZE },
     { "-XOffset",      "BYTE",                3, BYTESIZE },
     { "-YOffset",      "BYTE",                3, BYTESIZE }
  };
int sum, choice = -1;
  level++;
  while (choice) {
    sum = SetOptionText(string, structdata, (APTR)window, DATASIZE, offset);
    switch (choice = GetChoice(MAXGADG + 1)) {
      case 2:
        if (window->WScreen)
          PrScreen("The screen referenced in the window structure",
             window->WScreen);
        break;
      case 3:
        if (window->RPort)
          PrRastPort("The window's RPort (RastPort)", window->RPort);
        break;
      case 8:
        if (window->BorderRPort)
          PrRastPort("The window's BorderRPort", window->BorderRPort);
        break;
      case 9:
        if (window->FirstGadget)
          PrGadget("The window's first gadget", window->FirstGadget);
        break;
      case 12:
        printf("Sorry, selection not implemented\n\n");
        break;
      case 10:
        if (window->Parent)
          PrWindow("The 'parent' window", window->Parent);
        break;
      case 11:
        if (window->Descendant)
          PrWindow("The 'descendent' window", window->Descendant);
        break;
      case MOREGADG:
        PrWindow3("Window members (page 3)", window, sum);
        break;
    }
  }
  level--;
}


void PrWindow3(string, window, offset)
char *string; struct Window *window; int offset;
{
static struct StructData structdata[] = {
     { " IDCMPFlags",   "ULONG",                  1, PTRSIZE  },
     { " UserPort",     "struct MsgPort *",       5, PTRSIZE  },
     { " WindowPort",   "struct MsgPort *",       5, PTRSIZE  },
     { "(MessageKey",   "struct IntuiMessage *)", 5, PTRSIZE  },
     { "-DetailPen",    "UBYTE",                 13, BYTESIZE },
     { "-BlockPen",     "UBYTE",                 13, BYTESIZE },
     { "(CheckMark",    "struct Image *)",        5, PTRSIZE  },
     { " ScreenTitle",  "UBYTE",                  4, PTRSIZE  },
     { "-GZZMouseX",    "SHORT",                  2, INTSIZE  },
     { "-GZZMouseY",    "SHORT",                  2, INTSIZE  },
     { "-GZZWidth",     "SHORT",                  2, INTSIZE  },
     { "-GZZHeight",    "SHORT",                  2, INTSIZE  },
     { "(ExtData",      "UBYTE *)",               5, PTRSIZE  },
     { "(UserData",     "BYTE *)",                5, PTRSIZE  },
     { "(WLayer",       "struct Layer *)",        5, PTRSIZE  }
  };
static char *IDCMPnames[32] = {
     "SIZEVERIFY",     "NEWSIZE",       "REFRESHWINDOW",  "MOUSEBUTTONS",
     "MOUSEMOVE",      "GADGETDOWN",    "GADGETUP",       "REQSET",
     "MENUPICK",       "CLOSEWINDOW",   "RAWKEY",         "REQVERIFY",
     "REQCLEAR",       "MENUVERIFY",    "NEWPREFS",       "DISKINSERTED",
     "DISKREMOVED",    "WBENCHMESSAGE", "ACTIVATEWINDOW", "INACTIVEWINDOW",
     "DELTAMOVE",      "VANILLAKEY",    "INTUITICKS",     NULL,
     NULL,             NULL,            NULL,             NULL,
     NULL,             NULL,            NULL,             "LONELYMESSAGE"
  };
int sum, choice = -1;
  level++;
  while (choice) {
    sum = SetOptionText(string, structdata, (APTR)window, DATASIZE, offset);
    switch (choice = GetChoice(DATASIZE)) {
      case 1:
        FlagPrint("IDCMP flags set in this window",
              IDCMPnames, window->IDCMPFlags);
        break;
      case 2:
        if (window->UserPort)
          PrMsgPort("Window->UserPort",window->UserPort);
        break;
      case 3:
        if (window->WindowPort)
          PrMsgPort("Window->WindowPort",window->WindowPort);
        break;
      case 8:
        PrString("The screen title when this window is activated",
                 window->ScreenTitle);
        break;
    }
  }
  level--;
}
