BigEasy/OneWindow.c

/*
    File:       OneWindow.c
 
    Contains:   xxx put contents here xxx
 
    Written by: xxx put writers here xxx
 
    Copyright:  © 1991-1992, 1994 by Apple Computer, Inc., all rights reserved.
 
    This file is used in these builds: Warhol
 
    Change History (most recent first):
 
         <7>     17-8-94    dvb     Big Easy Printing, and various tidiness
         <5>      1/7/93    dvb     Built in window-copy command.
         <4>    11/12/91    dvb     General fixation
         <3>     7/18/91    dvb     More.
         <2>     4/25/91    JB      
 
    To Do:
*/
 
/*
 * file: OneWindow.c
 *
 * started 7 July 1988 09:34
 * david van brink
 *
 * A starting point for BigEasy programs
 *
 */
 
 
/*--------------------------
    Inclusions
--------------------------*/
 
#include <QuickDraw.h>
#include <Memory.h>
#include <Windows.h>
//#include <OSUtils.h>
 
#include "BigEasy2.h"
#include "BigEasyUtils.h"
#include "BigEasyGrafish.h"
 
/*--------------------------
    Limits and Konstants
--------------------------*/
enum
    {
    mFirstDocOnly = 100,
    mClose,
    mLastDocOnly,
    mOpen
    };
 
typedef struct
    {
    WindowPtr w;
    } Globals;
 
Globals *g = nil;
 
/*--------------------------
    Prototypes
--------------------------*/
static void DrawDoc(short n);
static void ClickDoc(short n,Point p,short mods);
static void KeyDoc(short n,short key,short code,short mods);
static void IdleDoc(short n, Boolean front);
static void GoAwayDoc(short n);
static void ActivateDoc(short n);
static void DeactivateDoc(short n);
static void LetsQuit(short n,short menuItem,short menuRef);
static void OpenWindow(short n,short menuItem,short menuRef);
static void InitVars(void);
 
 
/*--------------------------
    Computer Programs
--------------------------*/
 
 
#define kHeaderHeight 17
#define kWindowWidth 200
#define kWindowHeight 100
 
void DrawDoc(short n)
/*
 * Draws the window.
 */
    {
    #pragma unused (n)
    Rect r;
 
    GoBW();
    EraseRect(&qd.thePort->portRect);
    TextSize(9);
    MoveTo(10,12);
    DrawString("\pThis is the window");
    MoveTo(0,kHeaderHeight-3);
    Line(qd.thePort->portRect.right,0);
    MoveTo(0,kHeaderHeight-1);
    Line(qd.thePort->portRect.right,0);
 
 
    RGBFore(50000,50000,65535);
    r = qd.thePort->portRect;
    r.top = kHeaderHeight;
    PaintRect(&r);
    GoBW();
    }
 
 
void ClickDoc(short n,Point p,short mods)
/*
 * Come here for a click in the window.
 */
    {
    #pragma unused (n,p,mods)
    SysBeep(1);
    }
 
 
void KeyDoc(short n,short key,short code,short mods)
    {
    #pragma unused (n,key,code,mods)
    }
 
void IdleDoc(short n, Boolean front)
    {
    #pragma unused (n,front)
    }
 
void GoAwayDoc(short n)
/*
 * Close that window...
 */
    {
    UninstallWindow(n);
    }
 
void ActivateDoc(short n)
    {
    #pragma unused (n)
 
    SetMenuItemRange(mFirstDocOnly,mLastDocOnly,1,0);
    SetMenuItem(mOpen,-1,0,0,nil);              /* disable "Open" menu item     */
    }
 
void DeactivateDoc(short n)
    {
    #pragma unused (n)
 
    SetMenuItemRange(mFirstDocOnly,mLastDocOnly,-1,0);
    SetMenuItem(mOpen,1,0,0,nil);               /* enable "Open" menu item      */
    }
 
void LetsQuit(short n,short menuItem,short menuRef)
    {
    #pragma unused (n,menuItem,menuRef)
    gQuitApp++;
    }
 
void OpenWindow(short n,short menuItem,short menuRef)
    {
    #pragma unused (n,menuItem,menuRef)
    Rect r;
    WindowPtr w;
 
    SetRect(&r,0,0,kWindowWidth,kWindowHeight);
    OffsetRect(&r,30,50);
 
    g->w = InstallWindow(1,"\pWindow",&r,0,wCopyDraw + wGrowable + wPrintDraw,
            DrawDoc,ClickDoc,KeyDoc,GoAwayDoc,
            ActivateDoc,DeactivateDoc,IdleDoc);
    }
 
void InitVars()
/*
 * Called once at startup: yes, it
 * inits the vars.
 */
    {
    gMenuNeedsCmdKey = false;
 
    g = (Globals *)NewPtrClear(sizeof(Globals));
    }
 
void Bootstrap()
    {
    InitVars();
 
/*** File Menu ***/
    InstallMenu("\pFile",nil,0);
    InstallMenuItem("\pOpen/O",OpenWindow,mOpen);
    InstallMenuItem("\pClose/W",(void *)GoAwayDoc,-mClose);
    InstallMenuItem("\p(-",nil,0);
    InstallPrintItems(nil,nil);
    InstallMenuItem("\p(-",nil,0);
    InstallQuitItem(LetsQuit,0);
 
/*** Edit Menu ***/
    InstallEditMenu(nil,nil,nil,nil,nil);
 
    OpenWindow(0,0,0);
    }
 
void Hatstrap()
/*
  * clean up
  */
    {
    }