Taking a short break.
[SquirrelJME.git] / nanocoat / lib / scritchui / win32 / win32ScrollPanel.c
blob40085e2de3cde9c2d3effb88fc66be28286e8a12
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include "lib/scritchui/scritchuiTypes.h"
11 #include "lib/scritchui/win32/win32.h"
12 #include "lib/scritchui/win32/win32Intern.h"
14 sjme_errorCode sjme_scritchui_win32_scrollPanelNew(
15 sjme_attrInNotNull sjme_scritchui inState,
16 sjme_attrInNotNull sjme_scritchui_uiScrollPanel inScrollPanel,
17 sjme_attrInNullable sjme_pointer ignored)
19 HWND window;
20 WNDCLASSEX windowClass;
21 ATOM classAtom;
23 if (inState == NULL || inScrollPanel == NULL)
24 return SJME_ERROR_NULL_ARGUMENTS;
26 /* Register window class for this window. */
27 memset(&windowClass, 0, sizeof(windowClass));
28 windowClass.cbSize = sizeof(windowClass);
29 windowClass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
30 windowClass.hInstance = GetModuleHandle(NULL);
31 windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
32 windowClass.lpszClassName = inScrollPanel->component.strId;
33 windowClass.lpfnWndProc = inState->implIntern->windowProcWin32;
34 SetLastError(0);
35 classAtom = RegisterClassEx(&windowClass);
36 if (classAtom == 0)
37 return inState->implIntern->getLastError(inState,
38 SJME_ERROR_NATIVE_WIDGET_FAILURE);
40 /* Create window, child windows must always have a parent. */
41 SetLastError(0);
42 window = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_RIGHTSCROLLBAR |
43 WS_EX_COMPOSITED,
44 inScrollPanel->component.strId,
45 "SquirrelJME",
46 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
47 WS_HSCROLL | WS_VSCROLL,
48 CW_USEDEFAULT, CW_USEDEFAULT,
49 CW_USEDEFAULT, CW_USEDEFAULT,
50 inState->common.handle[SJME_SUI_WIN32_H_VOID],
51 NULL,
52 GetModuleHandle(NULL),
53 NULL);
54 if (window == NULL)
55 return inState->implIntern->getLastError(inState,
56 SJME_ERROR_NATIVE_WIDGET_CREATE_FAILED);
58 /* Store handle. */
59 inScrollPanel->component.common.handle[SJME_SUI_WIN32_H_HWND] = window;
60 inScrollPanel->component.common.handle[SJME_SUI_WIN32_H_HWNDATOM] =
61 (sjme_scritchui_handle)classAtom;
63 /* Link back to this panel. */
64 SetLastError(0);
65 SetWindowLongPtr(window, GWLP_USERDATA,
66 (LONG_PTR)inScrollPanel);
68 /* Success? */
69 return inState->implIntern->getLastError(inState, SJME_ERROR_NONE);