IconEditorImplA:
CEDAR
PROGRAM
IMPORTS IconEditorDefs, IconRegistry, MBQueue, Menus, MessageWindow, PrincOpsUtils, Rope, ViewerOps, ViewerTools
EXPORTS IconEditorDefs = {
CreateMenu:
PUBLIC
PROC [handle: IconEditorDefs.IconHandle]
RETURNS [iconMenu: Menus.Menu] = {
queue: MBQueue.Queue ← handle.queue; --an automaticallly managed queue
iconMenu ← Menus.CreateMenu[lines: 3];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"BlackLabel", proc:BlackLabelProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"WhiteLabel", proc:WhiteLabelProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"DrawLine", proc:LineProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"InvertColor", proc:InvertProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"Black", proc:BlackProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"DarkGray", proc:DarkGrayProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"DeskTopGray", proc:DeskTopGrayProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"White", proc:WhiteProc, fork:TRUE, clientData:handle], 2];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"Register", proc:RegisterIconProc, fork:TRUE, clientData:handle], 1]; -- w.t.
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"UnSetLabel", proc:UnLabelIconProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"SetLabel", proc:LabelIconProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"Mirror", proc:MirrorProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"ShiftRt", proc:RightProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"ShiftLf", proc:LeftProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"ShiftDn", proc:DownProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"ShiftUp", proc:UpProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"UNDO", proc:IconEditorDefs.UndoProc, fork:TRUE, clientData:handle], 1];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"CreateFilledIcon", proc: FillIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"ShowLabel", proc:ShowLabelProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"CreateIcon", proc:CreateIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"DeleteIcon", proc:IconEditorDefs.DeleteIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"RotateDisplay", proc:RotateDisplayProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"Load", proc:LoadIconProc, fork:TRUE, clientData:handle], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"Save", proc:SaveProc, fork:TRUE, clientData:handle, guarded: TRUE, documentation:"Confirm write to Icon file"], 0];
Menus.InsertMenuEntry[iconMenu, MBQueue.CreateMenuEntry[q: queue, name:"Reset", proc:ResetProc, fork:TRUE, clientData:handle], 0];
};
LoadIconProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
IF handle.container.newVersion THEN
IF ~MessageWindow.Confirm["Confirm discard of current icon edits..."] THEN
RETURN;
handle.iconFileName ← ViewerTools.GetContents[handle.iconFileWindow];
IF Rope.Size[handle.iconFileName]=0
THEN {
MessageWindow.Append[message: "Enter file name prior to Load.", clearFirst: TRUE];
RETURN
};
[handle.numberReadIn, handle.iconFile] ← IconEditorDefs.LoadIcons[handle,
handle.iconFileName ! IconEditorDefs.CouldntLoadIcons => {MessageWindow.Append[
Rope.Cat["Icon file ", handle.iconFileName," could not be loaded"], TRUE];
GOTO BadFile
}];
IF handle.iconFile#
NIL
THEN {
handle.numberOfIcons ← handle.numberReadIn;
handle.startDisplay ← 0;
handle.currentIC ← FIRST[IconEditorDefs.IconFlavor];
handle.container.newVersion ← FALSE;
handle.drewLine ← FALSE;
handle.drewRectangle ← FALSE;
ViewerOps.PaintViewer[viewer: handle.container, hint: all];
};
EXITS BadFile => RETURN
};
RotateDisplayProc:
PUBLIC Menus.MenuProc = {
MenuProc: TYPE = PROC [parent: REF ANY, clientData: REF ANY ← NIL,
mouseButton: MouseButton ← red, shift, control: BOOL ← FALSE];
rotates the display incrementally by moving up the starting position in the icons array
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef;
increment: INTEGER ← IF mouseButton=red THEN 1 ELSE 4;
IF shift THEN increment ← -increment;
handle.startDisplay ← (handle.startDisplay + increment) MOD handle.numberOfIcons;
IF handle.startDisplay < 0 THEN handle.startDisplay ← handle.startDisplay+handle.numberOfIcons;
handle.currentIC ← LOOPHOLE[handle.startDisplay];
iconInfo ← NEW[IconEditorDefs.IconInfoRec ← [handle, screen, handle.currentIC]];
ViewerOps.SetNewVersion[handle.container];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo, clearClient: FALSE];
};
BlackProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetBlack[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
InvertProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.Invert[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
MirrorProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.MirrorIcon[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
DeskTopGrayProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetDeskTopGray[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
DarkGrayProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetDarkGray[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
WhiteProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, rect]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetWhite[handle, handle.currentIC, handle.currentRectangle];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
RightProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveRight[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
LeftProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveLeft[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
UpProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveUp[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
DownProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IconEditorDefs.SaveBitMap[handle];
IconEditorDefs.MoveDown[handle, handle.currentIC, (mouseButton = red)];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
LineProc:
PUBLIC Menus.MenuProc = {
for DrawLine and mark1 and mark2.
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, icon, handle.currentIC]];
IF IconEditorDefs.PointsMarked[handle, line]
THEN {
IconEditorDefs.SaveBitMap[handle];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.DrawLine[handle, handle.currentLine, handle.currentIC];
handle.drewLine ← FALSE;
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
};
CreateIconProc:
PUBLIC Menus.MenuProc = {
This allows a new icon to be created. It creates a completely "blank" icon and causes this to become the new current icon.
handle: IconEditorDefs.IconHandle = NARROW[clientData];
newLastFlavor: IconEditorDefs.IconFlavor = IconEditorDefs.GetNewFlavor[handle];
insertAt: IconEditorDefs.IconFlavor = SELECT mouseButton FROM red, yellow => newLastFlavor, blue => handle.currentIC, ENDCASE => ERROR;
iaQuaNat: IconEditorDefs.Nat = LOOPHOLE[insertAt];
iconInfo: IconEditorDefs.IconInfoRef = IF insertAt = newLastFlavor THEN NEW[IconEditorDefs.IconInfoRec ← [handle, newIcon, insertAt]] ELSE NIL;
handle.currentIC ← insertAt;
FOR f: IconEditorDefs.IconFlavor
DECREASING
IN [insertAt .. newLastFlavor)
DO
handle.icons[LOOPHOLE[f.SUCC]] ← handle.icons[LOOPHOLE[f]];
ENDLOOP;
handle.currentIconRep ← handle.icons[LOOPHOLE[insertAt]] ← NEW[IconEditorDefs.IconFileFormat];
handle.numberOfIcons ← handle.numberOfIcons + 1;
ViewerOps.SetNewVersion[handle.container];
make sure the new icon is blank
IconEditorDefs.ClearIcon[handle, handle.currentIC];
before we paint the screen, make sure new icon is visible
handle.startDisplay ← MAX[iaQuaNat - IconEditorDefs.maxIconsOnDisplay + 1, MIN[iaQuaNat, handle.startDisplay]];
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
FillIconProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
IconEditorDefs.FillIcon[handle];
};
ShowLabelProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, rect, handle.currentIC]];
ViewerOps.SetNewVersion[handle.container];
IF ~handle.currentIconRep.label
THEN {
MessageWindow.Append[message: "Current icon has no label.", clearFirst: TRUE];
MessageWindow.Blink[];
RETURN
}
ELSE {
handle.labelRect.x ← handle.currentIconRep.lx;
handle.labelRect.y ←
IconEditorDefs.iconH-1-(handle.currentIconRep.ly+handle.currentIconRep.lh);
handle.labelRect.w ← handle.currentIconRep.lw;
handle.labelRect.h ← handle.currentIconRep.lh
};
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo,
clearClient: FALSE];
};
WhiteLabelProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.WhiteLabel[handle, handle.currentIC];
};
BlackLabelProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.BlackLabel[handle, handle.currentIC];
};
LabelIconProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
iconInfo: IconEditorDefs.IconInfoRef ← NEW[IconEditorDefs.IconInfoRec ← [handle, rect, handle.currentIC]];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.SetLabel[handle, handle.currentIC, handle.currentRectangle];
now erase the sketch
ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo, clearClient: FALSE];
};
UnLabelIconProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
ViewerOps.SetNewVersion[handle.container];
IconEditorDefs.UnSetLabel[handle, handle.currentIC];
};
RegisterIconProc: Menus.MenuProc =
TRUSTED {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
IF
NOT PrincOpsUtils.IsBound[
LOOPHOLE[IconRegistry.RegisterIcon]]
THEN {
MessageWindow.Append["IconRegistryImpl.bcd has not been run", TRUE];
MessageWindow.Blink[]
}
ELSE IconRegistry.RegisterIcon[iconName: ViewerTools.GetContents[handle.iconNameWindow], fileName: ViewerTools.GetContents[handle.iconFileWindow], index: LOOPHOLE[handle.currentIC, IconEditorDefs.Nat], saveInCatalogue: TRUE];
};
SaveProc:
PUBLIC Menus.MenuProc = {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
handle.iconFileName ← ViewerTools.GetContents[handle.iconFileWindow];
IF Rope.Size[handle.iconFileName]=0
THEN {
MessageWindow.Append[message: "Enter file name prior to Save.", clearFirst: TRUE];
RETURN
};
handle.iconFile ← IconEditorDefs.SaveIcons[handle, handle.iconFileName, handle.numberOfIcons
! IconEditorDefs.CouldntSaveIcons => {MessageWindow.Append[
Rope.Cat["Icon file ", handle.iconFileName, " could not be saved"], TRUE];
GOTO BadFile
}];
IF handle.iconFile#NIL THEN MessageWindow.Append[message: Rope.Cat["Icons saved in ", handle.iconFileName], clearFirst: TRUE];
handle.container.newVersion ← FALSE;
ViewerOps.PaintViewer[handle.container, caption];
EXITS BadFile => RETURN
};
ResetProc:
PUBLIC Menus.MenuProc =
TRUSTED {
handle: IconEditorDefs.IconHandle ← NARROW[clientData];
IF ~handle.container.newVersion OR ~MessageWindow.Confirm["Confirm discard of new icon edits..."] THEN RETURN;
[handle.numberReadIn, handle.iconFile] ← IconEditorDefs.LoadIcons[handle,
handle.iconFileName ! IconEditorDefs.CouldntLoadIcons => {MessageWindow.Append[
Rope.Cat["Icon file ", handle.iconFileName," could not be reset"], TRUE];
GOTO BadFile
}];
IF handle.iconFile#
NIL
THEN {
handle.numberOfIcons ← handle.numberReadIn;
handle.startDisplay ← 0;
handle.currentIC ← FIRST[IconEditorDefs.IconFlavor];
handle.container.newVersion ← FALSE;
handle.drewLine ← FALSE;
handle.drewRectangle ← FALSE;
ViewerOps.PaintViewer[viewer: handle.container, hint: all];
};
};
}.