More TODO resolving. More TODOs.

This commit is contained in:
Pietro Gagliardi 2015-04-08 17:06:23 -04:00
parent a97c9297c3
commit ec070204a5
3 changed files with 31 additions and 23 deletions

View File

@ -43,29 +43,28 @@ const char *initCommonControls(void)
BOOL (*WINAPI ficc)(const LPINITCOMMONCONTROLSEX);
if (GetTempPathW(MAX_PATH + 1, temppath) == 0)
return "getting temporary path for writing manifest file";
return "getting temporary path for writing manifest file in initCommonControls()";
if (GetTempFileNameW(temppath, L"manifest", 0, filename) == 0)
return "getting temporary filename for writing manifest file";
return "getting temporary filename for writing manifest file in initCommonControls()";
file = CreateFileW(filename, GENERIC_WRITE,
0, // don't share while writing
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == NULL)
return "creating manifest file";
return "creating manifest file in initCommonControls()";
nExpected = (sizeof manifest / sizeof manifest[0]) - 1; // - 1 to omit the terminating null character)
SetLastError(0); // catch errorless short writes
if (WriteFile(file, manifest, nExpected, &nGot, NULL) == 0)
return "writing manifest file";
return "writing manifest file in initCommonControls()";
if (nGot != nExpected) {
DWORD lasterr;
lasterr = GetLastError();
// TODO reword these
if (lasterr == 0)
return "short write to manifest file without error code";
return "short write to manifest file";
return "writing entire manifest file (short write) without error code in initCommonControls()";
return "writing entire manifest file (short write) in initCommonControls()";
}
if (CloseHandle(file) == 0)
return "closing manifest file (this IS an error here because not doing so will prevent Windows from being able to use the manifest file in an activation context)";
return "closing manifest file (this IS an error here because not doing so will prevent Windows from being able to use the manifest file in an activation context) in initCommonControls()";
ZeroMemory(&actctx, sizeof (ACTCTX));
actctx.cbSize = sizeof (ACTCTX);
@ -73,9 +72,9 @@ const char *initCommonControls(void)
actctx.lpSource = filename;
ac = CreateActCtx(&actctx);
if (ac == INVALID_HANDLE_VALUE)
return "creating activation context for synthesized manifest file";
return "creating activation context for synthesized manifest file in initCommonControls()";
if (ActivateActCtx(ac, &comctlManifestCookie) == FALSE)
return "activating activation context for synthesized manifest file";
return "activating activation context for synthesized manifest file in initCommonControls()";
ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX));
icc.dwSize = sizeof (INITCOMMONCONTROLSEX);
@ -83,12 +82,12 @@ const char *initCommonControls(void)
comctl32 = LoadLibraryW(L"comctl32.dll");
if (comctl32 == NULL)
return "loading comctl32.dll";
return "loading comctl32.dll in initCommonControls()";
// GetProcAddress() only takes a multibyte string
#define LOAD(fn) f = GetProcAddress(comctl32, fn); \
if (f == NULL) \
return "loading " fn "()";
return "loading " fn "() in initCommonControls()";
LOAD("InitCommonControlsEx");
ficc = (BOOL (*WINAPI)(const LPINITCOMMONCONTROLSEX)) f;
@ -100,7 +99,7 @@ const char *initCommonControls(void)
fv_DefSubclassProc = (LRESULT (*WINAPI)(HWND, UINT, WPARAM, LPARAM)) f;
if ((*ficc)(&icc) == FALSE)
return "initializing Common Controls (comctl32.dll)";
return "initializing Common Controls (comctl32.dll) in initCommonControls()";
return NULL;
}

View File

@ -12,18 +12,25 @@ static void uiContainer_init(uiContainer *c)
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
}
// TODO explain the order here
// TODO guard against use of forall after the ptr array unref
// instead of having GtkContainer itself unref all our controls, we'll run our own uiControlDestroy() functions for child, which will do that and more
// we still chain up because we need to, but by that point there will be no children for GtkContainer to free
static void uiContainer_dispose(GObject *obj)
{
g_ptr_array_unref(uiContainer(obj)->children);
if (uiContainer(obj)->child != NULL) {
uiControlDestroy(uiContainer(obj)->child);
uiContainer(obj)->child = NULL;
uiContainer *c = uiContainer(obj);
if (c->children != NULL) {
g_ptr_array_unref(c->children);
c->children = NULL;
}
if (c->child != NULL) {
uiControlDestroy(c->child);
c->child = NULL;
}
G_OBJECT_CLASS(uiContainer_parent_class)->dispose(obj);
}
// TODO switch from using uiContainer() directly below
static void uiContainer_finalize(GObject *obj)
{
G_OBJECT_CLASS(uiContainer_parent_class)->finalize(obj);
@ -35,13 +42,15 @@ static void uiContainer_finalize(GObject *obj)
static void uiContainer_add(GtkContainer *container, GtkWidget *widget)
{
gtk_widget_set_parent(widget, GTK_WIDGET(container));
g_ptr_array_add(uiContainer(container)->children, widget);
if (uiContainer(container)->children != NULL)
g_ptr_array_add(uiContainer(container)->children, widget);
}
static void uiContainer_remove(GtkContainer *container, GtkWidget *widget)
{
gtk_widget_unparent(widget);
g_ptr_array_remove(uiContainer(container)->children, widget);
if (uiContainer(container)->children != NULL)
g_ptr_array_remove(uiContainer(container)->children, widget);
}
static void uiContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
@ -73,7 +82,8 @@ static void uiContainer_forall(GtkContainer *container, gboolean includeInternal
s.callback = callback;
s.data = data;
g_ptr_array_foreach(uiContainer(container)->children, doforall, &s);
if (uiContainer(container)->children != NULL)
g_ptr_array_foreach(uiContainer(container)->children, doforall, &s);
}
static void uiContainer_class_init(uiContainerClass *class)

View File

@ -45,7 +45,6 @@ uiInitError *uiInit(uiInitOptions *o)
if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
nCmdShow = si.wShowWindow;
// TODO add "in initCommonControls()" to each of the messages this returns
ce = initCommonControls();
if (ce != NULL)
return loadLastError(err, ce);