btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / musiccollection / MusicFileListView.h
blob025bec11169208e301d6fb56522b31ebe93b1770
1 /*
2 * Copyright 2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
7 */
8 #ifndef MUSIC_FILE_LIST_VIEW_H
9 #define MUSIC_FILE_LIST_VIEW_H
12 #include <Bitmap.h>
13 #include <ListItem.h>
14 #include <OutlineListView.h>
15 #include <Roster.h>
17 #include "QueryMonitor.h"
20 class FileListItem : public BStringItem {
21 public:
22 FileListItem(const char* text, WatchedFile* file = NULL)
24 BStringItem(text),
25 fFile(file)
30 WatchedFile*
31 File()
33 return fFile;
36 private:
37 WatchedFile* fFile;
41 class MusicFileListView : public BOutlineListView {
42 public:
44 MusicFileListView(const char *name)
46 BOutlineListView(name)
51 bool
52 InitiateDrag(BPoint where, int32 index, bool wasSelected)
54 int32 itemIndex = IndexOf(where);
55 FileListItem* item = (FileListItem*)ItemAt(itemIndex);
56 if (item == NULL)
57 return false;
59 const char* text = item->Text();
61 BRect rect(0, 0, 200, 50);
62 BBitmap* bitmap = new BBitmap(rect, B_RGB32, true);
63 BView* bitmapView = new BView(rect, "bitmap", B_FOLLOW_NONE,
64 B_WILL_DRAW);
66 bitmap->Lock();
67 bitmap->AddChild(bitmapView);
69 bitmapView->SetLowColor(255, 255, 255, 0); // transparent
70 bitmapView->SetHighColor(0, 0, 0, 100);
71 bitmapView->SetDrawingMode(B_OP_COPY);
72 bitmapView->FillRect(bitmapView->Bounds(), B_SOLID_LOW);
74 bitmapView->SetDrawingMode(B_OP_OVER);
75 font_height height;
76 bitmapView->GetFontHeight(&height);
77 float fontHeight = height.ascent + height.descent;
78 BRect latchRect = LatchRect(BRect(0, 0, item->Width(), item->Height()),
79 item->OutlineLevel());
80 bitmapView->DrawString(text, BPoint(latchRect.Width(), fontHeight));
82 bitmapView->Sync();
83 bitmap->Unlock();
85 BMessage dragMessage(B_SIMPLE_DATA);
86 dragMessage.AddPoint("click_location", where);
88 _RecursiveAddRefs(dragMessage, item);
90 BRect itemFrame(ItemFrame(itemIndex));
91 BPoint pt(where.x + itemFrame.left, where.y - itemFrame.top);
92 DragMessage(&dragMessage, bitmap, B_OP_ALPHA, pt, this);
94 return true;
98 void
99 Launch(BMessage* message)
101 int32 index;
102 for (int32 i = 0; ; i++) {
103 if (message->FindInt32("index", i, &index) != B_OK)
104 break;
105 FileListItem* item = (FileListItem*)ItemAt(index);
107 BMessage refs(B_REFS_RECEIVED);
108 _RecursiveAddRefs(refs, item);
109 be_roster->Launch("application/x-vnd.Haiku-MediaPlayer", &refs);
113 private:
115 void
116 _RecursiveAddRefs(BMessage& message, FileListItem* item)
118 WatchedFile* file = item->File();
119 if (file != NULL) {
120 message.AddRef("refs", &(file->entry));
121 } else {
122 for (int32 i = 0; i < CountItemsUnder(item, true); i++) {
123 _RecursiveAddRefs(message, (FileListItem*)ItemUnderAt(
124 item, true, i));
130 #endif // MUSIC_FILE_LIST_VIEW_H