1/*
2 * Copyright 2014, Stephan A��mus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6
7#include "LinkedBitmapView.h"
8
9#include <Cursor.h>
10
11
12LinkedBitmapView::LinkedBitmapView(const char* name, BMessage* message)
13	:
14	BitmapView(name),
15	BInvoker(message, NULL),
16	fEnabled(true),
17	fMouseInside(false)
18{
19}
20
21
22void
23LinkedBitmapView::AllAttached()
24{
25	//  We don't want to use BitmapView's default behavior here.
26}
27
28
29void
30LinkedBitmapView::MouseMoved(BPoint where, uint32 transit,
31	const BMessage* dragMessage)
32{
33	// TODO: Check that no buttons are pressed, don't indicate clickable
34	// link if a button is held.
35	if (transit == B_ENTERED_VIEW) {
36		fMouseInside = true;
37		_UpdateViewCursor();
38	} else if (transit == B_EXITED_VIEW) {
39		fMouseInside = false;
40		_UpdateViewCursor();
41	}
42}
43
44
45void
46LinkedBitmapView::MouseDown(BPoint where)
47{
48	if (fEnabled)
49		Invoke(Message());
50}
51
52
53void
54LinkedBitmapView::SetEnabled(bool enabled)
55{
56	if (fEnabled != enabled) {
57		fEnabled = enabled;
58		_UpdateViewCursor();
59	}
60}
61
62
63void
64LinkedBitmapView::_UpdateViewCursor()
65{
66	if (fEnabled && fMouseInside) {
67		BCursor cursor(B_CURSOR_ID_FOLLOW_LINK);
68		SetViewCursor(&cursor, true);
69	} else {
70		BCursor cursor(B_CURSOR_SYSTEM_DEFAULT);
71		SetViewCursor(&cursor, true);
72	}
73}
74