diff --git a/windows/comctl32.c b/windows/comctl32.c deleted file mode 100644 index 93b3a271..00000000 --- a/windows/comctl32.c +++ /dev/null @@ -1,105 +0,0 @@ -// 17 july 2014 -#include "uipriv_windows.h" - -static ULONG_PTR comctlManifestCookie; -static HMODULE comctl32; - -// these are listed as WINAPI in both Microsoft's and MinGW's headers, but not on MSDN for some reason -BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR); -BOOL (*WINAPI fv_RemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR); -LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM); - -#define wantedICCClasses ( \ - ICC_STANDARD_CLASSES | /* user32.dll controls */ \ - ICC_PROGRESS_CLASS | /* progress bars */ \ - ICC_TAB_CLASSES | /* tabs */ \ - ICC_LISTVIEW_CLASSES | /* table headers */ \ - ICC_UPDOWN_CLASS | /* spinboxes */ \ - 0) - -// note that this is an 8-bit character string we're writing; see the encoding clause -static const char manifest[] = "\n\n\nYour application description here.\n\n \n \n \n\n\n"; - -/* -Windows requires a manifest file to enable Common Controls version 6. -The only way to not require an external manifest is to synthesize the manifest ourselves. -We can use the activation context API to load it at runtime. -References: -- http://stackoverflow.com/questions/4308503/how-to-enable-visual-styles-without-a-manifest -- http://support.microsoft.com/kb/830033 -Because neither Go nor MinGW have ways to compile in resources like this (as far as I know), we have to do the work ourselves. -*/ -const char *initCommonControls(void) -{ - WCHAR temppath[MAX_PATH + 1]; - WCHAR filename[MAX_PATH + 1]; - HANDLE file; - DWORD nExpected, nGot; - ACTCTX actctx; - HANDLE ac; - INITCOMMONCONTROLSEX icc; - FARPROC f; - // this is listed as WINAPI in both Microsoft's and MinGW's headers, but not on MSDN for some reason - BOOL (*WINAPI ficc)(const LPINITCOMMONCONTROLSEX); - - if (GetTempPathW(MAX_PATH + 1, temppath) == 0) - 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 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 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 in initCommonControls()"; - if (nGot != nExpected) { - DWORD lasterr; - - lasterr = GetLastError(); - if (lasterr == 0) - 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) in initCommonControls()"; - - ZeroMemory(&actctx, sizeof (ACTCTX)); - actctx.cbSize = sizeof (ACTCTX); - actctx.dwFlags = ACTCTX_FLAG_SET_PROCESS_DEFAULT; - actctx.lpSource = filename; - ac = CreateActCtx(&actctx); - if (ac == INVALID_HANDLE_VALUE) - return "creating activation context for synthesized manifest file in initCommonControls()"; - if (ActivateActCtx(ac, &comctlManifestCookie) == FALSE) - return "activating activation context for synthesized manifest file in initCommonControls()"; - - ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); - icc.dwSize = sizeof (INITCOMMONCONTROLSEX); - icc.dwICC = wantedICCClasses; - - comctl32 = LoadLibraryW(L"comctl32.dll"); - if (comctl32 == NULL) - 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 "() in initCommonControls()"; - - LOAD("InitCommonControlsEx"); - ficc = (BOOL (*WINAPI)(const LPINITCOMMONCONTROLSEX)) f; - LOAD("SetWindowSubclass"); - fv_SetWindowSubclass = (BOOL (*WINAPI)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR)) f; - LOAD("RemoveWindowSubclass"); - fv_RemoveWindowSubclass = (BOOL (*WINAPI)(HWND, SUBCLASSPROC, UINT_PTR)) f; - LOAD("DefSubclassProc"); - fv_DefSubclassProc = (LRESULT (*WINAPI)(HWND, UINT, WPARAM, LPARAM)) f; - - if ((*ficc)(&icc) == FALSE) - return "initializing Common Controls (comctl32.dll) in initCommonControls()"; - - return NULL; -} diff --git a/windows/newcontrol.c b/windows/newcontrol.c deleted file mode 100644 index 1b4c19f1..00000000 --- a/windows/newcontrol.c +++ /dev/null @@ -1,209 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.h" - -struct singleHWND { - HWND hwnd; - BOOL (*onWM_COMMAND)(uiControl *, WORD, LRESULT *); - BOOL (*onWM_NOTIFY)(uiControl *, NMHDR *, LRESULT *); - void (*onDestroy)(void *); - void *onDestroyData; - uiContainer *parent; - int hidden; - int userDisabled; - int containerDisabled; -}; - -static void singleDestroy(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - if (s->parent != NULL) - complain("attempt to destroy a uiControl at %p while it still has a parent", c); - (*(s->onDestroy))(s->onDestroyData); - if (DestroyWindow(s->hwnd) == 0) - logLastError("error destroying control in singleDestroy()"); - uiFree(s); -} - -static uintptr_t singleHandle(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - return (uintptr_t) (s->hwnd); -} - -static void singleSetParent(uiControl *c, uiContainer *parent) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - uiContainer *oldparent; - HWND newParentHWND; - - oldparent = s->parent; - s->parent = parent; - newParentHWND = initialParent; - if (s->parent != NULL) - newParentHWND = (HWND) uiControlHandle(uiControl(s->parent)); - if (SetParent(s->hwnd, newParentHWND) == NULL) - logLastError("error setting control parent in singleSetParent()"); -} - -static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - moveAndReorderWindow(s->hwnd, d->Sys->InsertAfter, x, y, width, height); - d->Sys->InsertAfter = s->hwnd; -} - -static int singleVisible(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - return !s->hidden; -} - -static void singleShow(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - ShowWindow(s->hwnd, SW_SHOW); - s->hidden = 0; - if (s->parent != NULL) - uiContainerUpdate(s->parent); -} - -static void singleHide(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - ShowWindow(s->hwnd, SW_HIDE); - s->hidden = 1; - if (s->parent != NULL) - uiContainerUpdate(s->parent); -} - -static void singleEnable(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - s->userDisabled = 0; - if (!s->containerDisabled) - EnableWindow(s->hwnd, TRUE); -} - -static void singleDisable(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - s->userDisabled = 1; - EnableWindow(s->hwnd, FALSE); -} - -static void singleSysFunc(uiControl *c, uiControlSysFuncParams *p) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - - switch (p->Func) { - case uiWindowsSysFuncContainerEnable: - s->containerDisabled = 0; - if (!s->userDisabled) - EnableWindow(s->hwnd, TRUE); - return; - case uiWindowsSysFuncContainerDisable: - s->containerDisabled = 1; - EnableWindow(s->hwnd, FALSE); - return; - case uiWindowsSysFuncHasTabStops: - if (IsWindowEnabled(s->hwnd) != 0) - if ((getStyle(s->hwnd) & WS_TABSTOP) != 0) - p->HasTabStops = TRUE; - return; - } - complain("unknown p->Func %d in singleSysFunc()", p->Func); -} - -static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - uiControl *c = (uiControl *) dwRefData; - struct singleHWND *s = (struct singleHWND *) (c->Internal); - LRESULT lResult; - - switch (uMsg) { - case msgCOMMAND: - if ((*(s->onWM_COMMAND))(c, HIWORD(wParam), &lResult) != FALSE) - return lResult; - break; - case msgNOTIFY: - if ((*(s->onWM_NOTIFY))(c, (NMHDR *) lParam, &lResult) != FALSE) - return lResult; - break; - case WM_NCDESTROY: - if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE) - logLastError("error removing Windows control subclass in singleSubclassProc()"); - break; - } - return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); -} - -void uiWindowsMakeControl(uiControl *c, uiWindowsMakeControlParams *p) -{ - struct singleHWND *s; - - s = uiNew(struct singleHWND); - s->hwnd = CreateWindowExW(p->dwExStyle, - p->lpClassName, p->lpWindowName, - p->dwStyle | WS_CHILD | WS_VISIBLE, - 0, 0, - // use a nonzero initial size just in case some control breaks with a zero initial size - 100, 100, - initialParent, NULL, p->hInstance, NULL); - if (s->hwnd == NULL) - logLastError("error creating control in uiWindowsMakeControl()"); - s->onWM_COMMAND = p->onWM_COMMAND; - s->onWM_NOTIFY = p->onWM_NOTIFY; - - s->onDestroy = p->onDestroy; - s->onDestroyData = p->onDestroyData; - - if (p->useStandardControlFont) - SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); - - // this handles redirected notification messages - if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE) - logLastError("error subclassing Windows control in uiWindowsMakeControl()"); - - uiControl(c)->Internal = s; - uiControl(c)->Destroy = singleDestroy; - uiControl(c)->Handle = singleHandle; - uiControl(c)->SetParent = singleSetParent; - uiControl(c)->Resize = singleResize; - uiControl(c)->Visible = singleVisible; - uiControl(c)->Show = singleShow; - uiControl(c)->Hide = singleHide; - uiControl(c)->Enable = singleEnable; - uiControl(c)->Disable = singleDisable; - uiControl(c)->SysFunc = singleSysFunc; -} - -char *uiWindowsControlText(uiControl *c) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - WCHAR *wtext; - char *text; - - wtext = windowText(s->hwnd); - text = toUTF8(wtext); - uiFree(wtext); - return text; -} - -void uiWindowsControlSetText(uiControl *c, const char *text) -{ - struct singleHWND *s = (struct singleHWND *) (c->Internal); - WCHAR *wtext; - - wtext = toUTF16(text); - if (SetWindowTextW(s->hwnd, wtext) == 0) - logLastError("error setting control text in uiWindowsControlSetText()"); - uiFree(wtext); -}