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>
39 #include <Year.h> // +jmc+
42 #include "cx_private.h"
45 #define Exchange_NUMBERS
46 #define Exchange_ARRAY
48 #include STR(SCALOSLOCALE)
50 //----------------------------------------------------------------------------
52 #if !defined(__amigaos4__) && !defined(__AROS__)
55 long _stack
= 16384; // minimum stack size, used by SAS/C startup code
58 //----------------------------------------------------------------------------
60 // local data structures
62 #define KeyButtonHelp(name,key,HelpText)\
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,\
80 STRPTR xle_Description
;
81 struct Task
*xle_Task
;
85 char xle_PriString
[10];
88 //----------------------------------------------------------------------------
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
);
110 static void TranslateNewMenu(struct NewMenu
*nm
);
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
,
138 //----------------------------------------------------------------------------
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
;
150 struct IntuitionIFace
*IIntuition
= NULL
;
151 struct MUIMasterIFace
*IMUIMaster
= NULL
;
152 struct CxIFace
*ICx
= NULL
;
153 struct LocaleIFace
*ILocale
= NULL
;
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
[])
175 if (!CheckMCCVersion(MUIC_NListview
, 19, 66) )
177 d1(KPrintF(__FILE__
"/%s/%ld: CheckMCCVersion failed\n", __FUNC__
, __LINE__
));
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
,
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
,
210 End
, //NListviewObject
213 Child
, FloattextDescription
= FloattextObject
,
216 End
, //FloattextObject
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
,
231 Child
, ButtonRemove
= KeyButtonHelp(GetLocString(MSGID_BUTTON_REMOVE
),
232 *GetLocString(MSGID_BUTTON_REMOVE_KEY
),
233 GetLocString(MSGID_BUTTON_REMOVE_SHORTHELP
)),
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
),
245 Child
, MenuAboutMUI
= MenuitemObject
,
246 MUIA_Menuitem_Title
, GetLocString(MSGID_MENU_PROJECT_ABOUTMUI
),
248 Child
, MenuitemObject
,
249 MUIA_Menuitem_Title
, -1,
251 Child
, MenuQuit
= MenuitemObject
,
252 MUIA_Menuitem_Title
, GetLocString(MSGID_MENU_PROJECT_QUIT
),
253 MUIA_Menuitem_Shortcut
, GetLocString(MSGID_MENU_PROJECT_QUIT_SHORT
),
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
);
336 ULONG Action
= DoMethod(APP_Main
, MUIM_Application_NewInput
, &sigs
);
340 case MUIV_Application_ReturnID_Quit
:
349 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
);
351 if (sigs
& SIGBREAKF_CTRL_C
)
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
);
373 //----------------------------------------------------------------------------
375 static VOID
fail(APTR APP_Main
, CONST_STRPTR str
)
377 CxFreeBrokerList(&BrokerCopyList
);
381 MUI_DisposeObject(APP_Main
);
385 CloseCatalog(ExchangeCatalog
);
386 ExchangeCatalog
= NULL
;
400 //----------------------------------------------------------------------------
402 static void init(void)
404 NewList(&BrokerCopyList
);
406 if (!OpenLibraries())
407 fail(NULL
, "Failed to open "MUIMASTER_NAME
".");
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
)
426 IIntuition
= (struct IntuitionIFace
*)GetInterface((struct Library
*)IntuitionBase
, "main", 1, NULL
);
427 if (NULL
== IIntuition
)
432 MUIMasterBase
= OpenLibrary(MUIMASTER_NAME
, MUIMASTER_VMIN
-1);
433 if (NULL
== MUIMasterBase
)
438 IMUIMaster
= (struct MUIMasterIFace
*)GetInterface((struct Library
*)MUIMasterBase
, "main", 1, NULL
);
439 if (NULL
== IMUIMaster
)
444 CxBase
= OpenLibrary("commodities.library", 40);
450 ICx
= (struct CxIFace
*)GetInterface((struct Library
*)CxBase
, "main", 1, NULL
);
456 LocaleBase
= (T_LOCALEBASE
) OpenLibrary("locale.library", 39);
458 if (NULL
!= LocaleBase
)
460 ILocale
= (struct LocaleIFace
*)GetInterface((struct Library
*)LocaleBase
, "main", 1, NULL
);
469 //----------------------------------------------------------------------------
471 static void CloseLibraries(void)
477 CloseCatalog(ExchangeCatalog
);
478 ExchangeCatalog
= NULL
;
483 DropInterface((struct Interface
*)ILocale
);
487 CloseLibrary((struct Library
*) LocaleBase
);
493 DropInterface((struct Interface
*)ICx
);
499 CloseLibrary((struct Library
*) CxBase
);
505 DropInterface((struct Interface
*) IMUIMaster
);
511 CloseLibrary(MUIMasterBase
);
512 MUIMasterBase
= NULL
;
517 DropInterface((struct Interface
*) IIntuition
);
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
;
536 li
.li_LocaleBase
= LocaleBase
;
538 li
.li_ILocale
= ILocale
;
541 return (STRPTR
)GetExchangeString(&li
, MsgId
);
544 //----------------------------------------------------------------------------
546 static void TranslateStringArray(STRPTR
*stringArray
)
550 *stringArray
= GetLocString((IPTR
) *stringArray
);
555 //----------------------------------------------------------------------------
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
);
565 nm
->nm_CommKey
= GetLocString((ULONG
) nm
->nm_CommKey
);
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
,
584 set(WIN_AboutMUI
, MUIA_Window_Open
, TRUE
);
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
;
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
));
619 xle
->xle_Name
= strdup(bc
->bc_Name
);
620 if (NULL
== xle
->xle_Name
)
623 xle
->xle_Title
= strdup(bc
->bc_Title
);
624 if (NULL
== xle
->xle_Title
)
627 xle
->xle_Description
= strdup(bc
->bc_Descr
);
628 if (NULL
== xle
->xle_Description
)
631 xle
->xle_Task
= bc
->bc_Task
;
632 xle
->xle_Pri
= bc
->bc_Node
.ln_Pri
;
633 xle
->xle_Flags
= bc
->bc_Flags
;
635 xle
->xle_Addr
= bc
->bc_Port
;
637 xle
->xle_Addr
= bc
->bc_Addr
;
650 free(xle
->xle_Title
);
651 if (xle
->xle_Description
)
652 free(xle
->xle_Description
);
654 FreePooled(nlcm
->pool
, xle
, sizeof(struct CxListEntry
));
659 d1(KPrintF("%s/%s/%ld: END xle=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, 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__
));
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
)
693 d1(KPrintF("%s/%s/%ld: START\n", __FILE__
, __FUNC__
, __LINE__
));
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
;
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__
));
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
;
732 d1(KPrintF("%s/%s/%ld: START\n", __FILE__
, __FUNC__
, __LINE__
));
734 if (ncm
->sort_type
!= MUIV_NList_SortType_None
)
739 case 0: // sort by name
740 if (ncm
->sort_type
& MUIV_NList_TitleMark_TypeMask
)
741 Result
= Stricmp(xle2
->xle_Name
, xle1
->xle_Name
);
743 Result
= Stricmp(xle1
->xle_Name
, xle2
->xle_Name
);
745 case 1: // sort by title
746 if (ncm
->sort_type
& MUIV_NList_TitleMark_TypeMask
)
747 Result
= Stricmp(xle2
->xle_Title
, xle1
->xle_Title
);
749 Result
= Stricmp(xle1
->xle_Title
, xle2
->xle_Title
);
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
);
755 Result
= (xle1
->xle_Flags
& COF_ACTIVE
) - (xle2
->xle_Flags
& COF_ACTIVE
);
757 case 3: // sort by priority
758 if (ncm
->sort_type
& MUIV_NList_TitleMark_TypeMask
)
759 Result
= xle2
->xle_Pri
- xle1
->xle_Pri
;
761 Result
= xle1
->xle_Pri
- xle2
->xle_Pri
;
767 if (0 == Result
&& col1
!= 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
);
776 Result
= Stricmp(xle1
->xle_Name
, xle2
->xle_Name
);
778 case 1: // sort by title
779 if (ncm
->sort_type2
& MUIV_NList_TitleMark2_TypeMask
)
780 Result
= Stricmp(xle2
->xle_Title
, xle1
->xle_Title
);
782 Result
= Stricmp(xle1
->xle_Title
, xle2
->xle_Title
);
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
);
788 Result
= (xle1
->xle_Flags
& COF_ACTIVE
) - (xle2
->xle_Flags
& COF_ACTIVE
);
790 case 3: // sort by priority
791 if (ncm
->sort_type
& MUIV_NList_TitleMark_TypeMask
)
792 Result
= xle2
->xle_Pri
- xle1
->xle_Pri
;
794 Result
= xle1
->xle_Pri
- xle2
->xle_Pri
;
802 d1(KPrintF("%s/%s/%ld: END Result=%ld\n", __FILE__
, __FUNC__
, __LINE__
, 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__
));
814 struct BrokerCopy
*bc
;
817 CxFreeBrokerList(&BrokerCopyList
);
819 set(NListCxList
, MUIA_NList_Quiet
, MUIV_NList_Quiet_Full
);
820 DoMethod(NListCxList
, MUIM_NList_Clear
);
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
);
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
,
857 MUIV_NList_GetEntry_Active
,
864 Description
= malloc(3 + strlen(xle
->xle_Title
) + strlen(xle
->xle_Description
));
867 sprintf(Description
, "%s\n%s", xle
->xle_Title
, xle
->xle_Description
);
868 set(FloattextDescription
, MUIA_Floattext_Text
, 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);
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
,
896 MUIV_NList_GetEntry_Active
,
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
))
914 set(WIN_Main
, MUIA_Window_Open
, TRUE
);
917 DoMethod(APP_Main
, MUIM_CallHook
, &RescanHook
);
925 //----------------------------------------------------------------------------
927 // Checks if a certain version of a MCC is available
928 BOOL
CheckMCCVersion(CONST_STRPTR name
, ULONG minver
, ULONG minrev
)
932 d1(KPrintF("%s/%s/%ld: %s ", __FILE__
, __FUNC__
, __LINE__
, name
);)
938 struct Library
*base
;
941 // First we attempt to acquire the version and revision through MUI
942 Object
*obj
= MUI_NewObject((STRPTR
) name
, TAG_DONE
);
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
);)
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
;
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
);)
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
))
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)
998 struct Library
*result
;
999 extern struct ExecBase
*SysBase
;
1002 if ((result
= (struct Library
*) FindName(&SysBase
->LibList
, name
)))
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
))
1027 // No MCC at all - no need to attempt flush
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
))
1043 //----------------------------------------------------------------------------