Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Is there a way to make a text label appear next to a combo box in a toolbar? Collapse All
Subject Author Date
Paul Boswell Nov 26, 2008 - 11:46 AM

I have a CExtToolControlBar and I put a CExtComboBox into it. How can I make a text label show up next to it like it would for a regular button?

Robert Webb Nov 30, 2008 - 11:49 PM

I discovered a little more regarding my problem posted earlier.  The default width for a CExtBarTextFieldButton is 100 pixels.  However, in our derived classes we specify other widths in the constructor, eg 30 in this example:



MyTextField::MyTextField() : CExtBarTextFieldButton(false, 30)
{
}



However, they still turn up as 100 pixels wide in the GUI, even though calling CExtBarTextFieldButton::GetTextFieldWidth() after InsertSpecButton() does indeed return 30.  Why is this and how do I get it to appear as 30 pixels wide?


So onto my label field.  Remember I said that with method (2) the label came out in the wrong place, part-way through a text field earlier in the toolbar?  Well, measuring distances, it appears that it would be in the right place IF the other text fields had appeared in their appropriate widths.  So I guess the only problem here is that those text fields don’t come out in the width I set.


Any thoughts?


Thanks,

Rob.

Robert Webb Nov 30, 2008 - 7:41 PM

I’m also trying to insert a label on a toolbar, but am having trouble getting it to work.


It seems there are two ways:



  1. Create a CExtBarLabelButton and insert using InsertSpecButton()

  2. Create a CExtLabel and replace a place-holder button with SetButtonCtrl()


Is there any reason to use one over the other?


Method (1) is not used in any of the sample code and I can’t get it to work.  How do I specify the text for the label?  What about the width?


Method (2) I did get to work, sort of, but the label appears on the wrong part of the toolbar!  It starts half way through another edit control.  This toolbar already has other edit-boxes and similar appearing on it, using custom classes derived from CExtBarButton.  Is it necessary to derive a new class just to insert a label?  Is there a problem mixing methods (1) and (2)?


Thanks,

Rob.

Technical Support Dec 1, 2008 - 10:25 AM

It is not the best option to insert a label as a standalone button. A combo box and its label then may turn out to be in two different rows in a floating toolbar, which is resized for displaying its buttons into more than one row. So, we think the best way is to code a custom CExtBarTextFieldButton-derived class which implements the CalculateLayout(), PaintCompound() and OnInplaceControlCalcRect() virtual methods. Make the CalculateLayout() and PaintCompound() similar to the original ones, but reserve some space for the label and paint it. The OnInplaceControlCalcRect() virtual method should return the correct rectangle for text/combo area inside the toolbar button. You can use this combo box button in toolbars by overriding the CExtToolControlBar::OnCreateBarCommandBtn virtual method, in which your button class should be instantiated with an appropriate command identifier. If you are using customizable toolbars and menus, you should override the CExtCustomizeSite::OnCreateToolbarButton() virtual method.

We guess the text/combo button has different widths because you are using customizable toolbars and menus. Please set text/combo field width in the command tree node using the CExtCustomizeCmdTreeNode::TextFieldWidthSet() method. Please also do not forget to remove control bar and customize site state data of your program or invoke the reset command for toolbar with combo/text field to see changes.

Robert Webb Dec 11, 2008 - 12:38 AM

I have found that after the call to CExtCustomizeSite::EnableCustomization(), any custom buttons I have replaced using InsertSpecButton() are changed back again.  I would like this toolbar to be customizable, but how?  Rather than inserting the custom button into the toolbar, shouldn’t I be inserting it into the CExtCmdItem somehow?


Thanks,

Rob.

Technical Support Dec 11, 2008 - 10:48 AM

You should use the CExtToolControlBar::InsertSpecButton() method only with non-customizable toolbars. The customizable toolbars and menus are based on the CExtCustomizeCmdTreeNode command tree nodes and each toolbar button and menu item should have its own command node. The initial command trees are constructed inside customize site. You can specify the command tree flags for each node and ask customize site to create appropriate toolbar buttons. If you need to create your own button classes, then you should implement the CExtToolControlBar::OnCreateBarCommandBtn() virtual method. Please take a look at the CMainFrame::OnCreate() method in the DRAWCLI sample application. It configures several command nodes near invocation of the CExtCustomizeSite::EnableCustomization() method invocation.

Robert Webb Dec 12, 2008 - 12:22 AM

OK, I can see that OnCreateBarCommandBtn() works, although if I customise and create a new toolbar, then it is not of my derived type, so if I drag one of my controls onto it, it won’t draw it right.  Can I tell it to always use my class instead of the default?


Also, I found that the reason I couldn’t get text to display next to the check box (and maybe in labels too but haven’t tested that yet) is simply because the flag to always display text is not set (__ECTN_DISPLAY_TEXTONLY_ALWAYS).  But how do I set this flag?  Before EnableCustomization() there’s no CExtCustomizeCmdTreeNode for the button.  Afterwards I can set the flag, but it doesn’t take, presumably because the control is updated from the CExtCmdItem.  But I can’t see how to tell the CExtCmdItem that this item should always show text.  Any advice?


Thanks,

Rob.

Technical Support Dec 15, 2008 - 9:41 AM

If you cannot implement the OnCreateBarCommandBtn() virtual method for some of your toolbars,you can implement the CExtCustomizeSite::OnCreateToolbarButton() virtual method instead.

The __ECTN_DISPLAY_TEXTONLY_ALWAYS style can be applied using the CExtCustomizeCmdTreeNode::ModifyFlags() method. The command tree node of toolbar button is returned by the CExtBarButton::GetCmdNode() method. To update any changes of visual styles you did you should re-compute layout of toolbar’s parent frame window using the pToolbar->GetParentFrame()->RecalcLayout(); or pToolbarButton->GetBar()->GetParentFrame()->RecalcLayout(); code.

Robert Webb Dec 15, 2008 - 11:47 PM

Oh, yes OnCreateToolbarButton() looks more useful.  I’m not sure why OnCreateBarCommandBtn() would ever be used instead.  I’ll try it out.

Yes, I know about ModifyFlags().  I should have asked when to set that flag rather than how, or how to make it stick.  Setting before EnableCustomization() was not possible, and setting after didn’t work.

I found a solution however.  I found CExtBarButton::OnCustomizeUpdateProps() and overrode that, using it to set the __ECTN_DISPLAY_TEXTONLY_ALWAYS flag.  At last I have text showing up for labels and check boxes!

It really is weird though that the default flags for labels are set so that text is not visible!  Took a long time to figure that out, given it was so unexpected.  Maybe you should change the default flags for labels and check-boxes, or ignore the flag and always display text anyway.

Rob.

Technical Support Dec 18, 2008 - 11:42 AM

The CExtCustomizeSite class allows you to implement customizable toolbars and menus similar to that you can see in Visual Studio and some of MS Office applications. The main idea was to provide the customizable toolbars and menus with the set of basic command items, split buttons, menu trees, edit fields and combo box like fields. These set of basic UI elements should be automatically clone-able via drag-n-dropping in the customize mode and drag-n-dropping with the ALT key pressed. All the multiple copies of each element should be automatically synchronized. This is the main idea of the CExtCustomizeSite class. It’s possible to use other toolbar buttons with the customization subsystem like label buttons in toolbar, but such label buttons assumed as advanced elements and we agree they may require some improvements in the CExtCustomizeSite class.

Technical Support Nov 26, 2008 - 1:33 PM

Please add a command updating method for the button which was used for attaching a combo box control in the toolbar and enable this command. Alternatively you can add a command hander method for this button.

Toolbar buttons are controlled by MFC’s command updating mechanism. If a toolbar button has no handler/updating methods, it will be disabled. If some window is attached to a toolbar button, the window’s enabled state is automatically synchronized with the state of the toolbar button.


Technical Support Nov 26, 2008 - 1:31 PM

You should insert a CExtBarLabelButton into your toolbar near the combo box button using CExtToolControlBar::InsertSpecButton() and CExtToolControlBar::CommandToIndexMethod() allows you to determine the position of the combo box button by its command identifier.

Paul Boswell Nov 26, 2008 - 11:49 AM

I use EnableWindow(FALSE) to set the state of a CExtComboBox in a CExtToolControlBar to disabled. Immediately after the call, the combo box goes disabled. However, whenever I move the cursor over the box, it becomes enabled again.


How do I keep it disabled?