home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / filedlg5 / source / fitpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-08  |  4.1 KB  |  91 lines

  1. /****************************************************************************
  2.  * PSZ FitPathToBox( HWND hDlg,USHORT idText,PSZ pszPath );                 *
  3.  * Purpose                  This function modifies the input                *
  4.  *                          drive:\directory string so that it              *
  5.  *                          fits within the bounds of the specified         *
  6.  *                          static text control.                            *
  7.  *                                                                          *
  8.  * Parameters               hDlg is a handle to the dialog box.             *
  9.  *                                                                          *
  10.  *                          idText is the static text control id.           *
  11.  *                                                                          *
  12.  *                          pszPath is a pointer to the drive:\directory    *
  13.  *                          string that is to be modified.                  *
  14.  *                                                                          *
  15.  * Return Value             The function returns a pointer to the           *
  16.  *                          modified path string.                           *
  17.  *                                                                          *
  18.  *                                                                          *
  19.  * Modifications -                                                          *
  20.  *      17-Aug-1989 : Initial version.                                      *
  21.  *                                                                          *
  22.  * (c)Copyright 1989 Rick Yoder                                             *
  23.  ****************************************************************************/
  24.  
  25.     #define INCL_WINWINDOWMGR
  26.     #define INCL_WINMESSAGEMGR
  27.     #define INCL_GPIPRIMITIVES
  28.     #include <os2.h>
  29.     #include <string.h>
  30.     #include "tools.h"
  31.     #include "static.h"
  32.  
  33. /****************************************************************************
  34.  * Internal function declarations                                           *
  35.  ****************************************************************************/
  36.     static LONG near GetTextExtent( HPS hps,PCH pchStr,USHORT cch );
  37. /****************************************************************************/
  38.  
  39.  
  40. /****************************************************************************/
  41.     PSZ FitPathToBox( HWND hDlg,USHORT idText,PSZ pszPath )
  42.     {
  43.         RECTL   rc;
  44.         LONG    cxField;
  45.         HPS     hps;
  46.         CHAR    chDrive;
  47.  
  48.     /* get length of static field */
  49.         WinQueryWindowRect( WinWindowFromID(hDlg,idText),(PRECTL)&rc );
  50.         cxField = rc.xRight - rc.xLeft;
  51.  
  52.         hps = WinGetPS(hDlg);
  53.         if ( cxField < GetTextExtent(hps,pszPath,strlen(pszPath)) )
  54.             {
  55.             chDrive = *pszPath;
  56.  
  57.             /* chop characters off front of string until text is short enough */
  58.             do
  59.                 {
  60.                 do
  61.                     if ( *pszPath ) pszPath++;
  62.                 while ( pszPath[6] != '\\' && pszPath[6] != '\0' );
  63.                 *pszPath = chDrive;
  64.                 memcpy( pszPath+1,szFitReplace,5 );
  65.                 }
  66.             while ( cxField < GetTextExtent(hps,pszPath,strlen(pszPath)) );
  67.             }
  68.  
  69.         WinReleasePS(hps);
  70.         return pszPath;
  71.     }
  72. /****************************************************************************/
  73.  
  74.  
  75. /****************************************************************************
  76.  * GetTextExtent() - Get width of the text box for the input string.        *
  77.  ****************************************************************************/
  78.     static LONG near GetTextExtent( HPS hps,PCH pchStr,USHORT cch )
  79.     {
  80.         POINTL aptl[TXTBOX_COUNT];
  81.  
  82.         if ( cch )
  83.             {
  84.             GpiQueryTextBox( hps,(LONG)cch,pchStr,TXTBOX_COUNT,aptl );
  85.             return (aptl[TXTBOX_CONCAT].x - aptl[TXTBOX_BOTTOMLEFT].x);
  86.             }
  87.         else
  88.             return 0L;
  89.     }
  90. /****************************************************************************/
  91.