home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / BIDI / HEBREW / STYLE / STY_USER.C < prev    next >
C/C++ Source or Header  |  1995-08-24  |  35KB  |  1,078 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_USER.C
  4. *
  5. *  Description : This module contains the code for processing
  6. *                messages sent to the standard window that the
  7. *                standard window does not process.
  8. *                BIDI - Added: Bidirectional Language processing sample code.
  9. *
  10. *  Concepts    : Message processing
  11. *
  12. *  API's       : WinSetWindowPos
  13. *                WinSetFocus
  14. *                WinDefWIndowProc
  15. *                WinDlgBox
  16. *                WinSendMsg
  17. *                WinOpenClipbrd
  18. *                WinQueryClipbrdFmtInfo
  19. *                WinCloseClipbrd
  20. *                WinMessageBox
  21. *                WinLoadString
  22. *                WinSendMsg
  23. *                GpiCreateLogFont
  24. *                GpiSetCharSet
  25. *                GpiQueryFontMetrics
  26. *                GpiDeleteSetId
  27. *                WinGetPS
  28. *                WinReleasePS
  29. *                WinFontDlg
  30. *
  31. *  Copyright (C) 1992 IBM Corporation
  32. *
  33. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  34. *      sample code created by IBM Corporation. This sample code is not
  35. *      part of any standard or IBM product and is provided to you solely
  36. *      for  the purpose of assisting you in the development of your
  37. *      applications.  The code is provided "AS IS", without
  38. *      warranty of any kind.  IBM shall not be liable for any damages
  39. *      arising out of your use of the sample code, even if they have been
  40. *      advised of the possibility of such damages.                                                    *
  41. *
  42. ************************************************************************/
  43.  
  44. /*  Include files, macros, defined constants, and externs               */
  45.  
  46. #define INCL_WINMENUS
  47. #define INCL_WINWINDOWMGR
  48. #define INCL_WINCLIPBOARD
  49. #define INCL_WINMLE
  50. #define INCL_WINSTDFONT
  51. #define INCL_GPILCIDS
  52. #define INCL_GPIPRIMITIVES
  53. #define INCL_WINSYS
  54. #define INCL_WINSTDDLGS      // For FNTS_NATIONAL_LANGUAGE
  55. #define INCL_WINFRAMEMGR     // For FID_MENU
  56. #define INCL_WINCOUNTRY      // For WinQueryCp
  57. #define INCL_WINHOOKS         // For HMQ_CURRENT
  58.  
  59.  
  60.  
  61. #define INCL_WINDIALOGS
  62.  
  63. #include <os2.h>
  64. #include "sty_main.h"
  65. #include "sty_xtrn.h"
  66. #include "sty_dlg.h"
  67. #include <string.h>
  68.  
  69. // BIDI
  70. #include <pmbidi.h>
  71. #include <layout.h>
  72.  
  73. /*  Global variables */
  74.  
  75. LONG lClrForeground = CLR_BLACK;                    /* color for window text */
  76. LONG lClrBackground = CLR_WHITE;                     /* color for background */
  77.  
  78. LONG lClrDefaultForeground = CLR_BLACK;             /* color for window text */
  79. LONG lClrDefaultBackground = CLR_WHITE;              /* color for background */
  80.  
  81. /*--------------------------------------------------------------*\
  82.  *  Entry point declarations
  83. \*--------------------------------------------------------------*/
  84.  
  85. VOID SetForegroundColor(SHORT idMenu);
  86. VOID SetBackgroundColor(SHORT idMenu);
  87. VOID SetFont(VOID);
  88. VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs);
  89. MRESULT EXPENTRY DemoDlgProc(HWND hwnd, USHORT msg,
  90.                                   MPARAM mp1, MPARAM mp2);
  91. MRESULT EXPENTRY PresParamDemoDlgProc(HWND hwnd, USHORT msg,
  92.                                   MPARAM mp1, MPARAM mp2);
  93. VOID ShowDemoDlg(SHORT idMenuItem);
  94. VOID ShowDemoMsgBox(SHORT idMenuItem);
  95.  
  96. //BIDI
  97. VOID    ToggleWndOrient(HWND hwnd);
  98. MRESULT EXPENTRY TextConvertDlgProc(HWND hwnd, USHORT msg,
  99.                                   MPARAM mp1, MPARAM mp2);
  100.  
  101. /*********************************************************************
  102.  *  Name: UserWndProc
  103.  *
  104.  *  Description : Process any messages sent to hwndMain
  105.  *                that are not processed by the standard
  106.  *                window procedure.
  107.  *
  108.  *  Concepts : Routine is called for each message MainWndProc does
  109.  *             not process.  A switch statement branches control
  110.  *             based upon the message passed.  Any messages not
  111.  *             processed here must be passed onto
  112.  *             WinDefWindowProc()
  113.  *
  114.  *  API's : WinSetWindowPos
  115.  *          WinSetFocus
  116.  *          WinDefWIndowProc
  117.  *
  118.  * Parameters   : hwnd - Window handle to which message is addressed
  119.  *                msg - Message type
  120.  *                mp1 - First message parameter
  121.  *                mp2 - Second message parameter
  122.  *
  123.  *  Returns: Return value depended upon the message processed
  124.  *
  125.  ****************************************************************/
  126. MRESULT UserWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  127. {
  128.    switch(msg)
  129.    {
  130.       case WM_SIZE:
  131.          /*
  132.           * Re-size the MLE to be the same width and height
  133.           * as the client window
  134.           */
  135. // BIDI
  136. //         WinSetWindowPos(hwndMLE, HWND_TOP, 0, 0, SHORT1FROMMP(mp2),
  137. //                            SHORT2FROMMP(mp2), SWP_SIZE);
  138.            WinSetWindowPos(hwndMLE, HWND_TOP, 0, 0, SHORT1FROMMP(mp2),
  139.                             (SHORT2FROMMP(mp2)/2), SWP_SIZE);
  140.          break;
  141.  
  142.       case WM_SETFOCUS:
  143.          if(SHORT1FROMMP(mp1))
  144.          {
  145.             WinPostMsg(hwnd, SM_SETFOCUS, NULL, NULL);
  146.          }
  147.          break;
  148.  
  149.       case SM_SETFOCUS:
  150.          WinSetFocus(HWND_DESKTOP, hwndMLE);
  151.          break;
  152.  
  153.       default:
  154.          /*
  155.           * Default must call WinDefWindowProc()
  156.           */
  157.          return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  158.          break;
  159.    }
  160.  
  161.    return (MRESULT)0;
  162.  
  163. }   /*    End of UserWndProc()                                          */
  164.  
  165. /*********************************************************************
  166.  *  Name: UserCommand
  167.  *
  168.  *  Description : Process any WM_COMMAND messages send to
  169.  *                hwndMain that are not processed by MainCommand
  170.  *
  171.  *  Concepts : Routine is called for each WM_COMMAND that is not
  172.  *             posted by a standard menu item. A switch statement
  173.  *             branches control based upon the id of the control
  174.  *             which posted the message.
  175.  *
  176.  *  API's : WinDlgBox
  177.  *
  178.  *  Parameters :  mp1 - First message parameter
  179.  *                mp2 - Second message parameter
  180.  *
  181.  *  Returns: Void
  182.  *
  183.  ****************************************************************/
  184. VOID UserCommand(MPARAM mp1, MPARAM mp2)
  185. {
  186.    switch(SHORT1FROMMP(mp1))
  187.    {
  188.       case IDM_OPTIONSFORECOLORBLACK:
  189.       case IDM_OPTIONSFORECOLORBLUE:
  190.       case IDM_OPTIONSFORECOLORRED:
  191.       case IDM_OPTIONSFORECOLORDEFAULT:
  192.           SetForegroundColor(SHORT1FROMMP(mp1));
  193.           break;
  194.  
  195.       case IDM_OPTIONSBACKCOLORPINK:
  196.       case IDM_OPTIONSBACKCOLORCYAN:
  197.       case IDM_OPTIONSBACKCOLORYELLOW:
  198.       case IDM_OPTIONSBACKCOLORDEFAULT:
  199.           SetBackgroundColor(SHORT1FROMMP(mp1));
  200.           break;
  201.  
  202.       case IDM_OPTIONSFONT:
  203.           SetFont();
  204.           break;
  205.  
  206.       case IDM_DEMODLGBUTTONS:
  207.       case IDM_DEMODLGLISTBOXES:
  208.       case IDM_DEMODLGCOMBOBOXES:
  209.       case IDM_DEMODLG_SL_ENTRYFIELDS:
  210.       case IDM_DEMODLG_ML_ENTRYFIELDS:
  211.       case IDM_DEMODLGSTATIC:
  212.       case IDM_DEMODLGSLIDER:
  213.       case IDM_DEMODLGSPINBUTTON:
  214.       case IDM_DEMODLGVALUESET:
  215.       case IDM_DEMODLGNOTEBOOK:
  216.       case IDM_DEMODLGCONTAINER:
  217.           ShowDemoDlg(SHORT1FROMMP(mp1));
  218.           break;
  219.  
  220.       case IDM_DEMOMSGBOXOK:
  221.       case IDM_DEMOMSGBOXOKCANCEL:
  222.       case IDM_DEMOMSGBOXYESNO:
  223.       case IDM_DEMOMSGBOXYESNOCANCEL:
  224.       case IDM_DEMOMSGBOXRETRYCANCEL:
  225.       case IDM_DEMOMSGBOXABORT:
  226.       case IDM_DEMOMSGBOXENTER:
  227.       case IDM_DEMOMSGBOXENTERCANCEL:
  228.       case IDM_DEMOMSGBOXQUERY:
  229.       case IDM_DEMOMSGBOXWARNING:
  230.       case IDM_DEMOMSGBOXINFO:
  231.       case IDM_DEMOMSGBOXCRITICAL:
  232.       case IDM_DEMOMSGBOXAPP:
  233.       case IDM_DEMOMSGBOXSYS:
  234.       case IDM_DEMOMSGBOXHELP:
  235.           ShowDemoMsgBox(SHORT1FROMMP(mp1));
  236.           break;
  237.  
  238.       case IDM_DEMODLGPP:
  239.           WinDlgBox(hwndMain, hwndMain, (PFNWP)PresParamDemoDlgProc,
  240.                     (HMODULE)0, IDD_PPDEMODLG, (PVOID)NULL);
  241.           break;
  242.  
  243. //BIDI
  244.       case IDM_TEXTCONV:
  245.           WinDlgBox(hwndMain, hwndMain, (PFNWP)TextConvertDlgProc,
  246.                     (HMODULE)0, IDD_TEXTCONV_DLG, (PVOID)NULL);
  247.           break;
  248.  
  249.       case IDM_MENU_INVERSE:
  250.           ToggleWndOrient(hwndMainFrame);
  251.           break;
  252. //BIDI
  253.  
  254.       default:
  255.           break;
  256.    }
  257.  /*
  258.   * This routine currently doesn't use the mp2 parameter but
  259.   * it is referenced here to prevent an 'Unreferenced Parameter'
  260.   * warning at compile time.
  261.   */
  262.   mp2;
  263. }   /*    End of UserCommand()                                          */
  264.  
  265. /*********************************************************************
  266.  *  Name: InitMenu
  267.  *
  268.  *  Description : Processes the WM_INITMENU message for the main
  269.  *                window, disabling any menus that are not active
  270.  *
  271.  *  Concepts : Routine is called each time a menu is selected.  A
  272.  *             switch statement branches control based upon the
  273.  *             id of the menu which is being displayed.
  274.  *
  275.  *  API's : WinSendMsg
  276.  *          WinOpenClipbrd
  277.  *          WinQueryClipbrdFmtInfo
  278.  *          WinCloseClipbrd
  279.  *
  280.  *  Parameters :  mp1 - First message parameter
  281.  *                mp2 - Second message parameter
  282.  *
  283.  *  Returns: Nome
  284.  *
  285.  ****************************************************************/
  286. VOID InitMenu( MPARAM mp1, MPARAM mp2)
  287. {
  288. // ULONG  ulFmtInfo;
  289. // SHORT sRc1,sRc2;
  290.    BOOL bEnable;
  291.  
  292.    switch(SHORT1FROMMP(mp1))
  293.    {
  294.       case IDM_HELP:
  295.       /*
  296.        * Enable or disable the Help menu depending upon whether the
  297.        * help manager has been enabled
  298.        */
  299.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPUSINGHELP, fHelpEnabled);
  300.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPGENERAL, fHelpEnabled);
  301.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPKEYS, fHelpEnabled);
  302.          EnableMenuItem(HWNDFROMMP(mp2), IDM_HELPINDEX, fHelpEnabled);
  303.          break;
  304.  
  305.       case IDM_EDIT:
  306.       /*
  307.        * if text is selected in the MLE, the enable the Cut, Copy,
  308.        * and Clear menus.  Otherwise, do not
  309.        */
  310. // BIDI
  311. //
  312. // Removed this, so that copy is always enabled.
  313. // Since now, 'copy to the clipbaord' copies an internal buffer.
  314. //         sRc1 = (SHORT) WinSendMsg(hwndMLE, MLM_QUERYSEL,
  315. //                           MPFROMSHORT(MLFQS_MINSEL), NULL);
  316. //
  317. //         sRc2 = (SHORT) WinSendMsg(hwndMLE, MLM_QUERYSEL,
  318. //                           MPFROMSHORT(MLFQS_MAXSEL), NULL);
  319. //
  320. //         if (sRc1 != sRc2)
  321. //            bEnable = TRUE;
  322. //         else
  323. //            bEnable = FALSE;
  324.  
  325.          bEnable = TRUE;
  326.  
  327.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCOPY_NOCONV, bEnable);
  328.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITCOPY_AUTOCONV, bEnable);
  329.  
  330.  
  331.  
  332. // BIDI
  333. // commented.
  334.          /*
  335.           * determine if the clipboard has some text on it.  If it
  336.           * doesn't, then disable the Paste menu
  337.           */
  338. //       if(WinOpenClipbrd(hab))
  339. //       {
  340. //         if (WinQueryClipbrdFmtInfo(hab, CF_TEXT, &ulFmtInfo))
  341. //            bEnable = TRUE;
  342. //         else
  343. //            bEnable = FALSE;
  344. //         WinCloseClipbrd(hab);
  345. //       }
  346. //       else
  347. //          bEnable = TRUE;
  348.  
  349.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITPASTE_NOCONV, bEnable);
  350.          EnableMenuItem(HWNDFROMMP(mp2), IDM_EDITPASTE_AUTOCONV,   bEnable);
  351.          break;
  352.  
  353.       case IDM_OPTIONSFORECOLOR:
  354.          {
  355.           LONG lColor;
  356.           BOOL bBlack = TRUE;
  357.           BOOL bBlue = TRUE;
  358.           BOOL bRed = TRUE;
  359.           BOOL bDefault = TRUE;
  360.  
  361.           lColor = (LONG)WinSendMsg(hwndMLE,MLM_QUERYTEXTCOLOR, NULL, NULL);
  362.           switch (lColor)
  363.           {
  364.              case CLR_BLACK:
  365.                 bBlack = FALSE;
  366.                 break;
  367.              case CLR_BLUE:
  368.                 bBlue = FALSE;
  369.                 break;
  370.              case CLR_RED:
  371.                 bRed = FALSE;
  372.                 break;
  373.              default:
  374.                 bDefault = FALSE;
  375.                 break;
  376.            }
  377.  
  378.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORBLACK,
  379.                            bBlack);
  380.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORBLUE, bBlue);
  381.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORRED, bRed);
  382.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSFORECOLORDEFAULT,
  383.                            bDefault);
  384.          }
  385.          break;
  386.       case IDM_OPTIONSBACKCOLOR:
  387.          {
  388.           LONG lColor;
  389.           BOOL bYellow = TRUE;
  390.           BOOL bPink = TRUE;
  391.           BOOL bCyan = TRUE;
  392.           BOOL bDefault = TRUE;
  393.  
  394.           lColor = (LONG)WinSendMsg(hwndMLE,MLM_QUERYBACKCOLOR, NULL, NULL);
  395.           switch (lColor)
  396.           {
  397.              case CLR_YELLOW:
  398.                 bYellow = FALSE;
  399.                 break;
  400.              case CLR_PINK:
  401.                 bPink = FALSE;
  402.                 break;
  403.              case CLR_CYAN:
  404.                 bCyan = FALSE;
  405.                 break;
  406.              default:
  407.                 bDefault = FALSE;
  408.                 break;
  409.            }
  410.  
  411.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORYELLOW,
  412.                            bYellow);
  413.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORPINK, bPink);
  414.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORCYAN, bCyan);
  415.            EnableMenuItem(HWNDFROMMP(mp2), IDM_OPTIONSBACKCOLORDEFAULT,
  416.                            bDefault);
  417.          }
  418.          break;
  419.  
  420.       default:
  421.           break;
  422.    }
  423. }   /*       End of InitMenu()                                          */
  424.  
  425. /*********************************************************************
  426.  *  Name: EnableMenuItem
  427.  *
  428.  *  Description : Enables or disables menu item.
  429.  *
  430.  *  Concepts : Called whenever a menu item is to be enabled or
  431.  *             disabled.  Sends a MM_SETITEMATTR to the menu with
  432.  *             the given item id.  Sets the MIA_DISABLED
  433.  *             attribute flag if the item is to be disabled,
  434.  *             clears the flag if enabling.
  435.  *
  436.  *  API's : WinSendMsg
  437.  *
  438.  *  Parameters   : hwnd - Window handle of the menu
  439.  *                 sIditem  - Id of the menu item.
  440.  *                 bEnable - Enable/Disable flag
  441.  *
  442.  *  Returns: Void
  443.  *
  444.  ****************************************************************/
  445. VOID EnableMenuItem( HWND hwndMenu, SHORT sIditem, BOOL bEnable)
  446. {
  447.   SHORT sFlag;
  448.  
  449.   if(bEnable)
  450.     sFlag = 0;
  451.   else
  452.     sFlag = MIA_DISABLED;
  453.  
  454.   WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(sIditem, TRUE),
  455.                MPFROM2SHORT(MIA_DISABLED, sFlag));
  456.  
  457. }   /*         End of EnableMenuItem()                                  */
  458.  
  459. /*********************************************************************
  460.  *  Name: ShowDemoDlg
  461.  *
  462.  *  Description : Displays the demonstration dialog for the menu
  463.  *                id chosen.
  464.  *
  465.  *  Concepts : Called whenever a menu item from the Dialog Box
  466.  *             menu of the Demo menu is selected.  Determines the
  467.  *             id of the dialog template and creates a dialog of
  468.  *             that template.
  469.  *
  470.  *  API's : WinDlgBox
  471.  *
  472.  *  Parameters :   sIdMenuItem - Id of the menu item.
  473.  *
  474.  *  Returns: Void
  475.  *
  476.  ****************************************************************/
  477. VOID ShowDemoDlg( SHORT sIdMenuItem)
  478. {
  479.   static SHORT sIdDlg;
  480.  
  481.   switch(sIdMenuItem)
  482.   {
  483.      case IDM_DEMODLGBUTTONS:
  484.          sIdDlg = IDD_BUTTONSDLG;
  485.          break;
  486.  
  487.      case IDM_DEMODLGLISTBOXES:
  488.          sIdDlg = IDD_LISTBOXDLG;
  489.          break;
  490.  
  491.      case IDM_DEMODLGCOMBOBOXES:
  492.          sIdDlg = IDD_COMBOBOXDLG;
  493.          break;
  494.  
  495.      case IDM_DEMODLG_SL_ENTRYFIELDS:
  496.          sIdDlg = IDD_SL_ENTRYFIELDDLG;
  497.          break;
  498.  
  499.      case IDM_DEMODLG_ML_ENTRYFIELDS:
  500.          sIdDlg = IDD_ML_ENTRYFIELDDLG;
  501.          break;
  502.  
  503.      case IDM_DEMODLGSTATIC:
  504.          sIdDlg = IDD_STATICDLG;
  505.          break;
  506.  
  507.      case IDM_DEMODLGSLIDER:
  508.          sIdDlg = IDD_SLIDERDLG;
  509.          break;
  510.  
  511.      case IDM_DEMODLGSPINBUTTON:
  512.          sIdDlg = IDD_SPINBUTTONDLG;
  513.          break;
  514.  
  515.      case IDM_DEMODLGVALUESET:
  516.          sIdDlg = IDD_VALUESETDLG;
  517.          break;
  518.  
  519.      case IDM_DEMODLGNOTEBOOK:
  520.          sIdDlg = IDD_NOTEBOOKDLG;
  521.          break;
  522.  
  523.      case IDM_DEMODLGCONTAINER:
  524.          sIdDlg = IDD_CONTAINERDLG;
  525.          break;
  526.  
  527.      default:    /* unknown menu id */
  528.          return;
  529.          break;
  530.   }
  531.  
  532.   WinDlgBox(HWND_DESKTOP, hwndMain,
  533.            (PFNWP)DemoDlgProc,          /* all demos use DemoDlgProc    */
  534.            (HMODULE)0,
  535.            sIdDlg,                      /* id of template               */
  536.            (PVOID)&sIdDlg);             /* pass id as mp2 of WM_INITDLG */
  537.  
  538. }   /*      End of ShowDemoDlg()                                        */
  539.  
  540.  
  541. /*********************************************************************
  542.  *  Name: ShowDemoMsgBox
  543.  *
  544.  *  Description : Displays the demonstration message box for the menu
  545.  *                id chosen.
  546.  *
  547.  *  Concepts :  Called whenever a menu item from the Message Box menu
  548.  *              of the Demo menu is selected.  Determines the options
  549.  *              for the message box and then creates the box.
  550.  *
  551.  *  API's : WinLoadString
  552.  *          WinMessageBox
  553.  *
  554.  *  Parameters : sIdMenuItem - Id of the menu item.
  555.  *
  556.  *  Returns: VOID
  557.  *
  558.  ****************************************************************/
  559. VOID ShowDemoMsgBox( SHORT sIdMenuItem)
  560. {
  561.   SHORT sOptions, sIdText;
  562.   CHAR szText[MESSAGELEN];
  563.  
  564.   switch(sIdMenuItem)
  565.   {
  566.      case IDM_DEMOMSGBOXOK:
  567.         sOptions = MB_OK | MB_MOVEABLE;
  568.         sIdText = IDS_DEMOMSGBOXOK;
  569.         break;
  570.  
  571.      case IDM_DEMOMSGBOXOKCANCEL:
  572.         sOptions = MB_OKCANCEL | MB_MOVEABLE;
  573.         sIdText = IDS_DEMOMSGBOXOKCANCEL;
  574.         break;
  575.  
  576.      case IDM_DEMOMSGBOXYESNO:
  577.         sOptions = MB_YESNO | MB_MOVEABLE;
  578.         sIdText = IDS_DEMOMSGBOXYESNO;
  579.         break;
  580.  
  581.      case IDM_DEMOMSGBOXYESNOCANCEL:
  582.         sOptions = MB_YESNOCANCEL | MB_MOVEABLE;
  583.         sIdText = IDS_DEMOMSGBOXYESNOCANCEL;
  584.         break;
  585.  
  586.      case IDM_DEMOMSGBOXRETRYCANCEL:
  587.         sOptions = MB_RETRYCANCEL | MB_MOVEABLE;
  588.         sIdText = IDS_DEMOMSGBOXRETRYCANCEL;
  589.         break;
  590.  
  591.      case IDM_DEMOMSGBOXABORT:
  592.         sOptions = MB_ABORTRETRYIGNORE | MB_MOVEABLE;
  593.         sIdText = IDS_DEMOMSGBOXABORT;
  594.         break;
  595.  
  596.      case IDM_DEMOMSGBOXENTER:
  597.         sOptions = MB_ENTER | MB_MOVEABLE;
  598.         sIdText = IDS_DEMOMSGBOXENTER;
  599.         break;
  600.  
  601.      case IDM_DEMOMSGBOXENTERCANCEL:
  602.         sOptions = MB_ENTERCANCEL | MB_MOVEABLE;
  603.         sIdText = IDS_DEMOMSGBOXENTERCANCEL;
  604.         break;
  605.  
  606.      case IDM_DEMOMSGBOXQUERY:
  607.         sOptions = MB_OK | MB_QUERY | MB_MOVEABLE;
  608.         sIdText = IDS_DEMOMSGBOXQUERY;
  609.         break;
  610.  
  611.      case IDM_DEMOMSGBOXWARNING:
  612.         sOptions = MB_OK | MB_WARNING | MB_MOVEABLE;
  613.         sIdText = IDS_DEMOMSGBOXWARNING;
  614.         break;
  615.  
  616.      case IDM_DEMOMSGBOXINFO:
  617.         sOptions = MB_OK | MB_INFORMATION | MB_MOVEABLE;
  618.         sIdText = IDS_DEMOMSGBOXINFO;
  619.         break;
  620.  
  621.      case IDM_DEMOMSGBOXCRITICAL:
  622.         sOptions = MB_OK | MB_CRITICAL | MB_MOVEABLE;
  623.         sIdText = IDS_DEMOMSGBOXCRITICAL;
  624.         break;
  625.  
  626.      case IDM_DEMOMSGBOXAPP:
  627.         sOptions = MB_OK | MB_APPLMODAL | MB_MOVEABLE;
  628.         sIdText = IDS_DEMOMSGBOXAPP;
  629.         break;
  630.  
  631.      case IDM_DEMOMSGBOXSYS:
  632.         sOptions = MB_OK | MB_SYSTEMMODAL | MB_MOVEABLE;
  633.         sIdText = IDS_DEMOMSGBOXSYS;
  634.         break;
  635.  
  636.      case IDM_DEMOMSGBOXHELP:
  637.         sOptions = MB_OK | MB_HELP | MB_MOVEABLE;
  638.         sIdText = IDS_DEMOMSGBOXHELP;
  639.         break;
  640.  
  641.      default:
  642.         /*
  643.         * Unknown menu id
  644.         */
  645.         return;
  646.         break;
  647.   }
  648.  
  649.   /*
  650.   * Get the text for the message box
  651.   */
  652.   if(!WinLoadString(hab, (HMODULE)0, sIdText, MESSAGELEN, (PSZ)szText))
  653.   {
  654.      MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  655.         return;
  656.   }
  657.  
  658.   /* bring up the message box                                           */
  659.   WinMessageBox(HWND_DESKTOP, hwndMain, szText, szAppName, IDD_DEMOMSGBOX,
  660.                 sOptions);
  661.  
  662. }   /*   End of ShowDemoMsgBox()                                        */
  663.  
  664. /*********************************************************************
  665.  *  Name: SetForegroundColor
  666.  *
  667.  *  Description : Allows the user to select a color for the
  668.  *                window foreground
  669.  *
  670.  *  Concepts : Routine is called each time the user selects one
  671.  *             of the Foreground colors listed in the Foreground
  672.  *             Color submenu of the Options menu.  A switch
  673.  *             statement determines which menu item was chosen
  674.  *             and then the appropriate color is placed into
  675.  *             lClrForeground.
  676.  *
  677.  *  API's : WinSendMsg
  678.  *
  679.  *  Parameters : sIdItem - Id of the menu item.
  680.  *
  681.  *  Returns: Void
  682.  *
  683.  ****************************************************************/
  684. VOID SetForegroundColor(SHORT sIdMenu)
  685. {
  686.    switch(sIdMenu)
  687.    {
  688.       case IDM_OPTIONSFORECOLORBLACK:
  689.          lClrForeground = CLR_BLACK;
  690.          break;
  691.  
  692.       case IDM_OPTIONSFORECOLORBLUE:
  693.          lClrForeground = CLR_BLUE;
  694.          break;
  695.  
  696.       case IDM_OPTIONSFORECOLORRED:
  697.          lClrForeground = CLR_RED;
  698.          break;
  699.  
  700.       /*
  701.        *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
  702.        *  the background color to the default back color
  703.        */
  704.       default:
  705.          lClrForeground = lClrDefaultForeground;
  706.          break;
  707.    }
  708.    WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, MPFROMLONG(lClrForeground), NULL);
  709. }   /*   End of SetForegroundColor()                                    */
  710.  
  711. /*********************************************************************
  712.  *  Name: SetBackgroundColor
  713.  *
  714.  *  Description : Allows the user to select a color for the
  715.  *                window Background
  716.  *
  717.  *  Concepts : Routine is called each time the user selects one
  718.  *             of the Background colors listed in the Background
  719.  *             Color submenu of the Options menu.  A switch
  720.  *             statement determines which menu item was chosen
  721.  *             and then the appropriate color is placed into
  722.  *             lClrBackground.
  723.  *
  724.  *  API's : WinSendMsg
  725.  *
  726.  *  Parameters : sIdItem - Id of the menu item.
  727.  *
  728.  *  Returns: Void
  729.  *
  730.  ****************************************************************/
  731. VOID SetBackgroundColor( SHORT idMenu)
  732. {
  733.    switch(idMenu)
  734.    {
  735.       case IDM_OPTIONSBACKCOLORPINK:
  736.          lClrBackground = CLR_PINK;
  737.          break;
  738.  
  739.       case IDM_OPTIONSBACKCOLORCYAN:
  740.          lClrBackground = CLR_CYAN;
  741.          break;
  742.  
  743.       case IDM_OPTIONSBACKCOLORYELLOW:
  744.          lClrBackground = CLR_YELLOW;
  745.          break;
  746.  
  747.       /*
  748.        *  For any others, including IDM_OPTIONSBACKCOLORDEFAULT, set
  749.        *  the background color to the default back color
  750.        */
  751.       default:
  752.          lClrBackground = lClrDefaultBackground;
  753.          break;
  754.    }
  755.    WinSendMsg(hwndMLE, MLM_SETBACKCOLOR, MPFROMLONG(lClrBackground), NULL);
  756. }   /*  End of SetBackgroundColor()                                     */
  757.  
  758.  
  759. /*********************************************************************
  760.  *  Name: SetFont
  761.  *
  762.  *  Description : Allows the user to select a font for the text
  763.  *                displayed in the MLE.
  764.  *
  765.  *  Concepts : Routine is called each time the user selects the
  766.  *             Font menu item from the Options menu.  The
  767.  *             standard font dialog is called with the current
  768.  *             available fonts.  If the user selects one, then
  769.  *             the MLM_SETFONT message is sent to the MLE to
  770.  *             display its text to the font chosen.
  771.  *
  772.  *  API's : WinSendMsg
  773.  *          GpiCreateLogFont
  774.  *          GpiSetCharSet
  775.  *          GpiQueryFontMetrics
  776.  *          GpiDeleteSetId
  777.  *          WinGetPS
  778.  *          WinReleasePS
  779.  *          WinLoadString
  780.  *          WinFontDlg
  781.  *
  782.  *  Parameters :  None
  783.  *
  784.  *  Returns: None
  785.  *
  786.  ****************************************************************/
  787. VOID SetFont(void)
  788. {
  789.    FONTDLG fontDlg;
  790.    HPS hps;
  791.    FONTMETRICS fontMetrics;
  792.    CHAR szTitle[MESSAGELEN];
  793.    CHAR szFamily[CCHMAXPATH];
  794.    static fxPointSize = 0;            /* keep track of this for vector fonts */
  795.  
  796.    memset(&fontDlg, 0, sizeof(fontDlg));            /* initialize all fields */
  797.    /*
  798.     * Get the current font attributes
  799.     */
  800.    hps = WinGetPS(hwndMLE);
  801.    WinSendMsg(hwndMLE, MLM_QUERYFONT,
  802.       MPFROMP((PFATTRS)&(fontDlg.fAttrs)), NULL);
  803.  
  804.    /* create system default font */
  805.  
  806.    GpiCreateLogFont(
  807.       hps,
  808.       (PSTR8)fontDlg.fAttrs.szFacename,
  809.       1,
  810.       &(fontDlg.fAttrs));
  811.  
  812.    GpiSetCharSet(hps, 1);
  813.  
  814.    GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fontMetrics);
  815.  
  816.    GpiSetCharSet(hps, LCID_DEFAULT);
  817.    GpiDeleteSetId(hps, 1);
  818.    WinReleasePS(hps);
  819.  
  820.    /*
  821.     * Initialize the FONTDLG structure with the current font
  822.     */
  823.    fontDlg.cbSize     = sizeof(FONTDLG);                  /* sizeof(FONTDLG) */
  824.    fontDlg.hpsScreen  = WinGetScreenPS(HWND_DESKTOP);  /* Screen presentation space */
  825.    fontDlg.hpsPrinter = NULLHANDLE;            /* Printer presentation space */
  826.  
  827.    if(!WinLoadString(hab, (HMODULE)0, IDS_FONTDLGTITLE, MESSAGELEN, szTitle))
  828.    {
  829.       MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
  830.       return;
  831.    }
  832.  
  833. // BIDI
  834. //
  835. // Commented out the 'application supplied title' so that the default
  836. // title (which may be in Arabic/Hebrew) can be displayed.
  837.  
  838. // fontDlg.pszTitle      = szTitle;       /* Application supplied title      */
  839.    fontDlg.pszTitle      = NULL;          /* Default text.                   */
  840.    fontDlg.pszPreview    = NULL;          /* String to print in preview wndw */
  841.    fontDlg.pszPtSizeList = NULL;          /* Application provided size list  */
  842.    fontDlg.pfnDlgProc    = NULL;          /* Dialog subclass procedure       */
  843.    strcpy(szFamily, fontMetrics.szFamilyname); /* Family name of font        */
  844.    fontDlg.pszFamilyname = szFamily;      /* point to Family name of font    */
  845.    fontDlg.fxPointSize = fxPointSize;     /* Point size the user selected    */
  846.    fontDlg.fl           = FNTS_CENTER |   /* FNTS_* flags - dialog styles    */
  847.                           FNTS_INITFROMFATTRS ;
  848. //BIDI
  849. // The following line can be made active to always force
  850. // Right-to-left and National language in the font dialog.
  851. // When commented, the RtL and National Language are dependent
  852. // on the STDDLGLANG=NATIONAL environement variable.
  853. // fontDlg.fl          |= FNTS_NATIONAL_LANGUAGE;
  854.    fontDlg.flFlags      = 0;              /* FNTF_* state flags              */
  855.                                           /* Font type option bits           */
  856.    fontDlg.flType       = (LONG) fontMetrics.fsType;
  857.    fontDlg.flTypeMask   = 0;              /* Mask of which font types to use */
  858.    fontDlg.flStyle      = 0;              /* The selected style bits         */
  859.    fontDlg.flStyleMask  = 0;              /* Mask of which style bits to use */
  860.    fontDlg.clrFore      = lClrForeground; /* Selected foreground color       */
  861.    fontDlg.clrBack      = lClrBackground; /* Selected background color       */
  862.    fontDlg.ulUser       = 0;              /* Blank field for application     */
  863.    fontDlg.lReturn      = 0;              /* Return Value of the Dialog      */
  864.    fontDlg.lSRC;                          /* System return code.             */
  865.    fontDlg.lEmHeight    = 0;              /* Em height of the current font   */
  866.    fontDlg.lXHeight     = 0;              /* X height of the current font    */
  867.    fontDlg.lExternalLeading = 0;          /* External Leading of font        */
  868.    fontDlg.hMod;                          /* Module to load custom template  */
  869.                                           /* Nominal Point Size of font      */
  870.    fontDlg.sNominalPointSize = fontMetrics.sNominalPointSize;
  871.    fontDlg.usWeight = fontMetrics.usWeightClass; /* The boldness of the font */
  872.    fontDlg.usWidth = fontMetrics.usWidthClass;  /* The width of the font     */
  873.    fontDlg.x            = 0;              /* X coordinate of the dialog      */
  874.    fontDlg.y            = 0;              /* Y coordinate of the dialog      */
  875.    fontDlg.usDlgId      = IDD_FONT;       /* ID of a custom dialog template  */
  876.    fontDlg.usFamilyBufLen = sizeof(szFamily); /*Length of family name buffer */
  877.    fontDlg.fAttrs;                        /* Font attribute structure        */
  878.  
  879.    /*
  880.     *   Bring up the standard Font Dialog
  881.     */
  882.  
  883.    if(WinFontDlg(HWND_DESKTOP, hwndMLE, &fontDlg) != DID_OK)
  884.    {
  885.       WinReleasePS(fontDlg.hpsScreen);
  886.       return;
  887.    }
  888.    fxPointSize = fontDlg.fxPointSize;     /* save point size for next dialog */
  889.  
  890.    /*
  891.     *   If outline font, calculate the maxbaselineext and
  892.     *   avecharwidth for the point size selected
  893.     */
  894.  
  895.    if ( fontDlg.fAttrs.fsFontUse == FATTR_FONTUSE_OUTLINE )
  896.    {
  897.       ConvertVectorFontSize(fontDlg.fxPointSize, &fontDlg.fAttrs);
  898.    }
  899.  
  900.    WinReleasePS(fontDlg.hpsScreen);
  901.    WinSendMsg(hwndMLE, MLM_SETFONT, MPFROMP(&(fontDlg.fAttrs)), NULL);
  902.  
  903. }   /* End of SetFont()                                                 */
  904.  
  905. /*
  906.  *   Convert vector font size using point size and fAttrs structure and
  907.  *   return it in that structure.
  908.  */
  909.  
  910. VOID ConvertVectorFontSize(FIXED fxPointSize, PFATTRS pfattrs)
  911. {
  912.   HPS   hps;
  913.   HDC   hDC;
  914.   LONG  lxFontResolution;
  915.   LONG  lyFontResolution;
  916.   SIZEF sizef;
  917.  
  918.   hps = WinGetScreenPS(HWND_DESKTOP);        /* Screen presentation space */
  919.  
  920.   /*
  921.    *   Query device context for the screen and then query
  922.    *   the resolution of the device for the device context.
  923.    */
  924.  
  925.   hDC = GpiQueryDevice(hps);
  926.   DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES, (LONG)1, &lxFontResolution);
  927.   DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES, (LONG)1, &lyFontResolution);
  928.  
  929.   /*
  930.    *   Calculate the size of the character box, based on the
  931.    *   point size selected and the resolution of the device.
  932.    *   The size parameters are of type FIXED, NOT int.
  933.    *   NOTE: 1 point == 1/72 of an inch.
  934.    */
  935.  
  936.   sizef.cx = (FIXED)(((fxPointSize) / 72 ) * lxFontResolution );
  937.   sizef.cy = (FIXED)(((fxPointSize) / 72 ) * lyFontResolution );
  938.  
  939.   pfattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( sizef.cy ), 0 );
  940.   pfattrs->lAveCharWidth   = MAKELONG( HIUSHORT( sizef.cx ), 0 );
  941.   WinReleasePS(hps);
  942.  
  943. }   /* end ConvertVectorPointSize() */
  944.  
  945.  
  946. //BIDI
  947. /*********************************************************************
  948.  *  Name: TransformText()
  949.  *
  950.  *  Description : Performs bidirectional text conversion/transformation.
  951.  *
  952.  *
  953.  *  Concepts : Prepares and calls a Layout Object to do the text
  954.  *             transformation.
  955.  *
  956.  *  Parameters :  Window handle of dialog
  957.  *
  958.  *  Returns: TRUE=Success, FALSE=Failure
  959.  *
  960.  ****************************************************************/
  961. ULONG TransformText(HWND hwnd)
  962. { HWND            hwndSource,
  963.                   hwndTarget;
  964.   LAYOUT_OBJECT   hLayout;
  965.   LAYOUT_VALUES   Layout[4];
  966.   UCHAR           String[128];
  967.   APIRET          RC=0;
  968.   ULONG           SrcBDAtts,
  969.                   TrgBDAtts,
  970.                   BDMask,
  971.                   index,
  972.                   ulLength;
  973.  
  974.                                  /* Get handles of static text windows */
  975.   hwndTarget =  WinWindowFromID (hwnd, IDC_TEXTCONV_TARGET);
  976.   hwndSource =  WinWindowFromID (hwnd, IDC_TEXTCONV_SOURCE);
  977.  
  978.                       /* Load string, initialize attributes and create */
  979.                       /* layout object according to current codepage   */
  980.  
  981.                                                              /* Arabic */
  982.   if (WinQueryCp(HMQ_CURRENT) == 864)
  983.   {
  984.       WinLoadString( hab, NULLHANDLE, IDS_CONVTEXT+ARA_OFF,127, String);
  985.       BDMask    =  BDAM_TEXT_ORIENTATION | BDAM_TEXTTYPE |
  986.                    BDAM_NUMERALS | BDAM_TEXT_SHAPE;
  987.       SrcBDAtts =  BDA_TEXT_ORIENT_RTL | BDA_TEXTTYPE_IMPLICIT |
  988.                    BDA_NUMERALS_NOMINAL | BDA_TEXT_NOMINAL;
  989.       TrgBDAtts =  BDA_TEXT_ORIENT_LTR | BDA_TEXTTYPE_VISUAL   |
  990.                    BDA_NUMERALS_CONTEXTUAL | BDA_TEXT_DISPLAY_SHAPED;
  991.       RC = LayoutCreateObject (Locale_Arabic,&hLayout);
  992.   }
  993.   else
  994.                                                            /* Hebrew */
  995.   {
  996.       WinLoadString( hab, NULLHANDLE, IDS_CONVTEXT, 127, String);
  997.       BDMask    =  BDAM_TEXT_ORIENTATION | BDAM_TEXTTYPE;
  998.       SrcBDAtts =  BDA_TEXT_ORIENT_CONTEXT | BDA_TEXTTYPE_IMPLICIT;
  999.       TrgBDAtts =  BDA_TEXT_ORIENT_LTR     | BDA_TEXTTYPE_VISUAL;
  1000.       RC = LayoutCreateObject (Locale_Hebrew,&hLayout);
  1001.   }
  1002.  
  1003.   if (RC)
  1004.   {
  1005.    WinMessageBox(HWND_DESKTOP, hwnd, "Failed to create layout object",
  1006.                 "Bidi text transform - Error",
  1007.                  IDD_MSGBOX, MB_ERROR | MB_OK);
  1008.      return FALSE;
  1009.   }
  1010.  
  1011.   ulLength=strlen(String);
  1012.  
  1013.                                              /* Display Source String */
  1014.   WinSetWindowText ( hwndSource, String );
  1015.  
  1016.                                            /* Initialize layout array */
  1017.   Layout[0].name  =  InOutTextDescrMask;
  1018.   Layout[0].value =  &BDMask;
  1019.  
  1020.   Layout[1].name  =  InOnlyTextDescr;
  1021.   Layout[1].value =  &SrcBDAtts;
  1022.  
  1023.   Layout[2].name  =  OutOnlyTextDescr;
  1024.   Layout[2].value =  &TrgBDAtts;
  1025.  
  1026.   Layout[3].name = 0;
  1027.                                                     /* Set layout values */
  1028.   RC = LayoutSetValues (hLayout,Layout,&index);
  1029.   if (RC)
  1030.   {
  1031.    WinMessageBox(HWND_DESKTOP, hwnd, "Failed to set layout values",
  1032.                 "Bidi text transform - Error",
  1033.                  IDD_MSGBOX, MB_ERROR | MB_OK);
  1034.      return FALSE;
  1035.   }
  1036.                                         /* Do actual text transformation */
  1037.   RC = LayoutTransformText (hLayout,
  1038.                             String,
  1039.                             &ulLength,
  1040.                             String ,
  1041.                             &ulLength, NULL, NULL, NULL);
  1042.   if (RC)
  1043.   {
  1044.    WinMessageBox(HWND_DESKTOP, hwnd, "LayoutTransformText failed",
  1045.                 "Bidi text transform - Error",
  1046.                  IDD_MSGBOX, MB_ERROR | MB_OK);
  1047.    return FALSE;
  1048.   }
  1049.  
  1050.                                            /* Display converted String */
  1051.   WinSetWindowText ( hwndTarget, String );
  1052.  
  1053.   return TRUE;
  1054.  
  1055. }
  1056.  
  1057. /*********************************************************************
  1058.  *  Name: ToggleWndOrient()
  1059.  *
  1060.  *  Description : Toggles a window orientation.
  1061.  *
  1062.  *
  1063.  *  Parameters :  window handle of which window orientation is toggled.
  1064.  *
  1065.  *  Returns: None
  1066.  *
  1067.  ****************************************************************/
  1068. VOID ToggleWndOrient(HWND hwnd)
  1069. {
  1070. ULONG BidiAttr = WinQueryLangInfo( hwnd, LI_BD_WND_ATTR, 0L, 0L);
  1071.  
  1072.       BidiAttr ^= BDAM_WND_ORIENTATION ;
  1073.  
  1074.       WinSetLangInfo (hwnd, LI_BD_WND_ATTR, BidiAttr,
  1075.                       BDAM_WND_ORIENTATION, LIF_WND_REFRESH, 0L);
  1076. } /* ToggleWndOrient() */
  1077.  
  1078.