Пример #1
0
action_ref new_transmit_action(sensor_ref s) {
	action_ref tx = new_action();
	action_set_func(tx, &encode_data_for_transmit);
	node_ref arg1 = new_node(s, 0);
	action_set_args(tx, arg1);
	return tx;
}
Пример #2
0
extern void make_fake_action(void)
{   int i;
    char action_sub[MAX_IDENTIFIER_LENGTH+4];

    get_next_token();
    if (token_type != SYMBOL_TT)
    {   ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    sprintf(action_sub, "%s__A", token_text);
    i = symbol_index(action_sub, -1);

    if (!(sflags[i] & UNKNOWN_SFLAG))
    {   ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    assign_symbol(i, ((grammar_version_number==1)?256:4096)+no_fake_actions++,
        FAKE_ACTION_T);

    new_action(token_text, i);
    if (debugfile_switch)
    {   write_debug_byte(FAKE_ACTION_DBR);
        write_debug_byte(svals[i]/256);
        write_debug_byte(svals[i]%256);
        write_debug_string(token_text);
    }
    return;
}
Пример #3
0
action_ref action_copy (action_ref action_proto) {
	if(!action_proto) return FAILURE;
	action_ref result = new_action();
	if(result) {
		result->action_func = action_proto->action_func;
		result->arguments = node_copy_list(action_proto->arguments);
		return result;
	}
	return FAILURE;
}
Пример #4
0
/**
 * Add the actions to the manager actions table
 * @param manager Management struct to build into
 */
void action_add_to_manager( Management manager ) {

	// add exit action to actions table
	Action quit = new_action( action_quit );
	hash_table_add( manager->actions, (void *)"quit", quit);

    /* --------------------
     * movement actions
     */
    // north
    Action north = new_action_linked( action_north, 2 );
    hash_table_add( manager->actions, (void *)"north", north);
    hash_table_add( manager->actions, (void *)"n", north);
    
    // south
    Action south = new_action_linked( action_south, 2 );
    hash_table_add( manager->actions, (void *)"south", south);
    hash_table_add( manager->actions, (void *)"s", south);
    
    // east
    Action east = new_action_linked( action_east, 2 );
    hash_table_add( manager->actions, (void *)"east", east);
    hash_table_add( manager->actions, (void *)"e", east);
    
    // west
    Action west = new_action_linked( action_west, 2 );
    hash_table_add( manager->actions, (void *)"west", west);
    hash_table_add( manager->actions, (void *)"w", west);
    
    /* --------------------
     * common actions
     */

	// add look action to actions table
	Action look = new_action( action_look );
	hash_table_add( manager->actions, (void *)"look", look);

	// add look action to actions table
	Action shout = new_action( action_shout );
	hash_table_add( manager->actions, (void *)"shout", shout);
}
Пример #5
0
Файл: uzbl.c Проект: dusanx/uzbl
static void
add_binding (const gchar *key, const gchar *act) {
    char **parts = g_strsplit(act, " ", 2);
    Action *action;

    if (!parts)
        return;

    //Debug:
    printf ("Binding %-10s : %s\n", key, act);
    action = new_action(parts[0], parts[1]);
    g_hash_table_insert(bindings, g_strdup(key), action);

    g_strfreev(parts);
}
Пример #6
0
extern assembly_operand action_of_name(char *name)
{
    /*  Returns the action number of the given name, creating it as a new
        action name if it isn't already known as such.                       */

    char action_sub[MAX_IDENTIFIER_LENGTH+4];
    int j;
    assembly_operand AO;

    sprintf(action_sub, "%s__A", name);
    j = symbol_index(action_sub, -1);

    if (stypes[j] == FAKE_ACTION_T)
    {   AO.value = svals[j];
        AO.marker = 0;
        if (!glulx_mode)
          AO.type = LONG_CONSTANT_OT;
        else
          set_constant_ot(&AO);
        sflags[j] |= USED_SFLAG;
        return AO;
    }

    if (sflags[j] & UNKNOWN_SFLAG)
    {
        if (no_actions>=MAX_ACTIONS) memoryerror("MAX_ACTIONS",MAX_ACTIONS);
        new_action(name, no_actions);
        action_symbol[no_actions] = j;
        assign_symbol(j, no_actions++, CONSTANT_T);
        sflags[j] |= ACTION_SFLAG;
    }
    sflags[j] |= USED_SFLAG;

    AO.value = svals[j];
    AO.marker = ACTION_MV;
    if (!glulx_mode) {
      AO.type = (module_switch)?LONG_CONSTANT_OT:SHORT_CONSTANT_OT;
      if (svals[j] >= 256) AO.type = LONG_CONSTANT_OT;
    }
    else {
      AO.type = CONSTANT_OT;
    }
    return AO;
}
Пример #7
0
extern void make_fake_action(void)
{   int i;
    char action_sub[MAX_IDENTIFIER_LENGTH+4];
    debug_location_beginning beginning_debug_location =
        get_token_location_beginning();

    get_next_token();
    if (token_type != SYMBOL_TT)
    {   discard_token_location(beginning_debug_location);
        ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    sprintf(action_sub, "%s__A", token_text);
    i = symbol_index(action_sub, -1);

    if (!(sflags[i] & UNKNOWN_SFLAG))
    {   discard_token_location(beginning_debug_location);
        ebf_error("new fake action name", token_text);
        panic_mode_error_recovery(); return;
    }

    assign_symbol(i, ((grammar_version_number==1)?256:4096)+no_fake_actions++,
        FAKE_ACTION_T);

    new_action(token_text, i);

    if (debugfile_switch)
    {   debug_file_printf("<fake-action>");
        debug_file_printf("<identifier>##%s</identifier>", token_text);
        debug_file_printf("<value>%d</value>", svals[i]);
        get_next_token();
        write_debug_locations
            (get_token_location_end(beginning_debug_location));
        put_token_back();
        debug_file_printf("</fake-action>");
    }

    return;
}
Пример #8
0
void theme::add_object(const config& cfg)
{
	if(const config& c = cfg.child("main_map")) {
		main_map_ = object(c);
	}

	if(const config& c = cfg.child("mini_map")) {
		mini_map_ = object(c);
	}

	if(const config& c = cfg.child("palette")) {
		palette_ = object(c);
	}

	if(const config& status_cfg = cfg.child("status")) {
		for(const config::any_child& i : status_cfg.all_children_range()) {
			status_.emplace(i.key, status_item(i.cfg));
		}
		if(const config& unit_image_cfg = status_cfg.child("unit_image")) {
			unit_image_ = object(unit_image_cfg);
		} else {
			unit_image_ = object();
		}
	}

	for(const config& p : cfg.child_range("panel")) {
		panel new_panel(p);
		set_object_location(new_panel, p["rect"], p["ref"]);
		panels_.push_back(new_panel);
	}

	for(const config& lb : cfg.child_range("label")) {
		label new_label(lb);
		set_object_location(new_label, lb["rect"], lb["ref"]);
		labels_.push_back(new_label);
	}

	for(const config& m : cfg.child_range("menu")) {
		menu new_menu(m);
		DBG_DP << "adding menu: " << (new_menu.is_context() ? "is context" : "not context") << "\n";
		if(new_menu.is_context())
			context_ = new_menu;
		else {
			set_object_location(new_menu, m["rect"], m["ref"]);
			menus_.push_back(new_menu);
		}

		DBG_DP << "done adding menu...\n";
	}

	for(const config& a : cfg.child_range("action")) {
		action new_action(a);
		DBG_DP << "adding action: " << (new_action.is_context() ? "is context" : "not context") << "\n";
		if(new_action.is_context())
			action_context_ = new_action;
		else {
			set_object_location(new_action, a["rect"], a["ref"]);
			actions_.push_back(new_action);
		}

		DBG_DP << "done adding action...\n";
	}

	for(const config& s : cfg.child_range("slider")) {
		slider new_slider(s);
		DBG_DP << "adding slider\n";
		set_object_location(new_slider, s["rect"], s["ref"]);
		sliders_.push_back(new_slider);

		DBG_DP << "done adding slider...\n";
	}

	if(const config& c = cfg.child("main_map_border")) {
		border_ = border_t(c);
	}
}
Пример #9
0
BOOL OpWindowList::OnInputAction(OpInputAction* action)
{
	switch (action->GetAction())
	{
		case OpInputAction::ACTION_GET_ACTION_STATE:
		{
			OpInputAction* child_action = action->GetChildAction();
			OpTreeModelItem* item = GetSelectedItem();
			DesktopWindow* dw = item
					? static_cast<DesktopWindowCollectionItem*>(item)
							->GetDesktopWindow()
					: 0;

			switch(child_action->GetAction())
			{
				case OpInputAction::ACTION_MAXIMIZE_PAGE:
				case OpInputAction::ACTION_MINIMIZE_PAGE:
				case OpInputAction::ACTION_RESTORE_PAGE:
				case OpInputAction::ACTION_ACTIVATE_WINDOW:
				case OpInputAction::ACTION_DETACH_PAGE:
					{
						child_action->SetEnabled( dw && dw->GetType() != WINDOW_TYPE_BROWSER && dw->GetWorkspace() );
					}
					return TRUE;

				case OpInputAction::ACTION_RELOAD:
					{
						child_action->SetEnabled( dw && dw->GetType() == WINDOW_TYPE_DOCUMENT && dw->GetWorkspace() );
					}
					return TRUE;

				case OpInputAction::ACTION_LOCK_PAGE:
				case OpInputAction::ACTION_UNLOCK_PAGE:
					{
						UINT32 items = GetSelectedItemCount();
						if(items > 1)
						{
							child_action->SetSelected(FALSE);
						}
						else
						{
							child_action->SetEnabled( dw && dw->GetType() != WINDOW_TYPE_BROWSER && dw->GetWorkspace() );
							if(child_action->GetAction() == OpInputAction::ACTION_LOCK_PAGE)
							{
								child_action->SetSelected( dw && dw->IsLockedByUser());
							}
							else
							{
								child_action->SetSelected( dw && !dw->IsLockedByUser());
							}
						}
					}
					return TRUE;

				case OpInputAction::ACTION_CLOSE_PAGE:
					{
						UINT32 items = GetSelectedItemCount();
						if(items > 1)
						{
							child_action->SetEnabled(TRUE);
						}
						else
						{
							child_action->SetEnabled( dw && dw->IsClosableByUser());
						}
					}
					return TRUE;

				case OpInputAction::ACTION_DISSOLVE_TAB_GROUP:
				case OpInputAction::ACTION_CLOSE_TAB_GROUP:
					child_action->SetEnabled(item && item->GetType() == WINDOW_TYPE_GROUP);
					return TRUE;
			}
			return FALSE;
		}

		case OpInputAction::ACTION_LOCK_PAGE:
		case OpInputAction::ACTION_UNLOCK_PAGE:
			{
				OpINT32Vector items;
				INT32 idx;
				INT32 count = GetSelectedItems(items, FALSE);

				for(idx = 0; idx < count; idx++)
				{
					INT32 id = items.Get((UINT32)idx);
					OpTreeModelItem* item = GetItemByPosition(id);
					if (item)
					{
						DesktopWindow *window =
								static_cast<DesktopWindowCollectionItem*>(item)
										->GetDesktopWindow();
						if(window != NULL)
						{
							OpPagebar* pagebar = NULL;

							window->SetLockedByUser(window->IsLockedByUser() ? FALSE : TRUE);

							pagebar = (OpPagebar *)window->GetWidgetByType(OpTypedObject::WIDGET_TYPE_PAGEBAR);
							if(pagebar)
							{
								INT32 pos = pagebar->FindWidgetByUserData(window);
								if (pos >= 0)
								{
									OpWidget *button = pagebar->GetWidget(pos);
									if(button && button->IsOfType(WIDGET_TYPE_PAGEBAR_BUTTON))
									{
										pagebar->OnLockedByUser(static_cast<PagebarButton *>(button), window->IsLockedByUser());
									}
									else
									{
										if (button)
											button->Relayout(TRUE, TRUE);
									}
								}
							}
						}
					}
				}
				g_input_manager->UpdateAllInputStates();
			}
			return TRUE;

		// Only the first.
		case OpInputAction::ACTION_ACTIVATE_WINDOW:
		{
			OpTreeModelItem* item = GetSelectedItem();
			if (item)
			{
				DesktopWindow* window =
						static_cast<DesktopWindowCollectionItem*>(item)
								->GetDesktopWindow();
				if (!window)
					break;

				window->Activate();

#if defined(_UNIX_DESKTOP_)
				// We cannot do Raise() in Activate() in unix because focus-follows-mouse
				// focus mode shall activate but not auto raise a window [espen 2006-09-28]
				if( window->GetType() == WINDOW_TYPE_BROWSER )
				{
					window->GetOpWindow()->Raise();
				}
				else if( window->GetParentDesktopWindow() )
				{
					window->GetParentDesktopWindow()->GetOpWindow()->Raise();
					window->GetOpWindow()->Raise();
				}
#endif

			}
			return TRUE;
		}

		case OpInputAction::ACTION_DELETE:
		{
			OpInputAction new_action(OpInputAction::ACTION_CLOSE_PAGE);
			new_action.SetActionData(2);
			return OnInputAction(&new_action);
		}

		case OpInputAction::ACTION_SHOW_CONTEXT_MENU:
		{
			OnContextMenu(GetBounds().Center(), NULL, action->IsKeyboardInvoked());
			return TRUE;
		}
		case OpInputAction::ACTION_CLOSE_PAGE:
		{
			OpINT32Vector items;
			INT32 idx;
			INT32 count = GetSelectedItems(items, FALSE);

			for(idx = 0; idx < count; idx++)
			{
				INT32 id = items.Get((UINT32)idx);
				OpTreeModelItem* item = GetItemByPosition(id);
				if (item)
				{
					if (item->GetType() == WINDOW_TYPE_BROWSER)
					{
						BrowserDesktopWindow *window =
								static_cast<BrowserDesktopWindow*>(
										static_cast<DesktopWindowCollectionItem*>(
												item)->GetDesktopWindow());
						window->Close(FALSE, TRUE, FALSE);
						return TRUE;
					}
					else
					{
						DesktopWindow *window =
								static_cast<DesktopWindowCollectionItem*>(item)
										->GetDesktopWindow();
						if(window != NULL && window->IsClosableByUser())
						{
							window->Close(FALSE, TRUE, FALSE);
						}
					}
				}
			}
		}
		return TRUE;

		case OpInputAction::ACTION_FOCUS_NEXT_WIDGET:
		case OpInputAction::ACTION_FOCUS_PREVIOUS_WIDGET:
			return OpTreeView::OnInputAction(action);

		case OpInputAction::ACTION_DISSOLVE_TAB_GROUP:
		{
			DesktopWindowCollectionItem* item = static_cast<DesktopWindowCollectionItem*>(GetSelectedItem());
			if (item && item->GetType() == WINDOW_TYPE_GROUP)
				item->GetModel()->UnGroup(item);
			return TRUE;
		}
		case OpInputAction::ACTION_CLOSE_TAB_GROUP:
		{
			DesktopWindowCollectionItem* item = static_cast<DesktopWindowCollectionItem*>(GetSelectedItem());
			if (item && item->GetType() == WINDOW_TYPE_GROUP)
				item->GetModel()->DestroyGroup(item);
			return TRUE;
		}

		default:
		{
			// Prevent sending lowlevel events to desktop windows (bug #227626) [espen 2007-02-22]
			if( action->GetAction() < OpInputAction::LAST_ACTION )
			{
				OpINT32Vector items;
				int item_count = GetSelectedItems(items);
				BOOL handled = FALSE;

				for (INT32 i = 0; i < item_count; i++)
				{
					DesktopWindow* window = GetDesktopWindowByPosition(GetItemByID(items.Get(i)));
					if( window && window->OnInputAction(action) )
					{
						handled = TRUE;
					}
				}

				if (handled)
					return TRUE;
			}
		}
	}

	return OpTreeView::OnInputAction(action);
}
Пример #10
0
// staticなメンバー関数を使った実装例。
TEST(FunctionTest2, StaticMemFunc)
{
  ActionBase *a = new_action(std::bind(StaticMemFunc::add_static, std::placeholders::_1, std::placeholders::_2));
  EXPECT_EQ(5, a->invoke(2, 3));
}
Пример #11
0
// 関数オブジェクトを使った実装例。
TEST(FunctionTest2, FuncObj)
{
  FuncObj ta;
  ActionBase *a = new_action(ta);
  EXPECT_EQ(5, a->invoke(2, 3));
}
Пример #12
0
// ローカル関数を使った実装例。
TEST(FunctionTest2, LocalFunc)
{
  ActionBase *a = new_action(&add);
  EXPECT_EQ(5, a->invoke(2, 3));
}
Пример #13
0
// staticではないメンバー関数を使った実装例。
TEST(FunctionTest2, MemFunc)
{
  MemFunc ta;
  ActionBase *a = new_action(std::bind(&MemFunc::add, &ta, std::placeholders::_1, std::placeholders::_2));
  EXPECT_EQ(5, a->invoke(2, 3));
}
Пример #14
0
Action new_action_linked( void *(*action_func)( const char *, User, Management ), char links )
{
    Action action = new_action( action_func );
    action->links = links;
    return action;
}
Пример #15
0
event_ref new_timer_event(uint8_t timer, uint16_t period, uint8_t repeat, uint16_t repeat_count) {
	event_ref e = 0;
	action_ref check_action = 0;

	node_ref period_arg = 0;
	node_ref trigger_arg = 0;

	time_ref time_trigger = 0;
	time_ref time_period = 0;


	for(;;) {

		// Create a new time period
		time_period = new_time();
		if(!time_period) break;
		// Set up the period
		if(timer == CLOCK_TIME) {
			time_period->clock_time = period;
		} else if (timer == MILLISECONDS) {
			time_period->milliseconds = period;
		} else if (timer == SECONDS) {
			time_period->seconds = period;
		} else if (timer == MINUTES) {
			time_period->minutes = period;
		} else if (timer == HOURS) {
			time_period->hours = period;
		} else if (timer == DAYS) {
			time_period->days = period;
		}

		// Create a new time trigger
		time_trigger = new_time();
		if(!time_trigger) break;
		// Set up the trigger = global + period
		add_time_to_time(time_trigger, global_time());
		add_time_to_time(time_trigger, time_period);

		// Create a new event
		e = new_event();
		if(!e) break;

		// Create a new action
		check_action = new_action();
		if(!check_action) break;
		// Set its function
		action_set_func(check_action, &check_time_args);

		// Create a trigger arg
		trigger_arg = new_node(time_trigger, &time_delete);
		if(!trigger_arg) break;

		// Create the period arg
		period_arg = new_node(time_period, &time_delete);
		if(!period_arg) break;
		node_append(period_arg, trigger_arg);

		action_set_args(check_action, period_arg);
		event_set_check(e, check_action);
		event_set_repeat(e, repeat, repeat_count);

		return e;
	}

	event_delete(&e);

	node_delete(&period_arg);
	node_delete(&trigger_arg);

	action_delete(&check_action);

	time_delete(&time_period);
	time_delete(&time_trigger);

	return FAILURE;
}
Пример #16
0
sensor_ref create_temperature_sensor(uint8_t loc, time_ref period, uint16_t size) {
	sensor_ref * temperature_sensor;
	uint8_t (*delete_func)();
	uint8_t (*enable_func)();
	uint8_t (*disable_func)();
	uint8_t channel;

	if(loc == 'I') {
		temperature_sensor = &internal_temperature_sensor;
		delete_func = &delete_internal_temperature_sensor;
		enable_func = &enable_internal_temperature_sensor;
		disable_func = &disable_internal_temperature_sensor;
		channel = TEMPERATURE_ADC;
	} else if (loc == 'A') {
		temperature_sensor = &external_temperature_sensor_A;
		delete_func = &delete_external_temperature_sensor_A;
		enable_func = &enable_external_temperature_sensor_A;
		disable_func = &disable_external_temperature_sensor_A;
		channel = PORT_A_ADC;
	} else if (loc == 'B') {
		temperature_sensor = &external_temperature_sensor_B;
		delete_func = &delete_external_temperature_sensor_B;
		enable_func = &enable_external_temperature_sensor_B;
		disable_func = &disable_external_temperature_sensor_B;
		channel = PORT_B_ADC;
	} else {
		return FAILURE;
	}

	if(*temperature_sensor) {
		// We already have one there
		if((time_cmp(period, sensor_get_period(*temperature_sensor)) == 0) && size == sensor_get_size(*temperature_sensor)) {
			// If they are the same...do nothing
			return *temperature_sensor;
		} else {
			// They are different, so delete the old one
			delete_func();
		}
	}


	action_ref transmit_action = 0;
	action_ref lookup_temp_action = 0;

	node_ref temperature_node = 0;

	for(;;) {

		*temperature_sensor = new_sensor('T', channel, period, size);
		if(!*temperature_sensor) break;

		// Create the lookup_temp_action
		lookup_temp_action = new_action();
		if(!lookup_temp_action) break;
		action_set_func(lookup_temp_action, &fix_temperature);

		temperature_node = new_node(*temperature_sensor, 0);
		if(!temperature_node) break;
		action_set_args(lookup_temp_action, temperature_node);

		sensor_add_action_on_data_full(*temperature_sensor, lookup_temp_action);




		// Create the transmit action
		transmit_action = new_transmit_action(*temperature_sensor);
		if(!transmit_action) break;
		sensor_add_action_on_data_full(*temperature_sensor, transmit_action);

		sensor_set_delete_func(*temperature_sensor, delete_func);
		sensor_set_enable_func(*temperature_sensor, enable_func);
		sensor_set_disable_func(*temperature_sensor, disable_func);

		return *temperature_sensor;
	}

	delete_func();
	node_delete(&temperature_node);
	action_delete(&lookup_temp_action);
	action_delete(&transmit_action);

	return FAILURE;


}
Пример #17
0
// lambdaでの実装例。
TEST(FunctionTest2, BoostLambda)
{
  auto a = new_action([](int x, int y){ return x + y; });
  EXPECT_EQ(5, a->invoke(2, 3));
}