A Sample of an Extension to the Monitors Control Panel
A Sample of an Extension to the Monitors Control Panel
The following program shows code that defines an extension to the Monitors
control panel. The next program after that shows the resources for this
extension in Rez format.
In response to the startup message, the Monitors extension shown in the first
program checks the value of the item parameter to determine whether the user
is a superuser. If the user is not a superuser, the Monitors extension uses the
default values for the 'RECT' resource shown in the second program This
rectangle ends just before the dividing line, so that the superuser controls are
not displayed. If the user is a superuser, the SetUpData function in the first
program extends the rectangle in the 'RECT' resource so that the rectangle
includes all of the controls in the 'DITL' resource.
The code for the startup message allocates memory for the use of the Monitors
extension and returns a handle to this memory as the function result. For all
subsequent messages, the Monitors control panel passes the previous function
result to the extension in the monitorValue parameter. In order to preserve the
handle to this memory, the first program example sets the monitor function
equal to the monitorValue parameter for all messages that the function does not
process.
// Sample of an extension to the Monitors control panel
// Assuming inclusion of MacHeaders
// constants used in code
#define textItem 1 // StaticText item in cdev
#define lineItem 2 // separation line
#define downItem 3 // Down Arrow user item
#define upItem 4 // Up Arrow user item
#define countItem 6 // frame for count
#define brightItem 9 // radio button " filter
#define lessItem 10 // radio button " aliasing
#define slotCount 6 // a reasonable value
#define initMsg 1 // initialization
#define okMsg 2 // user clicked OK button
#define cancelMsg 3 // user clicked Cancel button
#define hitMsg 4 // user clicked control in Options dialog box
#define nulMsg 5 // periodic event
#define updateMsg 6 // update event
#define activateMsg 7 // not used
#define deactivateMsg 8 // not used
#define keyEvtMsg 9 // keyboard event
#define superMsg 10 // show superuser controls
#define normalMsg 11 // show only normal controls
#define startupMsg 12 // code has been loaded
// resource IDs
#define MemErrAlert 130 // alert to user: out of memory
#define deepAlert 131 // all other errors
#define dataRes -4080 // store data
// global typedefs
struct ScrnRecord { // 'scrn' info for each screen
short srDrvrHW; // spDrvrHW from Slot Manager
short srSlot; // slot # for the screen's video card
long srDCtlDevBase; // base address of card's memory
short srMode; // sRsrcID for desired Mode
short srFlagMask; // 0x77FE
short srFlags; // active,main screen, B/W or color
short srColorTable; // resource ID of desired 'clut'
short srGammaTable; // resource ID of desired 'gamma'
Rect srRect; // device's rectangle global coordinates
short srCtlCount; // number of control calls
};
typedef struct ScrnRecord ScrnRecord; // Record type for 'scrn' info
typedef ScrnRecord *ScrnRecordPtr; // Pointer type for 'scrn' info
typedef ScrnRecordPtr *ScrnRecordHandle; // Handle type for 'scrn' info
struct ScrnRsrc { // complete 'scrn' resource
short count; // # of screens con figured here
ScrnRecord scrnRecs[slotCount]; // config for each one
};
typedef struct ScrnRsrc ScrnRsrc; // record type for 'scrn' resource
typedef ScrnRsrc *ScrnRsrcPtr; // pointer type for 'scrn' resource
typedef ScrnRsrcPtr *ScrnRsrcHandle; // handle type for 'scrn' resource
struct MonitorData { // local data for extension
Boolean isSuperUser; // is the user a superuser?
short filteringSetting; // new filter setting
short oldFiltering; // previous filter setting
short sleepTime; // new sleep time
short oldSleep; // previous sleep time
};
typedef struct MonitorData MonitorData; // record type for local data
typedef MonitorData *MonitorDataPtr; // pointer type for local data
typedef MonitorDataPtr *MonitorDataHandle; // handle type for local data
// some handy typedefs