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

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more

Latest Forum Discussions

See All

Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »
TouchArcade Game of the Week: ‘Vroomies’
So here’s a thing: Vroomies from developer Alex Taber aka Unordered Games is the Game of the Week! Except… Vroomies came out an entire month ago. It wasn’t on my radar until this week, which is why I included it in our weekly new games round-up, but... | Read more »
SwitchArcade Round-Up: ‘MLB The Show 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for March 15th, 2024. We’re closing out the week with a bunch of new games, with Sony’s baseball franchise MLB The Show up to bat yet again. There are several other interesting games to... | Read more »
Steam Deck Weekly: WWE 2K24 and Summerho...
Welcome to this week’s edition of the Steam Deck Weekly. The busy season has begun with games we’ve been looking forward to playing including Dragon’s Dogma 2, Horizon Forbidden West Complete Edition, and also console exclusives like Rise of the... | Read more »
Steam Spring Sale 2024 – The 10 Best Ste...
The Steam Spring Sale 2024 began last night, and while it isn’t as big of a deal as say the Steam Winter Sale, you may as well take advantage of it to save money on some games you were planning to buy. I obviously recommend checking out your own... | Read more »
New ‘SaGa Emerald Beyond’ Gameplay Showc...
Last month, Square Enix posted a Let’s Play video featuring SaGa Localization Director Neil Broadley who showcased the worlds, companions, and more from the upcoming and highly-anticipated RPG SaGa Emerald Beyond. | Read more »
Choose Your Side in the Latest ‘Marvel S...
Last month, Marvel Snap (Free) held its very first “imbalance" event in honor of Valentine’s Day. For a limited time, certain well-known couples were given special boosts when conditions were right. It must have gone over well, because we’ve got a... | Read more »
Warframe welcomes the arrival of a new s...
As a Warframe player one of the best things about it launching on iOS, despite it being arguably the best way to play the game if you have a controller, is that I can now be paid to talk about it. To whit, we are gearing up to receive the first... | Read more »
Apple Arcade Weekly Round-Up: Updates an...
Following the new releases earlier in the month and April 2024’s games being revealed by Apple, this week has seen some notable game updates and events go live for Apple Arcade. What The Golf? has an April Fool’s Day celebration event going live “... | Read more »

Price Scanner via MacPrices.net

Apple Education is offering $100 discounts on...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take $100 off the price of a new M3 MacBook Air.... Read more
Apple Watch Ultra 2 with Blood Oxygen feature...
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
New promo at Sams Club: Apple HomePods for $2...
Sams Club has Apple HomePods on sale for $259 through March 31, 2024. Their price is $40 off Apple’s MSRP, and both Space Gray and White colors are available. Sale price is for online orders only, in... Read more
Get Apple’s 2nd generation Apple Pencil for $...
Apple’s Pencil (2nd generation) works with the 12″ iPad Pro (3rd, 4th, 5th, and 6th generation), 11″ iPad Pro (1st, 2nd, 3rd, and 4th generation), iPad Air (4th and 5th generation), and iPad mini (... Read more
10th generation Apple iPads on sale for $100...
Best Buy has Apple’s 10th-generation WiFi iPads back on sale for $100 off MSRP on their online store, starting at only $349. With the discount, Best Buy’s prices are the lowest currently available... Read more
iPad Airs on sale again starting at $449 on B...
Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices again for $150 off Apple’s MSRP, starting at $449. Sale prices for online orders only, in-store price may vary. Order online, and choose... Read more
Best Buy is blowing out clearance 13-inch M1...
Best Buy is blowing out clearance Apple 13″ M1 MacBook Airs this weekend for only $649.99, or $350 off Apple’s original MSRP. Sale prices for online orders only, in-store prices may vary. Order... Read more
Low price alert! You can now get a 13-inch M1...
Walmart has, for the first time, begun offering new Apple MacBooks for sale on their online store, albeit clearance previous-generation models. They now have the 13″ M1 MacBook Air (8GB RAM, 256GB... Read more
Best Apple MacBook deal this weekend: Get the...
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 15-inch M3 MacBook Air (Midnight) on sale...
Amazon has the new 15″ M3 MacBook Air (8GB RAM/256GB SSD/Midnight) in stock and on sale today for $1249.99 including free shipping. Their price is $50 off MSRP, and it’s the lowest price currently... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-350696 **Updated:** Mon Mar 11 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill WellSpan Medical Group, York, PA | Nursing | Nursing Support | FTE: 1 | Regular | Tracking Code: 200555 Apply Now Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.