void Item::add( ItemPtr item ) { if( isAncestor( item.getObject() ) ) throw 1; subitems_.push_back( item ); item->addParent( this ); }
void Menu::insertMenuItem( HMENU hmenu, int index, ItemPtr item ) { MENUITEMINFO info = { sizeof( info ), MIIM_STRING | MIIM_ID | MIIM_DATA, 0, 0, item->commandID(), NULL, NULL, NULL, (DWORD)item.getObject(), "menu" }; InsertMenuItem( hmenu, index, MF_BYPOSITION, &info ); }
int Toolbar::getImageIndex( ItemPtr item ) { if( imageIndices_.find( item.getObject() ) == imageIndices_.end() ) { COLORREF transparency = RGB( 192, 192, 192 ); if( item->exist( "transparency" ) ) { std::string color = (*item)[ "transparency" ]; if( std::count( color.begin(), color.end(), ',' ) == 2 ) { BYTE r = atoi( color.c_str() ); BYTE g = atoi( color.c_str() + color.find( ',' ) + 1 ); std::string::size_type next = color.find( ',' ) + 1; BYTE b = atoi( color.c_str() + color.find( ',', next ) + 1 ); transparency = RGB( r, g, b ); } } BitmapPtr bitmap = Manager::instance().bitmaps().get( (*item)["imageNormal"], transparency ); result_ = ImageList_Add( normalImageList_, (*bitmap), NULL ); if( item->exist( "imageHot" ) ) ImageList_Add( hotImageList_, *Manager::instance().bitmaps().get( (*item)["imageHot"], transparency ), NULL ); else ImageList_Add( hotImageList_, *Manager::instance().bitmaps().get( (*item)["imageNormal"], transparency, "HOVER" ), NULL ); if( item->exist( "imageDisabled" ) ) ImageList_Add( disabledImageList_, *Manager::instance().bitmaps().get( (*item)["imageDisabled"], transparency ), NULL ); else ImageList_Add( disabledImageList_, *Manager::instance().bitmaps().get( (*item)["imageNormal"], transparency, "DISABLED" ), NULL ); imageIndices_[ item.getObject() ] = result_; } return imageIndices_[ item.getObject() ]; }
void Menu::updateChoice( HMENU hmenu, int& index, ItemPtr item, const MENUITEMINFO& info ) { static const unsigned int MAX_MENU_TEXT = 1024; char txtBuf[ MAX_MENU_TEXT + 1 ]; unsigned int subItemIndex = 0; while( index < GetMenuItemCount( hmenu ) ) { MENUITEMINFO info = { sizeof( info ), MIIM_BITMAP | MIIM_CHECKMARKS | MIIM_DATA | MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING | MIIM_SUBMENU }; info.cch = MAX_MENU_TEXT; info.dwTypeData = txtBuf; GetMenuItemInfo( hmenu, index, TRUE, &info ); if( info.dwItemData != (DWORD)item.getObject() ) break; if( subItemIndex < item->num() ) { ItemPtr subItem = ( *item )[ subItemIndex ]; if( !info.dwTypeData || buildMenuText( subItem ) != (LPCTSTR)info.dwTypeData ) insertMenuItem( hmenu, index, item ); ModifyMenu( hmenu, index, MF_BYPOSITION | MF_STRING, subItem->commandID(), buildMenuText( subItem ).c_str() ); EnableMenuItem( hmenu, index, MF_BYPOSITION | ( item->update() ? MF_ENABLED : MF_GRAYED ) ); CheckMenuItem( hmenu, index, MF_BYPOSITION | ( subItem->update() ? MF_CHECKED : MF_UNCHECKED ) ); ++index; ++subItemIndex; } else DeleteMenu( hmenu, index, MF_BYPOSITION ); } while( subItemIndex < item->num() ) { ItemPtr subItem = ( *item )[ subItemIndex ]; insertMenuItem( hmenu, index, item ); ModifyMenu( hmenu, index, MF_BYPOSITION | MF_STRING, subItem->commandID(), buildMenuText( subItem ).c_str() ); EnableMenuItem( hmenu, index, MF_BYPOSITION | ( item->update() ? MF_ENABLED : MF_GRAYED ) ); CheckMenuItem( hmenu, index, MF_BYPOSITION | ( subItem->update() ? MF_CHECKED : MF_UNCHECKED ) ); ++subItemIndex; } --index; }
void Toolbar::updateToggle( unsigned int& index, ItemPtr item, TBBUTTONINFO& info ) { if( ( info.fsStyle & BTNS_CHECK ) == 0 || // not a toggle button info.idCommand != item->commandID() ) // not for me { TBBUTTON button; memset( &button, 0, sizeof(button) ); button.iBitmap = getImageIndex( item ); button.idCommand = item->commandID(); button.fsState = TBSTATE_ENABLED; button.fsStyle = BTNS_CHECK; button.dwData = (DWORD)item.getObject(); button.iString = -1; sendMessage( TB_INSERTBUTTON, index, (LPARAM)&button ); } TBBUTTONINFO buttonInfo = { sizeof( buttonInfo ), TBIF_TEXT | TBIF_BYINDEX | TBIF_STATE }; std::string tooltip = item->description(); // auto tooltip if( item->shortcutKey().size() ) { tooltip += " ("; tooltip += item->shortcutKey(); tooltip += ')'; } buttonInfo.pszText = &tooltip[0]; LPARAM enabled = item->update() && isEnabled() ? TBSTATE_ENABLED : 0; LPARAM checked = ( *item )[ 0 ]->update() ? 0 : TBSTATE_CHECKED; if( !enabled ) checked = 0; buttonInfo.fsState = (BYTE)( enabled | checked ); if ( sendMessage( WM_CGUITOOLBAR_USE_WRAP, 0, 0 ) && ( info.fsState & TBSTATE_WRAP ) ) buttonInfo.fsState |= TBSTATE_WRAP; if( forceChanged_ || info.pszText != tooltip || info.fsState != buttonInfo.fsState ) sendMessage( TB_SETBUTTONINFO, index, (LPARAM)&buttonInfo ); }