win32toolbar.cpp
来自「这是VCF框架的代码」· C++ 代码 · 共 1,556 行 · 第 1/3 页
CPP
1,556 行
} //info.iImage = I_IMAGECALLBACK; SendMessage( hwnd_, TB_SETBUTTONINFOA, index, (LPARAM)&info ); delete [] tmp; } resizeToolbarItems(); currentlyModifyingItem_ = false;}void Win32Toolbar::resetItems( std::vector<ToolbarItem*>& items ){ int buttonCount = SendMessage( hwnd_, TB_BUTTONCOUNT, 0, 0 ); int index = 0; items.resize(buttonCount); bool unicodeEnabled = System::isUnicodeEnabled() ; long state = 0; ToolbarItem* item = NULL; for (index=0;index<buttonCount;index++ ) { if ( unicodeEnabled ) { TBBUTTONINFOW info = {0}; info.cbSize = sizeof(info); info.dwMask |= TBIF_LPARAM | TBIF_STYLE | TBIF_STATE; SendMessage( hwnd_, TB_GETBUTTONINFOW, index, (LPARAM)&info ); item = (ToolbarItem*)info.lParam; items[index] = item; state = item->getState(); if ( (TBSTATE_CHECKED & info.fsState) && ( state & ToolbarItem::tisChecked ) ) { state |= ToolbarItem::tisPressed; } else { state &= ~ToolbarItem::tisPressed; } } else { TBBUTTONINFOA info = {0}; info.cbSize = sizeof(info); info.dwMask |= TBIF_LPARAM | TBIF_STYLE | TBIF_STATE; SendMessage( hwnd_, TB_GETBUTTONINFOA, index, (LPARAM)&info ); item = (ToolbarItem*)info.lParam; items[index] = item; state = item->getState(); if ( (TBSTATE_CHECKED & info.fsState) && ( state & ToolbarItem::tisChecked ) ) { state |= ToolbarItem::tisPressed; } else { state &= ~ToolbarItem::tisPressed; } } currentlyModifyingItem_ = true; item->setState( state ); currentlyModifyingItem_ = false; SendMessage( hwnd_, TB_DELETEBUTTON, 0, 0 ); }}void Win32Toolbar::showButtonCaptions( const bool& val ){ peerControl_->setVisible( false ); int index = 0; std::vector<ToolbarItem*> items; resetItems( items ); for (index=0;index<items.size();index++ ) { insertToolbarButton( index, items[index], val ); } SendMessage(hwnd_, TB_AUTOSIZE, 0, 0 ); peerControl_->setVisible( true );}void Win32Toolbar::setButtonCaptionPlacementHorizontal( const bool& val ){ if ( currentlyModifyingItem_ ) { return; } currentlyModifyingItem_ = true; peerControl_->setVisible( false ); int index = 0; std::vector<ToolbarItem*> items; resetItems( items ); DWORD style = GetWindowLong( hwnd_, GWL_STYLE ); if ( val ) { style |= TBSTYLE_LIST; } else { style &= ~TBSTYLE_LIST; } SetWindowLong( hwnd_, GWL_STYLE, style ); ::SetWindowPos(hwnd_, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); bool showCaptions = ((Toolbar*)peerControl_)->getShowButtonCaptions(); for (index=0;index<items.size();index++ ) { insertToolbarButton( index, items[index], showCaptions ); } SendMessage(hwnd_, TB_AUTOSIZE, 0, 0 ); peerControl_->setVisible( true ); currentlyModifyingItem_ = false;}void Win32Toolbar::setButtonSize( const Size& buttonSize ){ if ( currentlyModifyingItem_ ) { return; } currentlyModifyingItem_ = true; peerControl_->setVisible( false ); int buttonCount = SendMessage( hwnd_, TB_BUTTONCOUNT, 0, 0 ); int index = 0; std::vector<ToolbarItem*> items; resetItems( items ); SendMessage( hwnd_, TB_SETIMAGELIST, 0, 0 ); DWORD style = GetWindowLong( hwnd_, GWL_STYLE ); SetWindowLong( hwnd_, GWL_STYLE, style|TBSTYLE_TRANSPARENT|TBSTYLE_FLAT ); ::SetWindowPos(hwnd_, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); SendMessage( hwnd_, TB_SETBUTTONSIZE, 0, (LPARAM) MAKELONG((short)buttonSize.width_, (short)buttonSize.height_) ); SetWindowLong( hwnd_, GWL_STYLE, style ); SendMessage( hwnd_, TB_SETIMAGELIST, 0, (LPARAM)imageListCtrl_ ); bool val = ((Toolbar*)peerControl_)->getShowButtonCaptions(); for (index=0;index<items.size();index++ ) { insertToolbarButton( index, items[index], val ); } SetWindowLong( hwnd_, GWL_STYLE, style ); SendMessage(hwnd_, TB_AUTOSIZE, 0, 0 ); peerControl_->setVisible( true );/* Container* container = peerControl_->getParent()->getContainer(); if ( NULL != container ) { container->resizeChildren(NULL); }*/ currentlyModifyingItem_ = false;}void Win32Toolbar::removeToolbarButton( ToolbarItem* item ){ SendMessage( hwnd_, TB_DELETEBUTTON, item->getIndex(), 0 ); resizeToolbarItems();}void Win32Toolbar::onImageListImageChanged( ImageListEvent* e ){ ImageList* imageList = (ImageList*)e->getSource(); switch ( e->getType() ) { case IMAGELIST_EVENT_WIDTH_CHANGED : case IMAGELIST_EVENT_HEIGHT_CHANGED :{ int cx = imageList->getImageWidth(); int cy = imageList->getImageHeight(); int err = ImageList_SetIconSize( imageListCtrl_, cx, cy ); //reset the contents Win32Image* win32Img = (Win32Image*)imageList->getMasterImage(); /* JC added this cause it appears that for 32bit images the alpa val matters! If it's not set back to 0 then the transparency affect doesn't work? Bizarre */ SysPixelType* pix = win32Img->getImageBits()->pixels_; int sz = win32Img->getWidth() * win32Img->getHeight(); unsigned char* oldAlpaVals = new unsigned char[sz]; do { sz --; oldAlpaVals[sz] = pix[sz].a; pix[sz].a = 0; } while( sz > 0 ); HBITMAP hbmImage = win32Img->getBitmap(); HBITMAP hCopyImg = (HBITMAP)CopyImage( hbmImage, IMAGE_BITMAP, 0, 0, NULL ); Color* transparentColor = imageList->getTransparentColor(); COLORREF color = transparentColor->getColorRef32(); err = ImageList_AddMasked( imageListCtrl_, hCopyImg, color ); if ( err < 0 ) { //error condition ! } DeleteObject( hCopyImg ); sz = win32Img->getWidth() * win32Img->getHeight(); do { sz --; pix[sz].a = oldAlpaVals[sz]; } while( sz > 0 ); delete [] oldAlpaVals; } break; case IMAGELIST_EVENT_ITEM_ADDED : { Win32Image* win32Img = (Win32Image*)e->getImage(); SysPixelType* pix = win32Img->getImageBits()->pixels_; int sz = win32Img->getWidth() * win32Img->getHeight(); unsigned char* oldAlpaVals = new unsigned char[sz]; do { sz --; oldAlpaVals[sz] = pix[sz].a; pix[sz].a = 0; } while( sz > 0 ); HBITMAP hbmImage = win32Img->getBitmap(); HBITMAP hCopyImg = (HBITMAP)CopyImage( hbmImage, IMAGE_BITMAP, 0, 0, NULL ); Color* transparentColor = imageList->getTransparentColor(); COLORREF color = transparentColor->getColorRef32(); int err = ImageList_AddMasked( imageListCtrl_, hCopyImg, color ); ::DeleteObject( hCopyImg ); sz = win32Img->getWidth() * win32Img->getHeight(); do { sz --; pix[sz].a = oldAlpaVals[sz]; } while( sz > 0 ); delete [] oldAlpaVals; } break; case IMAGELIST_EVENT_ITEM_DELETED : { } break; }}void Win32Toolbar::setImageList( ImageList* imageList ){ if ( NULL != imageListCtrl_ ) { //destroy the old one int err = ImageList_Destroy( imageListCtrl_ ); imageListCtrl_ = NULL; } if ( NULL != imageList ) { peerControl_->setVisible( false ); int buttonCount = SendMessage( hwnd_, TB_BUTTONCOUNT, 0, 0 ); int index = 0; std::vector<ToolbarItem*> items; resetItems( items ); SendMessage( hwnd_, TB_SETBITMAPSIZE, 0, (LPARAM) MAKELONG(imageList->getImageWidth(), imageList->getImageHeight()) ); EventHandler* imgListHandler = getEventHandler( "Win32Toolbar::onImageListImageChanged" ); imageListCtrl_ = ImageList_Create( imageList->getImageWidth(), imageList->getImageHeight(), ILC_COLOR24 | ILC_MASK, imageList->getImageCount(), 4 ); if ( imageList->getImageCount() > 0 ) { Win32Image* win32Img = (Win32Image*)imageList->getMasterImage(); SysPixelType* pix = win32Img->getImageBits()->pixels_; int sz = win32Img->getWidth() * win32Img->getHeight(); unsigned char* oldAlpaVals = new unsigned char[sz]; do { sz --; oldAlpaVals[sz] = pix[sz].a; pix[sz].a = 0; } while( sz > 0 ); HBITMAP hbmImage = win32Img->getBitmap(); HBITMAP hCopyImg = (HBITMAP)CopyImage( hbmImage, IMAGE_BITMAP, 0, 0, NULL ); Color* transparentColor = imageList->getTransparentColor(); COLORREF color = transparentColor->getColorRef32(); int err = ImageList_AddMasked( imageListCtrl_, hCopyImg, color ); ::DeleteObject( hCopyImg ); sz = win32Img->getWidth() * win32Img->getHeight(); do { sz --; pix[sz].a = oldAlpaVals[sz]; } while( sz > 0 ); delete [] oldAlpaVals; } SendMessage( hwnd_, TB_SETIMAGELIST, 0, (LPARAM)imageListCtrl_ ); if ( NULL == imgListHandler ) { imgListHandler = new ImageListEventHandler<Win32Toolbar>(this, &Win32Toolbar::onImageListImageChanged, "Win32Toolbar::onImageListImageChanged" ); } imageList->SizeChanged.addHandler( imgListHandler ); imageList->ImageAdded.addHandler( imgListHandler ); imageList->ImageDeleted.addHandler( imgListHandler ); bool val = ((Toolbar*)peerControl_)->getShowButtonCaptions(); for (index=0;index<items.size();index++ ) { insertToolbarButton( index, items[index], val ); } SendMessage(hwnd_, TB_AUTOSIZE, 0, 0 ); peerControl_->setVisible( true ); }}/***CVS Log info*$Log$*Revision 1.5 2006/04/07 02:35:26 ddiego*initial checkin of merge from 0.6.9 dev branch.**Revision 1.4.2.4 2006/03/18 19:04:56 ddiego*minor update to remove dead code for checkFontUpdate function.**Revision 1.4.2.3 2006/03/16 03:23:11 ddiego*fixes some font change notification issues in win32 peers.**Revision 1.4.2.2 2006/02/14 20:19:25 ddiego*some minor bugs**Revision 1.4.2.1 2006/02/11 04:51:34 ddiego*little more browser coding.**Revision 1.4 2005/07/09 23:14:58 ddiego*merging in changes from devmain-0-6-7 branch.**Revision 1.3.2.6 2005/06/26 01:31:20 marcelloptr*improvements to the Color class. The default, when packing the components into a single integer, is now cpsARGB instead than cpsABGR.**Revision 1.3.2.5 2005/06/09 06:13:08 marcelloptr*simpler and more useful use of Color class with ctor and getters/setters**Revision 1.3.2.4 2005/05/05 12:42:26 ddiego*this adds initial support for run loops,*fixes to some bugs in the win32 control peers, some fixes to the win32 edit*changes to teh etxt model so that notification of text change is more*appropriate.**Revision 1.3.2.3 2005/04/26 02:29:40 ddiego*fixes font setting bug brought up by scott and glen_f**Revision 1.3.2.2 2005/04/20 02:26:01 ddiego*fixes for single line text and formatting problems in text window creation.**Revision 1.3.2.1 2005/02/16 05:09:32 ddiego*bunch o bug fixes and enhancements to the property editor and treelist control.**Revision 1.3 2004/12/01 04:31:39 ddiego*merged over devmain-0-6-6 code. Marcello did a kick ass job*of fixing a nasty bug (1074768VCF application slows down modal dialogs.)*that he found. Many, many thanks for this Marcello.**Revision 1.2.2.3 2004/11/18 06:45:44 ddiego*updated toolbar btn bug, and added text edit sample.**Revision 1.2.2.2 2004/09/06 21:30:20 ddiego*added a separate paintBorder call to Control class**Revision 1.2.2.1 2004/09/06 18:33:43 ddiego*fixed some more transparent drawing issues**Revision 1.2 2004/08/07 02:49:11 ddiego*merged in the devmain-0-6-5 branch to stable**Revision 1.1.2.11 2004/07/30 17:27:14 kiklop74*Added first release of Borland midifications for VCF**Revision 1.1.2.10 2004/07/21 03:35:49 ddiego*some minor updates to the QTPlayer example**Revision 1.1.2.9 2004/07/15 14:55:11 ddiego*borders fixed**Revision 1.1.2.8 2004/07/14 18:18:14 ddiego*fixed problem with edit control. Turns out we were using the wrong*subclassed wndproc. This is now fixed.**Revision 1.1.2.7 2004/07/14 04:56:02 ddiego*fixed Win32 bugs. Got rid of flicker in the common control*wrappers and toolbar. tracking down combo box display bugs.**Revision 1.1.2.6 2004/07/13 04:34:32 ddiego*little changes**Revision 1.1.2.5 2004/07/11 18:45:34 ddiego*some toolbar fixes, plus some other minor glithches fixed**Revision 1.1.2.4 2004/07/09 18:48:05 ddiego*added locale translation support for most classes**Revision 1.1.2.3 2004/06/26 15:49:36 ddiego*miscellaneous Unicode changes**Revision 1.1.2.2 2004/04/29 03:43:16 marcelloptr*reformatting of source files: macros and csvlog and copyright sections**Revision 1.1.2.1 2004/04/28 00:28:21 ddiego*migration towards new directory structure**Revision 1.2.4.1 2004/04/21 02:17:26 ddiego*checking in change to FoundationKit, GraphicsKit and Application*Kit to support unicode in Win32**Revision 1.2 2003/12/18 05:16:01 ddiego*merge from devmain-0-6-2 branch into the stable branch**Revision 1.1.2.4 2003/12/08 05:05:28 ddiego*added a bunch more documentation to classes, and added support for new doc*keywords (@delegates, @del, @delegate, @event, and @eventtype). This*makes it easier to see at a glance what events a class fires off.*Added finishing touches for the Action implementation and have a partially*complete example for this checked in.**Revision 1.1.2.3 2003/12/02 22:11:31 ddiego*some minor changes to support Actions. Still not done yet.**Revision 1.1.2.2 2003/12/01 03:44:13 ddiego*added some fixes to the Win32Toolbar impl. A few minor changes to the*toolbar example (which also got added). Some minor changes to docs*as well.**Revision 1.1.2.1 2003/10/31 05:06:38 ddiego*added toolbar impl**/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?