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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.