Merge branch 'common-namespace-cleanup'

This begins the process of cleaning up the libui namespace.
This commit is contained in:
Pietro Gagliardi 2018-04-18 00:55:21 -04:00
commit 3539cda280
81 changed files with 435 additions and 416 deletions

View File

@ -184,3 +184,14 @@ https://msdn.microsoft.com/en-us/library/windows/desktop/aa969513(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa969527(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/dd388198(v=vs.85).aspx
I hope the MFC ribbon can have customizable colors too, otherwise I'll have to do some serious image processing...
windows debugging
https://msdn.microsoft.com/en-us/library/windows/desktop/hh780351(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ff476881(v=vs.85).aspx#Debug
https://msdn.microsoft.com/en-us/library/windows/desktop/hh780343(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/dn457937(v=vs.85).aspx
more OS2 stuff
https://www.google.com/search?q=%22ibm+graphics+development+toolkit%22&ie=utf-8&oe=utf-8&client=firefox-b-1
https://www.google.com/search?q=%22os%2F2+graphics+development+toolkit%22&ie=utf-8&oe=utf-8&client=firefox-b-1
http://www.edm2.com/index.php/IBM_OS/2_Developer%27s_Packages

View File

@ -16,7 +16,7 @@ TODO note the bits about asymmetry and g_rcClick initial value not mattering in
// x, y, xdist, ydist, and c.rect must have the same units
// so must time, maxTime, and c.prevTime
int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist)
int uiprivClickCounterClick(uiprivClickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist)
{
// different button than before? if so, don't count
if (button != c->curButton)
@ -50,7 +50,7 @@ int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time,
return c->count;
}
void clickCounterReset(clickCounter *c)
void uiprivClickCounterReset(uiprivClickCounter *c)
{
c->curButton = 0;
c->rectX0 = 0;
@ -151,7 +151,7 @@ static const struct {
{ 0xFFFF, 0 },
};
int fromScancode(uintptr_t scancode, uiAreaKeyEvent *ke)
int uiprivFromScancode(uintptr_t scancode, uiAreaKeyEvent *ke)
{
int i;

View File

@ -85,7 +85,7 @@ uiAttribute *uiNewFamilyAttribute(const char *family)
uiAttribute *a;
a = newAttribute(uiAttributeTypeFamily);
a->u.family = (char *) uiAlloc((strlen(family) + 1) * sizeof (char), "char[] (uiAttribute)");
a->u.family = (char *) uiprivAlloc((strlen(family) + 1) * sizeof (char), "char[] (uiAttribute)");
strcpy(a->u.family, family);
return a;
}

View File

@ -18,7 +18,7 @@ struct uiAttributedString {
size_t *u16tou8;
// this is lazily created to keep things from getting *too* slow
struct graphemes *graphemes;
uiprivGraphemes *graphemes;
};
static void resize(uiAttributedString *s, size_t u8, size_t u16)
@ -93,11 +93,11 @@ static void u8u16len(const char *str, size_t *n8, size_t *n16)
*n8 = 0;
*n16 = 0;
while (*str) {
str = utf8DecodeRune(str, 0, &rune);
str = uiprivUTF8DecodeRune(str, 0, &rune);
// TODO document the use of the function vs a pointer subtract here
// TODO also we need to consider namespace collision with utf.h...
*n8 += utf8EncodeRune(rune, buf);
*n16 += utf16EncodeRune(rune, buf16);
*n8 += uiprivUTF8EncodeRune(rune, buf);
*n16 += uiprivUTF16EncodeRune(rune, buf16);
}
}
@ -179,9 +179,9 @@ void uiAttributedStringInsertAtUnattributed(uiAttributedString *s, const char *s
while (*str) {
size_t n;
str = utf8DecodeRune(str, 0, &rune);
n = utf8EncodeRune(rune, buf);
n16 = utf16EncodeRune(rune, buf16);
str = uiprivUTF8DecodeRune(str, 0, &rune);
n = uiprivUTF8EncodeRune(rune, buf);
n16 = uiprivUTF16EncodeRune(rune, buf16);
s->s[old] = buf[0];
s->u8tou16[old] = old16;
if (n > 1) {

View File

@ -1,10 +1,8 @@
// 19 february 2018
// TODO remove when done migrating these functions
#define uiprivNew(x) uiNew(x)
#define uiprivAlloc(x, y) uiAlloc(x, y)
#define uiprivRealloc(x, y, z) uiRealloc(x, y, z)
#define uiprivFree(x) uiFree(x)
#ifdef __cplusplus
extern "C" {
#endif
// attribute.c
extern uiAttribute *uiprivAttributeRetain(uiAttribute *a);
@ -34,10 +32,15 @@ extern size_t *uiprivAttributedStringCopyUTF8ToUTF16Table(const uiAttributedStri
extern size_t *uiprivAttributedStringCopyUTF16ToUTF8Table(const uiAttributedString *s, size_t *n);
// per-OS graphemes.c/graphemes.cpp/graphemes.m/etc.
struct graphemes {
typedef struct uiprivGraphemes uiprivGraphemes;
struct uiprivGraphemes {
size_t len;
size_t *pointsToGraphemes;
size_t *graphemesToPoints;
};
extern int uiprivGraphemesTakesUTF16(void);
extern struct graphemes *uiprivNewGraphemes(void *s, size_t len);
extern uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len);
#ifdef __cplusplus
}
#endif

View File

@ -57,14 +57,14 @@ void uiControlDisable(uiControl *c)
(*(c->Disable))(c);
}
#define uiControlSignature 0x7569436F
#define uiprivControlSignature 0x7569436F
uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr)
{
uiControl *c;
c = (uiControl *) uiAlloc(size, typenamestr);
c->Signature = uiControlSignature;
c = (uiControl *) uiprivAlloc(size, typenamestr);
c->Signature = uiprivControlSignature;
c->OSSignature = OSsig;
c->TypeSignature = typesig;
return c;
@ -73,8 +73,8 @@ uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const c
void uiFreeControl(uiControl *c)
{
if (uiControlParent(c) != NULL)
userbug("You cannot destroy a uiControl while it still has a parent. (control: %p)", c);
uiFree(c);
uiprivUserBug("You cannot destroy a uiControl while it still has a parent. (control: %p)", c);
uiprivFree(c);
}
void uiControlVerifySetParent(uiControl *c, uiControl *parent)
@ -82,12 +82,12 @@ void uiControlVerifySetParent(uiControl *c, uiControl *parent)
uiControl *curParent;
if (uiControlToplevel(c))
userbug("You cannot give a toplevel uiControl a parent. (control: %p)", c);
uiprivUserBug("You cannot give a toplevel uiControl a parent. (control: %p)", c);
curParent = uiControlParent(c);
if (parent != NULL && curParent != NULL)
userbug("You cannot give a uiControl a parent while it already has one. (control: %p; current parent: %p; new parent: %p)", c, curParent, parent);
uiprivUserBug("You cannot give a uiControl a parent while it already has one. (control: %p; current parent: %p; new parent: %p)", c, curParent, parent);
if (parent == NULL && curParent == NULL)
implbug("attempt to double unparent uiControl %p", c);
uiprivImplBug("attempt to double unparent uiControl %p", c);
}
int uiControlEnabledToUser(uiControl *c)

View File

@ -1,5 +1,7 @@
// 24 april 2016
// LONGTERM if I don't decide to remove these outright, should they be renamed uiprivTypeNameSignature? these aren't real symbols, so...
#define uiAreaSignature 0x41726561
#define uiBoxSignature 0x426F784C
#define uiButtonSignature 0x42746F6E

View File

@ -2,20 +2,20 @@
#include "../ui.h"
#include "uipriv.h"
void _implbug(const char *file, const char *line, const char *func, const char *format, ...)
void uiprivDoImplBug(const char *file, const char *line, const char *func, const char *format, ...)
{
va_list ap;
va_start(ap, format);
realbug(file, line, func, "POSSIBLE IMPLEMENTATION BUG; CONTACT ANDLABS:\n", format, ap);
uiprivRealBug(file, line, func, "POSSIBLE IMPLEMENTATION BUG; CONTACT ANDLABS:\n", format, ap);
va_end(ap);
}
void _userbug(const char *file, const char *line, const char *func, const char *format, ...)
void uiprivDoUserBug(const char *file, const char *line, const char *func, const char *format, ...)
{
va_list ap;
va_start(ap, format);
realbug(file, line, func, "You have a bug: ", format, ap);
uiprivRealBug(file, line, func, "You have a bug: ", format, ap);
va_end(ap);
}

View File

@ -18,7 +18,7 @@ void uiDrawMatrixSetIdentity(uiDrawMatrix *m)
// see https://msdn.microsoft.com/en-us/library/windows/desktop/ff684171%28v=vs.85%29.aspx#skew_transform
// TODO see if there's a way we can avoid the multiplication
void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
void uiprivFallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
{
uiDrawMatrix n;
@ -31,7 +31,7 @@ void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double ya
uiDrawMatrixMultiply(m, &n);
}
void scaleCenter(double xCenter, double yCenter, double *x, double *y)
void uiprivScaleCenter(double xCenter, double yCenter, double *x, double *y)
{
*x = xCenter - (*x * xCenter);
*y = yCenter - (*y * yCenter);
@ -39,7 +39,7 @@ void scaleCenter(double xCenter, double yCenter, double *x, double *y)
// the basic algorithm is from cairo
// but it's the same algorithm as the transform point, just without M31 and M32 taken into account, so let's just do that instead
void fallbackTransformSize(uiDrawMatrix *m, double *x, double *y)
void uiprivFallbackTransformSize(uiDrawMatrix *m, double *x, double *y)
{
uiDrawMatrix m2;

View File

@ -8,7 +8,7 @@ static int defaultOnShouldQuit(void *data)
}
static int (*onShouldQuit)(void *) = defaultOnShouldQuit;
static void *onShouldQuitData;
static void *onShouldQuitData = NULL;
void uiOnShouldQuit(int (*f)(void *), void *data)
{
@ -16,7 +16,7 @@ void uiOnShouldQuit(int (*f)(void *), void *data)
onShouldQuitData = data;
}
int shouldQuit(void)
int uiprivShouldQuit(void)
{
return (*onShouldQuit)(onShouldQuitData);
}

View File

@ -1,46 +1,47 @@
// 6 april 2015
// this must go outside other extern "C" blocks, otherwise we'll get double-declaration errors
// note: this file should not include ui.h, as the OS-specific ui_*.h files are included between that one and this one in the OS-specific uipriv_*.h* files
#include <stdarg.h>
#include <string.h>
#include "controlsigs.h"
#include "utf.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <string.h>
#include "controlsigs.h"
// OS-specific init.* or main.* files
extern uiInitOptions uiprivOptions;
extern uiInitOptions options;
// OS-specific alloc.* files
extern void *uiprivAlloc(size_t, const char *);
#define uiprivNew(T) ((T *) uiprivAlloc(sizeof (T), #T))
extern void *uiprivRealloc(void *, size_t, const char *);
extern void uiprivFree(void *);
extern void *uiAlloc(size_t, const char *);
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T))
extern void *uiRealloc(void *, size_t, const char *);
extern void uiFree(void *);
// ugh, this was only introduced in MSVC 2015...
// debug.c and OS-specific debug.* files
// TODO get rid of this mess...
// ugh, __func__ was only introduced in MSVC 2015...
#ifdef _MSC_VER
#define __func__ __FUNCTION__
#define uiprivMacro__func__ __FUNCTION__
#else
#define uiprivMacro__func__ __func__
#endif
extern void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap);
#define _ns2(s) #s
#define _ns(s) _ns2(s)
extern void _implbug(const char *file, const char *line, const char *func, const char *format, ...);
#define implbug(...) _implbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
extern void _userbug(const char *file, const char *line, const char *func, const char *format, ...);
#define userbug(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__)
// control.c
extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr);
extern void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap);
#define uiprivMacro_ns2(s) #s
#define uiprivMacro_ns(s) uiprivMacro_ns2(s)
extern void uiprivDoImplBug(const char *file, const char *line, const char *func, const char *format, ...);
#define uiprivImplBug(...) uiprivDoImplBug(__FILE__, uiprivMacro_ns(__LINE__), uiprivMacro__func__, __VA_ARGS__)
extern void uiprivDoUserBug(const char *file, const char *line, const char *func, const char *format, ...);
#define uiprivUserBug(...) uiprivDoUserBug(__FILE__, uiprivMacro_ns(__LINE__), uiprivMacro__func__, __VA_ARGS__)
// shouldquit.c
extern int shouldQuit(void);
extern int uiprivShouldQuit(void);
// areaevents.c
typedef struct clickCounter clickCounter;
typedef struct uiprivClickCounter uiprivClickCounter;
// you should call Reset() to zero-initialize a new instance
// it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly
struct clickCounter {
struct uiprivClickCounter {
int curButton;
int rectX0;
int rectY0;
@ -49,14 +50,14 @@ struct clickCounter {
uintptr_t prevTime;
int count;
};
int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist);
extern void clickCounterReset(clickCounter *);
extern int fromScancode(uintptr_t, uiAreaKeyEvent *);
extern int uiprivClickCounterClick(uiprivClickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist);
extern void uiprivClickCounterReset(uiprivClickCounter *);
extern int uiprivFromScancode(uintptr_t, uiAreaKeyEvent *);
// matrix.c
extern void fallbackSkew(uiDrawMatrix *, double, double, double, double);
extern void scaleCenter(double, double, double *, double *);
extern void fallbackTransformSize(uiDrawMatrix *, double *, double *);
extern void uiprivFallbackSkew(uiDrawMatrix *, double, double, double, double);
extern void uiprivScaleCenter(double, double, double *, double *);
extern void uiprivFallbackTransformSize(uiDrawMatrix *, double *, double *);
// OS-specific text.* files
extern int uiprivStricmp(const char *a, const char *b);

View File

@ -4,5 +4,5 @@
void uiUserBugCannotSetParentOnToplevel(const char *type)
{
userbug("You cannot make a %s a child of another uiControl,", type);
uiprivUserBug("You cannot make a %s a child of another uiControl,", type);
}

View File

@ -1,5 +1,6 @@
// utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/
// 10 november 2016
// function names have been altered to avoid namespace collisions in libui static builds (see utf.h)
#include "utf.h"
// this code imitates Go's unicode/utf8 and unicode/utf16
@ -9,7 +10,7 @@
// encoded must be at most 4 bytes
// TODO clean this code up somehow
size_t utf8EncodeRune(uint32_t rune, char *encoded)
size_t uiprivUTF8EncodeRune(uint32_t rune, char *encoded)
{
uint8_t b, c, d, e;
size_t n;
@ -72,7 +73,7 @@ done:
return n;
}
const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune)
const char *uiprivUTF8DecodeRune(const char *s, size_t nElem, uint32_t *rune)
{
uint8_t b, c;
uint8_t lowestAllowed, highestAllowed;
@ -172,7 +173,7 @@ const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune)
}
// encoded must have at most 2 elements
size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded)
size_t uiprivUTF16EncodeRune(uint32_t rune, uint16_t *encoded)
{
uint16_t low, high;
@ -198,7 +199,7 @@ size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded)
}
// TODO see if this can be cleaned up somehow
const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune)
const uint16_t *uiprivUTF16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune)
{
uint16_t high, low;
@ -240,7 +241,7 @@ const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune)
// TODO find a way to reduce the code in all of these somehow
// TODO find a way to remove u as well
size_t utf8RuneCount(const char *s, size_t nElem)
size_t uiprivUTF8RuneCount(const char *s, size_t nElem)
{
size_t len;
uint32_t rune;
@ -251,7 +252,7 @@ size_t utf8RuneCount(const char *s, size_t nElem)
len = 0;
t = s;
while (nElem != 0) {
u = utf8DecodeRune(t, nElem, &rune);
u = uiprivUTF8DecodeRune(t, nElem, &rune);
len++;
nElem -= u - t;
t = u;
@ -260,13 +261,13 @@ size_t utf8RuneCount(const char *s, size_t nElem)
}
len = 0;
while (*s) {
s = utf8DecodeRune(s, nElem, &rune);
s = uiprivUTF8DecodeRune(s, nElem, &rune);
len++;
}
return len;
}
size_t utf8UTF16Count(const char *s, size_t nElem)
size_t uiprivUTF8UTF16Count(const char *s, size_t nElem)
{
size_t len;
uint32_t rune;
@ -278,8 +279,8 @@ size_t utf8UTF16Count(const char *s, size_t nElem)
len = 0;
t = s;
while (nElem != 0) {
u = utf8DecodeRune(t, nElem, &rune);
len += utf16EncodeRune(rune, encoded);
u = uiprivUTF8DecodeRune(t, nElem, &rune);
len += uiprivUTF16EncodeRune(rune, encoded);
nElem -= u - t;
t = u;
}
@ -287,13 +288,13 @@ size_t utf8UTF16Count(const char *s, size_t nElem)
}
len = 0;
while (*s) {
s = utf8DecodeRune(s, nElem, &rune);
len += utf16EncodeRune(rune, encoded);
s = uiprivUTF8DecodeRune(s, nElem, &rune);
len += uiprivUTF16EncodeRune(rune, encoded);
}
return len;
}
size_t utf16RuneCount(const uint16_t *s, size_t nElem)
size_t uiprivUTF16RuneCount(const uint16_t *s, size_t nElem)
{
size_t len;
uint32_t rune;
@ -304,7 +305,7 @@ size_t utf16RuneCount(const uint16_t *s, size_t nElem)
len = 0;
t = s;
while (nElem != 0) {
u = utf16DecodeRune(t, nElem, &rune);
u = uiprivUTF16DecodeRune(t, nElem, &rune);
len++;
nElem -= u - t;
t = u;
@ -313,13 +314,13 @@ size_t utf16RuneCount(const uint16_t *s, size_t nElem)
}
len = 0;
while (*s) {
s = utf16DecodeRune(s, nElem, &rune);
s = uiprivUTF16DecodeRune(s, nElem, &rune);
len++;
}
return len;
}
size_t utf16UTF8Count(const uint16_t *s, size_t nElem)
size_t uiprivUTF16UTF8Count(const uint16_t *s, size_t nElem)
{
size_t len;
uint32_t rune;
@ -331,8 +332,8 @@ size_t utf16UTF8Count(const uint16_t *s, size_t nElem)
len = 0;
t = s;
while (nElem != 0) {
u = utf16DecodeRune(t, nElem, &rune);
len += utf8EncodeRune(rune, encoded);
u = uiprivUTF16DecodeRune(t, nElem, &rune);
len += uiprivUTF8EncodeRune(rune, encoded);
nElem -= u - t;
t = u;
}
@ -340,8 +341,8 @@ size_t utf16UTF8Count(const uint16_t *s, size_t nElem)
}
len = 0;
while (*s) {
s = utf16DecodeRune(s, nElem, &rune);
len += utf8EncodeRune(rune, encoded);
s = uiprivUTF16DecodeRune(s, nElem, &rune);
len += uiprivUTF8EncodeRune(rune, encoded);
}
return len;
}

View File

@ -1,25 +1,29 @@
// utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/
// 10 november 2016
// note the overridden names with uipriv at the beginning; this avoids potential symbol clashes when building libui as a static library
// LONGTERM find a way to encode the name overrides directly into the utf library
#ifdef __cplusplus
extern "C" {
#endif
// TODO (for utf itself as well) should this go outside the extern "C" block or not
#include <stddef.h>
#include <stdint.h>
// if nElem == 0, assume the buffer has no upper limit and is '\0' terminated
// otherwise, assume buffer is NOT '\0' terminated but is bounded by nElem *elements*
extern size_t utf8EncodeRune(uint32_t rune, char *encoded);
extern const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune);
extern size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded);
extern const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune);
extern size_t uiprivUTF8EncodeRune(uint32_t rune, char *encoded);
extern const char *uiprivUTF8DecodeRune(const char *s, size_t nElem, uint32_t *rune);
extern size_t uiprivUTF16EncodeRune(uint32_t rune, uint16_t *encoded);
extern const uint16_t *uiprivUTF16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune);
extern size_t utf8RuneCount(const char *s, size_t nElem);
extern size_t utf8UTF16Count(const char *s, size_t nElem);
extern size_t utf16RuneCount(const uint16_t *s, size_t nElem);
extern size_t utf16UTF8Count(const uint16_t *s, size_t nElem);
extern size_t uiprivUTF8RuneCount(const char *s, size_t nElem);
extern size_t uiprivUTF8UTF16Count(const char *s, size_t nElem);
extern size_t uiprivUTF16RuneCount(const uint16_t *s, size_t nElem);
extern size_t uiprivUTF16UTF8Count(const uint16_t *s, size_t nElem);
#ifdef __cplusplus
}
@ -33,27 +37,27 @@ extern size_t utf16UTF8Count(const uint16_t *s, size_t nElem);
// TODO same for UniChar/unichar on Mac? if both are unsigned then we have nothing to worry about
#if defined(_MSC_VER)
inline size_t utf16EncodeRune(uint32_t rune, __wchar_t *encoded)
inline size_t uiprivUTF16EncodeRune(uint32_t rune, __wchar_t *encoded)
{
return utf16EncodeRune(rune, reinterpret_cast<uint16_t *>(encoded));
return uiprivUTF16EncodeRune(rune, reinterpret_cast<uint16_t *>(encoded));
}
inline const __wchar_t *utf16DecodeRune(const __wchar_t *s, size_t nElem, uint32_t *rune)
inline const __wchar_t *uiprivUTF16DecodeRune(const __wchar_t *s, size_t nElem, uint32_t *rune)
{
const uint16_t *ret;
ret = utf16DecodeRune(reinterpret_cast<const uint16_t *>(s), nElem, rune);
ret = uiprivUTF16DecodeRune(reinterpret_cast<const uint16_t *>(s), nElem, rune);
return reinterpret_cast<const __wchar_t *>(ret);
}
inline size_t utf16RuneCount(const __wchar_t *s, size_t nElem)
inline size_t uiprivUTF16RuneCount(const __wchar_t *s, size_t nElem)
{
return utf16RuneCount(reinterpret_cast<const uint16_t *>(s), nElem);
return uiprivUTF16RuneCount(reinterpret_cast<const uint16_t *>(s), nElem);
}
inline size_t utf16UTF8Count(const __wchar_t *s, size_t nElem)
inline size_t uiprivUTF16UTF8Count(const __wchar_t *s, size_t nElem)
{
return utf16UTF8Count(reinterpret_cast<const uint16_t *>(s), nElem);
return uiprivUTF16UTF8Count(reinterpret_cast<const uint16_t *>(s), nElem);
}
#endif

View File

@ -37,11 +37,11 @@ void uninitAlloc(void)
ptr = [v pointerValue];
[str appendString:[NSString stringWithFormat:@"%p %s\n", ptr, *TYPE(ptr)]];
}
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", [str UTF8String]);
uiprivUserBug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", [str UTF8String]);
[str release];
}
void *uiAlloc(size_t size, const char *type)
void *uiprivAlloc(size_t size, const char *type)
{
void *out;
@ -57,17 +57,17 @@ void *uiAlloc(size_t size, const char *type)
return DATA(out);
}
void *uiRealloc(void *p, size_t new, const char *type)
void *uiprivRealloc(void *p, size_t new, const char *type)
{
void *out;
size_t *s;
if (p == NULL)
return uiAlloc(new, type);
return uiprivAlloc(new, type);
p = BASE(p);
out = realloc(p, EXTRA + new);
if (out == NULL) {
fprintf(stderr, "memory exhausted in uiRealloc()\n");
fprintf(stderr, "memory exhausted in uiprivRealloc()\n");
abort();
}
s = SIZE(out);
@ -79,10 +79,10 @@ void *uiRealloc(void *p, size_t new, const char *type)
return DATA(out);
}
void uiFree(void *p)
void uiprivFree(void *p)
{
if (p == NULL)
implbug("attempt to uiFree(NULL)");
uiprivImplBug("attempt to uiprivFree(NULL)");
p = BASE(p);
free(p);
[allocations removeObject:[NSValue valueWithPointer:p]];

View File

@ -390,7 +390,7 @@ int sendAreaEvents(NSEvent *e)
void uiAreaSetSize(uiArea *a, int width, int height)
{
if (!a->scrolling)
userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a);
uiprivUserBug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a);
[a->area setScrollingSize:NSMakeSize(width, height)];
}
@ -402,7 +402,7 @@ void uiAreaQueueRedrawAll(uiArea *a)
void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)
{
if (!a->scrolling)
userbug("You cannot call uiAreaScrollTo() on a non-scrolling uiArea. (area: %p)", a);
uiprivUserBug("You cannot call uiAreaScrollTo() on a non-scrolling uiArea. (area: %p)", a);
[a->area scrollRectToVisible:NSMakeRect(x, y, width, height)];
// don't worry about the return value; it just says whether scrolling was needed
}

View File

@ -428,7 +428,7 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
// LONGTERM on other platforms
// or at leat allow this and implicitly turn it into a spacer
if (c == NULL)
userbug("You cannot add NULL to a uiBox.");
uiprivUserBug("You cannot add NULL to a uiBox.");
[b->view append:c stretchy:stretchy];
}

View File

@ -3,7 +3,7 @@
// LONGTERM don't halt on release builds
void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
{
NSMutableString *str;
NSString *formatted;

View File

@ -12,7 +12,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
{
uiDrawPath *p;
p = uiNew(uiDrawPath);
p = uiprivNew(uiDrawPath);
p->path = CGPathCreateMutable();
p->fillMode = mode;
return p;
@ -21,13 +21,13 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
void uiDrawFreePath(uiDrawPath *p)
{
CGPathRelease((CGPathRef) (p->path));
uiFree(p);
uiprivFree(p);
}
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
{
if (p->ended)
userbug("You cannot call uiDrawPathNewFigure() on a uiDrawPath that has already been ended. (path; %p)", p);
uiprivUserBug("You cannot call uiDrawPathNewFigure() on a uiDrawPath that has already been ended. (path; %p)", p);
CGPathMoveToPoint(p->path, NULL, x, y);
}
@ -37,7 +37,7 @@ void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, d
double startx, starty;
if (p->ended)
userbug("You cannot call uiDrawPathNewFigureWithArc() on a uiDrawPath that has already been ended. (path; %p)", p);
uiprivUserBug("You cannot call uiDrawPathNewFigureWithArc() on a uiDrawPath that has already been ended. (path; %p)", p);
sinStart = sin(startAngle);
cosStart = cos(startAngle);
startx = xCenter + radius * cosStart;
@ -50,7 +50,7 @@ void uiDrawPathLineTo(uiDrawPath *p, double x, double y)
{
// TODO refine this to require being in a path
if (p->ended)
implbug("attempt to add line to ended path in uiDrawPathLineTo()");
uiprivImplBug("attempt to add line to ended path in uiDrawPathLineTo()");
CGPathAddLineToPoint(p->path, NULL, x, y);
}
@ -60,7 +60,7 @@ void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radiu
// TODO likewise
if (p->ended)
implbug("attempt to add arc to ended path in uiDrawPathArcTo()");
uiprivImplBug("attempt to add arc to ended path in uiDrawPathArcTo()");
if (sweep > 2 * uiPi)
sweep = 2 * uiPi;
cw = false;
@ -77,7 +77,7 @@ void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, doubl
{
// TODO likewise
if (p->ended)
implbug("attempt to add bezier to ended path in uiDrawPathBezierTo()");
uiprivImplBug("attempt to add bezier to ended path in uiDrawPathBezierTo()");
CGPathAddCurveToPoint(p->path, NULL,
c1x, c1y,
c2x, c2y,
@ -88,14 +88,14 @@ void uiDrawPathCloseFigure(uiDrawPath *p)
{
// TODO likewise
if (p->ended)
implbug("attempt to close figure of ended path in uiDrawPathCloseFigure()");
uiprivImplBug("attempt to close figure of ended path in uiDrawPathCloseFigure()");
CGPathCloseSubpath(p->path);
}
void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height)
{
if (p->ended)
userbug("You cannot call uiDrawPathAddRectangle() on a uiDrawPath that has already been ended. (path; %p)", p);
uiprivUserBug("You cannot call uiDrawPathAddRectangle() on a uiDrawPath that has already been ended. (path; %p)", p);
CGPathAddRect(p->path, NULL, CGRectMake(x, y, width, height));
}
@ -108,7 +108,7 @@ uiDrawContext *newContext(CGContextRef ctxt, CGFloat height)
{
uiDrawContext *c;
c = uiNew(uiDrawContext);
c = uiprivNew(uiDrawContext);
c->c = ctxt;
c->height = height;
return c;
@ -116,7 +116,7 @@ uiDrawContext *newContext(CGContextRef ctxt, CGFloat height)
void freeContext(uiDrawContext *c)
{
uiFree(c);
uiprivFree(c);
}
// a stroke is identical to a fill of a stroked path
@ -132,7 +132,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro
uiDrawPath p2;
if (!path->ended)
userbug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path);
uiprivUserBug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path);
switch (p->Cap) {
case uiDrawLineCapFlat:
@ -160,7 +160,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro
// create a temporary path identical to the previous one
dashPath = (CGPathRef) path->path;
if (p->NumDashes != 0) {
dashes = (CGFloat *) uiAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]");
dashes = (CGFloat *) uiprivAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]");
for (i = 0; i < p->NumDashes; i++)
dashes[i] = p->Dashes[i];
dashPath = CGPathCreateCopyByDashingPath(path->path,
@ -168,7 +168,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro
p->DashPhase,
dashes,
p->NumDashes);
uiFree(dashes);
uiprivFree(dashes);
}
// the documentation is wrong: this produces a path suitable for calling CGPathCreateCopyByStrokingPath(), not for filling directly
// the cast is safe; we never modify the CGPathRef and always cast it back to a CGPathRef anyway
@ -224,8 +224,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
// TODO add NULL check to other uses of CGColorSpace
// make the gradient
colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]");
locations = uiAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]");
colors = uiprivAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]");
locations = uiprivAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]");
for (i = 0; i < b->NumStops; i++) {
colors[i * 4 + 0] = b->Stops[i].R;
colors[i * 4 + 1] = b->Stops[i].G;
@ -234,8 +234,8 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
locations[i] = b->Stops[i].Pos;
}
gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops);
uiFree(locations);
uiFree(colors);
uiprivFree(locations);
uiprivFree(colors);
// because we're mucking with clipping, we need to save the graphics state and restore it later
CGContextSaveGState(ctxt);
@ -280,7 +280,7 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b)
{
if (!path->ended)
userbug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path);
uiprivUserBug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path);
CGContextAddPath(c->c, (CGPathRef) (path->path));
switch (b->Type) {
case uiDrawBrushTypeSolid:
@ -294,7 +294,7 @@ void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b)
// TODO
return;
}
userbug("Unknown brush type %d passed to uiDrawFill().", b->Type);
uiprivUserBug("Unknown brush type %d passed to uiDrawFill().", b->Type);
}
static void m2c(uiDrawMatrix *m, CGAffineTransform *c)
@ -334,7 +334,7 @@ void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x
m2c(m, &c);
xt = x;
yt = y;
scaleCenter(xCenter, yCenter, &xt, &yt);
uiprivScaleCenter(xCenter, yCenter, &xt, &yt);
c = CGAffineTransformTranslate(c, xt, yt);
c = CGAffineTransformScale(c, x, y);
c = CGAffineTransformTranslate(c, -xt, -yt);
@ -354,7 +354,7 @@ void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)
void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
{
fallbackSkew(m, x, y, xamount, yamount);
uiprivFallbackSkew(m, x, y, xamount, yamount);
}
void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src)
@ -425,7 +425,7 @@ void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m)
void uiDrawClip(uiDrawContext *c, uiDrawPath *path)
{
if (!path->ended)
userbug("You cannot call uiDrawCilp() on a uiDrawPath that has not been ended. (path: %p)", path);
uiprivUserBug("You cannot call uiDrawCilp() on a uiDrawPath that has not been ended. (path: %p)", path);
CGContextAddPath(c->c, (CGPathRef) (path->path));
switch (path->fillMode) {
case uiDrawFillModeWinding:

View File

@ -365,7 +365,7 @@ static CTFontDescriptorRef matchStyle(CTFontDescriptorRef against, uiFontDescrip
if ([d variation] != NULL)
axisDict = uiprivMakeVariationAxisDict([d variationAxes], [d table:kCTFontTableAvar]);
closeness = (struct closeness *) uiAlloc(n * sizeof (struct closeness), "struct closeness[]");
closeness = (struct closeness *) uiprivAlloc(n * sizeof (struct closeness), "struct closeness[]");
for (i = 0; i < n; i++) {
uiFontDescriptor fields;
@ -409,7 +409,7 @@ static CTFontDescriptorRef matchStyle(CTFontDescriptorRef against, uiFontDescrip
// release everything
if (axisDict != nil)
[axisDict release];
uiFree(closeness);
uiprivFree(closeness);
CFRelease(matching);
// and release the original descriptor since we no longer need it
CFRelease(against);

View File

@ -187,7 +187,7 @@ static fixed1616 *avarExtract(CFDataRef table, CFIndex index, size_t *n)
}
nEntries = nextuint16be();
*n = nEntries * 2;
entries = (fixed1616 *) uiAlloc(*n * sizeof (fixed1616), "fixed1616[]");
entries = (fixed1616 *) uiprivAlloc(*n * sizeof (fixed1616), "fixed1616[]");
p = entries;
for (i = 0; i < *n; i++) {
*p++ = fixed214ToFixed1616((fixed214) nextuint16be());
@ -247,7 +247,7 @@ fail:
- (void)dealloc
{
if (self->avarMappings != NULL) {
uiFree(self->avarMappings);
uiprivFree(self->avarMappings);
self->avarMappings = NULL;
}
[super dealloc];

View File

@ -530,7 +530,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
// LONGTERM on other platforms
// or at leat allow this and implicitly turn it into a spacer
if (c == NULL)
userbug("You cannot add NULL to a uiForm.");
uiprivUserBug("You cannot add NULL to a uiForm.");
[f->view append:toNSString(label) c:c stretchy:stretchy];
}

View File

@ -10,16 +10,16 @@ int uiprivGraphemesTakesUTF16(void)
return 1;
}
struct graphemes *uiprivNewGraphemes(void *s, size_t len)
uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len)
{
struct graphemes *g;
uiprivGraphemes *g;
UniChar *str = (UniChar *) s;
CFStringRef cfstr;
size_t ppos, gpos;
CFRange range;
size_t i;
g = uiprivNew(struct graphemes);
g = uiprivNew(uiprivGraphemes);
cfstr = CFStringCreateWithCharactersNoCopy(NULL, str, len, kCFAllocatorNull);
if (cfstr == NULL) {

View File

@ -288,11 +288,11 @@ struct uiGrid {
// now build a topological map of the grid gg[y][x]
// also figure out which cells contain spanned views so they can be ignored later
// treat hidden controls by keeping the indices -1
gg = (int **) uiAlloc(ycount * sizeof (int *), "int[][]");
gspan = (BOOL **) uiAlloc(ycount * sizeof (BOOL *), "BOOL[][]");
gg = (int **) uiprivAlloc(ycount * sizeof (int *), "int[][]");
gspan = (BOOL **) uiprivAlloc(ycount * sizeof (BOOL *), "BOOL[][]");
for (y = 0; y < ycount; y++) {
gg[y] = (int *) uiAlloc(xcount * sizeof (int), "int[]");
gspan[y] = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]");
gg[y] = (int *) uiprivAlloc(xcount * sizeof (int), "int[]");
gspan[y] = (BOOL *) uiprivAlloc(xcount * sizeof (BOOL), "BOOL[]");
for (x = 0; x < xcount; x++)
gg[y][x] = -1; // empty
}
@ -344,9 +344,9 @@ struct uiGrid {
// now build a topological map of the grid's views gv[y][x]
// for any empty cell, create a dummy view
gv = (NSView ***) uiAlloc(ycount * sizeof (NSView **), "NSView *[][]");
gv = (NSView ***) uiprivAlloc(ycount * sizeof (NSView **), "NSView *[][]");
for (y = 0; y < ycount; y++) {
gv[y] = (NSView **) uiAlloc(xcount * sizeof (NSView *), "NSView *[]");
gv[y] = (NSView **) uiprivAlloc(xcount * sizeof (NSView *), "NSView *[]");
for (x = 0; x < xcount; x++)
if (gg[y][x] == -1) {
gv[y][x] = [[NSView alloc] initWithFrame:NSZeroRect];
@ -360,8 +360,8 @@ struct uiGrid {
}
// now figure out which rows and columns really expand
hexpand = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]");
vexpand = (BOOL *) uiAlloc(ycount * sizeof (BOOL), "BOOL[]");
hexpand = (BOOL *) uiprivAlloc(xcount * sizeof (BOOL), "BOOL[]");
vexpand = (BOOL *) uiprivAlloc(ycount * sizeof (BOOL), "BOOL[]");
// first, which don't span
for (gc in self->children) {
if (!uiControlVisible(gc.c))
@ -522,16 +522,16 @@ struct uiGrid {
// TODO make all expanding rows/columns the same height/width
// and finally clean up
uiFree(hexpand);
uiFree(vexpand);
uiprivFree(hexpand);
uiprivFree(vexpand);
for (y = 0; y < ycount; y++) {
uiFree(gg[y]);
uiFree(gv[y]);
uiFree(gspan[y]);
uiprivFree(gg[y]);
uiprivFree(gv[y]);
uiprivFree(gspan[y]);
}
uiFree(gg);
uiFree(gv);
uiFree(gspan);
uiprivFree(gg);
uiprivFree(gv);
uiprivFree(gspan);
}
- (void)append:(gridChild *)gc
@ -574,7 +574,7 @@ struct uiGrid {
break;
}
if (!found)
userbug("Existing control %p is not in grid %p; you cannot add other controls next to it", c, self->g);
uiprivUserBug("Existing control %p is not in grid %p; you cannot add other controls next to it", c, self->g);
switch (at) {
case uiAtLeading:
@ -742,9 +742,9 @@ static gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand, uiAli
gridChild *gc;
if (xspan < 0)
userbug("You cannot have a negative xspan in a uiGrid cell.");
uiprivUserBug("You cannot have a negative xspan in a uiGrid cell.");
if (yspan < 0)
userbug("You cannot have a negative yspan in a uiGrid cell.");
uiprivUserBug("You cannot have a negative yspan in a uiGrid cell.");
gc = [gridChild new];
gc.xspan = xspan;
gc.yspan = yspan;
@ -763,7 +763,7 @@ void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int ysp
// LONGTERM on other platforms
// or at leat allow this and implicitly turn it into a spacer
if (c == NULL)
userbug("You cannot add NULL to a uiGrid.");
uiprivUserBug("You cannot add NULL to a uiGrid.");
gc = toChild(c, xspan, yspan, hexpand, halign, vexpand, valign, g);
gc.left = left;
gc.top = top;

View File

@ -11,23 +11,23 @@ uiImage *uiNewImage(double width, double height)
{
uiImage *i;
i = uiNew(uiImage);
i = uiprivNew(uiImage);
i->size = NSMakeSize(width, height);
i->i = [[NSImage alloc] initWithSize:i->size];
i->swizzled = [NSMutableArray new];
return i;
}
void uiFreeImage(uiImage *i)
void Image(uiImage *i)
{
NSValue *v;
[i->i release];
// to be safe, do this after releasing the image
for (v in i->swizzled)
uiFree([v pointerValue]);
uiprivFree([v pointerValue]);
[i->swizzled release];
uiFree(i);
uiprivFree(i);
}
void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride)
@ -40,7 +40,7 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
// OS X demands that R and B are in the opposite order from what we expect
// we must swizzle :(
// LONGTERM test on a big-endian system
swizzled = (uint8_t *) uiAlloc((pixelStride * pixelHeight * 4) * sizeof (uint8_t), "uint8_t[]");
swizzled = (uint8_t *) uiprivAlloc((pixelStride * pixelHeight * 4) * sizeof (uint8_t), "uint8_t[]");
bp = (uint8_t *) pixels;
sp = swizzled;
for (y = 0; y < pixelHeight * pixelStride; y += pixelStride)

View File

@ -57,7 +57,7 @@ static BOOL stepsIsRunning;
NSEvent *e;
if (!canQuit)
implbug("call to [NSApp terminate:] when not ready to terminate; definitely contact andlabs");
uiprivImplBug("call to [NSApp terminate:] when not ready to terminate; definitely contact andlabs");
[realNSApp() stop:realNSApp()];
// stop: won't register until another event has passed; let's synthesize one
@ -91,7 +91,7 @@ static BOOL stepsIsRunning;
{
// for debugging
NSLog(@"in applicationShouldTerminate:");
if (shouldQuit()) {
if (uiprivShouldQuit()) {
canQuit = YES;
// this will call terminate:, which is the same as uiQuit()
return NSTerminateNow;
@ -106,12 +106,12 @@ static BOOL stepsIsRunning;
@end
uiInitOptions options;
uiInitOptions uiprivOptions;
const char *uiInit(uiInitOptions *o)
{
@autoreleasepool {
options = *o;
uiprivOptions = *o;
app = [[applicationClass sharedApplication] retain];
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
// see https://github.com/andlabs/ui/issues/6
@ -139,9 +139,8 @@ const char *uiInit(uiInitOptions *o)
void uiUninit(void)
{
if (!globalPool) {
userbug("You must call uiInit() first!");
}
if (!globalPool)
uiprivUserBug("You must call uiInit() first!");
[globalPool release];
@autoreleasepool {

View File

@ -12,7 +12,7 @@ struct mapTable *newMap(void)
{
struct mapTable *m;
m = uiNew(struct mapTable);
m = uiprivNew(struct mapTable);
m->m = [[NSMapTable alloc] initWithKeyOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
valueOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality)
capacity:0];
@ -22,9 +22,9 @@ struct mapTable *newMap(void)
void mapDestroy(struct mapTable *m)
{
if ([m->m count] != 0)
implbug("attempt to destroy map with items inside");
uiprivImplBug("attempt to destroy map with items inside");
[m->m release];
uiFree(m);
uiprivFree(m);
}
void *mapGet(struct mapTable *m, void *key)

View File

@ -71,7 +71,7 @@ static void mapItemReleaser(void *key, void *value)
- (IBAction)onQuitClicked:(id)sender
{
if (shouldQuit())
if (uiprivShouldQuit())
uiQuit();
}
@ -80,17 +80,17 @@ static void mapItemReleaser(void *key, void *value)
switch (smi->type) {
case typeQuit:
if (self->hasQuit)
userbug("You can't have multiple Quit menu items in one program.");
uiprivUserBug("You can't have multiple Quit menu items in one program.");
self->hasQuit = YES;
break;
case typePreferences:
if (self->hasPreferences)
userbug("You can't have multiple Preferences menu items in one program.");
uiprivUserBug("You can't have multiple Preferences menu items in one program.");
self->hasPreferences = YES;
break;
case typeAbout:
if (self->hasAbout)
userbug("You can't have multiple About menu items in one program.");
uiprivUserBug("You can't have multiple About menu items in one program.");
self->hasAbout = YES;
break;
}
@ -212,7 +212,7 @@ void uiMenuItemDisable(uiMenuItem *item)
void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
{
if (item->type == typeQuit)
userbug("You can't call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
uiprivUserBug("You can't call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
item->onClicked = f;
item->onClickedData = data;
}
@ -239,9 +239,9 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
uiMenuItem *item;
if (menusFinalized)
userbug("You can't create a new menu item after menus have been finalized.");
uiprivUserBug("You can't create a new menu item after menus have been finalized.");
item = uiNew(uiMenuItem);
item = uiprivNew(uiMenuItem);
item->type = type;
switch (item->type) {
@ -315,11 +315,11 @@ uiMenu *uiNewMenu(const char *name)
uiMenu *m;
if (menusFinalized)
userbug("You can't create a new menu after menus have been finalized.");
uiprivUserBug("You can't create a new menu after menus have been finalized.");
if (menus == nil)
menus = [NSMutableArray new];
m = uiNew(uiMenu);
m = uiprivNew(uiMenu);
m->menu = [[NSMenu alloc] initWithTitle:toNSString(name)];
// use automatic menu item enabling for all menus for consistency's sake
@ -359,10 +359,10 @@ void uninitMenus(void)
v = (NSValue *) obj;
mi = (uiMenuItem *) [v pointerValue];
uiFree(mi);
uiprivFree(mi);
}];
[m->items release];
uiFree(m);
uiprivFree(m);
}];
[menus release];
}

View File

@ -48,7 +48,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value)
}
if (value < 0 || value > 100)
userbug("Value %d out of range for a uiProgressBar.", value);
uiprivUserBug("Value %d out of range for a uiProgressBar.", value);
// on 10.8 there's an animation when the progress bar increases, just like with Aero
if (value == 100) {

View File

@ -39,7 +39,7 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa
[sv setAllowsMagnification:NO];
[sv setDocumentView:p->DocumentView];
d = uiNew(struct scrollViewData);
d = uiprivNew(struct scrollViewData);
scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll);
*dout = d;
@ -57,5 +57,5 @@ void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hsc
void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d)
{
uiFree(d);
uiprivFree(d);
}

View File

@ -39,11 +39,11 @@ void uninitAlloc(void)
return;
}
g_ptr_array_foreach(allocations, uninitComplain, &str);
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", str);
uiprivUserBug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", str);
g_free(str);
}
void *uiAlloc(size_t size, const char *type)
void *uiprivAlloc(size_t size, const char *type)
{
void *out;
@ -54,13 +54,13 @@ void *uiAlloc(size_t size, const char *type)
return DATA(out);
}
void *uiRealloc(void *p, size_t new, const char *type)
void *uiprivRealloc(void *p, size_t new, const char *type)
{
void *out;
size_t *s;
if (p == NULL)
return uiAlloc(new, type);
return uiprivAlloc(new, type);
p = BASE(p);
out = g_realloc(p, EXTRA + new);
s = SIZE(out);
@ -68,17 +68,17 @@ void *uiRealloc(void *p, size_t new, const char *type)
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
*s = new;
if (g_ptr_array_remove(allocations, p) == FALSE)
implbug("%p not found in allocations array in uiRealloc()", p);
uiprivImplBug("%p not found in allocations array in uiprivRealloc()", p);
g_ptr_array_add(allocations, out);
return DATA(out);
}
void uiFree(void *p)
void uiprivFree(void *p)
{
if (p == NULL)
implbug("attempt to uiFree(NULL)");
uiprivImplBug("attempt to uiprivFree(NULL)");
p = BASE(p);
g_free(p);
if (g_ptr_array_remove(allocations, p) == FALSE)
implbug("%p not found in allocations array in uiFree()", p);
uiprivImplBug("%p not found in allocations array in uiprivFree()", p);
}

View File

@ -19,7 +19,7 @@ struct areaWidget {
// construct-only parameters aare not set until after the init() function has returned
// we need this particular object available during init(), so put it here instead of in uiArea
// keep a pointer in uiArea for convenience, though
clickCounter cc;
uiprivClickCounter cc;
};
struct areaWidgetClass {
@ -45,7 +45,7 @@ struct uiArea {
int scrollHeight;
// note that this is a pointer; see above
clickCounter *cc;
uiprivClickCounter *cc;
// for user window drags
GdkEventButton *dragevent;
@ -68,7 +68,7 @@ static void areaWidget_init(areaWidget *aw)
gtk_widget_set_can_focus(GTK_WIDGET(aw), TRUE);
clickCounterReset(&(aw->cc));
uiprivClickCounterReset(&(aw->cc));
}
static void areaWidget_dispose(GObject *obj)
@ -261,7 +261,7 @@ static gboolean areaWidget_button_press_event(GtkWidget *w, GdkEventButton *e)
// e->time is guint32
// e->x and e->y are floating-point; just make them 32-bit integers
// maxTime and maxDistance... are gint, which *should* fit, hopefully...
me.Count = clickCounterClick(a->cc, me.Down,
me.Count = uiprivClickCounterClick(a->cc, me.Down,
e->x, e->y,
e->time, maxTime,
maxDistance, maxDistance);
@ -309,7 +309,7 @@ static gboolean onCrossing(areaWidget *aw, int left)
uiArea *a = aw->a;
(*(a->ah->MouseCrossed))(a->ah, a, left);
clickCounterReset(a->cc);
uiprivClickCounterReset(a->cc);
return GDK_EVENT_PROPAGATE;
}
@ -411,7 +411,7 @@ static int areaKeyEvent(uiArea *a, int up, GdkEventKey *e)
goto keyFound;
}
if (fromScancode(e->hardware_keycode - 8, &ke))
if (uiprivFromScancode(e->hardware_keycode - 8, &ke))
goto keyFound;
// no supported key found; treat as unhandled
@ -499,7 +499,7 @@ uiUnixControlAllDefaults(uiArea)
void uiAreaSetSize(uiArea *a, int width, int height)
{
if (!a->scrolling)
userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a);
uiprivUserBug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a);
a->scrollWidth = width;
a->scrollHeight = height;
gtk_widget_queue_resize(a->areaWidget);
@ -521,7 +521,7 @@ void uiAreaBeginUserWindowMove(uiArea *a)
GtkWidget *toplevel;
if (a->dragevent == NULL)
userbug("cannot call uiAreaBeginUserWindowMove() outside of a Mouse() with Down != 0");
uiprivUserBug("cannot call uiAreaBeginUserWindowMove() outside of a Mouse() with Down != 0");
// TODO don't we have a libui function for this? did I scrap it?
// TODO widget or areaWidget?
toplevel = gtk_widget_get_toplevel(a->widget);
@ -561,7 +561,7 @@ void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge)
GtkWidget *toplevel;
if (a->dragevent == NULL)
userbug("cannot call uiAreaBeginUserWindowResize() outside of a Mouse() with Down != 0");
uiprivUserBug("cannot call uiAreaBeginUserWindowResize() outside of a Mouse() with Down != 0");
// TODO don't we have a libui function for this? did I scrap it?
// TODO widget or areaWidget?
toplevel = gtk_widget_get_toplevel(a->widget);

View File

@ -33,7 +33,7 @@ struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parent
if (child == NULL)
return NULL;
c = uiNew(struct child);
c = uiprivNew(struct child);
c->c = child;
c->widget = GTK_WIDGET(uiControlHandle(c->c));
@ -82,7 +82,7 @@ void childRemove(struct child *c)
if (c->box != NULL)
gtk_widget_destroy(c->box);
uiFree(c);
uiprivFree(c);
}
void childDestroy(struct child *c)

View File

@ -3,7 +3,7 @@
// LONGTERM don't halt on release builds
void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
{
char *a, *b;

View File

@ -6,7 +6,7 @@ uiDrawContext *newContext(cairo_t *cr, GtkStyleContext *style)
{
uiDrawContext *c;
c = uiNew(uiDrawContext);
c = uiprivNew(uiDrawContext);
c->cr = cr;
c->style = style;
return c;
@ -15,7 +15,7 @@ uiDrawContext *newContext(cairo_t *cr, GtkStyleContext *style)
void freeContext(uiDrawContext *c)
{
// free neither cr nor style; we own neither
uiFree(c);
uiprivFree(c);
}
static cairo_pattern_t *mkbrush(uiDrawBrush *b)
@ -39,7 +39,7 @@ static cairo_pattern_t *mkbrush(uiDrawBrush *b)
// case uiDrawBrushTypeImage:
}
if (cairo_pattern_status(pat) != CAIRO_STATUS_SUCCESS)
implbug("error creating pattern in mkbrush(): %s",
uiprivImplBug("error creating pattern in mkbrush(): %s",
cairo_status_to_string(cairo_pattern_status(pat)));
switch (b->Type) {
case uiDrawBrushTypeLinearGradient:

View File

@ -39,7 +39,7 @@ void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x
m2c(m, &c);
xt = x;
yt = y;
scaleCenter(xCenter, yCenter, &xt, &yt);
uiprivScaleCenter(xCenter, yCenter, &xt, &yt);
cairo_matrix_translate(&c, xt, yt);
cairo_matrix_scale(&c, x, y);
cairo_matrix_translate(&c, -xt, -yt);
@ -59,7 +59,7 @@ void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)
void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
{
fallbackSkew(m, x, y, xamount, yamount);
uiprivFallbackSkew(m, x, y, xamount, yamount);
}
void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src)

View File

@ -28,7 +28,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
{
uiDrawPath *p;
p = uiNew(uiDrawPath);
p = uiprivNew(uiDrawPath);
p->pieces = g_array_new(FALSE, TRUE, sizeof (struct piece));
p->fillMode = mode;
return p;
@ -37,13 +37,13 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
void uiDrawFreePath(uiDrawPath *p)
{
g_array_free(p->pieces, TRUE);
uiFree(p);
uiprivFree(p);
}
static void add(uiDrawPath *p, struct piece *piece)
{
if (p->ended)
userbug("You cannot modify a uiDrawPath that has been ended. (path: %p)", p);
uiprivUserBug("You cannot modify a uiDrawPath that has been ended. (path: %p)", p);
g_array_append_vals(p->pieces, piece, 1);
}
@ -145,7 +145,7 @@ void runPath(uiDrawPath *p, cairo_t *cr)
void (*arc)(cairo_t *, double, double, double, double, double);
if (!p->ended)
userbug("You cannot draw with a uiDrawPath that has not been ended. (path: %p)", p);
uiprivUserBug("You cannot draw with a uiDrawPath that has not been ended. (path: %p)", p);
cairo_new_path(cr);
for (i = 0; i < p->pieces->len; i++) {
piece = &g_array_index(p->pieces, struct piece, i);

View File

@ -7,20 +7,20 @@ int uiprivGraphemesTakesUTF16(void)
return 0;
}
struct graphemes *uiprivNewGraphemes(void *s, size_t len)
uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len)
{
struct graphemes *g;
uiprivGraphemes *g;
char *text = (char *) s;
size_t lenchars;
PangoLogAttr *logattrs;
size_t i;
size_t *op;
g = uiNew(struct graphemes);
g = uiprivNew(uiprivGraphemes);
// TODO see if we can use the utf routines
lenchars = g_utf8_strlen(text, -1);
logattrs = (PangoLogAttr *) uiAlloc((lenchars + 1) * sizeof (PangoLogAttr), "PangoLogAttr[] (graphemes)");
logattrs = (PangoLogAttr *) uiprivAlloc((lenchars + 1) * sizeof (PangoLogAttr), "PangoLogAttr[] (graphemes)");
pango_get_log_attrs(text, len,
-1, NULL,
logattrs, lenchars + 1);
@ -31,8 +31,8 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
if (logattrs[i].is_cursor_position != 0)
g->len++;
g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->pointsToGraphemes = (size_t *) uiprivAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
// compute the graphemesToPoints array
// TODO merge with the next for loop somehow?
@ -58,6 +58,6 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
// and do the last one
*op++ = i;
uiFree(logattrs);
uiprivFree(logattrs);
return g;
}

View File

@ -14,14 +14,14 @@ static void freeImageRep(gpointer item)
buf = cairo_image_surface_get_data(cs);
cairo_surface_destroy(cs);
uiFree(buf);
uiprivFree(buf);
}
uiImage *uiNewImage(double width, double height)
{
uiImage *i;
i = uiNew(uiImage);
i = uiprivNew(uiImage);
i->width = width;
i->height = height;
i->images = g_ptr_array_new_with_free_func(freeImageRep);
@ -31,7 +31,7 @@ uiImage *uiNewImage(double width, double height)
void uiFreeImage(uiImage *i)
{
g_ptr_array_free(i->images, TRUE);
uiFree(i);
uiprivFree(i);
}
void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride)
@ -43,7 +43,7 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
int y;
cstride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, pixelWidth);
buf = (unsigned char *) uiAlloc((cstride * pixelHeight * 4) * sizeof (unsigned char), "unsigned char[]");
buf = (unsigned char *) uiprivAlloc((cstride * pixelHeight * 4) * sizeof (unsigned char), "unsigned char[]");
p = buf;
for (y = 0; y < pixelStride * pixelHeight; y += pixelStride) {
memmove(p, src + y, cstride);

View File

@ -1,14 +1,14 @@
// 6 april 2015
#include "uipriv_unix.h"
uiInitOptions options;
uiInitOptions uiprivOptions;
const char *uiInit(uiInitOptions *o)
{
GError *err = NULL;
const char *msg;
options = *o;
uiprivOptions = *o;
if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) {
msg = g_strdup(err->message);
g_error_free(err);
@ -99,7 +99,7 @@ void uiQueueMain(void (*f)(void *data), void *data)
{
struct queued *q;
// we have to use g_new0()/g_free() because uiAlloc() is only safe to call on the main thread
// we have to use g_new0()/g_free() because uiprivAlloc() is only safe to call on the main thread
// for some reason it didn't affect me, but it did affect krakjoe
q = g_new0(struct queued, 1);
q->f = f;

View File

@ -81,7 +81,7 @@ static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data)
static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data)
{
if (shouldQuit())
if (uiprivShouldQuit())
uiQuit();
}
@ -109,7 +109,7 @@ void uiMenuItemDisable(uiMenuItem *item)
void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
{
if (item->type == typeQuit)
userbug("You cannot call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
uiprivUserBug("You cannot call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
item->onClicked = f;
item->onClickedData = data;
}
@ -135,9 +135,9 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
uiMenuItem *item;
if (menusFinalized)
userbug("You cannot create a new menu item after menus have been finalized.");
uiprivUserBug("You cannot create a new menu item after menus have been finalized.");
item = uiNew(uiMenuItem);
item = uiprivNew(uiMenuItem);
g_array_append_val(m->items, item);
@ -196,7 +196,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name)
uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
{
if (hasQuit)
userbug("You cannot have multiple Quit menu items in the same program.");
uiprivUserBug("You cannot have multiple Quit menu items in the same program.");
hasQuit = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeQuit, NULL);
@ -205,7 +205,7 @@ uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
{
if (hasPreferences)
userbug("You cannot have multiple Preferences menu items in the same program.");
uiprivUserBug("You cannot have multiple Preferences menu items in the same program.");
hasPreferences = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typePreferences, NULL);
@ -214,7 +214,7 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
uiMenuItem *uiMenuAppendAboutItem(uiMenu *m)
{
if (hasAbout)
userbug("You cannot have multiple About menu items in the same program.");
uiprivUserBug("You cannot have multiple About menu items in the same program.");
hasAbout = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeAbout, NULL);
@ -230,11 +230,11 @@ uiMenu *uiNewMenu(const char *name)
uiMenu *m;
if (menusFinalized)
userbug("You cannot create a new menu after menus have been finalized.");
uiprivUserBug("You cannot create a new menu after menus have been finalized.");
if (menus == NULL)
menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *));
m = uiNew(uiMenu);
m = uiprivNew(uiMenu);
g_array_append_val(menus, m);
@ -260,7 +260,7 @@ static void appendMenuItem(GtkMenuShell *submenu, uiMenuItem *item, uiWindow *w)
singleSetChecked(GTK_CHECK_MENU_ITEM(menuitem), item->checked, signal);
}
gtk_menu_shell_append(submenu, menuitem);
ww = uiNew(struct menuItemWindow);
ww = uiprivNew(struct menuItemWindow);
ww->w = w;
ww->signal = signal;
g_hash_table_insert(item->windows, menuitem, ww);
@ -308,8 +308,8 @@ static void freeMenuItem(GtkWidget *widget, gpointer data)
item = g_array_index(fmi->items, uiMenuItem *, fmi->i);
w = (struct menuItemWindow *) g_hash_table_lookup(item->windows, widget);
if (g_hash_table_remove(item->windows, widget) == FALSE)
implbug("GtkMenuItem %p not in menu item's item/window map", widget);
uiFree(w);
uiprivImplBug("GtkMenuItem %p not in menu item's item/window map", widget);
uiprivFree(w);
fmi->i++;
}
@ -353,14 +353,14 @@ void uninitMenus(void)
for (j = 0; j < m->items->len; j++) {
item = g_array_index(m->items, uiMenuItem *, j);
if (g_hash_table_size(item->windows) != 0)
// TODO is this really a userbug()?
implbug("menu item %p (%s) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
// TODO is this really a uiprivUserBug()?
uiprivImplBug("menu item %p (%s) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
g_free(item->name);
g_hash_table_destroy(item->windows);
uiFree(item);
uiprivFree(item);
}
g_array_free(m->items, TRUE);
uiFree(m);
uiprivFree(m);
}
g_array_free(menus, TRUE);
}

View File

@ -53,7 +53,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value)
}
if (value < 0 || value > 100)
userbug("Value %d is out of range for a uiProgressBar.", value);
uiprivUserBug("Value %d is out of range for a uiProgressBar.", value);
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
}

View File

@ -22,12 +22,12 @@ void uninitAlloc(void)
// note the void * cast; otherwise it'll be treated as a string
oss << (void *) (alloc.first) << " " << types[alloc.second] << "\n";
ossstr = oss.str();
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", ossstr.c_str());
uiprivUserBug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", ossstr.c_str());
}
#define rawBytes(pa) (&((*pa)[0]))
void *uiAlloc(size_t size, const char *type)
void *uiprivAlloc(size_t size, const char *type)
{
byteArray *out;
@ -37,13 +37,13 @@ void *uiAlloc(size_t size, const char *type)
return rawBytes(out);
}
void *uiRealloc(void *_p, size_t size, const char *type)
void *uiprivRealloc(void *_p, size_t size, const char *type)
{
uint8_t *p = (uint8_t *) _p;
byteArray *arr;
if (p == NULL)
return uiAlloc(size, type);
return uiprivAlloc(size, type);
arr = heap[p];
// TODO does this fill in?
arr->resize(size, 0);
@ -52,12 +52,12 @@ void *uiRealloc(void *_p, size_t size, const char *type)
return rawBytes(arr);
}
void uiFree(void *_p)
void uiprivFree(void *_p)
{
uint8_t *p = (uint8_t *) _p;
if (p == NULL)
implbug("attempt to uiFree(NULL)");
uiprivImplBug("attempt to uiprivFree(NULL)");
types.erase(heap[p]);
delete heap[p];
heap.erase(p);

View File

@ -168,7 +168,7 @@ uiArea *uiNewArea(uiAreaHandler *ah)
a->ah = ah;
a->scrolling = FALSE;
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
// a->hwnd is assigned in areaWndProc()
uiWindowsEnsureCreateControlHWND(0,
@ -190,7 +190,7 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
a->scrolling = TRUE;
a->scrollWidth = width;
a->scrollHeight = height;
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
// a->hwnd is assigned in areaWndProc()
uiWindowsEnsureCreateControlHWND(0,

View File

@ -18,7 +18,7 @@ struct uiArea {
int hwheelCarry;
int vwheelCarry;
clickCounter cc;
uiprivClickCounter cc;
BOOL capturing;
BOOL inside;

View File

@ -92,11 +92,11 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l
if (inClient && !a->inside) {
a->inside = TRUE;
(*(a->ah->MouseCrossed))(a->ah, a, 0);
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
} else if (!inClient && a->inside) {
a->inside = FALSE;
(*(a->ah->MouseCrossed))(a->ah, a, 1);
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
}
}
@ -120,7 +120,7 @@ static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM l
// GetMessageTime() returns LONG and GetDoubleClckTime() returns UINT, which are int32 and uint32, respectively, but we don't need to worry about the signedness because for the same bit widths and two's complement arithmetic, s1-s2 == u1-u2 if bits(s1)==bits(s2) and bits(u1)==bits(u2) (and Windows requires two's complement: http://blogs.msdn.com/b/oldnewthing/archive/2005/05/27/422551.aspx)
// signedness isn't much of an issue for these calls anyway because http://stackoverflow.com/questions/24022225/what-are-the-sign-extension-rules-for-calling-windows-api-functions-stdcall-t and that we're only using unsigned values (think back to how you (didn't) handle signedness in assembly language) AND because of the above AND because the statistics below (time interval and width/height) really don't make sense if negative
// GetSystemMetrics() returns int, which is int32
me.Count = clickCounterClick(&(a->cc), me.Down,
me.Count = uiprivClickCounterClick(&(a->cc), me.Down,
me.X, me.Y,
GetMessageTime(), GetDoubleClickTime(),
GetSystemMetrics(SM_CXDOUBLECLK) / 2,
@ -164,7 +164,7 @@ static void onMouseEntered(uiArea *a)
track(a, TRUE);
(*(a->ah->MouseCrossed))(a->ah, a, 0);
// TODO figure out why we did this to begin with; either we do it on both GTK+ and Windows or not at all
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
}
// TODO genericize it so that it can be called above
@ -174,7 +174,7 @@ static void onMouseLeft(uiArea *a)
a->inside = FALSE;
(*(a->ah->MouseCrossed))(a->ah, a, 1);
// TODO figure out why we did this to begin with; either we do it on both GTK+ and Windows or not at all
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
}
// we use VK_SNAPSHOT as a sentinel because libui will never support the print screen key; that key belongs to the user
@ -300,7 +300,7 @@ static int areaKeyEvent(uiArea *a, int up, WPARAM wParam, LPARAM lParam)
}
// and finally everything else
if (fromScancode((lParam >> 16) & 0xFF, &ke))
if (uiprivFromScancode((lParam >> 16) & 0xFF, &ke))
goto keyFound;
// not a supported key, assume unhandled
@ -325,7 +325,7 @@ BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *l
switch (uMsg) {
case WM_ACTIVATE:
// don't keep the double-click timer running if the user switched programs in between clicks
clickCounterReset(&(a->cc));
uiprivClickCounterReset(&(a->cc));
*lResult = 0;
return TRUE;
case WM_MOUSEMOVE:

View File

@ -295,7 +295,7 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
hr = p->layout->SetFontFamilyName(wfamily, range);
if (hr != S_OK)
logHRESULT(L"error applying family name attribute", hr);
uiFree(wfamily);
uiprivFree(wfamily);
break;
case uiAttributeTypeSize:
hr = p->layout->SetFontSize(

View File

@ -1,7 +1,5 @@
// 11 march 2018
extern "C" {
#include "../common/attrstr.h"
}
// dwrite.cpp
extern IDWriteFactory *dwfactory;

View File

@ -95,7 +95,7 @@ uiButton *uiNewButton(const char *text)
BS_PUSHBUTTON | WS_TABSTOP,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
uiButtonOnClicked(b, defaultOnClicked, NULL);

View File

@ -108,7 +108,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
BS_CHECKBOX | WS_TABSTOP,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
uiCheckboxOnToggled(c, defaultOnToggled, NULL);

View File

@ -228,7 +228,7 @@ static void updateDouble(HWND hwnd, double d, HWND whichChanged)
return;
str = ftoutf16(d);
setWindowText(hwnd, str);
uiFree(str);
uiprivFree(str);
}
static void updateDialog(struct colorDialog *c, HWND whichChanged)
@ -259,22 +259,22 @@ static void updateDialog(struct colorDialog *c, HWND whichChanged)
if (whichChanged != c->editRInt) {
str = itoutf16(rb);
setWindowText(c->editRInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editGInt) {
str = itoutf16(gb);
setWindowText(c->editGInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editBInt) {
str = itoutf16(bb);
setWindowText(c->editBInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editAInt) {
str = itoutf16(ab);
setWindowText(c->editAInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editHex) {
@ -956,7 +956,7 @@ static struct colorDialog *beginColorDialog(HWND hwnd, LPARAM lParam)
{
struct colorDialog *c;
c = uiNew(struct colorDialog);
c = uiprivNew(struct colorDialog);
c->hwnd = hwnd;
c->out = (struct colorDialogRGBA *) lParam;
// load initial values now
@ -995,7 +995,7 @@ static void endColorDialog(struct colorDialog *c, INT_PTR code)
{
if (EndDialog(c->hwnd, code) == 0)
logLastError(L"error ending color dialog");
uiFree(c);
uiprivFree(c);
}
// TODO make this void on the font dialog too
@ -1020,7 +1020,7 @@ static double editDouble(HWND hwnd)
s = windowText(hwnd);
d = _wtof(s);
uiFree(s);
uiprivFree(s);
return d;
}
@ -1111,7 +1111,7 @@ static int editInt(HWND hwnd)
s = windowText(hwnd);
i = _wtoi(s);
uiFree(s);
uiprivFree(s);
return i;
}
@ -1176,7 +1176,7 @@ static void hexChanged(struct colorDialog *c)
buf = windowText(c->editHex);
is = hex2RGBA(buf, &r, &g, &b, &a);
uiFree(buf);
uiprivFree(buf);
if (!is)
return;
rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v));

View File

@ -66,7 +66,7 @@ void uiComboboxAppend(uiCombobox *c, const char *text)
logLastError(L"error appending item to uiCombobox");
else if (res == (LRESULT) CB_ERRSPACE)
logLastError(L"memory exhausted appending item to uiCombobox");
uiFree(wtext);
uiprivFree(wtext);
}
int uiComboboxSelected(uiCombobox *c)

View File

@ -19,7 +19,7 @@ static WCHAR *expandYear(WCHAR *dts, int n)
int ny = 0;
// allocate more than we need to be safe
out = (WCHAR *) uiAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]");
out = (WCHAR *) uiprivAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]");
q = out;
for (p = dts; *p != L'\0'; p++) {
// first, if the current character is a y, increment the number of consecutive ys
@ -44,7 +44,7 @@ static WCHAR *expandYear(WCHAR *dts, int n)
if (*p == L'\'')
break;
if (*p == L'\0')
implbug("unterminated quote in system-provided locale date string in expandYear()");
uiprivImplBug("unterminated quote in system-provided locale date string in expandYear()");
*q++ = *p;
}
// and fall through to copy the closing quote
@ -73,17 +73,17 @@ static void setDateTimeFormat(HWND hwnd)
ndate = GLI(LOCALE_SSHORTDATE, NULL, 0);
if (ndate == 0)
logLastError(L"error getting date string length");
date = (WCHAR *) uiAlloc(ndate * sizeof (WCHAR), "WCHAR[]");
date = (WCHAR *) uiprivAlloc(ndate * sizeof (WCHAR), "WCHAR[]");
if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0)
logLastError(L"error geting date string");
unexpandedDate = date; // so we can free it
date = expandYear(unexpandedDate, ndate);
uiFree(unexpandedDate);
uiprivFree(unexpandedDate);
ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0);
if (ndate == 0)
logLastError(L"error getting time string length");
time = (WCHAR *) uiAlloc(ntime * sizeof (WCHAR), "WCHAR[]");
time = (WCHAR *) uiprivAlloc(ntime * sizeof (WCHAR), "WCHAR[]");
if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0)
logLastError(L"error geting time string");
@ -91,9 +91,9 @@ static void setDateTimeFormat(HWND hwnd)
if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0)
logLastError(L"error applying format string to date/time picker");
uiFree(datetime);
uiFree(time);
uiFree(date);
uiprivFree(datetime);
uiprivFree(time);
uiprivFree(date);
}
// control implementation

View File

@ -26,7 +26,7 @@ HRESULT _logLastError(debugargs, const WCHAR *s)
if (useFormatted)
LocalFree(formatted); // ignore error
printDebug(msg);
uiFree(msg);
uiprivFree(msg);
DebugBreak();
SetLastError(le);
@ -53,13 +53,13 @@ HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr)
if (useFormatted)
LocalFree(formatted); // ignore error
printDebug(msg);
uiFree(msg);
uiprivFree(msg);
DebugBreak();
return hr;
}
void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
{
va_list ap2;
char *msg;
@ -71,14 +71,14 @@ void realbug(const char *file, const char *line, const char *func, const char *p
va_end(ap2);
n++; // terminating '\0'
msg = (char *) uiAlloc(n * sizeof (char), "char[]");
msg = (char *) uiprivAlloc(n * sizeof (char), "char[]");
// 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);
uiFree(msg);
uiprivFree(msg);
printDebug(final);
uiFree(final);
uiprivFree(final);
DebugBreak();
}

View File

@ -107,7 +107,7 @@ uiDrawContext *newContext(ID2D1RenderTarget *rt)
{
uiDrawContext *c;
c = uiNew(uiDrawContext);
c = uiprivNew(uiDrawContext);
c->rt = rt;
c->states = new std::vector<struct drawState>;
resetTarget(c->rt);
@ -120,9 +120,9 @@ void freeContext(uiDrawContext *c)
c->currentClip->Release();
if (c->states->size() != 0)
// TODO do this on other platforms
userbug("You did not balance uiDrawSave() and uiDrawRestore() calls.");
uiprivUserBug("You did not balance uiDrawSave() and uiDrawRestore() calls.");
delete c->states;
uiFree(c);
uiprivFree(c);
}
static ID2D1Brush *makeSolidBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props)
@ -152,7 +152,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
size_t i;
HRESULT hr;
stops = (D2D1_GRADIENT_STOP *) uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]");
stops = (D2D1_GRADIENT_STOP *) uiprivAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]");
for (i = 0; i < b->NumStops; i++) {
stops[i].position = b->Stops[i].Pos;
stops[i].color.r = b->Stops[i].R;
@ -170,7 +170,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
if (hr != S_OK)
logHRESULT(L"error creating stop collection", hr);
uiFree(stops);
uiprivFree(stops);
return s;
}
@ -253,7 +253,7 @@ static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt)
}
// TODO do this on all platforms
userbug("Invalid brush type %d given to drawing operation.", b->Type);
uiprivUserBug("Invalid brush type %d given to drawing operation.", b->Type);
// TODO dummy brush?
return NULL; // make compiler happy
}
@ -365,7 +365,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
// TODO be sure to formally document this
if (sp->NumDashes != 0) {
dsp.dashStyle = D2D1_DASH_STYLE_CUSTOM;
dashes = (FLOAT *) uiAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]");
dashes = (FLOAT *) uiprivAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]");
for (i = 0; i < sp->NumDashes; i++)
dashes[i] = sp->Dashes[i] / sp->Thickness;
}
@ -378,7 +378,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
if (hr != S_OK)
logHRESULT(L"error creating stroke style", hr);
if (sp->NumDashes != 0)
uiFree(dashes);
uiprivFree(dashes);
cliplayer = applyClip(c);
c->rt->DrawGeometry(

View File

@ -113,5 +113,5 @@ void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y)
void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y)
{
fallbackTransformSize(m, x, y);
uiprivFallbackTransformSize(m, x, y);
}

View File

@ -17,7 +17,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode fillmode)
uiDrawPath *p;
HRESULT hr;
p = uiNew(uiDrawPath);
p = uiprivNew(uiDrawPath);
hr = d2dfactory->CreatePathGeometry(&(p->path));
if (hr != S_OK)
logHRESULT(L"error creating path", hr);
@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p)
// TODO close sink first?
p->sink->Release();
p->path->Release();
uiFree(p);
uiprivFree(p);
}
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
@ -242,6 +242,6 @@ void uiDrawPathEnd(uiDrawPath *p)
ID2D1PathGeometry *pathGeometry(uiDrawPath *p)
{
if (p->sink != NULL)
userbug("You cannot draw with a uiDrawPath that was not ended. (path: %p)", p);
uiprivUserBug("You cannot draw with a uiDrawPath that was not ended. (path: %p)", p);
return p->path;
}

View File

@ -38,7 +38,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
FLOAT maxWidth;
HRESULT hr;
tl = uiNew(uiDrawTextLayout);
tl = uiprivNew(uiDrawTextLayout);
wDefaultFamily = toUTF16(p->DefaultFont->Family);
hr = dwfactory->CreateTextFormat(
@ -51,7 +51,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
// TODO use the current locale?
L"",
&(tl->format));
uiFree(wDefaultFamily);
uiprivFree(wDefaultFamily);
if (hr != S_OK)
logHRESULT(L"error creating IDWriteTextFormat", hr);
hr = tl->format->SetTextAlignment(dwriteAligns[p->Align]);
@ -95,14 +95,14 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
{
uiFree(tl->u16tou8);
uiFree(tl->u8tou16);
uiprivFree(tl->u16tou8);
uiprivFree(tl->u8tou16);
for (auto p : *(tl->backgroundParams))
uiprivFree(p);
delete tl->backgroundParams;
tl->layout->Release();
tl->format->Release();
uiFree(tl);
uiprivFree(tl);
}
// TODO make this shared code somehow

View File

@ -81,7 +81,7 @@ WCHAR *uiprivFontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStr
if (hr != S_OK)
logHRESULT(L"error getting length of font name", hr);
// GetStringLength() does not include the null terminator, but GetString() does
wname = (WCHAR *) uiAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]");
wname = (WCHAR *) uiprivAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]");
hr = names->GetString(index, wname, length + 1);
if (hr != S_OK)
logHRESULT(L"error getting font name", hr);

View File

@ -76,7 +76,7 @@ void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)
logLastError(L"error appending item to uiEditableCombobox");
else if (res == (LRESULT) CB_ERRSPACE)
logLastError(L"memory exhausted appending item to uiEditableCombobox");
uiFree(wtext);
uiprivFree(wtext);
}
char *uiEditableComboboxText(uiEditableCombobox *c)

View File

@ -23,7 +23,7 @@ static std::map<HWND, struct handler> handlers;
void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
{
if (handlers[hwnd].commandHandler != NULL)
implbug("already registered a WM_COMMAND handler to window handle %p", hwnd);
uiprivImplBug("already registered a WM_COMMAND handler to window handle %p", hwnd);
handlers[hwnd].commandHandler = handler;
handlers[hwnd].c = c;
}
@ -31,7 +31,7 @@ void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *,
void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c)
{
if (handlers[hwnd].notifyHandler != NULL)
implbug("already registered a WM_NOTIFY handler to window handle %p", hwnd);
uiprivImplBug("already registered a WM_NOTIFY handler to window handle %p", hwnd);
handlers[hwnd].notifyHandler = handler;
handlers[hwnd].c = c;
}
@ -39,7 +39,7 @@ void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, H
void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c)
{
if (handlers[hwnd].hscrollHandler != NULL)
implbug("already registered a WM_HSCROLL handler to window handle %p", hwnd);
uiprivImplBug("already registered a WM_HSCROLL handler to window handle %p", hwnd);
handlers[hwnd].hscrollHandler = handler;
handlers[hwnd].c = c;
}
@ -47,21 +47,21 @@ void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *,
void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd)
{
if (handlers[hwnd].commandHandler == NULL)
implbug("window handle %p not registered to receive WM_COMMAND events", hwnd);
uiprivImplBug("window handle %p not registered to receive WM_COMMAND events", hwnd);
handlers[hwnd].commandHandler = NULL;
}
void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd)
{
if (handlers[hwnd].notifyHandler == NULL)
implbug("window handle %p not registered to receive WM_NOTIFY events", hwnd);
uiprivImplBug("window handle %p not registered to receive WM_NOTIFY events", hwnd);
handlers[hwnd].notifyHandler = NULL;
}
void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd)
{
if (handlers[hwnd].hscrollHandler == NULL)
implbug("window handle %p not registered to receive WM_HSCROLL events", hwnd);
uiprivImplBug("window handle %p not registered to receive WM_HSCROLL events", hwnd);
handlers[hwnd].hscrollHandler = NULL;
}
@ -131,14 +131,14 @@ static std::map<HWND, bool> wininichanges;
void uiWindowsRegisterReceiveWM_WININICHANGE(HWND hwnd)
{
if (wininichanges[hwnd])
implbug("window handle %p already subscribed to receive WM_WINICHANGEs", hwnd);
uiprivImplBug("window handle %p already subscribed to receive WM_WINICHANGEs", hwnd);
wininichanges[hwnd] = true;
}
void uiWindowsUnregisterReceiveWM_WININICHANGE(HWND hwnd)
{
if (!wininichanges[hwnd])
implbug("window handle %p not registered to receive WM_WININICHANGEs", hwnd);
uiprivImplBug("window handle %p not registered to receive WM_WININICHANGEs", hwnd);
wininichanges[hwnd] = false;
}

View File

@ -121,7 +121,7 @@ static WCHAR *cbGetItemText(HWND cb, WPARAM item)
len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0);
if (len == (LRESULT) CB_ERR)
logLastError(L"error getting item text length from combobox");
text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
text = (WCHAR *) uiprivAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len)
logLastError(L"error getting item text from combobox");
return text;
@ -138,7 +138,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
text = windowText(cb);
pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text);
if (pos == (LRESULT) CB_ERR) {
uiFree(text);
uiprivFree(text);
return FALSE;
}
cbSetCurSel(cb, (WPARAM) pos);
@ -147,7 +147,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
if (restoreAfter)
if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE)
logLastError(L"error restoring old combobox text");
uiFree(text);
uiprivFree(text);
// and restore the selection like above
// TODO isn't there a 32-bit version of this
if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE)
@ -254,7 +254,7 @@ static void familyChanged(struct fontDialog *f)
logHRESULT(L"error getting font for filling styles box", hr);
label = fontStyleName(f->fc, font);
pos = cbAddString(f->styleCombobox, label);
uiFree(label);
uiprivFree(label);
cbSetItemData(f->styleCombobox, (WPARAM) pos, (LPARAM) font);
if (font->GetWeight() == weight &&
font->GetStyle() == style &&
@ -386,7 +386,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt
&format);
if (hr != S_OK)
logHRESULT(L"error creating IDWriteTextFormat", hr);
uiFree(family);
uiprivFree(family);
rect.left = 0;
rect.top = 0;
@ -402,7 +402,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt
format->Release();
if (exists)
uiFree(sample);
uiprivFree(sample);
black->Release();
}
@ -466,7 +466,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
HWND samplePlacement;
HRESULT hr;
f = uiNew(struct fontDialog);
f = uiprivNew(struct fontDialog);
f->hwnd = hwnd;
f->params = (struct fontDialogParams *) lParam;
@ -482,7 +482,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
logHRESULT(L"error getting font family", hr);
wname = uiprivFontCollectionFamilyName(f->fc, family);
pos = cbAddString(f->familyCombobox, wname);
uiFree(wname);
uiprivFree(wname);
cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family);
}
@ -506,7 +506,7 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code)
uiprivFontCollectionFree(f->fc);
if (EndDialog(f->hwnd, code) == 0)
logLastError(L"error ending font dialog");
uiFree(f);
uiprivFree(f);
}
static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
@ -681,7 +681,7 @@ WCHAR *uiprivFontDialogParamsToString(struct fontDialogParams *params)
WCHAR *text;
// TODO dynamically allocate
text = (WCHAR *) uiAlloc(512 * sizeof (WCHAR), "WCHAR[]");
text = (WCHAR *) uiprivAlloc(512 * sizeof (WCHAR), "WCHAR[]");
_snwprintf(text, 512, L"%s %s %g",
params->familyName,
params->styleName,

View File

@ -266,7 +266,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
SS_LEFT | SS_NOPREFIX,
hInstance, NULL,
TRUE);
uiFree(wlabel);
uiprivFree(wlabel);
uiWindowsEnsureSetParentHWND(fc.label, f->hwnd);
fc.stretchy = stretchy;
uiControlSetParent(fc.c, uiControl(f));

View File

@ -11,13 +11,13 @@ int uiprivGraphemesTakesUTF16(void)
return 1;
}
struct graphemes *uiprivNewGraphemes(void *s, size_t len)
uiprivGraphemes *uiprivNewGraphemes(void *s, size_t len)
{
struct graphemes *g;
uiprivGraphemes *g;
WCHAR *str;
size_t *pPTG, *pGTP;
g = uiNew(struct graphemes);
g = uiprivNew(uiprivGraphemes);
g->len = 0;
str = (WCHAR *) s;
@ -27,8 +27,8 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
// no need to worry about surrogates if we're just counting
}
g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->pointsToGraphemes = (size_t *) uiprivAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
pPTG = g->pointsToGraphemes;
pGTP = g->graphemesToPoints;

View File

@ -418,7 +418,7 @@ static void uiGridDestroy(uiControl *c)
for (struct gridChild *gc : *(g->children)) {
uiControlSetParent(gc->c, NULL);
uiControlDestroy(gc->c);
uiFree(gc);
uiprivFree(gc);
}
delete g->indexof;
delete g->children;
@ -562,10 +562,10 @@ static struct gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand
struct gridChild *gc;
if (xspan < 0)
userbug("You cannot have a negative xspan in a uiGrid cell.");
uiprivUserBug("You cannot have a negative xspan in a uiGrid cell.");
if (yspan < 0)
userbug("You cannot have a negative yspan in a uiGrid cell.");
gc = uiNew(struct gridChild);
uiprivUserBug("You cannot have a negative yspan in a uiGrid cell.");
gc = uiprivNew(struct gridChild);
gc->c = c;
gc->xspan = xspan;
gc->yspan = yspan;

View File

@ -208,7 +208,7 @@ uiGroup *uiNewGroup(const char *text)
BS_GROUPBOX,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE)
logLastError(L"error subclassing groupbox to handle parent messages");

View File

@ -28,19 +28,19 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value)
wmessage,
value, value,
sysmsg);
uiFree(wmessage);
uiprivFree(wmessage);
if (hassysmsg)
LocalFree(sysmsg); // ignore error
out = toUTF8(wout);
uiFree(wout);
uiprivFree(wout);
return out + 1;
}
#define ieLastErr(msg) initerr("=" msg, L"GetLastError() ==", GetLastError())
#define ieHRESULT(msg, hr) initerr("=" msg, L"HRESULT", (DWORD) hr)
// LONGTERM make common
uiInitOptions options;
// LONGTERM put this declaration in a common file
uiInitOptions uiprivOptions;
#define wantedICCClasses ( \
ICC_STANDARD_CLASSES | /* user32.dll controls */ \
@ -62,7 +62,7 @@ const char *uiInit(uiInitOptions *o)
INITCOMMONCONTROLSEX icc;
HRESULT hr;
options = *o;
uiprivOptions = *o;
initAlloc();
@ -157,7 +157,7 @@ void uiUninit(void)
void uiFreeInitError(const char *err)
{
if (*(err - 1) == '-')
uiFree((void *) (err - 1));
uiprivFree((void *) (err - 1));
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

View File

@ -51,7 +51,7 @@ uiLabel *uiNewLabel(const char *text)
SS_LEFTNOWORDWRAP | SS_NOPREFIX,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
return l;
}

View File

@ -68,7 +68,7 @@ static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data)
static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data)
{
if (shouldQuit())
if (uiprivShouldQuit())
uiQuit();
}
@ -87,7 +87,7 @@ void uiMenuItemDisable(uiMenuItem *i)
void uiMenuItemOnClicked(uiMenuItem *i, void (*f)(uiMenuItem *, uiWindow *, void *), void *data)
{
if (i->type == typeQuit)
userbug("You can not call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
uiprivUserBug("You can not call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead.");
i->onClicked = f;
i->onClickedData = data;
}
@ -111,14 +111,14 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
uiMenuItem *item;
if (menusFinalized)
userbug("You can not create a new menu item after menus have been finalized.");
uiprivUserBug("You can not create a new menu item after menus have been finalized.");
if (m->len >= m->cap) {
m->cap += grow;
m->items = (uiMenuItem **) uiRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]");
m->items = (uiMenuItem **) uiprivRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]");
}
item = uiNew(uiMenuItem);
item = uiprivNew(uiMenuItem);
m->items[m->len] = item;
m->len++;
@ -169,7 +169,7 @@ uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name)
uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
{
if (hasQuit)
userbug("You can not have multiple Quit menu items in a program.");
uiprivUserBug("You can not have multiple Quit menu items in a program.");
hasQuit = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeQuit, NULL);
@ -178,7 +178,7 @@ uiMenuItem *uiMenuAppendQuitItem(uiMenu *m)
uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
{
if (hasPreferences)
userbug("You can not have multiple Preferences menu items in a program.");
uiprivUserBug("You can not have multiple Preferences menu items in a program.");
hasPreferences = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typePreferences, NULL);
@ -187,8 +187,8 @@ uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m)
uiMenuItem *uiMenuAppendAboutItem(uiMenu *m)
{
if (hasAbout)
// TODO place these userbug strings in a header
userbug("You can not have multiple About menu items in a program.");
// TODO place these uiprivImplBug() and uiprivUserBug() strings in a header
uiprivUserBug("You can not have multiple About menu items in a program.");
hasAbout = TRUE;
newItem(m, typeSeparator, NULL);
return newItem(m, typeAbout, NULL);
@ -204,13 +204,13 @@ uiMenu *uiNewMenu(const char *name)
uiMenu *m;
if (menusFinalized)
userbug("You can not create a new menu after menus have been finalized.");
uiprivUserBug("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 *[]");
menus = (uiMenu **) uiprivRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]");
}
m = uiNew(uiMenu);
m = uiprivNew(uiMenu);
menus[len] = m;
len++;
@ -237,7 +237,7 @@ static void appendMenuItem(HMENU menu, uiMenuItem *item)
if (item->len >= item->cap) {
item->cap += grow;
item->hmenus = (HMENU *) uiRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]");
item->hmenus = (HMENU *) uiprivRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]");
}
item->hmenus[item->len] = menu;
item->len++;
@ -293,7 +293,7 @@ void runMenuEvent(WORD id, uiWindow *w)
}
}
// no match
implbug("unknown menu ID %hu in runMenuEvent()", id);
uiprivImplBug("unknown menu ID %hu in runMenuEvent()", id);
found:
// first toggle checkboxes, if any
@ -316,7 +316,7 @@ static void freeMenu(uiMenu *m, HMENU submenu)
if (item->hmenus[j] == submenu)
break;
if (j >= item->len)
implbug("submenu handle %p not found in freeMenu()", submenu);
uiprivImplBug("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;
@ -348,22 +348,22 @@ void uninitMenus(void)
for (i = 0; i < len; i++) {
m = menus[i];
uiFree(m->name);
uiprivFree(m->name);
for (j = 0; j < m->len; j++) {
item = m->items[j];
if (item->len != 0)
// LONGTERM userbug()?
implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
// LONGTERM uiprivUserBug()?
uiprivImplBug("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);
uiprivFree(item->name);
if (item->hmenus != NULL)
uiFree(item->hmenus);
uiFree(item);
uiprivFree(item->hmenus);
uiprivFree(item);
}
if (m->items != NULL)
uiFree(m->items);
uiFree(m);
uiprivFree(m->items);
uiprivFree(m);
}
if (menus != NULL)
uiFree(menus);
uiprivFree(menus);
}

View File

@ -76,7 +76,7 @@ void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)
e->inhibitChanged = TRUE;
crlf = LFtoCRLF(text);
uiWindowsSetWindowText(e->hwnd, text);
uiFree(crlf);
uiprivFree(crlf);
e->inhibitChanged = FALSE;
// don't queue the control for resize; entry sizes are independent of their contents
}
@ -95,9 +95,9 @@ void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text)
SendMessageW(e->hwnd, EM_SETSEL, n, n);
crlf = LFtoCRLF(text);
wtext = toUTF16(crlf);
uiFree(crlf);
uiprivFree(crlf);
SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext);
uiFree(wtext);
uiprivFree(wtext);
e->inhibitChanged = FALSE;
}

View File

@ -54,7 +54,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value)
}
if (value < 0 || value > 100)
userbug("Value %d is out of range for uiProgressBars.", value);
uiprivUserBug("Value %d is out of range for uiProgressBars.", value);
if (value == 100) { // because we can't 101
SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 101);

View File

@ -140,7 +140,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
BS_RADIOBUTTON | groupTabStop,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
uiWindowsEnsureSetParentHWND(hwnd, r->hwnd);
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
r->hwnds->push_back(hwnd);

View File

@ -48,10 +48,10 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
// This won't handle leading spaces, but spaces aren't allowed *anyway*.
wtext = windowText(s->edit);
if (wcscmp(wtext, L"-") == 0) {
uiFree(wtext);
uiprivFree(wtext);
return TRUE;
}
uiFree(wtext);
uiprivFree(wtext);
// value() does the work for us
value(s);
(*(s->onChanged))(s, s->onChangedData);

View File

@ -114,8 +114,8 @@ static void msgbox(HWND parent, const char *title, const char *description, TASK
if (hr != S_OK)
logHRESULT(L"error showing task dialog", hr);
uiFree(wdescription);
uiFree(wtitle);
uiprivFree(wdescription);
uiprivFree(wtitle);
}
void uiMsgBox(uiWindow *parent, const char *title, const char *description)

View File

@ -212,7 +212,7 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
item.pszText = wname;
if (SendMessageW(t->tabHWND, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
logLastError(L"error adding tab to uiTab");
uiFree(wname);
uiprivFree(wname);
// we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page
show = curpage(t);

View File

@ -83,7 +83,7 @@ struct tabPage *newTabPage(uiControl *child)
struct tabPage *tp;
HRESULT hr;
tp = uiNew(struct tabPage);
tp = uiprivNew(struct tabPage);
// unfortunately this needs to be a proper dialog for EnableThemeDialogTexture() to work; CreateWindowExW() won't suffice
if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog),
@ -114,7 +114,7 @@ void tabPageDestroy(struct tabPage *tp)
uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL);
// don't call EndDialog(); that's for the DialogBox() family of functions instead of CreateDialog()
uiWindowsEnsureDestroyWindow(tp->hwnd);
uiFree(tp);
uiprivFree(tp);
}
void tabPageMinimumSize(struct tabPage *tp, int *width, int *height)

View File

@ -10,7 +10,7 @@ WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len)
if (len != NULL)
*len = n;
// WM_GETTEXTLENGTH does not include the null terminator
text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
text = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
// note the comparison: the size includes the null terminator, but the return does not
if (GetWindowTextW(hwnd, text, n + 1) != n) {
logLastError(L"error getting window text");
@ -35,7 +35,7 @@ void setWindowText(HWND hwnd, WCHAR *wtext)
void uiFreeText(char *text)
{
uiFree(text);
uiprivFree(text);
}
int uiWindowsWindowTextWidth(HWND hwnd)
@ -78,11 +78,11 @@ int uiWindowsWindowTextWidth(HWND hwnd)
if (ReleaseDC(hwnd, dc) == 0)
logLastError(L"error releasing DC");
uiFree(text);
uiprivFree(text);
return size.cx;
noTextOrError:
uiFree(text);
uiprivFree(text);
return 0;
}
@ -93,7 +93,7 @@ char *uiWindowsWindowText(HWND hwnd)
wtext = windowText(hwnd);
text = toUTF8(wtext);
uiFree(wtext);
uiprivFree(wtext);
return text;
}
@ -103,7 +103,7 @@ void uiWindowsSetWindowText(HWND hwnd, const char *text)
wtext = toUTF16(text);
setWindowText(hwnd, wtext);
uiFree(wtext);
uiprivFree(wtext);
}
int uiprivStricmp(const char *a, const char *b)
@ -114,7 +114,7 @@ int uiprivStricmp(const char *a, const char *b)
wa = toUTF16(a);
wb = toUTF16(b);
ret = _wcsicmp(wa, wb);
uiFree(wb);
uiFree(wa);
uiprivFree(wb);
uiprivFree(wa);
return ret;
}

View File

@ -29,8 +29,8 @@ extern BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult);
extern void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam);
// utf16.cpp
#define emptyUTF16() ((WCHAR *) uiAlloc(1 * sizeof (WCHAR), "WCHAR[]"))
#define emptyUTF8() ((char *) uiAlloc(1 * sizeof (char), "char[]"))
#define emptyUTF16() ((WCHAR *) uiprivAlloc(1 * sizeof (WCHAR), "WCHAR[]"))
#define emptyUTF8() ((char *) uiprivAlloc(1 * sizeof (char), "char[]"))
extern WCHAR *toUTF16(const char *str);
extern char *toUTF8(const WCHAR *wstr);
extern WCHAR *utf16dup(const WCHAR *orig);

View File

@ -12,12 +12,12 @@ WCHAR *toUTF16(const char *str)
if (*str == '\0') // empty string
return emptyUTF16();
n = utf8UTF16Count(str, 0);
wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
n = uiprivUTF8UTF16Count(str, 0);
wstr = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
wp = wstr;
while (*str) {
str = utf8DecodeRune(str, 0, &rune);
n = utf16EncodeRune(rune, wp);
str = uiprivUTF8DecodeRune(str, 0, &rune);
n = uiprivUTF16EncodeRune(rune, wp);
wp += n;
}
return wstr;
@ -32,12 +32,12 @@ char *toUTF8(const WCHAR *wstr)
if (*wstr == L'\0') // empty string
return emptyUTF8();
n = utf16RuneCount(wstr, 0);
str = (char *) uiAlloc((n + 1) * sizeof (char), "char[]");
n = uiprivUTF16UTF8Count(wstr, 0);
str = (char *) uiprivAlloc((n + 1) * sizeof (char), "char[]");
sp = str;
while (*wstr) {
wstr = utf16DecodeRune(wstr, 0, &rune);
n = utf8EncodeRune(rune, sp);
wstr = uiprivUTF16DecodeRune(wstr, 0, &rune);
n = uiprivUTF8EncodeRune(rune, sp);
sp += n;
}
return str;
@ -49,7 +49,7 @@ WCHAR *utf16dup(const WCHAR *orig)
size_t len;
len = wcslen(orig);
out = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
out = (WCHAR *) uiprivAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
wcscpy_s(out, len + 1, orig);
return out;
}
@ -79,7 +79,7 @@ WCHAR *vstrf(const WCHAR *format, va_list ap)
va_end(ap2);
n++; // terminating L'\0'
buf = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]");
buf = (WCHAR *) uiprivAlloc(n * sizeof (WCHAR), "WCHAR[]");
// includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
vswprintf_s(buf, n, format, ap);
@ -97,7 +97,7 @@ char *LFtoCRLF(const char *lfonly)
char *out;
len = strlen(lfonly);
crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]");
crlf = (char *) uiprivAlloc((len * 2 + 1) * sizeof (char), "char[]");
out = crlf;
for (i = 0; i < len; i++) {
if (*lfonly == '\n')

View File

@ -23,8 +23,8 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
return lResult;
switch (uMsg) {
case WM_QUERYENDSESSION:
// TODO block handler
if (shouldQuit()) {
// TODO block handler (TODO figure out if this meant the Vista-style block handler or not)
if (uiprivShouldQuit()) {
uiQuit();
return TRUE;
}

View File

@ -480,7 +480,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
NULL, NULL, hInstance, w);
if (w->hwnd == NULL)
logLastError(L"error creating window");
uiFree(wtitle);
uiprivFree(wtitle);
if (hasMenubar) {
w->menubar = makeMenubar();