xref: /haiku/src/apps/showimage/ShowImageStatusView.cpp (revision 83b1a68c52ba3e0e8796282759f694b7fdddf06d)
1 /*
2  * Copyright 2003-2010, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Fernando Francisco de Oliveira
7  *		Michael Wilber
8  *		Axel Dörfler, axeld@pinc-software.de
9  */
10 
11 
12 #include "ShowImageStatusView.h"
13 
14 #include <Entry.h>
15 #include <MenuItem.h>
16 #include <Path.h>
17 #include <PopUpMenu.h>
18 
19 #include <tracker_private.h>
20 #include "DirMenu.h"
21 
22 #include "ShowImageView.h"
23 #include "ShowImageWindow.h"
24 
25 
26 ShowImageStatusView::ShowImageStatusView(BRect rect, const char* name,
27 	uint32 resizingMode, uint32 flags)
28 	:
29 	BView(rect, name, resizingMode, flags)
30 {
31 	SetViewColor(B_TRANSPARENT_32_BIT);
32 	SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
33 	SetHighColor(0, 0, 0, 255);
34 
35 	BFont font;
36 	GetFont(&font);
37 	font.SetSize(10.0);
38 	SetFont(&font);
39 }
40 
41 
42 void
43 ShowImageStatusView::Draw(BRect updateRect)
44 {
45 	rgb_color darkShadow = tint_color(LowColor(), B_DARKEN_2_TINT);
46 	rgb_color shadow = tint_color(LowColor(), B_DARKEN_1_TINT);
47 	rgb_color light = tint_color(LowColor(), B_LIGHTEN_MAX_TINT);
48 
49 	BRect b(Bounds());
50 
51 	BeginLineArray(5);
52 		AddLine(BPoint(b.left, b.top),
53 				BPoint(b.right, b.top), darkShadow);
54 		b.top += 1.0;
55 		AddLine(BPoint(b.left, b.top),
56 				BPoint(b.right, b.top), light);
57 		AddLine(BPoint(b.right, b.top + 1.0),
58 				BPoint(b.right, b.bottom), shadow);
59 		AddLine(BPoint(b.right - 1.0, b.bottom),
60 				BPoint(b.left + 1.0, b.bottom), shadow);
61 		AddLine(BPoint(b.left, b.bottom),
62 				BPoint(b.left, b.top + 1.0), light);
63 	EndLineArray();
64 
65 	b.InsetBy(1.0, 1.0);
66 
67 	// Truncate and layout text
68 	BString truncated(fText);
69 	BFont font;
70 	GetFont(&font);
71 	font.TruncateString(&truncated, B_TRUNCATE_MIDDLE, b.Width() - 4.0);
72 	font_height fh;
73 	font.GetHeight(&fh);
74 
75 	FillRect(b, B_SOLID_LOW);
76 	SetDrawingMode(B_OP_OVER);
77 	DrawString(truncated.String(), BPoint(b.left + 2.0,
78 		floorf(b.top + b.Height() / 2.0 + fh.ascent / 2.0)));
79 }
80 
81 
82 void
83 ShowImageStatusView::MouseDown(BPoint where)
84 {
85 	BPrivate::BDirMenu* menu = new BDirMenu(NULL, BMessenger(kTrackerSignature),
86 		B_REFS_RECEIVED);
87 	BEntry entry;
88 	if (entry.SetTo(&fRef) == B_OK)
89 		menu->Populate(&entry, Window(), false, false, true, false, true);
90 	else
91 		menu->Populate(NULL, Window(), false, false, true, false, true);
92 
93 	BPoint point = Bounds().LeftBottom();
94 	point.y += 3;
95 	ConvertToScreen(&point);
96 	BRect clickToOpenRect(Bounds());
97 	ConvertToScreen(&clickToOpenRect);
98 	menu->Go(point, true, true, clickToOpenRect);
99 	delete menu;
100 }
101 
102 
103 void
104 ShowImageStatusView::Update(const entry_ref& ref, const BString& text)
105 {
106 	fText = text;
107 	fRef = ref;
108 
109 	Invalidate();
110 }
111 
112