Ejemplo n.º 1
0
void PrinterSelectionView::MessageReceived(BMessage* msg)
{
	int32 index;
	switch (msg->what) {
		case 'sel': 
			if (msg->FindInt32("index", &index) == B_OK) {
				FileItem* file = (FileItem*)fVendors->ItemAt(index);
				if (file != NULL) {
					FillPrinters(file->GetFile());
				}
			}
			break;
		case 'prnt': 
			if (msg->FindInt32("index", &index) == B_OK) {
				FileItem* file = (FileItem*)fPrinters->ItemAt(index);
				if (file != NULL) {
					BMessage copy(*Message());
					copy.AddString("file", file->GetFile());
					InvokeNotify(&copy);
				}
			}
			break;
	}
	BView::MessageReceived(msg);
}
Ejemplo n.º 2
0
void
BListView::Select(int32 index, bool extend)
{
	if (_Select(index, extend)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 3
0
void
BListView::DeselectAll()
{
	if (_DeselectAll(-1, -1)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 4
0
void
BListView::Select(int32 start, int32 finish, bool extend)
{
	if (_Select(start, finish, extend)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 5
0
void
BListView::Deselect(int32 index)
{
	if (_Deselect(index)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 6
0
void
BButton::MouseDown(BPoint point)
{
	if (!IsEnabled())
		return;

	if (fBehavior == B_POP_UP_BEHAVIOR && _PopUpRect().Contains(point)) {
		InvokeNotify(fPopUpMessage, B_CONTROL_MODIFIED);
		return;
	}

	bool toggleBehavior = fBehavior == B_TOGGLE_BEHAVIOR;

	if (toggleBehavior) {
		bool wasPressed = Value() == B_CONTROL_ON;
		_SetFlag(FLAG_WAS_PRESSED, wasPressed);
		SetValue(wasPressed ? B_CONTROL_OFF : B_CONTROL_ON);
		Invalidate();
	} else
		SetValue(B_CONTROL_ON);

	if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
 		SetTracking(true);
 		SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
 	} else {
		BRect bounds = Bounds();
		uint32 buttons;
		bool inside = false;

		do {
			Window()->UpdateIfNeeded();
			snooze(40000);

			GetMouse(&point, &buttons, true);

 			inside = bounds.Contains(point);

			if (toggleBehavior) {
				bool pressed = inside ^ _Flag(FLAG_WAS_PRESSED);
				SetValue(pressed ? B_CONTROL_ON : B_CONTROL_OFF);
			} else {
				if ((Value() == B_CONTROL_ON) != inside)
					SetValue(inside ? B_CONTROL_ON : B_CONTROL_OFF);
			}
		} while (buttons != 0);

		if (inside) {
			if (toggleBehavior) {
				SetValue(
					_Flag(FLAG_WAS_PRESSED) ? B_CONTROL_OFF : B_CONTROL_ON);
			}

			Invoke();
		} else if (_Flag(FLAG_FLAT))
			Invalidate();
	}
}
Ejemplo n.º 7
0
void
BSlider::MouseDown(BPoint point)
{
	if (!IsEnabled())
		return;

	if (BarFrame().Contains(point) || ThumbFrame().Contains(point))
		fInitialLocation = _Location();

	uint32 buttons;
	GetMouse(&point, &buttons, true);

	_ConstrainPoint(point, fInitialLocation);
	SetValue(ValueForPoint(point));

	if (_Location() != fInitialLocation)
		InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);

	if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
		SetTracking(true);
		SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY);
	} else {
		// synchronous mouse tracking
		BPoint prevPoint;

		while (buttons) {
			prevPoint = point;

			snooze(SnoozeAmount());
			GetMouse(&point, &buttons, true);

			if (_ConstrainPoint(point, prevPoint)) {
				int32 value = ValueForPoint(point);
				if (value != Value()) {
					SetValue(value);
					InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
				}
			}
		}
		if (_Location() != fInitialLocation)
			Invoke();
	}
}
Ejemplo n.º 8
0
void
BListView::DeselectExcept(int32 exceptFrom, int32 exceptTo)
{
	if (exceptFrom > exceptTo || exceptFrom < 0 || exceptTo < 0)
		return;

	if (_DeselectAll(exceptFrom, exceptTo)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 9
0
void
BListView::SortItems(int (*cmp)(const void *, const void *))
{
	if (_DeselectAll(-1, -1)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}

	fList.SortItems(cmp);
	_RecalcItemTops(0);
	Invalidate();
}
Ejemplo n.º 10
0
void
RadioButtonGroup::_SelectionChanged()
{
	// send the message
	if (Message()) {
		BMessage message(*Message());
		message.AddPointer("button group", this);
		message.AddPointer("selected button", fSelected);
		message.AddInt32("selected index", SelectedIndex());
		InvokeNotify(&message);
	}
}
Ejemplo n.º 11
0
void DrumsetDropField::MessageReceived( BMessage *message ) {
	
	if (!message || message->what!='PecM') return;
	
	int8	key;
	message->FindInt8("key", &key);

	SetValue(key);
	InvokeNotify(Message());
	
	SetValue(0);

}
Ejemplo n.º 12
0
void
BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{
	if (IsTracking()) {
		if (_ConstrainPoint(point, _Location())) {
			int32 value = ValueForPoint(point);
			if (value != Value()) {
				SetValue(value);
				InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
			}
		}
	} else
		BControl::MouseMoved(point, transit, message);
}
Ejemplo n.º 13
0
void
BSlider::KeyDown(const char *bytes, int32 numBytes)
{
	if (!IsEnabled() || IsHidden())
		return;

	int32 newValue = Value();

	switch (bytes[0]) {
		case B_LEFT_ARROW:
		case B_DOWN_ARROW:
			newValue -= KeyIncrementValue();
			break;

		case B_RIGHT_ARROW:
		case B_UP_ARROW:
			newValue += KeyIncrementValue();
			break;

		case B_HOME:
			newValue = fMinValue;
			break;
		case B_END:
			newValue = fMaxValue;
			break;

		default:
			BControl::KeyDown(bytes, numBytes);
			return;
	}

	if (newValue < fMinValue)
		newValue = fMinValue;
	if (newValue > fMaxValue)
		newValue = fMaxValue;

	if (newValue != Value()) {
		fInitialLocation = _Location();
		SetValue(newValue);
		InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 14
0
void
BIconRule::SlideToIcon(int32 index)
{
	BIconItem* item = fIcons.ItemAt(index);
	if (item) {
		// Deselect previously selected item
		if (fSelIndex > -1) {
			BIconItem* selItem = fIcons.ItemAt(fSelIndex);
			selItem->Deselect();
		}

		// Select this item
		item->Select();
		fSelIndex = index;
		Invalidate();

		// Invoke notification
		InvokeNotify(fMessage, B_CONTROL_MODIFIED);
	}
}
void
TwoDimensionalSliderView::SetValue(BPoint value)
{
	BPoint location = fMinLocation + value;
	if (location.x < fMinLocation.x)
		location.x = fMinLocation.x;
	if (location.y < fMinLocation.y)
		location.y = fMinLocation.y;
	if (location.x > fMaxLocation.x)
		location.x = fMaxLocation.x;
	if (location.y > fMaxLocation.y)
		location.y = fMaxLocation.y;

	if (location != Location()) {
		SetFrame(Frame().OffsetToCopy(location));

		// send the message
		if (Message()) {
			BMessage message(*Message());
			message.AddPoint("value", Value());
			InvokeNotify(&message);
		}
	}
}
Ejemplo n.º 16
0
void
VolumeControl::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case B_MOUSE_WHEEL_CHANGED:
		{
			if (!fMixerControl->Connected())
				return;

			// Even though the volume bar is horizontal, we use the more common
			// vertical mouse wheel change
			float deltaY = 0.0f;

			msg->FindFloat("be:wheel_delta_y", &deltaY);

			if (deltaY == 0.0f)
				return;

			int32 currentValue = Value();
			int32 newValue = currentValue - int32(deltaY) * 3;

			if (newValue != currentValue) {
				SetValue(newValue);
				InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
			}
			break;
		}

		case B_MEDIA_NEW_PARAMETER_VALUE:
			if (IsTracking())
				break;

			SetValue((int32)fMixerControl->Volume());
			break;

		case B_SOME_APP_LAUNCHED:
		case B_SOME_APP_QUIT:
		{
			const char* signature;
			if (msg->FindString("be:signature", &signature) != B_OK)
				break;

			bool isMediaServer = !strcmp(signature, kMediaServerSignature);
			bool isAddOnServer = !strcmp(signature, kAddOnServerSignature);
			if (!isMediaServer && !isAddOnServer)
				break;

			if (isMediaServer)
				fMediaServerRunning = msg->what == B_SOME_APP_LAUNCHED;
			if (isAddOnServer)
				fAddOnServerRunning = msg->what == B_SOME_APP_LAUNCHED;

			if (!fMediaServerRunning && !fAddOnServerRunning) {
				// No media server around
				SetLabel(B_TRANSLATE("No media server running"));
				SetEnabled(false);
			} else if (fMediaServerRunning && fAddOnServerRunning) {
				// HACK!
				// quit our now invalid instance of the media roster
				// so that before new nodes are created,
				// we get a new roster
				BMediaRoster* roster = BMediaRoster::CurrentRoster();
				if (roster != NULL) {
					roster->Lock();
					roster->Quit();
				}

				BMessage reconnect(kMsgReconnectVolume);
				BMessageRunner::StartSending(this, &reconnect, 1000000LL, 1);
				fConnectRetries = 3;
			}
			break;
		}

		case B_QUIT_REQUESTED:
			Window()->MessageReceived(msg);
			break;

		case kMsgReconnectVolume:
			_ConnectVolume();
			if (!fMixerControl->Connected() && --fConnectRetries > 1) {
				BMessage reconnect(kMsgReconnectVolume);
				BMessageRunner::StartSending(this, &reconnect,
					6000000LL / fConnectRetries, 1);
			}
			break;

		default:
			return BView::MessageReceived(msg);
	}
}
Ejemplo n.º 17
0
void
VolumeControl::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case B_MOUSE_WHEEL_CHANGED:
		{
			if (!fMixerControl->Connected())
				return;

			// Even though the volume bar is horizontal, we use the more common
			// vertical mouse wheel change
			float deltaY = 0.0f;

			msg->FindFloat("be:wheel_delta_y", &deltaY);

			if (deltaY == 0.0f)
				return;

			int32 currentValue = Value();
			int32 newValue = currentValue - int32(deltaY) * 3;

			if (newValue != currentValue) {
				SetValue(newValue);
				InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
			}
			break;
		}

		case B_MEDIA_NEW_PARAMETER_VALUE:
			if (IsTracking())
				break;

			SetValue((int32)fMixerControl->Volume());
			break;

		case B_MEDIA_SERVER_STARTED:
		{
			BMessage reconnect(kMsgReconnectVolume);
			BMessageRunner::StartSending(this, &reconnect, 1000000LL, 1);
			fConnectRetries = 3;
			break;
		}

		case B_MEDIA_SERVER_QUIT:
		{
			// No media server around
			SetLabel(B_TRANSLATE("No media server running"));
			SetEnabled(false);
			break;
		}

		case B_QUIT_REQUESTED:
			Window()->MessageReceived(msg);
			break;

		case kMsgReconnectVolume:
			_ConnectVolume();
			if (!fMixerControl->Connected() && --fConnectRetries > 1) {
				BMessage reconnect(kMsgReconnectVolume);
				BMessageRunner::StartSending(this, &reconnect,
					6000000LL / fConnectRetries, 1);
			}
			break;

		default:
			return BView::MessageReceived(msg);
	}
}