2 * Copyright 2010, Haiku, Inc. All Rights Reserved.
3 * Copyright 2009, Pier Luigi Fiorini.
4 * Distributed under the terms of the MIT License.
7 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
15 #include <Directory.h>
17 #include <FindDirectory.h>
18 #include <GroupLayout.h>
19 #include <GridLayoutBuilder.h>
20 #include <SpaceLayoutItem.h>
21 #include <TextControl.h>
24 #include <MenuField.h>
27 #include <notification/Notifications.h>
30 #include "DisplayView.h"
31 #include "SettingsHost.h"
34 #undef B_TRANSLATION_CONTEXT
35 #define B_TRANSLATION_CONTEXT "DisplayView"
38 DisplayView::DisplayView(SettingsHost
* host
)
40 SettingsPane("display", host
)
43 fWindowWidth
= new BTextControl(B_TRANSLATE("Window width:"), NULL
,
44 new BMessage(kSettingChanged
));
47 fIconSize
= new BMenu("iconSize");
48 fIconSize
->AddItem(new BMenuItem(B_TRANSLATE("Mini icon"),
49 new BMessage(kSettingChanged
)));
50 fIconSize
->AddItem(new BMenuItem(B_TRANSLATE("Large icon"),
51 new BMessage(kSettingChanged
)));
52 fIconSize
->SetLabelFromMarked(true);
53 fIconSizeField
= new BMenuField(B_TRANSLATE("Icon size:"), fIconSize
);
56 float inset
= ceilf(be_plain_font
->Size() * 0.7f
);
58 SetLayout(new BGroupLayout(B_VERTICAL
));
59 AddChild(BGridLayoutBuilder(inset
, inset
)
60 .Add(fWindowWidth
->CreateLabelLayoutItem(), 0, 0)
61 .Add(fWindowWidth
->CreateTextViewLayoutItem(), 1, 0)
62 .Add(fIconSizeField
->CreateLabelLayoutItem(), 0, 1)
63 .Add(fIconSizeField
->CreateMenuBarLayoutItem(), 1, 1)
64 .Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2, 1)
65 .SetInsets(inset
, inset
, inset
, inset
)
71 DisplayView::AttachedToWindow()
73 fWindowWidth
->SetTarget(this);
74 fIconSize
->SetTargetForItems(this);
79 DisplayView::MessageReceived(BMessage
* msg
)
83 SettingsPane::MessageReceived(msg
);
86 BView::MessageReceived(msg
);
92 DisplayView::Load(BMessage
& settings
)
97 if (find_directory(B_USER_SETTINGS_DIRECTORY
, &path
) != B_OK
)
100 path
.Append(kSettingsFile
);
102 BFile
file(path
.Path(), B_READ_ONLY
);
104 settings
.Unflatten(&file
);
109 BMenuItem
* item
= NULL
;
112 if (settings
.FindFloat(kWidthName
, &width
) != B_OK
)
113 width
= kDefaultWidth
;
114 (void)sprintf(buffer
, "%.2f", width
);
115 fWindowWidth
->SetText(buffer
);
118 if (settings
.FindInt32(kIconSizeName
, &setting
) != B_OK
)
119 iconSize
= kDefaultIconSize
;
121 iconSize
= (icon_size
)setting
;
122 if (iconSize
== B_MINI_ICON
)
123 item
= fIconSize
->ItemAt(0);
125 item
= fIconSize
->ItemAt(1);
127 item
->SetMarked(true);
134 DisplayView::Save(BMessage
& settings
)
136 float width
= atof(fWindowWidth
->Text());
137 settings
.AddFloat(kWidthName
, width
);
139 icon_size iconSize
= kDefaultIconSize
;
140 switch (fIconSize
->IndexOf(fIconSize
->FindMarked())) {
142 iconSize
= B_MINI_ICON
;
145 iconSize
= B_LARGE_ICON
;
147 settings
.AddInt32(kIconSizeName
, (int32
)iconSize
);
154 DisplayView::Revert()