示例#1
0
bool MouseAwareTreeView::queueDrawIfNeccesary(int32_t x, int32_t y, Glib::ustring* pPath)
{
    Gtk::TreeModel::Path mousePath;
    Gtk::TreeViewColumn* pColumn;
    Gdk::Rectangle rect;

    convert_bin_window_to_widget_coords (x, y, m_MouseInfo.x, m_MouseInfo.y);

    if (get_path_at_pos(x, y, mousePath, pColumn, x, y))
    {
        int32_t offsetX, offsetY;
        convert_bin_window_to_widget_coords(0, 0, offsetX, offsetY);

        m_MouseInfo.x -= offsetX;
        m_MouseInfo.y -= offsetY;

        get_cell_area(mousePath, *pColumn, rect);
        queue_draw_area(rect.get_x() + offsetX, rect.get_y() + offsetY, rect.get_width(), rect.get_height());
        if (rect.get_y() != m_CurrentCell)
        {
            m_CurrentCell = rect.get_y();
            m_CellChanged = true;
        }

        if (pPath)
        {
            *pPath = mousePath.to_string();
        }
        return true;
    }

    return false;
}
//--------------------------------------------------------------------------------
void DbMySQLTableEditorIndexPage::cell_editing_done(GtkCellEditable *ce) {
  if (_editing_done_id != 0 && _editable_cell != 0) {
    g_signal_handler_disconnect(_editable_cell, _editing_done_id);
    _editing_done_id = 0;
    _editable_cell = 0;
  }

  // If it's Gtk::Entry, we try to find out if maybe user leave edit field empty,
  // if so we revert it to the last known value or to the default one.
  if (GTK_IS_ENTRY(ce)) {
    GtkEntry *entry_widget = GTK_ENTRY(ce);
    if (entry_widget) {
      Gtk::Entry *entry = Glib::wrap(entry_widget);

      if (entry && entry->get_text_length() == 0) {
        Gtk::TreeModel::Path path;
        Gtk::TreeView::Column *column(0);
        _indexes_tv->get_cursor(path, column);
        bec::NodeId node(path.to_string());
        if (node.is_valid()) {
          std::string name = _user_index_name;
          if (name.empty())
            name = strfmt("index%i", path[0] + 1);

          _be->get_indexes()->set_field(node, MySQLTableIndexListBE::Name, name);
          entry->set_text(name);
        }
      }
    }
  }
}
  void ArtistsWidget::loadArtistsSongs(std::string artist) {

    selectedArtist = artist;

    // set label of tab
    artistsLabel->set_text(selectedArtist);

    Gtk::TreeModel::Path path;
    Gtk::CellRenderer* cell;
    artistsView->get_cursor(path, cell);
    std::cout << "sel path:" << path.to_string();
    //    cell->;

    // clear treemodel
    m_actualSongs.clear();


    // start searching for artist
    MPD::Client::GetInstance()->StartSearch(1);
    MPD::Client::GetInstance()->AddSearch(MPD_TAG_ARTIST, artist);
    MPD::Client::GetInstance()->CommitSearch(m_actualSongs);

    // sort songs
    std::sort(m_actualSongs.begin(), m_actualSongs.end(), actualSongSortCond);

    artistsView->unset_model();
    treeModel->clear();

    // insert return button
    insertReturn();

    for (int i = 0; i < m_actualSongs.size(); i++) {
      Gtk::TreeModel::Row row = *(treeModel->append());
      row[columns.artist] = m_actualSongs[i]->GetTitle();
      Gtk::Image image;
      image.set("ui/icon_smaller.png");
      row[columns.image] = image.get_pixbuf();
      row[columns.isArtist] = 0;
      row[columns.song] = m_actualSongs[i];
    }


    artistsView->set_model(treeModel);
    //scroll to top
    artistScrolledWindow->get_vadjustment()->set_value(0);

  }
示例#4
0
	bool
	on_event(GdkEvent *event)
	{
		switch(event->type)
		{
		case GDK_SCROLL:
			if(mimic_tree_view)
			{
				if(event->scroll.direction==GDK_SCROLL_DOWN)
				{
					mimic_tree_view->get_vadjustment()->set_value(
						std::min(
							mimic_tree_view->get_vadjustment()->get_value()+
							mimic_tree_view->get_vadjustment()->get_step_increment(),
							mimic_tree_view->get_vadjustment()->get_upper()-
							mimic_tree_view->get_vadjustment()->get_page_size()
						)
					);
					mimic_tree_view->get_vadjustment()->value_changed();
				}
				else if(event->scroll.direction==GDK_SCROLL_UP)
				{
					mimic_tree_view->get_vadjustment()->set_value(
						std::max(
							mimic_tree_view->get_vadjustment()->get_value()-
							mimic_tree_view->get_vadjustment()->get_step_increment(),
							mimic_tree_view->get_vadjustment()->get_lower()
						)
					);
					mimic_tree_view->get_vadjustment()->value_changed();
				}
			}
			break;
		case GDK_BUTTON_PRESS:
			{
				Gtk::TreeModel::Path path;
				Gtk::TreeViewColumn *column;
				int cell_x, cell_y;
				if(!get_path_at_pos(
					int(event->button.x),int(event->button.y),	// x, y
					path, // TreeModel::Path&
					column, //TreeViewColumn*&
					cell_x,cell_y //int&cell_x,int&cell_y
					)
				) break;
				const Gtk::TreeRow row = *(get_model()->get_iter(path));

				if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
				{
					Gdk::Rectangle rect;
					get_cell_area(path,*column,rect);
					cellrenderer_time_track->property_value_desc()=row[model.value_desc];
					cellrenderer_time_track->property_canvas()=row[model.canvas];
					cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
					queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
					return true;
					//return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
				}
			}
			break;

		case GDK_MOTION_NOTIFY:
			{
				Gtk::TreeModel::Path path;
				Gtk::TreeViewColumn *column;
				int cell_x, cell_y;
				if(!get_path_at_pos(
					(int)event->motion.x,(int)event->motion.y,	// x, y
					path, // TreeModel::Path&
					column, //TreeViewColumn*&
					cell_x,cell_y //int&cell_x,int&cell_y
					)
				) break;

				if(!get_model()->get_iter(path))
					break;

				Gtk::TreeRow row = *(get_model()->get_iter(path));

				if ((event->motion.state&GDK_BUTTON1_MASK || event->motion.state&GDK_BUTTON3_MASK) &&
					column &&
					cellrenderer_time_track == column->get_first_cell_renderer())
				{
					Gdk::Rectangle rect;
					get_cell_area(path,*column,rect);
					cellrenderer_time_track->property_value_desc()=row[model.value_desc];
					cellrenderer_time_track->property_canvas()=row[model.canvas];
					cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
					queue_draw();
					//queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
					return true;
				}
/*				else
				if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
				{
					tooltips_.unset_tip(*this);
					Glib::ustring tooltips_string(row[layer_model.tooltip]);
					last_tooltip_path=path;
					if(!tooltips_string.empty())
					{
						tooltips_.set_tip(*this,tooltips_string);
						tooltips_.force_window();
					}
				}
*/
				return true;
			}
			break;
		case GDK_BUTTON_RELEASE:
			{
				Gtk::TreeModel::Path path;
				Gtk::TreeViewColumn *column;
				int cell_x, cell_y;
				if(!get_path_at_pos(
					(int)event->button.x,(int)event->button.y,	// x, y
					path, // TreeModel::Path&
					column, //TreeViewColumn*&
					cell_x,cell_y //int&cell_x,int&cell_y
					)
				) break;

				if(!get_model()->get_iter(path))
					break;

				Gtk::TreeRow row = *(get_model()->get_iter(path));

				if(column && cellrenderer_time_track==column->get_first_cell_renderer())
				{
					Gdk::Rectangle rect;
					get_cell_area(path,*column,rect);
					cellrenderer_time_track->property_value_desc()=row[model.value_desc];
					cellrenderer_time_track->property_canvas()=row[model.canvas];
					cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
					queue_draw();
					queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
					return true;
				}
			}
			break;
		default:
			break;
		}
		mimic_resync();
		return Gtk::TreeView::on_event(event);
	}
//------------------------------------------------------------------------------
bool ListModelWrapper::drag_data_get_vfunc(const Gtk::TreeModel::Path& path, Gtk::SelectionData& selection_data) const {
  selection_data.set("text/path", path.to_string());
  return true;
}
//------------------------------------------------------------------------------
bec::NodeId ListModelWrapper::get_node_for_path(const Gtk::TreeModel::Path& path) const {
  if (path.empty())
    return bec::NodeId();
  return bec::NodeId(path.to_string());
}
//------------------------------------------------------------------------------
bec::NodeId TreeModelWrapper::get_node_for_path(const Gtk::TreeModel::Path& path) const {
  if (path.empty())
    return _root_node_path_dot;
  return bec::NodeId(_root_node_path_dot + path.to_string());
}