box.h

Go to the documentation of this file.
00001 /*
00002   libwt - Vassilis Virvilis Toolkit - a widget library
00003   Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm>
00004  
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #ifndef WT_BOX_H
00022 #define WT_BOX_H
00023 
00024 #include <wt/frame.h>
00025 #include <wt/layout.h>
00026 
00027 namespace Wt {
00028 
00029 class Box : public Frame {
00030 public:
00031     typedef enum {
00032         Horizontal,
00033         Vertical
00034     } Orientation;
00035 
00036     Box(Orientation orientation, Widget * parent = 0,
00037         const std::string &name = "Box::anon", int wflags = 0) :
00038             Frame(parent, name, wflags),
00039     orientation(orientation) {
00040         Layout *l = 0;
00041         switch (orientation) {
00042         case Horizontal:
00043             l = new HBoxLayout(this);
00044             break;
00045         case Vertical:
00046             l = new VBoxLayout(this);
00047             break;
00048         default:
00049             assert(0);
00050             break;
00051         }
00052 
00053         l->autoAdd = true;
00054     }
00055 
00056     void add
00057         (LayoutItem *li) {
00058         layout()->addItem(li);
00059     }
00060 
00061     bool setStretchFactor(Widget *w, int stretch) {
00062         BoxLayout *l = static_cast<BoxLayout *>(layout());
00063         if (l->exists(w)) {
00064             trace("layout") << "Setting stretch factor to "
00065             << stretch << " in " << w << std::endl;
00066             SizePolicy sp = w->sizePolicy();
00067             bool horizontal = l->isWidthPrimaryLength();
00068             if (horizontal) {
00069                 sp.horizontalStretch = stretch;
00070             } else {
00071                 sp.verticalStretch = stretch;
00072             }
00073             w->setSizePolicy(sp);
00074             return true;
00075         }
00076         return false;
00077     }
00078 
00079 private:
00080     Orientation orientation;
00081 };
00082 
00083 class HBox : public Box {
00084 public:
00085     HBox(Widget *parent = 0,
00086          const std::string &name = "HBox::anon", int wflags = 0) :
00087     Box(Box::Horizontal, parent, name, wflags) {}
00088 
00089 private:
00090 };
00091 
00092 class VBox : public Box {
00093 public:
00094     VBox(Widget *parent = 0,
00095          const std::string &name = "VBox::anon", int wflags = 0) :
00096     Box(Box::Vertical, parent, name, wflags) {}
00097 
00098 private:
00099 };
00100 
00101 }
00102 
00103 #endif // WT_BOX_H

Generated Fri Jul 28 19:22:59 2006.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.