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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
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 »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.