4 #include <proto/muimaster.h>
5 #include <libraries/mui.h>
7 #include <proto/exec.h>
8 #include <proto/utility.h>
9 #include <exec/libraries.h>
10 #include <graphics/gfx.h>
11 #include <proto/alib.h>
12 #include <proto/graphics.h>
19 #include <constructor.h>
20 #include <intuition/pointerclass.h>
22 #define SYSTEM_PRIVATE
23 #include <proto/cybergraphics.h>
24 #include <cybergraphx/cybergraphics.h>
28 #include <clib/arossupport_protos.h>
31 #include <private/vapor/vapor.h>
32 #include <mui/Rawimage_mcc.h>
34 #include "pageview_class.h"
35 #include "toolbar_class.h"
36 #include "documentlayout_class.h"
37 #include "documentview_class.h"
38 #include "toolbar_images.h"
42 #include "../locale.h"
51 Object
*btnRotateRight
;
52 Object
*btnRotateLeft
;
53 Object
*btnLayouts
[4];
55 Object
*btnDragScroll
;
62 static float presets
[] = {
63 8.33f
, 12.5f
, 25.0f
, 33.33f
, 50.0f
, 66.67f
, 75.0f
, 100.0f
, 125.0f
, 150.0f
, 200.0f
, 300.0f
, 400.0f
, 600.0f
, 800.0f
, 1000.0f
};
68 MEN_ZOOM_FITWIDTH
, MEN_ZOOM_FITPAGE
,
78 static struct layoutmode layoutmodes
[4];
82 * MUI Standard methods
91 /* dispose parent class */
100 static Object
*layoutbutton(char *label
, UBYTE
*image
)
102 return RawimageObject
,
103 MUIA_Rawimage_Data
, image
,
104 MUIA_ShortHelp
, label
,
105 MUIA_Frame
, MUIV_Frame_Button
,
106 MUIA_Background
, MUII_ButtonBack
,
107 MUIA_InputMode
, MUIV_InputMode_Immediate
,
113 Object
*btnZoomIn
, *btnZoomOut
, *btnLayouts
[4], *strZoom
, *btnRotateLeft
, *btnRotateRight
, *btnOutline
;
114 Object
*btnZoomPopup
, *btnDragMark
, *btnDragScroll
;
116 layoutmodes
[0].mode
= MUIV_DocumentView_Layout_Single
;
117 layoutmodes
[1].mode
= MUIV_DocumentView_Layout_ContinuousSingle
;
118 layoutmodes
[2].mode
= MUIV_DocumentView_Layout_Facing
;
119 layoutmodes
[3].mode
= MUIV_DocumentView_Layout_ContinuousFacing
;
120 strncpy(layoutmodes
[0].name
, LOCSTR( MSG_TOOLBAR_SINGLE
),128);
121 strncpy(layoutmodes
[1].name
, LOCSTR( MSG_TOOLBAR_CONTINUOUS
),128);
122 strncpy(layoutmodes
[2].name
, LOCSTR( MSG_TOOLBAR_FACING
),128);
123 strncpy(layoutmodes
[3].name
, LOCSTR( MSG_TOOLBAR_CONT_FACING
),128);
125 obj
= DoSuperNew(cl
, obj
,
126 MUIA_Group_Horiz
, TRUE
,
127 Child
, strZoom
= TextObject
,
128 MUIA_Text_PreParse
, "\033c",
130 //MUIA_Frame, MUIV_Frame_Text,
132 Child
, btnZoomPopup
= ImageObject
,
134 MUIA_Image_Spec
, MUII_PopUp
,
135 MUIA_Image_FontMatchString
, "M",
136 MUIA_Image_FontMatchWidth
, TRUE
,
137 MUIA_Image_FreeVert
, TRUE
,
138 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
139 MUIA_Background
, MUII_ButtonBack
,
144 Child
, btnZoomIn
= RawimageObject
,
145 MUIA_Rawimage_Data
, button_zoomin
,
146 MUIA_ShortHelp
, LOCSTR( MSG_TOOLBAR_ZOOMIN
),
147 MUIA_Frame
, MUIV_Frame_Button
,
148 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
149 MUIA_Background
, MUII_ButtonBack
,
151 Child
, btnZoomOut
= RawimageObject
,
152 MUIA_Rawimage_Data
, button_zoomout
,
153 MUIA_ShortHelp
, LOCSTR( MSG_TOOLBAR_ZOOMOUT
),
154 MUIA_Frame
, MUIV_Frame_Button
,
155 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
156 MUIA_Background
, MUII_ButtonBack
,
162 Child
, btnRotateLeft
= RawimageObject
,
163 MUIA_Rawimage_Data
, button_rotatecounterclockwise
,
164 MUIA_ShortHelp
, LOCSTR( MSG_TOOLBAR_CLOCKWISE
),
165 MUIA_Frame
, MUIV_Frame_Button
,
166 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
167 MUIA_Background
, MUII_ButtonBack
,
169 Child
, btnRotateRight
= RawimageObject
,
170 MUIA_Rawimage_Data
, button_rotateclockwise
,
171 MUIA_ShortHelp
, LOCSTR( MSG_TOOLBAR_COUNTERCLOCKWISE
),
172 MUIA_Frame
, MUIV_Frame_Button
,
173 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
174 MUIA_Background
, MUII_ButtonBack
,
178 Child
, btnLayouts
[0] = layoutbutton(layoutmodes
[0].name
, button_singlepage
),
179 Child
, btnLayouts
[1] = layoutbutton(layoutmodes
[1].name
, button_singlepagecont
),
180 Child
, btnLayouts
[2] = layoutbutton(layoutmodes
[2].name
, button_doublepage
),
181 Child
, btnLayouts
[3] = layoutbutton(layoutmodes
[3].name
, button_doublepagecont
),
187 Child
, btnDragMark
= TextObject
,
188 MUIA_Frame
, MUIV_Frame_Button
,
189 MUIA_Text_Contents
, LOCSTR( MSG_TOOLBAR_MARK
),
190 MUIA_InputMode
, MUIV_InputMode_Toggle
,
191 MUIA_Background
, MUII_ButtonBack
,
193 Child
, btnDragScroll
= TextObject
,
194 MUIA_Frame
, MUIV_Frame_Button
,
195 MUIA_Text_Contents
, LOCSTR( MSG_TOOLBAR_SCROLL
),
196 MUIA_InputMode
, MUIV_InputMode_Toggle
,
197 MUIA_Background
, MUII_ButtonBack
,
198 MUIA_Selected
, TRUE
,
204 Child
, btnOutline
= TextObject
,
205 MUIA_Frame
, MUIV_Frame_Button
,
206 MUIA_Text_Contents
, LOCSTR( MSG_TOOLBAR_OUTLINE
),
207 MUIA_InputMode
, MUIV_InputMode_Toggle
,
208 MUIA_Background
, MUII_ButtonBack
,
217 memset(data
, 0, sizeof(struct Data
));
218 data
->strZoom
= strZoom
;
219 data
->btnZoomPopup
= btnZoomPopup
;
220 data
->btnDragMark
= btnDragMark
;
221 data
->btnDragScroll
= btnDragScroll
;
222 memcpy(data
->btnLayouts
, btnLayouts
, sizeof(btnLayouts
));
226 case MUIA_Toolbar_DocumentView
:
227 data
->document
= (Object
*)tag
->ti_Data
;
230 case MUIA_DocumentView_Outline
:
231 nnset(btnOutline
, MUIA_Selected
, tag
->ti_Data
);
236 DoMethod(btnZoomIn
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 2, MUIM_Toolbar_Zoom
, 10);
237 DoMethod(btnZoomOut
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 2, MUIM_Toolbar_Zoom
, -10);
238 DoMethod(btnZoomPopup
, MUIM_Notify
, MUIA_Selected
, FALSE
, obj
, 1, MUIM_Toolbar_ZoomPopup
);
240 DoMethod(btnRotateLeft
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 1, MUIM_DocumentView_RotateLeft
);
241 DoMethod(btnRotateRight
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 1, MUIM_DocumentView_RotateRight
);
243 DoMethod(btnOutline
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, obj
, 2, MUIM_Toolbar_ToggleOutline
, MUIV_TriggerValue
);
245 DoMethod(btnDragMark
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, obj
, 2, MUIM_Toolbar_DragAction
, MUIV_DocumentView_DragAction_Mark
);
246 DoMethod(btnDragScroll
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
, obj
, 2, MUIM_Toolbar_DragAction
, MUIV_DocumentView_DragAction_Scroll
);
249 DoMethod(btnLayouts
[i
], MUIM_Notify
, MUIA_Selected
, TRUE
, obj
, 2, MUIM_Toolbar_Layout
, i
);
278 /// zoom - format string
280 static char *zoomFormat(int zoomid
, char *buffer
, int buffersize
)
282 if (zoomid
== MEN_ZOOM_FITPAGE
)
283 snprintf(buffer
, buffersize
, LOCSTR( MSG_TOOLBAR_FITPAGE
));
284 else if (zoomid
== MEN_ZOOM_FITWIDTH
)
285 snprintf(buffer
, buffersize
, LOCSTR( MSG_TOOLBAR_FITWIDTH
));
288 float zoom
= presets
[zoomid
- MEN_ZOOM_PRESET0
] / 100.0f
;
289 snprintf(buffer
, buffersize
, "%.2f%%", zoom
* 100.0f
);
306 case MUIA_Toolbar_DocumentView
:
307 data
->document
= (Object
*)tag
->ti_Data
;
309 /* update state depending on assigned document view. for now only layout mode + outlines */
312 nnset(data
->btnLayouts
[i
], MUIA_Selected
, layoutmodes
[i
].mode
== xget(data
->document
, MUIA_DocumentView_Layout
));
314 /* setup zoom mode and factor (externalize if needed in other situations) */
318 int scaling
= xget(data
->document
, MUIA_DocumentLayout_Scaling
);
319 float zoom
= xget(data
->document
, MUIA_DocumentLayout_Zoom
) / 65536.0f
;
322 for(presnum
= 0; presets
[presnum
] < zoom
* 100.0f
&& presnum
< (sizeof(presets
) / sizeof(presets
[0])); presnum
++) {};
324 if (presnum
>= (sizeof(presets
) / sizeof(presets
[0])))
327 if (scaling
== MUIV_DocumentLayout_Scaling_FitPage
)
328 data
->zoomid
= MEN_ZOOM_FITPAGE
;
329 else if (scaling
== MUIV_DocumentLayout_Scaling_FitWidth
)
330 data
->zoomid
= MEN_ZOOM_FITWIDTH
;
332 data
->zoomid
= MEN_ZOOM_PRESET0
+ presnum
;
334 zoom
= presets
[presnum
] / 100.0f
;
336 zoomFormat(data
->zoomid
, buff
, sizeof(buff
));
337 set(data
->strZoom
, MUIA_Text_Contents
, buff
);
356 switch (msg
->opg_AttrID
)
358 case MUIA_PageView_NeedRefresh
:
370 DEFMMETHOD(Toolbar_Layout
)
377 if (i
!= msg
->layout
)
378 nnset(data
->btnLayouts
[i
], MUIA_Selected
, FALSE
);
381 return DoMethod(data
->document
, MUIM_DocumentView_Layout
, layoutmodes
[msg
->layout
].mode
);
388 DEFMMETHOD(Toolbar_Zoom
)
393 float zoom
= xget(data
->document
, MUIA_DocumentLayout_Zoom
) / 65536.0f
;
396 for(presnum
= 0; presets
[presnum
] < zoom
* 100.0f
&& presnum
< (sizeof(presets
) / sizeof(presets
[0])); presnum
++) {};
398 if (data
->zoomid
>= MEN_ZOOM_PRESET0
)
402 else if (msg
->change
< 0 && presnum
> 0)
405 else // move to nearest preset
410 else if (msg
->change
< 0 && presnum
> 0)
414 if (presnum
>= (sizeof(presets
) / sizeof(presets
[0])))
417 data
->zoomid
= MEN_ZOOM_PRESET0
+ presnum
;
418 zoom
= presets
[presnum
] / 100.0f
;
420 zoomFormat(data
->zoomid
, buff
, sizeof(buff
));
421 SetAttrs(data
->document
,
422 MUIA_DocumentLayout_Scaling
, MUIV_DocumentLayout_Scaling_Zoom
,
423 MUIA_DocumentLayout_Zoom
, (int)(zoom
* 65536),
425 //nnset(data->strZoom, MUIA_String_Contents, buff);
426 set(data
->strZoom
, MUIA_Text_Contents
, buff
);
435 DEFMMETHOD(Toolbar_ZoomPopup
)
440 float zoom
= xget(data
->document
, MUIA_DocumentLayout_Zoom
) / 65536.0f
;
447 char *extra
[] = {"Fit page", "Fit width"};
448 int extraid
[] = {MEN_ZOOM_FITPAGE
, MEN_ZOOM_FITWIDTH
};
450 menZoom
= MenuObject
,
451 MUIA_Menu_Title
, "Zoom",
454 for(i
=0; i
<sizeof(presets
) / sizeof(presets
[0]); i
++)
458 snprintf(pval
, sizeof(pval
), "%.2f%%", presets
[i
]);
460 menPreset
= MenuitemObject
,
461 MUIA_Menuitem_Title
, pval
,
462 MUIA_Menuitem_CopyStrings
, TRUE
,
463 MUIA_UserData
, MEN_ZOOM_PRESET0
+ i
,
466 DoMethod(menZoom
, MUIM_Family_AddTail
, menPreset
);
469 for(i
=0; i
<sizeof(extra
) / sizeof(extra
[0]); i
++)
473 menPreset
= MenuitemObject
,
474 MUIA_Menuitem_Title
, extra
[i
],
475 MUIA_UserData
, extraid
[i
],
478 DoMethod(menZoom
, MUIM_Family_AddTail
, menPreset
);
482 menZoom
= MenustripObject
, Child
, menZoom
, End
;
484 #if defined(__AROS__)
485 kprintf("[Toolbar_ZoomPopup] not implemented\n");
486 // FIXME: AROS doesn't have MUIM_Menustrip_Popup
488 id
= DoMethod(menZoom
, MUIM_Menustrip_Popup
, data
->btnZoomPopup
, 0 , _left(data
->btnZoomPopup
),_bottom(data
->btnZoomPopup
)+1);
496 zoomFormat(data
->zoomid
, buff
, sizeof(buff
));
497 set(data
->strZoom
, MUIA_Text_Contents
, buff
);
499 if (id
== MEN_ZOOM_FITWIDTH
)
500 set(data
->document
, MUIA_DocumentLayout_Scaling
, MUIV_DocumentLayout_Scaling_FitWidth
);
501 else if (id
== MEN_ZOOM_FITPAGE
)
502 set(data
->document
, MUIA_DocumentLayout_Scaling
, MUIV_DocumentLayout_Scaling_FitPage
);
505 float zoom
= presets
[id
- MEN_ZOOM_PRESET0
] / 100.0f
;
507 SetAttrs(data
->document
,
508 MUIA_DocumentLayout_Scaling
, MUIV_DocumentLayout_Scaling_Zoom
,
509 MUIA_DocumentLayout_Zoom
, (int)(zoom
* 65536),
516 MUI_DisposeObject(menZoom
);
523 DEFMMETHOD(DocumentView_RotateLeft
)
526 return DoMethodA(data
->document
, msg
);
529 DEFMMETHOD(DocumentView_RotateRight
)
532 return DoMethodA(data
->document
, msg
);
535 DEFMMETHOD(Toolbar_ToggleOutline
)
538 set(data
->document
, MUIA_DocumentView_Outline
, msg
->visible
);
542 DEFMMETHOD(Toolbar_DragAction
)
546 if (msg
->dragaction
== MUIV_DocumentView_DragAction_Mark
)
547 nnset(data
->btnDragScroll
, MUIA_Selected
, FALSE
);
549 nnset(data
->btnDragMark
, MUIA_Selected
, FALSE
);
551 set(data
->document
, MUIA_DocumentView_DragAction
, msg
->dragaction
);
562 DECMMETHOD(Toolbar_Zoom
)
563 DECMMETHOD(Toolbar_Layout
)
564 DECMMETHOD(Toolbar_ZoomPopup
)
565 DECMMETHOD(DocumentView_RotateLeft
)
566 DECMMETHOD(DocumentView_RotateRight
)
567 DECMMETHOD(Toolbar_ToggleOutline
)
568 DECMMETHOD(Toolbar_DragAction
)
571 DECSUBCLASS_NC(MUIC_Group
, ToolbarClass
)