<> <> <> DIRECTORY Containers USING [Container], IconEditorDefs, IconRegistry USING [RegisterIcon], MBQueue USING [Queue, CreateMenuEntry], Menus USING [CreateMenu, InsertMenuEntry, Menu, MenuProc], MessageWindow USING [Append, Blink, Confirm], PrincOpsUtils USING [IsBound], Rope USING [Cat, ROPE, Size], ViewerClasses USING [Viewer], ViewerOps USING [PaintViewer, SetNewVersion], ViewerTools USING [GetContents]; 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 = { <> <> 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 = { <> 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 = { <> 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]; <> IconEditorDefs.ClearIcon[handle, handle.currentIC]; <> 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]; <> 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]; }; EXITS BadFile => RETURN; }; }. <<>> <> <> <> <> <> <> -- Removed redundant menu items: Close Grow --> <-- Destroy <<>> <> <> <> <>