repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / ui_generic / BitmapButton.cpp
blob11d9d6d7f4572fa0ccdd1807f5b3f793458613da
1 /*
2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
7 #include "BitmapButton.h"
9 #include <ControlLook.h>
10 #include <LayoutUtils.h>
11 #include <Window.h>
14 BitmapButton::BitmapButton(const char* name, BMessage* message)
16 BitmapView(name),
17 BInvoker(message, NULL, NULL),
18 fMouseInside(false),
19 fMouseDown(false)
21 SetScaleBitmap(false);
25 BitmapButton::~BitmapButton()
30 void
31 BitmapButton::AttachedToWindow()
33 // TODO: Init fMouseInside
34 BitmapView::AttachedToWindow();
37 void
38 BitmapButton::MouseMoved(BPoint where, uint32 transit,
39 const BMessage* dragMessage)
41 int32 buttons = 0;
42 if (Window() != NULL && Window()->CurrentMessage() != NULL)
43 Window()->CurrentMessage()->FindInt32("buttons", &buttons);
45 bool ignoreEvent = dragMessage != NULL || (!fMouseDown && buttons != 0);
47 _SetMouseInside(!ignoreEvent && transit == B_INSIDE_VIEW);
51 void
52 BitmapButton::MouseDown(BPoint where)
54 if (fMouseInside) {
55 _SetMouseDown(true);
56 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
61 void
62 BitmapButton::MouseUp(BPoint where)
64 _SetMouseDown(false);
65 if (fMouseInside)
66 Invoke();
70 BSize
71 BitmapButton::MinSize()
73 BSize size = BitmapView::MinSize();
74 size.width += 6;
75 size.height += 6;
76 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
80 BSize
81 BitmapButton::PreferredSize()
83 BSize size = MinSize();
84 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
88 BSize
89 BitmapButton::MaxSize()
91 BSize size = MinSize();
92 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
96 // #pragma mark -
99 void
100 BitmapButton::DrawBackground(BRect& bounds, BRect updateRect)
102 if (Message() != NULL && (fMouseInside || fMouseDown)) {
103 rgb_color color = LowColor();
104 uint32 flags = 0;
105 if (fMouseDown)
106 flags |= BControlLook::B_ACTIVATED;
108 be_control_look->DrawButtonFrame(this, bounds, updateRect,
109 color, color, flags);
110 be_control_look->DrawButtonBackground(this, bounds, updateRect,
111 color, flags);
112 } else {
113 BitmapView::DrawBackground(bounds, updateRect);
118 // #pragma mark -
121 void
122 BitmapButton::_SetMouseInside(bool inside)
124 if (fMouseInside == inside)
125 return;
127 fMouseInside = inside;
129 if (Message() != NULL)
130 Invalidate();
134 void
135 BitmapButton::_SetMouseDown(bool down)
137 if (fMouseDown == down)
138 return;
140 fMouseDown = down;
142 if (Message() != NULL)
143 Invalidate();