├── .gitignore
├── README.md
├── bin
├── .gitignore
└── common.ini
├── common.sln
├── pro
├── .gitignore
├── common.vcxproj
└── common.vcxproj.filters
├── qrcode.jpg
├── res
├── .gitignore
├── 100.ico
├── common.rc
├── main_orig.xml
├── resource.h
└── xps.manifest
├── src
├── Windows
│ ├── DialogBuilder.cpp
│ ├── DialogBuilder.h
│ ├── FileDialog.cpp
│ ├── FileDialog.h
│ ├── FileOperation.cpp
│ ├── FileOperation.h
│ ├── InputBox.cpp
│ ├── InputBox.h
│ ├── TextEditor.cpp
│ ├── TextEditor.h
│ ├── Timer.cpp
│ ├── Timer.h
│ ├── WindowManager.cpp
│ ├── WindowManager.h
│ ├── Wnd.cpp
│ ├── Wnd.h
│ ├── theApp.cpp
│ └── theApp.h
├── about.cpp
├── about.h
├── asctable.cpp
├── asctable.h
├── comm.cpp
├── comm.h
├── data.cpp
├── data.h
├── debug.cpp
├── debug.h
├── main.cpp
├── msg.cpp
├── msg.h
├── pinctrl.cpp
├── pinctrl.h
├── sdklayout
│ ├── SdkLayout.cpp
│ ├── SdkLayout.h
│ ├── UIContainer.cpp
│ ├── UIContainer.h
│ ├── UIControl.cpp
│ ├── UIControl.h
│ ├── UIDlgBuilder.cpp
│ ├── UIDlgBuilder.h
│ ├── UIHorizontalLayout.cpp
│ ├── UIHorizontalLayout.h
│ ├── UIManager.cpp
│ ├── UIManager.h
│ ├── UIMarkup.cpp
│ ├── UIMarkup.h
│ ├── UISystemControls.cpp
│ ├── UISystemControls.h
│ ├── UIVerticalLayout.cpp
│ ├── UIVerticalLayout.h
│ ├── uiUtils.cpp
│ └── uiUtils.h
├── stdafx.cpp
├── stdafx.h
├── struct
│ ├── Config.cpp
│ ├── Config.h
│ ├── Thunk.cpp
│ ├── Thunk.h
│ ├── list.c
│ └── list.h
├── utils.cpp
└── utils.h
└── tools
├── README.md
├── gen_main_xml.bat
└── idxml.exe
/.gitignore:
--------------------------------------------------------------------------------
1 | /tmp/
2 | /ipch/
3 |
4 | /.vs/
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Common Copyright (C) 2012-2048 twofei
2 |
3 | 软件说明
4 | ========
5 |
6 | Win32平台上的串口通信调试助手
7 |
8 | 软件主页
9 | ========
10 |
11 | http://blog.twofei.com/566/
12 |
13 | 编译环境
14 | ========
15 |
16 | 为了方便管理, 目前只有VS2013的项目文件.
17 | 开发语言为C++/C++11.
18 |
19 | 联系作者
20 | ========
21 |
22 | QQ:191035066 Email:anhbk@qq.com
23 |
24 | 讨论QQ群
25 | =======
26 |
27 | 刚刚新建了一个QQ群用于相关讨论,目前人数还很少,欢迎加入。
28 |
29 |
30 |
--------------------------------------------------------------------------------
/bin/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 | !common.ini
4 |
--------------------------------------------------------------------------------
/bin/common.ini:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/bin/common.ini
--------------------------------------------------------------------------------
/common.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "pro/common.vcxproj", "{48044534-EFEB-44FC-A3AC-1202AE28AD95}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {48044534-EFEB-44FC-A3AC-1202AE28AD95}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {48044534-EFEB-44FC-A3AC-1202AE28AD95}.Debug|Win32.Build.0 = Debug|Win32
16 | {48044534-EFEB-44FC-A3AC-1202AE28AD95}.Release|Win32.ActiveCfg = Release|Win32
17 | {48044534-EFEB-44FC-A3AC-1202AE28AD95}.Release|Win32.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/pro/.gitignore:
--------------------------------------------------------------------------------
1 | /ipch/
2 | /.vs/
3 | /*.pdb
4 | /*.*sdf
5 | /*.user
6 | /*.suo
7 |
8 |
--------------------------------------------------------------------------------
/pro/common.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {48044534-EFEB-44FC-A3AC-1202AE28AD95}
15 | Win32Proj
16 | common
17 |
18 |
19 |
20 | Application
21 | true
22 | v120_xp
23 | MultiByte
24 |
25 |
26 | Application
27 | false
28 | v120_xp
29 | true
30 | MultiByte
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 | $(ProjectName)_debug
45 | ..\bin\
46 | ..\tmp\$(Configuration)\
47 |
48 |
49 | false
50 | ..\bin\
51 | ..\tmp\$(Configuration)\
52 |
53 |
54 |
55 | Use
56 | Level3
57 | Disabled
58 | WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)
59 | ..\src
60 | 4701;4706;%(TreatSpecificWarningsAsErrors)
61 | MultiThreadedDebug
62 | false
63 |
64 |
65 | Windows
66 | true
67 | setupapi.lib;imm32.lib;%(AdditionalDependencies)
68 |
69 |
70 |
71 |
72 | ..\res\xps.manifest
73 |
74 |
75 | %(PreprocessorDefinitions)
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | Level3
85 | Use
86 | MaxSpeed
87 | true
88 | true
89 | WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)
90 | ..\src
91 | 4701;4706;%(TreatSpecificWarningsAsErrors)
92 | MultiThreaded
93 |
94 |
95 | Windows
96 | true
97 | true
98 | true
99 | setupapi.lib;imm32.lib;%(AdditionalDependencies)
100 | NotSet
101 | false
102 | ./..\src/SdkLayout
103 |
104 |
105 | ..\res\xps.manifest
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | NotUsing
116 | NotUsing
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | Create
137 | Create
138 |
139 |
140 | Use
141 | Use
142 |
143 |
144 | NotUsing
145 | NotUsing
146 |
147 |
148 | NotUsing
149 | NotUsing
150 |
151 |
152 |
153 |
154 | Use
155 | Use
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 | Designer
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
--------------------------------------------------------------------------------
/pro/common.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | struct
6 |
7 |
8 | struct
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Windows
20 |
21 |
22 | Windows
23 |
24 |
25 | Windows
26 |
27 |
28 | sdklayout
29 |
30 |
31 | Windows
32 |
33 |
34 | Windows
35 |
36 |
37 | sdklayout
38 |
39 |
40 | sdklayout
41 |
42 |
43 | sdklayout
44 |
45 |
46 | sdklayout
47 |
48 |
49 | sdklayout
50 |
51 |
52 | sdklayout
53 |
54 |
55 | sdklayout
56 |
57 |
58 | sdklayout
59 |
60 |
61 | sdklayout
62 |
63 |
64 | Windows
65 |
66 |
67 | Windows
68 |
69 |
70 | Windows
71 |
72 |
73 | Windows
74 |
75 |
76 |
77 |
78 | struct
79 |
80 |
81 |
82 |
83 | struct
84 |
85 |
86 | struct
87 |
88 |
89 | struct
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | resources
101 |
102 |
103 | Windows
104 |
105 |
106 | Windows
107 |
108 |
109 | Windows
110 |
111 |
112 | sdklayout
113 |
114 |
115 | Windows
116 |
117 |
118 | Windows
119 |
120 |
121 | sdklayout
122 |
123 |
124 | sdklayout
125 |
126 |
127 | sdklayout
128 |
129 |
130 | sdklayout
131 |
132 |
133 | sdklayout
134 |
135 |
136 | sdklayout
137 |
138 |
139 | sdklayout
140 |
141 |
142 | sdklayout
143 |
144 |
145 | sdklayout
146 |
147 |
148 | Windows
149 |
150 |
151 | Windows
152 |
153 |
154 | Windows
155 |
156 |
157 | Windows
158 |
159 |
160 |
161 | struct
162 |
163 |
164 |
165 |
166 | {950386c5-54bc-49b0-9916-d268fa20788d}
167 |
168 |
169 | {d9a76f60-29ba-406f-878d-5cb33039f150}
170 |
171 |
172 | {15db0d98-9a56-4a42-a150-c5ad444cf07b}
173 |
174 |
175 | {be4a60a9-8b68-4cfe-a520-35707917f52b}
176 |
177 |
178 |
179 |
180 | resources
181 |
182 |
183 |
184 |
185 | resources
186 |
187 |
188 |
189 |
190 | resources
191 |
192 |
193 |
194 |
195 | resources
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/qrcode.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/qrcode.jpg
--------------------------------------------------------------------------------
/res/.gitignore:
--------------------------------------------------------------------------------
1 | common.aps
2 | *.xml
3 | !*_orig.xml
4 |
--------------------------------------------------------------------------------
/res/100.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/res/100.ico
--------------------------------------------------------------------------------
/res/common.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/res/common.rc
--------------------------------------------------------------------------------
/res/main_orig.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/res/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by common.rc
4 | //
5 | #define IDD_DLG_MAIN 101
6 | #define IDI_ICON1 106
7 | #define IDR_MENU_OTHER 111
8 | #define IDD_DLG_TIMEOUTS 114
9 | #define IDR_MENU_MORE 116
10 | #define IDD_DLG_PINCTRL 117
11 | #define IDD_SEND_CMD 128
12 | #define IDR_ACCELERATOR1 130
13 | #define IDD_DIALOG1 131
14 | #define IDD_GETBR 131
15 | #define IDR_101 134
16 | #define IDR_102 135
17 | #define IDR_RCDATA2 137
18 | #define MENU_EDIT_CONTEXTMENU 138
19 | #define MENU_RICHEDIT_CONTEXTMENU 138
20 | #define IDD_DIALOG2 139
21 | #define IDD_TEMPLATE 139
22 | #define IDR_MENU_SENDCMD 140
23 | #define IDC_BTN_SEND 1000
24 | #define IDC_CBO_CP 1002
25 | #define IDC_CBO_BR 1005
26 | #define IDC_CBO_CHK 1006
27 | #define IDC_CBO_DATA 1007
28 | #define IDC_CBO_STOP 1008
29 | #define IDC_BTN_OPEN 1009
30 | #define IDC_EDIT_RECV 1010
31 | #define IDC_EDIT_SEND 1011
32 | #define IDC_CHK_AUTO_SEND 1012
33 | #define IDC_EDIT_DELAY 1013
34 | #define IDC_RADIO_SEND_HEX 1014
35 | #define IDC_RADIO_SEND_CHAR 1015
36 | #define IDC_RADIO_RECV_HEX 1016
37 | #define IDC_RADIO_RECV_CHAR 1017
38 | #define IDC_CHK_TOP 1018
39 | #define IDC_STATIC_STATUS 1019
40 | #define IDC_BTN_CLR_RECV 1020
41 | #define IDC_BTN_CLR_SEND 1021
42 | #define IDC_BTN_CLR_COUNTER 1022
43 | #define IDC_BTN_HELP 1023
44 | #define IDC_BTN_COPY_RECV 1024
45 | #define IDC_BTN_COPY_SEND 1026
46 | #define IDC_BTN_SAVEFILE 1027
47 | #define IDC_BTN_STOPDISP 1029
48 | #define IDC_BTN_LOADFILE 1030
49 | #define IDC_EDIT_RECV2 1033
50 | #define IDC_BTN_MORE_SETTINGS 1035
51 | #define IDC_CTO_EDIT_READ_INTERVAL 1036
52 | #define IDC_CTO_EDIT_READ_MULTIPLIER 1037
53 | #define IDC_CTO_EDIT_READ_CONSTANT 1038
54 | #define IDC_CTO_EDIT_WRITE_MULTIPLIER 1039
55 | #define IDC_CTO_EDIT_WRITE_CONSTANT 1040
56 | #define IDC_CTO_BTN_OK 1041
57 | #define IDC_CTO_BTN_CANCEL 1042
58 | #define IDC_CTO_BTN_DEFAULT 1043
59 | #define IDC_PINCTRL_OK 1044
60 | #define IDC_CBO_PINCTRL_DTR 1045
61 | #define IDC_CBO_PINCTRL_RTS 1046
62 | #define IDC_STATIC_RECV 1049
63 | #define IDC_STATIC_TIMER 1050
64 | #define IDC_STATIC_PICTURE 1054
65 | #define IDC_STATIC_SEND 1056
66 | #define IDC_CMD_STATIC_TYPE 1062
67 | #define IDC_CMD_STATIC_SIZE 1064
68 | #define IDC_CMD_EDIT_CMD 1065
69 | #define IDC_CMD_BUTTON_SEND 1066
70 | #define IDC_CMD_STATIC_NAME 1067
71 | #define IDC_BUTTON1 1068
72 | #define IDC_BTN_SEND_FMT_CONFIG 1068
73 | #define IDC_BUTTON2 1069
74 | #define MAINSTATIC_CP 1071
75 | #define MAINSTATIC_BR 1072
76 | #define MAINSTATIC_CHK 1073
77 | #define MAINSTATIC_DATABIT 1074
78 | #define MAINSTATIC_STOPBIT 1075
79 | #define MAINSTATIC_TIMER 1076
80 | #define MAINSTATIC_RECV_FORMAT 1077
81 | #define MAINSTATIC_SEND_FORMAT 1078
82 | #define MAINSTATIC_AUTOSEND 1079
83 | #define IDC_CHECK_SIMPLE 1081
84 | #define IDC_CHECK2 1085
85 | #define MENU_OTHER_ASCII 40001
86 | #define MENU_OTHER_HELP 40002
87 | #define MENU_OTHER_CALC 40003
88 | #define MENU_OTHER_NOTEPAD 40004
89 | #define MENU_MORE_TIMEOUTS 40005
90 | #define MENU_MORE_DRIVER 40006
91 | #define MENU_MORE_PINCTRL 40007
92 | #define MENU_OTHER_DEVICEMGR 40008
93 | #define ID_POPUPMENU_40009 40009
94 | #define ID_POPUPMENU_40011 40011
95 | #define MENU_OTHER_STR2HEX 40012
96 | #define ID_POPUPMENU_40013 40013
97 | #define MENU_OTHER_MONITOR 40014
98 | #define ID_POPUPMENU_40015 40015
99 | #define MENU_OTHER_DRAW 40016
100 | #define ID_POPUPMENU_40017 40017
101 | #define MENU_OTHER_NEWVERSION 40018
102 | #define IDACC_SEND 40021
103 | #define IDACC_OPEN 40022
104 | #define IDACC_STOPDISP 40023
105 | #define IDACC_CLRCOUNTER 40024
106 | #define ID_POPUPMENU_40028 40028
107 | #define ID_POPUPMENU_40030 40030
108 | #define ID_POPUPMENU_40032 40032
109 | #define ID_EDITCONTEXTMENU_COPY 40039
110 | #define ID_EDITCONTEXTMENU_CUT 40040
111 | #define ID_EDITCONTEXTMENU_PASTE 40041
112 | #define ID_EDITCONTEXTMENU_DELETE 40042
113 | #define ID_EDITCONTEXTMENU_SELALL 40043
114 | #define ID_EDITCONTEXTMENU_FULLSCREEN 40044
115 | #define ID_40046 40046
116 | #define ID_40047 40047
117 | #define MENU_SENDCMD_NEWCMD 40048
118 | #define MENU_SENDCMD_COLLAPSEALL 40049
119 | #define ID_Menu 40050
120 | #define ID_EDITCONTEXTMENU_CLRSCR 40051
121 | #define ID_Menu40052 40052
122 | #define ID_EDITCONTEXTMENU_CALC 40053
123 |
124 | // Next default values for new objects
125 | //
126 | #ifdef APSTUDIO_INVOKED
127 | #ifndef APSTUDIO_READONLY_SYMBOLS
128 | #define _APS_NEXT_RESOURCE_VALUE 141
129 | #define _APS_NEXT_COMMAND_VALUE 40054
130 | #define _APS_NEXT_CONTROL_VALUE 1091
131 | #define _APS_NEXT_SYMED_VALUE 101
132 | #endif
133 | #endif
134 |
--------------------------------------------------------------------------------
/res/xps.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/Windows/DialogBuilder.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace Common{
4 |
5 | c_dialog_builder::c_dialog_builder()
6 | {
7 |
8 | }
9 |
10 | LRESULT c_dialog_builder::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
11 | {
12 | switch (uMsg)
13 | {
14 | case WM_SIZE:
15 | _layout.ResizeLayout();
16 | break;
17 | case WM_MOUSEWHEEL:
18 | case WM_HSCROLL:
19 | case WM_VSCROLL:
20 | _layout.ProcessScrollMessage(uMsg, wParam, lParam);
21 | break;
22 | case WM_INITDIALOG:
23 | {
24 | HWND hParent = GetWindowOwner(m_hWnd);
25 | SendMessage(WM_SETICON, ICON_BIG, LPARAM(::SendMessage(hParent, WM_GETICON, ICON_BIG, 0)));
26 | SendMessage(WM_SETICON, ICON_SMALL, LPARAM(::SendMessage(hParent, WM_GETICON, ICON_SMALL, 0)));
27 | _layout.SetLayout(m_hWnd, get_skin_xml());
28 | SMART_ASSERT(_layout.GetRoot() != NULL).Fatal();
29 |
30 | SetWindowLongPtr(m_hWnd, GWL_STYLE, get_window_style());
31 | if (get_window_style() & WS_CHILD) ::SetParent(m_hWnd, hParent);
32 |
33 | ::SetWindowText(m_hWnd, get_window_name());
34 | break;
35 | }
36 | case WM_COMMAND:
37 | {
38 | HWND hwnd = HWND(lParam);
39 | int id = LOWORD(wParam);
40 | int code = HIWORD(wParam);
41 |
42 | if (hwnd == nullptr &&code == 0){
43 | if (id == 2){
44 | response_key_event(VK_ESCAPE);
45 | return 0;
46 | }
47 | else if (id == 1){
48 | response_key_event(VK_RETURN);
49 | return 0;
50 | }
51 | }
52 |
53 | if (hwnd != NULL){
54 | SdkLayout::CControlUI* pControl = _layout.FindControl(hwnd);
55 | if (pControl){
56 | return on_command_ctrl(hwnd, pControl, code);
57 | }
58 | }
59 | else{
60 | if (HIWORD(wParam) == 0){
61 | return on_menu(LOWORD(wParam));
62 | }
63 | }
64 | break;
65 | }
66 | case WM_NOTIFY:
67 | {
68 | if (!lParam) break;
69 | auto hdr = reinterpret_cast(lParam);
70 | auto ctrl = _layout.FindControl(hdr->hwndFrom);
71 | if (!ctrl) break;
72 | return on_notify_ctrl(hdr->hwndFrom, ctrl, hdr->code ,hdr);
73 | }
74 | break;
75 | }
76 | return handle_message(uMsg, wParam, lParam, bHandled);
77 | }
78 |
79 | LRESULT c_dialog_builder::handle_message(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
80 | {
81 | return __super::HandleMessage(uMsg, wParam, lParam, bHandled);
82 | }
83 |
84 | void c_dialog_builder::response_key_event(WPARAM vk)
85 | {
86 | if (vk == VK_ESCAPE){
87 | Close();
88 | }
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/Windows/DialogBuilder.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common{
4 | class c_dialog_builder : public CWnd
5 | {
6 | public:
7 | c_dialog_builder();
8 |
9 | private:
10 | virtual LPCTSTR GetWindowClassName() const { return get_class_name(); }
11 | virtual LPCTSTR GetWndName() const { return get_window_name(); }
12 | virtual DWORD GetWndExStyle() const { return get_window_ex_style(); }
13 | virtual UINT GetClassStyle() const { return get_class_style(); }
14 | virtual DWORD GetWndStyle() const { return get_window_style(); }
15 | virtual HBRUSH GetClassBrush() const override { return get_class_brush(); }
16 | virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
17 | virtual void OnFinalMessage(HWND hWnd) { on_final_message(hWnd); }
18 |
19 | protected:
20 | virtual void response_key_event(WPARAM vk);
21 | virtual void end_dialog() { ::EndDialog(m_hWnd, 0); }
22 | virtual LRESULT handle_message(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
23 | virtual void on_final_message(HWND hwnd) { CWnd::OnFinalMessage(hwnd); }
24 | virtual LRESULT on_notify_ctrl(HWND hwnd, SdkLayout::CControlUI* ctrl, int code, NMHDR* hdr) { return 0; }
25 | virtual LRESULT on_command_ctrl(HWND hwnd, SdkLayout::CControlUI* ctrl, int code) { return 0; }
26 | virtual LRESULT on_menu(int id) { return 0; }
27 | virtual LPCTSTR get_class_name() const { return "c_dialog_builder"; }
28 | virtual UINT get_class_style() const { return 0; }
29 | virtual HBRUSH get_class_brush() const { return (HBRUSH)(COLOR_WINDOW); }
30 | virtual LPCTSTR get_window_name() const { return get_class_name(); }
31 | virtual DWORD get_window_style() const { return WS_OVERLAPPEDWINDOW; }
32 | virtual DWORD get_window_ex_style() const { return 0; }
33 | virtual LPCTSTR get_skin_xml() const = 0;
34 |
35 |
36 | protected:
37 | SdkLayout::CSdkLayout _layout;
38 | };
39 | }
40 |
--------------------------------------------------------------------------------
/src/Windows/FileDialog.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace Common{
4 |
5 |
6 | c_file_dlg::c_file_dlg()
7 | {
8 | ::memset(&_ofn, 0, sizeof(_ofn));
9 | _ofn.lStructSize = sizeof(_ofn);
10 | _ofn.hInstance = theApp.instance();
11 | _ofn.nMaxFile = sizeof(_buffer);
12 | _ofn.lpstrFile = _buffer;
13 | *_buffer = '\0';
14 |
15 | }
16 |
17 | c_file_open_dlg::c_file_open_dlg()
18 | {
19 | _ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST;
20 | }
21 |
22 | bool c_file_open_dlg::do_modal(HWND hOwner)
23 | {
24 | _ofn.hwndOwner = hOwner;
25 | return !!::GetOpenFileName(&_ofn);
26 | }
27 |
28 |
29 |
30 | c_file_save_dlg::c_file_save_dlg()
31 | {
32 | _ofn.Flags = OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_EXPLORER | OFN_NOREADONLYRETURN | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
33 | }
34 |
35 | bool c_file_save_dlg::do_modal(HWND hOwner)
36 | {
37 | _ofn.hwndOwner = hOwner;
38 | return !!::GetSaveFileName(&_ofn);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/Windows/FileDialog.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common{
4 | class c_file_dlg
5 | {
6 | public:
7 | c_file_dlg();
8 | virtual bool do_modal(HWND hOwner) = 0;
9 | void set_title(const char* tt) { _ofn.lpstrTitle = tt; }
10 | void set_filter(const char* flt){ _ofn.lpstrFilter = flt; }
11 | void set_flag(DWORD dwflg) { _ofn.Flags = dwflg; }
12 | char* get_buffer() { return _buffer; }
13 |
14 |
15 |
16 | protected:
17 | char _buffer[64 * (1 << 10)]; // 64KB max file
18 | OPENFILENAME _ofn;
19 | };
20 |
21 | class c_file_open_dlg : public c_file_dlg
22 | {
23 | public:
24 | c_file_open_dlg();
25 | virtual bool do_modal(HWND hOwner) override;
26 | };
27 |
28 | class c_file_save_dlg : public c_file_dlg
29 | {
30 | public:
31 | c_file_save_dlg();
32 | virtual bool do_modal(HWND hOwner) override;
33 | };
34 | }
35 |
--------------------------------------------------------------------------------
/src/Windows/FileOperation.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace Common{
4 |
5 |
6 |
7 | c_binary_file::~c_binary_file()
8 | {
9 | close();
10 | }
11 |
12 | bool c_binary_file::open(const char* fn, const char* mode)
13 | {
14 | _fn = fn;
15 | _fp = ::fopen(_fn.c_str(), mode);
16 | return !!_fp;
17 | }
18 |
19 |
20 | bool c_binary_file::close()
21 | {
22 | bool r = true;
23 | if (_fp){
24 | r = ::fclose(_fp)==0;
25 | if (r == true){
26 | _fp = NULL;
27 | }
28 | }
29 | return r;
30 | }
31 |
32 | int c_binary_file::seek(int offset, int origin)
33 | {
34 | SMART_ASSERT(_fp != NULL).Fatal();
35 | return ::fseek(_fp, offset, origin);
36 | }
37 |
38 | bool c_binary_file::read(unsigned char* buf, int size)
39 | {
40 | SMART_ASSERT(_fp != NULL).Fatal();
41 | return ::fread(buf, 1, size, _fp) == size;
42 | }
43 |
44 | bool c_binary_file::write(unsigned char* buf, int size)
45 | {
46 | SMART_ASSERT(_fp != NULL).Fatal();
47 | return ::fwrite(buf, 1, size, _fp) == size;
48 | }
49 |
50 | int c_binary_file::tell()
51 | {
52 | SMART_ASSERT(_fp != NULL).Fatal();
53 | return ::ftell(_fp);
54 | }
55 |
56 | void c_binary_file::flush()
57 | {
58 | SMART_ASSERT(_fp != NULL).Fatal();
59 | ::fflush(_fp);
60 | }
61 |
62 | const std::string& c_binary_file::get_fn()
63 | {
64 | return _fn;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/Windows/FileOperation.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/Windows/FileOperation.h
--------------------------------------------------------------------------------
/src/Windows/InputBox.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/Windows/InputBox.cpp
--------------------------------------------------------------------------------
/src/Windows/InputBox.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common{
4 | class c_input_box;
5 |
6 | class i_input_box
7 | {
8 | public:
9 | virtual bool try_close() = 0;
10 | virtual bool check_valid(const char* str) = 0;
11 | virtual void set_notifier(i_notifier* notifier) = 0;
12 | virtual void set_this(c_input_box* that) = 0;
13 | virtual const char* get_enter_text() = 0;
14 | virtual const char* get_prompt_text() = 0;
15 | };
16 |
17 | class c_input_box : public c_dialog_builder
18 | {
19 | public:
20 | c_input_box(i_input_box* piib);
21 | ~c_input_box();
22 |
23 | bool test_get_int_value();
24 | int get_int_value();
25 | std::string get_string_value();
26 | int get_dlg_code() const { return _dlg_code; }
27 |
28 | private:
29 | virtual LPCTSTR get_skin_xml() const override;
30 |
31 | protected:
32 | virtual void response_key_event(WPARAM vk) override;
33 | virtual LRESULT handle_message(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) override;
34 | virtual LRESULT on_command_ctrl(HWND hwnd, SdkLayout::CControlUI* ctrl, int code) override;
35 | bool call_interface();
36 |
37 | protected:
38 | i_input_box* _piib;
39 | int _dlg_code;
40 | const char* _prompt_str;
41 | const char* _enter_string;
42 | const char* _pstr;
43 | int _i;
44 |
45 | HWND _hPrompt, _hEnter, _hOk, _hCancel;
46 | };
47 | }
48 |
--------------------------------------------------------------------------------
/src/Windows/TextEditor.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace Common{
4 | namespace Window{
5 |
6 | //////////////////////////////////////////////////////////////////////////
7 | bool c_edit::back_delete_char( int n )
8 | {
9 | return false;
10 | }
11 |
12 | bool c_edit::append_text( const char* str )
13 | {
14 | int len = ::GetWindowTextLength(m_hWnd);
15 | Edit_SetSel(m_hWnd, len, len);
16 | Edit_ReplaceSel(m_hWnd, str);
17 | return true;
18 | }
19 |
20 | void c_edit::limit_text( int sz )
21 | {
22 | SendMessage(EM_LIMITTEXT, sz == -1 ? 0 : sz);
23 | }
24 |
25 | void c_edit::set_text(const char* str)
26 | {
27 | ::SetWindowText(*this, str);
28 | }
29 |
30 | HMENU c_edit::_load_default_menu()
31 | {
32 | return nullptr;
33 | }
34 |
35 | LRESULT c_edit::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
36 | {
37 | if (uMsg == WM_CONTEXTMENU) {
38 | if (!_bUseDefMenu){
39 | return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
40 | }
41 | else{
42 |
43 | }
44 | }
45 | return __super::HandleMessage(uMsg, wParam, lParam, bHandled);
46 | }
47 |
48 | bool c_edit::is_read_only()
49 | {
50 | return !!(::GetWindowLongPtr(*this, GWL_STYLE) & ES_READONLY);
51 | }
52 |
53 | //////////////////////////////////////////////////////////////////////////
54 | bool c_rich_edit::back_delete_char( int n )
55 | {
56 | int cch;
57 | GETTEXTLENGTHEX gtl;
58 |
59 | if(n <= 0)
60 | return false;
61 |
62 | gtl.flags = GTL_DEFAULT;
63 | gtl.codepage = CP_ACP;
64 | cch = SendMessage(EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
65 | if(cch > 0){
66 | if(n >= cch){
67 | SetWindowText(m_hWnd, "");
68 | return true;
69 | }
70 | else{
71 | CHARRANGE rng;
72 | rng.cpMax = cch;
73 | rng.cpMin = cch - n;
74 | SendMessage(EM_EXSETSEL, 0, (LPARAM)&rng);
75 | SendMessage(EM_REPLACESEL, FALSE, (LPARAM)"");
76 | }
77 | }
78 | return true;
79 | }
80 |
81 | bool c_rich_edit::append_text( const char* str )
82 | {
83 | GETTEXTLENGTHEX gtl;
84 | CHARRANGE rng;
85 | int cch;
86 |
87 | gtl.flags = GTL_DEFAULT;
88 | gtl.codepage = CP_ACP;
89 | cch = SendMessage(EM_GETTEXTLENGTHEX, (WPARAM)>l);
90 |
91 | rng.cpMax = cch;
92 | rng.cpMin = cch;
93 | SendMessage(EM_EXSETSEL, 0, (LPARAM)&rng);
94 | Edit_ReplaceSel(m_hWnd,str);
95 |
96 | // Richedit bug: EM_SCROLLCARET will not work if a richedit gets no focus
97 | // http://stackoverflow.com/questions/9757134/scrolling-richedit-without-it-having-focus
98 | SendMessage(WM_VSCROLL, SB_BOTTOM);
99 |
100 | return true;
101 | }
102 |
103 | bool c_rich_edit::apply_linux_attributes(char* attrs)
104 | {
105 | const char* p = attrs;
106 | const char* end;
107 |
108 | if (!attrs || !*attrs)
109 | return false;
110 |
111 | end = attrs + strlen(attrs) - 1;
112 |
113 | assert(*p++ == '\033');
114 | assert(*p++ == '[');
115 |
116 | switch (*end)
117 | {
118 | case 'm': // \033[a1;a1;...m
119 | {
120 | for (;*p != 'm';){
121 | if (*p == ';'){
122 | p++;
123 | }
124 | else if (*p >= '0' && *p <= '9'){
125 | int a = 0;
126 | p += read_integer(p, &a);
127 | apply_linux_attribute_m(a);
128 | }
129 | else{
130 | SMART_ASSERT(0)(*p).Fatal();
131 | }
132 | }
133 | break;
134 | }
135 |
136 | }
137 |
138 |
139 | return true;
140 | }
141 |
142 | bool c_rich_edit::apply_linux_attribute_m(int attr)
143 | {
144 | CHARFORMAT2 cf;
145 | static struct{
146 | int k;
147 | COLORREF v;
148 | }def_colors[] =
149 | {
150 | {30, RGB(0, 0, 0)},
151 | {31, RGB(255, 0, 0)},
152 | {32, RGB(0, 255, 0)},
153 | {33, RGB(255,255, 0)},
154 | {34, RGB(0, 0,255)},
155 | {35, RGB(255, 0,255)},
156 | {36, RGB(0, 255,255)},
157 | {37, RGB(255,255,255)},
158 | {-1, RGB(0,0,0) },
159 | };
160 |
161 | cf.cbSize = sizeof(cf);
162 |
163 | if(attr>=30 && attr<=37){
164 | cf.dwMask = CFM_COLOR;
165 | cf.dwEffects = 0;
166 | assert(_deffg>=30 && _deffg<=37);
167 | cf.crTextColor = def_colors[attr-30].v;
168 | SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
169 | }
170 | else if(attr>=40 && attr<=47){
171 | cf.dwMask = CFM_BACKCOLOR;
172 | cf.dwEffects = 0;
173 | assert(_defbg>=40 && _defbg<=47);
174 | cf.crBackColor = def_colors[attr-40].v;
175 | SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
176 | }
177 | else if(attr == 0){
178 | cf.dwMask = CFM_COLOR | CFM_BACKCOLOR | CFM_BOLD;
179 | cf.dwEffects = 0;
180 | assert( (_deffg>=30 && _deffg<=37)
181 | && (_defbg>=40 && _defbg<=47));
182 | cf.crTextColor = def_colors[_deffg-30].v;
183 | cf.crBackColor = def_colors[_defbg-40].v;
184 | SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
185 | }
186 | else if(attr == 1){
187 | cf.dwMask = CFM_BOLD;
188 | cf.dwEffects = CFE_BOLD;
189 | SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
190 | }
191 | else{
192 | //debug_out(("unknown or unsupported Linux control format!\n"));
193 | }
194 |
195 | return true;
196 | }
197 |
198 | LRESULT c_rich_edit::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
199 | {
200 | return __super::HandleMessage(uMsg, wParam, lParam, bHandled);
201 | }
202 |
203 | bool c_rich_edit::get_sel_range(int* start /*= nullptr*/, int* end /*= nullptr*/)
204 | {
205 | CHARRANGE rng;
206 | SendMessage(EM_EXGETSEL, 0, LPARAM(&rng));
207 | if (start) *start = rng.cpMin;
208 | if (end) *end = rng.cpMax;
209 | return rng.cpMin != rng.cpMax;
210 | }
211 |
212 | void c_rich_edit::do_copy()
213 | {
214 | SendMessage(WM_COPY);
215 | }
216 |
217 | void c_rich_edit::do_cut()
218 | {
219 | SendMessage(WM_CUT);
220 | }
221 |
222 | void c_rich_edit::do_paste()
223 | {
224 | SendMessage(WM_PASTE);
225 | }
226 |
227 | void c_rich_edit::do_delete()
228 | {
229 | SendMessage(WM_CLEAR);
230 | }
231 |
232 | void c_rich_edit::do_sel_all()
233 | {
234 | SendMessage(EM_SETSEL, 0, -1);
235 | }
236 |
237 | void c_rich_edit::set_default_text_fgcolor(COLORREF fg)
238 | {
239 | CHARFORMAT2 cf;
240 | ::memset(&cf, 0, sizeof(cf));
241 | cf.cbSize = sizeof(cf);
242 | cf.dwMask = CFM_COLOR;
243 | cf.dwEffects = 0;
244 | cf.crTextColor = fg;
245 | SMART_ENSURE(SendMessage(EM_SETCHARFORMAT, 0, LPARAM(&cf)), != 0).Warning();
246 | }
247 |
248 | void c_rich_edit::set_default_text_bgcolor(COLORREF bg)
249 | {
250 | CHARFORMAT2 cf;
251 | cf.cbSize = sizeof(cf);
252 | cf.dwMask = CFM_BACKCOLOR;
253 | cf.dwEffects = 0;
254 | cf.crBackColor = bg;
255 | SMART_ENSURE(SendMessage(EM_SETCHARFORMAT, SCF_ALL, LPARAM(&cf)), != 0).Warning();
256 | }
257 |
258 | void c_rich_edit::limit_text(int sz) {
259 | // https://msdn.microsoft.com/en-us/library/windows/desktop/bb761647(v=vs.85).aspx
260 | SendMessage(EM_EXLIMITTEXT, 0, sz == -1 ? 0x7ffffffe : sz);
261 | }
262 |
263 | }
264 | }
265 |
--------------------------------------------------------------------------------
/src/Windows/TextEditor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common {
4 | namespace Window{
5 | class c_edit : public CWnd
6 | {
7 | public:
8 | c_edit()
9 | : _bUseDefMenu(true)
10 | {
11 | }
12 | virtual ~c_edit(){
13 | }
14 |
15 | virtual LPCTSTR GetSuperClassName() const{return WC_EDIT;}
16 | virtual LPCTSTR GetWindowClassName() const{return "Common" WC_EDIT;}
17 | virtual bool ResponseDefaultKeyEvent(HWND hwnd, WPARAM wParam) {return false;}
18 |
19 | void clear() {
20 | ::SetWindowText(*this, "");
21 | }
22 | virtual bool back_delete_char(int n);
23 | virtual bool append_text(const char* str);
24 | virtual void set_text(const char* str);
25 |
26 | public: // menu support functions
27 | virtual bool is_read_only();
28 |
29 | public:
30 | virtual void limit_text(int sz);
31 |
32 | protected:
33 | virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) override;
34 | HMENU _load_default_menu();
35 |
36 |
37 | protected:
38 | bool _bUseDefMenu;
39 |
40 | };
41 |
42 | class c_rich_edit : public c_edit
43 | {
44 | public:
45 | c_rich_edit()
46 | : _deffg(30)
47 | , _defbg(47)
48 | {}
49 |
50 | virtual LPCTSTR GetSuperClassName() const {return RICHEDIT_CLASS;}
51 | virtual LPCTSTR GetWindowClassName() const{return "Common" RICHEDIT_CLASS;}
52 | virtual bool back_delete_char(int n);
53 | virtual bool append_text(const char* str);
54 | virtual bool apply_linux_attributes(char* attrs);
55 | virtual bool apply_linux_attribute_m(int attr);
56 |
57 | public:
58 | virtual void limit_text(int sz) override;
59 | void set_default_text_fgcolor(COLORREF fg);
60 | void set_default_text_bgcolor(COLORREF bg);
61 | bool get_sel_range(int* start = nullptr, int* end = nullptr);
62 | void do_copy();
63 | void do_cut();
64 | void do_paste();
65 | void do_delete();
66 | void do_sel_all();
67 |
68 | protected:
69 | virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled) override;
70 |
71 | protected:
72 | int _deffg;
73 | int _defbg;
74 | };
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Windows/Timer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/Windows/Timer.cpp
--------------------------------------------------------------------------------
/src/Windows/Timer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/Windows/Timer.h
--------------------------------------------------------------------------------
/src/Windows/WindowManager.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 | #include "WindowManager.h"
3 |
4 | namespace Common{
5 | c_ptr_array CWindowManager::m_aWndMgrs;
6 |
7 | CWindowManager::CWindowManager()
8 | : m_hWnd(0)
9 | , m_pMsgFilter(0)
10 | , m_pAcceTrans(0)
11 | {
12 |
13 | }
14 |
15 | CWindowManager::~CWindowManager()
16 | {
17 |
18 | }
19 |
20 | bool CWindowManager::FilterMessage(MSG* pmsg)
21 | {
22 | return m_pMsgFilter && m_pMsgFilter->FilterMessage(
23 | pmsg->hwnd, pmsg->message, pmsg->wParam, pmsg->lParam);
24 | }
25 |
26 | bool CWindowManager::AddWindowManager(CWindowManager* pwm)
27 | {
28 | return m_aWndMgrs.add(pwm);
29 | }
30 |
31 | bool CWindowManager::RemoveWindowManager(CWindowManager* pwm)
32 | {
33 | return m_aWndMgrs.remove(pwm);
34 | }
35 |
36 | bool CWindowManager::TranslateAccelerator( MSG* pmsg )
37 | {
38 | return m_pAcceTrans && m_pAcceTrans->TranslateAccelerator(pmsg);
39 | }
40 |
41 | void CWindowManager::MessageLoop()
42 | {
43 | MSG msg;
44 | while(::GetMessage(&msg, NULL, 0, 0)){
45 | if(!TranslateMessage(&msg)){
46 | ::TranslateMessage(&msg);
47 | ::DispatchMessage(&msg);
48 | }
49 | }
50 | }
51 |
52 | bool CWindowManager::TranslateMessage( MSG* pmsg )
53 | {
54 | bool bChild = !!(GetWindowStyle(pmsg->hwnd) & WS_CHILD);
55 | if(bChild){
56 | HWND hParent = pmsg->hwnd;
57 | while (hParent && ::GetWindowLongPtr(hParent, GWL_STYLE)&WS_CHILD){
58 | hParent = ::GetParent(hParent);
59 | }
60 |
61 | if (hParent != NULL){
62 | for (int i = 0; i < m_aWndMgrs.size(); i++){
63 | CWindowManager* pWM = m_aWndMgrs.getat(i);
64 | if (pWM->hWnd() == hParent){
65 | if (pWM->TranslateAccelerator(pmsg))
66 | return true;
67 | if (pWM->FilterMessage(pmsg))
68 | return true;
69 | return false;
70 | }
71 | }
72 | }
73 | }
74 | else{
75 | for(int i=0; ihwnd == pWM->hWnd()){
78 | if(pWM->TranslateAccelerator(pmsg))
79 | return true;
80 | if(pWM->FilterMessage(pmsg))
81 | return true;
82 |
83 | return false;
84 | }
85 | }
86 | }
87 | return false;
88 | }
89 |
90 | void CWindowManager::Init( HWND hWnd , IMessageFilter* flt)
91 | {
92 | //TODO
93 | //assert((GetWindowLongPtr(hWnd, GWL_STYLE)&WS_CHILD) == 0);
94 | m_hWnd = hWnd;
95 | AddWindowManager(this);
96 | MessageFilter() = flt;
97 | }
98 |
99 | void CWindowManager::DeInit()
100 | {
101 | RemoveWindowManager(this);
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/Windows/WindowManager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common {
4 |
5 | class IMessageFilter
6 | {
7 | public:
8 | virtual bool FilterMessage(HWND hChild, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
9 | };
10 |
11 | class IAcceleratorTranslator
12 | {
13 | public:
14 | virtual bool TranslateAccelerator(MSG* pmsg) = 0;
15 | };
16 |
17 | class CWindowManager
18 | {
19 | public:
20 | CWindowManager();
21 | virtual ~CWindowManager();
22 |
23 | void Init(HWND hWnd, IMessageFilter* flt);
24 | void DeInit();
25 | HWND& hWnd() {return m_hWnd;}
26 |
27 | bool FilterMessage(MSG* pmsg);
28 | IMessageFilter*& MessageFilter(){return m_pMsgFilter;}
29 |
30 | bool TranslateAccelerator(MSG* pmsg);
31 | IAcceleratorTranslator*& AcceleratorTranslator() { return m_pAcceTrans; }
32 |
33 | static void MessageLoop();
34 | static bool TranslateMessage(MSG* pmsg);
35 | bool AddWindowManager(CWindowManager* pwm);
36 | bool RemoveWindowManager(CWindowManager* pwm);
37 |
38 |
39 | protected:
40 | HWND m_hWnd;
41 | IMessageFilter* m_pMsgFilter;
42 | IAcceleratorTranslator* m_pAcceTrans;
43 | static c_ptr_array m_aWndMgrs;
44 | };
45 | }
46 |
--------------------------------------------------------------------------------
/src/Windows/Wnd.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/Windows/Wnd.cpp
--------------------------------------------------------------------------------
/src/Windows/Wnd.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/Windows/Wnd.h
--------------------------------------------------------------------------------
/src/Windows/theApp.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace Common{
4 |
5 | c_the_app::c_the_app()
6 | {
7 | _hinst = ::GetModuleHandle(0);
8 |
9 | char buf[MAX_PATH]={0};
10 | ::GetModuleFileName(_hinst, buf, _countof(buf));
11 |
12 | char* p = strrchr(buf, '\\');
13 | if(!p) p = strrchr(buf, '/');
14 | if(p) *p = '\0';
15 |
16 | _path = buf;
17 | }
18 |
19 | HINSTANCE c_the_app::instance()
20 | {
21 | return _hinst;
22 | }
23 |
24 | std::string c_the_app::path()
25 | {
26 | return _path;
27 | }
28 |
29 | c_the_app::operator HINSTANCE()
30 | {
31 | return _hinst;
32 | }
33 |
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/Windows/theApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common{
4 | class c_the_app
5 | {
6 | public:
7 | c_the_app();
8 | HINSTANCE instance();
9 | std::string path();
10 | operator HINSTANCE();
11 |
12 | private:
13 | HINSTANCE _hinst;
14 | std::string _path;
15 | };
16 | }
17 |
18 | extern Common::c_the_app theApp;
19 |
--------------------------------------------------------------------------------
/src/about.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/about.cpp
--------------------------------------------------------------------------------
/src/about.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | namespace Common{
4 |
5 | #define COMMON_NAME "Com Monitor"
6 | #define COMMON_VERSION "1.20"
7 |
8 | #ifdef _DEBUG
9 | #define COMMON_NAME_AND_VERSION COMMON_NAME " " COMMON_VERSION " - Debug Mode"
10 | #else
11 | #define COMMON_NAME_AND_VERSION COMMON_NAME " " COMMON_VERSION " "
12 | #endif
13 |
14 | class c_about_dlg : public c_dialog_builder
15 | {
16 | protected:
17 | virtual LRESULT handle_message(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
18 | virtual void on_final_message(HWND hwnd) { __super::on_final_message(hwnd); delete this; }
19 | virtual LPCTSTR get_skin_xml() const override;
20 | virtual LRESULT on_command_ctrl(HWND hwnd, SdkLayout::CControlUI* ctrl, int code) override;
21 | virtual LPCTSTR get_window_name() const;
22 |
23 | private:
24 | static const char* about_str;
25 | static const char* soft_name;
26 | };
27 | }
28 |
--------------------------------------------------------------------------------
/src/asctable.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/asctable.cpp
--------------------------------------------------------------------------------
/src/asctable.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/asctable.h
--------------------------------------------------------------------------------
/src/comm.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/comm.cpp
--------------------------------------------------------------------------------
/src/comm.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/comm.h
--------------------------------------------------------------------------------
/src/data.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/data.cpp
--------------------------------------------------------------------------------
/src/data.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/data.h
--------------------------------------------------------------------------------
/src/debug.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "debug.h"
7 |
8 |
9 | std::fstream __debug_file;
10 |
--------------------------------------------------------------------------------
/src/debug.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/debug.h
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/main.cpp
--------------------------------------------------------------------------------
/src/msg.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/msg.cpp
--------------------------------------------------------------------------------
/src/msg.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/msg.h
--------------------------------------------------------------------------------
/src/pinctrl.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/pinctrl.cpp
--------------------------------------------------------------------------------
/src/pinctrl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | void show_pinctrl(HWND owner, std::function get_com_handle);
4 |
--------------------------------------------------------------------------------
/src/sdklayout/SdkLayout.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 |
3 | namespace SdkLayout{
4 |
5 | bool CSdkLayout::SetLayout(HWND hWnd, LPCTSTR xml, HINSTANCE hInst)
6 | {
7 | DeleteLayout();
8 |
9 | assert(::IsWindow(hWnd));
10 | m_hWnd = hWnd;
11 | CDialogBuilder builder;
12 | CContainerUI* pRoot = static_cast(
13 | builder.Create(xml, &m_Manager, hInst ? hInst : GetModuleHandle(NULL), m_getid));
14 | assert(pRoot);
15 | if(pRoot){
16 | m_Manager.SetHWND(hWnd);
17 | m_pRoot = pRoot;
18 | m_pRoot->SetManager(&m_Manager);
19 | DWORD dwStyle = GetWindowLongPtr(GetHWND(), GWL_STYLE);
20 | dwStyle |= WS_VSCROLL | WS_HSCROLL;
21 | SetWindowLongPtr(GetHWND(), GWL_STYLE, dwStyle);
22 | ShowScrollBar(m_hWnd, SB_VERT, TRUE);
23 | ShowScrollBar(m_hWnd, SB_HORZ, TRUE);
24 | _InitializeLayout();
25 | }
26 | return !!m_pRoot;
27 | }
28 |
29 | bool CSdkLayout::SetLayout( HWND hWnd, UINT id, HINSTANCE hInst/*=NULL*/ )
30 | {
31 | return SetLayout(hWnd, MAKEINTRESOURCE(id), hInst ? hInst : GetModuleHandle(NULL));
32 | }
33 |
34 | void CSdkLayout::DeleteLayout()
35 | {
36 | delete m_pRoot;
37 | m_pRoot = NULL;
38 | m_hWnd = NULL;
39 | }
40 |
41 | void CSdkLayout::ResizeLayout(const RECT& rc)
42 | {
43 | if(!m_pRoot || !m_hWnd) return;
44 | m_pRoot->SetPos(rc);
45 | _ProcessScrollBar(rc);
46 | ::InvalidateRect(m_hWnd, &rc, FALSE);
47 | m_rcLast = rc;
48 | }
49 |
50 | void CSdkLayout::ResizeLayout()
51 | {
52 | if(!m_pRoot || !m_hWnd || !IsWindow(m_hWnd)) return;
53 | RECT rc;
54 | ::GetClientRect(m_hWnd, &rc);
55 | ResizeLayout(rc);
56 | }
57 |
58 | CControlUI* CSdkLayout::FindControl(LPCTSTR name)
59 | {
60 | return m_pRoot ? m_pRoot->FindControl(name) : NULL;
61 | }
62 |
63 |
64 | CControlUI* CSdkLayout::FindControl(HWND hwnd)
65 | {
66 | return m_pRoot ? m_pRoot->FindControl(hwnd) : NULL;
67 | }
68 |
69 |
70 | void CSdkLayout::SetDefFont(LPCTSTR face, int sz)
71 | {
72 | GetManager()->SetDefaultFont(face, sz, false, false, false);
73 | if(GetRoot()){
74 | GetRoot()->SetFont(-2);
75 | }
76 | }
77 |
78 | void CSdkLayout::_InitializeLayout()
79 | {
80 | if(!m_pRoot) return;
81 |
82 | SIZE& sz = m_Manager.InitSize();
83 | RECT rc = { 0 };
84 | rc.right = sz.cx;
85 | rc.bottom = sz.cy;
86 | if (!::AdjustWindowRectEx(&rc, GetWindowStyle(m_hWnd), (!(GetWindowStyle(m_hWnd) & WS_CHILD) && (::GetMenu(m_hWnd) != NULL)), GetWindowExStyle(m_hWnd))) return;
87 | ::SetWindowPos(m_hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
88 |
89 | m_pRoot->SetFont(-2);
90 | m_pRoot->SetVisible(m_pRoot->IsVisible());
91 |
92 | m_pRoot->DoInit();
93 |
94 | ResizeLayout();
95 | }
96 |
97 | void CSdkLayout::_ProcessScrollBar(const CDuiRect& rc)
98 | {
99 | const SIZE& szPost = GetPostSize();
100 |
101 | bool bSetVert=false,bSetHorz=false;
102 |
103 | if(szPost.cy > rc.GetHeight())
104 | bSetVert = true;
105 |
106 | if(szPost.cx > rc.GetWidth())
107 | bSetHorz = true;
108 |
109 | SCROLLINFO si = {0};
110 | si.cbSize = sizeof(si);
111 | si.fMask = SIF_ALL;
112 | si.nMin = 0;
113 | si.nPos = 0;
114 | si.nPage = 100;
115 | if(bSetVert){
116 | si.nMax = szPost.cy-rc.GetHeight()-1+si.nPage-1;
117 | SetScrollInfo(GetHWND(), SB_VERT, &si, TRUE);
118 | ShowScrollBar(GetHWND(), SB_VERT, TRUE);
119 | }
120 | else{
121 | ShowScrollBar(GetHWND(), SB_VERT, FALSE);
122 | }
123 | if(bSetHorz){
124 | si.nMax = szPost.cx-rc.GetWidth()-1+si.nPage-1;
125 | SetScrollInfo(GetHWND(), SB_HORZ, &si, TRUE);
126 | ShowScrollBar(GetHWND(), SB_HORZ, TRUE);
127 | }
128 | else{
129 | ShowScrollBar(GetHWND(), SB_HORZ, FALSE);
130 | }
131 | }
132 |
133 | void CSdkLayout::ProcessScrollMessage( UINT uMsg, WPARAM wParam, LPARAM lParam )
134 | {
135 | if(uMsg == WM_VSCROLL){
136 | SCROLLINFO si = {0};
137 | int iVertPos = 0;
138 | si.cbSize = sizeof(si);
139 | si.fMask = SIF_ALL;
140 | GetScrollInfo(GetHWND(),SB_VERT,&si);
141 | iVertPos = si.nPos;
142 |
143 | switch(LOWORD(wParam))
144 | {
145 | case SB_ENDSCROLL: break;
146 | case SB_TOP: si.nPos = 0; break;
147 | case SB_BOTTOM: si.nPos = si.nMax; break;
148 | case SB_LINEUP: si.nPos --; break;
149 | case SB_LINEDOWN: si.nPos ++; break;
150 | case SB_PAGEUP: si.nPos -= si.nPage; break;
151 | case SB_PAGEDOWN: si.nPos += si.nPage; break;
152 | case SB_THUMBTRACK:
153 | case SB_THUMBPOSITION:
154 | si.nPos = si.nTrackPos;break;
155 | }
156 |
157 | si.fMask = SIF_POS;
158 | SetScrollInfo(GetHWND(),SB_VERT,&si,TRUE);
159 | GetScrollInfo(GetHWND(), SB_VERT, &si);
160 |
161 | if(si.nPos != iVertPos){
162 | ScrollWindow(GetHWND(), 0, (iVertPos-si.nPos), NULL, NULL);
163 | UpdateWindow(GetHWND());
164 | }
165 | }
166 | else if(uMsg == WM_HSCROLL){
167 | SCROLLINFO si = {0};
168 | int iHorzPos = 0;
169 | si.cbSize = sizeof(si);
170 | si.fMask = SIF_ALL;
171 | GetScrollInfo(GetHWND(),SB_HORZ,&si);
172 | iHorzPos = si.nPos;
173 |
174 | switch(LOWORD(wParam))
175 | {
176 | case SB_ENDSCROLL: break;
177 | case SB_LEFT: si.nPos = 0; break;
178 | case SB_RIGHT: si.nPos = si.nMax; break;
179 | case SB_LINELEFT: si.nPos --; break;
180 | case SB_LINERIGHT: si.nPos ++; break;
181 | case SB_PAGELEFT: si.nPos -= si.nPage; break;
182 | case SB_PAGERIGHT: si.nPos += si.nPage; break;
183 | case SB_THUMBTRACK:
184 | case SB_THUMBPOSITION:
185 | si.nPos = si.nTrackPos;break;
186 | }
187 |
188 | si.fMask = SIF_POS;
189 | SetScrollInfo(GetHWND(),SB_HORZ,&si,TRUE);
190 | GetScrollInfo(GetHWND(), SB_HORZ, &si);
191 |
192 | if(si.nPos != iHorzPos){
193 | ScrollWindow(GetHWND(), (iHorzPos-si.nPos), 0, NULL, NULL);
194 | UpdateWindow(GetHWND());
195 | }
196 | }
197 | }
198 |
199 | }
200 |
201 | sdklayout* layout_new( HWND hWnd, LPCTSTR xml, HINSTANCE hInst )
202 | {
203 | sdklayout* layout = new SdkLayout::CSdkLayout;
204 | if(layout->SetLayout(hWnd, xml, hInst)){
205 | return layout;
206 | }
207 | else{
208 | delete layout;
209 | return NULL;
210 | }
211 | }
212 |
213 |
214 | void layout_delete( sdklayout* layout )
215 | {
216 | delete layout;
217 | }
218 |
219 |
220 | sdkcontrol* layout_root( sdklayout* layout )
221 | {
222 | return layout ? layout->GetRoot() : NULL;
223 | }
224 |
225 |
226 | void layout_post_size( sdklayout* layout, int* x, int* y )
227 | {
228 | if(layout){
229 | const SIZE& size = layout->GetPostSize();
230 | *x = size.cx;
231 | *y = size.cy;
232 | }
233 | else{
234 | *x = 0;
235 | *y = 0;
236 | }
237 | }
238 |
239 | void layout_scroll( sdklayout* layout, UINT uMsg, WPARAM wParam, LPARAM lParam )
240 | {
241 | if(layout)
242 | layout->ProcessScrollMessage(uMsg, wParam, lParam);
243 | }
244 |
245 | void layout_resize( sdklayout* layout, SIZE* sz)
246 | {
247 | if(layout){
248 | if(sz){
249 | RECT rc = {0,0,sz->cx, sz->cy};
250 | layout->ResizeLayout(rc);
251 | }
252 | else{
253 | layout->ResizeLayout();
254 | }
255 | }
256 | }
257 |
258 | sdkcontrol* layout_control(sdklayout* layout, LPCTSTR name )
259 | {
260 | return layout ? layout->FindControl(name) : NULL;
261 | }
262 |
263 |
264 | void layout_visible( sdkcontrol* ctrl, BOOL bVisible )
265 | {
266 | if(ctrl){
267 | ctrl->SetVisible(!!bVisible);
268 | }
269 | }
270 |
271 | void layout_deffont(sdklayout* layout, const char* face, int sz)
272 | {
273 | if(layout){
274 | layout->SetDefFont(face, sz);
275 | }
276 | }
277 |
278 | int layout_newfont(sdklayout* layout, const char* face, int sz)
279 | {
280 | if(layout){
281 | HFONT hFont = layout->GetManager()->AddFont(face, sz, false, false, false);
282 | return layout->GetManager()->GetFont(hFont);
283 | }
284 | return -1;
285 | }
286 |
287 | void layout_setfont(sdkcontrol* ctrl, int id)
288 | {
289 | if(ctrl){
290 | ctrl->SetFont(id);
291 | }
292 | }
293 |
--------------------------------------------------------------------------------
/src/sdklayout/SdkLayout.h:
--------------------------------------------------------------------------------
1 | #ifndef __SDK_LAYOUT_H__
2 | #define __SDK_LAYOUT_H__
3 |
4 | #pragma once
5 |
6 | #if defined(__cplusplus)
7 |
8 | #include
9 |
10 | #define lengthof(x) (sizeof(x)/sizeof(*x))
11 | #define MAX max
12 | #define MIN min
13 | #define CLAMP(x,a,b) (MIN(b,MAX(a,x)))
14 |
15 | #include "uiUtils.h"
16 | #include "UIControl.h"
17 | #include "UIContainer.h"
18 | #include "UIManager.h"
19 | #include "UIMarkup.h"
20 | #include "UIDlgBuilder.h"
21 | #include "UIVerticalLayout.h"
22 | #include "UIHorizontalLayout.h"
23 | #include "UISystemControls.h"
24 |
25 | namespace SdkLayout{
26 |
27 | class IDialogBuilder_GetID
28 | {
29 | public:
30 | virtual UINT get_ctrl_id(LPCTSTR name) const = 0;
31 | };
32 |
33 | class CSdkLayout
34 | {
35 | public:
36 | CSdkLayout(){ m_hWnd = NULL; m_pRoot = NULL; m_getid = NULL;}
37 | ~CSdkLayout(){DeleteLayout();}
38 | HWND GetHWND() const {return m_hWnd;}
39 | CContainerUI* GetRoot() const {return m_pRoot;}
40 | const SIZE& GetPostSize() const
41 | {
42 | assert(m_pRoot);
43 | assert(m_pRoot->GetAt(0));
44 | return m_pRoot->GetAt(0)->GetPostSize();
45 | }
46 | void ProcessScrollMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
47 | CPaintManagerUI* GetManager() {return &m_Manager;}
48 | bool SetLayout(HWND hWnd, LPCTSTR xml, HINSTANCE hInst=NULL);
49 | bool SetLayout(HWND hWnd, UINT id, HINSTANCE hInst=NULL);
50 | void SetDlgGetID(IDialogBuilder_GetID* pgetid){ m_getid = pgetid; }
51 | void DeleteLayout();
52 | void ResizeLayout(const RECT& rc);
53 | void ResizeLayout();
54 | CControlUI* FindControl(LPCTSTR name);
55 | CControlUI* FindControl(HWND hwnd);
56 | void SetDefFont(LPCTSTR face, int sz);
57 |
58 | private:
59 | void _InitializeLayout();
60 | void _ProcessScrollBar(const CDuiRect& rc);
61 |
62 | private:
63 | HWND m_hWnd;
64 | CContainerUI* m_pRoot;
65 | CPaintManagerUI m_Manager;
66 | CDuiRect m_rcLast;
67 | IDialogBuilder_GetID* m_getid;
68 | };
69 |
70 | }
71 |
72 | #endif
73 |
74 | #if defined(__cplusplus)
75 | typedef SdkLayout::CSdkLayout sdklayout;
76 | typedef SdkLayout::CControlUI sdkcontrol;
77 | #else
78 | typedef struct sdklayout sdklayout;
79 | typedef struct sdkcontrol sdkcontrol;
80 | #endif
81 |
82 | #ifdef __cplusplus
83 | EXTERN_C {
84 | #endif
85 |
86 | sdklayout* layout_new(HWND hWnd, LPCTSTR xml, HINSTANCE hInst);
87 | void layout_delete(sdklayout* layout);
88 | sdkcontrol* layout_root(sdklayout* layout);
89 | void layout_post_size(sdklayout* layout, int* x, int* y);
90 | void layout_scroll(sdklayout* layout, UINT uMsg, WPARAM wParam, LPARAM lParam);
91 | void layout_resize(sdklayout* layout, SIZE* sz);
92 | sdkcontrol* layout_control(sdklayout* layout, LPCTSTR name);
93 | void layout_visible(sdkcontrol* ctrl, BOOL bVisible);
94 | void layout_deffont(sdklayout* layout, const char* face, int sz);
95 | int layout_newfont(sdklayout* layout, const char* face, int sz);
96 | void layout_setfont(sdkcontrol* ctrl, int id);
97 |
98 | #ifdef __cplusplus
99 | }
100 | #endif
101 |
102 | #endif // !__SDK_LAYOUT_H__
103 |
--------------------------------------------------------------------------------
/src/sdklayout/UIContainer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/sdklayout/UIContainer.cpp
--------------------------------------------------------------------------------
/src/sdklayout/UIContainer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/sdklayout/UIContainer.h
--------------------------------------------------------------------------------
/src/sdklayout/UIControl.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 |
3 | namespace SdkLayout {
4 |
5 | CControlUI::CControlUI() :
6 | m_bInited(false),
7 | m_bVisible(true),
8 | m_bVisibleByParent(true),
9 | m_bDisplayed(true),
10 | m_id(0),
11 | m_name(""),
12 | m_font(-1),
13 | m_pManager(NULL),
14 | m_pParent(NULL),
15 | m_ud(0)
16 | {
17 | m_cXY.cx = m_cXY.cy = 0;
18 | m_cxyFixed.cx = m_cxyFixed.cy = 0;
19 | m_cxyMin.cx = m_cxyMin.cy = 0;
20 | m_cxyMax.cx = m_cxyMax.cy = 9999;
21 | m_szPostSize.cx = m_szPostSize.cy = 0;
22 |
23 | ::ZeroMemory(&m_rcItem, sizeof(RECT));
24 | ::ZeroMemory(&m_rcInset, sizeof(m_rcInset)); // class object
25 | }
26 |
27 | CControlUI::~CControlUI()
28 | {
29 | }
30 |
31 | void CControlUI::DoInit()
32 | {
33 | assert(m_pManager != NULL);
34 | m_bInited = true;
35 | }
36 |
37 | bool CControlUI::SetFocus()
38 | {
39 | if(::IsWindow(GetHWND())){
40 | ::SetFocus(GetHWND());
41 | return true;
42 | }
43 | else{
44 | return false;
45 | }
46 | }
47 |
48 | const CDuiRect& CControlUI::GetPos() const
49 | {
50 | return m_rcItem;
51 | }
52 |
53 | void CControlUI::SetPos(const CDuiRect& rc)
54 | {
55 | m_rcItem = rc;
56 | if(m_rcItem.right < m_rcItem.left) m_rcItem.right = m_rcItem.left;
57 | if(m_rcItem.bottom< m_rcItem.top) m_rcItem.bottom = m_rcItem.top;
58 |
59 | SIZE tmpsz = {m_rcItem.GetWidth(), m_rcItem.GetHeight()};
60 | SetPostSize(tmpsz);
61 |
62 | if(!IsWindow(m_hWnd) || m_rcItem.IsNull())
63 | return;
64 |
65 | CDuiRect rct = m_rcItem;
66 | rct = m_rcItem;
67 |
68 | rct.left += m_rcInset.left;
69 | rct.top += m_rcInset.top;
70 | rct.right -= m_rcInset.right;
71 | rct.bottom -= m_rcInset.bottom;
72 |
73 | ::SetWindowPos(m_hWnd, 0, rct.left, rct.top, rct.GetWidth(), rct.GetHeight(), SWP_NOZORDER);
74 | }
75 |
76 | int CControlUI::GetWidth() const
77 | {
78 | return m_rcItem.right - m_rcItem.left;
79 | }
80 |
81 | int CControlUI::GetHeight() const
82 | {
83 | return m_rcItem.bottom - m_rcItem.top;
84 | }
85 |
86 | int CControlUI::GetX() const
87 | {
88 | return m_rcItem.left;
89 | }
90 |
91 | int CControlUI::GetY() const
92 | {
93 | return m_rcItem.top;
94 | }
95 |
96 | SIZE CControlUI::GetFixedXY() const
97 | {
98 | return m_cXY;
99 | }
100 |
101 | void CControlUI::SetFixedXY(SIZE szXY)
102 | {
103 | m_cXY.cx = szXY.cx;
104 | m_cXY.cy = szXY.cy;
105 | }
106 |
107 | int CControlUI::GetFixedWidth() const
108 | {
109 | return m_cxyFixed.cx;
110 | }
111 |
112 | void CControlUI::SetFixedWidth(int cx)
113 | {
114 | if( cx < 0 ) return;
115 | m_cxyFixed.cx = cx;
116 | }
117 |
118 | int CControlUI::GetFixedHeight() const
119 | {
120 | return m_cxyFixed.cy;
121 | }
122 |
123 | void CControlUI::SetFixedHeight(int cy)
124 | {
125 | if( cy < 0 ) return;
126 | m_cxyFixed.cy = cy;
127 | }
128 |
129 | int CControlUI::GetMinWidth() const
130 | {
131 | return m_cxyMin.cx;
132 | }
133 |
134 | void CControlUI::SetMinWidth(int cx)
135 | {
136 | if( cx < 0 ) return;
137 | m_cxyMin.cx = cx;
138 | }
139 |
140 | int CControlUI::GetMaxWidth() const
141 | {
142 | return m_cxyMax.cx;
143 | }
144 |
145 | void CControlUI::SetMaxWidth(int cx)
146 | {
147 | if( cx < 0 ) return;
148 | m_cxyMax.cx = cx;
149 | }
150 |
151 | int CControlUI::GetMinHeight() const
152 | {
153 | return m_cxyMin.cy;
154 | }
155 |
156 | void CControlUI::SetMinHeight(int cy)
157 | {
158 | if( cy < 0 ) return;
159 | m_cxyMin.cy = cy;
160 | }
161 |
162 | int CControlUI::GetMaxHeight() const
163 | {
164 | return m_cxyMax.cy;
165 | }
166 |
167 | void CControlUI::SetMaxHeight(int cy)
168 | {
169 | if( cy < 0 ) return;
170 | m_cxyMax.cy = cy;
171 | }
172 |
173 | void CControlUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
174 | {
175 | if( _tcscmp(pstrName, _T("id")) == 0 ) SetID(_ttoi(pstrValue));
176 | else if(_tcscmp(pstrName,_T("font")) == 0) SetFont(_ttoi(pstrValue));
177 | else if(_tcscmp(pstrName, _T("name")) == 0) SetName(pstrValue);
178 | else if( _tcscmp(pstrName, _T("width")) == 0 ) SetFixedWidth(_ttoi(pstrValue));
179 | else if( _tcscmp(pstrName, _T("height")) == 0 ) SetFixedHeight(_ttoi(pstrValue));
180 | else if( _tcscmp(pstrName, _T("minwidth")) == 0 ) SetMinWidth(_ttoi(pstrValue));
181 | else if( _tcscmp(pstrName, _T("minheight")) == 0 ) SetMinHeight(_ttoi(pstrValue));
182 | else if( _tcscmp(pstrName, _T("maxwidth")) == 0 ) SetMaxWidth(_ttoi(pstrValue));
183 | else if( _tcscmp(pstrName, _T("maxheight")) == 0 ) SetMaxHeight(_ttoi(pstrValue));
184 | else if( _tcscmp(pstrName, _T("inset")) == 0) {
185 | RECT rcInset = { 0 };
186 | LPTSTR pstr = NULL;
187 | rcInset.left = _tcstol(pstrValue, &pstr, 10);
188 | rcInset.top = _tcstol(pstr + 1, &pstr, 10);
189 | rcInset.right = _tcstol(pstr + 1, &pstr, 10);
190 | rcInset.bottom = _tcstol(pstr + 1, &pstr, 10);
191 | SetInset(rcInset);
192 | }
193 | else if(_tcscmp(pstrName, _T("visible")) == 0){
194 | bool bVisible = _tcscmp(pstrValue, _T("true"))==0;
195 | SetVisible(bVisible);
196 | }
197 | else if(_tcscmp(pstrName, _T("display")) == 0) SetDisplayed(_tcscmp(pstrValue, _T("true"))==0);
198 | else{
199 | #ifdef _DEBUG
200 | MessageBox(NULL, pstrValue, pstrName, MB_ICONEXCLAMATION);
201 | #endif
202 | }
203 | }
204 |
205 | SIZE CControlUI::EstimateSize(SIZE szAvailable)
206 | {
207 | return m_cxyFixed;
208 | }
209 |
210 | CControlUI* CControlUI::FindControl(LPCTSTR name)
211 | {
212 | return name == m_name ? this : NULL;
213 | }
214 |
215 | CControlUI* CControlUI::FindControl(HWND hwnd)
216 | {
217 | return hwnd == m_hWnd ? this : NULL;
218 | }
219 |
220 | void CControlUI::SetFont( int id )
221 | {
222 | if(id != -2)
223 | m_font = id;
224 | if(IsWindow(GetHWND()) && m_pManager){
225 | HFONT hFont = m_font==-1 ? m_pManager->GetDefaultFont() : m_pManager->GetFont(m_font);
226 | SendMessage(m_hWnd, WM_SETFONT, WPARAM(hFont), MAKELPARAM(TRUE,0));
227 | }
228 | }
229 |
230 | void CControlUI::SetManager(CPaintManagerUI* mgr)
231 | {
232 | m_pManager = mgr;
233 | if (m_id <= 0){
234 | m_hWnd = NULL;
235 | }
236 | else if (m_id > 0){
237 | m_hWnd = GetDlgItem(m_pManager->GetHWND(), m_id);
238 | assert(m_hWnd != 0);
239 | }
240 | }
241 |
242 | void CControlUI::NeedParentUpdate()
243 | {
244 | if (!m_bInited)
245 | return;
246 | if (GetParent())
247 | GetParent()->NeedUpdate();
248 | else
249 | NeedUpdate(); // root only
250 | }
251 |
252 | } // namespace SdkLayout
253 |
--------------------------------------------------------------------------------
/src/sdklayout/UIControl.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/sdklayout/UIControl.h
--------------------------------------------------------------------------------
/src/sdklayout/UIDlgBuilder.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/sdklayout/UIDlgBuilder.cpp
--------------------------------------------------------------------------------
/src/sdklayout/UIDlgBuilder.h:
--------------------------------------------------------------------------------
1 | #ifndef __UIDLGBUILDER_H__
2 | #define __UIDLGBUILDER_H__
3 |
4 | #pragma once
5 |
6 | namespace SdkLayout {
7 |
8 | class IDialogBuilder_GetID;
9 |
10 | class CDialogBuilder
11 | {
12 | public:
13 | CContainerUI* Create(LPCTSTR xml, CPaintManagerUI* manager, HINSTANCE hInst = NULL, IDialogBuilder_GetID* pgetid=0);
14 |
15 | private:
16 | CControlUI* _Parse(CMarkupNode* parent, CContainerUI* pParent = NULL);
17 |
18 | CMarkup m_xml;
19 | CPaintManagerUI* m_pManager;
20 | IDialogBuilder_GetID* m_getid;
21 | };
22 |
23 | } // namespace SdkLayout
24 |
25 | #endif // __UIDLGBUILDER_H__
26 |
--------------------------------------------------------------------------------
/src/sdklayout/UIHorizontalLayout.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "UIHorizontalLayout.h"
3 |
4 | namespace SdkLayout
5 | {
6 | void CHorizontalLayoutUI::SetPos(const CDuiRect& rc)
7 | {
8 | CControlUI::SetPos(rc);
9 |
10 | if( m_items.IsEmpty() ) return;
11 |
12 | CDuiRect rct = m_rcItem;
13 | rct.left += m_rcInset.left;
14 | rct.top += m_rcInset.top;
15 | rct.right -= m_rcInset.right;
16 | rct.bottom -= m_rcInset.bottom;
17 |
18 | // Determine the width of elements that are sizeable
19 | SIZE szAvailable = {rct.GetWidth(), rct.GetHeight()};
20 |
21 | int nAdjustables = 0;
22 | int cxFixed = 0;
23 | int nEstimateNum = 0;
24 | for( int it1 = 0; it1 < m_items.GetSize(); it1++ ) {
25 | CControlUI* pControl = static_cast(m_items[it1]);
26 | if( !pControl->IsVisible() ) continue;
27 | SIZE sz = pControl->EstimateSize(szAvailable);
28 | if( sz.cx == 0 ) {
29 | nAdjustables++;
30 | }
31 | else {
32 | if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
33 | if( sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
34 | }
35 | cxFixed += sz.cx;
36 | nEstimateNum++;
37 | }
38 |
39 | int cxExpand = 0;
40 | int cxNeeded = 0;
41 | if( nAdjustables > 0 ) cxExpand = MAX(0, (szAvailable.cx - cxFixed) / nAdjustables);
42 | // Position the elements
43 | SIZE szRemaining = szAvailable;
44 | int iPosX = rct.left;
45 | int iAdjustable = 0;
46 | int cxFixedRemaining = cxFixed;
47 | for( int it2 = 0; it2 < m_items.GetSize(); it2++ ) {
48 | CControlUI* pControl = static_cast(m_items[it2]);
49 | if( !pControl->IsVisible() ) continue;
50 |
51 | SIZE sz = pControl->EstimateSize(szRemaining);
52 | if( sz.cx == 0 ) {
53 | iAdjustable++;
54 | sz.cx = cxExpand;
55 | // Distribute remaining to last element (usually round-off left-overs)
56 | if( iAdjustable == nAdjustables ) {
57 | sz.cx = MAX(0, szRemaining.cx - cxFixedRemaining);
58 | }
59 | if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
60 | if( sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
61 | }
62 | else {
63 | if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
64 | if( sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
65 |
66 | cxFixedRemaining -= sz.cx;
67 | }
68 |
69 | sz.cy = pControl->GetFixedHeight();
70 | if( sz.cy == 0 ) sz.cy = rct.bottom - rct.top;
71 | if( sz.cy < 0 ) sz.cy = 0;
72 | if( sz.cy < pControl->GetMinHeight() ) sz.cy = pControl->GetMinHeight();
73 | if( sz.cy > pControl->GetMaxHeight() ) sz.cy = pControl->GetMaxHeight();
74 |
75 | RECT rcCtrl = { iPosX, rct.top, iPosX + sz.cx, rct.top + sz.cy};
76 | pControl->SetPos(rcCtrl);
77 | iPosX += sz.cx;
78 | cxNeeded += sz.cx;
79 | szRemaining.cx -= sz.cx;
80 | }
81 |
82 | SIZE sztmp = {cxNeeded, m_rcItem.GetHeight()};
83 | sztmp.cx += m_rcInset.left + m_rcInset.right;
84 | SetPostSize(sztmp);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/sdklayout/UIHorizontalLayout.h:
--------------------------------------------------------------------------------
1 | #ifndef __UIHORIZONTALLAYOUT_H__
2 | #define __UIHORIZONTALLAYOUT_H__
3 |
4 | #pragma once
5 |
6 | namespace SdkLayout
7 | {
8 | class CHorizontalLayoutUI : public CContainerUI
9 | {
10 | public:
11 | virtual LPCTSTR GetClass() const {return GetClassStatic();}
12 | static LPCTSTR GetClassStatic() {return _T("Horizontal");}
13 |
14 | virtual void SetPos(const CDuiRect& rc);
15 | };
16 | }
17 | #endif // __UIHORIZONTALLAYOUT_H__
18 |
--------------------------------------------------------------------------------
/src/sdklayout/UIManager.cpp:
--------------------------------------------------------------------------------
1 | #include "StdAfx.h"
2 |
3 | namespace SdkLayout {
4 |
5 | CPaintManagerUI::CPaintManagerUI()
6 | {
7 | LOGFONT lf = { 0 };
8 | ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
9 | lf.lfCharSet = DEFAULT_CHARSET;
10 | m_DefaultFontInfo = ::CreateFontIndirect(&lf);
11 | m_szInitSize.cx = m_szInitSize.cy = 500;
12 | }
13 |
14 | CPaintManagerUI::~CPaintManagerUI()
15 | {
16 | ::DeleteObject(m_DefaultFontInfo);
17 | RemoveAllFonts();
18 | }
19 |
20 | HFONT CPaintManagerUI::GetDefaultFont()
21 | {
22 | return m_DefaultFontInfo;
23 | }
24 |
25 | void CPaintManagerUI::SetDefaultFont( LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic )
26 | {
27 | if(m_DefaultFontInfo) ::DeleteObject(m_DefaultFontInfo);
28 |
29 | LOGFONT lf = { 0 };
30 | ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
31 | _tcsncpy(lf.lfFaceName, pStrFontName, LF_FACESIZE);
32 | lf.lfCharSet = DEFAULT_CHARSET;
33 | lf.lfHeight = -nSize;
34 | if( bBold ) lf.lfWeight += FW_BOLD;
35 | if( bUnderline ) lf.lfUnderline = TRUE;
36 | if( bItalic ) lf.lfItalic = TRUE;
37 | m_DefaultFontInfo = ::CreateFontIndirect(&lf);
38 | }
39 |
40 | DWORD CPaintManagerUI::GetCustomFontCount() const
41 | {
42 | return m_aCustomFonts.GetSize();
43 | }
44 |
45 | HFONT CPaintManagerUI::AddFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic)
46 | {
47 | LOGFONT lf = { 0 };
48 | ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
49 | _tcsncpy(lf.lfFaceName, pStrFontName, LF_FACESIZE);
50 | lf.lfCharSet = DEFAULT_CHARSET;
51 | lf.lfHeight = -nSize;
52 | if( bBold ) lf.lfWeight += FW_BOLD;
53 | if( bUnderline ) lf.lfUnderline = TRUE;
54 | if( bItalic ) lf.lfItalic = TRUE;
55 | HFONT hFont = ::CreateFontIndirect(&lf);
56 | if( hFont == NULL ) return NULL;
57 |
58 | if( !m_aCustomFonts.Add(hFont) ) {
59 | ::DeleteObject(hFont);
60 | return NULL;
61 | }
62 | return hFont;
63 | }
64 |
65 | bool CPaintManagerUI::RemoveFont(HFONT hFont)
66 | {
67 | for( int it = 0; it < m_aCustomFonts.GetSize(); it++ ) {
68 | HFONT hFont2 = static_cast(m_aCustomFonts[it]);
69 | if( hFont == hFont2 ) {
70 | ::DeleteObject(hFont);
71 | return m_aCustomFonts.Remove(it);
72 | }
73 | }
74 | return false;
75 | }
76 |
77 | void CPaintManagerUI::RemoveAllFonts()
78 | {
79 | for( int it = 0; it < m_aCustomFonts.GetSize(); it++ ) {
80 | HFONT hFont = static_cast(m_aCustomFonts[it]);
81 | ::DeleteObject(hFont);
82 | }
83 | m_aCustomFonts.Empty();
84 | }
85 |
86 | HFONT CPaintManagerUI::GetFont( int index )
87 | {
88 | if( index < 0 || index >= m_aCustomFonts.GetSize() ) return GetDefaultFont();
89 | return static_cast(m_aCustomFonts[index]);
90 | }
91 |
92 | int CPaintManagerUI::GetFont(HFONT hFont)
93 | {
94 | for( int it = 0; it < m_aCustomFonts.GetSize(); it++ ) {
95 | HFONT hF = static_cast(m_aCustomFonts[it]);
96 | if(hFont == hF)
97 | return it;
98 | }
99 | return -1;
100 | }
101 |
102 | } // namespace SdkLayout
103 |
--------------------------------------------------------------------------------
/src/sdklayout/UIManager.h:
--------------------------------------------------------------------------------
1 | #ifndef __UIMANAGER_H__
2 | #define __UIMANAGER_H__
3 |
4 | #pragma once
5 |
6 | namespace SdkLayout {
7 | /////////////////////////////////////////////////////////////////////////////////////
8 | //
9 |
10 | class CControlUI;
11 |
12 | class CPaintManagerUI
13 | {
14 | public:
15 | CPaintManagerUI();
16 | ~CPaintManagerUI();
17 |
18 | public:
19 | HFONT GetDefaultFont();
20 | void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
21 | DWORD GetCustomFontCount() const;
22 | HFONT AddFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
23 | bool RemoveFont(HFONT hFont);
24 | void RemoveAllFonts();
25 | HFONT GetFont(int index);
26 | int GetFont(HFONT hFont);
27 | void SetHWND(HWND hwnd) {m_hWnd = hwnd;}
28 | HWND GetHWND() {return m_hWnd;}
29 | SIZE& InitSize() { return m_szInitSize; }
30 |
31 | private:
32 | HWND m_hWnd;
33 | HFONT m_DefaultFontInfo;
34 | CStdPtrArray m_aCustomFonts;
35 | SIZE m_szInitSize;
36 | };
37 |
38 | } // namespace SdkLayout
39 |
40 | #endif // __UIMANAGER_H__
41 |
--------------------------------------------------------------------------------
/src/sdklayout/UIMarkup.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/sdklayout/UIMarkup.cpp
--------------------------------------------------------------------------------
/src/sdklayout/UIMarkup.h:
--------------------------------------------------------------------------------
1 | #ifndef __UIMARKUP_H__
2 | #define __UIMARKUP_H__
3 |
4 | #pragma once
5 |
6 | namespace SdkLayout {
7 |
8 | enum
9 | {
10 | XMLFILE_ENCODING_UTF8 = 0,
11 | XMLFILE_ENCODING_UNICODE = 1,
12 | XMLFILE_ENCODING_ASNI = 2,
13 | };
14 |
15 | class CMarkup;
16 | class CMarkupNode;
17 |
18 |
19 | class CMarkup
20 | {
21 | friend class CMarkupNode;
22 | public:
23 | CMarkup(LPCTSTR pstrXML = NULL);
24 | ~CMarkup();
25 |
26 | bool Load(LPCTSTR pstrXML);
27 | bool LoadFromMem(BYTE* pByte, DWORD dwSize, int encoding = XMLFILE_ENCODING_UTF8);
28 | void Release();
29 | bool IsValid() const;
30 |
31 | void SetPreserveWhitespace(bool bPreserve = true);
32 | void GetLastErrorMessage(LPTSTR pstrMessage, SIZE_T cchMax) const;
33 | void GetLastErrorLocation(LPTSTR pstrSource, SIZE_T cchMax) const;
34 |
35 | CMarkupNode GetRoot();
36 |
37 | private:
38 | typedef struct tagXMLELEMENT
39 | {
40 | ULONG iStart;
41 | ULONG iChild;
42 | ULONG iNext;
43 | ULONG iParent;
44 | ULONG iData;
45 | } XMLELEMENT;
46 |
47 | LPTSTR m_pstrXML;
48 | XMLELEMENT* m_pElements;
49 | ULONG m_nElements;
50 | ULONG m_nReservedElements;
51 | TCHAR m_szErrorMsg[100];
52 | TCHAR m_szErrorXML[50];
53 | bool m_bPreserveWhitespace;
54 |
55 | private:
56 | bool _Parse();
57 | bool _Parse(LPTSTR& pstrText, ULONG iParent);
58 | XMLELEMENT* _ReserveElement();
59 | inline void _SkipWhitespace(LPTSTR& pstr) const;
60 | inline void _SkipWhitespace(LPCTSTR& pstr) const;
61 | inline void _SkipIdentifier(LPTSTR& pstr) const;
62 | inline void _SkipIdentifier(LPCTSTR& pstr) const;
63 | bool _ParseData(LPTSTR& pstrText, LPTSTR& pstrData, char cEnd);
64 | void _ParseMetaChar(LPTSTR& pstrText, LPTSTR& pstrDest);
65 | bool _ParseAttributes(LPTSTR& pstrText);
66 | bool _Failed(LPCTSTR pstrError, LPCTSTR pstrLocation = NULL);
67 | };
68 |
69 |
70 | class CMarkupNode
71 | {
72 | friend class CMarkup;
73 | private:
74 | CMarkupNode();
75 | CMarkupNode(CMarkup* pOwner, int iPos);
76 |
77 | public:
78 | bool IsValid() const;
79 |
80 | CMarkupNode GetParent();
81 | CMarkupNode GetSibling();
82 | CMarkupNode GetChild();
83 | CMarkupNode GetChild(LPCTSTR pstrName);
84 |
85 | bool HasSiblings() const;
86 | bool HasChildren() const;
87 | LPCTSTR GetName() const;
88 | LPCTSTR GetValue() const;
89 |
90 | bool HasAttributes();
91 | bool HasAttribute(LPCTSTR pstrName);
92 | int GetAttributeCount();
93 | LPCTSTR GetAttributeName(int iIndex);
94 | LPCTSTR GetAttributeValue(int iIndex);
95 | LPCTSTR GetAttributeValue(LPCTSTR pstrName);
96 | bool GetAttributeValue(int iIndex, LPTSTR pstrValue, SIZE_T cchMax);
97 | bool GetAttributeValue(LPCTSTR pstrName, LPTSTR pstrValue, SIZE_T cchMax);
98 |
99 | private:
100 | void _MapAttributes();
101 |
102 | enum { MAX_XML_ATTRIBUTES = 64 };
103 |
104 | typedef struct
105 | {
106 | ULONG iName;
107 | ULONG iValue;
108 | } XMLATTRIBUTE;
109 |
110 | int m_iPos;
111 | int m_nAttributes;
112 | XMLATTRIBUTE m_aAttributes[MAX_XML_ATTRIBUTES];
113 | CMarkup* m_pOwner;
114 | };
115 |
116 | } // namespace SdkLayout
117 |
118 | #endif // __UIMARKUP_H__
119 |
--------------------------------------------------------------------------------
/src/sdklayout/UISystemControls.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace SdkLayout{
4 |
5 | bool map_style(DWORD* dwStyle, style_map* known_styles, std::vector& styles)
6 | {
7 | int n = 0;
8 | for (auto& style : styles){
9 | if (style.size()){
10 | for (int i = 0; known_styles[i].strStyle != nullptr; i++){
11 | if (strcmp(known_styles[i].strStyle, style.c_str()) == 0){
12 | *dwStyle |= known_styles[i].dwStyle;
13 | style = "";
14 | n++;
15 | break;
16 | }
17 | }
18 | }
19 | else{
20 | n++;
21 | }
22 | }
23 | return n == styles.size();
24 | }
25 |
26 | CSystemControlUI::CSystemControlUI()
27 | : m_dwStyle(WS_CHILD|WS_VISIBLE)
28 | , m_dwExStyle(0)
29 | {
30 |
31 | }
32 |
33 | void CSystemControlUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
34 | {
35 | if(_tcscmp(pstrName, "text") == 0) m_strText = pstrValue;
36 | else if(_tcscmp(pstrName, "style")==0){
37 | std::vector styles;
38 | split_string(&styles, pstrValue, ',');
39 | SetStyle(styles);
40 | }
41 | else if(_tcscmp(pstrName, "exstyle")==0){
42 | std::vector exstyles;
43 | split_string(&exstyles, pstrValue, ',');
44 | SetStyle(exstyles, true);
45 | }
46 | else CControlUI::SetAttribute(pstrName, pstrValue);
47 | }
48 |
49 | void CSystemControlUI::Create( LPCTSTR lpClass )
50 | {
51 | m_hWnd = ::CreateWindowEx(m_dwExStyle, lpClass, m_strText.c_str(), m_dwStyle,
52 | 0, 0, 0, 0, m_pManager->GetHWND(), HMENU(m_id), GetModuleHandle(0), NULL);
53 | assert(m_hWnd != NULL);
54 | }
55 |
56 | void CSystemControlUI::SetManager(CPaintManagerUI* mgr)
57 | {
58 | m_pManager = mgr;
59 | Create(GetWindowClass());
60 | }
61 |
62 | void CSystemControlUI::SetStyle(std::vector& styles, bool bex)
63 | {
64 | static style_map known_styles[] =
65 | {
66 | { WS_BORDER, "border" },
67 | { WS_CAPTION, "caption" },
68 | { WS_CHILD, "child" },
69 | { WS_CLIPSIBLINGS, "clipsiblings" },
70 | { WS_CLIPCHILDREN, "clipchildren" },
71 | { WS_DISABLED, "disabled" },
72 | { WS_GROUP, "group" },
73 | { WS_HSCROLL, "hscroll" },
74 | { WS_TABSTOP, "tabstop" },
75 | { WS_VSCROLL, "vscroll" },
76 | { 0, nullptr }
77 | };
78 |
79 | static style_map known_ex_styles[] =
80 | {
81 | { WS_EX_ACCEPTFILES, "acceptfiles" },
82 | { WS_EX_CLIENTEDGE, "clientedge" },
83 | { WS_EX_STATICEDGE, "staticedge" },
84 | { WS_EX_TOOLWINDOW, "toolwindow" },
85 | { WS_EX_TOPMOST, "topmost" },
86 | { WS_EX_TRANSPARENT, "transparent" },
87 | { 0, nullptr }
88 | };
89 |
90 | auto ks = bex ? &known_ex_styles[0] : &known_styles[0];
91 | auto& thestyle = bex ? m_dwExStyle : m_dwStyle;
92 | if (!map_style(&thestyle, ks, styles)){
93 | assert(0 && "unknown style detected!");
94 | }
95 | }
96 |
97 | //////////////////////////////////////////////////////////////////////////
98 | void CButtonUI::SetStyle(std::vector& styles, bool bex /*= false*/)
99 | {
100 | static style_map known_styles[] =
101 | {
102 | { BS_MULTILINE, "multiline" },
103 | { 0, nullptr }
104 | };
105 |
106 | static style_map known_ex_styles[] =
107 | {
108 | { 0, nullptr }
109 | };
110 |
111 | auto ks = bex ? &known_ex_styles[0] : &known_styles[0];
112 | auto& thestyle = bex ? m_dwExStyle : m_dwStyle;
113 | if (!map_style(&thestyle, ks, styles)){
114 | return __super::SetStyle(styles, bex);
115 | }
116 | }
117 |
118 | //////////////////////////////////////////////////////////////////////////
119 | COptionUI::COptionUI()
120 | {
121 | m_bHasWsGroup = false;
122 | m_dwStyle |= BS_AUTORADIOBUTTON;
123 | }
124 |
125 | //////////////////////////////////////////////////////////////////////////
126 | void COptionUI::SetStyle(std::vector& styles, bool bex /*= false*/)
127 | {
128 | return __super::SetStyle(styles, bex);
129 | }
130 |
131 | //////////////////////////////////////////////////////////////////////////
132 | CCheckUI::CCheckUI()
133 | {
134 | m_bCheck = false;
135 | m_dwStyle |= BS_AUTOCHECKBOX;
136 | }
137 |
138 | void CCheckUI::SetManager( CPaintManagerUI* mgr )
139 | {
140 | __super::SetManager(mgr);
141 | ::SendMessage(GetHWND(), BM_SETCHECK, m_bCheck ? BST_CHECKED : BST_UNCHECKED, 0);
142 | }
143 |
144 | void CCheckUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
145 | {
146 | if(_tcscmp(pstrName, "checked") == 0) m_bCheck = _tcscmp(pstrValue,"true")==0;
147 | else CSystemControlUI::SetAttribute(pstrName, pstrValue);
148 | }
149 |
150 | //////////////////////////////////////////////////////////////////////////
151 | CGroupUI::CGroupUI()
152 | {
153 | m_dwStyle |= BS_GROUPBOX;
154 | }
155 |
156 | //////////////////////////////////////////////////////////////////////////
157 | CEditUI::CEditUI()
158 | {
159 | m_dwStyle |= ES_AUTOHSCROLL | ES_AUTOVSCROLL;
160 | }
161 |
162 | void CEditUI::SetStyle(std::vector& styles, bool bex /*= false*/)
163 | {
164 | static style_map known_styles[] =
165 | {
166 | { ES_CENTER, "center" },
167 | { ES_MULTILINE, "multiline" },
168 | { ES_NOHIDESEL, "nohidesel" },
169 | { ES_NUMBER, "number" },
170 | { ES_READONLY, "readonly" },
171 | { ES_WANTRETURN, "wantreturn" },
172 | { 0, nullptr }
173 | };
174 |
175 | static style_map known_ex_styles[] =
176 | {
177 | { 0, nullptr }
178 | };
179 |
180 | auto ks = bex ? &known_ex_styles[0] : &known_styles[0];
181 | auto& thestyle = bex ? m_dwExStyle : m_dwStyle;
182 | if (!map_style(&thestyle, ks, styles)){
183 | return __super::SetStyle(styles, bex);
184 | }
185 | }
186 |
187 |
188 |
189 | }
190 |
191 |
--------------------------------------------------------------------------------
/src/sdklayout/UISystemControls.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/movsb/common/196b8434965500f798f824bbd60ba58a57a0d194/src/sdklayout/UISystemControls.h
--------------------------------------------------------------------------------
/src/sdklayout/UIVerticalLayout.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "UIVerticalLayout.h"
3 |
4 | namespace SdkLayout
5 | {
6 | void CVerticalLayoutUI::SetPos(const CDuiRect& rc)
7 | {
8 | CControlUI::SetPos(rc);
9 |
10 | if( m_items.IsEmpty() ) return;
11 |
12 | CDuiRect rct = m_rcItem;
13 | rct.left += m_rcInset.left;
14 | rct.top += m_rcInset.top;
15 | rct.right -= m_rcInset.right;
16 | rct.bottom -= m_rcInset.bottom;
17 |
18 | // Determine the width of elements that are sizeable
19 | SIZE szAvailable = {rct.GetWidth(), rct.GetHeight()};
20 | int nAdjustables = 0;
21 | int cyFixed = 0;
22 | int nEstimateNum = 0;
23 | for( int it1 = 0; it1 < m_items.GetSize(); it1++ ) {
24 | CControlUI* pControl = static_cast(m_items[it1]);
25 | if( !pControl->IsVisible() ) continue;
26 | SIZE sz = pControl->EstimateSize(szAvailable);
27 | if( sz.cy == 0 ) {
28 | nAdjustables++;
29 | }
30 | else {
31 | if( sz.cy < pControl->GetMinHeight() ) sz.cy = pControl->GetMinHeight();
32 | if( sz.cy > pControl->GetMaxHeight() ) sz.cy = pControl->GetMaxHeight();
33 | }
34 | cyFixed += sz.cy;
35 | nEstimateNum++;
36 | }
37 |
38 | // Place elements
39 | int cyNeeded = 0;
40 | int cyExpand = 0;
41 | if( nAdjustables > 0 ) cyExpand = MAX(0, (szAvailable.cy - cyFixed) / nAdjustables);
42 | // Position the elements
43 | SIZE szRemaining = szAvailable;
44 | int iPosY = rct.top;
45 | int iPosX = rct.left;
46 | int iAdjustable = 0;
47 | int cyFixedRemaining = cyFixed;
48 | for( int it2 = 0; it2 < m_items.GetSize(); it2++ ) {
49 | CControlUI* pControl = static_cast(m_items[it2]);
50 | if( !pControl->IsVisible() ) continue;
51 |
52 | SIZE sz = pControl->EstimateSize(szRemaining);
53 | if( sz.cy == 0 ) {
54 | iAdjustable++;
55 | sz.cy = cyExpand;
56 | // Distribute remaining to last element (usually round-off left-overs)
57 | if( iAdjustable == nAdjustables ) {
58 | sz.cy = MAX(0, szRemaining.cy - cyFixedRemaining);
59 | }
60 | if( sz.cy < pControl->GetMinHeight() ) sz.cy = pControl->GetMinHeight();
61 | if( sz.cy > pControl->GetMaxHeight() ) sz.cy = pControl->GetMaxHeight();
62 | }
63 | else {
64 | if( sz.cy < pControl->GetMinHeight() ) sz.cy = pControl->GetMinHeight();
65 | if( sz.cy > pControl->GetMaxHeight() ) sz.cy = pControl->GetMaxHeight();
66 | cyFixedRemaining -= sz.cy;
67 | }
68 |
69 | sz.cx = pControl->GetFixedWidth();
70 | if( sz.cx == 0 ) sz.cx = szAvailable.cx;
71 | if( sz.cx < 0 ) sz.cx = 0;
72 | if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
73 | if( sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
74 |
75 | RECT rcCtrl = { iPosX, iPosY, iPosX + sz.cx, iPosY + sz.cy};
76 | pControl->SetPos(rcCtrl);
77 |
78 | iPosY += sz.cy;
79 | cyNeeded += sz.cy ;
80 | szRemaining.cy -= sz.cy;
81 | }
82 |
83 | SIZE sztmp = {m_rcItem.GetWidth(), cyNeeded};
84 | sztmp.cy += m_rcInset.top + m_rcInset.bottom;
85 | SetPostSize(sztmp);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/sdklayout/UIVerticalLayout.h:
--------------------------------------------------------------------------------
1 | #ifndef __UIVERTICALLAYOUT_H__
2 | #define __UIVERTICALLAYOUT_H__
3 |
4 | #pragma once
5 |
6 | namespace SdkLayout
7 | {
8 | class CVerticalLayoutUI : public CContainerUI
9 | {
10 | public:
11 | virtual LPCTSTR GetClass() const {return GetClassStatic();}
12 | static LPCTSTR GetClassStatic() {return _T("Vertical");}
13 |
14 | virtual void SetPos(const CDuiRect& rc);
15 | };
16 | }
17 | #endif // __UIVERTICALLAYOUT_H__
18 |
--------------------------------------------------------------------------------
/src/sdklayout/uiUtils.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | namespace SdkLayout
4 | {
5 | UINT HashKey(LPCTSTR Key)
6 | {
7 | UINT i = 0;
8 | SIZE_T len = _tcslen(Key);
9 | while( len-- > 0 ) i = (i << 5) + i + Key[len];
10 | return i;
11 | }
12 |
13 | void split_string(std::vector* vec, const char* str, char delimiter)
14 | {
15 | const char* p = str;
16 | std::string tmp;
17 | for (;;){
18 | if (*p){
19 | if (*p != delimiter){
20 | tmp += *p;
21 | p++;
22 | continue;
23 | }
24 | else{
25 | vec->push_back(tmp);
26 | tmp = "";
27 | p++;
28 | continue;
29 | }
30 | }
31 | else{
32 | if (tmp.size()) vec->push_back(tmp);
33 | break;
34 | }
35 | }
36 | }
37 |
38 | /////////////////////////////////////////////////////////////////////////////////////
39 | //
40 | //
41 |
42 | CDuiRect::CDuiRect()
43 | {
44 | left = top = right = bottom = 0;
45 | }
46 |
47 | CDuiRect::CDuiRect(const RECT& src)
48 | {
49 | left = src.left;
50 | top = src.top;
51 | right = src.right;
52 | bottom = src.bottom;
53 | }
54 |
55 | CDuiRect::CDuiRect(int iLeft, int iTop, int iRight, int iBottom)
56 | {
57 | left = iLeft;
58 | top = iTop;
59 | right = iRight;
60 | bottom = iBottom;
61 | }
62 |
63 | int CDuiRect::GetWidth() const
64 | {
65 | return right - left;
66 | }
67 |
68 | int CDuiRect::GetHeight() const
69 | {
70 | return bottom - top;
71 | }
72 |
73 | void CDuiRect::Empty()
74 | {
75 | left = top = right = bottom = 0;
76 | }
77 |
78 | bool CDuiRect::IsNull() const
79 | {
80 | return (left == 0 && right == 0 && top == 0 && bottom == 0);
81 | }
82 |
83 | void CDuiRect::Join(const RECT& rc)
84 | {
85 | if( rc.left < left ) left = rc.left;
86 | if( rc.top < top ) top = rc.top;
87 | if( rc.right > right ) right = rc.right;
88 | if( rc.bottom > bottom ) bottom = rc.bottom;
89 | }
90 |
91 | void CDuiRect::ResetOffset()
92 | {
93 | ::OffsetRect(this, -left, -top);
94 | }
95 |
96 | void CDuiRect::Normalize()
97 | {
98 | if( left > right ) { int iTemp = left; left = right; right = iTemp; }
99 | if( top > bottom ) { int iTemp = top; top = bottom; bottom = iTemp; }
100 | }
101 |
102 | void CDuiRect::Offset(int cx, int cy)
103 | {
104 | ::OffsetRect(this, cx, cy);
105 | }
106 |
107 | void CDuiRect::Inflate(int cx, int cy)
108 | {
109 | ::InflateRect(this, cx, cy);
110 | }
111 |
112 | void CDuiRect::Deflate(int cx, int cy)
113 | {
114 | ::InflateRect(this, -cx, -cy);
115 | }
116 |
117 | void CDuiRect::Union(CDuiRect& rc)
118 | {
119 | ::UnionRect(this, this, &rc);
120 | }
121 |
122 | /////////////////////////////////////////////////////////////////////////////////////
123 | //
124 | //
125 |
126 | CStdPtrArray::CStdPtrArray(int iPreallocSize) : m_ppVoid(NULL), m_nCount(0), m_nAllocated(iPreallocSize)
127 | {
128 | if( iPreallocSize > 0 ) m_ppVoid = static_cast(malloc(iPreallocSize * sizeof(LPVOID)));
129 | }
130 |
131 | CStdPtrArray::CStdPtrArray(const CStdPtrArray& src) : m_ppVoid(NULL), m_nCount(0), m_nAllocated(0)
132 | {
133 | for(int i=0; i(malloc(iSize * sizeof(LPVOID)));
153 | ::ZeroMemory(m_ppVoid, iSize * sizeof(LPVOID));
154 | m_nAllocated = iSize;
155 | m_nCount = iSize;
156 | }
157 |
158 | bool CStdPtrArray::IsEmpty() const
159 | {
160 | return m_nCount == 0;
161 | }
162 |
163 | bool CStdPtrArray::Add(LPVOID pData)
164 | {
165 | if( ++m_nCount >= m_nAllocated) {
166 | int nAllocated = m_nAllocated * 2;
167 | if( nAllocated == 0 ) nAllocated = 11;
168 | LPVOID* ppVoid = static_cast(realloc(m_ppVoid, nAllocated * sizeof(LPVOID)));
169 | if( ppVoid != NULL ) {
170 | m_nAllocated = nAllocated;
171 | m_ppVoid = ppVoid;
172 | }
173 | else {
174 | --m_nCount;
175 | return false;
176 | }
177 | }
178 | m_ppVoid[m_nCount - 1] = pData;
179 | return true;
180 | }
181 |
182 | bool CStdPtrArray::InsertAt(int iIndex, LPVOID pData)
183 | {
184 | if( iIndex == m_nCount ) return Add(pData);
185 | if( iIndex < 0 || iIndex > m_nCount ) return false;
186 | if( ++m_nCount >= m_nAllocated) {
187 | int nAllocated = m_nAllocated * 2;
188 | if( nAllocated == 0 ) nAllocated = 11;
189 | LPVOID* ppVoid = static_cast(realloc(m_ppVoid, nAllocated * sizeof(LPVOID)));
190 | if( ppVoid != NULL ) {
191 | m_nAllocated = nAllocated;
192 | m_ppVoid = ppVoid;
193 | }
194 | else {
195 | --m_nCount;
196 | return false;
197 | }
198 | }
199 | memmove(&m_ppVoid[iIndex + 1], &m_ppVoid[iIndex], (m_nCount - iIndex - 1) * sizeof(LPVOID));
200 | m_ppVoid[iIndex] = pData;
201 | return true;
202 | }
203 |
204 | bool CStdPtrArray::SetAt(int iIndex, LPVOID pData)
205 | {
206 | if( iIndex < 0 || iIndex >= m_nCount ) return false;
207 | m_ppVoid[iIndex] = pData;
208 | return true;
209 | }
210 |
211 | bool CStdPtrArray::Remove(int iIndex)
212 | {
213 | if( iIndex < 0 || iIndex >= m_nCount ) return false;
214 | if( iIndex < --m_nCount ) ::CopyMemory(m_ppVoid + iIndex, m_ppVoid + iIndex + 1, (m_nCount - iIndex) * sizeof(LPVOID));
215 | return true;
216 | }
217 |
218 | int CStdPtrArray::Find(LPVOID pData) const
219 | {
220 | for( int i = 0; i < m_nCount; i++ ) if( m_ppVoid[i] == pData ) return i;
221 | return -1;
222 | }
223 |
224 | int CStdPtrArray::GetSize() const
225 | {
226 | return m_nCount;
227 | }
228 |
229 | LPVOID* CStdPtrArray::GetData()
230 | {
231 | return m_ppVoid;
232 | }
233 |
234 | LPVOID CStdPtrArray::GetAt(int iIndex) const
235 | {
236 | if( iIndex < 0 || iIndex >= m_nCount ) return NULL;
237 | return m_ppVoid[iIndex];
238 | }
239 |
240 | LPVOID CStdPtrArray::operator[] (int iIndex) const
241 | {
242 | return m_ppVoid[iIndex];
243 | }
244 |
245 | //////////////////////////////////////////////////////////////////////////
246 | CTinyString::CTinyString()
247 | {
248 | clear();
249 | }
250 |
251 | CTinyString::CTinyString(LPCTSTR lpsz)
252 | {
253 | _tcsncpy(_szBuff, lpsz, _countof(_szBuff));
254 | }
255 |
256 | const CTinyString& CTinyString::operator=(LPCTSTR lpsz)
257 | {
258 | _tcsncpy(_szBuff, lpsz, _countof(_szBuff));
259 | return *this;
260 | }
261 |
262 | CTinyString::operator LPCTSTR() const
263 | {
264 | return _szBuff;
265 | }
266 |
267 | void CTinyString::clear()
268 | {
269 | *_szBuff = _T('\0');
270 | }
271 |
272 | int CTinyString::size()
273 | {
274 | return _tcslen(_szBuff);
275 | }
276 |
277 | bool CTinyString::empty()
278 | {
279 | return _szBuff[0] == _T('\0');
280 | }
281 |
282 | bool operator==(const CTinyString& lhs, const CTinyString& rhs)
283 | {
284 | return _tcscmp(LPCTSTR(lhs), LPCTSTR(rhs)) == 0;
285 | }
286 |
287 | bool operator==(const CTinyString& lhs, LPCTSTR rhs)
288 | {
289 | return _tcscmp(LPCTSTR(lhs), LPCTSTR(rhs)) == 0;
290 | }
291 |
292 | bool operator==(LPCTSTR lhs, const CTinyString& rhs)
293 | {
294 | return _tcscmp(LPCTSTR(lhs), LPCTSTR(rhs)) == 0;
295 | }
296 |
297 | } // namespace SdkLayout
--------------------------------------------------------------------------------
/src/sdklayout/uiUtils.h:
--------------------------------------------------------------------------------
1 | #ifndef __UTILS_H__
2 | #define __UTILS_H__
3 |
4 | #pragma once
5 |
6 | namespace SdkLayout
7 | {
8 | UINT HashKey(LPCTSTR Key);
9 | void split_string(std::vector* vec, const char* str, char delimiter);
10 |
11 | /////////////////////////////////////////////////////////////////////////////////////
12 | //
13 |
14 | class CDuiRect : public tagRECT
15 | {
16 | public:
17 | CDuiRect();
18 | CDuiRect(const RECT& src);
19 | CDuiRect(int iLeft, int iTop, int iRight, int iBottom);
20 |
21 | int GetWidth() const;
22 | int GetHeight() const;
23 | void Empty();
24 | bool IsNull() const;
25 | void Join(const RECT& rc);
26 | void ResetOffset();
27 | void Normalize();
28 | void Offset(int cx, int cy);
29 | void Inflate(int cx, int cy);
30 | void Deflate(int cx, int cy);
31 | void Union(CDuiRect& rc);
32 | };
33 |
34 | /////////////////////////////////////////////////////////////////////////////////////
35 | //
36 |
37 | class CStdPtrArray
38 | {
39 | public:
40 | CStdPtrArray(int iPreallocSize = 0);
41 | CStdPtrArray(const CStdPtrArray& src);
42 | ~CStdPtrArray();
43 |
44 | void Empty();
45 | void Resize(int iSize);
46 | bool IsEmpty() const;
47 | int Find(LPVOID iIndex) const;
48 | bool Add(LPVOID pData);
49 | bool SetAt(int iIndex, LPVOID pData);
50 | bool InsertAt(int iIndex, LPVOID pData);
51 | bool Remove(int iIndex);
52 | int GetSize() const;
53 | LPVOID* GetData();
54 |
55 | LPVOID GetAt(int iIndex) const;
56 | LPVOID operator[] (int nIndex) const;
57 |
58 | protected:
59 | LPVOID* m_ppVoid;
60 | int m_nCount;
61 | int m_nAllocated;
62 | };
63 |
64 | class CTinyString
65 | {
66 | public:
67 | CTinyString();
68 | CTinyString(LPCTSTR lpsz);
69 | const CTinyString& operator=(LPCTSTR lpsz);
70 | operator LPCTSTR() const;
71 |
72 | void clear();
73 | int size();
74 | bool empty();
75 |
76 | friend bool operator==(const CTinyString& lhs, const CTinyString& rhs);
77 | friend bool operator==(const CTinyString& lhs, LPCTSTR rhs);
78 | friend bool operator==(LPCTSTR lhs, const CTinyString& rhs);
79 |
80 | protected:
81 | TCHAR _szBuff[64];
82 | };
83 |
84 | bool operator==(const CTinyString& lhs, const CTinyString& rhs);
85 | bool operator==(const CTinyString& lhs, LPCTSTR rhs);
86 | bool operator==(LPCTSTR lhs, const CTinyString& rhs);
87 |
88 | }// namespace SdkLayout
89 |
90 | #endif // __UTILS_H__
91 |
--------------------------------------------------------------------------------
/src/stdafx.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 |
--------------------------------------------------------------------------------
/src/stdafx.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifndef __stdafx_120937012387901247_h__
3 | #define __stdafx_120937012387901247_h__
4 |
5 | #include
6 | #include
7 | #include
8 | #include