-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatusControl.cpp
More file actions
165 lines (156 loc) · 5.7 KB
/
statusControl.cpp
File metadata and controls
165 lines (156 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <Windows.h>
#include "appconst.h"
#include "globalVars.h"
#include "nonMenuids.h"
#include "inputLangChange.h"
#include "statusControl.h"
#include "resource1.h"
#include <commctrl.h>
TCHAR *statusControlMessages[] = {
_T("Ready"),
_T("File loaded"),
_T("File saved"),
_T("File quick saved"),
_T("File not saved"),
_T("Snoozing...")
};
void createStatusControl(HWND mainWindow) {
TCHAR lang[129];
staticImageUSA_active = (HICON)LoadImage(ghInstance, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, LR_VGACOLOR);
staticImageRU_active = (HICON)LoadImage(ghInstance, MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON, 16, 16, LR_VGACOLOR);
RECT windowDims;
int msgPartPosX,langPartPosX,linePartPosX,wordsPartPosX,charsPartPosX;
GetClientRect(mainWindow,&windowDims);
msgPartPosX = 100;
langPartPosX = windowDims.right/2;
//linePartPosX = windowDims.right-80;
linePartPosX = langPartPosX + 100;
wordsPartPosX = linePartPosX + 100;
charsPartPosX = wordsPartPosX + 100;
statusBar = CreateWindowEx
(
0,
STATUSCLASSNAME,
NULL,
WS_CHILD |
WS_VISIBLE|
SBARS_SIZEGRIP,
0, 0, 20, 50,
mainWindow, (HMENU)IDC_STATUS_BAR, GetModuleHandle(NULL), NULL);
//int statwidths[] = {msgPartPosX,langPartPosX,linePartPosX,-1};
int statwidths[] = { msgPartPosX,langPartPosX,linePartPosX,wordsPartPosX,charsPartPosX,-1 };
//int statwidths[] = {80, -1}; //fallback, only RDY
SendMessage(statusBar, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);
SendMessage(statusBar, SB_SETTEXT, 0|0, (LPARAM)statusControlMessages[0]);
SendMessage(statusBar, SB_SETTEXT, 1 | 0, (LPARAM)_T("Zoom: 100%"));
//SendMessage(statusBar, SB_SETTEXT, 2|0, (LPARAM)_T("English (U.S.)")); //debug
changeLangStatBar();
//SendMessage(statusBar, SB_SETTEXT, 3|0, (LPARAM)_T("Line: 145"));
SendMessage(statusBar, SB_SETTEXT, 3|0, (LPARAM)_T("Line: 1"));
//SendMessage(statusBar, SB_SETTEXT, 4|0, (LPARAM)_T("Words: 666"));
SendMessage(statusBar, SB_SETTEXT, 5|0, (LPARAM)_T("Chars: 0"));
//index is missing because the adjacent empty space is considered a part for w/e reason
}
void resizeStatusControl(void) {
SendMessage(statusBar, WM_SIZE, 0, 0);
SendMessage(toolBar,TB_AUTOSIZE, 0, 0);
RECT statusDims;
RECT mainWindowDims;
RECT toolbarDims;
GetWindowRect(statusBar, &statusDims);
GetWindowRect(toolBar, &toolbarDims);
GetClientRect(hwnd, &mainWindowDims);
int toolbarHeight = toolbarDims.bottom - toolbarDims.top;
int statusbarHeight = statusDims.bottom - statusDims.top;
int richEditHeight = mainWindowDims.bottom - toolbarHeight - statusbarHeight;
SetWindowPos(richEditControl, NULL, 0, toolbarHeight, mainWindowDims.right, richEditHeight, SWP_NOZORDER);
}
//todo make static text into separate toolbar parts to avoid memory hogging
//10% increment
void changeZoomPartText(void) {
TCHAR value[16];
TCHAR text[8];
TCHAR complete[48];
ZeroMemory(&complete, sizeof(value));
ZeroMemory(&value, sizeof(value));
ZeroMemory(&text,sizeof(text));
double newRatio = ((double)zoomRatio_e/zoomRatio_d);
newRatio*=100;
_tcscat(text,_T("Zoom: "));
_stprintf(value, _T("%.0lf"),newRatio);
_tcscat(value, _T("%"));
_tcscat(complete,text);
_tcscat(complete,value);
SendMessage(statusBar, SB_SETTEXT, 1 | 0, (LPARAM)complete);
}
void changeStatusControlMessage(int msgCode) {
//TONEVERDO delete
//if (msgCode == 4)
//{
//paintStatusSaveWarning();
// }
//else
{
SendMessage(statusBar, SB_SETTEXT, 0, (LPARAM)statusControlMessages[msgCode]);
}
}
//experimental
void paintStatusSaveWarning(void) {
RECT dims;
HDC deviceContext = GetDC(statusBar);
GetClientRect(statusBar,&dims);
SetTextColor(deviceContext, RGB(255,0,0));
SetBkMode(deviceContext,TRANSPARENT);
DrawText(deviceContext,statusControlMessages[4],-1,&dims,DT_SINGLELINE|DT_NOCLIP);
ReleaseDC(statusBar, deviceContext);
}
void changeLangPartIcon(TCHAR *kbdLayOut) {
HICON iconToSet;
if (!_tcscmp(kbdLayOut, _T("English (U.S.)"))) {
iconToSet = staticImageUSA_active;
}
else if(!_tcscmp(kbdLayOut, _T("Russian"))) {
iconToSet = staticImageRU_active;
}
SendMessage(statusBar, SB_SETICON, 2 | 0, (LPARAM)iconToSet);
}
void changeLangPartText(TCHAR* kbdLayOut) {
SendMessage(statusBar, SB_SETTEXT, 2 | 0, (LPARAM)kbdLayOut);
}
void changeLinePartText(void) {
TCHAR lineIndexStrFull[20];
TCHAR lineIndexDigits[12];
ZeroMemory(&lineIndexStrFull, sizeof(lineIndexStrFull));
ZeroMemory(&lineIndexDigits, sizeof(lineIndexDigits));
_tcscpy(lineIndexStrFull,_T("Line: "));
INT32 lineIndex = SendMessage(richEditControl, EM_LINEFROMCHAR, -1, NULL);
_stprintf(lineIndexDigits,_T("%d"),++lineIndex);
_tcscat(lineIndexStrFull,lineIndexDigits);
SendMessage(statusBar, SB_SETTEXT, 3 | 0, (LPARAM)lineIndexStrFull);
//TODO also do get the number of lines in the edit control
}
//characters in richedit
void changeCharPartText(void) {
//TODO use a global variable to store the current number of characters, remove -2 characters worth of \r\n whitespace
GETTEXTLENGTHEX textLengthStruct;
UINT64 docLength = 0;
textLengthStruct.flags = GTL_DEFAULT;
textLengthStruct.codepage = 1200;
docLength = SendMessage(richEditControl,EM_GETTEXTLENGTHEX,(WPARAM)&textLengthStruct,NULL);
TCHAR lineIndexStrFull[20];
TCHAR lineIndexDigits[12];
ZeroMemory(&lineIndexStrFull, sizeof(lineIndexStrFull));
ZeroMemory(&lineIndexDigits, sizeof(lineIndexDigits));
_tcscpy(lineIndexStrFull, _T("Chars: "));
//UINT64 docLength = GetWindowTextLength(richEditControl);
//_stprintf(lineIndexDigits, _T("%d"), docLength<0?1:docLength-1);
//_tcscat(lineIndexStrFull, lineIndexDigits);
_stprintf(lineIndexDigits,_T("%d"),docLength);
_tcscat(lineIndexStrFull,lineIndexDigits);
SendMessage(statusBar, SB_SETTEXT, 5 | 0, (LPARAM)lineIndexStrFull);
}
//words in richedit
void changeWordPartText(void)
{
//stub
}