Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Find PopupControl
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Find PopupControl

 Post Reply Post Reply
Author
Message
Paolo View Drop Down
Newbie
Newbie


Joined: 02 March 2006
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Paolo Quote  Post ReplyReply Direct Link To This Post Topic: Find PopupControl
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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:
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Source View Drop Down
Senior Member
Senior Member


Joined: 19 June 2006
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote Source Quote  Post ReplyReply Direct Link To This Post Posted: 18 May 2007 at 7:08am
Can you please send this example in vbasic ?
Regards.
Back to Top
Source View Drop Down
Senior Member
Senior Member


Joined: 19 June 2006
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote Source Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Paolo View Drop Down
Newbie
Newbie


Joined: 02 March 2006
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Paolo Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.027 seconds.