2 * Copyright 2003-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
8 * Axel Dörfler, axeld@pinc-software.de.
12 #include "VolumeWindow.h"
15 #include <GroupLayout.h>
16 #include <MessageRunner.h>
19 #include "VolumeControl.h"
22 static const uint32 kMsgVolumeUpdate
= 'vlup';
23 static const uint32 kMsgVolumeChanged
= 'vlcg';
26 VolumeWindow::VolumeWindow(BRect frame
, bool dontBeep
, int32 volumeWhich
)
27 : BWindow(frame
, "VolumeWindow", B_BORDERED_WINDOW_LOOK
,
28 B_FLOATING_ALL_WINDOW_FEEL
,
29 B_ASYNCHRONOUS_CONTROLS
| B_WILL_ACCEPT_FIRST_CLICK
30 | B_AUTO_UPDATE_SIZE_LIMITS
, 0),
33 SetLayout(new BGroupLayout(B_HORIZONTAL
));
35 BGroupLayout
* layout
= new BGroupLayout(B_HORIZONTAL
);
36 layout
->SetInsets(5, 5, 5, 5);
38 BBox
* box
= new BBox("sliderbox");
39 box
->SetLayout(layout
);
40 box
->SetBorder(B_PLAIN_BORDER
);
43 BSlider
* slider
= new VolumeControl(volumeWhich
, !dontBeep
,
44 new BMessage(kMsgVolumeChanged
));
45 slider
->SetModificationMessage(new BMessage(kMsgVolumeUpdate
));
46 box
->AddChild(slider
);
48 slider
->SetTarget(this);
51 // Make sure it's not outside the screen.
52 const int32 kMargin
= 3;
53 BRect windowRect
= Frame();
54 BRect
screenFrame(BScreen(B_MAIN_SCREEN_ID
).Frame());
55 if (screenFrame
.right
< windowRect
.right
+ kMargin
)
56 MoveBy(- kMargin
- windowRect
.right
+ screenFrame
.right
, 0);
57 if (screenFrame
.bottom
< windowRect
.bottom
+ kMargin
)
58 MoveBy(0, - kMargin
- windowRect
.bottom
+ screenFrame
.bottom
);
59 if (screenFrame
.left
> windowRect
.left
- kMargin
)
60 MoveBy(kMargin
+ screenFrame
.left
- windowRect
.left
, 0);
61 if (screenFrame
.top
> windowRect
.top
- kMargin
)
62 MoveBy(0, kMargin
+ screenFrame
.top
- windowRect
.top
);
66 VolumeWindow::~VolumeWindow()
72 VolumeWindow::MessageReceived(BMessage
*msg
)
75 case kMsgVolumeUpdate
:
79 case kMsgVolumeChanged
:
80 if (fUpdatedCount
< 2) {
81 // If the slider was set by click only, wait a bit until
82 // closing the window to give some feedback that how volume
83 // was changed, and that it is.
84 BMessage
quit(B_QUIT_REQUESTED
);
85 BMessageRunner::StartSending(this, &quit
, 150000, 1);
90 case B_QUIT_REQUESTED
:
95 BWindow::MessageReceived(msg
);