TweetFollow Us on Twitter

ScreenPicker
Volume Number:8
Issue Number:6
Column Tag:TCL Workshop

Related Info: Picture Utilities Resource Manager

Object Support for Resources and cdev's

How to integrate Toolbox calls with Object Programming

By Joeseph Simpkins, MacTutor Regular Contributing Author

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

About the author

Joe is a programmer with over 18 years real time programming. He has used a variety of minis while working on several automation, seismic and telephony systems. He is completing a Geology degree while looking for his next job.

What is ScreenPicker?

ScreenPicker is an INIT/cdev that selects a PICT resource from the file StartupScreen at random by swapping the ID with the PICT resource ID = 0. This selects a random screen for the next startup. It performs the same function on the file DeskPicture, used by the extension DeskPict. The associated control panel enables or disables the randomization of each file and display of an Icon on startup. ScreenPicker does not patch any traps. This is a very simple example of an init with a control panel.

Why ScreenPicker?

As a diversion, I have created several startup screens and would like to see them without manual manipulations. This trait is called laziness, the key attribute of any effective programmer. I tried out two public domain randomizers, one manipulated a set of startup screens as files. It was painfully slow. The other operated on one file with multiple PICT resources. It ran fast enough but had the habit of crashing.

I disassembled the INIT that used the multiple PICT approach with the latest ResEdit and used it as a starting point. How should I implement the new routine? I considered assembly, normal Pascal and then Object Oriented Pascal and selected Object Oriented Pascal using TCL. When I examined TCL, I found little support for munging resources. This starts sounding like fun.

Project Organization

This project was developed in Think Pascal 4.0 and used a library generated by Think C 5.0. There were three major parts to this project, the ShowIconFamily library, the ScreenPickerINIT code resource, and the ScreenPicker control panel code resource. The ScreenPickerINIT project outputs the resource file for the ScreenPicker project. The resource file for the ScreenPickerINIT project was built using ResEdit. Here is a picture of my development folder:

ShowIconFamily Library

This library has only one entry point, the procedure ShowINIT. This is an implementation in C written by Patrick C. Beard and modified by James W. Walker. They were inspired by the oft used “Thank You Paul” routine. I was far too lazy (aka wise) to do more than compile and use the code as suggested by those authors.

ScreenPicker INIT

The critical functions of ScreenPicker are accomplished by manipulating the ID’s of resources. Resources pose some interesting problems when treated as objects. These are not naive objects with everything implemented as data. Many methods cannot obtain the needed information from instance variables but must query the system. In an object oriented environment, the users of the object are shielded from such gruesome details. Where possible, the methods’ connection to the toolbox calls is obvious. I implemented three objects to support the resource operations defined in Inside Macintosh Volumes 1 and 4. These sections of IM must be mastered to understand the code for this module. The class cFlags defines the flags used to communicate between the INIT and control panel. Here is the class hierarchy for the INIT:

Class CAllRes

The class CAllRes implements the toolbox resource calls that pertain to all the resources active in the system. Some of the methods for this class include the functions CurResFile and Unique1ID as well as the procedure SetResLoad. CurResFile returns the reference number for the current resource file. Unique1ID returns an unused ID in the current resource file for the specified resource type. SetResLoad enables or disables loading the data for resources.

The inspiration for this module would crash on startup with memory problems. I prevented this by calling SetResLoad to load only the resource information header, without loading the PICT resource data.

There is one coding trick used in all toolbox calls presented as methods in this and the next two classes. The actual toolbox call is implemented in a locally defined inline procedure or function. This avoids name conflicts since I used the toolbox name for the function wherever possible. One interesting thing about this class is that it has no instance variables. This class is intended for general use and is defined in the file TCLResources.p.

Class CRes

The class CRes implements the toolbox resource calls that pertain to individual resources. Some of the methods for this class include the functions GetType and GetResAttrs as well as the procedure ChangedResource. GetType returns the resource type defined in the instance variable for the specified resource. GetResAttrs returns the resource attributes from the system. ChangedResource sets the specified resource to be updated at the next appropriate time.

The instance variables for this class include the resource handle, type, ID number and name. There is no function to query which fields of that data are current. That sounds like a possible extension. If one needed to support the 7.0 feature of partial resources, one could derive a class from CRes with the needed instance variables and methods. I did not want to clutter up the normal case with unneeded instance variables nor did I need such methods in this module. The largest ScreenPicker resource manipulated is three bytes long.

Class CResFile

The class CResFile implements the toolbox resource calls that pertain to resource files. Some of the methods for this class include the functions GetRefNum and GetResFileAttrs as well as the procedure UpdateResFile. GetRefNum returns the file reference number defined in the instance variable for the specified resource file. GetResFileAttrs returns the resource file attributes from the system. UpdateResFile updates the disk copy of a resource file without closing it.

The instance variables for this class include the file name and file reference number. There is no function to query which fields of that data are current. That sounds like a possible extension. The largest ScreenPicker resource manipulated is three bytes long.

Class cScreenSet

The class cScreenSet is an application specific class that illustrates a derived object. It is descended from CResFile and defines the method RandomizeScreenSet. This is the method that does the major functions of the INIT. Look at the code for the details.

Class cFlags

The class cFlags is an application specific class that communicates between the INIT and cdev code resources. The flags are written by the cdev and read by the INIT. The Free method overrides the method from TObject.

Unit UScreenPickerINIT

The mainline for the INIT is this unit. It interfaces between the nonobject oriented startup environment and the object oriented rest of the module. The major interesting point is the manipulation of A4. Read and understand the ReadMe file that comes with Think Pascal 4.0. That is the only documentation for linking requirements. They define the requirements for using object oriented techniques in code resources such as INITs and cdevs. Here is segment view of this project:

ScreenPicker Control Panel

The ScreenPicker control panel is a very simple example of a control panel. It supports three check boxes and a display. However, it is implemented using object oriented techniques. The resource classes and the flag class are also used in the control panel. There are three modules dedicated to the cdev code resource. These are detailed below. Here is the class hierarchy for the cdev:

Class cControlPanel

UControlPanel defines a control panel class. That class provides default methods for all control panel messages. Even the cursor message that is described only in the Tech Notes is supported. The methods support command key equivalents for cut, copy and paste. All the arguments are copied to instance variables so that all arguments are available for all messages.

Class cCPScreenPicker

UCPScreenPicker overrides the specific methods and defines the instance variables used by ScreenPicker. This class overrides three methods Init, Deactivate and Hit. This is intended to be a very simple control panel. The method DoControlPanel is the common point for all messages.

There is one very important design decision in this module. I discovered that the graphics support in TCL was unusable in a Control Panel. TCL assumes that an application is present and contains the window. In a control panel, the window resides in the system. This made the TCL graphics support unusable. I decided there was too much work involved with complete object support, so I used conventional toolbox calls in the methods of this class.

General Comments

UScreenPicker is the interface between the conventional world and the object oriented environment of ScreenPicker. It handles the A4 manipulation and declares the ScreenPicker object. It passes every message to the ScreenPicker object.

To modify this routine for a different control panel, just replace the string ‘ScreenPicker’ with the name of the new control panel. The comments might need some updating before reuse.

Resources for ScreenPicker

Each code resource, ScreenPicker has the cdev and the INIT, requires a resource dedicated the object support. These resources are named in the Segment Type field in the dialog from the Set Project Type item from the Project menu. The default resource name is CCOD. The names must be unique to each code resource. I used CCIN and CCCP for my two resources.

General Comments

This was an educational exercise. I hope there is better object support for code resources in the future. TCL should be extended to support object oriented graphics for control panels. Symantec should update the User Manual for Think Pascal and should add the information from the ReadMe file. I leave porting these classes to C or MacApp as an exercise to any interested reader.

Listing:  UScreenSet
{ UScreenSet©1991, Joseph R. L. Simkins }

{ DESCRIPTION:  Provides the data type UScreenSet, }
{ which is an object class.  UScreenSet inherits }
{ its variables from CResFile. }

{ USE:  Add this file to your THINK Pascal project }
{ below ObjIntf.p and above your main program file }
{ or unit which uses this unit.  In your using code, }
{ include a 'uses' clause listing UScreenSet. }

unit UScreenSet;     { File is UScreenSet.p }

interface

 uses
  ObjIntf, TCLResources;

{ Here we declare the CRcScreenSetFile class; its method }
{  bodies are postponed until the implementation }
{  part below. This class does not support }
{  manipulations on partial resources. (IM6) }

 type
  cScreenSet = object(CResFile)

{ No New Instance variables }

{ Methods }
    procedure cScreenSet.IScreenSet (n: Str255);
{ Initializes a cScreenSet object with a Name }
    procedure cScreenSet.RandomizeScreenSet;
{ Selects random PICT, ID = 0, for a ScreenSet object }

{ Note:  These method names include the optional class }
{ name prefix, }
{ as in 'procedure cScreenSet.IScreenSet;' }

{ Note:  The class also inherits all of }
{ class CResFile's methods }
   end; { Class cScreenSet }

implementation

{ Here we implement cScreenSet's method bodies. }

 procedure cScreenSet.IScreenSet (n: Str255);
 { Assign parameters to instance variables }
 { Note the name IScreenSet instead of Init }
 begin
  self.IResFile(n);
 end; { cScreenSet.IScreenSet }

 procedure cScreenSet.RandomizeScreenSet;
  var
   oldPict, newPict: CRes;{ ScreenSet's resources }
   pictCount: Integer;    { ScreenSet's number of }
 { pictures }
   pictIndex: Integer;    { ScreenSet's number of }
 { pictures }
   resources: CAllRes;    { Global Resources Object }
 begin
  if self.OpenResFile <> -1 then begin
    { set up for resource information }
    new(resources);
    resources.IAllRes;
    { get number of PICT resources in file }
    pictCount := resources.Count1Resources('PICT');
    if pictCount > 1 then begin
      { get information on active (ID = 0) PICT }
      resources.SetResLoad(False);
      new(oldPict);
      oldPict.SetType('PICT');
      oldPict.SetIDNum(0);
      oldPict.Get1Resource;
      { continue only on no error }
      if oldPict.ResError = 0 then begin
        { work on next active PICT }
        new(newPict);
        newPict.SetType('PICT');
        { compute random index from tick count }
        pictIndex := abs(TickCount mod pictCount) + 1;
        newPict.Get1IndResource(pictIndex);
        { continue only on no error }
        if newPict.ResError = 0 then begin
          newPict.GetResInfo;
          { only update if different resource chosen }

          if newPict.GetIDNum <> 0 then begin
            { set old ID = 0 to ID from new }
            oldPict.SetIDNum(newPict.GetIDNum);
            oldPict.SetResInfoRetainName;
            oldPict.ChangedResource;
            { set new ID to 0 }
            newPict.SetIDNum(0);
            newPict.SetResInfoRetainName;
            newPict.ChangedResource;
          end;
        end;
        newPict.Free;
      end;
      oldPict.Free;
      resources.SetResLoad(True);
    end;
    resources.Free;
    self.CloseResFile;
  end;
 end; { cScreenSet.RandomizeScreenSet }

end.  { Unit UScreenSet }

Listing:  UFlags
{ UFlags©1991, Joseph R. L. Simkins }

{ DESCRIPTION:  Provides the data type UFlags, }
{ which is an object class.  UFlags has instance  }
{ variables of the show icon flag, startup flag }
{ and the desk flag. }

{ USE:  Add this file to your THINK Pascal project }
{ below TCLResources.p and above your main program file }
{ or unit which uses this unit.  In your using code, }
{ include a 'uses' clause listing UFlags. }

unit UFlags;     { File is UFlags.p }

interface

 uses
  ObjIntf, TCLResources;

{ Here we declare the CResFile class; its method }
{  bodies are postponed until the implementation }
{  part below. This class does not support }
{  manipulations on partial resources. (IM6) }

 type
  cFlags = object(TObject)

 { Instance variables }
    fFlagRes: CRes;{ cFlags's resources }
    fFlagResFile: CResFile; { cFlags's resources }

 { Methods }
    procedure cFlags.IFlags;
   { Initializes a cFlags object }
    procedure cFlags.TSetShowFlag (f: Boolean);
   { Sets the display icon on startup flag }
    procedure cFlags.TSetStartupFlag (f: Boolean);
   { Sets the randomize StartupScreen flag }
    procedure cFlags.TSetDeskFlag (f: Boolean);
   { Sets the randomize DeskPicture flag }
    function cFlags.TShowFlag: Boolean;
   { Returns the display icon on startup flag }
    function cFlags.TStartupFlag: Boolean;
   { Returns the randomize StartupScreen flag }
    function cFlags.TDeskFlag: Boolean;
   { Returns the randomize DeskPicture flag }

    procedure cFlags.Free;
    Override;
 { dispose of handles }

     { Note:  These method names include the optional }
   { class name prefix, }
     { as in 'procedure cFlags.IFlags;' }

   end; { Class cFlags }

implementation

 type
  flagsIndex = (ShowIndex, StartupIndex, DeskIndex);
  flagsString = packed array[flagsIndex] of byte;
  flagsStringPtr = ^flagsString;
  flagsStringHdl = ^flagsStringPtr;

{ Here we implement cFlags's method bodies. }

 procedure cFlags.IFlags;
 { Get the flags from the resource }
 { Note the name IFlags instead of Init }
 begin
  { set up resource with control flags, one per byte }
  new(self.fFlagRes);
  self.fFlagRes.SetType('JRS0');
  self.fFlagRes.SetIDNum(-4033);
  self.fFlagRes.GetResource;
  { set up for update of ScreenPicker Resources }
  new(fFlagResFile);
  self.fFlagResFile.IResFile('');
  self.fFlagResFile.SetRefNum(self.fFlagRes.HomeResFile);
 end; { cFlags.IFlags }

 procedure cFlags.TSetShowFlag (f: Boolean);
 { Sets the display icon on startup flag }
 begin
  { update both copies of the flags in memory }
  flagsStringHdl(self.fFlagRes.GetHandle)^^[ShowIndex] :=
    ord(f);
  self.fFlagRes.ChangedResource;
  self.fFlagResFile.UpdateResFile;
 end; { cFlags.TSetShowFlag }

 procedure cFlags.TSetStartupFlag (f: Boolean);
   { Sets the randomize StartupScreen flag }
 begin
  flagsStringHdl(self.fFlagRes.GetHandle)^^[StartupIndex] :=
    ord(f);
  self.fFlagRes.ChangedResource;
  self.fFlagResFile.UpdateResFile;
 end; { cFlags.TSetStartupFlag }

 procedure cFlags.TSetDeskFlag (f: Boolean);
 { Sets the randomize DeskPicture flag }
 begin
  flagsStringHdl(self.fFlagRes.GetHandle)^^[DeskIndex] :=
    ord(f);
  self.fFlagRes.ChangedResource;
  self.fFlagResFile.UpdateResFile;
 end; { cFlags.TSetDeskFlag }

 function cFlags.TShowFlag: Boolean;
   { Returns the display icon on startup flag }
 begin
  TShowFlag := Boolean
    (flagsStringHdl(self.fFlagRes.GetHandle)^^[ShowIndex]);

 end; { cFlags.TShowFlag }

 function cFlags.TStartupFlag: Boolean;
 { Returns the randomize StartupScreen flag }
 begin
  TStartupFlag := Boolean
  (flagsStringHdl(self.fFlagRes.GetHandle)^^[StartupIndex]);

 end; { cFlags.TStartupFlag }
 function cFlags.TDeskFlag: Boolean;
   { Returns the randomize DeskPicture flag }
 begin
  TDeskFlag := Boolean
    (flagsStringHdl(self.fFlagRes.GetHandle)^^[DeskIndex]);

 end; { cFlags.TDeskFlag }

 procedure cFlags.Free;
  Override;
 begin
  fFlagRes.Free; { dispose of the handle to the }
 { flags resource }
  fFlagResFile.Free; { dispose of the ScreenPicker }
 { file reference number }
  inherited Free;{ dispose flags data }
 end;

end.  { Unit UFlags }

Listing:  ScreenPicker
{ ScreenPicker   ©1991, Joseph R. L. Simkins }

{ DESCRIPTION:  This program consists of the main }
{ program, in this file. }

{ USE:  Create a THINK Pascal project that builds }
{  a code resource. Include UScreenSet.p and }
{ ShowIconFamily library. Then insert their }
{  dependancies. }

unit UScreenPickerINIT;   { File is UScreenPickerINIT.p }

interface

 uses
  UScreenSet, UFlags;

 procedure Main;
implementation

 procedure Main;

  var
   rs1: cScreenSet;{ defined in unit UScreenSet }
   flags: cFlags;{ Control Panel Flags }

  procedure ShowIconFamily (iconNumber: Integer);
 { show icon at Start up }
  external;

    {$S %_MethTables}
    {$Push}
    {$N-}
  procedure LoadMethTables;
  begin

  end;
    {$Pop}
    {$S}

 begin { Main }
 { point to globals }
  RememberA4;
  SetUpA4;
  LoadMethTables;

 { get old control panal flags }
  New(flags);
  flags.IFlags;

 { display startup }
  if flags.TShowFlag then
   ShowIconFamily(-4064);

 { Randomize StartupScreen }
  if flags.TStartupFlag then begin
    New(rs1);
    rs1.IScreenSet('StartupScreen');
    rs1.RandomizeScreenSet;
    rs1.Free;
   end;

 { Randomize DeskPicture }
  if flags.TDeskFlag then begin
    New(rs1);
    rs1.IScreenSet('DeskPicture');
    rs1.RandomizeScreenSet;
    rs1.Free;
   end;

 { prepare for exit }
  flags.Free;
  UnloadA4Seg(nil);
  RestoreA4;
 end; { Main }

end.  { Unit ScreenPicker }

Listing:  UControlPanel
{ UControlPanel  ©1991, Joseph R. L. Simkins }

{ DESCRIPTION:  Provides the data type UControlPanel, }
{ which is an object class.  UControlPanel inherits }
{ its variables from CCollaborator. }

{ USE:  Add this file to your THINK Pascal project }
{ below CCollaborator.p and above your main program file }
{ or unit which uses this unit.  In your using code, }
{ include a 'uses' clause listing UScreenSet. }

unit UControlPanel;       { File is UControlPanel.p }

interface

 uses
  ObjIntf;

{ Here we declare the cControlPanel class; its method }
{  bodies are postponed until the implementation }
{  part below. }

 type
  cControlPanel = object(TObject)
  { Note heritage of this class }

    { Instance variables }
    fItem: Integer;
    { local copy of Item for this call }
    fNumItems: Integer;
    { local copy of number of cdev items }
    fCPid: Integer;
    { local copy of Base resource of Control Panel driver }
    fEventptr: ^EventRecord;
    { local pointer to event record }
    fDlg: DialogPtr;
    { local copy of Control Panal Dialog pointer }

    { Methods }
    function cControlPanel.DoControlPanel (message, item, 
       numItems, CPid: integer;
       var event: EventRecord;
       dlg: DialogPtr): Longint;
    { master entry point }
    function cControlPanel.DoInitDev: Longint;
    { initialition of cdev }
    function cControlPanel.DoHitDev: Longint;
    { user clicked dialog item }
    function cControlPanel.DoCloseDev: Longint;
    { user did something to deactivate control panel }
    function cControlPanel.DoNulDev: Longint;
    { desk accessory run }
    function cControlPanel.DoUpdateDev: Longint;
    { update event }
    function cControlPanel.DoActivateDev: Longint;
    { activate event }
    function cControlPanel.DoDeactivateDev: Longint;
    { deactivate event }
    function cControlPanel.DoKeyEvtDev: Longint;
    { key-down or auto-key event, automaticly }
    { decodes undo, cut, copy, paste }
    function cControlPanel.DoMacDev: Longint;
    { check machine charistics }
    function cControlPanel.DoUndoDev: Longint;
    { standard menu undo }
    function cControlPanel.DoCutDev: Longint;
    { standard menu cut }
    function cControlPanel.DoCopyDev: Longint;
    { standard menu copy }
    function cControlPanel.DoPasteDev: Longint;
    { standard menu paste }
    function cControlPanel.DoClearDev: Longint;
    { standard menu clear }
    function cControlPanel.DoCursorDev: Longint;
    { custom cursor processing per TN 215 }

   end; { Class cControlPanel }

implementation

 function cControlPanel.DoInitDev: Longint;
 begin
  DoInitDev := Longint(self);
 end;

 function cControlPanel.DoHitDev: Longint;
 begin
  DoHitDev := Longint(self);
 end;

 function cControlPanel.DoCloseDev: Longint;
 begin
  self.Free;
  { minimal Control Panel has no additional data }
  DoCloseDev := Longint(nil);
 end;

 function cControlPanel.DoNulDev: Longint;
 begin
  DoNulDev := Longint(self);
 end;

 function cControlPanel.DoUpdateDev: Longint;
 begin
  DoUpdateDev := Longint(self);
 end;

 function cControlPanel.DoActivateDev: Longint;
 begin
  DoActivateDev := Longint(self);
 end;

 function cControlPanel.DoDeactivateDev: Longint;
 begin
  DoDeactivateDev := Longint(self);
 end;

 function cControlPanel.DoKeyEvtDev: Longint;
 begin
  sysBeep(1);
  { Minimal Control Panal does not support text processing }
  DoKeyEvtDev := Longint(self);
 end;

 function cControlPanel.DoMacDev: Longint;
 begin
  DoMacDev := Longint(true);
  { Minimal Control Panal runs on all machines }
 end;

 function cControlPanel.DoUndoDev: Longint;
 begin
  sysBeep(1);
  { Minimal Control Panal does not support text processing }
  DoUndoDev := Longint(self);
 end;

 function cControlPanel.DoCutDev: Longint;
 begin
  sysBeep(1);
  { Minimal Control Panal does not support text processing }
  DoCutDev := Longint(self);
 end;

 function cControlPanel.DoCopyDev: Longint;
 begin
  sysBeep(1);
  { Minimal Control Panal does not support text processing }
  DoCopyDev := Longint(self);
 end;

 function cControlPanel.DoPasteDev: Longint;
 begin
  sysBeep(1);
  { Minimal Control Panal does not support text processing }
  DoPasteDev := Longint(self);
 end;

 function cControlPanel.DoClearDev: Longint;
 begin
  sysBeep(1);
  { Minimal Control Panal does not support text processing }
  DoClearDev := Longint(self);
 end;

 function cControlPanel.DoCursorDev: Longint;
 begin
  DoCursorDev := Longint(self);
 end;

 function cControlPanel.DoControlPanel (message, item,
       numItems, CPid: integer;
       var event: EventRecord;
       dlg: DialogPtr): Longint;

  var
   ch: char;{To get the character pressed}

 begin
  { save arguments for this call }
  fItem := item;
  fNumItems := numItems;
  fCPid := CPid;
  fEventptr := @event;
  fDlg := dlg;

  case message of{Check the message sent}
   initDev: 
    DoControlPanel := self.DoInitDev;
   hitDev: 
    DoControlPanel := self.DoHitDev;
   closeDev: 
    DoControlPanel := self.DoCloseDev;
   nulDev: 
    DoControlPanel := self.DoNulDev;
   updateDev: 
    DoControlPanel := self.DoUpdateDev;
   activDev: 
    DoControlPanel := self.DoActivateDev;
   deactivDev: 
    DoControlPanel := self.DoDeactivateDev;
   keyEvtDev:  begin
     if event.what <> autoKey then
     {If its not an autoKey event}
      begin
       if BitAnd(event.modifiers, CmdKey) <> 0 then
       {Is the Command Key down?}
         ch := chr(BitAnd(fEventptr^.message,charCodeMask));
         {Convert to char}
       if ch in 
         ['z', 'Z', 'x', 'X', 'c', 'C', 'v', 'V'] then
         fEventptr^.what := nullEvent; { per TN 215 }
       case ch of{Translate the standard Edit Cmd Keys}
       'z', 'Z': 
      
         DoControlPanel := self.DoUndoDev;
       'x', 'X': 
         DoControlPanel := self.DoCutDev;
       'c', 'C': 
         DoControlPanel := self.DoCopyDev;
       'v', 'V': 
         DoControlPanel := self.DoPasteDev;
       otherwise
         DoControlPanel := self.DoKeyEvtDev;
       end;
      end
     else
      DoControlPanel := self.DoKeyEvtDev;
    end;
   macDev: 
    DoControlPanel := self.DoMacDev;
   undoDev: 
    DoControlPanel := self.DoUndoDev;
   cutDev: 
    DoControlPanel := self.DoCutDev;
   copyDev: 
    DoControlPanel := self.DoCopyDev;
   pasteDev: 
    DoControlPanel := self.DoPasteDev;
   clearDev: 
    DoControlPanel := self.DoClearDev;
   cursorDev: 
    DoControlPanel := self.DoCursorDev;
  end;
 end;

end.

Listing:  UCPScreenPicker
{ UCPScreenPicker©1991, Joseph R. L. Simkins }

{ DESCRIPTION:  Overrides the genegic procedures }
{ defined in UControlPanel inherits }
{ its variables from UControlPanel. }

{ USE:  Add this file to your THINK Pascal project }
{ below UControlPanel.p and above your main program file }
{ or unit which uses this unit.  In your using code, }
{ include a 'uses' clause listing UScreenSet. }

unit UCPScreenPicker;     { File is UCPScreenPicker.p }

interface

 uses
  UControlPanel, UFlags;

{ Here we declare the CControlPanel class; its method }
{  bodies are postponed until the implementation }
{  part below. }

 type
  cCPScreenPicker = object(CControlPanel)
  { Note heritage of this class }

    fFlags: cFlags;{ Control Panel Flags }

    function cCPScreenPicker.DoInitDev: Longint;
    Override;
    { initialition of cdev }

    function cCPScreenPicker.DoHitDev: Longint;
    Override;
    { user clicked dialog item }

    procedure cCPScreenPicker.Free;
    Override;
    { dispose of flags as well as control panel }

   end; { Class cCPScreenPicker }

  controlIndex = (skip, ShowIndex, StartupIndex, DeskIndex);

implementation
 function cCPScreenPicker.DoInitDev: Longint;
  Override;
  var
   itemType: Integer;
   itemHandle: Handle;
   itemBox: Rect;
 begin
  { get old control panal flags }
  New(fFlags);
  fFlags.IFlags;
  { copy flags from resource to dialog }
  GetDItem(fDlg, fNumItems + ord(ShowIndex), itemType,
    itemHandle, itemBox);
  SetCtlValue(ControlHandle(itemHandle),
    ord(fFlags.TShowFlag));
  GetDItem(fDlg, fNumItems + ord(StartupIndex), itemType,
    itemHandle, itemBox);
  SetCtlValue(ControlHandle(itemHandle),
    ord(fFlags.TStartupFlag));
  GetDItem(fDlg, fNumItems + ord(DeskIndex), itemType,
    itemHandle, itemBox);
  SetCtlValue(ControlHandle(itemHandle),
    ord(fFlags.TDeskFlag));
  DoInitDev := inherited DoInitDev;
 end;

 function cCPScreenPicker.DoHitDev: Longint;
  Override;
  var
   itemType: Integer;
   itemHandle: Handle;
   itemBox: Rect;
   boxValue: Boolean;
 begin
  GetDItem(fDlg, fItem, itemType, itemHandle, itemBox);
  boxValue := not
    odd(GetCtlValue(ControlHandle(itemHandle)));
  SetCtlValue(ControlHandle(itemHandle), ord(boxValue));
  case controlIndex(fItem - fNumItems) of
   ShowIndex: 
    fFlags.TSetShowFlag(boxValue);
   StartupIndex: 
    fFlags.TSetStartupFlag(boxValue);
   DeskIndex: 
    fFlags.TSetDeskFlag(boxValue);
  end;
  DoHitDev := inherited DoHitDev;
 end;

 procedure cCPScreenPicker.Free;
  Override;
 begin
  fFlags.Free;
  inherited Free;{ dispose Control Panel data }
 end;

end.

Listing:  ScreenPicker
{ ScreenPicker   ©1991, Joseph R. L. Simkins }

{ DESCRIPTION:  This program consists of the main }
{ program, in this file. }

{ USE:  Create a THINK Pascal project that builds }
{  a code resource. Include UScreenSet.p and }
{ ShowIconFamily library. Then insert their }
{  dependancies. }

unit UScreenPicker;{ File is UScreenPicker.p }

interface

 uses
  UCPScreenPicker;

 function Main (message, item, numItems, cPanelID: Integer;
       var theEvent: EventRecord;
       cdevValue: LongInt;
       CPDialog: DialogPtr): LongInt;

implementation

    {$S %_MethTables}
    {$Push}
    {$N-}
 procedure LoadMethTables;
 begin

 end;
    {$Pop}
    {$S}

 function Main (message, item, numItems, cPanelID: Integer;
       var theEvent: EventRecord;
       cdevValue: LongInt;
       CPDialog: DialogPtr): LongInt;

  var
   controlPanel: cCPScreenPicker;

 begin { Main }
  { point to globals }
  RememberA4;
  SetUpA4;
  LoadMethTables;

  { allocate ScreenPicker control panel object on init }
  if message = initDev then
   new(controlPanel)
  else
   controlPanel := cCPScreenPicker(cdevValue);
  if controlPanel <> nil then
   Main := controlPanel.DoControlPanel(message, item,
     numItems, cPanelID, theEvent, CPDialog)
  else
   Main := 0;

  { prepare for exit }
  UnloadA4Seg(nil);
  RestoreA4;
 end; { Main }

end.  { Unit ScreenPicker }

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »

Price Scanner via MacPrices.net

Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.