3 #define MUIMASTER_YES_INLINE_STDARG
7 #define SYSTEM_REALLY_PRIVATE
11 #include <proto/muimaster.h>
12 #include <proto/intuition.h>
13 #include <proto/dos.h>
14 #include <proto/exec.h>
15 #include <proto/locale.h>
16 #include <proto/icon.h>
19 #include <exec/execbase.h>
22 #include <private/vapor/vapor.h>
23 #include <libraries/mui.h>
24 #include <workbench/startup.h>
25 #include <clib/alib_protos.h>
26 #include <proto/rexxsyslib.h>
30 #include "mcc/classes.h"
32 #include "system/system.h"
34 #include "mcc/pageview_class.h"
35 #include "mcc/documentview_class.h"
36 #include "mcc/outlineview_class.h"
37 #include "mcc/documentlayout_class.h"
38 #include "mcc/toolbar_class.h"
39 #include "mcc/renderer_class.h"
40 #include "mcc/title_class.h"
41 #include "mcc/search_class.h"
42 #include "mcc/thumbnaillist_class.h"
43 #include "mcc/lay_class.h"
44 #include "mcc/annotation_class.h"
45 #include "application.h"
48 #include "pagenumberclass.h"
49 #include "arrowstring_class.h"
54 int __stack
= 1000000;
56 #define PROGNAME "VPDF"
60 #define ARG_TEMPLATE "FILE/M,NEWAPP/S,APPTOFRONT/S"
63 extern struct Library
*CairoBase
;
64 extern char * _ProgramName
; // from libnix startup code
66 struct classinitialization_function
68 ULONG (*initfunc
)(void);
69 void (*endfunc
)(void);
74 static struct classinitialization_function classinitialization_functions
[] = {
75 {create_RendererClass
, delete_RendererClass
},
76 {create_AnnotationClass
, delete_AnnotationClass
},
77 {create_LayClass
, delete_LayClass
},
78 //{create_ThumbnailClass, delete_ThumbnailClass},
79 {create_SearchClass
, delete_SearchClass
},
80 {create_TitleClass
, delete_TitleClass
},
81 {create_ToolbarClass
, delete_ToolbarClass
},
82 {create_ContinuousLayoutClass
, delete_ContinuousLayoutClass
},
83 {create_ContinuousDynamicLayoutClass
, delete_ContinuousDynamicLayoutClass
},
84 {create_SinglePageLayoutClass
, delete_SinglePageLayoutClass
},
85 {create_PageViewClass
, delete_PageViewClass
},
86 {create_OutlineViewClass
, delete_OutlineViewClass
},
87 {create_DocumentViewClass
, delete_DocumentViewClass
},
88 {create_ThumbnailListClass
, delete_ThumbnailListClass
},
89 {create_VPDFSettingsClass
, delete_VPDFSettingsClass
},
90 {create_VPDFWindowClass
, delete_VPDFWindowClass
},
91 {create_VPDFTitleButtonClass
, delete_VPDFTitleButtonClass
},
92 {create_ArrowStringClass
, delete_ArrowStringClass
},
93 {create_VPDFNumberGeneratorClass
, delete_VPDFNumberGeneratorClass
},
94 {create_VPDFPrinterClass
, delete_VPDFPrinterClass
},
95 {create_VPDFClass
, delete_VPDFClass
},
96 {create_LoggerClass
, delete_LoggerClass
},
100 static void cleanupclasses(void)
102 int i
= sizeof(classinitialization_functions
) / sizeof(*classinitialization_functions
) - 1;
106 if (classinitialization_functions
[ i
].done
)
107 classinitialization_functions
[ i
].endfunc();
112 static Object
*_app
= NULL
;
114 void vpdfErrorFunction(int pos
, char *message
)
116 if (_app
!= NULL
&& message
!= NULL
)
117 DoMethod(_app
, MUIM_Application_PushMethod
, _app
, 3, MUIM_VPDF_LogMessage
, MUIV_VPDF_LogMessage_Error
, strdup(message
));
120 static void MessageAddFile(struct MsgPort
*port
, struct MsgPort
*replyport
, struct RexxMsg
*rexxmsg
, STRPTR file
)
125 BPTR lock
= Lock(file
, ACCESS_READ
);
127 strcpy(arexxstr
, "OPEN FILE=");
131 lock
= Lock("", ACCESS_READ
);
132 NameFromLock(lock
, filepath
, sizeof(filepath
));
133 AddPart(filepath
, file
, sizeof(filepath
));
136 NameFromLock(lock
, filepath
, sizeof(filepath
));
140 char *ftemp
= filepath
;
144 while(*ftemp
!= '\0')
151 strlcat(arexxstr
, filepath
, sizeof(arexxstr
));
152 rexxmsg
->rm_Args
[0] = (char *)CreateArgstring(arexxstr
, strlen(arexxstr
));
153 rexxmsg
->rm_Action
= RXCOMM
;
154 PutMsg(port
, (struct Message
*)rexxmsg
);
157 DeleteArgstring(rexxmsg
->rm_Args
[0]);
161 int main(int argc
, char *argv
[])
164 struct ExecBase
*MySysBase
= *(unsigned int*)4;
166 /* make us halt on first hit! */
168 struct Task
*this = FindTask(NULL
);
169 this->tc_ETask
->MaxHits
= 1;
173 MySysBase
->ex_AlertMsgPort
= NULL
;
175 InitSystem(argc
, argv
);
176 /* initialize classes */
183 while (classinitialization_functions
[ i
].initfunc
!= NULL
)
185 if (!classinitialization_functions
[ i
].initfunc())
189 snprintf(message
, sizeof(message
), "Failed to initialize class (%d)", i
);
190 MUI_Request(NULL
, NULL
, 0, "Error...", "OK", message
, TAG_END
);
194 classinitialization_functions
[ i
].done
= TRUE
;
201 struct RDArgs
*myargs
= NULL
;
202 LONG args
[ARG_NUMARGS
] = {0};
203 Object
*app
, *window
;
206 struct MsgPort
*port
= NULL
;
207 struct DiskObject
*disk_object
= NULL
;
211 if(argc
&& !(myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
212 Fault(IoErr(), 0, buf
, sizeof(buf
));
216 if(!args
[ARG_NEWAPP
])
219 port
= FindPort("VPDF.1");
222 struct MsgPort
*replyport
;
223 struct RexxMsg
*rexxmsg
;
226 replyport
= CreateMsgPort();
227 rexxmsg
= CreateRexxMsg(replyport
, NULL
, "VPDF.1");
234 char **files
= (char**)args
[ARG_FILE
];
237 for(i
= 0; files
[i
]; i
++)
238 MessageAddFile(port
, replyport
, rexxmsg
, files
[i
]);
242 struct WBStartup
*wbs
= (struct WBStartup
*)argv
;
247 while(i
< wbs
->sm_NumArgs
)
249 wba
= wbs
->sm_ArgList
+ i
;
253 if(NameFromLock(wba
->wa_Lock
, filename
, sizeof(filename
)))
255 if(AddPart(filename
, (char*)wba
->wa_Name
, sizeof(filename
)))
256 MessageAddFile(port
, replyport
, rexxmsg
, filename
);
264 strcpy(arexxstr
, "APPTOFRONT");
265 rexxmsg
->rm_Args
[0] = (char *)CreateArgstring(arexxstr
, strlen(arexxstr
));
266 rexxmsg
->rm_Action
= RXCOMM
;
269 port
= FindPort("VPDF.1");
273 PutMsg(port
, (struct Message
*)rexxmsg
);
278 DeleteArgstring(rexxmsg
->rm_Args
[0]);
279 DeleteRexxMsg(rexxmsg
);
282 DeleteMsgPort(replyport
);
290 /* build new application object */
291 disk_object
=GetDiskObject(_ProgramName
);
294 MUIA_Application_Title
, PROGNAME
,
295 MUIA_Application_Version
, "$VER: " PROGNAME
" " VERSION
"." REVISION
" ("VERSIONDATE
")""© 2009-2012 by Michal Wozniak",
296 MUIA_Application_Copyright
, "© 2009-2012 by Michal Wozniak",
297 MUIA_Application_Author
, "Michal Wozniak",
298 MUIA_Application_Description
, LOCSTR( MSG_APPLICATION_DESCRIPTION
),
299 MUIA_Application_Base
, "VPDF",
300 MUIA_Application_DiskObject
, disk_object
,
306 DoMethod(app
, MUIM_Application_Load
, MUIV_Application_Load_ENV
);
313 char **files
= (char**)args
[ARG_FILE
];
316 for(i
= 0; files
[i
] != NULL
; i
++)
318 DoMethod(app
, MUIM_VPDF_OpenFile
, 0, files
[i
], MUIV_VPDFWindow_OpenFile_NewTab
);
325 struct WBStartup
*wbs
= (struct WBStartup
*)argv
;
330 while(i
< wbs
->sm_NumArgs
)
332 wba
= wbs
->sm_ArgList
+ i
;
336 if(NameFromLock(wba
->wa_Lock
, filename
, sizeof(filename
)))
338 if(AddPart(filename
, (char*)wba
->wa_Name
, sizeof(filename
)))
340 DoMethod(app
, MUIM_VPDF_OpenFile
, 0, filename
, MUIV_VPDFWindow_OpenFile_NewTab
);
351 DoMethod(app
, MUIM_VPDF_CreateWindow
);
353 while(DoMethod(app
, MUIM_Application_NewInput
, &sigs
) != (ULONG
)MUIV_Application_ReturnID_Quit
)
357 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
);
358 if(sigs
& SIGBREAKF_CTRL_C
) break;
362 DoMethod(app
, MUIM_Application_Save
, MUIV_Application_Save_ENV
);
363 DoMethod(app
, MUIM_Application_Save
, MUIV_Application_Save_ENVARC
);
365 MUI_DisposeObject(app
);
368 FreeDiskObject(disk_object
);