From: <arn...@us...> - 2007-12-03 22:25:42
|
Revision: 926 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=926&view=rev Author: arnetheduck Date: 2007-12-03 14:25:40 -0800 (Mon, 03 Dec 2007) Log Message: ----------- patches, begin upgrade to adc 1.0 (protocol string, features, error handling etc) Modified Paths: -------------- dcplusplus/trunk/changelog.txt dcplusplus/trunk/dcpp/AdcCommand.h dcplusplus/trunk/dcpp/AdcHub.cpp dcplusplus/trunk/dcpp/AdcHub.h dcplusplus/trunk/dcpp/BufferedSocket.cpp dcplusplus/trunk/dcpp/ClientManager.cpp dcplusplus/trunk/dcpp/FavoriteManager.cpp dcplusplus/trunk/dcpp/FavoriteManager.h dcplusplus/trunk/dcpp/SearchManager.cpp dcplusplus/trunk/dcpp/User.h dcplusplus/trunk/dcpp/UserCommand.h dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetToolbar.h dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp dcplusplus/trunk/smartwin/source/widgets/WidgetToolbar.cpp Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/changelog.txt 2007-12-03 22:25:40 UTC (rev 926) @@ -7,7 +7,7 @@ * Fixed version info (poy) * Keep selection visible on move up/down in some list views (poy) * Fixed clicking in the header of the favorite hubs list view (poy) -* Update to ADC 0.14 +* Update to ADC 1.0 * Fixed pressing enter in the notepad (poy) * Fixed user commands params (poy) * Readded list view double buffering (thanks poy) @@ -19,6 +19,10 @@ * Fixed user list filter (poy) * Readded chat message box auto-scroll (poy) * Fixed tab order in public hubs (poy) +* Tooltips for toolbars (thanks poy) +* Close tab with middle mouse button (thanks poy) +* Fixed socket ip bind (thanks garg's quasi-friend) +* Finished UCMD extension draft implementation -- 0.703 2007-11-08 -- * Fixed invalid strings (thanks james ross) Modified: dcplusplus/trunk/dcpp/AdcCommand.h =================================================================== --- dcplusplus/trunk/dcpp/AdcCommand.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/AdcCommand.h 2007-12-03 22:25:40 UTC (rev 926) @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if !defined(ADC_COMMAND_H) -#define ADC_COMMAND_H +#ifndef DCPLUSPLUS_DCPP_ADC_COMMAND_H +#define DCPLUSPLUS_DCPP_ADC_COMMAND_H #include "SettingsManager.h" #include "Exception.h" @@ -58,10 +58,12 @@ ERROR_BAD_STATE = 44, ERROR_FEATURE_MISSING = 45, ERROR_BAD_IP = 46, + ERROR_NO_HUB_HASH = 47, ERROR_TRANSFER_GENERIC = 50, ERROR_FILE_NOT_AVAILABLE = 51, ERROR_FILE_PART_NOT_AVAILABLE = 52, - ERROR_SLOTS_FULL = 53 + ERROR_SLOTS_FULL = 53, + ERROR_NO_CLIENT_HASH = 54 }; enum Severity { Modified: dcplusplus/trunk/dcpp/AdcHub.cpp =================================================================== --- dcplusplus/trunk/dcpp/AdcHub.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/AdcHub.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -28,21 +28,22 @@ #include "version.h" #include "Util.h" #include "UserCommand.h" -#include "FavoriteManager.h" #include "CryptoManager.h" #include "ResourceManager.h" #include "LogManager.h" namespace dcpp { -const string AdcHub::CLIENT_PROTOCOL("ADC/0.10"); -const string AdcHub::SECURE_CLIENT_PROTOCOL("ADCS/0.10"); +const string AdcHub::CLIENT_PROTOCOL("ADC/1.0"); +const string AdcHub::CLIENT_PROTOCOL_TEST("ADC/0.10"); +const string AdcHub::SECURE_CLIENT_PROTOCOL_TEST("ADCS/0.10"); const string AdcHub::ADCS_FEATURE("ADC0"); const string AdcHub::TCP4_FEATURE("TCP4"); const string AdcHub::UDP4_FEATURE("UDP4"); const string AdcHub::BASE_SUPPORT("ADBASE"); const string AdcHub::BAS0_SUPPORT("ADBAS0"); const string AdcHub::TIGR_SUPPORT("ADTIGR"); +const string AdcHub::UCM0_SUPPORT("ADUCM0"); AdcHub::AdcHub(const string& aHubURL, bool secure) : Client(aHubURL, '\n', secure), sid(0) { TimerManager::getInstance()->addListener(this); @@ -288,10 +289,10 @@ token = c.getParam(2); } - bool secure; - if(protocol == CLIENT_PROTOCOL) { - secure = false; - } else if(protocol == SECURE_CLIENT_PROTOCOL && CryptoManager::getInstance()->TLSOk()) { + bool secure = false; + if(protocol == CLIENT_PROTOCOL || protocol == CLIENT_PROTOCOL_TEST) { + // Nothing special + } else if(protocol == SECURE_CLIENT_PROTOCOL_TEST && CryptoManager::getInstance()->TLSOk()) { secure = true; } else { AdcCommand cmd(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_UNSUPPORTED, "Protocol unknown"); @@ -328,9 +329,9 @@ bool hasToken = c.getParam("TO", 1, token); bool secure; - if(protocol == CLIENT_PROTOCOL) { + if(protocol == CLIENT_PROTOCOL || protocol == CLIENT_PROTOCOL_TEST) { secure = false; - } else if(protocol == SECURE_CLIENT_PROTOCOL && CryptoManager::getInstance()->TLSOk()) { + } else if(protocol == SECURE_CLIENT_PROTOCOL_TEST && CryptoManager::getInstance()->TLSOk()) { secure = true; } else { AdcCommand cmd(AdcCommand::SEV_FATAL, AdcCommand::ERROR_PROTOCOL_UNSUPPORTED, "Protocol unknown"); @@ -352,9 +353,8 @@ const string& name = c.getParam(0); bool rem = c.hasFlag("RM", 1); if(rem) { - int cmd = FavoriteManager::getInstance()->findUserCommand(name); - if(cmd != -1) - FavoriteManager::getInstance()->removeUserCommand(cmd); + fire(ClientListener::HubUserCommand(), this, (int)UserCommand::TYPE_REMOVE, 0, name, Util::emptyString); + return; } bool sep = c.hasFlag("SP", 1); string sctx; @@ -364,14 +364,14 @@ if(ctx <= 0) return; if(sep) { - FavoriteManager::getInstance()->addUserCommand(UserCommand::TYPE_SEPARATOR, ctx, UserCommand::FLAG_NOSAVE, name, "", getHubUrl()); + fire(ClientListener::HubUserCommand(), this, (int)UserCommand::TYPE_SEPARATOR, ctx, name, Util::emptyString); return; } bool once = c.hasFlag("CO", 1); string txt; if(!c.getParam("TT", 1, txt)) return; - FavoriteManager::getInstance()->addUserCommand(once ? UserCommand::TYPE_RAW_ONCE : UserCommand::TYPE_RAW, ctx, UserCommand::FLAG_NOSAVE, name, txt, getHubUrl()); + fire(ClientListener::HubUserCommand(), this, (int)(once ? UserCommand::TYPE_RAW_ONCE : UserCommand::TYPE_RAW), ctx, name, txt); } void AdcHub::sendUDP(const AdcCommand& cmd) throw() { @@ -417,8 +417,19 @@ if(code == AdcCommand::ERROR_BAD_PASSWORD) { setPassword(Util::emptyString); + } else if(code == AdcCommand::ERROR_PROTOCOL_UNSUPPORTED) { + string tmp; + if(c.getParam("PR", 1, tmp)) { + if(tmp == CLIENT_PROTOCOL) { + u->getUser()->setFlag(User::NO_ADC_1_0_PROTOCOL); + } else if(tmp == CLIENT_PROTOCOL_TEST) { + u->getUser()->setFlag(User::NO_ADC_0_10_PROTOCOL); + } else if(tmp == SECURE_CLIENT_PROTOCOL_TEST) { + u->getUser()->setFlag(User::NO_ADCS_0_10_PROTOCOL); + u->getUser()->unsetFlag(User::TLS); + } + } } - // @todo Check for invalid protocol and unset TLS if necessary fire(ClientListener::Message(), this, *u, c.getParam(1)); } @@ -448,8 +459,26 @@ void AdcHub::connect(const OnlineUser& user, string const& token, bool secure) { if(state != STATE_NORMAL) return; + + const string* proto = 0; + if(secure) { + if(user.getUser()->isSet(User::NO_ADCS_0_10_PROTOCOL)) { + /// @todo log + return; + } + proto = &SECURE_CLIENT_PROTOCOL_TEST; + } else { + if(user.getUser()->isSet(User::NO_ADC_1_0_PROTOCOL)) { + if(user.getUser()->isSet(User::NO_ADC_0_10_PROTOCOL)) { + /// @todo log + return; + } + proto = &CLIENT_PROTOCOL_TEST; + } else { + proto = &CLIENT_PROTOCOL; + } + } - const string& proto = secure ? SECURE_CLIENT_PROTOCOL : CLIENT_PROTOCOL; if(ClientManager::getInstance()->isActive()) { uint16_t port = secure ? ConnectionManager::getInstance()->getSecurePort() : ConnectionManager::getInstance()->getPort(); if(port == 0) { @@ -457,9 +486,9 @@ LogManager::getInstance()->message(STRING(NOT_LISTENING)); return; } - send(AdcCommand(AdcCommand::CMD_CTM, user.getIdentity().getSID(), AdcCommand::TYPE_DIRECT).addParam(proto).addParam(Util::toString(port)).addParam(token)); + send(AdcCommand(AdcCommand::CMD_CTM, user.getIdentity().getSID(), AdcCommand::TYPE_DIRECT).addParam(*proto).addParam(Util::toString(port)).addParam(token)); } else { - send(AdcCommand(AdcCommand::CMD_RCM, user.getIdentity().getSID(), AdcCommand::TYPE_DIRECT).addParam(proto).addParam(token)); + send(AdcCommand(AdcCommand::CMD_RCM, user.getIdentity().getSID(), AdcCommand::TYPE_DIRECT).addParam(*proto).addParam(token)); } } @@ -576,7 +605,6 @@ addParam(lastInfoMap, c, "DS", Util::emptyString); } - string su; if(CryptoManager::getInstance()->TLSOk()) { su += ADCS_FEATURE + ","; @@ -637,7 +665,13 @@ lastInfoMap.clear(); sid = 0; - send(AdcCommand(AdcCommand::CMD_SUP, AdcCommand::TYPE_HUB).addParam(BAS0_SUPPORT).addParam(TIGR_SUPPORT)); + AdcCommand cmd(AdcCommand::CMD_SUP, AdcCommand::TYPE_HUB); + cmd.addParam(BAS0_SUPPORT).addParam(TIGR_SUPPORT); + + if(BOOLSETTING(HUB_USER_COMMANDS)) { + cmd.addParam(UCM0_SUPPORT); + } + send(cmd); } void AdcHub::on(Line, const string& aLine) throw() { Modified: dcplusplus/trunk/dcpp/AdcHub.h =================================================================== --- dcplusplus/trunk/dcpp/AdcHub.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/AdcHub.h 2007-12-03 22:25:40 UTC (rev 926) @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if !defined(ADC_HUB_H) -#define ADC_HUB_H +#ifndef DCPLUSPLUS_DCPP_ADC_HUB_H +#define DCPLUSPLUS_DCPP_ADC_HUB_H #include "Client.h" #include "AdcCommand.h" @@ -73,13 +73,15 @@ uint32_t sid; static const string CLIENT_PROTOCOL; - static const string SECURE_CLIENT_PROTOCOL; + static const string CLIENT_PROTOCOL_TEST; + static const string SECURE_CLIENT_PROTOCOL_TEST; static const string ADCS_FEATURE; static const string TCP4_FEATURE; static const string UDP4_FEATURE; static const string BASE_SUPPORT; static const string BAS0_SUPPORT; static const string TIGR_SUPPORT; + static const string UCM0_SUPPORT; virtual string checkNick(const string& nick); Modified: dcplusplus/trunk/dcpp/BufferedSocket.cpp =================================================================== --- dcplusplus/trunk/dcpp/BufferedSocket.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/BufferedSocket.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -112,6 +112,7 @@ sock = secure ? CryptoManager::getInstance()->getClientSocket(allowUntrusted) : new Socket; sock->create(); + sock->bind(0, SETTING(BIND_ADDRESS)); if(SETTING(SOCKET_IN_BUFFER) >= 1024) sock->setSocketOpt(SO_RCVBUF, SETTING(SOCKET_IN_BUFFER)); if(SETTING(SOCKET_OUT_BUFFER) >= 1024) Modified: dcplusplus/trunk/dcpp/ClientManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/ClientManager.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/ClientManager.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -481,7 +481,11 @@ void ClientManager::on(HubUserCommand, Client* client, int aType, int ctx, const string& name, const string& command) throw() { if(BOOLSETTING(HUB_USER_COMMANDS)) { - if(aType == UserCommand::TYPE_CLEAR) { + if(aType == UserCommand::TYPE_REMOVE) { + int cmd = FavoriteManager::getInstance()->findUserCommand(name, client->getHubUrl()); + if(cmd != -1) + FavoriteManager::getInstance()->removeUserCommand(cmd); + } else if(aType == UserCommand::TYPE_CLEAR) { FavoriteManager::getInstance()->removeHubUserCommands(ctx, client->getHubUrl()); } else { FavoriteManager::getInstance()->addUserCommand(aType, ctx, UserCommand::FLAG_NOSAVE, name, command, client->getHubUrl()); Modified: dcplusplus/trunk/dcpp/FavoriteManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/FavoriteManager.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/FavoriteManager.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -98,10 +98,10 @@ save(); } -int FavoriteManager::findUserCommand(const string& aName) { +int FavoriteManager::findUserCommand(const string& aName, const string& aUrl) { Lock l(cs); for(UserCommand::List::iterator i = userCommands.begin(); i != userCommands.end(); ++i) { - if(i->getName() == aName) { + if(i->getName() == aName && i->getHub() == aUrl) { return i->getId(); } } Modified: dcplusplus/trunk/dcpp/FavoriteManager.h =================================================================== --- dcplusplus/trunk/dcpp/FavoriteManager.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/FavoriteManager.h 2007-12-03 22:25:40 UTC (rev 926) @@ -90,7 +90,7 @@ // User Commands UserCommand addUserCommand(int type, int ctx, int flags, const string& name, const string& command, const string& hub); bool getUserCommand(int cid, UserCommand& uc); - int findUserCommand(const string& aName); + int findUserCommand(const string& aName, const string& aUrl); bool moveUserCommand(int cid, int pos); void updateUserCommand(const UserCommand& uc); void removeUserCommand(int cid); Modified: dcplusplus/trunk/dcpp/SearchManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/SearchManager.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/SearchManager.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -126,7 +126,7 @@ socket = new Socket(); socket->create(Socket::TYPE_UDP); - port = socket->bind(static_cast<uint16_t>(SETTING(UDP_PORT))); + port = socket->bind(static_cast<uint16_t>(SETTING(UDP_PORT)), SETTING(BIND_ADDRESS)); start(); } @@ -166,7 +166,7 @@ try { socket->disconnect(); socket->create(Socket::TYPE_UDP); - socket->bind(port); + socket->bind(port, SETTING(BIND_ADDRESS)); } catch(const SocketException& e) { // Oops, fatal this time... dcdebug("SearchManager::run Stopped listening: %s\n", e.getError().c_str()); Modified: dcplusplus/trunk/dcpp/User.h =================================================================== --- dcplusplus/trunk/dcpp/User.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/User.h 2007-12-03 22:25:40 UTC (rev 926) @@ -40,7 +40,10 @@ NMDC_BIT, BOT_BIT, TLS_BIT, - OLD_CLIENT_BIT + OLD_CLIENT_BIT, + NO_ADC_1_0_PROTOCOL_BIT, + NO_ADC_0_10_PROTOCOL_BIT, + NO_ADCS_0_10_PROTOCOL_BIT }; /** Each flag is set if it's true in at least one hub */ @@ -51,7 +54,10 @@ NMDC = 1<<NMDC_BIT, BOT = 1<<BOT_BIT, TLS = 1<<TLS_BIT, //< Client supports TLS - OLD_CLIENT = 1<<OLD_CLIENT_BIT //< Can't download - old client + OLD_CLIENT = 1<<OLD_CLIENT_BIT, //< Can't download - old client + NO_ADC_1_0_PROTOCOL = 1<<NO_ADC_1_0_PROTOCOL_BIT, //< Doesn't support "ADC/1.0" (dc++ <=0.703) + NO_ADC_0_10_PROTOCOL = 1<<NO_ADC_0_10_PROTOCOL_BIT, //< Doesn't support "ADC/0.10" + NO_ADCS_0_10_PROTOCOL = 1<< NO_ADCS_0_10_PROTOCOL_BIT //< Doesn't support "ADCS/0.10" }; struct Hash { @@ -90,8 +96,9 @@ CT_BOT = 1, CT_REGGED = 2, CT_OP = 4, - CT_OWNER = 8, - CT_HUB = 16 + CT_SU = 8, + CT_OWNER = 16, + CT_HUB = 32 }; Identity() : sid(0) { } @@ -117,7 +124,7 @@ string getTag() const; bool supports(const string& name) const; bool isHub() const { return isClientType(CT_HUB) || !get("HU").empty(); } - bool isOp() const { return isClientType(CT_OP) || !get("OP").empty(); } + bool isOp() const { return isClientType(CT_OP) || isClientType(CT_SU) || isClientType(CT_OWNER) || !get("OP").empty(); } bool isRegistered() const { return isClientType(CT_REGGED) || !get("RG").empty(); } bool isHidden() const { return !get("HI").empty(); } bool isBot() const { return isClientType(CT_BOT) || !get("BO").empty(); } Modified: dcplusplus/trunk/dcpp/UserCommand.h =================================================================== --- dcplusplus/trunk/dcpp/UserCommand.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/dcpp/UserCommand.h 2007-12-03 22:25:40 UTC (rev 926) @@ -32,7 +32,8 @@ TYPE_SEPARATOR, TYPE_RAW, TYPE_RAW_ONCE, - TYPE_CLEAR = 255 + TYPE_REMOVE, + TYPE_CLEAR = 255 // In a momentary lapse of reason, 255 was chosen in the nmdc version of usercommand for clearing them all }; enum { Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h 2007-12-03 22:25:40 UTC (rev 926) @@ -101,6 +101,7 @@ bool handleSized(const WidgetSizedEventResult&); void handleTabSelected(); bool handleContextMenu(SmartWin::ScreenCoordinate pt); + void handleMiddleMouseDown(const MouseEventResult& mouseEventResult); SmartUtil::tstring cutTitle(const SmartUtil::tstring& title); void layout(); Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetToolbar.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetToolbar.h 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetToolbar.h 2007-12-03 22:25:40 UTC (rev 926) @@ -171,8 +171,6 @@ virtual bool tryFire( const MSG & msg, LRESULT & retVal ); private: - std::map< unsigned int, SmartUtil::tstring > itsToolTips; - // Keep references ImageListPtr itsNormalImageList; ImageListPtr itsHotImageList; Modified: dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp =================================================================== --- dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -31,6 +31,7 @@ onSized(std::tr1::bind(&WidgetTabView::handleSized, this, _1)); tab->onContextMenu(std::tr1::bind(&WidgetTabView::handleContextMenu, this, _1)); + tab->onMiddleMouseDown(std::tr1::bind(&WidgetTabView::handleMiddleMouseDown, this, _1)); } void WidgetTabView::add(WidgetChildWindow* w, const IconPtr& icon) { @@ -268,7 +269,7 @@ return image; } -bool WidgetTabView::handleContextMenu(SmartWin::ScreenCoordinate pt) { +bool WidgetTabView::handleContextMenu(ScreenCoordinate pt) { TabInfo* ti = 0; if(pt.x() == -1 && pt.y() == -1) { int i = tab->getSelectedIndex(); @@ -294,6 +295,12 @@ return false; } +void WidgetTabView::handleMiddleMouseDown(const MouseEventResult& mouseEventResult) { + TabInfo* ti = getTabInfo(tab->hitTest(mouseEventResult.pos)); + if(ti) + ti->w->close(); +} + bool WidgetTabView::filter(const MSG& msg) { if(msg.message == WM_KEYUP && msg.wParam == VK_CONTROL) { inTab = false; Modified: dcplusplus/trunk/smartwin/source/widgets/WidgetToolbar.cpp =================================================================== --- dcplusplus/trunk/smartwin/source/widgets/WidgetToolbar.cpp 2007-12-01 23:34:02 UTC (rev 925) +++ dcplusplus/trunk/smartwin/source/widgets/WidgetToolbar.cpp 2007-12-03 22:25:40 UTC (rev 926) @@ -3,7 +3,7 @@ namespace SmartWin { WidgetToolbar::Seed::Seed() : - Widget::Seed(TOOLBARCLASSNAME, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS) + Widget::Seed(TOOLBARCLASSNAME, WS_CHILD | WS_VISIBLE | TBSTYLE_LIST | TBSTYLE_TOOLTIPS) { } @@ -11,6 +11,8 @@ { ControlType::create(cs); + this->sendMessage(TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS); + //// Telling the toolbar what the size of TBBUTTON struct is this->sendMessage(TB_BUTTONSTRUCTSIZE, ( WPARAM ) sizeof( TBBUTTON )); } @@ -30,46 +32,25 @@ void WidgetToolbar::appendItem( unsigned int id, int image, const SmartUtil::tstring& toolTip, const Dispatcher::F& f) { - // Checking if tooltip id exists from before - if ( itsToolTips.find( id ) != itsToolTips.end() ) - { - xCeption x( _T( "Tried to add a button with an ID that already exists..." ) ); - throw x; - } - // Adding button TBBUTTON tb = { 0 }; tb.iBitmap = image; tb.idCommand = id; tb.fsState = TBSTATE_ENABLED; tb.fsStyle = BTNS_AUTOSIZE; + tb.iString = reinterpret_cast<INT_PTR>(toolTip.c_str()); if ( this->sendMessage(TB_ADDBUTTONS, 1, reinterpret_cast< LPARAM >( &tb ) ) == FALSE ) { xCeption x( _T( "Error while trying to add a button to toolbar..." ) ); throw x; } - - if(!toolTip.empty()) { - itsToolTips[id] = toolTip; - } - + if(f) setCallback(Message(WM_COMMAND, id), Dispatcher(f)); } bool WidgetToolbar::tryFire( const MSG & msg, LRESULT & retVal ) { - if(msg.message == WM_NOTIFY) { - LPNMHDR hdr = reinterpret_cast< LPNMHDR >( msg.lParam ); - if(hdr->code == TTN_GETDISPINFO) { - LPTOOLTIPTEXT lpttt = reinterpret_cast< LPTOOLTIPTEXT >( msg.lParam ); - if(itsToolTips.find(lpttt->hdr.idFrom) != itsToolTips.end()) { - lpttt->lpszText = const_cast < TCHAR * >( itsToolTips[lpttt->hdr.idFrom].c_str() ); - return true; - } - } - } - bool handled = PolicyType::tryFire(msg, retVal); if(!handled && msg.message == WM_COMMAND) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |