Drag And Drop

Hi
The macro below is for two listboxes with entries. So I want to be able to transfer the entries from one listbox to another. That is, if right arrow button is clicked the selected entries in listbox1 should be moved to listbox2, and if left arrow button is clicked the selected entries in listbox2 should be moved to listbox1. I also want to add the drag and drop capability if it is possible.

#include <TROOT.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TGLabel.h>
#include <TGButton.h>
#include <TGListBox.h>
#include <RQ_OBJECT.h>

class Frame
{
	RQ_OBJECT("Frame")
	private:
		TGMainFrame		*fMain;
		TGCompositeFrame	*fF1, *fF2, *fF3;
		TGLayoutHints		*fL1;
		TGListBox  		*fListBox1, *fListBox2;
		TGCheckButton 		*fCheckMulti1, *fCheckMulti2;
		TGTextButton 		*but1, *but2;
		
	public:
		Frame(const TGWindow *p,UInt_t w,UInt_t h);
		virtual ~Frame();
		void MultiSelect();
		void MoveEntries();
};

Frame::Frame(const TGWindow *p,UInt_t w,UInt_t h)
{
	fMain = new TGMainFrame(p,w,h);
	fMain->SetWindowName("Drag and Drop");
	fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);

	fF1 = new TGCompositeFrame(fMain, 300, 850, kVerticalFrame);
	fF2 = new TGCompositeFrame(fMain, 100, 20, kVerticalFrame | kFixedWidth);
	fF3 = new TGCompositeFrame(fMain, 300, 850, kVerticalFrame);
			
	fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft,5,5,5,5);
	fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft,0,0,30,0);

	//Add first listbox to frame fF1
	char buff1[100];
	fF1->AddFrame(fListBox1 = new TGListBox(fF1, 110),fL1);
	fF1->AddFrame(fCheckMulti1 = new TGCheckButton(fF1, "&MultiSelect", 120), fL2);
	fCheckMulti1->Connect("Clicked()", "Frame", this, "MultiSelect()");
	for (int i = 1; i <= 5; ++i)
	{
		sprintf(buff1, "A %d", i-1);
		fListBox1->AddEntry(buff1, i);
	}
	fListBox1->Resize(100, 300);
	fF1->Resize();

	//Add buttons to frame fF2
	but1= new TGTextButton(fF2,"--->",130);
	but1->Connect("Clicked()", "Frame", this, "MoveEntries()");
	but1->Resize(50, 60);
	fF2->AddFrame(but1,new TGLayoutHints(kLHintsTop | kLHintsCenterX,0,0,100,0));
	but2= new TGTextButton(fF2,"<---",131);
	but2->Connect("Clicked()", "Frame", this, "MoveEntries()");
	but2->Resize(50, 60);
	fF2->AddFrame(but2,new TGLayoutHints(kLHintsTop | kLHintsCenterX,0,0,50,0));
	fF2->Resize();

	char buff2[100];
	fF3->AddFrame(fListBox2 = new TGListBox(fF3, 111),fL1);
	fF3->AddFrame(fCheckMulti2 = new TGCheckButton(fF3, "Multi&Select", 121), fL2);
	fCheckMulti2->Connect("Clicked()", "Frame", this, "MultiSelect()");
	for (int i = 1; i <= 5; ++i)
	{
		sprintf(buff2, "B %d", i-1);
		fListBox2->AddEntry(buff2, i);
	}
	fListBox2->Resize(100, 300);
	fF3->Resize();

	fMain->AddFrame(fF1);
	fMain->AddFrame(fF2);
	fMain->AddFrame(fF3);

	fMain->MapSubwindows();
	fMain->Resize(330,370);
	fMain->MapWindow();
}

Frame::~Frame()
{
	fMain->Cleanup();
 	delete fMain;
}

void Frame::MultiSelect()
{
   	TGButton *btn = (TGButton *) gTQSender;
      	Int_t id = btn->WidgetId();
   	cout<<" Button id: "<<id<<endl;
	
	switch(id)
	{
		case 120:
			fListBox1->SetMultipleSelections(fCheckMulti1->GetState());
         		break;
		case 121:
			fListBox2->SetMultipleSelections(fCheckMulti2->GetState());
         		break;
 		default:
         		break;
	}
}

void Frame::MoveEntries()
{
	TGButton *btn = (TGButton *) gTQSender;
      	Int_t id = btn->WidgetId();
   	cout<<" Button id: "<<id<<endl;
	
	TList *fSelected = new TList;
       	char str[128];
	switch(id)
	{
		case 130:
			//MOVE selected entries to the right listbox;
         		break;
		case 131:
			//COPY selected entries to the left listbox;;
         		break;
 		default:
         		break;
	}
}

void transfer()
{
   	new Frame(gClient->GetRoot(), 500, 500);
}

Can you please help me with how I can achieve that.

Cheers!

Hi,

Sorry, but there is no drag and drop capability from/to a TGListBox

Cheers, Bertrand.

An idea would be to select the items of interest and then have a command button to transfer them to the other list box.

Cheers,