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