← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2726: add a search icon in filter boxes

 

------------------------------------------------------------
revno: 2726
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2011-12-18 14:39:46 +0100
message:
  add a search icon in filter boxes
modified:
  win32/ListFilter.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 'win32/ListFilter.cpp'
--- win32/ListFilter.cpp	2011-12-17 14:08:57 +0000
+++ win32/ListFilter.cpp	2011-12-18 13:39:46 +0000
@@ -19,6 +19,10 @@
 #include "stdafx.h"
 #include "ListFilter.h"
 
+#include <dwt/WidgetCreator.h>
+
+#include "resource.h"
+
 ListFilter::ListFilter(const ColumnInfo* columns, size_t colCount, UpdateF updateF) :
 columns(columns),
 colCount(colCount),
@@ -28,11 +32,25 @@
 
 void ListFilter::createTextBox(GridPtr grid) {
 	auto seed = WinUtil::Seeds::textBox;
-	seed.style |= ES_AUTOHSCROLL;
+	seed.style |= ES_AUTOHSCROLL | WS_CLIPCHILDREN;
 	seed.exStyle |= WS_EX_TRANSPARENT;
 	text = grid->addChild(seed);
 
 	text->onUpdated([this] { textUpdated(); });
+
+	// add a search icon by creating a transparent label on top of the text control.
+
+	// structure of the right border: text | spacing | icon | margin | right border
+	const int spacing = 2, size = 16;
+	const auto margin = HIWORD(text->sendMessage(EM_GETMARGINS));
+	text->sendMessage(EM_SETMARGINS, EC_RIGHTMARGIN, MAKELONG(0, spacing + size + margin));
+
+	auto label = dwt::WidgetCreator<Label>::create(text, Label::Seed(IDI_SEARCH));
+	label->onRaw([](WPARAM, LPARAM) { return reinterpret_cast<LRESULT>(::GetStockObject(NULL_BRUSH)); }, dwt::Message(WM_CTLCOLOR));
+	text->onSized([this, label, size, margin](const dwt::SizedEvent&) {
+		auto box = text->getClientSize();
+		label->resize(dwt::Rectangle(box.x - margin - size, std::max(box.y - size, 0L) / 2, size, size));
+	});
 }
 
 void ListFilter::createColumnBox(GridPtr grid) {