home *** CD-ROM | disk | FTP | other *** search
/ The Best Internet Programs / BESTINTERNET.bin / internet / winftp / ws_child.c < prev    next >
C/C++ Source or Header  |  1994-01-11  |  29KB  |  795 lines

  1. /***************************************************************************
  2.   Windows Sockets FTP Client Application Support Module
  3.  
  4.   Written by:
  5.      Santanu Lahiri              Internet: slahiri@magnus.acs.ohio-state.edu
  6.  
  7. Converted the Create Buttons calls to simulated buttons.  Added necessary
  8. WM_PAINT code to handle displaying the buttons in the appropriate mode
  9.  
  10. Added the ComboBox "History" feature.
  11.  
  12. Cleaned up WM_PAINT code that was eating resources - Deselected created
  13. brushes and pens before the hdc was released.
  14.  
  15. *****************************************************************************/
  16. /*
  17.   MODULE: WS_CHILD.C  (child window functions)
  18. */
  19.  
  20. #include "ws_glob.h"
  21. #include "winftp.H"
  22. #include <dos.h>
  23. #include <ctype.h>
  24.  
  25. #define WS_CHILDSTYLE  WS_CHILD|WS_VISIBLE
  26. #define LBS_STYLE      LBS_STANDARD|WS_VSCROLL|WS_CHILDSTYLE|LBS_NOTIFY|LBS_NOINTEGRALHEIGHT
  27. #define WS_TXTSTYLE    WS_CHILDSTYLE|SS_LEFTNOWORDWRAP
  28. #define WS_RADIOSTYLE  WS_CHILDSTYLE|BS_RADIOBUTTON
  29. #define CBS_STYLE      WS_CHILDSTYLE|WS_VSCROLL|CBS_DROPDOWNLIST|CBS_HASSTRINGS|CBS_SORT
  30. #define SBV_STYLE      WS_CHILDSTYLE|SBS_VERT|WS_VISIBLE
  31. #define EDT_STYLE      WS_CHILDSTYLE|WS_BORDER|ES_AUTOHSCROLL
  32.  
  33. #define XSIZ(x) (x*nWndx)/4
  34. #define YSIZ(x) (x*nWndy)/8
  35.  
  36. #ifdef WIN32
  37.    #define MAXLINES 150
  38. #else
  39.    #define MAXLINES 100
  40. #endif
  41.  
  42. #define STATLEN  151
  43.  
  44. char *lpStatusLines=NULL;
  45. int nStatusPtr=0;
  46. int nStatusScroll=1;
  47.  
  48. RECT rcMsg;
  49.  
  50. BOOL bCanMKD,bCanRMD,bCanREN,bCanDELE,bIsQVT,bIsNCSA,bIs5000,bIsDual;
  51. BOOL bHELP=FALSE;
  52.  
  53. LPSTR lpListBox = "listbox";
  54. LPSTR lpButton  = "button";
  55. LPSTR lpStatic  = "static";
  56. LPSTR lpEdit    = "edit";
  57. LPSTR lpComboBox= "combobox";
  58. LPSTR lpScroll  = "scrollbar";
  59. LPSTR lpChgDir  = "ChgDir";
  60. LPSTR lpMkDir   = "MkDir";
  61. LPSTR lpRmDir   = "RmDir";
  62. LPSTR lpRefresh = "Refresh";
  63. LPSTR lpDisplay = "Display";
  64. LPSTR lpRename  = "Rename";
  65. LPSTR lpDelete  = "Delete";
  66. LPSTR lpConnect = "Connect";
  67. LPSTR lpClose   = "Close";
  68. LPSTR lpLongDir = "LongDir";
  69. LPSTR lpAbort   = "Abort";
  70. LPSTR lpOptions = "Options";
  71. LPSTR lpAbout   = "About";
  72. LPSTR lpExit    = "Exit";
  73. LPSTR lpToRemote= "-->";
  74. LPSTR lpToLocal = "<--";
  75.  
  76. typedef struct
  77. {
  78.   LPSTR *lpBtnTxt;
  79.   RECT rcBtn;
  80.   int nBtnID, nStat;
  81.   int nTxtx, nTxty;
  82.   int nSendMsg;
  83.   RECT rcExt;
  84. } BTNPOS;
  85.  
  86. static RECT rcLEdt, rcREdt, rcLLst, rcRLst, rcLDir, rcLFile, rcRDir, rcRFile;
  87.  
  88. #define  BUTTONS   23
  89.  
  90. BOOL bEnabled[BUTTONS];
  91.  
  92. BTNPOS bpButton[BUTTONS] = 
  93. {  
  94.   &lpChgDir,  {  84,  32, 26, 13}, BTN_LCHANGE,         0, 0, 0, 0, {0, 0, 0, 0},
  95.   &lpMkDir,   {  84,  46, 26, 13}, BTN_LMKDIR,          0, 0, 0, 0, {0, 0, 0, 0},
  96.   &lpRmDir,   {  84,  60, 26, 13}, BTN_LRMDIR,          0, 0, 0, 0, {0, 0, 0, 0},
  97.   &lpRefresh, {  84,  84, 26, 13}, BTN_LREFRESH,        0, 0, 0, 0, {0, 0, 0, 0},
  98.   &lpDisplay, {  84, 107, 26, 13}, BTN_LDISPLAY,        0, 0, 0, 0, {0, 0, 0, 0},
  99.   &lpRename,  {  84, 121, 26, 13}, BTN_LRENAME,         0, 0, 0, 0, {0, 0, 0, 0},
  100.   &lpDelete,  {  84, 135, 26, 13}, BTN_LDELETE,         0, 0, 0, 0, {0, 0, 0, 0},
  101.   &lpChgDir,  { 213,  32, 26, 13}, BTN_RCHANGE,         0, 0, 0, 0, {0, 0, 0, 0},
  102.   &lpMkDir,   { 213,  46, 26, 13}, BTN_RMKDIR,          0, 0, 0, 0, {0, 0, 0, 0},
  103.   &lpRmDir,   { 213,  60, 26, 13}, BTN_RRMDIR,          0, 0, 0, 0, {0, 0, 0, 0},
  104.   &lpRefresh, { 213,  84, 26, 13}, BTN_RREFRESH,        0, 0, 0, 0, {0, 0, 0, 0},
  105.   &lpDisplay, { 213, 107, 26, 13}, BTN_RDISPLAY,        0, 0, 0, 0, {0, 0, 0, 0},
  106.   &lpRename,  { 213, 121, 26, 13}, BTN_RRENAME,         0, 0, 0, 0, {0, 0, 0, 0},
  107.   &lpDelete,  { 213, 135, 26, 13}, BTN_RDELETE,         0, 0, 0, 0, {0, 0, 0, 0},
  108.   &lpToLocal, { 116, 101, 14, 13}, BTN_REMOTE_TO_LOCAL, 0, 0, 0, 0, {0, 0, 0, 0},
  109.   &lpToRemote,{ 116, 118, 14, 13}, BTN_LOCAL_TO_REMOTE, 0, 0, 0, 0, {0, 0, 0, 0},
  110.   &lpConnect, {   4, 185, 32,  9}, BTN_CONNECT,         0, 0, 0, 0, {0, 0, 0, 0},
  111.   &lpClose,   {  38, 185, 32,  9}, BTN_CLOSE,           0, 0, 0, 0, {0, 0, 0, 0},
  112.   &lpLongDir, {  72, 185, 32,  9}, BTN_LONG,            0, 0, 0, 0, {0, 0, 0, 0},
  113.   &lpAbort,   { 106, 185, 34,  9}, BTN_ABORT,           0, 0, 0, 1, {0, 0, 0, 0},
  114.   &lpOptions, { 142, 185, 32,  9}, BTN_OPTION,          0, 0, 0, 0, {0, 0, 0, 0},
  115.   &lpAbout,   { 176, 185, 32,  9}, BTN_ABOUT,           0, 0, 0, 0, {0, 0, 0, 0},
  116.   &lpExit,    { 210, 185, 32,  9}, BTN_EXIT,            0, 0, 0, 0, {0, 0, 0, 0} 
  117. };
  118.  
  119. //*********************************************************************
  120. //  Create the Button positions array.  Compute the actual screen sizes
  121. //  and the screen text positions based on the initial button position
  122. //  and size.  Use the actual screen size of text to locate it in a button.
  123. //*********************************************************************
  124. void CreateButtonPos (HWND hWnd)
  125. {
  126.   HDC hdc;
  127.   DWORD dwExt;
  128.   RECT rc;
  129.   int nI, cExt, cHt;
  130.  
  131. #ifdef WIN32
  132.   SIZE sizeStr;
  133. #endif
  134.   
  135.   hdc = GetDC (hWnd);
  136.   SelectObject (hdc, GetStockObject (ANSI_VAR_FONT));   //  This allows actual size calc.
  137.  
  138.   for (nI=0; nI<sizeof (bpButton)/sizeof (BTNPOS); nI++)
  139.   {
  140.     bEnabled[nI] = TRUE;
  141.  
  142. #ifdef WIN32
  143.     dwExt = GetTextExtentPoint (hdc, *bpButton[nI].lpBtnTxt, lstrlen (*bpButton[nI].lpBtnTxt), &sizeStr);
  144.     cExt = sizeStr.cx;                 //  Length of screen text
  145.     cHt  = sizeStr.cy;                 //  Height of screen text
  146. #else
  147.     dwExt = GetTextExtent (hdc, *bpButton[nI].lpBtnTxt, lstrlen (*bpButton[nI].lpBtnTxt));
  148.     cExt = LOWORD (dwExt);                 //  Length of screen text
  149.     cHt  = HIWORD (dwExt);                 //  Height of screen text
  150. #endif
  151.     
  152.     rc = bpButton[nI].rcExt = bpButton[nI].rcBtn;  //  Copy button size for later use
  153.     rc.right += rc.left;                   //  Compute screen right bound
  154.     rc.bottom+= rc.top;                    //  Compute screen lower bound
  155.     rc.left   = (rc.left   * nWndx) / 4;   //  Convert to MM_TEXT pixel count
  156.     rc.top    = (rc.top    * nWndy) / 8;
  157.     rc.right  = (rc.right  * nWndx) / 4;
  158.     rc.bottom = (rc.bottom * nWndy) / 8;
  159.     bpButton[nI].rcBtn = rc;               //  Save the computed sizes.
  160.     bpButton[nI].nTxtx = (rc.left+rc.right-cExt)/2;  //  Compute the text position
  161.     bpButton[nI].nTxty = (rc.top+rc.bottom-cHt)/2;   //  horizontal and vertical both.
  162.   }
  163.   
  164.   rcMsg.top    = YSIZ (164);
  165.   rcMsg.bottom = YSIZ (179);
  166.   rcMsg.left   = XSIZ (8);
  167.   rcMsg.right  = XSIZ (228);
  168.   
  169.   ReleaseDC (hWnd, hdc);    //  Done here, release resources.
  170. }
  171.  
  172. //*********************************************************************
  173. //*********************************************************************
  174. void CreateListRectPos (LPRECT rcLDir, int nX, int nY, int nExt, int nH)
  175. {
  176.   rcLDir->left  = nX;
  177.   rcLDir->top   = nY;
  178.   rcLDir->right = nX+nExt-1;
  179.   rcLDir->bottom= nY+nH-1;
  180. }
  181.  
  182. //*********************************************************************
  183. //*********************************************************************
  184. int GetChildWindowID (LPARAM lParam)
  185. {
  186.   POINT pt;
  187.   BOOL bFlag = (pt.y > rcLLst.bottom);
  188.  
  189.   pt.y = HIWORD (lParam);
  190.   pt.x = LOWORD (lParam);
  191.   if (PtInRect (&rcLFile, pt)) return LST_LFILES;
  192.   if (PtInRect (&rcRFile, pt)) return LST_RFILES;
  193.   if (PtInRect (&rcLDir, pt)) return LST_LDIRS;
  194.   if (PtInRect (&rcRDir, pt)) return LST_RDIRS;
  195.   if (PtInRect (&rcLLst, pt)) return LST_LDIRLST;
  196.   if (PtInRect (&rcRLst, pt)) return LST_RDIRLST;
  197.   if (PtInRect (&rcLEdt, pt)) return EDT_LFILETYPE;
  198.   if (PtInRect (&rcREdt, pt)) return EDT_RFILETYPE;
  199.   
  200.   return 0;
  201. }
  202.  
  203. //*********************************************************************
  204. //*********************************************************************
  205. int CreateSubWindows(HWND hParent,HWND hInst)
  206. {
  207.   HFONT hFont = GetStockObject (ANSI_VAR_FONT);
  208.   int nX1, nX2, nY1, nY2, nH1, nH2, nExt;
  209.  
  210.   CreateButtonPos (hParent);  //  Create the button screen positions.
  211.   
  212.   nExt= XSIZ ( 28);           //  Editbox Extent
  213.   nX1 = XSIZ ( 81);           //  Local File Type position
  214.   nX2 = XSIZ (210);           //  Remote File Type position
  215.   nY1 = YSIZ (  6);           //  EditBox Y position
  216.   nH1