Ticket #5690: filetypes.patch
File filetypes.patch, 98.2 KB (added by , 15 years ago) |
---|
-
AttributeListView.h
50 50 51 51 class AttributeListView : public BListView { 52 52 public: 53 AttributeListView( BRect frame, const char* name, uint32 resizingMode);53 AttributeListView(const char* name); 54 54 virtual ~AttributeListView(); 55 55 56 56 void SetTo(BMimeType* type); … … 76 76 77 77 extern const struct display_as_map kDisplayAsMap[]; 78 78 79 AttributeItem *create_attribute_item(BMessage& attributes, int32 index);79 AttributeItem* create_attribute_item(BMessage& attributes, int32 index); 80 80 81 81 #endif // ATTRIBUTE_LIST_VIEW_H -
StringView.cpp
4 4 */ 5 5 6 6 7 #include <GroupView.h> 8 #include <LayoutItem.h> 9 #include <StringView.h> 10 7 11 #include "StringView.h" 8 12 9 10 StringView::StringView(BRect frame, const char* name, const char* label, 11 const char* text, uint32 resizeMask, uint32 flags) 12 : BView(frame, name, resizeMask, flags), 13 fLabel(label), 14 fText(text), 15 fLabelAlignment(B_ALIGN_RIGHT), 16 fTextAlignment(B_ALIGN_LEFT), 17 fEnabled(true) 13 StringView::StringView(const char* label, const char* text) 14 : 15 fView(NULL), 16 fLabel(new BStringView(NULL, label)), 17 fLabelItem(NULL), 18 fText(new BStringView(NULL, text)), 19 fTextItem(NULL) 18 20 { 19 fDivider = StringWidth(label) + 4.0f;20 21 } 21 22 22 23 23 StringView::~StringView()24 {25 }26 27 28 24 void 29 StringView::Set Alignment(alignment labelAlignment, alignment textAlignment)25 StringView::SetLabel(const char* label) 30 26 { 31 if (labelAlignment == fLabelAlignment && textAlignment == fTextAlignment) 32 return; 33 34 fLabelAlignment = labelAlignment; 35 fTextAlignment = textAlignment; 36 37 Invalidate(); 27 fLabel->SetText(label); 38 28 } 39 29 40 30 41 31 void 42 StringView:: GetAlignment(alignment* _label, alignment* _text) const32 StringView::SetText(const char* text) 43 33 { 44 if (_label) 45 *_label = fLabelAlignment; 46 if (_text) 47 *_text = fTextAlignment; 34 fText->SetText(text); 48 35 } 49 36 50 37 51 void 52 StringView:: SetDivider(float divider)38 BLayoutItem* 39 StringView::GetLabelLayoutItem() 53 40 { 54 fDivider = divider; 55 _UpdateText(); 56 57 Invalidate(); 41 return fLabelItem; 58 42 } 59 43 60 44 61 void 62 StringView::AttachedToWindow() 63 { 64 if (Parent() != NULL) 65 SetViewColor(Parent()->ViewColor()); 66 else 67 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 45 BView* 46 StringView::LabelView() 47 { return fLabel; } 68 48 69 SetLowColor(ViewColor());70 _UpdateText();71 }72 49 73 74 void 75 StringView::Draw(BRect updateRect) 50 BLayoutItem* 51 StringView::GetTextLayoutItem() 76 52 { 77 BRect rect = Bounds(); 78 79 font_height fontHeight; 80 GetFontHeight(&fontHeight); 81 82 float y = ceilf(fontHeight.ascent) + 1.0f; 83 float x; 84 85 #if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE) 86 rgb_color textColor = {0, 0, 0, 255}; 87 #else 88 rgb_color textColor = ui_color(B_CONTROL_TEXT_COLOR); 89 #endif 90 91 SetHighColor(IsEnabled() ? textColor 92 : tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT)); 93 94 if (Label()) { 95 switch (fLabelAlignment) { 96 case B_ALIGN_RIGHT: 97 x = Divider() - StringWidth(Label()) - 3.0f; 98 break; 99 100 case B_ALIGN_CENTER: 101 x = Divider() - StringWidth(Label()) / 2.0f; 102 break; 103 104 default: 105 x = 1.0f; 106 break; 107 } 108 109 DrawString(Label(), BPoint(x, y)); 110 } 111 112 if (fTruncatedText.String() != NULL) { 113 switch (fTextAlignment) { 114 case B_ALIGN_RIGHT: 115 x = rect.Width() - StringWidth(fTruncatedText.String()); 116 break; 117 118 case B_ALIGN_CENTER: 119 x = Divider() + (rect.Width() - Divider() - StringWidth(Label())) / 2.0f; 120 break; 121 122 default: 123 x = Divider() + 3.0f; 124 break; 125 } 126 127 DrawString(fTruncatedText.String(), BPoint(x, y)); 128 } 53 return fTextItem; 129 54 } 130 55 131 56 132 void 133 StringView::FrameResized(float width, float height) 134 { 135 BString oldTruncated = fTruncatedText; 136 _UpdateText(); 57 BView* 58 StringView::TextView() 59 { return fText; } 137 60 138 if (oldTruncated != fTruncatedText) {139 // invalidate text portion only140 BRect rect = Bounds();141 rect.left = Divider();142 Invalidate(rect);143 }144 }145 61 146 147 62 void 148 StringView:: ResizeToPreferred()63 StringView::SetEnabled(bool enabled) 149 64 { 150 float width, height;151 GetPreferredSize(&width, &height);65 66 rgb_color color; 152 67 153 // Resize the width only for B_ALIGN_LEFT (if its large enough already, that is) 154 if (Bounds().Width() > width 155 && (fLabelAlignment != B_ALIGN_LEFT || fTextAlignment != B_ALIGN_LEFT)) 156 width = Bounds().Width(); 157 158 BView::ResizeTo(width, height); 159 } 160 161 162 void 163 StringView::GetPreferredSize(float* _width, float* _height) 164 { 165 if (!Text() && !Label()) { 166 BView::GetPreferredSize(_width, _height); 167 return; 68 if (!enabled) { 69 color = tint_color( 70 ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT); 71 } else { 72 color = ui_color(B_CONTROL_TEXT_COLOR); 168 73 } 169 74 170 if (_width) 171 *_width = 7.0f + ceilf(StringWidth(Label()) + StringWidth(Text())); 172 173 if (_height) { 174 font_height fontHeight; 175 GetFontHeight(&fontHeight); 176 *_height = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 2.0f; 177 } 75 fLabel->SetHighColor(color); 76 fText->SetHighColor(color); 77 fLabel->Invalidate(); 78 fText->Invalidate(); 178 79 } 179 80 180 181 void 182 StringView:: SetEnabled(bool enabled)81 82 //cast operator BView* 83 StringView::operator BView*() 183 84 { 184 if (IsEnabled() == enabled) 185 return; 186 187 fEnabled = enabled; 188 Invalidate(); 85 if (fView) return fView; 86 fView = new BGroupView(B_HORIZONTAL); 87 BLayout* layout = fView->GroupLayout(); 88 fLabelItem = layout->AddView(fLabel); 89 fTextItem = layout->AddView(fText); 90 return fView; 189 91 } 190 92 191 93 192 void 193 StringView:: SetLabel(const char* label)94 const char* 95 StringView::Label() const 194 96 { 195 fLabel = label; 196 197 // invalidate label portion only 198 BRect rect = Bounds(); 199 rect.right = Divider(); 200 Invalidate(rect); 97 return fLabel->Text(); 201 98 } 202 99 203 100 204 void 205 StringView:: SetText(const char* text)101 const char* 102 StringView::Text() const 206 103 { 207 fText = text; 208 209 _UpdateText(); 210 211 // invalidate text portion only 212 BRect rect = Bounds(); 213 rect.left = Divider(); 214 Invalidate(rect); 104 return fText->Text(); 215 105 } 216 106 217 218 void219 StringView::_UpdateText()220 {221 fTruncatedText = fText;222 TruncateString(&fTruncatedText, B_TRUNCATE_MIDDLE, Bounds().Width() - Divider());223 } -
ExtensionWindow.cpp
9 9 #include "FileTypesWindow.h" 10 10 11 11 #include <Button.h> 12 #include <ControlLook.h> 13 #include <GridLayoutBuilder.h> 14 #include <GroupLayout.h> 12 15 #include <MenuField.h> 13 16 #include <MenuItem.h> 14 17 #include <Mime.h> … … 104 107 ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type, 105 108 const char* extension) 106 109 : BWindow(BRect(100, 100, 350, 200), "Extension", B_MODAL_WINDOW_LOOK, 107 B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_ V_RESIZABLE108 | B_ASYNCHRONOUS_CONTROLS ),110 B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE 111 | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), 109 112 fTarget(target), 110 113 fMimeType(type.Type()), 111 114 fExtension(extension) 112 115 { 113 BRect rect = Bounds(); 114 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); 115 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 116 AddChild(topView); 116 SetLayout(new BGroupLayout(B_VERTICAL)); 117 117 118 rect.InsetBy(8.0f, 8.0f); 119 fExtensionControl = new BTextControl(rect, "extension", "Extension:", extension, 120 NULL, B_FOLLOW_LEFT_RIGHT); 121 122 float labelWidth = fExtensionControl->StringWidth(fExtensionControl->Label()) + 2.0f; 118 float padding = 3.0f; 119 //if (be_control_look) 120 // padding = be_control_look->DefaultItemSpacing(); 121 // this seems to be very large! 122 123 fExtensionControl = new BTextControl("Extension:", extension, NULL); 123 124 fExtensionControl->SetModificationMessage(new BMessage(kMsgExtensionUpdated)); 124 fExtensionControl->SetDivider(labelWidth); 125 fExtensionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 125 fExtensionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); 126 126 127 127 // filter out invalid characters that can't be part of an extension 128 128 BTextView* textView = fExtensionControl->TextView(); … … 131 131 textView->DisallowChar(disallowedCharacters[i]); 132 132 } 133 133 134 float width, height; 135 fExtensionControl->GetPreferredSize(&width, &height); 136 fExtensionControl->ResizeTo(rect.Width(), height); 137 topView->AddChild(fExtensionControl); 138 139 fAcceptButton = new BButton(rect, "add", extension ? "Done" : "Add", 140 new BMessage(kMsgAccept), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 141 fAcceptButton->ResizeToPreferred(); 142 fAcceptButton->MoveTo(Bounds().Width() - 8.0f - fAcceptButton->Bounds().Width(), 143 Bounds().Height() - 8.0f - fAcceptButton->Bounds().Height()); 134 fAcceptButton = new BButton(extension ? "Done" : "Add", 135 new BMessage(kMsgAccept)); 144 136 fAcceptButton->SetEnabled(false); 145 topView->AddChild(fAcceptButton);146 137 147 BButton* button = new BButton(rect, "cancel", "Cancel", 148 new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 149 button->ResizeToPreferred(); 150 button->MoveTo(fAcceptButton->Frame().left - 10.0f - button->Bounds().Width(), 151 fAcceptButton->Frame().top); 152 topView->AddChild(button); 138 BButton* button = new BButton("Cancel", 139 new BMessage(B_QUIT_REQUESTED)); 153 140 154 ResizeTo(labelWidth * 4.0f + 24.0f, fExtensionControl->Bounds().Height() 155 + fAcceptButton->Bounds().Height() + 28.0f); 156 SetSizeLimits(button->Bounds().Width() + fAcceptButton->Bounds().Width() + 26.0f, 157 32767.0f, Frame().Height(), Frame().Height()); 141 AddChild(BGridLayoutBuilder(padding, padding) 142 .Add(fExtensionControl->CreateLabelLayoutItem(), 0, 0) 143 .Add(fExtensionControl->CreateTextViewLayoutItem(), 1, 0) 144 .Add(fAcceptButton, 0, 1) 145 .Add(button, 1, 1) 146 .SetInsets(padding, padding, padding, padding) 147 ); 158 148 159 149 // omit the leading dot 160 150 if (fExtension.ByteAt(0) == '.') -
TypeListWindow.cpp
8 8 #include "TypeListWindow.h" 9 9 10 10 #include <Button.h> 11 #include <ControlLook.h> 12 #include <GroupLayoutBuilder.h> 11 13 #include <ScrollView.h> 12 14 13 15 #include <string.h> … … 17 19 const uint32 kMsgSelected = 'seld'; 18 20 19 21 20 TypeListWindow::TypeListWindow(const char* currentType, uint32 what, BWindow* target) 21 : BWindow(BRect(100, 100, 360, 440), "Choose type", B_MODAL_WINDOW, 22 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), 22 TypeListWindow::TypeListWindow(const char* currentType, 23 uint32 what, BWindow* target) 24 : 25 BWindow(BRect(100, 100, 360, 440), "Choose type", B_MODAL_WINDOW, 26 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), 23 27 fTarget(target), 24 28 fWhat(what) 25 29 { 26 BRect rect = Bounds();27 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);28 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));29 AddChild(topView);30 float padding=3.0f; 31 //if (be_control_look) 32 // padding = be_control_look->DefaultItemSpacing(); 33 // seems too big 30 34 31 fSelectButton = new BButton(rect, "select", "Done", 32 new BMessage(kMsgSelected), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 33 fSelectButton->ResizeToPreferred(); 34 fSelectButton->MoveTo(topView->Bounds().right - 8.0f - fSelectButton->Bounds().Width(), 35 topView->Bounds().bottom - 8.0f - fSelectButton->Bounds().Height()); 35 fSelectButton = new BButton("select", "Done", 36 new BMessage(kMsgSelected)); 36 37 fSelectButton->SetEnabled(false); 37 topView->AddChild(fSelectButton);38 38 39 BButton* button = new BButton(fSelectButton->Frame(), "cancel", "Cancel", 40 new BMessage(B_CANCEL), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 41 button->ResizeToPreferred(); 42 button->MoveBy(-button->Bounds().Width() - 8.0f, 0.0f); 43 topView->AddChild(button); 39 BButton* button = new BButton("cancel", "Cancel", 40 new BMessage(B_CANCEL)); 44 41 45 42 fSelectButton->MakeDefault(true); 46 43 47 rect.bottom = button->Frame().top - 10.0f; 48 rect.top = 10.0f; 49 rect.left = 10.0f; 50 rect.right -= 10.0f + B_V_SCROLL_BAR_WIDTH; 51 fListView = new MimeTypeListView(rect, "typeview", NULL, true, false, 52 B_FOLLOW_ALL); 44 fListView = new MimeTypeListView("typeview", NULL, true, false); 53 45 fListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); 54 46 fListView->SetInvocationMessage(new BMessage(kMsgSelected)); 55 47 56 48 BScrollView* scrollView = new BScrollView("scrollview", fListView, 57 B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 58 topView->AddChild(scrollView); 49 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 59 50 51 SetLayout(new BGroupLayout(B_VERTICAL)); 52 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 53 .Add(scrollView) 54 .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) 55 .Add(button) 56 .Add(fSelectButton) 57 ) 58 .SetInsets(padding, padding, padding, padding) 59 ); 60 61 BAlignment buttonAlignment = 62 BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_CENTER); 63 button->SetExplicitAlignment(buttonAlignment); 64 fSelectButton->SetExplicitAlignment(buttonAlignment); 65 60 66 MoveTo(target->Frame().LeftTop() + BPoint(15.0f, 15.0f)); 61 SetSizeLimits(button->Bounds().Width() + fSelectButton->Bounds().Width() + 64.0f, 32767.0f,62 fSelectButton->Bounds().Height() * 5.0f, 32767.0f);63 67 } 64 68 65 69 -
DropTargetListView.h
11 11 12 12 class DropTargetListView : public BListView { 13 13 public: 14 DropTargetListView( BRect frame,const char* name,14 DropTargetListView(const char* name, 15 15 list_view_type type = B_SINGLE_SELECTION_LIST, 16 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,17 16 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 18 17 virtual ~DropTargetListView(); 19 18 -
PreferredAppMenu.h
15 15 16 16 void update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what, 17 17 const char* preferredFrom = NULL); 18 status_t retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType,19 BString& preferredApp);20 18 19 status_t retrieve_preferred_app(BMessage* message, bool sameAs, 20 const char* forType, BString& preferredApp); 21 21 22 #endif // PREFERRED_APP_MENU_H -
FileTypeWindow.cpp
14 14 #include <Bitmap.h> 15 15 #include <Box.h> 16 16 #include <Button.h> 17 #include <ControlLook.h> 17 18 #include <File.h> 19 #include <GridLayoutBuilder.h> 20 #include <GroupLayoutBuilder.h> 18 21 #include <MenuField.h> 19 22 #include <MenuItem.h> 20 23 #include <Mime.h> 21 24 #include <NodeInfo.h> 22 25 #include <PopUpMenu.h> 26 #include <SpaceLayoutItem.h> 23 27 #include <TextControl.h> 24 28 25 29 #include <stdio.h> … … 39 43 40 44 41 45 FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) 42 : BWindow(BRect(0.0f, 0.0f, 200.0f, 200.0f).OffsetBySelf(position), 46 : 47 BWindow(BRect(0.0f, 0.0f, 200.0f, 200.0f).OffsetBySelf(position), 43 48 "File type", B_TITLED_WINDOW, 44 B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) 49 B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | 50 B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) 45 51 { 46 BRect rect = Bounds();47 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);48 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));49 AddChild(topView);52 float padding = 3.0f; 53 // if (be_control_look) 54 // padding = be_control_look->DefaultItemSpacing(); 55 // too big! 50 56 51 57 // "File Type" group 58 BBox* fileTypeBox = new BBox("file type BBox"); 59 fileTypeBox->SetLabel("File type"); 52 60 53 BFont font(be_bold_font); 54 font_height fontHeight; 55 font.GetHeight(&fontHeight); 61 fTypeControl = new BTextControl("type", NULL, "fTypeControl", 62 new BMessage(kMsgTypeEntered)); 56 63 57 rect.InsetBy(8.0f, 8.0f);58 BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);59 box->SetLabel("File type");60 topView->AddChild(box);61 62 rect = box->Bounds();63 rect.InsetBy(8.0f, 4.0f + fontHeight.ascent + fontHeight.descent);64 fTypeControl = new BTextControl(rect, "type", NULL, NULL,65 new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT);66 fTypeControl->SetDivider(0.0f);67 float width, height;68 fTypeControl->GetPreferredSize(&width, &height);69 fTypeControl->ResizeTo(rect.Width(), height);70 box->AddChild(fTypeControl);71 72 64 // filter out invalid characters that can't be part of a MIME type name 73 65 BTextView* textView = fTypeControl->TextView(); 74 66 const char* disallowedCharacters = "<>@,;:\"()[]?="; … … 76 68 textView->DisallowChar(disallowedCharacters[i]); 77 69 } 78 70 79 rect.OffsetBy(0.0f, fTypeControl->Bounds().Height() + 5.0f); 80 fSelectTypeButton = new BButton(rect, "select type", "Select" B_UTF8_ELLIPSIS, 81 new BMessage(kMsgSelectType), B_FOLLOW_LEFT | B_FOLLOW_TOP); 82 fSelectTypeButton->ResizeToPreferred(); 83 box->AddChild(fSelectTypeButton); 71 fSelectTypeButton = new BButton("select type", "Select" B_UTF8_ELLIPSIS, 72 new BMessage(kMsgSelectType)); 84 73 85 rect.OffsetBy(fSelectTypeButton->Bounds().Width() + 8.0f, 0.0f); 86 fSameTypeAsButton = new BButton(rect, "same type as", "Same as" B_UTF8_ELLIPSIS, 87 new BMessage(kMsgSameTypeAs), B_FOLLOW_LEFT | B_FOLLOW_TOP); 88 fSameTypeAsButton->ResizeToPreferred(); 89 box->AddChild(fSameTypeAsButton); 74 fSameTypeAsButton = new BButton("same type as", "Same as" B_UTF8_ELLIPSIS, 75 new BMessage(kMsgSameTypeAs)); 90 76 91 width = font.StringWidth("Icon") + 16.0f; 92 if (width < B_LARGE_ICON + 16.0f) 93 width = B_LARGE_ICON + 16.0f; 77 fileTypeBox->AddChild(BGridLayoutBuilder(padding, padding) 78 .Add(fTypeControl, 0, 0, 2, 1) 79 .Add(fSelectTypeButton, 0, 1) 80 .Add(fSameTypeAsButton, 1, 1) 81 .SetInsets(padding, padding, padding, padding) 82 ); 94 83 95 height = fSelectTypeButton->Frame().bottom + 8.0f;96 if (height < 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent)97 height = 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent;98 box->ResizeTo(box->Bounds().Width() - width - 8.0f, height);99 100 84 // "Icon" group 101 85 102 rect = box->Frame(); 103 rect.left = rect.right + 8.0f; 104 rect.right += width + 8.0f; 105 float iconBoxWidth = rect.Width(); 106 box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP); 107 box->SetLabel("Icon"); 108 topView->AddChild(box); 86 BBox* iconBox = new BBox("icon BBox"); 87 iconBox->SetLabel("Icon"); 88 fIconView = new IconView("icon"); 89 iconBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) 90 .Add(fIconView) 91 .SetInsets(padding, padding, padding, padding)); 109 92 110 rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f);111 rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f);112 if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f)113 rect.top = fontHeight.ascent + fontHeight.descent + 4.0f;114 fIconView = new IconView(rect, "icon");115 box->AddChild(fIconView);116 117 93 // "Preferred Application" group 118 94 119 rect.top = box->Frame().bottom + 8.0f; 120 rect.bottom = rect.top + box->Bounds().Height(); 121 rect.left = 8.0f; 122 rect.right = Bounds().Width() - 8.0f; 123 box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 124 box->SetLabel("Preferred application"); 125 topView->AddChild(box); 95 BBox* preferredBox = new BBox("preferred BBox"); 96 preferredBox->SetLabel("Preferred application"); 126 97 127 98 BMenu* menu = new BPopUpMenu("preferred"); 128 99 BMenuItem* item; … … 130 101 new BMessage(kMsgPreferredAppChosen))); 131 102 item->SetMarked(true); 132 103 133 rect = fTypeControl->Frame(); 134 BView* constrainingView = new BView(rect, NULL, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW); 135 constrainingView->SetViewColor(topView->ViewColor()); 104 fPreferredField = new BMenuField("preferred", NULL, menu); 136 105 137 fPreferredField = new BMenuField(rect.OffsetToCopy(B_ORIGIN), "preferred", 138 NULL, menu); 139 fPreferredField->GetPreferredSize(&width, &height); 140 fPreferredField->ResizeTo(rect.Width(), height); 141 constrainingView->ResizeTo(rect.Width(), height); 142 constrainingView->AddChild(fPreferredField); 143 // we embed the menu field in another view to make it behave like 144 // we want so that it can't obscure other elements with larger 145 // labels 106 fSelectAppButton = new BButton("select app", "Select" B_UTF8_ELLIPSIS, 107 new BMessage(kMsgSelectPreferredApp)); 146 108 147 box->AddChild(constrainingView); 109 fSameAppAsButton = new BButton("same app as", "Same as" B_UTF8_ELLIPSIS, 110 new BMessage(kMsgSamePreferredAppAs)); 148 111 149 rect.OffsetBy(0.0f, height + 5.0f); 150 fSelectAppButton = new BButton(rect, "select app", "Select" B_UTF8_ELLIPSIS, 151 new BMessage(kMsgSelectPreferredApp), B_FOLLOW_LEFT | B_FOLLOW_TOP); 152 fSelectAppButton->ResizeToPreferred(); 153 box->AddChild(fSelectAppButton); 112 preferredBox->AddChild(BGridLayoutBuilder(padding, padding) 113 .Add(fPreferredField, 0, 0, 2, 1) 114 .Add(fSelectAppButton, 0, 1) 115 .Add(fSameAppAsButton, 1, 1) 116 .Add(BSpaceLayoutItem::CreateGlue(), 3, 0, 1, 2) 117 .SetInsets(padding, padding, padding, padding) 118 ); 154 119 155 rect.OffsetBy(fSelectAppButton->Bounds().Width() + 8.0f, 0.0f); 156 fSameAppAsButton = new BButton(rect, "same app as", "Same as" B_UTF8_ELLIPSIS, 157 new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_LEFT | B_FOLLOW_TOP); 158 fSameAppAsButton->ResizeToPreferred(); 159 box->AddChild(fSameAppAsButton); 160 box->ResizeBy(0.0f, height - fTypeControl->Bounds().Height()); 120 SetLayout(new BGroupLayout(B_VERTICAL)); 121 AddChild(BGridLayoutBuilder(padding, padding) 122 .Add(fileTypeBox, 0, 0, 1, 2) 123 .Add(iconBox, 1, 1, 1, 2) 124 .Add(preferredBox, 0, 2, 1, 2) 125 .SetInsets(padding, padding, padding, padding) 126 ); 161 127 162 ResizeTo(fSameAppAsButton->Frame().right + 100.0f, box->Frame().bottom + 8.0f);163 SetSizeLimits(fSameAppAsButton->Frame().right + iconBoxWidth + 32.0f, 32767.0f,164 Bounds().Height(), Bounds().Height());128 float minWidth, minHeight; 129 GetSizeLimits(&minWidth, NULL, &minHeight, NULL); 130 ResizeTo(minWidth, minHeight); 165 131 166 132 fTypeControl->MakeFocus(true); 167 168 133 BMimeType::StartWatching(this); 169 134 _SetTo(refs); 170 135 } -
MimeTypeListView.cpp
267 267 // #pragma mark - 268 268 269 269 270 MimeTypeListView::MimeTypeListView(BRect rect, const char* name, 271 const char* supertype, bool showIcons, bool applicationMode, 272 uint32 resizingMode) 273 : BOutlineListView(rect, name, B_SINGLE_SELECTION_LIST, resizingMode), 270 MimeTypeListView::MimeTypeListView(const char* name, 271 const char* supertype, bool showIcons, bool applicationMode) 272 : BOutlineListView(name, B_SINGLE_SELECTION_LIST), 274 273 fSupertype(supertype), 275 274 fShowIcons(showIcons), 276 275 fApplicationMode(applicationMode) -
NewFileTypeWindow.cpp
9 9 #include "NewFileTypeWindow.h" 10 10 11 11 #include <Button.h> 12 #include <ControlLook.h> 13 #include <GroupLayout.h> 14 #include <GridLayoutBuilder.h> 15 #include <MenuBar.h> 12 16 #include <MenuField.h> 13 17 #include <MenuItem.h> 14 18 #include <Mime.h> 15 19 #include <PopUpMenu.h> 20 #include <SpaceLayoutItem.h> 16 21 #include <String.h> 22 #include <StringView.h> 17 23 #include <TextControl.h> 18 24 19 25 #include <string.h> … … 27 33 const uint32 kMsgAddType = 'atyp'; 28 34 29 35 30 NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, const char* currentType) 31 : BWindow(BRect(100, 100, 350, 200), "New file type", B_TITLED_WINDOW, 32 B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), 36 NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, 37 const char* currentType) 38 : 39 BWindow(BRect(100, 100, 350, 200), "New file type", B_MODAL_WINDOW, 40 B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS 41 | B_AUTO_UPDATE_SIZE_LIMITS ), 33 42 fTarget(target) 34 43 { 35 BRect rect = Bounds();36 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);37 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));38 AddChild(topView);39 40 float labelWidth = be_plain_font->StringWidth("Internal name:") + 2.0f;41 42 rect.InsetBy(8.0f, 6.0f);43 44 fSupertypesMenu = new BPopUpMenu("supertypes"); 44 45 BMenuItem* item; 45 46 BMessage types; … … 61 62 if (i > 1) 62 63 fSupertypesMenu->AddSeparatorItem(); 63 64 } 65 64 66 fSupertypesMenu->AddItem(new BMenuItem("Add new group", 65 67 new BMessage(kMsgNewSupertypeChosen))); 68 BMenuField* typesMenuField = new BMenuField(NULL, fSupertypesMenu); 66 69 67 BMenuField* menuField = new BMenuField(rect, "supertypes", 68 "Group:", fSupertypesMenu); 69 menuField->SetDivider(labelWidth); 70 menuField->SetAlignment(B_ALIGN_RIGHT); 71 float width, height; 72 menuField->GetPreferredSize(&width, &height); 73 menuField->ResizeTo(rect.Width(), height); 74 topView->AddChild(menuField); 70 BStringView* typesMenuLabel = new BStringView(NULL, "Group:"); 71 // Create a separate label view, otherwise things don't line up right 72 typesMenuLabel->SetAlignment(B_ALIGN_LEFT); 73 typesMenuLabel->SetExplicitAlignment( 74 BAlignment(B_ALIGN_LEFT, B_ALIGN_USE_FULL_HEIGHT)); 75 75 76 fNameControl = new BTextControl(rect, "internal", "Internal name:", "", 77 NULL, B_FOLLOW_LEFT_RIGHT); 76 fNameControl = new BTextControl("Internal name:", "", NULL); 78 77 fNameControl->SetModificationMessage(new BMessage(kMsgNameUpdated)); 79 fNameControl->SetDivider(labelWidth);80 fNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);81 78 82 79 // filter out invalid characters that can't be part of a MIME type name 83 BTextView* textView = fNameControl->TextView();80 BTextView* nameControlTextView = fNameControl->TextView(); 84 81 const char* disallowedCharacters = "/<>@,;:\"()[]?="; 85 82 for (int32 i = 0; disallowedCharacters[i]; i++) { 86 textView->DisallowChar(disallowedCharacters[i]);83 nameControlTextView->DisallowChar(disallowedCharacters[i]); 87 84 } 88 85 89 fNameControl->GetPreferredSize(&width, &height); 90 fNameControl->ResizeTo(rect.Width(), height); 91 fNameControl->MoveTo(8.0f, 12.0f + menuField->Bounds().Height()); 92 topView->AddChild(fNameControl); 86 fAddButton = new BButton("Add type", new BMessage(kMsgAddType)); 93 87 94 fAddButton = new BButton(rect, "add", "Add type", new BMessage(kMsgAddType), 95 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 96 fAddButton->ResizeToPreferred(); 97 fAddButton->MoveTo(Bounds().Width() - 8.0f - fAddButton->Bounds().Width(), 98 Bounds().Height() - 8.0f - fAddButton->Bounds().Height()); 99 fAddButton->SetEnabled(false); 100 topView->AddChild(fAddButton); 88 float padding = 3.0f; 89 // if (be_control_look) 90 // padding = be_control_look->DefaultItemSpacing(); 101 91 102 BButton* button = new BButton(rect, "cancel", "Cancel", 103 new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 104 button->ResizeToPreferred(); 105 button->MoveTo(fAddButton->Frame().left - 10.0f - button->Bounds().Width(), 106 fAddButton->Frame().top); 107 topView->AddChild(button); 92 SetLayout(new BGroupLayout(B_VERTICAL)); 93 AddChild(BGridLayoutBuilder(padding, padding) 94 .SetInsets(padding, padding, padding, padding) 95 .Add(typesMenuLabel, 0, 0) 96 .Add(typesMenuField, 1, 0, 2) 97 .Add(fNameControl->CreateLabelLayoutItem(), 0, 1) 98 .Add(fNameControl->CreateTextViewLayoutItem(), 1, 1, 2) 99 .Add(BSpaceLayoutItem::CreateGlue(), 0, 2) 100 .Add(new BButton("Cancel", new BMessage(B_QUIT_REQUESTED)), 1, 2) 101 .Add(fAddButton, 2, 2) 102 .SetColumnWeight(0, 3) 103 ); 108 104 109 ResizeTo(labelWidth * 4.0f + 24.0f, fNameControl->Bounds().Height() 110 + menuField->Bounds().Height() + fAddButton->Bounds().Height() + 30.0f); 111 SetSizeLimits(button->Bounds().Width() + fAddButton->Bounds().Width() + 26.0f, 112 32767.0f, Frame().Height(), Frame().Height()); 105 BAlignment fullSize = BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); 106 typesMenuField->MenuBar()->SetExplicitAlignment(fullSize); 107 fNameControl->TextView()->SetExplicitAlignment(fullSize); 113 108 109 BLayoutItem* nameControlLabelItem = fNameControl->CreateLabelLayoutItem(); 110 nameControlLabelItem->SetExplicitMinSize(nameControlLabelItem->MinSize()); 111 // stops fNameControl's label from truncating under certain conditions 112 114 113 fAddButton->MakeDefault(true); 115 114 fNameControl->MakeFocus(true); 116 115 … … 131 130 fAddButton->SetLabel("Add type"); 132 131 fNameControl->SetLabel("Internal name:"); 133 132 fNameControl->MakeFocus(true); 133 InvalidateLayout(true); 134 134 break; 135 135 136 136 case kMsgNewSupertypeChosen: 137 137 fAddButton->SetLabel("Add group"); 138 138 fNameControl->SetLabel("Group name:"); 139 139 fNameControl->MakeFocus(true); 140 InvalidateLayout(true); 140 141 break; 141 142 142 143 case kMsgNameUpdated: … … 195 196 fTarget.SendMessage(kMsgNewTypeWindowClosed); 196 197 return true; 197 198 } 199 200 -
ApplicationTypesWindow.h
27 27 ApplicationTypesWindow(const BMessage& settings); 28 28 virtual ~ApplicationTypesWindow(); 29 29 30 virtual void FrameResized(float width, float height);31 30 virtual void MessageReceived(BMessage* message); 32 31 virtual bool QuitRequested(); 33 32 -
IconView.h
50 50 51 51 Icon& operator=(const Icon& source); 52 52 53 void AdoptLarge(BBitmap *large);54 void AdoptMini(BBitmap *mini);53 void AdoptLarge(BBitmap* large); 54 void AdoptMini(BBitmap* mini); 55 55 void AdoptData(uint8* data, size_t size); 56 56 57 57 static BBitmap* AllocateBitmap(int32 size, int32 space = -1); … … 63 63 size_t fSize; 64 64 }; 65 65 66 class BSize; 67 66 68 class IconView : public BControl { 67 69 public: 68 IconView(BRect rect, const char* name, 69 uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, 70 uint32 flags = B_NAVIGABLE); 70 IconView(const char* name, uint32 flags = B_NAVIGABLE); 71 71 virtual ~IconView(); 72 72 73 73 virtual void AttachedToWindow(); … … 76 76 virtual void Draw(BRect updateRect); 77 77 virtual void GetPreferredSize(float* _width, float* _height); 78 78 79 virtual BSize MaxSize(); 80 virtual BSize MinSize(); 81 virtual BSize PreferredSize(); 82 79 83 virtual void MouseDown(BPoint where); 80 84 virtual void MouseUp(BPoint where); 81 85 virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); … … 92 96 void SetIconSize(int32 size); 93 97 void ShowIconHeap(bool show); 94 98 void ShowEmptyFrame(bool show); 95 voidSetTarget(const BMessenger& target);99 status_t SetTarget(const BMessenger& target); 96 100 void SetModificationMessage(BMessage* message); 97 voidInvoke(const BMessage* message = NULL);101 status_t Invoke(const BMessage* message = NULL); 98 102 99 103 ::Icon* Icon(); 100 104 int32 IconSize() const { return fIconSize; } -
AttributeListView.cpp
71 71 buffer[4] = 0xff & (type); 72 72 buffer[5] = '\''; 73 73 buffer[6] = 0; 74 for (int16 i = 0; i < 4;i++) {74 for (int16 i = 0; i < 4; i++) { 75 75 if (buffer[i] < ' ') 76 76 buffer[i] = '.'; 77 77 } … … 81 81 } 82 82 83 83 84 AttributeItem 84 AttributeItem* 85 85 create_attribute_item(BMessage& attributes, int32 index) 86 86 { 87 87 const char* publicName; … … 235 235 // #pragma mark - 236 236 237 237 238 AttributeListView::AttributeListView(BRect frame, const char* name, 239 uint32 resizingMode) 240 : BListView(frame, name, B_SINGLE_SELECTION_LIST, resizingMode, 238 AttributeListView::AttributeListView(const char* name) 239 : BListView(name, B_SINGLE_SELECTION_LIST, 241 240 B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) 242 241 { 243 242 } -
AttributeWindow.cpp
11 11 #include <Box.h> 12 12 #include <Button.h> 13 13 #include <CheckBox.h> 14 #include <ControlLook.h> 15 #include <GridLayoutBuilder.h> 16 #include <GroupLayoutBuilder.h> 14 17 #include <MenuField.h> 15 18 #include <MenuItem.h> 16 19 #include <Mime.h> 17 20 #include <PopUpMenu.h> 21 #include <SpaceLayoutItem.h> 18 22 #include <String.h> 19 23 #include <TextControl.h> 20 24 … … 85 89 86 90 AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, 87 91 AttributeItem* attributeItem) 88 : BWindow(BRect(100, 100, 350, 200), "Attribute", B_MODAL_WINDOW_LOOK, 89 B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE 92 : 93 BWindow(BRect(100, 100, 350, 200), "Attribute", B_MODAL_WINDOW_LOOK, 94 B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS 90 95 | B_ASYNCHRONOUS_CONTROLS), 91 96 fTarget(target), 92 97 fMimeType(mimeType.Type()) 93 98 { 99 float padding = 3.0f; 100 //if (be_control_look) 101 //padding = be_control_look->DefaultItemSpacing(); 102 94 103 if (attributeItem != NULL) 95 104 fAttribute = *attributeItem; 96 105 97 BRect rect = Bounds(); 98 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); 99 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 100 AddChild(topView); 101 102 rect.InsetBy(8.0f, 8.0f); 103 fPublicNameControl = new BTextControl(rect, "public", "Attribute name:", 104 fAttribute.PublicName(), NULL, B_FOLLOW_LEFT_RIGHT); 105 fPublicNameControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); 106 107 float labelWidth = fPublicNameControl->StringWidth(fPublicNameControl->Label()) + 2.0f; 108 fPublicNameControl->SetDivider(labelWidth); 106 fPublicNameControl = new BTextControl("Attribute name:", 107 fAttribute.PublicName(), NULL); 108 fPublicNameControl->SetModificationMessage( 109 new BMessage(kMsgAttributeUpdated)); 109 110 fPublicNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 110 111 111 float width, height; 112 fPublicNameControl->GetPreferredSize(&width, &height); 113 fPublicNameControl->ResizeTo(rect.Width(), height); 114 topView->AddChild(fPublicNameControl); 115 116 rect = fPublicNameControl->Frame(); 117 rect.OffsetBy(0.0f, rect.Height() + 5.0f); 118 fAttributeControl = new BTextControl(rect, "internal", "Internal name:", 119 fAttribute.Name(), NULL, B_FOLLOW_LEFT_RIGHT); 120 fAttributeControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); 121 fAttributeControl->SetDivider(labelWidth); 112 fAttributeControl = new BTextControl("Internal name:", 113 fAttribute.Name(), NULL); 114 fAttributeControl->SetModificationMessage( 115 new BMessage(kMsgAttributeUpdated)); 122 116 fAttributeControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 123 117 124 118 // filter out invalid characters that can't be part of an attribute … … 128 122 textView->DisallowChar(disallowedCharacters[i]); 129 123 } 130 124 131 topView->AddChild(fAttributeControl);132 133 125 fTypeMenu = new BPopUpMenu("type"); 134 126 BMenuItem* item = NULL; 135 127 for (int32 i = 0; kTypeMap[i].name != NULL; i++) { … … 143 135 item->SetMarked(true); 144 136 } 145 137 146 rect.OffsetBy(0.0f, rect.Height() + 4.0f); 147 BMenuField* menuField = new BMenuField(rect, "types", 148 "Type:", fTypeMenu); 149 menuField->SetDivider(labelWidth); 150 menuField->SetAlignment(B_ALIGN_RIGHT); 151 menuField->GetPreferredSize(&width, &height); 152 menuField->ResizeTo(rect.Width(), height); 153 topView->AddChild(menuField); 138 BMenuField* typeMenuField = new BMenuField("types" , "Type:", fTypeMenu); 139 typeMenuField->SetAlignment(B_ALIGN_RIGHT); 154 140 155 rect.OffsetBy(0.0f, rect.Height() + 4.0f); 156 rect.bottom = rect.top + fAttributeControl->Bounds().Height() * 2.0f + 18.0f; 157 BBox* box = new BBox(rect, "", B_FOLLOW_LEFT_RIGHT); 158 topView->AddChild(box); 159 160 fVisibleCheckBox = new BCheckBox(rect, "visible", "Visible", 141 fVisibleCheckBox = new BCheckBox("visible", "Visible", 161 142 new BMessage(kMsgVisibilityChanged)); 162 143 fVisibleCheckBox->SetValue(fAttribute.Visible()); 163 fVisibleCheckBox->ResizeToPreferred();164 box->SetLabel(fVisibleCheckBox);165 144 166 labelWidth -= 8.0f;167 168 145 BMenu* menu = new BPopUpMenu("display as"); 169 146 for (int32 i = 0; kDisplayAsMap[i].name != NULL; i++) { 170 147 BMessage* message = new BMessage(kMsgDisplayAsChosen); … … 182 159 item->SetMarked(true); 183 160 } 184 161 185 rect.OffsetTo(8.0f, fVisibleCheckBox->Bounds().Height()); 186 rect.right -= 18.0f; 187 fDisplayAsMenuField = new BMenuField(rect, "display as", 162 fDisplayAsMenuField = new BMenuField("display as", 188 163 "Display as:", menu); 189 fDisplayAsMenuField->SetDivider(labelWidth);190 164 fDisplayAsMenuField->SetAlignment(B_ALIGN_RIGHT); 191 fDisplayAsMenuField->ResizeTo(rect.Width(), height);192 box->AddChild(fDisplayAsMenuField);193 165 194 fEditableCheckBox = new BCheckBox( rect,"editable", "Editable",195 new BMessage(kMsgAttributeUpdated) , B_FOLLOW_RIGHT);166 fEditableCheckBox = new BCheckBox("editable", "Editable", 167 new BMessage(kMsgAttributeUpdated)); 196 168 fEditableCheckBox->SetValue(fAttribute.Editable()); 197 fEditableCheckBox->ResizeToPreferred();198 fEditableCheckBox->MoveTo(rect.right - fEditableCheckBox->Bounds().Width(),199 rect.top + (fDisplayAsMenuField->Bounds().Height()200 - fEditableCheckBox->Bounds().Height()) / 2.0f);201 box->AddChild(fEditableCheckBox);202 169 203 rect.OffsetBy(0.0f, menuField->Bounds().Height() + 4.0f); 204 rect.bottom = rect.top + fPublicNameControl->Bounds().Height(); 205 fSpecialControl = new BTextControl(rect, "special", "Special:", 206 display_as_parameter(fAttribute.DisplayAs()), NULL, 207 B_FOLLOW_LEFT_RIGHT); 208 fSpecialControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); 209 fSpecialControl->SetDivider(labelWidth); 170 fSpecialControl = new BTextControl("Special:", 171 display_as_parameter(fAttribute.DisplayAs()), NULL); 172 fSpecialControl->SetModificationMessage( 173 new BMessage(kMsgAttributeUpdated)); 210 174 fSpecialControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 211 175 fSpecialControl->SetEnabled(false); 212 box->AddChild(fSpecialControl);213 176 214 177 char text[64]; 215 178 snprintf(text, sizeof(text), "%ld", fAttribute.Width()); 216 rect.OffsetBy(0.0f, fSpecialControl->Bounds().Height() + 4.0f); 217 fWidthControl = new BTextControl(rect, "width", "Width:", 218 text, NULL, B_FOLLOW_LEFT_RIGHT); 219 fWidthControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); 220 fWidthControl->SetDivider(labelWidth); 179 fWidthControl = new BTextControl("Width:", text, NULL); 180 fWidthControl->SetModificationMessage( 181 new BMessage(kMsgAttributeUpdated)); 221 182 fWidthControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 222 183 223 184 // filter out invalid characters that can't be part of a width … … 228 189 } 229 190 textView->SetMaxBytes(4); 230 191 231 box->AddChild(fWidthControl);232 233 192 const struct alignment_map { 234 193 int32 alignment; 235 194 const char* name; … … 252 211 item->SetMarked(true); 253 212 } 254 213 255 rect.OffsetBy(0.0f, menuField->Bounds().Height() + 1.0f); 256 fAlignmentMenuField = new BMenuField(rect, "alignment", 214 fAlignmentMenuField = new BMenuField("alignment", 257 215 "Alignment:", menu); 258 fAlignmentMenuField->SetDivider(labelWidth);259 216 fAlignmentMenuField->SetAlignment(B_ALIGN_RIGHT); 260 fAlignmentMenuField->ResizeTo(rect.Width(), height);261 box->AddChild(fAlignmentMenuField);262 box->ResizeBy(0.0f, fAlignmentMenuField->Bounds().Height() * 2.0f263 + fVisibleCheckBox->Bounds().Height());264 217 265 fAcceptButton = new BButton(rect, "add", item ? "Done" : "Add", 266 new BMessage(kMsgAccept), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 267 fAcceptButton->ResizeToPreferred(); 268 fAcceptButton->MoveTo(Bounds().Width() - 8.0f - fAcceptButton->Bounds().Width(), 269 Bounds().Height() - 8.0f - fAcceptButton->Bounds().Height()); 218 fAcceptButton = new BButton("add", item ? "Done" : "Add", 219 new BMessage(kMsgAccept)); 270 220 fAcceptButton->SetEnabled(false); 271 topView->AddChild(fAcceptButton);272 221 273 BButton* button = new BButton(rect, "cancel", "Cancel", 274 new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 275 button->ResizeToPreferred(); 276 button->MoveTo(fAcceptButton->Frame().left - 10.0f - button->Bounds().Width(), 277 fAcceptButton->Frame().top); 278 topView->AddChild(button); 222 BButton* cancelButton = new BButton("cancel", "Cancel", 223 new BMessage(B_QUIT_REQUESTED)); 279 224 280 ResizeTo(labelWidth * 4.0f + 24.0f, box->Frame().bottom 281 + button->Bounds().Height() + 20.0f); 282 SetSizeLimits(fEditableCheckBox->Bounds().Width() + button->Bounds().Width() 283 + fAcceptButton->Bounds().Width() + labelWidth + 24.0f, 284 32767.0f, Frame().Height(), Frame().Height()); 225 BBox* visibleBox; 226 SetLayout(new BGroupLayout(B_VERTICAL)); 227 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 228 .SetInsets(padding, padding, padding, padding) 229 .Add(BGridLayoutBuilder(padding, padding) 230 .Add(fPublicNameControl->CreateLabelLayoutItem(), 0, 0) 231 .Add(fPublicNameControl->CreateTextViewLayoutItem(), 1, 0) 232 .Add(fAttributeControl->CreateLabelLayoutItem(), 0, 1) 233 .Add(fAttributeControl->CreateTextViewLayoutItem(), 1, 1) 234 .Add(typeMenuField->CreateLabelLayoutItem(), 0, 2) 235 .Add(typeMenuField->CreateMenuBarLayoutItem(), 1, 2) 236 ) 237 .Add(visibleBox = new BBox(B_FANCY_BORDER, 238 BGridLayoutBuilder(padding, padding) 239 .Add(fDisplayAsMenuField->CreateLabelLayoutItem(), 0, 0) 240 .Add(fDisplayAsMenuField->CreateMenuBarLayoutItem(), 1, 0) 241 .Add(fEditableCheckBox, 3, 0) 242 .Add(fSpecialControl->CreateLabelLayoutItem(), 0, 1) 243 .Add(fSpecialControl->CreateTextViewLayoutItem(), 1, 1, 3) 244 .Add(fWidthControl->CreateLabelLayoutItem(), 0, 2) 245 .Add(fWidthControl->CreateTextViewLayoutItem(), 1, 2, 3) 246 .Add(fAlignmentMenuField->CreateLabelLayoutItem(), 0, 3) 247 .Add(fAlignmentMenuField->CreateMenuBarLayoutItem(), 1, 3, 3) 248 .SetInsets(padding, padding, padding, padding) 249 )) 250 .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) 251 .Add(BSpaceLayoutItem::CreateGlue()) 252 .Add(BSpaceLayoutItem::CreateGlue()) 253 .Add(cancelButton) 254 .Add(fAcceptButton) 255 ) 256 ); 257 visibleBox->SetLabel(fVisibleCheckBox); 285 258 286 259 fAcceptButton->MakeDefault(true); 287 260 fPublicNameControl->MakeFocus(true); -
FileTypesWindow.h
20 20 21 21 class AttributeListView; 22 22 class ExtensionListView; 23 class StringView; 23 24 class TypeIconView; 24 25 class MimeTypeListView; 25 class StringView;26 26 27 27 28 28 class FileTypesWindow : public BWindow { -
DropTargetListView.cpp
7 7 #include "DropTargetListView.h" 8 8 9 9 10 DropTargetListView::DropTargetListView( BRect frame,const char* name,11 list_view_type type, uint32 resizeMask, uint32flags)12 : BListView( frame, name, type, resizeMask, flags),10 DropTargetListView::DropTargetListView(const char* name, 11 list_view_type type, uint32 flags) 12 : BListView(name, type, flags), 13 13 fDropTarget(false) 14 14 { 15 15 } -
StringView.h
6 6 #define STRING_VIEW_H 7 7 8 8 9 #include <String.h> 10 #include <View.h> 9 class BLayoutItem; 10 class BGroupView; 11 class BStringView; 11 12 12 13 class StringView : public BView { 13 class StringView { 14 14 public: 15 StringView(BRect frame, const char* name, const char* label, 16 const char* text, uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, 17 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS); 18 virtual ~StringView(); 15 StringView(const char* label, 16 const char* text); 19 17 20 virtual void Draw(BRect updateRect);21 virtual void AttachedToWindow();22 23 virtual void FrameResized(float width, float height);24 25 virtual void GetPreferredSize(float* _width, float* _height);26 virtual void ResizeToPreferred();27 28 18 void SetEnabled(bool enabled); 29 bool IsEnabled() const { return fEnabled; }30 19 31 20 void SetLabel(const char* label); 32 const char* Label() const { return fLabel.String(); } 33 21 const char* Label() const; 34 22 void SetText(const char* text); 35 const char* Text() const { return fText.String(); }23 const char* Text() const; 36 24 37 void SetDivider(float divider); 38 float Divider() const { return fDivider; } 25 BLayoutItem* GetLabelLayoutItem(); 26 BView* LabelView(); 27 BLayoutItem* GetTextLayoutItem(); 28 BView* TextView(); 39 29 40 void SetAlignment(alignment labelAlignment, alignment textAlignment); 41 void GetAlignment(alignment* _label, alignment* _text) const; 30 operator BView*(); 42 31 43 32 private: 44 void _UpdateText();45 33 46 BString fLabel; 47 BString fText; 48 BString fTruncatedText; 49 float fDivider; 50 alignment fLabelAlignment; 51 alignment fTextAlignment; 52 bool fEnabled; 34 BGroupView* fView; 35 BStringView* fLabel; 36 BLayoutItem* fLabelItem; 37 BStringView* fText; 38 BLayoutItem* fTextItem; 53 39 }; 54 40 41 55 42 #endif // STRING_VIEW_H -
ApplicationTypesWindow.cpp
16 16 #include <Bitmap.h> 17 17 #include <Box.h> 18 18 #include <Button.h> 19 #include <ControlLook.h> 20 #include <GridLayoutBuilder.h> 21 #include <GroupLayoutBuilder.h> 19 22 #include <MenuField.h> 20 23 #include <MenuItem.h> 21 24 #include <Mime.h> … … 54 57 const uint32 kMsgEdit = 'edit'; 55 58 56 59 57 const char* 60 const char* 58 61 variety_to_text(uint32 variety) 59 62 { 60 63 #if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE) … … 88 91 // #pragma mark - 89 92 90 93 91 ProgressWindow::ProgressWindow(const char* message, int32 max, volatile bool* signalQuit) 92 : BWindow(BRect(0, 0, 300, 200), "Progress", B_MODAL_WINDOW_LOOK, 93 B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE), 94 ProgressWindow::ProgressWindow(const char* message, 95 int32 max, volatile bool* signalQuit) 96 : 97 BWindow(BRect(0, 0, 300, 200), "Progress", B_MODAL_WINDOW_LOOK, 98 B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | 99 B_NOT_V_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), 94 100 fQuitListener(signalQuit) 95 101 { 96 BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);97 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));98 AddChild(topView);99 100 102 char count[100]; 101 103 snprintf(count, sizeof(count), "/%ld", max); 102 104 103 BRect rect = Bounds().InsetByCopy(8, 8); 104 fStatusBar = new BStatusBar(rect, "status", message, count); 105 fStatusBar = new BStatusBar("status", message, count); 105 106 fStatusBar->SetMaxValue(max); 106 fStatusBar->SetResizingMode(B_FOLLOW_LEFT_RIGHT); 107 float width, height; 108 fStatusBar->GetPreferredSize(&width, &height); 109 fStatusBar->ResizeTo(rect.Width(), height); 110 topView->AddChild(fStatusBar); 107 fAbortButton = new BButton("abort", "Abort", new BMessage(B_CANCEL)); 108 109 SetLayout(new BGroupLayout(B_VERTICAL)); 110 AddChild(BGroupLayoutBuilder(B_VERTICAL, 3.0f) 111 .Add(fStatusBar) 112 .Add(fAbortButton) 113 .SetInsets(3.0f, 3.0f, 3.0f, 3.0f) 114 ); 111 115 112 fAbortButton = new BButton(rect, "abort", "Abort", new BMessage(B_CANCEL),113 B_FOLLOW_H_CENTER | B_FOLLOW_TOP);114 fAbortButton->ResizeToPreferred();115 fAbortButton->MoveTo((Bounds().Width() - fAbortButton->Bounds().Width()) / 2,116 fStatusBar->Frame().bottom + 10.0f);117 topView->AddChild(fAbortButton);118 119 ResizeTo(width * 1.4f, fAbortButton->Frame().bottom + 8.0f);120 SetSizeLimits(width + 42.0f, 32767.0f,121 Bounds().Height(), Bounds().Height());122 123 116 // center on screen 124 117 BScreen screen(this); 125 MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2.0f, 126 screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2.0f); 118 MoveTo(screen.Frame().left + (screen.Frame().Width() 119 - Bounds().Width()) / 2.0f, 120 screen.Frame().top + (screen.Frame().Height() 121 - Bounds().Height()) / 2.0f); 127 122 } 128 123 129 124 … … 159 154 // #pragma mark - 160 155 161 156 162 ApplicationTypesWindow::ApplicationTypesWindow(const BMessage &settings)157 ApplicationTypesWindow::ApplicationTypesWindow(const BMessage& settings) 163 158 : BWindow(_Frame(settings), "Application types", B_TITLED_WINDOW, 164 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS )159 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) 165 160 { 166 // Application list167 161 168 BRect rect = Bounds(); 169 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); 170 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 171 AddChild(topView); 162 float padding = 3.0f; 163 BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); 164 BAlignment fullWidthTopAlignment = 165 BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP); 166 if (be_control_look) { 167 // padding = be_control_look->DefaultItemSpacing(); 168 // seems too big 169 labelAlignment = be_control_look->DefaultLabelAlignment(); 170 } 172 171 173 BButton* button = new BButton(rect, "remove", "Remove uninstalled", 174 new BMessage(kMsgRemoveUninstalled), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); 175 button->ResizeToPreferred(); 176 button->MoveTo(8.0f, rect.bottom - 8.0f - button->Bounds().Height()); 177 topView->AddChild(button); 172 // Application list 173 BView* currentView = new BGroupView(B_VERTICAL, padding); 178 174 179 rect.bottom = button->Frame().top - 10.0f; 180 rect.top = 10.0f; 181 rect.left = 10.0f; 182 rect.right = 170; 183 184 fTypeListView = new MimeTypeListView(rect, "listview", "application", true, true, 185 B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); 175 fTypeListView = new MimeTypeListView("listview", "application", true, true); 186 176 fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); 187 177 fTypeListView->SetInvocationMessage(new BMessage(kMsgTypeInvoked)); 188 178 189 179 BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, 190 B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 191 topView->AddChild(scrollView); 180 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 192 181 193 // "Information" group 182 BButton* button = new BButton("remove", "Remove uninstalled", 183 new BMessage(kMsgRemoveUninstalled)); 194 184 195 BFont font(be_bold_font); 196 font_height fontHeight; 197 font.GetHeight(&fontHeight); 185 SetLayout(BGroupLayoutBuilder(B_HORIZONTAL)); 198 186 199 rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; 200 rect.top -= 2.0f; 201 rect.right = topView->Bounds().Width() - 8.0f; 202 rect.bottom = rect.top + ceilf(fontHeight.ascent) + 24.0f; 203 BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 204 box->SetLabel("Information"); 205 topView->AddChild(box); 187 // "Information" group 206 188 207 BRect innerRect = box->Bounds().InsetByCopy(8.0f, 6.0f); 208 float labelWidth = topView->StringWidth("Description:") + 4.0f; 189 BBox* infoBox = new BBox((char*)NULL); 190 infoBox->SetLabel("Information"); 191 infoBox->SetExplicitAlignment(fullWidthTopAlignment); 192 193 fNameView = new StringView("Name:", NULL); 194 fNameView->TextView()->SetExplicitAlignment(labelAlignment); 195 fNameView->LabelView()->SetExplicitAlignment(labelAlignment); 196 fSignatureView = new StringView("Signature:", NULL); 197 fSignatureView->TextView()->SetExplicitAlignment(labelAlignment); 198 fSignatureView->LabelView()->SetExplicitAlignment(labelAlignment); 199 fPathView = new StringView("Path:", NULL); 200 fPathView->TextView()->SetExplicitAlignment(labelAlignment); 201 fPathView->LabelView()->SetExplicitAlignment(labelAlignment); 209 202 210 innerRect.right = box->Bounds().Width() - 8.0f; 211 innerRect.top += ceilf(fontHeight.ascent); 212 fNameView = new StringView(innerRect, "name", "Name:", NULL, B_FOLLOW_LEFT_RIGHT); 213 fNameView->SetDivider(labelWidth); 214 float width, height; 215 fNameView->GetPreferredSize(&width, &height); 216 fNameView->ResizeTo(innerRect.Width(), height); 217 box->ResizeBy(0, fNameView->Bounds().Height() * 3.0f); 218 box->AddChild(fNameView); 203 infoBox->AddChild( 204 BGridLayoutBuilder(padding, padding) 205 .Add(fNameView->LabelView(), 0, 0) 206 .Add(fNameView->TextView(), 1, 0, 2) 207 .Add(fSignatureView->LabelView(), 0, 1) 208 .Add(fSignatureView->TextView(), 1, 1, 2, 2) 209 .Add(fPathView->LabelView(), 0, 2) 210 .Add(fPathView->TextView(), 1, 2, 2) 211 .SetInsets(padding, padding, padding, padding) 212 ); 219 213 220 innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f);221 innerRect.bottom = innerRect.top + height;222 fSignatureView = new StringView(innerRect, "signature", "Signature:", NULL,223 B_FOLLOW_LEFT_RIGHT);224 fSignatureView->SetDivider(labelWidth);225 box->AddChild(fSignatureView);226 227 innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f);228 fPathView = new StringView(innerRect, "path", "Path:", NULL,229 B_FOLLOW_LEFT_RIGHT);230 fPathView->SetDivider(labelWidth);231 box->AddChild(fPathView);232 233 214 // "Version" group 234 215 235 rect.top = box->Frame().bottom + 8.0f; 236 rect.bottom = rect.top + ceilf(fontHeight.ascent) 237 + fNameView->Bounds().Height() * 4.0f + 20.0f; 238 box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 239 box->SetLabel("Version"); 240 topView->AddChild(box); 216 BBox* versionBox = new BBox(""); 217 versionBox->SetLabel("Version"); 218 versionBox->SetExplicitAlignment(fullWidthTopAlignment); 241 219 242 innerRect = fNameView->Frame(); 243 fVersionView = new StringView(innerRect, "version", "Version:", NULL, 244 B_FOLLOW_LEFT_RIGHT); 245 fVersionView->SetDivider(labelWidth); 246 box->AddChild(fVersionView); 247 248 innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f); 249 innerRect.right = innerRect.left + labelWidth; 250 fDescriptionLabel = new StringView(innerRect, "description", "Description:", NULL); 251 fDescriptionLabel->SetDivider(labelWidth); 252 box->AddChild(fDescriptionLabel); 253 254 innerRect.left = innerRect.right + 3.0f; 255 innerRect.top += 1.0f; 256 innerRect.right = box->Bounds().Width() - 8.0f; 257 innerRect.bottom += fNameView->Bounds().Height() * 2.0f - 1.0f; 258 fDescriptionView = new BTextView(innerRect, "description", 259 innerRect.OffsetToCopy(B_ORIGIN), B_FOLLOW_LEFT_RIGHT, 260 B_WILL_DRAW | B_FRAME_EVENTS); 220 fVersionView = new StringView("Version:", NULL); 221 fVersionView->TextView()->SetExplicitAlignment(labelAlignment); 222 fVersionView->LabelView()->SetExplicitAlignment(labelAlignment); 223 fDescriptionLabel = new StringView("Description:", NULL); 224 fDescriptionLabel->LabelView()->SetExplicitAlignment(labelAlignment); 225 fDescriptionView = new BTextView("description"); 261 226 fDescriptionView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 262 227 fDescriptionView->SetLowColor(fDescriptionView->ViewColor()); 263 228 fDescriptionView->MakeEditable(false); 264 box->AddChild(fDescriptionView); 229 230 versionBox->AddChild(currentView = 231 BGridLayoutBuilder(padding, padding) 232 .Add(fVersionView->LabelView(), 0, 0) 233 .Add(fVersionView->TextView(), 1, 0) 234 .Add(fDescriptionLabel->LabelView(), 0, 1) 235 .Add(fDescriptionView, 1, 1, 2, 2) 236 .SetInsets(padding, padding, padding, padding) 237 ); 238 currentView->SetExplicitAlignment(fullWidthTopAlignment); 265 239 266 240 // Launch and Tracker buttons 267 241 268 rect = box->Frame(); 269 rect.top = rect.bottom + 8.0f; 270 rect.bottom = rect.top + 20.0f; 271 fTrackerButton = new BButton(rect, "tracker", "Show in Tracker" B_UTF8_ELLIPSIS, NULL, 272 B_FOLLOW_RIGHT); 273 fTrackerButton->ResizeToPreferred(); 274 fTrackerButton->MoveTo(rect.right - fTrackerButton->Bounds().Width(), rect.top); 275 topView->AddChild(fTrackerButton); 242 fEditButton = new BButton("Edit" B_UTF8_ELLIPSIS, new BMessage(kMsgEdit)); 243 // launch and tracker buttons get messages in _SetType() 244 fLaunchButton = new BButton("Launch"); 245 fTrackerButton = new BButton("Show in Tracker" B_UTF8_ELLIPSIS); 276 246 277 fLaunchButton = new BButton(rect, "launch", "Launch", NULL, 278 B_FOLLOW_RIGHT); 279 fLaunchButton->ResizeToPreferred(); 280 fLaunchButton->MoveTo(fTrackerButton->Frame().left - 6.0f 281 - fLaunchButton->Bounds().Width(), rect.top); 282 topView->AddChild(fLaunchButton); 283 284 fEditButton = new BButton(rect, "edit", "Edit" B_UTF8_ELLIPSIS, new BMessage(kMsgEdit), 285 B_FOLLOW_RIGHT); 286 fEditButton->ResizeToPreferred(); 287 fEditButton->MoveTo(fLaunchButton->Frame().left - 6.0f 288 - fEditButton->Bounds().Width(), rect.top); 289 topView->AddChild(fEditButton); 247 AddChild(BGroupLayoutBuilder(B_HORIZONTAL, padding) 248 .Add(BGroupLayoutBuilder(B_VERTICAL, padding) 249 .Add(scrollView) 250 .Add(button) 251 .SetInsets(padding, padding, padding, padding) 252 , 3) 253 .Add(BGroupLayoutBuilder(B_VERTICAL, padding) 254 .Add(infoBox) 255 .Add(versionBox) 256 .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) 257 .Add(fEditButton) 258 .Add(fLaunchButton) 259 .Add(fTrackerButton) 260 ) 261 .AddGlue() 262 .SetInsets(padding, padding, padding, padding) 263 ) 264 .SetInsets(padding, padding, padding, padding) 265 ); 290 266 291 SetSizeLimits(scrollView->Frame().right + 22.0f + fTrackerButton->Frame().Width()292 + fLaunchButton->Frame().Width() + 6 + fEditButton->Frame().Width(), 32767.0f,293 fTrackerButton->Frame().bottom + 8.0f, 32767.0f);294 295 267 BMimeType::StartWatching(this); 296 268 _SetType(NULL); 297 269 } … … 322 294 int32 removed = 0; 323 295 volatile bool quit = false; 324 296 325 BWindow* progressWindow = new ProgressWindow("Removing uninstalled application types", 326 fTypeListView->FullListCountItems(), &quit); 297 BWindow* progressWindow = 298 new ProgressWindow("Removing uninstalled application types", 299 fTypeListView->FullListCountItems(), &quit); 327 300 progressWindow->AddToSubset(this); 328 301 progressWindow->Show(); 329 302 330 303 for (int32 i = fTypeListView->FullListCountItems(); i-- > 0 && !quit;) { 331 MimeTypeItem* item = dynamic_cast<MimeTypeItem*>(fTypeListView->FullListItemAt(i)); 304 MimeTypeItem* item = dynamic_cast<MimeTypeItem*> 305 (fTypeListView->FullListItemAt(i)); 332 306 progressWindow->PostMessage(B_UPDATE_STATUS_BAR); 333 307 334 308 if (item == NULL) … … 474 448 fNameView->SetEnabled(enabled); 475 449 fSignatureView->SetEnabled(enabled); 476 450 fPathView->SetEnabled(enabled); 477 451 478 452 fVersionView->SetEnabled(enabled); 479 453 fDescriptionLabel->SetEnabled(enabled); 480 454 … … 485 459 486 460 487 461 void 488 ApplicationTypesWindow::FrameResized(float width, float height)489 {490 // This works around a flaw of BTextView491 fDescriptionView->SetTextRect(fDescriptionView->Bounds());492 }493 494 495 void496 462 ApplicationTypesWindow::MessageReceived(BMessage* message) 497 463 { 498 464 switch (message->what) { -
IconView.cpp
21 21 #include <PopUpMenu.h> 22 22 #include <Resources.h> 23 23 #include <Roster.h> 24 #include <Size.h> 24 25 25 26 #include <new> 26 27 #include <stdlib.h> … … 523 524 // #pragma mark - 524 525 525 526 526 IconView::IconView( BRect rect, const char* name, uint32 resizeMode, uint32 flags)527 : BControl( rect, name, NULL, NULL, resizeMode, B_WILL_DRAW | flags),527 IconView::IconView(const char* name, uint32 flags) 528 : BControl(name, NULL, NULL, B_WILL_DRAW | flags), 528 529 fModificationMessage(NULL), 529 530 fIconSize(B_LARGE_ICON), 530 531 fIcon(NULL), … … 781 782 } 782 783 783 784 785 BSize 786 IconView::MinSize() 787 { 788 float width, height; 789 GetPreferredSize(&width, &height); 790 return BSize(width, height); 791 } 792 793 794 BSize 795 IconView::PreferredSize() 796 { 797 return MinSize(); 798 } 799 800 801 BSize 802 IconView::MaxSize() 803 { 804 return MinSize(); 805 } 806 807 784 808 void 785 809 IconView::MouseDown(BPoint where) 786 810 { … … 1108 1132 } 1109 1133 1110 1134 1111 void 1135 status_t 1112 1136 IconView::SetTarget(const BMessenger& target) 1113 1137 { 1114 1138 fTarget = target; 1139 return B_OK; 1115 1140 } 1116 1141 1117 1142 … … 1123 1148 } 1124 1149 1125 1150 1126 void 1151 status_t 1127 1152 IconView::Invoke(const BMessage* _message) 1128 1153 { 1129 1154 if (_message == NULL) … … 1132 1157 BMessage message(*_message); 1133 1158 fTarget.SendMessage(&message); 1134 1159 } 1160 return B_OK; 1135 1161 } 1136 1162 1137 1163 -
MimeTypeListView.h
52 52 53 53 class MimeTypeListView : public BOutlineListView { 54 54 public: 55 MimeTypeListView( BRect rect,const char* name,55 MimeTypeListView(const char* name, 56 56 const char* supertype = NULL, bool showIcons = false, 57 bool applicationMode = false, 58 uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP); 57 bool applicationMode = false); 59 58 virtual ~MimeTypeListView(); 60 59 61 60 void SelectNewType(const char* type); -
FileTypesWindow.cpp
16 16 #include "PreferredAppMenu.h" 17 17 #include "StringView.h" 18 18 19 #include <Alignment.h> 19 20 #include <AppFileInfo.h> 20 21 #include <Application.h> 21 22 #include <Bitmap.h> 22 23 #include <Box.h> 23 24 #include <Button.h> 25 #include <ControlLook.h> 26 #include <GridLayoutBuilder.h> 27 #include <GroupLayoutBuilder.h> 24 28 #include <ListView.h> 25 29 #include <MenuBar.h> 26 30 #include <MenuField.h> … … 30 34 #include <OutlineListView.h> 31 35 #include <PopUpMenu.h> 32 36 #include <ScrollView.h> 37 #include <SpaceLayoutItem.h> 38 #include <SplitView.h> 33 39 #include <TextControl.h> 34 40 35 41 #include <OverrideAlert.h> … … 38 44 #include <stdio.h> 39 45 #include <stdlib.h> 40 46 41 42 47 const uint32 kMsgTypeSelected = 'typs'; 43 48 const uint32 kMsgAddType = 'atyp'; 44 49 const uint32 kMsgRemoveType = 'rtyp'; … … 69 74 70 75 class TypeIconView : public IconView { 71 76 public: 72 TypeIconView(BRect frame, const char* name, 73 int32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP); 77 TypeIconView(const char* name); 74 78 virtual ~TypeIconView(); 75 79 76 80 virtual void Draw(BRect updateRect); … … 82 86 83 87 class ExtensionListView : public DropTargetListView { 84 88 public: 85 ExtensionListView( BRect frame,const char* name,89 ExtensionListView(const char* name, 86 90 list_view_type type = B_SINGLE_SELECTION_LIST, 87 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,88 91 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 89 92 virtual ~ExtensionListView(); 90 93 … … 101 104 // #pragma mark - 102 105 103 106 104 TypeIconView::TypeIconView( BRect frame, const char* name, int32 resizingMode)105 : IconView( frame, name, resizingMode)107 TypeIconView::TypeIconView(const char* name) 108 : IconView(name) 106 109 { 107 110 ShowEmptyFrame(false); 108 111 } … … 202 205 // #pragma mark - 203 206 204 207 205 ExtensionListView::ExtensionListView( BRect frame,const char* name,206 list_view_type type, uint32 resizeMask, uint32flags)207 : DropTargetListView( frame, name, type, resizeMask, flags)208 ExtensionListView::ExtensionListView(const char* name, 209 list_view_type type, uint32 flags) 210 : DropTargetListView(name, type, flags) 208 211 { 209 212 } 210 213 … … 271 274 272 275 273 276 FileTypesWindow::FileTypesWindow(const BMessage& settings) 274 : BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW, 275 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), 277 : 278 BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW, 279 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), 276 280 fNewTypeWindow(NULL) 277 281 { 278 282 bool showIcons; … … 282 286 if (settings.FindBool("show_rule", &showRule) != B_OK) 283 287 showRule = false; 284 288 289 SetLayout(new BGroupLayout(B_VERTICAL)); 290 float padding = 3.0f; 291 BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); 292 if (be_control_look) { 293 // padding = be_control_look->DefaultItemSpacing(); 294 // this seems to be very large! 295 labelAlignment = be_control_look->DefaultLabelAlignment(); 296 } 297 BAlignment fullAlignment = 298 BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); 299 285 300 // add the menu 301 BMenuBar* menuBar = new BMenuBar(""); 286 302 287 BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);288 AddChild(menuBar);289 290 303 BMenu* menu = new BMenu("File"); 291 304 BMenuItem* item; 292 305 menu->AddItem(item = new BMenuItem("New resource file" B_UTF8_ELLIPSIS, … … 298 311 item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel)); 299 312 item->SetShortcut('O', B_COMMAND_KEY); 300 313 menu->AddItem(item); 314 301 315 menu->AddItem(new BMenuItem("Application types" B_UTF8_ELLIPSIS, 302 316 new BMessage(kMsgOpenApplicationTypesWindow))); 303 317 menu->AddSeparatorItem(); … … 323 337 menu->AddItem(item); 324 338 menuBar->AddItem(menu); 325 339 340 AddChild(menuBar); 341 menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); 342 326 343 // MIME Types list 344 BButton* addTypeButton = new BButton( "add", "Add" B_UTF8_ELLIPSIS, 345 new BMessage(kMsgAddType)); 327 346 328 BRect rect = Bounds(); 329 rect.top = menuBar->Bounds().Height() + 1.0f; 330 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); 331 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 332 AddChild(topView); 347 fRemoveTypeButton = new BButton( "remove", "Remove", 348 new BMessage(kMsgRemoveType) ); 333 349 334 BButton* button = new BButton(rect, "add", "Add" B_UTF8_ELLIPSIS, 335 new BMessage(kMsgAddType), B_FOLLOW_BOTTOM); 336 button->ResizeToPreferred(); 337 button->MoveTo(8.0f, topView->Bounds().bottom - 8.0f - button->Bounds().Height()); 338 topView->AddChild(button); 339 340 rect = button->Frame(); 341 rect.OffsetBy(rect.Width() + 8.0f, 0.0f); 342 fRemoveTypeButton = new BButton(rect, "remove", "Remove", 343 new BMessage(kMsgRemoveType), B_FOLLOW_BOTTOM); 344 fRemoveTypeButton->ResizeToPreferred(); 345 topView->AddChild(fRemoveTypeButton); 346 347 rect.bottom = rect.top - 10.0f; 348 rect.top = 10.0f; 349 rect.left = 10.0f; 350 rect.right -= B_V_SCROLL_BAR_WIDTH + 2.0f; 351 if (rect.right < 180) 352 rect.right = 180; 353 354 fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false, 355 B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); 350 fTypeListView = new MimeTypeListView( "typeview", NULL, showIcons, false); 356 351 fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); 357 352 358 BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, 359 B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 360 topView->AddChild(scrollView); 353 BScrollView* typeListScrollView = new BScrollView("scrollview", fTypeListView, 354 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 361 355 362 356 // "Icon" group 363 357 364 font_height plainHeight; 365 be_plain_font->GetHeight(&plainHeight); 366 float height = ceilf(plainHeight.ascent + plainHeight.descent 367 + plainHeight.leading) + 2.0f; 368 369 BFont font(be_bold_font); 370 float labelWidth = font.StringWidth("Icon"); 371 font_height boldHeight; 372 font.GetHeight(&boldHeight); 373 374 BRect innerRect; 375 fIconView = new TypeIconView(innerRect, "icon", 376 B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); 377 fIconView->ResizeToPreferred(); 378 379 rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; 380 rect.right = rect.left + max_c(fIconView->Bounds().Width(), labelWidth) + 16.0f; 381 rect.bottom = rect.top + ceilf(boldHeight.ascent) 382 + max_c(fIconView->Bounds().Height(), 383 button->Bounds().Height() * 2.0f + height + 4.0f) + 12.0f; 384 rect.top -= 2.0f; 385 fIconBox = new BBox(rect); 358 fIconView = new TypeIconView( "icon"); 359 fIconBox = new BBox("Icon BBox"); 386 360 fIconBox->SetLabel("Icon"); 387 topView->AddChild(fIconBox); 361 fIconBox->AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 362 .Add(BSpaceLayoutItem::CreateGlue(), 1) 363 .Add(fIconView, 3) 364 .Add(BSpaceLayoutItem::CreateGlue(), 1) 365 .SetInsets(padding, padding, padding, padding) 366 ); 388 367 389 innerRect.left = 8.0f;390 innerRect.top = plainHeight.ascent + 3.0f391 + (rect.Height() - boldHeight.ascent - fIconView->Bounds().Height()) / 2.0f;392 if (innerRect.top + fIconView->Bounds().Height() > fIconBox->Bounds().Height() - 6.0f)393 innerRect.top = fIconBox->Bounds().Height() - 6.0f - fIconView->Bounds().Height();394 fIconView->MoveTo(innerRect.LeftTop());395 fIconBox->AddChild(fIconView);396 397 368 // "File Recognition" group 398 369 399 BRect rightRect(rect); 400 rightRect.left = rect.right + 8.0f; 401 rightRect.right = topView->Bounds().Width() - 8.0f; 402 fRecognitionBox = new BBox(rightRect, NULL, B_FOLLOW_LEFT_RIGHT); 370 fRecognitionBox = new BBox("Recognition Box"); 403 371 fRecognitionBox->SetLabel("File recognition"); 404 topView->AddChild(fRecognitionBox);372 fRecognitionBox->SetExplicitAlignment(fullAlignment); 405 373 406 innerRect = fRecognitionBox->Bounds().InsetByCopy(8.0f, 4.0f); 407 innerRect.top += ceilf(boldHeight.ascent); 408 fExtensionLabel = new StringView(innerRect, "extension", "Extensions:", NULL); 409 fExtensionLabel->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); 410 fExtensionLabel->ResizeToPreferred(); 411 fRecognitionBox->AddChild(fExtensionLabel); 374 fExtensionLabel = new StringView("Extensions:", NULL); 375 fExtensionLabel->LabelView()->SetExplicitAlignment(labelAlignment); 412 376 413 innerRect.top += fExtensionLabel->Bounds().Height() + 2.0f; 414 innerRect.left = innerRect.right - button->StringWidth("Remove") - 16.0f; 415 innerRect.bottom = innerRect.top + button->Bounds().Height(); 416 fAddExtensionButton = new BButton(innerRect, "add ext", "Add" B_UTF8_ELLIPSIS, 417 new BMessage(kMsgAddExtension), B_FOLLOW_RIGHT); 418 fRecognitionBox->AddChild(fAddExtensionButton); 377 fAddExtensionButton = new BButton("add ext", "Add" B_UTF8_ELLIPSIS, 378 new BMessage(kMsgAddExtension)); 419 379 420 innerRect.OffsetBy(0, innerRect.Height() + 4.0f); 421 fRemoveExtensionButton = new BButton(innerRect, "remove ext", "Remove", 422 new BMessage(kMsgRemoveExtension), B_FOLLOW_RIGHT); 423 fRecognitionBox->AddChild(fRemoveExtensionButton); 380 fRemoveExtensionButton = new BButton("remove ext", "Remove", 381 new BMessage(kMsgRemoveExtension)); 424 382 425 innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; 426 innerRect.left = 10.0f; 427 innerRect.top = fAddExtensionButton->Frame().top + 2.0f; 428 innerRect.bottom = innerRect.bottom - 2.0f; 429 // take scrollview border into account 430 fExtensionListView = new ExtensionListView(innerRect, "listview ext", 431 B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT_RIGHT); 383 fExtensionListView = new ExtensionListView("listview ext", 384 B_SINGLE_SELECTION_LIST); 432 385 fExtensionListView->SetSelectionMessage(new BMessage(kMsgExtensionSelected)); 433 386 fExtensionListView->SetInvocationMessage(new BMessage(kMsgExtensionInvoked)); 434 387 435 scrollView = new BScrollView("scrollview ext", fExtensionListView, 436 B_FOLLOW_LEFT_RIGHT, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 437 fRecognitionBox->AddChild(scrollView); 388 BScrollView* scrollView = new BScrollView("scrollview ext", 389 fExtensionListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 438 390 439 innerRect.left = 8.0f; 440 innerRect.top = innerRect.bottom + 10.0f; 441 innerRect.right = fRecognitionBox->Bounds().right - 8.0f; 442 innerRect.bottom = innerRect.top + 20.0f; 443 fRuleControl = new BTextControl(innerRect, "rule", "Rule:", "", 444 new BMessage(kMsgRuleEntered), B_FOLLOW_LEFT_RIGHT); 445 //fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 446 fRuleControl->SetDivider(fRuleControl->StringWidth(fRuleControl->Label()) + 6.0f); 391 fRuleControl = new BTextControl("rule", "Rule:", "", 392 new BMessage(kMsgRuleEntered)); 393 fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 447 394 fRuleControl->Hide(); 448 fRecognitionBox->AddChild(fRuleControl);449 395 396 BView* recognitionBoxGrid = 397 BGridLayoutBuilder(padding, padding) 398 .Add(fExtensionLabel->LabelView(), 0, 0) 399 .Add(scrollView, 0, 1, 2, 3) 400 .Add(fAddExtensionButton, 2, 1) 401 .Add(fRemoveExtensionButton, 2, 2) 402 .Add(fRuleControl, 0, 4, 3, 1) 403 .SetInsets(padding, padding, padding, padding); 404 405 recognitionBoxGrid->SetExplicitAlignment(fullAlignment); 406 fRecognitionBox->AddChild(recognitionBoxGrid); 407 450 408 // "Description" group 451 409 452 rect.top = rect.bottom + 8.0f; 453 rect.bottom = rect.top + ceilf(boldHeight.ascent) + 24.0f; 454 rect.right = rightRect.right; 455 fDescriptionBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 410 fDescriptionBox = new BBox("description BBox"); 456 411 fDescriptionBox->SetLabel("Description"); 457 topView->AddChild(fDescriptionBox);412 fDescriptionBox->SetExplicitAlignment(fullAlignment); 458 413 459 innerRect = fDescriptionBox->Bounds().InsetByCopy(8.0f, 6.0f); 460 innerRect.top += ceilf(boldHeight.ascent); 461 innerRect.bottom = innerRect.top + button->Bounds().Height(); 462 fInternalNameView = new StringView(innerRect, "internal", "Internal name:", "", 463 B_FOLLOW_LEFT_RIGHT); 464 labelWidth = fInternalNameView->StringWidth(fInternalNameView->Label()) + 2.0f; 465 fInternalNameView->SetDivider(labelWidth); 414 fInternalNameView = new StringView("Internal name:", NULL); 466 415 fInternalNameView->SetEnabled(false); 467 fInternalNameView->ResizeToPreferred(); 468 fDescriptionBox->AddChild(fInternalNameView); 416 fTypeNameControl = new BTextControl("type", "Type name:", "", 417 new BMessage(kMsgTypeEntered)); 418 fDescriptionControl = new BTextControl("description", "Description:", 419 "", new BMessage(kMsgDescriptionEntered)); 469 420 470 innerRect.OffsetBy(0, fInternalNameView->Bounds().Height() + 5.0f); 471 fTypeNameControl = new BTextControl(innerRect, "type", "Type name:", "", 472 new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT); 473 fTypeNameControl->SetDivider(labelWidth); 474 fTypeNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); 475 fDescriptionBox->ResizeBy(0, fInternalNameView->Bounds().Height() 476 + fTypeNameControl->Bounds().Height() * 2.0f); 477 fDescriptionBox->AddChild(fTypeNameControl); 421 fDescriptionBox->AddChild(BGridLayoutBuilder(padding, padding) 422 .Add(fInternalNameView->LabelView(), 0, 0) 423 .Add(fInternalNameView->TextView(), 1, 0) 424 .Add(fTypeNameControl->CreateLabelLayoutItem(), 0, 1) 425 .Add(fTypeNameControl->CreateTextViewLayoutItem(), 1, 1, 2) 426 .Add(fDescriptionControl->CreateLabelLayoutItem(), 0, 2) 427 .Add(fDescriptionControl->CreateTextViewLayoutItem(), 1, 2, 2) 428 .SetInsets(padding, padding, padding, padding) 429 ); 478 430 479 innerRect.OffsetBy(0, fTypeNameControl->Bounds().Height() + 5.0f);480 fDescriptionControl = new BTextControl(innerRect, "description", "Description:", "",481 new BMessage(kMsgDescriptionEntered), B_FOLLOW_LEFT_RIGHT);482 fDescriptionControl->SetDivider(labelWidth);483 fDescriptionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);484 fDescriptionBox->AddChild(fDescriptionControl);485 431 486 432 // "Preferred Application" group 487 433 488 rect = fDescriptionBox->Frame(); 489 rect.top = rect.bottom + 8.0f; 490 rect.bottom = rect.top + ceilf(boldHeight.ascent) 491 + button->Bounds().Height() + 14.0f; 492 fPreferredBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 434 fPreferredBox = new BBox("preferred BBox"); 493 435 fPreferredBox->SetLabel("Preferred application"); 494 topView->AddChild(fPreferredBox);495 436 496 innerRect = fPreferredBox->Bounds().InsetByCopy(8.0f, 6.0f);497 innerRect.top += ceilf(boldHeight.ascent);498 innerRect.left = innerRect.right - button->StringWidth(499 "Same as" B_UTF8_ELLIPSIS) - 24.0f;500 innerRect.bottom = innerRect.top + button->Bounds().Height();501 fSameAsButton = new BButton(innerRect, "same as",502 "Same as" B_UTF8_ELLIPSIS,503 new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_RIGHT);504 fPreferredBox->AddChild(fSameAsButton);505 506 innerRect.OffsetBy(-innerRect.Width() - 6.0f, 0.0f);507 fSelectButton = new BButton(innerRect, "select", "Select" B_UTF8_ELLIPSIS,508 new BMessage(kMsgSelectPreferredApp), B_FOLLOW_RIGHT);509 fPreferredBox->AddChild(fSelectButton);510 511 437 menu = new BPopUpMenu("preferred"); 512 438 menu->AddItem(item = new BMenuItem("None", 513 439 new BMessage(kMsgPreferredAppChosen))); 514 440 item->SetMarked(true); 441 fPreferredField = new BMenuField("preferred", (char*)NULL, menu); 515 442 516 innerRect.right = innerRect.left - 6.0f;517 innerRect.left = 8.0f;443 fSelectButton = new BButton("select", "Select" B_UTF8_ELLIPSIS, 444 new BMessage(kMsgSelectPreferredApp)); 518 445 519 fPreferredField = new BMenuField(innerRect, "preferred", NULL, menu, true, 520 B_FOLLOW_LEFT_RIGHT); 521 float width; 522 fPreferredField->GetPreferredSize(&width, &height); 523 fPreferredField->ResizeTo(innerRect.Width(), height); 524 fPreferredField->MoveBy(0.0f, (innerRect.Height() - height) / 2.0f); 446 fSameAsButton = new BButton("same as", "Same as" B_UTF8_ELLIPSIS, 447 new BMessage(kMsgSamePreferredAppAs)); 525 448 526 fPreferredBox->AddChild(fPreferredField); 449 fPreferredBox->AddChild( 450 BGroupLayoutBuilder(B_HORIZONTAL, padding) 451 .Add(fPreferredField) 452 .Add(fSelectButton) 453 .Add(fSameAsButton) 454 .SetInsets(padding, padding, padding, padding) 455 ); 527 456 528 457 // "Extra Attributes" group 529 530 rect.top = rect.bottom + 8.0f; 531 rect.bottom = topView->Bounds().Height() - 8.0f; 532 fAttributeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT 533 | B_FOLLOW_TOP_BOTTOM); 458 fAttributeBox = new BBox("fAttributeBox"); 534 459 fAttributeBox->SetLabel("Extra attributes"); 535 topView->AddChild(fAttributeBox);536 460 537 innerRect = fAttributeBox->Bounds().InsetByCopy(8.0f, 6.0f); 538 innerRect.top += ceilf(boldHeight.ascent); 539 innerRect.left = innerRect.right - button->StringWidth("Remove") - 16.0f; 540 innerRect.bottom = innerRect.top + button->Bounds().Height(); 541 fAddAttributeButton = new BButton(innerRect, "add attr", 542 "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddAttribute), B_FOLLOW_RIGHT); 543 fAttributeBox->AddChild(fAddAttributeButton); 461 fAddAttributeButton = new BButton("add attr", 462 "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddAttribute)); 544 463 545 innerRect.OffsetBy(0, innerRect.Height() + 4.0f); 546 fRemoveAttributeButton = new BButton(innerRect, "remove attr", "Remove", 547 new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); 548 fAttributeBox->AddChild(fRemoveAttributeButton); 549 /* 550 innerRect.OffsetBy(0, innerRect.Height() + 4.0f); 551 button = new BButton(innerRect, "push attr", "Push Up", 552 new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); 553 fAttributeBox->AddChild(button); 554 */ 555 innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; 556 innerRect.left = 10.0f; 557 innerRect.top = 8.0f + ceilf(boldHeight.ascent); 558 innerRect.bottom = fAttributeBox->Bounds().bottom - 10.0f; 559 // take scrollview border into account 560 fAttributeListView = new AttributeListView(innerRect, "listview attr", 561 B_FOLLOW_ALL); 464 fRemoveAttributeButton = new BButton("remove attr", "Remove", 465 new BMessage(kMsgRemoveAttribute)); 466 467 fAttributeListView = new AttributeListView("listview attr"); 562 468 fAttributeListView->SetSelectionMessage(new BMessage(kMsgAttributeSelected)); 563 469 fAttributeListView->SetInvocationMessage(new BMessage(kMsgAttributeInvoked)); 564 470 565 scrollView = new BScrollView("scrollview attr", fAttributeListView, 566 B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 567 fAttributeBox->AddChild(scrollView); 471 BScrollView* attributesScroller = new BScrollView("scrollview attr", 472 fAttributeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 568 473 569 SetSizeLimits(rightRect.left + 72.0f + font.StringWidth("jpg") 570 + font.StringWidth(fRecognitionBox->Label()), 32767.0f, 571 rect.top + 2.0f * button->Bounds().Height() + boldHeight.ascent 572 + 32.0f + menuBar->Bounds().Height(), 32767.0f); 474 fAttributeBox->AddChild(BGridLayoutBuilder(padding, padding) 475 .Add(attributesScroller, 0, 0, 2, 3) 476 .Add(fAddAttributeButton, 2, 0) 477 .Add(fRemoveAttributeButton, 2, 1) 478 .SetInsets(padding, padding, padding, padding) 479 ); 573 480 481 482 BView* topView = 483 BGroupLayoutBuilder(B_HORIZONTAL, padding) 484 .SetInsets(padding, padding, padding, padding) 485 .Add(BGroupLayoutBuilder(B_VERTICAL, padding) 486 .Add(typeListScrollView) 487 .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) 488 .Add(addTypeButton).Add(fRemoveTypeButton) 489 ) 490 ) 491 // Right side 492 .Add(BGroupLayoutBuilder(B_VERTICAL, padding) 493 .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) 494 .Add(fIconBox, 1).Add(fRecognitionBox, 3) 495 ) 496 .Add(fDescriptionBox) 497 .Add(fPreferredBox) 498 .Add(fAttributeBox, 5) 499 ); 500 501 //topView->SetExplicitAlignment(fullAlignment); 502 //topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 503 AddChild(topView); 504 574 505 _SetType(NULL); 575 506 _ShowSnifferRule(showRule); 576 507 … … 591 522 if (settings.FindRect("file_types_frame", &rect) == B_OK) 592 523 return rect; 593 524 594 return BRect(80.0f, 80.0f, 600.0f, 480.0f);525 return BRect(80.0f, 80.0f, 0.0f, 0.0f); 595 526 } 596 527 597 528 … … 601 532 if (fRuleControl->IsHidden() == !show) 602 533 return; 603 534 604 float minWidth, maxWidth, minHeight, maxHeight; 605 GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); 606 607 float diff = fRuleControl->Bounds().Height() + 8.0f; 608 609 if (!show) { 535 if (!show) 610 536 fRuleControl->Hide(); 611 diff = -diff; 612 } 613 614 // adjust other controls to make space or take it again 615 616 fIconBox->ResizeBy(0.0f, diff); 617 fRecognitionBox->ResizeBy(0.0f, diff); 618 fDescriptionBox->MoveBy(0.0f, diff); 619 fPreferredBox->MoveBy(0.0f, diff); 620 fAttributeBox->MoveBy(0.0f, diff); 621 fAttributeBox->ResizeBy(0.0f, -diff); 622 623 if (show) 537 else 624 538 fRuleControl->Show(); 625 626 SetSizeLimits(minWidth, maxWidth, minHeight + diff, maxHeight);627 539 } 628 540 629 541 -
ApplicationTypeWindow.cpp
17 17 #include <Box.h> 18 18 #include <Button.h> 19 19 #include <CheckBox.h> 20 #include <ControlLook.h> 20 21 #include <File.h> 22 #include <GridLayoutBuilder.h> 23 #include <GroupLayoutBuilder.h> 24 #include <GroupView.h> 21 25 #include <ListView.h> 22 26 #include <MenuBar.h> 23 27 #include <MenuField.h> … … 28 32 #include <RadioButton.h> 29 33 #include <Roster.h> 30 34 #include <ScrollView.h> 35 #include <StringView.h> 31 36 #include <TextControl.h> 32 37 33 38 #include <ctype.h> … … 54 59 // TextView that filters the tab key to be able to tab-navigate while editing 55 60 class TabFilteringTextView : public BTextView { 56 61 public: 57 TabFilteringTextView(BRect frame, const char* name, BRect textRect, 58 uint32 resizeMask, uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED); 62 TabFilteringTextView(const char* name); 59 63 virtual ~TabFilteringTextView(); 60 64 virtual void KeyDown(const char* bytes, int32 count); 61 65 }; 62 66 63 67 64 TabFilteringTextView::TabFilteringTextView(BRect frame, const char* name, 65 BRect textRect, uint32 resizeMask, uint32 flags) 66 : BTextView(frame, name, textRect, resizeMask, flags) 68 TabFilteringTextView::TabFilteringTextView(const char* name) 69 : BTextView(name, B_WILL_DRAW | B_PULSE_NEEDED) 67 70 { 68 71 } 69 72 … … 102 105 103 106 class SupportedTypeListView : public DropTargetListView { 104 107 public: 105 SupportedTypeListView( BRect frame,const char* name,108 SupportedTypeListView(const char* name, 106 109 list_view_type type = B_SINGLE_SELECTION_LIST, 107 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,108 110 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 109 111 virtual ~SupportedTypeListView(); 110 112 … … 153 155 { 154 156 const SupportedTypeItem* a = *(const SupportedTypeItem**)_a; 155 157 const SupportedTypeItem* b = *(const SupportedTypeItem**)_b; 156 158 157 159 int compare = strcasecmp(a->Text(), b->Text()); 158 160 if (compare != 0) 159 161 return compare; 160 162 161 163 return strcasecmp(a->Type(), b->Type()); 162 164 } 163 165 … … 165 167 // #pragma mark - 166 168 167 169 168 SupportedTypeListView::SupportedTypeListView(BRect frame, const char* name, 169 list_view_type type, uint32 resizeMask, uint32 flags) 170 : DropTargetListView(frame, name, type, resizeMask, flags) 170 SupportedTypeListView::SupportedTypeListView(const char* name, 171 list_view_type type, uint32 flags) 172 : 173 DropTargetListView(name, type, flags) 171 174 { 172 175 } 173 176 … … 188 191 BNodeInfo info(&node); 189 192 if (node.InitCheck() != B_OK || info.InitCheck() != B_OK) 190 193 continue; 191 194 192 195 // TODO: we could identify the file in case it doesn't have a type... 193 196 char type[B_MIME_TYPE_LENGTH]; 194 197 if (info.GetType(type) != B_OK) 195 198 continue; 196 199 197 200 // check if that type is already in our list 198 201 bool found = false; 199 202 for (int32 i = CountItems(); i-- > 0;) { … … 203 206 break; 204 207 } 205 208 } 206 209 207 210 if (!found) { 208 211 // add type 209 212 AddItem(new SupportedTypeItem(type)); 210 213 } 211 214 } 212 215 213 216 SortItems(&SupportedTypeItem::Compare); 214 217 } else 215 218 DropTargetListView::MessageReceived(message); … … 227 230 // #pragma mark - 228 231 229 232 230 ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry) 231 : BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), 233 ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, 234 const BEntry& entry) 235 : 236 BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), 232 237 "Application Type", B_TITLED_WINDOW, 233 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), 238 B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | 239 B_FRAME_EVENTS | B_AUTO_UPDATE_SIZE_LIMITS), 234 240 fChangedProperties(0) 235 241 { 236 // add the menu 237 238 BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); 239 AddChild(menuBar); 240 242 float padding = 3.0f; 243 BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); 244 if (be_control_look){ 245 // padding = be_control_look->DefaultItemSpacing(); 246 // seems too big 247 labelAlignment = be_control_look->DefaultLabelAlignment(); 248 } 249 250 BMenuBar* menuBar = new BMenuBar((char*)NULL); 251 menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); 252 241 253 BMenu* menu = new BMenu("File"); 242 254 fSaveMenuItem = new BMenuItem("Save", new BMessage(kMsgSave), 'S'); 243 255 fSaveMenuItem->SetEnabled(false); … … 246 258 menu->AddItem(item = new BMenuItem("Save into resource file" B_UTF8_ELLIPSIS, 247 259 NULL)); 248 260 item->SetEnabled(false); 249 261 250 262 menu->AddSeparatorItem(); 251 263 menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 252 264 'W', B_COMMAND_KEY)); 253 265 menuBar->AddItem(menu); 266 254 267 255 // Top view and signature 256 257 BRect rect = Bounds(); 258 rect.top = menuBar->Bounds().Height() + 1.0f; 259 BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); 260 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 261 AddChild(topView); 262 263 rect = topView->Bounds().InsetByCopy(8.0f, 8.0f); 264 fSignatureControl = new BTextControl(rect, "signature", "Signature:", NULL, 265 new BMessage(kMsgSignatureChanged), B_FOLLOW_LEFT_RIGHT); 266 fSignatureControl->SetModificationMessage( 268 // Signature 269 270 fSignatureControl = new BTextControl("Signature:", NULL, 267 271 new BMessage(kMsgSignatureChanged)); 268 fSignatureControl->SetDivider(fSignatureControl->StringWidth( 269 fSignatureControl->Label()) + 4.0f); 270 float width, height; 271 fSignatureControl->GetPreferredSize(&width, &height); 272 fSignatureControl->ResizeTo(rect.Width(), height); 273 topView->AddChild(fSignatureControl); 274 272 fSignatureControl->SetModificationMessage( 273 new BMessage(kMsgSignatureChanged)); 274 275 275 // filter out invalid characters that can't be part of a MIME type name 276 276 BTextView* textView = fSignatureControl->TextView(); 277 277 textView->SetMaxBytes(B_MIME_TYPE_LENGTH); … … 279 279 for (int32 i = 0; disallowedCharacters[i]; i++) { 280 280 textView->DisallowChar(disallowedCharacters[i]); 281 281 } 282 282 283 283 // "Application Flags" group 284 285 BBox* flagsBox = new BBox("flagsBox"); 284 286 285 BFont font(be_bold_font); 286 font_height fontHeight; 287 font.GetHeight(&fontHeight); 288 289 width = font.StringWidth("Icon") + 16.0f; 290 if (width < B_LARGE_ICON + 16.0f) 291 width = B_LARGE_ICON + 16.0f; 292 293 rect.top = fSignatureControl->Frame().bottom + 4.0f; 294 rect.bottom = rect.top + 100.0f; 295 rect.right -= width + 8.0f; 296 BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 297 topView->AddChild(box); 298 299 fFlagsCheckBox = new BCheckBox(rect, "flags", "Application flags", 287 fFlagsCheckBox = new BCheckBox("flags", "Application flags", 300 288 new BMessage(kMsgToggleAppFlags)); 301 289 fFlagsCheckBox->SetValue(B_CONTROL_ON); 302 fFlagsCheckBox->ResizeToPreferred(); 303 box->SetLabel(fFlagsCheckBox); 304 305 rect.top = fFlagsCheckBox->Bounds().Height() + 4.0f; 306 fSingleLaunchButton = new BRadioButton(rect, "single", "Single launch", 290 291 fSingleLaunchButton = new BRadioButton("single", "Single launch", 307 292 new BMessage(kMsgAppFlagsChanged)); 308 fSingleLaunchButton->ResizeToPreferred(); 309 box->AddChild(fSingleLaunchButton); 310 311 rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f); 312 fMultipleLaunchButton = new BRadioButton(rect, "multiple", 293 294 fMultipleLaunchButton = new BRadioButton("multiple", 313 295 "Multiple launch", new BMessage(kMsgAppFlagsChanged)); 314 fMultipleLaunchButton->ResizeToPreferred(); 315 box->AddChild(fMultipleLaunchButton); 316 317 rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f); 318 fExclusiveLaunchButton = new BRadioButton(rect, "exclusive", 296 297 fExclusiveLaunchButton = new BRadioButton("exclusive", 319 298 "Exclusive launch", new BMessage(kMsgAppFlagsChanged)); 320 fExclusiveLaunchButton->ResizeToPreferred(); 321 box->AddChild(fExclusiveLaunchButton); 322 323 rect.top = fSingleLaunchButton->Frame().top; 324 rect.left = fExclusiveLaunchButton->Frame().right + 4.0f; 325 fArgsOnlyCheckBox = new BCheckBox(rect, "args only", "Args only", 299 300 fArgsOnlyCheckBox = new BCheckBox("args only", "Args only", 326 301 new BMessage(kMsgAppFlagsChanged)); 327 fArgsOnlyCheckBox->ResizeToPreferred(); 328 box->AddChild(fArgsOnlyCheckBox); 329 330 rect.top += fArgsOnlyCheckBox->Bounds().Height(); 331 fBackgroundAppCheckBox = new BCheckBox(rect, "background", 302 303 fBackgroundAppCheckBox = new BCheckBox("background", 332 304 "Background app", new BMessage(kMsgAppFlagsChanged)); 333 fBackgroundAppCheckBox->ResizeToPreferred(); 334 box->AddChild(fBackgroundAppCheckBox); 335 336 box->ResizeTo(box->Bounds().Width(), 337 fExclusiveLaunchButton->Frame().bottom + 8.0f); 338 305 306 flagsBox->AddChild(BGridLayoutBuilder(padding, padding) 307 .Add(fSingleLaunchButton, 0, 0).Add(fArgsOnlyCheckBox, 1, 0) 308 .Add(fMultipleLaunchButton, 0, 1).Add(fBackgroundAppCheckBox, 1, 1) 309 .Add(fExclusiveLaunchButton, 0, 2) 310 .SetInsets(padding, padding, padding, padding)); 311 flagsBox->SetLabel(fFlagsCheckBox); 312 339 313 // "Icon" group 340 341 rect = box->Frame(); 342 #ifdef __HAIKU__ 343 rect.top += box->TopBorderOffset(); 344 #endif 345 rect.left = rect.right + 8.0f; 346 rect.right += width + 8.0f; 347 float iconBoxWidth = rect.Width(); 348 box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP); 349 box->SetLabel("Icon"); 350 #ifdef __HAIKU__ 351 box->MoveBy(0.0f, -box->TopBorderOffset()); 352 box->ResizeBy(0.0f, box->TopBorderOffset()); 353 #endif 354 topView->AddChild(box); 355 356 rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f); 357 #ifdef __HAIKU__ 358 rect.OffsetBy(0.0f, (box->Bounds().Height() + box->TopBorderOffset() 359 - rect.Height()) / 2.0f); 360 #else 361 rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f); 362 #endif 363 if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f) 364 rect.top = fontHeight.ascent + fontHeight.descent + 4.0f; 365 fIconView = new IconView(rect, "icon"); 314 315 BBox* iconBox = new BBox("IconBox"); 316 iconBox->SetLabel("Icon"); 317 fIconView = new IconView("icon"); 366 318 fIconView->SetModificationMessage(new BMessage(kMsgIconChanged)); 367 box->AddChild(fIconView); 368 319 iconBox->AddChild( 320 BGroupLayoutBuilder(B_HORIZONTAL) 321 .Add(fIconView) 322 .SetInsets(padding, padding, padding, padding) 323 ); 324 369 325 // "Supported Types" group 370 371 rect.top = box->Frame().bottom + 8.0f; 372 rect.bottom = rect.top + box->Bounds().Height(); 373 rect.left = 8.0f; 374 rect.right = Bounds().Width() - 8.0f; 375 BBox* typeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 326 327 BBox* typeBox = new BBox("typesBox"); 376 328 typeBox->SetLabel("Supported types"); 377 topView->AddChild(typeBox); 378 379 rect = typeBox->Bounds().InsetByCopy(8.0f, 6.0f); 380 rect.top += ceilf(fontHeight.ascent); 381 fAddTypeButton = new BButton(rect, "add type", "Add" B_UTF8_ELLIPSIS, 382 new BMessage(kMsgAddType), B_FOLLOW_RIGHT); 383 fAddTypeButton->ResizeToPreferred(); 384 fAddTypeButton->MoveBy(rect.right - fAddTypeButton->Bounds().Width() 385 - B_LARGE_ICON - 16.0f, 0.0f); 386 typeBox->AddChild(fAddTypeButton); 387 388 rect = fAddTypeButton->Frame(); 389 rect.OffsetBy(0, rect.Height() + 4.0f); 390 fRemoveTypeButton = new BButton(rect, "remove type", "Remove", 391 new BMessage(kMsgRemoveType), B_FOLLOW_RIGHT); 392 typeBox->AddChild(fRemoveTypeButton); 393 394 rect.right = rect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; 395 rect.left = 10.0f; 396 rect.top = 8.0f + ceilf(fontHeight.ascent); 397 rect.bottom -= 2.0f; 398 // take scrollview border into account 399 fTypeListView = new SupportedTypeListView(rect, "type listview", 400 B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL); 329 330 fTypeListView = new SupportedTypeListView("Suppported Types", 331 B_SINGLE_SELECTION_LIST); 401 332 fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); 402 333 403 334 BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView, 404 B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 405 406 typeBox->ResizeTo(typeBox->Bounds().Width(), fRemoveTypeButton->Frame().bottom + 8.0f); 407 typeBox->AddChild(scrollView); 408 409 rect.left = fRemoveTypeButton->Frame().right + 8.0f; 410 #ifdef __HAIKU__ 411 rect.top = (box->Bounds().Height() + box->TopBorderOffset() - B_LARGE_ICON) / 2.0f; 412 #else 413 rect.top = (box->Bounds().Height() - B_LARGE_ICON) / 2.0f; 414 #endif 415 rect.right = rect.left + B_LARGE_ICON - 1.0f; 416 rect.bottom = rect.top + B_LARGE_ICON - 1.0f; 417 fTypeIconView = new IconView(rect, "type icon", B_FOLLOW_RIGHT | B_FOLLOW_TOP); 335 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 336 337 fAddTypeButton = new BButton("add type", "Add" B_UTF8_ELLIPSIS, 338 new BMessage(kMsgAddType)); 339 340 fRemoveTypeButton = new BButton("remove type", "Remove", 341 new BMessage(kMsgRemoveType)); 342 343 fTypeIconView = new IconView("type icon"); 344 BView* iconHolder = BGroupLayoutBuilder(B_HORIZONTAL).Add(fTypeIconView); 418 345 fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged)); 419 typeBox->AddChild(fTypeIconView); 420 346 347 typeBox->AddChild(BGridLayoutBuilder(padding, padding) 348 .Add(scrollView, 0, 0, 1, 4) 349 .Add(fAddTypeButton, 1, 0, 1, 2) 350 .Add(fRemoveTypeButton, 1, 2, 1, 2) 351 .Add(iconHolder, 2, 1, 1, 2) 352 .SetInsets(padding, padding, padding, padding) 353 .SetColumnWeight(0, 3) 354 .SetColumnWeight(1, 2) 355 .SetColumnWeight(2, 1) 356 ); 357 iconHolder->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE)); 358 421 359 // "Version Info" group 422 423 rect.top = typeBox->Frame().bottom + 8.0f; 424 rect.bottom = rect.top + typeBox->Bounds().Height(); 425 rect.left = 8.0f; 426 rect.right = Bounds().Width() - 8.0f; 427 box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); 428 // the resizing mode will later also be set to B_FOLLOW_BOTTOM 429 box->SetLabel("Version info"); 430 topView->AddChild(box); 431 432 BMenuField* menuField; 433 #if 0 434 BPopUpMenu *popUpMenu = new BPopUpMenu("version info", true, true); 435 item = new BMenuItem("Version Info", NULL); 436 item->SetMarked(true); 437 popUpMenu->AddItem(item); 438 item = new BMenuItem("System Version Info", NULL); 439 popUpMenu->AddItem(item); 440 441 menuField = new BMenuField(BRect(0, 0, 100, 15), 442 "version kind", NULL, popUpMenu, true); 443 menuField->ResizeToPreferred(); 444 box->SetLabel(menuField); 445 #endif 446 447 rect.top = 4.0f + ceilf(fontHeight.ascent + fontHeight.descent); 448 rect.bottom = rect.top + height; 449 fMajorVersionControl = new BTextControl(rect, "major", "Version:", NULL, 450 NULL); 451 fMajorVersionControl->SetDivider(fMajorVersionControl->StringWidth( 452 fMajorVersionControl->Label()) + 4.0f); 453 fMajorVersionControl->GetPreferredSize(&width, &height); 454 width = 12.0f + fMajorVersionControl->StringWidth("99"); 455 fMajorVersionControl->ResizeTo(fMajorVersionControl->Divider() + width, height); 360 361 BBox* versionBox = new BBox("versionBox"); 362 versionBox->SetLabel("Version info"); 363 364 fMajorVersionControl = new BTextControl("Version:", NULL, NULL); 456 365 _MakeNumberTextControl(fMajorVersionControl); 457 box->AddChild(fMajorVersionControl); 458 459 rect.left = fMajorVersionControl->Frame().right + 1.0f; 460 fMiddleVersionControl = new BTextControl(rect, "middle", ".", NULL, 461 NULL); 462 fMiddleVersionControl->SetDivider(fMiddleVersionControl->StringWidth( 463 fMiddleVersionControl->Label()) + 4.0f); 464 fMiddleVersionControl->ResizeTo(fMiddleVersionControl->Divider() + width, height); 366 367 fMiddleVersionControl = new BTextControl(".", NULL, NULL); 465 368 _MakeNumberTextControl(fMiddleVersionControl); 466 box->AddChild(fMiddleVersionControl); 467 468 rect.left = fMiddleVersionControl->Frame().right + 1.0f; 469 fMinorVersionControl = new BTextControl(rect, "middle", ".", NULL, 470 NULL); 471 fMinorVersionControl->SetDivider(fMinorVersionControl->StringWidth( 472 fMinorVersionControl->Label()) + 4.0f); 473 fMinorVersionControl->ResizeTo(fMinorVersionControl->Divider() + width, height); 369 370 fMinorVersionControl = new BTextControl(".", NULL, NULL); 474 371 _MakeNumberTextControl(fMinorVersionControl); 475 box->AddChild(fMinorVersionControl); 476 372 477 373 fVarietyMenu = new BPopUpMenu("variety", true, true); 478 374 fVarietyMenu->AddItem(new BMenuItem("Development", NULL)); 479 375 fVarietyMenu->AddItem(new BMenuItem("Alpha", NULL)); 480 376 fVarietyMenu->AddItem(new BMenuItem("Beta", NULL)); 481 377 fVarietyMenu->AddItem(new BMenuItem("Gamma", NULL)); 482 fVarietyMenu->AddItem(item = new BMenuItem("Golden master", NULL)); 378 item = new BMenuItem("Golden master", NULL); 379 fVarietyMenu->AddItem(item); 483 380 item->SetMarked(true); 484 381 fVarietyMenu->AddItem(new BMenuItem("Final", NULL)); 485 486 rect.top--; 487 // BMenuField oddity 488 rect.left = fMinorVersionControl->Frame().right + 6.0f; 489 menuField = new BMenuField(rect, 490 "variety", NULL, fVarietyMenu, true); 491 menuField->ResizeToPreferred(); 492 box->AddChild(menuField); 493 494 rect.top++; 495 rect.left = menuField->Frame().right; 496 rect.right = rect.left + 30.0f; 497 fInternalVersionControl = new BTextControl(rect, "internal", "/", NULL, 498 NULL); 499 fInternalVersionControl->SetDivider(fInternalVersionControl->StringWidth( 500 fInternalVersionControl->Label()) + 4.0f); 501 fInternalVersionControl->ResizeTo(fInternalVersionControl->Divider() + width, height); 502 box->AddChild(fInternalVersionControl); 503 504 rect = box->Bounds().InsetByCopy(8.0f, 0.0f); 505 rect.top = fInternalVersionControl->Frame().bottom + 8.0f; 506 fShortDescriptionControl = new BTextControl(rect, "short desc", "Short description:", 507 NULL, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 508 float labelWidth = fShortDescriptionControl->StringWidth( 509 fShortDescriptionControl->Label()) + 4.0f; 510 fShortDescriptionControl->SetDivider(labelWidth); 511 fShortDescriptionControl->GetPreferredSize(&width, &height); 512 fShortDescriptionControl->ResizeTo(rect.Width(), height); 513 382 383 BMenuField* varietyField = new BMenuField("", fVarietyMenu); 384 fInternalVersionControl = new BTextControl("/", NULL, NULL); 385 fShortDescriptionControl = 386 new BTextControl("Short description:", NULL, NULL); 387 514 388 // TODO: workaround for a GCC 4.1.0 bug? Or is that really what the standard says? 515 389 version_info versionInfo; 516 fShortDescriptionControl->TextView()->SetMaxBytes(sizeof(versionInfo.short_info)); 517 box->AddChild(fShortDescriptionControl); 518 519 rect.OffsetBy(0.0f, fShortDescriptionControl->Bounds().Height() + 5.0f); 520 rect.right = rect.left + labelWidth; 521 StringView* label = new StringView(rect, NULL, "Long description:", NULL); 522 label->SetDivider(labelWidth); 523 box->AddChild(label); 524 525 rect.left = rect.right + 3.0f; 526 rect.top += 1.0f; 527 rect.right = box->Bounds().Width() - 10.0f - B_V_SCROLL_BAR_WIDTH; 528 rect.bottom = rect.top + fShortDescriptionControl->Bounds().Height() * 3.0f - 1.0f; 529 fLongDescriptionView = new TabFilteringTextView(rect, "long desc", 530 rect.OffsetToCopy(B_ORIGIN), B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS 531 | B_NAVIGABLE); 390 fShortDescriptionControl->TextView()->SetMaxBytes( 391 sizeof(versionInfo.short_info)); 392 393 BStringView* longLabel = new BStringView(NULL, "Long description:"); 394 longLabel->SetExplicitAlignment(labelAlignment); 395 fLongDescriptionView = new TabFilteringTextView("long desc"); 532 396 fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info)); 533 397 534 398 scrollView = new BScrollView("desc scrollview", fLongDescriptionView, 535 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 536 box->ResizeTo(box->Bounds().Width(), scrollView->Frame().bottom + 8.0f); 537 box->AddChild(scrollView); 399 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 538 400 539 // Adjust window size and limits 401 // TODO: remove workaround (bug #5678) 402 BSize minScrollSize = scrollView->ScrollBar(B_VERTICAL)->MinSize(); 403 minScrollSize.width+=fLongDescriptionView->MinSize().width; 404 scrollView->SetExplicitMinSize(minScrollSize); 405 406 versionBox->AddChild(BGridLayoutBuilder(padding, padding) 407 .Add(fMajorVersionControl->CreateLabelLayoutItem(), 0, 0) 408 .Add(fMajorVersionControl->CreateTextViewLayoutItem(), 1, 0) 409 .Add(fMiddleVersionControl, 2, 0, 2) 410 .Add(fMinorVersionControl, 4, 0, 2) 411 .Add(varietyField, 6, 0, 3) 412 .Add(fInternalVersionControl, 9, 0, 2) 413 .Add(fShortDescriptionControl->CreateLabelLayoutItem(), 0, 1) 414 .Add(fShortDescriptionControl->CreateTextViewLayoutItem(), 1, 1, 10) 415 .Add(longLabel, 0, 2) 416 .Add(scrollView, 1, 2, 10, 3) 417 .SetInsets(padding, padding, padding, padding) 418 .SetRowWeight(3, 3) 419 ); 540 420 541 width = fInternalVersionControl->Frame().right + 16.0f; 542 float minWidth = fBackgroundAppCheckBox->Frame().right + iconBoxWidth + 32.0f; 543 if (width > minWidth) 544 minWidth = width; 421 // put it all together 422 SetLayout(new BGroupLayout(B_VERTICAL)); 423 AddChild(menuBar); 424 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 425 .Add(fSignatureControl) 426 .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) 427 .Add(flagsBox, 3) 428 .Add(iconBox, 1) 429 ) 430 .Add(typeBox) 431 .Add(versionBox) 432 .SetInsets(padding, padding, padding, padding) 433 ); 545 434 546 ResizeTo(Bounds().Width() > minWidth ? Bounds().Width() : minWidth, 547 box->Frame().bottom + topView->Frame().top + 8.0f); 548 SetSizeLimits(minWidth, 32767.0f, Bounds().Height(), 32767.0f); 549 typeBox->SetResizingMode(B_FOLLOW_ALL); 550 box->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM); 435 SetKeyMenuBar(menuBar); 551 436 552 437 fSignatureControl->MakeFocus(true); 553 554 438 BMimeType::StartWatching(this); 555 439 _SetTo(entry); 556 440 }