RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / desklink / VolumeWindow.cpp
blobf1c8b52c31597c2e969721ef9142a208c05593ec
1 /*
2 * Copyright 2003-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Jérôme Duval
7 * François Revol
8 * Axel Dörfler, axeld@pinc-software.de.
9 */
12 #include "VolumeWindow.h"
14 #include <Box.h>
15 #include <GroupLayout.h>
16 #include <MessageRunner.h>
17 #include <Screen.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),
31 fUpdatedCount(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);
41 AddChild(box);
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);
49 ResizeTo(300, 50);
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()
71 void
72 VolumeWindow::MessageReceived(BMessage *msg)
74 switch (msg->what) {
75 case kMsgVolumeUpdate:
76 fUpdatedCount++;
77 break;
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);
86 } else
87 Quit();
88 break;
90 case B_QUIT_REQUESTED:
91 Quit();
92 break;
94 default:
95 BWindow::MessageReceived(msg);
96 break;