vfs: check userland buffers before reading them.
[haiku.git] / src / preferences / datatranslations / TranslatorListView.cpp
blobd7cf40a9c61aecd705860f6e7755be7484e0c3f4
1 /*
2 * Copyright 2002-2006, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Oliver Siebenmarck
7 * Andrew McCall, mccall@digitalparadise.co.uk
8 * Michael Wilber
9 */
12 #include "TranslatorListView.h"
14 #include <string.h>
16 #include <Application.h>
19 static int
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());
29 // #pragma mark -
32 TranslatorItem::TranslatorItem(translator_id id, const char* name)
34 BStringItem(name),
35 fID(id)
40 TranslatorItem::~TranslatorItem()
45 // #pragma mark -
48 TranslatorListView::TranslatorListView(const char* name, list_view_type type)
50 BListView(name, B_SINGLE_SELECTION_LIST)
55 TranslatorListView::~TranslatorListView()
60 TranslatorItem*
61 TranslatorListView::TranslatorAt(int32 index) const
63 return dynamic_cast<TranslatorItem*>(ItemAt(index));
67 void
68 TranslatorListView::MessageReceived(BMessage* message)
70 uint32 type;
71 int32 count;
73 switch (message->what) {
74 case B_SIMPLE_DATA:
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);
81 Invalidate();
83 break;
85 default:
86 BListView::MessageReceived(message);
87 break;
92 void
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);
100 SetPenSize(4);
101 StrokeRect(Bounds());
102 SetHighColor(0, 0, 0);
103 } else if (dragMessage != NULL && transit == B_EXITED_VIEW)
104 Invalidate();
108 void
109 TranslatorListView::SortItems()
111 BListView::SortItems(&compare_items);