Tear-off, Float menus (code)
Volume Number: 4
Issue Number: 4
Column Tag: C Workshop
Tear-off Menus & Floating Palettes (code)
TearOffMDEF.project
TearOffMDEF.c ÍThe menu definition.
PaletteWDEF.project
(No need to link with MacTraps)
PaletteWDEF.c ÍThe window definition.
TearOffPalette.project
(All of these go in the main segment)
TearOffPalette.c ÍThe main program.
Interface.c ÍAdjusts the use of color at runtime.
Error.c ÍError and grow zone function.
Window.c ÍCreation and updating of windows.
Dialog.c ÍAbout dialog and utilities.
Menu.c ÍThe routines called by the MDEF.
Palette.c ÍThe code that floats the palettes.
(Place this in a separate segment)
Initialize.c ÍInitialization and creation of palettes.
(The include files are used by all of the sources)
Constants.h Íinclude files and our definitions.
Variables.h ÍGlobal variables.
(MPW Rez format resource file)
TearOffPalette.project.r
(Move the MDEF and WDEF into this file with ResEdit)
TearOffPalette.project.rsrc
Finally, if you program in C, you had better try to maintain a style of some kind.
If you don’t, nobody will ever be able to make heads or tails of your code, including
you. We’ve tried to use classic indentation, but we’d like to clarify our nomenclature.
FunctionName() Always an initial capital.
GlobalVariable Just like the functions.
localVariable The first letter is always lower case.
A_CONSTANT All capitals, underscores dividing words.
Of course many of Apple’s globals and constants don’t follow our rules. Oh well. It
might not make sense to you, but at least we’re consistent. On to the code!
/*
----------T E A R O F F P A L E T T E
version 1.0
by Don Melton and Mike Ritter
Copyright © 1987, 1988 by Impulse Technologies,
Inc., all rights reserved.
Filename: Constants.h
Font: Courier, 9 point
Tab setting: 2
Compiler: LightspeedC 2.15
Project type: APPL
Creator: TOPD */
/*
----------------------------------------
INCLUDE DEFINITIONS */
#include “Color.h”
#include “ColorToolbox.h”
#include “ControlMgr.h”
#include “DeskMgr.h”
#include “DialogMgr.h”
#include “EventMgr.h”
#include “FileMgr.h”
#include “FontMgr.h”
#include “MacTypes.h”
#include “MemoryMgr.h”
#include “MenuMgr.h”
#include “OSUtil.h”
#include “PackageMgr.h”
#include “Quickdraw.h”
#include “ResourceMgr.h”
#include “SegmentLdr.h”
#include “StdFilePkg.h”
#include “TextEdit.h”
#include “ToolboxUtil.h”
#include “WindowMgr.h”
/*
--------------------------------------------------------
SYSTEM CONSTANTS */
#define nil 0
#define NULL 0
#define zoomDocProc 8
#define zoomNoGrow 12
/*
--------------------------------------------------------
ENVIRONMENT */
#define VERSION_REQUESTED 1
#define WAIT_NEXT_EVENT_TRAP_NUMBER 0x60
#define UNIMPLEMENTED_TRAP_NUMBER 0x9f
/*
--------------------------------------------------------
MEMORY */
#define MEMORY_BUFFER_SIZE 0x8000 /* 32K. */
/*
--------------------------------------------------------
EVENTS */
#define SLEEP_DURATION 50
/*
--------------------------------------------------------
WINDOWS */
#define VISIBLE true
#define NOT_VISIBLE false
#define BRING_TO_FRONT (WindowPtr) -1
#define SEND_BEHIND nil
#define GO_AWAY_BOX true
#define NO_GO_AWAY_BOX false
#define NO_REFCON nil
/*
--------------------------------------------------------
PALETTES */
enum {
TOOL_PALETTE,
PATTERN_PALETTE,
COLOR_PALETTE,
DOCUMENT_WINDOW
};
#define PALETTE_COUNT 3
#define PALETTE_WDEF_ID 128
#define TEAROFF_MDEF_ID 128
/*
--------------------------------------------------------
TEAROFF MENU GLOBALS */
typedef struct TearOffMenuGlobals {
void (*drawMenuProc)();
short (*findItemProc)();
void (*hiliteItemProc)();
SysEnvRec *environment;
WindowPtr paletteWindow;
Point position;
short currentItem;
Boolean itemHilited;
} TearOffMenuGlobals, *TearOffMGlobalsPtr, **TearOffMGlobalsHdl;
#define TEAR_OFF_MENU_GLOBALS_TYPE ‘TOMG’
/*
--------------------------------------------------------
TOOL PALETTE */
#define TOOLS_ACROSS 4