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

📄 render_form.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) *           (C) 1999 Antti Koivisto (koivisto@kde.org) *           (C) 2000 Dirk A. Mueller (mueller@kde.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: render_form.cpp,v 1.2 2002/01/28 04:31:02 leon Exp $ */#include <assert.h>#include "kdebug.h"#include "kurl.h"#include "render_interface.h"#include "mgcolor.h"#include "mgpen.h"#include "mgbrush.h"#include "mgsize.h"#include "mgrect.h"#include "mgfontmetrics.h"#include "mgpainter.h"#include "mghtmlview.h"#include "mghtml_part.h"#include "dom_nodeimpl.h"#include "dom_textimpl.h"#include "dom_docimpl.h"#include "html_formimpl.h"#include "html_documentimpl.h"#include "htmlhashes.h"#include "render_form.h"#include "render_style.h"#include "mghtmlview.h"#include <minigui/filedlg.h>#define CODE_BY_YAN#define FORM_DEBUG	0#define DEBUG_BY_XHTANG 0using namespace khtml;RenderFormElement::RenderFormElement(MGHTMLView *view,                                     HTMLGenericFormElementImpl *element)    : RenderWidget(view){#if FOMR_DEBUG    fprintf(stderr, "RenderFormElemet::RenderFormElement\n");#endif    // init RenderObject attributes    m_inline = true;   // our object is Inline    m_element = element;}RenderFormElement::~RenderFormElement(){}void RenderFormElement::applyLayout(int iWidth, int iHeight){    if(m_widget) {        m_widget->resize (iWidth, iHeight);//        m_widget->setEnabled(!m_element->disabled());    }    m_width  = iWidth  + borderLeft() + paddingLeft() + paddingRight() + borderRight();    m_height = iHeight + borderTop() + paddingTop() + paddingBottom() + borderBottom();}void RenderFormElement::calcMinMaxWidth(){    layout();    //kdDebug( 6040 ) << "inside RenderFormElement::calcMinMaxWidth()" << endl;    m_minWidth = m_width;    m_maxWidth = m_width;}void RenderFormElement::blur(){    //disconnect(m_widget,SIGNAL(blurred()),this,SLOT(slotBlurred()));    //RenderWidget::blur(); // calls m_widget->clearFocus();    //connect(m_widget,SIGNAL(blurred()),this,SLOT(slotBlurred()));}void RenderFormElement::focus(){    //disconnect(m_widget,SIGNAL(focused()),this,SLOT(slotFocused()));    //RenderWidget::focus(); // calls m_widget->setFocus();    //connect(m_widget,SIGNAL(focused()),this,SLOT(slotFocused()));}void RenderFormElement::slotBlurred(){    m_element->onBlur();}void RenderFormElement::slotFocused(){    m_element->onFocus();}void RenderFormElement::slotSelected(){}void RenderFormElement::slotClicked(){	//    m_element->mouseEventHandler(0, DOM::NodeImpl::MouseClick, true);}// ----------------------------------------------------------------------------------------------------------RenderButtonRenderButton::RenderButton(MGHTMLView *view,                           HTMLGenericFormElementImpl *element)    : RenderFormElement(view, element){#if FOMR_DEBUG    fprintf(stderr, "RenderButton::RenderButton\n");#endif}void RenderButton::layout(){    MGSize s;    if(m_widget)        s = m_widget->sizeHint();    applyLayout(s.width(), s.height());    setLayouted();}// -----------------------------------------------------------------------------------------------------------hiddenButtonRenderHiddenButton::RenderHiddenButton(MGHTMLView *view,                                       HTMLInputElementImpl *element)    : RenderButton(view, element){}// -------------------------------------------------------------------------------#if 0CheckBoxWidget::CheckBoxWidget(QWidget *parent)    : QCheckBox(parent){    setAutoMask(true);}void CheckBoxWidget::focusInEvent(QFocusEvent* e){    QCheckBox::focusInEvent(e);    emit focused();}void CheckBoxWidget::focusOutEvent(QFocusEvent* e){    QCheckBox::focusOutEvent(e);    emit blurred();}#endif// ----------------------------------------------------------------------------------------------------------------checkBoxRenderCheckBox::RenderCheckBox(MGHTMLView *view,                               HTMLInputElementImpl *element)    : RenderButton(view, element){#if FOMR_DEBUG    fprintf(stderr,"RenderCheckBox::RenderCheckBox\n");#endif    MGWidgetCheck * p = new MGWidgetCheck(view->getHwnd(), this);	element ->style()->setVerticalAlign(TOP);    setQWidget( p, false );    /*    CheckBoxWidget *b = new CheckBoxWidget(view->viewport());    setQWidget(b, false);    connect(b,SIGNAL(focused()),this,SLOT(slotFocused()));    connect(b,SIGNAL(blurred()),this,SLOT(slotBlurred()));    connect(b,SIGNAL(stateChanged(int)),this,SLOT(slotStateChanged(int)));    connect(b,SIGNAL(clicked()), this, SLOT(slotClicked()));    */}void RenderCheckBox::layout(){    static_cast<MGWidgetCheck*>(m_widget)->setChecked(static_cast<HTMLInputElementImpl*>(m_element)->checked());    RenderButton::layout();}void RenderCheckBox::slotStateChanged(int state){//    kdDebug(0) << " ----------------------------------RenderCheckBox::slotStateChanged(int state) "<< endl;    m_element->setAttribute(ATTR_CHECKED,state == 2 ? "" : 0);}// ----------------------------------------------------------------------------------------------------------RadioButtonRenderRadioButton::RenderRadioButton(MGHTMLView *view,                                     HTMLInputElementImpl *element)    : RenderButton(view, element){#if FOMR_DEBUG    fprintf(stderr,"RenderRadioButton::RenderRadioButton\n");#endif    MGWidgetRadio * p = new MGWidgetRadio(view->getHwnd(), this);	element ->style()->setVerticalAlign(TOP);    setQWidget( p, false );}void RenderRadioButton::setChecked(bool checked){    static_cast<MGWidgetRadio *>(m_widget) -> setChecked(checked);}void RenderRadioButton::slotClicked(){    // emit mouseClick event etc    RenderButton::slotClicked();    m_element->setAttribute(ATTR_CHECKED,"");/*    if (m_element->ownerDocument()->isHTMLDocument())        static_cast<HTMLDocumentImpl*>(m_element->ownerDocument())->updateRendering();*/}void RenderRadioButton::layout(){    static_cast<MGWidgetRadio *>(m_widget)->setChecked(static_cast<HTMLInputElementImpl*>(m_element)->checked());    RenderButton::layout();}// ------------------------------------------------------------------------------------------------------------SubmitButtonRenderSubmitButton::RenderSubmitButton(MGHTMLView *view, HTMLInputElementImpl *element) : RenderButton(view, element){#if FOMR_DEBUG    fprintf(stderr,"RenderSubmitButton::RenderSubmitButton\n");#endif        MGWidgetButton * p = new MGWidgetButton(view->getHwnd(), this);    setQWidget( p, false );}RenderSubmitButton::~RenderSubmitButton(){}void RenderSubmitButton::slotClicked(){//        kdDebug(0) << " ----------------------------------RenderSubmitButton::slotClicked() "<< endl;/*    m_clicked = true;    RenderButton::slotClicked();    // ### if the above line calls some javascript which deletes us we will probably crash here    if (m_element->form())        m_element->form()->prepareSubmit();*/#if DEBUG_BY_XHTANG	fprintf(stderr,"RenderSubmitButton::slotClicked\n");#endif	    m_clicked = true;#if 0	//it seems to do nothing, so I delete it.    RenderButton::slotClicked();#else    RenderButton::slotClicked();#endif    // ### if the above line calls some javascript which deletes us we will probably crash here    if (m_element->form())        m_element->form()->prepareSubmit();}void RenderSubmitButton::layout(){    QString value = static_cast<HTMLInputElementImpl*>(m_element)->value().isEmpty() ?        defaultLabel() : static_cast<HTMLInputElementImpl*>(m_element)->value().string();    value = value.visual();    m_widget->setText(value.stripWhiteSpace());//    static_cast<PushButtonWidget*>(m_widget)->setFont(m_style->font());    RenderButton::layout();}QString RenderSubmitButton::defaultLabel() {    return "Submit";}// -------------------------------------------------------------------------------------------------------------ResetButtonRenderResetButton::RenderResetButton(MGHTMLView *view, HTMLInputElementImpl *element)    : RenderSubmitButton(view, element){}RenderResetButton::~RenderResetButton(){}void RenderResetButton::slotClicked(){//    kdDebug(0) << " ----------------------------------RenderResetButton::slotClicked() "<< endl;    m_clicked = true;    // don't call RenderSubmitButton::slotClicked here!    RenderButton::slotClicked();    if (m_element->form())        m_element->form()->reset();}QString RenderResetButton::defaultLabel() {    return "Reset";}// ----------------------------------------------------------------------------------------------------------------LineEditRenderLineEdit::RenderLineEdit(MGHTMLView *view, HTMLInputElementImpl *element)    : RenderFormElement(view, element){#if FOMR_DEBUG    fprintf(stderr,"MGWidgetEdit::MGWidgetEdit\n");#endif    MGWidgetEdit * p = new MGWidgetEdit(view->getHwnd(), this);        if(element->inputType() != HTMLInputElementImpl::PASSWORD)    p = new MGWidgetEdit(view->getHwnd(), this);    else    p = new MGWidgetEditPassword(view->getHwnd(), this);    setQWidget( p, false );}void RenderLineEdit::layout(){    HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(m_element);    int size = input->size();// inorder to test i have changedit !#if 1    int w = ( int ) ( 6.2 * (size > 0 ? size : 17) ); // "some"#else	int w = ( int ) ( 0*(size > 0? size : 17 ) );#endif    if(m_widget) {    m_widget->setText(static_cast<HTMLInputElementImpl*>(m_element)->value().string().visual());    MGSize size;        if(m_widget){               size = m_widget->sizeHint();        applyLayout(w, size.height());            setLayouted();        }    }}void RenderLineEdit::slotReturnPressed(){    if (m_element->form())        m_element->form()->maybeSubmit();}void RenderLineEdit::slotTextChanged(const QString &string){//    kdDebug(0) << "--------------------------------str = " << string << endl;    static_cast<HTMLInputElementImpl*>(m_element)->setValue(DOMString(string));}void RenderLineEdit::select(){    //static_cast<LineEditWidget*>(m_widget)->selectAll();}// --------------------------------------------------------------------------------------------------------pushbuttonRenderPushButton::RenderPushButton(MGHTMLView *view, HTMLInputElementImpl *element)    : RenderSubmitButton(view, element){}RenderPushButton::~RenderPushButton(){}void RenderPushButton::slotClicked(){    // DON't call RenderSubmitButton::slotClicked here!    RenderButton::slotClicked();}QString RenderPushButton::defaultLabel() {    QString s;    return s;}

⌨️ 快捷键说明

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