⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kwqcombobox.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
字号:
/*
 * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
 * Portions Copyright (c) 2005 Nokia Corporation, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "KWQComboBox.h"
#include "KWQAssertions.h"
#include "KWQButton.h"
#include "KWQKHTMLPart.h"
#include "WebCoreBridge.h"

QComboBox::QComboBox()
    : _widthGood(false)
    , _currentItem(0)
    , _menuPopulated(true)
    , _activated(this, SIGNAL(activated(int)))
{
	_selectWidget = TWebCoreFormControlFactory::Factory()->ConstructSelect(EFalse);
	if(_selectWidget)
	{
		_selectWidget->SetEventHandler(this);
		setView(_selectWidget);
	}
}

QComboBox::~QComboBox()
{
	if(_selectWidget)
	{
		_selectWidget->Close();
	}
}

void QComboBox::appendItem(const QString &text, bool isLabel, bool isDisabled)
{
	if(_selectWidget)
	{
		_selectWidget->AppendItem(text.Des(), isLabel, isDisabled);
	}
}

QSize QComboBox::sizeHint() const
{
	if(_selectWidget)
	{
		return QSize(_selectWidget->SizeForNumberOfLines(1));
	}
	return QSize(0,0);
}

QRect QComboBox::frameGeometry() const
{
	if(_selectWidget)
	{
		return QRect(_selectWidget->Rect());
	}
	return QRect();
}

void QComboBox::setFrameGeometry(const QRect &r)
{
	if(_selectWidget)
	{
		_selectWidget->SetRect(r.Rect());
	}
}

int QComboBox::baselinePosition(int height) const
{
    return height;
}

void QComboBox::clear()
{
	if(_selectWidget)
	{
		_selectWidget->Clear();
	}
}

void QComboBox::setCurrentItem(int index)
{
	if(_selectWidget)
	{
		_selectWidget->ClearSelection();
		_selectWidget->SetSelected(index, ETrue);
		_selectWidget->DoneSelectingItems();
	}
}

void QComboBox::itemSelected()
{
	ASSERT(_menuPopulated);
	if(_selectWidget)
	{
		_activated.call(_selectWidget->SelectedIndex());
	}
}

void QComboBox::setFont(const QFont &font)
{
	QWidget::setFont(font);
	if(_selectWidget)
	{
		QFont fontCpy = font;
		CFont* symFont = const_cast<CFont*>(fontCpy.Font());
		_selectWidget->SetFont(symFont );
	}
}

QWidget::FocusPolicy QComboBox::focusPolicy() const
{
    return QWidget::focusPolicy();
}

void QComboBox::setWritingDirection(QPainter::TextDirection direction)
{
}

void QComboBox::populateMenu()
{
	/*
    if (!_menuPopulated) {
        KWQ_BLOCK_EXCEPTIONS;

        KWQPopUpButton *button = getView();
	[button setPopulatingMenu:YES];
        [button removeAllItems];
        QValueListConstIterator<KWQListBoxItem> i = const_cast<const QValueList<KWQListBoxItem> &>(_items).begin();
        QValueListConstIterator<KWQListBoxItem> e = const_cast<const QValueList<KWQListBoxItem> &>(_items).end();
        for (; i != e; ++i) {
            // We must add the item with no title and then set the title because
            // addItemWithTitle does not allow duplicate titles.
            [button addItemWithTitle:@""];
            NSMenuItem *menuItem = [button lastItem];
            setTitle(menuItem, *i);
        }
        [button selectItemAtIndex:_currentItem];
	[button setPopulatingMenu:NO];

        KWQ_UNBLOCK_EXCEPTIONS;

        _menuPopulated = true;
    }
    */
}

void QComboBox::populate()
{
    populateMenu();
}


void QComboBox::HandleEvent(TEvent aEvent)
{
	itemSelected();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -