|
From: <arn...@us...> - 2008-01-04 21:03:40
|
Revision: 960
http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=960&view=rev
Author: arnetheduck
Date: 2008-01-04 13:03:38 -0800 (Fri, 04 Jan 2008)
Log Message:
-----------
tab drag/drop
Modified Paths:
--------------
dcplusplus/trunk/changelog.txt
dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabSheet.h
dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h
dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp
Modified: dcplusplus/trunk/changelog.txt
===================================================================
--- dcplusplus/trunk/changelog.txt 2008-01-04 15:55:23 UTC (rev 959)
+++ dcplusplus/trunk/changelog.txt 2008-01-04 21:03:38 UTC (rev 960)
@@ -10,6 +10,7 @@
* Fixed an issue with nick encodings and nmdc connections (thanks stanislav maslovski)
* Added download view which shows per-file download information
* Chat timestamps on by default
+* Added tab drag/drop (thanks poy)
-- 0.704 2007-12-14 --
* Hub lists added to utilize Coral's distributed network (ullner)
Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabSheet.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabSheet.h 2008-01-04 15:55:23 UTC (rev 959)
+++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabSheet.h 2008-01-04 21:03:38 UTC (rev 960)
@@ -165,7 +165,9 @@
*/
// the negative values are already covered by throwing an exception
unsigned int addPage( const SmartUtil::tstring & header, unsigned index, LPARAM lParam = 0, int image = -1 );
-
+
+ int getImage(unsigned idx) const;
+
LPARAM getData(unsigned idx);
void setData(unsigned idx, LPARAM data);
@@ -297,6 +299,16 @@
return buffer;
}
+inline int WidgetTabSheet::getImage(unsigned idx) const
+{
+ TCITEM item = { TCIF_IMAGE };
+ if ( !TabCtrl_GetItem( this->handle(), idx, & item ) )
+ {
+ throw xCeption( _T( "Couldn't get image of item." ) );
+ }
+ return item.iImage;
+}
+
inline LPARAM WidgetTabSheet::getData(unsigned idx)
{
TCITEM item = { TCIF_PARAM };
Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h 2008-01-04 15:55:23 UTC (rev 959)
+++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h 2008-01-04 21:03:38 UTC (rev 960)
@@ -88,6 +88,7 @@
Rectangle clientSize;
std::vector<IconPtr> icons;
int active;
+ int dragging;
int findTab(WidgetChildWindow* w);
@@ -100,6 +101,8 @@
bool handleTextChanging(WidgetChildWindow* w, const SmartUtil::tstring& newText);
bool handleSized(const WidgetSizedEventResult&);
void handleTabSelected();
+ void handleLeftMouseDown(const MouseEventResult& mouseEventResult);
+ void handleLeftMouseUp(const MouseEventResult& mouseEventResult);
bool handleContextMenu(SmartWin::ScreenCoordinate pt);
void handleMiddleMouseDown(const MouseEventResult& mouseEventResult);
Modified: dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp
===================================================================
--- dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp 2008-01-04 15:55:23 UTC (rev 959)
+++ dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp 2008-01-04 21:03:38 UTC (rev 960)
@@ -16,7 +16,8 @@
PolicyType(w),
tab(0),
inTab(false),
- active(-1)
+ active(-1),
+ dragging(-1)
{ }
void WidgetTabView::create(const Seed & cs) {
@@ -30,6 +31,8 @@
tab->onSelectionChanged(std::tr1::bind(&WidgetTabView::handleTabSelected, this));
onSized(std::tr1::bind(&WidgetTabView::handleSized, this, _1));
+ tab->onLeftMouseDown(std::tr1::bind(&WidgetTabView::handleLeftMouseDown, this, _1));
+ tab->onLeftMouseUp(std::tr1::bind(&WidgetTabView::handleLeftMouseUp, this, _1));
tab->onContextMenu(std::tr1::bind(&WidgetTabView::handleContextMenu, this, _1));
tab->onMiddleMouseDown(std::tr1::bind(&WidgetTabView::handleMiddleMouseDown, this, _1));
}
@@ -269,6 +272,56 @@
return image;
}
+void WidgetTabView::handleLeftMouseDown(const MouseEventResult& mouseEventResult) {
+ int i = tab->hitTest(mouseEventResult.pos);
+ if(i != -1) {
+ if(mouseEventResult.isShiftPressed)
+ getTabInfo(i)->w->close();
+ else {
+ dragging = i;
+ ::SetCapture(tab->handle());
+ }
+ }
+}
+
+void WidgetTabView::handleLeftMouseUp(const MouseEventResult& mouseEventResult) {
+ ::ReleaseCapture();
+
+ if(dragging != -1) {
+ int dropPos = tab->hitTest(mouseEventResult.pos);
+
+ if(dropPos == -1) {
+ // not in the tab control; move the tab to the end
+ dropPos = tab->size() - 1;
+ }
+
+ if(dropPos == dragging) {
+ // the tab hasn't moved; select it
+ setActive(dropPos);
+ dragging = -1;
+ return;
+ }
+
+ // save some information about the tab before we erase it
+ TabInfo* ti = getTabInfo(dragging);
+ int image = tab->getImage(dragging);
+
+ tab->erase(dragging);
+
+ tab->addPage(cutTitle(ti->w->getText()), dropPos, reinterpret_cast<LPARAM>(ti), image);
+
+ // in case the active tab was moved
+ if(dragging == active)
+ active = dropPos;
+ else if(dropPos == active)
+ active = dragging;
+
+ layout();
+
+ dragging = -1;
+ }
+}
+
bool WidgetTabView::handleContextMenu(ScreenCoordinate pt) {
TabInfo* ti = 0;
if(pt.x() == -1 && pt.y() == -1) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|