00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "ToolBarEx.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CToolBarEx::CToolBarEx()
00017 {
00018 m_cNames = 0;
00019 }
00020
00021 CToolBarEx::~CToolBarEx()
00022 {
00023 }
00024
00025 BEGIN_MESSAGE_MAP(CToolBarEx, CToolBar)
00026
00027 ON_WM_RBUTTONUP()
00028
00029 END_MESSAGE_MAP()
00030
00031 BOOL CToolBarEx::Create(CWnd* pParent)
00032 {
00033 if (!CreateEx (pParent, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT
00034 ,
00035 WS_CHILD | WS_VISIBLE | CBRS_TOOLTIPS | CBRS_ALIGN_TOP)
00036 )
00037 return FALSE;
00038
00039 m_bar = &GetToolBarCtrl ();
00040
00041 m_bar->SetBitmapSize (CSize (_TB_SIZE_X, _TB_SIZE_Y));
00042
00043 SetSizes (CSize (_TB_SIZE_X+7, _TB_SIZE_Y+7),
00044 CSize (_TB_SIZE_X, _TB_SIZE_Y));
00045
00046 if (!m_images.Create (_TB_SIZE_X, _TB_SIZE_Y, ILC_COLOR32 | ILC_MASK, 30, 5))
00047 return FALSE;
00048
00049 m_dimages.Create (_TB_SIZE_X, _TB_SIZE_Y, ILC_COLOR32 | ILC_MASK, 30, 5);
00050
00051 m_bar->SetImageList (&m_images);
00052 m_bar->SetDisabledImageList (&m_dimages);
00053
00054 return TRUE;
00055 }
00056
00057 BOOL CToolBarEx::InsertGroup(wgTButtonInfo *pButtons, CBitmap *pBitmap, CBitmap *pBmpDisabled, int cButtons)
00058 {
00059 int cBitmaps = m_images.GetImageCount ();
00060 COLORREF clrBg;
00061
00062 if (_TB_USE_ALPHA)
00063 clrBg = GetSysColor (COLOR_3DFACE);
00064 else
00065 clrBg = RGB (255, 0, 255);
00066
00067 m_images.Add (pBitmap, clrBg);
00068 m_dimages.Add (pBmpDisabled, clrBg);
00069
00070 fs::list <fsTBInfo> vB;
00071
00072 for (int i = 0; i < cButtons; i++)
00073 {
00074 fsTBInfo tb;
00075
00076 tb.bStyle = pButtons [i].bStyle;
00077 tb.idCommand = pButtons [i].iIdCommand;
00078 tb.strToolTip = pButtons [i].pszToolTip;
00079
00080 if (tb.bStyle == 0 && tb.idCommand == 0)
00081 {
00082 cBitmaps++;
00083 continue;
00084 }
00085
00086 if (pButtons [i].pszName)
00087 {
00088 CString str;
00089 str.Format("%s\0", pButtons [i].pszName);
00090 GetToolBarCtrl().AddStrings(str);
00091 tb.iName = m_cNames++;
00092 }
00093 else
00094 tb.iName = -1;
00095
00096 if (tb.bStyle & TBSTYLE_SEP)
00097 tb.iImage = 0;
00098 else
00099 tb.iImage = cBitmaps++;
00100
00101 vB.add (tb);
00102 }
00103
00104 m_vGroups.add (vB);
00105
00106 return TRUE;
00107 }
00108
00109 BOOL CToolBarEx::ShowGroup(int iGrp, int iWhere)
00110 {
00111 if (iGrp >= m_vGroups.size ())
00112 return FALSE;
00113
00114 fs::list <fsTBInfo> *pGroup = &m_vGroups [iGrp];
00115
00116 for (int i = 0; i < pGroup->size (); i++)
00117 {
00118 fsTBInfo *tb = &pGroup->at (i);
00119 TBBUTTON btn;
00120
00121
00122 btn.dwData = iGrp;
00123 btn.fsState = TBSTATE_ENABLED;
00124 btn.fsStyle = tb->bStyle;
00125
00126 btn.iBitmap = tb->iImage;
00127 btn.idCommand = tb->idCommand;
00128 btn.iString = tb->iName;
00129
00130 GetToolBarCtrl ().InsertButton (iWhere++, &btn);
00131 }
00132
00133 GetToolBarCtrl().AutoSize();
00134
00135 UpdateSize ();
00136
00137 return TRUE;
00138 }
00139
00140 void CToolBarEx::HideGroup(int iGrp)
00141 {
00142 int cButtons = m_bar->GetButtonCount ();
00143 while (cButtons--)
00144 {
00145 TBBUTTON tb;
00146 m_bar->GetButton (cButtons, &tb);
00147
00148 if (tb.dwData == (DWORD) iGrp)
00149 m_bar->DeleteButton (cButtons);
00150 }
00151
00152 UpdateSize ();
00153 }
00154
00155 void CToolBarEx::UpdateSize()
00156 {
00157 GetParentFrame ()->RecalcLayout ();
00158 }
00159
00160 BOOL CToolBarEx::OnNotify(LPNMHDR nm)
00161 {
00162 if (nm->hwndFrom != m_hWnd)
00163 return FALSE;
00164
00165 int nID = ((LPNMTBGETINFOTIPA) nm)->iItem;
00166
00167 fsTBInfo *tb = FindButton (nID);
00168
00169 if (tb == NULL)
00170 return FALSE;
00171
00172 switch (nm->code)
00173 {
00174 case TBN_GETINFOTIPA:
00175 {
00176 LPNMTBGETINFOTIPA inf = (LPNMTBGETINFOTIPA) nm;
00177 strcpy (inf->pszText, tb->strToolTip);
00178 }
00179 break;
00180
00181 case TBN_GETINFOTIPW:
00182 {
00183 return FALSE;
00184
00185 }
00186 break;
00187
00188 default:
00189 return FALSE;
00190 }
00191
00192 return TRUE;
00193 }
00194
00195 CToolBarEx::fsTBInfo* CToolBarEx::FindButton(UINT nID)
00196 {
00197 int cButtons = m_bar->GetButtonCount ();
00198
00199 for (int i = 0; i < cButtons; i++)
00200 {
00201 TBBUTTON bt;
00202 m_bar->GetButton (i, &bt);
00203
00204 if (bt.idCommand != (int)nID)
00205 continue;
00206
00207 fs::list <fsTBInfo> *pvGroup = &m_vGroups [bt.dwData];
00208
00209 for (int j = 0; j < pvGroup->size (); j++)
00210 if (pvGroup->at (j).idCommand == bt.idCommand)
00211 break;
00212
00213 return &pvGroup->at (j);
00214 }
00215
00216 return NULL;
00217 }
00218
00219 void CToolBarEx::UpdateGroupToolTips(int iGrp, LPCSTR *ppszTips, UINT uSize)
00220 {
00221 int cTips = min ((int)uSize, m_vGroups [iGrp].size ());
00222 for (int i = 0; i < cTips; i++)
00223 m_vGroups [iGrp][i].strToolTip = ppszTips [i];
00224 }
00225
00226 void CToolBarEx::OnRButtonUp(UINT nFlags, CPoint point)
00227 {
00228
00229 CToolBar::OnRButtonUp(nFlags, point);
00230 }
00231
00232 BOOL CToolBarEx::OnTBGetButtonInfo(NMHDR *nm)
00233 {
00234 LPNMTOOLBAR nmt = (LPNMTOOLBAR) nm;
00235
00236 int i = nmt->iItem;
00237
00238 if (i < 5)
00239 {
00240
00241
00242 }
00243 else
00244 return FALSE;
00245
00246 return TRUE;
00247 }
00248
00249 void CToolBarEx::AutoSize() const
00250 {
00251 RECT rcTB;
00252 GetParent ()->GetWindowRect (&rcTB);
00253
00254 int cButtons = GetToolBarCtrl ().GetButtonCount ();
00255 int dx = 0, dy = rcTB.bottom-rcTB.top;
00256
00257 for (int i = 0; i < cButtons; i++)
00258 {
00259 RECT rc;
00260 GetToolBarCtrl ().GetItemRect (i, &rc);
00261 dx += rc.right - rc.left;
00262 dy = max (dy, rc.bottom);
00263 }
00264
00265 dx += 10;
00266 dy += 5;
00267
00268 GetToolBarCtrl().SetWindowPos(0, 0, 0, dx, dy, SWP_NOZORDER|SWP_NOMOVE);
00269 }
00270
00271 CImageList* CToolBarEx::get_Images()
00272 {
00273 return &m_images;
00274 }