forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / scalos / Modules / Exchange.MUI / Exchange.c
bloba078c5d1c5f00989e89b7ca6aa1fa176d6d56314
1 // Exchange.c
2 // $Date$
3 // $Revision$
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <ctype.h>
9 #include <dos/dos.h>
10 #include <exec/types.h>
11 #include <exec/memory.h>
12 #include <exec/ports.h>
13 #include <exec/execbase.h>
14 #include <libraries/dos.h>
15 #include <libraries/dosextens.h>
16 #include <libraries/asl.h>
17 #include <libraries/mui.h>
18 #include <libraries/gadtools.h>
19 #include <libraries/iffparse.h> // MAKE_ID()
20 #include <libraries/commodities.h>
21 #include <mui/NListview_mcc.h>
22 #include <workbench/workbench.h>
23 #include <intuition/intuition.h>
24 #include <intuition/classusr.h>
26 #include <clib/alib_protos.h>
28 #include <proto/exec.h>
29 #include <proto/dos.h>
30 #include <proto/intuition.h>
31 #include <proto/utility.h>
32 #include <proto/asl.h>
33 #include <proto/muimaster.h>
34 #include <proto/locale.h>
35 #include <proto/commodities.h>
37 #include <DefIcons.h>
38 #include <defs.h>
39 #include <Year.h> // +jmc+
41 #include "Exchange.h"
42 #include "cx_private.h"
43 #include "debug.h"
45 #define Exchange_NUMBERS
46 #define Exchange_ARRAY
47 #define Exchange_CODE
48 #include STR(SCALOSLOCALE)
50 //----------------------------------------------------------------------------
52 #if !defined(__amigaos4__) && !defined(__AROS__)
53 #include <dos.h>
55 long _stack = 16384; // minimum stack size, used by SAS/C startup code
56 #endif
58 //----------------------------------------------------------------------------
60 // local data structures
62 #define KeyButtonHelp(name,key,HelpText)\
63 TextObject,\
64 ButtonFrame,\
65 MUIA_CycleChain, TRUE, \
66 MUIA_Font, MUIV_Font_Button,\
67 MUIA_Text_Contents, name,\
68 MUIA_Text_PreParse, "\33c",\
69 MUIA_Text_HiChar , key,\
70 MUIA_ControlChar , key,\
71 MUIA_InputMode , MUIV_InputMode_RelVerify,\
72 MUIA_Background , MUII_ButtonBack,\
73 MUIA_ShortHelp, HelpText,\
74 End
76 struct CxListEntry
78 STRPTR xle_Name;
79 STRPTR xle_Title;
80 STRPTR xle_Description;
81 struct Task *xle_Task;
82 APTR xle_Addr;
83 LONG xle_Pri;
84 UWORD xle_Flags;
85 char xle_PriString[10];
88 //----------------------------------------------------------------------------
90 // local functions
92 static void init(void);
93 static void fail(APTR APP_Main, CONST_STRPTR str);
94 static BOOL OpenLibraries(void);
95 static void CloseLibraries(void);
96 static SAVEDS(APTR) INTERRUPT OpenAboutMUIFunc(struct Hook *hook, Object *o, Msg msg);
97 static SAVEDS(void) INTERRUPT OpenAboutFunc(struct Hook *hook, Object *o, Msg msg);
98 static SAVEDS(APTR) INTERRUPT CxListConstructHookFunc(struct Hook *hook, APTR unused, struct NList_ConstructMessage *nlcm);
99 static SAVEDS(void) INTERRUPT CxListDestructHookFunc(struct Hook *hook, APTR unused, struct NList_DestructMessage *nldm);
100 static SAVEDS(ULONG) INTERRUPT CxListDisplayHookFunc(struct Hook *hook, APTR unused, struct NList_DisplayMessage *nldm);
101 static SAVEDS(LONG) INTERRUPT CxListCompareHookFunc(struct Hook *hook, Object *obj, struct NList_CompareMessage *ncm);
102 static SAVEDS(void) INTERRUPT RescanHookFunc(struct Hook *hook, Object *obj, Msg *msg);
103 static SAVEDS(void) INTERRUPT SelectCxHookFunc(struct Hook *hook, Object *obj, Msg *msg);
104 static SAVEDS(void) INTERRUPT CxCommandHookFunc(struct Hook *hook, Object *obj, LONG *cmd);
105 static SAVEDS(void) INTERRUPT BrokerHookFunc(struct Hook *hook, Object *obj, CxMsg *msg);
107 static STRPTR GetLocString(ULONG MsgId);
108 static void TranslateStringArray(STRPTR *stringArray);
109 #if 0
110 static void TranslateNewMenu(struct NewMenu *nm);
111 #endif
113 BOOL CheckMCCVersion(CONST_STRPTR name, ULONG minver, ULONG minrev);
115 //----------------------------------------------------------------------------
117 static struct Hook AboutHook = {{ NULL, NULL }, HOOKFUNC_DEF(OpenAboutFunc), NULL };
118 static struct Hook AboutMUIHook = {{ NULL, NULL }, HOOKFUNC_DEF(OpenAboutMUIFunc), NULL };
120 static struct Hook CxListConstructHook = {{ NULL, NULL }, HOOKFUNC_DEF(CxListConstructHookFunc), NULL };
121 static struct Hook CxListDestructHook = {{ NULL, NULL }, HOOKFUNC_DEF(CxListDestructHookFunc), NULL };
122 static struct Hook CxListDisplayHook = {{ NULL, NULL }, HOOKFUNC_DEF(CxListDisplayHookFunc), NULL };
123 static struct Hook CxListCompareHook = {{ NULL, NULL }, HOOKFUNC_DEF(CxListCompareHookFunc), NULL };
124 static struct Hook RescanHook = {{ NULL, NULL }, HOOKFUNC_DEF(RescanHookFunc), NULL };
125 static struct Hook SelectCxHook = {{ NULL, NULL }, HOOKFUNC_DEF(SelectCxHookFunc), NULL };
126 static struct Hook CxCommandHook = {{ NULL, NULL }, HOOKFUNC_DEF(CxCommandHookFunc), NULL };
127 static struct Hook BrokerHook = {{ NULL, NULL }, HOOKFUNC_DEF(BrokerHookFunc), NULL };
129 //----------------------------------------------------------------------------
131 static STRPTR CycleActiveEntries[] =
133 (STRPTR) MSGID_CYCLE_ACTIVE_ACTIVE,
134 (STRPTR) MSGID_CYCLE_ACTIVE_INACTIVE,
135 NULL
138 //----------------------------------------------------------------------------
140 // local data items
142 static struct List BrokerCopyList;
144 struct IntuitionBase *IntuitionBase = NULL;
145 struct Library *MUIMasterBase = NULL;
146 struct Library *CxBase = NULL;
147 T_LOCALEBASE LocaleBase = NULL;
149 #ifdef __amigaos4__
150 struct IntuitionIFace *IIntuition = NULL;
151 struct MUIMasterIFace *IMUIMaster = NULL;
152 struct CxIFace *ICx = NULL;
153 struct LocaleIFace *ILocale = NULL;
154 #endif
156 static struct Catalog *ExchangeCatalog;
158 static Object *APP_Main;
159 static Object *WIN_Main;
160 static Object *WIN_AboutMUI;
161 static Object *ButtonShow, *ButtonHide, *ButtonRemove;
162 static Object *CycleActive;
163 static Object *NListCxList;
164 static Object *FloattextDescription;
165 static Object *MenuAbout, *MenuAboutMUI, *MenuQuit;
167 //----------------------------------------------------------------------------
169 int main(int argc, char *argv[])
171 LONG win_opened = 0;
173 init();
175 if (!CheckMCCVersion(MUIC_NListview, 19, 66) )
177 d1(KPrintF(__FILE__ "/%s/%ld: CheckMCCVersion failed\n", __FUNC__, __LINE__));
178 return 10;
181 APP_Main = ApplicationObject,
182 MUIA_Application_Title, GetLocString(MSGID_TITLENAME),
183 MUIA_Application_Version, "$VER: Scalos Exchange.module V" VERS_MAJOR "." VERS_MINOR " (" __DATE__ ") " COMPILER_STRING,
184 MUIA_Application_Copyright, "© The Scalos Team, 2008" CURRENTYEAR,
185 MUIA_Application_Author, "The Scalos Team",
186 MUIA_Application_Description, "Scalos Exchange module",
187 MUIA_Application_Base, "SCALOS_EXCHANGE_MODULE",
188 MUIA_Application_BrokerHook, &BrokerHook,
190 SubWindow, WIN_Main = WindowObject,
191 MUIA_Window_Title, GetLocString(MSGID_TITLENAME),
192 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
193 MUIA_Window_AppWindow, TRUE,
195 WindowContents, VGroup,
196 Child, NListviewObject,
197 MUIA_Weight, 200,
198 MUIA_CycleChain, TRUE,
199 MUIA_NListview_NList, NListCxList = NListObject,
200 MUIA_NList_Title, TRUE,
201 MUIA_NList_TitleSeparator, TRUE,
202 MUIA_NList_TitleMark, MUIV_NList_TitleMark_Down | 0,
203 MUIA_NList_SortType, 0,
204 MUIA_NList_Format, "BAR,BAR,BAR,BAR",
205 MUIA_NList_DisplayHook2, &CxListDisplayHook,
206 MUIA_NList_ConstructHook2, &CxListConstructHook,
207 MUIA_NList_DestructHook2, &CxListDestructHook,
208 MUIA_NList_CompareHook2, &CxListCompareHook,
209 End, //NListObject
210 End, //NListviewObject
212 Child, VGroup,
213 Child, FloattextDescription = FloattextObject,
214 TextFrame,
215 MUIA_VertWeight, 0,
216 End, //FloattextObject
218 Child, ColGroup(2),
219 Child, ButtonShow = KeyButtonHelp(GetLocString(MSGID_BUTTON_SHOW),
220 *GetLocString(MSGID_BUTTON_SHOW_KEY),
221 GetLocString(MSGID_BUTTON_SHOW_SHORTHELP)),
222 Child, ButtonHide = KeyButtonHelp(GetLocString(MSGID_BUTTON_HIDE),
223 *GetLocString(MSGID_BUTTON_HIDE_KEY),
224 GetLocString(MSGID_BUTTON_HIDE_SHORTHELP)),
226 Child, CycleActive = CycleObject,
227 MUIA_CycleChain, TRUE,
228 MUIA_Cycle_Entries, CycleActiveEntries,
229 End, //CycleObject
231 Child, ButtonRemove = KeyButtonHelp(GetLocString(MSGID_BUTTON_REMOVE),
232 *GetLocString(MSGID_BUTTON_REMOVE_KEY),
233 GetLocString(MSGID_BUTTON_REMOVE_SHORTHELP)),
234 End, //ColGroup
235 End, //VGroup
236 End, //VGroup
237 End, //WindowObject
239 MUIA_Application_Menustrip, MenustripObject,
240 Child, MenuObjectT(GetLocString(MSGID_MENU_PROJECT)),
242 Child, MenuAbout = MenuitemObject,
243 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_ABOUT),
244 End,
245 Child, MenuAboutMUI = MenuitemObject,
246 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_ABOUTMUI),
247 End,
248 Child, MenuitemObject,
249 MUIA_Menuitem_Title, -1,
250 End,
251 Child, MenuQuit = MenuitemObject,
252 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_QUIT),
253 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_QUIT_SHORT),
254 End,
256 End, //MenuObjectT
258 End, //MenuStripObject
260 End; //ApplicationObject
262 if (NULL == APP_Main)
264 fail(APP_Main, "Failed to create Application.");
267 DoMethod(APP_Main, MUIM_Application_Load, MUIV_Application_Load_ENV);
269 d1(KPrintF("%s/%s/%ld: before MUIM_CallHook APP_Main=%08lx\n", __FILE__, __FUNC__, __LINE__, APP_Main));
271 DoMethod(APP_Main, MUIM_CallHook, &RescanHook, 0);
272 d1(KPrintF("%s/%s/%ld: after MUIM_CallHook APP_Main=%08lx\n", __FILE__, __FUNC__, __LINE__, APP_Main));
274 //--------------------------------------------------------------------------//
276 DoMethod(WIN_Main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
277 WIN_Main, 3, MUIM_Set, MUIA_Window_Open, FALSE);
278 DoMethod(WIN_Main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
279 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
281 // Call hook whenever an entry is selected
282 DoMethod(NListCxList, MUIM_Notify, MUIA_NList_SelectChange, MUIV_EveryTime,
283 APP_Main, 2, MUIM_CallHook, &SelectCxHook);
285 // Show Cx Application Window whenever "Show" button is pressed
286 DoMethod(ButtonShow, MUIM_Notify, MUIA_Pressed, FALSE,
287 APP_Main, 3, MUIM_CallHook, &CxCommandHook, CXCMD_APPEAR);
289 // Show Cx Application Window whenever list entry is double-clicked
290 DoMethod(NListCxList, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
291 APP_Main, 3, MUIM_CallHook, &CxCommandHook, CXCMD_APPEAR);
293 // Hide Cx Application Window whenever "Hide" button is pressed
294 DoMethod(ButtonHide, MUIM_Notify, MUIA_Pressed, FALSE,
295 APP_Main, 3, MUIM_CallHook, &CxCommandHook, CXCMD_DISAPPEAR);
297 // Activate Cx Application when cycle "active" is selected
298 DoMethod(CycleActive, MUIM_Notify, MUIA_Cycle_Active, 0,
299 APP_Main, 3, MUIM_CallHook, &CxCommandHook, CXCMD_ENABLE);
301 // Deactivate Cx Application when cycle "inactive" is selected
302 DoMethod(CycleActive, MUIM_Notify, MUIA_Cycle_Active, 1,
303 APP_Main, 3, MUIM_CallHook, &CxCommandHook, CXCMD_DISABLE);
305 // Remove Cx Application whenever "Remove" button is pressed
306 DoMethod(ButtonRemove, MUIM_Notify, MUIA_Pressed, FALSE,
307 APP_Main, 3, MUIM_CallHook, &CxCommandHook, CXCMD_KILL);
309 // setup sorting hooks for Cx list
310 DoMethod(NListCxList, MUIM_Notify, MUIA_NList_TitleClick, MUIV_EveryTime,
311 NListCxList, 4, MUIM_NList_Sort3, MUIV_TriggerValue, MUIV_NList_SortTypeAdd_2Values, MUIV_NList_Sort3_SortType_Both);
312 DoMethod(NListCxList, MUIM_Notify, MUIA_NList_TitleClick2, MUIV_EveryTime,
313 NListCxList, 4, MUIM_NList_Sort3, MUIV_TriggerValue, MUIV_NList_SortTypeAdd_2Values, MUIV_NList_Sort3_SortType_2);
314 DoMethod(NListCxList, MUIM_Notify, MUIA_NList_SortType, MUIV_EveryTime,
315 NListCxList, 3, MUIM_Set, MUIA_NList_TitleMark, MUIV_TriggerValue);
316 DoMethod(NListCxList, MUIM_Notify, MUIA_NList_SortType2, MUIV_EveryTime,
317 NListCxList, 3, MUIM_Set, MUIA_NList_TitleMark2, MUIV_TriggerValue);
319 DoMethod(MenuAbout, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
320 APP_Main, 2, MUIM_CallHook, &AboutHook);
321 DoMethod(MenuAboutMUI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
322 APP_Main, 2, MUIM_CallHook, &AboutMUIHook);
323 DoMethod(MenuQuit, MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
324 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
326 set(WIN_Main, MUIA_Window_Open, TRUE);
327 get(WIN_Main, MUIA_Window_Open, &win_opened);
329 if (win_opened)
331 ULONG sigs = 0;
332 BOOL Run = TRUE;
334 while (Run)
336 ULONG Action = DoMethod(APP_Main, MUIM_Application_NewInput, &sigs);
338 switch (Action)
340 case MUIV_Application_ReturnID_Quit:
341 Run = FALSE;
342 break;
343 default:
344 break;
347 if (Run && sigs)
349 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
351 if (sigs & SIGBREAKF_CTRL_C)
353 Run = FALSE;
358 else
360 printf("failed to open main window !\n");
363 set(WIN_Main, MUIA_Window_Open, FALSE);
365 DoMethod(APP_Main, MUIM_Application_Save, MUIV_Application_Save_ENV);
366 DoMethod(APP_Main, MUIM_Application_Save, MUIV_Application_Save_ENVARC);
368 fail(APP_Main, NULL);
370 return 0;
373 //----------------------------------------------------------------------------
375 static VOID fail(APTR APP_Main, CONST_STRPTR str)
377 CxFreeBrokerList(&BrokerCopyList);
379 if (APP_Main)
381 MUI_DisposeObject(APP_Main);
383 if (ExchangeCatalog)
385 CloseCatalog(ExchangeCatalog);
386 ExchangeCatalog = NULL;
389 CloseLibraries();
391 if (str)
393 puts(str);
394 exit(20);
397 exit(0);
400 //----------------------------------------------------------------------------
402 static void init(void)
404 NewList(&BrokerCopyList);
406 if (!OpenLibraries())
407 fail(NULL, "Failed to open "MUIMASTER_NAME".");
409 if (LocaleBase)
410 ExchangeCatalog = OpenCatalogA(NULL, "Scalos/Exchange.catalog", NULL);
412 // TranslateNewMenu(NewContextMenuHistoryPopup);
413 TranslateStringArray(CycleActiveEntries);
416 //----------------------------------------------------------------------------
418 static BOOL OpenLibraries(void)
420 IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
421 if (NULL == IntuitionBase)
422 return FALSE;
423 #ifdef __amigaos4__
424 else
426 IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, NULL);
427 if (NULL == IIntuition)
428 return FALSE;
430 #endif
432 MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN-1);
433 if (NULL == MUIMasterBase)
434 return FALSE;
435 #ifdef __amigaos4__
436 else
438 IMUIMaster = (struct MUIMasterIFace *)GetInterface((struct Library *)MUIMasterBase, "main", 1, NULL);
439 if (NULL == IMUIMaster)
440 return FALSE;
442 #endif
444 CxBase = OpenLibrary("commodities.library", 40);
445 if (NULL == CxBase)
446 return FALSE;
447 #ifdef __amigaos4__
448 else
450 ICx = (struct CxIFace *)GetInterface((struct Library *)CxBase, "main", 1, NULL);
451 if (NULL == ICx)
452 return FALSE;
454 #endif
456 LocaleBase = (T_LOCALEBASE) OpenLibrary("locale.library", 39);
457 #ifdef __amigaos4__
458 if (NULL != LocaleBase)
460 ILocale = (struct LocaleIFace *)GetInterface((struct Library *)LocaleBase, "main", 1, NULL);
461 if (NULL == ILocale)
462 return FALSE;
464 #endif
466 return TRUE;
469 //----------------------------------------------------------------------------
471 static void CloseLibraries(void)
473 if (LocaleBase)
475 if (ExchangeCatalog)
477 CloseCatalog(ExchangeCatalog);
478 ExchangeCatalog = NULL;
480 #ifdef __amigaos4__
481 if (ILocale)
483 DropInterface((struct Interface *)ILocale);
484 ILocale = NULL;
486 #endif
487 CloseLibrary((struct Library *) LocaleBase);
488 LocaleBase = NULL;
490 #ifdef __amigaos4__
491 if (ICx)
493 DropInterface((struct Interface *)ICx);
494 ICx = NULL;
496 #endif
497 if (CxBase)
499 CloseLibrary((struct Library *) CxBase);
500 CxBase = NULL;
502 #ifdef __amigaos4__
503 if (IMUIMaster)
505 DropInterface((struct Interface *) IMUIMaster);
506 IMUIMaster = NULL;
508 #endif
509 if (MUIMasterBase)
511 CloseLibrary(MUIMasterBase);
512 MUIMasterBase = NULL;
514 #ifdef __amigaos4__
515 if (IIntuition)
517 DropInterface((struct Interface *) IIntuition);
518 IIntuition = NULL;
520 #endif
521 if (IntuitionBase)
523 CloseLibrary((struct Library *) IntuitionBase);
524 IntuitionBase = NULL;
528 //----------------------------------------------------------------------------
530 static STRPTR GetLocString(ULONG MsgId)
532 struct Exchange_LocaleInfo li;
534 li.li_Catalog = ExchangeCatalog;
535 #ifndef __amigaos4__
536 li.li_LocaleBase = LocaleBase;
537 #else
538 li.li_ILocale = ILocale;
539 #endif
541 return (STRPTR)GetExchangeString(&li, MsgId);
544 //----------------------------------------------------------------------------
546 static void TranslateStringArray(STRPTR *stringArray)
548 while (*stringArray)
550 *stringArray = GetLocString((IPTR) *stringArray);
551 stringArray++;
555 //----------------------------------------------------------------------------
556 #if 0
557 static void TranslateNewMenu(struct NewMenu *nm)
559 while (nm && NM_END != nm->nm_Type)
561 if (NM_BARLABEL != nm->nm_Label)
562 nm->nm_Label = GetLocString((ULONG) nm->nm_Label);
564 if (nm->nm_CommKey)
565 nm->nm_CommKey = GetLocString((ULONG) nm->nm_CommKey);
567 nm++;
570 #endif
571 //----------------------------------------------------------------------------
573 static SAVEDS(APTR) INTERRUPT OpenAboutMUIFunc(struct Hook *hook, Object *o, Msg msg)
575 if (NULL == WIN_AboutMUI)
577 WIN_AboutMUI = MUI_NewObject(MUIC_Aboutmui,
578 MUIA_Window_RefWindow, WIN_Main,
579 MUIA_Aboutmui_Application, APP_Main,
580 End;
583 if (WIN_AboutMUI)
584 set(WIN_AboutMUI, MUIA_Window_Open, TRUE);
586 return 0;
589 //----------------------------------------------------------------------------
591 static SAVEDS(void) INTERRUPT OpenAboutFunc(struct Hook *hook, Object *o, Msg msg)
593 MUI_Request(APP_Main, WIN_Main, 0, NULL,
594 GetLocString(MSGID_ABOUTREQOK),
595 GetLocString(MSGID_ABOUTREQFORMAT),
596 VERSION_MAJOR, VERSION_MINOR, COMPILER_STRING, CURRENTYEAR);
599 //----------------------------------------------------------------------------
601 static SAVEDS(APTR) INTERRUPT CxListConstructHookFunc(struct Hook *hook, APTR unused, struct NList_ConstructMessage *nlcm)
603 struct CxListEntry *xle = AllocPooled(nlcm->pool, sizeof(struct CxListEntry));
604 BOOL Success = FALSE;
606 (void) unused;
608 do {
609 struct BrokerCopy *bc = nlcm->entry;
611 d1(KPrintF("%s/%s/%ld: bc=%08lx\n", __FILE__, __FUNC__, __LINE__, bc));
612 d1(KPrintF("%s/%s/%ld: bc_Name=<%s>\n", __FILE__, __FUNC__, __LINE__, bc->bc_Name));
613 d1(KPrintF("%s/%s/%ld: bc_Title=<%s>\n", __FILE__, __FUNC__, __LINE__, bc->bc_Title));
614 d1(KPrintF("%s/%s/%ld: bc_Descr=<%s>\n", __FILE__, __FUNC__, __LINE__, bc->bc_Descr));
616 if (NULL == xle)
617 break;
619 xle->xle_Name = strdup(bc->bc_Name);
620 if (NULL == xle->xle_Name)
621 break;
623 xle->xle_Title = strdup(bc->bc_Title);
624 if (NULL == xle->xle_Title)
625 break;
627 xle->xle_Description = strdup(bc->bc_Descr);
628 if (NULL == xle->xle_Description)
629 break;
631 xle->xle_Task = bc->bc_Task;
632 xle->xle_Pri = bc->bc_Node.ln_Pri;
633 xle->xle_Flags = bc->bc_Flags;
634 #ifdef __AROS__
635 xle->xle_Addr = bc->bc_Port;
636 #else
637 xle->xle_Addr = bc->bc_Addr;
638 #endif
640 Success = TRUE;
641 } while (0);
643 if (!Success)
645 if (xle)
647 if (xle->xle_Name)
648 free(xle->xle_Name);
649 if (xle->xle_Title)
650 free(xle->xle_Title);
651 if (xle->xle_Description)
652 free(xle->xle_Description);
654 FreePooled(nlcm->pool, xle, sizeof(struct CxListEntry));
655 xle = NULL;
659 d1(KPrintF("%s/%s/%ld: END xle=%08lx\n", __FILE__, __FUNC__, __LINE__, xle));
661 return (APTR) xle;
665 static SAVEDS(void) INTERRUPT CxListDestructHookFunc(struct Hook *hook, APTR unused, struct NList_DestructMessage *nldm)
667 struct CxListEntry *xle = (struct CxListEntry *) nldm->entry;
669 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
671 (void) unused;
673 if (xle)
675 if (xle->xle_Name)
676 free(xle->xle_Name);
677 if (xle->xle_Title)
678 free(xle->xle_Title);
679 if (xle->xle_Description)
680 free(xle->xle_Description);
682 FreePooled(nldm->pool, xle, sizeof(struct CxListEntry));
685 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
689 static SAVEDS(ULONG) INTERRUPT CxListDisplayHookFunc(struct Hook *hook, APTR unused, struct NList_DisplayMessage *nldm)
691 (void) unused;
693 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
695 if (nldm->entry)
697 struct CxListEntry *xle = (struct CxListEntry *) nldm->entry;
699 d1(KPrintF("%s/%s/%ld: xle=%08lx\n", __FILE__, __FUNC__, __LINE__, xle));
700 d1(KPrintF("%s/%s/%ld: xle_Name=<%s>\n", __FILE__, __FUNC__, __LINE__, xle->xle_Name));
702 sprintf(xle->xle_PriString, "%ld", (long int)xle->xle_Pri);
704 nldm->strings[0] = xle->xle_Name;
705 nldm->strings[1] = xle->xle_Title;
706 nldm->strings[2] = CycleActiveEntries[(xle->xle_Flags & COF_ACTIVE) ? 0 : 1];
707 nldm->strings[3] = xle->xle_PriString;
709 else
711 // display titles
712 nldm->strings[0] = GetLocString(MSGID_CXLIST_NAME);
713 nldm->strings[1] = GetLocString(MSGID_CXLIST_TITLE);
714 nldm->strings[2] = GetLocString(MSGID_CXLIST_STATE);
715 nldm->strings[3] = GetLocString(MSGID_CXLIST_PRIORITY);
718 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
720 return 0;
724 static SAVEDS(LONG) INTERRUPT CxListCompareHookFunc(struct Hook *hook, Object *obj, struct NList_CompareMessage *ncm)
726 const struct CxListEntry *xle1 = (const struct CxListEntry *) ncm->entry1;
727 const struct CxListEntry *xle2 = (const struct CxListEntry *) ncm->entry2;
728 LONG col1 = ncm->sort_type & MUIV_NList_TitleMark_ColMask;
729 LONG col2 = ncm->sort_type2 & MUIV_NList_TitleMark2_ColMask;
730 LONG Result = 0;
732 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
734 if (ncm->sort_type != MUIV_NList_SortType_None)
736 // primary sorting
737 switch (col1)
739 case 0: // sort by name
740 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
741 Result = Stricmp(xle2->xle_Name, xle1->xle_Name);
742 else
743 Result = Stricmp(xle1->xle_Name, xle2->xle_Name);
744 break;
745 case 1: // sort by title
746 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
747 Result = Stricmp(xle2->xle_Title, xle1->xle_Title);
748 else
749 Result = Stricmp(xle1->xle_Title, xle2->xle_Title);
750 break;
751 case 2: // sort by state
752 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
753 Result = (xle2->xle_Flags & COF_ACTIVE) - (xle1->xle_Flags & COF_ACTIVE);
754 else
755 Result = (xle1->xle_Flags & COF_ACTIVE) - (xle2->xle_Flags & COF_ACTIVE);
756 break;
757 case 3: // sort by priority
758 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
759 Result = xle2->xle_Pri - xle1->xle_Pri;
760 else
761 Result = xle1->xle_Pri - xle2->xle_Pri;
762 break;
763 default:
764 break;
767 if (0 == Result && col1 != col2)
769 // Secondary sorting
770 switch (col2)
772 case 0: // sort by name
773 if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
774 Result = Stricmp(xle2->xle_Name, xle1->xle_Name);
775 else
776 Result = Stricmp(xle1->xle_Name, xle2->xle_Name);
777 break;
778 case 1: // sort by title
779 if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
780 Result = Stricmp(xle2->xle_Title, xle1->xle_Title);
781 else
782 Result = Stricmp(xle1->xle_Title, xle2->xle_Title);
783 break;
784 case 2: // sort by state
785 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
786 Result = (xle2->xle_Flags & COF_ACTIVE) - (xle1->xle_Flags & COF_ACTIVE);
787 else
788 Result = (xle1->xle_Flags & COF_ACTIVE) - (xle2->xle_Flags & COF_ACTIVE);
789 break;
790 case 3: // sort by priority
791 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
792 Result = xle2->xle_Pri - xle1->xle_Pri;
793 else
794 Result = xle1->xle_Pri - xle2->xle_Pri;
795 break;
796 default:
797 break;
802 d1(KPrintF("%s/%s/%ld: END Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
804 return Result;
807 //----------------------------------------------------------------------------
809 static SAVEDS(void) INTERRUPT RescanHookFunc(struct Hook *hook, Object *obj, Msg *msg)
811 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
813 do {
814 struct BrokerCopy *bc;
815 d1(LONG res;)
817 CxFreeBrokerList(&BrokerCopyList);
819 set(NListCxList, MUIA_NList_Quiet, MUIV_NList_Quiet_Full);
820 DoMethod(NListCxList, MUIM_NList_Clear);
822 d1(res =)
823 CxCopyBrokerList(&BrokerCopyList);
825 d1(KPrintF("%s/%s/%ld: CxCopyBrokerList returned %ld\n", __FILE__, __FUNC__, __LINE__, res);)
827 for (bc = (struct BrokerCopy *) BrokerCopyList.lh_Head;
828 bc != (struct BrokerCopy *) &BrokerCopyList.lh_Tail;
829 bc = (struct BrokerCopy *) bc->bc_Node.ln_Succ)
831 d1(KPrintF("%s/%s/%ld: bc=%08lx\n", __FILE__, __FUNC__, __LINE__, bc));
832 d1(KPrintF("%s/%s/%ld: bc_Name=<%s> bc_Title=<%s> bc_Descr=<%s>\n", \
833 __FILE__, __FUNC__, __LINE__, bc->bc_Name, bc->bc_Title, bc->bc_Descr));
834 d1(KPrintF("%s/%s/%ld: bc_Addr=%08lx bc_Dummy2=%08lx\n", \
835 __FILE__, __FUNC__, __LINE__, bc->bc_Addr, bc->bc_Dummy2));
837 DoMethod(NListCxList,
838 MUIM_NList_InsertSingle,
840 MUIV_NList_Insert_Sorted);
843 set(NListCxList, MUIA_NList_Quiet, MUIV_NList_Quiet_None);
844 } while (0);
846 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
849 //----------------------------------------------------------------------------
851 static SAVEDS(void) INTERRUPT SelectCxHookFunc(struct Hook *hook, Object *obj, Msg *msg)
853 const struct CxListEntry *xle = NULL;
855 DoMethod(NListCxList,
856 MUIM_NList_GetEntry,
857 MUIV_NList_GetEntry_Active,
858 &xle);
860 if (xle)
862 STRPTR Description;
864 Description = malloc(3 + strlen(xle->xle_Title) + strlen(xle->xle_Description));
865 if (Description)
867 sprintf(Description, "%s\n%s", xle->xle_Title, xle->xle_Description);
868 set(FloattextDescription, MUIA_Floattext_Text, Description);
869 free(Description);
872 set(ButtonShow, MUIA_Disabled, !(xle->xle_Flags & COF_SHOW_HIDE));
873 set(ButtonHide, MUIA_Disabled, !(xle->xle_Flags & COF_SHOW_HIDE));
874 set(ButtonRemove, MUIA_Disabled, FALSE);
875 set(CycleActive, MUIA_Disabled, FALSE);
876 setcycle(CycleActive, (xle->xle_Flags & COF_ACTIVE) ? 0 : 1);
878 else
880 set(FloattextDescription, MUIA_Floattext_Text, "");
881 set(ButtonShow, MUIA_Disabled, TRUE);
882 set(ButtonHide, MUIA_Disabled, TRUE);
883 set(ButtonRemove, MUIA_Disabled, TRUE);
884 set(CycleActive, MUIA_Disabled, TRUE);
888 //----------------------------------------------------------------------------
890 static SAVEDS(void) INTERRUPT CxCommandHookFunc(struct Hook *hook, Object *obj, LONG *cmd)
892 struct CxListEntry *xle = NULL;
894 DoMethod(NListCxList,
895 MUIM_NList_GetEntry,
896 MUIV_NList_GetEntry_Active,
897 &xle);
899 if (xle)
901 (void) CxBrokerCommand(xle->xle_Name, *cmd);
905 //----------------------------------------------------------------------------
907 static SAVEDS(void) INTERRUPT BrokerHookFunc(struct Hook *hook, Object *obj, CxMsg *msg)
909 if (CXM_COMMAND == CxMsgType(msg))
911 switch (CxMsgID(msg))
913 case CXCMD_APPEAR:
914 set(WIN_Main, MUIA_Window_Open, TRUE);
915 break;
916 case CXCMD_LIST_CHG:
917 DoMethod(APP_Main, MUIM_CallHook, &RescanHook);
918 break;
919 default:
920 break;
925 //----------------------------------------------------------------------------
927 // Checks if a certain version of a MCC is available
928 BOOL CheckMCCVersion(CONST_STRPTR name, ULONG minver, ULONG minrev)
930 BOOL flush = TRUE;
932 d1(KPrintF("%s/%s/%ld: %s ", __FILE__, __FUNC__, __LINE__, name);)
934 while (1)
936 ULONG ver = 0;
937 ULONG rev = 0;
938 struct Library *base;
939 char libname[256];
941 // First we attempt to acquire the version and revision through MUI
942 Object *obj = MUI_NewObject((STRPTR) name, TAG_DONE);
943 if (obj)
945 get(obj, MUIA_Version, &ver);
946 get(obj, MUIA_Revision, &rev);
948 MUI_DisposeObject(obj);
950 if(ver > minver || (ver == minver && rev >= minrev))
952 d1(kprintf("%s/%s/%ld: v%ld.%ld found through MUIA_Version/Revision\n", __FILE__, __FUNC__, __LINE__, ver, rev);)
953 return TRUE;
957 // If we did't get the version we wanted, let's try to open the
958 // libraries ourselves and see what happens...
959 stccpy(libname, "PROGDIR:mui", sizeof(libname));
960 AddPart(libname, name, sizeof(libname));
962 if ((base = OpenLibrary(&libname[8], 0)) || (base = OpenLibrary(&libname[0], 0)))
964 UWORD OpenCnt = base->lib_OpenCnt;
966 ver = base->lib_Version;
967 rev = base->lib_Revision;
969 CloseLibrary(base);
971 // we add some additional check here so that eventual broken .mcc also have
972 // a chance to pass this test (i.e. Toolbar.mcc is broken)
973 if (ver > minver || (ver == minver && rev >= minrev))
975 d1(kprintf("%s/%s/%ld: v%ld.%ld found through OpenLibrary()\n", __FILE__, __FUNC__, __LINE__, ver, rev);)
976 return TRUE;
979 if (OpenCnt > 1)
981 if (MUI_Request(NULL, NULL, 0L,
982 (STRPTR) GetLocString(MSGID_STARTUP_FAILURE),
983 (STRPTR) GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD),
984 (STRPTR) GetLocString(MSGID_STARTUP_MCC_IN_USE),
985 name, minver, minrev, ver, rev))
987 flush = TRUE;
989 else
990 break;
993 // Attempt to flush the library if open count is 0 or because the
994 // user wants to retry (meaning there's a chance that it's 0 now)
996 if (flush)
998 struct Library *result;
999 extern struct ExecBase *SysBase;
1001 Forbid();
1002 if ((result = (struct Library *) FindName(&SysBase->LibList, name)))
1003 RemLibrary(result);
1004 Permit();
1005 flush = FALSE;
1007 else
1009 d1(kprintf("%s/%s/%ld: couldn`t Exchange minimum required version.\n", __LINE__);)
1011 // We're out of luck - open count is 0, we've tried to flush
1012 // and still haven't got the version we want
1013 if (MUI_Request(NULL, NULL, 0L,
1014 (STRPTR) GetLocString(MSGID_STARTUP_FAILURE),
1015 (STRPTR) GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD),
1016 (STRPTR) GetLocString(MSGID_STARTUP_OLD_MCC),
1017 name, minver, minrev, ver, rev))
1019 flush = TRUE;
1021 else
1022 break;
1025 else
1027 // No MCC at all - no need to attempt flush
1028 flush = FALSE;
1029 if (!MUI_Request(NULL, NULL, 0L,
1030 (STRPTR) GetLocString(MSGID_STARTUP_FAILURE),
1031 (STRPTR) GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD),
1032 (STRPTR) GetLocString(MSGID_STARTUP_MCC_NOT_FOUND),
1033 name, minver, minrev))
1035 break;
1040 return FALSE;
1043 //----------------------------------------------------------------------------