diff --git a/src/apps/haiku-depot/FilterView.cpp b/src/apps/haiku-depot/FilterView.cpp new file mode 100644 index 0000000000..50c12a3880 --- /dev/null +++ b/src/apps/haiku-depot/FilterView.cpp @@ -0,0 +1,95 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "FilterView.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "FilterView" + + +enum { + MSG_CATEGORY_SELECTED = 'ctsl', + MSG_REPOSITORY_SELECTED = 'rpsl', + MSG_SEARCH_TERMS_MODIFIED = 'stmd', +}; + + +FilterView::FilterView() + : + BGroupView("filter view") +{ + // Contruct category popup + BPopUpMenu* categoryMenu = new BPopUpMenu(B_TRANSLATE("Category")); + fCategoryField = new BMenuField("category", B_TRANSLATE("Category:"), + categoryMenu); + + // Construct repository popup + BPopUpMenu* repositoryMenu = new BPopUpMenu(B_TRANSLATE("Depot")); + fRepositoryField = new BMenuField("repository", B_TRANSLATE("Depot:"), + repositoryMenu); + + // Construct search terms field + fSearchTermsText = new BTextControl("search terms", + B_TRANSLATE("Search terms:"), "", NULL); + fSearchTermsText->SetModificationMessage( + new BMessage(MSG_SEARCH_TERMS_MODIFIED)); + + BSize minSearchSize = fSearchTermsText->MinSize(); + float minSearchWidth + = be_plain_font->StringWidth(fSearchTermsText->Label()) + + be_plain_font->StringWidth("XXX") * 6; + minSearchWidth = std::max(minSearchSize.width, minSearchWidth); + minSearchSize.width = minSearchWidth; + fSearchTermsText->SetExplicitMinSize(minSearchSize); + float maxSearchWidth = minSearchWidth * 2; + fSearchTermsText->SetExplicitMaxSize(BSize(maxSearchWidth, B_SIZE_UNSET)); + + // Build layout + BLayoutBuilder::Group<>(this) + .Add(fCategoryField, 0.0f) + .Add(fRepositoryField, 0.0f) + .AddGlue(0.5f) + .Add(fSearchTermsText, 1.0f) + + .SetInsets(B_USE_DEFAULT_SPACING) + ; +} + + +FilterView::~FilterView() +{ +} + + +void +FilterView::AttachedToWindow() +{ + fCategoryField->Menu()->SetTargetForItems(this); + fRepositoryField->Menu()->SetTargetForItems(this); + fSearchTermsText->SetTarget(this); +} + + +void +FilterView::MessageReceived(BMessage* message) +{ + switch (message->what) { + default: + BGroupView::MessageReceived(message); + break; + } +} diff --git a/src/apps/haiku-depot/FilterView.h b/src/apps/haiku-depot/FilterView.h new file mode 100644 index 0000000000..d52adcffa0 --- /dev/null +++ b/src/apps/haiku-depot/FilterView.h @@ -0,0 +1,29 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef FILTER_VIEW_H +#define FILTER_VIEW_H + +#include + + +class BMenuField; +class BTextControl; + + +class FilterView : public BGroupView { +public: + FilterView(); + virtual ~FilterView(); + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage* message); + +private: + BMenuField* fCategoryField; + BMenuField* fRepositoryField; + BTextControl* fSearchTermsText; +}; + +#endif // FILTER_VIEW_H