xref: /haiku/src/apps/haikudepot/ui_generic/LinkedBitmapView.cpp (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 
12 LinkedBitmapView::LinkedBitmapView(const char* name, BMessage* message)
13 	:
14 	BitmapView(name),
15 	BInvoker(message, NULL),
16 	fEnabled(true),
17 	fMouseInside(false)
18 {
19 }
20 
21 
22 void
23 LinkedBitmapView::AllAttached()
24 {
25 	//  We don't want to use BitmapView's default behavior here.
26 }
27 
28 
29 void
30 LinkedBitmapView::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 
45 void
46 LinkedBitmapView::MouseDown(BPoint where)
47 {
48 	if (fEnabled)
49 		Invoke(Message());
50 }
51 
52 
53 void
54 LinkedBitmapView::SetEnabled(bool enabled)
55 {
56 	if (fEnabled != enabled) {
57 		fEnabled = enabled;
58 		_UpdateViewCursor();
59 	}
60 }
61 
62 
63 void
64 LinkedBitmapView::_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