6 #include <exec/types.h>
7 #include <graphics/rastport.h>
8 #include <utility/hooks.h>
9 #include <intuition/gadgetclass.h>
10 #include <workbench/workbench.h>
11 #include <workbench/startup.h>
12 #include <workbench/icon.h>
13 #include <libraries/gadtools.h>
14 #include <libraries/iffparse.h>
15 #include <datatypes/pictureclass.h>
16 #include <dos/dostags.h>
17 #include <guigfx/guigfx.h>
21 #include <proto/dos.h>
22 #include <proto/exec.h>
23 #include <proto/layers.h>
24 #include <proto/intuition.h>
25 #include <proto/graphics.h>
26 #include <proto/utility.h>
27 #include <proto/icon.h>
28 #include <proto/iconobject.h>
29 #include <proto/guigfx.h>
30 #include <proto/datatypes.h>
31 #include <proto/gadtools.h>
34 #include <proto/scalos.h>
36 #include <clib/alib_protos.h>
39 #include <datatypes/iconobject.h>
40 #include <scalos/palette.h>
41 #include <scalos/pattern.h>
42 #include <scalos/scalos.h>
48 #include "scalos_structures.h"
49 #include "functions.h"
50 #include "Variables.h"
53 //----------------------------------------------------------------------------
56 // 20011203 jl initial history
57 //----------------------------------------------------------------------------
59 // local data structures
63 struct Interface
**pe_Interface
;
69 //----------------------------------------------------------------------------
73 static void SetPatches(const struct PatchEntry
*PatchList
);
74 static BOOL
RemovePatches(const struct PatchEntry
*PatchList
);
76 //----------------------------------------------------------------------------
80 //----------------------------------------------------------------------------
83 static LIBFUNC_P7VA_PROTO(struct AppIcon
*, sca_AddAppIcon
,
86 A0
, CONST_STRPTR
, IconText
,
87 A1
, struct MsgPort
*, iconPort
,
89 A3
, struct DiskObject
*, DiskObj
,
90 A6
, struct Library
*, wbBase
);
91 static LIBFUNC_P5VA_PROTO(struct AppWindow
*, sca_AddAppWindow
,
94 A0
, struct Window
*, window
,
95 A1
, struct MsgPort
*, iconPort
,
96 A6
, struct Library
*, wbBase
);
97 static LIBFUNC_P5VA_PROTO(struct AppMenuItem
*, sca_AddAppMenuItem
,
100 A0
, CONST_STRPTR
, text
,
101 A1
, struct MsgPort
*, iconPort
,
102 A6
, struct Library
*, wbBase
);
103 static LIBFUNC_P2VA_PROTO(struct Screen
*, sca_OpenScreen
,
104 A0
, struct NewScreen
*, newScr
,
105 A6
, struct IntuitionBase
*, iBase
);
107 static APTR OldAddAppIcon
;
108 static APTR OldAddAppWindow
;
109 static APTR OldAppAppMenuItem
;
110 static APTR OldOpenScreen
;
112 //----------------------------------------------------------------------------
114 #define OffsetCloseWorkBench offsetof(struct IntuitionIFace, CloseWorkBench)
115 #define OffsetOpenWorkBench offsetof(struct IntuitionIFace, OpenWorkBench)
116 #define OffsetOpenScreenTagList offsetof(struct IntuitionIFace, OpenScreenTagList)
117 #define OffsetOpenScreen offsetof(struct IntuitionIFace, OpenScreen)
119 #define OffsetUpdateWorkbench offsetof(struct WorkbenchIFace, UpdateWorkbench)
120 //#define OffsetwbPrivate2 offsetof(struct WorkbenchIFace, Private1)
121 #define OffsetAddAppWindowA offsetof(struct WorkbenchIFace, AddAppWindowA)
122 #define OffsetAddAppWindow offsetof(struct WorkbenchIFace, AddAppWindow)
123 #define OffsetRemoveAppWindow offsetof(struct WorkbenchIFace, RemoveAppWindow)
124 #define OffsetAddAppIconA offsetof(struct WorkbenchIFace, AddAppIconA)
125 #define OffsetAddAppIcon offsetof(struct WorkbenchIFace, AddAppIcon)
126 #define OffsetRemoveAppIcon offsetof(struct WorkbenchIFace, RemoveAppIcon)
127 #define OffsetAddAppMenuItemA offsetof(struct WorkbenchIFace, AddAppMenuItemA)
128 #define OffsetAddAppMenuItem offsetof(struct WorkbenchIFace, AddAppMenuItem)
129 #define OffsetRemoveAppMenuItem offsetof(struct WorkbenchIFace, RemoveAppMenuItem)
130 #define OffsetWBInfo offsetof(struct WorkbenchIFace, WBInfo)
131 //#define OffsetSetBackFill offsetof(struct WorkbenchIFace, ...)
133 #define OffsetPutDiskObject offsetof(struct IconIFace, PutDiskObject)
134 #define OffsetDeleteDiskObject offsetof(struct IconIFace, DeleteDiskObject)
135 #define OffsetPutIconTagList offsetof(struct IconIFace, PutIconTagList)
137 #define OffsetRename offsetof(struct DOSIFace, Rename)
138 #define OffsetDeleteFile offsetof(struct DOSIFace, DeleteFile)
139 #define OffsetOpen offsetof(struct DOSIFace, Open)
140 #define OffsetClose offsetof(struct DOSIFace, Close)
141 #define OffsetCreateDir offsetof(struct DOSIFace, CreateDir)
143 //----------------------------------------------------------------------------
144 static const struct PatchEntry EmulationPatches
[] =
146 { (struct Interface
**)(APTR
) &IIntuition
, OffsetCloseWorkBench
, (APTR
)sca_CloseWorkBench
, (APTR
) &OldCloseWB
},
147 { (struct Interface
**)(APTR
) &IIntuition
, OffsetOpenWorkBench
, (APTR
)sca_OpenWorkBench
, (APTR
) &OldOpenWB
},
148 { (struct Interface
**)(APTR
) &IIntuition
, OffsetOpenScreenTagList
, (APTR
)sca_OpenScreenTagList
, (APTR
) &OldOpenScreenTagList
},
149 { (struct Interface
**)(APTR
) &IIntuition
, OffsetOpenScreen
, (APTR
)sca_OpenScreen
, (APTR
) &OldOpenScreen
},
150 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetAddAppIconA
, (APTR
)sca_AddAppIconA
, (APTR
) &OldAddAppIconA
},
151 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetAddAppIcon
, (APTR
)sca_AddAppIcon
, (APTR
) &OldAddAppIcon
},
152 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetRemoveAppIcon
, (APTR
)sca_RemoveAppIcon
, (APTR
) &OldRemoveAppIcon
},
153 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetAddAppWindowA
, (APTR
)sca_AddAppWindowA
, (APTR
) &OldAddAppWindowA
},
154 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetAddAppWindow
, (APTR
)sca_AddAppWindow
, (APTR
) &OldAddAppWindow
},
155 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetRemoveAppWindow
, (APTR
)sca_RemoveAppWindow
, (APTR
) &OldRemoveAppWindow
},
156 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetAddAppMenuItemA
, (APTR
)sca_AddAppMenuItemA
, (APTR
) &OldAppAppMenuItemA
},
157 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetAddAppMenuItem
, (APTR
)sca_AddAppMenuItem
, (APTR
) &OldAppAppMenuItem
},
158 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetRemoveAppMenuItem
, (APTR
)sca_RemoveAppMenuItem
, (APTR
) &OldRemoveAppMenuItem
},
159 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetWBInfo
, (APTR
)sca_WBInfo
, (APTR
) &OldWBInfo
},
161 // { (struct Interface **)(APTR) &IWorkbench, OffsetwbPrivate2, (APTR)sca_GetLocString, (APTR) &OldwbPrivate2 },
162 { NULL
, 0, (APTR
)NULL
, NULL
},
164 static const struct PatchEntry StandardPatches
[] =
166 { (struct Interface
**)(APTR
) &IIcon
, OffsetPutDiskObject
, (APTR
)sca_PutDiskObject
, (APTR
) &OldPutDiskObject
},
167 { (struct Interface
**)(APTR
) &IIcon
, OffsetDeleteDiskObject
, (APTR
)sca_DeleteDiskObject
, (APTR
) &OldDeleteDiskObject
},
168 { (struct Interface
**)(APTR
) &IIcon
, OffsetPutIconTagList
, (APTR
)sca_PutIconTagList
, (APTR
) &OldPutIconTagList
},
170 { (struct Interface
**)(APTR
) &IDOS
, OffsetDeleteFile
, (APTR
)sca_DeleteFile
, (APTR
) &OldDeleteFile
},
171 { (struct Interface
**)(APTR
) &IDOS
, OffsetRename
, (APTR
)sca_Rename
, (APTR
) &OldRename
},
172 { (struct Interface
**)(APTR
) &IDOS
, OffsetOpen
, (APTR
)sca_Open
, (APTR
) &OldOpen
},
173 { (struct Interface
**)(APTR
) &IDOS
, OffsetClose
, (APTR
)sca_Close
, (APTR
) &OldClose
},
174 { (struct Interface
**)(APTR
) &IDOS
, OffsetCreateDir
, (APTR
)sca_CreateDir
, (APTR
) &OldCreateDir
},
175 { NULL
, 0, (APTR
)NULL
, NULL
},
177 static const struct PatchEntry HardEmulationPatches
[] =
179 { (struct Interface
**)(APTR
) &IWorkbench
, OffsetUpdateWorkbench
, (APTR
)sca_UpdateWorkbench
, (APTR
) &OldUpdateWorkbench
},
180 // { (struct Interface **)(APTR) &IWorkbench, OffsetSetBackFill, (APTR)sca_SetBackFill, (APTR) &OldSetBackFill },
181 { NULL
, 0, (APTR
)NULL
, NULL
},
184 //----------------------------------------------------------------------------
186 void SetAllPatches(struct MainTask
*mt
)
190 SetPatches(StandardPatches
);
194 if (CurrentPrefs
.pref_HardEmulation
)
195 SetPatches(HardEmulationPatches
);
197 SetPatches(EmulationPatches
);
202 ULONG
RemoveAllPatches(struct MainTask
*mt
)
204 if (!RemovePatches(StandardPatches
))
209 if (!RemovePatches(EmulationPatches
))
211 SetPatches(StandardPatches
);
215 if (CurrentPrefs
.pref_HardEmulation
)
217 if (!RemovePatches(HardEmulationPatches
))
219 SetPatches(EmulationPatches
);
220 SetPatches(StandardPatches
);
231 static void SetPatches(const struct PatchEntry
*PatchList
)
235 d1(kprintf("%s/%s/%ld: PatchList=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, PatchList
));
237 while (PatchList
->pe_Interface
)
239 if (NULL
== *PatchList
->pe_OldFunction
)
241 *PatchList
->pe_OldFunction
= SetMethod(*PatchList
->pe_Interface
,
242 PatchList
->pe_IFaceOffset
, PatchList
->pe_NewFunction
);
244 d1(KPrintF("%s/%s/%ld: Library=%08lx Offset=%ld NewFunc=%08lx OldFunc=%08lx\n", \
245 __FILE__
, __FUNC__
, __LINE__
, *PatchList
->pe_Interface
, \
246 PatchList
->pe_IFaceOffset
, PatchList
->pe_NewFunction
, \
247 *PatchList
->pe_OldFunction
));
258 static BOOL
RemovePatches(const struct PatchEntry
*PatchList
)
260 const struct PatchEntry
*pl
= PatchList
;
263 d1(KPrintF("%s/%s/%ld: PatchList=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, PatchList
));
267 while (pl
->pe_Interface
)
269 if (pl
->pe_OldFunction
)
271 APTR patchedFunction
;
273 patchedFunction
= SetMethod(*pl
->pe_Interface
,
274 pl
->pe_IFaceOffset
, *pl
->pe_OldFunction
);
275 *pl
->pe_OldFunction
= NULL
;
277 d1(KPrintF("%s/%s/%ld: Library=%08lx Offset=%ld NewFunc=%08lx patchedFunc=%08lx\n", \
278 __FILE__
, __FUNC__
, __LINE__
, *pl
->pe_Interface
, \
279 pl
->pe_IFaceOffset
, pl
->pe_NewFunction
, patchedFunction
));
280 #if !defined(__MORPHOS__)
281 if (patchedFunction
!= pl
->pe_NewFunction
)
283 *pl
->pe_OldFunction
= SetMethod(*pl
->pe_Interface
,
284 pl
->pe_IFaceOffset
, patchedFunction
);
288 #endif /* __MORPHOS__ */
297 d1(KPrintF("%s/%s/%ld: Success=%ld\n", __FILE__
, __FUNC__
, __LINE__
, Success
));
300 SetPatches(PatchList
);
305 static LIBFUNC_P7VA(struct AppIcon
*, sca_AddAppIcon
,
308 A0
, CONST_STRPTR
, IconText
,
309 A1
, struct MsgPort
*, iconPort
,
311 A3
, struct DiskObject
*, DiskObj
,
312 A6
, struct Library
*, wbBase
)
315 struct WorkbenchIFace
*IWorkbench
= (struct WorkbenchIFace
*)self
;
317 va_startlinear(args
, DiskObj
);
321 ret
= AddAppIconA(Id
, UserData
, IconText
, iconPort
, lock
, DiskObj
,
322 va_getlinearva(args
, const struct TagItem
*));
330 static LIBFUNC_P5VA(struct AppWindow
*, sca_AddAppWindow
,
333 A0
, struct Window
*, window
,
334 A1
, struct MsgPort
*, iconPort
,
335 A6
, struct Library
*, wbBase
)
337 struct AppWindow
*ret
;
338 struct WorkbenchIFace
*IWorkbench
= (struct WorkbenchIFace
*)self
;
340 va_startlinear(args
, iconPort
);
344 ret
= AddAppWindowA(Id
, UserData
, window
, iconPort
, va_getlinearva(args
, const struct TagItem
*));
352 static LIBFUNC_P5VA(struct AppMenuItem
*, sca_AddAppMenuItem
,
355 A0
, CONST_STRPTR
, text
,
356 A1
, struct MsgPort
*, iconPort
,
357 A6
, struct Library
*, wbBase
)
359 struct AppMenuItem
*ret
;
360 struct WorkbenchIFace
*IWorkbench
= (struct WorkbenchIFace
*)self
;
362 va_startlinear(args
, iconPort
);
366 ret
= AddAppMenuItemA(Id
, UserData
, text
, iconPort
, va_getlinearva(args
, const struct TagItem
*));
374 static LIBFUNC_P2VA(struct Screen
*, sca_OpenScreen
,
375 A0
, struct NewScreen
*, newScr
,
376 A6
, struct IntuitionBase
*, iBase
)
379 struct IntuitionIFace
*IIntuition
= (struct IntuitionIFace
*)self
;
381 va_startlinear(args
, newScr
);
385 ret
= OpenScreenTagList(newScr
, va_getlinearva(args
, const struct TagItem
*));