PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/noah_palm/src/better_formatting.c

https://github.com/kjk/noah-palm
C | 1665 lines | 1349 code | 158 blank | 158 comment | 188 complexity | 2df77dec3779e0792eeeb9dd8b642cbd MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. Copyright (C) 2000-2003 Krzysztof Kowalczyk
  3. Author: szymon knitter (szknitter@wp.pl)
  4. Set of functions that improve the word display format:
  5. + window event handle function for DisplayPrefsForm
  6. + functions that format word definition in extBuffer
  7. + ebufWrapLine (moved from extensible_buffer.c)
  8. + functions used to draw word
  9. */
  10. //#pragma warn_a5_access on
  11. #include "common.h"
  12. #ifdef NOAH_PRO
  13. #include "noah_pro_2nd_segment.h"
  14. #endif
  15. #ifdef I_NOAH
  16. #include "inet_definition_format.h"
  17. #endif
  18. #if 0
  19. // just in case PackRGB macro turns out to be buggy
  20. PackedRGB PackRGB_f(int r,int g, int b)
  21. {
  22. PackedRGB res;
  23. res = (long)r<<16;
  24. res &= 0xff0000L;
  25. res |= (g<<8)&0xff00L;
  26. res |= b&0xffL;
  27. return res;
  28. }
  29. #endif
  30. /* Free ptrOldDisplayPrefs if its not NULL*/
  31. void bfFreePTR(AppContext *appContext)
  32. {
  33. if(appContext->ptrOldDisplayPrefs != NULL)
  34. new_free(appContext->ptrOldDisplayPrefs);
  35. appContext->ptrOldDisplayPrefs = NULL;
  36. }
  37. /* When we change global background we need to change all backgrounds to global background color */
  38. static void SetAllBackGroundLikeGlobal(DisplayPrefs *displayPrefs, PackedRGB rgb)
  39. {
  40. displayPrefs->pos.bgCol = rgb;
  41. displayPrefs->word.bgCol = rgb;
  42. displayPrefs->definition.bgCol = rgb;
  43. displayPrefs->example.bgCol = rgb;
  44. displayPrefs->synonym.bgCol = rgb;
  45. displayPrefs->defList.bgCol = rgb;
  46. displayPrefs->posList.bgCol = rgb;
  47. displayPrefs->pronunciation.bgCol = rgb;
  48. }
  49. /* Sets &prefs (only used by SetDefaultDisplayParam) */
  50. static void SetPrefsAs(DisplayElementPrefs *prefs, FontID font, PackedRGB color, PackedRGB bgCol)
  51. {
  52. prefs->font = font;
  53. prefs->color = color;
  54. prefs->bgCol = bgCol;
  55. }
  56. /* Sets rest of display params to actual listStyle */
  57. void SetDefaultDisplayParam(DisplayPrefs *displayPrefs, Boolean onlyFont, Boolean onlyColor)
  58. {
  59. DisplayElementPrefs prefs[16];
  60. DisplayElementPrefs *prefsToSet;
  61. // format 3(0): (old)
  62. SetPrefsAs(&prefs[ 0], stdFont, BLACK_Packed, WHITE_Packed); // color is black, font is small
  63. // format 1:
  64. SetPrefsAs(&prefs[ 1], largeBoldFont, PackRGB(0,0,255), WHITE_Packed ); // word
  65. SetPrefsAs(&prefs[ 2], boldFont, PackRGB(0,220,0), WHITE_Packed ); // pos
  66. SetPrefsAs(&prefs[ 3], stdFont, BLACK_Packed, WHITE_Packed ); // definition
  67. SetPrefsAs(&prefs[ 4], stdFont, PackRGB(221,34,17), WHITE_Packed ); // example
  68. #ifdef THESAURUS
  69. SetPrefsAs(&prefs[ 5], stdFont, PackRGB(0,0,68), WHITE_Packed ); // synonyms
  70. #else
  71. SetPrefsAs(&prefs[ 5], boldFont, PackRGB(0,0,68), WHITE_Packed ); // synonyms
  72. #endif
  73. SetPrefsAs(&prefs[ 6], stdFont, BLACK_Packed, WHITE_Packed ); // definition list
  74. SetPrefsAs(&prefs[ 7], boldFont, PackRGB(0,220,0), WHITE_Packed ); // pos list
  75. // format 2: (default)
  76. SetPrefsAs(&prefs[ 8], largeBoldFont, PackRGB(0,0,255), WHITE_Packed ); // word
  77. SetPrefsAs(&prefs[ 9], boldFont, PackRGB(0,220,0), WHITE_Packed ); // pos
  78. SetPrefsAs(&prefs[10], stdFont, BLACK_Packed, WHITE_Packed ); // definition
  79. SetPrefsAs(&prefs[11], stdFont, PackRGB(221,34,17), WHITE_Packed ); // example
  80. #ifdef THESAURUS
  81. SetPrefsAs(&prefs[12], stdFont, PackRGB(0,0,68), WHITE_Packed ); // synonyms
  82. #else
  83. SetPrefsAs(&prefs[12], boldFont, PackRGB(0,0,68), WHITE_Packed ); // synonyms
  84. #endif
  85. SetPrefsAs(&prefs[13], stdFont, BLACK_Packed, WHITE_Packed ); // definition list
  86. SetPrefsAs(&prefs[14], boldFont, PackRGB(0,220,0), WHITE_Packed ); // pos list
  87. //pronunciation for both
  88. SetPrefsAs(&prefs[15], largeBoldFont, PackRGB(80,160,0), WHITE_Packed ); //pronunciation
  89. prefsToSet = &prefs[0];
  90. if(!onlyFont && !onlyColor)
  91. {
  92. switch(displayPrefs->listStyle)
  93. {
  94. case 1:
  95. displayPrefs->word = prefsToSet[1];
  96. displayPrefs->pos = prefsToSet[2];
  97. displayPrefs->definition = prefsToSet[3];
  98. displayPrefs->example = prefsToSet[4];
  99. displayPrefs->synonym = prefsToSet[5];
  100. displayPrefs->defList = prefsToSet[6];
  101. displayPrefs->posList = prefsToSet[7];
  102. break;
  103. case 2:
  104. displayPrefs->word = prefsToSet[8];
  105. displayPrefs->pos = prefsToSet[9];
  106. displayPrefs->definition = prefsToSet[10];
  107. displayPrefs->example = prefsToSet[11];
  108. displayPrefs->synonym = prefsToSet[12];
  109. displayPrefs->defList = prefsToSet[13];
  110. displayPrefs->posList = prefsToSet[14];
  111. break;
  112. case 0: //without break
  113. default: //if not supported then dafault
  114. displayPrefs->pos = prefsToSet[0];
  115. displayPrefs->word = prefsToSet[0];
  116. displayPrefs->definition = prefsToSet[0];
  117. displayPrefs->example = prefsToSet[0];
  118. displayPrefs->synonym = prefsToSet[0];
  119. displayPrefs->defList = prefsToSet[0];
  120. displayPrefs->posList = prefsToSet[0];
  121. break;
  122. }
  123. // settings common to all styles
  124. displayPrefs->pronunciation = prefsToSet[15];
  125. displayPrefs->bgCol = WHITE_Packed;
  126. displayPrefs->fEnablePronunciation = true;
  127. displayPrefs->fEnablePronunciationSpecialFonts = false;
  128. if(!IsColorSupported(GetAppContext())) //we need to set all colors to black&white
  129. {
  130. displayPrefs->bgCol = WHITE_Packed;
  131. SetAllBackGroundLikeGlobal(displayPrefs, displayPrefs->bgCol);
  132. displayPrefs->pos.color = BLACK_Packed;
  133. displayPrefs->word.color = BLACK_Packed;
  134. displayPrefs->definition.color = BLACK_Packed;
  135. displayPrefs->example.color = BLACK_Packed;
  136. displayPrefs->synonym.color = BLACK_Packed;
  137. displayPrefs->defList.color = BLACK_Packed;
  138. displayPrefs->posList.color = BLACK_Packed;
  139. displayPrefs->pronunciation.color = BLACK_Packed;
  140. }
  141. }
  142. }
  143. /* sets fonts (used in ebufWrapLine */
  144. void SetOnlyFont(char type,DisplayPrefs *displayPrefs)
  145. {
  146. // I use "case (char) FORMAT_POS:" instead of "case FORMAT_POS:" because
  147. // FORMAT_POS is greater than 127 and we use signed char!!!
  148. // (because if "char z = 150;" and "#define FORMAT_POS 150" then "z != FORMAT_POS" !!!)
  149. switch(type)
  150. {
  151. case (char) FORMAT_POS :
  152. FntSetFont(displayPrefs->pos.font);
  153. break;
  154. case (char) FORMAT_WORD :
  155. FntSetFont(displayPrefs->word.font);
  156. break;
  157. case (char) FORMAT_DEFINITION :
  158. FntSetFont(displayPrefs->definition.font);
  159. break;
  160. case (char) FORMAT_EXAMPLE :
  161. FntSetFont(displayPrefs->example.font);
  162. break;
  163. case (char) FORMAT_SYNONYM :
  164. FntSetFont(displayPrefs->synonym.font);
  165. break;
  166. case (char) FORMAT_LIST :
  167. FntSetFont(displayPrefs->defList.font);
  168. break;
  169. case (char) FORMAT_BIG_LIST :
  170. FntSetFont(displayPrefs->posList.font);
  171. break;
  172. case (char) FORMAT_PRONUNCIATION :
  173. FntSetFont(displayPrefs->pronunciation.font);
  174. break;
  175. default:
  176. FntSetFont((FontID) 0x00);
  177. break;
  178. }
  179. }
  180. static void SetFontAndCols(AppContext *appContext, DisplayElementPrefs *displayPrefs)
  181. {
  182. FntSetFont(displayPrefs->font);
  183. SetTextColorRGB(appContext, displayPrefs->color);
  184. SetBackColorRGB(appContext, displayPrefs->bgCol);
  185. }
  186. /* used in display */
  187. void SetDrawParam(char type, DisplayPrefs *displayPrefs, AppContext * appContext)
  188. {
  189. // I use "case (char) FORMAT_POS:" instead of "case FORMAT_POS:" because
  190. // FORMAT_POS is greater than 127 and we use signed char!!!
  191. // (because if "char z = 150;" and "#define FORMAT_POS 150" then "z != FORMAT_POS" !!!)
  192. switch(type)
  193. {
  194. case (char) FORMAT_POS:
  195. SetFontAndCols(appContext, &(displayPrefs->pos));
  196. break;
  197. case (char) FORMAT_WORD:
  198. SetFontAndCols(appContext, &(displayPrefs->word));
  199. break;
  200. case (char) FORMAT_DEFINITION:
  201. SetFontAndCols(appContext, &(displayPrefs->definition));
  202. break;
  203. case (char) FORMAT_EXAMPLE:
  204. SetFontAndCols(appContext, &(displayPrefs->example));
  205. break;
  206. case (char) FORMAT_SYNONYM:
  207. SetFontAndCols(appContext, &(displayPrefs->synonym));
  208. break;
  209. case (char) FORMAT_LIST:
  210. SetFontAndCols(appContext, &(displayPrefs->defList));
  211. break;
  212. case (char) FORMAT_BIG_LIST:
  213. SetFontAndCols(appContext, &(displayPrefs->posList));
  214. break;
  215. case (char) FORMAT_PRONUNCIATION:
  216. SetFontAndCols(appContext, &(displayPrefs->pronunciation));
  217. break;
  218. default:
  219. FntSetFont((FontID) 0x00);
  220. SetBackColorRGB(appContext, WHITE_Packed);
  221. SetTextColorRGB(appContext, BLACK_Packed);
  222. break;
  223. }
  224. }
  225. static DisplayElementPrefs *GetDEPForTag(DisplayPrefs *dp, ActualTag tag)
  226. {
  227. switch(tag)
  228. {
  229. case actTagPos:
  230. return &dp->pos;
  231. case actTagWord:
  232. return &dp->word;
  233. case actTagDefinition:
  234. return &dp->definition;
  235. case actTagExample:
  236. return &dp->example;
  237. case actTagSynonym:
  238. return &dp->synonym;
  239. case actTagDefList:
  240. return &dp->defList;
  241. case actTagPosList:
  242. return &dp->posList;
  243. case actTagPronunciation:
  244. return &dp->pronunciation;
  245. default:
  246. Assert(0);
  247. return NULL;
  248. break;
  249. }
  250. }
  251. static void RunColorSetForm(int *Rinout, int *Ginout, int *Binout)
  252. {
  253. RGBColorType rgb_color;
  254. rgb_color.index = 0;
  255. rgb_color.r = *Rinout;
  256. rgb_color.g = *Ginout;
  257. rgb_color.b = *Binout;
  258. if(IsColorSupported(GetAppContext()))
  259. UIPickColor (&rgb_color.index, &rgb_color, UIPickColorStartRGB,"Choose color", NULL);
  260. *Rinout = rgb_color.r;
  261. *Ginout = rgb_color.g;
  262. *Binout = rgb_color.b;
  263. }
  264. // devnote: return the same color if colors are not supported or the user didn't
  265. // canceled the color selection process
  266. static PackedRGB RunColorSetForm(PackedRGB rgb)
  267. {
  268. RGBColorType rgb_color;
  269. if( !IsColorSupported(GetAppContext()))
  270. return rgb;
  271. rgb_color.index = 0;
  272. rgb_color.r = RGBGetR(rgb);
  273. rgb_color.g = RGBGetG(rgb);
  274. rgb_color.b = RGBGetB(rgb);
  275. if ( UIPickColor (&rgb_color.index, &rgb_color, UIPickColorStartRGB,"Choose color", NULL) )
  276. return PackRGB(rgb_color.r,rgb_color.g,rgb_color.b);
  277. else
  278. return rgb;
  279. }
  280. static void RunColorSetFormForTag(DisplayPrefs *dp, ActualTag tag, Boolean bgCol)
  281. {
  282. DisplayElementPrefs *dep;
  283. dep = GetDEPForTag(dp, tag);
  284. if (bgCol)
  285. dep->bgCol = RunColorSetForm(dep->bgCol);
  286. else
  287. dep->color = RunColorSetForm(dep->color);
  288. }
  289. static PackedRGB GetRGBForTag(DisplayPrefs *dp, ActualTag tag, Boolean fBgCol)
  290. {
  291. DisplayElementPrefs *dep;
  292. dep = GetDEPForTag(dp, tag);
  293. if ( fBgCol )
  294. return dep->bgCol;
  295. else
  296. return dep->color;
  297. }
  298. /* Set color to draw buttons */
  299. static void SetColorButton(AppContext * appContext, ActualTag actTag, Boolean fBgCol, DisplayPrefs *displayPrefs)
  300. {
  301. SetTextColorRGB(appContext, GetRGBForTag(displayPrefs, actTag, fBgCol));
  302. }
  303. /* Draw color rectangles over the buttons */
  304. static void RedrawFormElements( AppContext *appContext, ActualTag actTag, DisplayPrefs *displayPrefs)
  305. {
  306. /* Now we dont use Font button draw in current font... but we can do it here!*/
  307. // FontID prev_font;
  308. RectangleType r;
  309. UInt16 index=0;
  310. FormType* frm = FrmGetActiveForm();
  311. // prev_font = FntGetFont();
  312. // WinDrawChars("Aa",2, 70, 30);
  313. SetTextColorRGB(appContext,appContext->prefs.displayPrefs.bgCol);
  314. r.topLeft.x = 160 - 22;
  315. r.topLeft.y = 16;
  316. r.extent.x = 20;
  317. r.extent.y = 10;
  318. WinDrawRectangle(&r, 4);
  319. SetColorButton(appContext,actTag,false,displayPrefs);
  320. r.topLeft.x = 95;
  321. r.topLeft.y = 29;
  322. r.extent.x = 20;
  323. r.extent.y = 12;
  324. WinDrawRectangle(&r, 4);
  325. SetColorButton(appContext,actTag,true,displayPrefs);
  326. r.topLeft.x = 160 - 22;
  327. r.topLeft.y = 29;
  328. r.extent.x = 20;
  329. r.extent.y = 12;
  330. WinDrawRectangle(&r, 4);
  331. SetTextColorRGB(appContext, BLACK_Packed);
  332. // FntSetFont(prev_font);
  333. #ifdef NOAH_PRO
  334. if(actTag == actTagPronunciation)
  335. {
  336. index=FrmGetObjectIndex(frm, buttonFpos);
  337. Assert(index!=frmInvalidObjectId);
  338. FrmHideObject(frm, index);
  339. FrmGetObjectBounds(frm, index, &r);
  340. r.topLeft.x=28;
  341. FrmSetObjectBounds(frm, index, &r);
  342. FrmShowObject(frm, index);
  343. index=FrmGetObjectIndex(frm, checkEnablePron);
  344. FrmSetControlValue (frm, index, appContext->prefs.displayPrefs.fEnablePronunciation);
  345. FrmShowObject(frm, index);
  346. }
  347. else
  348. {
  349. FrmHideObject(frm, FrmGetObjectIndex(frm, checkEnablePron));
  350. index=FrmGetObjectIndex(frm, buttonFpos);
  351. Assert(index!=frmInvalidObjectId);
  352. FrmHideObject(frm, index);
  353. FrmGetObjectBounds(frm, index, &r);
  354. r.topLeft.x=10;
  355. FrmSetObjectBounds(frm, index, &r);
  356. FrmShowObject(frm, index);
  357. }
  358. #endif
  359. }
  360. /* Makes definition and draw it! */
  361. static void RedrawExampleDefinition(AppContext* appContext)
  362. {
  363. ExtensibleBuffer *Buf;
  364. char *rawTxt;
  365. #ifdef NOAH_PRO
  366. char *pron;
  367. unsigned char decompresed[10];
  368. #endif
  369. char pos[3], word[3], def[3], example[3], synonym[3], point[3];
  370. //initialize data (resident mode)
  371. pos[0]=FORMAT_TAG; pos[1]=FORMAT_POS; pos[2]=0;
  372. word[0]=FORMAT_TAG; word[1]=FORMAT_WORD; word[2]=0;
  373. def[0]=FORMAT_TAG; def[1]=FORMAT_DEFINITION; def[2]=0;
  374. example[0]=FORMAT_TAG; example[1]=FORMAT_EXAMPLE; example[2]=0;
  375. synonym[0]=FORMAT_TAG; synonym[1]=FORMAT_SYNONYM; synonym[2]=0;
  376. point[0]=149; point[1]=' '; point[2]=0;
  377. Buf = ebufNew();
  378. Assert(Buf);
  379. //it will do format later (it looks like normal selected word)
  380. if(appContext->prefs.displayPrefs.listStyle != 0)
  381. {
  382. ebufAddStr(Buf, synonym);
  383. ebufAddStr(Buf, "word\n");
  384. #ifdef NOAH_PRO
  385. if(appContext->prefs.displayPrefs.fEnablePronunciation)
  386. if(appContext->pronData.isPronInUsedDictionary)
  387. {
  388. ebufAddChar(Buf, FORMAT_TAG);
  389. ebufAddChar(Buf, FORMAT_PRONUNCIATION);
  390. ebufAddStr(Buf, "[");
  391. decompresed[0] = 36;
  392. decompresed[1] = 12;
  393. decompresed[2] = 9;
  394. decompresed[3] = 0;
  395. pron = pronTranslateDecompresed(appContext, decompresed);
  396. ebufAddStr(Buf, pron);
  397. new_free(pron);
  398. ebufAddStr(Buf, "]\n");
  399. }
  400. #endif
  401. }
  402. ebufAddStr(Buf, pos);
  403. ebufAddStr(Buf, point);
  404. ebufAddStr(Buf, "(Noun) ");
  405. ebufAddStr(Buf, word);
  406. if(appContext->prefs.displayPrefs.listStyle == 0)
  407. ebufAddStr(Buf, "word, ");
  408. ebufAddStr(Buf, "word2, word3\n");
  409. #ifndef THESAURUS //why? think :)
  410. ebufAddStr(Buf, def);
  411. ebufAddStr(Buf, "definition1\n");
  412. ebufAddStr(Buf, pos);
  413. ebufAddStr(Buf, point);
  414. ebufAddStr(Buf, "(Noun) ");
  415. if(appContext->prefs.displayPrefs.listStyle == 0)
  416. {
  417. ebufAddStr(Buf, word);
  418. ebufAddStr(Buf, "word\n");
  419. }
  420. ebufAddStr(Buf, def);
  421. ebufAddStr(Buf, "definition2\n");
  422. ebufAddStr(Buf, example);
  423. ebufAddStr(Buf, "example\n");
  424. ebufAddStr(Buf, pos);
  425. ebufAddStr(Buf, point);
  426. ebufAddStr(Buf, "(Verb) ");
  427. if(appContext->prefs.displayPrefs.listStyle == 0)
  428. {
  429. ebufAddStr(Buf, word);
  430. ebufAddStr(Buf, "word\n");
  431. }
  432. ebufAddStr(Buf, def);
  433. ebufAddStr(Buf, "definition\n\0");
  434. #else
  435. ebufAddStr(Buf, pos);
  436. ebufAddStr(Buf, point);
  437. ebufAddStr(Buf, "(Noun) ");
  438. if(appContext->prefs.displayPrefs.listStyle == 0)
  439. {
  440. ebufAddStr(Buf, word);
  441. ebufAddStr(Buf, "word, ");
  442. }
  443. ebufAddStr(Buf, word);
  444. ebufAddStr(Buf, "word3, word4\n");
  445. ebufAddStr(Buf, pos);
  446. ebufAddStr(Buf, point);
  447. ebufAddStr(Buf, "(Verb) ");
  448. if(appContext->prefs.displayPrefs.listStyle == 0)
  449. {
  450. ebufAddStr(Buf, word);
  451. ebufAddStr(Buf, "word, ");
  452. }
  453. ebufAddStr(Buf, word);
  454. ebufAddStr(Buf, "word4, word5\n\0");
  455. #endif
  456. ebufAddChar(Buf, '\0');
  457. ebufWrapBigLines(Buf,true);
  458. if (NULL == appContext->currDispInfo)
  459. {
  460. appContext->currDispInfo = diNew();
  461. if (NULL == appContext->currDispInfo)
  462. {
  463. ebufDelete(Buf);
  464. return;
  465. }
  466. }
  467. rawTxt = ebufGetDataPointer(Buf);
  468. diSetRawTxt(appContext->currDispInfo, rawTxt);
  469. ebufDelete(Buf);
  470. appContext->firstDispLine = 0;
  471. SetGlobalBackColor(appContext);
  472. ClearRectangle(DRAW_DI_X, 42, appContext->screenWidth, appContext->screenHeight-42-15);
  473. SetBackColorRGB(appContext, WHITE_Packed);
  474. DrawDisplayInfo(appContext->currDispInfo, 0, DRAW_DI_X, 30+12, appContext->dispLinesCount);
  475. }
  476. static Boolean DisplPrefFormDisplayChanged(AppContext* appContext, FormType* frm)
  477. {
  478. Assert( DIA_Supported(&appContext->diaSettings) );
  479. if ( !DIA_Supported(&appContext->diaSettings) )
  480. return false;
  481. UpdateFrmBounds(frm);
  482. FrmSetObjectPosByID(frm, buttonOk, -1, appContext->screenHeight-14);
  483. FrmSetObjectPosByID(frm, buttonCancel, -1, appContext->screenHeight-14);
  484. FrmSetObjectPosByID(frm, buttonDefault, -1, appContext->screenHeight-14);
  485. FrmDrawForm(frm);
  486. return true;
  487. }
  488. static void InitOldDisplayPrefs(AppContext *appContext)
  489. {
  490. appContext->ptrOldDisplayPrefs = new_malloc(sizeof(DisplayPrefs));
  491. }
  492. static void CopyParamsFromTo(DisplayPrefs *src, DisplayPrefs *dst)
  493. {
  494. Assert(src);
  495. Assert(dst);
  496. dst->listStyle = src->listStyle;
  497. dst->bgCol = src->bgCol;
  498. dst->pos = src->pos;
  499. dst->word = src->word;
  500. dst->definition = src->definition;
  501. dst->example = src->example;
  502. dst->synonym = src->synonym;
  503. dst->defList = src->defList;
  504. dst->posList = src->posList;
  505. dst->pronunciation = src->pronunciation;
  506. }
  507. #ifdef I_NOAH
  508. void ReformatLastResponse(AppContext* appContext)
  509. {
  510. if (mainFormShowsDefinition==appContext->mainFormContent)
  511. {
  512. const char* responseBegin=ebufGetDataPointer(&appContext->lastResponse);
  513. Assert(responseBegin);
  514. const char* responseEnd=responseBegin+ebufGetDataSize(&appContext->lastResponse);
  515. Err error=ProcessDefinitionResponse(appContext, responseBegin, responseEnd);
  516. Assert(!error);
  517. }
  518. }
  519. #endif
  520. Boolean DisplayPrefFormHandleEvent(EventType * event)
  521. {
  522. int setColor = 0;
  523. ActualTag actTag = actTagWord;
  524. FormType * frm;
  525. ListType * list;
  526. char * listTxt;
  527. char txt[20];
  528. AppContext* appContext;
  529. DisplayElementPrefs *dep;
  530. #ifdef NOAH_PRO
  531. char *tab[10];
  532. #endif
  533. frm = FrmGetActiveForm();
  534. appContext=GetAppContext();
  535. AppPrefs *prefs = &(appContext->prefs);
  536. DisplayPrefs *displayPrefs = &(prefs->displayPrefs);
  537. switch (event->eType)
  538. {
  539. case winDisplayChangedEvent:
  540. DisplPrefFormDisplayChanged(appContext, frm);
  541. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  542. SetPopupLabel(frm, listListStyle, popupListStyle, 2 - displayPrefs->listStyle);
  543. SetPopupLabel(frm, listActTag, popupActTag, actTag);
  544. RedrawFormElements(appContext,actTag,displayPrefs);
  545. RedrawExampleDefinition(appContext);
  546. return true;
  547. case frmOpenEvent:
  548. cbNoSelection(appContext);
  549. InitOldDisplayPrefs(appContext);
  550. CopyParamsFromTo(displayPrefs, (DisplayPrefs*)appContext->ptrOldDisplayPrefs);
  551. FrmDrawForm(FrmGetActiveForm());
  552. actTag = actTagWord;
  553. SetPopupLabel(frm, listListStyle, popupListStyle, 2 - displayPrefs->listStyle);
  554. SetPopupLabel(frm, listActTag, popupActTag, actTag);
  555. RedrawExampleDefinition(appContext);
  556. RedrawFormElements(appContext,actTag,displayPrefs);
  557. #ifdef NOAH_PRO
  558. if(appContext->pronData.isPronInUsedDictionary)
  559. {
  560. list =(ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag));
  561. for(setColor = 0; setColor < 7; setColor++)
  562. tab[setColor] = LstGetSelectionText(list, setColor);
  563. tab[setColor] = "pronunciation";
  564. LstSetListChoices (list, tab , 8);
  565. }
  566. #endif
  567. return true;
  568. case popSelectEvent:
  569. list =(ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, event->data.popSelect.listID));
  570. listTxt = LstGetSelectionText(list, event->data.popSelect.selection);
  571. switch (event->data.popSelect.listID)
  572. {
  573. case listListStyle:
  574. displayPrefs->listStyle = 2 - (LayoutType) event->data.popSelect.selection;
  575. SafeStrNCopy(txt, sizeof(txt), listTxt, -1);
  576. CtlSetLabel((ControlType *)FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,popupListStyle)),txt);
  577. SetDefaultDisplayParam(displayPrefs,false,false);
  578. RedrawExampleDefinition(appContext);
  579. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  580. RedrawFormElements(appContext,actTag,displayPrefs);
  581. break;
  582. case listActTag:
  583. actTag = (ActualTag) event->data.popSelect.selection;
  584. SafeStrNCopy(txt, sizeof(txt), listTxt, -1);
  585. CtlSetLabel((ControlType *)FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,popupActTag)),txt);
  586. RedrawFormElements(appContext,actTag,displayPrefs);
  587. break;
  588. default:
  589. Assert(0);
  590. break;
  591. }
  592. return true;
  593. break;
  594. case ctlSelectEvent:
  595. switch (event->data.ctlSelect.controlID)
  596. {
  597. case popupListStyle:
  598. case popupActTag:
  599. // need to propagate the event down to popus
  600. return false;
  601. break;
  602. case buttonFpos:
  603. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  604. if ( actTagPronunciation == actTag )
  605. {
  606. if(! displayPrefs->fEnablePronunciationSpecialFonts)
  607. displayPrefs->pronunciation.font = FontSelect(displayPrefs->pronunciation.font);
  608. } else {
  609. dep = GetDEPForTag(displayPrefs, actTag);
  610. dep->font = FontSelect(dep->font);
  611. }
  612. RedrawFormElements(appContext,actTag,displayPrefs);
  613. RedrawExampleDefinition(appContext);
  614. break;
  615. case buttonCOLpos:
  616. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  617. RunColorSetFormForTag(displayPrefs, actTag, false);
  618. RedrawFormElements(appContext,actTag,displayPrefs);
  619. RedrawExampleDefinition(appContext);
  620. setColor = 2;
  621. break;
  622. case buttonBGpos:
  623. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  624. RunColorSetFormForTag(displayPrefs, actTag, true);
  625. RedrawFormElements(appContext,actTag,displayPrefs);
  626. RedrawExampleDefinition(appContext);
  627. setColor = 2;
  628. break;
  629. case buttonGlobalBGcol:
  630. displayPrefs->bgCol = RunColorSetForm(displayPrefs->bgCol);
  631. SetAllBackGroundLikeGlobal(displayPrefs, displayPrefs->bgCol);
  632. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  633. RedrawFormElements(appContext,actTag,displayPrefs);
  634. RedrawExampleDefinition(appContext);
  635. setColor = 2;
  636. break;
  637. #ifdef NOAH_PRO
  638. case checkEnablePron:
  639. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  640. if(FrmGetControlValue (frm, FrmGetObjectIndex(frm, checkEnablePron)))
  641. displayPrefs->fEnablePronunciation = true;
  642. else
  643. displayPrefs->fEnablePronunciation = false;
  644. RedrawFormElements(appContext,actTag,displayPrefs);
  645. RedrawExampleDefinition(appContext);
  646. break;
  647. #endif
  648. case buttonDefault:
  649. SetDefaultDisplayParam(displayPrefs,false,false);
  650. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  651. RedrawFormElements(appContext,actTag,displayPrefs);
  652. RedrawExampleDefinition(appContext);
  653. break;
  654. case buttonOk:
  655. #ifdef NOAH_PRO
  656. SavePreferencesNoahPro(appContext);
  657. #endif
  658. #ifdef THESAURUS
  659. SavePreferencesThes(appContext);
  660. #endif
  661. #ifdef I_NOAH
  662. SavePreferencesInoah(appContext);
  663. #endif
  664. bfFreePTR(appContext);
  665. #ifdef I_NOAH
  666. SendEvtWithType(evtReformatLastResponse);
  667. #else
  668. SendEvtWithType(evtNewWordSelected);
  669. #endif
  670. FrmReturnToForm(0);
  671. #ifdef I_NOAH
  672. SendEvtWithType(evtRefresh);
  673. #endif
  674. break;
  675. case buttonCancel:
  676. CopyParamsFromTo((DisplayPrefs*)appContext->ptrOldDisplayPrefs, displayPrefs);
  677. bfFreePTR(appContext);
  678. /*#ifdef I_NOAH
  679. ReformatLastResponse(appContext);
  680. #else
  681. SendNewWordSelected();
  682. #endif*/
  683. FrmReturnToForm(0);
  684. break;
  685. default:
  686. Assert(0);
  687. break;
  688. }
  689. //we need to redraw form when change colors! (realy needed only if colors > 65000)
  690. if(setColor != 0)
  691. {
  692. actTag = (ActualTag)LstGetSelection ((ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listActTag)));
  693. FrmDrawForm(FrmGetActiveForm());
  694. SetPopupLabel(frm, listListStyle, popupListStyle, 2 - displayPrefs->listStyle);
  695. SetPopupLabel(frm, listActTag, popupActTag, actTag);
  696. RedrawFormElements(appContext,actTag,displayPrefs);
  697. RedrawExampleDefinition(appContext);
  698. setColor--;
  699. if(setColor > 0)
  700. setColor--;
  701. }
  702. return true;
  703. default:
  704. break;
  705. }
  706. return false;
  707. }
  708. Err DisplayPrefsFormLoad(AppContext* appContext)
  709. {
  710. Err error=errNone;
  711. FormType* form=FrmInitForm(formDisplayPrefs);
  712. if (!form)
  713. {
  714. error=memErrNotEnoughSpace;
  715. goto OnError;
  716. }
  717. error=DefaultFormInit(appContext, form);
  718. if (!error)
  719. {
  720. FrmSetActiveForm(form);
  721. FrmSetEventHandler(form, DisplayPrefFormHandleEvent);
  722. }
  723. else
  724. FrmDeleteForm(form);
  725. OnError:
  726. return error;
  727. }
  728. // return true if a,b represents a tag
  729. Boolean IsTag(char a, char b)
  730. {
  731. if(a != (char)FORMAT_TAG)
  732. return false;
  733. switch(b)
  734. {
  735. case (char)FORMAT_POS:
  736. case (char)FORMAT_WORD:
  737. case (char)FORMAT_DEFINITION:
  738. case (char)FORMAT_LIST:
  739. case (char)FORMAT_BIG_LIST:
  740. case (char)FORMAT_SYNONYM:
  741. case (char)FORMAT_EXAMPLE:
  742. case (char)FORMAT_PRONUNCIATION:
  743. return true;
  744. default:
  745. return false;
  746. }
  747. }
  748. // return true if a,b represents a tag
  749. // inline version to make it faster!
  750. static inline Boolean IsTagInLine(char a, char b)
  751. {
  752. if(a != (char)FORMAT_TAG)
  753. return false;
  754. switch(b)
  755. {
  756. case (char)FORMAT_POS:
  757. case (char)FORMAT_WORD:
  758. case (char)FORMAT_DEFINITION:
  759. case (char)FORMAT_LIST:
  760. case (char)FORMAT_BIG_LIST:
  761. case (char)FORMAT_SYNONYM:
  762. case (char)FORMAT_EXAMPLE:
  763. case (char)FORMAT_PRONUNCIATION:
  764. return true;
  765. default:
  766. return false;
  767. }
  768. }
  769. /* Remove all tags from buffer*/
  770. void bfStripBufferFromTags(ExtensibleBuffer *buf)
  771. {
  772. int i = 0;
  773. while(i+1 < buf->used)
  774. {
  775. if(IsTagInLine(buf->data[i],buf->data[i+1]))
  776. {
  777. ebufDeleteChar(buf, i);
  778. ebufDeleteChar(buf, i);
  779. }
  780. else
  781. i++;
  782. }
  783. if(buf->data[buf->used] != '\0')
  784. {
  785. ebufAddChar(buf,'\0');
  786. }
  787. }
  788. /*return: r<0 if pos1 < pos2
  789. r=0 if pos1 = pos2
  790. r>0 if pos1 > pos2 */
  791. int CmpPos(char *pos1, char *pos2)
  792. {
  793. int i,len1,len2;
  794. i = 1;
  795. while( !IsTagInLine(pos1[i],pos1[i+1]) && pos1[i+1]!='\0')
  796. i++;
  797. len1 = i;
  798. i = 1;
  799. while( !IsTagInLine(pos2[i],pos2[i+1]) && pos2[i+1]!='\0')
  800. i++;
  801. len2 = i;
  802. i = 0;
  803. while(pos1[i] == pos2[i] && i < len1 && i < len2)
  804. i++;
  805. //end of pos1 or end of pos2?
  806. if(i < len1 && i < len2)
  807. {
  808. if(pos1[i] < pos2[i])
  809. return (-1);
  810. if(pos1[i] > pos2[i])
  811. return (1);
  812. }
  813. return(len1 - len2);
  814. }
  815. /* Xchg AbcdEef -> EefAbcd return updated offset2 */
  816. /* |off1 |off2 |end2 */
  817. /* before: abCdefghijKlmnopqrstuwXyz */
  818. /* after: abKlmnopqrstuwCdefghijXyz */
  819. /* |off2 - return */
  820. /* //old version - in place
  821. int XchgInBuffer(char *txt, int offset1, int offset2, int end2)
  822. {
  823. int i;
  824. char z;
  825. char *txt1;
  826. char *txt2;
  827. //reverse all
  828. txt1 = txt + offset1;
  829. txt2 = txt + end2 - 1;
  830. for(i = 0; i < (end2-offset1)/2 ; i++)
  831. {
  832. z = txt1[0];
  833. txt1[0] = txt2[0];
  834. txt2[0] = z;
  835. txt1++;
  836. txt2--;
  837. }
  838. //mirror offset2
  839. i = offset2 - offset1;
  840. offset2 = end2 - i;
  841. //reverse 1st
  842. txt1 = txt + offset1;
  843. txt2 = txt + offset2 - 1;
  844. for(i = 0; i < (offset2-offset1)/2 ; i++)
  845. {
  846. z = txt1[0];
  847. txt1[0] = txt2[0];
  848. txt2[0] = z;
  849. txt1++;
  850. txt2--;
  851. }
  852. //reverse 2nd
  853. txt1 = txt + offset2;
  854. txt2 = txt + end2 - 1;
  855. for(i = 0; i < (end2-offset2)/2 ; i++)
  856. {
  857. z = txt1[0];
  858. txt1[0] = txt2[0];
  859. txt2[0] = z;
  860. txt1++;
  861. txt2--;
  862. }
  863. return offset2;
  864. }
  865. */
  866. //faster but with malloc!
  867. int XchgInBuffer(char *txt, int offset1, int offset2, int end2)
  868. {
  869. char *txt1;
  870. int i = end2 - (offset2 - offset1);
  871. txt1 = (char *) new_malloc(offset2 - offset1 + 1);
  872. MemMove(txt1,&txt[offset1],offset2 - offset1);
  873. MemMove(&txt[offset1],&txt[offset2],end2-offset2);
  874. MemMove(&txt[i],txt1,offset2 - offset1);
  875. new_free(txt1);
  876. return i;
  877. }
  878. /* Sort buffer by text after 'FORMAT_TAG''FORMAT_POS'
  879. sort method - shake sort */
  880. Boolean ShakeSortExtBuf(ExtensibleBuffer *buf)
  881. {
  882. int i, n;
  883. int L, r, k, j; //to shake sort
  884. int *array;
  885. char *txt;
  886. int len;
  887. Boolean ret = false;
  888. txt = ebufGetDataPointer(buf);
  889. len = ebufGetDataSize(buf);
  890. //if buffer without '\0' at the end
  891. if(txt[len-1] != '\0')
  892. len++;
  893. //get number of elements (n)
  894. n = 0;
  895. for(i = 0; i < len-1; i++)
  896. if(txt[i] == (char)FORMAT_TAG && txt[i+1] == (char)FORMAT_POS)
  897. n++;
  898. if(n < 2)
  899. return ret;
  900. //make array of offsets
  901. array = (int *) new_malloc(n*sizeof(int));
  902. if (!array)
  903. return ret;
  904. n = 0;
  905. for(i = 0; i < len-1; i++)
  906. if(txt[i] == (char)FORMAT_TAG && txt[i+1] == (char)FORMAT_POS)
  907. {
  908. array[n] = i;
  909. n++;
  910. }
  911. //sort array!
  912. L = 1;
  913. r = n-1;
  914. k = n-1;
  915. do
  916. {
  917. for(j = r; j >= L; j--)
  918. if(CmpPos(&txt[array[j-1]], &txt[array[j]]) > 0)
  919. {
  920. if(j < n-1)
  921. i = array[j+1];
  922. else
  923. i = len-1;
  924. //reverse in buffer
  925. array[j] = XchgInBuffer(txt, array[j-1], array[j], i);
  926. ret = true;
  927. k=j;
  928. }
  929. L = k + 1;
  930. for(j = L; j <= r; j++)
  931. if(CmpPos(&txt[array[j-1]], &txt[array[j]]) > 0)
  932. {
  933. if(j < n-1)
  934. i = array[j+1];
  935. else
  936. i = len-1;
  937. //reverse in buffer
  938. array[j] = XchgInBuffer(txt, array[j-1], array[j], i);
  939. ret = true;
  940. k = j;
  941. }
  942. r = k - 1;
  943. }while(L <= r);
  944. //free array!!!!!!!!!
  945. new_free((int *)array);
  946. return ret;
  947. }
  948. //delete all text until tag or EOB is reached
  949. static void ebufDeletePos(ExtensibleBuffer *buf, int pos)
  950. {
  951. while( !IsTagInLine(buf->data[pos],buf->data[pos+1]) && pos < buf->used)
  952. ebufDeleteChar(buf, pos);
  953. }
  954. //word is marked as synonym! and synonyms are marked as words!
  955. //we need to change it... and sort synonyms after definition and examples
  956. //also add "synonyms:" text (but not in thes.).
  957. static void XchgWordsWithSynonyms(ExtensibleBuffer *buf)
  958. {
  959. int i, j, k;
  960. int used;
  961. char *data;
  962. char *dataCurr;
  963. char *dataEnd;
  964. i = 0;
  965. if(buf->data[1] == (char)FORMAT_SYNONYM /*|| buf->data[1] == (char)FORMAT_WORD*/)
  966. {
  967. buf->data[1] = FORMAT_WORD;
  968. i = 2;
  969. }
  970. else
  971. return; //we dont have "word" at the begining. This is not Format1 or Format2...
  972. used = buf->used;
  973. data = buf->data;
  974. while(i < used)
  975. {
  976. //set i on word tag
  977. while(i < used && !(data[i]==(char)FORMAT_TAG && data[i+1]==(char)FORMAT_WORD))
  978. i++;
  979. if(i < used)
  980. {
  981. ebufReplaceChar(buf, FORMAT_SYNONYM, i + 1);
  982. #ifndef THESAURUS //why? think :)
  983. ebufInsertStringOnPos(buf, "Synonyms: ", i + 2);
  984. used = buf->used;
  985. data = buf->data;
  986. #endif
  987. }
  988. //set j on next tag
  989. j = i+2;
  990. dataCurr = data+j;
  991. dataEnd = data+used;
  992. while(dataCurr < dataEnd && !IsTagInLine(dataCurr[0],dataCurr[1]))
  993. dataCurr++;
  994. j = dataCurr-data;
  995. //some problems with unformated data
  996. if(!(j+1 < used))
  997. return;
  998. k = j;
  999. //set k on pos //but not if its reached
  1000. if(data[j+1] != (char)FORMAT_POS)
  1001. {
  1002. k = j+2;
  1003. if(!(k+1 < used))
  1004. return;
  1005. }
  1006. dataCurr = data+k;
  1007. while(dataCurr < dataEnd && dataCurr[0]!='\0' && !(dataCurr[0]==(char)FORMAT_TAG && dataCurr[1]==(char)FORMAT_POS))
  1008. dataCurr++;
  1009. k = dataCurr - data;
  1010. //(i,j)(j,k) ---> (j,k)(i,j)
  1011. if(j < used && j!=k)
  1012. XchgInBuffer(data, i, j, k);
  1013. i = k+2;
  1014. }
  1015. }
  1016. //return true if format wants leading "word" before first "pos"
  1017. Boolean FormatWantsWord(AppContext* appContext)
  1018. {
  1019. switch(appContext->prefs.displayPrefs.listStyle)
  1020. {
  1021. case 1: //no break!
  1022. case 2:
  1023. return true;
  1024. case 0: //0 is Format 3 mode (the old one)
  1025. default:
  1026. return false;
  1027. }
  1028. }
  1029. //format 1
  1030. void Format1OnSortedBuf(int format_id, ExtensibleBuffer *buf)
  1031. {
  1032. int i, j;
  1033. int first_pos;
  1034. int number;
  1035. char str_number[10];
  1036. if(format_id != 1) //as it was without formatting
  1037. return;
  1038. XchgWordsWithSynonyms(buf);
  1039. i = 0;
  1040. while((buf->data[i] != (char)FORMAT_TAG || buf->data[i+1] != (char)FORMAT_POS) && i+1 < buf->used)
  1041. i++;
  1042. first_pos = i + 2;
  1043. if(first_pos > buf->used)
  1044. return;
  1045. i = first_pos;
  1046. number = 1;
  1047. while( i+1 < buf->used )
  1048. {
  1049. if(buf->data[i] == (char)FORMAT_TAG && buf->data[i+1] == (char)FORMAT_POS)
  1050. {
  1051. i += 2;
  1052. if(CmpPos(&buf->data[i], &buf->data[first_pos])==0)
  1053. {
  1054. //add numbers to buff (2. 3. 4. etc)
  1055. ebufDeletePos(buf, i);
  1056. number++;
  1057. StrPrintF(str_number,"%d: \0",number);
  1058. ebufReplaceChar(buf, FORMAT_LIST, i - 1);
  1059. j = 0;
  1060. while(str_number[j] != '\0')
  1061. {
  1062. ebufInsertChar(buf, str_number[j], i + j);
  1063. j++;
  1064. }
  1065. i += j-1;
  1066. }
  1067. else
  1068. {
  1069. //put 1. in first_pos (if its not a single pos type)
  1070. if(buf->data[first_pos] == (char)149)
  1071. {
  1072. ebufDeleteChar(buf, first_pos);
  1073. ebufDeleteChar(buf, first_pos);
  1074. i-=2;
  1075. }
  1076. j = 0;
  1077. while( !IsTagInLine(buf->data[first_pos+j],buf->data[first_pos+j+1]) )
  1078. {
  1079. if(buf->data[first_pos+j] == ')' || buf->data[first_pos+j]== '(')
  1080. {
  1081. ebufDeleteChar(buf, first_pos+j);
  1082. j--;
  1083. i--;
  1084. }
  1085. j++;
  1086. }
  1087. j = first_pos + j;
  1088. ebufInsertChar(buf, FORMAT_TAG, j);
  1089. ebufInsertChar(buf, FORMAT_BIG_LIST, j + 1);
  1090. if(number > 1)
  1091. {
  1092. ebufInsertChar(buf, '1', j + 2);
  1093. j++;
  1094. i++;
  1095. }
  1096. ebufInsertChar(buf, ':', j + 2);
  1097. ebufInsertChar(buf, ' ', j + 3);
  1098. i += 4;
  1099. number = 1;
  1100. first_pos = i;
  1101. i++;
  1102. }
  1103. }
  1104. else
  1105. i++;
  1106. }
  1107. //put 1. in first_pos
  1108. if(buf->data[first_pos] == (char)149)
  1109. {
  1110. ebufDeleteChar(buf, first_pos);
  1111. ebufDeleteChar(buf, first_pos);
  1112. }
  1113. j = 0;
  1114. while( !IsTagInLine(buf->data[first_pos+j],buf->data[first_pos+j+1]) )
  1115. {
  1116. if(buf->data[first_pos+j] == ')' || buf->data[first_pos+j]== '(')
  1117. {
  1118. ebufDeleteChar(buf, first_pos+j);
  1119. j--;
  1120. }
  1121. j++;
  1122. }
  1123. j = first_pos + j;
  1124. ebufInsertChar(buf, FORMAT_TAG, j);
  1125. ebufInsertChar(buf, FORMAT_BIG_LIST, j + 1);
  1126. if(number > 1)
  1127. ebufInsertChar(buf, '1', (j++) + 2);
  1128. ebufInsertChar(buf, ':', j + 2);
  1129. ebufInsertChar(buf, ' ', j + 3);
  1130. }
  1131. //format 2
  1132. void Format2OnSortedBuf(int format_id, ExtensibleBuffer *buf)
  1133. {
  1134. int i, j;
  1135. int first_pos;
  1136. int number;
  1137. int bignumber;
  1138. char str_number[10];
  1139. char *roman[10];// = {""," I"," II"," III"," IV"," V"," VI"," VII"," VIII"," IX"};
  1140. char *data;
  1141. char *dataTest;
  1142. if(format_id != 2) //as it was without formatting
  1143. return;
  1144. //initialize data (resident mode)
  1145. roman[0] = " ";
  1146. roman[1] = " I";
  1147. roman[2] = " II";
  1148. roman[3] = " III";
  1149. roman[4] = " IV";
  1150. roman[5] = " V";
  1151. roman[6] = " VI";
  1152. roman[7] = " VII";
  1153. roman[8] = " VIII";
  1154. roman[9] = " IX";
  1155. XchgWordsWithSynonyms(buf);
  1156. i = 0;
  1157. while((buf->data[i] != (char)FORMAT_TAG || buf->data[i+1] != (char)FORMAT_POS) && i+1 < buf->used)
  1158. i++;
  1159. first_pos = i + 2;
  1160. if(first_pos > buf->used)
  1161. return;
  1162. i = first_pos;
  1163. number = 1;
  1164. bignumber = 1;
  1165. data = buf->data;
  1166. data += i;
  1167. dataTest = (buf->data) + (buf->used) - 1;
  1168. while(data < dataTest)
  1169. {
  1170. if(data[0] == (char)FORMAT_TAG)
  1171. {
  1172. if(data[1] == (char)FORMAT_POS)
  1173. {
  1174. i = buf->used - (dataTest+1-data);
  1175. i += 2;
  1176. if(CmpPos(&buf->data[i], &buf->data[first_pos])==0)
  1177. {
  1178. //add numbers to buff (2. 3. 4. etc)
  1179. ebufDeletePos(buf, i);
  1180. number++;
  1181. StrPrintF(str_number,"%d) \0",number);
  1182. j = 0;
  1183. while(str_number[j] != '\0')
  1184. {
  1185. ebufInsertChar(buf, str_number[j], i + j);
  1186. j++;
  1187. }
  1188. ebufReplaceChar(buf, FORMAT_LIST, i - 1);
  1189. i += j-1;
  1190. }
  1191. else
  1192. {
  1193. //put 1) in first_pos (if its not a single pos type)
  1194. if(buf->data[first_pos] == (char)149)
  1195. {
  1196. ebufDeleteChar(buf, first_pos);
  1197. ebufDeleteChar(buf, first_pos);
  1198. i-=2;
  1199. }
  1200. j = first_pos;
  1201. while( !IsTagInLine(buf->data[j],buf->data[j+1]) )
  1202. {
  1203. if(buf->data[j] == ')' || buf->data[j]== '(')
  1204. {
  1205. ebufDeleteChar(buf, j);
  1206. j--;
  1207. i--;
  1208. }
  1209. j++;
  1210. }
  1211. ebufInsertChar(buf, '\n', j);
  1212. j++;
  1213. i++;
  1214. if(number > 1)
  1215. {
  1216. ebufInsertChar(buf, FORMAT_TAG, j);
  1217. ebufInsertChar(buf, FORMAT_LIST , j + 1);
  1218. ebufInsertChar(buf, '1', j + 2);
  1219. ebufInsertChar(buf, ')', j + 3);
  1220. ebufInsertChar(buf, ' ', j + 4);
  1221. i += 5;
  1222. }
  1223. StrPrintF(str_number,"%c%c%s \0", FORMAT_TAG, FORMAT_BIG_LIST, roman[bignumber%10]);
  1224. j = 0;
  1225. while(str_number[j] != '\0')
  1226. {
  1227. ebufInsertChar(buf, str_number[j], first_pos - 2 + j);
  1228. j++;
  1229. }
  1230. i += j-1;
  1231. i++;
  1232. number = 1;
  1233. first_pos = i;
  1234. i++;
  1235. bignumber++;
  1236. }
  1237. data = buf->data + i;
  1238. dataTest = (buf->data) + (buf->used) - 1;
  1239. }
  1240. else
  1241. data++;
  1242. }
  1243. else
  1244. data++;
  1245. }
  1246. //put 1) in first_pos (if its not a single pos type)
  1247. if(buf->data[first_pos] == (char)149)
  1248. {
  1249. ebufDeleteChar(buf, first_pos);
  1250. ebufDeleteChar(buf, first_pos);
  1251. }
  1252. j = first_pos;
  1253. while( !IsTagInLine(buf->data[j],buf->data[j+1]) )
  1254. {
  1255. if(buf->data[j] == ')' || buf->data[j]== '(')
  1256. {
  1257. ebufDeleteChar(buf, j);
  1258. j--;
  1259. }
  1260. j++;
  1261. }
  1262. //goto end of pos
  1263. j = first_pos + 1;
  1264. while( !IsTagInLine(buf->data[j], buf->data[j+1]) )
  1265. j++;
  1266. ebufInsertChar(buf, '\n', j);
  1267. j++;
  1268. if(number > 1)
  1269. {
  1270. ebufInsertChar(buf, FORMAT_TAG, j);
  1271. ebufInsertChar(buf, FORMAT_LIST , j + 1);
  1272. ebufInsertChar(buf, '1', j + 2);
  1273. ebufInsertChar(buf, ')', j + 3);
  1274. ebufInsertChar(buf, ' ', j + 4);
  1275. }
  1276. if(bignumber > 1)
  1277. {
  1278. StrPrintF(str_number,"%c%c%s \0", FORMAT_TAG, FORMAT_BIG_LIST, roman[bignumber%10]);
  1279. j = 0;
  1280. while(str_number[j] != '\0')
  1281. {
  1282. ebufInsertChar(buf, str_number[j], first_pos - 2 + j);
  1283. j++;
  1284. }
  1285. }
  1286. }
  1287. //from "extensible_buffer.c" cut lines to smaller ones
  1288. int ebufWrapLine(ExtensibleBuffer *buf, int line_start, int line_len, int spaces_at_start, AppContext* appContext)
  1289. {
  1290. char * txt;
  1291. Int16 string_dx;
  1292. Int16 pos_dx;
  1293. Int16 pos_dx2;
  1294. Int16 string_len;
  1295. Int16 pos_len;
  1296. Int16 tagOffset;
  1297. Boolean fits;
  1298. Boolean found;
  1299. int pos, breakLine;
  1300. int i,j;
  1301. // Int16 displayDx=152;
  1302. Int16 displayDx = GetAppContext()->screenWidth-8;
  1303. txt = buf->data;
  1304. if (NULL == txt)
  1305. return 0;
  1306. string_dx = displayDx;
  1307. pos_dx = displayDx;
  1308. string_len = line_len;
  1309. txt += line_start;
  1310. tagOffset = 0;
  1311. if( IsTagInLine(txt[0],txt[1]) )
  1312. {
  1313. SetOnlyFont(txt[1],&appContext->prefs.displayPrefs); //we dont reset it to default before return!
  1314. string_len -= 2;
  1315. tagOffset += 2;
  1316. }
  1317. //we need to put as many as we can in one line
  1318. fits = false;
  1319. //is there more than one tag in his line???
  1320. j = 1;
  1321. while(j < string_len)
  1322. if(txt[j] != (char)FORMAT_TAG)
  1323. j++;
  1324. else
  1325. if(IsTagInLine(txt[j],txt[j+1]))
  1326. break;
  1327. else
  1328. j++;
  1329. //more than one tag in line!!!
  1330. if(j < string_len)
  1331. {
  1332. pos_dx = 0;
  1333. found = false;
  1334. while(!found)
  1335. {
  1336. pos_len = j - tagOffset + 1;
  1337. pos_dx2 = pos_dx;
  1338. pos_dx += FntCharsWidth(&txt[tagOffset], pos_len);
  1339. if(pos_dx >= string_dx)
  1340. {
  1341. pos_dx2 = string_dx - pos_dx2;
  1342. FntCharsInWidth(&txt[tagOffset], &pos_dx2, &pos_len, &fits);
  1343. pos = pos_len + tagOffset - 1;
  1344. breakLine = pos_len + tagOffset - 1;
  1345. found = true;
  1346. fits = false;
  1347. }
  1348. else
  1349. {
  1350. if( IsTagInLine(txt[j],txt[j+1]) )
  1351. {
  1352. SetOnlyFont(txt[j+1],&appContext->prefs.displayPrefs);
  1353. tagOffset = j+2;
  1354. j += 2;
  1355. while(j < string_len && !IsTagInLine(txt[j],txt[j+1]))
  1356. j++;
  1357. }
  1358. else
  1359. {
  1360. //j = string_len
  1361. //and it fits perfect
  1362. return string_len-1;
  1363. }
  1364. }
  1365. };//end while
  1366. }
  1367. else
  1368. {
  1369. //only one(at the begining) or zero tags in line
  1370. FntCharsInWidth(&txt[tagOffset], &string_dx, &string_len, &fits);
  1371. if (fits)
  1372. return string_len-1;
  1373. pos = string_len - 1 + tagOffset;
  1374. breakLine = string_len - 1 + tagOffset;
  1375. }
  1376. /* doesn't fit, so we have to cut it */
  1377. /* find last space or some other charactar that is save
  1378. to wrap around */
  1379. while (pos > 0)
  1380. {
  1381. switch (txt[pos])
  1382. {
  1383. case ' ':
  1384. txt[pos] = '\n';
  1385. for (i = 0; i < spaces_at_start; i++)
  1386. {
  1387. ebufInsertChar(buf, ' ', line_start + pos + i + 1);
  1388. }
  1389. return pos-1;
  1390. case ';':
  1391. case ',':
  1392. ebufInsertChar(buf, '\n', line_start + pos + 1);
  1393. for (i = 0; i < spaces_at_start; i++)
  1394. {
  1395. ebufInsertChar(buf, ' ', line_start + pos + i + 2);
  1396. }
  1397. return pos-1;
  1398. }
  1399. --pos;
  1400. }
  1401. /* didn't find so just brutally insert a newline */
  1402. ebufInsertChar(buf, '\n', line_start + breakLine);
  1403. return breakLine-1;
  1404. }
  1405. //from "common.c"
  1406. /* display maxLines from DisplayInfo, starting with first line,
  1407. starting at x,y coordinates */
  1408. void DrawDisplayInfo(DisplayInfo * di, int firstLine, Int16 x, Int16 y,
  1409. int maxLines)
  1410. {
  1411. int totalLines;
  1412. int i,j;
  1413. char *line;
  1414. Int16 curY;
  1415. Int16 curX;
  1416. Int16 fontDY;
  1417. FontID prev_font;
  1418. int tagOffset;
  1419. AppContext *appContext = GetAppContext();
  1420. Assert(firstLine >= 0);
  1421. Assert(maxLines > 0);
  1422. curY = y;
  1423. prev_font = FntGetFont();
  1424. totalLines = diGetLinesCount(di) - firstLine;
  1425. if (totalLines > maxLines)
  1426. {
  1427. totalLines = maxLines;
  1428. }
  1429. //find and set
  1430. //previous TAG
  1431. if(firstLine > 0)
  1432. {
  1433. line = diGetLine(di, firstLine);
  1434. if( !IsTagInLine(line[0],line[1]) ) //no tag at the begining
  1435. {
  1436. i = firstLine - 1;
  1437. while(i >= 0)
  1438. {
  1439. line = diGetLine(di, i);
  1440. for(j = strlen(

Large files files are truncated, but you can click here to view the full file