diff --git a/src/apps/haikudepot/ui_generic/LinkedBitmapView.cpp b/src/apps/haikudepot/ui_generic/LinkedBitmapView.cpp new file mode 100644 index 0000000000..50eaccdcbe --- /dev/null +++ b/src/apps/haikudepot/ui_generic/LinkedBitmapView.cpp @@ -0,0 +1,66 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include "LinkedBitmapView.h" + +#include + + +LinkedBitmapView::LinkedBitmapView(const char* name, BMessage* message) + : + BitmapView(name), + BInvoker(message, NULL), + fEnabled(true), + fMouseInside(false) +{ +} + + +void +LinkedBitmapView::MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage) +{ + // TODO: Check that no buttons are pressed, don't indicate clickable + // link if a button is held. + if (transit == B_ENTERED_VIEW) { + fMouseInside = true; + _UpdateViewCursor(); + } else if (transit == B_EXITED_VIEW) { + fMouseInside = false; + _UpdateViewCursor(); + } +} + + +void +LinkedBitmapView::MouseDown(BPoint where) +{ + if (fEnabled) + Invoke(Message()); +} + + +void +LinkedBitmapView::SetEnabled(bool enabled) +{ + if (fEnabled != enabled) { + fEnabled = enabled; + _UpdateViewCursor(); + } +} + + +void +LinkedBitmapView::_UpdateViewCursor() +{ + if (fEnabled && fMouseInside) { + BCursor cursor(B_CURSOR_ID_FOLLOW_LINK); + SetViewCursor(&cursor, true); + } else { + BCursor cursor(B_CURSOR_SYSTEM_DEFAULT); + SetViewCursor(&cursor, true); + } +} diff --git a/src/apps/haikudepot/ui_generic/LinkedBitmapView.h b/src/apps/haikudepot/ui_generic/LinkedBitmapView.h new file mode 100644 index 0000000000..5d4c62f0c5 --- /dev/null +++ b/src/apps/haikudepot/ui_generic/LinkedBitmapView.h @@ -0,0 +1,34 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef LINKED_BITMAP_VIEW_H +#define LINKED_BITMAP_VIEW_H + + +#include + +#include "BitmapView.h" + + +class LinkedBitmapView : public BitmapView, public BInvoker { +public: + LinkedBitmapView(const char* name, + BMessage* message); + + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); + virtual void MouseDown(BPoint where); + + void SetEnabled(bool enabled); + +private: + void _UpdateViewCursor(); + +private: + bool fEnabled; + bool fMouseInside; +}; + + +#endif // LINKED_BITMAP_VIEW_H