home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DRGDRO.ZIP / DRAGINFO.ZIP / DRAGDLG.C next >
Text File  |  1993-04-06  |  13KB  |  433 lines

  1. /***************************************************************************/
  2. /* Dialog module for DRAGINFO                                              */
  3. /***************************************************************************/
  4. #include "draginfo.h"
  5.  
  6.  
  7. static char *apcReturn[][2] = {
  8.    { "DRR_SOURCE",  (char *)DRR_SOURCE },
  9.    { "DRR_TARGET",  (char *)DRR_TARGET },
  10.    { "DRR_ABORT",   (char *)DRR_ABORT },
  11.    { NULL, NULL }
  12. };
  13.  
  14. static char *apcControl[][2] = {
  15.    { "DC_OPEN",              (char *)DC_OPEN },
  16.    { "DC_REF",               (char *)DC_REF },
  17.    { "DC_GROUP",             (char *)DC_GROUP },
  18.    { "DC_CONTAINER",         (char *)DC_CONTAINER },
  19.    { "DC_PREPARE",           (char *)DC_PREPARE },
  20.    { "DC_REMOVEABLEMEDIA",   (char *)DC_REMOVEABLEMEDIA },
  21.    { NULL, NULL }
  22. };
  23. static char *apcOperations[][2] = {
  24.   {"DO_DEFAULT", (char *)DO_DEFAULT },
  25.   {"DO_UNKNOWN", (char *)DO_UNKNOWN },
  26.   {"DO_COPY",    (char *)DO_COPY },
  27.   {"DO_LINK",    (char *)DO_LINK },
  28.   {"DO_MOVE",    (char *)DO_MOVE },
  29.   {"DO_CREATE",  (char *)DO_CREATE },
  30.   { NULL, NULL }
  31. };
  32. static char *apcTypes[][2] = {
  33.   {"DRT_TEXT",               "Plain Text"},
  34.   {"DRT_TEXT(wps)",          "DRT_TEXT"},
  35.   {"DRT_UNKNOWN",            "Unknown"},
  36.   {"DRT_ASM",                "Assembler Code"},
  37.   {"DRT_BASIC",              "BASIC Code"},
  38.   {"DRT_BINDATA",            "Binary Data"},
  39.   {"DRT_BITMAP",             "Bitmap"},
  40.   {"DRT_C",                  "C Code"},
  41.   {"DRT_COBOL",              "COBOL Code"},
  42.   {"DRT_DLL",                "Dynamic Link Library"},
  43.   {"DRT_DOSCMD",             "DOS Command File"},
  44.   {"DRT_EXE",                "Executable"},
  45.   {"DRT_FORTRAN",            "FORTRAN Code"},
  46.   {"DRT_ICON",               "Icon"},
  47.   {"DRT_LIB",                "Library"},
  48.   {"DRT_METAFILE",           "Metafile"},
  49.   {"DRT_OS2CMD",             "OS/2 Command File"},
  50.   {"DRT_PASCAL",             "Pascal Code"},
  51.   {"DRT_RESOURCE",           "Resource File"},
  52.   { NULL, NULL }
  53. };
  54. static char *apcMechanisms[] = {
  55.   "DRM_OS2FILE",
  56.   "DRM_PRINT",
  57.   "DRM_DISCARD",
  58.   "DRM_DDE",
  59.   "DRM_OBJECT",
  60.   NULL
  61. };
  62. static char *apcFormats[] = {
  63.   "DRF_TEXT",
  64.   "DRF_UNKNOWN",
  65.   "DRF_OBJECT",
  66.   "DRF_BITMAP",
  67.   "DRF_DIB",
  68.   "DRF_DIF",
  69.   "DRF_DSPBITMAP",
  70.   "DRF_METAFILE",
  71.   "DRF_OEMTEXT",
  72.   "DRF_QWNERDISPLAY",
  73.   "DRF_PTRPICT",
  74.   "DRF_RTF",
  75.   "DRF_SYLK",
  76.   "DRF_TIFF",
  77.   NULL
  78. };
  79.  
  80. /*************************/
  81. /* exportierte Variablen */
  82. /*************************/
  83. USHORT usUseSelected  = 1;
  84. BOOL   bDrgDrag       = TRUE;
  85. BOOL   bSourceRender  = TRUE;
  86. USHORT usDrgControl   = 0;
  87. USHORT usDrgOperation = DO_DEFAULT;
  88. USHORT usDrgReturn    = DRR_SOURCE;
  89. PSZ    szDrgType      = DRT_TEXT;
  90. CHAR   szDrgRMF[100]  = "<DRM_OS2FILE, DRF_TEXT>";
  91. CHAR   szPath[CCHMAXPATHCOMP] = "D:\\TMP\\";
  92. CHAR   szSource[256] = "TEST.TXT";
  93. CHAR   szTarget[256] = "TEST.TXT";
  94. CHAR   szFilePath[CCHMAXPATHCOMP] = "D:\\TMP\\TEST.TXT";
  95. CHAR   szSelDir[CCHMAXPATHCOMP] = "X:\\";
  96.  
  97. static USHORT unRe=0;
  98. static USHORT unOp=0;
  99. static USHORT unTy=0;
  100. static USHORT unMe=0;
  101. static USHORT unFo=0;
  102.  
  103.  
  104. USHORT InitConfigDlg( HWND hwnd );
  105. void SetInfoParams( HWND hwnd );
  106.  
  107.  
  108. /*******************************************/
  109. /*Dialogprozedur für Konfigurations-Dialog */
  110. /*******************************************/
  111. MRESULT EXPENTRY 
  112. wpConfDrgDragFiles( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  113. {
  114.   switch( msg )
  115.   {
  116.   case WM_INITDLG:
  117.     if( bSourceRender )
  118.     {
  119.       /*WinSendDlgItemMsg( hwnd, RB_SOURCETRUE, BM_SETCHECK, (MPARAM)1, 0L );*/
  120.       WinSendDlgItemMsg( hwnd, RB_SOURCETRUE, BM_CLICK, (MPARAM)0, 0L );
  121.     }
  122.     else
  123.     {
  124.       /*WinSendDlgItemMsg( hwnd, RB_SOURCEFALSE, BM_SETCHECK, (MPARAM)1, 0L );*/
  125.       WinSendDlgItemMsg( hwnd, RB_SOURCEFALSE, BM_CLICK, (MPARAM)0, 0L );
  126.     }
  127.     WinSetDlgItemText( hwnd, EF_FILEPATH, szFilePath );
  128.     WinEnableControl( hwnd, EF_FILEPATH, !usUseSelected );
  129.  
  130.     WinCheckButton( hwnd, CB_SELECTED_D2, !usUseSelected );
  131.     break;
  132.  
  133.   case WM_CONTROL:
  134.     if( SHORT1FROMMP( mp1 ) == CB_SELECTED_D2 )
  135.     {
  136.       USHORT usSel;
  137.       usSel = !((USHORT)WinQueryButtonCheckstate( hwnd, CB_SELECTED_D2 ));
  138.       WinEnableControl( hwnd, EF_FILEPATH, !usSel );
  139.     }
  140.   case WM_COMMAND:                 
  141.     switch( SHORT1FROMMP( mp1 ) )
  142.     {
  143.     case DID_OK:
  144.       usUseSelected = !((USHORT)WinQueryButtonCheckstate( hwnd, CB_SELECTED_D2 ));
  145.       bSourceRender = (BOOL)WinSendDlgItemMsg( hwnd, RB_SOURCETRUE, 
  146.                             BM_QUERYCHECK, 0L, 0L );
  147.       WinQueryDlgItemText( hwnd, EF_FILEPATH, 100L, szFilePath );
  148.     case DID_CANCEL:
  149.       WinDismissDlg( hwnd, TRUE );  /* Remove the dialog box    */
  150.       break;
  151.     }
  152.     break;
  153.   default:
  154.     return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  155.   }
  156.   return (MRESULT) FALSE;
  157. }
  158.  
  159. /*******************************************/
  160. /*Dialogprozedur für Konfigurations-Dialog */
  161. /*******************************************/
  162. MRESULT EXPENTRY 
  163. wpConfDrgDrag( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  164. {
  165.   switch ( msg )
  166.   {
  167.   case WM_INITDLG:
  168.      InitConfigDlg(hwnd);
  169.      break;
  170.  
  171.   case WM_CONTROL:
  172.     if( SHORT1FROMMP( mp1 ) == CB_SELECTED_D1 )
  173.     {
  174.       usUseSelected = 
  175.         !((USHORT)WinQueryButtonCheckstate( hwnd, CB_SELECTED_D1 ));
  176.       WinEnableControl( hwnd, EF_CONTAINER, !usUseSelected );
  177.       WinEnableControl( hwnd, EF_SOURCE, !usUseSelected );
  178.       WinEnableControl( hwnd, EF_TARGET, !usUseSelected );
  179.     }
  180.   case WM_COMMAND:                 /* Posted by pushbutton or key  */
  181.     switch( SHORT1FROMMP( mp1 ) )     
  182.     {
  183.     case DID_OK:
  184.       SetInfoParams( hwnd );
  185.     case DID_CANCEL:
  186.       WinDismissDlg( hwnd, TRUE );  /* Remove the dialog box    */
  187.       return (MRESULT) FALSE;
  188.     default:
  189.       break;
  190.     }
  191.     break;
  192.   default:
  193.     return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  194.   }
  195.   return (MRESULT) FALSE;
  196. }
  197.  
  198.  
  199. /****************************************/
  200. /* Initialisieren der Dialog-Cotrols    */
  201. /****************************************/
  202. USHORT InitConfigDlg( HWND hwnd )
  203. {
  204.   HWND    hControl;
  205.   USHORT  unCnt;
  206.  
  207.   /* set entryfields */
  208.   WinSetDlgItemText( hwnd, EF_CONTAINER, szPath );
  209.   WinSetDlgItemText( hwnd, EF_SOURCE, szSource );
  210.   WinSetDlgItemText( hwnd, EF_TARGET, szTarget );
  211.   if( usUseSelected )
  212.   {
  213.     WinEnableControl( hwnd, EF_CONTAINER, FALSE );
  214.     WinEnableControl( hwnd, EF_SOURCE, FALSE );
  215.     WinEnableControl( hwnd, EF_TARGET, FALSE );
  216.   }
  217.   WinCheckButton( hwnd, CB_SELECTED_D1, !usUseSelected );
  218.  
  219.   /* set combobox 'Operation' */
  220.   hControl = WinWindowFromID(hwnd, CO_OPERATION);
  221.   for( unCnt=0; apcOperations[unCnt][0]; unCnt++ )
  222.   {
  223.     WinSendMsg( hControl, LM_INSERTITEM, (MPARAM)LIT_END,
  224.                             MPFROMP(apcOperations[unCnt][0]) );
  225.   }
  226.   WinSendMsg( hControl, LM_SELECTITEM, (MPARAM)unOp, (MPARAM)0 );
  227.   WinSetDlgItemText( hwnd, CO_OPERATION, apcOperations[unOp][0] );
  228.  
  229.   /* set combobox 'Return' */
  230.   hControl = WinWindowFromID(hwnd, CO_RETURN);
  231.   for( unCnt=0; apcReturn[unCnt][0]; unCnt++ )
  232.   {
  233.     WinSendMsg( hControl, LM_INSERTITEM, (MPARAM)LIT_END,
  234.                             MPFROMP(apcReturn[unCnt][0]) );
  235.   }
  236.   WinSendMsg( hControl, LM_SELECTITEM, (MPARAM)unRe, (MPARAM)0 );
  237.   WinSetDlgItemText( hwnd, CO_RETURN, apcReturn[unRe][0] );
  238.  
  239.   /* set combobox 'Type' */
  240.   hControl = WinWindowFromID(hwnd, CO_TYPE );
  241.   for( unCnt=0; apcTypes[unCnt][0]; unCnt++ )
  242.   {
  243.     WinSendMsg( hControl, LM_INSERTITEM, (MPARAM)LIT_END,
  244.                             MPFROMP(apcTypes[unCnt][0]) );
  245.   }
  246.   WinSendMsg( hControl, LM_SELECTITEM, (MPARAM)unTy, (MPARAM)0 );
  247.   WinSetDlgItemText( hwnd, CO_TYPE, apcTypes[unTy][0] );
  248.  
  249.   /* set listbox 'Control' */
  250.   hControl = WinWindowFromID(hwnd, CO_FCONTROL );
  251.   for( unCnt=0; apcControl[unCnt][0]; unCnt++ )
  252.   {
  253.     WinSendMsg( hControl, LM_INSERTITEM, (MPARAM)LIT_END,
  254.                             MPFROMP(apcControl[unCnt][0]) );
  255.   }
  256.   for( unCnt=0; apcControl[unCnt][0]; unCnt++ )
  257.     if( (USHORT)(apcControl[unCnt][1]) & usDrgControl )
  258.       WinSendMsg( hControl, LM_SELECTITEM, (MPARAM)unCnt, (MPARAM)TRUE );
  259.  
  260.   /* set combobox 'Mechanism' */
  261.   hControl = WinWindowFromID(hwnd, CO_MECH );
  262.   for( unCnt=0; apcMechanisms[unCnt]; unCnt++ )
  263.   {
  264.     WinSendMsg( hControl, LM_INSERTITEM, (MPARAM)LIT_END,
  265.                             MPFROMP(apcMechanisms[unCnt]) );
  266.   }
  267.   WinSendMsg( hControl, LM_SELECTITEM, (MPARAM)unMe, (MPARAM)0 );
  268.   WinSetDlgItemText( hwnd, CO_MECH, apcMechanisms[unMe]);
  269.  
  270.   /* set combobox 'Format' */
  271.   hControl = WinWindowFromID(hwnd, CO_FORMAT );
  272.   for( unCnt=0; apcFormats[unCnt]; unCnt++ )
  273.   {
  274.     WinSendMsg( hControl, LM_INSERTITEM, (MPARAM)LIT_END,
  275.                             MPFROMP(apcFormats[unCnt]) );
  276.   }
  277.   WinSendMsg( hControl, LM_SELECTITEM, (MPARAM)unFo, (MPARAM)0 );
  278.   WinSetDlgItemText( hwnd, CO_FORMAT, apcFormats[unFo] );
  279.  
  280.   return 0;
  281. }
  282.  
  283.  
  284. /****************************************************/
  285. /*Belegen der Parameter für die Drag-Drop-Operation */
  286. /****************************************************/
  287. void SetInfoParams( HWND hwnd )
  288. {
  289. #define BUFLEN CCHMAXPATHCOMP
  290.   USHORT  unCnt, unIdx;
  291.   CHAR    achBuf[BUFLEN];
  292.   CHAR    szDrgMechanism[30];
  293.   CHAR    szDrgFormat[30];
  294.  
  295.   WinQueryDlgItemText( hwnd, EF_CONTAINER, sizeof(szPath), szPath );
  296.   WinQueryDlgItemText( hwnd, EF_SOURCE, sizeof(szSource), szSource );
  297.   WinQueryDlgItemText( hwnd, EF_SOURCE, sizeof(szTarget), szTarget );
  298.  
  299.   WinQueryDlgItemText( hwnd, CO_OPERATION, BUFLEN, achBuf );
  300.   for( unOp=0,unCnt=0; apcOperations[unCnt][0]; unCnt++ )
  301.   {
  302.     if( !strcmp( apcOperations[unCnt][0], achBuf ) )
  303.     {
  304.       unOp = unCnt;
  305.       usDrgOperation = (USHORT)apcOperations[unCnt][1];
  306.       break;
  307.     }
  308.   }
  309.  
  310.   WinQueryDlgItemText( hwnd, CO_RETURN, BUFLEN, achBuf );
  311.   for( unRe=0,unCnt=0; apcReturn[unCnt][0]; unCnt++ )
  312.   {
  313.     if( !strcmp( apcReturn[unCnt][0], achBuf ) )
  314.     {
  315.       unRe = unCnt;
  316.       usDrgReturn = (USHORT)apcReturn[unCnt][1];
  317.       break;
  318.     }
  319.   }
  320.  
  321.   WinQueryDlgItemText( hwnd, CO_TYPE, BUFLEN, achBuf );
  322.   for( unTy=0, unCnt=0; apcTypes[unCnt][0]; unCnt++ )
  323.   {
  324.     if( !strcmp( apcTypes[unCnt][0], achBuf ) )
  325.     {
  326.       unTy = unCnt;
  327.       szDrgType = apcTypes[unCnt][1];
  328.       break;
  329.     }
  330.   }
  331.  
  332.   usDrgControl = 0;
  333.   unIdx = (USHORT)WinSendMsg(WinWindowFromID(hwnd,CO_FCONTROL), 
  334.                        LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0);
  335.   while( unIdx != (USHORT)LIT_NONE )
  336.   {
  337.     usDrgControl |= (USHORT)(apcControl[unIdx][1]);
  338.     unIdx = (USHORT)WinSendMsg(WinWindowFromID(hwnd,CO_FCONTROL),
  339.                        LM_QUERYSELECTION, (MPARAM)unIdx, (MPARAM)0);
  340.   }
  341.  
  342.   if( WinQueryDlgItemText( hwnd, CO_MECH, BUFLEN, achBuf ) )
  343.   {
  344.     strcpy( szDrgMechanism, achBuf );
  345.     for( unMe=0, unCnt=0; apcMechanisms[unCnt]; unCnt++ )
  346.     {
  347.       if( !strcmp( apcMechanisms[unCnt], achBuf ) )
  348.       {
  349.         unMe = unCnt;
  350.         break;
  351.       }
  352.     }
  353.   }
  354.  
  355.   if( WinQueryDlgItemText( hwnd, CO_FORMAT, BUFLEN, achBuf ) )
  356.   {
  357.     strcpy( szDrgFormat, achBuf );
  358.     for( unFo=0, unCnt=0; apcFormats[unCnt]; unCnt++ )
  359.     {
  360.       if( !strcmp( apcFormats[unCnt], achBuf ) )
  361.       {
  362.         unFo = unCnt;
  363.         break;
  364.       }
  365.     }
  366.   }
  367.   sprintf( szDrgRMF, "<%s,%s>", szDrgMechanism, szDrgFormat );
  368. }
  369.  
  370. /****************************************************/
  371. /* discard dialog - show selected files             */
  372. /****************************************************/
  373. MRESULT EXPENTRY
  374. delLboxProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  375. {
  376.   if( msg == WM_INITDLG )
  377.   {
  378.     CHAR      achName[ 50 ];
  379.     PDRAGITEM pDragItem;
  380.     ULONG     ulItems;
  381.     HWND      hLbox;
  382.     PDISCARD_PARAM    pparam;
  383.     
  384.     pparam = (PDISCARD_PARAM)(PVOIDFROMMP(mp2));
  385.   
  386.     hLbox = WinWindowFromID( hwnd, LB_DISCARD );
  387.     for( ulItems = DrgQueryDragitemCount( pparam->pd ); 
  388.          ulItems; ulItems-- )
  389.     {
  390.       pDragItem = DrgQueryDragitemPtr( pparam->pd, ulItems-1 );
  391.       DrgQueryStrName( pDragItem->hstrTargetName, 50, achName );
  392.       WinInsertLboxItem( hLbox, LIT_END, achName );
  393.     }
  394.   }
  395.   WinDefDlgProc( hwnd, msg, mp1, mp2 );
  396. }
  397.  
  398. /***************************************/
  399. /* this dialog does 'change directory' */
  400. /***************************************/
  401. MRESULT EXPENTRY wpCDDlg( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  402. {
  403.   CHAR achBuf[CCHMAXPATHCOMP] = "X:\\";
  404.   ULONG ulDrv, ulLen=CCHMAXPATHCOMP-2;
  405.  
  406.   switch( msg )
  407.   {
  408.   case WM_INITDLG:
  409.     WinSendMsg( hObject, DRI_GET_CURDIR, 0L, 0L );
  410.     WinSetDlgItemText( hwnd, EF_DIRECTORY, szSelDir );
  411.     WinSendDlgItemMsg( hwnd, EF_DIRECTORY, EM_SETSEL, MPFROM2SHORT(0,ulLen), 0L );
  412.     break;
  413.   case WM_COMMAND:
  414.     if( SHORT1FROMMP( mp1 ) == DID_OK &&
  415.         WinQueryDlgItemText( hwnd, EF_DIRECTORY, CCHMAXPATHCOMP, achBuf ) )
  416.     {
  417.       if( strchr( achBuf, ':' ) > achBuf )
  418.         ulDrv = (achBuf[0]<91?achBuf[0]-64:achBuf[0]-96);
  419.       if( DosSetCurrentDir( achBuf ) || DosSetDefaultDisk( ulDrv ))
  420.       {
  421.         WinAlarm(HWND_DESKTOP, WA_ERROR);
  422.       }
  423.       else
  424.       {
  425.         strcpy( szSelDir, achBuf );
  426.         WinPostMsg( hFileList, DRI_INIT_LIST, 0L, 0L );
  427.       }
  428.     }
  429.     break;
  430.   }
  431.   WinDefDlgProc( hwnd, msg, mp1, mp2 );
  432. }
  433.