2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 Exchange -- controls commodities.
8 /******************************************************************************
16 CX_PRIORITY/K/N,CX_POPUP/K/S,CX_POPKEY/K
20 Workbench:Tools/Commodities
24 Manages the commodities in the system
28 CX_PRIORITY -- Priority of the Exchange broker
29 CX_POPUP -- Appear at startup
30 CX_POPKEY -- Hotkey combination for Exchange
44 ******************************************************************************/
46 #define AROS_ALMOST_COMPATIBLE
47 #define MUIMASTER_YES_INLINE_STDARG
58 #include <aros/debug.h>
59 #include <aros/asmcall.h>
60 #include <aros/symbolsets.h>
61 #include <libraries/iffparse.h>
62 #include <libraries/mui.h>
63 #include <proto/muimaster.h>
64 #include <proto/locale.h>
65 #include <proto/intuition.h>
66 #include <proto/exec.h>
67 #include <proto/gadtools.h>
68 #include <proto/dos.h>
69 #include <proto/alib.h>
70 #include <proto/commodities.h>
71 #include <proto/utility.h>
77 #define CATALOG_NAME "System/Tools/Commodities.catalog"
79 #define CATALOG_NAME "System/Tools/Exchange.catalog"
81 #define CATALOG_VERSION 2
83 TEXT version
[] = "$VER: Exchange 1.1 (08.01.2009)";
85 #define ARG_TEMPLATE "CX_PRIORITY/N/K,CX_POPKEY/K,CX_POPUP/S"
86 #define DEF_POPKEY "ctrl alt h"
95 static Object
*app
, *wnd
, *listgad
, *textgad1
, *textgad2
, *showgad
, *hidegad
, *cyclegad
, *killgad
;
96 static CONST_STRPTR cyclestrings
[3];
97 static struct Catalog
*catalog
;
99 static struct List brokerList
;
101 static struct Hook broker_hook
;
102 static struct Hook list_disp_hook
;
103 static struct Hook list_select_hook
;
104 static struct Hook inform_broker_hook
;
107 static char *cx_popkey
;
108 static BOOL cx_popup
= FALSE
;
109 static CxObj
*broker
;
110 static struct MsgPort
*brokermp
;
111 static struct Task
*maintask
;
113 static void Cleanup(CONST_STRPTR txt
);
114 static void GetArguments(int argc
, char **argv
);
115 static void HandleAll(void);
116 static void InitMenus(void);
117 static VOID
Locale_Deinitialize(VOID
);
118 static int Locale_Initialize(VOID
);
119 static void MakeGUI(void);
120 static void showSimpleMessage(CONST_STRPTR msgString
);
121 static void update_list(void);
122 static CONST_STRPTR
_(ULONG id
);
124 /*********************************************************************************************/
126 static CONST_STRPTR
_(ULONG id
)
128 if (LocaleBase
!= NULL
&& catalog
!= NULL
)
130 return GetCatalogStr(catalog
, id
, CatCompArray
[id
].cca_Str
);
134 return CatCompArray
[id
].cca_Str
;
138 #define __(id) ((IPTR) _(id)) /* Get a message, as an IPTR */
140 /*********************************************************************************************/
142 static int Locale_Initialize(VOID
)
144 if (LocaleBase
!= NULL
)
146 catalog
= OpenCatalog
148 NULL
, CATALOG_NAME
, OC_Version
, CATALOG_VERSION
, TAG_DONE
155 /* Note that in AROS constructors should return value opposite to the standard one.
156 Probably it's a misdesign, but we can do nothing with it. */
164 /*********************************************************************************************/
166 static VOID
Locale_Deinitialize(VOID
)
168 if(LocaleBase
!= NULL
&& catalog
!= NULL
) CloseCatalog(catalog
);
171 /*********************************************************************************************/
173 static void GetArguments(int argc
, char **argv
)
175 static struct RDArgs
*myargs
;
176 static IPTR args
[NUM_ARGS
];
177 static UBYTE
**wbargs
;
180 if (!(myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
182 Fault(IoErr(), 0, s
, 256);
185 if (args
[ARG_CXPRI
]) cx_pri
= *(LONG
*)args
[ARG_CXPRI
];
186 if (args
[ARG_CXPOPKEY
])
188 cx_popkey
= StrDup((char *)args
[ARG_CXPOPKEY
]);
192 cx_popkey
= StrDup(DEF_POPKEY
);
194 if (args
[ARG_CXPOPUP
]) cx_popup
= TRUE
;
199 wbargs
= ArgArrayInit(argc
, (UBYTE
**)argv
);
200 cx_pri
= ArgInt(wbargs
, "CX_PRIORITY", 0);
201 cx_popkey
= StrDup(ArgString(wbargs
, "CX_POPKEY", DEF_POPKEY
));
202 if (strnicmp(ArgString(wbargs
, "CX_POPUP", "NO"), "Y", 1) == 0)
208 D(bug("Exchange Arguments pri %d popkey %s popup %d\n", cx_pri
, cx_popkey
, cx_popup
));
211 /*********************************************************************************************/
213 static struct NewMenu nm
[] =
215 {NM_TITLE
, (STRPTR
)MSG_MEN_PROJECT
},
216 {NM_ITEM
, (STRPTR
)MSG_MEN_PROJECT_HIDE
},
217 {NM_ITEM
, (STRPTR
)MSG_MEN_PROJECT_ICONIFY
},
218 {NM_ITEM
, NM_BARLABEL
},
219 {NM_ITEM
, (STRPTR
)MSG_MEN_PROJECT_QUIT
},
223 /*********************************************************************************************/
225 static void InitMenus(void)
227 struct NewMenu
*actnm
= nm
;
229 for(actnm
= nm
; actnm
->nm_Type
!= NM_END
; actnm
++)
231 if (actnm
->nm_Label
!= NM_BARLABEL
)
233 ULONG id
= (ULONG
)actnm
->nm_Label
;
234 CONST_STRPTR str
= _(id
);
236 if (actnm
->nm_Type
== NM_TITLE
)
238 actnm
->nm_Label
= str
;
240 actnm
->nm_Label
= str
+ 2;
241 if (str
[0] != ' ') actnm
->nm_CommKey
= str
;
243 actnm
->nm_UserData
= (APTR
)id
;
245 } /* if (actnm->nm_Label != NM_BARLABEL) */
247 } /* for(actnm = nm; nm->nm_Type != NM_END; nm++) */
250 /*********************************************************************************************/
252 static void showSimpleMessage(CONST_STRPTR msgString
)
254 struct EasyStruct easyStruct
;
256 easyStruct
.es_StructSize
= sizeof(easyStruct
);
257 easyStruct
.es_Flags
= 0;
258 easyStruct
.es_Title
= _(MSG_EXCHANGE_CXNAME
);
259 easyStruct
.es_TextFormat
= msgString
;
260 easyStruct
.es_GadgetFormat
= _(MSG_OK
);
262 if (IntuitionBase
!= NULL
&& !Cli() )
264 EasyRequestArgs(NULL
, &easyStruct
, NULL
, NULL
);
272 /*********************************************************************************************/
274 static void update_list(void)
276 struct BrokerCopy
*node
;
277 CopyBrokerList(&brokerList
);
279 nnset(textgad1
, MUIA_Text_Contents
, NULL
);
280 nnset(textgad2
, MUIA_Text_Contents
, NULL
);
282 set(listgad
, MUIA_List_Quiet
, TRUE
);
283 DoMethod(listgad
, MUIM_List_Clear
);
284 ForeachNode(&brokerList
, node
)
286 D(bug("Exchange: Brokernode %s\n", node
->bc_Name
));
287 DoMethod(listgad
, MUIM_List_InsertSingle
, node
, MUIV_List_Insert_Bottom
);
289 set(listgad
, MUIA_List_Quiet
, FALSE
);
292 /*********************************************************************************************/
294 AROS_UFH3(void, broker_func
,
295 AROS_UFHA(struct Hook
*, h
, A0
),
296 AROS_UFHA(Object
* , object
, A2
),
297 AROS_UFHA(CxMsg
* , msg
, A1
))
301 D(bug("Exchange: Broker hook called\n"));
302 if (CxMsgType(msg
) == CXM_COMMAND
)
304 if (CxMsgID(msg
) == CXCMD_APPEAR
)
306 //This opens window if application was started with cx_popup=no
307 set(app
, MUIA_Application_Iconified
, FALSE
);
309 else if (CxMsgID(msg
) == CXCMD_LIST_CHG
)
317 /*********************************************************************************************/
319 AROS_UFH3(void, list_display_func
,
320 AROS_UFHA(struct Hook
* , h
, A0
),
321 AROS_UFHA(char ** , array
, A2
),
322 AROS_UFHA(struct BrokerCopy
*, node
, A1
))
326 *array
= node
->bc_Name
;
331 /*********************************************************************************************/
333 AROS_UFH3(void, list_select_func
,
334 AROS_UFHA(struct Hook
*, h
, A0
),
335 AROS_UFHA(Object
* , object
, A2
),
336 AROS_UFHA(APTR
, msg
, A1
))
340 struct BrokerCopy
*bc
;
341 DoMethod(listgad
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, (IPTR
)&bc
);
344 BOOL showHide
= (bc
->bc_Flags
& COF_SHOW_HIDE
) == 0;
345 BOOL active
= (bc
->bc_Flags
& COF_ACTIVE
) != 0;
346 nnset(textgad1
, MUIA_Text_Contents
, bc
->bc_Title
);
347 nnset(textgad2
, MUIA_Text_Contents
, bc
->bc_Descr
);
348 nnset(hidegad
, MUIA_Disabled
, showHide
);
349 nnset(showgad
, MUIA_Disabled
, showHide
);
350 nnset(cyclegad
, MUIA_Cycle_Active
, active
? 0 : 1);
356 /*********************************************************************************************/
358 AROS_UFH3(void, inform_broker_func
,
359 AROS_UFHA(struct Hook
*, h
, A0
),
360 AROS_UFHA(Object
* , object
, A2
),
361 AROS_UFHA(LONG
* , command
, A1
))
365 struct BrokerCopy
*bc
;
366 DoMethod(listgad
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, (IPTR
) &bc
);
369 D(bug("Exchange: Broker inform %s\n", bc
->bc_Node
.ln_Name
));
370 BrokerCommand(bc
->bc_Node
.ln_Name
, *command
);
376 /*********************************************************************************************/
378 static void MakeGUI(void)
381 static TEXT wintitle
[100];
384 cyclestrings
[0] = _(MSG_EXCHANGE_CYCLE_ACTIVE
);
385 cyclestrings
[1] = _(MSG_EXCHANGE_CYCLE_INACTIVE
);
386 menu
= MUI_MakeObject(MUIO_MenustripNM
, &nm
, 0);
388 broker_hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(broker_func
);
389 list_disp_hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(list_display_func
);
390 list_select_hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(list_select_func
);
391 inform_broker_hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(inform_broker_func
);
393 snprintf(wintitle
, sizeof(wintitle
), _(MSG_EXCHANGE_WINTITLE
), cx_popkey
);
395 app
= (Object
*)ApplicationObject
,
396 MUIA_Application_Title
, __(MSG_EXCHANGE_CXNAME
),
397 MUIA_Application_Version
, (IPTR
)version
,
398 MUIA_Application_Copyright
, (IPTR
)"Copyright © 1995-2009, The AROS Development TEAM",
399 MUIA_Application_Author
, (IPTR
)"The AROS Development Team",
400 MUIA_Application_Description
, __(MSG_EXCHANGE_CXDESCR
),
401 MUIA_Application_BrokerPri
, cx_pri
,
402 MUIA_Application_BrokerHook
, (IPTR
)&broker_hook
,
403 MUIA_Application_Base
, (IPTR
)"EXCHANGE",
404 MUIA_Application_SingleTask
, TRUE
,
405 MUIA_Application_Menustrip
, (IPTR
)menu
,
406 SubWindow
, (IPTR
)(wnd
= (Object
*)WindowObject
,
407 MUIA_Window_Title
, (IPTR
)wintitle
,
408 MUIA_Window_ID
, MAKE_ID('E', 'X', 'C', 'H'),
409 WindowContents
, (IPTR
)(HGroup
,
410 Child
, (IPTR
)(VGroup
,
411 GroupFrameT(_(MSG_EXCHANGE_LISTVIEW
)),
412 Child
, (IPTR
)(ListviewObject
,
413 MUIA_Listview_List
, (IPTR
)(listgad
= (Object
*)ListObject
,
415 MUIA_List_DisplayHook
, (IPTR
)&list_disp_hook
,
420 Child
, (IPTR
)(BalanceObject
, MUIA_CycleChain
, 1, End
),
421 Child
, (IPTR
)(VGroup
,
422 MUIA_HorizWeight
, 150,
423 Child
, (IPTR
)(VGroup
,
424 GroupFrameT(_(MSG_EXCHANGE_INFO
)),
425 Child
, (IPTR
)(textgad1
= (Object
*)TextObject
, TextFrame
,
426 MUIA_Background
, MUII_TextBack
, End
),
427 Child
, (IPTR
)(textgad2
= (Object
*)TextObject
, TextFrame
,
428 MUIA_Background
, MUII_TextBack
, End
),
430 Child
, (IPTR
)HVSpace
,
431 Child
, (IPTR
)(ColGroup(2),
432 MUIA_Group_SameSize
, TRUE
,
433 Child
, (IPTR
)(hidegad
= SimpleButton(_(MSG_EXCHANGE_GAD_HIDE
))),
434 Child
, (IPTR
)(showgad
= SimpleButton(_(MSG_EXCHANGE_GAD_SHOW
))),
435 Child
, (IPTR
)(cyclegad
= MUI_MakeObject(MUIO_Cycle
, NULL
, cyclestrings
)),
436 Child
, (IPTR
)(killgad
= SimpleButton(_(MSG_EXCHANGE_GAD_REMOVE
))),
444 Cleanup(NULL
); // Propably double start
447 maintask
= FindTask(NULL
);
448 get(app
, MUIA_Application_Broker
, &broker
);
449 get(app
, MUIA_Application_BrokerPort
, &brokermp
);
450 if ( ! broker
|| ! brokermp
)
451 Cleanup(_(MSG_CANT_CREATE_BROKER
));
453 popfilter
= CxFilter(cx_popkey
);
456 CxObj
*popsig
= CxSignal(maintask
, SIGBREAKB_CTRL_F
);
460 AttachCxObj(popfilter
, popsig
);
461 trans
= CxTranslate(NULL
);
462 if (trans
) AttachCxObj(popsig
, trans
);
464 AttachCxObj(broker
, popfilter
);
467 // initial entry of brokers to listgadget
470 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
471 (IPTR
)app
, 3, MUIM_Set
, MUIA_Application_Iconified
, TRUE
);
473 DoMethod(app
, MUIM_Notify
, MUIA_Application_DoubleStart
, TRUE
,
474 (IPTR
)app
, 3, MUIM_Set
, MUIA_Application_Iconified
, FALSE
);
476 // Open the window when app isn't iconified
477 DoMethod(app
, MUIM_Notify
, MUIA_Application_Iconified
, FALSE
,
478 (IPTR
)wnd
, 3, MUIM_Set
, MUIA_Window_Open
, TRUE
);
480 DoMethod(listgad
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
481 (IPTR
)listgad
, 2, MUIM_CallHook
, (IPTR
)&list_select_hook
);
483 DoMethod(cyclegad
, MUIM_Notify
, MUIA_Cycle_Active
, 0 /* Enable */,
484 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&inform_broker_hook
, CXCMD_ENABLE
);
486 DoMethod(cyclegad
, MUIM_Notify
, MUIA_Cycle_Active
, 1 /* Disable */,
487 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&inform_broker_hook
, CXCMD_DISABLE
);
489 DoMethod(hidegad
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
490 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&inform_broker_hook
, CXCMD_DISAPPEAR
);
492 DoMethod(showgad
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
493 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&inform_broker_hook
, CXCMD_APPEAR
);
495 DoMethod(killgad
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
496 (IPTR
)app
, 3, MUIM_CallHook
, (IPTR
)&inform_broker_hook
, CXCMD_KILL
);
498 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_PROJECT_QUIT
,
499 (IPTR
)app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
501 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_PROJECT_HIDE
,
502 (IPTR
)app
, 3, MUIM_Set
, MUIA_Application_Iconified
, TRUE
);
504 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_PROJECT_ICONIFY
,
505 (IPTR
)app
, 3, MUIM_Set
, MUIA_Application_Iconified
, TRUE
);
509 /*********************************************************************************************/
511 static void HandleAll(void)
515 set(app
, MUIA_Application_Iconified
, cx_popup
? FALSE
: TRUE
);
517 while((LONG
) DoMethod(app
, MUIM_Application_NewInput
, (IPTR
)&sigs
)
518 != MUIV_Application_ReturnID_Quit
)
522 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
| SIGBREAKF_CTRL_F
);
523 if (sigs
& SIGBREAKF_CTRL_C
)
527 if (sigs
& SIGBREAKF_CTRL_F
)
529 set(app
, MUIA_Application_Iconified
, FALSE
);
535 /*********************************************************************************************/
537 static void Cleanup(CONST_STRPTR txt
)
539 MUI_DisposeObject(app
);
541 FreeBrokerList(&brokerList
);
544 showSimpleMessage(txt
);
550 /*********************************************************************************************/
552 int main(int argc
, char **argv
)
554 D(bug("Exchange started\n"));
555 NewList(&brokerList
);
556 GetArguments(argc
, argv
);
564 /*********************************************************************************************/
566 ADD2INIT(Locale_Initialize
, 90);
567 ADD2EXIT(Locale_Deinitialize
, 90);