2 #include <proto/muimaster.h>
3 #include <libraries/mui.h>
4 #include <workbench/workbench.h>
5 #include <proto/exec.h>
6 #include <intuition/intuition.h>
7 #include <exec/libraries.h>
8 #include <proto/intuition.h>
13 #include <clib/arossupport_protos.h>
16 #include <proto/alib.h>
17 #include <proto/utility.h>
20 #include <private/vapor/vapor.h>
22 #include "application.h"
23 #include "pagenumberclass.h"
24 #include "system/functions.h"
51 PageNumberItem pages_bitmap
[1024];
59 char initial_range
[128];
61 if ((obj
= DoSuperNew(cl
, obj
,
63 Child
, str_pages
= StringObject
,
64 MUIA_String_Accept
, "0123456789-, ",
65 MUIA_Frame
, MUIV_Frame_String
,
71 data
->min
= GetTagData(MUIA_VPDFNumberGeneratorPageStart
, 1, INITTAGS
);
72 data
->max
= GetTagData(MUIA_VPDFNumberGeneratorPageEnd
, 999999999, INITTAGS
);
73 data
->reverse
= FALSE
;
74 data
->str_pages
= str_pages
;
76 sprintf(initial_range
, "1 - %d", data
->end
);
77 set(data
->str_pages
, MUIA_String_Contents
, initial_range
);
79 memset(data
->pages_bitmap
, 0, sizeof(data
->pages_bitmap
));
81 data
->sub_pos
= -1; // position within range
95 DEFMMETHOD(VPDFNumberGeneratorFirst
)
100 char *break_pos
, *pch
;
104 data
->sub_pos
= -1; // position within range
106 get(data
->str_pages
, MUIA_String_Contents
, &str
);
109 pch
= strtok (buffer
, ",");
111 while ((pch
!= NULL
))
113 // checking if we have range here
114 if ((break_pos
= (strchr(pch
, '-'))))
117 data
->pages_bitmap
[current_pos
].type
= TYPE_RANGE
;
118 data
->pages_bitmap
[current_pos
].max
= atoi(break_pos
+1);
119 data
->pages_bitmap
[current_pos
].min
= atoi(pch
);
121 if (data
->pages_bitmap
[current_pos
].max
<data
->pages_bitmap
[current_pos
].min
)
124 tmp
= data
->pages_bitmap
[current_pos
].min
;
125 data
->pages_bitmap
[current_pos
].min
= data
->pages_bitmap
[current_pos
].max
;
126 data
->pages_bitmap
[current_pos
].max
= tmp
;
130 if (data
->pages_bitmap
[current_pos
].min
==data
->pages_bitmap
[current_pos
].max
)
132 data
->pages_bitmap
[current_pos
].type
= TYPE_NUMBER
;
133 data
->pages_bitmap
[current_pos
].page_number
= data
->pages_bitmap
[current_pos
].max
;
135 if (data
->pages_bitmap
[current_pos
].page_number
>data
->max
)
137 data
->pages_bitmap
[current_pos
].page_number
= data
->max
;
143 if (data
->pages_bitmap
[current_pos
].max
>data
->max
)
145 data
->pages_bitmap
[current_pos
].max
= data
->max
;
147 total_pages
+= data
->pages_bitmap
[current_pos
].max
-data
->pages_bitmap
[current_pos
].min
+1;
150 D(kprintf("range [%d, %d]\n", data
->pages_bitmap
[current_pos
].min
, data
->pages_bitmap
[current_pos
].max
));
154 data
->pages_bitmap
[current_pos
].page_number
= atoi(pch
);
155 data
->pages_bitmap
[current_pos
].type
= TYPE_NUMBER
;
157 if (data
->pages_bitmap
[current_pos
].page_number
>data
->max
)
159 data
->pages_bitmap
[current_pos
].page_number
= data
->max
;
162 D(kprintf("number [%d]\n", data
->pages_bitmap
[current_pos
].page_number
));
166 pch
= strtok (NULL
, ",");
169 data
->pages_bitmap
[current_pos
].type
= TYPE_END
;
171 // if we have reverse mode turned on: start from end
172 if (msg
->reverse
== TRUE
)
174 data
->pos
= current_pos
-1;
175 data
->reverse
= TRUE
;
179 data
->reverse
= FALSE
;
187 DEFMMETHOD(VPDFNumberGeneratorNext
)
193 switch(data
->pages_bitmap
[data
->pos
].type
)
197 return data
->pages_bitmap
[data
->pos
- 1].page_number
;
200 if(data
->sub_pos
== -1) // start of range
202 data
->sub_pos
= data
->pages_bitmap
[data
->pos
].min
;
203 return data
->sub_pos
;
209 if(data
->sub_pos
== data
->pages_bitmap
[data
->pos
].max
)
213 return data
->pages_bitmap
[data
->pos
- 1].max
;
215 return data
->sub_pos
;
219 return MUIV_VPDFNumberGeneratorEndPos
; // end of page list
227 switch(data
->pages_bitmap
[data
->pos
].type
)
231 return data
->pages_bitmap
[data
->pos
+ 1].page_number
;
234 if(data
->sub_pos
== -1) // start of range
236 data
->sub_pos
= data
->pages_bitmap
[data
->pos
].max
;
237 return data
->sub_pos
;
243 if(data
->sub_pos
== data
->pages_bitmap
[data
->pos
].min
)
247 return data
->pages_bitmap
[data
->pos
+ 1].min
;
249 return data
->sub_pos
;
255 return MUIV_VPDFNumberGeneratorEndPos
;
257 return MUIV_VPDFNumberGeneratorEndPos
;
263 char initial_range
[128];
268 /*case MUIA_VPDFNumberGeneratorPageSkip:
270 data->skip_mode = tag->ti_Data;
275 case MUIA_VPDFNumberGeneratorPageStart
:
276 data
->min
= tag
->ti_Data
;
277 sprintf(initial_range
, "%d - %d", data
->min
, data
->end
);
278 set(data
->str_pages
, MUIA_String_Contents
, initial_range
);
281 case MUIA_VPDFNumberGeneratorPageEnd
:
282 data
->end
= tag
->ti_Data
;
283 sprintf(initial_range
, "%d - %d", data
->min
, data
->end
);
284 set(data
->str_pages
, MUIA_String_Contents
, initial_range
);
287 case MUIA_VPDFNumberGeneratorPageMax
:
288 data
->max
= tag
->ti_Data
;
303 DECMMETHOD(VPDFNumberGeneratorFirst
)
304 DECMMETHOD(VPDFNumberGeneratorNext
)
307 DECSUBCLASS_NC(MUIC_Group
, VPDFNumberGeneratorClass
)