-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathStatusBar.c
211 lines (183 loc) · 5 KB
/
StatusBar.c
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
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
208
209
210
211
/*
* CLCL
*
* StatusBar.c
*
* Copyright (C) 1996-2019 by Ohno Tomoaki. All rights reserved.
* https://www.nakka.com/
*/
/* Include Files */
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include <commctrl.h>
#include "General.h"
#include "Memory.h"
#include "Data.h"
#include "Ini.h"
#include "Message.h"
#include "Menu.h"
#include "Viewer.h"
#include "TreeView.h"
#include "dpi.h"
#include "resource.h"
/* Define */
#ifndef SBT_TOOLTIPS
#define SBT_TOOLTIPS 0x0800
#endif
/* Global Variables */
extern HTREEITEM clip_treeitem;
extern HTREEITEM history_treeitem;
extern HTREEITEM regist_treeitem;
extern DATA_INFO history_data;
extern DATA_INFO regist_data;
// オプション
extern OPTION_INFO option;
/* Local Function Prototypes */
static int statusbar_get_allsize(DATA_INFO *di);
static void statusbar_get_size_text(const int size, TCHAR *ret);
/*
* statusbar_create - StatusBarの作成
*/
HWND statusbar_create(const HWND hWnd, const int id)
{
HWND hStatusBar;
int width[] = {Scale(150), Scale(270), -1};
if ((hStatusBar = CreateStatusWindow(WS_CHILD | SBT_TOOLTIPS, TEXT(""), hWnd, id)) == NULL) {
return NULL;
}
if (option.viewer_show_statusbar == 1) {
// ステータスバー表示
ShowWindow(hStatusBar, SW_SHOW);
}
// パーツの設定
SendMessage(hStatusBar, SB_SETPARTS, (WPARAM)sizeof(width) / sizeof(int), (LPARAM)width);
return hStatusBar;
}
/*
* statusbar_get_allsize - データサイズの合計
*/
static int statusbar_get_allsize(DATA_INFO *di)
{
DATA_INFO *cdi = di;
int cnt = 0;
for (; cdi != NULL; cdi = cdi->next) {
switch (cdi->type) {
case TYPE_FOLDER:
break;
case TYPE_ITEM:
cnt += statusbar_get_allsize(cdi->child);
break;
case TYPE_DATA:
cnt += cdi->size;
break;
}
}
return cnt;
}
/*
* statusbar_set_text - サイズ文字列の取得
*/
static void statusbar_get_size_text(const int size, TCHAR *ret)
{
if (size < 1024) {
wsprintf(ret, message_get_res(IDS_STATUSBAR_BYTES), size);
} else {
wsprintf(ret, message_get_res(IDS_STATUSBAR_KB), size / 1024);
}
}
/*
* statusbar_set_text - StatusBarのテキストを設定
*/
BOOL statusbar_set_text(const HWND hWnd, const HWND hStatusBar)
{
HWND hTreeView = GetDlgItem(hWnd, ID_TREE);
HWND hListView = GetDlgItem(GetDlgItem(hWnd, ID_CONTAINER), ID_LIST);
HTREEITEM hItem;
DATA_INFO *di;
DATA_INFO *cdi;
TCHAR buf[BUF_SIZE];
TCHAR *str_hkey;
int cnt;
// 初期化
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0 | 0, (LPARAM)TEXT(""));
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)TEXT(""));
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)2 | 0, (LPARAM)TEXT(""));
// 選択アイテムの取得
if ((hItem = TreeView_GetSelection(hTreeView)) == NULL || hItem == clip_treeitem) {
return FALSE;
}
if (hItem == history_treeitem || hItem == regist_treeitem) {
cnt = ListView_GetItemCount(hListView);
wsprintf(buf, message_get_res(IDS_STATUSBAR_ITEM_CNT), cnt);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0 | 0, (LPARAM)buf);
if (hItem == history_treeitem) {
cnt = statusbar_get_allsize(history_data.child);
} else {
cnt = statusbar_get_allsize(regist_data.child);
}
statusbar_get_size_text(cnt, buf);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)buf);
return TRUE;
}
// データの取得
if ((di = (DATA_INFO *)treeview_get_lparam(hTreeView, hItem)) == NULL) {
return FALSE;
}
switch (di->type) {
case TYPE_FOLDER:
// フォルダ
cnt = ListView_GetItemCount(hListView);
wsprintf(buf, message_get_res(IDS_STATUSBAR_ITEM_CNT), cnt);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0 | 0, (LPARAM)buf);
cnt = statusbar_get_allsize(di->child);
statusbar_get_size_text(cnt, buf);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)buf);
break;
case TYPE_ITEM:
// アイテム
// 更新日時
data_get_modified_string(di, buf);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)0 | 0, (LPARAM)buf);
// 合計サイズ
cnt = 0;
for (cdi = di->child; cdi != NULL; cdi = cdi->next) {
cnt += cdi->size;
}
statusbar_get_size_text(cnt, buf);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)buf);
if (di->window_name != NULL) {
// ウィンドウタイトル
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)2 | 0, (LPARAM)di->window_name);
} else {
// ホットキー
if ((str_hkey = menu_get_keyname(di->op_modifiers, di->op_virtkey)) != NULL) {
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)2 | 0, (LPARAM)str_hkey);
mem_free(&str_hkey);
}
}
break;
case TYPE_DATA:
// データ
statusbar_get_size_text(di->size, buf);
SendMessage(hStatusBar, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)buf);
break;
}
return TRUE;
}
/*
* statusbar_notify_proc - ステータスバーのツールチップの設定
*/
LRESULT statusbar_notify_proc(const HWND hStatusBar, LPARAM lParam)
{
NMHDR *nmhdr = (NMHDR *)lParam;
TOOLTIPTEXT *tt = (TOOLTIPTEXT *)lParam;
static TCHAR tooltip_string[BUF_SIZE];
*tooltip_string = TEXT('\0');
SendMessage(hStatusBar, SB_GETTEXT, (WPARAM)nmhdr->idFrom, (LPARAM)tooltip_string);
tt->hinst = NULL;
tt->lpszText = tooltip_string;
return TRUE;
}
/* End of source */