← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2190: tab close button

 

------------------------------------------------------------
revno: 2190
committer: poy <poy@xxxxxxxxxx>
branch nick: repo
timestamp: Sat 2010-08-07 00:46:00 +0200
message:
  tab close button
modified:
  dwt/include/dwt/widgets/TabView.h
  dwt/src/widgets/TabView.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/include/dwt/widgets/TabView.h'
--- dwt/include/dwt/widgets/TabView.h	2010-08-06 21:35:10 +0000
+++ dwt/include/dwt/widgets/TabView.h	2010-08-06 22:46:00 +0000
@@ -160,6 +160,8 @@
 
 	bool inTab;
 	int highlighted;
+	bool highlightClose;
+	bool closeAuthorized;
 
 	typedef std::list<ContainerPtr> WindowList;
 	typedef WindowList::iterator WindowIter;
@@ -170,6 +172,7 @@
 	int active;
 	ContainerPtr dragging;
 	tstring tipText;
+	Rectangle closeRect;
 
 	int findTab(ContainerPtr w) const;
 
@@ -204,6 +207,7 @@
 	void setText(unsigned idx, const tstring& text);
 	void redraw(unsigned index);
 	void draw(Canvas& canvas, unsigned index, Rectangle&& rect, bool isSelected);
+	bool inCloseRect(const ScreenCoordinate& pos) const;
 
 	// AspectCollection
 	void eraseImpl( int row );

=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp	2010-08-06 21:35:10 +0000
+++ dwt/src/widgets/TabView.cpp	2010-08-06 22:46:00 +0000
@@ -64,6 +64,8 @@
 boldFont(0),
 inTab(false),
 highlighted(-1),
+highlightClose(false),
+closeAuthorized(false),
 active(-1),
 dragging(0)
 {
@@ -461,6 +463,7 @@
 		if(mouseEvent.isShiftPressed)
 			ti->w->close();
 		else {
+			closeAuthorized = inCloseRect(mouseEvent.pos);
 			dragging = ti->w;
 			::SetCapture(handle());
 		}
@@ -488,7 +491,11 @@
 		if(dropPos == dragPos) {
 			// the tab hasn't moved; handle the click
 			if(dropPos == active) {
-				if(toggleActive)
+				if(closeAuthorized && inCloseRect(mouseEvent.pos)) {
+					TabInfo* ti = getTabInfo(active);
+					if(ti)
+						ti->w->close();
+				} else if(toggleActive)
 					next();
 			} else
 				setActive(dropPos);
@@ -561,12 +568,19 @@
 	if(highlighted != -1 && i != highlighted) {
 		redraw(highlighted);
 		highlighted = -1;
+		highlightClose = false;
 	}
 	if(i != -1 && i != highlighted) {
 		redraw(i);
 		highlighted = i;
 		onMouseLeave(std::bind(&TabView::handleMouseLeave, this));
 	}
+	if(i != -1 && i == active) {
+		if(highlightClose ^ inCloseRect(mouseEvent.pos)) {
+			highlightClose = !highlightClose;
+			redraw(i);
+		}
+	}
 	return false;
 }
 
@@ -669,8 +683,8 @@
 		rect.size.x -= size.x;
 	}
 
-	//if(isSelected)
-	//	rect.size.x -= margin.x + 16; // keep some space for the 'X' button
+	if(isSelected)
+		rect.size.x -= margin.x + 16; // keep some space for the 'X' button
 
 	const tstring text = ti->w->getText();
 	const unsigned dtFormat = DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_WORD_ELLIPSIS;
@@ -682,11 +696,29 @@
 		canvas.drawText(text, rect, dtFormat);
 	}
 
-	//if(isSelected) {
-	//	rect.pos.x = rect.right() + margin.x;
-	//	rect.size.x = 16;
-	//	drawThemeBackground(canvas, WP_SMALLCLOSEBUTTON, 0, rect);
-	//}
+	if(isSelected) {
+		rect.pos.x = rect.right() + margin.x;
+		rect.size.x = 16;
+		rect.size.y = 16;
+
+		UINT format = DFCS_CAPTIONCLOSE | DFCS_FLAT;
+		if(isHighlighted && highlightClose)
+			format |= DFCS_HOT;
+		::RECT rc(rect);
+		::DrawFrameControl(canvas.handle(), &rc, DFC_CAPTION, format);
+
+		closeRect = rect;
+		closeRect.pos = ScreenCoordinate(ClientCoordinate(closeRect.pos, this)).getPoint();
+		closeRect.size = ScreenCoordinate(ClientCoordinate(closeRect.size, this)).getPoint();
+	}
+}
+
+bool TabView::inCloseRect(const ScreenCoordinate& pos) const {
+	if(closeRect.width() > 0 && closeRect.height() > 0) {
+		::RECT rc(closeRect);
+		return ::PtInRect(&rc, pos.getPoint());
+	}
+	return false;
 }
 
 void TabView::helpImpl(unsigned& id) {