Exemple #1
0
bool key_button::handle_event(const SDL_Event& event, bool claimed)
{
    if(claimed) {
		current_button_image_set_ = normal_button_image_set_;
    }

	if(event.type == SDL_MOUSEMOTION && !grab_keys_) {
		const SDL_MouseMotionEvent& e = event.motion;
		if(current_button_image_set_ == depressed_button_image_set_) {
			//pass
		} else if(in_button(e.x,e.y)) {
			current_button_image_set_ = focus_button_image_set_;
		} else {
			current_button_image_set_ = normal_button_image_set_;
		}
	} else if(event.type == SDL_MOUSEBUTTONDOWN) {
		const SDL_MouseButtonEvent& e = event.button;
		if(in_button(e.x,e.y)) {
			current_button_image_set_ = depressed_button_image_set_;
		}
	} else if(event.type == SDL_MOUSEBUTTONUP) {
		const SDL_MouseButtonEvent& e = event.button;
		if(current_button_image_set_ == depressed_button_image_set_) {
			if(in_button(e.x,e.y)) {
				current_button_image_set_ = focus_button_image_set_;
				grab_keys_ = true;
				dynamic_cast<graphical_font_label*>(label_.get())->set_text("...");
				claimed = true;
			} else {
				current_button_image_set_ = normal_button_image_set_;
			}
		} else if (grab_keys_) {
			dynamic_cast<graphical_font_label*>(label_.get())->set_text(get_key_name(key_));
			current_button_image_set_ = normal_button_image_set_;
			grab_keys_ = false;
		}
	}

	if(event.type == SDL_KEYDOWN && grab_keys_) {
		key_ = event.key.keysym.sym;
		if(key_ != SDLK_RETURN && key_ != SDLK_ESCAPE) {
			dynamic_cast<graphical_font_label*>(label_.get())->set_text(get_key_name(key_));
			claimed = true;
			current_button_image_set_ = normal_button_image_set_;
			grab_keys_ = false;
		}
	}

	return claimed;
}
Exemple #2
0
static void key_callback(GLFWwindow* window, int key, int action)
{
    const char* name = get_key_name(key);

    printf("%08x at %0.3f: Key 0x%04x", counter++, glfwGetTime(), key);

    if (name)
        printf(" (%s) was %s\n", name, get_action_name(action));
    else
        printf(" was %s\n", get_action_name(action));

    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_C:
        {
            closeable = !closeable;

            printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
            break;
        }
    }
}
  /**
   * Fetches the contents of a block.
   * Returns true on success and false on failure.
   */
  bool fetch_block(char* output, 
                   size_t block_number,
                   size_t startpos, 
                   size_t length) {
    auto& bc = block_cache::get_instance();
    std::string key = get_key_name(block_number);
    int64_t ret = bc.read(key, output, startpos, startpos + length);
    if (ret == length) return true;

    logstream(LOG_INFO) << "Fetching " << sanitize_url(m_filename) << " Block " << block_number << std::endl;
    // ok. failure... no such block or block is bad. We read it ourselves.
    // read the whole block
    auto block_start = block_number * READ_CACHING_BLOCK_SIZE;
    auto block_end = std::min(block_start +  READ_CACHING_BLOCK_SIZE, m_file_size);
    // seek to the block and read the whole block at once
    auto& contents = get_contents();
    contents->seek(block_start, std::ios_base::beg, std::ios_base::in);
    std::string block_contents(block_end - block_start, 0);
    auto bytes_read = contents->read(&(block_contents[0]),
                                     block_end - block_start);
    // read failed.
    if (bytes_read < block_end - block_start) return false;

    // write the block
    bool write_block_ok = bc.write(key, block_contents);
    if (write_block_ok == false) {
      logstream(LOG_ERROR) << "Unable to write block " << key << std::endl;
      // still ok. we can continue. but too many of these are bad.
    }
    // since we just read the block, lets fill the output
    const char* src = block_contents.c_str();
    memcpy(output, src + startpos, length);
    return true;
  }
std::string InputOutputException::get_message(ModelObject *o) const {
  std::ostringstream oss;
  switch (get_entity()) {
    case DERIVATIVE:
      if (o->get_model()->get_stage() == BEFORE_EVALUATING) {
        oss << "Derivatives cannot be read before evaluating.";
        break;
      }
    default:
      switch (get_operation()) {
        case GET:
          oss << "Not in input list.";
          break;
        case SET:
        case ADD:
        case REMOVE:
          oss << "Not in output list.";
          break;
        default:
          // should not exist
          oss << "Unknown read/write error";
      }
      break;
  };
  oss << " Violating object: \"" << o->get_name() << "\".";
  if (particle_index_ >= 0) {
    oss << " Attribute " << get_key_name() << " of particle \""
        << o->get_model()
               ->get_particle(ParticleIndex(get_particle_index()))
               ->get_name() << "\" with id " << get_particle_index();
  } else {
    oss << "Container \"" << container_name_ << "\".";
  }
  return oss.str();
}
Exemple #5
0
static bool
append_key(char *buf, size_t *pos, const struct keybinding *keybinding, bool all)
{
	const char *sep = *pos > 0 ? ", " : "";
	const char *keyname = get_key_name(keybinding->key, keybinding->keys, all);

	return string_nformat(buf, BUFSIZ, pos, "%s%s", sep, keyname);
}
Exemple #6
0
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    Slot* slot = glfwGetWindowUserPointer(window);
    const char* name = glfwGetKeyName(key, scancode);

    if (name)
    {
        printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (%s) (with%s) was %s\n",
               counter++, slot->number, glfwGetTime(), key, scancode,
               get_key_name(key),
               name,
               get_mods_name(mods),
               get_action_name(action));
    }
    else
    {
        printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (with%s) was %s\n",
               counter++, slot->number, glfwGetTime(), key, scancode,
               get_key_name(key),
               get_mods_name(mods),
               get_action_name(action));
    }

    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_C:
        {
            slot->closeable = !slot->closeable;

            printf("(( closing %s ))\n", slot->closeable ? "enabled" : "disabled");
            break;
        }

        case GLFW_KEY_L:
        {
            const int state = glfwGetInputMode(window, GLFW_LOCK_KEY_MODS);
            glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, !state);

            printf("(( lock key mods %s ))\n", !state ? "enabled" : "disabled");
            break;
        }
    }
}
void button_released(int type)
{
	char key_name[16];

	get_key_name(type, key_name);
	HS_LOG_TIME("%s (%d) released", key_name, type);
	atomic_set(&hi->btn_state, 0);
	input_report_key(hi->input, type, 0);
	input_sync(hi->input);
}
Exemple #8
0
void get_keys_name(struct key_struct* key, char* buf)
{
    int i=0;
    buf[0]=0;
    while (i<10&&key->mapped[i]) {
        get_key_name(key->mapped[i], buf+strlen(buf));
        strcat(buf, " ");
        i++;
    }
    buf[strlen(buf)-1] = 0;
}
Exemple #9
0
key_button::key_button(SDLKey key, BUTTON_RESOLUTION button_resolution)
  : label_(widget_ptr(new graphical_font_label(get_key_name(key), "door_label", 2))),
	key_(key), button_resolution_(button_resolution),
	normal_button_image_set_(framed_gui_element::get("regular_button")),
	depressed_button_image_set_(framed_gui_element::get("regular_button_pressed")),
	focus_button_image_set_(framed_gui_element::get("regular_button_focus")),
	current_button_image_set_(normal_button_image_set_), grab_keys_(false)
	
{
	set_dim(label_->width()+hpadding*2,label_->height()+vpadding*2);
}
Exemple #10
0
static int set_keydefine_show(struct _select_def *conf, int i)
{
    char buf[120], buf2[20], buf3[200];
    get_key_name(keymem[i-1].key, buf2);
    get_keys_name(keymem+i-1, buf);
    get_modes_name(keymem+i-1, buf3);
    buf2[6]=0;
    buf[36]=0;
    buf3[32]=0;
    prints("%-6s  %-36s  %-32s", buf2, buf, buf3);
    return SHOW_CONTINUE;
}
Exemple #11
0
void loop()
{
	int val = get_key(analogRead(0));
	if (val == -1)
		digitalWrite(7, LOW);
	else
		digitalWrite(7, HIGH);
	const char *str = get_key_name(val);
	u8g.firstPage();
	do  {
		u8g.setFont(u8g_font_unifont);
		u8g.drawStr(45, 35, str);
	} while( u8g.nextPage() );
}
Exemple #12
0
static int set_keydefine_select(struct _select_def *conf)
{
    char buf[20],buf2[120],buf3[240];
    clear();
    get_key_name(keymem[conf->pos-1].key,buf);
    get_keys_name(keymem+conf->pos-1,buf2);
    get_modes_name(keymem+conf->pos-1,buf3);
    move(1,0);
    prints("自定义键: %s\n\n", buf);
    prints("替换序列: %s\n\n", buf2);
    prints("允许模式: %s\n\n", buf3);
    pressanykey();

    return SHOW_REFRESH;
}
static void GLFWCALL key_callback(int key, int action)
{
    const char* name = get_key_name(key);

    printf("%08x at %0.3f: Key 0x%04x", counter++, glfwGetTime(), key);

    if (name)
        printf(" (%s) was %s\n", name, get_action_name(action));
    else if (isgraph(key))
        printf(" (%c) was %s\n", key, get_action_name(action));
    else
        printf(" was %s\n", get_action_name(action));

    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case 'R':
        {
            keyrepeat = !keyrepeat;
            if (keyrepeat)
                glfwEnable(GLFW_KEY_REPEAT);
            else
                glfwDisable(GLFW_KEY_REPEAT);

            printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
            break;
        }

        case 'S':
        {
            systemkeys = !systemkeys;
            if( systemkeys )
                glfwEnable(GLFW_SYSTEM_KEYS);
            else
                glfwDisable(GLFW_SYSTEM_KEYS);

            printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
            break;
        }
    }
}
Exemple #14
0
static void key_callback(GLFWwindow window, int key, int action)
{
    const char* name = get_key_name(key);

    printf("%08x at %0.3f: Key 0x%04x", counter++, glfwGetTime(), key);

    if (name)
        printf(" (%s) was %s\n", name, get_action_name(action));
    else
        printf(" was %s\n", get_action_name(action));

    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_R:
        {
            keyrepeat = !keyrepeat;
            glfwSetInputMode(window, GLFW_KEY_REPEAT, keyrepeat);

            printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
            break;
        }

        case GLFW_KEY_S:
        {
            systemkeys = !systemkeys;
            glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys);

            printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
            break;
        }

        case GLFW_KEY_C:
        {
            closeable = !closeable;

            printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
            break;
        }
    }
}
Exemple #15
0
static bool
foreach_key_visit(struct key_visitor_state *state, const char *group,
		  enum request request,
		  const struct request_info *req_info, const struct run_request *run_req)
{
	struct keymap *keymap = state->keymap;
	int i;

	if (state->group == group)
		group = NULL;

	if (state->combine_keys) {
		const char *key = get_keys(keymap, request, true);

		if (!key || !*key)
			return true;

		if (group)
			state->group = group;
		return state->visitor(state->data, group, keymap, request,
				      key, req_info, run_req);
	}

	for (i = 0; i < keymap->size; i++) {
		if (keymap->data[i]->request == request) {
			struct keybinding *keybinding = keymap->data[i];
			const char *key = get_key_name(keybinding->key, keybinding->keys, false);

			if (!key || !*key)
				continue;

			if (!state->visitor(state->data, group, keymap, request,
					    key, req_info, run_req))
				return false;

			if (group)
				state->group = group;
			group = NULL;
		}
	}

	return true;
}
Exemple #16
0
Fichier : help.c Projet : zhez/tig
static void
help_open_keymap_run_requests(struct help_request_iterator *iterator)
{
	struct view *view = iterator->view;
	struct keymap *keymap = iterator->keymap;
	char buf[SIZEOF_STR];
	const char *group = "External commands:";
	int i;

	for (i = 0; TRUE; i++) {
		struct run_request *req = get_run_request(REQ_NONE + i + 1);
		const char *key;

		if (!req)
			break;

		if (req->keymap != keymap)
			continue;

		key = get_key_name(req->key);
		if (!*key)
			key = "(no key defined)";

		if (iterator->add_title && help_open_keymap_title(view, keymap))
			return;
		iterator->add_title = FALSE;

		if (group) {
			add_line_text(view, group, LINE_HELP_GROUP);
			group = NULL;
		}

		if (!argv_to_string(req->argv, buf, sizeof(buf), " "))
			return;

		add_line_format(view, LINE_DEFAULT, "    %-25s `%s`", key, buf);
	}
}
  // Because the device has bidirectional tag, close will be called 
  // twice, one with the std::ios_base::in, followed by out.
  // Only close the file when the close tag matches the actual file type.
  void close(std::ios_base::openmode mode = std::ios_base::openmode()) {
    if (mode == std::ios_base::out && m_writing) {
      if (m_contents) m_contents->close(mode);
      m_contents.reset();
      // evict all blocks for this key
      auto& bc = block_cache::get_instance();
      size_t block_number = 0;
      while(1) {
        std::string key = get_key_name(block_number);
        if (bc.evict_key(key) == false) break;
        ++ block_number;
      }
      // evict the file size cache
      {
        std::lock_guard<mutex> file_size_guard(m_filesize_cache_mutex);
        m_filename_to_filesize_map.erase(m_filename);
      }

    } else if (mode == std::ios_base::in && !m_writing) {
      if (m_contents) m_contents->close(mode);
      m_contents.reset();
    }
  }
Exemple #18
0
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    Slot* slot = glfwGetWindowUserPointer(window);

    printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (with%s) was %s\n",
           counter++, slot->number, glfwGetTime(), key, scancode,
           get_key_name(key),
           get_mods_name(mods),
           get_action_name(action));

    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_C:
        {
            slot->closeable = !slot->closeable;

            printf("(( closing %s ))\n", slot->closeable ? "enabled" : "disabled");
            break;
        }
    }
}
Exemple #19
0
void handle_key(int key)
{
        const char *keyname;
	char *str;
        int add_history;

	/* Quit if we get 5 CTRL-C's in a row. */
	if (key != CTRL('c'))
		sigint_count = 0;
	else if (++sigint_count >= 5)
		raise(SIGTERM);

	idle_time = time(NULL);

	if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) {
		handle_key_redirect(key);
		return;
	}

	switch (key)
	{
	case 27:
		key = getch();
		if (key == 'O') {
			key = getch();
			switch (key) {
			case 'a':
                                str = g_strdup("CTRL-Up");
				break;
			case 'b':
                                str = g_strdup("CTRL-Down");
				break;
			case 'c':
                                str = g_strdup("CTRL-Right");
                                break;
			case 'd':
                                str = g_strdup("CTRL-Left");
				break;
			default:
				return;
			}
		} else if (key == toupper(key) && key != tolower(key))
			str = g_strdup_printf("ALT-SHIFT-%c", key);
		else {
			keyname = get_key_name(key);
			if (keyname != NULL)
				str = g_strdup_printf("ALT-%s", keyname);
			else if (key >= 32 && key < 256 && key != 128)
				str = g_strdup_printf("ALT-%c", toupper(key));
			else {
				str = g_strdup_printf("ALT-%d", key);
			}
		}
		key_pressed(str, NULL);
		g_free(str);
		break;
	case '\n':
	case 13:
		key_pressed("Return", NULL);

		str = gui_entry_get_text();
		if (*str == '\0') break;

		translate_output(str);

                add_history = TRUE;
		if (redir == NULL) {
			signal_emit("send command", 3, str,
				    active_win->active_server,
				    active_win->active);
		} else {
			if (redir->flags & ENTRY_REDIRECT_FLAG_HIDDEN)
                                add_history = FALSE;
			handle_entry_redirect(str);
		}

		if (add_history) {
			command_history_add(active_win, gui_entry_get_text(),
					    FALSE);
		}
		gui_entry_set_text("");
		command_history_clear_pos(active_win);
		break;

	default:
                keyname = get_key_name(key);
		if (keyname != NULL) {
			key_pressed(keyname, NULL);
			break;
		}
		if (key >= 0 && key < 32) {
			str = g_strdup_printf("CTRL-%c",
					      key == 0 ? ' ' :
					      (key == 31 ? '-' : key+'A'-1));
			key_pressed(str, NULL);
			g_free(str);
			break;
		}

		if (key < 256) {
			char str[2];

			str[0] = toupper(key); str[1] = '\0';
			key_pressed(str, NULL);
			gui_entry_insert_char((char) key);
		}
		break;
	}
}
Exemple #20
0
static int set_keydefine_key(struct _select_def *conf, int key)
{
    int oldmode;

    switch (key) {
        case KEY_TAB:
            ask_define();
            return SHOW_DIRCHANGE;
        case 'a':                  /* add new user */
            if (keymem_total < MAX_KEY_DEFINE) {
                int i,j;
                struct key_struct k;
                char buf[120];

                clear();
                move(1, 0);
                prints("请键入自定义键: ");
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) return SHOW_DIRCHANGE;
                prints("%s\n", buf);
                k.key = i;
                move(2, 0);
                prints("请输入替换序列(最多10个),按一次ESC结束: ");
                j=0;
                do {
                    do {
                        i = igetkey();
                        get_key_name(i, buf);
                    } while (!buf[0]&&i!=KEY_ESC);
                    if (i==KEY_ESC) break;
                    prints("%s ", buf);
                    k.mapped[j] = i;
                    j++;
                    if (j>=10) break;
                } while (1);
                if (j<10) k.mapped[j]=0;
                if (j==0) return SHOW_DIRCHANGE;

                k.status[0] = -1;
                add_key(&k);

                return SHOW_DIRCHANGE;
            }
            break;
        case 'e':
            set_modes(keymem[conf->pos-1].status);
            return SHOW_DIRCHANGE;
        case 's': {
            int i,j,x,y;
            struct key_struct k;
            char buf[120];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1, 0);
            prints("请键入自定义键: ");
            do {
                i = igetkey();
                get_key_name(i, buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC) return SHOW_DIRCHANGE;
            prints("%s\n", buf);
            k.key = i;
            move(2, 0);
            prints("请输入替换序列(最多10个),按一次ESC结束: ");
            j=0;
            do {
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j] = i;
                j++;
                if (j>=10) break;
            } while (1);
            if (j<10) k.mapped[j]=0;
            if (j==0) return SHOW_DIRCHANGE;

            memcpy(keymem+conf->pos-1, &k, sizeof(struct key_struct));

            return SHOW_DIRCHANGE;
        }
        break;
        case 'x': {
            struct key_struct k;
            int i;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请键入自定义键: ");
            do {
                i=igetkey();
                get_key_name(i,buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC)
                return SHOW_DIRCHANGE;
            k.key=i;
            prints("%s",buf);
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 't': {
            struct key_struct k;
            int i,j,x,y;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请输入替换序列(最多10个), 按一次ESC结束: ");
            for (j=0; j<10; j++) {
                do {
                    i=igetkey();
                    get_key_name(i,buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC)
                    break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j]=i;
            }
            if (!j)
                return SHOW_DIRCHANGE;
            if (j<10)
                k.mapped[j]=0;
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 'd':                  /* delete existed user */
            if (keymem_total > 0) {
                char ans[3];

                getdata(t_lines - 1, 0, "确实要删除该定义键吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true);
                if (ans[0] == 'Y' || ans[0] == 'y') {
                    remove_key(conf->pos-1);
                    if (keymem_total==0) {
                        struct key_struct key;
                        key.key = 'A';
                        key.mapped[0] = 'A';
                        key.mapped[1] = 0;
                        key.status[0] = 0;
                        add_key(&key);
                    }
                }
                return SHOW_DIRCHANGE;
            }
            break;
        case 'L':
        case 'l':
            oldmode = uinfo.mode;
            show_allmsgs();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'W':
        case 'w':
            oldmode = uinfo.mode;
            if (!HAS_PERM(getCurrentUser(), PERM_PAGE))
                break;
            s_msg();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'u':
            oldmode = uinfo.mode;
            clear();
            modify_user_mode(QUERY);
            t_query(NULL);
            modify_user_mode(oldmode);
            clear();
            return SHOW_REFRESH;
    }

    return SHOW_CONTINUE;
}
    virtual BOOL on_key(HELEMENT he, HELEMENT target, UINT event_type, UINT code, UINT keyboardStates ) 
    { 
        const char* keyname = 0;
        if( event_type == (KEY_DOWN | SINKING) && (keyboardStates & ALT_KEY_PRESSED) == 0  )
        {
          keyname = get_key_name( code, keyboardStates);
          if( !keyname )
            return FALSE;
        }
        else if( (event_type == (KEY_CHAR | SINKING)) && (keyboardStates == ALT_KEY_PRESSED) ) 
        {
          if( code != '\'' && code != '\"' )
          {
            static char name[2];
            name[0] = (char) code;
            name[1] = 0;
            keyname = name;
          }
          else
            return false;
        }
        else 
          return false;

        dom::element container = he;

        HWND thisHWnd = container.get_element_hwnd(false);
        
        // handling IFrame in focus situation
        if( ::GetFocus() == thisHWnd) 
        {
          dom::element super_container = dom::element::root_element( ::GetParent(thisHWnd)  );
          if( super_container.is_valid() ) // yes, we have outer frame
          {
            if(process_key(super_container, keyname))
                return TRUE;
          }
        }

        // normal handling

        if(process_key(container, keyname))
            return TRUE;

        // child iframes handling (if any)
        struct CB:public htmlayout::dom::callback 
        {
          const char* keyname;
          bool done;
          virtual bool on_element(HELEMENT he) 
          {
            htmlayout::dom::element iframe = he; 
            if( iframe.enabled() && iframe.visible() ) // only if it is visible and enabled
            {
              HWND hwndIFrame = iframe.get_element_hwnd(false);
              htmlayout::dom::element iframeRoot = htmlayout::dom::element::root_element(hwndIFrame);
              if(accesskeys::process_key( iframeRoot, keyname ))
              {
                done = true;
                return true; // stop enumeration
              }
            }
            return false;
          }
        };
        CB cb;
        cb.done = false;        
        cb.keyname = keyname;
        container.find_all(&cb, "iframe");
        return cb.done;
       
    }
Exemple #22
0
int 
check_key_name_hierarchy(const unsigned char *ccnb, 
										struct ccn_parsed_ContentObject *pco,
										int key_type, int content_type){
	printf("check_key_name_hierarchy called\n");	
	if (key_type == UNKNOWN_KEY ){
		return 1;
	}
	int res;
	struct ccn_charbuf *key_name=get_key_name(ccnb, pco);

	struct ccn_charbuf *key_uri = ccn_charbuf_create();
	ccn_uri_append(key_uri, key_name->buf, key_name->length, 0);
	printf("Key Name: %s\n",ccn_charbuf_as_string(key_uri));
	ccn_charbuf_destroy(&key_uri);

	struct ccn_charbuf *content_name=ccn_charbuf_create();
	res=ccn_charbuf_append(content_name, ccnb + pco->offset[CCN_PCO_B_Name],
			pco->offset[CCN_PCO_E_Name] - pco->offset[CCN_PCO_B_Name]);

	struct ccn_charbuf *content_uri = ccn_charbuf_create();
	ccn_uri_append(content_uri, content_name->buf, content_name->length, 0);
	printf("Content Name: %s\n",ccn_charbuf_as_string(content_uri));
	ccn_charbuf_destroy(&content_uri);
	
	if ( key_type == NLSR_KEY){
		char *orig_router_key_name=get_orig_router_from_key_name(key_name,0,0);
		char *orig_router_content_name;
		if ( content_type == 1 ){
			orig_router_content_name=get_orig_router_from_lsa_name(content_name);
		}
		else if ( content_type == 0 ){
			orig_router_content_name=get_orig_router_from_info_content_name(content_name);
		}
		printf("Orig Router (Key Name):%s\n",orig_router_key_name);
		printf("Orig Router (Content Name):%s\n",orig_router_content_name);

		if (strcmp(orig_router_key_name,orig_router_content_name) == 0 ){
			free(orig_router_key_name);
			free(orig_router_content_name);
			ccn_charbuf_destroy(&key_name);
			ccn_charbuf_destroy(&content_name);
			return 1;
		}
	}

	if ( key_type == ROUTING_KEY){
		char *orig_router_key_name=get_orig_router_from_key_name(key_name,1,0);
		char *orig_router_content_name=get_orig_router_from_key_name(content_name,1,1);
		printf("Orig Router (Key Name):%s\n",orig_router_key_name);
		printf("Orig Router (Content Name):%s\n",orig_router_content_name);
		
		if (strcmp(orig_router_key_name,orig_router_content_name) == 0 ){
			free(orig_router_key_name);
			free(orig_router_content_name);
			ccn_charbuf_destroy(&key_name);
			ccn_charbuf_destroy(&content_name);
			return 1;
		}
	}
	if ( key_type == OPERATOR_KEY){
		struct ccn_indexbuf *key_name_comps;
		key_name_comps = ccn_indexbuf_create();
		res = ccn_name_split(key_name, key_name_comps);
		int last_indx=check_for_tag_component_in_name(key_name,key_name_comps,"O.N.Start");
		char *site_key_prefix_key=get_name_segments_from_name(key_name,0,last_indx);
		printf("Site key prefix(key Name):%s\n",site_key_prefix_key);
		ccn_indexbuf_destroy(&key_name_comps);

		struct ccn_indexbuf *content_name_comps;
		content_name_comps = ccn_indexbuf_create();
		res = ccn_name_split(content_name, content_name_comps);
		int last_indx_rtr=check_for_tag_component_in_name(content_name,content_name_comps,"R.N.Start");
		char *site_key_prefix_content=get_name_segments_from_name(key_name,0,last_indx_rtr);
		printf("Site key prefix(Content Name):%s\n",site_key_prefix_content);
		ccn_indexbuf_destroy(&content_name_comps);

		if( strcmp(site_key_prefix_key,site_key_prefix_content) == 0 ){
			free(site_key_prefix_key);
			free(site_key_prefix_content);
			ccn_charbuf_destroy(&key_name);
			ccn_charbuf_destroy(&content_name);
			return 1;
		}

	}

	if ( key_type == SITE_KEY){
		struct ccn_indexbuf *key_name_comps;
		key_name_comps = ccn_indexbuf_create();
		res = ccn_name_split(key_name, key_name_comps);
		int last_indx=check_for_tag_component_in_name(key_name,key_name_comps,"M.K");
		char *site_key_prefix_key=get_name_segments_from_name(key_name,0,last_indx);
		printf("Site key prefix(key Name):%s\n",site_key_prefix_key);
		ccn_indexbuf_destroy(&key_name_comps);

		struct ccn_indexbuf *content_name_comps;
		content_name_comps = ccn_indexbuf_create();
		res = ccn_name_split(content_name, content_name_comps);
		int last_indx_rtr=check_for_tag_component_in_name(content_name,content_name_comps,"O.N.Start");
		char *site_key_prefix_content=get_name_segments_from_name(key_name,0,last_indx_rtr);
		printf("Site key prefix(Content Name):%s\n",site_key_prefix_content);
		ccn_indexbuf_destroy(&content_name_comps);

		if( strcmp(site_key_prefix_key,site_key_prefix_content) == 0 ){
			free(site_key_prefix_key);
			free(site_key_prefix_content);
			ccn_charbuf_destroy(&key_name);
			ccn_charbuf_destroy(&content_name);
			return 1;
		}

	}
	
	if ( key_type == ROOT_KEY){
		ccn_charbuf_destroy(&key_name);
		ccn_charbuf_destroy(&content_name);
		return 1;
	}

	ccn_charbuf_destroy(&key_name);
	ccn_charbuf_destroy(&content_name);
	return 0;
}
Exemple #23
0
int 
verify_key(const unsigned char *ccnb, 
		struct ccn_parsed_ContentObject *pco,
		int content_type){
	if ( nlsr->debugging )
		printf("verify key called\n");
	int ret=-1;
	//int res;
	
	if ( contain_key_name(ccnb, pco) == 1){
		
		struct ccn_charbuf *key_name=get_key_name(ccnb, pco);
		struct ccn_charbuf *key_uri = ccn_charbuf_create();
		ccn_uri_append(key_uri, key_name->buf, key_name->length, 0);
		if ( nlsr->debugging )
			printf("Key Name from Incoming Content: %s\n",ccn_charbuf_as_string(key_uri));
		int key_type=get_key_type_from_key_name(key_name);
		if ( nlsr->debugging )		
			printf("Key Type: %d \n",key_type);

		struct ccn_charbuf *result = ccn_charbuf_create();
		struct ccn_parsed_ContentObject temp_pco = {0};
		int get_flags = 0;
		get_flags |= CCN_GET_NOKEYWAIT;
		int counter = 0;
		while(ccn_get(nlsr->ccn, key_name, NULL, 500, result, &temp_pco, NULL, 
										get_flags) < 0 && counter < 3) counter++;

		int chk_verify=ccn_verify_content(nlsr->ccn,ccnb,pco);		

		if ( chk_verify == 0 ){
			if ( nlsr->debugging )
				printf("Content verification Successful :)\n");

			if ( counter == 3){
				if ( nlsr->debugging )
					printf("Could not retrieve key by name !!!\n");
			}
			else{
				if ( key_type == ROOT_KEY ){
					ret=0;
				}
				else{
					if ( nlsr->isStrictHierchicalKeyCheck ){
						int key_name_test=check_key_name_hierarchy(ccnb,
																	pco,
																	key_type,
																	content_type);
						if ( key_name_test == 1){
							ret=verify_key(result->buf,&temp_pco,content_type);
						}
					}
					else{ 
						ret=verify_key(result->buf,&temp_pco,content_type);
					}
				}
			}
		}
		ccn_charbuf_destroy(&result);
		ccn_charbuf_destroy(&key_uri);
		ccn_charbuf_destroy(&key_name);
		return ret;
	}

	return ret;
}
Exemple #24
0
void
KeyboardMenu::refresh()
{
  KeyboardConfig& kbd_cfg = g_config->keyboard_config;
  ItemControlField* micf;

  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::UP));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::UP)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::DOWN));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::DOWN)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::LEFT));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::LEFT)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::RIGHT));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::RIGHT)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::JUMP));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::JUMP)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::ACTION));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::ACTION)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::PEEK_LEFT));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_LEFT)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::PEEK_RIGHT));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_RIGHT)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::PEEK_UP));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_UP)));
  micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::PEEK_DOWN));
  if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::PEEK_DOWN)));

  if (g_config->developer_mode) {
    micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::CHEAT_MENU));
    if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::CHEAT_MENU)));
  }

  if (g_config->developer_mode || g_config->console_enabled) {
    micf = dynamic_cast<ItemControlField*>(&get_item_by_id((int) Controller::CONSOLE));
    if (micf) micf->change_input(get_key_name(kbd_cfg.reversemap_key(Controller::CONSOLE)));
  }
}
bool state_keyredefinition_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard)
{
	int i;

	if (SUBSTATE==0) {
		if (image!=0) SDL_FreeSurface(image);
		if (image2!=0) SDL_FreeSurface(image);
		image=IMG_Load("graphics/tittle.png");
	} /* if */ 

	SDL_BlitSurface(image,0,screen,0);
	surface_fader(screen,0.5F,0.5F,0.5F,-1,0);

	font_print_centered(sx/2,20,"REDEFINE CONTROLS:",screen);
	font_print_centered(sx/2,40,"[PRESS SELECT TO SKIP]",screen);

	if (SUBSTATE<32) {
		surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0);
		SUBSTATE++;
	} /* if */ 
	if (SUBSTATE>39) {
		surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0);
		SUBSTATE++;
		if (SUBSTATE==64) {
			save_configuration();

			SDL_FreeSurface(image);
			image=0;

			STATE=1;
			SUBSTATE=0;
		} /* if */ 
	} /* if */ 

	if (SUBSTATE>=32) {
		bool found;
		char keystr[256];
		char *upstr;

		SUBSTATE-=32;
		if (SUBSTATE>=0) {
			font_print(16,60,"PRESS A BUTTON FOR THRUST:",screen);
		} /* if */ 
		if (SUBSTATE>=1) {
			strcpy(keystr,get_key_name((SDLKey)THRUST_KEY)); 
			upstr=strupr(keystr);
			font_print(200,60,upstr,screen);
			font_print(16,70,"PRESS A BUTTON FOR ANTITHRUST:",screen);
		} /* if */ 
		if (SUBSTATE>=2) { 
                        strcpy(keystr,get_key_name((SDLKey)ANTITHRUST_KEY));
                        upstr=strupr(keystr);
			font_print(200,70,upstr,screen);
			font_print(16,80,"PRESS A BUTTON FOR LEFT:",screen);
		} /* if */ 
		if (SUBSTATE>=3) {  
			strcpy(keystr,get_key_name((SDLKey)LEFT_KEY));
			upstr=strupr(keystr);
			font_print(200,80,upstr,screen);
			font_print(16,90,"PRESS A BUTTON FOR RIGHT:",screen);
		} /* if */ 
		if (SUBSTATE>=4) { 
			strcpy(keystr,get_key_name((SDLKey)RIGHT_KEY));
			upstr=strupr(keystr);
			font_print(200,90,upstr,screen);
			font_print(16,100,"PRESS A BUTTON FOR FIRE:",screen);
		} /* if */ 
		if (SUBSTATE>=5) { 
			strcpy(keystr,get_key_name((SDLKey)FIRE_KEY));
			upstr=strupr(keystr);
			font_print(200,100,upstr,screen);
			font_print(16,110,"PRESS A BUTTON FOR ATRACTOR:",screen);
		} /* if */ 
		if (SUBSTATE>=6) {
			strcpy(keystr,get_key_name((SDLKey)ATRACTOR_KEY));
			upstr=strupr(keystr);
			font_print(200,110,upstr,screen);
			font_print(16,120,"PRESS A BUTTON FOR PAUSE:",screen);
		} /* if */ 
		if (SUBSTATE>=7) { 
			strcpy(keystr,get_key_name((SDLKey)PAUSE_KEY));
			upstr=strupr(keystr);
			font_print(200,120,upstr,screen);
			font_print(32,140,"PRESS ANY BUTTON",screen);
		} /* if */ 

		found=SUBSTATE < 7 ? false : true;
		for(i=0;!found && i<SDLK_LAST;i++) {
			if (keyboard[i] && !old_keyboard[i]) {
				if ((SDLKey)i == SDLK_ESCAPE) {
					keyboard[i] = 0;
					SUBSTATE++;
					break;
				}

				switch(SUBSTATE) {
				case 0:THRUST_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				case 1:ANTITHRUST_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				case 2:LEFT_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				case 3:RIGHT_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				case 4:FIRE_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				case 5:ATRACTOR_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				case 6:PAUSE_KEY=(SDLKey)i;
					   SUBSTATE++;
					   found=true;
					   break;
				} /* switch */ 
			} /* if */ 
		} /* for */ 

		if (SUBSTATE==7 && 
			((keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) ||
			 (keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY])
			)) {
			SUBSTATE++;
		} /* if */ 
		SUBSTATE+=32;
	} /* if */ 

	return true;
} /* state_keyredefinition_cycle */