{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
{
GENERIC CUSTOM CREATORS
```````````````````````````````````````````
A Generic Utilities unit, for use by any program.
Copyright İ by David Sinclair, 1990 2001.
I am releasing these units to the Pascal community. Feel free to use them in whole or part in your Pascal programs.
You are also welcome to modify these units to suit your needs. If you wish to re-distribute the sources with your changes,
please clearly indicate that you have changed them. In all cases, you must leave these comments and the copyright notice intact.
If you use a significant portion of these units, I would appreciate acknowledgement in your About dialog and/or documentation,
e.g. ³Dejal Generic Utilities copyright İ by David Sinclair, 1990 - 2001.²
Iıd appreciate it if you also e-mail me at if you find these units useful. If you have any questions about
these units, you can e-mail me at that address and I will do my best to help, time permitting. However, these units are provided
³as is² and I do not guarantee their reliablity or suitability for any particular purpose.
These units have been used extensively in my Dejal shareware and freeware products over the years. Most of the code was written
many years ago, and the code and style may not be optimal in all cases, but unless otherwise noted all routines have been used
in released software, so should work as described.
Please visit and try out Dejal QuickEncrypt and/or my other shareware products. If you want to show
your appreciation for these units financially, registrations for my shareware are always welcome! Or you can make a donation to
me via my online order form: .
I hope you find these units useful, and good luck in your Pascal endeavors!
- David Sinclair, Dejal
* * *
UNIT HISTORY: (Reverse chronology)
Start finish dates: Comments / changes:
27 October 2001 Public release as source code.
16 August 1997 Added the CreatorHandleButtonHits routine.
17 January 1995 Added the creatorSetupPopupMenu routine.
12 January 1995 Started the unit based on code from my Phase Two Shareware applications.
}
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
unit genCustomCreators;
interface
uses
genToolbox, genStrings, genDialogs;
type
popupDataRec = record
mHandle: menuHandle;
mID: integer;
mPrivate: array[0..0] of signedByte
end;
popupDataPtr = ^popupDataRec;
popupDataHandle = ^popupDataPtr;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
procedure creatorSetupPopupMenu (theDialog: dialogPtr; theItem, theValue: integer);
procedure creatorSetupItems (theDialog: dialogPtr; theEdit, thePopup: integer; {}
theCreator: osType; creatorStringList: integer);
procedure creatorHandleEditHits (theDialog: dialogPtr; theEdit, thePopup: integer; {}
var theCreator: osType; creatorStringList: integer);
procedure creatorHandlePopupHits (theDialog: dialogPtr; theEdit, thePopup: integer; {}
var theCreator: osType; creatorStringList: integer);
PROCEDURE CreatorHandleButtonHits (theDialog: DialogPtr; theEdit, thePopup: Integer; VAR theCreator: OSType; creatorStringList: Integer);
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
implementation
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
procedure creatorSetupPopupMenu (theDialog: dialogPtr; theItem, theValue: integer);
{ Adjusts the itemBox of the specified popup menu to get around ResEditıs little }
{ quirk of not setting the botRight position properly (I dunno why... it used to work?). }
{ Also sets the current menu item to the value specified, and the controlıs max }
{ value to the correct value (it wonıt be correct if you inserted or appended items). }
{ Note that you can call this routine for general-purpose popup menus, not just creator }
{ selection menus. }
{ Written by David Sinclair, 1 June 1994; added max value setting, 14 November 1994; }
{ made into a genCustomCreators routine, 17 January 1995. }
const
popupHeight = 19;
var
itemType: integer;
itemHandle: handle;
itemBox: rect;
theMenu: menuHandle;
begin
GetDialogItem(theDialog, theItem, itemType, itemHandle, itemBox);
if dlogItemIsCtrl(itemType, itemHandle) then
begin
with controlHandle(itemHandle)^^ do
begin
contrlRect.bottom:= contrlRect.top + popupHeight;
itemBox:= contrlRect;
end;
SetDialogItem(theDialog, theItem, itemType, itemHandle, itemBox);
theMenu:= popupDataHandle(controlHandle(itemHandle)^^.contrlData)^^.mHandle;
if theMenu <> nil then
SetControlMaximum(controlHandle(itemHandle), countMItems(theMenu));
SetControlValue(controlHandle(itemHandle), theValue);
end
end;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
procedure setupCreatorPopup (theDialog: dialogPtr; theItem: integer; theCreator: osType; {}
creatorStringList: integer; fromSetup: boolean);
{ Sets up the creator popup menu items; pass true for fromSetup if calling from the setup routine. }
{ Written by David Sinclair, 18 June 1994, based on code from SndCataloguer; genericised }
{ 12 January 1995. }
var
itemHandle: controlHandle;
popupMenu: menuHandle;
theText, blert: str255;
count, index, popItemNo: integer;
begin
if dlogGetCtrlItem(theDialog, theItem, itemHandle) then
popupMenu:= popupDataHandle(itemHandle^^.contrlData)^^.mHandle
else
popupMenu:= nil;
count:= strCountStrings(creatorStringList);
if (popupMenu <> nil) & (count > 0) then
begin
popItemNo:= 0;
for index:= 1 to count do
begin
GetIndString(theText, creatorStringList, index);
if fromSetup then
begin
InsertMenuItem(popupMenu, period, index - 1); { Avoid interpreting meta-characters }
SetMenuItemText(popupMenu, index, copy(theText, 6, etc));
end;
if StrToOSType(theText) = theCreator then
popItemNo:= index
end;
if popItemNo = 0 then { Custom creator }
begin
popItemNo:= CountMItems(popupMenu);
GetMenuItemText(popupMenu, popItemNo, theText);
strSplitString(theText, space, theText, blert);
theText:= concat(theText, ' (', theCreator, ')');
SetMenuItemText(popupMenu, popItemNo, theText)
end;
if fromSetup then
creatorSetupPopupMenu(theDialog, theItem, popItemNo)
else
SetControlValue(itemHandle, popItemNo);
end;
end;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
procedure creatorSetupItems (theDialog: dialogPtr; theEdit, thePopup: integer; {}
theCreator: osType; creatorStringList: integer);
{ Sets up the creator code items. Pass the item numbers of the edit and popup items, the current }
{ value of the creator variable, and the ID of the STR# containing the creator information (in the }
{ form ³CREA=Application Name², where CREA is a 4-char creator code). }
{ Written by David Sinclair, 19 July 1994; genericised 12 January 1995. }
begin
dlogSetItemStatus(theDialog, theEdit, 4, itemDefaultOptions);
dlogSetItemText(theDialog, theEdit, theCreator);
setupCreatorPopup(theDialog, thePopup, theCreator, creatorStringList, true);
end;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
procedure creatorHandleEditHits (theDialog: dialogPtr; theEdit, thePopup: integer; {}
var theCreator: osType; creatorStringList: integer);
{ Handles hits on a creator edit field. The new creator value is returned. See creatorSetupItems }
{ for a description of the parameters. }
{ Written by David Sinclair, 18 June 1994; genericised 12 January 1995. }
var
itemType: integer;
itemHandle: handle;
itemBox: rect;
theText: str255;
oldCreator: osType;
begin
oldCreator:= theCreator;
theText:= dlogGetItemText(theDialog, theEdit);
if theText = null then
begin
theText:= '????';
dlogSetItemText(theDialog, theEdit, theText);
SelectDialogItemText(theDialog, theEdit, 0, 4)
end;
theCreator:= StrToOSType(theText);
if theCreator <> oldCreator then
begin
setupCreatorPopup(theDialog, thePopup, StrToOSType(theText), creatorStringList, false);
GetDialogItem(theDialog, thePopup, itemType, itemHandle, itemBox);
InvalRect(itemBox); { Refresh the popup menu box }
end
end;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
procedure creatorHandlePopupHits (theDialog: dialogPtr; theEdit, thePopup: integer; {}
var theCreator: osType; creatorStringList: integer);
{ Handles hits on a creator popup menu. The new creator value is returned. See creatorSetupItems }
{ for a description of the parameters. }
{ Written by David Sinclair, 18 June 1994, based on code from SndCataloguer; genericised }
{ 12 January 1995. }
var
itemHandle: controlHandle;
popupMenu: menuHandle;
theText, blert: str255;
count, popItemNo, customCreatorItem: integer;
begin
if dlogGetCtrlItem(theDialog, thePopup, itemHandle) then
popupMenu:= popupDataHandle(itemHandle^^.contrlData)^^.mHandle
else
popupMenu:= nil;
count:= strCountStrings(creatorStringList);
if (popupMenu <> nil) & (count > 0) then
begin
popItemNo:= GetControlValue(itemHandle); { Get selected menu item }
customCreatorItem:= CountMItems(popupMenu);
if popItemNo <= customCreatorItem - 2 then
GetIndString(theText, creatorStringList, popItemNo)
else { Other }
begin
GetMenuItemText(popupMenu, customCreatorItem, theText);
strSplitString(theText, '(', blert, theText);
if theText = null then
theText:= '????';
end;
theCreator:= StrToOSType(theText);
dlogSetItemText(theDialog, theEdit, theCreator);
SelectDialogItemText(theDialog, theEdit, 0, 4);
end;
end;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
PROCEDURE CreatorHandleButtonHits (theDialog: DialogPtr; theEdit, thePopup: Integer; VAR theCreator: OSType; creatorStringList: Integer);
{Handles hits on a creator Set button. The new creator value is returned. See creatorSetupItems for a description
of the parameters. }
{Written by David Sinclair, 16 August 1997. }
VAR
itemType: Integer;
itemHndl: Handle;
itemBox: Rect;
reply: StandardFileReply;
typeList: SFTypeList;
fndrInfo: FInfo;
err: OSErr;
BEGIN
typeList[0]:= 'APPL';
typeList[1]:= 'adrp';
StandardGetFile(Nil,2,@typeList,reply);
IF reply.sfGood THEN BEGIN
err:= FSpGetFInfo(reply.sfFile,fndrInfo);
IF err=noErr THEN BEGIN
theCreator:= fndrInfo.fdCreator;
DlogSetItemText(theDialog,theEdit,theCreator);
SelectDialogItemText(theDialog,theEdit,0,4);
SetupCreatorPopup(theDialog,thePopup,theCreator,creatorStringList,false);
GetDialogItem(theDialog,thePopup,itemType,itemHndl,itemBox);
InvalRect(itemBox); {Refresh the popup menu box}
END;
END;
END;
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
{--------------------------------|--------------------------------------------------------------------|---------------------------------------------------------|------------------------}
end.