示例#1
0
LLComboBox::LLComboBox(const std::string& name, const LLRect& rect, const std::string& label, commit_callback_t commit_callback)
:	LLUICtrl(name, rect, TRUE, commit_callback, FOLLOWS_LEFT | FOLLOWS_TOP),
	mTextEntry(NULL),
	mTextEntryTentative(TRUE),
	mArrowImage(NULL),
	mHasAutocompletedText(false),
	mAllowTextEntry(false),
	mAllowNewValues(false),
	mMaxChars(20),
	mPrearrangeCallback( NULL ),
	mTextEntryCallback( NULL ),
	mListPosition(BELOW),
	mSuppressTentative( false ),
	mSuppressAutoComplete( false ),
	mListColor(LLUI::sColorsGroup->getColor("ComboBoxBg")),
	mLastSelectedIndex(-1),
	mLabel(label)
{
	// Always use text box 
	// Text label button
	mButton = new LLButton(mLabel, LLRect(), LLStringUtil::null);
	mButton->setImageUnselected(LLUI::getUIImage("square_btn_32x128.tga"));
	mButton->setImageSelected(LLUI::getUIImage("square_btn_selected_32x128.tga"));
	mButton->setImageDisabled(LLUI::getUIImage("square_btn_32x128.tga"));
	mButton->setImageDisabledSelected(LLUI::getUIImage("square_btn_selected_32x128.tga"));
	mButton->setScaleImage(TRUE);

	mButton->setMouseDownCallback(boost::bind(&LLComboBox::onButtonMouseDown,this));
	mButton->setFont(LLFontGL::getFontSansSerifSmall());
	mButton->setFollows(FOLLOWS_LEFT | FOLLOWS_BOTTOM | FOLLOWS_RIGHT);
	mButton->setHAlign( LLFontGL::LEFT );
	mButton->setRightHPad(2);

	addChild(mButton);

	// disallow multiple selection
	mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(),
								 boost::bind(&LLComboBox::onItemSelected, this, _2), FALSE);
	mList->setVisible(false);
	mList->setBgWriteableColor(mListColor);
	mList->setCommitOnKeyboardMovement(false);
	addChild(mList);

	// Mouse-down on button will transfer mouse focus to the list
	// Grab the mouse-up event and make sure the button state is correct
	mList->setMouseUpCallback(boost::bind(&LLComboBox::onListMouseUp, this));

	mArrowImage = LLUI::getUIImage("combobox_arrow.tga");
	mButton->setImageOverlay("combobox_arrow.tga", LLFontGL::RIGHT);

	updateLayout();

	mTopLostSignalConnection = setTopLostCallback(boost::bind(&LLComboBox::hideList, this));
}
LLComboBox::LLComboBox(	const std::string& name, const LLRect &rect, const std::string& label,
	void (*commit_callback)(LLUICtrl*,void*),
	void *callback_userdata
	)
:	LLUICtrl(name, rect, TRUE, commit_callback, callback_userdata, 
			 FOLLOWS_LEFT | FOLLOWS_TOP),
	mTextEntry(NULL),
	mArrowImage(NULL),
	mAllowTextEntry(FALSE),
	mMaxChars(20),
	mTextEntryTentative(TRUE),
	mListPosition(BELOW),
	mPrearrangeCallback( NULL ),
	mTextEntryCallback( NULL ),
	mSuppressTentative( false ),
	mSuppressAutoComplete( false ),
	mLabel(label),
	mListColor(LLUI::sColorsGroup->getColor("ComboBoxBg"))
{
	// Always use text box 
	// Text label button
	mButton = new LLButton(mLabel,
								LLRect(), 
								LLStringUtil::null,
								NULL, this);
	mButton->setImageUnselected(LLUI::getUIImage("square_btn_32x128.tga"));
	mButton->setImageSelected(LLUI::getUIImage("square_btn_selected_32x128.tga"));
	mButton->setImageDisabled(LLUI::getUIImage("square_btn_32x128.tga"));
	mButton->setImageDisabledSelected(LLUI::getUIImage("square_btn_selected_32x128.tga"));
	mButton->setScaleImage(TRUE);

	mButton->setMouseDownCallback(boost::bind(&LLComboBox::onButtonDown,this));
	mButton->setFont(LLFontGL::getFontSansSerifSmall());
	mButton->setFollows(FOLLOWS_LEFT | FOLLOWS_BOTTOM | FOLLOWS_RIGHT);
	mButton->setHAlign( LLFontGL::LEFT );
	mButton->setRightHPad(2);
	addChild(mButton);

	// disallow multiple selection
	mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(), 
								 &LLComboBox::onItemSelected, this, FALSE);
	mList->setVisible(FALSE);
	mList->setBgWriteableColor(mListColor);
	mList->setCommitOnKeyboardMovement(FALSE);
	addChild(mList);

	mArrowImage = LLUI::getUIImage("combobox_arrow.tga");
	mButton->setImageOverlay("combobox_arrow.tga", LLFontGL::RIGHT);

	updateLayout();
	
	mTopLostSignalConnection = setTopLostCallback(boost::bind(&LLComboBox::hideList, this));
}
示例#3
0
LLComboBox::LLComboBox(const LLComboBox::Params& p)
:	LLUICtrl(p),
	mTextEntry(NULL),
	mTextEntryTentative(p.show_text_as_tentative),
	mHasAutocompletedText(false),
	mAllowTextEntry(p.allow_text_entry),
	mAllowNewValues(p.allow_new_values),
	mMaxChars(p.max_chars),
	mPrearrangeCallback(p.prearrange_callback()),
	mTextEntryCallback(p.text_entry_callback()),
	mListPosition(p.list_position),
	mLastSelectedIndex(-1),
	mLabel(p.label)
{
	// Text label button

	LLButton::Params button_params = (mAllowTextEntry ? p.combo_button : p.drop_down_button);
	button_params.mouse_down_callback.function(
		boost::bind(&LLComboBox::onButtonMouseDown, this));
	button_params.follows.flags(FOLLOWS_LEFT|FOLLOWS_BOTTOM|FOLLOWS_RIGHT);
	button_params.rect(p.rect);

	if(mAllowTextEntry)
	{
		button_params.pad_right(2);
	}

	mArrowImage = button_params.image_unselected;

	mButton = LLUICtrlFactory::create<LLButton>(button_params);

	
	if(mAllowTextEntry)
	{
		//redo to compensate for button hack that leaves space for a character
		//unless it is a "minimal combobox"(drop down)
		mButton->setRightHPad(2);
	}
	addChild(mButton);

	LLScrollListCtrl::Params params = p.combo_list;
	params.name("ComboBox");
	params.commit_callback.function(boost::bind(&LLComboBox::onItemSelected, this, _2));
	params.visible(false);
	params.commit_on_keyboard_movement(false);

	mList = LLUICtrlFactory::create<LLScrollListCtrl>(params);
	addChild(mList);

	// Mouse-down on button will transfer mouse focus to the list
	// Grab the mouse-up event and make sure the button state is correct
	mList->setMouseUpCallback(boost::bind(&LLComboBox::onListMouseUp, this));

	for (LLInitParam::ParamIterator<ItemParams>::const_iterator it = p.items.begin();
		it != p.items.end();
		++it)
	{
		LLScrollListItem::Params item_params = *it;
		if (it->label.isProvided())
		{
			item_params.columns.add().value(it->label());
		}

		mList->addRow(item_params);
	}

	createLineEditor(p);

	mTopLostSignalConnection = setTopLostCallback(boost::bind(&LLComboBox::hideList, this));
}
示例#4
0
LLSplitButton::LLSplitButton(const LLSplitButton::Params& p)
:	LLUICtrl(p),
	mArrowBtn(NULL),
	mShownItem(NULL),
	mItemsPanel(NULL),
	mArrowPosition(p.arrow_position)
{
	LLRect rc(p.rect);

	LLButton::Params arrow_params = p.arrow_button;
	S32 arrow_width = p.arrow_button.rect.width;

	//Default arrow rect values for LEFT arrow position
	S32 arrow_left = 0;
	S32 arrow_right = arrow_width;
	S32 btn_left = arrow_width;
	S32 btn_right = rc.getWidth();

	if (mArrowPosition == RIGHT)
	{
		arrow_left = rc.getWidth()- arrow_width;
		arrow_right = rc.getWidth();
		btn_left = 0;
		btn_right = arrow_left;
	}

	arrow_params.rect(LLRect(arrow_left, rc.getHeight(), arrow_right, 0));
	arrow_params.label("");
	arrow_params.mouse_down_callback.function(boost::bind(&LLSplitButton::onArrowBtnDown, this));
	mArrowBtn = LLUICtrlFactory::create<LLButton>(arrow_params);
	addChild(mArrowBtn);

	//a panel for hidden item buttons
	LLPanel::Params panel_params = p.items_panel;
	mItemsPanel= prepareItemsPanel(panel_params, p.items.numValidElements());
	addChild(mItemsPanel);


	LLInitParam::ParamIterator<ItemParams>::const_iterator it = p.items().begin();

	//processing shown item button
	mShownItem = prepareItemButton(*it);
	mShownItem->setHeldDownCallback(boost::bind(&LLSplitButton::onHeldDownShownButton, this));
	mShownItem->setMouseUpCallback(boost::bind(&LLSplitButton::onItemSelected, this, _1));
	mShownItem->setRect(LLRect(btn_left, rc.getHeight(), btn_right, 0));
	addChild(mShownItem);

	//processing hidden item buttons
	S32 item_top = mItemsPanel->getRect().getHeight();
	for (++it; it != p.items().end(); ++it)
	{
		LLButton* hidden_button = prepareItemButton(*it);
		hidden_button->setRect(LLRect(btn_left, item_top, btn_right, item_top - rc.getHeight()));
		hidden_button->setMouseDownCallback(boost::bind(&LLSplitButton::onItemSelected, this, _1));
		mHidenItems.push_back(hidden_button);
		mItemsPanel->addChild(hidden_button);

		//calculate next button's top
		item_top -= (rc.getHeight() + BUTTON_PAD);
	}

	setTopLostCallback(boost::bind(&LLSplitButton::hideButtons, this));
}