home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / tlktbeta / samples / textfldr / textfldr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-12  |  14.0 KB  |  405 lines

  1.  
  2. /*
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: textfldr.c.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitc: 1.24
  8.  */
  9.  
  10. /*
  11.  *
  12.  *
  13.  *   Module Name: TEXTFLDR
  14.  *
  15.  *   OS/2 Work Place Shell Sample Program
  16.  *
  17.  *   Copyright (C) 1993 IBM Corporation
  18.  *
  19.  *       DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  20.  *       sample code created by IBM Corporation. This sample code is not
  21.  *       part of any standard or IBM product and is provided to you solely
  22.  *       for  the purpose of assisting you in the development of your
  23.  *       applications.  The code is provided "AS IS", without
  24.  *       warranty of any kind.  IBM shall not be liable for any damages
  25.  *       arising out of your use of the sample code, even if they have been
  26.  *       advised of the possibility of such damages.
  27.  *
  28.  */
  29.  
  30.  
  31. #define TextFolder_Class_Source
  32. #include "textfldr.ih"
  33.  
  34. /*
  35.  *
  36.  *  METHOD: IsTextFile                                     (X) PRIVATE
  37.  *                                                         ( ) PUBLIC
  38.  *  DESCRIPTION:
  39.  *
  40.  *    This method checks the first 'n' characters of a file to determine
  41.  *    if it is or is not text. This method is invoked by the
  42.  *    ValidateDragAndDrop method. It is invoked only if no type is specified
  43.  *    for the object being manipulated.  A file is considered to be text if
  44.  *    the first 'n' bytes are in the range of ASCII 32 (20 Hex) to ASCII 126
  45.  *    (7E Hex), or is a carriage return (ASCII 10, Hex 0A), line feed
  46.  *    (ASCII 13, Hex 0D), tab (ASCII 8, HEX 08), or end of file marker
  47.  *    (ASCII 26, Hex 1A).
  48.  *
  49.  *    NOTE: The value used for 'n' is stored in the variable ulSampleSize
  50.  *    which is local to the IsTextFile method.
  51.  *
  52.  *  RETURN:
  53.  *
  54.  *    TRUE  - the object is a text file.
  55.  *    FALSE - the object is not a text file.
  56.  *
  57.  *  HOW TO OVERRIDE:
  58.  *
  59.  *    n/a
  60.  *
  61.  */
  62.  
  63. SOM_Scope BOOL   SOMLINK TextFolderwps_IsTextFile(TextFolder *somSelf,
  64.                 PSZ pszFileName)
  65. {
  66.     ULONG   Action;              /* The action performed on the file */
  67.     HFILE   hFile;               /* The file handle */
  68.     ULONG   ulSampleSize = 500L; /* Number of bytes to test */
  69.     ULONG   ulBytesRead;         /* Number of sample bytes read */
  70.     ULONG   ulCount;             /* Counter variable */
  71.     PSZ     pszSample = NULL;    /* The sample buffer */
  72.     CHAR    cChar;               /* Current character from sample buffer */
  73.     APIRET  aRC;                 /* Return code from API calls */
  74.     BOOL    bRC = FALSE;         /* True - it is a text file */
  75.                                  /* False - it isn't not a text file */
  76.  
  77.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  78.     TextFolderMethodDebug("TextFolder","TextFolderwps_IsTextFile");
  79.  
  80.  
  81.     /* Open the file that contains the object */
  82.     if( NO_ERROR != ( aRC=DosOpen( pszFileName,        /* File path name */
  83.                              &hFile,                   /* File handle */
  84.                              &Action,                  /* Action taken */
  85.                              0L,                       /* File size */
  86.                              FILE_NORMAL,              /* File attribute */
  87.                              OPEN_ACTION_FAIL_IF_NEW | /* Open function type */
  88.                              OPEN_ACTION_OPEN_IF_EXISTS,
  89.                              OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYNONE |
  90.                              OPEN_ACCESS_READONLY, 0L)))
  91.        somPrintf( "Unable to open file %s (%ld)\r\n", pszFileName, aRC);
  92.  
  93.     else{
  94.  
  95.        /* Allocate buffer for reading a sample of the object into. */
  96.        if( NO_ERROR != (aRC = DosAllocMem( (PPVOID)&pszSample, ulSampleSize,
  97.                                            PAG_COMMIT | PAG_READ | PAG_WRITE)))
  98.           somPrintf( "Unable to allocate buffer of %ld bytes (%ld)\r\n",
  99.                                                             ulSampleSize, aRC);
  100.        else{
  101.  
  102.           if( NO_ERROR != ( aRC = DosRead( hFile, pszSample, ulSampleSize,
  103.                                                                &ulBytesRead)))
  104.              somPrintf( "Unable to read %ld bytes from file %s (%ld)\r\n",
  105.                                                ulSampleSize, pszFileName, aRC);
  106.           else{
  107.  
  108.              /* Check all the characters read in the sample buffer */
  109.              for( ulCount=0, bRC=TRUE; (ulCount<ulBytesRead) && (bRC == TRUE);
  110.                                                                     ulCount++){
  111.  
  112.                 cChar = pszSample[ ulCount];
  113.  
  114.                 /* Make sure the characters are text characters,   */
  115.                 /* carriage return, line feed, tab, or end of file */
  116.  
  117.                 if( ((cChar < FIRST_TEXT_CHAR) || (cChar > LAST_TEXT_CHAR)) &&
  118.                    (cChar != CHAR_CARRIAGE_RETURN) && (cChar != CHAR_LINE_FEED)
  119.                         && (cChar != CHAR_TAB) && (cChar != CHAR_END_OF_FILE)){
  120.                     bRC = FALSE;
  121.                 }
  122.              }
  123.           }
  124.  
  125.           /* Clean up */
  126.           DosFreeMem( pszSample);
  127.           DosClose( hFile);
  128.        }
  129.     }
  130.  
  131.     return( bRC);
  132. }
  133.  
  134. /*
  135.  *
  136.  *  METHOD: ValidateDragAndDrop                            (X) PRIVATE
  137.  *                                                         ( ) PUBLIC
  138.  *  DESCRIPTION:
  139.  *
  140.  *    This method determines if an object can be dragged/dropped on the
  141.  *    TextFolder. It is invoked by the wpDrag and wpDragOver methods.
  142.  *
  143.  *    The ValidateDragAndDrop method first checks the type of the object
  144.  *    being manipulated. If a type is specified, and it is Plain Text,
  145.  *    the operation is considered to be valid. If a type is specified and
  146.  *    it is not Plain Text the operation is considered invalid. If no
  147.  *    type is specified the IsTextFile() method is invoked to determine
  148.  *    if the object is or is not a text object.
  149.  *
  150.  *  RETURN:
  151.  *
  152.  *    TRUE  - The object can be dragged/dropped on the TextFolder.
  153.  *    FALSE - The object can not be dragged/dropped on the TextFolder.
  154.  *
  155.  *  HOW TO OVERRIDE:
  156.  *
  157.  *    n/a
  158.  *
  159.  */
  160.  
  161. SOM_Scope BOOL   SOMLINK TextFolderwps_ValidateDragAndDrop(TextFolder *somSelf,
  162.                 PDRAGINFO pdrgInfo)
  163. {
  164.     CHAR    pszBuffer[ 255];     // Buffer for file system object name
  165.     ULONG   ulNumberOfObjects;   // Number of object draged over object
  166.     ULONG   ulCurrentObject;     // Used to increment list of objects
  167.     BOOL    bObjectType;         // Type of object
  168.  
  169.     PDRAGITEM pDragItem;
  170.  
  171.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  172.     TextFolderMethodDebug("TextFolder","TextFolderwps_ValidateDragAndDrop");
  173.  
  174.     /* Get the number of objects being dragged */
  175.     ulNumberOfObjects = DrgQueryDragitemCount( pdrgInfo);
  176.  
  177.     /* Test each object */
  178.     for( ulCurrentObject = 0; ulCurrentObject<ulNumberOfObjects;
  179.                                                             ulCurrentObject++){
  180.         pDragItem = DrgQueryDragitemPtr( pdrgInfo, ulCurrentObject);
  181.  
  182.         /* If the object isn't Plain Text check to see if any type is */
  183.         /* associated with the object. If no type is associated then  */
  184.         /* check the contents of the file to see if it is text only.  */
  185.         if( FALSE == DrgVerifyType( pDragItem, DRT_TEXT)){
  186.  
  187.             /* If the associated type is known, this isn't a text      */
  188.             /* object. If it isn't known, check the object's contents. */
  189.             bObjectType = DrgVerifyType( pDragItem, "Reserved");
  190.  
  191.             /* Get the path */
  192.             DrgQueryStrName( pDragItem->hstrContainerName, sizeof( pszBuffer),
  193.                                                                     pszBuffer);
  194.             /* Append the name of the object to the path */
  195.             DrgQueryStrName( pDragItem->hstrSourceName,
  196.                                        sizeof( pszBuffer) - strlen( pszBuffer),
  197.                                               &pszBuffer[ strlen( pszBuffer)]);
  198.  
  199.             /* If a type was specified, it isn't Plain Text. */
  200.             /* If no type was specified check if it is a text file. */
  201.             if( bObjectType == FALSE || ( bObjectType == TRUE &&
  202.                                  FALSE == _IsTextFile( somSelf, pszBuffer)) ){
  203.  
  204.                 somPrintf( "This is not a Plain Text object. ");
  205.                 DrgQueryStrName( pDragItem->hstrType, sizeof( pszBuffer),
  206.                                                                     pszBuffer);
  207.                 somPrintf( "The types for this object are: '%s'\n", pszBuffer);
  208.  
  209.                 return( FALSE);
  210.             }
  211.         }
  212.     }
  213.  
  214.     return( TRUE);
  215. }
  216.  
  217. /*
  218.  *
  219.  *   METHOD: wpFilterPopupMenu                              ( ) PRIVATE
  220.  *                                                          (X) PUBLIC
  221.  *   DESCRIPTION:
  222.  *
  223.  *     Removes the Tree view option from the Open popup menu.
  224.  *
  225.  */
  226.  
  227. SOM_Scope ULONG   SOMLINK TextFolderwps_wpFilterPopupMenu(TextFolder *somSelf,
  228.                 ULONG ulFlags,
  229.                 HWND hwndCnr,
  230.                 BOOL fMultiSelect)
  231. {
  232.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  233.     TextFolderMethodDebug("TextFolder","TextFolderwps_wpFilterPopupMenu");
  234.  
  235.     ulFlags = parent_wpFilterPopupMenu(somSelf,ulFlags,hwndCnr,fMultiSelect);
  236.  
  237.     /* Remove the tree view menu option and make sure delete is available */
  238.     return ( ( ulFlags | CTXT_DELETE) & ~CTXT_TREE);
  239. }
  240.  
  241. /*
  242.  *
  243.  *   METHOD: wpAddFolderView2Page                           ( ) PRIVATE
  244.  *                                                          (X) PUBLIC
  245.  *   DESCRIPTION:
  246.  *
  247.  *     Removes the tree view settings page for the TextFolder.
  248.  *
  249.  */
  250.  
  251. SOM_Scope ULONG   SOMLINK TextFolderwps_wpAddFolderView2Page(TextFolder *somSelf,
  252.                 HWND hwndNotebook)
  253. {
  254.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  255.     TextFolderMethodDebug("TextFolder","TextFolderwps_wpAddFolderView2Page");
  256.  
  257.     return( SETTINGS_PAGE_REMOVED);
  258. }
  259.  
  260. /*
  261.  *
  262.  *   METHOD: wpAddFolderIncludePage                         ( ) PRIVATE
  263.  *                                                          (X) PUBLIC
  264.  *   DESCRIPTION:
  265.  *
  266.  *     Removes the Include Page from the TextFolder's settings.
  267.  *
  268.  */
  269.  
  270. SOM_Scope ULONG   SOMLINK TextFolderwps_wpAddFolderIncludePage(TextFolder *somSelf,
  271.                 HWND hwndNotebook)
  272. {
  273.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  274.     TextFolderMethodDebug("TextFolder","TextFolderwps_wpAddFolderIncludePage");
  275.  
  276.     return ( SETTINGS_PAGE_REMOVED);
  277. }
  278.  
  279. /*
  280.  *
  281.  *   METHOD: wpDragOver                                     ( ) PRIVATE
  282.  *                                                          (X) PUBLIC
  283.  *   DESCRIPTION:
  284.  *
  285.  *     Allows or disallows an object to be dragged over the TextFolder.
  286.  *
  287.  */
  288.  
  289. SOM_Scope MRESULT   SOMLINK TextFolderwps_wpDragOver(TextFolder *somSelf,
  290.                 HWND hwndCnr,
  291.                 PDRAGINFO pdrgInfo)
  292. {
  293.     MRESULT mResult;
  294.  
  295.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  296.     TextFolderMethodDebug("TextFolder","TextFolderwps_wpDragOver");
  297.  
  298.     mResult = parent_wpDragOver(somSelf,hwndCnr,pdrgInfo);
  299.  
  300.     /* If the parent said it is okay to drop then we will check it also. */
  301.     if( DOR_NEVERDROP != SHORT1FROMMR( mResult)){
  302.  
  303.         /* If the object is acceptable, return the mResult from the parent */
  304.         if( FALSE == _ValidateDragAndDrop( somSelf, pdrgInfo))
  305.             mResult = MRFROM2SHORT( DOR_NEVERDROP, DO_UNKNOWN);
  306.     }
  307.  
  308.     return ( mResult);
  309. }
  310.  
  311. /*
  312.  *
  313.  *   METHOD: wpDrop                                         ( ) PRIVATE
  314.  *                                                          (X) PUBLIC
  315.  *   DESCRIPTION:
  316.  *
  317.  *     Allows or disallows an object to be dropped on the TextFolder.
  318.  *
  319.  */
  320.  
  321. SOM_Scope MRESULT   SOMLINK TextFolderwps_wpDrop(TextFolder *somSelf,
  322.                 HWND hwndCnr,
  323.                 PDRAGINFO pdrgInfo,
  324.                 PDRAGITEM pdrgItem)
  325. {
  326.     MRESULT mResult;
  327.  
  328.     /* TextFolderData *somThis = TextFolderGetData(somSelf); */
  329.     TextFolderMethodDebug("TextFolder","TextFolderwps_wpDrop");
  330.  
  331.     mResult = parent_wpDrop(somSelf,hwndCnr,pdrgInfo,pdrgItem);
  332.  
  333.     /* If the parent said it is okay to drop then we will check it also */
  334.     if( DOR_NEVERDROP != SHORT1FROMMR( mResult)){
  335.  
  336.  
  337.         /* Validate the objects */
  338.         if( FALSE == _ValidateDragAndDrop( somSelf, pdrgInfo))
  339.             mResult = MRFROM2SHORT( DOR_NEVERDROP, DO_UNKNOWN);
  340.     }
  341.  
  342.     return ( mResult);
  343. }
  344.  
  345. #undef SOM_CurrentClass
  346. #define SOM_CurrentClass SOMMeta
  347. /*
  348.  *
  349.  *  METHOD: wpclsQueryTitle
  350.  *
  351.  *  DESCRIPTION:
  352.  *
  353.  *    Provides a default name of Text Folder for TextFolder.
  354.  *
  355.  */
  356.  
  357. SOM_Scope PSZ   SOMLINK TextFolderM_wpclsQueryTitle(M_TextFolder *somSelf)
  358. {
  359.     /* M_TextFolderData *somThis = M_TextFolderGetData(somSelf); */
  360.     M_TextFolderMethodDebug("M_TextFolder","TextFolderM_wpclsQueryTitle");
  361.  
  362.     return ( "Text Folder");
  363. }
  364.  
  365. /*
  366.  *
  367.  *  METHOD: wpclsQueryIconData
  368.  *
  369.  *  DESCRIPTION:
  370.  *
  371.  *    Provides an icon for the TextFolder.
  372.  *
  373.  */
  374.  
  375. SOM_Scope ULONG   SOMLINK TextFolderM_wpclsQueryIconData(M_TextFolder *somSelf,
  376.                 PICONINFO pIconInfo)
  377. {
  378.     static HMODULE hModule = NULLHANDLE;
  379.     PSZ            pszLibraryName;
  380.  
  381.     /* M_TextFolderData *somThis = M_TextFolderGetData(somSelf); */
  382.     M_TextFolderMethodDebug("M_TextFolder","TextFolderM_wpclsQueryIconData");
  383.  
  384.     /* Only get the handle once */
  385.     if( (hModule == NULLHANDLE) && pIconInfo){
  386.  
  387.        /* Get the name of the library so we can get it's handle. */
  388.        if( NULL != ( pszLibraryName = _somLocateClassFile( SOMClassMgrObject,
  389.                       SOM_IdFromString( "TextFolder"), TextFolder_MajorVersion,
  390.                                                      TextFolder_MinorVersion)))
  391.  
  392.            /* Get the handle for the library. */
  393.            DosQueryModuleHandle( pszLibraryName, &hModule);
  394.     }
  395.  
  396.     if( pIconInfo){
  397.  
  398.        pIconInfo->fFormat = ICON_RESOURCE;
  399.        pIconInfo->resid   = ID_ICON;
  400.        pIconInfo->hmod    = hModule;
  401.     }
  402.  
  403.     return ( sizeof( ICONINFO));
  404. }
  405.