1/*
2 * Copyright 2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Author:
6 *		Artur Wyszynski <harakash@gmail.com>
7 *		Modified by Pieter Panman
8 */
9
10#include "PropertyListPlain.h"
11
12#include <GridLayout.h>
13#include <GridLayoutBuilder.h>
14#include <GroupLayout.h>
15#include <GroupLayoutBuilder.h>
16#include <Message.h>
17#include <SpaceLayoutItem.h>
18#include <String.h>
19#include <StringView.h>
20
21#include "Device.h"
22
23
24PropertyListPlain::PropertyListPlain(const char* name)
25	:
26	BView(name, 0, NULL)
27{
28	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
29	SetLayout(new BGroupLayout(B_VERTICAL));
30}
31
32
33PropertyListPlain::~PropertyListPlain()
34{
35
36}
37
38
39void
40PropertyListPlain::AddAttributes(const Attributes& attributes)
41{
42	RemoveAll();
43	BGridLayoutBuilder builder(5, 5);
44	unsigned int i;
45	for (i = 0; i < attributes.size(); i++) {
46		const char* name = attributes[i].fName;
47		const char* value = attributes[i].fValue;
48
49		BString tempViewName(name);
50		BStringView *nameView = new BStringView(tempViewName.String(), name);
51		tempViewName.Append("Value");
52		BStringView *valueView = new BStringView(tempViewName.String(), value);
53
54		nameView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
55			B_ALIGN_VERTICAL_UNSET));
56		valueView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
57			B_ALIGN_VERTICAL_UNSET));
58
59		builder
60			.Add(nameView, 0, i)
61			.Add(valueView, 1, i);
62	}
63
64	// make sure that all content is left and top aligned
65	builder.Add(BSpaceLayoutItem::CreateGlue(), 2, i);
66
67	AddChild(BGroupLayoutBuilder(B_VERTICAL,5)
68		.Add(builder)
69		.SetInsets(5, 5, 5, 5)
70	);
71}
72
73
74void
75PropertyListPlain::RemoveAll()
76{
77	BView *child;
78	while((child = ChildAt(0))) {
79		RemoveChild(child);
80		delete child;
81	}
82}
83
84
85void
86PropertyListPlain::MessageReceived(BMessage* message)
87{
88	switch (message->what) {
89		default:
90			BView::MessageReceived(message);
91	}
92}
93
94
95void
96PropertyListPlain::AttachedToWindow()
97{
98}
99
100
101void
102PropertyListPlain::DetachedFromWindow()
103{
104}
105