예제 #1
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
void pagesel_update (Pagesel *pagesel)
{
    GtkTreeModel *model;
    TOPLEVEL *toplevel;
    PAGE *p_current;
    GList *iter;

    g_assert (IS_PAGESEL (pagesel));

    g_return_if_fail (GSCHEM_DIALOG (pagesel)->w_current);

    toplevel = GSCHEM_DIALOG (pagesel)->w_current->toplevel;
    model    = gtk_tree_view_get_model (pagesel->treeview);

    /* wipe out every thing in the store */
    gtk_tree_store_clear (GTK_TREE_STORE (model));
    /* now rebuild */
    for ( iter = geda_list_get_glist( toplevel->pages );
            iter != NULL;
            iter = g_list_next( iter ) ) {

        p_current = (PAGE *)iter->data;
        /* find every page that is not a hierarchy-down of another page */
        if (p_current->up < 0 ||
                s_page_search_by_page_id (toplevel->pages,
                                          p_current->up) == NULL) {
            add_page (model, NULL, toplevel->pages, p_current);
        }
    }

    /* select the current page in the treeview */
    select_page (pagesel->treeview, NULL, toplevel->page_current);
}
예제 #2
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *  Recursive function to select the current page in the treeview
 *
 */
static void select_page(GtkTreeView *treeview,
                        GtkTreeIter *parent, PAGE *page)
{
    GtkTreeModel *treemodel = gtk_tree_view_get_model (treeview);
    GtkTreeIter iter;
    PAGE *p_current;

    if (!gtk_tree_model_iter_children (treemodel, &iter, parent)) {
        return;
    }

    do {
        gtk_tree_model_get (treemodel, &iter,
                            COLUMN_PAGE, &p_current,
                            -1);
        if (p_current == page) {
            gtk_tree_view_expand_all (treeview);
            gtk_tree_selection_select_iter (
                gtk_tree_view_get_selection (treeview),
                &iter);
            return;
        }

        select_page (treeview, &iter, page);

    } while (gtk_tree_model_iter_next (treemodel, &iter));

}
예제 #3
0
static void
bt_settings_dialog_set_property (GObject * object, guint property_id,
    const GValue * value, GParamSpec * pspec)
{
  BtSettingsDialog *self = BT_SETTINGS_DIALOG (object);
  return_if_disposed ();
  switch (property_id) {
    case PROP_PAGE:
      select_page (self, g_value_get_enum (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}
예제 #4
0
static page * select_page_wrapper()
{
    page * current_page;
    if (pthread_mutex_lock(&globals.select_mutex) == ERROR)
        return NULL;
    current_page = select_page(globals.pages, globals.mem_size);
    if (current_page == NULL)
    {
        pthread_mutex_unlock(&globals.select_mutex);
        return NULL;
    }
    if (pthread_mutex_lock(&(current_page->meta->lock)) == ERROR)
    {
        pthread_mutex_unlock(&globals.select_mutex);
        return NULL;
    }
    return current_page;
}
예제 #5
0
void CL_TabHeader_Impl::on_process_message(CL_GUIMessage &msg)
{
	if(component->is_enabled())
	{
		if (msg.is_type(CL_GUIMessage_Input::get_type_name()))
		{
			CL_GUIMessage_Input input_msg = msg;
			CL_InputEvent e = input_msg.get_event();
			CL_Point pos = e.mouse_pos;

			if (e.type == CL_InputEvent::pressed && e.id == CL_MOUSE_LEFT)
			{
				std::vector<Handle>::iterator it;
				for (it = tabs.begin(); it != tabs.end(); ++it)
				{
					bool inside = (*it).rect.contains(pos);
					if (inside)
					{
						unselect_all();
						(*it).part.set_state(CssStr::selected, true);
						(*it).part.set_state(CssStr::normal, false);

						component->request_repaint();
						if (!func_page_selected.is_null())
							func_page_selected.invoke((*it).tab_page);
					}
				}
				msg.set_consumed();
			}
			else if (e.type == CL_InputEvent::pointer_moved)
			{
				std::vector<Handle>::iterator it;
				for (it = tabs.begin(); it != tabs.end(); ++it)
				{
					bool inside = (*it).rect.contains(pos);
					if (inside)
					{
						if ((*it).part.get_state(CssStr::selected))
							return;
						(*it).part.set_state(CssStr::hot, true);
						(*it).part.set_state(CssStr::normal, false);
						component->request_repaint();
						msg.set_consumed();
					}
					else if ((*it).part.get_state(CssStr::hot))
					{
						(*it).part.set_state(CssStr::hot, false);
						(*it).part.set_state(CssStr::normal, true);						
						component->request_repaint();
						msg.set_consumed();
					}
				}
			}
			else if (e.type == CL_InputEvent::pressed && e.id == CL_KEY_LEFT)
			{
				int next_page = selected_page - 1;
				if (next_page < 0)
					next_page = tabs.size()-1;

				unselect_all();
				select_page(next_page);

				if (!func_page_selected.is_null())
					func_page_selected.invoke(tabs[next_page].tab_page);

				component->select_page(next_page);
				msg.set_consumed();
			}
			else if (e.type == CL_InputEvent::pressed && e.id == CL_KEY_RIGHT)
			{
				int next_page = selected_page + 1;
				if (next_page >= tabs.size())
					next_page = 0;

				unselect_all();
				select_page(next_page);

				if (!func_page_selected.is_null())
					func_page_selected.invoke(tabs[next_page].tab_page);

				component->request_repaint();
				msg.set_consumed();
			}
			else if (e.type == CL_InputEvent::pressed && (e.id == CL_KEY_UP || e.id == CL_KEY_DOWN))
			{
				// block focus switching with up/down when in tab header.
				msg.set_consumed();
			}
		}
		else if (msg.is_type(CL_GUIMessage_Pointer::get_type_name()))
		{
			CL_GUIMessage_Pointer pointer = msg;
			if (pointer.get_pointer_type() == CL_GUIMessage_Pointer::pointer_leave)
			{
				std::vector<Handle>::iterator it;
				for (it = tabs.begin(); it != tabs.end(); ++it)
				{
					(*it).part.set_state(CssStr::hot, false);
					(*it).part.set_state(CssStr::normal, true);
				}
				component->request_repaint();
			}
		}
		else if (msg.is_type(CL_GUIMessage_FocusChange::get_type_name()))
		{
			CL_GUIMessage_FocusChange focus_msg = msg;
			if (focus_msg.get_focus_type() == CL_GUIMessage_FocusChange::gained_focus)
			{
				part_background.set_state(CssStr::focused, true);
				component->request_repaint();
			}
			else 
			{
				part_background.set_state(CssStr::focused, false);
				component->request_repaint();
			}
			msg.set_consumed();
		}
	}
}
예제 #6
0
void TabHeader_Impl::on_process_message(std::shared_ptr<GUIMessage> &msg)
{
	if(component->is_enabled())
	{
		std::shared_ptr<GUIMessage_Input> input_msg = std::dynamic_pointer_cast<GUIMessage_Input>(msg);
		if (input_msg)
		{
			
			const InputEvent &e = input_msg->input_event;
			Point pos = e.mouse_pos;

			if (e.type == InputEvent::pressed && e.id == mouse_left)
			{
				std::vector<Handle>::iterator it;
				for (it = tabs.begin(); it != tabs.end(); ++it)
				{
					bool inside = (*it).rect.contains(pos);
					if (inside)
					{
						unselect_all();
						(*it).part.set_pseudo_class(CssStr::selected, true);
						(*it).part.set_pseudo_class(CssStr::normal, false);

						component->request_repaint();
						if (!func_page_selected.is_null())
							func_page_selected.invoke((*it).tab_page);
					}
				}
				msg->consumed = true;
			}
			else if (e.type == InputEvent::pointer_moved)
			{
				std::vector<Handle>::iterator it;
				for (it = tabs.begin(); it != tabs.end(); ++it)
				{
					bool inside = (*it).rect.contains(pos);
					if (inside)
					{
						if ((*it).part.get_pseudo_class(CssStr::selected))
							return;
						(*it).part.set_pseudo_class(CssStr::hover, true);
						(*it).part.set_pseudo_class(CssStr::normal, false);
						component->request_repaint();
						msg->consumed = true;
					}
					else if ((*it).part.get_pseudo_class(CssStr::hover))
					{
						(*it).part.set_pseudo_class(CssStr::hover, false);
						(*it).part.set_pseudo_class(CssStr::normal, true);						
						component->request_repaint();
						msg->consumed = true;
					}
				}
			}
			else if (e.type == InputEvent::pressed && e.id == keycode_left)
			{
				int next_page = selected_page - 1;
				if (next_page < 0)
					next_page = tabs.size()-1;

				unselect_all();
				select_page(next_page);

				if (!func_page_selected.is_null())
					func_page_selected.invoke(tabs[next_page].tab_page);

				component->select_page(next_page);
				msg->consumed = true;
			}
			else if (e.type == InputEvent::pressed && e.id == keycode_right)
			{
				int next_page = selected_page + 1;
				if (next_page >= tabs.size())
					next_page = 0;

				unselect_all();
				select_page(next_page);

				if (!func_page_selected.is_null())
					func_page_selected.invoke(tabs[next_page].tab_page);

				component->request_repaint();
				msg->consumed = true;
			}
			else if (e.type == InputEvent::pressed && (e.id == keycode_up || e.id == keycode_down))
			{
				// block focus switching with up/down when in tab header.
				msg->consumed = true;
			}
		}
		std::shared_ptr<GUIMessage_Pointer> pointer = std::dynamic_pointer_cast<GUIMessage_Pointer>(msg);
		if (pointer)
		{
			
			if (pointer->pointer_type == GUIMessage_Pointer::pointer_leave)
			{
				std::vector<Handle>::iterator it;
				for (it = tabs.begin(); it != tabs.end(); ++it)
				{
					(*it).part.set_pseudo_class(CssStr::hover, false);
					(*it).part.set_pseudo_class(CssStr::normal, true);
				}
				component->request_repaint();
			}
		}
		std::shared_ptr<GUIMessage_FocusChange> focus_change_msg = std::dynamic_pointer_cast<GUIMessage_FocusChange>(msg);
		if (focus_change_msg)
		{
			
			if (focus_change_msg->focus_type == GUIMessage_FocusChange::gained_focus)
			{
				component->set_pseudo_class(CssStr::focused, true);
				component->request_repaint();
			}
			else 
			{
				component->set_pseudo_class(CssStr::focused, false);
				component->request_repaint();
			}
			msg->consumed = true;
		}
	}
}
예제 #7
0
int load_page(unsigned num, page *my_page)
/* Function loads page number [num] from the drive to the operating memory. *
 * If there is no place for new frame, it's waiting for place or other      *
 * frame which could be removed in order to complete request                *
 *                                                                          *
 * Function assumes, that the thread has lock on the [data.mutex]           *
 *                                                                          *
 * MUTABLE PARAMETERS: my_page                                              *
 *                                                                          *
 * RETURN VALUE:                                                            *
 *   0              success                                                 *
 *   PSIM_ECOND     there was a problem with a operation on condition       *
 *   PSIM_ELOCK     mutex lock operation failed                             *
 *   PSIM_EUNLO     mutex unlock operation failed                           *
 *   IOERROR        aio operation failed                                    */
{
  int ret;
  page *to_delete = NULL;
  my_page->state = PSIM_IN_USE;
  // while we don't have place and candidate to delete - wait
  while(data.pages_count >= data.mem_size &&
      (to_delete = select_page(data.first_page)) == NULL)
    CHECK_NZERO(pthread_cond_wait(&data.create_page_cond, &data.mutex),
                PSIM_ECOND);
  if(to_delete != NULL)
  // we must remove frame before loading
  {
    to_delete->state = PSIM_IN_USE;
    frames_list_remove(to_delete);
    ret = 0;
    if(to_delete->mod);
    // frame was modified, so we have to write it back
    {
      if(data.callback != NULL)
        data.callback(2, to_delete->p_num, to_delete->f_num);
      CHECK_NZERO(wait_for_place(), PSIM_ECOND);
      DEC_CHECK_NZERO(pthread_mutex_unlock(&data.mutex), PSIM_EUNLO);
      ret = write_page(to_delete);
      DEC_CHECK_NZERO(pthread_mutex_lock(&data.mutex), PSIM_ELOCK);
      data.current_operations--;
      if(ret != 0)
      // aio_write failed, so we have to attach our frame back
      {
        frames_list_push_back(to_delete);
        // we don't control error, because we already have one
        pthread_cond_broadcast(&to_delete->cond);
        pthread_cond_signal(&data.max_operations_cond);
        to_delete->state = PSIM_READY;
        return PSIM_EIO;
      }
      // We want to try every necessary signal, before returning!
      ret = ret || pthread_cond_signal(&data.max_operations_cond);
      if(data.callback != NULL)
        data.callback(3, to_delete->p_num, to_delete->f_num);
    }
    stash_frame(to_delete);
    data.pages_count--;
    ret = ret || pthread_cond_broadcast(&to_delete->cond);
    if(ret != 0)
      return PSIM_ECOND;
  }
  data.pages_count++;

  pop_frame(my_page);
  if(data.callback != NULL)
    data.callback(4, my_page->p_num, my_page->f_num);
  CHECK_NZERO(wait_for_place(), PSIM_ECOND);
  DEC_CHECK_NZERO(pthread_mutex_unlock(&data.mutex), PSIM_EUNLO);
  ret = read_page(my_page);
  DEC_CHECK_NZERO(pthread_mutex_lock(&data.mutex), PSIM_ELOCK);
  data.current_operations--;
  if(ret != 0)
  // aio_read failed, so we have to stash frame back
  {
    stash_frame(my_page);
    data.pages_count--;
    // we don't control error, because we already have one
    pthread_cond_signal(&data.max_operations_cond);
    pthread_cond_broadcast(&data.create_page_cond);
    pthread_cond_broadcast(&my_page->cond);
    return PSIM_EIO;
  }
  my_page->state = PSIM_READY;
  frames_list_push_back(my_page);
  if(data.callback != NULL)
    data.callback(5, my_page->p_num, my_page->f_num);

  // We want to try every necessary signal, before returning!
  ret = 0;
  ret = pthread_cond_signal(&data.max_operations_cond);
  // First the ones which are waiting on the "create_page" cond!  
  ret = ret || pthread_cond_broadcast(&data.create_page_cond);
  ret = ret || pthread_cond_broadcast(&my_page->cond);
  if(ret != 0)
    return PSIM_ECOND;
  return 0;
}