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

📄 htmlview.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* This file is part of the KDE libraries    Copyright (C) 1997 Martin Jones (mjones@kde.org)              (C) 1997 Torben Weis (weis@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.*///----------------------------------------------------------------------------//// KDE HTML Widget//// Copyright (c) 1997 The KDE Project//#include "htmlview.h"#include <kcursor.h>#define SCROLLBAR_WH 12QList<KHTMLView> *KHTMLView::viewList = 0L;KHTMLView::KHTMLView( QWidget *_parent, const char *_name, int _flags, KHTMLView *_parent_view )     : QWidget( _parent, _name, _flags ){        parentView = _parent_view;        // Allow resizing of frame    bAllowResize = TRUE;    // Set scrolling to auto    scrolling = -1;    // border on    frameBorder = 1;        // debugT("Constructed KHTML View\n");        if ( viewList == 0L )	viewList = new QList<KHTMLView>;    viewList->setAutoDelete( FALSE );    viewList->append( this );        frameName = _name;        displayVScroll = FALSE;    displayHScroll = FALSE;    // This is the second part of the ugly hack in main.cpp    // we need to make sure that we have a real parent before    // we map our window so that the window manager doesn't    // grab this. ... jsk    if(_flags) { ((Fl_Window *)_flags)->add(this); }    // These are needed to make sure the parents are shown    // before we are .. jsk    if(_parent) { _parent->add(this); _parent->raise(); }    if(_parent_view) { _parent_view->raise();}    raise();    initGUI();}KHTMLView::~KHTMLView(){  viewList->removeRef( this );        // debugT("Deleted View\n");}KHTMLView* KHTMLView::newView( QWidget *_parent, const char *_name, int _flags ){    return new KHTMLView( _parent, _name, _flags, this );    /*    connect( view, SIGNAL( documentStarted( KHTMLView * ) ),	     this, SLOT( slotDocumentStarted( KHTMLView * ) ) );    connect( view, SIGNAL( documentDone( KHTMLView * ) ),	     this, SLOT( slotDocumentDone( KHTMLView * ) ) );    connect( view, SIGNAL( imageRequest( KHTMLView *, const char * ) ),	     this, SLOT( slotImageRequest( KHTMLView *, const char * ) ) );    connect( view, SIGNAL( URLSelected( KHTMLView *, const char*, int, const char* ) ),	     this, SLOT( slotURLSelected( KHTMLView *, const char *, int, const char* ) ) );        connect( view, SIGNAL( onURL( KHTMLView *, const char* ) ),	     this, SLOT( slotOnURL( KHTMLView *, const char * ) ) );    connect( view, SIGNAL( popupMenu( KHTMLView *, const char*, const QPoint & ) ),	     this, SLOT( slotPopupMenu( KHTMLView *, const char *, const QPoint & ) ) );    connect( view, SIGNAL( cancelImageRequest( KHTMLView *, const char* ) ),	     this, SLOT( slotCancelImageRequest( KHTMLView *, const char * ) ) );    connect( view, SIGNAL( formSubmitted( KHTMLView *, const char *, const char*, const char* ) ),	     this, SLOT( slotFormSubmitted( KHTMLView *, const char *, const char*, const char* ) ) ); */}KHTMLView* KHTMLView::findView( const char *_name ){    KHTMLView *v;     if ( strcmp( _name, "_top" ) == 0 )    {	v = this;	while ( v->getParentView() )	    v = v->getParentView();		return v;    }    else if ( strcmp( _name, "_self" ) == 0 )    {	return this;    }    else if ( strcmp( _name, "_parent" ) == 0 )    {	if ( getParentView() )	    return getParentView();    }    else if ( strcmp( _name, "_blank" ) == 0 )    {	return 0;    }    for ( v = viewList->first(); v != 0; v = viewList->next() )    {	if ( v->getFrameName() )	{	    // debugT("Comparing '%s' '%s'\n", _name, v->getFrameName() );	    if ( strcmp( v->getFrameName(), _name ) == 0 )		return v;	}    }        return 0;}void KHTMLView::begin( const char *_url, int _dx, int _dy ){    if ( displayHScroll )	view->setGeometry( 0, 0, width(), height() );    displayVScroll = FALSE;    displayHScroll = FALSE;    vert->hide();    horz->hide();    vert->setSteps( 12, view->height() );    horz->setSteps( 12, view->width() );    if ( _url )	url = _url;        scrollToX = _dx;    scrollToY = _dy;    //    view->begin( _url, _dx, _dy );    view->begin( _url, 0, 0 );}void KHTMLView::write( const char *_text ){    view->write( _text );}void KHTMLView::end(){    view->end();}void KHTMLView::parse(){    view->parse();}void KHTMLView::print(){    view->print();}void KHTMLView::initGUI(){    horz = new QScrollBar( 0, 0, 12, width(), 0, QScrollBar::Horizontal,	    this, "horz" );    horz->hide();    vert = new QScrollBar( 0, 0, 12, height(), 0, QScrollBar::Vertical,	    this, "vert" );    vert->hide();        horz->setMinimumSize( SCROLLBAR_WH, SCROLLBAR_WH );    vert->setMinimumSize( SCROLLBAR_WH, SCROLLBAR_WH );    view = new KHTMLWidget( this, "" );    CHECK_PTR( view );    view->setView( this );    setFocusProxy( view );    connect( view, SIGNAL( scrollVert( int ) ), SLOT( slotInternScrollVert( int ) ) );    connect( view, SIGNAL( scrollHorz( int ) ), SLOT( slotInternScrollHorz( int ) ) );    connect( vert, SIGNAL(valueChanged(int)), view, SLOT(slotScrollVert(int)) );    connect( horz, SIGNAL(valueChanged(int)), view, SLOT(slotScrollHorz(int)) );    connect( view, SIGNAL( documentChanged() ), SLOT( slotDocumentChanged() ) );    connect( view, SIGNAL( setTitle( const char* ) ),	     this, SLOT( slotSetTitle( const char * ) ) );    connect( view, SIGNAL( URLSelected( const char*, int, const char* ) ),	     this, SLOT( slotURLSelected( const char *, int, const char* ) ) );        connect( view, SIGNAL( onURL( const char* ) ),	     this, SLOT( slotOnURL( const char * ) ) );    connect( view, SIGNAL( textSelected( bool ) ),	     this, SLOT( slotTextSelected( bool ) ) );    connect( view, SIGNAL( popupMenu( const char*, const QPoint & ) ),	     this, SLOT( slotPopupMenu( const char *, const QPoint & ) ) );    connect( view, SIGNAL( fileRequest( const char* ) ),	     this, SLOT( slotImageRequest( const char * ) ) );    connect( view, SIGNAL( cancelFileRequest( const char* ) ),    	     this, SLOT( slotCancelImageRequest( const char * ) ) );    connect( view, SIGNAL( formSubmitted( const char *, const char*, const char* ) ),	     this, SLOT( slotFormSubmitted( const char *, const char*, const char* ) ) );    connect( view, SIGNAL( documentStarted() ),	     this, SLOT( slotDocumentStarted() ) );    connect( view, SIGNAL( documentDone() ),	     this, SLOT( slotDocumentDone() ) );    connect( view, SIGNAL( goUp() ), this, SLOT( slotGoUp() ) );    connect( view, SIGNAL( goLeft() ), this, SLOT( slotGoLeft() ) );    connect( view, SIGNAL( goRight() ), this, SLOT( slotGoRight() ) );    view->setURLCursor( KCursor::upArrowCursor() );    view->raise();}void KHTMLView::resizeEvent( QResizeEvent * ){    // resize the view - it will handle object size/pos calc    view->setGeometry( 0, 0, width(), height() );    if ( url.isEmpty() )	return;    // place/hide scrollbars    calcScrollBars();    // if we need a horzontal scrollbar then resize view again.    // This does not cause object size/pos to be recalculated as    // the width is not changed.    if ( displayHScroll )    {	view->setGeometry( 0, 0, width(), height() - SCROLLBAR_WH );    }    vert->setSteps( 12, view->height() );    horz->setSteps( 12, view->width() );}    void KHTMLView::closeEvent( QCloseEvent *e ){    // debugT("Closing\n");    e->accept();    delete this;}    void KHTMLView::slotScrollVert( int _y ){  if ( !view )    return;        view->slotScrollVert( _y );  vert->setValue( view->yOffset() );}void KHTMLView::slotScrollHorz( int _x ){  if ( !view )    return;        view->slotScrollHorz( _x );  horz->setValue( view->xOffset() );}void KHTMLView::slotInternScrollVert( int _y ){  // Update the scrollbar only  vert->setValue( _y );}void KHTMLView::slotInternScrollHorz( int _x ){  // Update the scrollbar only  horz->setValue( _x );}void KHTMLView::slotDocumentChanged(){        if ( url.isNull() )	return;    bool oldh = displayHScroll;    calcScrollBars();        if ( displayHScroll && !oldh )	view->setGeometry( 0, 0, width(), height() - SCROLLBAR_WH );    else if ( !displayHScroll && oldh )	view->setGeometry( 0, 0, width(), height() );}void KHTMLView::calcScrollBars(){    if ( view->docWidth() > view->width() && !isFrameSet() && scrolling )	displayHScroll = TRUE;    else        displayHScroll = FALSE;        if ( view->docHeight() > view->height() && !isFrameSet() && scrolling )	displayVScroll = TRUE;    else        displayVScroll = FALSE;    if ( displayVScroll && displayHScroll )    {	horz->setRange( 0, view->docWidth() + SCROLLBAR_WH - view->width() );	if(horz->value() != view->xOffset())	    horz->setValue( view->xOffset() );	vert->setRange( 0, view->docHeight() - height() + SCROLLBAR_WH );	if(vert->value() != view->yOffset())	    vert->setValue( view->yOffset() );    }    else if ( displayHScroll )    {	horz->setRange( 0, view->docWidth() - view->width() );	if(horz->value() != view->xOffset())	    horz->setValue( view->xOffset() );    }    else if ( displayVScroll )    {	vert->setRange( 0, view->docHeight() - height() );	if(vert->value() != view->yOffset())	    vert->setValue( view->yOffset() );    }        int right = 0;    if ( displayVScroll )	right = SCROLLBAR_WH;      int bottom = 0;    if ( !displayHScroll )    {	horz->hide();	view->slotScrollHorz( 0 );    }	    else    {	bottom = SCROLLBAR_WH;	// debugT("Showing HScrollBar\n");	horz->setGeometry( 0, height() - SCROLLBAR_WH, width() - right, SCROLLBAR_WH );	horz->show();	horz->raise();    }    if ( !displayVScroll )    {	vert->hide();	view->slotScrollVert( 0 );    }    else    {	// debugT("Showing VScrollBar\n");	vert->setGeometry( width() - SCROLLBAR_WH, 0, SCROLLBAR_WH, height() - bottom );	vert->show();	vert->raise();    }}void KHTMLView::cancelAllRequests(){    if ( view )	view->cancelAllRequests();}void KHTMLView::slotDocumentStarted( KHTMLView *_view ){    // debug( "emit documentStarted( _view );" );    emit documentStarted( _view );}void KHTMLView::slotDocumentStarted(){    // debug( "emit documentStarted( this );" );    emit documentStarted( this );}void KHTMLView::slotDocumentDone( KHTMLView *_view ){    // debug( "emit documentDone( _view );" );

⌨️ 快捷键说明

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