Hint added.
[AROS.git] / workbench / utilities / MultiView / main.c
blob1e2b1f1f7746835f5b04cbbb61441ec7d6b5c0a2
1 /*
2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*********************************************************************************************/
8 #include "global.h"
10 #include "compilerspecific.h"
11 #include "debug.h"
12 #include "arossupport.h"
14 #include <setjmp.h>
15 #include <stdio.h>
16 #include <string.h>
18 extern struct NewMenu nm[];
19 extern struct NewMenu nmpict[];
20 extern struct NewMenu nmtext[];
22 /*********************************************************************************************/
24 /* Many datatype classes seem to rely on OM_NOTIFY calls coming back to the datatype object
25 as OM_UPDATE :-\ */
27 #define BACK_CONNECTION 1
29 /*********************************************************************************************/
31 #define ARG_TEMPLATE "FILE,CLIPBOARD/S,CLIPUNIT/K/N,SCREEN/S,PUBSCREEN/K,REQUESTER/S," \
32 "BOOKMARK/S,FONTNAME/K,FONTSIZE/K/N,BACKDROP/S,WINDOW/S," \
33 "PORTNAME/K,IMMEDIATE/S,REPEAT/S,PRTUNIT/K/N"
35 #define ARG_FILE 0
36 #define ARG_CLIPBOARD 1
37 #define ARG_CLIPUNIT 2
38 #define ARG_SCREEN 3
39 #define ARG_PUBSCREEN 4
40 #define ARG_REQUESTER 5
41 #define ARG_BOOKMARK 6
42 #define ARG_FONTNAME 7
43 #define ARG_FONTSIZE 8
44 #define ARG_BACKDROP 9
45 #define ARG_WINDOW 10
46 #define ARG_PORTNAME 11
47 #define ARG_IMMEDIATE 12
48 #define ARG_REPEAT 13
49 #define ARG_PRTUNIT 14
51 #define NUM_ARGS 15
53 /*********************************************************************************************/
55 static struct libinfo
57 APTR var;
58 STRPTR name;
59 WORD version;
60 } libtable[] =
62 {&IntuitionBase , "intuition.library" , 39 },
63 {&GfxBase , "graphics.library" , 39 },
64 {&GadToolsBase , "gadtools.library" , 39 },
65 {&LayersBase , "layers.library" , 39 },
66 {&UtilityBase , "utility.library" , 39 },
67 {&KeymapBase , "keymap.library" , 39 },
68 {&DataTypesBase , "datatypes.library" , 39 },
69 {&DiskfontBase , "diskfont.library" , 39 },
70 {NULL }
73 static struct TextAttr textattr;
74 static struct TextFont *font;
75 static struct RDArgs *myargs;
76 static IPTR args[NUM_ARGS];
77 static UBYTE fontname[256];
78 static WORD winwidth, winheight;
79 static WORD sizeimagewidth, sizeimageheight;
80 static BOOL model_has_members;
81 static jmp_buf exit_buf;
83 /*********************************************************************************************/
85 static void CloseLibs(void);
86 static void KillFont(void);
87 static void FreeArguments(void);
88 static void KillICObjects(void);
89 static void FreeVisual(void);
90 static void KillGadgets(void);
91 static void CloseDTO(void);
92 static void KillWindow(void);
93 static void ScrollTo(UWORD dir, UWORD quali);
94 static void FitToWindow(void);
96 /*********************************************************************************************/
98 void OutputMessage(CONST_STRPTR msg)
100 struct EasyStruct es;
102 if (msg)
104 if ( IntuitionBase && !((struct Process *)FindTask(NULL))->pr_CLI )
106 es.es_StructSize = sizeof(es);
107 es.es_Flags = 0;
108 es.es_Title = "MultiView";
109 es.es_TextFormat = msg;
110 es.es_GadgetFormat = MSG(MSG_OK);
112 EasyRequestArgs(win, &es, NULL, NULL);
114 else
116 Printf("MultiView: %s\n", msg);
121 /*********************************************************************************************/
123 void WinCleanup(void)
126 if (win)
128 wincoords.MinX = win->LeftEdge;
129 wincoords.MinY = win->TopEdge;
130 wincoords.MaxX = win->Width;
131 wincoords.MaxY = win->Height;
133 D(bug("[Multiview] WinCleanup() MinX = %d MinY = %d MaxX = %d MaxY = %d\n",
134 wincoords.MinX, wincoords.MinY, wincoords.MaxX, wincoords.MaxY));
136 if (msgport)
138 DeleteMsgPort(msgport);
139 msgport = NULL;
140 D(bug("[Multiview] removed msgport\n"));
142 if (appwindow)
144 RemoveAppWindow(appwindow);
145 appwindow = NULL;
146 D(bug("[Multiview] removed appwindow\n"));
149 KillWindow();
150 KillMenus();
151 KillGadgets();
152 FreeVisual();
153 CloseDTO();
154 KillICObjects();
155 KillFont();
158 /*********************************************************************************************/
160 void Cleanup(CONST_STRPTR msg)
162 struct ScreenNotifyMessage *snmsg;
164 OutputMessage(msg);
166 while (!EndScreenNotify (isnstarted))
167 Delay (10);
169 if (isnport)
171 while ((snmsg = (struct ScreenNotifyMessage *) GetMsg (isnport)))
173 ReplyMsg((struct Message *)snmsg);
175 DeleteMsgPort(isnport);
178 WinCleanup();
180 FreeArguments();
182 if (cd != BNULL)
183 CurrentDir(cd); /* restore current directory */
185 CloseLibs();
186 CleanupLocale();
188 longjmp(exit_buf, 0);
192 /*********************************************************************************************/
194 static void OpenLibs(void)
196 struct libinfo *li;
198 for(li = libtable; li->var; li++)
200 if (!((*(struct Library **)li->var) = OpenLibrary(li->name, li->version)))
202 __sprintf(s, MSG(MSG_CANT_OPEN_LIB), li->name, li->version);
203 Cleanup(s);
209 /*********************************************************************************************/
211 static void CloseLibs(void)
213 struct libinfo *li;
215 for(li = libtable; li->var; li++)
217 if (*(struct Library **)li->var) CloseLibrary((*(struct Library **)li->var));
221 /*********************************************************************************************/
223 static void LoadFont(void)
225 font = OpenDiskFont(&textattr);
226 if (!font)
228 textattr.ta_Name = "topaz.font";
229 textattr.ta_YSize = 8;
230 textattr.ta_Style = 0;
231 textattr.ta_Flags = 0;
233 font = OpenFont(&textattr);
237 /*********************************************************************************************/
239 static void KillFont(void)
241 if (font) CloseFont(font);
244 /*********************************************************************************************/
246 static void InitDefaults(void)
248 struct TextFont *defaultfont = GfxBase->DefaultFont;
250 /* This might be a bit problematic depending on how default system font
251 switching through Font prefs program works and if then the previous
252 default system font is closed or not. So this is very likely only safe
253 when in such a case the previous font is not closed (means -> the font
254 will remain in memory in any case)
256 ClipView example program on Amiga Dev CD also does it like this. So ... */
258 textattr.ta_Name = defaultfont->tf_Message.mn_Node.ln_Name;
259 textattr.ta_YSize = defaultfont->tf_YSize;
260 textattr.ta_Style = defaultfont->tf_Style;
261 textattr.ta_Flags = defaultfont->tf_Flags;
264 /*********************************************************************************************/
266 static void GetArguments(void)
269 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, NULL)))
271 Fault(IoErr(), 0, s, 256);
272 Cleanup(s);
275 filename = (STRPTR)args[ARG_FILE];
276 if (!filename && !args[ARG_CLIPBOARD])
278 filename = GetFileName(MSG_ASL_OPEN_TITLE);
279 if (!filename) Cleanup(NULL);
282 if (args[ARG_FONTNAME])
284 strncpy(fontname, (char *)args[ARG_FONTNAME], 255 - 5);
285 if (!strstr(fontname, ".font")) strcat(fontname, ".font");
287 textattr.ta_Name = fontname;
290 if (args[ARG_FONTSIZE])
292 textattr.ta_YSize = *(LONG *)args[ARG_FONTSIZE];
297 /*********************************************************************************************/
299 static void FreeArguments(void)
301 if (myargs) FreeArgs(myargs);
304 /*********************************************************************************************/
306 static void MakeICObjects(void)
308 static const struct TagItem dto_to_vert_map[] =
310 {DTA_TopVert , PGA_Top },
311 {DTA_VisibleVert , PGA_Visible },
312 {DTA_TotalVert , PGA_Total },
313 {TAG_DONE }
315 static const struct TagItem dto_to_horiz_map[] =
317 {DTA_TopHoriz , PGA_Top },
318 {DTA_VisibleHoriz , PGA_Visible },
319 {DTA_TotalHoriz , PGA_Total },
320 {TAG_DONE }
322 static const struct TagItem vert_to_dto_map[] =
324 {PGA_Top , DTA_TopVert },
325 {TAG_DONE }
327 static const struct TagItem horiz_to_dto_map[] =
329 {PGA_Top , DTA_TopHoriz },
330 {TAG_DONE }
333 model_obj = NewObject(NULL, MODELCLASS, ICA_TARGET, ICTARGET_IDCMP,
334 TAG_DONE);
335 dto_to_vert_ic_obj = NewObject(NULL, ICCLASS, ICA_MAP, (IPTR)dto_to_vert_map,
336 TAG_DONE);
337 dto_to_horiz_ic_obj = NewObject(NULL, ICCLASS, ICA_MAP, (IPTR)dto_to_horiz_map,
338 TAG_DONE);
339 vert_to_dto_ic_obj = NewObject(NULL, ICCLASS, ICA_MAP, (IPTR)vert_to_dto_map,
340 TAG_DONE);
341 horiz_to_dto_ic_obj = NewObject(NULL, ICCLASS, ICA_MAP, (IPTR)horiz_to_dto_map,
342 TAG_DONE);
343 #if BACK_CONNECTION
344 model_to_dto_ic_obj = NewObject(NULL, ICCLASS, TAG_DONE);
345 #endif
347 if (!model_obj ||
348 !dto_to_vert_ic_obj ||
349 !dto_to_horiz_ic_obj ||
350 !vert_to_dto_ic_obj ||
351 !horiz_to_dto_ic_obj
352 #if BACK_CONNECTION
353 || !model_to_dto_ic_obj
354 #endif
357 Cleanup(MSG(MSG_CANT_CREATE_IC));
360 DoMethod(model_obj, OM_ADDMEMBER, (IPTR) dto_to_vert_ic_obj);
361 DoMethod(model_obj, OM_ADDMEMBER, (IPTR) dto_to_horiz_ic_obj);
362 #if BACK_CONNECTION
363 DoMethod(model_obj, OM_ADDMEMBER, (IPTR) model_to_dto_ic_obj);
364 #endif
366 model_has_members = TRUE;
370 /*********************************************************************************************/
372 static void KillICObjects(void)
374 if (!model_has_members)
376 if (dto_to_vert_ic_obj) DisposeObject(dto_to_vert_ic_obj);
377 if (dto_to_horiz_ic_obj) DisposeObject(dto_to_horiz_ic_obj);
378 #if BACK_CONNECTION
379 if (model_to_dto_ic_obj) DisposeObject(model_to_dto_ic_obj);
380 #endif
383 if (model_obj) DisposeObject(model_obj);
384 if (vert_to_dto_ic_obj) DisposeObject(vert_to_dto_ic_obj);
385 if (horiz_to_dto_ic_obj) DisposeObject(horiz_to_dto_ic_obj);
388 /*********************************************************************************************/
390 static void GetVisual(void)
392 scr = LockPubScreen((CONST_STRPTR)args[ARG_PUBSCREEN]);
393 if (!scr) Cleanup(MSG(MSG_CANT_LOCK_SCR));
395 dri = GetScreenDrawInfo(scr);
396 if (!dri) Cleanup(MSG(MSG_CANT_GET_DRI));
398 vi = GetVisualInfoA(scr, NULL);
399 if (!vi) Cleanup(MSG(MSG_CANT_GET_VI));
402 /*********************************************************************************************/
404 static void FreeVisual(void)
406 if (vi) FreeVisualInfo(vi);
407 if (dri) FreeScreenDrawInfo(scr, dri);
408 if (scr) UnlockPubScreen(NULL, scr);
411 /*********************************************************************************************/
413 static void MakeGadgets(void)
415 static WORD img2which[] =
417 UPIMAGE,
418 DOWNIMAGE,
419 LEFTIMAGE,
420 RIGHTIMAGE,
421 SIZEIMAGE
424 IPTR imagew[NUM_IMAGES], imageh[NUM_IMAGES];
425 WORD v_offset, h_offset, btop, i;
427 for(i = 0; i < NUM_IMAGES; i++)
429 img[i] = NewObject(NULL, SYSICLASS, SYSIA_DrawInfo , (IPTR)( dri ),
430 SYSIA_Which , (IPTR)( img2which[i] ),
431 TAG_DONE);
433 if (!img[i]) Cleanup(MSG(MSG_CANT_CREATE_SYSIMAGE));
435 GetAttr(IA_Width,(Object *)img[i],&imagew[i]);
436 GetAttr(IA_Height,(Object *)img[i],&imageh[i]);
439 sizeimagewidth = imagew[IMG_SIZE];
440 sizeimageheight = imageh[IMG_SIZE];
442 btop = scr->WBorTop + dri->dri_Font->tf_YSize + 1;
444 v_offset = imagew[IMG_DOWNARROW] / 4;
445 h_offset = imageh[IMG_LEFTARROW] / 4;
447 gad[GAD_UPARROW] = NewObject(NULL, BUTTONGCLASS,
448 GA_Image , (IPTR)( img[IMG_UPARROW] ),
449 GA_RelRight , (IPTR)( -imagew[IMG_UPARROW] + 1 ),
450 GA_RelBottom , (IPTR)( -imageh[IMG_DOWNARROW] - imageh[IMG_UPARROW] - imageh[IMG_SIZE] + 1 ),
451 GA_ID , (IPTR)( GAD_UPARROW ),
452 GA_RightBorder , (IPTR)TRUE,
453 GA_Immediate , (IPTR)TRUE,
454 GA_RelVerify , (IPTR)TRUE,
455 TAG_DONE);
457 gad[GAD_DOWNARROW] = NewObject(NULL, BUTTONGCLASS,
458 GA_Image , (IPTR)( img[IMG_DOWNARROW] ),
459 GA_RelRight , (IPTR)( -imagew[IMG_UPARROW] + 1 ),
460 GA_RelBottom , (IPTR)( -imageh[IMG_UPARROW] - imageh[IMG_SIZE] + 1 ),
461 GA_ID , (IPTR)( GAD_DOWNARROW ),
462 GA_RightBorder , (IPTR)TRUE,
463 GA_Previous , (IPTR)( gad[GAD_UPARROW] ),
464 GA_Immediate , (IPTR)TRUE,
465 GA_RelVerify , (IPTR)TRUE,
466 TAG_DONE);
468 gad[GAD_VERTSCROLL] = NewObject(NULL, PROPGCLASS,
469 GA_Top , (IPTR)( btop + 1 ),
470 GA_RelRight , (IPTR)( -imagew[IMG_DOWNARROW] + v_offset + 1 ),
471 GA_Width , (IPTR)( imagew[IMG_DOWNARROW] - v_offset * 2 ),
472 GA_RelHeight , (IPTR)( -imageh[IMG_DOWNARROW] - imageh[IMG_UPARROW] - imageh[IMG_SIZE] - btop -2 ),
473 GA_ID , (IPTR)( GAD_VERTSCROLL ),
474 GA_Previous , (IPTR)( gad[GAD_DOWNARROW] ),
475 GA_RightBorder , (IPTR)TRUE,
476 GA_RelVerify , (IPTR)TRUE,
477 GA_Immediate , (IPTR)TRUE,
478 PGA_NewLook , (IPTR)TRUE,
479 PGA_Borderless , (IPTR)TRUE,
480 PGA_Total , (IPTR)100,
481 PGA_Visible , (IPTR)100,
482 PGA_Freedom , (IPTR)FREEVERT,
483 PGA_NotifyBehaviour , (IPTR)PG_BEHAVIOUR_NICE,
484 TAG_DONE);
486 gad[GAD_RIGHTARROW] = NewObject(NULL, BUTTONGCLASS,
487 GA_Image , (IPTR)( img[IMG_RIGHTARROW] ),
488 GA_RelRight , (IPTR)( -imagew[IMG_SIZE] - imagew[IMG_RIGHTARROW] + 1 ),
489 GA_RelBottom , (IPTR)( -imageh[IMG_RIGHTARROW] + 1 ),
490 GA_ID , (IPTR)( GAD_RIGHTARROW ),
491 GA_BottomBorder , (IPTR)TRUE,
492 GA_Previous , (IPTR)( gad[GAD_VERTSCROLL] ),
493 GA_Immediate , (IPTR)TRUE,
494 GA_RelVerify , (IPTR)TRUE,
495 TAG_DONE);
497 gad[GAD_LEFTARROW] = NewObject(NULL, BUTTONGCLASS,
498 GA_Image , (IPTR)( img[IMG_LEFTARROW] ),
499 GA_RelRight , (IPTR)( -imagew[IMG_SIZE] - imagew[IMG_RIGHTARROW] - imagew[IMG_LEFTARROW] + 1 ),
500 GA_RelBottom , (IPTR)( -imageh[IMG_RIGHTARROW] + 1 ),
501 GA_ID , (IPTR)( GAD_LEFTARROW ),
502 GA_BottomBorder , (IPTR)TRUE,
503 GA_Previous , (IPTR)( gad[GAD_RIGHTARROW] ),
504 GA_Immediate , (IPTR)TRUE,
505 GA_RelVerify , (IPTR)TRUE,
506 TAG_DONE);
508 gad[GAD_HORIZSCROLL] = NewObject(NULL, PROPGCLASS,
509 GA_Left , (IPTR)( scr->WBorLeft ),
510 GA_RelBottom , (IPTR)( -imageh[IMG_LEFTARROW] + h_offset + 1 ),
511 GA_RelWidth , (IPTR)( -imagew[IMG_LEFTARROW] - imagew[IMG_RIGHTARROW] - imagew[IMG_SIZE] - scr->WBorRight - 2 ),
512 GA_Height , (IPTR)( imageh[IMG_LEFTARROW] - (h_offset * 2) ),
513 GA_ID , (IPTR)( GAD_HORIZSCROLL ),
514 GA_Previous , (IPTR)( gad[GAD_LEFTARROW] ),
515 GA_BottomBorder , (IPTR)TRUE,
516 GA_RelVerify , (IPTR)TRUE,
517 GA_Immediate , (IPTR)TRUE,
518 PGA_NewLook , (IPTR)TRUE,
519 PGA_Borderless , (IPTR)TRUE,
520 PGA_Total , (IPTR)100,
521 PGA_Visible , (IPTR)100,
522 PGA_Freedom , (IPTR)FREEHORIZ,
523 PGA_NotifyBehaviour , (IPTR)PG_BEHAVIOUR_NICE,
524 TAG_DONE);
526 for(i = 0;i < NUM_GADGETS;i++)
528 if (!gad[i]) Cleanup(MSG(MSG_CANT_CREATE_GADGET));
531 SetAttrs(gad[GAD_VERTSCROLL] , ICA_TARGET, (IPTR)vert_to_dto_ic_obj, TAG_DONE);
532 SetAttrs(gad[GAD_HORIZSCROLL], ICA_TARGET, (IPTR)horiz_to_dto_ic_obj, TAG_DONE);
533 SetAttrs(dto_to_vert_ic_obj , ICA_TARGET, (IPTR)gad[GAD_VERTSCROLL], TAG_DONE);
534 SetAttrs(dto_to_horiz_ic_obj , ICA_TARGET, (IPTR)gad[GAD_HORIZSCROLL], TAG_DONE);
537 /*********************************************************************************************/
539 static void KillGadgets(void)
541 WORD i;
543 for(i = 0; i < NUM_GADGETS;i++)
545 if (win) RemoveGadget(win, (struct Gadget *)gad[i]);
546 if (gad[i]) DisposeObject(gad[i]);
547 gad[i] = 0;
550 for(i = 0; i < NUM_IMAGES;i++)
552 if (img[i]) DisposeObject(img[i]);
553 img[i] = NULL;
557 /*********************************************************************************************/
559 void AddDTOToWin(void)
561 EraseRect(win->RPort, win->BorderLeft,
562 win->BorderTop,
563 win->Width - 1 - win->BorderRight,
564 win->Height - 1 - win->BorderBottom);
566 SetDTAttrs (dto, NULL, NULL, GA_Left , win->BorderLeft + 2 ,
567 GA_Top , win->BorderTop + 2 ,
568 GA_RelWidth , - win->BorderLeft - win->BorderRight - 4 ,
569 GA_RelHeight , - win->BorderTop - win->BorderBottom - 4 ,
570 TAG_DONE);
572 AddDTObject(win, NULL, dto, -1);
573 RefreshDTObjects(dto, win, NULL, 0); // seems to be needed by text datatype to render more than first line at start...
576 /*********************************************************************************************/
578 static void OpenDTO(void)
580 struct DTMethod *triggermethods;
581 ULONG *methods;
582 STRPTR objname = NULL;
583 IPTR val;
584 struct DataType *dt;
586 old_dto = dto;
590 if (!old_dto && args[ARG_CLIPBOARD])
592 APTR clipunit = 0;
594 if (args[ARG_CLIPUNIT]) clipunit = *(APTR *)args[ARG_CLIPUNIT];
596 D(bug("MultiView: calling NewDTObject\n"));
598 dto = NewDTObject(clipunit, ICA_TARGET , (IPTR)model_obj,
599 GA_ID , 1000 ,
600 DTA_SourceType, DTST_CLIPBOARD ,
601 DTA_TextAttr , (IPTR)&textattr,
602 TAG_DONE);
604 D(bug("MultiView: NewDTObject returned %x\n", dto));
606 else
608 dto = NewDTObject(filename, ICA_TARGET , (IPTR)model_obj,
609 GA_ID , 1000 ,
610 DTA_TextAttr , (IPTR)&textattr,
611 TAG_DONE);
614 if (!dto)
616 ULONG errnum = IoErr();
618 if (errnum == DTERROR_UNKNOWN_DATATYPE)
620 BPTR lock = Lock(filename,ACCESS_READ);
621 if (lock)
623 struct DataType *dtn;
624 if ((dtn = ObtainDataTypeA(DTST_FILE, (APTR)lock, NULL)))
626 if (!Stricmp(dtn->dtn_Header->dth_Name, "directory"))
628 /* file is a directory and no directory.datatype is installed */
629 strncpy(filenamebuffer, (filename ? filename : (STRPTR)""), 298);
630 filenamebuffer[298]=0;
632 if (strlen(filenamebuffer) &&
633 filenamebuffer[strlen(filenamebuffer)-1] != ':' &&
634 filenamebuffer[strlen(filenamebuffer)-1] != '/')
636 strcat(filenamebuffer,"/");
639 filename = GetFileName(MSG_ASL_OPEN_TITLE);
640 if (filename) continue;
642 ReleaseDataType(dtn);
644 UnLock(lock);
648 if (errnum >= DTERROR_UNKNOWN_DATATYPE)
649 __sprintf(s, GetDTString(errnum), filename);
650 else
651 Fault(errnum, 0, s, 256);
653 if (!old_dto)
655 /* Check if file is 0-length, fail silently (AOS confirmed) */
656 STRPTR msg = s;
657 BPTR lock = Lock(filename, ACCESS_READ);
658 if (lock)
660 struct FileInfoBlock * fib = AllocDosObject(DOS_FIB, NULL);
661 if (Examine(lock, fib))
663 if (fib->fib_Size == 0)
665 /* prog_exitcode = 20; */ /* ABIV1 Multiview no longer exits in Cleanup */
666 msg = NULL;
669 FreeDosObject(DOS_FIB, fib);
670 UnLock(lock);
673 Cleanup(msg);
675 dto = old_dto;
676 return;
678 } while (!dto);
680 strncpy(filenamebuffer, (filename ? filename : (STRPTR)""), 299);
682 SetAttrs(vert_to_dto_ic_obj, ICA_TARGET, (IPTR)dto, TAG_DONE);
683 SetAttrs(horiz_to_dto_ic_obj, ICA_TARGET, (IPTR)dto, TAG_DONE);
684 #if BACK_CONNECTION
685 SetAttrs(model_to_dto_ic_obj, ICA_TARGET, (IPTR)dto, TAG_DONE);
686 #endif
688 val = 0;
689 GetDTAttrs(dto, DTA_NominalHoriz, (IPTR)&val, TAG_DONE);
690 pdt_origwidth = winwidth = (WORD)val;
691 GetDTAttrs(dto, DTA_NominalVert , (IPTR)&val, TAG_DONE);
692 pdt_origheight = winheight = (WORD)val;
693 pdt_zoom = 1;
696 * Add 4 Pixels for border around DataType-Object
697 * See AddDTOToWin() for details
699 if(winwidth)
701 winwidth += 4;
704 if(winheight)
706 winheight += 4;
709 GetDTAttrs(dto, DTA_ObjName, (IPTR)&objname, TAG_DONE);
710 strncpy(objnamebuffer, objname ? objname : filenamebuffer, 299);
712 dt = NULL;
713 dto_subclass_gid = 0;
714 if (GetDTAttrs(dto, DTA_DataType, (IPTR)&dt, TAG_DONE))
716 if (dt)
718 dto_subclass_gid = dt->dtn_Header->dth_GroupID;
722 dto_supports_write = FALSE;
723 dto_supports_write_iff = FALSE;
724 dto_supports_print = FALSE;
725 dto_supports_copy = FALSE;
726 dto_supports_selectall = FALSE;
727 dto_supports_clearselected = FALSE;
729 if (DoWriteMethod(NULL, DTWM_RAW)) dto_supports_write = TRUE; /* probe raw saving */
730 if ((methods = GetDTMethods(dto)))
732 if (FindMethod(methods, DTM_WRITE)) dto_supports_write_iff = TRUE;
733 if (FindMethod(methods, DTM_PRINT)) dto_supports_print = TRUE;
734 if (FindMethod(methods, DTM_COPY)) dto_supports_copy = TRUE;
735 if (FindMethod(methods, DTM_SELECT)) dto_supports_selectall = TRUE;
736 if (FindMethod(methods, DTM_CLEARSELECTED)) dto_supports_clearselected = TRUE;
739 dto_supports_activate_field = FALSE;
740 dto_supports_next_field = FALSE;
741 dto_supports_prev_field = FALSE;
742 dto_supports_retrace = FALSE;
743 dto_supports_browse_next = FALSE;
744 dto_supports_browse_prev = FALSE;
745 dto_supports_search = FALSE;
746 dto_supports_search_next = FALSE;
747 dto_supports_search_prev = FALSE;
749 if ((triggermethods = (struct DTMethod *)GetDTTriggerMethods(dto)))
751 if (FindTriggerMethod(triggermethods, NULL, STM_ACTIVATE_FIELD)) dto_supports_activate_field = TRUE;
752 if (FindTriggerMethod(triggermethods, NULL, STM_NEXT_FIELD)) dto_supports_next_field = TRUE;
753 if (FindTriggerMethod(triggermethods, NULL, STM_PREV_FIELD)) dto_supports_prev_field = TRUE;
754 if (FindTriggerMethod(triggermethods, NULL, STM_RETRACE)) dto_supports_retrace = TRUE;
755 if (FindTriggerMethod(triggermethods, NULL, STM_BROWSE_NEXT)) dto_supports_browse_next = TRUE;
756 if (FindTriggerMethod(triggermethods, NULL, STM_BROWSE_PREV)) dto_supports_browse_prev = TRUE;
757 if (FindTriggerMethod(triggermethods, NULL, STM_SEARCH)) dto_supports_search = TRUE;
758 if (FindTriggerMethod(triggermethods, NULL, STM_SEARCH_NEXT)) dto_supports_search_next = TRUE;
759 if (FindTriggerMethod(triggermethods, NULL, STM_SEARCH_PREV)) dto_supports_search_prev = TRUE;
762 D(bug("\nMultiview: Found Methods:%s%s%s%s%s%s\n",
763 dto_supports_write ? " DTM_WRITE->RAW" : "",
764 dto_supports_write_iff ? " DTM_WRITE->IFF" : "",
765 dto_supports_print ? " DTM_PRINT" : "",
766 dto_supports_copy ? " DTM_COPY" : "",
767 dto_supports_selectall ? " DTM_SELECT" : "",
768 dto_supports_clearselected ? " DTM_CLEARSELECTED" : ""));
770 D(bug("Multiview: Found Triggers:%s%s%s%s%s%s%s\n\n",
771 dto_supports_activate_field ? " STM_ACTIVATE_FIELD" : "",
772 dto_supports_next_field ? " STM_NEXT_FIELD" : "",
773 dto_supports_prev_field ? " STM_PREV_FIELD" : "",
774 dto_supports_retrace ? " STM_RETRACE" : "",
775 dto_supports_browse_next ? " STM_BROWSE_NEXT" : "",
776 dto_supports_browse_prev ? " STM_BROWSE_PREV" : "",
777 dto_supports_search ? " STM_SEARCH" : "",
778 dto_supports_search_next ? " STM_SEARCH_NEXT" : "",
779 dto_supports_search_prev ? " STM_SEARCH_PREV" : ""));
781 if (old_dto)
783 if (win) RemoveDTObject(win, old_dto);
784 DisposeDTObject(old_dto);
786 if (win)
788 AddDTOToWin();
789 SetWindowTitles(win, objnamebuffer, (UBYTE *)~0);
790 SetMenuFlags();
792 // adopt object to current settings
793 if (dto_subclass_gid == GID_TEXT)
795 SetDTAttrs (dto, NULL, NULL,
796 TDTA_WordWrap, tdt_text_wordwrap,
797 TAG_DONE);
798 DoLayout(TRUE);
800 else if (dto_subclass_gid == GID_PICTURE)
802 // zoom has been set to 1 above
803 FitToWindow();
804 SetDTAttrs (dto, NULL, NULL,
805 PDTA_DestMode, (pdt_force_map) ? PMODE_V42 : PMODE_V43,
806 TAG_DONE);
807 SetDTAttrs (dto, NULL, NULL,
808 PDTA_DitherQuality, pdt_pict_dither ? 4 : 0,
809 TAG_DONE);
810 DoLayout(TRUE);
816 /*********************************************************************************************/
818 static void CloseDTO(void)
820 if (dto)
822 if (win) RemoveDTObject(win, dto);
823 DisposeDTObject(dto);
824 dto = NULL;
828 /*********************************************************************************************/
830 static void MakeWindow(void)
832 WORD minwidth, minheight;
833 if (pdt_fit_win)
834 winwidth = winheight = 0;
836 if (wincoords.MinX == 0)
837 wincoords.MinX = (- scr->LeftEdge);
838 if (wincoords.MinY == 0)
839 wincoords.MinY = ( (- scr->TopEdge) < (scr->BarHeight + 1) ) ? (scr->BarHeight + 1) : (- scr->TopEdge);
840 if (wincoords.MaxX == 0)
841 wincoords.MaxX = scr->ViewPort.DWidth;
842 if (wincoords.MaxY == 0)
843 wincoords.MaxY = scr->ViewPort.DHeight - scr->BarHeight - 1;
845 minwidth = ( (winwidth) && (winwidth < 50) ) ? winwidth : 50;
846 minheight = ( (winheight) && (winheight < 50) ) ? winheight : 50;
848 win = OpenWindowTags(0, WA_PubScreen , (IPTR)scr ,
849 WA_Title , (IPTR)objnamebuffer ,
850 WA_CloseGadget , TRUE ,
851 WA_DepthGadget , TRUE ,
852 WA_DragBar , TRUE ,
853 WA_SizeGadget , TRUE ,
854 WA_Activate , TRUE ,
855 WA_SimpleRefresh , TRUE ,
856 WA_NoCareRefresh , TRUE ,
857 WA_NewLookMenus , TRUE ,
858 WA_Left , wincoords.MinX ,
859 WA_Top , wincoords.MinY ,
860 ( winwidth ? WA_InnerWidth
861 : WA_Width ) ,
862 ( winwidth ? winwidth
863 : wincoords.MaxX ) ,
864 ( winheight ? WA_InnerHeight
865 : WA_Height ) ,
866 ( winheight ? winheight
867 : wincoords.MaxY ) ,
868 WA_AutoAdjust , TRUE ,
869 WA_MinWidth , minwidth ,
870 WA_MinHeight , minheight ,
871 WA_MaxWidth , 16383 ,
872 WA_MaxHeight , 16383 ,
873 WA_Gadgets , (IPTR)gad[GAD_UPARROW],
874 WA_IDCMP , IDCMP_CLOSEWINDOW |
875 IDCMP_GADGETUP |
876 IDCMP_GADGETDOWN |
877 IDCMP_MOUSEMOVE |
878 IDCMP_VANILLAKEY |
879 IDCMP_RAWKEY |
880 IDCMP_IDCMPUPDATE |
881 IDCMP_MENUPICK |
882 IDCMP_NEWSIZE |
883 IDCMP_INTUITICKS ,
884 TAG_DONE);
886 if (!win) Cleanup(MSG(MSG_CANT_CREATE_WIN));
888 AddDTOToWin();
890 SetMenuStrip(win, menus);
892 winmask = 1L << win->UserPort->mp_SigBit;
893 if (!(msgport = CreateMsgPort()))
895 Cleanup(MSG(MSG_CANT_CREATE_MSGPORT));
897 if (!(appwindow = AddAppWindow(0, 0, win, msgport, NULL)))
899 Cleanup(MSG(MSG_CANT_ADD_APPWINDOW));
901 msgmask = 1L << msgport->mp_SigBit;
904 /*********************************************************************************************/
906 static void KillWindow(void)
908 if (win)
910 if (dto) RemoveDTObject(win, dto);
911 if (menus) ClearMenuStrip(win);
912 CloseWindow(win);
913 win = NULL;
915 winwidth = winheight = 0;
919 /*********************************************************************************************/
921 static void InitIScreenNotify(void)
923 if (!(isnport = CreateMsgPort()))
925 Cleanup(MSG(MSG_CANT_CREATE_MSGPORT));
927 if ( (isnstarted = StartScreenNotifyTags(SNA_Notify, SNOTIFY_WAIT_REPLY |
928 SNOTIFY_BEFORE_CLOSEWB |
929 SNOTIFY_AFTER_OPENWB,
930 SNA_MsgPort, isnport,
931 SNA_Priority, 0,
932 TAG_END )) )
934 isnmask = 1L << isnport->mp_SigBit;
938 /************************************************************************************/
939 /* Handle Intuition's ScreenNotify signals */
941 static void HandleIScreenNotify(void)
943 struct ScreenNotifyMessage *isnmsg;
944 while ((isnmsg = (struct ScreenNotifyMessage *) GetMsg (isnport)))
946 IPTR isnmclass = isnmsg->snm_Class;
948 switch (isnmclass)
950 case SNOTIFY_BEFORE_CLOSEWB:
951 D(bug("[Multiview] received isn before close WB msg\n"));
952 if (win)
954 WinCleanup();
956 ReplyMsg ((struct Message *) isnmsg);
957 break;
958 case SNOTIFY_AFTER_OPENWB:
959 ReplyMsg ((struct Message *) isnmsg);
960 D(bug("[Multiview] received isn after open WB msg\n"));
961 if (!win)
963 InitWin();
965 break;
966 default:
967 ReplyMsg ((struct Message *) isnmsg);
968 D(bug("[Multiview] received unexpected msg!\n"));
969 break;
974 /*********************************************************************************************/
976 static void ScrollTo(UWORD dir, UWORD quali)
978 IPTR val;
979 LONG oldtop, top, total, visible, delta = 1;
980 BOOL horiz;
981 BOOL inc;
983 #ifdef __AROS__
984 switch(dir)
986 case RAWKEY_NM_WHEEL_UP:
987 dir = CURSORUP;
988 delta = 3;
989 break;
991 case RAWKEY_NM_WHEEL_DOWN:
992 dir = CURSORDOWN;
993 delta = 3;
994 break;
996 case RAWKEY_NM_WHEEL_LEFT:
997 dir = CURSORLEFT;
998 delta = 3;
999 break;
1001 case RAWKEY_NM_WHEEL_RIGHT:
1002 dir = CURSORRIGHT;
1003 delta = 3;
1004 break;
1006 #endif
1008 if ((dir == CURSORUP) || (dir == CURSORDOWN))
1010 horiz = FALSE;
1011 if (dir == CURSORUP) inc = FALSE; else inc = TRUE;
1013 GetDTAttrs(dto, DTA_TopVert, (IPTR)&val, TAG_DONE);
1014 top = (LONG)val;
1015 GetDTAttrs(dto, DTA_TotalVert, (IPTR)&val, TAG_DONE);
1016 total = (LONG)val;
1017 GetDTAttrs(dto, DTA_VisibleVert, (IPTR)&val, TAG_DONE);
1018 visible = (LONG)val;
1020 else
1022 horiz = TRUE;
1023 if (dir == CURSORLEFT) inc = FALSE; else inc = TRUE;
1025 GetDTAttrs(dto, DTA_TopHoriz, (IPTR)&val, TAG_DONE);
1026 top = (LONG)val;
1027 GetDTAttrs(dto, DTA_TotalHoriz, (IPTR)&val, TAG_DONE);
1028 total = (LONG)val;
1029 GetDTAttrs(dto, DTA_VisibleHoriz, (IPTR)&val, TAG_DONE);
1030 visible = (LONG)val;
1034 oldtop = top;
1035 if (quali & (IEQUALIFIER_LALT | IEQUALIFIER_RALT | IEQUALIFIER_CONTROL))
1037 if (inc) top = total; else top = 0;
1039 else
1040 if (quali & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
1042 if (inc) top += visible - 1; else top -= visible - 1;
1044 else
1046 if (inc) top += delta; else top -= delta;
1049 if (top + visible > total) top = total - visible;
1050 if (top < 0) top = 0;
1052 if (top != oldtop)
1054 struct Gadget *g;
1056 if (horiz)
1058 g = (struct Gadget *)gad[GAD_HORIZSCROLL];
1060 else
1062 g = (struct Gadget *)gad[GAD_VERTSCROLL];
1065 SetGadgetAttrs(g, win, NULL, PGA_Top, top,
1066 TAG_DONE);
1068 #ifdef __MORPHOS__
1069 /* Looks like setting PGA_Top on Amiga does not cause OM_NOTIFIEs
1070 to be sent (to dto). Or something like that. */
1072 SetDTAttrs(dto, win, NULL, (horiz ? DTA_TopHoriz : DTA_TopVert), top, TAG_DONE);
1073 #endif
1075 } /* if (top != oldtop) */
1079 /*********************************************************************************************/
1081 static void FitToWindow(void)
1083 if( pdt_fit_win )
1085 int x, y;
1087 x = win->Width - (win->BorderLeft + win->BorderRight + 4);
1088 y = win->Height - (win->BorderTop + win->BorderBottom + 4);
1089 D(bug("=> width %ld height %ld\n", x, y));
1090 DoScaleMethod(x, y, pdt_keep_aspect);
1091 // DoLayout(TRUE); seems to be done by intuition ?
1095 /*********************************************************************************************/
1097 static void HandleAll(void)
1099 struct IntuiMessage *msg;
1100 struct TagItem *tstate, *tags;
1101 struct TagItem *tag;
1102 struct MenuItem *item;
1103 struct Gadget *activearrowgad = NULL;
1104 WORD arrowticker = 0, activearrowkind = 0;
1105 IPTR tidata;
1106 UWORD men;
1107 BOOL quitme = FALSE;
1108 const STRPTR not_supported = "Sorry, not supported yet\n";
1109 ULONG sigs;
1111 while (!quitme)
1113 // if ( (sigs & winmask) || (sigs & msgmask) )
1114 TEXT editorvarbuffer[300];
1115 struct AppMessage *appmsg;
1117 sigs = Wait(msgmask | winmask | isnmask);
1119 if (sigs & isnmask)
1121 HandleIScreenNotify();
1124 while ( (msgport) && (appmsg = (struct AppMessage *) GetMsg(msgport)) )
1126 if (appmsg->am_Type == AMTYPE_APPWINDOW)
1128 if (appmsg->am_NumArgs >= 1)
1130 NameFromLock(appmsg->am_ArgList->wa_Lock, filenamebuffer, 299);
1131 AddPart(filenamebuffer, appmsg->am_ArgList->wa_Name, 299);
1132 filename = filenamebuffer;
1133 D(bug("[Multiview] appwindow received message: filename = %s\n", filename));
1137 ReplyMsg ((struct Message *) appmsg);
1138 ActivateWindow(win);
1140 if (filename)
1142 OpenDTO();
1143 FitToWindow();
1146 } /* while ((appmsg = (struct AppMessage *) GetMsg(msgport))) */
1148 while( (win) && (msg = (struct IntuiMessage *)GetMsg(win->UserPort)) )
1150 // D(if (msg->Class!=IDCMP_INTUITICKS) bug(" Msg Class %08lx\n", (long)msg->Class));
1151 switch (msg->Class)
1153 case IDCMP_CLOSEWINDOW:
1154 quitme = TRUE;
1155 break;
1157 case IDCMP_VANILLAKEY:
1158 D(bug("[Multiview] Vanillakey %d\n", (int)msg->Code));
1159 switch(msg->Code)
1161 case 27: /* ESC */
1162 quitme = TRUE;
1163 break;
1165 case 13: /* RETURN */
1166 if (dto_supports_activate_field) DoTrigger(STM_ACTIVATE_FIELD);
1167 else if (dto_supports_search) DoTrigger(STM_SEARCH);
1168 RefreshDTObjects (dto, win, NULL, (IPTR) NULL);
1169 break;
1171 case 9: /* TAB */
1172 if (dto_supports_next_field) DoTrigger(STM_NEXT_FIELD);
1173 else if (dto_supports_search_next) DoTrigger(STM_SEARCH_NEXT);
1174 break;
1176 case 8: /* Backspace */
1177 if (dto_supports_retrace) DoTrigger(STM_RETRACE);
1178 else ScrollTo(CURSORUP, IEQUALIFIER_LSHIFT);
1179 break;
1181 case ' ':
1182 ScrollTo(CURSORDOWN, IEQUALIFIER_LSHIFT);
1183 break;
1185 case '>':
1186 if (dto_supports_browse_next) DoTrigger(STM_BROWSE_NEXT);
1187 break;
1189 case '<':
1190 if (dto_supports_browse_prev) DoTrigger(STM_BROWSE_PREV);
1191 break;
1193 } /* switch(msg->Code) */
1194 if (strchr(MSG(MSG_SHORTCUT_EDITOR), ToUpper(msg->Code)))
1196 if ( (GetVar("editor", (STRPTR) editorvarbuffer, 299, GVF_GLOBAL_ONLY)) != -1L )
1198 __sprintf(s, "Run QUIET \"%s\" \"%s\"", editorvarbuffer, filename );
1199 D(bug("[Multiview] editor command: '%s'\n", s));
1200 if (SystemTags(s, TAG_END))
1201 DisplayBeep(NULL);
1204 break;
1206 case IDCMP_RAWKEY:
1207 switch(msg->Code)
1209 #ifdef __AROS__
1210 case RAWKEY_NM_WHEEL_UP:
1211 case RAWKEY_NM_WHEEL_DOWN:
1212 case RAWKEY_NM_WHEEL_LEFT:
1213 case RAWKEY_NM_WHEEL_RIGHT:
1214 #endif
1215 case CURSORUP:
1216 case CURSORDOWN:
1217 case CURSORRIGHT:
1218 case CURSORLEFT:
1219 ScrollTo(msg->Code, msg->Qualifier);
1220 break;
1222 #ifdef __AROS__
1223 case RAWKEY_HOME: /* HOME */
1224 ScrollTo(CURSORUP, IEQUALIFIER_LALT);
1225 break;
1227 case RAWKEY_END: /* END */
1228 ScrollTo(CURSORDOWN, IEQUALIFIER_LALT);
1229 break;
1231 case RAWKEY_PAGEUP: /* PAGE UP */
1232 ScrollTo(CURSORUP, IEQUALIFIER_LSHIFT);
1233 break;
1235 case RAWKEY_PAGEDOWN: /* PAGE DOWN */
1236 ScrollTo(CURSORDOWN, IEQUALIFIER_LSHIFT);
1237 break;
1238 #endif
1240 case 0x42: /* SHIFT TAB? */
1241 if (msg->Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
1243 if (dto_supports_prev_field) DoTrigger(STM_PREV_FIELD);
1244 else if (dto_supports_search_prev) DoTrigger(STM_SEARCH_PREV);
1246 break;
1248 } /* switch(msg->Code) */
1249 break;
1251 case IDCMP_GADGETDOWN:
1252 arrowticker = 3;
1253 activearrowgad = (struct Gadget *)msg->IAddress;
1254 switch(activearrowgad->GadgetID)
1256 case GAD_UPARROW:
1257 activearrowkind = CURSORUP;
1258 ScrollTo(CURSORUP, 0);
1259 break;
1261 case GAD_DOWNARROW:
1262 activearrowkind = CURSORDOWN;
1263 ScrollTo(CURSORDOWN, 0);
1264 break;
1266 case GAD_LEFTARROW:
1267 activearrowkind = CURSORLEFT;
1268 ScrollTo(CURSORLEFT, 0);
1269 break;
1271 case GAD_RIGHTARROW:
1272 activearrowkind = CURSORRIGHT;
1273 ScrollTo(CURSORRIGHT, 0);
1274 break;
1276 default:
1277 activearrowkind = 0;
1278 break;
1281 break;
1283 case IDCMP_INTUITICKS:
1284 if (activearrowkind)
1286 if (arrowticker)
1288 arrowticker--;
1290 else if (activearrowgad->Flags & GFLG_SELECTED)
1292 ScrollTo(activearrowkind, 0);
1295 break;
1297 case IDCMP_GADGETUP:
1298 switch(((struct Gadget *)msg->IAddress)->GadgetID)
1300 case GAD_UPARROW:
1301 case GAD_DOWNARROW:
1302 case GAD_LEFTARROW:
1303 case GAD_RIGHTARROW:
1304 activearrowkind = 0;
1305 break;
1307 break;
1309 case IDCMP_MENUPICK:
1310 men = msg->Code;
1311 // D(bug(" * MV: men %08lx\n", (long)men));
1312 while(men != MENUNULL)
1314 if ((item = ItemAddress(menus, men)))
1316 // D(bug(" * MV: item %08lx menus %08lx\n", (long)item, (long)menus));
1317 switch((IPTR)GTMENUITEM_USERDATA(item))
1319 case MSG_MEN_PROJECT_OPEN:
1320 filename = GetFileName(MSG_ASL_OPEN_TITLE);
1321 if (filename) OpenDTO();
1322 break;
1324 case MSG_MEN_PROJECT_SAVEAS:
1325 filename = GetFileName(MSG_ASL_SAVE_TITLE);
1326 if (filename) DoWriteMethod(filename, DTWM_RAW);
1327 break;
1329 case MSG_MEN_PROJECT_SAVEAS_IFF:
1330 filename = GetFileName(MSG_ASL_SAVE_TITLE);
1331 if (filename) DoWriteMethod(filename, DTWM_IFF);
1332 break;
1334 case MSG_MEN_PROJECT_PRINT:
1335 DoPrintMethod();
1336 break;
1338 case MSG_MEN_PROJECT_ABOUT:
1339 About();
1340 break;
1342 case MSG_MEN_PROJECT_QUIT:
1343 quitme = TRUE;
1344 break;
1346 case MSG_MEN_EDIT_MARK:
1347 #if defined(__AROS__) && !defined(__MORPHOS__)
1348 if (StartDragSelect(dto))
1349 #else
1351 struct DTSpecialInfo *si;
1354 ** ClipView example on AmigaDev CD does just the following.
1355 ** None of the checks AROS datatypes.library/StartDragSelect()
1356 ** does.
1359 si = (struct DTSpecialInfo *)(((struct Gadget *)dto)->SpecialInfo);
1360 si->si_Flags |= DTSIF_DRAGSELECT;
1362 #endif
1364 //TODO: change mouse pointer to crosshair
1366 break;
1368 case MSG_MEN_EDIT_COPY:
1370 struct dtGeneral dtg;
1372 dtg.MethodID = DTM_COPY;
1373 dtg.dtg_GInfo = NULL;
1375 DoDTMethodA(dto, win, NULL, (Msg)&dtg);
1377 break;
1379 case MSG_MEN_EDIT_SELECTALL:
1380 OutputMessage(not_supported);
1381 break;
1383 case MSG_MEN_EDIT_CLEARSELECTED:
1385 struct dtGeneral dtg;
1387 dtg.MethodID = DTM_CLEARSELECTED;
1388 dtg.dtg_GInfo = NULL;
1390 DoDTMethodA(dto, win, NULL, (Msg)&dtg);
1392 break;
1394 case MSG_MEN_WINDOW_SEPSCREEN:
1395 OutputMessage(not_supported);
1396 break;
1398 case MSG_MEN_WINDOW_MINIMIZE:
1399 OutputMessage(not_supported);
1400 break;
1402 case MSG_MEN_WINDOW_NORMAL:
1403 OutputMessage(not_supported);
1404 break;
1406 case MSG_MEN_WINDOW_MAXIMIZE:
1407 OutputMessage(not_supported);
1408 break;
1410 case MSG_MEN_SETTINGS_SAVEDEF:
1411 OutputMessage(not_supported);
1412 break;
1414 case MSG_MEN_PICT_ZOOM_IN:
1415 pdt_zoom++;
1416 if (pdt_zoom == -1 ) pdt_zoom = 1;
1417 DoZoom(pdt_zoom);
1418 break;
1420 case MSG_MEN_PICT_ZOOM_OUT:
1421 pdt_zoom--;
1422 if (pdt_zoom == 0 ) pdt_zoom = -2;
1423 DoZoom(pdt_zoom);
1424 break;
1426 case MSG_MEN_PICT_RESET:
1427 pdt_zoom = 1;
1428 DoZoom(pdt_zoom);
1429 break;
1431 case MSG_MEN_PICT_FIT_WIN:
1432 pdt_fit_win = (item->Flags & CHECKED) ? TRUE : FALSE;
1433 FitToWindow();
1434 DoLayout(TRUE);
1435 break;
1437 case MSG_MEN_PICT_KEEP_ASPECT:
1438 pdt_keep_aspect = (item->Flags & CHECKED) ? TRUE : FALSE;
1439 FitToWindow();
1440 DoLayout(TRUE);
1441 break;
1443 case MSG_MEN_PICT_FORCE_MAP:
1444 pdt_force_map = (item->Flags & CHECKED) ? TRUE : FALSE;
1445 SetDTAttrs (dto, NULL, NULL,
1446 PDTA_DestMode, (pdt_force_map) ? PMODE_V42 : PMODE_V43,
1447 TAG_DONE);
1448 DoLayout(TRUE);
1449 break;
1451 case MSG_MEN_PICT_DITHER:
1452 pdt_pict_dither = (item->Flags & CHECKED) ? TRUE : FALSE;
1453 SetDTAttrs (dto, NULL, NULL,
1454 PDTA_DitherQuality, pdt_pict_dither ? 4 : 0,
1455 TAG_DONE);
1456 DoLayout(TRUE);
1457 break;
1459 case MSG_MEN_TEXT_WORDWRAP:
1460 tdt_text_wordwrap = (item->Flags & CHECKED) ? TRUE : FALSE;
1462 if (tdt_text_wordwrap)
1463 bug("wordwrap enabled\n");
1464 else
1465 bug("wordwrap disabled\n");
1467 SetDTAttrs (dto, NULL, NULL,
1468 TDTA_WordWrap, tdt_text_wordwrap,
1469 TAG_DONE);
1470 DoLayout(TRUE);
1471 break;
1473 case MSG_MEN_TEXT_SEARCH:
1474 if (dto_supports_search) DoTrigger(STM_SEARCH);
1475 break;
1477 case MSG_MEN_TEXT_SEARCH_PREV:
1478 if (dto_supports_search_prev) DoTrigger(STM_SEARCH_PREV);
1479 break;
1481 case MSG_MEN_TEXT_SEARCH_NEXT:
1482 if (dto_supports_search_next) DoTrigger(STM_SEARCH_NEXT);
1483 break;
1485 } /* switch(GTMENUITEM_USERDATA(item)) */
1487 men = item->NextSelect;
1489 else
1491 men = MENUNULL;
1494 } /* while(men != MENUNULL) */
1495 break;
1497 case IDCMP_NEWSIZE:
1498 D(bug("IDCMP NEWSIZE\n"));
1499 FitToWindow();
1500 break;
1502 case IDCMP_IDCMPUPDATE:
1503 tstate = tags = (struct TagItem *) msg->IAddress;
1504 while ((tag = NextTagItem(&tstate)) != NULL)
1506 tidata = tag->ti_Data;
1507 // D(bug("IDCMP UPDATE %08lx %08lx\n", (long)tag->ti_Tag, (long)tag->ti_Data));
1508 switch (tag->ti_Tag)
1510 /* Change in busy state */
1511 case DTA_Busy:
1512 if (tidata)
1513 SetWindowPointer (win, WA_BusyPointer, TRUE, TAG_DONE);
1514 else
1515 SetWindowPointer (win, WA_Pointer, (IPTR) NULL, TAG_DONE);
1516 break;
1518 case DTA_Title:
1519 SetWindowTitles(win, (UBYTE *)tidata, (UBYTE *)~0);
1520 break;
1522 /* Error message */
1523 case DTA_ErrorLevel:
1524 /* if (tidata)
1526 errnum = GetTagData (DTA_ErrorNumber, NULL, tags);
1527 PrintErrorMsg (errnum, (STRPTR) options[OPT_NAME]);
1529 break;
1531 /* Time to refresh */
1532 case DTA_Sync:
1533 /* Refresh the DataType object */
1534 D(bug("Multiview: DTA_SYNC\n"));
1535 RefreshDTObjects (dto, win, NULL, (IPTR) NULL);
1536 break;
1538 } /* switch (tag->ti_Tag) */
1540 } /* while ((tag = NextTagItem ((const struct TagItem **)&tstate))) */
1541 break;
1543 } /* switch (msg->Class) */
1545 ReplyMsg((struct Message *)msg);
1547 } /* while((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
1549 } /* while (!quitme) */
1552 /*********************************************************************************************/
1554 void InitWin(void)
1556 InitDefaults();
1557 LoadFont();
1558 MakeICObjects();
1559 OpenDTO();
1560 GetVisual();
1561 MakeGadgets();
1562 menus = MakeMenus(nm);
1563 pictmenus = MakeMenus(nmpict);
1564 textmenus = MakeMenus(nmtext);
1565 SetMenuFlags();
1566 MakeWindow();
1567 SetDTAttrs (dto, NULL, NULL,
1568 PDTA_DestMode, (pdt_force_map) ? PMODE_V42 : PMODE_V43,
1569 PDTA_DitherQuality, (pdt_pict_dither) ? 4 : 0,
1570 TDTA_WordWrap, tdt_text_wordwrap,
1571 TAG_DONE);
1572 FitToWindow();
1575 /*********************************************************************************************/
1577 int main(int argc, char **argv)
1579 int rc;
1581 /* This is for when Cleanup() is called */
1582 rc = setjmp(exit_buf);
1583 if (rc)
1584 return rc;
1586 wincoords.MinX = 0;
1587 wincoords.MinY = 0;
1588 wincoords.MaxX = 0;
1589 wincoords.MaxY = 0;
1591 pdt_fit_win = FALSE;
1592 pdt_keep_aspect = FALSE;
1593 pdt_force_map = FALSE;
1594 pdt_pict_dither = TRUE;
1595 tdt_text_wordwrap = TRUE;
1596 separate_screen = FALSE;
1598 InitLocale("System/Utilities/MultiView.catalog", 2);
1599 InitMenus(nm);
1600 InitMenus(nmpict);
1601 InitMenus(nmtext);
1602 OpenLibs();
1604 if (argc == 0)
1606 struct WBStartup *startup = (struct WBStartup *) argv;
1608 if (startup->sm_NumArgs >= 2)
1610 /* FIXME: all arguments but the first are ignored */
1611 cd = CurrentDir(startup->sm_ArgList[1].wa_Lock);
1612 filename = startup->sm_ArgList[1].wa_Name;
1614 else
1616 filename = GetFileName(MSG_ASL_OPEN_TITLE);
1617 if (!filename) Cleanup(NULL);
1620 else
1622 GetArguments();
1625 InitIScreenNotify();
1626 InitWin();
1628 HandleAll();
1629 Cleanup(NULL);
1631 return 0;
1634 /*********************************************************************************************/