2 * Copyright 2002-2006, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
7 * Andrew McCall, mccall@digitalparadise.co.uk
12 #include "TranslatorListView.h"
16 #include <Application.h>
20 compare_items(const void* a
, const void* b
)
22 const BStringItem
* stringA
= *(const BStringItem
**)a
;
23 const BStringItem
* stringB
= *(const BStringItem
**)b
;
25 return strcmp(stringA
->Text(), stringB
->Text());
32 TranslatorItem::TranslatorItem(translator_id id
, const char* name
)
40 TranslatorItem::~TranslatorItem()
48 TranslatorListView::TranslatorListView(const char* name
, list_view_type type
)
50 BListView(name
, B_SINGLE_SELECTION_LIST
)
55 TranslatorListView::~TranslatorListView()
61 TranslatorListView::TranslatorAt(int32 index
) const
63 return dynamic_cast<TranslatorItem
*>(ItemAt(index
));
68 TranslatorListView::MessageReceived(BMessage
* message
)
73 switch (message
->what
) {
75 // Tell the application object that a
76 // file has been dropped on this view
77 message
->GetInfo("refs", &type
, &count
);
78 if (count
> 0 && type
== B_REF_TYPE
) {
79 message
->what
= B_REFS_RECEIVED
;
80 be_app
->PostMessage(message
);
86 BListView::MessageReceived(message
);
93 TranslatorListView::MouseMoved(BPoint point
, uint32 transit
,
94 const BMessage
* dragMessage
)
96 if (dragMessage
!= NULL
&& transit
== B_ENTERED_VIEW
) {
97 // Draw a red box around the inside of the view
98 // to tell the user that this view accepts drops
99 SetHighColor(220, 0, 0);
101 StrokeRect(Bounds());
102 SetHighColor(0, 0, 0);
103 } else if (dragMessage
!= NULL
&& transit
== B_EXITED_VIEW
)
109 TranslatorListView::SortItems()
111 BListView::SortItems(&compare_items
);