1 /*
2 * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include "DropTargetListView.h"
8
9
DropTargetListView(const char * name,list_view_type type,uint32 flags)10 DropTargetListView::DropTargetListView(const char* name,
11 list_view_type type, uint32 flags)
12 : BListView(name, type, flags),
13 fDropTarget(false)
14 {
15 }
16
17
~DropTargetListView()18 DropTargetListView::~DropTargetListView()
19 {
20 }
21
22
23 void
Draw(BRect updateRect)24 DropTargetListView::Draw(BRect updateRect)
25 {
26 BListView::Draw(updateRect);
27
28 if (fDropTarget) {
29 // mark this view as a drop target
30 rgb_color color = HighColor();
31
32 SetHighColor(0, 0, 0);
33 SetPenSize(2);
34 BRect rect = Bounds();
35 // TODO: this is an incompatibility between R5 and Haiku and should be fixed!
36 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
37 rect.left++;
38 rect.top++;
39 #else
40 rect.right--;
41 rect.bottom--;
42 #endif
43 StrokeRect(rect);
44
45 SetPenSize(1);
46 SetHighColor(color);
47 }
48 }
49
50
51 void
MouseMoved(BPoint where,uint32 transit,const BMessage * dragMessage)52 DropTargetListView::MouseMoved(BPoint where, uint32 transit,
53 const BMessage* dragMessage)
54 {
55 if (dragMessage != NULL && AcceptsDrag(dragMessage)) {
56 bool dropTarget = transit == B_ENTERED_VIEW || transit == B_INSIDE_VIEW;
57 if (dropTarget != fDropTarget) {
58 fDropTarget = dropTarget;
59 _InvalidateFrame();
60 }
61 } else if (fDropTarget) {
62 fDropTarget = false;
63 _InvalidateFrame();
64 }
65 }
66
67
68 bool
AcceptsDrag(const BMessage *)69 DropTargetListView::AcceptsDrag(const BMessage* /*message*/)
70 {
71 return true;
72 }
73
74
75 void
_InvalidateFrame()76 DropTargetListView::_InvalidateFrame()
77 {
78 // only update the parts affected by the change to reduce flickering
79 BRect rect = Bounds();
80 rect.right = rect.left + 1;
81 Invalidate(rect);
82
83 rect = Bounds();
84 rect.left = rect.right - 1;
85 Invalidate(rect);
86
87 rect = Bounds();
88 rect.bottom = rect.top + 1;
89 Invalidate(rect);
90
91 rect = Bounds();
92 rect.top = rect.bottom - 1;
93 Invalidate(rect);
94 }
95