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