📄 kwqwidget.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 "KWQWidget.h"
#include "KWQExceptions.h"
#include "KWQKHTMLPart.h"
#include "KWQLogging.h"
#include "KWQWindowWidget.h"
#include "WebCoreBridge.h"
#include "khtmlview.h"
#include "WebCorePalette.h"
/*
A QWidget roughly corresponds to an MWebCoreWidget. In Qt a QFrame and QMainWindow inherit
from a QWidget.
*/
class KWQWidgetPrivate
OOM_MODIFIED
{
public:
QStyle *style;
QFont font;
QPalette pal;
MWebCoreWidget* view;
bool visible;
};
QWidget::QWidget() : data(new KWQWidgetPrivate)
{
static QStyle defaultStyle;
data->style = &defaultStyle;
data->view = NULL;
data->visible = true;
}
QWidget::QWidget(MWebCoreWidget* aView) : data(new KWQWidgetPrivate)
{
static QStyle defaultStyle;
data->style = &defaultStyle;
data->view = aView;
data->visible = true;
}
QWidget::~QWidget()
{
delete data;
}
QSize QWidget::sizeHint() const
{
// May be overriden by subclasses.
return QSize(0,0);
}
void QWidget::resize(int w, int h)
{
setFrameGeometry(QRect(pos().x(), pos().y(), w, h));
}
void QWidget::setActiveWindow()
{
KWQKHTMLPart::bridgeForWidget(this)->Client().FocusWindow();
}
void QWidget::setEnabled(bool enabled)
{
// set the widget active or inactive
if( getView() )
getView()->MakeVisible(enabled) ;
}
bool QWidget::isEnabled() const
{
// Tests if the control is visible.
if( getView() )
return getView()->IsVisible() ;
return EFalse;
}
long QWidget::winId() const
{
return (long)this;
}
int QWidget::x() const
{
return frameGeometry().topLeft().x();
}
int QWidget::y() const
{
return frameGeometry().topLeft().y();
}
int QWidget::width() const
{
return frameGeometry().size().width();
}
int QWidget::height() const
{
return frameGeometry().size().height();
}
QSize QWidget::size() const
{
return frameGeometry().size();
}
void QWidget::resize(const QSize &s)
{
resize(s.width(), s.height());
}
QPoint QWidget::pos() const
{
return frameGeometry().topLeft();
}
void QWidget::move(int x, int y)
{
setFrameGeometry(QRect(x, y, width(), height()));
}
void QWidget::move(const QPoint &p)
{
move(p.x(), p.y());
}
QRect QWidget::frameGeometry() const
{
if( getOuterView() ) //FIXME NOKIA: remove this if widgets are implemented
return QRect(getOuterView()->Rect());
return QRect();
}
int QWidget::baselinePosition(int height) const
{
return height;
}
bool QWidget::hasFocus() const
{
if( getView() )
return getView()->IsFocused();
return EFalse;
}
bool QWidget::isActive() const
{
// the derived classes override the behaviour
return false;
}
void QWidget::setFocus()
{
if (hasFocus()) {
return;
}
if ( getView() )
getView()->SetFocus(ETrue);
}
void QWidget::activate()
{
if ( getView() )
getView()->Activate();
}
void QWidget::clearFocus()
{
if (!hasFocus()) {
return;
}
//KWQKHTMLPart::clearDocumentFocus(this);
if ( getView() )
getView()->SetFocus(EFalse);
}
bool QWidget::checksDescendantsForFocus() const
{
return false;
}
QWidget::FocusPolicy QWidget::focusPolicy() const
{
// This provides support for controlling the widgets that take
// part in tab navigation. Widgets must:
// 1. not be hidden by css
// 2. be enabled
// 3. accept first responder
/* RenderWidget *widget = const_cast<RenderWidget *>
(static_cast<const RenderWidget *>(eventFilterObject()));
if (widget->style()->visibility() != khtml::VISIBLE)
return NoFocus;
if (!isEnabled())
return NoFocus;
// overriden by subclasses which can handle key events ,
// the default implementation is a control cannot handle a key event
if (CanHandleKeyEvent())
return NoFocus;
*/
return TabFocus;
}
const QPalette& QWidget::palette() const
{
return data->pal;
}
void QWidget::setPalette(const QPalette &palette)
{
data->pal = palette;
MWebCoreWidget* view = getView();
TWebCorePalette webCorePalette(palette.background().Rgb(), palette.foreground().Rgb());
view->SetPalette(webCorePalette);
}
void QWidget::setOutlineWidth (unsigned short width)
{
MWebCoreWidget* view = getView();
if( view )
{
view->SetOutlineWidth (width);
}
}
QStyle &QWidget::style() const
{
return *data->style;
}
void QWidget::setStyle(QStyle *style)
{
// According to the Qt implementation
/*
Sets the widget's GUI style to \a style. Ownership of the style
object is not transferred.
*/
data->style = style;
}
QFont QWidget::font() const
{
return data->font;
}
void QWidget::setFont(const QFont &font)
{
// ensure the font has renderer before caching it
const_cast<QFont&>(font).Renderer();
data->font = font;
}
void QWidget::constPolish() const
{
}
bool QWidget::isVisible() const
{
// FIXME - rewrite interms of top level widget?
if( getView() )
return getView()->IsVisible();
return EFalse;
}
void QWidget::setCursor(const QCursor &cur)
{
// TODO
}
QCursor QWidget::cursor()
{
//TODO
return QCursor();
}
void QWidget::unsetCursor()
{
setCursor(QCursor());
}
bool QWidget::event(QEvent *)
{
return false;
}
void QWidget::show()
{
if (!data || data->visible)
return;
data->visible = true;
if( getOuterView() )
getOuterView()->MakeVisible(ETrue);
}
void QWidget::hide()
{
if (!data || !data->visible)
return;
data->visible = false;
if( getOuterView() )
getOuterView()->MakeVisible(EFalse);
}
void QWidget::setFrameGeometry(const QRect &rect)
{
if( getOuterView() )
{
MWebCoreWidget* view = getOuterView();
if (view->Rect() != rect.Rect()) {
view->SetRect(rect.Rect());
}
}
}
QPoint QWidget::mapFromGlobal(const QPoint &p) const
{
/*NSPoint bp = {0,0};
bp = [[KWQKHTMLPart::bridgeForWidget(this) window] convertScreenToBase:[data->view convertPoint:p toView:NULL]];
*/
return QPoint(0,0);
}
MWebCoreWidget* QWidget::getView() const
{
return data->view;
}
void QWidget::setView(MWebCoreWidget* view)
{
data->view = view;
}
MWebCoreWidget* QWidget::getOuterView() const
{
// A QScrollView is a widget normally used to represent a frame.
// If this widget's view is a WebCoreFrameView the we resize its containing view, a WebFrameView.
// The scroll view contained by the WebFrameView will be autosized.
MWebCoreWidget* view = getView();
//ASSERT(view);
/*if ([view conformsToProtocol:@protocol(WebCoreFrameView)]) {
view = [view superview];
ASSERT(view);
}
*/
return view;
}
void QWidget::lockDrawingFocus()
{
//[getView() lockFocus];
}
void QWidget::unlockDrawingFocus()
{
}
void QWidget::disableFlushDrawing()
{
}
void QWidget::enableFlushDrawing()
{
}
void QWidget::setDrawingAlpha(float alpha)
{
}
void QWidget::paint(QPainter *p, const QRect &r)
{
if (p->paintingDisabled()) {
return;
}
// KWQTextArea and KWQTextField both rely on the fact that we use this particular
// MWebCoreWidgetControl display method. If you change this, be sure to update them as well.
//getView()->Draw(r.Rect());
if( getView() )
getView()->Draw(p->Gc(), r.Rect());
}
void QWidget::sendConsumedMouseUp()
{
/*khtml::RenderWidget *widget = const_cast<khtml::RenderWidget *>
(static_cast<const khtml::RenderWidget *>(eventFilterObject()));
widget->sendConsumedMouseUp(QPoint([[NSApp currentEvent] locationInWindow]),
// FIXME: should send real state and button
0, 0);
*/
}
void QWidget::setIsSelected(bool isSelected)
{
//[KWQKHTMLPart::bridgeForWidget(this) setIsSelected:isSelected forView:getView()];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -