home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / DRAGLIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.6 KB  |  174 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Implementation of TDragList
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_DRAGLIST_H)
  11. # include <owl/draglist.h>
  12. #endif
  13.  
  14. OWL_DIAGINFO;
  15.  
  16. DEFINE_RESPONSE_TABLE1(TDragList, TListBox)
  17.   EV_REGISTERED(DRAGLISTMSGSTRING, DragNotify),
  18. END_RESPONSE_TABLE;
  19.  
  20. //
  21. // Constructor for creating a drag list dynamically.
  22. //
  23. TDragList::TDragList(TWindow* parent, int id, int x, int y, int w, int h,
  24.                      TModule* module)
  25. :
  26.   TListBox(parent, id, x, y, w, h, module)
  27. {
  28. }
  29.  
  30. //
  31. // Constructor for creating a drag list from a resource.
  32. //
  33. TDragList::TDragList(TWindow* parent, int resourceId, TModule* module)
  34. :
  35.   TListBox(parent, resourceId, module)
  36. {
  37. }
  38.  
  39. //
  40. // SetupWindow for the drag listbox must call MakeDragList().
  41. //
  42. void
  43. TDragList::SetupWindow()
  44. {
  45.   // Call base class
  46.   //
  47.   TListBox::SetupWindow();
  48.  
  49.   if (TCommCtrl::IsAvailable())
  50.     TCommCtrl::Dll()->MakeDragList(*this);
  51. }
  52.  
  53. //
  54. // Handle the DRAGLISTMSGSTRING notification by calling virtual functions
  55. // based on the notification message.
  56. //
  57. TResult
  58. TDragList::DragNotify(TParam1, TParam2 lp)
  59. {
  60.   DRAGLISTINFO far* info = (DRAGLISTINFO far*)lp;
  61.   if (info) {
  62.     TPoint p = info->ptCursor;
  63.     int item = ItemFromPoint(p);
  64.  
  65.     switch (info->uNotification) {
  66.       case DL_BEGINDRAG:
  67.         return BeginDrag(item, p);
  68.  
  69.       case DL_DRAGGING:
  70.         return Dragging(item, p);
  71.  
  72.       case DL_DROPPED:
  73.         Dropped(item, p);
  74.         break;
  75.  
  76.       case DL_CANCELDRAG:
  77.         CancelDrag(item, p);
  78.         break;
  79.  
  80.       default:
  81.         // Should not ever happen.
  82.         break;
  83.     }
  84.   }
  85.   return 0;
  86. }
  87.  
  88. //
  89. // The drag UI has started.
  90. // Return true to allow drag.
  91. //
  92. bool
  93. TDragList::BeginDrag(int, const TPoint&)
  94. {
  95.   return false;
  96. }
  97.  
  98. //
  99. // User has moved the mouse.
  100. // Return the type of cursor to represent the allowable action.
  101. //
  102. TDragList::TCursorType
  103. TDragList::Dragging(int, const TPoint&)
  104. {
  105.   return dlStop;
  106. }
  107.  
  108. //
  109. // User has dropped the item.
  110. //
  111. void
  112. TDragList::Dropped(int, const TPoint&)
  113. {
  114.  
  115. }
  116.  
  117. //
  118. // User has cancelled the drag.
  119. //
  120. void
  121. TDragList::CancelDrag(int, const TPoint&)
  122. {
  123.  
  124. }
  125.  
  126. //
  127. // Draw the drag cursor.
  128. //
  129. void
  130. TDragList::DrawInsert(int item)
  131. {
  132.   if (TCommCtrl::IsAvailable())
  133.     TCommCtrl::Dll()->DrawInsert(*GetParentO(), *this, item);
  134. }
  135.  
  136. //
  137. // Retrieve the item from the specified point.
  138. // Return -1 if the point is not on an item.
  139. // 'scroll' determines whether the listbox will scroll if the point is
  140. // above or below the listbox.
  141. //
  142. int
  143. TDragList::ItemFromPoint(const TPoint& p, bool scroll)
  144. {
  145.   if (TCommCtrl::IsAvailable())
  146.     return TCommCtrl::Dll()->LBItemFromPt(*this, p, scroll);
  147.  
  148.   return -1;
  149. }
  150.  
  151. //----------------------------------------------------------------------------
  152.  
  153. DEFINE_RESPONSE_TABLE1(TDragListEventHandler, TEventHandler)
  154.   EV_REGISTERED(DRAGLISTMSGSTRING, DragNotify),
  155. END_RESPONSE_TABLE;
  156.  
  157. //
  158. // Forward the drag notification messages from the parent window
  159. // to the drag listbox for it to handle.
  160. //
  161. TResult
  162. TDragListEventHandler::DragNotify(TParam1 wp, TParam2 lp)
  163. {
  164.   DRAGLISTINFO far* info = (DRAGLISTINFO far*)lp;
  165.   if (info) {
  166.     // Forward messages from parent to listbox
  167.     //
  168.     return ::SendMessage(info->hWnd,
  169.                          ::RegisterWindowMessage(DRAGLISTMSGSTRING),
  170.                          wp, lp);
  171.   }
  172.   return 0;
  173. }
  174.