The Media preflet was using a mix of old and layout style primitives to set itself up. As a consequence resizing basically didn't work correctly at all. Fixes ticket #3427.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31038 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent 2009-06-14 00:37:07 +00:00
parent 2e38e90efb
commit c8602bcd11
3 changed files with 37 additions and 93 deletions

View File

@ -31,8 +31,8 @@
#include "MediaViews.h" #include "MediaViews.h"
BarView::BarView(BRect frame) BarView::BarView()
: BView (frame, "barView", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW ), : BView ("barView", B_WILL_DRAW ),
fDisplay(true) fDisplay(true)
{ {
} }
@ -56,24 +56,18 @@ BarView::Draw(BRect updateRect)
} }
SettingsView::SettingsView (BRect frame, bool isVideo) SettingsView::SettingsView (bool isVideo)
: BView (frame, "SettingsView", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ), : BView ("SettingsView", B_WILL_DRAW | B_SUPPORTS_LAYOUT),
fIsVideo(isVideo) fIsVideo(isVideo)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BRect rect(frame); BBox *defaultsBox = new BBox("defaults");
rect.left += 10;
rect.top += 12;
rect.right -=21;
rect.bottom = rect.top + 104;
BBox *defaultsBox = new BBox(rect, "defaults");
defaultsBox->SetLabel(fIsVideo ? "Default Nodes" : "Defaults"); defaultsBox->SetLabel(fIsVideo ? "Default Nodes" : "Defaults");
// create the default box // create the default box
BGroupLayout* defaultBoxLayout = new BGroupLayout(B_VERTICAL, 5); BGroupLayout* defaultBoxLayout = new BGroupLayout(B_VERTICAL, 5);
float inset = defaultsBox->Frame().left - defaultsBox->InnerFrame().left; defaultBoxLayout->SetInsets(10,10,10,10);
defaultBoxLayout->SetInsets(inset, defaultsBox->TopBorderOffset() * 2, inset, inset);
defaultsBox->SetLayout(defaultBoxLayout); defaultsBox->SetLayout(defaultBoxLayout);
defaultBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5)); defaultBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5));
@ -82,19 +76,17 @@ SettingsView::SettingsView (BRect frame, bool isVideo)
defaultsBox->GetLayout()->AddView(inputField); defaultsBox->GetLayout()->AddView(inputField);
defaultsBox->GetLayout()->AddView(outputField); defaultsBox->GetLayout()->AddView(outputField);
BRect defaultRect(20, 22, 250, 40);
float divider = StringWidth(fIsVideo ? "Video Output:" : "Audio Output:") + 5; float divider = StringWidth(fIsVideo ? "Video Output:" : "Audio Output:") + 5;
fMenu1 = new BPopUpMenu("<none>"); fMenu1 = new BPopUpMenu("<none>");
fMenu1->SetLabelFromMarked(true); fMenu1->SetLabelFromMarked(true);
BMenuField *menuField1 = new BMenuField(defaultRect, "menuField1", BMenuField *menuField1 = new BMenuField("menuField1",
fIsVideo ? "Video Input:" : "Audio Input:", fMenu1); fIsVideo ? "Video Input:" : "Audio Input:", fMenu1, NULL);
menuField1->SetDivider(divider); menuField1->SetDivider(divider);
defaultRect.OffsetBy(0, 26);
fMenu2 = new BPopUpMenu("<none>"); fMenu2 = new BPopUpMenu("<none>");
fMenu2->SetLabelFromMarked(true); fMenu2->SetLabelFromMarked(true);
BMenuField *menuField2 = new BMenuField(defaultRect, "menuField2", BMenuField *menuField2 = new BMenuField("menuField2",
fIsVideo ? "Video Output:" : "Audio Output:", fMenu2); fIsVideo ? "Video Output:" : "Audio Output:", fMenu2, NULL);
menuField2->SetDivider(divider); menuField2->SetDivider(divider);
inputField->GroupLayout()->AddView(menuField1); inputField->GroupLayout()->AddView(menuField1);
@ -102,48 +94,37 @@ SettingsView::SettingsView (BRect frame, bool isVideo)
BMenuField *menuField3 = NULL; BMenuField *menuField3 = NULL;
if (!fIsVideo) { if (!fIsVideo) {
defaultRect.OffsetBy(186, 0);
defaultRect.right -= 30;
fMenu3 = new BPopUpMenu("<none>"); fMenu3 = new BPopUpMenu("<none>");
fMenu3->SetLabelFromMarked(true); fMenu3->SetLabelFromMarked(true);
menuField3 = new BMenuField(defaultRect, "menuField3", menuField3 = new BMenuField("menuField3",
"Channel:", fMenu3); "Channel:", fMenu3, NULL);
outputField->GroupLayout()->AddView(menuField3); outputField->GroupLayout()->AddView(menuField3);
menuField3->SetDivider(StringWidth("Channel:")+5); menuField3->SetDivider(StringWidth("Channel:")+5);
defaultRect.right += 30;
defaultRect.OffsetBy(-186, 0);
} }
defaultRect.OffsetBy(0, 32);
defaultRect.right += 100;
rgb_color red_color = {222, 32, 33}; rgb_color red_color = {222, 32, 33};
fRestartView = new BStringView(defaultRect, "restartStringView", "Restart the Media Server to apply changes.", fRestartView = new BStringView("restartStringView",
B_FOLLOW_ALL, B_WILL_DRAW); "Restart the Media Server to apply changes.");
fRestartView->SetHighColor(red_color); fRestartView->SetHighColor(red_color);
defaultsBox->AddChild(fRestartView); defaultsBox->AddChild(fRestartView);
fRestartView->Hide(); fRestartView->Hide();
// create the realtime box // create the realtime box
rect.top = rect.bottom + 10; BBox *realtimeBox = new BBox("realtime");
rect.bottom = rect.top + 162;
BBox *realtimeBox = new BBox(rect, "realtime");
realtimeBox->SetLabel("Real-Time"); realtimeBox->SetLabel("Real-Time");
BMessage *message = new BMessage(ML_ENABLE_REAL_TIME); BMessage *message = new BMessage(ML_ENABLE_REAL_TIME);
message->AddBool("isVideo", fIsVideo); message->AddBool("isVideo", fIsVideo);
BRect rect2(22,20, frame.Width() - 22, 40); fRealtimeCheckBox = new BCheckBox("realtimeCheckBox",
fRealtimeCheckBox = new BCheckBox(rect2, "realtimeCheckBox", fIsVideo ? "Enable Real-Time Video" : "Enable Real-Time Audio",
fIsVideo ? "Enable Real-Time Video" : "Enable Real-Time Audio", message); message);
uint32 flags; uint32 flags;
BMediaRoster::Roster()->GetRealtimeFlags(&flags); BMediaRoster::Roster()->GetRealtimeFlags(&flags);
if (flags & (fIsVideo ? B_MEDIA_REALTIME_VIDEO : B_MEDIA_REALTIME_AUDIO)) if (flags & (fIsVideo ? B_MEDIA_REALTIME_VIDEO : B_MEDIA_REALTIME_AUDIO))
fRealtimeCheckBox->SetValue(B_CONTROL_ON); fRealtimeCheckBox->SetValue(B_CONTROL_ON);
rect2.top += 26; BTextView *textView = new BTextView("stringView");
rect2.bottom = rect.Height() - 5;
BRect textRect(3, 3, rect2.Width() - 3, rect2.Height() - 3);
BTextView *textView = new BTextView(rect2, "stringView", textRect, B_FOLLOW_ALL, B_WILL_DRAW);
textView->Insert(fIsVideo ? "Enabling Real-Time Video allows system to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM." textView->Insert(fIsVideo ? "Enabling Real-Time Video allows system to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM."
"\n\nOnly enable this feature if you need the lowest latency possible." "\n\nOnly enable this feature if you need the lowest latency possible."
: "Enabling Real-time Audio allows system to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM." : "Enabling Real-time Audio allows system to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM."
@ -153,8 +134,7 @@ SettingsView::SettingsView (BRect frame, bool isVideo)
textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BGroupLayout* realtimeBoxLayout = new BGroupLayout(B_VERTICAL, 5); BGroupLayout* realtimeBoxLayout = new BGroupLayout(B_VERTICAL, 5);
inset = realtimeBox->Frame().left - realtimeBox->InnerFrame().left; realtimeBoxLayout->SetInsets(10,10,10,10);
realtimeBoxLayout->SetInsets(inset, defaultsBox->TopBorderOffset() * 2, inset, inset);
realtimeBox->SetLayout(realtimeBoxLayout); realtimeBox->SetLayout(realtimeBoxLayout);
realtimeBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5)); realtimeBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5));
@ -163,19 +143,11 @@ SettingsView::SettingsView (BRect frame, bool isVideo)
// create the bottom line: volumen in deskbar checkbox and restart button // create the bottom line: volumen in deskbar checkbox and restart button
BGroupView* bottomView = new BGroupView(B_HORIZONTAL); BGroupView* bottomView = new BGroupView(B_HORIZONTAL);
rect.top = rect.bottom + 11; BButton *restartButton = new BButton("restartButton",
rect.bottom = rect.top + 20;
rect.left = rect.right - StringWidth("Restart Media Services") - 20;
BButton *restartButton = new BButton(rect, "restartButton",
"Restart Media Services", new BMessage(ML_RESTART_MEDIA_SERVER)); "Restart Media Services", new BMessage(ML_RESTART_MEDIA_SERVER));
if (!fIsVideo) { if (!fIsVideo) {
rect.right = rect.left - 10; fVolumeCheckBox = new BCheckBox("volumeCheckBox",
rect.top += 4;
rect.left = frame.left + 33;
if (StringWidth("Show Volume Control on Deskbar") > rect.Width() - 30)
rect.left -= 10;
fVolumeCheckBox = new BCheckBox(rect, "volumeCheckBox",
"Show Volume Control on Deskbar", new BMessage(ML_SHOW_VOLUME_CONTROL)); "Show Volume Control on Deskbar", new BMessage(ML_SHOW_VOLUME_CONTROL));
bottomView->GroupLayout()->AddView(fVolumeCheckBox); bottomView->GroupLayout()->AddView(fVolumeCheckBox);
if (BDeskbar().HasItem("MediaReplicant")) if (BDeskbar().HasItem("MediaReplicant"))

View File

@ -30,7 +30,7 @@ const uint32 ML_DEFAULTOUTPUT_CHANGE = 'doch';
class BarView : public BView class BarView : public BView
{ {
public: public:
BarView(BRect frame); BarView();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
bool fDisplay; bool fDisplay;
}; };
@ -58,7 +58,7 @@ class Settings2Item : public BMenuItem
class SettingsView : public BView class SettingsView : public BView
{ {
public: public:
SettingsView(BRect frame, bool isVideo); SettingsView(bool isVideo);
void AddNodes(BList &list, bool isInput); void AddNodes(BList &list, bool isInput);
void SetDefault(dormant_node_info &info, bool isInput, int32 outputID = -1); void SetDefault(dormant_node_info &info, bool isInput, int32 outputID = -1);
BCheckBox *fRealtimeCheckBox; BCheckBox *fRealtimeCheckBox;

View File

@ -35,7 +35,7 @@ const uint32 ML_INIT_MEDIA = 'MlIM';
// MediaWindow - Constructor // MediaWindow - Constructor
MediaWindow::MediaWindow(BRect frame) MediaWindow::MediaWindow(BRect frame)
: BWindow (frame, "Media", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS), : BWindow (frame, "Media", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fCurrentNode(NULL), fCurrentNode(NULL),
fParamWeb(NULL), fParamWeb(NULL),
fAlert(NULL), fAlert(NULL),
@ -172,59 +172,36 @@ MediaWindow::InitWindow(void)
fIcons.AddItem(icon); fIcons.AddItem(icon);
const float scrollWidth = 9 * be_plain_font->Size() + 30; const float scrollWidth = 9 * be_plain_font->Size() + 30;
const float contentWidth = 34 * be_plain_font->Size();
float totalWidthFont = scrollWidth + contentWidth + 14 * 3;
const float totalWidth = (605.0 > totalWidthFont) ?
605.0 : totalWidthFont;
BRect bounds = Bounds(); // the whole view fListView = new BListView("media_list_view");
// Create the OutlineView
font_height titleHeightStruct;
be_bold_font->GetHeight(&titleHeightStruct);
float titleHeight = titleHeightStruct.ascent + titleHeightStruct.descent
+ titleHeightStruct.leading + 1;
BRect menuRect(bounds.left + 14, bounds.top + 14, scrollWidth,
bounds.bottom - 14);
BRect titleRect(menuRect.right + 14, menuRect.top,
totalWidth - 10, menuRect.top + titleHeight);
BRect availableRect(menuRect.right + 15, titleRect.bottom + 12,
totalWidth - 14, bounds.bottom - 16);
BRect barRect(titleRect.left, titleRect.bottom + 10,
titleRect.right - 2, titleRect.bottom + 11);
fListView = new BListView(menuRect, "media_list_view",
B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
fListView->SetSelectionMessage(new BMessage(ML_SELECTED_NODE)); fListView->SetSelectionMessage(new BMessage(ML_SELECTED_NODE));
// Add ScrollView to Media Menu // Add ScrollView to Media Menu
BScrollView *scrollView = new BScrollView("listscroller", BScrollView *scrollView = new BScrollView("listscroller",
fListView, B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM, 0, false, false, fListView, 0, false, false, B_FANCY_BORDER);
B_FANCY_BORDER);
scrollView->SetExplicitMinSize(BSize(scrollWidth, B_SIZE_UNSET)); scrollView->SetExplicitMinSize(BSize(scrollWidth, B_SIZE_UNSET));
scrollView->SetExplicitMaxSize(BSize(scrollWidth, B_SIZE_UNSET)); scrollView->SetExplicitMaxSize(BSize(scrollWidth, B_SIZE_UNSET));
// Create the Views // Create the Views
fBox = new BBox(bounds, "background", B_FOLLOW_ALL_SIDES, fBox = new BBox("background", B_WILL_DRAW | B_FRAME_EVENTS,
B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); B_PLAIN_BORDER);
SetLayout(new BGroupLayout(B_HORIZONTAL)); SetLayout(new BGroupLayout(B_HORIZONTAL));
GetLayout()->AddView(fBox); GetLayout()->AddView(fBox);
// StringViews // StringViews
rgb_color titleFontColor = { 0,0,0,0 }; rgb_color titleFontColor = { 0,0,0,0 };
fTitleView = new BStringView(titleRect, "AudioSettings", fTitleView = new BStringView("AudioSettings",
"Audio Settings", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); "Audio Settings", B_WILL_DRAW);
fTitleView->SetFont(be_bold_font); fTitleView->SetFont(be_bold_font);
fTitleView->SetHighColor(titleFontColor); fTitleView->SetHighColor(titleFontColor);
fContentView = new BBox(availableRect, "contentView", fContentView = new BBox("contentView", B_WILL_DRAW | B_FRAME_EVENTS,
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, B_NO_BORDER); B_NO_BORDER);
BRect settingsRect(0, 0, availableRect.Width(), availableRect.Height()); fAudioView = new SettingsView(false);
fAudioView = new SettingsView(settingsRect, false); fVideoView = new SettingsView(true);
fVideoView = new SettingsView(settingsRect, true);
fBar = new BarView(barRect); fBar = new BarView();
BGroupView* titleGroupView = new BGroupView(B_HORIZONTAL); BGroupView* titleGroupView = new BGroupView(B_HORIZONTAL);
titleGroupView->GroupLayout()->AddView(fTitleView); titleGroupView->GroupLayout()->AddView(fTitleView);
titleGroupView->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); titleGroupView->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
@ -252,11 +229,6 @@ MediaWindow::InitWindow(void)
if (IsHidden()) if (IsHidden())
Show(); Show();
} }
// Set window limits
ResizeTo(totalWidth + 14, bounds.Height());
SetZoomLimits(totalWidth + 14, bounds.Height());
SetSizeLimits(totalWidth + 14, 100000, bounds.Height(), 100000);
} }
@ -705,7 +677,7 @@ MediaWindow::UpdateProgress(int stage, const char * message, void * cookie)
{ {
MediaAlert *alert = static_cast<MediaAlert*>(cookie); MediaAlert *alert = static_cast<MediaAlert*>(cookie);
PRINT(("stage : %i\n", stage)); PRINT(("stage : %i\n", stage));
char *string = "Unknown stage"; const char *string = "Unknown stage";
switch (stage) { switch (stage) {
case 10: case 10:
string = "Stopping Media Server" B_UTF8_ELLIPSIS; string = "Stopping Media Server" B_UTF8_ELLIPSIS;