2021-12-06 07:52 AM
Hi,
I used DG::Palette for an addon and observed it auto re-opens after being closed, when I change to certain views. These are the steps to reproduce the scenario:
This can be tested with the example addon DG_Test > OwnerDrawnListBoxPalette
This however does not happen with the 'Favorites' palette, for example. I want the addon palette to behave like that.
Anyone any idea?
Thanks.
Dushyant
Solved! Go to Solution.
2022-01-03 01:13 PM
Some additional flagging is missing from the palette (DG_Test/OwnerDrawnListBoxPalette) code. The palette state should be stored before the palette temporarily goes to/comes back from hidden state due to window switching.
A static bool variable can be used to temporarily store the visibility state (paletteOpenAtClose):
GSErrCode __ACENV_CALL	OwnerDrawnListBoxPalette::PaletteAPIControlCallBack (Int32 referenceID, API_PaletteMessageID messageID, GS::IntPtr param)
{
	static bool paletteOpenAtClose = false;
	GSErrCode err = NoError;
	if (referenceID == OwnerDrawnListBoxPalette::ODLBPaletteRefId ()) {
		OwnerDrawnListBoxPalette& palette = OwnerDrawnListBoxPalette::GetInstance();
		switch (messageID) {
			case APIPalMsg_ClosePalette:
			case APIPalMsg_HidePalette_Begin:
				if (palette.IsVisible()) {
					paletteOpenAtClose = true;
					palette.Hide();
				} else {
					paletteOpenAtClose = false;
				}
				break;
			case APIPalMsg_OpenPalette:
				paletteOpenAtClose = true;
				// no break
			case APIPalMsg_HidePalette_End:
				if (paletteOpenAtClose && !palette.IsVisible()) {
					palette.Show ();
				}
				break;
			case APIPalMsg_DisableItems_Begin:
				palette.DisableItems();
				break;
			case APIPalMsg_DisableItems_End:
				palette.EnableItems();
				break;
			case APIPalMsg_IsPaletteVisible:
				(*reinterpret_cast<bool*> (param)) = palette.IsVisible();
				break;
			default:
				break;
		}
	}
	return err;
}
2022-01-03 01:13 PM
Some additional flagging is missing from the palette (DG_Test/OwnerDrawnListBoxPalette) code. The palette state should be stored before the palette temporarily goes to/comes back from hidden state due to window switching.
A static bool variable can be used to temporarily store the visibility state (paletteOpenAtClose):
GSErrCode __ACENV_CALL	OwnerDrawnListBoxPalette::PaletteAPIControlCallBack (Int32 referenceID, API_PaletteMessageID messageID, GS::IntPtr param)
{
	static bool paletteOpenAtClose = false;
	GSErrCode err = NoError;
	if (referenceID == OwnerDrawnListBoxPalette::ODLBPaletteRefId ()) {
		OwnerDrawnListBoxPalette& palette = OwnerDrawnListBoxPalette::GetInstance();
		switch (messageID) {
			case APIPalMsg_ClosePalette:
			case APIPalMsg_HidePalette_Begin:
				if (palette.IsVisible()) {
					paletteOpenAtClose = true;
					palette.Hide();
				} else {
					paletteOpenAtClose = false;
				}
				break;
			case APIPalMsg_OpenPalette:
				paletteOpenAtClose = true;
				// no break
			case APIPalMsg_HidePalette_End:
				if (paletteOpenAtClose && !palette.IsVisible()) {
					palette.Show ();
				}
				break;
			case APIPalMsg_DisableItems_Begin:
				palette.DisableItems();
				break;
			case APIPalMsg_DisableItems_End:
				palette.EnableItems();
				break;
			case APIPalMsg_IsPaletteVisible:
				(*reinterpret_cast<bool*> (param)) = palette.IsVisible();
				break;
			default:
				break;
		}
	}
	return err;
}
2022-01-03 01:24 PM
@Miklos Vegh That works perfectly! Thanks a tonne!!