void
BluetoothSettingsView::_BuildClassMenu()
{
	
	BMessage* message = NULL;
	BMenuItem* item = NULL;

	fClassMenu = new BPopUpMenu(B_TRANSLATE("Identify us as..."));

	message = new BMessage(kMsgSetDeviceClass);
	message->AddInt8("DeviceClass", 1);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kDesktopLabel), message);
	fClassMenu->AddItem(item);

	message = new BMessage(kMsgSetDeviceClass);
	message->AddInt8("DeviceClass", 2);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kServerLabel), message);
	fClassMenu->AddItem(item);

	message = new BMessage(kMsgSetDeviceClass);
	message->AddInt8("DeviceClass", 3);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kLaptopLabel), message);
	fClassMenu->AddItem(item);

	message = new BMessage(kMsgSetDeviceClass);
	message->AddInt8("DeviceClass", 4);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kHandheldLabel), message);
	fClassMenu->AddItem(item);

	message = new BMessage(kMsgSetDeviceClass);
	message->AddInt8("DeviceClass", 5);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kPhoneLabel), message);
	fClassMenu->AddItem(item);
}
Exemple #2
0
BPopUpMenu*
TPrefsWindow::_BuildButtonBarMenu(uint8 show)
{
	BMenuItem* item;
	BMessage* msg;
	BPopUpMenu* menu = new BPopUpMenu("");

	msg = new BMessage(P_BUTTON_BAR);
	msg->AddInt8("bar", kShowToolBar);
	menu->AddItem(item = new BMenuItem(
		B_TRANSLATE("Show icons & labels"), msg));
	if (show & 1)
		item->SetMarked(true);

	msg = new BMessage(P_BUTTON_BAR);
	msg->AddInt8("bar", kShowToolBarIconsOnly);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show icons only"), msg));
	if (show & 2)
		item->SetMarked(true);

	msg = new BMessage(P_BUTTON_BAR);
	msg->AddInt8("bar", kHideToolBar);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Hide"), msg));
	if (!show)
		item->SetMarked(true);

	return menu;
}
void ArchiveColor(const char *name, BMessage *archive, const rgb_color &color) { 
	if (name == NULL) {
		archive->AddInt8("red", color.red);
		archive->AddInt8("green", color.green);
		archive->AddInt8("blue", color.blue);
		archive->AddInt8("alpha", color.alpha);
	} else {
		BMessage msg;
		msg.AddInt8("red", color.red);
		msg.AddInt8("green", color.green);
		msg.AddInt8("blue", color.blue);
		msg.AddInt8("alpha", color.alpha);
		archive->AddMessage(name, &msg);
	}
}
  virtual void Pulse (void)
  {
    return; // Not force testing message injection at this time.

    BMessage EventMessage;
    char     KeyAsString [16];
    int      i;
    m_EventTriggerCounter++;
printf ("Event %d\n", m_EventTriggerCounter);
    switch (m_EventTriggerCounter)
    {
      case 4:
//        EventMessage.what = B_MOUSE_MOVED;
//        EventMessage.AddFloat ("x", 0.2);
//        EventMessage.AddFloat ("y", 0.1);
//        EventMessage.AddInt64 ("when", system_time ());
//        EventMessage.AddInt32 ("buttons", 2);
//        EventMessage.what = B_MOUSE_WHEEL_CHANGED;
//        EventMessage.AddFloat ("be:wheel_delta_x", 0.0F);
//        EventMessage.AddFloat ("be:wheel_delta_y", -1.0F);
//        m_InputDeviceMousePntr->Control ('ViNC', &EventMessage);
        EventMessage.what = B_KEY_DOWN;
        EventMessage.AddInt64 ("when", system_time ());
        EventMessage.AddInt32 ("key", 61);
        EventMessage.AddInt32 ("modifiers", 0);
        strcpy (KeyAsString, "é");
        for (i = 0; KeyAsString[i] != 0; i++)
          EventMessage.AddInt8 ("byte", KeyAsString [i]);
        EventMessage.AddString ("bytes", KeyAsString);
        EventMessage.AddData ("states", B_UINT8_TYPE, KeyAsString, 16);
        EventMessage.AddInt32 ("raw_char", 62);
        m_InputDeviceKeyboardPntr->Control ('ViNC', &EventMessage);
        EventMessage.MakeEmpty ();
        EventMessage.what = B_KEY_UP;
        EventMessage.AddInt64 ("when", system_time ());
        EventMessage.AddInt32 ("key", 61);
        EventMessage.AddInt32 ("modifiers", 0);
        for (i = 0; KeyAsString[i] != 0; i++)
          EventMessage.AddInt8 ("byte", KeyAsString [i]);
        EventMessage.AddString ("bytes", KeyAsString);
        EventMessage.AddData ("states", B_UINT8_TYPE, KeyAsString, 16);
        EventMessage.AddInt32 ("raw_char", 62);
        m_InputDeviceKeyboardPntr->Control ('ViNC', &EventMessage);
        break;
      default:
        break;
    }
  };
Exemple #5
0
void
LocalDeviceImpl::RemoteNameRequestComplete(
	struct hci_ev_remote_name_request_complete_reply* remotename,
	BMessage* request)
{
	BMessage reply;

	if (remotename->status == BT_OK) {
		reply.AddString("friendlyname", (const char*)remotename->remote_name );
	}

	reply.AddInt8("status", remotename->status);

	TRACE_BT("LocalDeviceImpl: %s for %s with status %s\n",
		BluetoothEvent(HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE),
		bdaddrUtils::ToString(remotename->bdaddr).String(),
		BluetoothError(remotename->status));

	status_t status = request->SendReply(&reply);
	if (status < B_OK)
		printf("%s: Error sending reply to BMessage request: %s!\n",
			__func__, strerror(status));

	// This request is not gonna be used anymore
	ClearWantedEvent(request);
}
void PasteOMaticPaster::_Progress(int8 percentage)
{
    BMessage message;
    message.what = MESSAGE_PASTE_PROGRESS;
    message.AddInt8("percentage", percentage);
    fHandler->Looper()->Lock();
    fHandler->MessageReceived(&message);
    fHandler->Looper()->Unlock();
}
void
AntialiasingSettingsView::_BuildHintingMenu()
{
	fHintingMenu = new BPopUpMenu(B_TRANSLATE("Hinting menu"));

	BMessage* message = new BMessage(kMsgSetHinting);
	message->AddInt8("hinting", HINTING_MODE_OFF);
	fHintingMenu->AddItem(new BMenuItem(B_TRANSLATE(kNoHintingLabel),
		message));

	message = new BMessage(kMsgSetHinting);
	message->AddInt8("hinting", HINTING_MODE_ON);
	fHintingMenu->AddItem(new BMenuItem(B_TRANSLATE(kFullHintingLabel),
		message));

	message = new BMessage(kMsgSetHinting);
	message->AddInt8("hinting", HINTING_MODE_MONOSPACED_ONLY);
	fHintingMenu->AddItem(new BMenuItem(B_TRANSLATE(kMonospacedHintingLabel),
		message));
}
Exemple #8
0
status_t
TouchpadPref::UpdateSettings()
{
	if (!fConnected)
		return B_ERROR;

	LOG("UpdateSettings of device %s\n", fTouchPad->Name());

	BMessage msg;
	msg.AddBool("scroll_twofinger", fSettings.scroll_twofinger);
	msg.AddBool("scroll_twofinger_horizontal",
		fSettings.scroll_twofinger_horizontal);
	msg.AddFloat("scroll_rightrange", fSettings.scroll_rightrange);
	msg.AddFloat("scroll_bottomrange", fSettings.scroll_bottomrange);
	msg.AddInt16("scroll_xstepsize", fSettings.scroll_xstepsize);
	msg.AddInt16("scroll_ystepsize", fSettings.scroll_ystepsize);
	msg.AddInt8("scroll_acceleration", fSettings.scroll_acceleration);
	msg.AddInt8("tapgesture_sensibility", fSettings.tapgesture_sensibility);

	return fTouchPad->Control(MS_SET_TOUCHPAD_SETTINGS, &msg);
}
void
BluetoothSettingsView::_BuildConnectionPolicy()
{
	BMessage* message = NULL;
	BMenuItem* item = NULL;

	fPolicyMenu = new BPopUpMenu(B_TRANSLATE("Policy..."));

	message = new BMessage(kMsgSetConnectionPolicy);
	message->AddInt8("Policy", 1);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kAllLabel), message);
	fPolicyMenu->AddItem(item);

	message = new BMessage(kMsgSetConnectionPolicy);
	message->AddInt8("Policy", 2);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kTrustedLabel), message);
	fPolicyMenu->AddItem(item);

	message = new BMessage(kMsgSetConnectionPolicy);
	message->AddInt8("Policy", 3);
	item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kAlwaysLabel), NULL);
	fPolicyMenu->AddItem(item);
}
/*!	
 *	\brief			Internal function that creates a menu with month names.
 *	\param[in]	listOfMonths	List of months for a given year.
 *	\returns		The created BMenu.
 *	\remarks		Deletion and deallocation of the created menu is in
 *					responcibility of the caller.
 */
BPopUpMenu* CalendarControl::CreateMonthsMenu( map<int, DoubleNames> &listOfMonths )
{
	BMessage* message = NULL;
	BMenuItem* item = NULL;
	BString monthName;
	BPopUpMenu* toReturn = new BPopUpMenu("Months list");
	
	if (!toReturn) {
		/* Panic! */
		fLastError = B_NO_MEMORY; 
		return NULL;
	}
	toReturn->SetLabelFromMarked(true);
	toReturn->SetRadioMode(true);
	BFont font(be_plain_font);
	toReturn->SetFont(&font, B_FONT_FAMILY_AND_STYLE);
		
	int limit = listOfMonths.size();
	
	for (int i = 1; i <= limit; ++i ) {
		message = new BMessage( kMonthChanged );
		if ( !message ) {
			/* Panic! */
			fLastError = B_NO_MEMORY;
			return NULL;
		}
		if ( B_OK != message->AddInt8( "Month", ( int8 )i ) ) { 	//< Number of selected month in the year
			// Panic!
			exit(5);
		}
		monthName = listOfMonths[ i ].longName;
		item = new BMenuItem( monthName.String(), message );
		if (!item) { 
			/* Panic! */ 
			fLastError = B_NO_MEMORY; 
			return NULL;
		}
		if ( i == this->fRepresentedTime.tm_mon )
		{
			item->SetMarked(true);
		}
		toReturn->AddItem(item);
	}
	UpdateTargets( toReturn );
	return toReturn;
}
Exemple #11
0
void
LocalDeviceImpl::DisconnectionComplete(
	struct hci_ev_disconnection_complete_reply* event, BMessage* request)
{
	TRACE_BT("LocalDeviceImpl: %s: Handle=%#x, reason=%s status=%x\n", __FUNCTION__, event->handle,
		BluetoothError(event->reason), event->status);

	if (request != NULL) {
		BMessage reply;
		reply.AddInt8("status", event->status);

		printf("%s: Sending reply...\n", __func__);
		status_t status = request->SendReply(&reply);
		if (status < B_OK)
			printf("%s: Error sending reply!\n", __func__);
		// debug reply.PrintToStream();

		ClearWantedEvent(request);
	}
}
Exemple #12
0
void
LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event,
	BMessage* request)
{

	if (event->status == BT_OK) {
		uint8 cod[3] = {0, 0, 0};

		// TODO: Review, this rDevice is leaked
		ConnectionIncoming* iConnection = new ConnectionIncoming(
			new RemoteDevice(event->bdaddr, cod));
		iConnection->Show();

		TRACE_BT("LocalDeviceImpl: %s: Address %s handle=%#x type=%d encrypt=%d\n", __FUNCTION__,
				bdaddrUtils::ToString(event->bdaddr).String(), event->handle,
				event->link_type, event->encrypt_mode);

	} else {
		TRACE_BT("LocalDeviceImpl: %s: failed with error %s\n", __FUNCTION__,
			BluetoothError(event->status));
	}

	// it was expected
	if (request != NULL) {
		BMessage reply;
		reply.AddInt8("status", event->status);

		if (event->status == BT_OK)
			reply.AddInt16("handle", event->handle);

		printf("%s: Sending reply...\n", __func__);
		status_t status = request->SendReply(&reply);
		if (status < B_OK)
			printf("%s: Error sending reply!\n", __func__);
		// debug reply.PrintToStream();

		// This request is not gonna be used anymore
		ClearWantedEvent(request);
	}

}
Exemple #13
0
void Description::MessageReceived( BMessage* aMessage ) {
	switch( aMessage->what ) {
		case SET_AVAIL:
			iStatus = GG_STATUS_AVAIL_DESCR;
			break;
		case SET_BRB:
			iStatus = GG_STATUS_BUSY_DESCR;
			break;
		case SET_INVIS:
			iStatus = GG_STATUS_INVISIBLE_DESCR;
			break;
		case SET_NOT_AVAIL:
			iStatus = GG_STATUS_NOT_AVAIL_DESCR;
			break;
		case DESCRIPTION_OK:
			{
			BString description;
			BMessage *desc = new BMessage( SET_DESCRIPTION );
			fprintf( stderr, "iStatus = %d\n", iStatus );
			desc->AddInt8( "iStatus", iStatus );
			if( iDescription->LockLooper() ) {
				description.SetTo( iDescription->Text() );
				iDescription->UnlockLooper();
			}
			BString *desciso = toISO2(description.String());
			description.SetTo(desciso->String());
			desc->AddString( "iDescription", description );
			BMessenger( iWindow ).SendMessage( desc );
			delete desc;
			delete desciso;
			BMessenger( this ).SendMessage( B_QUIT_REQUESTED );
			break;
			}
		case DESCRIPTION_CANCEL:
			BMessenger( this ).SendMessage( B_QUIT_REQUESTED );
			break;
		default:
			BWindow::MessageReceived( aMessage );
	}
}
/*!	\brief		Create drop-down menu for day-month-year order.
 *	\param[in]	frame	Frame for this control
 *	\param[in]	id		ID of the CalendarControl
 */
BMenuField*		CalendarModulePreferencesView::CreateDayMonthYearOrderChooser( BRect frame, const BString& id )
{
	BMenuItem* 	toAdd = NULL;
	BMessage*	toSend = NULL;
	
	CalendarModulePreferences* prefs = pref_GetPreferencesForCalendarModule( id );
	BPopUpMenu* dmyOrderMenu = new BPopUpMenu( "DmyOrderChooser" );
	if ( ( !prefs ) || ( !dmyOrderMenu ) ) {
		return NULL;
	}
	
	for ( int8 i = 0; i < DMY_ORDER_NUMBER_OF_ELEMENTS; ++i ) {
		toSend = new BMessage( kCalendarModuleDateOrderSelected );
		if ( !toSend ) { return NULL; }
		toSend->AddString( "Calendar module", id );
		toSend->AddInt8( "DayMonthYearOrder", i );
		
		toAdd = new BMenuItem( DmyOrderNames[ i ], toSend );
		if ( !toAdd ) { delete toSend; return NULL; }
		dmyOrderMenu->AddItem( toAdd );
		toAdd->SetTarget( this );
		if ( i == ( int8 )prefs->GetDayMonthYearOrder() ) {
			toAdd->SetMarked( true );
		}
	}
	
	BMenuField* toReturn = new BMenuField( frame,
											"Day-Month-Year order chooser",
											"Select the order for day, month and year:",
											dmyOrderMenu );
	if ( !toReturn ) {
		delete dmyOrderMenu;
		return NULL;
	}
	
	toReturn->ResizeToPreferred();
	
	return toReturn;
}	// <-- end of function CalendarModulePreferencesView::CreateDayMonthYearOrderChooser
Exemple #15
0
BMenuItem* SplitWindow::MakeCatMenu(Cat* cat)
{
	BMenuItem* mi;
	BMessage* msgs = new BMessage(CatPopUpMSG);
	msgs->AddString("text", cat->Name().c_str());
	msgs->AddInt8("num", catnum);
	cas* childcats = cat->SetOfChildren();
	
	if (childcats->empty())
	{
		mi = new BMenuItem(cat->LeafName().c_str(), msgs);
	}
	else
	{
		BMenu* m = new BMenu(cat->LeafName().c_str());
		mi = new BMenuItem(m, msgs);
		for (cas::iterator ci = childcats->begin();	ci != childcats->end(); ci++)
		{
			m->AddItem(MakeCatMenu(*ci));
		}
	}
	
	return mi;
}
Exemple #16
0
BooleanEditor::BooleanEditor(BRect rect, DataEditor &editor)
	: TypeEditorView(rect, B_TRANSLATE("Boolean editor"), B_FOLLOW_NONE, 0, editor)
{
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	BPopUpMenu *menu = new BPopUpMenu("bool");
	BMessage *message;
	menu->AddItem(fFalseMenuItem = new BMenuItem("false",
		new BMessage(kMsgValueChanged)));
	menu->AddItem(fTrueMenuItem = new BMenuItem("true",
		message = new BMessage(kMsgValueChanged)));
	message->AddInt8("value", 1);

	BMenuField *menuField = new BMenuField(rect.InsetByCopy(5, 5),
		B_EMPTY_STRING, B_TRANSLATE("Boolean value:"), menu, B_FOLLOW_LEFT_RIGHT);
	menuField->SetDivider(StringWidth(menuField->Label()) + 8);
	menuField->ResizeToPreferred();
	ResizeTo(menuField->Bounds().Width() + 10,
		menuField->Bounds().Height() + 10);

	_UpdateMenuField();

	AddChild(menuField);
}
Exemple #17
0
void
LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event,
	BMessage* request, int32 index)
{

	int16 opcodeExpected;
	BMessage reply;
	status_t status;

	// Handle command complete information
	request->FindInt16("opcodeExpected", index, &opcodeExpected);

	if (request->IsSourceWaiting() == false) {
		TRACE_BT("LocalDeviceImpl: Nobody waiting for the event\n");
	}

	switch (opcodeExpected) {

		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY):
		{
			reply.what = BT_MSG_INQUIRY_STARTED;

			TRACE_BT("LocalDeviceImpl: Inquiry status %x\n", event->status);

			reply.AddInt8("status", event->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			ClearWantedEvent(request, HCI_EVENT_CMD_STATUS,
				PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY));
		}
		break;

		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST):
		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_CREATE_CONN):
		{
			if (event->status == BT_OK) {
				ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, opcodeExpected);
			} else {
				TRACE_BT("LocalDeviceImpl: Command Status for remote friendly name %x\n",
					event->status);

				reply.AddInt8("status", event->status);
				status = request->SendReply(&reply);
				//printf("Sending reply... %ld\n", status);
				// debug reply.PrintToStream();

				ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, opcodeExpected);
			}
		}
		break;
		/*
		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ):
		{
			ClearWantedEvent(request, HCI_EVENT_CMD_STATUS,
				PACK_OPCODE(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ));
		}
		break;

		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ):
		{
			ClearWantedEvent(request, HCI_EVENT_CMD_STATUS,
				PACK_OPCODE(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ));
		}
		break;*/

		default:
			TRACE_BT("LocalDeviceImpl: Command Status not handled\n");
		break;
	}

}
Exemple #18
0
bool
TTracker::QuitRequested()
{
	// don't allow user quitting
	if (CurrentMessage() && CurrentMessage()->FindBool("shortcut"))
		return false;

	gStatusWindow->AttemptToQuit();
		// try quitting the copy/move/empty trash threads
		
	BVolume bootVolume;
	DEBUG_ONLY(status_t err =) BVolumeRoster().GetBootVolume(&bootVolume);
	ASSERT(err == B_OK);
	BMessage message;
	AutoLock<WindowList> lock(&fWindowList);
	// save open windows in a message inside an attribute of the desktop
	int32 count = fWindowList.CountItems();
	for (int32 i = 0; i < count; i++) {
		BContainerWindow *window = dynamic_cast<BContainerWindow *>
			(fWindowList.ItemAt(i));

		if (window && window->TargetModel() && !window->PoseView()->IsDesktopWindow()) {
			if (window->TargetModel()->IsRoot())
				message.AddBool("open_disks_window", true);
			else {
				BEntry entry;
				BPath path;
				const entry_ref *ref = window->TargetModel()->EntryRef();
				if (entry.SetTo(ref) == B_OK && entry.GetPath(&path) == B_OK) {
					int8 flags = window->IsMinimized() ? kOpenWindowMinimized : kOpenWindowNoFlags;
					uint32 deviceFlags = GetVolumeFlags(window->TargetModel());

					// save state for every window which is
					//	a) already open on another workspace
					//	b) on a volume not capable of writing attributes
					if (window != FindContainerWindow(ref)
						|| (deviceFlags & (B_FS_HAS_ATTR | B_FS_IS_READONLY)) != B_FS_HAS_ATTR) {
						BMessage stateMessage;
						window->SaveState(stateMessage);
						window->SetSaveStateEnabled(false);
							// This is to prevent its state to be saved to the node when closed.
						message.AddMessage("window state", &stateMessage);
						flags |= kOpenWindowHasState;
					}
					const char *target;
					bool pathAlreadyExists = false;
					for (int32 index = 0;message.FindString("paths", index, &target) == B_OK;index++) {
						if (!strcmp(target,path.Path())) {
							pathAlreadyExists = true;
							break;
						}
					}
					if (!pathAlreadyExists)
						message.AddString("paths", path.Path());
					message.AddInt8(path.Path(), flags);
				}
			}	
		}
	}
	lock.Unlock();

	// write windows to open on disk
	BDirectory deskDir;
	if (!BootedInSafeMode() && FSGetDeskDir(&deskDir, bootVolume.Device()) == B_OK) {
		// if message is empty, delete the corresponding attribute
		if (message.CountNames(B_ANY_TYPE)) {
			size_t size = (size_t)message.FlattenedSize();
			char *buffer = new char[size];
			message.Flatten(buffer, (ssize_t)size);
			deskDir.WriteAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer, size);
			delete [] buffer;
		} else
			deskDir.RemoveAttr(kAttrOpenWindows);
	}

	for (int32 count = 0; count == 50; count++) {
		// wait 5 seconds for the copiing/moving to quit
		if (gStatusWindow->AttemptToQuit())
			break;

		snooze(100000);
	}

	return _inherited::QuitRequested();
}
bool
CanvasEventStream::EventReceived(CanvasMessage& message)
{
	uint16 code = message.Code();
	uint32 what = 0;
	switch (code) {
		case RP_MOUSE_MOVED:
			what = B_MOUSE_MOVED;
			break;
		case RP_MOUSE_DOWN:
			what = B_MOUSE_DOWN;
			break;
		case RP_MOUSE_UP:
			what = B_MOUSE_UP;
			break;
		case RP_MOUSE_WHEEL_CHANGED:
			what = B_MOUSE_WHEEL_CHANGED;
			break;
		case RP_KEY_DOWN:
			what = B_KEY_DOWN;
			break;
		case RP_KEY_UP:
			what = B_KEY_UP;
			break;
		case RP_MODIFIERS_CHANGED:
			what = B_MODIFIERS_CHANGED;
			break;
	}

	if (what == 0)
		return false;

	BMessage* event = new BMessage(what);
	if (event == NULL)
		return false;

	event->AddInt64("when", system_time());

	switch (code) {
		case RP_MOUSE_MOVED:
		case RP_MOUSE_DOWN:
		case RP_MOUSE_UP:
		{
			message.Read(fMousePosition);
			if (code != RP_MOUSE_MOVED)
				message.Read(fMouseButtons);

			event->AddPoint("where", fMousePosition);
			event->AddInt32("buttons", fMouseButtons);
			event->AddInt32("modifiers", fModifiers);

			if (code == RP_MOUSE_DOWN) {
				int32 clicks;
				if (message.Read(clicks) == B_OK)
					event->AddInt32("clicks", clicks);
			}

			if (code == RP_MOUSE_MOVED)
				fLatestMouseMovedEvent = event;
			break;
		}

		case RP_MOUSE_WHEEL_CHANGED:
		{
			float xDelta, yDelta;
			message.Read(xDelta);
			message.Read(yDelta);
			event->AddFloat("be:wheel_delta_x", xDelta);
			event->AddFloat("be:wheel_delta_y", yDelta);
			break;
		}

		case RP_KEY_DOWN:
		case RP_KEY_UP:
		{
			int32 numBytes;
			if (message.Read(numBytes) != B_OK)
				break;

			char* bytes = (char*)malloc(numBytes + 1);
			if (bytes == NULL)
				break;

			if (message.ReadList(bytes, numBytes) != B_OK) {
				free(bytes);
				break;
			}

			for (int32 i = 0; i < numBytes; i++)
				event->AddInt8("byte", (int8)bytes[i]);

			bytes[numBytes] = 0;
			event->AddData("bytes", B_STRING_TYPE, bytes, numBytes + 1, false);
			event->AddInt32("modifiers", fModifiers);

			int32 rawChar;
			if (message.Read(rawChar) == B_OK)
				event->AddInt32("raw_char", rawChar);

			int32 key;
			if (message.Read(key) == B_OK)
				event->AddInt32("key", key);

			free(bytes);
			break;
		}

		case RP_MODIFIERS_CHANGED:
		{
			event->AddInt32("be:old_modifiers", fModifiers);
			message.Read(fModifiers);
			event->AddInt32("modifiers", fModifiers);
			break;
		}
	}

	BAutolock lock(fEventListLocker);
	fEventList.AddItem(event);
	if (fWaitingOnEvent) {
		fWaitingOnEvent = false;
		lock.Unlock();
		release_sem(fEventNotification);
	}

	return true;
}
Exemple #20
0
FindWindow::FindWindow(BRect _rect, BMessage& previous, BMessenger& target,
		const BMessage* settings)
	: BWindow(_rect, B_TRANSLATE("Find"), B_TITLED_WINDOW,
		B_ASYNCHRONOUS_CONTROLS | B_CLOSE_ON_ESCAPE),
	fTarget(target)
{
	BView* view = new BView(Bounds(), "main", B_FOLLOW_ALL, 0);
	view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	AddChild(view);

	int8 mode = kAsciiMode;
	if (previous.FindInt8("find_mode", &mode) != B_OK && settings != NULL)
		settings->FindInt8("find_mode", &mode);

	// add the top widgets

	fMenu = new BPopUpMenu("mode");
	BMessage* message;
	BMenuItem* item;
	fMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Text"),
		message = new BMessage(kMsgFindMode)));
	message->AddInt8("mode", kAsciiMode);
	if (mode == kAsciiMode)
		item->SetMarked(true);
	fMenu->AddItem(item = new BMenuItem(B_TRANSLATE_COMMENT("Hexadecimal", 
		"A menu item, as short as possible, noun is recommended if it is "
		"shorter than adjective."), message = new BMessage(kMsgFindMode)));
	message->AddInt8("mode", kHexMode);
	if (mode == kHexMode)
		item->SetMarked(true);

	BRect rect = Bounds().InsetByCopy(5, 5);
	BMenuField* menuField = new BMenuField(rect, B_EMPTY_STRING,
		B_TRANSLATE("Mode:"), fMenu, B_FOLLOW_LEFT | B_FOLLOW_TOP);
	menuField->SetDivider(menuField->StringWidth(menuField->Label()) + 8);
	menuField->ResizeToPreferred();
	view->AddChild(menuField);

	// add the bottom widgets

	BButton* button = new BButton(rect, B_EMPTY_STRING, B_TRANSLATE("Find"),
		new BMessage(kMsgStartFind), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
	button->MakeDefault(true);
	button->ResizeToPreferred();
	button->MoveTo(rect.right - button->Bounds().Width(),
		rect.bottom - button->Bounds().Height());
	view->AddChild(button);

	fCaseCheckBox = new BCheckBox(rect, B_EMPTY_STRING, B_TRANSLATE("Case sensitive"),
		NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
	fCaseCheckBox->ResizeToPreferred();
	fCaseCheckBox->MoveTo(5, button->Frame().top);
	bool caseSensitive;
	if (previous.FindBool("case_sensitive", &caseSensitive) != B_OK) {
		if (settings == NULL
			|| settings->FindBool("case_sensitive", &caseSensitive) != B_OK)
			caseSensitive = true;
	}
	fCaseCheckBox->SetValue(caseSensitive);
	view->AddChild(fCaseCheckBox);

	// and now those inbetween

	rect.top = menuField->Frame().bottom + 5;
	rect.bottom = fCaseCheckBox->Frame().top - 8;
	rect.InsetBy(2, 2);
	fTextView = new FindTextView(rect, B_EMPTY_STRING,
		rect.OffsetToCopy(B_ORIGIN).InsetByCopy(3, 3), B_FOLLOW_ALL);
	fTextView->SetWordWrap(true);
	fTextView->SetMode((find_mode)mode);
	fTextView->SetData(previous);

	BScrollView* scrollView = new BScrollView("scroller", fTextView,
		B_FOLLOW_ALL, B_WILL_DRAW, false, false);
	view->AddChild(scrollView);

	ResizeTo(290, button->Frame().Height() * 3 + 30);

	SetSizeLimits(fCaseCheckBox->Bounds().Width() + button->Bounds().Width()
			+ 20, 32768, button->Frame().Height() * 3 + 10, 32768);
}
Exemple #21
0
static inline status_t SaveInt8(BMessage &msg, const char *string, int8 data)
{
	if(msg.ReplaceInt8(string, data) == B_NAME_NOT_FOUND)
		return msg.AddInt8(string, data);
	return msg.ReplaceInt8(string, data);
}
Exemple #22
0
void ColorMenu::MouseMoved (BPoint point, uint32 transit, const BMessage *msg)
{
	msg = msg;
	uint32 buttons;
	if (!Parent())
		return;
//	printf ("("); fflush (stdout);
	GetMouse (&point, &buttons);
//	printf (")"); fflush (stdout);
	if (transit == B_EXITED_VIEW && buttons)	// Do the tear off thing!
	{
#if defined (EASTER_EGG_SFX)
		extern bool EasterEgg;
		if (modifiers() & B_SHIFT_KEY && EasterEgg)
		{
			extern EffectsPlayer *easterEgg;
			easterEgg->StartEffect();
		}
#endif
		BMessage *tearmsg = new BMessage ('tear');
		BBitmap *dragmap = new BBitmap (Bounds(), B_RGBA32, true);
		dragmap->Lock();
		BView *dragview = new BView (Bounds(), "temp dragmap view", B_FOLLOW_ALL, B_WILL_DRAW);
		dragmap->AddChild (dragview);
		//dragview->SetLowColor (LightGrey);
		//dragview->FillRect (Bounds(), B_SOLID_LOW);
		for (int i = 0; i < MAX_COLORS; i++)
		{
			dragview->SetHighColor (items[i]->getColor());
			dragview->FillRect (items[i]->Frame());
			dragview->Sync();
		}
		dragview->SetHighColor (DarkGrey);
		dragview->StrokeRect (Bounds());
		dragmap->RemoveChild (dragview);
		bgra_pixel *bits = (bgra_pixel *) dragmap->Bits();
		for (bgra_pixel p = 0; p < dragmap->BitsLength()/4; p++)
		{
			bgra_pixel pixel = *bits;
			*bits++ = (pixel & COLOR_MASK) | (127 << ALPHA_BPOS);
		}
		dragmap->Unlock();
		delete dragview;
		DragMessage (tearmsg, dragmap, B_OP_ALPHA, B_ORIGIN);
		delete tearmsg;
		BRect place = Bounds();
		
		// Send a fake Esc keydown to the popup
		char kbuf[2];
		BMessage kmsg (B_KEY_DOWN);
		kmsg.AddInt64 ("when", system_time());
		kmsg.AddInt32 ("modifiers", 0);
		kmsg.AddInt32 ("key", B_ESCAPE);
		kmsg.AddInt8 ("byte", B_ESCAPE);
		kbuf[0] = B_ESCAPE;
		kbuf[1] = '\0';
		kmsg.AddString ("bytes", kbuf);
		Window()->PostMessage (&kmsg, this);
		// This makes the original popup go away.
		// We can't use Hide() since that crashes.
		
		colorTearInfo *tearInfo = new colorTearInfo (place, this, parent);
		resume_thread (spawn_thread (color_tear_drag, "Menu Tear Thread", B_NORMAL_PRIORITY, tearInfo));
	}
}
Exemple #23
0
void
LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
	BMessage* request, int32 index)
{
	int16 opcodeExpected;
	BMessage reply;
	status_t status;

	// Handle command complete information
	request->FindInt16("opcodeExpected", index, &opcodeExpected);

	if (request->IsSourceWaiting() == false) {
		TRACE_BT("LocalDeviceImpl: Nobody waiting for the event\n");
	}

	switch ((uint16)opcodeExpected) {

		case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION):
		{
			struct hci_rp_read_loc_version* version
				= JumpEventHeader<struct hci_rp_read_loc_version,
				struct hci_ev_cmd_complete>(event);


			if (version->status == BT_OK) {

				if (!IsPropertyAvailable("hci_version"))
					fProperties->AddInt8("hci_version", version->hci_version);

				if (!IsPropertyAvailable("hci_revision")) {
					fProperties->AddInt16("hci_revision",
						version->hci_revision);
				}

				if (!IsPropertyAvailable("lmp_version"))
					fProperties->AddInt8("lmp_version", version->lmp_version);

				if (!IsPropertyAvailable("lmp_subversion")) {
					fProperties->AddInt16("lmp_subversion",
						version->lmp_subversion);
				}

				if (!IsPropertyAvailable("manufacturer")) {
					fProperties->AddInt16("manufacturer",
						version->manufacturer);
				}
			}

			TRACE_BT("LocalDeviceImpl: Reply for Local Version %x\n", version->status);

			reply.AddInt8("status", version->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
			break;
		}

		case  PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_PG_TIMEOUT):
		{
			struct hci_rp_read_page_timeout* pageTimeout
				= JumpEventHeader<struct hci_rp_read_page_timeout,
				struct hci_ev_cmd_complete>(event);

			if (pageTimeout->status == BT_OK) {
				fProperties->AddInt16("page_timeout",
					pageTimeout->page_timeout);

				TRACE_BT("LocalDeviceImpl: Page Timeout=%x\n", pageTimeout->page_timeout);
			}

			reply.AddInt8("status", pageTimeout->status);
			reply.AddInt32("result", pageTimeout->page_timeout);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
			break;
		}

		case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_FEATURES):
		{
			struct hci_rp_read_loc_features* features
				= JumpEventHeader<struct hci_rp_read_loc_features,
				struct hci_ev_cmd_complete>(event);

			if (features->status == BT_OK) {

				if (!IsPropertyAvailable("features")) {
					fProperties->AddData("features", B_ANY_TYPE,
						&features->features, 8);

					uint16 packetType = HCI_DM1 | HCI_DH1 | HCI_HV1;

					bool roleSwitch
						= (features->features[0] & LMP_RSWITCH) != 0;
					bool encryptCapable
						= (features->features[0] & LMP_ENCRYPT) != 0;

					if (features->features[0] & LMP_3SLOT)
						packetType |= (HCI_DM3 | HCI_DH3);

					if (features->features[0] & LMP_5SLOT)
						packetType |= (HCI_DM5 | HCI_DH5);

					if (features->features[1] & LMP_HV2)
						packetType |= (HCI_HV2);

					if (features->features[1] & LMP_HV3)
						packetType |= (HCI_HV3);

					fProperties->AddInt16("packet_type", packetType);
					fProperties->AddBool("role_switch_capable", roleSwitch);
					fProperties->AddBool("encrypt_capable", encryptCapable);

					TRACE_BT("LocalDeviceImpl: Packet type %x role switch %d encrypt %d\n",
						packetType, roleSwitch, encryptCapable);
				}

			}

			TRACE_BT("LocalDeviceImpl: Reply for Local Features %x\n", features->status);

			reply.AddInt8("status", features->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
			break;
		}

		case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE):
		{
			struct hci_rp_read_buffer_size* buffer
				= JumpEventHeader<struct hci_rp_read_buffer_size,
				struct hci_ev_cmd_complete>(event);

			if (buffer->status == BT_OK) {

				if (!IsPropertyAvailable("acl_mtu"))
					fProperties->AddInt16("acl_mtu", buffer->acl_mtu);

				if (!IsPropertyAvailable("sco_mtu"))
					fProperties->AddInt8("sco_mtu", buffer->sco_mtu);

				if (!IsPropertyAvailable("acl_max_pkt"))
					fProperties->AddInt16("acl_max_pkt", buffer->acl_max_pkt);

				if (!IsPropertyAvailable("sco_max_pkt"))
					fProperties->AddInt16("sco_max_pkt", buffer->sco_max_pkt);

			}

			TRACE_BT("LocalDeviceImpl: Reply for Read Buffer Size %x\n", buffer->status);


			reply.AddInt8("status", buffer->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
		}
		break;

		case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR):
		{
			struct hci_rp_read_bd_addr* readbdaddr
				= JumpEventHeader<struct hci_rp_read_bd_addr,
				struct hci_ev_cmd_complete>(event);

			if (readbdaddr->status == BT_OK) {
				reply.AddData("bdaddr", B_ANY_TYPE, &readbdaddr->bdaddr,
					sizeof(bdaddr_t));
			}

			TRACE_BT("LocalDeviceImpl: Read bdaddr status = %x\n", readbdaddr->status);

			reply.AddInt8("status", readbdaddr->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
		}
		break;


		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV):
		{
			struct hci_read_dev_class_reply* classDev
				= JumpEventHeader<struct hci_read_dev_class_reply,
				struct hci_ev_cmd_complete>(event);

			if (classDev->status == BT_OK) {
				reply.AddData("devclass", B_ANY_TYPE, &classDev->dev_class,
					sizeof(classDev->dev_class));
			}

			TRACE_BT("LocalDeviceImpl: Read DeviceClass status = %x DeviceClass = [%x][%x][%x]\n",
				classDev->status, classDev->dev_class[0],
				classDev->dev_class[1], classDev->dev_class[2]);


			reply.AddInt8("status", classDev->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
			break;
		}

		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME):
		{
			struct hci_rp_read_local_name* readLocalName
				= JumpEventHeader<struct hci_rp_read_local_name,
				struct hci_ev_cmd_complete>(event);


			if (readLocalName->status == BT_OK) {
				reply.AddString("friendlyname",
					(const char*)readLocalName->local_name);
			}

			TRACE_BT("LocalDeviceImpl: Friendly name status %x\n", readLocalName->status);

			reply.AddInt8("status", readLocalName->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
			break;
		}

		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY):
		{
			uint8* statusReply = (uint8*)(event + 1);

			// TODO: This reply has to match the BDADDR of the outgoing message
			TRACE_BT("LocalDeviceImpl: pincode accept status %x\n", *statusReply);

			reply.AddInt8("status", *statusReply);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			//ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected);
			ClearWantedEvent(request);
			break;
		}

		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY):
		{
			uint8* statusReply = (uint8*)(event + 1);

			// TODO: This reply might match the BDADDR of the outgoing message
			// => FindPetition should be expanded....
			TRACE_BT("LocalDeviceImpl: pincode reject status %x\n", *statusReply);

			reply.AddInt8("status", *statusReply);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected);
			break;
		}

		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_STORED_LINK_KEY):
		{
			struct hci_read_stored_link_key_reply* linkKeyRetrieval
				= JumpEventHeader<struct hci_read_stored_link_key_reply,
				struct hci_ev_cmd_complete>(event);

			TRACE_BT("LocalDeviceImpl: Status %s MaxKeys=%d, KeysRead=%d\n",
				BluetoothError(linkKeyRetrieval->status),
				linkKeyRetrieval->max_num_keys,
				linkKeyRetrieval->num_keys_read);

			reply.AddInt8("status", linkKeyRetrieval->status);
			status = request->SendReply(&reply);
			//printf("Sending reply... %ld\n", status);
			// debug reply.PrintToStream();

			ClearWantedEvent(request);
			break;
		}

		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_LINK_KEY_NEG_REPLY):
		case PACK_OPCODE(OGF_LINK_CONTROL, OCF_LINK_KEY_REPLY):
		{
			struct hci_cp_link_key_reply_reply* linkKeyReply
				= JumpEventHeader<struct hci_cp_link_key_reply_reply,
				struct hci_ev_cmd_complete>(event);

			TRACE_BT("LocalDeviceImpl: Status %s addresss=%s\n", BluetoothError(linkKeyReply->status),
				bdaddrUtils::ToString(linkKeyReply->bdaddr).String());

			ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected);
			break;
		}

		case  PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_SCAN_ENABLE):
		{
			struct hci_read_scan_enable* scanEnable
				= JumpEventHeader<struct hci_read_scan_enable,
				struct hci_ev_cmd_complete>(event);

			if (scanEnable->status == BT_OK) {
				fProperties->AddInt8("scan_enable", scanEnable->enable);

				TRACE_BT("LocalDeviceImpl: enable = %x\n", scanEnable->enable);
			}

			reply.AddInt8("status", scanEnable->status);
			reply.AddInt8("scan_enable", scanEnable->enable);
			status = request->SendReply(&reply);
			printf("Sending reply. scan_enable = %d\n", scanEnable->enable);
			// debug reply.PrintToStream();

			// This request is not gonna be used anymore
			ClearWantedEvent(request);
			break;
		}

		// place here all CC that just replies a uint8 status
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_RESET):
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE):
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_CLASS_OF_DEV):
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_PG_TIMEOUT):
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_CA_TIMEOUT):
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_AUTH_ENABLE):
		case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_LOCAL_NAME):
		case PACK_OPCODE(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR):
		{
			reply.AddInt8("status", *(uint8*)(event + 1));

			TRACE_BT("LocalDeviceImpl: %s for %s status %x\n", __FUNCTION__,
				BluetoothCommandOpcode(opcodeExpected), *(uint8*)(event + 1));

			status = request->SendReply(&reply);
			printf("%s: Sending reply write...\n", __func__);
			if (status < B_OK)
				printf("%s: Error sending reply write!\n", __func__);

			ClearWantedEvent(request);
			break;
		}

		default:
			TRACE_BT("LocalDeviceImpl: Command Complete not handled\n");
			break;

	}
}