uiAlloc() et al -> uiprivAlloc() et al, Windows code.
This commit is contained in:
parent
099c4ff631
commit
c6bb463692
|
@ -27,7 +27,7 @@ void uninitAlloc(void)
|
||||||
|
|
||||||
#define rawBytes(pa) (&((*pa)[0]))
|
#define rawBytes(pa) (&((*pa)[0]))
|
||||||
|
|
||||||
void *uiAlloc(size_t size, const char *type)
|
void *uiprivAlloc(size_t size, const char *type)
|
||||||
{
|
{
|
||||||
byteArray *out;
|
byteArray *out;
|
||||||
|
|
||||||
|
@ -37,13 +37,13 @@ void *uiAlloc(size_t size, const char *type)
|
||||||
return rawBytes(out);
|
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;
|
uint8_t *p = (uint8_t *) _p;
|
||||||
byteArray *arr;
|
byteArray *arr;
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return uiAlloc(size, type);
|
return uiprivAlloc(size, type);
|
||||||
arr = heap[p];
|
arr = heap[p];
|
||||||
// TODO does this fill in?
|
// TODO does this fill in?
|
||||||
arr->resize(size, 0);
|
arr->resize(size, 0);
|
||||||
|
@ -52,12 +52,12 @@ void *uiRealloc(void *_p, size_t size, const char *type)
|
||||||
return rawBytes(arr);
|
return rawBytes(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiFree(void *_p)
|
void uiprivFree(void *_p)
|
||||||
{
|
{
|
||||||
uint8_t *p = (uint8_t *) _p;
|
uint8_t *p = (uint8_t *) _p;
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
implbug("attempt to uiFree(NULL)");
|
implbug("attempt to uiprivFree(NULL)");
|
||||||
types.erase(heap[p]);
|
types.erase(heap[p]);
|
||||||
delete heap[p];
|
delete heap[p];
|
||||||
heap.erase(p);
|
heap.erase(p);
|
||||||
|
|
|
@ -295,7 +295,7 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
|
||||||
hr = p->layout->SetFontFamilyName(wfamily, range);
|
hr = p->layout->SetFontFamilyName(wfamily, range);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error applying family name attribute", hr);
|
logHRESULT(L"error applying family name attribute", hr);
|
||||||
uiFree(wfamily);
|
uiprivFree(wfamily);
|
||||||
break;
|
break;
|
||||||
case uiAttributeTypeSize:
|
case uiAttributeTypeSize:
|
||||||
hr = p->layout->SetFontSize(
|
hr = p->layout->SetFontSize(
|
||||||
|
|
|
@ -95,7 +95,7 @@ uiButton *uiNewButton(const char *text)
|
||||||
BS_PUSHBUTTON | WS_TABSTOP,
|
BS_PUSHBUTTON | WS_TABSTOP,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
|
|
||||||
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
|
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
|
||||||
uiButtonOnClicked(b, defaultOnClicked, NULL);
|
uiButtonOnClicked(b, defaultOnClicked, NULL);
|
||||||
|
|
|
@ -108,7 +108,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
BS_CHECKBOX | WS_TABSTOP,
|
BS_CHECKBOX | WS_TABSTOP,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
|
|
||||||
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
|
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
|
||||||
uiCheckboxOnToggled(c, defaultOnToggled, NULL);
|
uiCheckboxOnToggled(c, defaultOnToggled, NULL);
|
||||||
|
|
|
@ -228,7 +228,7 @@ static void updateDouble(HWND hwnd, double d, HWND whichChanged)
|
||||||
return;
|
return;
|
||||||
str = ftoutf16(d);
|
str = ftoutf16(d);
|
||||||
setWindowText(hwnd, str);
|
setWindowText(hwnd, str);
|
||||||
uiFree(str);
|
uiprivFree(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateDialog(struct colorDialog *c, HWND whichChanged)
|
static void updateDialog(struct colorDialog *c, HWND whichChanged)
|
||||||
|
@ -259,22 +259,22 @@ static void updateDialog(struct colorDialog *c, HWND whichChanged)
|
||||||
if (whichChanged != c->editRInt) {
|
if (whichChanged != c->editRInt) {
|
||||||
str = itoutf16(rb);
|
str = itoutf16(rb);
|
||||||
setWindowText(c->editRInt, str);
|
setWindowText(c->editRInt, str);
|
||||||
uiFree(str);
|
uiprivFree(str);
|
||||||
}
|
}
|
||||||
if (whichChanged != c->editGInt) {
|
if (whichChanged != c->editGInt) {
|
||||||
str = itoutf16(gb);
|
str = itoutf16(gb);
|
||||||
setWindowText(c->editGInt, str);
|
setWindowText(c->editGInt, str);
|
||||||
uiFree(str);
|
uiprivFree(str);
|
||||||
}
|
}
|
||||||
if (whichChanged != c->editBInt) {
|
if (whichChanged != c->editBInt) {
|
||||||
str = itoutf16(bb);
|
str = itoutf16(bb);
|
||||||
setWindowText(c->editBInt, str);
|
setWindowText(c->editBInt, str);
|
||||||
uiFree(str);
|
uiprivFree(str);
|
||||||
}
|
}
|
||||||
if (whichChanged != c->editAInt) {
|
if (whichChanged != c->editAInt) {
|
||||||
str = itoutf16(ab);
|
str = itoutf16(ab);
|
||||||
setWindowText(c->editAInt, str);
|
setWindowText(c->editAInt, str);
|
||||||
uiFree(str);
|
uiprivFree(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whichChanged != c->editHex) {
|
if (whichChanged != c->editHex) {
|
||||||
|
@ -956,7 +956,7 @@ static struct colorDialog *beginColorDialog(HWND hwnd, LPARAM lParam)
|
||||||
{
|
{
|
||||||
struct colorDialog *c;
|
struct colorDialog *c;
|
||||||
|
|
||||||
c = uiNew(struct colorDialog);
|
c = uiprivNew(struct colorDialog);
|
||||||
c->hwnd = hwnd;
|
c->hwnd = hwnd;
|
||||||
c->out = (struct colorDialogRGBA *) lParam;
|
c->out = (struct colorDialogRGBA *) lParam;
|
||||||
// load initial values now
|
// load initial values now
|
||||||
|
@ -995,7 +995,7 @@ static void endColorDialog(struct colorDialog *c, INT_PTR code)
|
||||||
{
|
{
|
||||||
if (EndDialog(c->hwnd, code) == 0)
|
if (EndDialog(c->hwnd, code) == 0)
|
||||||
logLastError(L"error ending color dialog");
|
logLastError(L"error ending color dialog");
|
||||||
uiFree(c);
|
uiprivFree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO make this void on the font dialog too
|
// TODO make this void on the font dialog too
|
||||||
|
@ -1020,7 +1020,7 @@ static double editDouble(HWND hwnd)
|
||||||
|
|
||||||
s = windowText(hwnd);
|
s = windowText(hwnd);
|
||||||
d = _wtof(s);
|
d = _wtof(s);
|
||||||
uiFree(s);
|
uiprivFree(s);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,7 +1111,7 @@ static int editInt(HWND hwnd)
|
||||||
|
|
||||||
s = windowText(hwnd);
|
s = windowText(hwnd);
|
||||||
i = _wtoi(s);
|
i = _wtoi(s);
|
||||||
uiFree(s);
|
uiprivFree(s);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1176,7 +1176,7 @@ static void hexChanged(struct colorDialog *c)
|
||||||
|
|
||||||
buf = windowText(c->editHex);
|
buf = windowText(c->editHex);
|
||||||
is = hex2RGBA(buf, &r, &g, &b, &a);
|
is = hex2RGBA(buf, &r, &g, &b, &a);
|
||||||
uiFree(buf);
|
uiprivFree(buf);
|
||||||
if (!is)
|
if (!is)
|
||||||
return;
|
return;
|
||||||
rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v));
|
rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v));
|
||||||
|
|
|
@ -66,7 +66,7 @@ void uiComboboxAppend(uiCombobox *c, const char *text)
|
||||||
logLastError(L"error appending item to uiCombobox");
|
logLastError(L"error appending item to uiCombobox");
|
||||||
else if (res == (LRESULT) CB_ERRSPACE)
|
else if (res == (LRESULT) CB_ERRSPACE)
|
||||||
logLastError(L"memory exhausted appending item to uiCombobox");
|
logLastError(L"memory exhausted appending item to uiCombobox");
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uiComboboxSelected(uiCombobox *c)
|
int uiComboboxSelected(uiCombobox *c)
|
||||||
|
|
|
@ -19,7 +19,7 @@ static WCHAR *expandYear(WCHAR *dts, int n)
|
||||||
int ny = 0;
|
int ny = 0;
|
||||||
|
|
||||||
// allocate more than we need to be safe
|
// 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;
|
q = out;
|
||||||
for (p = dts; *p != L'\0'; p++) {
|
for (p = dts; *p != L'\0'; p++) {
|
||||||
// first, if the current character is a y, increment the number of consecutive ys
|
// first, if the current character is a y, increment the number of consecutive ys
|
||||||
|
@ -73,17 +73,17 @@ static void setDateTimeFormat(HWND hwnd)
|
||||||
ndate = GLI(LOCALE_SSHORTDATE, NULL, 0);
|
ndate = GLI(LOCALE_SSHORTDATE, NULL, 0);
|
||||||
if (ndate == 0)
|
if (ndate == 0)
|
||||||
logLastError(L"error getting date string length");
|
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)
|
if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0)
|
||||||
logLastError(L"error geting date string");
|
logLastError(L"error geting date string");
|
||||||
unexpandedDate = date; // so we can free it
|
unexpandedDate = date; // so we can free it
|
||||||
date = expandYear(unexpandedDate, ndate);
|
date = expandYear(unexpandedDate, ndate);
|
||||||
uiFree(unexpandedDate);
|
uiprivFree(unexpandedDate);
|
||||||
|
|
||||||
ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0);
|
ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0);
|
||||||
if (ndate == 0)
|
if (ndate == 0)
|
||||||
logLastError(L"error getting time string length");
|
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)
|
if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0)
|
||||||
logLastError(L"error geting time string");
|
logLastError(L"error geting time string");
|
||||||
|
|
||||||
|
@ -91,9 +91,9 @@ static void setDateTimeFormat(HWND hwnd)
|
||||||
if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0)
|
if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0)
|
||||||
logLastError(L"error applying format string to date/time picker");
|
logLastError(L"error applying format string to date/time picker");
|
||||||
|
|
||||||
uiFree(datetime);
|
uiprivFree(datetime);
|
||||||
uiFree(time);
|
uiprivFree(time);
|
||||||
uiFree(date);
|
uiprivFree(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
// control implementation
|
// control implementation
|
||||||
|
|
|
@ -26,7 +26,7 @@ HRESULT _logLastError(debugargs, const WCHAR *s)
|
||||||
if (useFormatted)
|
if (useFormatted)
|
||||||
LocalFree(formatted); // ignore error
|
LocalFree(formatted); // ignore error
|
||||||
printDebug(msg);
|
printDebug(msg);
|
||||||
uiFree(msg);
|
uiprivFree(msg);
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
|
|
||||||
SetLastError(le);
|
SetLastError(le);
|
||||||
|
@ -53,7 +53,7 @@ HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr)
|
||||||
if (useFormatted)
|
if (useFormatted)
|
||||||
LocalFree(formatted); // ignore error
|
LocalFree(formatted); // ignore error
|
||||||
printDebug(msg);
|
printDebug(msg);
|
||||||
uiFree(msg);
|
uiprivFree(msg);
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
@ -71,14 +71,14 @@ void realbug(const char *file, const char *line, const char *func, const char *p
|
||||||
va_end(ap2);
|
va_end(ap2);
|
||||||
n++; // terminating '\0'
|
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
|
// includes terminating '\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
|
||||||
vsprintf_s(msg, n, format, ap);
|
vsprintf_s(msg, n, format, ap);
|
||||||
|
|
||||||
final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg);
|
final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg);
|
||||||
uiFree(msg);
|
uiprivFree(msg);
|
||||||
printDebug(final);
|
printDebug(final);
|
||||||
uiFree(final);
|
uiprivFree(final);
|
||||||
|
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ uiDrawContext *newContext(ID2D1RenderTarget *rt)
|
||||||
{
|
{
|
||||||
uiDrawContext *c;
|
uiDrawContext *c;
|
||||||
|
|
||||||
c = uiNew(uiDrawContext);
|
c = uiprivNew(uiDrawContext);
|
||||||
c->rt = rt;
|
c->rt = rt;
|
||||||
c->states = new std::vector<struct drawState>;
|
c->states = new std::vector<struct drawState>;
|
||||||
resetTarget(c->rt);
|
resetTarget(c->rt);
|
||||||
|
@ -122,7 +122,7 @@ void freeContext(uiDrawContext *c)
|
||||||
// TODO do this on other platforms
|
// TODO do this on other platforms
|
||||||
userbug("You did not balance uiDrawSave() and uiDrawRestore() calls.");
|
userbug("You did not balance uiDrawSave() and uiDrawRestore() calls.");
|
||||||
delete c->states;
|
delete c->states;
|
||||||
uiFree(c);
|
uiprivFree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID2D1Brush *makeSolidBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props)
|
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;
|
size_t i;
|
||||||
HRESULT hr;
|
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++) {
|
for (i = 0; i < b->NumStops; i++) {
|
||||||
stops[i].position = b->Stops[i].Pos;
|
stops[i].position = b->Stops[i].Pos;
|
||||||
stops[i].color.r = b->Stops[i].R;
|
stops[i].color.r = b->Stops[i].R;
|
||||||
|
@ -170,7 +170,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error creating stop collection", hr);
|
logHRESULT(L"error creating stop collection", hr);
|
||||||
|
|
||||||
uiFree(stops);
|
uiprivFree(stops);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
|
||||||
// TODO be sure to formally document this
|
// TODO be sure to formally document this
|
||||||
if (sp->NumDashes != 0) {
|
if (sp->NumDashes != 0) {
|
||||||
dsp.dashStyle = D2D1_DASH_STYLE_CUSTOM;
|
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++)
|
for (i = 0; i < sp->NumDashes; i++)
|
||||||
dashes[i] = sp->Dashes[i] / sp->Thickness;
|
dashes[i] = sp->Dashes[i] / sp->Thickness;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error creating stroke style", hr);
|
logHRESULT(L"error creating stroke style", hr);
|
||||||
if (sp->NumDashes != 0)
|
if (sp->NumDashes != 0)
|
||||||
uiFree(dashes);
|
uiprivFree(dashes);
|
||||||
|
|
||||||
cliplayer = applyClip(c);
|
cliplayer = applyClip(c);
|
||||||
c->rt->DrawGeometry(
|
c->rt->DrawGeometry(
|
||||||
|
|
|
@ -17,7 +17,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode fillmode)
|
||||||
uiDrawPath *p;
|
uiDrawPath *p;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
p = uiNew(uiDrawPath);
|
p = uiprivNew(uiDrawPath);
|
||||||
hr = d2dfactory->CreatePathGeometry(&(p->path));
|
hr = d2dfactory->CreatePathGeometry(&(p->path));
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error creating path", hr);
|
logHRESULT(L"error creating path", hr);
|
||||||
|
@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p)
|
||||||
// TODO close sink first?
|
// TODO close sink first?
|
||||||
p->sink->Release();
|
p->sink->Release();
|
||||||
p->path->Release();
|
p->path->Release();
|
||||||
uiFree(p);
|
uiprivFree(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
|
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
|
||||||
|
|
|
@ -38,7 +38,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
FLOAT maxWidth;
|
FLOAT maxWidth;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
tl = uiNew(uiDrawTextLayout);
|
tl = uiprivNew(uiDrawTextLayout);
|
||||||
|
|
||||||
wDefaultFamily = toUTF16(p->DefaultFont->Family);
|
wDefaultFamily = toUTF16(p->DefaultFont->Family);
|
||||||
hr = dwfactory->CreateTextFormat(
|
hr = dwfactory->CreateTextFormat(
|
||||||
|
@ -51,7 +51,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
// TODO use the current locale?
|
// TODO use the current locale?
|
||||||
L"",
|
L"",
|
||||||
&(tl->format));
|
&(tl->format));
|
||||||
uiFree(wDefaultFamily);
|
uiprivFree(wDefaultFamily);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error creating IDWriteTextFormat", hr);
|
logHRESULT(L"error creating IDWriteTextFormat", hr);
|
||||||
hr = tl->format->SetTextAlignment(dwriteAligns[p->Align]);
|
hr = tl->format->SetTextAlignment(dwriteAligns[p->Align]);
|
||||||
|
@ -95,14 +95,14 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
|
|
||||||
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
||||||
{
|
{
|
||||||
uiFree(tl->u16tou8);
|
uiprivFree(tl->u16tou8);
|
||||||
uiFree(tl->u8tou16);
|
uiprivFree(tl->u8tou16);
|
||||||
for (auto p : *(tl->backgroundParams))
|
for (auto p : *(tl->backgroundParams))
|
||||||
uiprivFree(p);
|
uiprivFree(p);
|
||||||
delete tl->backgroundParams;
|
delete tl->backgroundParams;
|
||||||
tl->layout->Release();
|
tl->layout->Release();
|
||||||
tl->format->Release();
|
tl->format->Release();
|
||||||
uiFree(tl);
|
uiprivFree(tl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO make this shared code somehow
|
// TODO make this shared code somehow
|
||||||
|
|
|
@ -81,7 +81,7 @@ WCHAR *uiprivFontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStr
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error getting length of font name", hr);
|
logHRESULT(L"error getting length of font name", hr);
|
||||||
// GetStringLength() does not include the null terminator, but GetString() does
|
// 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);
|
hr = names->GetString(index, wname, length + 1);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error getting font name", hr);
|
logHRESULT(L"error getting font name", hr);
|
||||||
|
|
|
@ -76,7 +76,7 @@ void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)
|
||||||
logLastError(L"error appending item to uiEditableCombobox");
|
logLastError(L"error appending item to uiEditableCombobox");
|
||||||
else if (res == (LRESULT) CB_ERRSPACE)
|
else if (res == (LRESULT) CB_ERRSPACE)
|
||||||
logLastError(L"memory exhausted appending item to uiEditableCombobox");
|
logLastError(L"memory exhausted appending item to uiEditableCombobox");
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiEditableComboboxText(uiEditableCombobox *c)
|
char *uiEditableComboboxText(uiEditableCombobox *c)
|
||||||
|
|
|
@ -121,7 +121,7 @@ static WCHAR *cbGetItemText(HWND cb, WPARAM item)
|
||||||
len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0);
|
len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0);
|
||||||
if (len == (LRESULT) CB_ERR)
|
if (len == (LRESULT) CB_ERR)
|
||||||
logLastError(L"error getting item text length from combobox");
|
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)
|
if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len)
|
||||||
logLastError(L"error getting item text from combobox");
|
logLastError(L"error getting item text from combobox");
|
||||||
return text;
|
return text;
|
||||||
|
@ -138,7 +138,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
|
||||||
text = windowText(cb);
|
text = windowText(cb);
|
||||||
pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text);
|
pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text);
|
||||||
if (pos == (LRESULT) CB_ERR) {
|
if (pos == (LRESULT) CB_ERR) {
|
||||||
uiFree(text);
|
uiprivFree(text);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
cbSetCurSel(cb, (WPARAM) pos);
|
cbSetCurSel(cb, (WPARAM) pos);
|
||||||
|
@ -147,7 +147,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
|
||||||
if (restoreAfter)
|
if (restoreAfter)
|
||||||
if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE)
|
if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE)
|
||||||
logLastError(L"error restoring old combobox text");
|
logLastError(L"error restoring old combobox text");
|
||||||
uiFree(text);
|
uiprivFree(text);
|
||||||
// and restore the selection like above
|
// and restore the selection like above
|
||||||
// TODO isn't there a 32-bit version of this
|
// TODO isn't there a 32-bit version of this
|
||||||
if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE)
|
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);
|
logHRESULT(L"error getting font for filling styles box", hr);
|
||||||
label = fontStyleName(f->fc, font);
|
label = fontStyleName(f->fc, font);
|
||||||
pos = cbAddString(f->styleCombobox, label);
|
pos = cbAddString(f->styleCombobox, label);
|
||||||
uiFree(label);
|
uiprivFree(label);
|
||||||
cbSetItemData(f->styleCombobox, (WPARAM) pos, (LPARAM) font);
|
cbSetItemData(f->styleCombobox, (WPARAM) pos, (LPARAM) font);
|
||||||
if (font->GetWeight() == weight &&
|
if (font->GetWeight() == weight &&
|
||||||
font->GetStyle() == style &&
|
font->GetStyle() == style &&
|
||||||
|
@ -386,7 +386,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt
|
||||||
&format);
|
&format);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error creating IDWriteTextFormat", hr);
|
logHRESULT(L"error creating IDWriteTextFormat", hr);
|
||||||
uiFree(family);
|
uiprivFree(family);
|
||||||
|
|
||||||
rect.left = 0;
|
rect.left = 0;
|
||||||
rect.top = 0;
|
rect.top = 0;
|
||||||
|
@ -402,7 +402,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt
|
||||||
|
|
||||||
format->Release();
|
format->Release();
|
||||||
if (exists)
|
if (exists)
|
||||||
uiFree(sample);
|
uiprivFree(sample);
|
||||||
black->Release();
|
black->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
|
||||||
HWND samplePlacement;
|
HWND samplePlacement;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
f = uiNew(struct fontDialog);
|
f = uiprivNew(struct fontDialog);
|
||||||
f->hwnd = hwnd;
|
f->hwnd = hwnd;
|
||||||
f->params = (struct fontDialogParams *) lParam;
|
f->params = (struct fontDialogParams *) lParam;
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
|
||||||
logHRESULT(L"error getting font family", hr);
|
logHRESULT(L"error getting font family", hr);
|
||||||
wname = uiprivFontCollectionFamilyName(f->fc, family);
|
wname = uiprivFontCollectionFamilyName(f->fc, family);
|
||||||
pos = cbAddString(f->familyCombobox, wname);
|
pos = cbAddString(f->familyCombobox, wname);
|
||||||
uiFree(wname);
|
uiprivFree(wname);
|
||||||
cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family);
|
cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +506,7 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code)
|
||||||
uiprivFontCollectionFree(f->fc);
|
uiprivFontCollectionFree(f->fc);
|
||||||
if (EndDialog(f->hwnd, code) == 0)
|
if (EndDialog(f->hwnd, code) == 0)
|
||||||
logLastError(L"error ending font dialog");
|
logLastError(L"error ending font dialog");
|
||||||
uiFree(f);
|
uiprivFree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
|
static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
|
||||||
|
@ -681,7 +681,7 @@ WCHAR *uiprivFontDialogParamsToString(struct fontDialogParams *params)
|
||||||
WCHAR *text;
|
WCHAR *text;
|
||||||
|
|
||||||
// TODO dynamically allocate
|
// TODO dynamically allocate
|
||||||
text = (WCHAR *) uiAlloc(512 * sizeof (WCHAR), "WCHAR[]");
|
text = (WCHAR *) uiprivAlloc(512 * sizeof (WCHAR), "WCHAR[]");
|
||||||
_snwprintf(text, 512, L"%s %s %g",
|
_snwprintf(text, 512, L"%s %s %g",
|
||||||
params->familyName,
|
params->familyName,
|
||||||
params->styleName,
|
params->styleName,
|
||||||
|
|
|
@ -266,7 +266,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
|
||||||
SS_LEFT | SS_NOPREFIX,
|
SS_LEFT | SS_NOPREFIX,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
uiFree(wlabel);
|
uiprivFree(wlabel);
|
||||||
uiWindowsEnsureSetParentHWND(fc.label, f->hwnd);
|
uiWindowsEnsureSetParentHWND(fc.label, f->hwnd);
|
||||||
fc.stretchy = stretchy;
|
fc.stretchy = stretchy;
|
||||||
uiControlSetParent(fc.c, uiControl(f));
|
uiControlSetParent(fc.c, uiControl(f));
|
||||||
|
|
|
@ -17,7 +17,7 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
|
||||||
WCHAR *str;
|
WCHAR *str;
|
||||||
size_t *pPTG, *pGTP;
|
size_t *pPTG, *pGTP;
|
||||||
|
|
||||||
g = uiNew(struct graphemes);
|
g = uiprivNew(struct graphemes);
|
||||||
|
|
||||||
g->len = 0;
|
g->len = 0;
|
||||||
str = (WCHAR *) s;
|
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
|
// 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->pointsToGraphemes = (size_t *) uiprivAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
|
||||||
g->graphemesToPoints = (size_t *) uiAlloc((g->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;
|
pPTG = g->pointsToGraphemes;
|
||||||
pGTP = g->graphemesToPoints;
|
pGTP = g->graphemesToPoints;
|
||||||
|
|
|
@ -418,7 +418,7 @@ static void uiGridDestroy(uiControl *c)
|
||||||
for (struct gridChild *gc : *(g->children)) {
|
for (struct gridChild *gc : *(g->children)) {
|
||||||
uiControlSetParent(gc->c, NULL);
|
uiControlSetParent(gc->c, NULL);
|
||||||
uiControlDestroy(gc->c);
|
uiControlDestroy(gc->c);
|
||||||
uiFree(gc);
|
uiprivFree(gc);
|
||||||
}
|
}
|
||||||
delete g->indexof;
|
delete g->indexof;
|
||||||
delete g->children;
|
delete g->children;
|
||||||
|
@ -565,7 +565,7 @@ static struct gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand
|
||||||
userbug("You cannot have a negative xspan in a uiGrid cell.");
|
userbug("You cannot have a negative xspan in a uiGrid cell.");
|
||||||
if (yspan < 0)
|
if (yspan < 0)
|
||||||
userbug("You cannot have a negative yspan in a uiGrid cell.");
|
userbug("You cannot have a negative yspan in a uiGrid cell.");
|
||||||
gc = uiNew(struct gridChild);
|
gc = uiprivNew(struct gridChild);
|
||||||
gc->c = c;
|
gc->c = c;
|
||||||
gc->xspan = xspan;
|
gc->xspan = xspan;
|
||||||
gc->yspan = yspan;
|
gc->yspan = yspan;
|
||||||
|
|
|
@ -208,7 +208,7 @@ uiGroup *uiNewGroup(const char *text)
|
||||||
BS_GROUPBOX,
|
BS_GROUPBOX,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
|
|
||||||
if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE)
|
if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE)
|
||||||
logLastError(L"error subclassing groupbox to handle parent messages");
|
logLastError(L"error subclassing groupbox to handle parent messages");
|
||||||
|
|
|
@ -28,11 +28,11 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value)
|
||||||
wmessage,
|
wmessage,
|
||||||
value, value,
|
value, value,
|
||||||
sysmsg);
|
sysmsg);
|
||||||
uiFree(wmessage);
|
uiprivFree(wmessage);
|
||||||
if (hassysmsg)
|
if (hassysmsg)
|
||||||
LocalFree(sysmsg); // ignore error
|
LocalFree(sysmsg); // ignore error
|
||||||
out = toUTF8(wout);
|
out = toUTF8(wout);
|
||||||
uiFree(wout);
|
uiprivFree(wout);
|
||||||
return out + 1;
|
return out + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ void uiUninit(void)
|
||||||
void uiFreeInitError(const char *err)
|
void uiFreeInitError(const char *err)
|
||||||
{
|
{
|
||||||
if (*(err - 1) == '-')
|
if (*(err - 1) == '-')
|
||||||
uiFree((void *) (err - 1));
|
uiprivFree((void *) (err - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||||
|
|
|
@ -51,7 +51,7 @@ uiLabel *uiNewLabel(const char *text)
|
||||||
SS_LEFTNOWORDWRAP | SS_NOPREFIX,
|
SS_LEFTNOWORDWRAP | SS_NOPREFIX,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,10 +115,10 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
|
||||||
|
|
||||||
if (m->len >= m->cap) {
|
if (m->len >= m->cap) {
|
||||||
m->cap += grow;
|
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->items[m->len] = item;
|
||||||
m->len++;
|
m->len++;
|
||||||
|
@ -207,10 +207,10 @@ uiMenu *uiNewMenu(const char *name)
|
||||||
userbug("You can not create a new menu after menus have been finalized.");
|
userbug("You can not create a new menu after menus have been finalized.");
|
||||||
if (len >= cap) {
|
if (len >= cap) {
|
||||||
cap += grow;
|
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;
|
menus[len] = m;
|
||||||
len++;
|
len++;
|
||||||
|
@ -237,7 +237,7 @@ static void appendMenuItem(HMENU menu, uiMenuItem *item)
|
||||||
|
|
||||||
if (item->len >= item->cap) {
|
if (item->len >= item->cap) {
|
||||||
item->cap += grow;
|
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->hmenus[item->len] = menu;
|
||||||
item->len++;
|
item->len++;
|
||||||
|
@ -348,22 +348,22 @@ void uninitMenus(void)
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
m = menus[i];
|
m = menus[i];
|
||||||
uiFree(m->name);
|
uiprivFree(m->name);
|
||||||
for (j = 0; j < m->len; j++) {
|
for (j = 0; j < m->len; j++) {
|
||||||
item = m->items[j];
|
item = m->items[j];
|
||||||
if (item->len != 0)
|
if (item->len != 0)
|
||||||
// LONGTERM userbug()?
|
// LONGTERM userbug()?
|
||||||
implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
|
implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
|
||||||
if (item->name != NULL)
|
if (item->name != NULL)
|
||||||
uiFree(item->name);
|
uiprivFree(item->name);
|
||||||
if (item->hmenus != NULL)
|
if (item->hmenus != NULL)
|
||||||
uiFree(item->hmenus);
|
uiprivFree(item->hmenus);
|
||||||
uiFree(item);
|
uiprivFree(item);
|
||||||
}
|
}
|
||||||
if (m->items != NULL)
|
if (m->items != NULL)
|
||||||
uiFree(m->items);
|
uiprivFree(m->items);
|
||||||
uiFree(m);
|
uiprivFree(m);
|
||||||
}
|
}
|
||||||
if (menus != NULL)
|
if (menus != NULL)
|
||||||
uiFree(menus);
|
uiprivFree(menus);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)
|
||||||
e->inhibitChanged = TRUE;
|
e->inhibitChanged = TRUE;
|
||||||
crlf = LFtoCRLF(text);
|
crlf = LFtoCRLF(text);
|
||||||
uiWindowsSetWindowText(e->hwnd, text);
|
uiWindowsSetWindowText(e->hwnd, text);
|
||||||
uiFree(crlf);
|
uiprivFree(crlf);
|
||||||
e->inhibitChanged = FALSE;
|
e->inhibitChanged = FALSE;
|
||||||
// don't queue the control for resize; entry sizes are independent of their contents
|
// 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);
|
SendMessageW(e->hwnd, EM_SETSEL, n, n);
|
||||||
crlf = LFtoCRLF(text);
|
crlf = LFtoCRLF(text);
|
||||||
wtext = toUTF16(crlf);
|
wtext = toUTF16(crlf);
|
||||||
uiFree(crlf);
|
uiprivFree(crlf);
|
||||||
SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext);
|
SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
e->inhibitChanged = FALSE;
|
e->inhibitChanged = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
||||||
BS_RADIOBUTTON | groupTabStop,
|
BS_RADIOBUTTON | groupTabStop,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
uiWindowsEnsureSetParentHWND(hwnd, r->hwnd);
|
uiWindowsEnsureSetParentHWND(hwnd, r->hwnd);
|
||||||
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
|
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
|
||||||
r->hwnds->push_back(hwnd);
|
r->hwnds->push_back(hwnd);
|
||||||
|
|
|
@ -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*.
|
// This won't handle leading spaces, but spaces aren't allowed *anyway*.
|
||||||
wtext = windowText(s->edit);
|
wtext = windowText(s->edit);
|
||||||
if (wcscmp(wtext, L"-") == 0) {
|
if (wcscmp(wtext, L"-") == 0) {
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
// value() does the work for us
|
// value() does the work for us
|
||||||
value(s);
|
value(s);
|
||||||
(*(s->onChanged))(s, s->onChangedData);
|
(*(s->onChanged))(s, s->onChangedData);
|
||||||
|
|
|
@ -114,8 +114,8 @@ static void msgbox(HWND parent, const char *title, const char *description, TASK
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT(L"error showing task dialog", hr);
|
logHRESULT(L"error showing task dialog", hr);
|
||||||
|
|
||||||
uiFree(wdescription);
|
uiprivFree(wdescription);
|
||||||
uiFree(wtitle);
|
uiprivFree(wtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiMsgBox(uiWindow *parent, const char *title, const char *description)
|
void uiMsgBox(uiWindow *parent, const char *title, const char *description)
|
||||||
|
|
|
@ -212,7 +212,7 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
|
||||||
item.pszText = wname;
|
item.pszText = wname;
|
||||||
if (SendMessageW(t->tabHWND, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
|
if (SendMessageW(t->tabHWND, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
|
||||||
logLastError(L"error adding tab to uiTab");
|
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
|
// we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page
|
||||||
show = curpage(t);
|
show = curpage(t);
|
||||||
|
|
|
@ -83,7 +83,7 @@ struct tabPage *newTabPage(uiControl *child)
|
||||||
struct tabPage *tp;
|
struct tabPage *tp;
|
||||||
HRESULT hr;
|
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
|
// unfortunately this needs to be a proper dialog for EnableThemeDialogTexture() to work; CreateWindowExW() won't suffice
|
||||||
if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog),
|
if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog),
|
||||||
|
@ -114,7 +114,7 @@ void tabPageDestroy(struct tabPage *tp)
|
||||||
uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL);
|
uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL);
|
||||||
// don't call EndDialog(); that's for the DialogBox() family of functions instead of CreateDialog()
|
// don't call EndDialog(); that's for the DialogBox() family of functions instead of CreateDialog()
|
||||||
uiWindowsEnsureDestroyWindow(tp->hwnd);
|
uiWindowsEnsureDestroyWindow(tp->hwnd);
|
||||||
uiFree(tp);
|
uiprivFree(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tabPageMinimumSize(struct tabPage *tp, int *width, int *height)
|
void tabPageMinimumSize(struct tabPage *tp, int *width, int *height)
|
||||||
|
|
|
@ -10,7 +10,7 @@ WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len)
|
||||||
if (len != NULL)
|
if (len != NULL)
|
||||||
*len = n;
|
*len = n;
|
||||||
// WM_GETTEXTLENGTH does not include the null terminator
|
// 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
|
// note the comparison: the size includes the null terminator, but the return does not
|
||||||
if (GetWindowTextW(hwnd, text, n + 1) != n) {
|
if (GetWindowTextW(hwnd, text, n + 1) != n) {
|
||||||
logLastError(L"error getting window text");
|
logLastError(L"error getting window text");
|
||||||
|
@ -35,7 +35,7 @@ void setWindowText(HWND hwnd, WCHAR *wtext)
|
||||||
|
|
||||||
void uiFreeText(char *text)
|
void uiFreeText(char *text)
|
||||||
{
|
{
|
||||||
uiFree(text);
|
uiprivFree(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uiWindowsWindowTextWidth(HWND hwnd)
|
int uiWindowsWindowTextWidth(HWND hwnd)
|
||||||
|
@ -78,11 +78,11 @@ int uiWindowsWindowTextWidth(HWND hwnd)
|
||||||
if (ReleaseDC(hwnd, dc) == 0)
|
if (ReleaseDC(hwnd, dc) == 0)
|
||||||
logLastError(L"error releasing DC");
|
logLastError(L"error releasing DC");
|
||||||
|
|
||||||
uiFree(text);
|
uiprivFree(text);
|
||||||
return size.cx;
|
return size.cx;
|
||||||
|
|
||||||
noTextOrError:
|
noTextOrError:
|
||||||
uiFree(text);
|
uiprivFree(text);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ char *uiWindowsWindowText(HWND hwnd)
|
||||||
|
|
||||||
wtext = windowText(hwnd);
|
wtext = windowText(hwnd);
|
||||||
text = toUTF8(wtext);
|
text = toUTF8(wtext);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ void uiWindowsSetWindowText(HWND hwnd, const char *text)
|
||||||
|
|
||||||
wtext = toUTF16(text);
|
wtext = toUTF16(text);
|
||||||
setWindowText(hwnd, wtext);
|
setWindowText(hwnd, wtext);
|
||||||
uiFree(wtext);
|
uiprivFree(wtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uiprivStricmp(const char *a, const char *b)
|
int uiprivStricmp(const char *a, const char *b)
|
||||||
|
@ -114,7 +114,7 @@ int uiprivStricmp(const char *a, const char *b)
|
||||||
wa = toUTF16(a);
|
wa = toUTF16(a);
|
||||||
wb = toUTF16(b);
|
wb = toUTF16(b);
|
||||||
ret = _wcsicmp(wa, wb);
|
ret = _wcsicmp(wa, wb);
|
||||||
uiFree(wb);
|
uiprivFree(wb);
|
||||||
uiFree(wa);
|
uiprivFree(wa);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ extern BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult);
|
||||||
extern void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam);
|
extern void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
// utf16.cpp
|
// utf16.cpp
|
||||||
#define emptyUTF16() ((WCHAR *) uiAlloc(1 * sizeof (WCHAR), "WCHAR[]"))
|
#define emptyUTF16() ((WCHAR *) uiprivAlloc(1 * sizeof (WCHAR), "WCHAR[]"))
|
||||||
#define emptyUTF8() ((char *) uiAlloc(1 * sizeof (char), "char[]"))
|
#define emptyUTF8() ((char *) uiprivAlloc(1 * sizeof (char), "char[]"))
|
||||||
extern WCHAR *toUTF16(const char *str);
|
extern WCHAR *toUTF16(const char *str);
|
||||||
extern char *toUTF8(const WCHAR *wstr);
|
extern char *toUTF8(const WCHAR *wstr);
|
||||||
extern WCHAR *utf16dup(const WCHAR *orig);
|
extern WCHAR *utf16dup(const WCHAR *orig);
|
||||||
|
|
|
@ -13,7 +13,7 @@ WCHAR *toUTF16(const char *str)
|
||||||
if (*str == '\0') // empty string
|
if (*str == '\0') // empty string
|
||||||
return emptyUTF16();
|
return emptyUTF16();
|
||||||
n = utf8UTF16Count(str, 0);
|
n = utf8UTF16Count(str, 0);
|
||||||
wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
|
wstr = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
|
||||||
wp = wstr;
|
wp = wstr;
|
||||||
while (*str) {
|
while (*str) {
|
||||||
str = utf8DecodeRune(str, 0, &rune);
|
str = utf8DecodeRune(str, 0, &rune);
|
||||||
|
@ -33,7 +33,7 @@ char *toUTF8(const WCHAR *wstr)
|
||||||
if (*wstr == L'\0') // empty string
|
if (*wstr == L'\0') // empty string
|
||||||
return emptyUTF8();
|
return emptyUTF8();
|
||||||
n = utf16RuneCount(wstr, 0);
|
n = utf16RuneCount(wstr, 0);
|
||||||
str = (char *) uiAlloc((n + 1) * sizeof (char), "char[]");
|
str = (char *) uiprivAlloc((n + 1) * sizeof (char), "char[]");
|
||||||
sp = str;
|
sp = str;
|
||||||
while (*wstr) {
|
while (*wstr) {
|
||||||
wstr = utf16DecodeRune(wstr, 0, &rune);
|
wstr = utf16DecodeRune(wstr, 0, &rune);
|
||||||
|
@ -49,7 +49,7 @@ WCHAR *utf16dup(const WCHAR *orig)
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = wcslen(orig);
|
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);
|
wcscpy_s(out, len + 1, orig);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ WCHAR *vstrf(const WCHAR *format, va_list ap)
|
||||||
va_end(ap2);
|
va_end(ap2);
|
||||||
n++; // terminating L'\0'
|
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
|
// includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
|
||||||
vswprintf_s(buf, n, format, ap);
|
vswprintf_s(buf, n, format, ap);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ char *LFtoCRLF(const char *lfonly)
|
||||||
char *out;
|
char *out;
|
||||||
|
|
||||||
len = strlen(lfonly);
|
len = strlen(lfonly);
|
||||||
crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]");
|
crlf = (char *) uiprivAlloc((len * 2 + 1) * sizeof (char), "char[]");
|
||||||
out = crlf;
|
out = crlf;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (*lfonly == '\n')
|
if (*lfonly == '\n')
|
||||||
|
|
|
@ -480,7 +480,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
NULL, NULL, hInstance, w);
|
NULL, NULL, hInstance, w);
|
||||||
if (w->hwnd == NULL)
|
if (w->hwnd == NULL)
|
||||||
logLastError(L"error creating window");
|
logLastError(L"error creating window");
|
||||||
uiFree(wtitle);
|
uiprivFree(wtitle);
|
||||||
|
|
||||||
if (hasMenubar) {
|
if (hasMenubar) {
|
||||||
w->menubar = makeMenubar();
|
w->menubar = makeMenubar();
|
||||||
|
|
Loading…
Reference in New Issue