2 #define AROS_ALMOST_COMPATIBLE
3 #include <proto/muimaster.h>
4 #include <libraries/mui.h>
6 #include <libraries/asl.h>
7 #include <workbench/workbench.h>
9 #include <proto/exec.h>
10 #include <intuition/intuition.h>
11 #include <graphics/gfx.h>
12 #include <exec/libraries.h>
13 #include <proto/graphics.h>
14 #include <proto/intuition.h>
15 #include <proto/icon.h>
17 #include <proto/dos.h>
25 #include <proto/alib.h>
26 #include <proto/utility.h>
28 #include <proto/datatypes.h>
29 #include <proto/dtclass.h>
30 #include <datatypes/pictureclass.h>
31 #include <devices/rawkeycodes.h>
33 #include <libraries/gadtools.h>
35 #if defined(__MORPHOS__)
36 #include <emul/emulregs.h>
37 #include <emul/emulinterface.h>
41 #include <private/vapor/vapor.h>
46 #include "system/functions.h"
48 #include "mcc/documentview_class.h"
49 #include "mcc/documentlayout_class.h"
50 #include "mcc/toolbar_class.h"
51 #include "mcc/renderer_class.h"
52 #include "mcc/title_class.h"
63 static const char *layouts
[] = {"Single page", "Continuous", "Facing pages", "Continuous facing pages", NULL
};
64 static const char *scalings
[] = {"Fit to Window", "Fit to Window Width", "Original", NULL
};
65 static char *ps_levels
[] = {"Level 2", "Level 3", NULL
};
70 unsigned int attribute
;
73 char svalue
[512]; // TODO: group them in an union? fix length limit? -- kiero
78 struct attribute attributes
[MUIA_VPDFSettings_Last
- MUIA_VPDFSettings_First
+ 1] = {0};
79 struct attribute attributes_old
[MUIA_VPDFSettings_Last
- MUIA_VPDFSettings_First
+ 1] = {0};
83 Object
*register_attribute(int id
, char *name
, Object
*obj
, unsigned int attribute
, int group
, int etype
, unsigned int initial
)
85 id
= id
- MUIA_VPDFSettings_First
;
87 attributes
[id
].object
= obj
;
88 attributes
[id
].attribute
= attribute
;
89 attributes
[id
].group
= group
;
90 attributes
[id
].value
= 0;
91 attributes
[id
].svalue
[0] = 0;
92 attributes
[id
].etype
= etype
;
93 stccpy(attributes
[id
].name
, name
, sizeof(attributes
[id
].name
));
94 if (strlen(name
) >= sizeof(attributes
[id
].name
))
95 printf("************SETTINGS ERROR: Attribute name too long:%s****************\n", name
);
100 attributes
[id
].value
= initial
;
103 stccpy(attributes
[id
].svalue
, (char*)initial
, sizeof(attributes
[id
].svalue
));
110 /* save settings to disk */
112 static int setWrite(char *fname
)
114 FILE *f
= fopen(fname
, "w");
120 for(i
=MUIA_VPDFSettings_First
+1; i
<MUIA_VPDFSettings_Last
; i
++)
122 int id
= i
- MUIA_VPDFSettings_First
;
123 if (attributes
[id
].object
!= NULL
)
125 switch (attributes
[id
].etype
)
129 fprintf(f
, "%s 0x%x\n", attributes
[id
].name
, attributes
[id
].value
);
134 if ((enter
= strrchr(attributes
[id
].svalue
, '\n')))
136 fprintf(f
, "%s %s\n", attributes
[id
].name
, attributes
[id
].svalue
);
148 static int setRead(char *fname
)
150 FILE *f
= fopen(fname
, "r");
157 while(fgets(buffer
, sizeof(buffer
), f
))
159 char *delim
= strchr(buffer
, ' ');
163 char *value
= delim
+ 1;
167 /* lookup attribute and set value */
169 for(i
=MUIA_VPDFSettings_First
+1; i
<MUIA_VPDFSettings_Last
; i
++)
171 int id
= i
- MUIA_VPDFSettings_First
;
173 if (attributes
[id
].object
!= NULL
&& 0 == strcmp(name
, attributes
[id
].name
))
175 switch (attributes
[id
].etype
)
179 unsigned int lvalue
= strtol(value
, NULL
, 0); /* values are written as hex, but in case user modifies them... */
180 attributes
[id
].value
= lvalue
;
185 stccpy(attributes
[id
].svalue
, value
, sizeof(attributes
[id
].svalue
));
201 static int setSave(void)
203 return setWrite("ENVARC:VPDF.config");
206 static int setUse(void)
208 return setWrite("ENV:VPDF.config");
211 static Object
*buildGroupSeparator(const char *title
)
214 Object
*grp
= HGroup
,
217 MUIA_Group_VertSpacing
, 0,
218 Child
, p1
= MUI_MakeObject(MUIO_HBar
,1),
219 Child
, LLabel1(title
),
220 Child
, MUI_MakeObject(MUIO_HBar
,1),
223 set(p1
, MUIA_Weight
, 10);
230 obj
= (Object
*) DoSuperNew(cl
, obj
,
232 // MUIA_Group_ActivePage, 1,
234 MUIA_Background
, MUII_GroupBack
,
235 Child
, buildGroupSeparator(LOCSTR(MSG_SETTINGS_DOCUMENT
)),
237 Child
, LLabel1(LOCSTR(MSG_SETTINGS_LAYOUT
)),
238 Child
, register_attribute(ATTR(MUIA_VPDFSettings_Layout
),
239 CycleObject
, MUIA_Cycle_Entries
, layouts
, End
,
240 MUIA_Cycle_Active
, VPDF_SGROUP_LAYOUT
, ETYPE_NUMERIC
, MUIV_DocumentView_Layout_Single
),
242 Child
, LLabel1(LOCSTR(MSG_SETTINGS_SCALING
)),
243 Child
, register_attribute(ATTR(MUIA_VPDFSettings_Scaling
),
244 CycleObject
, MUIA_Cycle_Entries
, scalings
, End
,
245 MUIA_Cycle_Active
, VPDF_SGROUP_SCALING
, ETYPE_NUMERIC
, MUIV_DocumentLayout_Scaling_FitPage
),
249 Child
, buildGroupSeparator(LOCSTR(MSG_WINDOWS
)),
254 Child
, register_attribute(ATTR(MUIA_VPDFSettings_Outline
),
256 MUIA_Selected
, VPDF_SGROUP_GUI
, ETYPE_NUMERIC
, TRUE
),
258 Child
, LLabel1(LOCSTR(MSG_SETTINGS_OUTLINE
)),
263 Child
, register_attribute(ATTR(MUIA_VPDFSettings_OpenLog
),
265 MUIA_Selected
, VPDF_SGROUP_GUI
, ETYPE_NUMERIC
, FALSE
),
267 Child
, LLabel1(LOCSTR(MSG_SETTINGS_LOGWINDOW
)),
276 Child
, register_attribute(ATTR(MUIA_VPDFSettings_PSName
),
278 MUIA_Frame
, MUIV_Frame_String
,
279 MUIA_String_Contents
, "PS:",
280 MUIA_String_MaxLen
, 512,
282 MUIA_String_Contents
, VPDF_SGROUP_PRINTER
, ETYPE_STRING
, (IPTR
) "PS:"),
284 Child
, register_attribute(ATTR(MUIA_VPDFSettings_PrintingMode
),
286 MUIA_Selected
, VPDF_SGROUP_PRINTER
, ETYPE_NUMERIC
, 1),
288 Child
, register_attribute(ATTR(MUIA_VPDFSettings_PSMode
),
289 CycleObject
, MUIA_Cycle_Entries
, ps_levels
, End
,
290 MUIA_Cycle_Active
, VPDF_SGROUP_PRINTER
, ETYPE_NUMERIC
, 0),
301 setRead("ENV:VPDF.config");
303 /* move to objects and make a snapshot */
305 DoMethod(obj
, MUIM_VPDFSettings_ToObjects
);
306 memcpy(attributes_old
, attributes
, sizeof(attributes
));
308 setWrite("ENVARC:VPDF.config");
316 if (msg
->opg_AttrID
> MUIA_VPDFSettings_First
&& msg
->opg_AttrID
< MUIA_VPDFSettings_Last
)
318 int id
= msg
->opg_AttrID
- MUIA_VPDFSettings_First
;
319 switch (attributes
[id
].etype
)
322 *(ULONG
*)msg
->opg_Storage
= (ULONG
)attributes
[id
].value
;
325 *(ULONG
*)msg
->opg_Storage
= (ULONG
)attributes
[id
].svalue
;
339 struct TagItem
*tag
, *_tags
= INITTAGS
;
340 while ((tag
= NextTagItem(&_tags
)))
342 if (tag
->ti_Tag
> MUIA_VPDFSettings_First
&& tag
->ti_Tag
< MUIA_VPDFSettings_Last
)
344 int id
= tag
->ti_Tag
- MUIA_VPDFSettings_First
;
346 switch (attributes
[id
].etype
)
349 attributes
[id
].value
= tag
->ti_Data
;
352 stccpy(attributes
[id
].svalue
, (char*)tag
->ti_Data
, sizeof(attributes
[id
].svalue
));
356 if (attributes
[id
].object
!= NULL
)
357 nnset(attributes
[id
].object
, attributes
[id
].attribute
, tag
->ti_Data
);
365 DEFMMETHOD(VPDFSettings_FromObjects
)
370 data
->groupsmodified
= 0;
372 for(i
=MUIA_VPDFSettings_First
+1; i
<MUIA_VPDFSettings_Last
; i
++)
374 int id
= i
- MUIA_VPDFSettings_First
;
375 if (attributes
[id
].object
!= NULL
)
377 switch(attributes
[id
].etype
)
380 attributes
[id
].value
= xget(attributes
[id
].object
, attributes
[id
].attribute
);
381 if (attributes_old
[id
].value
!= attributes
[id
].value
)
382 data
->groupsmodified
|= attributes
[id
].group
;
385 stccpy(attributes
[id
].svalue
, (char*)xget(attributes
[id
].object
, attributes
[id
].attribute
), sizeof(attributes
[id
].svalue
));
386 if (strcmp(attributes_old
[id
].svalue
, attributes
[id
].svalue
))
387 data
->groupsmodified
|= attributes
[id
].group
;
393 return data
->groupsmodified
;
396 DEFMMETHOD(VPDFSettings_ToObjects
)
402 for(i
=MUIA_VPDFSettings_First
+1; i
<MUIA_VPDFSettings_Last
; i
++)
404 int id
= i
- MUIA_VPDFSettings_First
;
405 if (attributes
[id
].object
!= NULL
) /* always set. no matter what old state looked like. snapshot might be invalid */
407 switch(attributes
[id
].etype
)
410 nnset(attributes
[id
].object
, attributes
[id
].attribute
, attributes
[id
].value
);
413 nnset(attributes
[id
].object
, attributes
[id
].attribute
, attributes
[id
].svalue
);
418 switch(attributes
[id
].etype
)
421 if (attributes
[id
].value
!= attributes_old
[id
].value
)
422 modified
|= attributes
[id
].group
;
425 if (strcmp(attributes
[id
].svalue
, attributes_old
[id
].svalue
))
426 modified
|= attributes
[id
].group
;
431 data
->groupsmodified
= 0;
436 DEFMMETHOD(VPDFSettings_Use
)
438 unsigned int modified
= DoMethod(obj
, MUIM_VPDFSettings_FromObjects
);
440 memcpy(attributes_old
, attributes
, sizeof(attributes
));
444 DEFMMETHOD(VPDFSettings_Save
)
446 unsigned int modified
= DoMethod(obj
, MUIM_VPDFSettings_FromObjects
);
449 memcpy(attributes_old
, attributes
, sizeof(attributes
));
453 DEFMMETHOD(VPDFSettings_Cancel
)
455 unsigned int modified
;
456 memcpy(attributes
, attributes_old
, sizeof(attributes
));
457 return DoMethod(obj
, MUIM_VPDFSettings_ToObjects
);
464 DECMMETHOD(VPDFSettings_FromObjects
)
465 DECMMETHOD(VPDFSettings_ToObjects
)
466 DECMMETHOD(VPDFSettings_Use
)
467 DECMMETHOD(VPDFSettings_Save
)
468 DECMMETHOD(VPDFSettings_Cancel
)
471 DECSUBCLASS_NC(MUIC_Group
, VPDFSettingsClass
)