patch from Rob Stevens to add dragndrop-reordering of the tabs

This commit is contained in:
mathias 2004-11-24 23:27:28 +00:00
parent a128e9829f
commit a932a7a801
2 changed files with 113 additions and 0 deletions

View file

@ -357,6 +357,113 @@ void FbWinFrame::moveLabelButtonRight(const FbTk::TextButton &btn) {
redrawTitle(); redrawTitle();
} }
void FbWinFrame::moveLabelButtonTo(FbTk::TextButton &btn, int x, int y) {
Window parent_return=0,
root_return=75,
*children_return=NULL;
unsigned int nchildren_return;
//get the root window
if(!XQueryTree(FbTk::App::instance()->display(), window().window(),
&root_return, &parent_return, &children_return, &nchildren_return))
parent_return=parent_return;//return;
if(children_return!=NULL)
XFree(children_return);
int dest_x=0, dest_y=0;
Window labelbutton=0;
if(!XTranslateCoordinates(FbTk::App::instance()->display(),
root_return, label().window(),
x,y, &dest_x, &dest_y,
&labelbutton))
return;
LabelList::iterator it = m_labelbuttons.begin();
LabelList::iterator it_end = m_labelbuttons.end();
//find the label button to move next to
for(; it!=it_end; it++) {
if( (*it)->window()==labelbutton)
break;
}
//label button not found
if(it==it_end)
return;
Window child_return=0;
//make x and y relative to our labelbutton
if(!XTranslateCoordinates(FbTk::App::instance()->display(),
label().window(),labelbutton,
dest_x,dest_y, &x, &y,
&child_return))
return;
if(x>(*it)->width()/2)
moveLabelButtonRightOf(btn,**it);
else
moveLabelButtonLeftOf(btn,**it);
}
void FbWinFrame::moveLabelButtonLeftOf(const FbTk::TextButton &btn, const FbTk::TextButton &dest) {
LabelList::iterator it = find(m_labelbuttons.begin(),
m_labelbuttons.end(),
&btn);
LabelList::iterator new_pos = find(m_labelbuttons.begin(),
m_labelbuttons.end(),
&dest);
// make sure we found them
if (it == m_labelbuttons.end() || new_pos==m_labelbuttons.end())
{
cout<<"button to move not found"<<endl;
return;
}
//moving a button to the left of itself results in no change
if( new_pos == it)
{
cout<<"source and dest button are the same"<<endl;
return;
}
FbTk::TextButton *item = *it;
//remove from list
m_labelbuttons.erase(it);
//insert on the new place
m_labelbuttons.insert(new_pos, item);
//update titlebar
redrawTitle();
}
void FbWinFrame::moveLabelButtonRightOf(const FbTk::TextButton &btn, const FbTk::TextButton &dest) {
LabelList::iterator it = find(m_labelbuttons.begin(),
m_labelbuttons.end(),
&btn);
LabelList::iterator new_pos = find(m_labelbuttons.begin(),
m_labelbuttons.end(),
&dest);
// make sure we found them
if (it == m_labelbuttons.end() || new_pos==m_labelbuttons.end())
{
cout<<"button to move not found"<<endl;
return;
}
//moving a button to the right of itself results in no change
if( new_pos == it)
{
cout<<"source and dest button are the same"<<endl;
return;
}
FbTk::TextButton *item = *it;
//remove from list
m_labelbuttons.erase(it);
//need to insert into the next position
new_pos++;
//insert on the new place
if(new_pos == m_labelbuttons.end())
m_labelbuttons.push_back(item);
else
m_labelbuttons.insert(new_pos, item);
//update titlebar
redrawTitle();
}
void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn) { void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn) {
if (&btn == currentLabel()) if (&btn == currentLabel())
return; return;

View file

@ -105,6 +105,12 @@ public:
void moveLabelButtonLeft(const FbTk::TextButton &btn); void moveLabelButtonLeft(const FbTk::TextButton &btn);
/// move label button to the right /// move label button to the right
void moveLabelButtonRight(const FbTk::TextButton &btn); void moveLabelButtonRight(const FbTk::TextButton &btn);
/// move label button to the given location( x and y are relative to the root window)
void moveLabelButtonTo(FbTk::TextButton &btn, int x, int y);
/// move the first label button to the left of the second
void moveLabelButtonLeftOf(const FbTk::TextButton &btn, const FbTk::TextButton &dest);
//move the first label button to the right of the second
void moveLabelButtonRightOf(const FbTk::TextButton &btn, const FbTk::TextButton &dest);
/// which button is to be rendered focused /// which button is to be rendered focused
void setLabelButtonFocus(FbTk::TextButton &btn); void setLabelButtonFocus(FbTk::TextButton &btn);
/// attach a client window for client area /// attach a client window for client area