diff -r 59758314f811 -r d4524d6a4472 Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/options_8c_source.html --- a/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/options_8c_source.html Fri Jun 11 15:24:34 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,978 +0,0 @@ - - -
- -00001 /* -00002 * options.c -00003 * Copyright (C) 1998-2004 A.J. van Os; Released under GNU GPL -00004 * -00005 * Description: -00006 * Read and write the options -00007 */ -00008 -00009 #include <stdio.h> -00010 #include <stdlib.h> -00011 #include <string.h> -00012 #if defined(__riscos) -00013 #include "DeskLib:Error.h" -00014 #include "DeskLib:Wimp.h" -00015 #else -00016 #include <stdlib.h> -00017 #if defined(__dos) || defined(N_PLAT_NLM) -00018 extern int getopt(int, char **, const char *); -00019 #else -00020 #include <unistd.h> -00021 #endif /* __dos */ -00022 #endif /* __riscos */ -00023 #include "antiword.h" -00024 -00025 #if defined(__riscos) -00026 #define PARAGRAPH_BREAK "set paragraph_break=%d" -00027 #define AUTOFILETYPE "set autofiletype_allowed=%d" -00028 #define USE_OUTLINEFONTS "set use_outlinefonts=%d" -00029 #define SHOW_IMAGES "set show_images=%d" -00030 #define HIDE_HIDDEN_TEXT "set hide_hidden_text=%d" -00031 #define SCALE_FACTOR_START "set scale_factor_start=%d" -00032 #else -00033 #define LEAFNAME_SIZE (32+1) -00034 #endif /* __riscos */ -00035 -00036 /* Current values for options */ -00037 static options_type tOptionsCurr; -00038 #if defined(__riscos) -00039 /* Temporary values for options */ -00040 static options_type tOptionsTemp; -00041 #else -00042 typedef struct papersize_tag { -00043 char szName[16]; /* Papersize name */ -00044 USHORT usWidth; /* In points */ -00045 USHORT usHeight; /* In points */ -00046 } papersize_type; -00047 -00048 static const papersize_type atPaperSizes[] = { -00049 { "10x14", 720, 1008 }, -00050 { "a3", 842, 1191 }, -00051 { "a4", 595, 842 }, -00052 { "a5", 420, 595 }, -00053 { "b4", 729, 1032 }, -00054 { "b5", 516, 729 }, -00055 { "executive", 540, 720 }, -00056 { "folio", 612, 936 }, -00057 { "legal", 612, 1008 }, -00058 { "letter", 612, 792 }, -00059 { "note", 540, 720 }, -00060 { "quarto", 610, 780 }, -00061 { "statement", 396, 612 }, -00062 { "tabloid", 792, 1224 }, -00063 { "", 0, 0 }, -00064 }; -00065 #endif /* __riscos */ -00066 /* Default values for options */ -00067 static const options_type tOptionsDefault = { -00068 DEFAULT_SCREEN_WIDTH, -00069 #if defined(__riscos) -00070 conversion_draw, -00071 #else -00072 conversion_text, -00073 #endif /* __riscos */ -00074 TRUE, -00075 TRUE, -00076 FALSE, -00077 encoding_latin_1, -00078 INT_MAX, -00079 INT_MAX, -00080 level_default, -00081 #if defined(__riscos) -00082 TRUE, -00083 DEFAULT_SCALE_FACTOR, -00084 #endif /* __riscos */ -00085 }; -00086 -00087 -00088 #if !defined(__riscos) -00089 /* -00090 * bCorrectPapersize - see if the papersize is correct -00091 * -00092 * TRUE if the papersize is correct, otherwise FALSE -00093 */ -00094 static BOOL -00095 bCorrectPapersize(const char *szName, conversion_type eConversionType) -00096 { -00097 const papersize_type *pPaperSize; -00098 -00099 for (pPaperSize = atPaperSizes; -00100 pPaperSize->szName[0] != '\0'; -00101 pPaperSize++) { -00102 if (!STRCEQ(pPaperSize->szName, szName)) { -00103 continue; -00104 } -00105 DBG_DEC(pPaperSize->usWidth); -00106 DBG_DEC(pPaperSize->usHeight); -00107 tOptionsCurr.eConversionType = eConversionType; -00108 tOptionsCurr.iPageHeight = (int)pPaperSize->usHeight; -00109 tOptionsCurr.iPageWidth = (int)pPaperSize->usWidth; -00110 return TRUE; -00111 } -00112 return FALSE; -00113 } /* end of bCorrectPapersize */ -00114 -00115 /* -00116 * szCreateSuffix - create a suffix for the file -00117 * -00118 * Returns the suffix -00119 */ -00120 static const char * -00121 szCreateSuffix(const char *szLeafname) -00122 { -00123 const char *pcDot; -00124 -00125 pcDot = strrchr(szLeafname, '.'); -00126 if (pcDot != NULL && STRCEQ(pcDot, ".txt")) { -00127 /* There is already a .txt suffix, no need for another one */ -00128 return ""; -00129 } -00130 return ".txt"; -00131 } /* end of szCreateSuffix */ -00132 -00133 /* -00134 * eMappingFile2Encoding - convert the mapping file to an encoding -00135 */ -00136 static encoding_type -00137 eMappingFile2Encoding(const char *szLeafname) -00138 { -00139 char szMappingFile[LEAFNAME_SIZE+4]; -00140 -00141 fail(szLeafname == NULL); -00142 -00143 if (strlen(szLeafname) + 4 >= sizeof(szMappingFile)) { -00144 DBG_MSG(szLeafname); -00145 return encoding_latin_1; -00146 } -00147 -00148 sprintf(szMappingFile, "%s%s", szLeafname, szCreateSuffix(szLeafname)); -00149 -00150 DBG_MSG(szMappingFile); -00151 -00152 if (STRCEQ(szMappingFile, MAPPING_FILE_UTF_8)) { -00153 return encoding_utf_8; -00154 } -00155 if (STRCEQ(szMappingFile, MAPPING_FILE_CP852) || -00156 STRCEQ(szMappingFile, MAPPING_FILE_CP1250) || -00157 STRCEQ(szMappingFile, MAPPING_FILE_8859_2)) { -00158 return encoding_latin_2; -00159 } -00160 if (STRCEQ(szMappingFile, MAPPING_FILE_KOI8_R) || -00161 STRCEQ(szMappingFile, MAPPING_FILE_KOI8_U) || -00162 STRCEQ(szMappingFile, MAPPING_FILE_CP866) || -00163 STRCEQ(szMappingFile, MAPPING_FILE_CP1251) || -00164 STRCEQ(szMappingFile, MAPPING_FILE_8859_5)) { -00165 return encoding_cyrillic; -00166 } -00167 return encoding_latin_1; -00168 } /* end of eMappingFile2Encoding */ -00169 #endif /* !__riscos */ -00170 -00171 /* -00172 * pOpenCharacterMappingFile - open the mapping file -00173 * -00174 * Returns the file pointer or NULL -00175 */ -00176 static FILE * -00177 pOpenCharacterMappingFile(const char *szLeafname) -00178 { -00179 #if !defined(__riscos) -00180 FILE *pFile; -00181 const char *szHome, *szAntiword, *szSuffix; -00182 size_t tFilenameLen; -00183 char szMappingFile[PATH_MAX+1]; -00184 #endif /* !__riscos */ -00185 -00186 if (szLeafname == NULL || szLeafname[0] == '\0') { -00187 return NULL; -00188 } -00189 -00190 DBG_MSG(szLeafname); -00191 -00192 #if defined(__riscos) -00193 return fopen(szLeafname, "r"); -00194 #else -00195 /* Set the suffix */ -00196 szSuffix = szCreateSuffix(szLeafname); -00197 -00198 /* Set length */ -00199 tFilenameLen = strlen(szLeafname) + strlen(szSuffix); -00200 -00201 /* Try the environment version of the mapping file */ -00202 szAntiword = szGetAntiwordDirectory(); -00203 if (szAntiword != NULL && szAntiword[0] != '\0') { -00204 if (strlen(szAntiword) + tFilenameLen < -00205 sizeof(szMappingFile) - -00206 sizeof(FILE_SEPARATOR)) { -00207 sprintf(szMappingFile, -00208 "%s" FILE_SEPARATOR "%s%s", -00209 szAntiword, szLeafname, szSuffix); -00210 DBG_MSG(szMappingFile); -00211 pFile = fopen(szMappingFile, "r"); -00212 if (pFile != NULL) { -00213 return pFile; -00214 } -00215 } else { -00216 werr(0, "Environment mappingfilename ignored"); -00217 } -00218 } -00219 -00220 /* Try the local version of the mapping file */ -00221 szHome = szGetHomeDirectory(); -00222 if (strlen(szHome) + tFilenameLen < -00223 sizeof(szMappingFile) - -00224 sizeof(ANTIWORD_DIR) - -00225 2 * sizeof(FILE_SEPARATOR)) { -00226 #ifndef SYMBIAN -00227 sprintf(szMappingFile, -00228 "%s%s%s", -00229 szHome, szLeafname, szSuffix); -00230 #else -00231 sprintf(szMappingFile, -00232 "%s%s%s", -00233 szHome, szLeafname, szSuffix); -00234 #endif /*SYMBIAN*/ -00235 DBG_MSG(szMappingFile); -00236 pFile = fopen(szMappingFile, "r"); -00237 if (pFile != NULL) { -00238 return pFile; -00239 } -00240 } else { -00241 werr(0, "Local mappingfilename too long, ignored"); -00242 } -00243 -00244 /* Try the global version of the mapping file */ -00245 if (tFilenameLen < -00246 sizeof(szMappingFile) - -00247 sizeof(GLOBAL_ANTIWORD_DIR) - -00248 sizeof(FILE_SEPARATOR)) { -00249 sprintf(szMappingFile, -00250 GLOBAL_ANTIWORD_DIR FILE_SEPARATOR "%s%s", -00251 szLeafname, szSuffix); -00252 DBG_MSG(szMappingFile); -00253 pFile = fopen(szMappingFile, "r"); -00254 if (pFile != NULL) { -00255 return pFile; -00256 } -00257 } else { -00258 werr(0, "Global mappingfilename too long, ignored"); -00259 } -00260 werr(0, "I can't open your mapping file (%s%s)\n" -00261 "It is not in '%s" FILE_SEPARATOR ANTIWORD_DIR "' nor in '" -00262 GLOBAL_ANTIWORD_DIR "'.", szLeafname, szSuffix, szHome); -00263 return NULL; -00264 #endif /* __riscos */ -00265 } /* end of pOpenCharacterMappingFile */ -00266 -00267 /* -00268 * vCloseCharacterMappingFile - close the mapping file -00269 */ -00270 static void -00271 vCloseCharacterMappingFile(FILE *pFile) -00272 { -00273 (void)fclose(pFile); -00274 } /* end of pCloseCharacterMappingFile */ -00275 -00276 -00277 /* -00278 * iReadOptions - read options -00279 * -00280 * returns: -1: error -00281 * 0: help -00282 * >0: index first file argument -00283 */ -00284 int -00285 iReadOptions(int argc, char **argv) -00286 { -00287 #if defined(__riscos) -00288 FILE *pFile; -00289 const char *szAlphabet; -00290 int iAlphabet; -00291 char szLine[81]; -00292 #else -00293 extern char *optarg; -00294 extern int optind; -00295 char *pcChar, *szTmp; -00296 int iChar; -00297 char szLeafname[LEAFNAME_SIZE]; -00298 #endif /* __riscos */ -00299 FILE *pCharacterMappingFile; -00300 int iTmp; -00301 BOOL bSuccess; -00302 -00303 DBG_MSG("iReadOptions"); -00304 -00305 /* Defaults */ -00306 tOptionsCurr = tOptionsDefault; -00307 -00308 #if defined(__riscos) -00309 /* Choices file */ -00310 pFile = fopen("<AntiWord$ChoicesFile>", "r"); -00311 DBG_MSG_C(pFile == NULL, "Choices file not found"); -00312 DBG_HEX_C(pFile != NULL, pFile); -00313 if (pFile != NULL) { -00314 while (fgets(szLine, (int)sizeof(szLine), pFile) != NULL) { -00315 DBG_MSG(szLine); -00316 if (szLine[0] == '#' || -00317 szLine[0] == '\r' || -00318 szLine[0] == '\n') { -00319 continue; -00320 } -00321 if (sscanf(szLine, PARAGRAPH_BREAK, &iTmp) == 1 && -00322 (iTmp == 0 || -00323 (iTmp >= MIN_SCREEN_WIDTH && -00324 iTmp <= MAX_SCREEN_WIDTH))) { -00325 tOptionsCurr.iParagraphBreak = iTmp; -00326 DBG_DEC(tOptionsCurr.iParagraphBreak); -00327 } else if (sscanf(szLine, AUTOFILETYPE, &iTmp) -00328 == 1) { -00329 tOptionsCurr.bAutofiletypeAllowed = -00330 iTmp != 0; -00331 DBG_DEC(tOptionsCurr.bAutofiletypeAllowed); -00332 } else if (sscanf(szLine, USE_OUTLINEFONTS, &iTmp) -00333 == 1) { -00334 tOptionsCurr.eConversionType = -00335 iTmp == 0 ? -00336 conversion_text : conversion_draw; -00337 DBG_DEC(tOptionsCurr.eConversionType); -00338 } else if (sscanf(szLine, SHOW_IMAGES, &iTmp) -00339 == 1) { -00340 tOptionsCurr.eImageLevel = iTmp != 0 ? -00341 level_default : level_no_images; -00342 } else if (sscanf(szLine, HIDE_HIDDEN_TEXT, &iTmp) -00343 == 1) { -00344 tOptionsCurr.bHideHiddenText = iTmp != 0; -00345 DBG_DEC(tOptionsCurr.bHideHiddenText); -00346 } else if (sscanf(szLine, SCALE_FACTOR_START, &iTmp) -00347 == 1) { -00348 if (iTmp >= MIN_SCALE_FACTOR && -00349 iTmp <= MAX_SCALE_FACTOR) { -00350 tOptionsCurr.iScaleFactor = iTmp; -00351 DBG_DEC(tOptionsCurr.iScaleFactor); -00352 } -00353 } -00354 } -00355 (void)fclose(pFile); -00356 } -00357 iAlphabet = iReadCurrentAlphabetNumber(); -00358 switch (iAlphabet) { -00359 case 101: /* ISO-8859-1 aka Latin1 */ -00360 szAlphabet = "<AntiWord$Latin1>"; -00361 break; -00362 case 112: /* ISO-8859-15 aka Latin9 */ -00363 szAlphabet = "<AntiWord$Latin9>"; -00364 break; -00365 default: -00366 werr(0, "Alphabet '%d' is not supported", iAlphabet); -00367 return -1; -00368 } -00369 pCharacterMappingFile = pOpenCharacterMappingFile(szAlphabet); -00370 if (pCharacterMappingFile != NULL) { -00371 bSuccess = bReadCharacterMappingTable(pCharacterMappingFile); -00372 vCloseCharacterMappingFile(pCharacterMappingFile); -00373 } else { -00374 bSuccess = FALSE; -00375 } -00376 return bSuccess ? 1 : -1; -00377 #else -00378 /* Environment */ -00379 -00380 #ifdef SYMBIAN -00381 //Adding Some environment Variable explicitly -00382 if ( setenv("COLUMNS", "80", 1) == 0) -00383 #endif /*SYMBIAN*/ -00384 szTmp = getenv("COLUMNS"); -00385 -00386 if (szTmp != NULL) { -00387 DBG_MSG(szTmp); -00388 iTmp = (int)strtol(szTmp, &pcChar, 10); -00389 if (*pcChar == '\0') { -00390 iTmp -= 4; /* This is for the edge */ -00391 if (iTmp < MIN_SCREEN_WIDTH) { -00392 iTmp = MIN_SCREEN_WIDTH; -00393 } else if (iTmp > MAX_SCREEN_WIDTH) { -00394 iTmp = MAX_SCREEN_WIDTH; -00395 } -00396 tOptionsCurr.iParagraphBreak = iTmp; -00397 DBG_DEC(tOptionsCurr.iParagraphBreak); -00398 } -00399 } -00400 strncpy(szLeafname, szGetDefaultMappingFile(), sizeof(szLeafname) - 1); -00401 szLeafname[sizeof(szLeafname) - 1] = '\0'; -00402 /* Command line */ -00403 while ((iChar = getopt(argc, argv, "La:fhi:m:p:rstw:x:")) != -1) { -00404 switch (iChar) { -00405 case 'L': -00406 tOptionsCurr.bUseLandscape = TRUE; -00407 break; -00408 case 'a': -00409 if (!bCorrectPapersize(optarg, conversion_pdf)) { -00410 werr(0, "-a without a valid papersize"); -00411 return -1; -00412 } -00413 break; -00414 case 'f': -00415 tOptionsCurr.eConversionType = conversion_fmt_text; -00416 break; -00417 case 'h': -00418 return 0; -00419 case 'i': -00420 iTmp = (int)strtol(optarg, &pcChar, 10); -00421 if (*pcChar != '\0') { -00422 break; -00423 } -00424 switch (iTmp) { -00425 case 0: -00426 tOptionsCurr.eImageLevel = level_gs_special; -00427 break; -00428 case 1: -00429 tOptionsCurr.eImageLevel = level_no_images; -00430 break; -00431 case 2: -00432 tOptionsCurr.eImageLevel = level_ps_2; -00433 break; -00434 case 3: -00435 tOptionsCurr.eImageLevel = level_ps_3; -00436 break; -00437 default: -00438 tOptionsCurr.eImageLevel = level_default; -00439 break; -00440 } -00441 DBG_DEC(tOptionsCurr.eImageLevel); -00442 break; -00443 case 'm': -00444 if (tOptionsCurr.eConversionType == conversion_xml) { -00445 werr(0, "XML doesn't need a mapping file"); -00446 break; -00447 } -00448 strncpy(szLeafname, optarg, sizeof(szLeafname) - 1); -00449 szLeafname[sizeof(szLeafname) - 1] = '\0'; -00450 DBG_MSG(szLeafname); -00451 break; -00452 case 'p': -00453 if (!bCorrectPapersize(optarg, conversion_ps)) { -00454 werr(0, "-p without a valid papersize"); -00455 return -1; -00456 } -00457 break; -00458 case 'r': -00459 tOptionsCurr.bRemoveRemovedText = FALSE; -00460 break; -00461 case 's': -00462 tOptionsCurr.bHideHiddenText = FALSE; -00463 break; -00464 case 't': -00465 tOptionsCurr.eConversionType = conversion_text; -00466 break; -00467 case 'w': -00468 iTmp = (int)strtol(optarg, &pcChar, 10); -00469 if (*pcChar == '\0') { -00470 if (iTmp != 0 && iTmp < MIN_SCREEN_WIDTH) { -00471 iTmp = MIN_SCREEN_WIDTH; -00472 } else if (iTmp > MAX_SCREEN_WIDTH) { -00473 iTmp = MAX_SCREEN_WIDTH; -00474 } -00475 tOptionsCurr.iParagraphBreak = iTmp; -00476 DBG_DEC(tOptionsCurr.iParagraphBreak); -00477 } -00478 break; -00479 case 'x': -00480 if (STREQ(optarg, "db")) { -00481 tOptionsCurr.iParagraphBreak = 0; -00482 tOptionsCurr.eConversionType = conversion_xml; -00483 strcpy(szLeafname, MAPPING_FILE_UTF_8); -00484 } else { -00485 werr(0, "-x %s is not supported", optarg); -00486 return -1; -00487 } -00488 break; -00489 default: -00490 return -1; -00491 } -00492 } -00493 -00494 tOptionsCurr.eEncoding = eMappingFile2Encoding(szLeafname); -00495 DBG_DEC(tOptionsCurr.eEncoding); -00496 -00497 if (tOptionsCurr.eConversionType == conversion_ps && -00498 tOptionsCurr.eEncoding == encoding_utf_8) { -00499 werr(0, -00500 "The combination PostScript and UTF-8 is not supported"); -00501 return -1; -00502 } -00503 -00504 if (tOptionsCurr.eConversionType == conversion_pdf && -00505 tOptionsCurr.eEncoding == encoding_utf_8) { -00506 werr(0, -00507 "The combination PDF and UTF-8 is not supported"); -00508 return -1; -00509 } -00510 -00511 if (tOptionsCurr.eConversionType == conversion_pdf && -00512 tOptionsCurr.eEncoding == encoding_cyrillic) { -00513 werr(0, -00514 "The combination PDF and Cyrillic is not supported"); -00515 return -1; -00516 } -00517 -00518 if (tOptionsCurr.eConversionType == conversion_ps || -00519 tOptionsCurr.eConversionType == conversion_pdf) { -00520 /* PostScript or PDF mode */ -00521 if (tOptionsCurr.bUseLandscape) { -00522 /* Swap the page height and width */ -00523 iTmp = tOptionsCurr.iPageHeight; -00524 tOptionsCurr.iPageHeight = tOptionsCurr.iPageWidth; -00525 tOptionsCurr.iPageWidth = iTmp; -00526 } -00527 /* The paragraph break depends on the width of the paper */ -00528 tOptionsCurr.iParagraphBreak = iMilliPoints2Char( -00529 (long)tOptionsCurr.iPageWidth * 1000 - -00530 lDrawUnits2MilliPoints( -00531 PS_LEFT_MARGIN + PS_RIGHT_MARGIN)); -00532 DBG_DEC(tOptionsCurr.iParagraphBreak); -00533 } -00534 -00535 pCharacterMappingFile = pOpenCharacterMappingFile(szLeafname); -00536 if (pCharacterMappingFile != NULL) { -00537 bSuccess = bReadCharacterMappingTable(pCharacterMappingFile); -00538 vCloseCharacterMappingFile(pCharacterMappingFile); -00539 } else { -00540 bSuccess = FALSE; -00541 } -00542 return bSuccess ? optind : -1; -00543 #endif /* __riscos */ -00544 } /* end of iReadOptions */ -00545 -00546 /* -00547 * vGetOptions - get a copy of the current option values -00548 */ -00549 void -00550 vGetOptions(options_type *pOptions) -00551 { -00552 fail(pOptions == NULL); -00553 -00554 *pOptions = tOptionsCurr; -00555 } /* end of vGetOptions */ -00556 -00557 #if defined(__riscos) -00558 /* -00559 * vWriteOptions - write the current options to the Options file -00560 */ -00561 static void -00562 vWriteOptions(void) -00563 { -00564 FILE *pFile; -00565 char *szOptionsFile; -00566 -00567 TRACE_MSG("vWriteOptions"); -00568 -00569 szOptionsFile = getenv("AntiWord$ChoicesSave"); -00570 if (szOptionsFile == NULL) { -00571 werr(0, "Warning: Name of the Choices file not found"); -00572 return; -00573 } -00574 if (!bMakeDirectory(szOptionsFile)) { -00575 werr(0, -00576 "Warning: I can't make a directory for the Choices file"); -00577 return; -00578 } -00579 pFile = fopen(szOptionsFile, "w"); -00580 if (pFile == NULL) { -00581 werr(0, "Warning: I can't write the Choices file"); -00582 return; -00583 } -00584 (void)fprintf(pFile, PARAGRAPH_BREAK"\n", -00585 tOptionsCurr.iParagraphBreak); -00586 (void)fprintf(pFile, AUTOFILETYPE"\n", -00587 tOptionsCurr.bAutofiletypeAllowed); -00588 (void)fprintf(pFile, USE_OUTLINEFONTS"\n", -00589 tOptionsCurr.eConversionType == conversion_text ? 0 : 1); -00590 (void)fprintf(pFile, SHOW_IMAGES"\n", -00591 tOptionsCurr.eImageLevel == level_no_images ? 0 : 1); -00592 (void)fprintf(pFile, HIDE_HIDDEN_TEXT"\n", -00593 tOptionsCurr.bHideHiddenText); -00594 (void)fprintf(pFile, SCALE_FACTOR_START"\n", -00595 tOptionsCurr.iScaleFactor); -00596 (void)fclose(pFile); -00597 } /* end of vWriteOptions */ -00598 -00599 /* -00600 * vChoicesOpenAction - action to be taken when the Choices window opens -00601 */ -00602 void -00603 vChoicesOpenAction(window_handle tWindow) -00604 { -00605 TRACE_MSG("vChoicesOpenAction"); -00606 -00607 tOptionsTemp = tOptionsCurr; -00608 if (tOptionsTemp.iParagraphBreak == 0) { -00609 vUpdateRadioButton(tWindow, CHOICES_BREAK_BUTTON, FALSE); -00610 vUpdateRadioButton(tWindow, CHOICES_NO_BREAK_BUTTON, TRUE); -00611 vUpdateWriteableNumber(tWindow, CHOICES_BREAK_WRITEABLE, -00612 DEFAULT_SCREEN_WIDTH); -00613 } else { -00614 vUpdateRadioButton(tWindow, CHOICES_BREAK_BUTTON, TRUE); -00615 vUpdateRadioButton(tWindow, CHOICES_NO_BREAK_BUTTON, FALSE); -00616 vUpdateWriteableNumber(tWindow, -00617 CHOICES_BREAK_WRITEABLE, -00618 tOptionsTemp.iParagraphBreak); -00619 } -00620 vUpdateRadioButton(tWindow, CHOICES_AUTOFILETYPE_BUTTON, -00621 tOptionsTemp.bAutofiletypeAllowed); -00622 vUpdateRadioButton(tWindow, CHOICES_HIDDEN_TEXT_BUTTON, -00623 tOptionsTemp.bHideHiddenText); -00624 if (tOptionsTemp.eConversionType == conversion_draw) { -00625 vUpdateRadioButton(tWindow, -00626 CHOICES_WITH_IMAGES_BUTTON, -00627 tOptionsTemp.eImageLevel != level_no_images); -00628 vUpdateRadioButton(tWindow, -00629 CHOICES_NO_IMAGES_BUTTON, -00630 tOptionsTemp.eImageLevel == level_no_images); -00631 vUpdateRadioButton(tWindow, -00632 CHOICES_TEXTONLY_BUTTON, FALSE); -00633 } else { -00634 vUpdateRadioButton(tWindow, -00635 CHOICES_WITH_IMAGES_BUTTON, FALSE); -00636 vUpdateRadioButton(tWindow, -00637 CHOICES_NO_IMAGES_BUTTON, FALSE); -00638 vUpdateRadioButton(tWindow, -00639 CHOICES_TEXTONLY_BUTTON, TRUE); -00640 } -00641 vUpdateWriteableNumber(tWindow, -00642 CHOICES_SCALE_WRITEABLE, tOptionsTemp.iScaleFactor); -00643 TRACE_MSG("end of vChoicesOpenAction"); -00644 } /* end of vChoicesOpenAction */ -00645 -00646 /* -00647 * vDefaultButtonAction - action when the default button is clicked -00648 */ -00649 static void -00650 vDefaultButtonAction(window_handle tWindow) -00651 { -00652 TRACE_MSG("vDefaultButtonAction"); -00653 -00654 tOptionsTemp = tOptionsDefault; -00655 vUpdateRadioButton(tWindow, CHOICES_BREAK_BUTTON, TRUE); -00656 vUpdateRadioButton(tWindow, CHOICES_NO_BREAK_BUTTON, FALSE); -00657 vUpdateWriteableNumber(tWindow, CHOICES_BREAK_WRITEABLE, -00658 tOptionsTemp.iParagraphBreak); -00659 vUpdateRadioButton(tWindow, CHOICES_AUTOFILETYPE_BUTTON, -00660 tOptionsTemp.bAutofiletypeAllowed); -00661 vUpdateRadioButton(tWindow, CHOICES_HIDDEN_TEXT_BUTTON, -00662 tOptionsTemp.bHideHiddenText); -00663 vUpdateRadioButton(tWindow, CHOICES_WITH_IMAGES_BUTTON, -00664 tOptionsTemp.eConversionType == conversion_draw && -00665 tOptionsTemp.eImageLevel != level_no_images); -00666 vUpdateRadioButton(tWindow, CHOICES_NO_IMAGES_BUTTON, -00667 tOptionsTemp.eConversionType == conversion_draw && -00668 tOptionsTemp.eImageLevel == level_no_images); -00669 vUpdateRadioButton(tWindow, CHOICES_TEXTONLY_BUTTON, -00670 tOptionsTemp.eConversionType == conversion_text); -00671 vUpdateWriteableNumber(tWindow, CHOICES_SCALE_WRITEABLE, -00672 tOptionsTemp.iScaleFactor); -00673 } /* end of vDefaultButtonAction */ -00674 -00675 /* -00676 * vApplyButtonAction - action to be taken when the OK button is clicked -00677 */ -00678 static void -00679 vApplyButtonAction(void) -00680 { -00681 TRACE_MSG("vApplyButtonAction"); -00682 -00683 tOptionsCurr = tOptionsTemp; -00684 } /* end of vApplyButtonAction */ -00685 -00686 /* -00687 * vSaveButtonAction - action to be taken when the save button is clicked -00688 */ -00689 static void -00690 vSaveButtonAction(void) -00691 { -00692 TRACE_MSG("vSaveButtonAction"); -00693 -00694 vApplyButtonAction(); -00695 vWriteOptions(); -00696 } /* end of vSaveButtonAction */ -00697 -00698 /* -00699 * vSetParagraphBreak - set the paragraph break to the given number -00700 */ -00701 static void -00702 vSetParagraphBreak(window_handle tWindow, int iNumber) -00703 { -00704 tOptionsTemp.iParagraphBreak = iNumber; -00705 if (tOptionsTemp.iParagraphBreak == 0) { -00706 return; -00707 } -00708 vUpdateWriteableNumber(tWindow, -00709 CHOICES_BREAK_WRITEABLE, -00710 tOptionsTemp.iParagraphBreak); -00711 } /* end of vSetParagraphBreak */ -00712 -00713 /* -00714 * vChangeParagraphBreak - change the paragraph break with the given number -00715 */ -00716 static void -00717 vChangeParagraphBreak(window_handle tWindow, int iNumber) -00718 { -00719 int iTmp; -00720 -00721 iTmp = tOptionsTemp.iParagraphBreak + iNumber; -00722 if (iTmp < MIN_SCREEN_WIDTH || iTmp > MAX_SCREEN_WIDTH) { -00723 /* Ignore */ -00724 return; -00725 } -00726 tOptionsTemp.iParagraphBreak = iTmp; -00727 vUpdateWriteableNumber(tWindow, -00728 CHOICES_BREAK_WRITEABLE, -00729 tOptionsTemp.iParagraphBreak); -00730 } /* end of vChangeParagraphBreak */ -00731 -00732 /* -00733 * vChangeAutofiletype - invert the permission to autofiletype -00734 */ -00735 static void -00736 vChangeAutofiletype(window_handle tWindow) -00737 { -00738 tOptionsTemp.bAutofiletypeAllowed = -00739 !tOptionsTemp.bAutofiletypeAllowed; -00740 vUpdateRadioButton(tWindow, -00741 CHOICES_AUTOFILETYPE_BUTTON, -00742 tOptionsTemp.bAutofiletypeAllowed); -00743 } /* end of vChangeAutofiletype */ -00744 -00745 /* -00746 * vChangeHiddenText - invert the hide/show hidden text -00747 */ -00748 static void -00749 vChangeHiddenText(window_handle tWindow) -00750 { -00751 tOptionsTemp.bHideHiddenText = !tOptionsTemp.bHideHiddenText; -00752 vUpdateRadioButton(tWindow, -00753 CHOICES_HIDDEN_TEXT_BUTTON, -00754 tOptionsTemp.bHideHiddenText); -00755 } /* end of vChangeHiddenText */ -00756 -00757 /* -00758 * vUseFontsImages - use outline fonts, show images -00759 */ -00760 static void -00761 vUseFontsImages(BOOL bUseOutlineFonts, BOOL bShowImages) -00762 { -00763 tOptionsTemp.eConversionType = -00764 bUseOutlineFonts ? conversion_draw : conversion_text; -00765 tOptionsTemp.eImageLevel = -00766 bUseOutlineFonts && bShowImages ? -00767 level_default : level_no_images; -00768 } /* end of vUseFontsImages */ -00769 -00770 /* -00771 * vSetScaleFactor - set the scale factor to the given number -00772 */ -00773 static void -00774 vSetScaleFactor(window_handle tWindow, int iNumber) -00775 { -00776 tOptionsTemp.iScaleFactor = iNumber; -00777 vUpdateWriteableNumber(tWindow, -00778 CHOICES_SCALE_WRITEABLE, -00779 tOptionsTemp.iScaleFactor); -00780 } /* end of vSetScaleFactor */ -00781 -00782 /* -00783 * vChangeScaleFactor - change the scale factor with the given number -00784 */ -00785 static void -00786 vChangeScaleFactor(window_handle tWindow, int iNumber) -00787 { -00788 int iTmp; -00789 -00790 iTmp = tOptionsTemp.iScaleFactor + iNumber; -00791 if (iTmp < MIN_SCALE_FACTOR || iTmp > MAX_SCALE_FACTOR) { -00792 /* Ignore */ -00793 return; -00794 } -00795 tOptionsTemp.iScaleFactor = iTmp; -00796 vUpdateWriteableNumber(tWindow, -00797 CHOICES_SCALE_WRITEABLE, -00798 tOptionsTemp.iScaleFactor); -00799 } /* end of vChangeScaleFactor */ -00800 -00801 /* -00802 * bChoicesMouseClick - handle a mouse click in the Choices window -00803 */ -00804 BOOL -00805 bChoicesMouseClick(event_pollblock *pEvent, void *pvReference) -00806 { -00807 icon_handle tAction; -00808 mouse_block *pMouse; -00809 BOOL bCloseWindow; -00810 -00811 TRACE_MSG("bChoicesMouseClick"); -00812 -00813 fail(pEvent == NULL); -00814 fail(pEvent->type != event_CLICK); -00815 -00816 pMouse = &pEvent->data.mouse; -00817 if (!pMouse->button.data.select && !pMouse->button.data.adjust) { -00818 /* Not handled here */ -00819 DBG_HEX(pMouse->button.value); -00820 return FALSE; -00821 } -00822 -00823 /* Which action should be taken */ -00824 tAction = pMouse->icon; -00825 if (pMouse->button.data.adjust) { -00826 /* The adjust button reverses the direction */ -00827 switch (pMouse->icon) { -00828 case CHOICES_BREAK_UP_BUTTON: -00829 tAction = CHOICES_BREAK_DOWN_BUTTON; -00830 break; -00831 case CHOICES_BREAK_DOWN_BUTTON: -00832 tAction = CHOICES_BREAK_UP_BUTTON; -00833 break; -00834 case CHOICES_SCALE_UP_BUTTON: -00835 tAction = CHOICES_SCALE_DOWN_BUTTON; -00836 break; -00837 case CHOICES_SCALE_DOWN_BUTTON: -00838 tAction = CHOICES_SCALE_UP_BUTTON; -00839 break; -00840 default: -00841 break; -00842 } -00843 } -00844 -00845 /* Actions */ -00846 bCloseWindow = FALSE; -00847 switch (tAction) { -00848 case CHOICES_DEFAULT_BUTTON: -00849 vDefaultButtonAction(pMouse->window); -00850 break; -00851 case CHOICES_SAVE_BUTTON: -00852 vSaveButtonAction(); -00853 break; -00854 case CHOICES_CANCEL_BUTTON: -00855 bCloseWindow = TRUE; -00856 break; -00857 case CHOICES_APPLY_BUTTON: -00858 vApplyButtonAction(); -00859 bCloseWindow = TRUE; -00860 break; -00861 case CHOICES_BREAK_BUTTON: -00862 vSetParagraphBreak(pMouse->window, DEFAULT_SCREEN_WIDTH); -00863 break; -00864 case CHOICES_BREAK_UP_BUTTON: -00865 vChangeParagraphBreak(pMouse->window, 1); -00866 break; -00867 case CHOICES_BREAK_DOWN_BUTTON: -00868 vChangeParagraphBreak(pMouse->window, -1); -00869 break; -00870 case CHOICES_NO_BREAK_BUTTON: -00871 vSetParagraphBreak(pMouse->window, 0); -00872 break; -00873 case CHOICES_AUTOFILETYPE_BUTTON: -00874 vChangeAutofiletype(pMouse->window); -00875 break; -00876 case CHOICES_HIDDEN_TEXT_BUTTON: -00877 vChangeHiddenText(pMouse->window); -00878 break; -00879 case CHOICES_WITH_IMAGES_BUTTON: -00880 vUseFontsImages(TRUE, TRUE); -00881 break; -00882 case CHOICES_NO_IMAGES_BUTTON: -00883 vUseFontsImages(TRUE, FALSE); -00884 break; -00885 case CHOICES_TEXTONLY_BUTTON: -00886 vUseFontsImages(FALSE, FALSE); -00887 break; -00888 case CHOICES_SCALE_UP_BUTTON: -00889 vChangeScaleFactor(pMouse->window, 5); -00890 break; -00891 case CHOICES_SCALE_DOWN_BUTTON: -00892 vChangeScaleFactor(pMouse->window, -5); -00893 break; -00894 default: -00895 DBG_DEC(pMouse->icon); -00896 break; -00897 } -00898 if (bCloseWindow) { -00899 Error_CheckFatal(Wimp_CloseWindow(pMouse->window)); -00900 } -00901 return TRUE; -00902 } /* end of bChoicesMouseClick */ -00903 -00904 /* -00905 * bChoicesKeyPressed - handle a key in the Choices window -00906 */ -00907 BOOL -00908 bChoicesKeyPressed(event_pollblock *pEvent, void *pvReference) -00909 { -00910 icon_block tIcon; -00911 caret_block *pCaret; -00912 char *pcChar; -00913 int iNumber; -00914 -00915 DBG_MSG("bChoicesKeyPressed"); -00916 -00917 fail(pEvent == NULL); -00918 fail(pEvent->type != event_KEY); -00919 -00920 if (pEvent->data.key.code != '\r') { -00921 Error_CheckFatal(Wimp_ProcessKey(pEvent->data.key.code)); -00922 return TRUE; -00923 } -00924 -00925 pCaret = &pEvent->data.key.caret; -00926 -00927 Error_CheckFatal(Wimp_GetIconState(pCaret->window, pCaret->icon, &tIcon)); -00928 if (!tIcon.flags.data.text || !tIcon.flags.data.indirected) { -00929 werr(1, "Icon %d must be indirected text", (int)pCaret->icon); -00930 } -00931 iNumber = (int)strtol(tIcon.data.indirecttext.buffer, &pcChar, 10); -00932 -00933 switch(pCaret->icon) { -00934 case CHOICES_BREAK_WRITEABLE: -00935 if (*pcChar != '\0' && *pcChar != '\r') { -00936 DBG_DEC(*pcChar); -00937 iNumber = DEFAULT_SCREEN_WIDTH; -00938 } else if (iNumber < MIN_SCREEN_WIDTH) { -00939 iNumber = MIN_SCREEN_WIDTH; -00940 } else if (iNumber > MAX_SCREEN_WIDTH) { -00941 iNumber = MAX_SCREEN_WIDTH; -00942 } -00943 vSetParagraphBreak(pCaret->window, iNumber); -00944 break; -00945 case CHOICES_SCALE_WRITEABLE: -00946 if (*pcChar != '\0' && *pcChar != '\r') { -00947 DBG_DEC(*pcChar); -00948 iNumber = DEFAULT_SCALE_FACTOR; -00949 } else if (iNumber < MIN_SCALE_FACTOR) { -00950 iNumber = MIN_SCALE_FACTOR; -00951 } else if (iNumber > MAX_SCALE_FACTOR) { -00952 iNumber = MAX_SCALE_FACTOR; -00953 } -00954 vSetScaleFactor(pCaret->window, iNumber); -00955 break; -00956 default: -00957 DBG_DEC(pCaret->icon); -00958 break; -00959 } -00960 return TRUE; -00961 } /* end of bChoicesKeyPressed */ -00962 #endif /* __riscos */ -