1 | #include "stdafx.h" |
---|
2 | |
---|
3 | #include "Common.h" |
---|
4 | |
---|
5 | |
---|
6 | CMainTab *pobj_MainTab=0; |
---|
7 | WNDPROC OldMainTabWndProc; |
---|
8 | |
---|
9 | |
---|
10 | LRESULT CALLBACK MainTabWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){ |
---|
11 | static BOOL indexDrag=-1; |
---|
12 | TCHITTESTINFO tcHitTest; |
---|
13 | int iNewPos; |
---|
14 | char temporary[MAX_PATH]; |
---|
15 | switch(message){ |
---|
16 | case WM_LBUTTONDOWN: |
---|
17 | //クリックされたアイテムインデックスを取得 |
---|
18 | GetCursorPos(&tcHitTest.pt); |
---|
19 | ScreenToClient(pobj_MainTab->hTab,&tcHitTest.pt); |
---|
20 | indexDrag=TabCtrl_HitTest(pobj_MainTab->hTab,&tcHitTest); |
---|
21 | if(indexDrag==-1) break; |
---|
22 | |
---|
23 | SetCapture(hwnd); |
---|
24 | break; |
---|
25 | case WM_LBUTTONUP: |
---|
26 | indexDrag=-1; |
---|
27 | ReleaseCapture(); |
---|
28 | break; |
---|
29 | case WM_MOUSEMOVE: |
---|
30 | if(indexDrag!=-1){ |
---|
31 | GetCursorPos(&tcHitTest.pt); |
---|
32 | ScreenToClient(pobj_MainTab->hTab,&tcHitTest.pt); |
---|
33 | iNewPos=TabCtrl_HitTest(pobj_MainTab->hTab,&tcHitTest); |
---|
34 | if(iNewPos==-1) break; |
---|
35 | if(indexDrag!=iNewPos){ |
---|
36 | LockWindowUpdate(hOwner); |
---|
37 | |
---|
38 | TC_ITEM tcItem; |
---|
39 | tcItem.mask=TCIF_TEXT|TCIF_PARAM; |
---|
40 | tcItem.pszText=temporary; |
---|
41 | tcItem.cchTextMax=MAX_PATH; |
---|
42 | TabCtrl_GetItem(pobj_MainTab->hTab,indexDrag,&tcItem); |
---|
43 | |
---|
44 | TabCtrl_DeleteItem(pobj_MainTab->hTab,indexDrag); |
---|
45 | |
---|
46 | TabCtrl_InsertItem(pobj_MainTab->hTab,iNewPos,&tcItem); |
---|
47 | |
---|
48 | int iTemp; |
---|
49 | iTemp=TabCtrl_HitTest(pobj_MainTab->hTab,&tcHitTest); |
---|
50 | if(iTemp!=iNewPos){ |
---|
51 | TabCtrl_DeleteItem(pobj_MainTab->hTab,iNewPos); |
---|
52 | TabCtrl_InsertItem(pobj_MainTab->hTab,indexDrag,&tcItem); |
---|
53 | |
---|
54 | LockWindowUpdate(0); |
---|
55 | break; |
---|
56 | } |
---|
57 | |
---|
58 | indexDrag=iNewPos; |
---|
59 | |
---|
60 | LockWindowUpdate(0); |
---|
61 | } |
---|
62 | } |
---|
63 | return 0; |
---|
64 | case WM_PAINT: |
---|
65 | HDC hdc; |
---|
66 | PAINTSTRUCT ps; |
---|
67 | hdc=BeginPaint(hwnd,&ps); |
---|
68 | if(pobj_MainTab) |
---|
69 | pobj_MainTab->draw(hdc); |
---|
70 | EndPaint(hwnd,&ps); |
---|
71 | return 0; |
---|
72 | } |
---|
73 | return CallWindowProc(OldMainTabWndProc,hwnd,message,wParam,lParam); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | int CMainTab::SearchItemIndex( const char *lpszText ){ |
---|
78 | int i2,i3; |
---|
79 | char temporary[MAX_PATH]; |
---|
80 | |
---|
81 | i3=TabCtrl_GetItemCount(hTab); |
---|
82 | |
---|
83 | TC_ITEM tcItem; |
---|
84 | tcItem.mask=TCIF_TEXT; |
---|
85 | tcItem.pszText=temporary; |
---|
86 | tcItem.cchTextMax=MAX_PATH; |
---|
87 | |
---|
88 | for(i2=0;i2<i3;i2++){ |
---|
89 | TabCtrl_GetItem(hTab,i2,&tcItem); |
---|
90 | |
---|
91 | //アスタリスクを取り除いて評価する |
---|
92 | if( tcItem.pszText[ lstrlen( tcItem.pszText ) -1 ] == '*' ){ |
---|
93 | tcItem.pszText[ lstrlen( tcItem.pszText ) -1 ] = 0; |
---|
94 | } |
---|
95 | |
---|
96 | if(lstrcmpi(lpszText,tcItem.pszText)==0) break; |
---|
97 | } |
---|
98 | if(i2==i3) return -1; |
---|
99 | |
---|
100 | return i2; |
---|
101 | } |
---|
102 | void CMainTab::SetItemText( int index, const char *ItemText ){ |
---|
103 | TC_ITEM tcItem; |
---|
104 | tcItem.mask=TCIF_TEXT; |
---|
105 | tcItem.pszText=(LPSTR)ItemText; |
---|
106 | tcItem.cchTextMax=MAX_PATH; |
---|
107 | |
---|
108 | TabCtrl_SetItem(hTab,index,&tcItem); |
---|
109 | } |
---|
110 | void CMainTab::GetItemText( int index, char *ItemText ){ |
---|
111 | TC_ITEM tcItem; |
---|
112 | tcItem.mask = TCIF_TEXT; |
---|
113 | tcItem.pszText = ItemText; |
---|
114 | tcItem.cchTextMax = MAX_PATH; |
---|
115 | TabCtrl_GetItem( hTab, index, &tcItem ); |
---|
116 | } |
---|
117 | bool CMainTab::IsModified( int index ){ |
---|
118 | //アスタリスク表示かどうかを判断する |
---|
119 | |
---|
120 | //アイテム文字列を取得 |
---|
121 | char ItemText[MAX_PATH]; |
---|
122 | GetItemText( index, ItemText ); |
---|
123 | |
---|
124 | if( ItemText[ lstrlen( ItemText ) -1 ] == '*' ){ |
---|
125 | //アスタリスクがあったとき |
---|
126 | return true; |
---|
127 | } |
---|
128 | |
---|
129 | //その他 |
---|
130 | return false; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | CMainTab::CMainTab(HWND hParent){ |
---|
135 | extern HFONT hStatusFont; |
---|
136 | hTab=CreateWindowEx(0,WC_TABCONTROL,NULL, |
---|
137 | WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_VISIBLE|TCS_OWNERDRAWFIXED, |
---|
138 | 0,0,0,0, |
---|
139 | hParent,0,hInst,0); |
---|
140 | |
---|
141 | TabCtrl_SetPadding(hTab,5,4); |
---|
142 | |
---|
143 | DWORD dwStyle; |
---|
144 | dwStyle = TabCtrl_GetExtendedStyle(hTab); |
---|
145 | dwStyle &= ~TCS_EX_FLATSEPARATORS; |
---|
146 | TabCtrl_SetExtendedStyle(hTab, dwStyle); |
---|
147 | |
---|
148 | |
---|
149 | //サブクラス化 |
---|
150 | OldMainTabWndProc=(WNDPROC)GetWindowLongPtr(hTab,GWLP_WNDPROC); |
---|
151 | SetWindowLongPtr(hTab,GWLP_WNDPROC,(LONG_PTR)MainTabWndProc); |
---|
152 | |
---|
153 | //ボールド体フォントを生成 |
---|
154 | LOGFONT lf; |
---|
155 | GetObject(hStatusFont,sizeof(LOGFONT),&lf); |
---|
156 | lf.lfWeight=FW_BOLD; |
---|
157 | hBoldFont=CreateFontIndirect(&lf); |
---|
158 | |
---|
159 | SendMessage(hTab,WM_SETFONT,(long)hBoldFont,0); |
---|
160 | } |
---|
161 | |
---|
162 | CMainTab::~CMainTab(){ |
---|
163 | DeleteObject(hBoldFont); |
---|
164 | } |
---|
165 | |
---|
166 | void CMainTab::InsertItem( const char *lpszText, bool isResize, COLORREF color ){ |
---|
167 | int sw=0; |
---|
168 | if(TabCtrl_GetItemCount(hTab)==0) sw=1; |
---|
169 | |
---|
170 | if(color==-1) color=RGB(230,230,230); |
---|
171 | |
---|
172 | TC_ITEM tcItem; |
---|
173 | tcItem.mask=TCIF_TEXT|TCIF_PARAM; |
---|
174 | tcItem.pszText=(LPSTR)lpszText; |
---|
175 | tcItem.lParam=color; |
---|
176 | TabCtrl_InsertItem(hTab,0,&tcItem); |
---|
177 | TabCtrl_SetCurSel(hTab,0); |
---|
178 | |
---|
179 | if(isResize){ |
---|
180 | if(sw) ActiveBasic::IDE::Program::mainFrame.Resized(); |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | void CMainTab::DeleteItem( const char *lpszText, bool isResize ){ |
---|
185 | int i2; |
---|
186 | i2=SearchItemIndex(lpszText); |
---|
187 | if(i2==-1) return; |
---|
188 | |
---|
189 | TabCtrl_DeleteItem(hTab,i2); |
---|
190 | |
---|
191 | if(isResize){ |
---|
192 | if(TabCtrl_GetItemCount(hTab)==0) ActiveBasic::IDE::Program::mainFrame.Resized(); |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | void CMainTab::RenameItem( const char *lpszOldText, const char *lpszNewText ){ |
---|
197 | int i2; |
---|
198 | i2=SearchItemIndex(lpszOldText); |
---|
199 | if(i2==-1) return; |
---|
200 | |
---|
201 | SetItemText( i2, lpszNewText ); |
---|
202 | } |
---|
203 | |
---|
204 | void CMainTab::NofityModifyDocument( const char *ItemText ){ |
---|
205 | //ドキュメントが変更されたとき、アスタリスクを付けて表示する |
---|
206 | |
---|
207 | //インデックスを取得 |
---|
208 | int index = SearchItemIndex( ItemText ); |
---|
209 | if( index == -1 ) return; |
---|
210 | |
---|
211 | //既にアスタリスク表示されていた場合は抜ける |
---|
212 | if( IsModified( index ) ) return; |
---|
213 | |
---|
214 | //アスタリスクを付加 |
---|
215 | char temporary[MAX_PATH]; |
---|
216 | lstrcpy( temporary, ItemText ); |
---|
217 | lstrcat( temporary, "*" ); |
---|
218 | |
---|
219 | //タブアイテムを更新 |
---|
220 | SetItemText( index, temporary ); |
---|
221 | } |
---|
222 | void CMainTab::NofityUnModifyDocument( const char *ItemText ){ |
---|
223 | //ドキュメントが保存されたとき、アスタリスクを非表示にする |
---|
224 | |
---|
225 | //インデックスを取得 |
---|
226 | int index = SearchItemIndex( ItemText ); |
---|
227 | if( index == -1 ) return; |
---|
228 | |
---|
229 | //既にアスタリスクが非表示の場合は抜ける |
---|
230 | if( ! IsModified( index ) ) return; |
---|
231 | |
---|
232 | //タブアイテムを更新 |
---|
233 | SetItemText( index, ItemText ); |
---|
234 | } |
---|
235 | |
---|
236 | COLORREF CMainTab::GetItemColor( char *ItemText ){ |
---|
237 | //インデックスを取得 |
---|
238 | int index = SearchItemIndex( ItemText ); |
---|
239 | if( index == -1 ) return -1; |
---|
240 | |
---|
241 | TC_ITEM tcItem; |
---|
242 | tcItem.mask = TCIF_PARAM; |
---|
243 | TabCtrl_GetItem( hTab, index, &tcItem ); |
---|
244 | return tcItem.lParam; |
---|
245 | } |
---|
246 | |
---|
247 | void CMainTab::SelChangeEvent(){ |
---|
248 | int i; |
---|
249 | i=TabCtrl_GetCurSel(hTab); |
---|
250 | |
---|
251 | char ItemText[MAX_PATH]; |
---|
252 | TC_ITEM tcItem; |
---|
253 | tcItem.mask=TCIF_TEXT; |
---|
254 | tcItem.pszText=ItemText; |
---|
255 | tcItem.cchTextMax=MAX_PATH; |
---|
256 | TabCtrl_GetItem(hTab,i,&tcItem); |
---|
257 | |
---|
258 | if( ItemText[ lstrlen( ItemText ) -1 ] == '*' ){ |
---|
259 | //アスタリスクがあったときは取り除く |
---|
260 | ItemText[ lstrlen( ItemText ) -1 ] = 0; |
---|
261 | } |
---|
262 | |
---|
263 | for(i=0;i<MdiInfo.size();i++){ |
---|
264 | if(lstrcmpi(ItemText,MdiInfo[i]->title.c_str())==0) break; |
---|
265 | } |
---|
266 | BringWindowToTop(MdiInfo[i]->hwnd); |
---|
267 | } |
---|
268 | void CMainTab::MdiActiveEvent(const char *lpszText){ |
---|
269 | int i2; |
---|
270 | i2=SearchItemIndex(lpszText); |
---|
271 | if(i2==-1) return; |
---|
272 | |
---|
273 | TabCtrl_SetCurSel(hTab,i2); |
---|
274 | } |
---|
275 | |
---|
276 | void CMainTab::draw(HDC hdc){ |
---|
277 | COLORREF colorGray; |
---|
278 | HBRUSH hGrayBrush; |
---|
279 | |
---|
280 | int nMaxPage; |
---|
281 | nMaxPage=TabCtrl_GetItemCount(hTab); |
---|
282 | |
---|
283 | //ペンを生成 |
---|
284 | HPEN hPen,hOldPen; |
---|
285 | COLORREF colorPen; |
---|
286 | colorPen=RGB(127,140,155); |
---|
287 | hPen=CreatePen(PS_SOLID,0,colorPen); |
---|
288 | hOldPen=(HPEN)SelectObject(hdc,hPen); |
---|
289 | |
---|
290 | //描画領域を塗りつぶす |
---|
291 | RECT rc; |
---|
292 | GetClientRect(hTab,&rc); |
---|
293 | FillRect(hdc,&rc,GetSysColorBrush(COLOR_3DFACE)); |
---|
294 | |
---|
295 | //リージョンを生成 |
---|
296 | HRGN hDefaultRgn; |
---|
297 | hDefaultRgn=CreateRectRgnIndirect(&rc); |
---|
298 | |
---|
299 | int i; |
---|
300 | char temporary[MAX_PATH]; |
---|
301 | HFONT hOldFont; |
---|
302 | TCITEM item; |
---|
303 | memset(&item,0,sizeof(TCITEM)); |
---|
304 | item.mask=TCIF_TEXT|TCIF_PARAM; |
---|
305 | item.pszText=temporary; |
---|
306 | item.cchTextMax=MAX_PATH; |
---|
307 | for(i=nMaxPage-1;i>=0;i--){ |
---|
308 | if(i==TabCtrl_GetCurSel(hTab)){ |
---|
309 | //フォーカスを持つタブは最後に描画するため、飛び越す |
---|
310 | continue; |
---|
311 | } |
---|
312 | |
---|
313 | TabCtrl_GetItem(hTab,i,&item); |
---|
314 | |
---|
315 | //座標取得 |
---|
316 | TabCtrl_GetItemRect(hTab,i,&rc); |
---|
317 | |
---|
318 | |
---|
319 | |
---|
320 | //////////////////////////// |
---|
321 | // タブ枠を描画 |
---|
322 | //////////////////////////// |
---|
323 | colorGray=item.lParam; |
---|
324 | |
---|
325 | //ブラシを生成 |
---|
326 | hGrayBrush=CreateSolidBrush(colorGray); |
---|
327 | |
---|
328 | SetBkColor(hdc,colorGray); |
---|
329 | |
---|
330 | HBRUSH hOldBrush; |
---|
331 | hOldBrush=(HBRUSH)SelectObject(hdc,hGrayBrush); |
---|
332 | |
---|
333 | HRGN hRgn1,hRgn2; |
---|
334 | hRgn1=CreateRectRgn(rc.left,rc.top,rc.right-20,rc.bottom); |
---|
335 | hRgn2=CreateRectRgn(rc.right-20,rc.top,rc.right+2,rc.bottom); |
---|
336 | |
---|
337 | SelectObject(hdc,hRgn1); |
---|
338 | RoundRect(hdc,rc.left,rc.top,rc.right+2,rc.bottom+20,20,15); |
---|
339 | SelectObject(hdc,hRgn2); |
---|
340 | RoundRect(hdc,rc.left,rc.top,rc.right+2,rc.bottom+20,3,3); |
---|
341 | SelectObject(hdc,hDefaultRgn); |
---|
342 | |
---|
343 | DeleteObject(hRgn1); |
---|
344 | DeleteObject(hRgn2); |
---|
345 | |
---|
346 | SelectObject(hdc,hOldBrush); |
---|
347 | DeleteObject(hGrayBrush); |
---|
348 | |
---|
349 | |
---|
350 | extern HFONT hStatusFont; |
---|
351 | hOldFont=(HFONT)SelectObject(hdc,hStatusFont); |
---|
352 | |
---|
353 | |
---|
354 | |
---|
355 | //文字を描画 |
---|
356 | DrawText(hdc,item.pszText,-1,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE); |
---|
357 | |
---|
358 | |
---|
359 | SelectObject(hdc,hOldFont); |
---|
360 | } |
---|
361 | |
---|
362 | |
---|
363 | ///////////////////////////////// |
---|
364 | // フォーカスを持つタブを描画 |
---|
365 | ///////////////////////////////// |
---|
366 | i=TabCtrl_GetCurSel(hTab); |
---|
367 | |
---|
368 | TabCtrl_GetItem(hTab,i,&item); |
---|
369 | |
---|
370 | //座標取得 |
---|
371 | TabCtrl_GetItemRect(hTab,i,&rc); |
---|
372 | |
---|
373 | { |
---|
374 | rc.top-=2; |
---|
375 | //////////////////////////// |
---|
376 | // タブ枠を描画 |
---|
377 | //////////////////////////// |
---|
378 | colorGray=item.lParam; |
---|
379 | |
---|
380 | //ブラシを生成 |
---|
381 | hGrayBrush=CreateSolidBrush(colorGray); |
---|
382 | |
---|
383 | SetBkColor(hdc,colorGray); |
---|
384 | |
---|
385 | HBRUSH hOldBrush; |
---|
386 | hOldBrush=(HBRUSH)SelectObject(hdc,hGrayBrush); |
---|
387 | |
---|
388 | HRGN hRgn1,hRgn2; |
---|
389 | hRgn1=CreateRectRgn(rc.left,rc.top,rc.right-20,rc.bottom); |
---|
390 | hRgn2=CreateRectRgn(rc.right-20,rc.top,rc.right+2,rc.bottom); |
---|
391 | |
---|
392 | SelectObject(hdc,hRgn1); |
---|
393 | RoundRect(hdc,rc.left,rc.top,rc.right+2,rc.bottom+20,20,15); |
---|
394 | SelectObject(hdc,hRgn2); |
---|
395 | RoundRect(hdc,rc.left,rc.top,rc.right+2,rc.bottom+20,3,3); |
---|
396 | SelectObject(hdc,hDefaultRgn); |
---|
397 | |
---|
398 | DeleteObject(hRgn1); |
---|
399 | DeleteObject(hRgn2); |
---|
400 | |
---|
401 | SelectObject(hdc,hOldBrush); |
---|
402 | DeleteObject(hGrayBrush); |
---|
403 | |
---|
404 | rc.top+=2; |
---|
405 | } |
---|
406 | |
---|
407 | hOldFont=(HFONT)SelectObject(hdc,hBoldFont); |
---|
408 | |
---|
409 | //文字を描画 |
---|
410 | DrawText(hdc,item.pszText,-1,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE); |
---|
411 | |
---|
412 | SelectObject(hdc,hOldFont); |
---|
413 | |
---|
414 | |
---|
415 | |
---|
416 | SelectObject(hdc,hOldPen); |
---|
417 | DeleteObject(hPen); |
---|
418 | |
---|
419 | DeleteObject(hDefaultRgn); |
---|
420 | } |
---|