home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / bidi / arabic / style / sty_edit.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  8KB  |  263 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_EDIT.C
  4. *
  5. *  Description : This module contains the code for the WM_COMMAND
  6. *                messages posted by the standard edit menu.
  7. *
  8. *  Concepts    : Demonstrates the cut, paste, copy, undo, and
  9. *                clear features of an MLE control.
  10. *                BIDI - Added: Bidirectional Language processing sample code.
  11. *
  12. *  API's       : WinSendMsg
  13. *
  14. *  Copyright (C) 1992 IBM Corporation
  15. *
  16. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  17. *      sample code created by IBM Corporation. This sample code is not
  18. *      part of any standard or IBM product and is provided to you solely
  19. *      for  the purpose of assisting you in the development of your
  20. *      applications.  The code is provided "AS IS", without
  21. *      warranty of any kind.  IBM shall not be liable for any damages
  22. *      arising out of your use of the sample code, even if they have been
  23. *      advised of the possibility of such damages.                                                    *
  24. *
  25. ************************************************************************/
  26.  
  27. /*  Include files, macros, defined constants, and externs               */
  28.  
  29. #define INCL_WIN
  30.  
  31. #include <os2.h>
  32. #include <pmbidi.h>
  33. #include <string.h>
  34. #include "sty_main.h"
  35. #include "sty_xtrn.h"
  36.  
  37. extern LONG lClrForeground;                         /* color for window text */
  38. extern LONG lClrBackground;                          /* color for background */
  39.  
  40. CHAR   szPasteText[80];
  41.  
  42. //CHAR   szCopyVisualText[]    = "ABCDâéüÇ";
  43. //CHAR   szCopyImplicitText[]  = "ABCDÇüéâ";
  44. CHAR   szCopyVisualText[128]  ;
  45. CHAR   szCopyImplicitText[128];
  46.  
  47.  
  48. /*********************************************************************
  49.  *  Name: EditCopy
  50.  *
  51.  *  Description : Processes the Edit menu's Copy item.
  52.  *
  53.  *  Concepts : Called whenever Copy from the Edit menu is selected
  54.  *             Sends a MLM_COPY message to the MLE control.
  55.  *
  56.  *  API's : WinSendMsg
  57.  *
  58.  *  Parameters : mp1 - Message parameter
  59.  *             : mp2 - Message parameter
  60.  *
  61.  *  Returns: Void
  62.  *
  63.  ****************************************************************/
  64. VOID EditCopy(MPARAM mp1, MPARAM mp2)
  65. {
  66.    HAB hab;
  67.    PCHAR pchClipText, pText;
  68.    APIRET rc;
  69.    ULONG  BidiAttr;
  70.    BOOL   fSetClipAttr;
  71.    LONG   Offset =0;
  72.  
  73.       rc = DosAllocSharedMem ( (PPVOID) &pchClipText,
  74.                     NULL,
  75.                     sizeof(szPasteText),
  76.                     (PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE) );
  77.  
  78.       if (rc) {
  79.           DosBeep(100,100);
  80.           return;
  81.           } /* endif */
  82.  
  83.       hab =  WinQueryAnchorBlock( hwndMain);
  84.  
  85. //BIDI
  86. //
  87. // Load the national strings from the resource file.
  88. // These will be copied to the clipbaord.
  89. //
  90.       Offset = ARA_OFF;
  91.  
  92.       WinLoadString( hab, NULLHANDLE, IDS_COPYVISUALTEXT+Offset,
  93.                      127, szCopyVisualText);
  94.       WinLoadString( hab, NULLHANDLE, IDS_COPYIMPLICITTEXT+Offset,
  95.                      127, szCopyImplicitText);
  96.  
  97.       //
  98.       // Check if we have to SET the Clipboard Bidi Attribute
  99.       // and if so, with which value.
  100.       //
  101.       switch(SHORT1FROMMP(mp1)) {
  102.       case IDM_EDITCOPY_NOCONV:
  103.          BidiAttr     = 0L;
  104.          pText        = szCopyImplicitText;
  105.          fSetClipAttr = TRUE;
  106.          break;
  107.  
  108.       case IDM_EDITCOPY_CONV_VISUAL:
  109.          BidiAttr     = BDA_TEXTTYPE_VISUAL | BDA_INIT | BDA_LEVEL ;
  110.          pText        = szCopyVisualText;
  111.          fSetClipAttr = TRUE;
  112.          break;
  113.  
  114.       case IDM_EDITCOPY_CONV_IMPLICIT:
  115.          BidiAttr     = BDA_TEXTTYPE_IMPLICIT | BDA_INIT | BDA_LEVEL;
  116.          pText        = szCopyImplicitText;
  117.          fSetClipAttr = TRUE;
  118.          break;
  119.  
  120.       case IDM_EDITCOPY_AUTOCONV:
  121.       default:
  122.          pText        = szCopyImplicitText;
  123.          fSetClipAttr = FALSE;
  124.          break;
  125.  
  126.       }  /* end switch*/
  127.  
  128.       //
  129.       // Copy the 'relevant' text to the memory that we are
  130.       // going to hand to the clipboard.
  131.       //
  132.       strcpy(pchClipText, pText );
  133.  
  134.       /* Now, make give this text to the clipboard. */
  135.       hab =  WinQueryAnchorBlock( hwndMain);
  136.       WinOpenClipbrd  ( hab ) ;
  137.       WinEmptyClipbrd ( hab ) ;
  138.       WinSetClipbrdData ( hab, (ULONG) pchClipText, CF_TEXT, CFI_POINTER) ;
  139.  
  140.  
  141.       //
  142.       // If conversion is required, mark what kind of conversion
  143.       // (or none) is required.
  144.       //
  145.       if (fSetClipAttr)
  146.           WinSetLangInfo (NULLHANDLE,
  147.                           LI_BD_CLIP_ATTR,
  148.                           BidiAttr,
  149.                           0L,
  150.                           (ULONG)CF_TEXT,
  151.                           0L);
  152.  
  153.  
  154.       WinCloseClipbrd ( hab ) ;
  155.  
  156.  
  157. }   /*   End of EditCopy()                                              */
  158.  
  159. /*********************************************************************
  160.  *  Name: EditPaste
  161.  *
  162.  *  Description : Processes the Edit menu's Paste item.
  163.  *
  164.  *  Concepts : Called whenever Paste from the Edit menu is selected
  165.  *             Sends a MLM_PASTE message to the MLE control.
  166.  *
  167.  *  API's : WinSendMsg
  168.  *
  169.  *  Parameters : mp2 - Message parameter
  170.  *
  171.  *  Returns: Void
  172.  *
  173.  ****************************************************************/
  174. VOID EditPaste(MPARAM mp1, MPARAM mp2)
  175. {
  176.    HAB hab;
  177.    PCHAR pchClipText;
  178.    APIRET rc;
  179.    ULONG  BidiAttr;
  180.    BOOL   fSetClipConv;
  181.    PCHAR  pCompareText;
  182.    BOOL   fSuccess;
  183.  
  184.  
  185.    szPasteText[0] = '\0'; /* Init */
  186.  
  187.  
  188.    //
  189.    // Check if we have to set the 'Clipboard Conversion'
  190.    // BidiAttribute, and if so - to which value.
  191.    //
  192.    switch(SHORT1FROMMP(mp1)) {
  193.  
  194.       case IDM_EDITPASTE_NOCONV:
  195.          BidiAttr     = 0L;
  196.          fSetClipConv = TRUE;
  197.          pCompareText = szCopyImplicitText;
  198.          break;
  199.  
  200.       case IDM_EDITPASTE_CONV_VISUAL:
  201.          BidiAttr     = BDA_TEXTTYPE_VISUAL | BDA_INIT| BDA_LEVEL;
  202.          fSetClipConv = TRUE;
  203.          pCompareText = szCopyVisualText;
  204.          break;
  205.  
  206.       case IDM_EDITPASTE_CONV_IMPLICIT:
  207.          BidiAttr     = BDA_TEXTTYPE_IMPLICIT | BDA_INIT| BDA_LEVEL;
  208.          fSetClipConv = TRUE;
  209.          pCompareText = szCopyImplicitText;
  210.          break;
  211.  
  212.       case IDM_EDITPASTE_AUTOCONV:
  213.       default:
  214.          BidiAttr     = 0L;
  215.          fSetClipConv = FALSE;
  216.          pCompareText = szCopyImplicitText;
  217.  
  218.    } /* end switch */
  219.  
  220.  
  221.    hab =  WinQueryAnchorBlock( hwndMain);
  222.    WinOpenClipbrd  ( hab ) ;
  223.  
  224.    //
  225.    // Here we set (if necessary) the clipboard conversion attr
  226.    //
  227.    if (fSetClipConv == TRUE)
  228.        WinSetLangInfo (NULLHANDLE,
  229.                        LI_BD_CLIP_CONV_ATTR,
  230.                        BidiAttr,
  231.                        0L,
  232.                        (ULONG)CF_TEXT,
  233.                        0L);
  234.  
  235.  
  236.  
  237.    pchClipText =  (PCHAR) WinQueryClipbrdData (hab, CF_TEXT ) ;
  238.    if (pchClipText != 0) {
  239.  
  240.       //
  241.       // Get the clipboard text, and compare it to pCompareText.
  242.       //
  243.       strcpy(szPasteText, pchClipText);
  244.  
  245.  
  246.       //if (strcmp( szPasteText, pCompareText) != 0) {
  247.       //  fSuccess = FALSE;
  248.       //} else {
  249.       //      fSuccess = TRUE;  // Good!
  250.       //}
  251.       //
  252.       //ReportTestResult(HWND_DESKTOP, fSuccess);
  253.  
  254.    }  /* endif */
  255.  
  256.    WinCloseClipbrd ( hab ) ;
  257.  
  258.    WinInvalidateRect(hwndMain, NULL, FALSE);
  259.  
  260. }   /* End of EditPaste()                                               */
  261.  
  262.  
  263.