Esempio n. 1
0
void
Dockable::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{
	if (selection_data.get_length() >= 0
	 && selection_data.get_format() == 8
	 && selection_data.get_data_type() == "SYNFIG_DOCK")
	{
		Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));

		DockBook *parent = dynamic_cast<DockBook*>(get_parent());
		DockBook *dockable_parent = dynamic_cast<DockBook*>(dockable.get_parent());

		if (parent)
		{
			if (dockable_parent != parent)
				 parent->add(dockable,parent->page_num(*this));
			else
				parent->reorder_child(dockable,parent->page_num(*this));
			dockable.present();
			context->drag_finish(true, false, time);
			App::dock_manager->update_window_titles();
			return;
		}
	}

	context->drag_finish(false, false, time);
}
Esempio n. 2
0
void
DockDialog::drop_on_append(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{
	if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
	{
		Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
		append_dock_book()->add(dockable);
		context->drag_finish(true, false, time);
		return;
	}

	context->drag_finish(false, false, time);
}
Esempio n. 3
0
void
DockBook::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{
	if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
	{
		Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
		if(dockable.get_parent()!=this)
			add(dockable);
		dockable.present();
		context->drag_finish(true, false, time);
		return;
	}

	context->drag_finish(false, false, time);
}
Esempio n. 4
0
void Gui_MyWindow::on_dropped_file(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time){
    std::vector<std::string> paths;
    DEV_INFOS("D");
    if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8)){
        std::vector<Glib::ustring> file_list;
        file_list = selection_data.get_uris();
        for (auto &str: file_list){
            paths.push_back(str);
        }
        context->drag_finish(true, false, time);
    }
    else
        context->drag_finish(false, false, time);
    m_signal_drag_and_drop.emit(paths);

}
//------------------------------------------------------------------------------
void DbMySQLRoutineGroupEditor::on_routine_drop(const Glib::RefPtr<Gdk::DragContext>& context
                                               ,int x, int y
                                               , const Gtk::SelectionData& selection_data
                                               , guint info, guint time)
{
  bool dnd_status = false;
  
  if ( selection_data.get_target() == WB_DBOBJECT_DRAG_TYPE)
  {
    std::list<db_DatabaseObjectRef> objects;

    const std::string selection = selection_data.get_data_as_string();

    objects= bec::CatalogHelper::dragdata_to_dbobject_list(_be->get_catalog(), selection);
    
    for (std::list<db_DatabaseObjectRef>::const_iterator obj= objects.begin(); 
         obj != objects.end(); ++obj)
    {
      if (obj->is_instance<db_mysql_Routine>())
      {
        db_mysql_RoutineRef routine = db_mysql_RoutineRef::cast_from(*obj);
        if ( routine.is_valid() )
          _be->append_routine_with_id(routine.id());
      }
    }

    recreate_model_from_string_list(_routines_model, _be->get_routines_names());

    dnd_status = true;
  }
  context->drag_finish(dnd_status, false, time);
}
Esempio n. 6
0
void AppWindow::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, 
	int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
	{
	
#ifdef DEBUG	
	std::cout << "ON_DRAG_DATA_RECEIVED: type: " << selection_data.get_data_type() << std::endl;
	std::cout << "ON_DRAG_DATA_RECEIVED: data: " << selection_data.get_data_as_string() << std::endl;
#endif // DEBUG

	if (selection_data.get_data_type() == "text/uri-list")
		{
		std::list<Glib::ustring> new_filenames = selection_data.get_uris();
			
		const std::list<Glib::ustring>::iterator begin = new_filenames.begin();
		const std::list<Glib::ustring>::iterator end = new_filenames.end();
		std::list<Glib::ustring>::iterator iter = new_filenames.begin();
		int counter = 0;
		
		while( iter != end )
			{
			// we erase the protocol in front of the filename
			if( (*iter).find(':') != std::string::npos )
				(*iter).erase(0, (*iter).find(':')+3);
			
			// unescape the URI
			char * tempfilename = curl_unescape( iter->c_str(), 0);
			(*iter) = tempfilename;
			// curl requires this to be freed like this
			curl_free( tempfilename );

#ifdef DEBUG			
	std::cout << "ON_DRAG_DATA_RECEIVED: URI: " << *iter << std::endl;
#endif // DEBUG

			iter++;
			counter++;
			}
		open_list( new_filenames, counter );
		}
	
	// if we're given plain text, maybe it's still an uri or a filename, we should better check
	// ImageManager.OpenFiles is safe anyway	
	else if( selection_data.get_data_type() == "text/plain" )
		{
			std::string data = selection_data.get_data_as_string();
			data.erase( data.find('\n') ); // erase any newlines, all we can do is one file
			// we erase the protocol in front of the filename
			if( data.find(':') != std::string::npos )
				data.erase(0, data.find(':')+3);
			
			// unescape the URI
			char * tempfilename = curl_unescape( data.c_str(), 0);
			data = tempfilename;
			// curl requires this to be freed like this
			curl_free( tempfilename );
			
			open_new_file( data );
		} 	
	context->drag_finish(true, false, time);
	}
void ClipSelector::dropFunction( const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
                       const Gtk::SelectionData& selection_data, guint info, guint time)
{
  // drop target is of string type, load that sample
  
  int block = y / 18;
  cout << "DROP on block " << block << endl;
  
  const int length = selection_data.get_length();
  if( (length >= 0) ) // && (selection_data.get_format() == 8)
  {
    std::string filename = selection_data.get_data_as_string();
    std::cout << "Received " << filename << " in ClipSelector, loading now! " << std::endl;
    
    // audioFileLoader informs engine & updates StateStore
    int ret = top->offlineWorker->loadAudioBuffer( ID, block, filename );
    
    if ( ret == 0 ) // successful load, so store filename in vector
    {
      stateStore->addAudioBufferName(ID, Glib::path_get_basename(filename) );
    }
  }

  context->drag_finish(false, false, time);
}
Esempio n. 8
0
    void NotebooksTreeView::on_drag_data_received( const Glib::RefPtr<Gdk::DragContext> & context,
                                                   int x, int y,
                                                   const Gtk::SelectionData & selectionData,
                                                   guint , guint time_)
    {
      utils::UriList uriList(selectionData);
      if (uriList.size() == 0) {
        context->drag_finish (false, false, time_);
        return;
      }
      
      Gtk::TreePath treepath;
      Gtk::TreeViewDropPosition pos;
      if (get_dest_row_at_pos (x, y, treepath, pos) == false) {
        context->drag_finish (false, false, time_);
        return;
      }
      
      Gtk::TreeIter iter = get_model()->get_iter(treepath);
      if (!iter) {
        context->drag_finish (false, false, time_);
        return;
      }
      
      Notebook::Ptr destNotebook;
      iter->get_value(0, destNotebook);
      if(std::dynamic_pointer_cast<AllNotesNotebook>(destNotebook)) {
        context->drag_finish (false, false, time_);
        return;
      }

      for(utils::UriList::const_iterator uri_iter = uriList.begin();
          uri_iter != uriList.end(); ++uri_iter) {
        const sharp::Uri & uri(*uri_iter);
        NoteBase::Ptr note = m_note_manager.find_by_uri(uri.to_string());
        if (!note)
          continue;

        DBG_OUT ("Dropped into notebook: %s", note->get_title().c_str());

        destNotebook->add_note(std::static_pointer_cast<Note>(note));
      }

      context->drag_finish (true, false, time_);
    }
Esempio n. 9
0
void TestDnDWindow::on_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
{ 
  if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
  {
    std::cout << "Received \"" << selection_data.get_data_as_string() << "\" in label " << std::endl;
  }

  context->drag_finish(false, false, time);
}
Esempio n. 10
0
void
Toolbox::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int /*x*/, int /*y*/, const Gtk::SelectionData& selection_data_, guint /*info*/, guint time)
{
	// We will make this true once we have a solid drop
	bool success(false);

	if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
	{
		synfig::String selection_data((gchar *)(selection_data_.get_data()));

		// For some reason, GTK hands us a list of URLs separated
		// by not only Carriage-Returns, but also Line-Feeds.
		// Line-Feeds will mess us up. Remove all the line-feeds.
		while(selection_data.find_first_of('\r')!=synfig::String::npos)
			selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));

		std::stringstream stream(selection_data);

		while(stream)
		{
			synfig::String filename,URI;
			getline(stream,filename);

			// If we don't have a filename, move on.
			if(filename.empty())
				continue;

			// Make sure this URL is of the "file://" type.
			URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
			if(URI!="file://")
			{
				synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
				continue;
			}

			// Strip the "file://" part from the filename
			filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());

			synfig::info("Attempting to open "+filename);
			if(App::open(filename))
				success=true;
			else
				synfig::error("Drop failed: Unable to open "+filename);
		}
	}
	else
		synfig::error("Drop failed: bad selection data");

	// Finish the drag
	context->drag_finish(success, false, time);
}
Esempio n. 11
0
void ImportClassesBox::ClassesTreeView::on_drag_data_received(
    const Glib::RefPtr<Gdk::DragContext>& context, int, int,
    const Gtk::SelectionData& selection_data, guint, guint time)
{
    std::string className = selection_data.get_data_as_string();

    if (mClasses->exist(className)) {
	const std::string title(_("Choose a new class name"));
	InteractiveTypeBox box(title, mClasses, className);
	std::string newClassName = box.run();
	if (not newClassName.empty())
	    mParent->importClass(className, newClassName);
    } else {
	mParent->importClass(className);
    }
    build(mClasses);

    if ((context->get_actions () & Gdk::ACTION_MOVE) != 0)
	context->drag_finish(true, false, time);
}
Esempio n. 12
0
void AppWindow::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
	{  
    // this is totally ridiculous, but so be it!
	// we erase the protocol in front of the filename
	// using std::string because Glib::ustring throws a conversion error for some reason
	std::string string_filename = selection_data.get_data_as_string();
	string_filename.erase(0, string_filename.find(':')+3); 

	//convert to char* and unescape
	char * temp_filename = curl_unescape( string_filename.c_str(), 0);
	string_filename = temp_filename;
	// curl requires this to be freed
	curl_free( temp_filename );
	
	//let's remove any \n and \r that are typical of URI's
	if ( string_filename.find('\n') != Glib::ustring::npos )
		string_filename.erase( string_filename.find('\n'), 1 );
	if ( string_filename.find('\r') != Glib::ustring::npos )
		string_filename.erase( string_filename.find('\r'), 1 );

	open_new_file( string_filename );
	context->drag_finish(false, false, time);
	}
Esempio n. 13
0
  void BugzillaNoteAddin::drop_uri_list(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, 
                                        const Gtk::SelectionData & selection_data, guint time)
  {
    std::string uriString = selection_data.get_text();
    if(uriString.empty()) {
      return;
    }

    const char * regexString = "\\bhttps?://.*/show_bug\\.cgi\\?(\\S+\\&){0,1}id=(\\d{1,})";

    pcrecpp::RE re(regexString, pcrecpp::RE_Options(PCRE_CASELESS|PCRE_UTF8));
    int m;

    if(re.FullMatch(uriString, (void*)NULL, &m)) {

      int bugId = m;

      if (insert_bug (x, y, uriString, bugId)) {
        context->drag_finish(true, false, time);
        g_signal_stop_emission_by_name(get_window()->editor()->gobj(),
                                       "drag_data_received");
      }
    }
  }
Esempio n. 14
0
void window_main::file_drag_data_received(
	const Glib::RefPtr<Gdk::DragContext> & context, //info about drag (available on source and dest)
	const int x,                                    //x-coord of drop
	const int y,                                    //y-coord of drop
	const Gtk::SelectionData & selection_data,      //data dropped
	const guint info,                               //type of info dropped
	const guint time)                               //time stamp of when drop happened
{
//DEBUG, dragging file on to window does not work on windows, not sure why

	if(selection_data.get_length() >= 0 && selection_data.get_format() == 8){
		//this will look like file:///home/foo/bar.txt
		std::string URI = selection_data.get_data_as_string();
		if(URI.size() > 7){
			std::string path = URI.substr(7);
			//get rid of newline on the end
			boost::trim(path);
			p2p::load_file(path);
		}
	}

	//tell other end we're done with drag and drop so it can free resources
	context->drag_finish(true, true, time);
}
Esempio n. 15
0
void CircuitWidget::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
{
    (void)info; //placate compiler...
    (void)selection_data; //placate compiler...
    if (!circuit) {
        context->drag_finish(false, false, time);
        return;
    }
    selections.clear();
    static_cast<QCViewer*>(win)->set_selection (selections);
    Gtk::Widget* widget = drag_get_source_widget(context);
    Gtk::Button* button = dynamic_cast<Gtk::Button*>(widget);
    if (button == NULL) {
        context->drag_finish(false, false, time);
        return;
    }

    shared_ptr<Gate> newgate;
    unsigned int target = 0;
    switch (static_cast<GateIcon*>(button->get_image())->type) {
    case GateIcon::NOT:
        newgate = shared_ptr<Gate>(new UGate ("X"));
        newgate->drawType = Gate::NOT;
        break;
    case GateIcon::R:
        newgate = shared_ptr<Gate>(new RGate (1.0, RGate::Z));
        break;
    case GateIcon::SWAP:
        newgate = shared_ptr<Gate>(new UGate ("F"));
        newgate->drawType = Gate::FRED;
        newgate->targets.push_back (target++);
        break;
    case GateIcon::MEASURE:
        newgate = shared_ptr<Gate>(new UGate("MEASURE",""));
        newgate->drawType = Gate::MEASURE;
        break;
    default:
        newgate = shared_ptr<Gate>(new UGate(static_cast<GateIcon*>(button->get_image ())->symbol));
        break;
    }
    if (newgate->targets.size () > circuit->numLines ()) {
        context->drag_finish (false, false, time);
        return;
    }
    newgate->targets.push_back(target++);
    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height();
    // translate mouse click coords into circuit diagram coords
    double xx = (x - width/2.0 + ext.width/2.0)/scale + cx;
    double yy = (y - height/2.0 + ext.height/2.0)/scale + cy;
    vector<int> select_ids;
    string name;
    int pos = -1;
    getCircuitAndColPosition (xx, yy, circuit, rects, name, pos);
    if (name.compare("Main")==0||pos==-1||name.compare("")==0) {  //If the click is not in a subcircuit
        vector<unsigned int> para =  circuit->getGreedyParallel();
        unsigned int wire = getFirstWire (yy);
        if (wire + newgate->targets.size () - 1 >= circuit->numLines ()) {
            wire = circuit->numLines () - newgate->targets.size ();
        }
        for (unsigned int i = 0; i < newgate->targets.size(); i++) {
            newgate->targets[i] += wire;
        }
        if (columns.empty()||pos==-1) {
            insert_gate_at_front (newgate);
        } else if (pos >= (int)para.size()) {
            insert_gate_in_new_column (newgate, circuit->numGates(),circuit);
        } else {
            insert_gate_in_new_column (newgate, para.at(pos),circuit);
        }
        circuit->getGreedyParallel();
    } else {
        insert_gate_in_new_column (newgate, pos,circuit->subcircuits[name]);
        unsigned int wire = getFirstWire (yy);
        for (unsigned int i = 0; i < newgate->targets.size(); i++) newgate->targets[i] += wire;
    }
    context->drag_finish(true, false, time);
}
Esempio n. 16
0
    //
    // DND Drop handling
    //
  void NoteEditor::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext> & context,
                                         int x, int y,
                                         const Gtk::SelectionData & selection_data,
                                         guint info,  guint time)
  {
    bool has_url = false;

    std::vector<std::string> targets = context->list_targets();
    for(std::vector<std::string>::const_iterator iter = targets.begin();
        iter != targets.end(); ++iter) {
      const std::string & target(*iter);
      if (target == "text/uri-list" ||
          target == "_NETSCAPE_URL") {
        has_url = true;
        break;
      }
    }

    if (has_url) {
      utils::UriList uri_list(selection_data);
      bool more_than_one = false;

      // Place the cursor in the position where the uri was
      // dropped, adjusting x,y by the TextView's VisibleRect.
      Gdk::Rectangle rect;
      get_visible_rect(rect);
      int adjustedX = x + rect.get_x();
      int adjustedY = y + rect.get_y();
      Gtk::TextIter cursor;
      get_iter_at_location (cursor, adjustedX, adjustedY);
      get_buffer()->place_cursor (cursor);

      Glib::RefPtr<Gtk::TextTag> link_tag = get_buffer()->get_tag_table()->lookup ("link:url");

      for(utils::UriList::const_iterator iter = uri_list.begin();
          iter != uri_list.end(); ++iter) {
        const sharp::Uri & uri(*iter);
        DBG_OUT("Got Dropped URI: %s", uri.to_string().c_str());
        std::string insert;
        if (uri.is_file()) {
          // URL-escape the path in case
          // there are spaces (bug #303902)
          insert = sharp::Uri::escape_uri_string(uri.local_path());
        } 
        else {
          insert = uri.to_string ();
        }

        if (insert.empty() || sharp::string_trim(insert).empty())
          continue;

        if (more_than_one) {
          cursor = get_buffer()->get_iter_at_mark (get_buffer()->get_insert());

          // FIXME: The space here is a hack
          // around a bug in the URL Regex which
          // matches across newlines.
          if (cursor.get_line_offset() == 0) {
            get_buffer()->insert (cursor, " \n");
          }
          else {
            get_buffer()->insert (cursor, ", ");
          }
        }

        get_buffer()->insert_with_tag(cursor, insert, link_tag);
        more_than_one = true;
      }

      context->drag_finish(more_than_one, false, time);
    } 
    else {
      Gtk::TextView::on_drag_data_received (context, x, y, selection_data, info, time);
    }
  }