2 * Copyright 2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
8 #ifndef MUSIC_FILE_LIST_VIEW_H
9 #define MUSIC_FILE_LIST_VIEW_H
14 #include <OutlineListView.h>
17 #include "QueryMonitor.h"
20 class FileListItem
: public BStringItem
{
22 FileListItem(const char* text
, WatchedFile
* file
= NULL
)
41 class MusicFileListView
: public BOutlineListView
{
44 MusicFileListView(const char *name
)
46 BOutlineListView(name
)
52 InitiateDrag(BPoint where
, int32 index
, bool wasSelected
)
54 int32 itemIndex
= IndexOf(where
);
55 FileListItem
* item
= (FileListItem
*)ItemAt(itemIndex
);
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
,
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
);
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
));
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);
99 Launch(BMessage
* message
)
102 for (int32 i
= 0; ; i
++) {
103 if (message
->FindInt32("index", i
, &index
) != B_OK
)
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
);
116 _RecursiveAddRefs(BMessage
& message
, FileListItem
* item
)
118 WatchedFile
* file
= item
->File();
120 message
.AddRef("refs", &(file
->entry
));
122 for (int32 i
= 0; i
< CountItemsUnder(item
, true); i
++) {
123 _RecursiveAddRefs(message
, (FileListItem
*)ItemUnderAt(
130 #endif // MUSIC_FILE_LIST_VIEW_H