Stunt: get codesetslib from its own Sourceforge repository.
[cake.git] / workbench / libs / codesetslib / developer / examples / demo1.c
blob296e132cad881081bcb22b957ed91557e8eac57e
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-2007 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 <clib/alib_protos.h>
29 #include <proto/exec.h>
30 #include <proto/dos.h>
31 #include <proto/utility.h>
32 #include <proto/muimaster.h>
33 #include <proto/intuition.h>
34 #include <libraries/asl.h>
35 #include <libraries/gadtools.h>
36 #include <libraries/mui.h>
37 #include <mui/Textinput_mcc.h>
38 #include <mui/TextEditor_mcc.h>
40 #define USE_INLINE_STDARG
42 // tempoarly disable the INLINE STDARG define here
43 #if defined(NO_INLINE_STDARG)
44 #undef NO_INLINE_STDARG
45 #include <proto/codesets.h>
46 #define NO_INLINE_STDARG
47 #elif defined(NO_PPCINLINE_STDARG)
48 #undef NO_PPCINLINE_STDARG
49 #include <proto/codesets.h>
50 #define NO_PPCINLINE_STDARG
51 #else
52 #include <proto/codesets.h>
53 #endif
55 #include <stdio.h>
56 #include <string.h>
58 #include "SDI_compiler.h"
59 #include "SDI_hook.h"
60 #include "SDI_stdarg.h"
62 /***********************************************************************/
64 ** Some macro
67 #ifndef MAKE_ID
68 #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
69 #endif
71 #if defined(__amigaos4__)
72 #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL))
73 #define DROPINTERFACE(iface) (DropInterface((struct Interface *)iface), iface = NULL)
74 #else
75 #define GETINTERFACE(iface, base) TRUE
76 #define DROPINTERFACE(iface)
77 #endif
79 /***********************************************************************/
81 ** Globals
84 char __ver[] = "\0$VER: CodesetsDemo1 1.0 (10.11.2004)";
85 long __stack = 8192;
87 struct Library *MUIMasterBase = NULL;
88 struct Library *CodesetsBase = NULL;
89 struct Library *UtilityBase = NULL;
91 #if defined(__amigaos4__)
92 struct MUIMasterIFace *IMUIMaster = NULL;
93 struct CodesetsIFace *ICodesets = NULL;
94 struct IntuitionIFace *IIntuition = NULL;
95 struct UtilityIFace *IUtility = NULL;
96 struct Library *IntuitionBase = NULL;
97 #else
98 struct IntuitionBase *IntuitionBase = NULL;
99 #endif
102 struct MUI_CustomClass *appClass, *popupCodesetsClass, *editorClass;
104 /***********************************************************************/
106 ** MUI stuff
109 /* App attributes */
110 #define MUIA_App_Win (TAG_USER+1)
112 /* App methods */
113 #define MUIM_App_DisposeWin (TAG_USER+2)
114 #define MUIM_App_About (TAG_USER+3)
115 #define MUIM_App_AboutMUI (TAG_USER+4)
117 struct MUIP_App_DisposeWin
119 ULONG MethodID;
120 Object *win;
123 /* Editor attributes */
124 #define MUIA_Editor_CodesetsObj (TAG_USER+5)
126 /* Editor methods */
127 #define MUIM_Editor_Load (TAG_USER+6)
128 #define MUIM_Editor_Save (TAG_USER+7)
130 struct MUIP_Editor_Load
132 ULONG MethodID;
133 ULONG plain;
136 /* Classes object creation macros */
137 #define appObject NewObject(appClass->mcc_Class,NULL
138 #define editorObject NewObject(editorClass->mcc_Class,NULL
139 #define popupCodesetObject NewObject(popupCodesetsClass->mcc_Class,NULL
141 /***********************************************************************/
143 ** Usual DoSuperNew funct
146 /// DoSuperNew
147 // Calls parent NEW method within a subclass
148 #if !defined(__MORPHOS__)
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
163 /***********************************************************************/
165 ** Codesets popup open window hook funct
168 HOOKPROTONH(popupWindowFun, void, Object *pop, Object *win)
170 set(win,MUIA_Window_DefaultObject,pop);
172 MakeStaticHook(popupWindowHook, popupWindowFun);
174 /***********************************************************************/
176 ** Codesets popup open hook funct
177 ** Sets the active entry in the list
180 HOOKPROTONH(popupOpenFun, ULONG, Object *list, Object *str)
182 STRPTR s, x;
183 int i;
185 get(str, MUIA_Textinput_Contents, (ULONG)&s);
187 for (i = 0; ;i++)
189 DoMethod(list,MUIM_List_GetEntry,i,&x);
190 if (!x)
192 set(list,MUIA_List_Active,MUIV_List_Active_Off);
193 break;
195 else
196 if (!stricmp(x,s))
198 set(list,MUIA_List_Active,i);
199 break;
203 return TRUE;
205 MakeStaticHook(popupOpenHook, popupOpenFun);
207 /***********************************************************************/
209 ** Codesets popup close hook funct
210 ** Set the string contents
213 HOOKPROTONH(popupCloseFun, void, Object *list, Object *str)
215 STRPTR e;
217 DoMethod(list,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&e);
218 set(str,MUIA_Textinput_Contents,e);
220 MakeStaticHook(popupCloseHook, popupCloseFun);
222 /***********************************************************************/
224 ** Codesets popup new method
227 static ULONG
228 mpopupNew(struct IClass *cl,Object *obj,struct opSet *msg)
230 Object *str, *bt, *lv, *l;
232 if((obj = (Object *)DoSuperNew(cl,obj,
234 MUIA_Popstring_String, str = TextinputObject,
235 MUIA_ControlChar, (ULONG)'h',
236 MUIA_CycleChain, TRUE,
237 StringFrame,
238 MUIA_Textinput_AdvanceOnCR, TRUE,
239 MUIA_Textinput_MaxLen, 256,
240 End,
242 MUIA_Popstring_Button, bt = MUI_MakeObject(MUIO_PopButton,MUII_PopUp),
244 MUIA_Popobject_Object, lv = ListviewObject,
245 MUIA_Listview_List, l = ListObject,
246 MUIA_Frame, MUIV_Frame_InputList,
247 MUIA_Background, MUII_ListBack,
248 MUIA_List_AutoVisible, TRUE,
249 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
250 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
251 End,
252 End,
253 MUIA_Popobject_WindowHook, &popupWindowHook,
254 MUIA_Popobject_StrObjHook, &popupOpenHook,
255 MUIA_Popobject_ObjStrHook, &popupCloseHook,
257 TAG_MORE,msg->ops_AttrList)))
259 struct codeset *codeset;
260 STRPTR *array;
262 set(bt,MUIA_CycleChain,TRUE);
263 DoMethod(lv,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,obj,2,MUIM_Popstring_Close,TRUE);
265 /* Build list of available codesets */
266 if((array = CodesetsSupportedA(NULL)))
268 DoMethod(l,MUIM_List_Insert,array,-1,MUIV_List_Insert_Sorted);
269 CodesetsFreeA(array,NULL);
271 else SetSuperAttrs(cl,obj,MUIA_Disabled,TRUE,TAG_DONE);
273 /* Use the default codeset */
274 codeset = CodesetsFindA(NULL,NULL);
275 set(str,MUIA_Textinput_Contents,codeset->name);
278 return (ULONG)obj;
281 /***********************************************************************/
283 ** Codesets popup dispatcher
286 DISPATCHERPROTO(popupDispatcher)
288 switch (msg->MethodID)
290 case OM_NEW: return mpopupNew(cl,obj,(APTR)msg);
291 default: return DoSuperMethodA(cl,obj,msg);
295 /***********************************************************************/
297 ** Editor instance
300 struct editorData
302 Object *codesetsObj;
303 struct FileRequester *req;
306 /***********************************************************************/
308 ** Editor new method
311 static ULONG
312 meditorNew(struct IClass *cl,Object *obj,struct opSet *msg)
314 struct FileRequester *req;
316 if ((req = MUI_AllocAslRequest(ASL_FileRequest,NULL)) &&
317 (obj = (Object *)DoSuperNew(cl,obj,
318 TAG_MORE,msg->ops_AttrList)))
320 struct editorData *data = INST_DATA(cl,obj);
322 data->codesetsObj = (Object *)GetTagData(MUIA_Editor_CodesetsObj, 0, msg->ops_AttrList);
324 data->req = req;
326 else
328 if (req) MUI_FreeAslRequest(req);
331 return (ULONG)obj;
334 /***********************************************************************/
336 ** Editor dispose method
339 static ULONG
340 meditorDispose(struct IClass *cl,Object *obj,Msg msg)
342 struct editorData *data = INST_DATA(cl,obj);
344 if (data->req) MUI_FreeAslRequest(data->req);
346 return DoSuperMethodA(cl,obj,msg);
349 /***********************************************************************/
351 ** Editor load method
354 static ULONG
355 meditorLoad(struct IClass *cl,Object *obj,struct MUIP_Editor_Load *msg)
357 struct editorData *data = INST_DATA(cl,obj);
359 set(_app(obj),MUIA_Application_Sleep,TRUE);
360 SetSuperAttrs(cl,obj,MUIA_TextEditor_Quiet,FALSE,TAG_DONE);
362 /* Request file name */
363 if (MUI_AslRequestTags(data->req,ASLFR_TitleText,msg->plain ?
364 "Select a file to load" : "Select a file to load as UTF8",TAG_DONE))
366 char fname[256];
367 BPTR lock;
369 strcpy(fname,data->req->fr_Drawer);
370 AddPart(fname,data->req->fr_File,sizeof(fname));
372 /* Get size */
373 if((lock = Lock(fname,SHARED_LOCK)))
375 struct FileInfoBlock *fib;
376 ULONG go = FALSE, size = 0;
378 if((fib = AllocDosObject(DOS_FIB,NULL)))
380 if (Examine(lock,fib))
382 size = fib->fib_Size;
383 go = TRUE;
386 FreeDosObject(DOS_FIB,fib);
389 UnLock(lock);
391 if (go)
393 DoSuperMethod(cl,obj,MUIM_TextEditor_ClearText);
395 if (size>0)
397 STRPTR buf;
399 /* Alloc whole file buf */
400 if((buf = AllocMem(size+1,MEMF_ANY)))
402 BPTR file;
404 if((file = Open(fname,MODE_OLDFILE)))
406 LONG r;
408 r = Read(file,buf,size);
409 if(r >= 0)
411 buf[r] = 0;
413 if (msg->plain)
415 /* If plain just set it */
416 set(obj,MUIA_TextEditor_Contents,buf);
418 else
420 struct codeset *codeset;
421 STRPTR str;
422 STRPTR cname;
424 /* Get used codeset */
425 get(data->codesetsObj, MUIA_Textinput_Contents, (ULONG)&cname);
426 codeset = CodesetsFindA(cname,NULL);
428 /* Convert */
429 str = CodesetsUTF8ToStr(CSA_Source, buf,
430 CSA_SourceCodeset, codeset,
431 TAG_DONE);
432 if (str)
434 SetSuperAttrs(cl,obj,MUIA_TextEditor_Contents,str,TAG_DONE);
435 CodesetsFreeA(str,NULL);
440 Close(file);
443 FreeMem(buf,size+1);
447 SetSuperAttrs(cl,obj,MUIA_TextEditor_CursorX, 0,
448 MUIA_TextEditor_CursorY, 0,
449 TAG_DONE);
454 SetSuperAttrs(cl,obj,MUIA_TextEditor_Quiet,FALSE,TAG_DONE);
455 set(_app(obj),MUIA_Application_Sleep,FALSE);
457 return 0;
460 /***********************************************************************/
462 ** Editor save method
465 static ULONG
466 meditorSave(struct IClass *cl, Object *obj, Msg msg)
468 struct editorData *data = INST_DATA(cl,obj);
469 STRPTR text;
471 set(_app(obj),MUIA_Application_Sleep,TRUE);
473 /* Get editor text */
474 if((text = (STRPTR)DoSuperMethod(cl,obj,MUIM_TextEditor_ExportText)))
476 struct codeset *codeset;
477 UTF8 *utf8;
478 STRPTR cname;
479 ULONG dlen;
481 /* Get current user codeset */
482 get(data->codesetsObj, MUIA_Textinput_Contents, (ULONG)&cname);
483 codeset = CodesetsFindA(cname,NULL);
485 /* Convert text as utf8 */
486 if((utf8 = CodesetsUTF8Create(CSA_Source, text,
487 CSA_SourceCodeset, codeset,
488 CSA_DestLenPtr, &dlen,
489 TAG_DONE)))
491 /* Save converted text to a file */
493 if (MUI_AslRequestTags(data->req,ASLFR_DoSaveMode,TRUE,ASLFR_TitleText,"Select a file to save as UTF8",TAG_DONE))
495 char fname[256];
496 BPTR file;
498 strcpy(fname,data->req->fr_Drawer);
499 AddPart(fname,data->req->fr_File,sizeof(fname));
501 if((file = Open(fname,MODE_NEWFILE)))
503 Write(file,utf8,dlen);
504 Close(file);
508 /* Free converted string */
509 CodesetsFreeA(utf8,NULL);
512 FreeVec(text);
515 set(_app(obj),MUIA_Application_Sleep,FALSE);
517 return 0;
520 /***********************************************************************/
522 ** Editor dispatcher
525 DISPATCHERPROTO(editorDispatcher)
527 switch (msg->MethodID)
529 case OM_NEW: return meditorNew(cl,obj,(APTR)msg);
530 case OM_DISPOSE: return meditorDispose(cl,obj,(APTR)msg);
531 case MUIM_Editor_Save: return meditorSave(cl,obj,(APTR)msg);
532 case MUIM_Editor_Load: return meditorLoad(cl,obj,(APTR)msg);
533 default: return DoSuperMethodA(cl,obj,msg);
537 /***********************************************************************/
539 ** App instance
542 struct appData
544 Object *win;
545 Object *about;
546 Object *aboutMUI;
547 Object *config;
550 /***********************************************************************/
552 ** App new method
555 /* Menus */
556 #define MTITLE(t) {NM_TITLE,(STRPTR)(t),0,0,0,0}
557 #define MITEM(t,d) {NM_ITEM,(STRPTR)(t),0,0,0,(APTR)(d)}
558 #define MBAR {NM_ITEM,(STRPTR)NM_BARLABEL,0,0,0,NULL}
559 #define MEND {NM_END,NULL,0,0,0,NULL}
561 enum
563 MABOUT = 1,
564 MABOUTMUI,
565 MMUI,
566 MQUIT,
569 static struct NewMenu appMenu[] =
571 MTITLE("Project"),
572 MITEM("?\0About...",MABOUT),
573 MITEM("M\0About MUI...",MABOUTMUI),
574 MBAR,
575 MITEM("Q\0Quit",MQUIT),
577 MTITLE("Editor"),
578 MITEM("M\0MUI Settings...",MMUI),
580 MEND
583 static ULONG
584 mappNew(struct IClass *cl,Object *obj,struct opSet *msg)
586 Object *strip, *win, *codesets = NULL, *editor, *sb, *loadPlain, *loadUTF8, *save, *cancel;
588 if((obj = (Object *)DoSuperNew(cl,obj,
589 MUIA_Application_Title, "Codesets Demo1",
590 MUIA_Application_Version, "$VER: CodesetsDemo1 1.0 (10.11.2004)",
591 MUIA_Application_Copyright, "Copyright 2004 by Alfonso Ranieri",
592 MUIA_Application_Author, "Alfonso Ranieri <alforan@tin.it>",
593 MUIA_Application_Description, "Codesets example",
594 MUIA_Application_Base, "CODESETSEXAMPLE",
595 MUIA_Application_Menustrip, strip = MUI_MakeObject(MUIO_MenustripNM,appMenu,MUIO_MenustripNM_CommandKeyCheck),
597 SubWindow, win = WindowObject,
598 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
599 MUIA_Window_Title, "Codesets Demo1",
600 WindowContents, VGroup,
602 Child, HGroup,
603 Child, Label2("C_harset"),
604 Child, codesets = popupCodesetObject, End,
605 End,
607 Child, HGroup,
608 MUIA_Group_Horiz, TRUE,
609 MUIA_Group_Spacing, 0,
610 Child, editor = editorObject,
611 MUIA_Editor_CodesetsObj, codesets,
612 End,
613 Child, sb = ScrollbarObject, End,
614 End,
616 Child, HGroup,
617 Child, loadPlain = MUI_MakeObject(MUIO_Button,"Load _plain"),
618 Child, RectangleObject, MUIA_Weight, 50, End,
619 Child, loadUTF8 = MUI_MakeObject(MUIO_Button,"_Load utf8"),
620 Child, RectangleObject, MUIA_Weight, 50, End,
621 Child, save = MUI_MakeObject(MUIO_Button,"_Save utf8"),
622 Child, RectangleObject, MUIA_Weight, 50, End,
623 Child, cancel = MUI_MakeObject(MUIO_Button,"_Cancel"),
624 End,
626 End,
627 End,
628 TAG_MORE,msg->ops_AttrList)))
630 struct appData *data = INST_DATA(cl,obj);
632 data->win = win;
634 set(editor,MUIA_TextEditor_Slider,sb);
636 set(loadPlain,MUIA_CycleChain,TRUE);
637 set(loadUTF8,MUIA_CycleChain,TRUE);
638 set(save,MUIA_CycleChain,TRUE);
639 set(cancel,MUIA_CycleChain,TRUE);
641 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,
642 MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
644 DoMethod(loadPlain,MUIM_Notify,MUIA_Pressed,FALSE,editor,2,MUIM_Editor_Load,TRUE);
645 DoMethod(loadUTF8,MUIM_Notify,MUIA_Pressed,FALSE,editor,2,MUIM_Editor_Load,FALSE);
646 DoMethod(save,MUIM_Notify,MUIA_Pressed,FALSE,editor,1,MUIM_Editor_Save);
647 DoMethod(cancel,MUIM_Notify,MUIA_Pressed,FALSE,MUIV_Notify_Application,2,
648 MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
650 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MABOUT),MUIM_Notify,
651 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,1,MUIM_App_About);
653 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MABOUTMUI),MUIM_Notify,
654 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,1,MUIM_App_AboutMUI);
656 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MQUIT),MUIM_Notify,
657 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,2,MUIM_Application_ReturnID,
658 MUIV_Application_ReturnID_Quit);
660 DoMethod((Object *)DoMethod(strip,MUIM_FindUData,MMUI),MUIM_Notify,
661 MUIA_Menuitem_Trigger,MUIV_EveryTime,obj,2,MUIM_Application_OpenConfigWindow,0);
663 set(win,MUIA_Window_Open,TRUE);
666 return (ULONG)obj;
669 /***********************************************************************/
671 ** App dispose win method
674 static ULONG
675 mappDisposeWin(struct IClass *cl,Object *obj,struct MUIP_App_DisposeWin *msg)
677 struct appData *data = INST_DATA(cl,obj);
678 Object *win = msg->win;
680 set(win,MUIA_Window_Open,FALSE);
681 DoSuperMethod(cl,obj,OM_REMMEMBER,win);
682 MUI_DisposeObject(win);
684 if (win==data->about) data->about = NULL;
685 else if (win==data->aboutMUI) data->aboutMUI = NULL;
687 return 0;
690 /***********************************************************************/
692 ** App about method
695 static ULONG
696 mappAbout(struct IClass *cl,Object *obj,Msg msg)
698 struct appData *data = INST_DATA(cl,obj);
700 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,TRUE,TAG_DONE);
702 if (!data->about)
704 Object *ok;
706 if((data->about = WindowObject,
707 MUIA_Window_RefWindow, data->win,
708 MUIA_Window_Title, "About Codesets Demo1",
709 WindowContents, VGroup,
710 Child, TextObject,
711 MUIA_Text_Contents, "\n"
712 "Codesets Demo1\n"
713 "Copyright 2004 by Alfonso Ranieri <alforan@tin.it>\n",
714 MUIA_Text_PreParse, MUIX_C,
715 End,
716 Child, RectangleObject, MUIA_Weight, 0, MUIA_Rectangle_HBar, TRUE, End,
717 Child, HGroup,
718 Child, RectangleObject, MUIA_Weight, 200, End,
719 Child, ok = MUI_MakeObject(MUIO_Button,"_OK"),
720 Child, RectangleObject, MUIA_Weight, 200, End,
721 End,
722 End,
723 End))
725 DoSuperMethod(cl,obj,OM_ADDMEMBER,data->about);
727 set(data->about,MUIA_Window_ActiveObject,ok);
729 DoMethod(data->about,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,obj,5,
730 MUIM_Application_PushMethod,obj,2,MUIM_App_DisposeWin,data->about);
732 DoMethod(ok,MUIM_Notify,MUIA_Pressed,FALSE,obj,5,
733 MUIM_Application_PushMethod,obj,2,MUIM_App_DisposeWin,data->about);
737 set(data->about,MUIA_Window_Open,TRUE);
739 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,FALSE,TAG_DONE);
741 return 0;
744 /***********************************************************************/
746 ** App about mui method
749 static ULONG
750 mappAboutMUI(struct IClass *cl,Object *obj,Msg msg)
752 struct appData *data = INST_DATA(cl,obj);
754 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,TRUE,TAG_DONE);
756 if (!data->aboutMUI)
758 if((data->aboutMUI = AboutmuiObject,
759 MUIA_Aboutmui_Application, obj,
760 MUIA_Window_RefWindow, data->win,
761 End))
763 DoMethod(data->aboutMUI,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,obj,5,
764 MUIM_Application_PushMethod,obj,2,MUIM_App_DisposeWin,data->aboutMUI);
768 set(data->aboutMUI,MUIA_Window_Open,TRUE);
770 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,FALSE,TAG_DONE);
772 return 0;
775 /***********************************************************************/
777 ** App MUI settings method
780 static ULONG
781 mappOpenMUIConfigWindow(struct IClass *cl,Object *obj,Msg msg)
783 ULONG res;
785 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,TRUE,TAG_DONE);
786 res = DoSuperMethodA(cl,obj,msg);
787 SetSuperAttrs(cl,obj,MUIA_Application_Sleep,FALSE,TAG_DONE);
789 return res;
792 /***********************************************************************/
794 ** App dispatcher
797 DISPATCHERPROTO(appDispatcher)
799 switch (msg->MethodID)
801 case OM_NEW: return mappNew(cl,obj,(APTR)msg);
802 case MUIM_App_DisposeWin: return mappDisposeWin(cl,obj,(APTR)msg);
803 case MUIM_App_About: return mappAbout(cl,obj,(APTR)msg);
804 case MUIM_App_AboutMUI: return mappAboutMUI(cl,obj,(APTR)msg);
805 case MUIM_Application_OpenConfigWindow: return mappOpenMUIConfigWindow(cl,obj,(APTR)msg);
806 default: return DoSuperMethodA(cl,obj,msg);
810 /***********************************************************************/
812 ** Main
816 main(int argc,char **argv)
818 int res = RETURN_FAIL;
820 if((IntuitionBase = (APTR)OpenLibrary("intuition.library", 39)) && // open intuition.library
821 GETINTERFACE(IIntuition, IntuitionBase))
823 if((UtilityBase = OpenLibrary("utility.library", 39)) && // open utility.library
824 GETINTERFACE(IUtility, UtilityBase))
826 if((CodesetsBase = OpenLibrary(CODESETSNAME, CODESETSVER)) && // open codesets.library
827 GETINTERFACE(ICodesets, CodesetsBase))
829 /* Open muimaster.library */
830 if((MUIMasterBase = OpenLibrary("muimaster.library",19)) &&
831 GETINTERFACE(IMUIMaster, MUIMasterBase))
833 /* Create classes */
834 if ((appClass = MUI_CreateCustomClass(NULL,MUIC_Application,NULL,sizeof(struct appData),appDispatcher)) &&
835 (popupCodesetsClass = MUI_CreateCustomClass(NULL,MUIC_Popobject,NULL,0,popupDispatcher)) &&
836 (editorClass = MUI_CreateCustomClass(NULL,MUIC_TextEditor,NULL,sizeof(struct editorData),editorDispatcher)))
838 Object *app;
840 /* Create application */
841 if((app = appObject, End))
843 /* Here we go */
844 ULONG sigs = 0;
846 while (DoMethod(app,MUIM_Application_NewInput,&sigs) != (ULONG)MUIV_Application_ReturnID_Quit)
848 if (sigs)
850 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
851 if (sigs & SIGBREAKF_CTRL_C) break;
855 MUI_DisposeObject(app);
857 res = RETURN_OK;
859 else
861 printf("%s: can't create application\n",argv[0]);
864 MUI_DeleteCustomClass(popupCodesetsClass);
865 MUI_DeleteCustomClass(editorClass);
866 MUI_DeleteCustomClass(appClass);
868 else
870 if (appClass)
872 if (popupCodesetsClass) MUI_DeleteCustomClass(popupCodesetsClass);
873 MUI_DeleteCustomClass(appClass);
876 printf("%s: can't create custom classes\n",argv[0]);
879 DROPINTERFACE(IMUIMaster);
880 CloseLibrary(MUIMasterBase);
882 else
884 printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
885 res = RETURN_ERROR;
888 DROPINTERFACE(ICodesets);
889 CloseLibrary(CodesetsBase);
891 else
893 printf("%s: Can't open codesets.library ver %d or higher.\n", argv[0], CODESETSVER);
894 res = RETURN_ERROR;
897 DROPINTERFACE(IUtility);
898 CloseLibrary(UtilityBase);
901 DROPINTERFACE(IIntuition);
902 CloseLibrary((struct Library *)IntuitionBase);
905 return res;
908 /***********************************************************************/