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 #include <wt/frame.h> 00022 #include <wt/painter.h> 00023 00024 namespace Wt { 00025 00026 void Frame::onLayoutChange() { 00027 Layout *l = layout(); 00028 00029 if (l) { 00030 margin.connect(l->margin); 00031 spacing.connect(l->spacing); 00032 } 00033 } 00034 00035 Frame::Frame(Widget *parent, const std::string &name, int wflags) 00036 : Widget(parent, name, wflags), 00037 lineWidth(1), 00038 margin(1), 00039 spacing(-1), 00040 line_color_("gray90") { 00041 00042 void (Widget::*update)() = &Widget::update; 00043 sigc::slot0<void> update_slot = sigc::mem_fun(*this, update); 00044 lineWidth.changed.connect(update_slot); 00045 00046 layoutChanged.connect( 00047 sigc::slot0<void>( 00048 sigc::mem_fun(*this, &Frame::onLayoutChange))); 00049 } 00050 00051 Frame::~Frame() {} 00052 00053 int Frame::frameWidth() const { 00054 return width() - margin; 00055 } 00056 00057 Rect Frame::contentsRect() const { 00058 return rect() >> margin; 00059 } 00060 00061 const Color& Frame::lineColor() const { 00062 return line_color_; 00063 } 00064 00065 void Frame::setLineColor(const Color &color) { 00066 line_color_ = color; 00067 update(); 00068 } 00069 00070 void Frame::drawFrame(Painter *p) { 00071 int lw = lineWidth; 00072 int x2 = width() - 1; 00073 int y2 = height() - 1; 00074 int lw2 = y2 - lw; 00075 00076 p->save(); 00077 p->setPen(lineColor()); 00078 for (int i = 0; i < lw; i++) { 00079 p->drawHorizontalLine(0, x2, i); 00080 p->drawHorizontalLine(0, x2, y2 - i); 00081 p->drawVerticalLine(i, lw, lw2); 00082 p->drawVerticalLine(x2 - i, lw, lw2); 00083 } 00084 p->restore(); 00085 } 00086 00087 void Frame::drawContents(Painter *) { 00088 //p->fillRect(contentsRect(), Color("yellow")); 00089 } 00090 00091 void Frame::draw(Painter *p, const Region& r) { 00092 Widget::draw(p, r); 00093 drawFrame(p); 00094 drawContents(p); 00095 } 00096 00097 }
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.