home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / os2tk21j / c / samples / bidi / revscr.c__ / revscr.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  7.4 KB  |  237 lines

  1. /*static char *SCCSID = "@(#)revscr.c    6.1 92/02/19";*/
  2. /*************************************************************************
  3.  * File Name     : REVSCR.C
  4.  *
  5.  * Description   : This sample program demonstrates how to use the
  6.  *                 Bidirectional (Bidi) API NlsQueryBidiAttr and
  7.  *                 NlsSetBidiAttr to change the screen and keyboard
  8.  *                 attributes of a session.
  9.  *
  10.  * API's         : NlsSetBidiAttr
  11.  *                 NlsQuerytBidiAttr
  12.  *                 VioWrtCharStr
  13.  *                 VioScrollUp
  14.  *                 VioSetCurPos
  15.  *
  16.  * Required files: To build and run this sample code the following files
  17.  *                 are needed:
  18.  *                 - REVSCR.C
  19.  *                 - REVSCR.DEF
  20.  *                 - REVSCR.MAK
  21.  *                 - REVSCR.LNK
  22.  *
  23.  *  Copyright (C) 1991 IBM Corporation
  24.  *
  25.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  26.  *      sample code created by IBM Corporation. This sample code is not
  27.  *      part of any standard or IBM product and is provided to you solely
  28.  *      for  the purpose of assisting you in the development of your
  29.  *      applications.  The code is provided "AS IS", without
  30.  *      warranty of any kind.  IBM shall not be liable for any damages
  31.  *      arising out of your use of the sample code, even if they have been
  32.  *      advised of the possibility of such damages.                                                    *
  33.  ************************************************************************/
  34. #define INCL_BASE
  35. /* Including the system return codes, will include
  36.  *the bidi return error codes as well */
  37. #define INCL_DOSERRORS
  38. /* This to include the Bidi header file */
  39. #define INCL_BDCALLS
  40.  
  41. #include <os2.h>
  42. #include <stdio.h>
  43. #include <conio.h>
  44. #include <string.h>
  45. #include <stdlib.h>
  46.  
  47. /* declairation of the functions used */
  48. VOID GetAttr(VOID);
  49. VOID SetAttr(VOID);
  50. VOID Toggle(VOID);
  51. VOID Initialize(VOID);
  52.  
  53. #define ROW 15
  54. #define COL 5
  55.  
  56. /* define the structures that are going to be used to Set and Query
  57.  * the screen and keyboard attributes   */
  58. BDKVCB bdkvcbRetAttr, bdkvcbSaveAttr;
  59.  
  60.  
  61. /*************************************************************************
  62.  * Name          : Main
  63.  *
  64.  * Description   : This is the main part of the program, it first clear
  65.  *                 the screen and then queries the screen and keyboard
  66.  *                 attributes, change it, and set it, so that the screen
  67.  *                 orientation becomes RLT.
  68.  *
  69.  * API's         : NlsSetBidiAttr
  70.  *                 VioScrollUp
  71.  *                 VioSetCurPos
  72.  *
  73.  * Parameters    : This program does not take any command line parameters
  74.  *
  75.  * Returns       : None
  76.  *
  77.  ************************************************************************/
  78. INT main(SHORT sArgc,CHAR **ppArgv)
  79. {
  80.    INT iCh,
  81.        iRow ;
  82.  
  83.    iRow = ROW;
  84.  
  85.    /* clear the screen */
  86.    VioScrollUp(0, 0, 24, 79, -1," \x07", 0);
  87.  
  88.    /* Query the screen Bidi attributes */
  89.    GetAttr();
  90.  
  91.    /* Toggle the orientation and the language layer */
  92.    Toggle();
  93.  
  94.    /* Set the new screen and keyboard attributes */
  95.    SetAttr();
  96.  
  97.    /* Set the cursor position
  98.     * Note: When running the program, watch where the cursor got set,
  99.     * and remember that the cursor setting was done after we changed
  100.     * the screen orientation */
  101.  
  102.    VioSetCurPos(iRow, COL, 0);
  103.  
  104.    /* Display some text to the screen */
  105.    Initialize();
  106.  
  107.    /* Wait for Enter to end the program */
  108.    getchar ();
  109.  
  110.    /* Clear the screen */
  111.    VioScrollUp(0, 0, 24, 79, -1," \x07", 0);
  112.  
  113.    /* Reset the screen orientation and the language layer */
  114.    NlsSetBidiAtt( 0L, (PSETINFO)&bdkvcbSaveAttr);
  115.  
  116.    return (1);
  117. } /* end of main */
  118.  
  119. /*************************************************************************
  120.  * Name          : GetAttr
  121.  *
  122.  * Description   : This function issues the NlsQueryBidiAttr to query the
  123.  *                 the screen and keyboard attributes
  124.  *
  125.  * API's         : NlsQueryBidiAttr
  126.  *
  127.  * Parameters    : (VOID)
  128.  *
  129.  * Returns       : None
  130.  *
  131.  ************************************************************************/
  132. VOID GetAttr(VOID)
  133. {
  134.    APIRET RC;                         /* used for error checking */
  135.  
  136.    /* The length here is 16 to query the Bidi attributes
  137.     *  and the Bidi flags */
  138.    bdkvcbRetAttr.BDLength = 16;
  139.  
  140.    RC = NlsQueryBidiAtt( 0L,(PRETINFO)&bdkvcbRetAttr);
  141.    if(RC != 0)
  142.    {
  143.       printf("\n\nError in query bidi attr num %d\n",RC);
  144.       exit(1);
  145.    }
  146. }
  147. /*************************************************************************
  148.  * Name          : SetAttr
  149.  *
  150.  * Description   : This function issues the NlsSetBidiAttr to set the
  151.  *                 the screen and keyboard attributes
  152.  *
  153.  * API's         : NlsQueryBidiAttr
  154.  *
  155.  * Parameters    : (VOID)
  156.  *
  157.  * Returns       : None
  158.  *
  159.  ************************************************************************/
  160. VOID SetAttr(VOID)
  161. {
  162.   APIRET RC;
  163.  
  164.    /* The length here is 16 to set the Bidi attributes
  165.     *  and the Bidi flags */
  166.    bdkvcbRetAttr.BDLength= 16;
  167.  
  168.    RC = NlsSetBidiAtt( 0L, (PSETINFO)&bdkvcbRetAttr);
  169.    if( RC != 0)
  170.    {
  171.        printf("\n\nError in set Bidi attributes: %d\n",RC);
  172.        exit(1);
  173.    }
  174. }
  175. /*************************************************************************
  176.  * Name          : Toggle
  177.  *
  178.  * Description   : This function uses the Bidi defined values in the
  179.  *                 header file BDCALLS.H to change the attributes, by
  180.  *                 the mean of the operator OR.
  181.  *                 It also saves the original settings before it does
  182.  *                 change it.
  183.  *
  184.  * API's         : None
  185.  *
  186.  * Parameters    : (VOID)
  187.  *
  188.  * Returns       : None
  189.  *
  190.  ************************************************************************/
  191. VOID Toggle(VOID)
  192. {
  193.    /* save the original Bidi attributes settings */
  194.    bdkvcbSaveAttr = bdkvcbRetAttr;
  195.  
  196.    bdkvcbRetAttr.BDAtts = bdkvcbRetAttr.BDAtts | BDORIENT_RTL;
  197.                               /* here we toggle the orientation,             */
  198.                               /* if left to right, make it right to left     */
  199.                               /* and vise versa                              */
  200.  
  201.    bdkvcbRetAttr.BDFlags = bdkvcbRetAttr.BDAtts | BDFLAG_LAYER;
  202.  
  203. }
  204. /*************************************************************************
  205.  * Name          : Initialize
  206.  *
  207.  * Description   : This function is used to display some messages on the
  208.  *                 screen
  209.  *
  210.  * API's         : VioWrtCharStr
  211.  *
  212.  * Parameters    : (VOID)
  213.  *
  214.  * Returns       : None
  215.  *
  216.  ************************************************************************/
  217. VOID Initialize(VOID)
  218. {
  219.    int iI, iCol, iRow, iLength;
  220.    struct {
  221.          char cScreen[45];
  222.          }mssg[5];
  223.    strcpy(mssg[0].cScreen, "neercs eht ,ttAidiBteSslN gnillac retfA");
  224.    strcpy(mssg[1].cScreen, "   reyal egaugnal eht dna ,LTR won si  ");
  225.    strcpy(mssg[2].cScreen, "           lanoitaN won si             ");
  226.    strcpy(mssg[3].cScreen, "  ... sretcarahc emos epyt ot yrT      ");
  227.    strcpy(mssg[4].cScreen, "    margorp eht dne ot retnE sserP     ");
  228.    iLength = strlen(mssg[0].cScreen);
  229.    iCol = 23;
  230.    iRow = 2;
  231.    for( iI = 0; iI < 3; iI++, iRow++)
  232.        VioWrtCharStr(mssg[iI].cScreen, iLength, iRow, iCol, 0l);
  233.  
  234.        VioWrtCharStr(mssg[3].cScreen, iLength, 8, iCol, 0l);
  235.        VioWrtCharStr(mssg[4].cScreen, iLength, 23, iCol, 0l);
  236. }
  237.