diff --git a/src/preferences/filetypes/FileTypeWindow.cpp b/src/preferences/filetypes/FileTypeWindow.cpp index 319dcb2dbf..30ca74e186 100644 --- a/src/preferences/filetypes/FileTypeWindow.cpp +++ b/src/preferences/filetypes/FileTypeWindow.cpp @@ -6,6 +6,7 @@ #include "FileTypes.h" #include "FileTypeWindow.h" +#include "IconView.h" #include "PreferredAppMenu.h" #include @@ -36,37 +37,6 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) "File Type", B_TITLED_WINDOW, B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) { - // "Icon" group - -#if 0 - BFont font(be_bold_font); - float labelWidth = font.StringWidth("Icon"); - font_height fontHeight; - font.GetHeight(&fontHeight); - - BRect innerRect; - fIconView = new IconView(innerRect, "icon box", NULL); - fIconView->ResizeToPreferred(); - - rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; - rect.right = rect.left + max_c(fIconView->Bounds().Width(), labelWidth) + 16.0f; - rect.bottom = rect.top + ceilf(fontHeight.ascent) - + max_c(fIconView->Bounds().Height(), - button->Bounds().Height() * 2.0f + 4.0f) + 12.0f; - rect.top -= 2.0f; - BBox* box = new BBox(rect); - box->SetLabel("Icon"); - topView->AddChild(box); - - innerRect.left = 8.0f; - innerRect.top = fontHeight.ascent / 2.0f - + (rect.Height() - fontHeight.ascent / 2.0f - fIconView->Bounds().Height()) / 2.0f - + 3.0f + fontHeight.ascent; - if (innerRect.top + fIconView->Bounds().Height() > box->Bounds().Height() - 6.0f) - innerRect.top = box->Bounds().Height() - 6.0f - fIconView->Bounds().Height(); - fIconView->MoveTo(innerRect.LeftTop()); - box->AddChild(fIconView); -#endif BRect rect = Bounds(); BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -75,7 +45,6 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) // "File Type" group BFont font(be_bold_font); -// float labelWidth = font.StringWidth("Icon"); font_height fontHeight; font.GetHeight(&fontHeight); @@ -113,8 +82,31 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) fSameTypeAsButton->ResizeToPreferred(); box->AddChild(fSameTypeAsButton); - box->ResizeTo(box->Bounds().Width(), fSelectTypeButton->Frame().bottom - + 8.0f); + width = font.StringWidth("Icon") + 16.0f; + if (width < B_LARGE_ICON + 16.0f) + width = B_LARGE_ICON + 16.0f; + + height = fSelectTypeButton->Frame().bottom + 8.0f; + if (height < 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent) + height = 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent; + box->ResizeTo(box->Bounds().Width() - width - 8.0f, height); + + // "Icon" group + + rect = box->Frame(); + rect.left = rect.right + 8.0f; + rect.right += width + 8.0f; + float iconBoxWidth = rect.Width(); + box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP); + box->SetLabel("Icon"); + topView->AddChild(box); + + rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f); + rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f); + if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f) + rect.top = fontHeight.ascent + fontHeight.descent + 4.0f; + fIconView = new IconView(rect, "icon"); + box->AddChild(fIconView); // "Preferred Application" group @@ -160,8 +152,8 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) box->AddChild(fSameAppAsButton); ResizeTo(fSameAppAsButton->Frame().right + 100.0f, box->Frame().bottom + 8.0f); - SetSizeLimits(fSameAppAsButton->Frame().right + 24.0f, 32767.0f, Bounds().Height(), - Bounds().Height()); + SetSizeLimits(fSameAppAsButton->Frame().right + iconBoxWidth + 32.0f, 32767.0f, + Bounds().Height(), Bounds().Height()); fTypeControl->MakeFocus(true); @@ -259,10 +251,15 @@ FileTypeWindow::_SetTo(const BMessage& refs) fCommonPreferredApp = ""; } else fCommonPreferredApp = preferredApp; + + if (i == 0) + fIconView->SetTo(&ref); } fTypeControl->SetText(fCommonType.String()); _UpdatePreferredApps(); + + fIconView->ShowIconHeap(fEntries.CountItems() != 1); } diff --git a/src/preferences/filetypes/FileTypes.rdef b/src/preferences/filetypes/FileTypes.rdef index 0d9ad76b33..3b5836b7e6 100644 --- a/src/preferences/filetypes/FileTypes.rdef +++ b/src/preferences/filetypes/FileTypes.rdef @@ -79,3 +79,38 @@ resource large_icon array { $"FFFFFFFF002B2F000E0F0F0F0F0F0F0F0F0000ACD5000E0E0EFFFFFFFFFFFFFF" $"FFFFFFFF0000000E0F0F0F0F0F0F0F0F0F0F0F00000E0E0EFFFFFFFFFFFFFFFF" }; + +resource(200, "icon heap") #'ICON' array { + $"FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF0060600000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF0060606060600000FFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFF00603F603F603F603F0000FFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF00603F603F603F603F603F600000FFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFF00603F3F3F3F3F3F3F3F3F3F3F3F3F0000FFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFF00603F603F603F603F603F603F603F603F3F0000FFFFFFFFFFFF" + $"FFFFFFFFFF00603F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F0000FFFFFFFF" + $"FFFFFFFF00603F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F0000FFFF" + $"FFFFFF00603F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F603F00FF" + $"FFFF00603F603F603F603F603F603F603F603F603F603F603F603F603F00FFFF" + $"FF00603F603F603F603F603F603F603F603F603F603F603F603F603F00FFFFFF" + $"00003F603F603F603F603F603F603F603F603F603F603F603F603F000000FFFF" + $"FF000000603F603F603F603F603F603F603F603F603F603F603F00AE878700FF" + $"FF00870000006060606060606060606060606060606060606000AE87870100FF" + $"FF00008700AE00006060606060606060606060606060606000AE8700008700FF" + $"FF0087008700AEAE00006087608760876087608760876029AE000087870000FF" + $"FF00008700870087AEAE000087878787878787878787010000878700008700FF" + $"FF008700870087008787AEAE00008787878787878701008787000087870100FF" + $"FFAE00870087008700608787AEAE0000AEAEAEAE0087870000878700008700AE" + $"FFFFAE0087008700600060608787AEAE0000AE008700008787000087870100AE" + $"FFFFFFAE00870060006000606060870000870000008787000087870000AEAEFF" + $"FFFFFFFFAE00600060006000600000878700008787000087870000AEAEFFFFFF" + $"FFFFFFFFFFAE00600060006000606000008787000087870000AEAEFFFFFFFFFF" + $"FFFFFFFFFFFFAE00600060006000006087000087870000AEAEFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFAE00600060006060000087870000AEAEFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFAE00600060000060600000AEAEFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFAE00600060600000AEAEFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFAE00600000AEAEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFAE00AEAEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFAEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" +}; diff --git a/src/preferences/filetypes/FileTypesWindow.cpp b/src/preferences/filetypes/FileTypesWindow.cpp index b0bd799262..0a9e2597f0 100644 --- a/src/preferences/filetypes/FileTypesWindow.cpp +++ b/src/preferences/filetypes/FileTypesWindow.cpp @@ -59,10 +59,10 @@ const uint32 kMsgDescriptionEntered = 'dsce'; const uint32 kMsgToggleIcons = 'tgic'; -class IconView : public BControl { +class TypeIconView : public BControl { public: - IconView(BRect frame, const char* name, BMessage* message); - virtual ~IconView(); + TypeIconView(BRect frame, const char* name, BMessage* message); + virtual ~TypeIconView(); void SetTo(BMimeType* type); @@ -114,7 +114,7 @@ error_alert(const char* message, status_t status, alert_type type) // #pragma mark - -IconView::IconView(BRect frame, const char* name, BMessage* message) +TypeIconView::TypeIconView(BRect frame, const char* name, BMessage* message) : BControl(frame, name, NULL, message, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW), fIcon(NULL), @@ -123,14 +123,14 @@ IconView::IconView(BRect frame, const char* name, BMessage* message) } -IconView::~IconView() +TypeIconView::~TypeIconView() { delete fIcon; } void -IconView::SetTo(BMimeType* type) +TypeIconView::SetTo(BMimeType* type) { int32 sourceWas = fIconSource; fIconSource = kNoIcon; @@ -155,7 +155,7 @@ IconView::SetTo(BMimeType* type) void -IconView::Draw(BRect updateRect) +TypeIconView::Draw(BRect updateRect) { SetHighColor(ViewColor()); FillRect(updateRect); @@ -205,7 +205,7 @@ IconView::Draw(BRect updateRect) void -IconView::GetPreferredSize(float* _width, float* _height) +TypeIconView::GetPreferredSize(float* _width, float* _height) { if (_width) { float a = StringWidth("(from application)"); @@ -311,7 +311,7 @@ FileTypesWindow::FileTypesWindow(BRect frame) font.GetHeight(&fontHeight); BRect innerRect; - fIconView = new IconView(innerRect, "icon box", NULL); + fIconView = new TypeIconView(innerRect, "icon", NULL); fIconView->ResizeToPreferred(); rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; diff --git a/src/preferences/filetypes/FileTypesWindow.h b/src/preferences/filetypes/FileTypesWindow.h index 7c88d12c9a..1004ebc3f8 100644 --- a/src/preferences/filetypes/FileTypesWindow.h +++ b/src/preferences/filetypes/FileTypesWindow.h @@ -18,7 +18,7 @@ class BOutlineListView; class BTextControl; class AttributeListView; -class IconView; +class TypeIconView; class MimeTypeListView; class StringView; @@ -46,7 +46,7 @@ class FileTypesWindow : public BWindow { MimeTypeListView* fTypeListView; BButton* fRemoveTypeButton; - IconView* fIconView; + TypeIconView* fIconView; BListView* fExtensionListView; BButton* fAddExtensionButton; diff --git a/src/preferences/filetypes/IconView.cpp b/src/preferences/filetypes/IconView.cpp new file mode 100644 index 0000000000..8163e95cde --- /dev/null +++ b/src/preferences/filetypes/IconView.cpp @@ -0,0 +1,123 @@ +/* + * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include "IconView.h" + +#include +#include +#include +#include +#include +#include +#include + + +IconView::IconView(BRect rect, const char* name) + : BView(rect, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW), + fIcon(NULL), + fHeapIcon(NULL) +{ +} + + +IconView::~IconView() +{ +} + + +void +IconView::AttachedToWindow() +{ + if (Parent()) + SetViewColor(Parent()->ViewColor()); + else + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + +void +IconView::Draw(BRect updateRect) +{ + SetDrawingMode(B_OP_ALPHA); + + if (fHeapIcon != NULL) + DrawBitmap(fHeapIcon, BPoint(0.0f, 0.0f)); + else if (fIcon != NULL) + DrawBitmap(fIcon, BPoint(0.0f, 0.0f)); +} + + + +void +IconView::MouseDown(BPoint where) +{ + int32 buttons = B_PRIMARY_MOUSE_BUTTON; + if (Looper() != NULL && Looper()->CurrentMessage() != NULL) + Looper()->CurrentMessage()->FindInt32("buttons", &buttons); + + if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) { + // show context menu + + ConvertToScreen(&where); + + BPopUpMenu* menu = new BPopUpMenu("context"); + menu->SetFont(be_plain_font); + BMenuItem* item; + menu->AddItem(item = new BMenuItem("Edit Icon" B_UTF8_ELLIPSIS, NULL)); + item->SetEnabled(false); + menu->AddItem(item = new BMenuItem("Remove Icon", NULL)); + item->SetEnabled(false); + + menu->Go(where); + } +} + + +void +IconView::SetTo(entry_ref* file) +{ + delete fIcon; + fIcon = NULL; + + BNode node(file); + BNodeInfo info(&node); + if (node.InitCheck() != B_OK + || info.InitCheck() != B_OK) + return; + + BBitmap* icon = new BBitmap(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_CMAP8); + if (info.GetIcon(icon, B_LARGE_ICON) != B_OK) { + delete icon; + return; + } + + fIcon = icon; + Invalidate(); +} + + +void +IconView::ShowIconHeap(bool show) +{ + if (show == (fHeapIcon != NULL)) + return; + + if (show) { + BResources* resources = be_app->AppResources(); + const void* data = NULL; + if (resources != NULL) + data = resources->LoadResource('ICON', "icon heap", NULL); + if (data != NULL) { + fHeapIcon = new BBitmap(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), + B_CMAP8); + memcpy(fHeapIcon->Bits(), data, fHeapIcon->BitsLength()); + } + } else { + delete fHeapIcon; + fHeapIcon = NULL; + } +} + diff --git a/src/preferences/filetypes/IconView.h b/src/preferences/filetypes/IconView.h new file mode 100644 index 0000000000..3caa61d2d9 --- /dev/null +++ b/src/preferences/filetypes/IconView.h @@ -0,0 +1,30 @@ +/* + * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef ICON_VIEW_H +#define ICON_VIEW_H + + +#include + + +class IconView : public BView { + public: + IconView(BRect rect, const char* name); + virtual ~IconView(); + + virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + + virtual void MouseDown(BPoint where); + + void SetTo(entry_ref* file); + void ShowIconHeap(bool show); + + private: + BBitmap* fIcon; + BBitmap* fHeapIcon; +}; + +#endif // ICON_VIEW_H diff --git a/src/preferences/filetypes/Jamfile b/src/preferences/filetypes/Jamfile index 2f33e359b5..3e29e31af2 100644 --- a/src/preferences/filetypes/Jamfile +++ b/src/preferences/filetypes/Jamfile @@ -16,6 +16,7 @@ Preference FileTypes : AttributeWindow.cpp ExtensionWindow.cpp FileTypeWindow.cpp + IconView.cpp PreferredAppMenu.cpp StringView.cpp : be tracker