Show small icons in recent document menu.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5444 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -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 <Node.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -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 <Bitmap.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -10,6 +10,7 @@ App ShowImage : ShowImageApp.cpp
|
|||||||
ShowImageWindow.cpp
|
ShowImageWindow.cpp
|
||||||
PrintOptionsWindow.cpp
|
PrintOptionsWindow.cpp
|
||||||
Filter.cpp
|
Filter.cpp
|
||||||
|
EntryMenuItem.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs ShowImage : be tracker translation ;
|
LinkSharedOSLibs ShowImage : be tracker translation ;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#include <algobase.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -52,6 +51,7 @@
|
|||||||
#include "ShowImageWindow.h"
|
#include "ShowImageWindow.h"
|
||||||
#include "ShowImageView.h"
|
#include "ShowImageView.h"
|
||||||
#include "ShowImageStatusView.h"
|
#include "ShowImageStatusView.h"
|
||||||
|
#include "EntryMenuItem.h"
|
||||||
|
|
||||||
ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
ShowImageWindow::ShowImageWindow(const entry_ref *pref)
|
||||||
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
: BWindow(BRect(50, 50, 350, 250), "", B_DOCUMENT_WINDOW, 0)
|
||||||
@@ -180,10 +180,10 @@ ShowImageWindow::UpdateRecentDocumentsMenu()
|
|||||||
be_roster->GetRecentDocuments(&list, 20, NULL, APP_SIG);
|
be_roster->GetRecentDocuments(&list, 20, NULL, APP_SIG);
|
||||||
for (int i = 0; list.FindRef("refs", i, &ref) == B_OK; i++) {
|
for (int i = 0; list.FindRef("refs", i, &ref) == B_OK; i++) {
|
||||||
BEntry entry(&ref);
|
BEntry entry(&ref);
|
||||||
if (entry.GetName(name) == B_OK) {
|
if (entry.Exists() && entry.GetName(name) == B_OK) {
|
||||||
msg = new BMessage(B_REFS_RECEIVED);
|
msg = new BMessage(B_REFS_RECEIVED);
|
||||||
msg->AddRef("refs", &ref);
|
msg->AddRef("refs", &ref);
|
||||||
item = new BMenuItem(name, msg, 0, 0);
|
item = new EntryMenuItem(&ref, name, msg, 0, 0);
|
||||||
fOpenMenu->AddItem(item);
|
fOpenMenu->AddItem(item);
|
||||||
item->SetTarget(be_app, NULL);
|
item->SetTarget(be_app, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user