From 7c0bc4a231a41154fddf60a1f2e98e40a232d050 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Sat, 22 Nov 2003 19:52:31 +0000 Subject: [PATCH] Show small icons in recent document menu. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5444 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/EntryMenuItem.cpp | 117 +++++++++++++++++++++++++ src/apps/showimage/EntryMenuItem.h | 59 +++++++++++++ src/apps/showimage/Jamfile | 1 + src/apps/showimage/ShowImageWindow.cpp | 6 +- src/apps/showimage/ShowImageX.proj | Bin 15009 -> 15313 bytes 5 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 src/apps/showimage/EntryMenuItem.cpp create mode 100644 src/apps/showimage/EntryMenuItem.h diff --git a/src/apps/showimage/EntryMenuItem.cpp b/src/apps/showimage/EntryMenuItem.cpp new file mode 100644 index 0000000000..b2f1d0e8b8 --- /dev/null +++ b/src/apps/showimage/EntryMenuItem.cpp @@ -0,0 +1,117 @@ +/*****************************************************************************/ +// EntryMenuItem +// Written by Michael Pfeiffer +// +// EntryMenuItem.cpp +// +// +// Copyright (c) 2003 OpenBeOS Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ + +#include +#include + +#include "EntryMenuItem.h" + +EntryMenuItem::EntryMenuItem(entry_ref* ref, const char* label, BMessage* message, char shortcut, uint32 modifiers) + : BMenuItem(label, message, shortcut, modifiers) + , fEntry(*ref) + , fSmallIcon(NULL) +{ +} + +EntryMenuItem::~EntryMenuItem() +{ + delete fSmallIcon; +} + +void +EntryMenuItem::GetContentSize(float* width, float* height) +{ + BMenuItem::GetContentSize(width, height); + *width += kTextIndent; + if (*height < kIconSize) { + *height = kIconSize; + } +} + +void +EntryMenuItem::DrawContent() +{ + BView* view = Menu(); + BPoint pos(view->PenLocation()); + + if (fSmallIcon == NULL) { + fSmallIcon = LoadIcon(); // load on demand + } + + view->MovePenBy(kTextIndent, 0); + BMenuItem::DrawContent(); + + if (fSmallIcon) { + view->SetDrawingMode(B_OP_OVER); + view->DrawBitmap(fSmallIcon, pos); + } +} + +BBitmap* +EntryMenuItem::GetIcon(BMimeType* mimeType) +{ + BBitmap* icon; + icon = new BBitmap(BRect(0, 0, kIconSize-1, kIconSize-1), B_CMAP8); + if (mimeType->GetIcon(icon, B_MINI_ICON) != B_OK) { + delete icon; icon = NULL; + } + return icon; +} + +BBitmap* +EntryMenuItem::LoadIcon() +{ + BBitmap* icon = NULL; + BNode node(&fEntry); + BNodeInfo info(&node); + char type[B_MIME_TYPE_LENGTH+1]; + + // Note: BNodeInfo::GetTrackerIcon does not work as expected! + + // try to get the icon stored in file attribute + icon = new BBitmap(BRect(0, 0, kIconSize-1, kIconSize-1), B_CMAP8); + if (info.GetIcon(icon, B_MINI_ICON) == B_OK) { + return icon; + } + delete icon; icon = NULL; + + // get the icon from type + if (info.GetType(type) == B_OK) { + BMimeType mimeType(type); + BMimeType superType; + if (mimeType.InitCheck() == B_OK) { + icon = GetIcon(&mimeType); + // or super type + if (icon == NULL && mimeType.GetSupertype(&superType) == B_OK) { + icon = GetIcon(&superType); + } + } + } + + return icon; +} diff --git a/src/apps/showimage/EntryMenuItem.h b/src/apps/showimage/EntryMenuItem.h new file mode 100644 index 0000000000..07f66a697c --- /dev/null +++ b/src/apps/showimage/EntryMenuItem.h @@ -0,0 +1,59 @@ +/*****************************************************************************/ +// EntryMenuItem +// Written by Michael Pfeiffer +// +// EntryMenuItem.h +// +// +// Copyright (c) 2003 OpenBeOS Project +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +/*****************************************************************************/ + +#ifndef _EntryMenuItem_h +#define _EntryMenuItem_h + +#include +#include +#include +#include + +class EntryMenuItem : public BMenuItem +{ +public: + EntryMenuItem(entry_ref* entry, const char* label, BMessage* message, char shortcut = 0, uint32 modifiers = 0); + ~EntryMenuItem(); + + void GetContentSize(float* width, float* height); + void DrawContent(); + +private: + enum { + kIconSize = 16, + kTextIndent = kIconSize + 4, + }; + + BBitmap* GetIcon(BMimeType* mimeType); + BBitmap* LoadIcon(); + + entry_ref fEntry; + BBitmap* fSmallIcon; +}; + +#endif diff --git a/src/apps/showimage/Jamfile b/src/apps/showimage/Jamfile index cb229272bd..7506214a9a 100644 --- a/src/apps/showimage/Jamfile +++ b/src/apps/showimage/Jamfile @@ -10,6 +10,7 @@ App ShowImage : ShowImageApp.cpp ShowImageWindow.cpp PrintOptionsWindow.cpp Filter.cpp + EntryMenuItem.cpp ; LinkSharedOSLibs ShowImage : be tracker translation ; diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index b6cce699eb..8a4f5fd12f 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -26,7 +26,6 @@ // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ -#include #include #include #include @@ -52,6 +51,7 @@ #include "ShowImageWindow.h" #include "ShowImageView.h" #include "ShowImageStatusView.h" +#include "EntryMenuItem.h" ShowImageWindow::ShowImageWindow(const entry_ref *pref) : BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0) @@ -180,10 +180,10 @@ ShowImageWindow::UpdateRecentDocumentsMenu() be_roster->GetRecentDocuments(&list, 20, NULL, APP_SIG); for (int i = 0; list.FindRef("refs", i, &ref) == B_OK; i++) { BEntry entry(&ref); - if (entry.GetName(name) == B_OK) { + if (entry.Exists() && entry.GetName(name) == B_OK) { msg = new BMessage(B_REFS_RECEIVED); msg->AddRef("refs", &ref); - item = new BMenuItem(name, msg, 0, 0); + item = new EntryMenuItem(&ref, name, msg, 0, 0); fOpenMenu->AddItem(item); item->SetTarget(be_app, NULL); } diff --git a/src/apps/showimage/ShowImageX.proj b/src/apps/showimage/ShowImageX.proj index 68e1110c7f1973e422e0d8f3fd17af7b8d8e5272..791c0caf58371f049da2758697468ab94bed4963 100644 GIT binary patch delta 505 zcmZ2jda<0t*VDz7fx-IZMvfh9EFLrD8zu{|J8WiQ-=g9n!~g}1!TF^{$*Br%nK`M& z4B`z5iaLK?0*cbsYC{zKkk|QpIhVJA1th*hy`kl{IG7ER?NHE}q@%>V-#K`)fq~j) zZ=FU)DJDh+2B%1%WB?Fzf>bpCvHku%e?V#`^XM5&b~YB}cg-s)s`O3GEA=c%&DG18 ze8BM4W;uO+MxbGln+*)~8AV-y+CXNo12NPL=P0l}vkY%Aipd-Si30)9KDc}=*p79^ z$AHGff!T9S-on|NO)pALWME+34b-54s&kJvSoJJJQ4v&^B^MMh1Q$)VGnV2-k(m6; zC=N}e%1i-hRXorj>&Z9F?wOGkj(@Fzo(S;C%bsK^&I$~!y$q8%EXs9BGGp@^i?56T DFV>c9 delta 402 zcmcauzOa%$(F> z2JwajMVY@Y0YzzRwIK?A$jkh_oXgw50u8CnWUq{yxZgJWCKIB z&E7hVj8cqO85o=@fsz$K%mGr>0L1pYJ;gz4CO4R|O%~GA+MJ>HkrAlzCs^>ax#;BS z246%~fGPukm>r0r+B|-3USRl-QA~6SNDK%VK|})(+way~3)X$h_!#r9PDe2Nq{&<6 z-KICd?E9t{CvPzq1KRQzYRhLUlKl498fa61PhK|Aw#>t<8