xref: /haiku/src/preferences/datatranslations/TranslatorListView.cpp (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 /*
2  * Copyright 2002-2006, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Oliver Siebenmarck
7  *		Andrew McCall, mccall@digitalparadise.co.uk
8  *		Michael Wilber
9  */
10 
11 
12 #include "TranslatorListView.h"
13 
14 #include <Application.h>
15 
16 #include <string.h>
17 
18 
19 static int
20 compare_items(const void* a, const void* b)
21 {
22 	const BStringItem* stringA = *(const BStringItem**)a;
23 	const BStringItem* stringB = *(const BStringItem**)b;
24 
25 	return strcmp(stringA->Text(), stringB->Text());
26 }
27 
28 
29 //	#pragma mark -
30 
31 
32 TranslatorItem::TranslatorItem(translator_id id, const char* name)
33 	: BStringItem(name),
34 	fID(id)
35 {
36 }
37 
38 
39 TranslatorItem::~TranslatorItem()
40 {
41 }
42 
43 
44 //	#pragma mark -
45 
46 
47 TranslatorListView::TranslatorListView(BRect rect, const char *name,
48 		list_view_type type)
49 	: BListView(rect, name, B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES)
50 {
51 }
52 
53 
54 TranslatorListView::~TranslatorListView()
55 {
56 }
57 
58 
59 void
60 TranslatorListView::MessageReceived(BMessage *message)
61 {
62 	uint32 type;
63 	int32 count;
64 
65 	switch (message->what) {
66 		case B_SIMPLE_DATA:
67 			// Tell the application object that a
68 			// file has been dropped on this view
69 			message->GetInfo("refs", &type, &count);
70 			if (count > 0 && type == B_REF_TYPE) {
71 				message->what = B_REFS_RECEIVED;
72 				be_app->PostMessage(message);
73 				Invalidate();
74 			}
75 			break;
76 
77 		default:
78 			BView::MessageReceived(message);
79 			break;
80 	}
81 }
82 
83 
84 void
85 TranslatorListView::MouseMoved(BPoint point, uint32 transit, const BMessage *dragMessage)
86 {
87 	if (dragMessage != NULL && transit == B_ENTERED_VIEW) {
88 		// Draw a red box around the inside of the view
89 		// to tell the user that this view accepts drops
90 		SetHighColor(220,0,0);
91 	 	SetPenSize(4);
92 		StrokeRect(Bounds());
93 	 	SetHighColor(0,0,0);
94 	} else if (dragMessage != NULL && transit == B_EXITED_VIEW)
95 		Invalidate();
96 }
97 
98 
99 void
100 TranslatorListView::SortItems()
101 {
102 	BListView::SortItems(&compare_items);
103 }
104 
105