Print Page | Close Window

Find PopupControl

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=7168
Printed Date: 01 May 2025 at 6:04pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Find PopupControl
Posted By: Paolo
Subject: Find PopupControl
Date Posted: 17 May 2007 at 11:15am
I create a CXTPPopupToolBar instance and set it as TearOffPopup.
I create a CXTPControlPopup instance and set its CommandBar to be the CXTPPopupToolBar instance that was previously created.
I create a CXTPControl instance (a CXTPControlButton instance) and add it to the CXTPPopupToolBar instance that was previously created.


CXTPPopupToolBar *popupBar_p = CXTPPopupToolBar::CreatePopupToolBar(m_commandBars_p);
popupBar_p->SetTearOffPopup(_T(toolbarTitle.c_str()), 3500, 23 * 5);

CXTPControls *controls_p = toolBar_p->GetControls();
CXTPControlPopup *controlPopup_p = static_cast<CXTPControlPopup *>(controls_p->Add(xtpControlSplitButtonPopup, 3500));

controlPopup_p->SetCommandBar(popupBar_p);

CXTPControl *control_p = popupBar_p->GetControls()->Add(xtpControlButton, 3501);


When I click on this CXTPControlButton I want to get a pointer to its CXTPControlPopup instance parent to change Icon, Tooltip, Description, .. of the parent.

How can I do this?

I tried this way (commandId_ is correctly set to 3501):

    MainFrame *mainFrame_p = static_cast<MainFrame *>(AfxGetMainWnd());
    CXTPCommandBars *commandBars_p = mainFrame_p->GetCommandBars();
    CXTPControl *control_p = commandBars_p->FindControl(xtpControlButton, commandId_, TRUE, TRUE);
    CXTPCommandBar *parentCommandBar_p = control_p->GetParent();
    if ( parentCommandBar_p->IsPopupBar() ) {
         CXTPPopupBar *parentPopupBar_p = static_cast<CXTPPopupBar *>(parentCommandBar_p);
        CXTPControlPopup *controlPopup_p = parentPopupBar_p->GetControlPopup();
        if ( NULL != controlPopup_p ) {
            controlPopup_p->SetCustomIcon(control_p->GetImage()->GetIcon().GetIcon());
        }
    }


But controlPopup_p is always NULL.
Trying to follow events chain I found this:
- method CXTPPopupBar::Popup is called and sets m_pControlPopup to the right pointer: "m_pControlPopup = pControlPopup;";
- CXTPPopupBar::SetTrackingMode is then called and it executes instruction "m_pControlPopup = 0;"
- finally my method to handle button click is called.

So when I handle click for my button (ID=3501) "parentPopupBar_p->GetControlPopup();" returns NULL.

Is there another way to find Popup parent? Is there another way to keep Popup parent's icon, tooltip, description, ... syncronized to last clicked button?

Thanks for any hint. Paolo



Replies:
Posted By: Oleg
Date Posted: 18 May 2007 at 5:58am
Hi,
 
Never use FindControl if your application supports customization - user can delete/copy control and your FindControl will return 0;
 
Here sample how it can work:
https://forum.codejock.com/uploads/20070518_055809_SplitSample.zip - SplitSample.zip


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Source
Date Posted: 18 May 2007 at 7:08am
Can you please send this example in vbasic ?
Regards.


Posted By: Source
Date Posted: 18 May 2007 at 7:23am
My previous request is based on the following example:

Dim Control As CommandBarControl, ControlFile As CommandBarPopup
   
Set ControlFile = cmdBarraPrincipal.ActiveMenuBar.Controls.Add(xtpControlPopup, ID_APP, ID_APP_DESC, -1, False)
    With ControlFile.CommandBar.Controls
        Set Control = .Add(xtpControlButton, ID_APP_ACESSO, ID_APP_ACESSO_DESC)
        Control.BeginGroup = True
    End With

ID_APP = 100 in a const public declaration variable
ID_APP = 101 in a const public declaration variable

Using cmdBarraPrincipal.FindControl(, 100).Enabled = False I can change itīs state, but...

for the popup control 101 (ID_APP_ACESSO) this does not work!

Can you please help.
Regards.
Carlos Neves


Posted By: Paolo
Date Posted: 18 May 2007 at 9:55am
I looker into your sample, if I'm not wrong you're somewhat "hard-coding" a link between PopupControl button and its children.
Let me to explain: all children button set a boolean variable named "m_nOptionID" and parent PopupControl is updated by checking the value of m_nOptionID. By using your m_nOptionID variable I would be forced to create a variable for each set PopupControl-children and this is somewhat difficult to me as these toolbars are created from external source and I should create a non predefined number of variables and link all dynamically created buttons to their own variable.

I think I'll solve this problem by using a STL::map to associate PopupControl and its children while dynamically creating them.

2) In your reply you said me "Never use FindControl if your application supports customization". My previous code was just part of my application, and some cheks may have been omitted to make code block shorter. If I do check control_p to be non NULL would it be correct to use FindControl? If not, which is the correct way to get a Control pointer given its ID?

Thanks for help. Paolo



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net