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::MouseMoved(BPoint where, uint32 transit, 24 const BMessage* dragMessage) 25 { 26 // TODO: Check that no buttons are pressed, don't indicate clickable 27 // link if a button is held. 28 if (transit == B_ENTERED_VIEW) { 29 fMouseInside = true; 30 _UpdateViewCursor(); 31 } else if (transit == B_EXITED_VIEW) { 32 fMouseInside = false; 33 _UpdateViewCursor(); 34 } 35 } 36 37 38 void 39 LinkedBitmapView::MouseDown(BPoint where) 40 { 41 if (fEnabled) 42 Invoke(Message()); 43 } 44 45 46 void 47 LinkedBitmapView::SetEnabled(bool enabled) 48 { 49 if (fEnabled != enabled) { 50 fEnabled = enabled; 51 _UpdateViewCursor(); 52 } 53 } 54 55 56 void 57 LinkedBitmapView::_UpdateViewCursor() 58 { 59 if (fEnabled && fMouseInside) { 60 BCursor cursor(B_CURSOR_ID_FOLLOW_LINK); 61 SetViewCursor(&cursor, true); 62 } else { 63 BCursor cursor(B_CURSOR_SYSTEM_DEFAULT); 64 SetViewCursor(&cursor, true); 65 } 66 } 67