void ArpTwoStateButton::MouseDown(BPoint where)
{
	inherited::MouseDown(where);
	mSwitched = !mPressed;

	/* Quick hack */
	mPressed = !mPressed;
	BMessage*	msg = 0;
	if( Message() ) msg = new BMessage( *Message() );
	if( msg ) msg->AddBool("on", mPressed);
	Invoke(msg);

	Invalidate();
}
Beispiel #2
0
void uDelegate::Invoke(uTRef retval, size_t count, ...)
{
    va_list ap;
    va_start(ap, count);
    void** args = count > 0
        ? (void**)U_ALLOCA(count * sizeof(void*))
        : NULL;

    for (size_t i = 0; i < count; i++)
        args[i] = va_arg(ap, void*);

    va_end(ap);
    Invoke(retval, args, count);
}
Beispiel #3
0
void
Spinner::MessageReceived(BMessage *msg)
{
	if (msg->what == M_TEXT_CHANGED) {
		BString string(fTextControl->Text());
		int32 newvalue = 0;
		
		sscanf(string.String(),"%ld",&newvalue);
		if (newvalue >= GetMin() && newvalue <= GetMax()) {
			// new value is in range, so set it and go
			SetValue(newvalue);
			Invoke();
			Draw(Bounds());
			ValueChanged(Value());
		} else {
			// new value is out of bounds. Clip to range if current value is not
			// at the end of its range
			if (newvalue < GetMin() && Value() != GetMin()) {
				SetValue(GetMin());
				Invoke();
				Draw(Bounds());
				ValueChanged(Value());
			} else if (newvalue>GetMax() && Value() != GetMax()) {
				SetValue(GetMax());
				Invoke();
				Draw(Bounds());
				ValueChanged(Value());
			} else {
				char string[100];
				sprintf(string,"%ld",Value());
				fTextControl->SetText(string);
			}
		}
	}
	else
		BControl::MessageReceived(msg);
}
Beispiel #4
0
TEST_F(DataTest, testGetData) {{
	InSequence s;
	char buffer[256];
	memset(buffer, 0, sizeof(buffer));
	HDDEDATA hData = (HDDEDATA)88772;
		
	EXPECT_CALL(winApi, DdeGetData(hData, _, sizeof(buffer), 5))
		.Times(1)
		.WillOnce(Invoke(this, &DataTest::DdeGetData));

	auto_drop<Data> data(new Data(&instance, &winApi, hData));

	ASSERT_EQ(8, data->getData((LPBYTE)buffer, sizeof(buffer), 5));
	ASSERT_STREQ("zulu 19", buffer);
}}
TEST_F(ScriptRunnerTest, QueueReentrantScript_Async)
{
    MockScriptLoader scriptLoader1(m_element.get());
    MockScriptLoader scriptLoader2(m_element.get());
    MockScriptLoader scriptLoader3(m_element.get());

    m_scriptRunner->queueScriptForExecution(&scriptLoader1, ScriptRunner::ASYNC_EXECUTION);
    m_scriptRunner->queueScriptForExecution(&scriptLoader2, ScriptRunner::ASYNC_EXECUTION);
    m_scriptRunner->queueScriptForExecution(&scriptLoader3, ScriptRunner::ASYNC_EXECUTION);
    m_scriptRunner->notifyScriptReady(&scriptLoader1, ScriptRunner::ASYNC_EXECUTION);

    EXPECT_CALL(scriptLoader1, execute()).WillOnce(Invoke([&scriptLoader2, this] {
        m_order.push_back(1);
        m_scriptRunner->notifyScriptReady(&scriptLoader2, ScriptRunner::ASYNC_EXECUTION);
    }));

    EXPECT_CALL(scriptLoader2, execute()).WillOnce(Invoke([&scriptLoader3, this] {
        m_order.push_back(2);
        m_scriptRunner->notifyScriptReady(&scriptLoader3, ScriptRunner::ASYNC_EXECUTION);
    }));

    EXPECT_CALL(scriptLoader3, execute()).WillOnce(Invoke([this] {
        m_order.push_back(3);
    }));

    // Make sure that re-entrant calls to notifyScriptReady don't cause ScriptRunner::execute to do
    // more work than expected.
    m_platform.runSingleTask();
    EXPECT_THAT(m_order, ElementsAre(1));

    m_platform.runSingleTask();
    EXPECT_THAT(m_order, ElementsAre(1, 2));

    m_platform.runSingleTask();
    EXPECT_THAT(m_order, ElementsAre(1, 2, 3));
}
void ArpColourControl::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
		case _R_MSG:
			Invoke();
			if (mR && mA) {
				((_ArpRgbaControl*)mA)->SetColor(mR->Value(), -1, -1);
				mA->Invalidate();
			}
//			printf("R Changed\n");
			break;
		case _G_MSG:
			Invoke();
			if (mG && mA) {
				((_ArpRgbaControl*)mA)->SetColor(-1, mG->Value(), -1);
				mA->Invalidate();
			}
//			printf("G Changed\n");
			break;
		case _B_MSG:
			Invoke();
			if (mB && mA) {
				((_ArpRgbaControl*)mA)->SetColor(-1, -1, mB->Value());
				mA->Invalidate();
			}
//			printf("B Changed\n");
			break;
		case _A_MSG:
			Invoke();
//			printf("A Changed\n");
			break;
		default:
			inherited::MessageReceived(msg);
			break;
	}
}
Beispiel #7
0
TEST_F(ScriptRunnerTest, QueueReentrantScript_ManyAsyncScripts)
{
    OwnPtrWillBeRawPtr<MockScriptLoader> scriptLoaders[20];
    for (int i = 0; i < 20; i++)
        scriptLoaders[i] = nullptr;

    for (int i = 0; i < 20; i++) {
        scriptLoaders[i] = MockScriptLoader::create(m_element.get());
        EXPECT_CALL(*scriptLoaders[i], isReady()).WillRepeatedly(Return(true));

        m_scriptRunner->queueScriptForExecution(scriptLoaders[i].get(), ScriptRunner::ASYNC_EXECUTION);

        if (i > 0) {
            EXPECT_CALL(*scriptLoaders[i], execute()).WillOnce(Invoke([this, i] {
                m_order.append(i);
            }));
        }
    }

    m_scriptRunner->notifyScriptReady(scriptLoaders[0].get(), ScriptRunner::ASYNC_EXECUTION);
    m_scriptRunner->notifyScriptReady(scriptLoaders[1].get(), ScriptRunner::ASYNC_EXECUTION);

    EXPECT_CALL(*scriptLoaders[0], execute()).WillOnce(Invoke([&scriptLoaders, this] {
        for (int i = 2; i < 20; i++)
            m_scriptRunner->notifyScriptReady(scriptLoaders[i].get(), ScriptRunner::ASYNC_EXECUTION);
        m_order.append(0);
    }));

    m_platform.runAllTasks();

    int expected[] = {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
    };

    EXPECT_THAT(m_order, testing::ElementsAreArray(expected));
}
Beispiel #8
0
void
BIconButton::MouseUp(BPoint where)
{
	if (!IsValid())
		return;

	if (IsEnabled() && _HasFlags(STATE_PRESSED)
		&& Bounds().Contains(where)) {
		Invoke();
	} else if (Bounds().Contains(where))
		SetInside(true);

	_SetFlags(STATE_PRESSED, false);
	_SetTracking(false);
}
Beispiel #9
0
	virtual void MouseDown(BPoint point)
	{
		// Don't reopen the menu if it's already open or freshly closed.
		bigtime_t clickSpeed = 2000000;
		get_click_speed(&clickSpeed);
		bigtime_t clickTime = Window()->CurrentMessage()->FindInt64("when");
		if (!IsEnabled() || (Value() == B_CONTROL_ON) 
			|| clickTime < fCloseTime + clickSpeed) {
			return;
		}

		// Invoke must be called before setting B_CONTROL_ON
		// for the button to stay "down"
		Invoke();
		SetValue(B_CONTROL_ON);
	}
void
BRadioButton::MouseUp(BPoint point)
{
	if (!IsTracking())
		return;

	fOutlined = Bounds().Contains(point);
	if (fOutlined) {
		fOutlined = false;
		SetValue(B_CONTROL_ON);
		Invoke();
	}
	Invalidate();

	SetTracking(false);
}
Beispiel #11
0
int main()
{
	Lua lua;
	auto global = lua.GetGlobalEnvironment();
	
	// Write a function in Lua
	lua.RunScript(
		"function addTwo(a)\n"
		"  return a+2\n"
		"end\n"
	);

	auto addTwo = global.Get< LuaFunction<int(int)> >("addTwo");
	
	return addTwo.Invoke(5) != 7;
}
Beispiel #12
0
void ArpIntControl::MouseUp(BPoint pt)
{
	if (IsEnabled() == false) return;

	if (mMotion) mMotion->MouseUp(pt);
	if ( mDownPt == pt && Bounds().Contains(pt) ) {
		/* Start the edit timer in case the user is invoking an inline
		 * text view.
		 */
		bigtime_t	doubleClickTime;
		get_click_speed(&doubleClickTime);
		doubleClickTime *= 2;
		SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
		StartTimer(BMessage(EDIT_START_MSG), doubleClickTime);
	} else Invoke();
}
Beispiel #13
0
void
BButton::MouseUp(BPoint where)
{
	if (!IsTracking())
		return;

	if (Bounds().Contains(where)) {
		if (fBehavior == B_TOGGLE_BEHAVIOR)
			SetValue(_Flag(FLAG_WAS_PRESSED) ? B_CONTROL_OFF : B_CONTROL_ON);

		Invoke();
	} else if (_Flag(FLAG_FLAT))
		Invalidate();

	SetTracking(false);
}
Beispiel #14
0
//------------------------------------------------------------------------------
void BControl::KeyDown(const char *bytes, int32 numBytes)
{
	if (*bytes == B_ENTER || *bytes == B_SPACE)
	{
		if (!fEnabled)
			return;

		if (Value())
			SetValue(B_CONTROL_OFF);
		else
			SetValue(B_CONTROL_ON);
		
		Invoke();
	}
	else
		BView::KeyDown(bytes, numBytes);
}
void
ColorStepView::MessageReceived(BMessage *message)
{
	switch (message->what) {
		case kMSGSliderChanged:
			fSliderPosition = fSlider->Position();
			_CalculatePerformanceSteps();
			Invalidate();
			break;
		case kSteppingChanged:
			Invoke();
			break;
		default:
			BView::MessageReceived(message);
			break;
	}
}
Beispiel #16
0
void
BPictureButton::MouseUp(BPoint point)
{
	if (IsEnabled() && IsTracking()) {
		if (Bounds().Contains(point)) {
			if (fBehavior == B_ONE_STATE_BUTTON) {
				if (Value() == B_CONTROL_ON) {
					snooze(75000);
					SetValue(B_CONTROL_OFF);
				}
			}
			Invoke();
		}

		SetTracking(false);
	}
}
Beispiel #17
0
void
BButton::KeyDown(const char* bytes, int32 numBytes)
{
	if (*bytes == B_ENTER || *bytes == B_SPACE) {
		if (!IsEnabled())
			return;

		SetValue(B_CONTROL_ON);

		// make sure the user saw that
		Window()->UpdateIfNeeded();
		snooze(25000);

		Invoke();
	} else
		BControl::KeyDown(bytes, numBytes);
}
Beispiel #18
0
wxVariant wxAutomationObject::CallMethod(const wxString& member,
        const wxVariant& arg1, const wxVariant& arg2,
        const wxVariant& arg3, const wxVariant& arg4,
        const wxVariant& arg5, const wxVariant& arg6)
{
    const wxVariant** args = new const wxVariant*[6];
    int i = 0;
    if (!arg1.IsNull())
    {
        args[i] = & arg1;
        i ++;
    }
    if (!arg2.IsNull())
    {
        args[i] = & arg2;
        i ++;
    }
    if (!arg3.IsNull())
    {
        args[i] = & arg3;
        i ++;
    }
    if (!arg4.IsNull())
    {
        args[i] = & arg4;
        i ++;
    }
    if (!arg5.IsNull())
    {
        args[i] = & arg5;
        i ++;
    }
    if (!arg6.IsNull())
    {
        args[i] = & arg6;
        i ++;
    }
    wxVariant retVariant;
    if (!Invoke(member, DISPATCH_METHOD, retVariant, i, NULL, args))
    {
        retVariant.MakeNull();
    }
    delete[] args;
    return retVariant;
}
Beispiel #19
0
wxVariant wxAutomationObject::GetProperty(const wxString& property,
        const wxVariant& arg1, const wxVariant& arg2,
        const wxVariant& arg3, const wxVariant& arg4,
        const wxVariant& arg5, const wxVariant& arg6)
{
    const wxVariant** args = new const wxVariant*[6];
    int i = 0;
    if (!arg1.IsNull())
    {
        args[i] = & arg1;
        i ++;
    }
    if (!arg2.IsNull())
    {
        args[i] = & arg2;
        i ++;
    }
    if (!arg3.IsNull())
    {
        args[i] = & arg3;
        i ++;
    }
    if (!arg4.IsNull())
    {
        args[i] = & arg4;
        i ++;
    }
    if (!arg5.IsNull())
    {
        args[i] = & arg5;
        i ++;
    }
    if (!arg6.IsNull())
    {
        args[i] = & arg6;
        i ++;
    }
    wxVariant retVariant;
    if (!Invoke(property, DISPATCH_PROPERTYGET, retVariant, i, NULL, args))
    {
        retVariant.MakeNull();
    }
    delete[] args;
    return retVariant;
}
Beispiel #20
0
TEST(ClosureTest, ClosureDeletesSelf) {
  TestQObject sender;
  TestQObject receiver;
  _detail::ClosureBase* closure = NewClosure(
      &sender, SIGNAL(Emitted()),
      &receiver, SLOT(Invoke()));
  _detail::ObjectHelper* helper = closure->helper();
  QSignalSpy spy(helper, SIGNAL(destroyed()));
  EXPECT_EQ(0, receiver.invoked());
  sender.Emit();
  EXPECT_EQ(1, receiver.invoked());

  EXPECT_EQ(0, spy.count());
  QEventLoop loop;
  QObject::connect(helper, SIGNAL(destroyed()), &loop, SLOT(quit()));
  loop.exec();
  EXPECT_EQ(1, spy.count());
}
Beispiel #21
0
/** \brief Invoked
 * Handles when an icon within the view is invoked. If it is a directory
 * it should, the current directory should move into it. If it is a file
 * it should be opened if possible and otherwise it should be downloaded.
 *
 * \todo Should attempt to dowload and open the remote file if it's not a directory?
 * \todo What should be the default action when the file type is unknown?
 */
void RemoteIconView::Invoked( uint nIcon, IconData* pcData )
{
//	DEBUG( "RemoteIconView::Invoked on icon %i (%s)\n", nIcon, GetIconString( nIcon, 0 ).c_str() );
	
	RemoteIconData* pcRData = (RemoteIconData*)pcData;
	
	if( pcRData->m_cNode.IsDir() ) {
		Path cPath = m_zPath;
		cPath.Append( pcRData->m_cNode.m_zName );
		DEBUG( "RemoteView: Changing to %s\n", cPath.GetPath().c_str() );
		if( m_pcDirChangedMsg ) {
			Message cTmp = *m_pcDirChangedMsg;
			cTmp.AddString( "file/path", cPath.GetPath() );
			Invoke( &cTmp );
		}
		SetPath( cPath.GetPath() );
	}
}
Beispiel #22
0
void
UpDownButton::MouseUp(BPoint point)
{
	if (!IsTracking())
		return;
	
	if((Bounds().top + Bounds().Height()/2) > (fTrackingY + 3))
		SetValue(B_CONTROL_ON);
	else if((Bounds().top + Bounds().Height()/2) < (fTrackingY - 3))
		SetValue(B_CONTROL_OFF);
	
	if(Value()!=fLastValue)
		Invoke();
	SetTracking(false);
	Draw(Bounds());
	Flush();
	fLastValue = Value();
}
TEST_F(InterpreterWithChatbotTest, test_fallback_reply_on_edges)
{
    UserDefinedCommandMock *userDefinedCommandMock = new NiceMock<UserDefinedCommandMock>();
    Chatbot::UserDefinedActionHandler::SharedPtr userDefinedActionHandler(userDefinedCommandMock);

    SingleSessionChatbot chatbot(m_chatbotModel, userDefinedActionHandler);

    ON_CALL(*userDefinedCommandMock, execute(_, _, _)).WillByDefault(Invoke(pushVariables));

    std::vector<std::string> reply1 = chatbot.treatMessage("Je veux un Coca et deux Hein");
    std::vector<std::string> reply2 = chatbot.treatMessage("Bob!");
    std::vector<std::string> reply3 = chatbot.treatMessage("Blabla");

    EXPECT_THAT(reply1, ElementsAre("Je n'ai pas compris votre demande"));
    EXPECT_THAT(reply2, ElementsAre("Que puis-je vous offrir ?"));
    EXPECT_THAT(reply3,
                ElementsAre("Soyez le plus précis possible"));
}
Beispiel #24
0
void
SeekSlider::SetValue(int32 value)
{
    if (value == Value())
        return;

#if __ANTARES__
    BControl::SetValueNoUpdate(value);
#else
    BControl::SetValue(value);
    // this will Invalidate() the whole view
#endif
    Invoke();

    _SetKnobPosition(_KnobPosFor(Bounds(), Value()));

    fLastTrackTime = system_time();
}
TEST_F(InterpreterWithChatbotTest, test_full_scenario)
{
    UserDefinedCommandMock *userDefinedCommandMock = new NiceMock<UserDefinedCommandMock>();
    Chatbot::UserDefinedActionHandler::SharedPtr userDefinedActionHandler(userDefinedCommandMock);

    SingleSessionChatbot chatbot(m_chatbotModel, userDefinedActionHandler);

    ON_CALL(*userDefinedCommandMock, execute(_, _, _)).WillByDefault(Invoke(pushVariables));

    std::vector<std::string> reply1 = chatbot.treatMessage("Bob!");
    std::vector<std::string> reply2 = chatbot.treatMessage("Je veux un Coca et deux Hein");
    std::vector<std::string> reply3 = chatbot.treatMessage("Rien");

    EXPECT_THAT(reply1, ElementsAre("Que puis-je vous offrir ?"));
    EXPECT_THAT(reply2,
                ElementsAre("Vous-voulez quelque chose d'autre ?"));
    EXPECT_THAT(reply3,
                ElementsAre("Veuillez récupérer vos consommations au bar. Vous devrez payer 10.5€."));
}
Beispiel #26
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();
	}
}
Beispiel #27
0
void
TransportButton::MouseCancelPressing()
{
    if (!mouseDown || keyDown)
        return;

    mouseDown = false;

    if (pressingMessage) {
        ASSERT(messageSender);
        PeriodicMessageSender *sender = messageSender;
        messageSender = 0;
        sender->Quit();
    }

    if (donePressingMessage)
        Invoke(donePressingMessage);
    SetValue(0);
}
Beispiel #28
0
uObject* uDelegate::Invoke(size_t count, ...)
{
    va_list ap;
    va_start(ap, count);
    void** args = count > 0
        ? (void**)U_ALLOCA(count * sizeof(void*))
        : NULL;

    for (size_t i = 0; i < count; i++)
        args[i] = va_arg(ap, void*);

    va_end(ap);
    uType* returnType = ((uDelegateType*)__type)->ReturnType;
    void* retval = !U_IS_VOID(returnType)
        ? U_ALLOCA(returnType->ValueSize)
        : NULL;

    Invoke(retval, args, count);
    return uBoxPtr(returnType, retval, NULL, true);
}
void
BRadioButton::MouseDown(BPoint point)
{
	if (!IsEnabled())
		return;

	fOutlined = true;

	if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
		Invalidate();
		SetTracking(true);
		SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
	} else {
		_Redraw();

		BRect bounds = Bounds();
		uint32 buttons;

		do {
			snooze(40000);

			GetMouse(&point, &buttons, true);

			bool inside = bounds.Contains(point);

			if (fOutlined != inside) {
				fOutlined = inside;
				_Redraw();
			}
		} while (buttons != 0);

		if (fOutlined) {
			fOutlined = false;
			_Redraw();
			SetValue(B_CONTROL_ON);
			Invoke();
		} else {
			_Redraw();
		}
	}
}
void ArpKnobControl::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case B_OBSERVER_NOTICE_CHANGE:
			{
				int32 origWhat = 0;
				msg->FindInt32(B_OBSERVE_WHAT_CHANGE, &origWhat);
				if (origWhat == ARPMSG_INT_CONTROL_CHANGED) {
					int32	val;
					if (msg->FindInt32("value", &val) == B_OK) {
						SetValue(val);
						Invoke();
					}
				}
			}
			break;
		default:
			inherited::MessageReceived(msg);
			break;
	}
}