Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

# painter_holder.cpp

    00001 // painter_holder.cpp
    00002
    00003 // Copyright (C) 2004 Steven Weiß (steven11@gmx.de)
    00004 //
    00005 // Permission to copy, use, sell and distribute this software is granted
    00006 // provided this copyright notice appears in all copies.
    00007 // Permission to modify the code and to distribute modified code is granted
    00008 // provided this copyright notice appears in all copies, and a notice
    00009 // that the code was modified is included with the copyright notice.
    00010 //
    00011 // This software is provided "as is" without express or implied warranty,
    00012 // and with no claim as to its suitability for any purpose.
    00013
    00014
    00015 #include <background_wnd/painter_holder.hpp>
    00016
    00017
    00018 namespace win32 { namespace gui {
    00019
    00020 // ========================================================================================================== //
    00021 // painter_holder
    00022
    00023 // the big 4
    00024 painter_holder::painter_holder(painter_base* pPainter) : pPainter_(pPainter)
    00025 {}
    00026
    00027 painter_holder::painter_holder(const painter_holder& holder)
    00028 {
    00029      painter_base* p = holder.pPainter_.get();
    00030      if (p)
    00031           set_raw_painter(p->clone());
    00032 }
    00033
    00034 painter_holder::~painter_holder()
    00035 {}
    00036
    00037 const painter_holder& painter_holder::operator= (const painter_holder& holder)
    00038 {
    00039      if (&holder != this) {
    00040           release_painter();
    00041           painter_base* p = holder.pPainter_.get();
    00042           if (p)
    00043                set_raw_painter(p->clone());
    00044      }
    00045      return *this;
    00046 }
    00047
    00049 void painter_holder::set_painter(const painter_base& painter)
    00050 {
    00051      set_raw_painter(painter.clone());
    00052 }
    00053
    00055 void painter_holder::release_painter()
    00056 {
    00057      pPainter_.release();
    00058 }
    00059
    00061 painter_base& painter_holder::get_painter() const
    00062 {
    00063      painter_base* p = pPainter_.get();
    00064      if (p == NULL)
    00065           throw no_painter(*this);
    00066      return *p;
    00067 }
    00068
    00070 bool painter_holder::painter_available() const
    00071 {
    00072      return pPainter_.get() != NULL;
    00073 }
    00074
    00076 void painter_holder::swap(painter_holder& holder)
    00077 {
    00078      std::swap(pPainter_, holder.pPainter_);
    00079 }
    00080
    00081 // resets the painter
    00082 void painter_holder::set_raw_painter(painter_base* pPainter)
    00083 {
    00084      pPainter_.reset(pPainter);
    00085 }
    00086
    00087 } }  // namespace win32::gui