![]() |
global toolbar button image replacement |
Post Reply ![]() |
Author | |
brianh ![]() Groupie ![]() Joined: 30 April 2004 Location: United Kingdom Status: Offline Points: 83 |
![]() ![]() ![]() ![]() ![]() Posted: 07 December 2006 at 11:46am |
Hi, I would like to be able to replace some or all of the toolbar button images used in my application at program startup. Since all toolbars seem to use a global image manager instance by default (accessed by calling XTPImageManager()) it would be possible to set these new images by using CXTPImageManager::SetIcon(...) on this global instance, and passing in each new Icon ID and corresponding button command ID.
Unfortunately, if I do this at present then, when the toolbar is loaded, it overwrites the images I already added with the ones in the toolbar.
![]() Is it possible to add an option to the CXTPImageManager class to tell it not to overwrite existing icons? With this option it would be possible to replace all occurrences of a given toolbar button with a new image just by loading the new icon into the image manager at program startup and setting the "don't overwrite" option.
This also nicely gets around the problem of only being able to create toolbars with 16 colours in Visual Studio as the new icons can be full colour. :)
Thanks.
Brian
|
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
each toolbar or whole CommandBars can use individual imagemanager:
pCommandBars->SetImageManager(new CXTPImageManager());
There is option in LoadToolBar call to not load icons at all...
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
brianh ![]() Groupie ![]() Joined: 30 April 2004 Location: United Kingdom Status: Offline Points: 83 |
![]() ![]() ![]() ![]() ![]() |
Hi Oleg, I realise that each toolbar can have it's own image manager, but by default they all share one, which suits me fine because it would let me change icons in just one place to affect the whole application, which is what I want.
Telling the toolbars not to load any icons doesn't really help, because I would then NEED to load ALL the icons for ALL the toolbars at startup.
![]() What I want to do is have each toolbar load as normal, but if we decide to replace an icon for a command that is used in more than one toolbar, for instance the "refresh" icon, we can just pre-load this at start up and all toolbars with this command will still load all their icons as normal, except they won't replace this one pre-loaded icon.
Adding an option to CXTPImageManager to tell it not to overwrite existing icons would allow this to work. Alternatively, making some of the class's functions virtual would allow me to do this in my own override.
![]() |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hi,
You can assign another Id for such buttons. It is not logical - All buttons that have same Id must have same icon.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
brianh ![]() Groupie ![]() Joined: 30 April 2004 Location: United Kingdom Status: Offline Points: 83 |
![]() ![]() ![]() ![]() ![]() |
Hi Oleg, sorry, I don't think I've made myself clear.
![]() I want all buttons with the same ID to have the same icon, but I want to be able to change that icon in just one place. So instead of modifying all the toolbars that have the "refresh" command to use a new icon, I would just set the new icon for the refresh command's ID in the image manager at application start up. Then when each toolbar is loaded, it would see that there is already an icon for that command ID and not replace it with the (old) image from the toolbar's button.
![]() |
|
![]() |
|
rmercer ![]() Groupie ![]() Joined: 22 February 2006 Status: Offline Points: 34 |
![]() ![]() ![]() ![]() ![]() |
Passing FALSE for bLoadIcons in LoadToolBar() will do what you're looking for.
For example:
XTPImageManager()->SetIcon(IDI_TOOLBARICON1, ID_TOOLBARITEM1); // call for all toolbar items // IDR_TOOLBAR has only one item: ID_TOOLBARITEM1
CXTPToolBar *pBar = (CXTPToolBar*)pCommandBars->Add(_T("Test toolbar"), xtpBarTop); if (!pBar || !pBar->LoadToolBar(IDR_TOOLBAR, FALSE))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
I typed that by hand, so please excuse any mistakes.
|
|
![]() |
|
brianh ![]() Groupie ![]() Joined: 30 April 2004 Location: United Kingdom Status: Offline Points: 83 |
![]() ![]() ![]() ![]() ![]() |
Hi rmercer,
As I said to Oleg, I don't want to HAVE to load ALL the icons for ALL the toolbars at startup, I want the toolbars to load all their own icons as normal, EXCEPT for any command icons that I choose to pre-load at startup, that way I can replace just some icons as and when I like without having to edit every toolbar or load ALL the icons at startup.
If there was an option in the CXTPImageManager class to prevent existing images being overwritten, this would work. I could load any "new" icons that I want to use into the image manager at startup, set the option to prevent images being ovewritten, and allow toolbars to load as normal. Then when the toolbar loads, all it's icons for the commands would be loaded as normal, EXCEPT for the "new" ones which I already loaded at statup, thus I would have replaced these icons in ALL the toolbars without having had to edit any of them.
Replacing whole image sets could be done, as you and Oleg have suggested, by preventing the toolbars from loading any images at all and instead loading them ALL at startup, but this lacks the flexibilty to replace just some specific icons. It also means that we have to ensure that every piece of code that loads a toolbar passes FALSE for the "load icons" option, and that there is an icon loaded for every command button at startup - not a big deal but the fewer places you need to change code the less chance of making mistakes.
Having the option I've suggested for CXTPImageManager keeps all the changes in one place, toolbar loading code does not have to change, and if we forget to add a new icon for any command the original toolbar icon will still be used.
![]() |
|
![]() |
|
rmercer ![]() Groupie ![]() Joined: 22 February 2006 Status: Offline Points: 34 |
![]() ![]() ![]() ![]() ![]() |
Have you tried loading your toolbars first, then load your custom icons? I believe I do this in a few of my applications and it works without any issue, plus I change some icons depending on user activity and they update in the UI appropriately...
Maybe I'm mistaken though... I usually load all my icons manually first, since they're all alpha icons, and don't load them in LoadToolbar().
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |