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

📄 htmlclue.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* 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//#include <kurl.h>#include "htmlchain.h"#include "htmlobj.h"#include "htmlclue.h"#include "html.h"#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <qimage.h>#include <qdrawutil.h>//#define CLUE_DEBUG//#define DEBUG_ALIGN//-----------------------------------------------------------------------------HTMLClue::HTMLClue( int _x, int _y, int _max_width, int _percent )	 : HTMLObject(){    x = _x;    y = _y;    max_width = _max_width;    percent = _percent;    valign = Bottom;    halign = Left;    head = tail = curr = 0;    if ( percent > 0 )    {	width = max_width * percent / 100;	setFixedWidth( false );    }    else if ( percent < 0 )    {	width = max_width;	setFixedWidth( false );    }    else	width = max_width;}HTMLClue::~HTMLClue(){    while ( head )    {	curr = head->next();	delete head;	head = curr;    }}void HTMLClue::reset(){    HTMLObject *obj;    for ( obj = head; obj != 0; obj = obj->next() )	obj->reset();    curr = 0;}void HTMLClue::calcAbsolutePos( int _x, int _y ){    HTMLObject *obj;    int lx = _x + x;    int ly = _y + y - ascent;    for ( obj = head; obj != 0; obj = obj->next() )	obj->calcAbsolutePos( lx, ly );}HTMLAnchor* HTMLClue::findAnchor( const char *_name, QPoint *_p ){    HTMLObject *obj;    HTMLAnchor *ret;    _p->setX( _p->x() + x );    _p->setY( _p->y() + y - ascent );        for ( obj = head; obj != 0; obj = obj->next() )    {	ret = obj->findAnchor( _name, _p );	if ( ret != 0 )	    return ret;    }        _p->setX( _p->x() - x );    _p->setY( _p->y() - y + ascent );    return 0;}bool HTMLClue::getObjectPosition( const HTMLObject *objp, int &xp, int &yp ){    HTMLObject *obj;    xp += x;    yp += (y - ascent);        for ( obj = head; obj != 0; obj = obj->next() )    {	if ( obj->getObjectPosition( objp, xp, yp ) )	    return true;    }        xp -= x;    yp -= (y - ascent);    return false;}void HTMLClue::getSelected( QStrList &_list ){    HTMLObject *obj;    for ( obj = head; obj != 0; obj = obj->next() )	obj->getSelected( _list );}void HTMLClue::getSelectedText( QString &_str ){    HTMLObject *obj;    for ( obj = head; obj != 0; obj = obj->next() )	obj->getSelectedText( _str );}void HTMLClue::select( bool _select ){    HTMLObject *obj;    for ( obj = head; obj != 0; obj = obj->next() )    {	obj->select( _select );    }}void HTMLClue::select( KHTMLWidget *_htmlw, HTMLChain *_chain,    QRegExp& _pattern, bool _select, int _tx, int _ty ){    _tx += x;    _ty += y - ascent;    _chain->push( this );    for ( HTMLObject *obj = head; obj != 0; obj = obj->next() )    {	obj->select( _htmlw, _chain, _pattern, _select, _tx, _ty );    }    _chain->pop();}void HTMLClue::select( KHTMLWidget *_htmlw, HTMLChain *_chain,    bool _select, int _tx, int _ty ){    _tx += x;    _ty += y - ascent;    _chain->push( this );    for ( HTMLObject *obj = head; obj != 0; obj = obj->next() )    {	obj->select( _htmlw, _chain, _select, _tx, _ty );    }    _chain->pop();}void HTMLClue::select( KHTMLWidget *_htmlw, HTMLChain *_chain,    QRect & _rect, int _tx, int _ty ){    HTMLObject *obj;    QRect r( x + _tx, y - ascent + _ty, width, ascent + descent );    _tx += x;    _ty += y - ascent;    _chain->push( this );    if ( _rect.contains( r ) )    {	for ( obj = head; obj != 0; obj = obj->next() )	    obj->select( _htmlw, _chain, TRUE, _tx, _ty );    }    else if ( !_rect.intersects( r ) )    {	for ( obj = head; obj != 0; obj = obj->next() )	    obj->select( _htmlw, _chain, FALSE, _tx, _ty );    }    else    {	for ( obj = head; obj != 0; obj = obj->next() )	    obj->select( _htmlw, _chain, _rect, _tx, _ty );    }    _chain->pop();}void HTMLClue::selectByURL( KHTMLWidget *_htmlw, HTMLChain *_chain,    const char *_url, bool _select, int _tx, int _ty ){    HTMLObject *obj;    _tx += x;    _ty += y - ascent;    _chain->push( this );    for ( obj = head; obj != 0; obj = obj->next() )	obj->selectByURL( _htmlw, _chain, _url, _select, _tx, _ty );    _chain->pop();}void HTMLClue::findCells( int _tx, int _ty, QList<HTMLCellInfo> &_list ){    HTMLObject *obj;    _tx += x;    _ty += y - ascent;    for ( obj = head; obj != 0; obj = obj->next() )	obj->findCells( _tx, _ty, _list );}bool HTMLClue::selectText( KHTMLWidget *_htmlw, HTMLChain *_chain, int _x1,	int _y1, int _x2, int _y2, int _tx, int _ty ){    HTMLObject *obj;    bool isSel = false;    _tx += x;    _ty += y - ascent;    _chain->push( this );    for ( obj = head; obj != 0; obj = obj->next() )    {	isSel = obj->selectText( _htmlw, _chain, _x1 - x, _y1 - ( y - ascent ),		_x2 - x, _y2 - ( y - ascent ), _tx, _ty ) || isSel;    }    _chain->pop();    return isSel;}HTMLObject* HTMLClue::checkPoint( int _x, int _y ){    HTMLObject *obj;    HTMLObject *obj2;    if ( _x < x || _x > x + width || _y > y + descent || _y < y - ascent)	return 0L;    for ( obj = head; obj != 0; obj = obj->next() )    {	if ((obj2 = obj->checkPoint( _x - x, _y - (y - ascent) )) != 0L)	    return obj2;    }    return 0;}HTMLObject* HTMLClue::mouseEvent( int _x, int _y, int button, int state ){    HTMLObject *obj;    HTMLObject *obj2;    if ( _x < x || _x > x + width || _y > y + descent || _y < y - ascent)	return 0;    for ( obj = head; obj != 0; obj = obj->next() )    {	if ((obj2 = obj->mouseEvent( _x - x, _y - (y - ascent), button,		state )) != 0 )	    return obj2;    }    return 0;}void HTMLClue::calcSize( HTMLClue * ){    // If we have already called calcSize for the children, then just    // continue from the last object done in previous call.    if ( !curr )    {	ascent = 0;	curr = head;    }    while ( curr != 0 )    {	curr->calcSize( this );	curr = curr->next();    }    // remember the last object so that we can start from here next time    // we are called.    curr = tail;}void HTMLClue::recalcBaseSize( QPainter *_painter ){    HTMLObject *obj;    for ( obj = head; obj != 0; obj = obj->next() )	obj->recalcBaseSize( _painter );}int HTMLClue::calcMinWidth(){    HTMLObject *obj;    int minWidth = 0;    for ( obj = head; obj != 0; obj = obj->next() )    {	int w = obj->calcMinWidth();	if ( w > minWidth )	    minWidth = w;    }    if ( isFixedWidth() )    {        if (width > minWidth)            minWidth = width;    }    return minWidth;}int HTMLClue::calcPreferredWidth(){    if ( isFixedWidth() )	return width;    HTMLObject *obj;    int prefWidth = 0;    for ( obj = head; obj != 0; obj = obj->next() )    {	int w = obj->calcPreferredWidth();	if ( w > prefWidth )	    prefWidth = w;    }    return prefWidth;}void HTMLClue::setMaxAscent( int _a ){    HTMLObject *obj;    if ( valign == VCenter )    {	for ( obj = head; obj != 0; obj = obj->next() )	{		    obj->setYPos( obj->getYPos() + ( _a - ascent )/2 );	}    }    else if ( valign == Bottom )    {	for ( obj = head; obj != 0; obj = obj->next() )	{		    obj->setYPos( obj->getYPos() + _a - ascent );	}    }    ascent = _a;}void HTMLClue::setMaxDescent( int _d ){    HTMLObject *obj;    if ( valign == VCenter )    {	for ( obj = head; obj != 0; obj = obj->next() )	{		    obj->setYPos( obj->getYPos() + ( _d - descent )/2 );	}    }    else if ( valign == Bottom )    {	for ( obj = head; obj != 0; obj = obj->next() )	{		    obj->setYPos( obj->getYPos() + _d - descent );	}    }    descent = _d;}int HTMLClue::findPageBreak( int _y ){    if ( _y > y )	return -1;    HTMLObject *obj;    int pos;    for ( obj = head; obj != 0; obj = obj->next() )    {	if ( !obj->isAligned() )	{	    pos = obj->findPageBreak( _y - ( y - ascent ) );	    if ( pos >= 0 )		return ( pos + y - ascent );	}    }    return -1;}bool HTMLClue::print( QPainter *_painter, int _x, int _y, int _width, int _height, int _tx, int _ty, bool toPrinter ){    if ( _y + _height < y - getAscent() || _y > y + descent )	return false;        HTMLObject *obj;    _tx += x;    _ty += y - ascent;#ifdef CLUE_DEBUG    // draw rectangles around clues - for debugging    QBrush brush;    _painter->setBrush( brush );    _painter->drawRect( _tx, _ty, width, getHeight() );#endif    for ( obj = head; obj != 0; obj = obj->next() )    {	if ( !obj->isAligned() )	{	    if ( obj->print( _painter, _x - x, _y - (y - ascent),			_width, _height, _tx, _ty, toPrinter ) && toPrinter )	    return true;	}    }    return false;}void HTMLClue::print( QPainter *_painter, HTMLChain *_chain, int _x, int _y,    int _width, int _height, int _tx, int _ty ){    _tx += x;    _ty += y - ascent;    _chain->next();    if ( _chain->current() )    {        if ( _chain->isLast() )        {            // if a clue is the last in the chain, then draw its children too.            print( _painter, _tx, _ty );        }        else        {            _chain->current()->print( _painter, _chain, _x - x,                _y - (y - ascent), _width, _height, _tx, _ty );        }    }}void HTMLClue::print( QPainter *_painter, int _tx, int _ty ){    print( _painter, 0, 0, 0xFFFF, 0xFFFF, _tx, _ty, false );}void HTMLClue::print( QPainter *_painter, HTMLObject *_obj, int _x, int _y, int _width, int _height, int _tx, int _ty ){    if ( _y + _height < y - getAscent() || _y > y + descent )	return;        HTMLObject *obj;    _tx += x;    _ty += y - ascent;    for ( obj = head; obj != 0; obj = obj->next() )    {	if ( obj == _obj )	{	    obj->print( _painter, _x - x, _y - (y - ascent), _width,			_height, _tx, _ty, false );	    return;	}	else	    obj->print( _painter, _obj, _x - x, _y - (y - ascent),		_width, _height, _tx, _ty );    }}void HTMLClue::setBgColor( QColor c ){    HTMLObject *obj;    for ( obj = head; obj != 0; obj = obj->next() )	obj->setBgColor( c );}//-----------------------------------------------------------------------------HTMLClueV::HTMLClueV( int _x, int _y, int _max_width, int _percent )    : HTMLClue( _x, _y, _max_width, _percent ){    alignLeftList  = 0;    alignRightList = 0;    padding = 0;}void HTMLClueV::reset(){    HTMLClue::reset();    alignLeftList  = 0;    alignRightList = 0;}void HTMLClueV::setMaxWidth( int _max_width ){    HTMLObject *obj;    if ( !isFixedWidth() )    {	max_width = _max_width;	if ( percent > 0 )	    width = _max_width * percent / 100;	else	    width = max_width;    }    for ( obj = head; obj != 0; obj = obj->next() )	obj->setMaxWidth( width );}HTMLObject* HTMLClueV::checkPoint( int _x, int _y ){    HTMLObject *obj2;    if ( ( obj2 = HTMLClue::checkPoint( _x, _y ) ) != 0L )	    return obj2;    if ( _x < x || _x > x + width || _y > y + descent || _y < y - ascent)	return 0L;    HTMLClueAligned *clue;    for ( clue = alignLeftList; clue != 0; clue = clue->nextClue() )    {	if ((obj2 = clue->checkPoint( _x - x - clue->parent()->getXPos(),		 _y - (y - ascent) - ( clue->parent()->getYPos() -		 clue->parent()->getAscent() ) )) != 0L)	    return obj2;    }    for ( clue = alignRightList; clue != 0; clue = clue->nextClue() )    {	if ((obj2 = clue->checkPoint( _x - x - clue->parent()->getXPos(),		 _y - (y - ascent) - ( clue->parent()->getYPos() -		 clue->parent()->getAscent() ) )) != 0L)	    return obj2;    }    return 0L;}HTMLObject* HTMLClueV::mouseEvent( int _x, int _y, int button, int state ){    HTMLObject *obj2;    if ( ( obj2 = HTMLClue::mouseEvent( _x, _y, button, state ) ) != 0L )	    return obj2;    if ( _x < x || _x > x + width || _y > y + descent || _y < y - ascent)	return 0;    HTMLClueAligned *clue;    for ( clue = alignLeftList; clue != 0; clue = clue->nextClue() )    {	if ((obj2 = clue->mouseEvent( _x - x - clue->parent()->getXPos(),		 _y - (y - ascent) - ( clue->parent()->getYPos() -		 clue->parent()->getAscent() ), button, state )) != 0 )	    return obj2;    }    for ( clue = alignRightList; clue != 0; clue = clue->nextClue() )    {	if ((obj2 = clue->mouseEvent( _x - x - clue->parent()->getXPos(),		 _y - (y - ascent) - ( clue->parent()->getYPos() -		 clue->parent()->getAscent() ), button, state )) != 0 )	    return obj2;    }    return 0;}void HTMLClueV::calcSize( HTMLClue *parent ){	int lmargin = parent ? parent->getLeftMargin( getYPos() ) + padding : padding;	// If we have already called calcSize for the children, then just	// continue from the last object done in previous call.	if ( curr )	{	    ascent = padding;

⌨️ 快捷键说明

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