Author: yourpalal Date: 2011-01-11 20:34:05 +0100 (Tue, 11 Jan 2011) New Revision: 40207 Changeset: http://dev.haiku-os.org/changeset/40207 Modified: haiku/trunk/src/preferences/media/MediaListItem.cpp haiku/trunk/src/preferences/media/MediaWindow.cpp haiku/trunk/src/preferences/media/MediaWindow.h Log: In Media preflet: add an ItemWidth() method to MediaListItem::Renderer, which tells us how much space is needed onscreen for a MediaListItem. Use the new ItemWidth() method in MediaListItem::Update() to set our width. Add a MediaWindow::_UpdateListItemMinSize() method that uses the items' width to calculate the new explicit min width of our list view. This fixes a problem I saw with localized strings in the listview not being fully displayed. Modified: haiku/trunk/src/preferences/media/MediaListItem.cpp =================================================================== --- haiku/trunk/src/preferences/media/MediaListItem.cpp 2011-01-11 19:15:14 UTC (rev 40206) +++ haiku/trunk/src/preferences/media/MediaListItem.cpp 2011-01-11 19:34:05 UTC (rev 40207) @@ -119,6 +119,22 @@ onto->SetLowColor(lowColor); } + float ItemWidth() + { + float width = 4.0f; + // left margin + + float iconSpace = MediaIcons::sBounds.Width() + 1.0f; + if (fDoubleInsets) + iconSpace *= 2.0f; + width += iconSpace; + width += 8.0f; + // space between icons and text + + width += be_plain_font->StringWidth(fTitle) + 3.0f; + return width; + } + private: const char* fTitle; @@ -147,6 +163,11 @@ if ((Height() < iconHeight + kITEM_MARGIN * 2)) { SetHeight(iconHeight + kITEM_MARGIN * 2); } + + Renderer renderer; + renderer.SetTitle(Label()); + SetRenderParameters(renderer); + SetWidth(renderer.ItemWidth()); } Modified: haiku/trunk/src/preferences/media/MediaWindow.cpp =================================================================== --- haiku/trunk/src/preferences/media/MediaWindow.cpp 2011-01-11 19:15:14 UTC (rev 40206) +++ haiku/trunk/src/preferences/media/MediaWindow.cpp 2011-01-11 19:34:05 UTC (rev 40207) @@ -341,6 +341,19 @@ void +MediaWindow::_UpdateListViewMinWidth() +{ + float width = 0; + for (int32 i = 0; i < fListView->CountItems(); i++) { + BListItem* item = fListView->ItemAt(i); + width = max_c(width, item->Width()); + } + fListView->SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); + fListView->InvalidateLayout(); +} + + +void MediaWindow::_AddNodeItems(NodeList &list, MediaListItem::media_type type) { int32 count = list.CountItems(); @@ -365,16 +378,12 @@ void MediaWindow::InitWindow() { - const float scrollWidth = 9 * be_plain_font->Size() + 30; - fListView = new BListView("media_list_view"); fListView->SetSelectionMessage(new BMessage(ML_SELECTED_NODE)); - // Add ScrollView to Media Menu + // Add ScrollView to Media Menu for pretty border BScrollView* scrollView = new BScrollView("listscroller", fListView, 0, false, false, B_FANCY_BORDER); - scrollView->SetExplicitMinSize(BSize(scrollWidth, B_SIZE_UNSET)); - scrollView->SetExplicitMaxSize(BSize(scrollWidth, B_SIZE_UNSET)); // Create the Views fTitleView = new BSeparatorView(B_HORIZONTAL, B_FANCY_BORDER); @@ -455,7 +464,7 @@ } while (fListView->CountItems() > 0) - delete static_cast<MediaListItem*>(fListView->RemoveItem((int32)0)); + delete fListView->RemoveItem((int32)0); _EmptyNodeLists(); // Grab Media Info @@ -486,6 +495,7 @@ fListView->AddItem(mixer); fListView->SortItems(&MediaListItem::Compare); + _UpdateListViewMinWidth(); // Set default nodes for our setting views media_node default_node; Modified: haiku/trunk/src/preferences/media/MediaWindow.h =================================================================== --- haiku/trunk/src/preferences/media/MediaWindow.h 2011-01-11 19:15:14 UTC (rev 40206) +++ haiku/trunk/src/preferences/media/MediaWindow.h 2011-01-11 19:34:05 UTC (rev 40207) @@ -74,6 +74,7 @@ void _AddNodeItems(NodeList &from, MediaListItem::media_type type); void _EmptyNodeLists(); + void _UpdateListViewMinWidth(); NodeListItem* _FindNodeListItem(dormant_node_info* info); void InitWindow();