Got rid of most of Windows's complain()s.

This commit is contained in:
Pietro Gagliardi 2016-05-13 22:53:56 -04:00
parent 6d2d977363
commit 8067dc76b7
8 changed files with 31 additions and 25 deletions

View File

@ -44,7 +44,7 @@ static WCHAR *expandYear(WCHAR *dts, int n)
if (*p == L'\'')
break;
if (*p == L'\0')
complain("unterminated quote in system-provided locale date string in expandYear()");
implbug("unterminated quote in system-provided locale date string in expandYear()");
*q++ = *p;
}
// and fall through to copy the closing quote

View File

@ -71,10 +71,10 @@ void realbug(const char *file, const char *line, const char *func, const char *p
va_copy(ap2, ap);
n = _vscprintf(format, ap2);
va_end(ap2);
n++; // terminating L'\0'
n++; // terminating '\0'
buf = (char *) uiAlloc(n * sizeof (char), "char[]");
// includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
// includes terminating '\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
vsprintf_s(msg, n, format, ap);
final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg);

View File

@ -95,8 +95,8 @@ void freeContext(uiDrawContext *c)
if (c->currentClip != NULL)
c->currentClip->Release();
if (c->states->size() != 0)
// TODO userbug()
complain("unbalanced save/restore");
// TODO do this on other platforms
userbug("You did not balance uiDrawSave() and uiDrawRestore() calls.");
delete c->states;
uiFree(c);
}
@ -228,7 +228,9 @@ static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt)
// TODO
}
complain("invalid brush type %d in makeBrush()", b->Type);
// TODO do this on all platforms
userbug("Invalid brush type %d given to drawing operation.", b->Type);
// TODO dummy brush?
return NULL; // make compiler happy
}

View File

@ -241,7 +241,6 @@ void uiDrawPathEnd(uiDrawPath *p)
ID2D1PathGeometry *pathGeometry(uiDrawPath *p)
{
if (p->sink != NULL)
// TODO userbug()
complain("path not ended");
userbug("You cannot draw with a uiDrawPath that was not ended. (path: %p)", p);
return p->path;
}

View File

@ -139,7 +139,7 @@ void attrToDWriteAttr(struct dwriteAttr *attr)
break;
}
if (!found)
complain("invalid weight %d passed to attrToDWriteAttr()", attr->weight);
userbug("Invalid text weight %d passed to text function.", attr->weight);
found = false;
for (i = 0; ; i++) {
@ -152,7 +152,7 @@ void attrToDWriteAttr(struct dwriteAttr *attr)
break;
}
if (!found)
complain("invalid italic %d passed to attrToDWriteAttr()", attr->italic);
userbug("Invalid text italic %d passed to text function.", attr->italic);
found = false;
for (i = 0; ; i++) {
@ -165,7 +165,8 @@ void attrToDWriteAttr(struct dwriteAttr *attr)
break;
}
if (!found)
complain("invalid stretch %d passed to attrToDWriteAttr()", attr->stretch);
// TODO on other platforms too
userbug("Invalid text stretch %d passed to text function.", attr->stretch);
}
void dwriteAttrToAttr(struct dwriteAttr *attr)
@ -204,7 +205,8 @@ void dwriteAttrToAttr(struct dwriteAttr *attr)
break;
}
if (!found)
complain("invalid italic %d passed to dwriteAttrToAttr()", attr->ditalic);
// these are implbug()s because users shouldn't be able to get here directly; TODO?
implbug("invalid italic %d passed to dwriteAttrToAttr()", attr->ditalic);
found = false;
for (i = 0; ; i++) {
@ -217,7 +219,7 @@ void dwriteAttrToAttr(struct dwriteAttr *attr)
break;
}
if (!found)
complain("invalid stretch %d passed to dwriteAttrToAttr()", attr->dstretch);
implbug("invalid stretch %d passed to dwriteAttrToAttr()", attr->dstretch);
}
uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc)
@ -242,7 +244,7 @@ uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc)
if (hr != S_OK)
logHRESULT(L"error finding font family", hr);
if (!exists)
complain("TODO family not found in uiDrawLoadClosestFont()", hr);
implbug("TODO family not found in uiDrawLoadClosestFont()", hr);
hr = collection->GetFontFamily(index, &family);
if (hr != S_OK)
logHRESULT(L"error loading font family", hr);

View File

@ -87,7 +87,7 @@ void uiMenuItemDisable(uiMenuItem *i)
void uiMenuItemOnClicked(uiMenuItem *i, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
{
if (i->type == typeQuit)
complain("attempt to call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead");
userbug("You can not call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
i->onClicked = f;
i->onClickedData = data;
}
@ -111,7 +111,7 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
uiMenuItem *item;
if (menusFinalized)
complain("attempt to create a new menu item after menus have been finalized");
userbug("You can not create a new menu item after menus have been finalized.");
if (m->len >= m->cap) {
m->cap += grow;
@ -167,7 +167,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name)
uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
{
if (hasQuit)
complain("attempt to add multiple Quit menu items");
userbug("You can not have multiple Quit menu items in a program.");
hasQuit = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeQuit, NULL);
@ -176,7 +176,7 @@ uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
{
if (hasPreferences)
complain("attempt to add multiple Preferences menu items");
userbug("You can not have multiple Preferences menu items in a program.");
hasPreferences = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typePreferences, NULL);
@ -185,7 +185,8 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
uiMenuItem *uiMenuAppendAboutItem(uiMenu *m)
{
if (hasAbout)
complain("attempt to add multiple About menu items");
// TODO place these userbug strings in a header?
userbug("You can not have multiple About menu items in a program.");
hasAbout = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeAbout, NULL);
@ -201,7 +202,7 @@ uiMenu *uiNewMenu(const char *name)
uiMenu *m;
if (menusFinalized)
complain("attempt to create a new menu after menus have been finalized");
userbug("You can not create a new menu after menus have been finalized.");
if (len >= cap) {
cap += grow;
menus = (uiMenu **) uiRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]");
@ -290,7 +291,7 @@ void runMenuEvent(WORD id, uiWindow *w)
}
}
// no match
complain("unknown menu ID %hu in runMenuEvent()", id);
implbug("unknown menu ID %hu in runMenuEvent()", id);
found:
// first toggle checkboxes, if any
@ -313,7 +314,7 @@ static void freeMenu(uiMenu *m, HMENU submenu)
if (item->hmenus[j] == submenu)
break;
if (j >= item->len)
complain("submenu handle %p not found in freeMenu()", submenu);
implbug("submenu handle %p not found in freeMenu()", submenu);
for (; j < item->len - 1; j++)
item->hmenus[j] = item->hmenus[j + 1];
item->hmenus[j] = NULL;
@ -349,7 +350,8 @@ void uninitMenus(void)
for (j = 0; j < m->len; j++) {
item = m->items[j];
if (item->len != 0)
complain("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
// TODO userbug()?
implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
if (item->name != NULL)
uiFree(item->name);
if (item->hmenus != NULL)

View File

@ -33,7 +33,7 @@ static void uiProgressBarMinimumSize(uiWindowsControl *c, intmax_t *width, intma
void uiProgressBarSetValue(uiProgressBar *p, int value)
{
if (value < 0 || value > 100)
complain("value %d out of range in uiProgressBarSetValue()", value);
userbug("Value %d is out of range for uiProgressBars.", value);
if (value == 100) { // because we can't 101
SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 101);
SendMessageW(p->hwnd, PBM_SETPOS, 101, 0);

View File

@ -184,7 +184,8 @@ uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
uiSpinbox *s;
if (min >= max)
complain("error: min >= max in uiNewSpinbox()");
// TODO
implbug("error: min >= max in uiNewSpinbox()");
uiWindowsNewControl(uiSpinbox, s);