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

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 »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more

Jobs Board

Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Apr 20, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
*Apple* Systems Administrator - JAMF - Syste...
Title: Apple Systems Administrator - JAMF ALTA is supporting a direct hire opportunity. This position is 100% Onsite for initial 3-6 months and then remote 1-2 Read more
Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.