linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05007
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2738: throw exceptions from dwt asserts (to have Win error codes)
------------------------------------------------------------
revno: 2738
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-12-23 15:07:18 +0100
message:
throw exceptions from dwt asserts (to have Win error codes)
modified:
dwt/include/dwt/util/check.h
dwt/include/dwt/widgets/DateTime.h
dwt/include/dwt/widgets/MDIParent.h
dwt/include/dwt/widgets/ToolTip.h
dwt/src/Icon.cpp
dwt/src/LibraryLoader.cpp
dwt/src/Taskbar.cpp
dwt/src/Theme.cpp
dwt/src/util/GDI.cpp
dwt/src/widgets/Grid.cpp
dwt/src/widgets/Menu.cpp
dwt/src/widgets/MessageBox.cpp
dwt/src/widgets/Spinner.cpp
dwt/src/widgets/StatusBar.cpp
dwt/src/widgets/TabView.cpp
dwt/src/widgets/Table.cpp
dwt/src/widgets/TextBox.cpp
dwt/src/widgets/ToolTip.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/util/check.h'
--- dwt/include/dwt/util/check.h 2011-11-09 12:07:26 +0000
+++ dwt/include/dwt/util/check.h 2011-12-23 14:07:18 +0000
@@ -32,21 +32,28 @@
#ifndef DWT_CHECK_H_
#define DWT_CHECK_H_
+#include <dwt/DWTException.h>
+
namespace dwt { namespace util {
#ifdef _DEBUG
-#define dwtDebugFail(m) assert( (false && (m)) )
+#define dwtDebugFail(m) throw DWTException(m)
+#define dwtWin32DebugFail(m) throw Win32Exception(m)
+
+#define dwtassert(x, m) do { bool assertCheck = x; if(!assertCheck) dwtDebugFail(m); } while(false)
+#define dwtWin32Assert(x, m) do { bool assertCheck = x; if(!assertCheck) dwtWin32DebugFail(m); } while(false)
#else
-#define dwtDebugFail(m) do {} while(false)
+#define dwtDebugFail(m)
+#define dwtWin32DebugFail(m)
+
+#define dwtassert(x, m)
+#define dwtWin32Assert(x, m)
#endif
-#define dwtassert(x, m) assert( (x) && (m) )
-
-#define dwtWin32DebugFail(m) dwtDebugFail(m)
-
} }
+
#endif /*CHECK_H_*/
=== modified file 'dwt/include/dwt/widgets/DateTime.h'
--- dwt/include/dwt/widgets/DateTime.h 2011-11-07 22:11:39 +0000
+++ dwt/include/dwt/widgets/DateTime.h 2011-12-23 14:07:18 +0000
@@ -37,7 +37,6 @@
#define DWT_DateTime_h
#include "../aspects/Clickable.h"
-#include "../util/check.h"
#include "Control.h"
namespace dwt {
@@ -227,8 +226,6 @@
inline DateTime::DateTime( Widget* parent )
: BaseType(parent, ChainingDispatcher::superClass<DateTime>())
{
- // Can't have a text box without a parent...
- dwtassert( parent, _T( "Can't have a TextBox without a parent..." ) );
}
inline void DateTime::setBackgroundColor( COLORREF color )
=== modified file 'dwt/include/dwt/widgets/MDIParent.h'
--- dwt/include/dwt/widgets/MDIParent.h 2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/widgets/MDIParent.h 2011-12-23 14:07:18 +0000
@@ -148,8 +148,7 @@
inline MDIParent::MDIParent( Widget * parent )
: BaseType(parent, NormalDispatcher::getDefault())
{
- // Can't have a text box without a parent...
- dwtassert( parent, _T( "Can't have a MDIParent without a parent..." ) );
+ dwtassert(parent, "Can't have a MDIParent without a parent...");
}
// end namespace dwt
=== modified file 'dwt/include/dwt/widgets/ToolTip.h'
--- dwt/include/dwt/widgets/ToolTip.h 2011-11-07 22:11:39 +0000
+++ dwt/include/dwt/widgets/ToolTip.h 2011-12-23 14:07:18 +0000
@@ -110,7 +110,7 @@
inline ToolTip::ToolTip(Widget *parent)
: BaseType(parent, ChainingDispatcher::superClass<ToolTip>())
{
- dwtassert( parent, _T( "Can't have a ToolTip without a parent..." ) );
+ dwtassert(parent, "Can't have a ToolTip without a parent...");
}
inline void ToolTip::setMaxTipWidth(int width) {
=== modified file 'dwt/src/Icon.cpp'
--- dwt/src/Icon.cpp 2011-06-03 18:22:44 +0000
+++ dwt/src/Icon.cpp 2011-12-23 14:07:18 +0000
@@ -56,12 +56,18 @@
ResourceType((HICON)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(resourceId), IMAGE_ICON, size.x, size.y, LR_DEFAULTCOLOR)),
resId(resourceId)
{
+ if(!handle()) {
+ throw Win32Exception("Failed to create an icon from a resource");
+ }
}
Icon::Icon(const tstring& filePath, const Point& size) :
ResourceType((HICON)::LoadImage(0, filePath.c_str(), IMAGE_ICON, size.x, size.y, LR_DEFAULTCOLOR | LR_LOADFROMFILE)),
resId(0)
{
+ if(!handle()) {
+ throw Win32Exception("Failed to create an icon from a file");
+ }
}
Point Icon::getSize() const {
=== modified file 'dwt/src/LibraryLoader.cpp'
--- dwt/src/LibraryLoader.cpp 2011-11-07 18:36:42 +0000
+++ dwt/src/LibraryLoader.cpp 2011-12-23 14:07:18 +0000
@@ -67,7 +67,7 @@
// TODO: Rewrite xAssert to get support for submitting tstrings (could show library name)
if(!allowFailure) {
- dwtassert( itsHMod != 0, _T( "Error while trying to load library or dll!" ) );
+ dwtassert(itsHMod != 0, "Error while trying to load library or dll!");
}
}
=== modified file 'dwt/src/Taskbar.cpp'
--- dwt/src/Taskbar.cpp 2011-04-25 20:41:09 +0000
+++ dwt/src/Taskbar.cpp 2011-12-23 14:07:18 +0000
@@ -88,7 +88,7 @@
}
window = window_;
- dwtassert(window, _T("Taskbar: no widget set"));
+ dwtassert(window, "Taskbar: no widget set");
/* init the ITaskbarList3 COM pointer. MSDN recommends waiting for the
"TaskbarButtonCreated" message, but neither MFC nor Win SDK samples do that, so we don't
=== modified file 'dwt/src/Theme.cpp'
--- dwt/src/Theme.cpp 2011-10-26 18:23:40 +0000
+++ dwt/src/Theme.cpp 2011-12-23 14:07:18 +0000
@@ -47,7 +47,7 @@
void Theme::load(const tstring& classes, Widget* w_, bool handleThemeChanges) {
w = w_;
- dwtassert(w, _T("Theme: no widget set"));
+ dwtassert(w, "Theme: no widget set");
open(classes);
=== modified file 'dwt/src/util/GDI.cpp'
--- dwt/src/util/GDI.cpp 2011-04-26 17:54:15 +0000
+++ dwt/src/util/GDI.cpp 2011-12-23 14:07:18 +0000
@@ -40,7 +40,7 @@
IconPtr merge(const ImageList& icons) {
const size_t n = icons.size();
- dwtassert(n > 0, _T("No icons to merge"));
+ dwtassert(n > 0, "No icons to merge");
// only 1 icon, just return it back.
if(n == 1)
=== modified file 'dwt/src/widgets/Grid.cpp'
--- dwt/src/widgets/Grid.cpp 2011-12-22 22:14:45 +0000
+++ dwt/src/widgets/Grid.cpp 2011-12-23 14:07:18 +0000
@@ -333,7 +333,7 @@
}
void Grid::setWidget(Control* w, size_t row, size_t column, size_t rowSpan, size_t colSpan) {
- dwtassert(w->getParent() == this, _T("Control must be a child of the grid"));
+ dwtassert(w->getParent() == this, "Control must be a child of the grid");
for(auto i = widgetInfo.begin(), iend = widgetInfo.end(); i != iend; ++i) {
if(i->w == w) {
=== modified file 'dwt/src/widgets/Menu.cpp'
--- dwt/src/widgets/Menu.cpp 2011-11-20 16:59:46 +0000
+++ dwt/src/widgets/Menu.cpp 2011-12-23 14:07:18 +0000
@@ -88,7 +88,7 @@
popup(true),
drawSidebar(false)
{
- dwtassert(dynamic_cast<Control*>(parent), _T("A Menu must have a parent derived from dwt::Control"));
+ dwtassert(dynamic_cast<Control*>(parent), "A Menu must have a parent derived from dwt::Control");
}
void Menu::createHelper(const Seed& cs) {
@@ -202,7 +202,7 @@
}
void Menu::setMenu() {
- dwtassert(!popup, _T("Only non-popup menus may call setMenu (change the Seed accordingly)"));
+ dwtassert(!popup,"Only non-popup menus may call setMenu (change the Seed accordingly)");
if(!::SetMenu(getParent()->handle(), handle()))
throw Win32Exception("SetMenu in Menu::setMenu failed");
@@ -418,7 +418,7 @@
if(!::GetMenuItemInfo(handle(), wrapper.index, TRUE, &info))
throw Win32Exception("Couldn't get menu item info when drawing");
- dwtassert((info.fType & MFT_OWNERDRAW) != 0, _T("Trying to draw a menu item that is not owner-drawn"));
+ dwtassert((info.fType & MFT_OWNERDRAW) != 0, "Trying to draw a menu item that is not owner-drawn");
// get state info
bool isGrayed = ( drawInfo.itemState & ODS_GRAYED ) == ODS_GRAYED;
@@ -742,7 +742,7 @@
if(!::GetMenuItemInfo(handle(), wrapper.index, TRUE, &info))
throw Win32Exception("Couldn't get menu item info when measuring");
- dwtassert((info.fType & MFT_OWNERDRAW) != 0, _T("Trying to measure a menu item that is not owner-drawn"));
+ dwtassert((info.fType & MFT_OWNERDRAW) != 0, "Trying to measure a menu item that is not owner-drawn");
// check if separator
if(info.fType & MFT_SEPARATOR) {
=== modified file 'dwt/src/widgets/MessageBox.cpp'
--- dwt/src/widgets/MessageBox.cpp 2011-07-05 12:16:32 +0000
+++ dwt/src/widgets/MessageBox.cpp 2011-12-23 14:07:18 +0000
@@ -38,7 +38,7 @@
MessageBox::MessageBox(Widget* parent) :
parent(parent)
{
- dwtassert(parent, _T("A MessageBox must have a valid parent"));
+ dwtassert(parent, "A MessageBox must have a valid parent");
}
MessageBox::RetVal MessageBox::show(const tstring& message, const tstring& title, Buttons buttons, Icon icon) {
=== modified file 'dwt/src/widgets/Spinner.cpp'
--- dwt/src/widgets/Spinner.cpp 2011-11-07 22:11:39 +0000
+++ dwt/src/widgets/Spinner.cpp 2011-12-23 14:07:18 +0000
@@ -64,7 +64,7 @@
}
void Spinner::assignBuddy(Control* buddy) {
- dwtassert(buddy && buddy->handle() && buddy->getParent() == getParent(), _T("A spinner and its buddy must have the same parent"));
+ dwtassert(buddy && buddy->handle() && buddy->getParent() == getParent(), "A spinner and its buddy must have the same parent");
assignBuddy_(buddy);
buddy->onSized([this](const SizedEvent&) { handleSized(); });
}
=== modified file 'dwt/src/widgets/StatusBar.cpp'
--- dwt/src/widgets/StatusBar.cpp 2011-12-22 22:14:45 +0000
+++ dwt/src/widgets/StatusBar.cpp 2011-12-23 14:07:18 +0000
@@ -73,12 +73,12 @@
}
void StatusBar::setSize(unsigned part, unsigned size) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
parts[part].size = size;
}
void StatusBar::setText(unsigned part, const tstring& text, bool alwaysResize) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
Part& info = getPart(part);
info.text = text;
if(part != fill) {
@@ -101,7 +101,7 @@
}
void StatusBar::setIcon(unsigned part, const IconPtr& icon, bool alwaysResize) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
Part& info = getPart(part);
info.icon = icon;
if(part != fill)
@@ -110,17 +110,17 @@
}
void StatusBar::setToolTip(unsigned part, const tstring& text) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
getPart(part).tip = text;
}
void StatusBar::setHelpId(unsigned part, unsigned id) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
getPart(part).helpId = id;
}
void StatusBar::setWidget(unsigned part, Control* widget, const Rectangle& padding) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
auto p = new WidgetPart(widget, padding);
p->size = widget->getPreferredSize().x;
p->helpId = widget->getHelpId();
@@ -128,7 +128,7 @@
}
void StatusBar::onClicked(unsigned part, const F& f) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
getPart(part).clickF = f;
// imitate the default onClicked but with a setCallback.
@@ -136,7 +136,7 @@
}
void StatusBar::onRightClicked(unsigned part, const F& f) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
getPart(part).rightClickF = f;
// imitate the default onRightClicked but with a setCallback.
@@ -144,7 +144,7 @@
}
void StatusBar::onDblClicked(unsigned part, const F& f) {
- dwtassert(part < parts.size(), _T("Invalid part number."));
+ dwtassert(part < parts.size(), "Invalid part number");
getPart(part).dblClickF = f;
// imitate the default onDblClicked but with a setCallback.
=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp 2011-12-22 22:14:45 +0000
+++ dwt/src/widgets/TabView.cpp 2011-12-23 14:07:18 +0000
@@ -88,7 +88,7 @@
toggleActive = cs.toggleActive;
if(cs.style & TCS_OWNERDRAWFIXED) {
- dwtassert(dynamic_cast<Control*>(getParent()), _T("Owner-drawn tabs must have a parent derived from dwt::Control"));
+ dwtassert(dynamic_cast<Control*>(getParent()), "Owner-drawn tabs must have a parent derived from dwt::Control");
if(widthConfig < 100)
widthConfig = 100;
=== modified file 'dwt/src/widgets/Table.cpp'
--- dwt/src/widgets/Table.cpp 2011-12-22 22:14:45 +0000
+++ dwt/src/widgets/Table.cpp 2011-12-23 14:07:18 +0000
@@ -234,7 +234,7 @@
void Table::setIndex(LVITEM& item, int index) const {
if(grouped) {
- dwtassert(index >= 0, _T("Table::insert in grouped mode: index must be >= 0 since it is a group id"));
+ dwtassert(index >= 0, "Table::insert in grouped mode: index must be >= 0 since it is a group id");
item.mask |= LVIF_GROUPID;
item.iGroupId = index;
@@ -527,7 +527,7 @@
}
void Table::eraseColumn( unsigned columnNo ) {
- dwtassert( columnNo != 0, _T( "Can't delete the leftmost column" ) );
+ dwtassert(columnNo != 0, "Can't delete the leftmost column");
ListView_DeleteColumn( handle(), columnNo );
}
=== modified file 'dwt/src/widgets/TextBox.cpp'
--- dwt/src/widgets/TextBox.cpp 2011-12-18 13:41:12 +0000
+++ dwt/src/widgets/TextBox.cpp 2011-12-23 14:07:18 +0000
@@ -43,8 +43,7 @@
BaseType(parent, dispatcher),
lines(1)
{
- // Can't have a text box without a parent...
- dwtassert( parent, _T( "Cant have a TextBox without a parent..." ) );
+ dwtassert(parent, "Cant have a TextBox without a parent...");
}
TextBox::TextBox(Widget* parent) :
=== modified file 'dwt/src/widgets/ToolTip.cpp'
--- dwt/src/widgets/ToolTip.cpp 2011-11-07 22:11:39 +0000
+++ dwt/src/widgets/ToolTip.cpp 2011-12-23 14:07:18 +0000
@@ -41,7 +41,7 @@
}
void ToolTip::create( const Seed & cs ) {
- dwtassert((cs.style & WS_POPUP) == WS_POPUP, _T("Widget must have WS_POPUP style"));
+ dwtassert((cs.style & WS_POPUP) == WS_POPUP, "ToolTips must have the WS_POPUP style");
BaseType::create(cs);
}