Move Vaca classes to base and gui libraries.

+ Remove Vaca::Referenceable class and move Vaca::SharedPtr<> to base/shared_ptr.h (now shared pointers can point to any type).
+ Move Vaca::Component/Event/Property/PreferredSizeEvent to gui/component.cpp.
This commit is contained in:
David Capello 2010-09-29 17:14:11 -03:00
parent 7643b87cc3
commit b8ddd30a0d
37 changed files with 596 additions and 1021 deletions

View File

@ -0,0 +1,32 @@
// ASE base library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
#define BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
namespace base {
// Removes the first ocurrence of the specified element from the STL
// container.
template<typename ContainerType>
void remove_from_container(ContainerType& container,
typename ContainerType::const_reference element)
{
for (typename ContainerType::iterator
it = container.begin(),
end = container.end(); it != end; ) {
if (*it == element) {
it = container.erase(it);
end = container.end();
}
else
++it;
}
}
}
#endif

126
src/base/shared_ptr.h Normal file
View File

@ -0,0 +1,126 @@
// ASE base library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef BASE_SHARED_PTR_H_INCLUDED
#define BASE_SHARED_PTR_H_INCLUDED
// A class which wraps a pointer and keeps reference counting to
// automatically delete the pointed object when it is no longer
// used.
template<class T>
class SharedPtr
{
friend class SharedPtr;
public:
SharedPtr()
: m_ptr(0)
, m_refCount(0) {
}
explicit SharedPtr(T* ptr)
: m_ptr(ptr)
, m_refCount(ptr ? new int(0): 0) {
ref();
}
SharedPtr(const SharedPtr<T>& other)
: m_ptr(other.m_ptr)
, m_refCount(other.m_refCount) {
ref();
}
template<class T2>
SharedPtr(const SharedPtr<T2>& other)
: m_ptr(static_cast<T*>(other.m_ptr))
, m_refCount(other.m_refCount) {
ref();
}
virtual ~SharedPtr() {
unref();
}
void reset(T* ptr = 0) {
if (m_ptr != ptr) {
unref();
m_ptr = ptr;
m_refCount = (ptr ? new int(0): 0);
ref();
}
}
SharedPtr& operator=(const SharedPtr<T>& other) {
if (m_ptr != other.m_ptr) {
unref();
m_ptr = other.m_ptr;
m_refCount = other.m_refCount;
ref();
}
return *this;
}
template<class T2>
SharedPtr& operator=(const SharedPtr<T2>& other) {
if (m_ptr != static_cast<T*>(other.m_ptr)) {
unref();
m_ptr = static_cast<T*>(other.m_ptr);
m_refCount = other.m_refCount;
ref();
}
return *this;
}
inline T* get() const { return m_ptr; }
inline T& operator*() const { return *m_ptr; }
inline T* operator->() const { return m_ptr; }
inline operator T*() const { return m_ptr; }
int getRefCount() const { return m_refCount ? *m_refCount: 0; }
private:
// Adds a reference to the pointee.
void ref() {
if (m_ptr)
++(*m_refCount);
}
// Removes the reference to the pointee.
void unref() {
if (m_ptr) {
if (--(*m_refCount) == 0) {
delete m_ptr;
delete m_refCount;
}
m_ptr = 0;
m_refCount = 0;
}
}
T* m_ptr; // The pointee object.
int* m_refCount; // Number of references.
};
// Compares if two shared-pointers points to the same place (object,
// memory address).
template<class T>
bool operator==(const SharedPtr<T>& ptr1, const SharedPtr<T>& ptr2)
{
return ptr1.get() == ptr2.get();
}
// Compares if two shared-pointers points to different places
// (objects, memory addresses).
template<class T>
bool operator!=(const SharedPtr<T>& ptr1, const SharedPtr<T>& ptr2)
{
return ptr1.get() != ptr2.get();
}
#endif

View File

@ -0,0 +1,99 @@
// ASE base library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#include "tests/test.h"
#include "base/shared_ptr.h"
TEST(SharedPtr, IntPtr)
{
SharedPtr<int> a(new int(5));
EXPECT_EQ(5, *a);
}
TEST(SharedPtr, RefCount)
{
SharedPtr<int> a(new int(5));
EXPECT_EQ(1, a.getRefCount());
a.reset();
EXPECT_EQ(0, a.getRefCount());
SharedPtr<int> b(new int(5));
{
SharedPtr<int> c(b);
EXPECT_EQ(2, b.getRefCount());
EXPECT_EQ(2, c.getRefCount());
a = c;
EXPECT_EQ(3, a.getRefCount());
EXPECT_EQ(3, b.getRefCount());
EXPECT_EQ(3, c.getRefCount());
a.reset();
EXPECT_EQ(2, b.getRefCount());
EXPECT_EQ(2, c.getRefCount());
}
EXPECT_EQ(1, b.getRefCount());
}
TEST(SharedPtr, DeleteIsCalled)
{
class DeleteIsCalled
{
public:
DeleteIsCalled(bool& flag) : m_flag(flag) { }
~DeleteIsCalled() { m_flag = true; }
private:
bool& m_flag;
};
bool flag = false;
{
SharedPtr<DeleteIsCalled> a(new DeleteIsCalled(flag));
}
EXPECT_EQ(true, flag);
}
TEST(SharedPtr, Hierarchy)
{
class A { };
class B : public A { };
SharedPtr<A> a(new B);
SharedPtr<B> b = a;
SharedPtr<A> c = a;
SharedPtr<A> d = b;
EXPECT_EQ(4, a.getRefCount());
}
TEST(SharedPtr, Compare)
{
SharedPtr<int> a(new int(0));
SharedPtr<int> b(a);
SharedPtr<int> c(new int(0));
// Compare pointers
EXPECT_TRUE(a == b);
EXPECT_TRUE(a != c);
EXPECT_TRUE(b != c);
// Compare pointers
a = c;
c = b;
EXPECT_TRUE(a != b);
EXPECT_TRUE(a != c);
EXPECT_TRUE(b == c);
// Compare values
EXPECT_TRUE(*a == *b);
EXPECT_TRUE(*a == *c);
EXPECT_TRUE(*b == *c);
// Change values
*a = 2;
*b = 5;
EXPECT_EQ(2, *a);
EXPECT_EQ(5, *b);
EXPECT_EQ(5, *c);
}

View File

@ -2,6 +2,8 @@
# Copyright (C) 2001-2010 David Capello
add_library(gui-lib
component.cpp
event.cpp
jaccel.cpp
jalert.cpp
jbox.cpp
@ -43,4 +45,6 @@ add_library(gui-lib
jview.cpp
jwidget.cpp
jwindow.cpp
preferred_size_event.cpp
property.cpp
themes/jstandard_theme.cpp)

49
src/gui/component.cpp Normal file
View File

@ -0,0 +1,49 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#include "base/shared_ptr.h"
#include "gui/component.h"
#include "gui/property.h"
Component::Component()
{
}
Component::~Component()
{
}
PropertyPtr Component::getProperty(const base::string& name)
{
Properties::iterator it = m_properties.find(name);
if (it != m_properties.end())
return it->second;
else
return PropertyPtr();
}
void Component::setProperty(PropertyPtr property)
{
m_properties[property->getName()] = property;
}
bool Component::hasProperty(const base::string& name)
{
Properties::iterator it = m_properties.find(name);
return it != m_properties.end();
}
void Component::removeProperty(const base::string& name)
{
Properties::iterator it = m_properties.find(name);
if (it != m_properties.end())
m_properties.erase(it);
}
const Component::Properties& Component::getProperties() const
{
return m_properties;
}

41
src/gui/component.h Normal file
View File

@ -0,0 +1,41 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef GUI_COMPONENT_H_INCLUDED
#define GUI_COMPONENT_H_INCLUDED
#include <map>
#include "base/string.h"
#include "base/disable_copying.h"
#include "gui/property.h"
// A component is a visual object, such as widgets or menus.
//
// Components are non-copyable.
class Component
{
public:
typedef std::map<base::string, PropertyPtr> Properties;
Component();
virtual ~Component();
PropertyPtr getProperty(const base::string& name);
void setProperty(PropertyPtr property);
bool hasProperty(const base::string& name);
void removeProperty(const base::string& name);
const Properties& getProperties() const;
private:
Properties m_properties;
DISABLE_COPYING(Component);
};
#endif

21
src/gui/event.cpp Normal file
View File

@ -0,0 +1,21 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#include "gui/event.h"
Event::Event(Component* source)
: m_source(source)
{
}
Event::~Event()
{
}
Component* Event::getSource()
{
return m_source;
}

31
src/gui/event.h Normal file
View File

@ -0,0 +1,31 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef GUI_EVENT_H_INCLUDED
#define GUI_EVENT_H_INCLUDED
class Component;
// Base class for every kind of event.
class Event
{
// The component which generates the event.
Component* m_source;
public:
// Creates a new event specifying that it was generated from the
// source component.
Event(Component* source);
virtual ~Event();
// Returns the component which generated the event.
Component* getSource();
};
#endif

View File

@ -20,7 +20,7 @@
#include "gui/jtheme.h"
#include "gui/jwidget.h"
#include "gui/jwindow.h"
#include "Vaca/PreferredSizeEvent.h"
#include "gui/preferred_size_event.h"
ButtonBase::ButtonBase(const char* text, int type, int behaviorType, int drawType)
: Widget(type)
@ -235,7 +235,7 @@ bool ButtonBase::onProcessMessage(JMessage msg)
jwidget_emit_signal(this, JI_SIGNAL_CHECK_CHANGE);
// Fire onClick() event
Vaca::Event ev(this);
Event ev(this);
onClick(ev);
dirty();
@ -250,7 +250,7 @@ bool ButtonBase::onProcessMessage(JMessage msg)
jwidget_emit_signal(this, JI_SIGNAL_RADIO_CHANGE);
// Fire onClick() event
Vaca::Event ev(this);
Event ev(this);
onClick(ev);
}
break;
@ -333,7 +333,7 @@ void ButtonBase::generateButtonSelectSignal()
jwidget_emit_signal(this, JI_SIGNAL_BUTTON_SELECT);
// Fire onClick() event
Vaca::Event ev(this);
Event ev(this);
onClick(ev);
}

View File

@ -9,14 +9,12 @@
#include "base/signal.h"
#include "gui/jwidget.h"
#include "Vaca/NonCopyable.h"
#include <vector>
namespace Vaca { class Event; }
using Vaca::Event;
struct BITMAP;
class Event;
// Generic button
class ButtonBase : public Widget
{

View File

@ -8,9 +8,9 @@
#include <allegro.h>
#include "gui/jinete.h"
#include "gfx/size.h"
#include "Vaca/PreferredSizeEvent.h"
#include "gui/jinete.h"
#include "gui/preferred_size_event.h"
using namespace gfx;

View File

@ -8,10 +8,10 @@
#include <allegro.h>
#include "gfx/size.h"
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "gfx/size.h"
#include "Vaca/PreferredSizeEvent.h"
#include "gui/preferred_size_event.h"
using namespace gfx;

View File

@ -20,10 +20,10 @@
#include <allegro.h>
#include "gfx/size.h"
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "gfx/size.h"
#include "Vaca/PreferredSizeEvent.h"
#include "gui/preferred_size_event.h"
using namespace gfx;

View File

@ -23,7 +23,7 @@
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "Vaca/PreferredSizeEvent.h"
#include "gui/preferred_size_event.h"
using namespace gfx;

View File

@ -9,12 +9,12 @@
#include <string>
#include "gfx/rect.h"
#include "gui/component.h"
#include "gui/jbase.h"
#include "gui/jrect.h"
#include "gfx/rect.h"
#include "Vaca/Widget.h"
namespace Vaca { class PreferredSizeEvent; }
class PreferredSizeEvent;
#ifndef NDEBUG
#include "gui/jintern.h"
@ -24,8 +24,6 @@ namespace Vaca { class PreferredSizeEvent; }
#define ASSERT_VALID_WIDGET(widget) ((void)0)
#endif
using Vaca::PreferredSizeEvent;
struct FONT;
struct BITMAP;
@ -127,7 +125,7 @@ bool jwidget_check_underscored(JWidget widget, int scancode);
//////////////////////////////////////////////////////////////////////
class Widget : public Vaca::Widget
class Widget : public Component
{
public:
JID id; /* identify code */

View File

@ -11,10 +11,10 @@
#include <allegro.h>
#include "gfx/size.h"
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "gfx/size.h"
#include "Vaca/PreferredSizeEvent.h"
#include "gui/preferred_size_event.h"
using namespace gfx;

View File

@ -0,0 +1,69 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#include "gui/preferred_size_event.h"
#include "gui/jwidget.h"
using namespace gfx;
/**
Event generated to calculate the preferred size of a widget.
@param source
The widget that want to know its preferred size.
@param fitIn
This could be Size(0, 0) that means calculate the preferred size
without restrictions. If its width or height is greater than 0,
you could try to fit your widget to that width or height.
*/
PreferredSizeEvent::PreferredSizeEvent(Widget* source, const Size& fitIn)
: Event(source)
, m_fitIn(fitIn)
, m_preferredSize(0, 0)
{
}
/**
Destroys the PreferredSizeEvent.
*/
PreferredSizeEvent::~PreferredSizeEvent()
{
}
Size PreferredSizeEvent::fitInSize() const
{
return m_fitIn;
}
int PreferredSizeEvent::fitInWidth() const
{
return m_fitIn.w;
}
int PreferredSizeEvent::fitInHeight() const
{
return m_fitIn.h;
}
Size PreferredSizeEvent::getPreferredSize() const
{
return m_preferredSize;
}
void PreferredSizeEvent::setPreferredSize(const Size& preferredSize)
{
m_preferredSize = preferredSize;
}
/**
Sets the preferred size for the widget.
*/
void PreferredSizeEvent::setPreferredSize(int w, int h)
{
m_preferredSize.w = w;
m_preferredSize.h = h;
}

View File

@ -0,0 +1,35 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef GUI_PREFERRED_SIZE_EVENT_H_INCLUDED
#define GUI_PREFERRED_SIZE_EVENT_H_INCLUDED
#include "gui/event.h"
#include "gfx/size.h"
class Widget;
class PreferredSizeEvent : public Event
{
gfx::Size m_fitIn;
gfx::Size m_preferredSize;
public:
PreferredSizeEvent(Widget* source, const gfx::Size& fitIn);
virtual ~PreferredSizeEvent();
gfx::Size fitInSize() const;
int fitInWidth() const;
int fitInHeight() const;
gfx::Size getPreferredSize() const;
void setPreferredSize(const gfx::Size& preferredSize);
void setPreferredSize(int w, int h);
};
#endif

21
src/gui/property.cpp Normal file
View File

@ -0,0 +1,21 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#include "gui/property.h"
Property::Property(const base::string& name)
: m_name(name)
{
}
Property::~Property()
{
}
base::string Property::getName() const
{
return m_name;
}

30
src/gui/property.h Normal file
View File

@ -0,0 +1,30 @@
// ASE gui library
// Copyright (C) 2001-2010 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef GUI_PROPERTY_H_INCLUDED
#define GUI_PROPERTY_H_INCLUDED
#include "base/string.h"
#include "base/disable_copying.h"
#include "base/shared_ptr.h"
class Property
{
base::string m_name;
public:
Property(const base::string& name);
virtual ~Property();
base::string getName() const;
private:
DISABLE_COPYING(Property);
};
typedef SharedPtr<Property> PropertyPtr;
#endif

View File

@ -28,11 +28,8 @@
#include <winalleg.h>
#endif
#include "Vaca/SharedPtr.h"
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "app.h"
#include "base/shared_ptr.h"
#include "commands/command.h"
#include "commands/commands.h"
#include "commands/params.h"
@ -40,6 +37,8 @@
#include "core/cfg.h"
#include "core/drop_files.h"
#include "gfxmode.h"
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "modules/editors.h"
#include "modules/gfx.h"
#include "modules/gui.h"
@ -791,7 +790,7 @@ void get_widgets(JWidget window, ...)
void setup_mini_look(Widget* widget)
{
Vaca::SharedPtr<SkinProperty> skinProp;
SharedPtr<SkinProperty> skinProp;
skinProp = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinProp == NULL)
@ -803,7 +802,7 @@ void setup_mini_look(Widget* widget)
void setup_bevels(Widget* widget, int b1, int b2, int b3, int b4)
{
Vaca::SharedPtr<SkinProperty> skinProp;
SharedPtr<SkinProperty> skinProp;
skinProp = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinProp == NULL)

View File

@ -21,12 +21,11 @@
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include "Vaca/SharedPtr.h"
#include "ase_exception.h"
#include "base/bind.h"
#include "base/shared_ptr.h"
#include "gui/jinete.h"
#include "gui/jintern.h"
#include "ase_exception.h"
#include "loadpng.h"
#include "modules/gui.h"
#include "modules/skinneable_theme.h"
@ -627,7 +626,7 @@ void SkinneableTheme::draw_button(ButtonBase* widget, JRect clip)
// Tool buttons are smaller
bool isMiniLook = false;
Vaca::SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinPropery != NULL)
isMiniLook = skinPropery->isMiniLook();
@ -1117,7 +1116,7 @@ void SkinneableTheme::draw_slider(JWidget widget, JRect clip)
// Tool buttons are smaller
bool isMiniLook = false;
Vaca::SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinPropery != NULL)
isMiniLook = skinPropery->isMiniLook();
@ -1752,7 +1751,7 @@ bool SkinneableTheme::theme_frame_button_msg_proc(JWidget widget, JMessage msg)
//////////////////////////////////////////////////////////////////////
const Vaca::Char* SkinProperty::SkinPropertyName = L"SkinProperty";
const char* SkinProperty::SkinPropertyName = "SkinProperty";
SkinProperty::SkinProperty()
: Property(SkinPropertyName)

View File

@ -19,19 +19,20 @@
#ifndef MODULES_SKINNEABLE_THEME_H_INCLUDED
#define MODULES_SKINNEABLE_THEME_H_INCLUDED
#include <allegro/color.h>
#include <map>
#include <string>
#include <allegro/color.h>
#include "gui/jtheme.h"
#include "gui/jrect.h"
#include "Vaca/Property.h"
#include "gfx/rect.h"
#include "gui/jrect.h"
#include "gui/jtheme.h"
#include "gui/property.h"
// Property to show widgets with a special look (e.g.: buttons or sliders with mini-borders)
class SkinProperty : public Vaca::Property
class SkinProperty : public Property
{
public:
static const Vaca::Char* SkinPropertyName;
static const char* SkinPropertyName;
SkinProperty();
~SkinProperty();

View File

@ -20,10 +20,10 @@
#include <allegro.h>
#include "Vaca/PreferredSizeEvent.h"
#include "app/color.h"
#include "app/color_utils.h"
#include "gui/jinete.h"
#include "gui/preferred_size_event.h"
#include "modules/gfx.h"
#include "modules/gui.h"
#include "raster/sprite.h"

View File

@ -4,9 +4,4 @@
include_directories(include ../../src)
add_library(vaca
src/Component.cpp
src/Event.cpp
src/Exception.cpp
src/PreferredSizeEvent.cpp
src/Property.cpp
src/Referenceable.cpp)
src/Exception.cpp)

View File

@ -1,71 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_COMPONENT_H
#define VACA_COMPONENT_H
#include "Vaca/base.h"
#include "Vaca/Referenceable.h"
#include <map>
namespace Vaca {
/**
A component is a visual object, such as widgets or menus.
Components are non-copyable but are referenceable (e.g. you can
use them inside a SharedPtr).
@see NonCopyable, Referenceable, SharedPtr
*/
class VACA_DLL Component : public Referenceable
{
public:
typedef std::map<String, PropertyPtr> Properties;
Component();
virtual ~Component();
PropertyPtr getProperty(const String& name);
void setProperty(PropertyPtr property);
bool hasProperty(const String& name);
void removeProperty(const String& name);
const Properties& getProperties() const;
private:
Properties m_properties;
};
} // namespace Vaca
#endif // VACA_COMPONENT_H

View File

@ -1,61 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2010 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_EVENT_H
#define VACA_EVENT_H
#include "Vaca/base.h"
namespace Vaca {
/**
Base class for every kind of event.
*/
class VACA_DLL Event
{
/**
The component which generates the event. It's specified in the
@link Event#Event(Component*) Event's constructor@endlink
*/
Component* m_source;
public:
Event(Component* source);
virtual ~Event();
Component* getSource();
};
} // namespace Vaca
#endif // VACA_EVENT_H

View File

@ -1,63 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2010 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_PREFERREDSIZEEVENT_H
#define VACA_PREFERREDSIZEEVENT_H
#include "Vaca/base.h"
#include "Vaca/Event.h"
#include "gfx/size.h"
namespace Vaca {
class VACA_DLL PreferredSizeEvent : public Event
{
gfx::Size m_fitIn;
gfx::Size m_preferredSize;
public:
PreferredSizeEvent(Widget* source, const gfx::Size& fitIn);
virtual ~PreferredSizeEvent();
gfx::Size fitInSize() const;
int fitInWidth() const;
int fitInHeight() const;
gfx::Size getPreferredSize() const;
void setPreferredSize(const gfx::Size& preferredSize);
void setPreferredSize(int w, int h);
};
} // namespace Vaca
#endif // VACA_PREFERREDSIZEEVENT_H

View File

@ -1,53 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_PROPERTY_H
#define VACA_PROPERTY_H
#include "Vaca/base.h"
#include "Vaca/Referenceable.h"
namespace Vaca {
class VACA_DLL Property : public Referenceable
{
String m_name;
public:
Property(const String& name);
virtual ~Property();
String getName() const;
};
} // namespace Vaca
#endif // VACA_PROPERTY_H

View File

@ -1,68 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_REFERENCEABLE_H
#define VACA_REFERENCEABLE_H
#include "Vaca/base.h"
#include "Vaca/NonCopyable.h"
namespace Vaca {
/**
Class that counts references and can be wrapped by a SharedPtr.
*/
class VACA_DLL Referenceable : private NonCopyable
{
template<class> friend class SharedPtr;
unsigned m_refCount;
public:
Referenceable();
virtual ~Referenceable();
void ref();
unsigned unref();
unsigned getRefCount();
#ifndef NDEBUG
static void showLeaks();
#endif
private:
void destroy();
};
} // namespace Vaca
#endif // VACA_REFERENCEABLE_H

View File

@ -1,160 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_SHAREDPTR_H
#define VACA_SHAREDPTR_H
#include "Vaca/base.h"
#include "Vaca/Referenceable.h"
namespace Vaca {
/**
A pointer which maintains reference counting and
automatically deletes the pointed object when it is
no longer referenced.
What is a shared pointer? It is a class that wraps a pointer to a
dynamically allocated object. Various shared pointers can share
the same object counting references for that object. When the
last shared pointer is destroyed, the object is automatically
deleted.
The SharedPtr is mainly used to wrap classes that handle
graphics resources (like Brush, Pen, Image, Icon, etc.).
@tparam T Must be of Referenceable type, because Referenceable has
the reference counter.
*/
template<class T>
class SharedPtr
{
T* m_ptr;
public:
SharedPtr() {
m_ptr = NULL;
}
/*explicit*/ SharedPtr(T* ptr) {
m_ptr = ptr;
ref();
}
SharedPtr(const SharedPtr<T>& other) {
m_ptr = other.get();
ref();
}
template<class T2>
SharedPtr(const SharedPtr<T2>& other) {
m_ptr = static_cast<T*>(other.get());
ref();
}
virtual ~SharedPtr() {
unref();
}
void reset(T* ptr = NULL) {
if (m_ptr != ptr) {
unref();
m_ptr = ptr;
ref();
}
}
SharedPtr& operator=(const SharedPtr<T>& other) {
if (m_ptr != other.get()) {
unref();
m_ptr = other.get();
ref();
}
return *this;
}
template<class T2>
SharedPtr& operator=(const SharedPtr<T2>& other) {
if (m_ptr != static_cast<T*>(other.get())) {
unref();
m_ptr = static_cast<T*>(other.get());
ref();
}
return *this;
}
inline T* get() const { return m_ptr; }
inline T& operator*() const { return *m_ptr; }
inline T* operator->() const { return m_ptr; }
inline operator T*() const { return m_ptr; }
private:
void ref() {
if (m_ptr)
((Referenceable*)m_ptr)->ref();
}
void unref() {
if (m_ptr) {
if (((Referenceable*)m_ptr)->unref() == 0)
((Referenceable*)m_ptr)->destroy();
m_ptr = NULL;
}
}
};
/**
Compares if two shared-pointers points to the same place (object, memory address).
@see @ref SharedPtr
*/
template<class T>
bool operator==(const SharedPtr<T>& ptr1, const SharedPtr<T>& ptr2)
{
return ptr1.get() == ptr2.get();
}
/**
Compares if two shared-pointers points to different places (objects, memory addresses).
@see @ref SharedPtr
*/
template<class T>
bool operator!=(const SharedPtr<T>& ptr1, const SharedPtr<T>& ptr2)
{
return ptr1.get() != ptr2.get();
}
} // namespace Vaca
#endif // VACA_SHAREDPTR_H

View File

@ -1,48 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VACA_WIDGET_H
#define VACA_WIDGET_H
#include "Vaca/Component.h"
namespace Vaca {
class VACA_DLL Widget : public Component
{
public:
Widget() { }
virtual ~Widget() { }
};
} // namespace Vaca
#endif // VACA_WIDGET_H

View File

@ -1,90 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Component.h"
#include "Vaca/SharedPtr.h"
#include "Vaca/Property.h"
using namespace Vaca;
/**
Creates a new component.
With the debug version of the library, you will get in the
@ref page_debug_log a line specifying when the component
was created.
*/
Component::Component()
{
}
/**
Destroys the component.
With the debug version of the library, you will get in the
@ref page_debug_log a line specifying when the component
was destroyed.
*/
Component::~Component()
{
}
PropertyPtr Component::getProperty(const String& name)
{
Properties::iterator it = m_properties.find(name);
if (it != m_properties.end())
return it->second;
else
return PropertyPtr();
}
void Component::setProperty(PropertyPtr property)
{
m_properties[property->getName()] = property;
}
bool Component::hasProperty(const String& name)
{
Properties::iterator it = m_properties.find(name);
return it != m_properties.end();
}
void Component::removeProperty(const String& name)
{
Properties::iterator it = m_properties.find(name);
if (it != m_properties.end())
m_properties.erase(it);
}
const Component::Properties& Component::getProperties() const
{
return m_properties;
}

View File

@ -1,64 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2010 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Event.h"
using namespace Vaca;
/**
Creates a new event specifying that it was generated
from the @a source component.
@param source
The component which generates the event.
*/
Event::Event(Component* source)
: m_source(source)
{
}
/**
Destroys the event.
*/
Event::~Event()
{
}
/**
Returns the event's source.
@return
The component which generates the event.
*/
Component* Event::getSource()
{
return m_source;
}

View File

@ -1,95 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2010 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/PreferredSizeEvent.h"
#include "Vaca/Widget.h"
using namespace gfx;
using namespace Vaca;
/**
Event generated to calculate the preferred size of a widget.
@param source
The widget that want to know its preferred size.
@param fitIn
This could be Size(0, 0) that means calculate the preferred size
without restrictions. If its width or height is greater than 0,
you could try to fit your widget to that width or height.
*/
PreferredSizeEvent::PreferredSizeEvent(Widget* source, const Size& fitIn)
: Event(source)
, m_fitIn(fitIn)
, m_preferredSize(0, 0)
{
}
/**
Destroys the PreferredSizeEvent.
*/
PreferredSizeEvent::~PreferredSizeEvent()
{
}
Size PreferredSizeEvent::fitInSize() const
{
return m_fitIn;
}
int PreferredSizeEvent::fitInWidth() const
{
return m_fitIn.w;
}
int PreferredSizeEvent::fitInHeight() const
{
return m_fitIn.h;
}
Size PreferredSizeEvent::getPreferredSize() const
{
return m_preferredSize;
}
void PreferredSizeEvent::setPreferredSize(const Size& preferredSize)
{
m_preferredSize = preferredSize;
}
/**
Sets the preferred size for the widget.
*/
void PreferredSizeEvent::setPreferredSize(int w, int h)
{
m_preferredSize.w = w;
m_preferredSize.h = h;
}

View File

@ -1,54 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Property.h"
using namespace Vaca;
/**
Creates a new named property.
*/
Property::Property(const String& name)
: m_name(name)
{
}
/**
Destroys the property.
*/
Property::~Property()
{
}
String Property::getName() const
{
return m_name;
}

View File

@ -1,146 +0,0 @@
// Vaca - Visual Application Components Abstraction
// Copyright (c) 2005-2009 David Capello
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Vaca/Referenceable.h"
#ifndef NDEBUG
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include <vector>
#include <typeinfo>
#ifdef VACA_ON_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#endif
#include <cassert>
#include <iostream>
using namespace Vaca;
#ifndef NDEBUG
static Mutex s_mutex;
static std::vector<Referenceable*> s_list;
#endif
/**
Constructs a new referenceable object starting with zero references.
*/
Referenceable::Referenceable()
{
m_refCount = 0;
#ifndef NDEBUG
{
ScopedLock hold(s_mutex);
s_list.push_back(this);
}
#endif
}
/**
Destroys a referenceable object.
When compiling with assertions it checks that the references'
counter is really zero.
*/
Referenceable::~Referenceable()
{
#ifndef NDEBUG
{
ScopedLock hold(s_mutex);
remove_from_container(s_list, this);
}
#endif
assert(m_refCount == 0);
}
/**
Called by SharedPtr to destroy the referenceable.
*/
void Referenceable::destroy()
{
delete this;
}
/**
Makes a new reference to this object.
You are responsible for removing references using the #unref
member function. Remember that for each call to #ref that you made,
there should be a corresponding #unref.
@see unref
*/
void Referenceable::ref()
{
++m_refCount;
}
/**
Deletes an old reference to this object.
If assertions are activated this routine checks that the
reference counter never get negative, because that implies
an error of the programmer.
@see ref
*/
unsigned Referenceable::unref()
{
assert(m_refCount > 0);
return --m_refCount;
}
/**
Returns the current number of references that this object has.
If it's zero you can delete the object safely.
*/
unsigned Referenceable::getRefCount()
{
return m_refCount;
}
#ifndef NDEBUG
void Referenceable::showLeaks()
{
#ifdef VACA_ON_WINDOWS
if (!s_list.empty())
::Beep(400, 100);
#endif
for (std::vector<Referenceable*>::iterator
it=s_list.begin(); it!=s_list.end(); ++it) {
std::clog << "leak Referenceable " << (*it) << "\n";
}
}
#endif