3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
7 /////////////////////////////////////////////////////////////////////////////
9 // TODO: Prime candidate for ATL
11 #include "WinCommon.h"
14 #include "../resource.h"
16 // Track memory leaks on Windows to the line that new'd the memory
19 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
22 static char THIS_FILE
[] = __FILE__
;
26 struct SToolbarButton
{
33 SToolbarButton sButtons
[] = {
34 {STD_FILENEW
, 0, IDS_FILE_NEW
, ID_FILE_NEW
},
35 {STD_FILEOPEN
, 1, IDS_FILE_OPEN
, ID_FILE_OPEN
},
36 {STD_FILESAVE
, 2, IDS_FILE_SAVE
, ID_FILE_SAVE
},
38 {STD_CUT
, 3, IDS_EDIT_CUT
, ID_EDIT_CUT
},
39 {STD_COPY
, 4, IDS_EDIT_COPY
, ID_EDIT_COPY
},
40 {-2, 5, IDS_EDIT_COPY_ALL
, ID_EDIT_COPY_ALL
},
41 {STD_PASTE
, 6, IDS_EDIT_PASTE
, ID_EDIT_PASTE
}
44 CToolbar::CToolbar(HWND hParent
, bool bVisible
) {
54 void CToolbar::Resize() {
55 SendMessage(m_hRebar
, WM_SIZE
, 0, 0);
58 void CToolbar::ShowToolbar(bool bValue
) {
65 void CToolbar::CreateToolbar() {
66 WinHelper::InitCommonControlLib();
69 m_hRebar
= CreateWindowEx(WS_EX_TOOLWINDOW
,
72 WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|
73 WS_CLIPCHILDREN
|RBS_VARHEIGHT
,
75 m_hParent
, NULL
, WinHelper::hInstApp
,
79 rbi
.cbSize
= sizeof(REBARINFO
);
81 rbi
.himl
= (HIMAGELIST
)NULL
;
82 SendMessage(m_hRebar
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
);
85 rbBand
.cbSize
= sizeof(REBARBANDINFO
);
86 rbBand
.fMask
= RBBIM_STYLE
| RBBIM_CHILD
| RBBIM_CHILDSIZE
;
87 rbBand
.fStyle
= RBBS_CHILDEDGE
| RBBS_FIXEDBMP
| RBBS_GRIPPERALWAYS
| RBBS_USECHEVRON
;
91 m_hwnd
= CreateWindow(TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, m_hRebar
, NULL
, WinHelper::hInstApp
, NULL
);
93 //Unless I'm going for ultra-compatibility, display a nice flat-style toolbar
94 m_hwnd
= CreateWindow(TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| CCS_NODIVIDER
| CCS_NORESIZE
| CCS_NOPARENTALIGN
, 0, 0, 0, 0, m_hRebar
, NULL
, WinHelper::hInstApp
, NULL
);
97 // Allows system to work with any version of common controls library
98 SendMessage(m_hwnd
, TB_BUTTONSTRUCTSIZE
, (WPARAM
) sizeof(TBBUTTON
), 0);
100 // Get Standard toolbar bitmaps.
102 bitmaps
.hInst
= HINST_COMMCTRL
;
103 bitmaps
.nID
= IDB_STD_LARGE_COLOR
;
104 SendMessage(m_hwnd
, TB_ADDBITMAP
, 0, (LPARAM
) & bitmaps
);
106 // Get Non-standard Copy-All bitmap
107 bitmaps
.hInst
= WinHelper::hInstApp
;
108 bitmaps
.nID
= IDB_COPY_ALL_LARGE_COLOR
;
109 const int COPY_ALL_INDEX
= SendMessage(m_hwnd
, TB_ADDBITMAP
, 0, (LPARAM
) & bitmaps
);
114 int iNumButtons(sizeof(sButtons
)/sizeof(SToolbarButton
));
116 for(int i(0); i
< iNumButtons
; ++i
) {
117 if(sButtons
[i
].iBitmap
!= -1) {
118 WinLocalisation::GetResourceString(sButtons
[i
].iStringID
, &CurButton
);
119 AllButtons
+= CurButton
+ TEXT('\0');
123 const TCHAR
*szButtontext
= AllButtons
.c_str();
124 SendMessage(m_hwnd
, TB_ADDSTRING
, 0, (DWORD
) szButtontext
);
126 // TODO: Should do tooltips
128 TBBUTTON
*pButtons(new TBBUTTON
[iNumButtons
]);
130 for(int i(0); i
< iNumButtons
; ++i
) {
131 if(sButtons
[i
].iBitmap
== -2)
132 pButtons
[i
].iBitmap
= COPY_ALL_INDEX
;
134 pButtons
[i
].iBitmap
= sButtons
[i
].iBitmap
;
136 pButtons
[i
].idCommand
= sButtons
[i
].iCommand
;
137 pButtons
[i
].fsState
= TBSTATE_ENABLED
;
139 // TODO: Not sure if this is the best way to handle the separator
140 if(sButtons
[i
].iBitmap
== -1)
141 pButtons
[i
].fsStyle
= TBSTYLE_SEP
;
143 pButtons
[i
].fsStyle
= TBSTYLE_BUTTON
;
144 pButtons
[i
].iString
= sButtons
[i
].iString
;
147 SendMessage(m_hwnd
, TB_ADDBUTTONS
, iNumButtons
, (LPARAM
)pButtons
);
151 int dwBtnSize
= SendMessage(m_hwnd
, TB_GETBUTTONSIZE
, 0,0);
153 rbBand
.hwndChild
= m_hwnd
;
154 rbBand
.cxMinChild
= 0;
155 rbBand
.cyMinChild
= HIWORD(dwBtnSize
);
156 rbBand
.cxIdeal
= 250;
158 SendMessage(m_hRebar
, RB_INSERTBAND
, (WPARAM
)-1, (LPARAM
)&rbBand
);
161 void CToolbar::DestroyToolbar() {
162 DestroyWindow(m_hRebar
);
166 int CToolbar::GetHeight() {
168 GetWindowRect(m_hRebar
, &sRect
);
169 return sRect
.bottom
- sRect
.top
;