4 ** Copyright (C) 1994,95,96 by Bernardo Innocenti
6 ** Handle AppIcons & AppWindows
9 #include <exec/memory.h>
10 #include <workbench/workbench.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/intuition.h>
16 #include <proto/icon.h>
18 #include "XModulePriv.h"
22 XDEF ULONG AppSig = 0;
23 XDEF LONG IconX = NO_ICON_POSITION;
24 XDEF LONG IconY = NO_ICON_POSITION;
25 XDEF UBYTE IconName[16];
26 XDEF BOOL Iconified = FALSE;
29 static struct MsgPort *AppPort = NULL;
30 static struct AppIcon *MyAppIcon = NULL;
31 static struct DiskObject *AppDObj = NULL;
35 GLOBALCALL void HandleAppMessage (void)
37 /* App Window event handler. Get Workbench message and call server */
39 struct AppMessage *am;
41 while (am = (struct AppMessage *) GetMsg (AppPort))
45 case AMTYPE_APPWINDOW:
46 (((struct WinUserData *) am->am_UserData)->DropIcon) (am);
50 if (am->am_NumArgs == 0)
52 else if (am->am_UserData)
53 ((void (*) (struct AppMessage *am))(am->am_UserData)) (am);
61 ReplyMsg ((struct Message *) am);
67 GLOBALCALL void AddAppWin (struct WinUserData *wud)
69 wud->AppWin = AddAppWindowA (0, (ULONG)wud, wud->Win, AppPort, NULL);
74 GLOBALCALL void RemAppWin (struct WinUserData *wud)
79 RemoveAppWindow (wud->AppWin);
82 /* Reply all pending messages for this window */
86 msg = (struct Message *) AppPort->mp_MsgList.lh_Head;
88 while (succ = msg->mn_Node.ln_Succ)
90 if ((struct WinUserData *)(((struct AppMessage *)msg)->am_UserData) == wud)
92 Remove ((struct Node *)msg);
95 msg = (struct Message *) succ;
103 GLOBALCALL LONG CreateAppIcon (void (*handler) (struct AppMessage *am))
105 if (!AppPort) return RETURN_FAIL;
107 if (MyAppIcon) return RETURN_OK;
110 if ( !(AppDObj = GetProgramIcon() ))
111 AppDObj = GetDefDiskObject (WBTOOL);
113 if (!AppDObj) return RETURN_FAIL;
115 /* Initialize AppIcon */
116 AppDObj->do_CurrentX = IconX;
117 AppDObj->do_CurrentY = IconY;
119 if (MyAppIcon = AddAppIconA (0, (ULONG)handler, IconName, AppPort, NULL, AppDObj, NULL))
122 FreeDiskObject (AppDObj); AppDObj = NULL;
128 GLOBALCALL void DeleteAppIcon (void)
132 RemoveAppIcon (MyAppIcon); MyAppIcon = NULL;
133 FreeDiskObject (AppDObj); AppDObj = NULL;
139 GLOBALCALL void Iconify (void)
141 if (!CreateAppIcon (ToolBoxDropIcon))
150 GLOBALCALL void DeIconify (void)
155 if (!GuiSwitches.ShowAppIcon) DeleteAppIcon();
160 GLOBALCALL LONG SetupApp (void)
162 if (!(AppPort = CreateMsgPort()))
163 return ERROR_NO_FREE_STORE;
164 AppSig = 1 << AppPort->mp_SigBit;
167 if (GuiSwitches.ShowAppIcon)
168 CreateAppIcon (ToolBoxDropIcon);
175 GLOBALCALL void CleanupApp (void)
181 KillMsgPort (AppPort); AppPort = NULL;
182 Signals &= ~AppSig; AppSig = 0;