3 #include <Exec/Tasks.h>
4 #include <Libraries/MUI.h>
5 #include <Rexx/Storage.h>
6 #include <Utility/Hooks.h>
8 #include <Proto/Exec.h>
9 #include <Proto/Graphics.h>
10 #include <Proto/MUIMaster.h>
11 #include <Proto/Intuition.h>
12 #include <Proto/RexxSysLib.h>
14 #include <TextEditor_mcc.h>
16 struct Library
*MUIMasterBase
;
17 Object
*app
, *window
, *editorgad
;
18 STRPTR StdEntries
[] = {"Kind regards ", "Yours ", "Mvh ", NULL
}; //"Duff@DIKU.DK", "http://www.DIKU.dk/students/duff/", NULL};
21 LONG
ARexxHookCode (register __a1
struct RexxMsg
*rexxmsg
, register __a2 Object
*app
)
25 if(result
= DoMethod(editorgad
, MUIM_TextEditor_ARexxCmd
, rexxmsg
->rm_Args
[0]))
29 set(app
, MUIA_Application_RexxString
, result
);
30 FreeVec((APTR
)result
);
35 struct Hook ARexxHook
= {0, 0, (APTR
)ARexxHookCode
};
37 ULONG
TextEditor_Dispatcher (register __a0
struct IClass
*cl
, register __a2 Object
*obj
, register __a1
struct MUIP_TextEditor_HandleError
*msg
)
43 struct ColorMap
*cm
= muiRenderInfo(obj
)->mri_Screen
->ViewPort
.ColorMap
;
45 cmap
[0] = ObtainBestPenA(cm
, 0x00<<24, 0x00<<24, 0x00<<24, NULL
);
46 cmap
[1] = ObtainBestPenA(cm
, 0xff<<24, 0xff<<24, 0xff<<24, NULL
);
47 cmap
[2] = ObtainBestPenA(cm
, 0xff<<24, 0x00<<24, 0x00<<24, NULL
);
48 cmap
[3] = ObtainBestPenA(cm
, 0x00<<24, 0xff<<24, 0x00<<24, NULL
);
49 cmap
[4] = ObtainBestPenA(cm
, 0x00<<24, 0xff<<24, 0xff<<24, NULL
);
50 cmap
[5] = ObtainBestPenA(cm
, 0xff<<24, 0xff<<24, 0x00<<24, NULL
);
51 cmap
[6] = ObtainBestPenA(cm
, 0x00<<24, 0x00<<24, 0xff<<24, NULL
);
52 cmap
[7] = ObtainBestPenA(cm
, 0xff<<24, 0x00<<24, 0xff<<24, NULL
);
58 struct ColorMap
*cm
= muiRenderInfo(obj
)->mri_Screen
->ViewPort
.ColorMap
;
61 for(c
= 0; c
< 8; c
++)
65 ReleasePen(cm
, cmap
[c
]);
78 struct MUIP_DragDrop
*drop_msg
= (struct MUIP_DragDrop
*)msg
;
81 if(GetAttr(MUIA_List_Active
, drop_msg
->obj
, &active
))
83 DoMethod(obj
, MUIM_TextEditor_InsertText
, StdEntries
[active
]);
88 case MUIM_TextEditor_HandleError
:
90 char *errortxt
= NULL
;
92 switch(msg
->errorcode
)
94 case Error_ClipboardIsEmpty
:
95 errortxt
= "\33cThe clipboard is empty.";
97 case Error_ClipboardIsNotFTXT
:
98 errortxt
= "\33cThe clipboard does not contain text.";
100 case Error_MacroBufferIsFull
:
102 case Error_MemoryAllocationFailed
:
104 case Error_NoAreaMarked
:
105 errortxt
= "\33cNo area marked.";
107 case Error_NoMacroDefined
:
109 case Error_NothingToRedo
:
110 errortxt
= "\33cNothing to redo.";
112 case Error_NothingToUndo
:
113 errortxt
= "\33cNothing to undo.";
115 case Error_NotEnoughUndoMem
:
116 errortxt
= "There is not enough memory\nto keep the undo buffer.\n\nThe undobuffer is lost.";
118 case Error_StringNotFound
:
120 case Error_NoBookmarkInstalled
:
121 errortxt
= "There is no bookmark installed!";
123 case Error_BookmarkHasBeenLost
:
124 errortxt
= "Your bookmark has unfortunately been lost.";
129 MUI_Request(app
, window
, 0L, NULL
, "Continue", errortxt
);
134 return(DoSuperMethodA(cl
, obj
, (Msg
)msg
));
137 Object
*ImageGad (STRPTR text
, UBYTE key
)
140 MUIA_Background
, MUII_ButtonBack
,
141 MUIA_Frame
, MUIV_Frame_Button
,
142 MUIA_Text_PreParse
, "\33c",
143 MUIA_Font
, MUIV_Font_Tiny
,
144 MUIA_Text_Contents
, text
,
145 MUIA_Text_SetVMax
, FALSE
,
148 MUIA_InputMode
, MUIV_InputMode_Toggle
,
149 MUIA_ControlChar
, key
,
150 MUIA_CycleChain
, TRUE
,
154 #define MUIV_RunARexxScript 0xad800000
159 struct StackSwapStruct stackswap
;
160 struct Task
*mytask
= FindTask(NULL
);
162 LONG argarray
[6] = {0,0,0,0,0,0};
163 ULONG stacksize
= (ULONG
)mytask
->tc_SPUpper
-(ULONG
)mytask
->tc_SPLower
+8192;
164 APTR newstack
= AllocVec(stacksize
, 0L);
166 stackswap
.stk_Lower
= newstack
;
167 stackswap
.stk_Upper
= (ULONG
)newstack
+stacksize
;
168 stackswap
.stk_Pointer
= (APTR
)stackswap
.stk_Upper
;
171 StackSwap(&stackswap
);
173 if(args
= ReadArgs("Filename/A,EMail/S,MIME/S,MIMEQuoted/S,SkipHeader/S,Fixed/S", argarray
, NULL
))
175 if(MUIMasterBase
= OpenLibrary("muimaster.library", 11)) //MUIMASTER_VMIN))
177 struct MUI_CustomClass
*editor_mcc
;
178 Object
*clear
, *cut
, *copy
, *paste
, *erase
,
179 *bold
, *italic
, *underline
, *ischanged
, *undo
, *redo
,
180 *flow
, *separator
, *color
, *config
;
181 STRPTR flow_text
[] = {"Left", "Center", "Right", NULL
};
182 STRPTR colors
[] = {"Normal", "Black", "White", "Red", "Gren", "Cyan", "Yellow", "Blue", "Magenta", NULL
};
183 STRPTR classes
[] = {"TextEditor.mcc"};
185 if(editor_mcc
= MUI_CreateCustomClass(NULL
, "TextEditor.mcc", NULL
, 0, (void *)TextEditor_Dispatcher
))
187 app
= ApplicationObject
,
188 MUIA_Application_Author
, "Allan Odgaard",
189 MUIA_Application_Base
, "TextEditor-Demo",
190 MUIA_Application_Copyright
, "®1997 Allan Odgaard",
191 MUIA_Application_Description
, "TextEditor.mcc demonstration program",
192 MUIA_Application_RexxHook
, &ARexxHook
,
193 MUIA_Application_Title
, "TextEditor-Demo",
194 MUIA_Application_Version
, "$VER: TextEditor-Demo V1.0 (6-Aug-97)",
195 MUIA_Application_UsedClasses
, classes
,
196 SubWindow
, window
= WindowObject
,
197 MUIA_Window_Title
, "TextEditor-Demo",
198 MUIA_Window_ID
, 'MAIN',
199 WindowContents
, VGroup
,
201 MUIA_Background
, MUII_GroupBack
,
202 MUIA_Frame
, MUIV_Frame_Group
,
207 Child
, cut
= MUI_MakeObject(MUIO_Button
, "Cut"),
208 Child
, paste
= MUI_MakeObject(MUIO_Button
, "Paste"),
209 Child
, undo
= MUI_MakeObject(MUIO_Button
, "Undo"),
210 Child
, flow
= MUI_MakeObject(MUIO_Cycle
, NULL
, flow_text
),
211 Child
, separator
= MUI_MakeObject(MUIO_Button
, "Separator"),
212 Child
, clear
= MUI_MakeObject(MUIO_Button
, "Clear _Text"),
214 Child
, copy
= MUI_MakeObject(MUIO_Button
, "Copy"),
215 Child
, erase
= MUI_MakeObject(MUIO_Button
, "Erase"),
216 Child
, redo
= MUI_MakeObject(MUIO_Button
, "Redo"),
217 Child
, color
= MUI_MakeObject(MUIO_Cycle
, NULL
, colors
),
218 Child
, config
= MUI_MakeObject(MUIO_Button
, "Config..."),
220 Child
, ischanged
= MUI_MakeObject(MUIO_Checkmark
, "Is changed?"),
222 MUIA_Text_Contents
, "Is changed?",
227 Child
, RectangleObject
, End
,
229 Child
, bold
= ImageGad("\33I[5:ProgDir:Bold.Brush]\n\n\nBold", 'b'),
230 Child
, italic
= ImageGad("\33I[5:ProgDir:Italic.Brush]\n\n\nItalic", 'i'),
231 Child
, underline
= ImageGad("\33I[5:ProgDir:Underline.Brush]\n\n\nUnderline", 'u'),
237 MUIA_Group_Spacing
, 0,
238 Child
, editorgad
= NewObject(editor_mcc
->mcc_Class
, NULL
,
239 MUIA_TextEditor_Slider
, slider
,
240 MUIA_TextEditor_ColorMap
, cmap
,
241 MUIA_CycleChain
, TRUE
,
243 Child
, slider
= ScrollbarObject
,
248 Child
, ListviewObject
,
249 MUIA_Listview_DragType
, MUIV_Listview_DragType_Immediate
,
250 MUIA_Listview_List
, ListObject
,
252 MUIA_Background
, MUII_ListBack
,
253 MUIA_List_AdjustWidth
, TRUE
,
254 MUIA_List_AdjustHeight
, TRUE
,
255 MUIA_List_SourceArray
, StdEntries
,
258 Child
, RectangleObject
,
275 set(editorgad
, MUIA_TextEditor_FixedFont
, TRUE
);
277 if(fh
= Open((STRPTR
)argarray
[0], MODE_OLDFILE
))
279 STRPTR text
= AllocVec(300*1024, 0L);
280 STRPTR buffer
= text
;
285 size
= Read(fh
, text
, (300*1024)-2);
291 while(*buffer
!= '\n' && buffer
< &text
[size
])
293 while(*buffer
++ != '\n');
300 MUIA_TextEditor_ImportHook
, MUIV_TextEditor_ImportHook_MIMEQuoted
,
301 MUIA_TextEditor_ImportWrap
, 80,
302 MUIA_TextEditor_ExportHook
, MUIV_TextEditor_ExportHook_EMail
,
310 MUIA_TextEditor_ImportHook
, MUIV_TextEditor_ImportHook_MIME
,
311 MUIA_TextEditor_ExportHook
, MUIV_TextEditor_ExportHook_EMail
,
319 MUIA_TextEditor_ImportHook
, MUIV_TextEditor_ImportHook_EMail
,
320 MUIA_TextEditor_ExportHook
, MUIV_TextEditor_ExportHook_EMail
,
325 set(editorgad
, MUIA_TextEditor_Contents
, buffer
);
327 set(editorgad
, MUIA_TextEditor_ImportHook
, MUIV_TextEditor_ImportHook_Plain
);
331 DoMethod(window
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
, MUIV_Notify_Application
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
333 DoMethod(window
, MUIM_Notify
, MUIA_Window_InputEvent
, "f1", MUIV_Notify_Application
, 2, MUIM_Application_ReturnID
, MUIV_RunARexxScript
);
335 DoMethod(flow
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_Flow
, MUIV_TriggerValue
);
336 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_Flow
, MUIV_EveryTime
, flow
, 3, MUIM_NoNotifySet
, MUIA_Cycle_Active
, MUIV_TriggerValue
);
338 DoMethod(color
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_Pen
, MUIV_TriggerValue
);
339 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_Pen
, MUIV_EveryTime
, color
, 3, MUIM_NoNotifySet
, MUIA_Cycle_Active
, MUIV_TriggerValue
);
341 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_StyleBold
, MUIV_EveryTime
, bold
, 3, MUIM_NoNotifySet
, MUIA_Selected
, MUIV_TriggerValue
);
342 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_StyleItalic
, MUIV_EveryTime
, italic
, 3, MUIM_NoNotifySet
, MUIA_Selected
, MUIV_TriggerValue
);
343 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_StyleUnderline
, MUIV_EveryTime
, underline
, 3, MUIM_NoNotifySet
, MUIA_Selected
, MUIV_TriggerValue
);
345 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_HasChanged
, MUIV_EveryTime
, ischanged
, 3, MUIM_NoNotifySet
, MUIA_Selected
, MUIV_TriggerValue
);
346 DoMethod(editorgad
, MUIM_Notify
, MUIA_TextEditor_HasChanged
, MUIV_EveryTime
, ischanged
, 3, MUIM_NoNotifySet
, MUIA_Image_State
, MUIV_TriggerValue
);
347 DoMethod(ischanged
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_HasChanged
, MUIV_TriggerValue
);
349 DoMethod(separator
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_InsertText
, "\n\33c\33[s:2]\n");
351 DoMethod(config
, MUIM_Notify
, MUIA_Pressed
, FALSE
, MUIV_Notify_Application
, 2, MUIM_Application_OpenConfigWindow
, 1, "TextEditor.mcc");
353 DoMethod(clear
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Clear");
354 DoMethod(clear
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_HasChanged
, FALSE
);
356 DoMethod(cut
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Cut");
357 DoMethod(copy
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Copy");
358 DoMethod(paste
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Paste");
359 DoMethod(erase
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Erase");
360 DoMethod(undo
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Undo");
361 DoMethod(redo
, MUIM_Notify
, MUIA_Pressed
, FALSE
, editorgad
, 2, MUIM_TextEditor_ARexxCmd
, "Redo");
363 DoMethod(bold
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_StyleBold
, MUIV_TriggerValue
);
364 DoMethod(italic
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_StyleItalic
, MUIV_TriggerValue
);
365 DoMethod(underline
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, editorgad
, 3, MUIM_NoNotifySet
, MUIA_TextEditor_StyleUnderline
, MUIV_TriggerValue
);
367 SetAttrs(window
, MUIA_Window_ActiveObject
, editorgad
,
368 MUIA_Window_Open
, TRUE
,
372 struct MsgPort
*myport
= NULL
;
373 struct RexxMsg
*rxmsg
;
376 BPTR rxstdout
= NULL
;
378 while((ReturnID
= DoMethod(app
, MUIM_Application_NewInput
, &sigs
)) != MUIV_Application_ReturnID_Quit
)
380 if(ReturnID
== MUIV_RunARexxScript
&& !myport
)
382 struct MsgPort
*rexxport
;
383 STRPTR script
= "Rexx:TextEditor/Demo.Rexx";
385 if((rexxport
= FindPort("REXX")) && (myport
= CreateMsgPort()))
388 rxstdout
= Open("Con://640/100/TextEditor-Demo, ARexx output:/Close/Wait/Auto/InActive", MODE_READWRITE
);
389 rxmsg
= CreateRexxMsg(myport
, NULL
, "TEXTEDITOR-DEMO.1");
390 rxmsg
->rm_Action
= RXCOMM
;
391 rxmsg
->rm_Stdin
= rxstdout
;
392 rxmsg
->rm_Stdout
= rxstdout
;
393 rxmsg
->rm_Args
[0] = CreateArgstring(script
, strlen(script
));
394 PutMsg(rexxport
, (struct Message
*)rxmsg
);
399 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
| (myport
? 1<<myport
->mp_SigBit
: 0));
400 if(myport
&& (sigs
& 1<<myport
->mp_SigBit
))
403 if(!rxmsg
->rm_Result1
&& rxmsg
->rm_Result2
)
404 DeleteArgstring((STRPTR
)rxmsg
->rm_Result2
);
405 DeleteArgstring(rxmsg
->rm_Args
[0]);
406 DeleteRexxMsg(rxmsg
);
407 DeleteMsgPort(myport
);
410 if(sigs
& SIGBREAKF_CTRL_C
)
417 get(editorgad
, MUIA_TextEditor_HasChanged
, &changed
);
418 if(changed
&& !(sigs
& SIGBREAKF_CTRL_C
))
419 running
= MUI_Request(app
, window
, 0L, "Warning", "_Proceed|*_Save|_Cancel", "\33cText '%s'\n is modified. Save it?", argarray
[0]);
421 } while(running
== 0);
425 STRPTR text
= (STRPTR
)DoMethod(editorgad
, MUIM_TextEditor_ExportText
);
427 if(fh
= Open((STRPTR
)argarray
[0], MODE_NEWFILE
))
429 Write(fh
, text
, strlen(text
));
434 MUI_DisposeObject(app
);
436 else printf("Failed to create application\n");
437 MUI_DeleteCustomClass(editor_mcc
);
439 else printf("Failed to open TextEditor.mcc\n");
440 CloseLibrary(MUIMasterBase
);
442 else printf("Failed to open MUIMaster.Library V%d\n", MUIMASTER_VMIN
);
448 LONG error
= IoErr();
450 GetProgramName(prgname
, 32);
451 PrintFault(error
, prgname
);
453 StackSwap(&stackswap
);