khtml Library API Documentation

khtmllayout.h

00001 /*
00002     This file is part of the KDE libraries
00003 
00004     Copyright (C) 1999 Lars Knoll (knoll@kde.org)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 
00021     $Id: khtmllayout.h,v 1.18 2002/09/13 12:34:02 lunakl Exp $
00022 
00023     This widget holds some useful definitions needed for layouting Elements
00024 */
00025 #ifndef HTML_LAYOUT_H
00026 #define HTML_LAYOUT_H
00027 
00028 
00029 /*
00030  * this namespace contains definitions for various types needed for
00031  * layouting.
00032  */
00033 namespace khtml
00034 {
00035 
00036     const int UNDEFINED = -1;
00037 
00038     // alignment
00039     enum VAlign { VNone=0, Bottom, VCenter, Top, Baseline };
00040     enum HAlign { HDefault, Left, HCenter, Right, HNone = 0 };
00041 
00042     /*
00043      * %multiLength and %Length
00044      */
00045     enum LengthType { Variable = 0, Relative, Percent, Fixed, Static };
00046     struct Length
00047     {
00048     Length() { *((Q_UINT32 *)this) = 0; }
00049         Length(LengthType t) { type = t; value = 0; }
00050         Length(int v, LengthType t) : value(v), type(t) {}
00051         Length(const Length &o)
00052         { *((Q_UINT32 *)this) = *((Q_UINT32 *)&o); }
00053 
00054         Length& operator=(const Length& o)
00055             { *((Q_UINT32 *)this) = *((Q_UINT32 *)&o); return *this; }
00056         bool operator==(const Length& o) const
00057             { return *((Q_UINT32 *)this) == *((Q_UINT32 *)&o); }
00058         bool operator!=(const Length& o) const
00059             { return *((Q_UINT32 *)this) != *((Q_UINT32 *)&o); }
00060 
00061 
00062     /*
00063      * works only for Fixed and Percent, returns -1 otherwise
00064      */
00065     int width(int maxWidth) const
00066         {
00067         switch(type)
00068         {
00069         case Fixed:
00070             return value;
00071         case Percent:
00072             return maxWidth*value/100;
00073         case Variable:
00074             return maxWidth;
00075         default:
00076             return -1;
00077         }
00078         }
00079     /*
00080      * returns the minimum width value which could work...
00081      */
00082     int minWidth(int maxWidth) const
00083         {
00084         switch(type)
00085         {
00086         case Fixed:
00087             return value;
00088         case Percent:
00089             return maxWidth*value/100;
00090         case Variable:
00091         default:
00092             return 0;
00093         }
00094         }
00095         bool isVariable() const { return (type == Variable); }
00096         bool isRelative() const { return (type == Relative); }
00097         bool isPercent() const { return (type == Percent); }
00098         bool isFixed() const { return (type == Fixed); }
00099         bool isStatic() const { return (type == Static); }
00100 
00101         int value : 29;
00102         LengthType type : 3;
00103     };
00104 
00105 };
00106 
00107 #ifdef __GNUC__
00108 #if __GNUC__ < 3 // stupid stl_relops.h
00109 inline bool operator!=(khtml::LengthType __x, khtml::LengthType __y) {
00110   return !(__x == __y);
00111 }
00112 #endif
00113 #endif
00114 
00115 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:39 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001