3 * Copyright (C) 1998,1999 A.J. van Os
6 * Read and write the options
21 #define PARAGRAPH_BREAK "set paragraph_break=%d"
22 #define AUTOFILETYPE "set autofiletype_allowed=%d"
23 #define USE_OUTLINEFONTS "set use_outlinefonts=%d"
24 #define HIDE_HIDDEN_TEXT "set hide_hidden_text=%d"
26 /* Current values for options */
27 static options_type tOptionsCurr
;
29 /* Temporary values for options */
30 static options_type tOptionsTemp
;
32 static struct papersize_tag
{
34 int iWidth
; /* In points */
35 int iHeight
; /* In points */
37 { "10x14", 720, 1008 },
43 { "executive", 540, 720 },
44 { "folio", 612, 936 },
45 { "legal", 612, 1008 },
46 { "letter", 612, 792 },
48 { "quarto", 610, 780 },
49 { "statement", 396, 612 },
50 { "tabloid", 792, 1224 },
54 /* Default values for options */
55 static const options_type tOptionsDefault
= {
70 * iReadOptions - read options
74 * >0: index first file argument
77 iReadOptions(int argc
, char **argv
)
79 #if !defined(__riscos)
81 extern int optind
, optopt
;
82 struct papersize_tag
*pPaperSize
;
90 DBG_MSG("iReadOptions");
93 tOptionsCurr
= tOptionsDefault
;
96 #if !defined(__riscos)
97 szTmp
= getenv("COLUMNS");
100 iTmp
= (int)strtol(szTmp
, &pcChar
, 10);
101 if (pcChar
== '\0') {
102 iTmp
-= 4; /* This is the edge */
103 if (iTmp
< MIN_SCREEN_WIDTH
) {
104 iTmp
= MIN_SCREEN_WIDTH
;
105 } else if (iTmp
> MAX_SCREEN_WIDTH
) {
106 iTmp
= MAX_SCREEN_WIDTH
;
108 tOptionsCurr
.iParagraphBreak
= iTmp
;
109 DBG_DEC(tOptionsCurr
.iParagraphBreak
);
112 #endif /* __riscos */
115 pFile
= fopen(OPTIONS_FILE_R
, "r");
116 DBG_MSG_C(pFile
== NULL
, "Choices file not found");
117 DBG_HEX_C(pFile
!= NULL
, pFile
);
119 while (fgets(szLine
, sizeof(szLine
), pFile
) != NULL
) {
121 if (szLine
[0] == OPTIONS_COMMENT_CHAR
) {
124 if (sscanf(szLine
, PARAGRAPH_BREAK
, &iTmp
) == 1 &&
126 (iTmp
>= MIN_SCREEN_WIDTH
&&
127 iTmp
<= MAX_SCREEN_WIDTH
))) {
128 tOptionsCurr
.iParagraphBreak
= iTmp
;
129 DBG_DEC(tOptionsCurr
.iParagraphBreak
);
130 } else if (sscanf(szLine
, AUTOFILETYPE
, &iTmp
)
132 tOptionsCurr
.bAutofiletypeAllowed
=
134 DBG_DEC(tOptionsCurr
.bAutofiletypeAllowed
);
135 } else if (sscanf(szLine
, USE_OUTLINEFONTS
, &iTmp
)
137 tOptionsCurr
.bUseOutlineFonts
= iTmp
!= 0;
138 DBG_DEC(tOptionsCurr
.bUseOutlineFonts
);
139 } else if (sscanf(szLine
, HIDE_HIDDEN_TEXT
, &iTmp
)
141 tOptionsCurr
.bHideHiddenText
= iTmp
!= 0;
142 DBG_DEC(tOptionsCurr
.bHideHiddenText
);
149 #if defined(__riscos)
152 while ((iChar
= getopt(argc
, argv
, "cghp:stw:")) != -1) {
155 tOptionsCurr
.bUseColour
= TRUE
;
158 tOptionsCurr
.bUseColour
= FALSE
;
163 tOptionsCurr
.bUseOutlineFonts
= TRUE
;
164 for (pPaperSize
= atPaperSizes
;
165 pPaperSize
->szName
[0] != '\0';
167 if (StrEq(pPaperSize
->szName
, optarg
)) {
168 tOptionsCurr
.iPageHeight
=
169 iMilliPoints2DrawUnits(
170 pPaperSize
->iHeight
* 1000);
171 DBG_DEC(pPaperSize
->iHeight
);
172 DBG_DEC(tOptionsCurr
.iPageHeight
);
173 tOptionsCurr
.iParagraphBreak
=
175 pPaperSize
->iWidth
* 1000 -
176 iDrawUnits2MilliPoints(
179 DBG_DEC(pPaperSize
->iWidth
);
180 DBG_DEC(tOptionsCurr
.iParagraphBreak
);
184 tOptionsCurr
.bHideHiddenText
= FALSE
;
187 tOptionsCurr
.bUseOutlineFonts
= FALSE
;
190 iTmp
= (int)strtol(optarg
, &pcChar
, 10);
191 if (*pcChar
== '\0' &&
193 (iTmp
>= MIN_SCREEN_WIDTH
&&
194 iTmp
<= MAX_SCREEN_WIDTH
))) {
195 tOptionsCurr
.iParagraphBreak
= iTmp
;
196 DBG_DEC(tOptionsCurr
.iParagraphBreak
);
204 #endif /* __riscos */
205 } /* end of iReadOptions */
208 * vGetOptions - get a copy of the current option values
211 vGetOptions(options_type
*ptOptions
)
213 fail(ptOptions
== NULL
);
215 *ptOptions
= tOptionsCurr
;
216 } /* end of vGetOptions */
218 #if defined(__riscos)
220 * vWriteOptions - write the current options to the Options file
228 DBG_MSG("vWriteOptions");
230 szOptionsFile
= getenv(OPTIONS_FILE_W
);
231 if (szOptionsFile
== NULL
) {
232 werr(0, "Warning: Name of the Choices file not found");
235 if (!bMakeDirectory(szOptionsFile
)) {
237 "Warning: I can't make a directory for the Choices file");
240 pFile
= fopen(szOptionsFile
, "w");
242 werr(0, "Warning: I can't write the Choices file");
245 (void)fprintf(pFile
, PARAGRAPH_BREAK
"\n",
246 tOptionsCurr
.iParagraphBreak
);
247 (void)fprintf(pFile
, AUTOFILETYPE
"\n",
248 tOptionsCurr
.bAutofiletypeAllowed
);
249 (void)fprintf(pFile
, USE_OUTLINEFONTS
"\n",
250 tOptionsCurr
.bUseOutlineFonts
);
251 (void)fprintf(pFile
, HIDE_HIDDEN_TEXT
"\n",
252 tOptionsCurr
.bHideHiddenText
);
254 } /* end of vWriteOptions */
257 * vChoicesOpenAction - action to be taken when the Choices window opens
260 vChoicesOpenAction(wimp_w tWindow
)
262 DBG_MSG("vChoicesOpenAction");
264 tOptionsTemp
= tOptionsCurr
;
265 if (tOptionsTemp
.iParagraphBreak
== 0) {
266 vUpdateRadioButton(tWindow
, CHOICES_BREAK_BUTTON
, FALSE
);
267 vUpdateRadioButton(tWindow
, CHOICES_NO_BREAK_BUTTON
, TRUE
);
268 vUpdateWriteableNumber(tWindow
, CHOICES_BREAK_WRITEABLE
,
269 DEFAULT_SCREEN_WIDTH
);
271 vUpdateRadioButton(tWindow
, CHOICES_BREAK_BUTTON
, TRUE
);
272 vUpdateRadioButton(tWindow
, CHOICES_NO_BREAK_BUTTON
, FALSE
);
273 vUpdateWriteableNumber(tWindow
,
274 CHOICES_BREAK_WRITEABLE
,
275 tOptionsTemp
.iParagraphBreak
);
277 vUpdateRadioButton(tWindow
, CHOICES_AUTOFILETYPE_BUTTON
,
278 tOptionsTemp
.bAutofiletypeAllowed
);
279 vUpdateRadioButton(tWindow
, CHOICES_HIDDEN_TEXT_BUTTON
,
280 tOptionsTemp
.bHideHiddenText
);
281 if (tOptionsTemp
.bUseOutlineFonts
) {
282 vUpdateRadioButton(tWindow
,
283 CHOICES_OUTLINEFONT_BUTTON
, TRUE
);
284 vUpdateRadioButton(tWindow
,
285 CHOICES_SYSTEMFONT_BUTTON
, FALSE
);
287 vUpdateRadioButton(tWindow
,
288 CHOICES_OUTLINEFONT_BUTTON
, FALSE
);
289 vUpdateRadioButton(tWindow
,
290 CHOICES_SYSTEMFONT_BUTTON
, TRUE
);
292 } /* end of vChoicesOpenAction */
295 * vDefaultButtonAction - action when the default button is clicked
298 vDefaultButtonAction(wimp_w tWindow
)
300 DBG_MSG("vDefaultButtonAction");
302 tOptionsTemp
= tOptionsDefault
;
303 vUpdateRadioButton(tWindow
, CHOICES_BREAK_BUTTON
, TRUE
);
304 vUpdateRadioButton(tWindow
, CHOICES_NO_BREAK_BUTTON
, FALSE
);
305 vUpdateWriteableNumber(tWindow
, CHOICES_BREAK_WRITEABLE
,
306 tOptionsTemp
.iParagraphBreak
);
307 vUpdateRadioButton(tWindow
, CHOICES_AUTOFILETYPE_BUTTON
,
308 tOptionsTemp
.bAutofiletypeAllowed
);
309 vUpdateRadioButton(tWindow
, CHOICES_HIDDEN_TEXT_BUTTON
,
310 tOptionsTemp
.bHideHiddenText
);
311 vUpdateRadioButton(tWindow
, CHOICES_OUTLINEFONT_BUTTON
, TRUE
);
312 vUpdateRadioButton(tWindow
, CHOICES_SYSTEMFONT_BUTTON
, FALSE
);
313 } /* end of vDefaultButtonAction */
316 * vApplyButtonAction - action to be taken when the OK button is clicked
319 vApplyButtonAction(void)
321 DBG_MSG("vApplyButtonAction");
323 tOptionsCurr
= tOptionsTemp
;
324 } /* end of vApplyButtonAction */
327 * vSaveButtonAction - action to be taken when the save button is clicked
330 vSaveButtonAction(void)
332 DBG_MSG("vSaveButtonAction");
334 vApplyButtonAction();
336 } /* end of vSaveButtonAction */
339 * vSetParagraphBreak - set the paragraph break to the given number
342 vSetParagraphBreak(wimp_w tWindow
, int iNumber
)
344 tOptionsTemp
.iParagraphBreak
= iNumber
;
345 if (tOptionsTemp
.iParagraphBreak
== 0) {
348 vUpdateWriteableNumber(tWindow
,
349 CHOICES_BREAK_WRITEABLE
,
350 tOptionsTemp
.iParagraphBreak
);
351 } /* end of vSetParagraphBreak */
354 * vChangeParagraphBreak - change the paragraph break with the given number
357 vChangeParagraphBreak(wimp_w tWindow
, int iNumber
)
361 iTmp
= tOptionsTemp
.iParagraphBreak
+ iNumber
;
362 if (iTmp
< MIN_SCREEN_WIDTH
|| iTmp
> MAX_SCREEN_WIDTH
) {
365 tOptionsTemp
.iParagraphBreak
= iTmp
;
366 vUpdateWriteableNumber(tWindow
,
367 CHOICES_BREAK_WRITEABLE
,
368 tOptionsTemp
.iParagraphBreak
);
369 } /* end of vChangeParagraphBreak */
372 * vChangeAutofiletype - invert the permission to autofiletype
375 vChangeAutofiletype(wimp_w tWindow
)
377 tOptionsTemp
.bAutofiletypeAllowed
=
378 !tOptionsTemp
.bAutofiletypeAllowed
;
379 vUpdateRadioButton(tWindow
,
380 CHOICES_AUTOFILETYPE_BUTTON
,
381 tOptionsTemp
.bAutofiletypeAllowed
);
382 } /* end of vChangeAutofiletype */
385 * vChangeHiddenText - invert the hide/show hidden text
388 vChangeHiddenText(wimp_w tWindow
)
390 tOptionsTemp
.bHideHiddenText
= !tOptionsTemp
.bHideHiddenText
;
391 vUpdateRadioButton(tWindow
,
392 CHOICES_HIDDEN_TEXT_BUTTON
,
393 tOptionsTemp
.bHideHiddenText
);
394 } /* end of vChangeHiddenText */
397 * vUseOutlineFonts - use outline fonts
400 vUseOutlineFonts(BOOL bUseOutlineFonts
)
402 tOptionsTemp
.bUseOutlineFonts
= bUseOutlineFonts
;
403 } /* end of vUseOutlineFonts */
406 * bChoicesMouseClick - handle a mouse click in the Choices window
409 vChoicesMouseClick(wimp_mousestr
*m
)
412 BOOL bCloseWindow
, bLeft
, bRight
;
414 bLeft
= (m
->bbits
& wimp_BLEFT
) == wimp_BLEFT
;
415 bRight
= (m
->bbits
& wimp_BRIGHT
) == wimp_BRIGHT
;
416 if (!bLeft
&& !bRight
) {
421 /* Which action should be taken */
422 if (bRight
&& m
->i
== CHOICES_BREAK_UP_BUTTON
) {
423 tAction
= CHOICES_BREAK_DOWN_BUTTON
;
424 } else if (bRight
&& m
->i
== CHOICES_BREAK_DOWN_BUTTON
) {
425 tAction
= CHOICES_BREAK_UP_BUTTON
;
431 bCloseWindow
= FALSE
;
433 case CHOICES_DEFAULT_BUTTON
:
434 vDefaultButtonAction(m
->w
);
436 case CHOICES_SAVE_BUTTON
:
439 case CHOICES_CANCEL_BUTTON
:
442 case CHOICES_APPLY_BUTTON
:
443 vApplyButtonAction();
446 case CHOICES_BREAK_BUTTON
:
447 vSetParagraphBreak(m
->w
, DEFAULT_SCREEN_WIDTH
);
449 case CHOICES_BREAK_UP_BUTTON
:
450 vChangeParagraphBreak(m
->w
, 1);
452 case CHOICES_BREAK_DOWN_BUTTON
:
453 vChangeParagraphBreak(m
->w
, -1);
455 case CHOICES_NO_BREAK_BUTTON
:
456 vSetParagraphBreak(m
->w
, 0);
458 case CHOICES_AUTOFILETYPE_BUTTON
:
459 vChangeAutofiletype(m
->w
);
461 case CHOICES_HIDDEN_TEXT_BUTTON
:
462 vChangeHiddenText(m
->w
);
464 case CHOICES_OUTLINEFONT_BUTTON
:
465 vUseOutlineFonts(TRUE
);
467 case CHOICES_SYSTEMFONT_BUTTON
:
468 vUseOutlineFonts(FALSE
);
475 wimpt_noerr(wimp_close_wind(m
->w
));
477 } /* end of vChoicesMouseClick */
480 vChoicesKeyPressed(wimp_caretstr
*c
)
486 DBG_MSG("vChoicesKeyPressed");
490 wimpt_noerr(wimp_get_icon_info(c
->w
, c
->i
, &tIcon
));
491 if ((tIcon
.flags
& (wimp_ITEXT
|wimp_INDIRECT
)) !=
492 (wimp_ITEXT
|wimp_INDIRECT
)) {
493 werr(1, "Icon %d must be indirected text", (int)c
->i
);
496 iNumber
= (int)strtol(tIcon
.data
.indirecttext
.buffer
, &pcChar
, 10);
497 if (*pcChar
!= '\0') {
499 iNumber
= DEFAULT_SCREEN_WIDTH
;
500 } else if (iNumber
< MIN_SCREEN_WIDTH
) {
501 iNumber
= MIN_SCREEN_WIDTH
;
502 } else if (iNumber
> MAX_SCREEN_WIDTH
) {
503 iNumber
= MAX_SCREEN_WIDTH
;
505 vSetParagraphBreak(c
->w
, iNumber
);
506 } /* end of vChoicesKeyPressed */
507 #endif /* __riscos */