Settled the placement of functions formerly in sizing_windows.c and updated the winapi_windows.h header file to suit.
This commit is contained in:
parent
5198f7202f
commit
b4a97e871a
|
@ -3,64 +3,6 @@
|
|||
#include "winapi_windows.h"
|
||||
#include "_cgo_export.h"
|
||||
|
||||
HWND newControl(LPWSTR class, DWORD style, DWORD extstyle)
|
||||
{
|
||||
HWND hwnd;
|
||||
|
||||
hwnd = CreateWindowExW(
|
||||
extstyle,
|
||||
class, L"",
|
||||
style | WS_CHILD | WS_VISIBLE,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
/*
|
||||
the following has the consequence of making the control message-only at first
|
||||
this shouldn't cause any problems... hopefully not
|
||||
but see the msgwndproc() for caveat info
|
||||
also don't use low control IDs as they will conflict with dialog boxes (IDCANCEL, etc.)
|
||||
*/
|
||||
msgwin, (HMENU) 100, hInstance, NULL);
|
||||
if (hwnd == NULL)
|
||||
xpanic("error creating control", GetLastError());
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
void controlSetParent(HWND control, HWND parent)
|
||||
{
|
||||
if (SetParent(control, parent) == NULL)
|
||||
xpanic("error changing control parent", GetLastError());
|
||||
}
|
||||
|
||||
void controlSetControlFont(HWND which)
|
||||
{
|
||||
SendMessageW(which, WM_SETFONT, (WPARAM) controlFont, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
all controls that have events receive the events themselves through subclasses
|
||||
to do this, all windows (including the message-only window; see http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q104069) forward WM_COMMAND to each control with this function
|
||||
*/
|
||||
LRESULT forwardCommand(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
HWND control = (HWND) lParam;
|
||||
|
||||
/* don't generate an event if the control (if there is one) is unparented (a child of the message-only window) */
|
||||
if (control != NULL && IsChild(msgwin, control) == 0)
|
||||
return SendMessageW(control, msgCOMMAND, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
LRESULT forwardNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
NMHDR *nmhdr = (NMHDR *) lParam;
|
||||
HWND control = nmhdr->hwndFrom;
|
||||
|
||||
/* don't generate an event if the control (if there is one) is unparented (a child of the message-only window) */
|
||||
if (control != NULL && IsChild(msgwin, control) == 0)
|
||||
return SendMessageW(control, msgNOTIFY, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK buttonSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
||||
{
|
||||
switch (uMsg) {
|
||||
|
|
|
@ -82,3 +82,26 @@ HWND newContainer(void *data)
|
|||
xpanic("container creation failed", GetLastError());
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY, LONG *internalLeading)
|
||||
{
|
||||
HDC dc;
|
||||
HFONT prevFont;
|
||||
TEXTMETRICW tm;
|
||||
|
||||
dc = GetDC(hwnd);
|
||||
if (dc == NULL)
|
||||
xpanic("error getting DC for preferred size calculations", GetLastError());
|
||||
prevFont = (HFONT) SelectObject(dc, controlFont);
|
||||
if (prevFont == NULL)
|
||||
xpanic("error loading control font into device context for preferred size calculation", GetLastError());
|
||||
if (GetTextMetricsW(dc, &tm) == 0)
|
||||
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
||||
*baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
|
||||
*baseY = (int) tm.tmHeight;
|
||||
*internalLeading = tm.tmInternalLeading;
|
||||
if (SelectObject(dc, prevFont) != controlFont)
|
||||
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
|
||||
if (ReleaseDC(hwnd, dc) == 0)
|
||||
xpanic("error releasing DC for preferred size calculations", GetLastError());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/* 17 july 2014 */
|
||||
|
||||
#include "winapi_windows.h"
|
||||
#include "_cgo_export.h"
|
||||
|
||||
HWND newControl(LPWSTR class, DWORD style, DWORD extstyle)
|
||||
{
|
||||
HWND hwnd;
|
||||
|
||||
hwnd = CreateWindowExW(
|
||||
extstyle,
|
||||
class, L"",
|
||||
style | WS_CHILD | WS_VISIBLE,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
/*
|
||||
the following has the consequence of making the control message-only at first
|
||||
this shouldn't cause any problems... hopefully not
|
||||
but see the msgwndproc() for caveat info
|
||||
also don't use low control IDs as they will conflict with dialog boxes (IDCANCEL, etc.)
|
||||
*/
|
||||
msgwin, (HMENU) 100, hInstance, NULL);
|
||||
if (hwnd == NULL)
|
||||
xpanic("error creating control", GetLastError());
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
void controlSetParent(HWND control, HWND parent)
|
||||
{
|
||||
if (SetParent(control, parent) == NULL)
|
||||
xpanic("error changing control parent", GetLastError());
|
||||
}
|
||||
|
||||
void controlSetControlFont(HWND which)
|
||||
{
|
||||
SendMessageW(which, WM_SETFONT, (WPARAM) controlFont, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
all controls that have events receive the events themselves through subclasses
|
||||
to do this, all windows (including the message-only window; see http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q104069) forward WM_COMMAND to each control with this function
|
||||
*/
|
||||
LRESULT forwardCommand(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
HWND control = (HWND) lParam;
|
||||
|
||||
/* don't generate an event if the control (if there is one) is unparented (a child of the message-only window) */
|
||||
if (control != NULL && IsChild(msgwin, control) == 0)
|
||||
return SendMessageW(control, msgCOMMAND, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
LRESULT forwardNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
NMHDR *nmhdr = (NMHDR *) lParam;
|
||||
HWND control = nmhdr->hwndFrom;
|
||||
|
||||
/* don't generate an event if the control (if there is one) is unparented (a child of the message-only window) */
|
||||
if (control != NULL && IsChild(msgwin, control) == 0)
|
||||
return SendMessageW(control, msgNOTIFY, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
void moveWindow(HWND hwnd, int x, int y, int width, int height)
|
||||
{
|
||||
if (MoveWindow(hwnd, x, y, width, height, TRUE) == 0)
|
||||
xpanic("error setting window/control rect", GetLastError());
|
||||
}
|
||||
|
||||
LONG controlTextLength(HWND hwnd, LPWSTR text)
|
||||
{
|
||||
HDC dc;
|
||||
HFONT prev;
|
||||
SIZE size;
|
||||
|
||||
dc = GetDC(hwnd);
|
||||
if (dc == NULL)
|
||||
xpanic("error getting DC of control for text length", GetLastError());
|
||||
prev = SelectObject(dc, controlFont);
|
||||
if (prev == NULL)
|
||||
xpanic("error setting control font to DC for text length", GetLastError());
|
||||
if (GetTextExtentPoint32W(dc, text, wcslen(text), &size) == 0)
|
||||
xpanic("error actually getting text length", GetLastError());
|
||||
if (SelectObject(dc, prev) != controlFont)
|
||||
xpanic("error restoring previous control font to DC for text length", GetLastError());
|
||||
if (ReleaseDC(hwnd, dc) == 0)
|
||||
xpanic("error releasing DC of control for text length", GetLastError());
|
||||
return size.cx;
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/* 17 july 2014 */
|
||||
|
||||
#include "winapi_windows.h"
|
||||
#include "_cgo_export.h"
|
||||
|
||||
/* TODO figure out where these should go */
|
||||
|
||||
void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY, LONG *internalLeading)
|
||||
{
|
||||
HDC dc;
|
||||
HFONT prevFont;
|
||||
TEXTMETRICW tm;
|
||||
|
||||
dc = GetDC(hwnd);
|
||||
if (dc == NULL)
|
||||
xpanic("error getting DC for preferred size calculations", GetLastError());
|
||||
prevFont = (HFONT) SelectObject(dc, controlFont);
|
||||
if (prevFont == NULL)
|
||||
xpanic("error loading control font into device context for preferred size calculation", GetLastError());
|
||||
if (GetTextMetricsW(dc, &tm) == 0)
|
||||
xpanic("error getting text metrics for preferred size calculations", GetLastError());
|
||||
*baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */
|
||||
*baseY = (int) tm.tmHeight;
|
||||
*internalLeading = tm.tmInternalLeading;
|
||||
if (SelectObject(dc, prevFont) != controlFont)
|
||||
xpanic("error restoring previous font into device context after preferred size calculations", GetLastError());
|
||||
if (ReleaseDC(hwnd, dc) == 0)
|
||||
xpanic("error releasing DC for preferred size calculations", GetLastError());
|
||||
}
|
||||
|
||||
void moveWindow(HWND hwnd, int x, int y, int width, int height)
|
||||
{
|
||||
if (MoveWindow(hwnd, x, y, width, height, TRUE) == 0)
|
||||
xpanic("error setting window/control rect", GetLastError());
|
||||
}
|
||||
|
||||
LONG controlTextLength(HWND hwnd, LPWSTR text)
|
||||
{
|
||||
HDC dc;
|
||||
HFONT prev;
|
||||
SIZE size;
|
||||
|
||||
dc = GetDC(hwnd);
|
||||
if (dc == NULL)
|
||||
xpanic("error getting DC of control for text length", GetLastError());
|
||||
prev = SelectObject(dc, controlFont);
|
||||
if (prev == NULL)
|
||||
xpanic("error setting control font to DC for text length", GetLastError());
|
||||
if (GetTextExtentPoint32W(dc, text, wcslen(text), &size) == 0)
|
||||
xpanic("error actually getting text length", GetLastError());
|
||||
if (SelectObject(dc, prev) != controlFont)
|
||||
xpanic("error restoring previous control font to DC for text length", GetLastError());
|
||||
if (ReleaseDC(hwnd, dc) == 0)
|
||||
xpanic("error releasing DC of control for text length", GetLastError());
|
||||
return size.cx;
|
||||
}
|
|
@ -44,12 +44,16 @@ extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_P
|
|||
extern BOOL (*WINAPI fv_RemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR);
|
||||
extern LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
/* [TODO rename] controls_windows.c */
|
||||
/* control_windows.c */
|
||||
extern HWND newControl(LPWSTR, DWORD, DWORD);
|
||||
extern void controlSetParent(HWND, HWND);
|
||||
extern void controlSetControlFont(HWND);
|
||||
extern LRESULT forwardCommand(HWND, UINT, WPARAM, LPARAM);
|
||||
extern LRESULT forwardNotify(HWND, UINT, WPARAM, LPARAM);
|
||||
extern void moveWindow(HWND, int, int, int, int);
|
||||
extern LONG controlTextLength(HWND, LPWSTR);
|
||||
|
||||
/* basicctrls_windows.c */
|
||||
extern void setButtonSubclass(HWND, void *);
|
||||
extern void setCheckboxSubclass(HWND, void *);
|
||||
extern BOOL checkboxChecked(HWND);
|
||||
|
@ -68,11 +72,6 @@ extern HFONT statusbarFont;
|
|||
extern HBRUSH hollowBrush;
|
||||
extern DWORD initWindows(char **);
|
||||
|
||||
/* sizing_windows.c */
|
||||
extern void calculateBaseUnits(HWND, int *, int *, LONG *);
|
||||
extern void moveWindow(HWND, int, int, int, int);
|
||||
extern LONG controlTextLength(HWND, LPWSTR);
|
||||
|
||||
/* window_windows.c */
|
||||
extern DWORD makeWindowWindowClass(char **);
|
||||
extern HWND newWindow(LPWSTR, int, int, void *);
|
||||
|
@ -85,7 +84,7 @@ extern void setWindowText(HWND, LPWSTR);
|
|||
extern void updateWindow(HWND);
|
||||
extern void storelpParam(HWND, LPARAM);
|
||||
|
||||
/* containers_windows.go */
|
||||
/* tab_windows.go */
|
||||
extern LPWSTR xWC_TABCONTROL;
|
||||
extern void setTabSubclass(HWND, void *);
|
||||
extern void tabAppend(HWND, LPWSTR);
|
||||
|
@ -102,6 +101,7 @@ extern void tableAddExtendedStyles(HWND, LPARAM);
|
|||
/* container_windows.c */
|
||||
extern DWORD makeContainerWindowClass(char **);
|
||||
extern HWND newContainer(void *);
|
||||
extern void calculateBaseUnits(HWND, int *, int *, LONG *);
|
||||
|
||||
/* area_window.c */
|
||||
extern void repaintArea(HWND);
|
||||
|
|
Loading…
Reference in New Issue