Use a ColumnListView
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28359 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2003, OpenBeOS
|
||||
//
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
//
|
||||
// File: HEventItem.cpp
|
||||
// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu
|
||||
// Description: Sounds Preferences
|
||||
// Created : November 24, 2003
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#include "HEventItem.h"
|
||||
#include <View.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
#include <MediaFiles.h>
|
||||
#include <Alert.h>
|
||||
#include <Beep.h>
|
||||
|
||||
/***********************************************************
|
||||
* Constructor
|
||||
***********************************************************/
|
||||
HEventItem::HEventItem(const char* name, const char* path)
|
||||
: BListItem(),
|
||||
fName(name)
|
||||
{
|
||||
SetPath(path);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Destructor
|
||||
***********************************************************/
|
||||
HEventItem::~HEventItem()
|
||||
{
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set path
|
||||
***********************************************************/
|
||||
void
|
||||
HEventItem::SetPath(const char* in_path)
|
||||
{
|
||||
fPath = in_path;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************
|
||||
* Remove
|
||||
***********************************************************/
|
||||
void
|
||||
HEventItem::Remove(const char *type)
|
||||
{
|
||||
BMediaFiles().RemoveItem(type, Name());
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************
|
||||
* DrawItem
|
||||
***********************************************************/
|
||||
void
|
||||
HEventItem::DrawItem(BView *owner, BRect itemRect, bool complete)
|
||||
{
|
||||
rgb_color kBlack = { 0,0,0,0 };
|
||||
|
||||
if (IsSelected() || complete) {
|
||||
rgb_color color;
|
||||
if (IsSelected())
|
||||
color = tint_color(owner->LowColor(), B_DARKEN_2_TINT);
|
||||
else
|
||||
color = owner->ViewColor();
|
||||
|
||||
owner->SetHighColor(color);
|
||||
owner->SetLowColor(color);
|
||||
owner->FillRect(itemRect);
|
||||
owner->SetHighColor(kBlack);
|
||||
}
|
||||
else {
|
||||
owner->SetLowColor(owner->ViewColor());
|
||||
}
|
||||
|
||||
font_height fontHeight;
|
||||
be_plain_font->GetHeight(&fontHeight);
|
||||
BPoint point = itemRect.LeftTop() + BPoint(5, fontHeight.ascent);
|
||||
|
||||
owner->SetHighColor(kBlack);
|
||||
owner->SetFont(be_plain_font);
|
||||
owner->MovePenTo(point);
|
||||
owner->DrawString(Name());
|
||||
|
||||
point += BPoint(120, 0);
|
||||
BPath path(Path());
|
||||
owner->MovePenTo(point);
|
||||
owner->DrawString(path.Leaf() ? path.Leaf() : "<none>");
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2003, OpenBeOS
|
||||
//
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
//
|
||||
// File: HEventItem.h, Oliver Ruiz Dorantes, Atsushi Takamatsu
|
||||
// Author: Jérôme Duval
|
||||
// Description: Sounds Preferences
|
||||
// Created : November 24, 2003
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#ifndef __HEVENTITEM_H__
|
||||
#define __HEVENTITEM_H__
|
||||
|
||||
#include <ListItem.h>
|
||||
#include <String.h>
|
||||
#include <Entry.h>
|
||||
|
||||
|
||||
class HEventItem : public BListItem {
|
||||
public:
|
||||
HEventItem(const char* event_name
|
||||
,const char* path);
|
||||
virtual ~HEventItem();
|
||||
virtual void DrawItem(BView *owner, BRect itemRect,
|
||||
bool drawEverything = false);
|
||||
|
||||
const char* Name()const { return fName.String();}
|
||||
const char* Path()const { return fPath.String();}
|
||||
void Remove(const char *type);
|
||||
void SetPath(const char* path);
|
||||
protected:
|
||||
|
||||
private:
|
||||
BString fName;
|
||||
BString fPath;
|
||||
float fText_offset;
|
||||
};
|
||||
#endif
|
||||
@@ -1,58 +1,68 @@
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2003, OpenBeOS
|
||||
//
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
//
|
||||
// File: HEventList.cpp
|
||||
// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu
|
||||
// Description: Sounds Preferences
|
||||
// Created : November 24, 2003
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
/*
|
||||
* Copyright 2003-2008 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Jérôme Duval
|
||||
* Oliver Ruiz Dorantes
|
||||
* Atsushi Takamatsu
|
||||
*/
|
||||
#include "HEventList.h"
|
||||
#include "HEventItem.h"
|
||||
|
||||
#include "HWindow.h"
|
||||
#include <Bitmap.h>
|
||||
#include <ClassInfo.h>
|
||||
#include <Alert.h>
|
||||
#include <ColumnTypes.h>
|
||||
#include <Entry.h>
|
||||
#include <MediaFiles.h>
|
||||
#include <Path.h>
|
||||
#include <Alert.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <stdio.h>
|
||||
#include <Mime.h>
|
||||
#include <Roster.h>
|
||||
#include <NodeInfo.h>
|
||||
|
||||
/***********************************************************
|
||||
* Constructor
|
||||
***********************************************************/
|
||||
HEventList::HEventList(BRect rect, const char* name)
|
||||
: BListView(rect, name, B_SINGLE_SELECTION_LIST,
|
||||
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE),
|
||||
fType(NULL)
|
||||
|
||||
HEventRow::HEventRow(const char* name, const char* path)
|
||||
: BRow(),
|
||||
fName(name)
|
||||
{
|
||||
|
||||
SetPath(path);
|
||||
SetField(new BStringField(name), kEventColumn);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Destructor
|
||||
***********************************************************/
|
||||
|
||||
HEventRow::~HEventRow()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HEventRow::SetPath(const char* _path)
|
||||
{
|
||||
fPath = _path;
|
||||
BPath path(_path);
|
||||
SetField(new BStringField(_path ? path.Leaf() : "<none>"), kSoundColumn);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HEventRow::Remove(const char *type)
|
||||
{
|
||||
BMediaFiles().RemoveItem(type, Name());
|
||||
}
|
||||
|
||||
|
||||
HEventList::HEventList(BRect rect, const char* name)
|
||||
: BColumnListView(rect, name, B_FOLLOW_ALL, 0, B_NO_BORDER, true),
|
||||
fType(NULL)
|
||||
{
|
||||
AddColumn(new BStringColumn("Event", 150, 50, 500, B_TRUNCATE_MIDDLE), kEventColumn);
|
||||
AddColumn(new BStringColumn("Sound", 150, 50, 500, B_TRUNCATE_END), kSoundColumn);
|
||||
}
|
||||
|
||||
|
||||
HEventList::~HEventList()
|
||||
{
|
||||
RemoveAll();
|
||||
delete fType;
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Set type
|
||||
***********************************************************/
|
||||
|
||||
void
|
||||
HEventList::SetType(const char* type)
|
||||
{
|
||||
@@ -66,76 +76,64 @@ HEventList::SetType(const char* type)
|
||||
entry_ref ref;
|
||||
while (mfiles.GetNextRef(&name,&ref) == B_OK) {
|
||||
BPath path(&ref);
|
||||
AddItem(new HEventItem(name.String(), path.Path()));
|
||||
if ((path.InitCheck() == B_OK) || (ref.name == NULL) || (strcmp(ref.name, "") == 0))
|
||||
AddRow(new HEventRow(name.String(), path.Path()));
|
||||
else
|
||||
AddRow(new HEventRow(name.String(), NULL));
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Remove all items
|
||||
***********************************************************/
|
||||
|
||||
void
|
||||
HEventList::RemoveAll()
|
||||
{
|
||||
BListItem *item;
|
||||
while ((item = RemoveItem((int32)0))!=NULL)
|
||||
delete item;
|
||||
MakeEmpty();
|
||||
BRow *row;
|
||||
while ((row = RowAt((int32)0, NULL))!=NULL) {
|
||||
RemoveRow(row);
|
||||
delete row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************
|
||||
* Selection Changed
|
||||
***********************************************************/
|
||||
void
|
||||
HEventList::SelectionChanged()
|
||||
{
|
||||
BListView::SelectionChanged();
|
||||
BColumnListView::SelectionChanged();
|
||||
|
||||
int32 sel = CurrentSelection();
|
||||
if (sel >= 0) {
|
||||
HEventItem *item = cast_as(ItemAt(sel),HEventItem);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
HEventRow* row = (HEventRow *)CurrentSelection();
|
||||
if (row != NULL) {
|
||||
entry_ref ref;
|
||||
BMediaFiles().GetRefFor(fType, item->Name(), &ref);
|
||||
BMediaFiles().GetRefFor(fType, row->Name(), &ref);
|
||||
|
||||
BPath path(&ref);
|
||||
if ((path.InitCheck()==B_OK) || (ref.name == NULL) || (strcmp(ref.name, "")==0)) {
|
||||
item->SetPath(path.Path());
|
||||
InvalidateItem(sel);
|
||||
if ((path.InitCheck()==B_OK) || (ref.name == NULL) || (strcmp(ref.name, "") == 0)) {
|
||||
row->SetPath(path.Path());
|
||||
UpdateRow(row);
|
||||
} else {
|
||||
printf("name %s\n", ref.name);
|
||||
BMediaFiles().RemoveRefFor(fType, item->Name(), ref);
|
||||
BMediaFiles().RemoveRefFor(fType, row->Name(), ref);
|
||||
(new BAlert("alert", "No such file or directory", "Ok"))->Go();
|
||||
return;
|
||||
}
|
||||
BMessage msg(M_EVENT_CHANGED);
|
||||
msg.AddString("name",item->Name());
|
||||
|
||||
msg.AddString("path",item->Path());
|
||||
msg.AddString("name", row->Name());
|
||||
msg.AddString("path", row->Path());
|
||||
Window()->PostMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* SetPath
|
||||
***********************************************************/
|
||||
|
||||
void
|
||||
HEventList::SetPath(const char* path)
|
||||
{
|
||||
int32 sel = CurrentSelection();
|
||||
if (sel >= 0) {
|
||||
HEventItem *item = cast_as(ItemAt(sel),HEventItem);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
HEventRow* row = (HEventRow *)CurrentSelection();
|
||||
if (row != NULL) {
|
||||
entry_ref ref;
|
||||
BEntry entry(path);
|
||||
entry.GetRef(&ref);
|
||||
BMediaFiles().SetRefFor(fType, item->Name(), ref);
|
||||
BMediaFiles().SetRefFor(fType, row->Name(), ref);
|
||||
|
||||
item->SetPath(path);
|
||||
InvalidateItem(sel);
|
||||
row->SetPath(path);
|
||||
UpdateRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,57 @@
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2003, OpenBeOS
|
||||
//
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
//
|
||||
// File: HEventList.h
|
||||
// Author: Jérôme Duval, Oliver Ruiz Dorantes, Atsushi Takamatsu
|
||||
// Description: Sounds Preferences
|
||||
// Created : November 24, 2003
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
/*
|
||||
* Copyright 2003-2008 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* Jérôme Duval
|
||||
* Oliver Ruiz Dorantes
|
||||
* Atsushi Takamatsu
|
||||
*/
|
||||
#ifndef __HEVENTLIST_H__
|
||||
#define __HEVENTLIST_H__
|
||||
|
||||
#include <ListView.h>
|
||||
#include "HEventItem.h"
|
||||
#include <ColumnListView.h>
|
||||
#include <String.h>
|
||||
|
||||
enum{
|
||||
enum {
|
||||
kEventColumn,
|
||||
kSoundColumn,
|
||||
};
|
||||
|
||||
|
||||
class HEventRow : public BRow {
|
||||
public:
|
||||
HEventRow(const char* event_name,
|
||||
const char* path);
|
||||
virtual ~HEventRow();
|
||||
|
||||
const char* Name() const { return fName.String();}
|
||||
const char* Path() const { return fPath.String();}
|
||||
void Remove(const char *type);
|
||||
void SetPath(const char* path);
|
||||
protected:
|
||||
|
||||
private:
|
||||
BString fName;
|
||||
BString fPath;
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
M_EVENT_CHANGED = 'SCAG'
|
||||
};
|
||||
|
||||
class HEventList : public BListView {
|
||||
|
||||
class HEventList : public BColumnListView {
|
||||
public:
|
||||
HEventList(BRect rect
|
||||
, const char* name="EventList");
|
||||
HEventList(BRect rect,
|
||||
const char* name = "EventList");
|
||||
virtual ~HEventList();
|
||||
void RemoveAll();
|
||||
void SetType(const char* type);
|
||||
void SetPath(const char* path);
|
||||
protected:
|
||||
virtual void SelectionChanged();
|
||||
virtual void SelectionChanged();
|
||||
private:
|
||||
char *fType;
|
||||
};
|
||||
|
||||
@@ -50,8 +50,6 @@ HWindow::HWindow(BRect rect, const char *name)
|
||||
|
||||
fFilePanel = new BFilePanel();
|
||||
fFilePanel->SetTarget(this);
|
||||
|
||||
fEventList->Select(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,28 +69,13 @@ HWindow::InitGUI()
|
||||
listView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
AddChild(listView);
|
||||
|
||||
BRect stringRect(16, 5, 60, 22);
|
||||
BStringView *stringView = new BStringView(stringRect, "event", "Event");
|
||||
stringView->SetFont(be_bold_font);
|
||||
stringView->ResizeToPreferred();
|
||||
listView->AddChild(stringView);
|
||||
|
||||
stringRect.OffsetBy(120, 0);
|
||||
stringView = new BStringView(stringRect, "sound", "Sound");
|
||||
stringView->SetFont(be_bold_font);
|
||||
stringView->ResizeToPreferred();
|
||||
listView->AddChild(stringView);
|
||||
|
||||
rect.left += 13;
|
||||
rect.right -= B_V_SCROLL_BAR_WIDTH + 13;
|
||||
rect.right -= 13;
|
||||
rect.top += 28;
|
||||
rect.bottom -= 7;
|
||||
fEventList = new HEventList(rect);
|
||||
fEventList->SetType(BMediaFiles::B_SOUNDS);
|
||||
|
||||
BScrollView *scrollView = new BScrollView("", fEventList, B_FOLLOW_ALL, 0,
|
||||
false, true);
|
||||
listView->AddChild(scrollView);
|
||||
listView->AddChild(fEventList);
|
||||
|
||||
rect = Bounds();
|
||||
rect.top = rect.bottom - 105;
|
||||
@@ -158,10 +141,9 @@ HWindow::MessageReceived(BMessage *message)
|
||||
BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
|
||||
BMenu *menu = menufield->Menu();
|
||||
|
||||
int32 sel = fEventList->CurrentSelection();
|
||||
if (sel >= 0) {
|
||||
HEventItem *item = cast_as(fEventList->ItemAt(sel), HEventItem);
|
||||
BPath path(item->Path());
|
||||
HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
|
||||
if (row != NULL) {
|
||||
BPath path(row->Path());
|
||||
if (path.InitCheck() != B_OK) {
|
||||
BMenuItem *item = menu->FindItem("<none>");
|
||||
if (item)
|
||||
@@ -180,8 +162,8 @@ HWindow::MessageReceived(BMessage *message)
|
||||
case B_REFS_RECEIVED:
|
||||
{
|
||||
entry_ref ref;
|
||||
int32 sel = fEventList->CurrentSelection();
|
||||
if (message->FindRef("refs", &ref) == B_OK && sel >= 0) {
|
||||
HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
|
||||
if (message->FindRef("refs", &ref) == B_OK && row != NULL) {
|
||||
BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
|
||||
BMenu *menu = menufield->Menu();
|
||||
|
||||
@@ -218,10 +200,9 @@ HWindow::MessageReceived(BMessage *message)
|
||||
|
||||
case M_PLAY_MESSAGE:
|
||||
{
|
||||
int32 sel = fEventList->CurrentSelection();
|
||||
if (sel >= 0) {
|
||||
HEventItem *item = cast_as(fEventList->ItemAt(sel), HEventItem);
|
||||
const char *path = item->Path();
|
||||
HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
|
||||
if (row != NULL) {
|
||||
const char *path = row->Path();
|
||||
if (path) {
|
||||
entry_ref ref;
|
||||
::get_ref_for_path(path, &ref);
|
||||
@@ -291,13 +272,13 @@ HWindow::SetupMenuField()
|
||||
{
|
||||
BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
|
||||
BMenu *menu = menufield->Menu();
|
||||
int32 count = fEventList->CountItems();
|
||||
int32 count = fEventList->CountRows();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
HEventItem *item = cast_as(fEventList->ItemAt(i), HEventItem);
|
||||
if (!item)
|
||||
HEventRow *row = (HEventRow *)fEventList->RowAt(i);
|
||||
if (!row)
|
||||
continue;
|
||||
|
||||
BPath path(item->Path());
|
||||
BPath path(row->Path());
|
||||
if (path.InitCheck() != B_OK)
|
||||
continue;
|
||||
if (menu->FindItem(path.Leaf()))
|
||||
@@ -383,7 +364,7 @@ HWindow::SetupMenuField()
|
||||
void
|
||||
HWindow::Pulse()
|
||||
{
|
||||
int32 sel = fEventList->CurrentSelection();
|
||||
HEventRow* row = (HEventRow *)fEventList->CurrentSelection();
|
||||
BMenuField *menufield = cast_as(FindView("filemenu"), BMenuField);
|
||||
BButton *button = cast_as(FindView("play"), BButton);
|
||||
BButton *stop = cast_as(FindView("stop"), BButton);
|
||||
@@ -391,11 +372,10 @@ HWindow::Pulse()
|
||||
if (!menufield)
|
||||
return;
|
||||
|
||||
if (sel >= 0) {
|
||||
if (row != NULL) {
|
||||
menufield->SetEnabled(true);
|
||||
|
||||
HEventItem *item = cast_as(fEventList->ItemAt(sel), HEventItem);
|
||||
const char *path = item->Path();
|
||||
const char *path = row->Path();
|
||||
if (path && strcmp(path, ""))
|
||||
button->SetEnabled(true);
|
||||
else
|
||||
|
||||
@@ -2,15 +2,13 @@ SubDir HAIKU_TOP src preferences sounds ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
|
||||
SubDirC++Flags -fmultiple-symbol-spaces ;
|
||||
}
|
||||
UsePrivateHeaders interface ;
|
||||
|
||||
Preference Sounds :
|
||||
HApp.cpp
|
||||
HEventItem.cpp
|
||||
# HEventItem.cpp
|
||||
HWindow.cpp
|
||||
HEventList.cpp
|
||||
: be game tracker libmedia.so
|
||||
: be libcolumnlistview.a game tracker libmedia.so
|
||||
: Sounds.rdef
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user