forked from AppleWin/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUilib.cpp
More file actions
134 lines (115 loc) · 3.77 KB
/
Copy pathUilib.cpp
File metadata and controls
134 lines (115 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* uilib.c - Common UI elements for the Windows user interface.
*
* Written by
* Ettore Perazzoli <ettore@comm2000.it>
* Andreas Boose <viceteam@t-online.de>
* Manfred Spraul <manfreds@colorfullife.com>
* Andreas Matthies <andreas.matthies@gmx.net>
* Tibor Biczo <crown@mail.matav.hu>
*
* This file is part of VICE, the Versatile Commodore Emulator.
* See README for copyright notice.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA.
*
*/
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include <commctrl.h>
#include <commdlg.h>
#include "uilib.h"
/* Mingw & pre VC 6 headers doesn't have this definition */
#ifndef OFN_ENABLESIZING
#define OFN_ENABLESIZING 0x00800000
#endif
void uilib_get_general_window_extents(HWND hwnd, int *xsize, int *ysize)
{
HDC hdc;
HFONT hFont;
HFONT hOldFont;
int strlen;
char *buffer;
SIZE size;
hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
strlen = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);
/* RGJ added cast for AppleWin */
buffer = (char *) malloc(strlen + 1);
if (buffer == NULL) // TC: add null check for AppleWin
{
*xsize = 0;
*ysize = 0;
return;
}
GetWindowText(hwnd, buffer, strlen + 1);
hdc = GetDC(hwnd);
hOldFont = (HFONT)SelectObject(hdc, hFont);
GetTextExtentPoint32(hdc, buffer, strlen, &size);
free(buffer);
SelectObject(hdc, hOldFont);
ReleaseDC(hwnd, hdc);
*xsize = size.cx;
*ysize = size.cy;
}
void uilib_get_group_extent(HWND hwnd, uilib_dialog_group *group, int *xsize, int *ysize)
{
HWND element;
int x;
int y;
if (xsize && ysize) {
*xsize = 0;
*ysize = 0;
while (group->idc) {
element = GetDlgItem(hwnd, group->idc);
uilib_get_general_window_extents(element, &x, &y);
if (group->element_type == 1) x += 20;
if (*xsize < x) *xsize = x;
*ysize += y;
group++;
}
}
}
void uilib_move_group(HWND hwnd, uilib_dialog_group *group, int xpos)
{
HWND element;
RECT element_rect;
while (group->idc) {
element = GetDlgItem(hwnd, group->idc);
GetClientRect(element, &element_rect);
MapWindowPoints(element, hwnd, (POINT*)&element_rect, 2);
MoveWindow(element, xpos, element_rect.top, element_rect.right - element_rect.left, element_rect.bottom - element_rect.top, TRUE);
group++;
}
}
void uilib_adjust_group_width(HWND hwnd, uilib_dialog_group *group)
{
HWND element;
RECT element_rect;
int xsize;
int ysize;
while (group->idc) {
element = GetDlgItem(hwnd, group->idc);
GetClientRect(element, &element_rect);
MapWindowPoints(element, hwnd, (POINT*)&element_rect, 2);
uilib_get_general_window_extents(element, &xsize, &ysize);
if (group->element_type == 1) xsize += 20;
MoveWindow(element, element_rect.left, element_rect.top, xsize, element_rect.bottom - element_rect.top, TRUE);
group++;
}
}