home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / ODragEntryField.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  7KB  |  222 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Matthias Stuebner (matze@joker.berlinet.de)
  3. // (c) Benno Stein
  4. // (c) Cubus 1995
  5. // All Rights Reserved
  6. // ODragEntryField.cpp
  7.  
  8.  
  9. /*
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  16.  *    endorse or promote products derived from this software
  17.  *    without specific prior written permission.
  18.  * 3. See OCL.INF for a detailed copyright notice.
  19.  *
  20.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  */
  32.  
  33.  
  34. // $Header: W:/Projects/OCL/Source/rcs/ODragEntryField.cpp 1.50 1996/08/11 23:49:13 B.STEIN Release $
  35.  
  36. #define __OCL_SOURCE__
  37.  
  38. #define OINCL_OSTRING
  39. #define OINCL_BASE
  40.  
  41. #include <ocl.hpp>
  42. #include <ODragEntryField.hpp>
  43. #include <OMessage.hpp>
  44.  
  45.  
  46. ODragEntryField::ODragEntryField( 
  47.                         const ULONG     _id,
  48.                         const HWND      _Parent,
  49.                         const ULONG     _Style,
  50.                         const ULONG     _Limit)
  51.  
  52.  : OEntryField(_id, _Parent, _Style, _Limit)
  53.  {}
  54.  
  55. ODragEntryField::ODragEntryField( 
  56.                         const ULONG     _id,
  57.                         const OFrame&   _Parent,
  58.                         const ULONG     _Style,
  59.                         const ULONG     _Limit)
  60.  
  61.  : OEntryField(_id, _Parent, _Style, _Limit)
  62.  {}
  63.  
  64. ODragEntryField::ODragEntryField( 
  65.                         const ULONG     _id,
  66.                         const pOFrame   _Parent,
  67.                         const ULONG     _Style,
  68.                         const ULONG     _Limit)
  69.  
  70.   : OEntryField(_id, _Parent, _Style, _Limit)
  71.   {}
  72.  
  73.  
  74. ODragEntryField::~ODragEntryField()
  75.   {}
  76.  
  77.  
  78. PSZ ODragEntryField::isOfType() const
  79. {
  80.  return("ODragEntryField");
  81. }
  82.  
  83.  
  84. ODragEntryField& ODragEntryField::createEntryField(
  85.                           const ULONG x,
  86.                           const ULONG y,
  87.                           const ULONG cx,
  88.                           const ULONG cy)
  89. {
  90.  CLASSINFO clsi ;
  91.    
  92.  WinQueryClassInfo(OApp::current().anchor(),
  93.                    WC_ENTRYFIELD, &clsi);
  94.  
  95.  PM_EntryFieldProc = clsi.pfnWindowProc;
  96.  
  97.  if (!WinRegisterClass(OApp::current().anchor(),
  98.                        "ODragEntryField",
  99.                        (PFNWP) ODragEntryFieldProc,
  100.                        0,
  101.                        clsi.cbWindowData + sizeof (PVOID)))
  102.    throw OPMException(OCL::error(45), 0, OException::fatal);
  103.  
  104.  
  105.  if ((hwnd = WinCreateWindow(parent, "ODragEntryField", "",
  106.                              style | WS_VISIBLE,
  107.                              x, y, cx, cy, owner, HWND_TOP,
  108.                              res, this, NULL)) == NULLHANDLE)
  109.    throw OPMException(OCL::error(46), 0, OException::fatal);
  110.  
  111.  return(*this);
  112. }
  113.  
  114.  
  115.  
  116. OWindow& ODragEntryField::inherit(const HWND hwndDlg)
  117. {
  118.  OWindow::inherit(hwndDlg);
  119.  
  120.  if (!WinQueryWindowPos(WinWindowFromID(hwndDlg, res), &sizepos))
  121.    throw OPMException(OCL::error(47), 0, OException::fatal);
  122.  
  123.  WinDestroyWindow(WinWindowFromID(hwndDlg, res));
  124.  
  125.  return(createEntryField(sizepos.x, sizepos.y, sizepos.cx, sizepos.cy));
  126. }
  127.  
  128.  
  129. MRESULT ODragEntryField::EFDefaultCall(ULONG  msg,  
  130.                                        MPARAM mp1,
  131.                                        MPARAM mp2)
  132. {
  133.  return((MRESULT)PM_EntryFieldProc(hwnd, msg, mp1, mp2));
  134. }
  135.  
  136.  
  137.  
  138. BOOL ODragEntryField::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  139. {
  140.  return(FALSE);
  141. }
  142.  
  143.  
  144.  
  145. // The following function is strictly for internal use only!
  146.  
  147.  
  148. MRESULT EXPENTRY ODragEntryFieldProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  149. {
  150.  pODragEntryField odf_current = (pODragEntryField) WinQueryWindowPtr(hwnd, QWL_USER);
  151.  
  152.  if (odf_current)
  153.    odf_current->hwnd = hwnd;
  154.  
  155.  switch(msg)
  156.   {
  157.    case WM_CREATE:
  158.      if (!mp1)
  159.        return(MRESULT(TRUE));
  160.      odf_current = (pODragEntryField) mp1;
  161.      WinSetWindowPtr(hwnd, QWL_USER, odf_current);
  162.      odf_current->hwnd = hwnd;
  163.      odf_current->EFDefaultCall(msg, mp1, mp2);
  164.      odf_current->OCommand(msg, mp1, mp2);
  165.      WinPostMsg(hwnd, EM_SETTEXTLIMIT, MPFROMSHORT (CCHMAXPATH), 0) ;
  166.      break ;
  167.  
  168.    case WM_DESTROY:
  169.      WinSetWindowPtr(hwnd, QWL_USER, NULL);
  170.      if(odf_current) {
  171.        odf_current->OCommand(msg, mp1, mp2); 
  172.        return(odf_current->EFDefaultCall(msg, mp1, mp2)); }
  173.      break;
  174.  
  175.    case DM_DRAGOVER:
  176.     {
  177.      PDRAGINFO  pdinfo = (PDRAGINFO) mp1;
  178.      PDRAGITEM  pditem = NULL;
  179.  
  180.      DrgAccessDraginfo(pdinfo);
  181.      pditem = DrgQueryDragitemPtr(pdinfo, 0);
  182.      if (DrgVerifyRMF(pditem, "DRM_OS2FILE", NULL))
  183.        {
  184.         DrgFreeDraginfo (pdinfo) ;
  185.         return(MRFROM2SHORT(DOR_DROP, DO_COPY));
  186.        }
  187.      else
  188.        {
  189.         DrgFreeDraginfo (pdinfo) ;
  190.         return(MRFROM2SHORT(DOR_NEVERDROP, 0));
  191.        }
  192.     }
  193.  
  194.    case DM_DROP:
  195.     {
  196.      OString    Buffer1(CCHMAXPATH);
  197.      OString    Buffer2(CCHMAXPATH);
  198.      PDRAGINFO  pdinfo = (PDRAGINFO) mp1;
  199.      PDRAGITEM  pditem = NULL;
  200.  
  201.      DrgAccessDraginfo(pdinfo);
  202.      pditem = DrgQueryDragitemPtr(pdinfo, 0) ;
  203.      DrgQueryStrName (pditem->hstrContainerName, CCHMAXPATH, Buffer1);
  204.      DrgQueryStrName (pditem->hstrSourceName, CCHMAXPATH, Buffer2);
  205.      Buffer1 + Buffer2;
  206.      WinSetWindowText(hwnd, Buffer1);
  207.      DrgFreeDraginfo (pdinfo) ;
  208.      break;
  209.     }
  210.  
  211.    default:
  212.      if ((odf_current) &&
  213.         (!odf_current->OCommand(msg, mp1, mp2)))
  214.        return(odf_current->EFDefaultCall(msg, mp1, mp2));
  215.      break;
  216.   }
  217.  return((MRESULT)FALSE);
  218. }
  219.  
  220.  
  221. // end of source
  222.