codesetslib: use '#include <SDI/...>' for global SDI includes.
[AROS.git] / workbench / libs / codesetslib / developer / examples / demo1.c
blobfa1e98cabccad979f2acbe74c74ccecb53ab62a7
1 /***************************************************************************
3 codesets.library - Amiga shared library for handling different codesets
4 Copyright (C) 2001-2005 by Alfonso [alfie] Ranieri <alforan@tin.it>.
5 Copyright (C) 2005-2010 by codesets.library Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 codesets.library project: http://sourceforge.net/projects/codesetslib/
19 Most of the code included in this file was relicensed from GPL to LGPL
20 from the source code of SimpleMail (http://www.sf.net/projects/simplemail)
21 with full permissions by its authors.
23 $Id$
25 ***************************************************************************/
27 #include <proto/codesets.h>
29 #if defined(__MORPHOS__)
30 #if defined(USE_INLINE_STDARG)
31 #undef USE_INLINE_STDARG
32 #endif
33 #endif
34 #define INTUITION_NO_INLINE_STDARG
35 #define MUIMASTER_NO_INLINE_STDARG
37 #include <clib/alib_protos.h>
39 #include <proto/exec.h>
40 #include <proto/dos.h>
41 #include <proto/utility.h>
42 #include <proto/muimaster.h>
43 #include <proto/intuition.h>
44 #include <libraries/asl.h>
45 #include <libraries/gadtools.h>
46 #include <libraries/mui.h>
47 #include <mui/TextEditor_mcc.h>
49 #include <stdio.h>
50 #include <string.h>
52 #include <SDI/SDI_compiler.h>
53 #include <SDI/SDI_hook.h>
54 #include <SDI/SDI_stdarg.h>
56 /***********************************************************************/
58 ** Some macro
61 #ifndef MAKE_ID
62 #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
63 #endif
65 #if defined(__amigaos4__)
66 #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL))
67 #define DROPINTERFACE(iface) (DropInterface((struct Interface *)iface), iface = NULL)
68 #else
69 #define GETINTERFACE(iface, base) TRUE
70 #define DROPINTERFACE(iface)
71 #endif
73 /***********************************************************************/
75 ** Globals
78 char __ver[] = "\0$VER: CodesetsDemo1 1.0 (10.11.2004)";
79 long __stack = 8192;
81 struct Library *MUIMasterBase = NULL;
82 struct Library *CodesetsBase = NULL;
83 #ifdef __AROS__
84 struct UtilityBase *UtilityBase = NULL;
85 #else
86 struct Library *UtilityBase = NULL;
87 #endif
89 #if defined(__amigaos4__)
90 struct MUIMasterIFace *IMUIMaster = NULL;
91 struct CodesetsIFace *ICodesets = NULL;
92 struct IntuitionIFace *IIntuition = NULL;
93 struct UtilityIFace *IUtility = NULL;
94 struct Library *IntuitionBase = NULL;
95 #else
96 struct IntuitionBase *IntuitionBase = NULL;
97 #endif
100 struct MUI_CustomClass *appClass, *popupCodesetsClass, *editorClass;
102 /***********************************************************************/
104 ** MUI stuff
107 /* App attributes */
108 #define MUIA_App_Win (TAG_USER+1)
110 /* App methods */
111 #define MUIM_App_DisposeWin (TAG_USER+2)
112 #define MUIM_App_About (TAG_USER+3)
114 struct MUIP_App_DisposeWin
116 ULONG MethodID;
117 Object *win;
120 /* Editor attributes */
121 #define MUIA_Editor_CodesetsObj (TAG_USER+5)
123 /* Editor methods */
124 #define MUIM_Editor_Load (TAG_USER+6)
125 #define MUIM_Editor_Save (TAG_USER+7)
127 struct MUIP_Editor_Load
129 ULONG MethodID;
130 ULONG plain;
133 /* Classes object creation macros */
134 #define appObject NewObject(appClass->mcc_Class,NULL
135 #define editorObject NewObject(editorClass->mcc_Class,NULL
136 #define popupCodesetObject NewObject(popupCodesetsClass->mcc_Class,NULL
138 /***********************************************************************/
140 ** Usual DoSuperNew funct
143 /// DoSuperNew
144 // Calls parent NEW method within a subclass
145 #if !defined(__MORPHOS__)
146 #ifdef __AROS__
147 #define DoSuperNew(cl, obj, ...) DoSuperNewTags(cl, obj, NULL, __VA_ARGS__)
148 #else
149 Object * STDARGS VARARGS68K DoSuperNew(struct IClass *cl, Object *obj, ...)
151 Object *rc;
152 VA_LIST args;
154 VA_START(args, obj);
155 rc = (Object *)DoSuperMethod(cl, obj, OM_NEW, VA_ARG(args, ULONG), NULL);
156 VA_END(args);
158 return rc;
160 #endif
161 #endif
164 /***********************************************************************/
166 ** Codesets popup open window hook funct
169 HOOKPROTONH(popupWindowFun, void, Object *pop, Object *win)
171 set(win,MUIA_Window_DefaultObject,pop);
173 MakeStaticHook(popupWindowHook, popupWindowFun);
175 /***********************************************************************/
177 ** Codesets popup open hook funct
178 ** Sets the active entry in the list
181 HOOKPROTONH(popupOpenFun, ULONG, Object *list, Object *str)
183 STRPTR s = NULL, x;
184 int i;
186 get(str, MUIA_Text_Contents, (IPTR *)&s);
188 if(s != NULL)
190 for (i = 0; ;i++)
192 DoMethod(list,MUIM_List_GetEntry,i,&x);
193 if (x == NULL)
195 set(list,MUIA_List_Active,MUIV_List_Active_Off);
196 break;
198 else
199 if (stricmp(x,s) == 0)
201 set(list,MUIA_List_Active,i);
202 break;
207 return TRUE;
209 MakeStaticHook(popupOpenHook, popupOpenFun);
211 /***********************************************************************/
213 ** Codesets popup close hook funct
214 ** Set the string contents
217 HOOKPROTONH(popupCloseFun, void, Object *list, Object *str)
219 STRPTR e;
221 DoMethod(list,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&e);
222 set(str,MUIA_Text_Contents,e);
224 MakeStaticHook(popupCloseHook, popupCloseFun);
226 /***********************************************************************/
228 ** Codesets popup new method
231 static Object *
232 mpopupNew(struct IClass *cl,Object *obj,struct opSet *msg)
234 Object *str, *bt, *lv, *l;
236 if((obj = (Object *)DoSuperNew(cl,obj,
238 MUIA_Popstring_String, str = TextObject,
239 TextFrame,
240 MUIA_Background, MUII_TextBack,
241 End,
243 MUIA_Popstring_Button, bt = MUI_MakeObject(MUIO_PopButton,MUII_PopUp),
245 MUIA_Popobject_Object, lv = ListviewObject,
246 MUIA_Listview_List, l = ListObject,
247 MUIA_Frame, MUIV_Frame_InputList,
248 MUIA_Background, MUII_ListBack,
249 MUIA_List_AutoVisible, TRUE,
250 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
251 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
252 End,
253 End,
254 MUIA_Popobject_WindowHook, &popupWindowHook,
255 MUIA_Popobject_StrObjHook, &popupOpenHook,
256 MUIA_Popobject_ObjStrHook, &popupCloseHook,
258 TAG_MORE,msg->ops_AttrList)))
260 struct codeset *codeset;
261 STRPTR *array;
263 set(bt,MUIA_CycleChain,TRUE);
264 DoMethod(lv,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,obj,2,MUIM_Popstring_Close,TRUE);
266 /* Build list of available codesets */
267 if((array = CodesetsSupportedA(NULL)))
269 DoMethod(l,MUIM_List_Insert,array,-1,MUIV_List_Insert_Sorted);
270 CodesetsFreeA(array,NULL);
272 else SetSuperAttrs(cl,obj,MUIA_Disabled,TRUE,TAG_DONE);
274 /* Use the default codeset */
275 codeset = CodesetsFindA(NULL,NULL);
276 set(str,MUIA_Text_Contents,codeset->name);
279 return obj;
282 /***********************************************************************/
284 ** Codesets popup dispatcher
287 DISPATCHER(popupDispatcher)
289 switch (msg->MethodID)
291 case OM_NEW: return (IPTR)mpopupNew(cl,obj,(APTR)msg);
292 default: return DoSuperMethodA(cl,obj,msg);
296 /***********************************************************************/
298 ** Editor instance
301 struct editorData
303 Object *codesetsObj;
304 struct FileRequester *req;
307 /***********************************************************************/
309 ** Editor new method
312 static Object *
313 meditorNew(struct IClass *cl,Object *obj,struct opSet *msg)
315 struct FileRequester *req;
317 if ((req = MUI_AllocAslRequest(ASL_FileRequest,NULL)) &&
318 (obj = (Object *)DoSuperNew(cl,obj,
319 TAG_MORE,msg->ops_AttrList)))
321 struct editorData *data = INST_DATA(cl,obj);
323 data->codesetsObj = (Object *)GetTagData(MUIA_Editor_CodesetsObj, 0, msg->ops_AttrList);
325 data->req = req;
327 else
329 if (req) MUI_FreeAslRequest(req);
332 return obj;
335 /***********************************************************************/
337 ** Editor dispose method
340 static ULONG
341 meditorDispose(struct IClass *cl,Object *obj,Msg msg)
343 struct editorData *data = INST_DATA(cl,obj);
345 if (data->req) MUI_FreeAslRequest(data->req);
347 return DoSuperMethodA(cl,obj,msg);
350 /***********************************************************************/
352 ** Editor load method
355 static ULONG
356 meditorLoad(struct IClass *cl,Object *obj,struct MUIP_Editor_Load *msg)
358 struct editorData *data = INST_DATA(cl,obj);
360 set(_app(obj),MUIA_Application_Sleep,TRUE);
361 SetSuperAttrs(cl,obj,MUIA_TextEditor_Quiet,FALSE,TAG_DONE);
363 /* Request file name */
364 if (MUI_AslRequestTags(data->req,ASLFR_TitleText,msg->plain ?
365 "Select a file to load" : "Select a file to load as UTF8",TAG_DONE))
367 char fname[256];
368 BPTR lock;
370 strlcpy(fname,data->req->fr_Drawer,sizeof(fname));
371 AddPart(fname,data->req->fr_File,sizeof(fname));
373 /* Get size */
374 if((lock = Lock(fname,SHARED_LOCK)))
376 struct FileInfoBlock *fib;
377 ULONG go = FALSE, size = 0;
379 if((fib = AllocDosObject(DOS_FIB,NULL)))
381 if (Examine(lock,fib))
383 size = fib->fib_Size;
384 go = TRUE;
387 FreeDosObject(DOS_FIB,fib);
390 UnLock(lock);
392 if (go)
394 DoSuperMethod(cl,obj,MUIM_TextEditor_ClearText);
396 if (size>0)
398 STRPTR buf;
400 /* Alloc whole file buf */
401 if((buf = AllocMem(size+1,MEMF_ANY)))
403 BPTR file;
405 if((file = Open(fname,MODE_OLDFILE)))
407 LONG r;
409 r = Read(file,buf,size);
410 if(r >= 0)
412 buf[r] = 0;
414 if (msg->plain)
416 /* If plain just set it */
417 set(obj,MUIA_TextEditor_Contents,buf);
419 else
421 struct codeset *codeset;
422 STRPTR str;
423 STRPTR cname = NULL;
425 /* Get used codeset */
426 get(data->codesetsObj, MUIA_Text_Contents, (IPTR *)&cname);
427 codeset = CodesetsFindA(cname,NULL);
429 /* Convert */
430 str = CodesetsUTF8ToStr(CSA_Source, (Tag)buf,
431 CSA_SourceCodeset, (Tag)codeset,
432 TAG_DONE);
433 if (str)
435 SetSuperAttrs(cl,obj,MUIA_TextEditor_Contents,str,TAG_DONE);
436 CodesetsFreeA(str,NULL);
441 Close(file);
444 FreeMem(buf,size+1);
448 SetSuperAttrs(cl,obj,MUIA_TextEditor_CursorX, 0,
449 MUIA_TextEditor_CursorY, 0,
450 TAG_DONE);
455 SetSuperAttrs(cl,obj,MUIA_TextEditor_Quiet,FALSE,TAG_DONE);
456 set(_app(obj),MUIA_Application_Sleep,FALSE);
458 return 0;
461 /***********************************************************************/
463 ** Editor save method
466 static ULONG
467 meditorSave(struct IClass *cl, Object *obj, UNUSED Msg msg)
469 struct editorData *data = INST_DATA(cl,obj);
470 STRPTR text;
472 set(_app(obj),MUIA_Application_Sleep,TRUE);
474 /* Get editor text */
475 if((text = (STRPTR)DoSuperMethod(cl,obj,MUIM_TextEditor_ExportText)))
477 struct codeset *codeset;
478 UTF8 *utf8;
479 STRPTR cname = NULL;
480 ULONG dlen;
482 /* Get current user codeset */
483 get(data->codesetsObj, MUIA_Text_Contents, (IPTR *)&cname);
484 codeset = CodesetsFindA(cname,NULL);
486 /* Convert text as utf8 */
487 if((utf8 = CodesetsUTF8Create(CSA_Source, (Tag)text,
488 CSA_SourceCodeset, (Tag)codeset,
489 CSA_DestLenPtr, (Tag)&dlen,
490 TAG_DONE)))
492 /* Save converted text to a file */
494 if (MUI_AslRequestTags(data->req,ASLFR_DoSaveMode,TRUE,ASLFR_TitleText,"Select a file to save as UTF8",TAG_DONE))
496 char fname[256];
497 BPTR file;
499 strlcpy(fname,data->req->fr_Drawer,sizeof(fname));
500 AddPart(fname,data->req->fr_File,sizeof(fname));
502 if((file = Open(fname,MODE_NEWFILE)))
504 Write(file,utf8,dlen);
505 Close(file);
509 /* Free converted string */
510 CodesetsFreeA(utf8,NULL);
513 FreeVec(text);
516 set(_app(obj),MUIA_Application_Sleep,FALSE);
518 return 0;
521 /***********************************************************************/
523 ** Editor dispatcher
526 DISPATCHER(editorDispatcher)
528 switch (msg->MethodID)
530 case OM_NEW: return (IPTR)meditorNew(cl,obj,(APTR)msg);
531 case OM_DISPOSE: return meditorDispose(cl,obj,(APTR)msg);
532 case MUIM_Editor_Save: return meditorSave(cl,obj,(APTR)msg);
533 case MUIM_Editor_Load: return meditorLoad(cl,obj,(APTR)msg);
534 default: return DoSuperMethodA(cl,obj,msg);
538 /***********************************************************************/
540 ** App instance
543 struct appData
545 Object *win;
546 Object *about;
547 Object *aboutMUI;
548 Object *config;
551 /***********************************************************************/
553 ** App new method
556 /* Menus */
557 #define MTITLE(t) {NM_TITLE,(STRPTR)(t),0,0,0,0}
558 #define MITEM(t,d) {NM_ITEM,(STRPTR)(t),0,0,0,(APTR)(d)}
559 #define MBAR {NM_ITEM,(STRPTR)NM_BARLABEL,0,0,0,NULL}
560 #define MEND {NM_END,NULL,0,0,0,NULL}
562 enum
564 MABOUT = 1,
565 MABOUTMUI,
566 MMUI,
567 MQUIT,
570 static struct NewMenu appMenu[] =
572 MTITLE("Project"),
573 MITEM("?\0About...",MABOUT),
574 MITEM("M\0About MUI...",MABOUTMUI),
575 MBAR,
576 MITEM("Q\0Quit",MQUIT),
578 MTITLE("Editor"),
579 MITEM("M\0MUI Settings...",MMUI),
581 MEND
584 static Object *
585 mappNew(struct IClass *cl,Object *obj,struct opSet *msg)
587 Object *strip, *win, *codesets = NULL, *editor, *sb, *loadPlain, *loadUTF8, *save, *cancel;
589 codesets = popupCodesetObject, End;
591 if((obj = (Object *)DoSuperNew(cl,obj,
592 MUIA_Application_Title, "Codesets Demo1",
593 MUIA_Application_Version, "$VER: CodesetsDemo1 1.0 (10.11.2004)",
594 MUIA_Application_Copyright, "Copyright 2004 by Alfonso Ranieri",
595 MUIA_Application_Author, "Alfonso Ranieri <alforan@tin.it>",
596 MUIA_Application_Description, "Codesets example",
597 MUIA_Application_Base, "CODESETSEXAMPLE",
598 MUIA_Application_Menustrip, strip = MUI_MakeObject(MUIO_MenustripNM,appMenu,MUIO_MenustripNM_CommandKeyCheck),
600 SubWindow, win = WindowObject,
601 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
602 MUIA_Window_Title, "Codesets Demo1",
603 WindowContents, VGroup,
605 Child, HGroup,
606 Child, Label2("Charset"),
607 Child, codesets,
608 End,
610 Child, HGroup,
611 MUIA_Group_Horiz, TRUE,
612 MUIA_Group_Spacing, 0,
613 Child, editor = editorObject,
614 MUIA_Editor_CodesetsObj, codesets,
615 End,
616 Child, sb = ScrollbarObject, End,
617 End,
619 Child, HGroup,
620 Child, loadPlain = MUI_MakeObject(MUIO_Button,"Load _plain"),
621 Child, RectangleObject, MUIA_Weight, 50, End,
622 Child, loadUTF8 = MUI_MakeObject(MUIO_Button,"_Load utf8"),
623 Child, RectangleObject, MUIA_Weight, 50, End,
624 Child, save = MUI_MakeObject(MUIO_Button,"_Save utf8"),
625 Child, RectangleObject, MUIA_Weight, 50, End,
626 Child, cancel = MUI_MakeObject(MUIO_Button,"_Cancel"),
627 End,
629 End,
630 End,
631 TAG_MORE,msg->ops_AttrList)))
633 struct appData *data = INST_DATA(cl,obj);
634 data->win = win;
636 set(editor,MUIA_TextEditor_Slider,sb);
638 set(loadPlain,MUIA_CycleChain,TRUE);
639 set(loadUTF8,MUIA_CycleChain,TRUE);
640 set(save,MUIA_CycleChain,TRUE);
641 set(cancel,MUIA_CycleChain,TRUE);
643 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,
644 MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
646 DoMethod(loadPlain,MUIM_Notify,MUIA_Pressed,FALSE,editor,2,MUIM_Editor_Load,TRUE);
647 DoMethod(loadUTF8,MUIM_Notify,MUIA_Pressed,FALSE,editor,2,MUIM_Editor_Load,FALSE);
648 DoMethod(save,MUIM_Notify,MUIA_Pressed,FALSE,editor,1,MUIM_Editor_Save);
649 DoMethod(cancel,MUIM_Notify,MUIA_Pressed,FALSE,MUIV_Notify_Application,2,
650 MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
652 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MABOUT),MUIM_Notify,
653 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,1,MUIM_App_About);
655 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MABOUTMUI),MUIM_Notify,
656 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,1,MUIM_Application_AboutMUI);
658 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MQUIT),MUIM_Notify,
659 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,2,MUIM_Application_ReturnID,
660 MUIV_Application_ReturnID_Quit);
662 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MMUI),MUIM_Notify,
663 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,2,MUIM_Application_OpenConfigWindow,0);
665 set(win,MUIA_Window_Open,TRUE);
668 return obj;
671 /***********************************************************************/
673 ** App dispose win method
676 static ULONG
677 mappDisposeWin(struct IClass *cl,Object *obj,struct MUIP_App_DisposeWin *msg)
679 struct appData *data = INST_DATA(cl,obj);
680 Object *win = msg->win;
682 set(win,MUIA_Window_Open,FALSE);
683 DoSuperMethod(cl,obj,OM_REMMEMBER,win);
684 MUI_DisposeObject(win);
686 if (win==data->about) data->about = NULL;
687 else if (win==data->aboutMUI) data->aboutMUI = NULL;
689 return 0;
692 /***********************************************************************/
694 ** App about method
697 static ULONG
698 mappAbout(struct IClass *cl,Object *obj,UNUSED Msg msg)
700 struct appData *data = INST_DATA(cl,obj);
702 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,TRUE,TAG_DONE);
704 if (!data->about)
706 Object *ok;
708 if((data->about = WindowObject,
709 MUIA_Window_RefWindow, data->win,
710 MUIA_Window_Title, "About Codesets Demo1",
711 WindowContents, VGroup,
712 Child, TextObject,
713 MUIA_Text_Contents, "\n"
714 "Codesets Demo1\n"
715 "Copyright 2004 by Alfonso Ranieri <alforan@tin.it>\n",
716 MUIA_Text_PreParse, MUIX_C,
717 End,
718 Child, RectangleObject, MUIA_Weight, 0, MUIA_Rectangle_HBar, TRUE, End,
719 Child, HGroup,
720 Child, RectangleObject, MUIA_Weight, 200, End,
721 Child, ok = MUI_MakeObject(MUIO_Button,"_OK"),
722 Child, RectangleObject, MUIA_Weight, 200, End,
723 End,
724 End,
725 End))
727 DoSuperMethod(cl,obj,OM_ADDMEMBER,data->about);
729 set(data->about,MUIA_Window_ActiveObject,ok);
731 DoMethod(data->about,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,obj,5,
732 MUIM_Application_PushMethod,obj,2,MUIM_App_DisposeWin,data->about);
734 DoMethod(ok,MUIM_Notify,MUIA_Pressed,FALSE,obj,5,
735 MUIM_Application_PushMethod,obj,2,MUIM_App_DisposeWin,data->about);
739 set(data->about,MUIA_Window_Open,TRUE);
741 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,FALSE,TAG_DONE);
743 return 0;
746 /***********************************************************************/
748 ** App MUI settings method
751 static ULONG
752 mappOpenMUIConfigWindow(struct IClass *cl,Object *obj,Msg msg)
754 ULONG res;
756 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,TRUE,TAG_DONE);
757 res = DoSuperMethodA(cl,obj,msg);
758 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,FALSE,TAG_DONE);
760 return res;
763 /***********************************************************************/
765 ** App dispatcher
768 DISPATCHER(appDispatcher)
770 switch (msg->MethodID)
772 case OM_NEW: return (IPTR)mappNew(cl,obj,(APTR)msg);
773 case MUIM_App_DisposeWin: return mappDisposeWin(cl,obj,(APTR)msg);
774 case MUIM_App_About: return mappAbout(cl,obj,(APTR)msg);
775 case MUIM_Application_OpenConfigWindow: return mappOpenMUIConfigWindow(cl,obj,(APTR)msg);
776 default: return DoSuperMethodA(cl,obj,msg);
780 /***********************************************************************/
782 ** Main
786 main(UNUSED int argc,char **argv)
788 int res = RETURN_FAIL;
790 if((IntuitionBase = (APTR)OpenLibrary("intuition.library", 39)) && // open intuition.library
791 GETINTERFACE(IIntuition, IntuitionBase))
793 if((UtilityBase = (APTR)OpenLibrary("utility.library", 39)) && // open utility.library
794 GETINTERFACE(IUtility, UtilityBase))
796 if((CodesetsBase = OpenLibrary(CODESETSNAME, CODESETSVER)) && // open codesets.library
797 GETINTERFACE(ICodesets, CodesetsBase))
799 /* Open muimaster.library */
800 if((MUIMasterBase = OpenLibrary("muimaster.library",19)) &&
801 GETINTERFACE(IMUIMaster, MUIMasterBase))
803 /* Create classes */
804 if ((appClass = MUI_CreateCustomClass(NULL, MUIC_Application, NULL, sizeof(struct appData), ENTRY(appDispatcher))) &&
805 (popupCodesetsClass = MUI_CreateCustomClass(NULL, MUIC_Popobject, NULL, 0, ENTRY(popupDispatcher))) &&
806 (editorClass = MUI_CreateCustomClass(NULL, MUIC_TextEditor, NULL, sizeof(struct editorData), ENTRY(editorDispatcher))))
808 Object *app;
810 /* Create application */
811 if((app = appObject, End))
813 /* Here we go */
814 ULONG sigs = 0;
816 while (DoMethod(app,MUIM_Application_NewInput,&sigs) != (ULONG)MUIV_Application_ReturnID_Quit)
818 if (sigs)
820 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
821 if (sigs & SIGBREAKF_CTRL_C) break;
825 MUI_DisposeObject(app);
827 res = RETURN_OK;
829 else
831 printf("%s: can't create application\n",argv[0]);
834 MUI_DeleteCustomClass(popupCodesetsClass);
835 MUI_DeleteCustomClass(editorClass);
836 MUI_DeleteCustomClass(appClass);
838 else
840 if (appClass)
842 if (popupCodesetsClass) MUI_DeleteCustomClass(popupCodesetsClass);
843 MUI_DeleteCustomClass(appClass);
846 printf("%s: can't create custom classes\n",argv[0]);
849 DROPINTERFACE(IMUIMaster);
850 CloseLibrary(MUIMasterBase);
852 else
854 printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
855 res = RETURN_ERROR;
858 DROPINTERFACE(ICodesets);
859 CloseLibrary(CodesetsBase);
861 else
863 printf("%s: Can't open codesets.library ver %d or higher.\n", argv[0], CODESETSVER);
864 res = RETURN_ERROR;
867 DROPINTERFACE(IUtility);
868 CloseLibrary((struct Library *)UtilityBase);
871 DROPINTERFACE(IIntuition);
872 CloseLibrary((struct Library *)IntuitionBase);
875 return res;
878 /***********************************************************************/