Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

595 lines
15 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* Fontdlg.c -- WRITE font dialog routines */
  5. #define NOVIRTUALKEYCODES
  6. #define NOWINSTYLES
  7. #define NOSYSMETRICS
  8. #define NOMENUS
  9. #define NOICON
  10. #define NOKEYSTATE
  11. #define NOSYSCOMMANDS
  12. #define NORASTEROPS
  13. #define NOSHOWWINDOW
  14. #define NOATOM
  15. #define NOBITMAP
  16. #define NOBRUSH
  17. #define NOCLIPBOARD
  18. #define NOCOLOR
  19. #define NOCREATESTRUCT
  20. #define NODRAWTEXT
  21. #define NOMEMMGR
  22. #define NOMENUS
  23. #define NOMETAFILE
  24. #define NOMINMAX
  25. #define NOMSG
  26. #define NOOPENFILE
  27. #define NOPEN
  28. #define NOPOINT
  29. #define NOREGION
  30. #define NOSCROLL
  31. #define NOSOUND
  32. #define NOWH
  33. #define NOWINOFFSETS
  34. #define NOWNDCLASS
  35. #define NOCOMM
  36. #include <windows.h>
  37. #include "mw.h"
  38. #ifndef JAPAN //T-HIROYN Win3.1
  39. #define NOUAC
  40. #endif
  41. #include "cmddefs.h"
  42. #include "dlgdefs.h"
  43. #include "propdefs.h"
  44. #include "fontdefs.h"
  45. #include "prmdefs.h"
  46. #include "str.h"
  47. #include "docdefs.h"
  48. #include <commdlg.h>
  49. #ifdef JAPAN //T-HIROYN Win3.1 and added 02 Jun. 1992 by Hiraisi
  50. #include <dlgs.h>
  51. #include <ctype.h>
  52. #include "kanji.h"
  53. BOOL FAR PASCAL _export DeleteFacename( HWND , UINT , WPARAM , LPARAM );
  54. static BOOL NEAR PASCAL KanjiCheckAddSprm(HWND, int, int);
  55. extern int ferror; //01/21/93
  56. #elif defined(KOREA) // jinwoo : 10/14/92 : remove @Facename
  57. #include <dlgs.h>
  58. BOOL FAR PASCAL _export DeleteFacename( HWND , UINT , WPARAM , LPARAM );
  59. #endif
  60. extern HDC vhDCPrinter;
  61. extern struct DOD (**hpdocdod)[];
  62. extern HANDLE hMmwModInstance;
  63. extern HANDLE hParentWw;
  64. extern int vfSeeSel;
  65. extern int docCur;
  66. extern HWND vhWndMsgBoxParent;
  67. extern int vfCursorVisible;
  68. extern HCURSOR vhcArrow;
  69. extern int iszSizeEnum;
  70. extern int iszSizeEnumMac;
  71. extern int iszSizeEnumMax;
  72. extern int iffnEnum;
  73. extern int vfFontEnumFail;
  74. extern struct FFNTB **hffntbEnum;
  75. BOOL NEAR FValidateEnumFfid(struct FFN *);
  76. int FAR PASCAL NewFont(HWND hwnd)
  77. {
  78. TSV rgtsv[itsvchMax]; /* gets attributes and gray flags from CHP */
  79. int ftc;
  80. int fSetUndo;
  81. CHAR rgb[2];
  82. CHOOSEFONT cf;
  83. LOGFONT lf;
  84. HDC hdc;
  85. #if defined(JAPAN) || defined(KOREA) // added 02 Jun. 1992 by Hiraisi : jinwoo 11/10/92
  86. FARPROC lpfnDeleteFacename;
  87. int Result;
  88. #endif
  89. if (!vhDCPrinter)
  90. return FALSE;
  91. GetRgtsvChpSel(rgtsv);
  92. bltbc(&lf, 0, sizeof(LOGFONT));
  93. bltbc(&cf, 0, sizeof(CHOOSEFONT));
  94. cf.lStructSize = sizeof(cf);
  95. cf.hwndOwner = hwnd;
  96. cf.lpLogFont = &lf;
  97. cf.hDC = vhDCPrinter;
  98. cf.nSizeMin = 4;
  99. cf.nSizeMax = 127;
  100. #ifdef JAPAN //#3902 T-HIROYN
  101. cf.Flags = CF_PRINTERFONTS | CF_INITTOLOGFONTSTRUCT | CF_LIMITSIZE;
  102. #elif defined(KOREA) // MSCH bklee 01/26/95
  103. cf.Flags = CF_NOSIMULATIONS| CF_PRINTERFONTS /*| CF_ANSIONLY*/ | CF_INITTOLOGFONTSTRUCT | CF_LIMITSIZE;
  104. #else
  105. cf.Flags = CF_NOSIMULATIONS| CF_PRINTERFONTS | CF_INITTOLOGFONTSTRUCT | CF_LIMITSIZE;
  106. #endif
  107. #if defined(JAPAN) || defined(KOREA) // added 02 Jun. 1992 by Hiraisi : jinwoo 11/10/92
  108. cf.Flags |= CF_ENABLEHOOK;
  109. lpfnDeleteFacename = MakeProcInstance( DeleteFacename, hMmwModInstance );
  110. cf.lpfnHook = (FARPROC)lpfnDeleteFacename;
  111. #endif
  112. // check for multiple sizes selected
  113. if (rgtsv[itsvSize].fGray) {
  114. cf.Flags |= CF_NOSIZESEL;
  115. } else {
  116. hdc = GetDC(NULL);
  117. lf.lfHeight = -MulDiv(rgtsv[itsvSize].wTsv / 2, GetDeviceCaps(hdc, LOGPIXELSY), 72);
  118. ReleaseDC(NULL, hdc);
  119. }
  120. // check for multiple faces selected
  121. if (rgtsv[itsvFfn].fGray) {
  122. cf.Flags |= CF_NOFACESEL;
  123. lf.lfFaceName[0] = 0;
  124. } else {
  125. struct FFN **hffn;
  126. /* then, font name */
  127. /* note that the value stored in rgtsv[itsvFfn].wTsv
  128. is the font name handle, rather than the ftc */
  129. hffn = (struct FFN **)rgtsv[itsvFfn].wTsv;
  130. lstrcpy(lf.lfFaceName, (*hffn)->szFfn);
  131. }
  132. // check for multiple styles selected
  133. if (rgtsv[itsvBold].fGray || rgtsv[itsvItalic].fGray) {
  134. cf.Flags |= CF_NOSTYLESEL;
  135. } else {
  136. lf.lfWeight = rgtsv[itsvBold].wTsv ? FW_BOLD : FW_NORMAL;
  137. lf.lfItalic = rgtsv[itsvItalic].wTsv;
  138. }
  139. #if defined(JAPAN) || defined(KOREA) // added 02 Jun. 1992 by Hiraisi : jinwoo 11/10/92
  140. Result = ChooseFont(&cf);
  141. FreeProcInstance( lpfnDeleteFacename );
  142. if (!Result)
  143. return FALSE;
  144. #else
  145. if (!ChooseFont(&cf))
  146. return FALSE;
  147. #endif // JAPAN
  148. fSetUndo = TRUE;
  149. if (!(cf.Flags & CF_NOFACESEL))
  150. {
  151. CHAR rgbFfn[ibFfnMax];
  152. struct FFN *pffn = (struct FFN *)rgbFfn;
  153. lstrcpy(pffn->szFfn, lf.lfFaceName);
  154. pffn->ffid = lf.lfPitchAndFamily & grpbitFamily;
  155. pffn->chs = lf.lfCharSet;
  156. FValidateEnumFfid(pffn);
  157. ftc = FtcChkDocFfn(docCur, pffn);
  158. if (ftc != ftcNil) {
  159. #ifdef JAPAN //T-HIROYN Win3.1
  160. if ( pffn->chs == NATIVE_CHARSET ||
  161. FALSE == KanjiCheckAddSprm(hwnd, ftc, fSetUndo) ) {
  162. rgb[0] = sprmCFtc;
  163. rgb[1] = ftc;
  164. AddOneSprm(rgb, fSetUndo);
  165. }
  166. fSetUndo = FALSE;
  167. if(ferror) //01/21/93
  168. return TRUE;
  169. #else
  170. rgb[0] = sprmCFtc;
  171. rgb[1] = ftc;
  172. AddOneSprm(rgb, fSetUndo);
  173. #ifdef KKBUGFIX
  174. // when font name was changed we can't undo
  175. fSetUndo = FALSE;
  176. #endif
  177. #endif
  178. }
  179. }
  180. if (!(cf.Flags & CF_NOSIZESEL)) {
  181. /* we got a value */
  182. rgb[0] = sprmCHps;
  183. rgb[1] = cf.iPointSize / 10 * 2; /* KLUDGE alert */
  184. AddOneSprm(rgb, fSetUndo);
  185. fSetUndo = FALSE;
  186. }
  187. if (!(cf.Flags & CF_NOSTYLESEL)) {
  188. #ifdef KKBUGFIX //T-HIROYN Win3.1
  189. // when font name was changed we can't undo
  190. ApplyCLooksUndo(sprmCBold, lf.lfWeight > FW_NORMAL, fSetUndo);
  191. fSetUndo = FALSE;
  192. ApplyCLooksUndo(sprmCItalic, lf.lfItalic ? 1 : 0, fSetUndo);
  193. #else
  194. ApplyCLooks(0, sprmCBold, lf.lfWeight > FW_NORMAL);
  195. ApplyCLooks(0, sprmCItalic, lf.lfItalic ? 1 : 0);
  196. #endif
  197. }
  198. return TRUE;
  199. }
  200. BOOL NEAR FValidateEnumFfid(pffn)
  201. /* if the described ffn is in the enumeration table, then make sure we have
  202. a good family number for it */
  203. struct FFN *pffn;
  204. {
  205. int ftc;
  206. struct FFN *pffnAlready;
  207. ftc = FtcScanFfn(hffntbEnum, pffn);
  208. if (ftc != ftcNil)
  209. {
  210. pffnAlready = *((*hffntbEnum)->mpftchffn[ftc]);
  211. #ifdef JAPAN
  212. // Few fonts would be enumnrated with FF_DONTCARE in JAPAN
  213. // we won't check ffid here.
  214. #else
  215. if (pffnAlready->ffid != FF_DONTCARE)
  216. #endif
  217. {
  218. pffn->ffid = pffnAlready->ffid;
  219. #ifdef NEWFONTENUM
  220. pffn->chs = pffnAlready->chs;
  221. #endif
  222. return(TRUE);
  223. }
  224. }
  225. return(FALSE);
  226. }
  227. #ifdef JAPAN //T-HIROYN Win3.1
  228. /* When you want to change font name,
  229. if include japanese string in select string
  230. then don't change only japanese string
  231. but change alpha string
  232. */
  233. extern CHAR szAppName[];
  234. extern struct SEL selCur;
  235. extern struct CHP vchpFetch;
  236. extern int vcchFetch;
  237. extern int vccpFetch;
  238. extern CHAR *vpchFetch;
  239. extern typeCP vcpFetch;
  240. BOOL FontChangeDBCS = FALSE; //01/21/93
  241. static BOOL NEAR PASCAL KanjiCheckAddSprm(hwnd, alphaftc, fSetUndo)
  242. HWND hwnd;
  243. int alphaftc; //Not KANJI_CHARSET
  244. int fSetUndo;
  245. {
  246. typeCP CpLimNoSpaces(typeCP, typeCP);
  247. static BOOL NEAR KanjiCheckSelect();
  248. static BOOL NEAR PASCAL GetSelCur(typeCP *, typeCP *, typeCP);
  249. CHAR rgb[2];
  250. struct SEL selSave;
  251. typeCP cpLim, cpFirst, dcp, cpSt, cpEnd;
  252. if (selCur.cpFirst == selCur.cpLim)
  253. return(FALSE);
  254. /* include japanese string ? */
  255. if( KanjiCheckSelect() ) { // Yes
  256. char szMsg[cchMaxSz];
  257. PchFillPchId( szMsg, IDPMTNotKanjiFont, sizeof(szMsg) );
  258. MessageBox(hwnd, (LPSTR)szMsg, (LPSTR)szAppName,
  259. MB_OK | MB_ICONEXCLAMATION);
  260. }
  261. else
  262. return(FALSE);
  263. selSave = selCur;
  264. cpLim = CpLimNoSpaces(selCur.cpFirst, selCur.cpLim);
  265. cpFirst = selCur.cpFirst;
  266. dcp = cpLim - cpFirst;
  267. if (fSetUndo) {
  268. SetUndo(uacReplNS, docCur, cpFirst, dcp, docNil, cpNil, dcp, 0);
  269. fSetUndo = FALSE;
  270. }
  271. cpEnd = cpFirst;
  272. FontChangeDBCS = TRUE; //01/21/93
  273. while(TRUE) {
  274. cpSt = cpEnd;
  275. if( FALSE == GetSelCur(&cpSt, &cpEnd, cpLim))
  276. break;
  277. rgb[0] = sprmCFtc;
  278. rgb[1] = alphaftc;
  279. selCur.cpFirst = cpSt;
  280. selCur.cpLim = cpEnd;
  281. AddOneSprm(rgb, fSetUndo);
  282. if (ferror) //01/21/93
  283. break;
  284. }
  285. FontChangeDBCS = FALSE; //01/21/93
  286. if(ferror) { //01/21/93
  287. vfSeeSel = TRUE;
  288. selCur.cpFirst = selCur.cpLim = cpSt;
  289. } else {
  290. selCur = selSave;
  291. }
  292. return(TRUE);
  293. }
  294. static BOOL NEAR PASCAL GetSelCur(cpSt,cpEnd,cpLim)
  295. typeCP *cpSt, *cpEnd, cpLim;
  296. {
  297. static BOOL NEAR PASCAL GetSelCurStart(typeCP *, typeCP);
  298. static void NEAR PASCAL GetSelCurEnd(typeCP *,typeCP *, typeCP);
  299. if(FALSE == GetSelCurStart(cpSt,cpLim))
  300. return(FALSE);
  301. GetSelCurEnd(cpSt,cpEnd,cpLim);
  302. return(TRUE);
  303. }
  304. static BOOL NEAR PASCAL GetSelCurStart(cpSt,cpLim)
  305. typeCP *cpSt, cpLim;
  306. {
  307. int cch;
  308. CHAR *cp;
  309. CHAR ch;
  310. BOOL DBCSbundan = FALSE; // 02/12/93 bug fix
  311. if(*cpSt == cpLim)
  312. return(FALSE);
  313. FetchCp(docCur, *cpSt, 0, fcmChars);
  314. while(TRUE) {
  315. for(cch = 0,cp = vpchFetch; cch < vccpFetch; cch++,cp++) {
  316. if((vcpFetch + (typeCP)cch) >= cpLim)
  317. return(FALSE);
  318. ch = *cp;
  319. if( FKana(ch))
  320. ;
  321. else if( IsDBCSLeadByte(ch) ) {
  322. cp++; cch++;
  323. if(cch >= vccpFetch) { // 02/12/93 bug fix
  324. DBCSbundan = TRUE;
  325. break;
  326. }
  327. } else if (isprint(ch)) {
  328. *cpSt = vcpFetch + (typeCP)cch;
  329. return(TRUE);
  330. }
  331. }
  332. if((vcpFetch + (typeCP)cch) >= cpLim)
  333. return(FALSE);
  334. if(DBCSbundan) { // 02/12/93 bug fix
  335. FetchCp(docCur, vcpFetch + (typeCP)(cch+1), 0, fcmChars);
  336. DBCSbundan = FALSE;
  337. } else
  338. FetchCp(docNil, cpNil, 0, fcmChars);
  339. }
  340. }
  341. static void NEAR PASCAL GetSelCurEnd(cpSt,cpEnd,cpLim)
  342. typeCP *cpSt, *cpEnd, cpLim;
  343. {
  344. int cch;
  345. CHAR *cp;
  346. CHAR ch;
  347. FetchCp(docCur, *cpSt, 0, fcmChars);
  348. while(TRUE) {
  349. for(cch = 0,cp = vpchFetch; cch < vccpFetch; cch++,cp++) {
  350. if((vcpFetch + (typeCP)cch) >= cpLim) {
  351. *cpEnd = cpLim;
  352. return;
  353. }
  354. ch = *cp;
  355. if( FKana(ch) || IsDBCSLeadByte(ch) ) {
  356. *cpEnd = vcpFetch + (typeCP)cch;
  357. return;
  358. }
  359. }
  360. if((vcpFetch + (typeCP)cch) >= cpLim) {
  361. *cpEnd = cpLim;
  362. return;
  363. }
  364. FetchCp(docNil, cpNil, 0, fcmChars);
  365. }
  366. }
  367. static BOOL NEAR KanjiCheckSelect()
  368. {
  369. typeCP CpLimNoSpaces(typeCP, typeCP);
  370. typeCP cpLim;
  371. CHAR *cp;
  372. CHAR ch;
  373. int cch;
  374. cpLim = CpLimNoSpaces(selCur.cpFirst, selCur.cpLim);
  375. // FetchCp(docCur, selCur.cpFirst, 0, fcmChars);
  376. FetchCp(docCur, selCur.cpFirst, 0,fcmBoth + fcmParseCaps);
  377. while(TRUE) {
  378. if(NATIVE_CHARSET == GetCharSetFromChp(&vchpFetch)) {
  379. for(cch = 0,cp = vpchFetch; cch < vccpFetch; cch++,cp++) {
  380. if((vcpFetch + (typeCP)cch) >= cpLim)
  381. return(FALSE);
  382. ch = *cp;
  383. if( FKana(ch) || IsDBCSLeadByte(ch) ) {
  384. return(TRUE);
  385. }
  386. }
  387. }
  388. if((vcpFetch + (typeCP)vccpFetch) >= cpLim)
  389. return(FALSE);
  390. FetchCp(docNil, cpNil, 0, fcmBoth + fcmParseCaps);
  391. }
  392. }
  393. int FAR PASCAL GetKanjiStringLen(cch, cchF, cp)
  394. int cch, cchF;
  395. CHAR *cp;
  396. {
  397. int cblen = 0;
  398. for (; cch+cblen < cchF; cp++ ){
  399. if( FKana(*cp) )
  400. cblen++;
  401. else if( IsDBCSLeadByte(*cp) ) {
  402. cblen += 2;
  403. cp++;
  404. } else
  405. break;
  406. }
  407. return(cblen);
  408. }
  409. int FAR PASCAL GetAlphaStringLen(cch, cchF, cp)
  410. int cch, cchF;
  411. CHAR *cp;
  412. {
  413. int cblen = 0;
  414. for (; cch+cblen < cchF; cp++ ) {
  415. if( FKana(*cp) || IsDBCSLeadByte(*cp))
  416. break;
  417. else
  418. cblen++;
  419. }
  420. return(cblen);
  421. }
  422. // 02/15/93 add T-HIROYN 2 function
  423. int FAR PASCAL GetFtcFromPchp(pchp)
  424. struct CHP *pchp;
  425. {
  426. int ftc;
  427. ftc = pchp->ftc + (pchp->ftcXtra << 6);
  428. return ftc;
  429. }
  430. int FAR PASCAL SetFtcToPchp(pchp, ftc)
  431. struct CHP *pchp;
  432. int ftc;
  433. {
  434. pchp->ftc = ftc & 0x003f;
  435. pchp->ftcXtra = (ftc & 0x00c0) >> 6;
  436. }
  437. // added 02 Jun. 1992 by Hiraisi
  438. /*
  439. * This function deletes facename(s) with @-prefix
  440. * from FONT combobox(cmb1) of the CHOOSEFONT dialog.
  441. */
  442. BOOL FAR PASCAL _export DeleteFacename( hDlg, uMsg, wParam, lParam )
  443. HWND hDlg;
  444. UINT uMsg;
  445. WPARAM wParam;
  446. LPARAM lParam;
  447. {
  448. char str[50], sel[50];
  449. int ix;
  450. int cnt;
  451. if( uMsg != WM_INITDIALOG )
  452. return FALSE;
  453. cnt = (int)SendDlgItemMessage( hDlg, cmb1, CB_GETCOUNT, 0, 0L );
  454. ix = (int)SendDlgItemMessage( hDlg, cmb1, CB_GETCURSEL, 0, 0L );
  455. SendDlgItemMessage( hDlg, cmb1, CB_GETLBTEXT, ix, (DWORD)sel );
  456. for( ix = 0 ; ix < cnt ; ){
  457. SendDlgItemMessage( hDlg, cmb1, CB_GETLBTEXT, ix, (DWORD)str );
  458. if( str[0] == '@' )
  459. cnt = (int)SendDlgItemMessage( hDlg,cmb1,CB_DELETESTRING,ix,NULL );
  460. else
  461. ix++;
  462. }
  463. ix = (int)SendDlgItemMessage( hDlg, cmb1, CB_FINDSTRING, -1, (DWORD)sel );
  464. SendDlgItemMessage( hDlg, cmb1, CB_SETCURSEL, ix, 0L );
  465. return TRUE;
  466. }
  467. #elif defined(KOREA) // jinwoo : 10/14/92
  468. // added 02 Jun. 1992 by Hiraisi
  469. /*
  470. * This function deletes facename(s) with @-prefix
  471. * from FONT combobox(cmb1) of the CHOOSEFONT dialog.
  472. */
  473. BOOL FAR PASCAL _export DeleteFacename( hDlg, uMsg, wParam, lParam )
  474. HWND hDlg;
  475. UINT uMsg;
  476. WPARAM wParam;
  477. LPARAM lParam;
  478. {
  479. char str[50], sel[50];
  480. int ix;
  481. int cnt;
  482. if( uMsg != WM_INITDIALOG )
  483. return FALSE;
  484. cnt = (int)SendDlgItemMessage( hDlg, cmb1, CB_GETCOUNT, 0, 0L );
  485. ix = (int)SendDlgItemMessage( hDlg, cmb1, CB_GETCURSEL, 0, 0L );
  486. SendDlgItemMessage( hDlg, cmb1, CB_GETLBTEXT, ix, (DWORD)sel );
  487. for( ix = 0 ; ix < cnt ; ){
  488. SendDlgItemMessage( hDlg, cmb1, CB_GETLBTEXT, ix, (DWORD)str );
  489. if( str[0] == '@' )
  490. cnt = (int)SendDlgItemMessage( hDlg,cmb1,CB_DELETESTRING,ix,NULL );
  491. else
  492. ix++;
  493. }
  494. ix = (int)SendDlgItemMessage( hDlg, cmb1, CB_FINDSTRING, -1, (DWORD)sel );
  495. SendDlgItemMessage( hDlg, cmb1, CB_SETCURSEL, ix, 0L );
  496. return TRUE;
  497. }
  498. #endif