Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » X11 middle mouse copy paste in own widget [SOLVED]
X11 middle mouse copy paste in own widget [SOLVED] [message #48593] Fri, 04 August 2017 07:26 Go to next message
slashupp is currently offline  slashupp
Messages: 211
Registered: July 2009
Experienced Member
(Leaving this here for someone else with same problem)

All i can find searching this forum is that it is supported ( https://www.ultimatepp.org/forums/index.php?t=rview&th=2 383&goto=9803)

How do I implement/support/handle this in my own widget derived from Ctrl?

Cannot find how it's done in uppsrc - must be searching for wrong keywords..

found "GetSelectionData()" and overrode in my widget but it is never called

According to info on web X11 uses PRIMARY for this (CLIPBOARD for normal cut&paste)
and I found mention of this in uppsrc:gdkselection.h:GDK_SELECTION_PRIMARY
but not how to make use of it

Please help

[Updated on: Fri, 04 August 2017 13:05]

Report message to a moderator

Re: X11 middle mouse in own widget [message #48594 is a reply to message #48593] Fri, 04 August 2017 10:54 Go to previous message
slashupp is currently offline  slashupp
Messages: 211
Registered: July 2009
Experienced Member
Like most everything in Upp this turned out to be very simple & easy:

run the code below, double-click in the box and middle-click in some other editor to copy the text to that editor
then select==hilite some text somewhere and middle-click in the box to paste that text

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <test_x11_midclick_cnp/test_x11_midclick_cnp.lay>
#include <CtrlCore/lay.h>


struct Box : public Ctrl
{
	typedef Box CLASSNAME;
	
	String text;
	
	Box()
	{
		AddFrame(ThinInsetFrame());
		text="something";
	}
	virtual ~Box() {}
	virtual void Paint(Draw &drw)
	{
		drw.DrawText(10,10, text);
	}
	virtual String GetSelectionData(const String &fmt) const
	{
		return text;
	}
	virtual void LeftDouble(Point p, dword kf)
	{
		SetSelectionSource(ClipFmtsText());
	}
	virtual void MiddleDown(Point p, dword kf)
	{
		if(AcceptText(Selection()))
		{
			text=GetString(Selection());
			Refresh();
		}
	}
};


struct test_x11_midclick_cnp : public TopWindow
{
	typedef test_x11_midclick_cnp CLASSNAME;
	
	//EditString eb;
	Box box;
	
	test_x11_midclick_cnp();
};



test_x11_midclick_cnp::test_x11_midclick_cnp()
{
	Title("test_x11_midclick_cnp");
	SetRect(0,0,300,300);
	Sizeable();
	CenterScreen();
	
	//Add(eb.LeftPosZ(10, 200).TopPosZ(10, 20));
	Add(box.LeftPos(10,200).TopPos(40,200));
	
}

GUI_APP_MAIN
{
	test_x11_midclick_cnp().Run();
}


I was looking for complexity where there was none!

Thx mirek

Previous Topic: How to handle copy & paste with focus changing
Next Topic: [BUG] Patch to Switch.cpp to support touch screens
Goto Forum:
  


Current Time: Sun Oct 17 04:34:37 CEST 2021

Total time taken to generate the page: 0.02120 seconds