3 #define MUIMASTER_YES_INLINE_STDARG
7 #define AROS_ALMOST_COMPATIBLE
8 #include <proto/muimaster.h>
9 #include <libraries/mui.h>
11 #include <libraries/asl.h>
12 #include <workbench/workbench.h>
14 #include <proto/exec.h>
15 #include <intuition/intuition.h>
16 #include <graphics/gfx.h>
17 #include <exec/libraries.h>
18 #include <proto/graphics.h>
19 #include <proto/intuition.h>
20 #include <proto/icon.h>
22 #include <proto/dos.h>
23 #include <proto/locale.h>
31 #include <proto/alib.h>
32 #include <proto/utility.h>
34 #include <proto/datatypes.h>
35 #include <proto/dtclass.h>
36 #include <datatypes/pictureclass.h>
37 #include <devices/rawkeycodes.h>
39 #include <libraries/gadtools.h>
41 #if !defined(__AROS__)
42 #include <emul/emulregs.h>
43 #include <emul/emulinterface.h>
47 #include <private/vapor/vapor.h>
51 #include "application.h"
54 #include "system/functions.h"
56 #include "mcc/documentview_class.h"
57 #include "mcc/documentlayout_class.h"
58 #include "mcc/toolbar_class.h"
59 #include "mcc/renderer_class.h"
60 #include "mcc/title_class.h"
76 Object
*grpRoot
, *grpTitles
;
78 obj
= DoSuperNew(cl
, obj
,
79 MUIA_Window_Title
,"VPDF",
80 MUIA_Window_Width
, MUIV_Window_Width_Screen(50),
81 MUIA_Window_Height
, MUIV_Window_Height_Screen(50),
82 MUIA_Window_AppWindow
, TRUE
,
83 MUIA_Window_RootObject
,
85 MUIA_Background
, MUII_RegisterBack
,
86 MUIA_Frame
, MUIV_Frame_Register
,
87 MUIA_Group_PageMode
, TRUE
,
88 Child
, grpTitles
= NewObject(getTitleClass(), NULL
,
89 #if !defined(__AROS__)
91 MUIA_Title_Closable
, TRUE
,
92 MUIA_Title_Sortable
, TRUE
,
101 memset(data
, 0, sizeof(struct Data
));
102 data
->id
= GetTagData(MUIA_VPDFWindow_ID
, 0, INITTAGS
);
103 data
->grpRoot
= grpRoot
;
104 data
->grpTitles
= grpTitles
;
106 /* setup window id */
108 DoMethod(obj
, MUIM_Notify
, MUIA_AppMessage
, MUIV_EveryTime
, MUIV_Notify_Application
, 3, MUIM_VPDF_HandleAppMessage
, data
->id
, MUIV_TriggerValue
);
109 DoMethod(grpRoot
, MUIM_Notify
, MUIA_Group_ActivePage
, MUIV_EveryTime
, obj
, 2, MUIM_VPDFWindow_UpdateActive
, MUIV_TriggerValue
);
111 DoMethod(obj
, MUIM_VPDFWindow_CreateTab
);
117 DEFMMETHOD(VPDFWindow_CreateTab
)
121 /* place empty object into tab */
123 DoMethod(data
->grpRoot
, MUIM_Group_InitChange
);
124 DoMethod(data
->grpTitles
, MUIM_Group_InitChange
);
125 DoMethod(data
->grpTitles
, MUIM_Family_AddTail
, VPDFTitleButtonObject
,
127 MUIA_Text_Contents
, LOCSTR( MSG_NOFILE
) ,
128 // MUIA_Text_Copy, TRUE, // acc. to MUI4 autodocs that's already the default
132 DoMethod(data
->grpRoot
, MUIM_Family_AddTail
, VGroup
,
133 MUIA_UserData
, TRUE
, // move it to subclass
134 Child
, RectangleObject
,
138 DoMethod(data
->grpRoot
, MUIM_Group_ExitChange
);
139 DoMethod(data
->grpTitles
, MUIM_Group_ExitChange
);
141 /* return index of new group member */
143 set(data
->grpRoot
, MUIA_Group_ActivePage
, xget(data
->grpRoot
, MUIA_Family_ChildCount
) - 1);
144 return xget(data
->grpRoot
, MUIA_Family_ChildCount
) - 1;
147 DEFMMETHOD(VPDFWindow_OpenFile
)
150 char *filename
= msg
->filename
;
151 int mode
= msg
->mode
;
154 if (mode
== MUIV_VPDFWindow_OpenFile_CurrentTabIfEmpty
)
156 int tabind
= xget(data
->grpRoot
, MUIA_Group_ActivePage
);
157 Object
*tcontents
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, tabind
+ 1); // +1 for title object
158 if (xget(tcontents
, MUIA_UserData
) == TRUE
) // marker for empty page. fix
163 else if (mode
== MUIV_VPDFWindow_OpenFile_NewTab
)
167 else // if (MUIV_VPDFWindow_OpenFile_CurrentTab)
175 Object
*contents
, *tcontents
;
178 tabind
= DoMethod(obj
, MUIM_VPDFWindow_CreateTab
);
180 tabind
= xget(data
->grpRoot
, MUIA_Group_ActivePage
);
182 /* setup new label */
184 tcontents
= (Object
*)DoMethod(data
->grpTitles
, MUIM_Family_GetChild
, tabind
);
185 set(tcontents
, MUIA_Text_Contents
, filename
);
187 /* dispose old contents and add new browser */
189 contents
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, tabind
+ 1); /* +1 for title object */
190 DoMethod(contents
, MUIM_Group_InitChange
);
191 tcontents
= (Object
*)DoMethod(contents
, MUIM_Family_GetChild
, 0);
193 DoMethod(contents
, OM_REMMEMBER
, tcontents
);
194 MUI_DisposeObject(tcontents
);
197 Child
, document
= DocumentViewObject
,
198 MUIA_DocumentView_Renderer
, xget(_app(obj
), MUIA_VPDF_Renderer
),
199 MUIA_DocumentView_FileName
, filename
,
200 MUIA_DocumentView_Layout
, xget(_app(obj
), MUIA_VPDFSettings_Layout
),
201 MUIA_DocumentView_Outline
, xget(_app(obj
), MUIA_VPDFSettings_Outline
),
202 MUIA_DocumentLayout_Scaling
, xget(_app(obj
), MUIA_VPDFSettings_Scaling
),
206 if (tcontents
!= NULL
)
207 DoMethod(contents
, MUIM_Family_AddTail
, tcontents
);
209 set(contents
, MUIA_UserData
, FALSE
); // mark as not empty
210 DoMethod(contents
, MUIM_Group_ExitChange
);
211 DoMethod(obj
, MUIM_VPDFWindow_UpdateActive
, tabind
);
212 return tcontents
!= NULL
;
216 DEFMMETHOD(VPDFWindow_UpdateActive
)
220 Object
*group
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, msg
->active
+ 1); /* +1 for title object */
221 group
= (Object
*)DoMethod(group
, MUIM_Family_GetChild
, 0);
225 void *doc
= xget(group
, MUIA_DocumentView_PDFDocument
);
226 struct pdfAttribute
*attr
= NULL
;
229 attr
= pdfGetAttr(doc
, PDFATTR_TITLE
);
231 if (attr
!= NULL
&& attr
->value
.s
!= NULL
)
232 snprintf(data
->title
, sizeof(data
->title
), "VPDF [%s]", attr
->value
.s
);
233 else if (xget(group
, MUIA_DocumentView_FileName
))
234 snprintf(data
->title
, sizeof(data
->title
), "VPDF [%s]", FilePart((char*)xget(group
, MUIA_DocumentView_FileName
)));
236 snprintf(data
->title
, sizeof(data
->title
), "VPDF");
238 set(obj
, MUIA_Window_Title
, data
->title
);
239 pdfFreeAttr(doc
, attr
);
245 DEFMMETHOD(VPDFWindow_DetachView
)
249 if (msg
->tabind
== MUIV_VPDFWindow_DetachView_Active
)
251 int tabind
= xget(data
->grpRoot
, MUIA_Group_ActivePage
);
252 Object
*tcontents
= (Object
*)DoMethod(data
->grpTitles
, MUIM_Family_GetChild
, tabind
);
253 Object
*contents
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, tabind
+ 1);
255 DoMethod(data
->grpTitles
, MUIM_Group_InitChange
);
256 DoMethod(data
->grpRoot
, MUIM_Group_InitChange
);
258 DoMethod(data
->grpTitles
, OM_REMMEMBER
, tcontents
);
259 DoMethod(data
->grpRoot
, OM_REMMEMBER
, contents
);
261 DoMethod(data
->grpTitles
, MUIM_Group_ExitChange
);
262 DoMethod(data
->grpRoot
, MUIM_Group_ExitChange
);
264 msg
->docview
= contents
;
265 msg
->title
= tcontents
;
267 /* hmm, should we really close the window here? */
269 if (xget(data
->grpTitles
, MUIA_Family_ChildCount
) == 0)
270 DoMethod(_app(data
->grpTitles
), MUIM_Application_PushMethod
, obj
, 3, MUIM_Set
, MUIA_Window_CloseRequest
, TRUE
);
278 DEFMMETHOD(VPDFWindow_AttachView
)
281 int tabind
= msg
->tabind
;
283 Object
*contents
, *tcontents
;
285 if (tabind
== MUIV_VPDFWindow_OpenFile_CurrentTabIfEmpty
)
287 int tabind
= xget(data
->grpRoot
, MUIA_Group_ActivePage
);
288 Object
*tcontents
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, tabind
+ 1); // +1 for title object
289 if (xget(tcontents
, MUIA_UserData
) == TRUE
) // marker for empty page. fix
294 else if (tabind
== MUIV_VPDFWindow_OpenFile_NewTab
)
298 else // if (MUIV_VPDFWindow_OpenFile_CurrentTab)
304 tabind
= DoMethod(obj
, MUIM_VPDFWindow_CreateTab
);
306 tabind
= xget(data
->grpRoot
, MUIA_Group_ActivePage
);
308 /* dispose old title and put whole new object inplace */
310 tcontents
= (Object
*)DoMethod(data
->grpTitles
, MUIM_Family_GetChild
, tabind
);
311 DoMethod(data
->grpTitles
, MUIM_Group_InitChange
);
312 DoMethod(data
->grpTitles
, OM_REMMEMBER
, tcontents
);
313 MUI_DisposeObject(tcontents
);
314 DoMethod(data
->grpTitles
, MUIM_Family_AddTail
, msg
->title
);
315 DoMethod(data
->grpTitles
, MUIM_Group_ExitChange
);
317 /* dispose old contents and add new browser */
319 contents
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, tabind
+ 1); /* +1 for title object */
320 DoMethod(data
->grpRoot
, MUIM_Group_InitChange
);
321 DoMethod(data
->grpRoot
, OM_REMMEMBER
, contents
);
322 MUI_DisposeObject(contents
);
323 DoMethod(data
->grpRoot
, MUIM_Family_AddTail
, msg
->docview
);
324 DoMethod(data
->grpRoot
, MUIM_Group_ExitChange
);
326 DoMethod(obj
, MUIM_VPDFWindow_UpdateActive
, tabind
);
334 switch (msg
->opg_AttrID
)
336 case MUIA_VPDFWindow_ID
:
337 *(ULONG
*)msg
->opg_Storage
= data
->id
;
340 case MUIA_VPDFWindow_PDFDocument
:
343 Object
*group
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, xget(data
->grpRoot
, MUIA_Group_ActivePage
) + 1); /* +1 for title object */
344 group
= (Object
*)DoMethod(group
, MUIM_Family_GetChild
, 0);
347 doc
= xget(group
, MUIA_DocumentView_PDFDocument
);
349 *(ULONG
*)msg
->opg_Storage
= (ULONG
)doc
;
353 case MUIA_VPDFWindow_ActiveDocumentView
:
355 Object
*group
= (Object
*)DoMethod(data
->grpRoot
, MUIM_Family_GetChild
, xget(data
->grpRoot
, MUIA_Group_ActivePage
) + 1); /* +1 for title object */
356 group
= (Object
*)DoMethod(group
, MUIM_Family_GetChild
, 0);
360 *(ULONG
*)msg
->opg_Storage
= (ULONG
)group
;
373 DECMMETHOD(VPDFWindow_CreateTab
)
374 DECMMETHOD(VPDFWindow_OpenFile
)
375 DECMMETHOD(VPDFWindow_UpdateActive
)
376 DECMMETHOD(VPDFWindow_DetachView
)
377 DECMMETHOD(VPDFWindow_AttachView
)
381 DECSUBCLASS_NC(MUIC_Window
, VPDFWindowClass
)
383 struct VPDFTitleButton_Data
388 BEGINMTABLE2(VPDFTitleButtonClass
)
391 DECSUBCLASS2_NC(MUIC_Group
, VPDFTitleButtonClass
)