xref: /haiku/src/apps/showimage/ShowImageStatusView.cpp (revision 03187b607b2b5eec7ee059f1ead09bdba14991fb)
1 /*
2  * Copyright 2003-2009 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  */
9 
10 #include "ShowImageStatusView.h"
11 
12 #include <Entry.h>
13 #include <MenuItem.h>
14 #include <Path.h>
15 #include <PopUpMenu.h>
16 
17 #include "ShowImageView.h"
18 #include "ShowImageWindow.h"
19 
20 
21 ShowImageStatusView::ShowImageStatusView(BRect rect, const char* name,
22 	uint32 resizingMode, uint32 flags)
23 	:
24 	BView(rect, name, resizingMode, flags)
25 {
26 	SetViewColor(B_TRANSPARENT_32_BIT);
27 	SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
28 	SetHighColor(0, 0, 0, 255);
29 
30 	BFont font;
31 	GetFont(&font);
32 	font.SetSize(10.0);
33 	SetFont(&font);
34 }
35 
36 
37 void
38 ShowImageStatusView::Draw(BRect updateRect)
39 {
40 	rgb_color darkShadow = tint_color(LowColor(), B_DARKEN_2_TINT);
41 	rgb_color shadow = tint_color(LowColor(), B_DARKEN_1_TINT);
42 	rgb_color light = tint_color(LowColor(), B_LIGHTEN_MAX_TINT);
43 
44 	BRect b(Bounds());
45 
46 	BeginLineArray(5);
47 		AddLine(BPoint(b.left, b.top),
48 				BPoint(b.right, b.top), darkShadow);
49 		b.top += 1.0;
50 		AddLine(BPoint(b.left, b.top),
51 				BPoint(b.right, b.top), light);
52 		AddLine(BPoint(b.right, b.top + 1.0),
53 				BPoint(b.right, b.bottom), shadow);
54 		AddLine(BPoint(b.right - 1.0, b.bottom),
55 				BPoint(b.left + 1.0, b.bottom), shadow);
56 		AddLine(BPoint(b.left, b.bottom),
57 				BPoint(b.left, b.top + 1.0), light);
58 	EndLineArray();
59 
60 	b.InsetBy(1.0, 1.0);
61 
62 	// Truncate and layout text
63 	BString truncated(fText);
64 	BFont font;
65 	GetFont(&font);
66 	font.TruncateString(&truncated, B_TRUNCATE_MIDDLE, b.Width() - 4.0);
67 	font_height fh;
68 	font.GetHeight(&fh);
69 
70 	FillRect(b, B_SOLID_LOW);
71 	SetDrawingMode(B_OP_OVER);
72 	DrawString(truncated.String(), BPoint(b.left + 2.0,
73 		floorf(b.top + b.Height() / 2.0 + fh.ascent / 2.0)));
74 }
75 
76 
77 void
78 ShowImageStatusView::MouseDown(BPoint where)
79 {
80 	ShowImageWindow *window = dynamic_cast<ShowImageWindow *>(Window());
81 	if (!window || window->GetShowImageView() == NULL)
82 		return;
83 
84 	BPath path;
85 	path.SetTo(window->GetShowImageView()->Image());
86 
87 	BPopUpMenu popup("no title");
88 	popup.SetFont(be_plain_font);
89 
90 	while (path.GetParent(&path) == B_OK && path != "/") {
91 		popup.AddItem(new BMenuItem(path.Leaf(), NULL));
92 	}
93 
94 	BRect bounds(Bounds());
95 	ConvertToScreen(&bounds);
96 	where = bounds.LeftBottom();
97 
98 	BMenuItem *item;
99 	item = popup.Go(where, true, false, ConvertToScreen(Bounds()));
100 
101 	if (item) {
102 		path.SetTo(window->GetShowImageView()->Image());
103 		path.GetParent(&path);
104 		int index = popup.IndexOf(item);
105 		while (index--)
106 			path.GetParent(&path);
107 		BMessenger tracker("application/x-vnd.Be-TRAK");
108 		BMessage msg(B_REFS_RECEIVED);
109 		entry_ref ref;
110 		get_ref_for_path(path.Path(), &ref);
111 		msg.AddRef("refs", &ref);
112 		tracker.SendMessage(&msg);
113 	}
114 }
115 
116 
117 void
118 ShowImageStatusView::SetText(BString &text)
119 {
120 	fText = text;
121 	Invalidate();
122 }
123 
124