<> <> <> <> <> <> DIRECTORY Containers USING [Container], FileIO USING [Open], IconEditorDefs, IconRegistry USING [RegisterIcon], IO, Menus USING [ClickProc, CreateMenu, CreateEntry, InsertMenuEntry, Menu, MenuProc], MessageWindow USING [Append, Blink, Confirm], Rope USING [Cat, ROPE, Size], Runtime USING [IsBound], ViewerClasses USING [Viewer, ViewerClass, ViewerClassRec], ViewerOps USING [PaintViewer, SetNewVersion], ViewerTools USING [GetContents]; IconEditorImplA: CEDAR PROGRAM IMPORTS IconEditorDefs, IconRegistry, IO, Menus, MessageWindow, Rope, Runtime, ViewerOps, ViewerTools, FileIO EXPORTS IconEditorDefs = { OPEN IconEditorDefs; CreateMenu: PUBLIC PROC [handle: IconHandle] RETURNS [iconMenu: Menus.Menu] = { iconMenu _ Menus.CreateMenu[lines: 3]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"BlackLabel", proc:BlackLabelProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"WhiteLabel", proc:WhiteLabelProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DrawLine", proc:LineProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"InvertColor", proc:InvertProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Black", proc:BlackProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DarkGray", proc:DarkGrayProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DeskTopGray", proc:DeskTopGrayProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"White", proc:WhiteProc, fork:TRUE, clientData:handle], 2]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Register", proc:RegisterIconProc, fork:TRUE, clientData:handle], 1]; -- w.t. Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"UnSetLabel", proc:UnLabelIconProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"SetLabel", proc:LabelIconProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Mirror", proc:MirrorProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftRt", proc:RightProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftLf", proc:LeftProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftDn", proc:DownProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShiftUp", proc:UpProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"UNDO", proc:UndoProc, fork:TRUE, clientData:handle], 1]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"ShowLabel", proc:ShowLabelProc, fork:TRUE, clientData:handle], 0]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"CreateIcon", proc:CreateIconProc, fork:TRUE, clientData:handle], 0]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"DeleteIcon", proc:DeleteIconProc, fork:TRUE, clientData:handle], 0]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"RotateDisplay", proc:RotateDisplayProc, fork:TRUE, clientData:handle], 0]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Load", proc:LoadIconProc, fork:TRUE, clientData:handle], 0]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Save", proc:SaveProc, fork:TRUE, clientData:handle, guarded: TRUE, documentation:"Confirm write to Icon file"], 0]; Menus.InsertMenuEntry[iconMenu, Menus.CreateEntry[name:"Reset", proc:ResetProc, fork:TRUE, clientData:handle], 0]; }; LoadIconProc: PUBLIC Menus.MenuProc = { handle: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[iconInfoRec _ [handle, screen, handle.currentIC]]; 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}]; handle.numberOfIcons _ handle.numberReadIn; handle.startDisplay _ 0; handle.container.newVersion _ FALSE; handle.drewLine _ FALSE; handle.drewRectangle _ FALSE; ViewerOps.PaintViewer[viewer: handle.container, hint: client, whatChanged: iconInfo]; ViewerOps.PaintViewer[viewer: handle.container, hint: all]; EXITS BadFile => RETURN }; RotateDisplayProc: PUBLIC Menus.MenuProc = { <> handle: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef; IF (mouseButton = red) THEN handle.startDisplay _ (handle.startDisplay + 1) MOD handle.numberOfIcons ELSE handle.startDisplay _ (handle.startDisplay + 4) MOD handle.numberOfIcons; handle.currentIC _ LOOPHOLE[handle.startDisplay]; iconInfo _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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 = { OPEN IconEditorDefs; handle: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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 = { OPEN IconEditorDefs; -- for DrawLine and mark1 and mark2. handle: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[iconInfoRec _ [handle, icon, handle.currentIC]]; IF IconEditorDefs.PointsMarked[handle, line] THEN { IconEditorDefs.SaveBitMap[handle]; ViewerOps.SetNewVersion[handle.container]; 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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef; handle.currentIC _ IconEditorDefs.GetNewFlavor[handle]; handle.currentIconRep _ handle.icons[LOOPHOLE[handle.currentIC]] _ NEW[IconEditorDefs.iconFileFormat]; iconInfo _ NEW[iconInfoRec _ [handle, newIcon, handle.currentIC]]; handle.numberOfIcons _ handle.numberOfIcons + 1; ViewerOps.SetNewVersion[handle.container]; <> IconEditorDefs.ClearIcon[handle, handle.currentIC]; <> IF LOOPHOLE[handle.currentIC, CARDINAL] >= maxIconsOnDisplay THEN handle.startDisplay _ (handle.startDisplay + 1) MOD handle.numberOfIcons; ViewerOps.PaintViewer[viewer: handle.viewer, hint: client, whatChanged: iconInfo, clearClient: FALSE]; }; ShowLabelProc: PUBLIC Menus.MenuProc = { handle: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; ViewerOps.SetNewVersion[handle.container]; IconEditorDefs.WhiteLabel[handle, handle.currentIC]; }; BlackLabelProc: PUBLIC Menus.MenuProc = { handle: IconHandle _ NARROW[clientData]; ViewerOps.SetNewVersion[handle.container]; IconEditorDefs.BlackLabel[handle, handle.currentIC]; }; LabelIconProc: PUBLIC Menus.MenuProc = { handle: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[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: IconHandle _ NARROW[clientData]; ViewerOps.SetNewVersion[handle.container]; IconEditorDefs.UnSetLabel[handle, handle.currentIC]; }; RegisterIconProc: Menus.MenuProc = TRUSTED{ handle: IconHandle _ NARROW[clientData]; IF NOT Runtime.IsBound[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, CARDINAL], saveInCatalogue: TRUE]; }; SaveProc: PUBLIC Menus.MenuProc = { handle: 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}]; 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: IconHandle _ NARROW[clientData]; iconInfo: iconInfoRef _ NEW[iconInfoRec _ [handle, screen, handle.currentIC]]; newFlavor: IconEditorDefs.iconFlavor; IF ~handle.container.newVersion THEN RETURN ELSE IF ~MessageWindow.Confirm["Confirm discard of new icon edits..."] THEN RETURN; <> handle.iconFile _ FileIO.Open[fileName: handle.iconFileName]; handle.nextFlavor _ FIRST[IconEditorDefs.iconFlavor]; -- reset nextFlavor FOR n: CARDINAL IN [0 .. handle.numberReadIn) DO newFlavor _ IconEditorDefs.GetNewFlavor[handle]; []_ IO.UnsafeGetBlock[handle.iconFile, [LOOPHOLE[handle.icons[LOOPHOLE[newFlavor]]], 0, SIZE[IconEditorDefs.iconFileFormat]*2]]; ENDLOOP; handle.numberOfIcons _ handle.numberReadIn; handle.startDisplay _ 0; handle.container.newVersion _ FALSE; ViewerOps.PaintViewer[viewer: handle.container, hint: all, whatChanged: iconInfo]; }; }. <<>> <> <> <> <> <> <> < <-- Destroy>> <<>> <> <> <> <<>>