コード例 #1
0
void Toolbar::updateAction( unsigned int& index, ItemPtr item, TBBUTTONINFO& info )
{
	unsigned int mask = BTNS_SEP | BTNS_CHECK | BTNS_GROUP | BTNS_CHECKGROUP | BTNS_DROPDOWN;
	if( ( info.fsStyle & mask ) != 0 || // not a push 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_BUTTON;
		button.dwData = 0;
		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];
	buttonInfo.fsState = item->update()	&& isEnabled() ?	TBSTATE_ENABLED : 0;
	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 );
}
コード例 #2
0
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 );
}
コード例 #3
0
void Toolbar::updateChoice( unsigned int& index, ItemPtr item, TBBUTTONINFO& info )
{
	unsigned int i = 0;
	while( index < (unsigned int)sendMessage( TB_BUTTONCOUNT, 0, 0 ) &&
		i < item->num() )
	{
		static const unsigned int MAX_MENU_TEXT = 1024;
		char txtBuf[ MAX_MENU_TEXT + 1 ];

		TBBUTTONINFO info = { sizeof( info ), TBIF_BYINDEX | TBIF_COMMAND | TBIF_IMAGE
			| TBIF_LPARAM | TBIF_SIZE | TBIF_STATE | TBIF_STYLE | TBIF_TEXT };
		info.pszText = txtBuf;
		info.cchText = MAX_MENU_TEXT;

		sendMessage( TB_GETBUTTONINFO, index, (LPARAM)&info );

		ItemPtr subItem = (*item)[ i ];

		if( ( info.fsStyle & BTNS_CHECK ) == 0 || // not a toggle button
			info.idCommand != subItem->commandID() ) // not for me
		{
			TBBUTTON button;
			memset(	&button, 0, sizeof(button) );
			button.iBitmap = getImageIndex( subItem );
			button.idCommand = subItem->commandID();
			button.fsState = TBSTATE_ENABLED;
			button.fsStyle = BTNS_CHECK;
			button.dwData = 0;
			button.iString = -1;
			sendMessage( TB_INSERTBUTTON, index, (LPARAM)&button );
		}
		TBBUTTONINFO buttonInfo = { sizeof( buttonInfo ), TBIF_TEXT | TBIF_BYINDEX | TBIF_STATE };
		std::string tooltip = subItem->description();	// auto tooltip
		if( subItem->shortcutKey().size() || item->shortcutKey().size() )
		{
			if (subItem->shortcutKey().size() && item->shortcutKey().size())
			{
				tooltip = 
					L
					(
						"GUIMANAGER/GUI_TOOLBAR/TOOLTIP_FORM0", 
						subItem->description(),
						subItem->shortcutKey(),
						item->shortcutKey()
					);
			}
			else if (subItem->shortcutKey().size())
			{
				tooltip =
					L
					(
						"GUIMANAGER/GUI_TOOLBAR/TOOLTIP_FORM1",
						subItem->description(),
						subItem->shortcutKey()
					);
			}
			else if (item->shortcutKey().size())
			{
				tooltip =
					L
					(
						"GUIMANAGER/GUI_TOOLBAR/TOOLTIP_FORM2",
						subItem->description(),
						item->shortcutKey()
					);
			}
		}
		buttonInfo.pszText = &tooltip[0];
		LPARAM enabled = item->update()	&& isEnabled() ?	TBSTATE_ENABLED : 0;
		LPARAM checked = subItem->update()	?	TBSTATE_CHECKED : 0;
		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 );
		++i;
		++index;
	}
	while( i < item->num() )
	{
		ItemPtr subItem = (*item)[ i ];

		TBBUTTON button;
		memset(	&button, 0, sizeof(button) );
		button.iBitmap = getImageIndex( subItem );
		button.idCommand = subItem->commandID();
		button.fsState = TBSTATE_ENABLED;
		button.fsStyle = BTNS_CHECK;
		button.dwData = 0;
		button.iString = -1;
		sendMessage( TB_INSERTBUTTON, index, (LPARAM)&button );

		TBBUTTONINFO buttonInfo = { sizeof( buttonInfo ), TBIF_TEXT | TBIF_BYINDEX | TBIF_STATE };
		std::string tooltip = subItem->description();	// auto tooltip
		if( subItem->shortcutKey().size() || item->shortcutKey().size() )
		{
			if (subItem->shortcutKey().size() && item->shortcutKey().size())
			{
				tooltip = 
					L
					(
						"GUIMANAGER/GUI_TOOLBAR/TOOLTIP_FORM0", 
						subItem->description(),
						subItem->shortcutKey(),
						item->shortcutKey()
					);
			}
			else if (subItem->shortcutKey().size())
			{
				tooltip =
					L
					(
						"GUIMANAGER/GUI_TOOLBAR/TOOLTIP_FORM1",
						subItem->description(),
						subItem->shortcutKey()
					);
			}
			else if (item->shortcutKey().size())
			{
				tooltip =
					L
					(
						"GUIMANAGER/GUI_TOOLBAR/TOOLTIP_FORM2",
						subItem->description(),
						item->shortcutKey()
					);
			}
		}
		buttonInfo.pszText = &tooltip[0];
		LPARAM enabled = item->update()	&& isEnabled() ?	TBSTATE_ENABLED : 0;
		LPARAM checked = subItem->update()	?	TBSTATE_CHECKED : 0;
		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 );
		++i;
		++index;
	}
	--index;
}