aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-10 16:11:57 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-10 16:11:57 +0100
commita9e1b0d2f8a98a5299981fd0c297d2a0befac30d (patch)
tree13101feab80f910f02f68b65e8d6e988c453c648 /dw
parentc4f9b611e72fae43e354af489ece509525309b2a (diff)
parent08ca8a9857b54f2e647a555fd4f531c415adf042 (diff)
merge with main
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkplatform.cc5
-rw-r--r--dw/fltkplatform.hh3
-rw-r--r--dw/fltkui.cc51
-rw-r--r--dw/fltkui.hh7
-rw-r--r--dw/image.cc20
-rw-r--r--dw/ui.cc9
-rw-r--r--dw/ui.hh6
7 files changed, 88 insertions, 13 deletions
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc
index 94a5dd70..e35027d4 100644
--- a/dw/fltkplatform.cc
+++ b/dw/fltkplatform.cc
@@ -196,9 +196,10 @@ FltkPlatform::FltkResourceFactory::createOptionMenuResource ()
core::ui::EntryResource *
FltkPlatform::FltkResourceFactory::createEntryResource (int maxLength,
- bool password)
+ bool password,
+ const char *label)
{
- return new ui::FltkEntryResource (platform, maxLength, password);
+ return new ui::FltkEntryResource (platform, maxLength, password, label);
}
core::ui::MultiLineTextResource *
diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh
index e4600516..776204a6 100644
--- a/dw/fltkplatform.hh
+++ b/dw/fltkplatform.hh
@@ -81,7 +81,8 @@ private:
createListResource (core::ui::ListResource::SelectionMode selectionMode);
core::ui::OptionMenuResource *createOptionMenuResource ();
core::ui::EntryResource *createEntryResource (int maxLength,
- bool password);
+ bool password,
+ const char *label);
core::ui::MultiLineTextResource *createMultiLineTextResource (int cols,
int rows);
core::ui::CheckButtonResource *createCheckButtonResource (bool
diff --git a/dw/fltkui.cc b/dw/fltkui.cc
index 9d9b8107..f4090521 100644
--- a/dw/fltkui.cc
+++ b/dw/fltkui.cc
@@ -199,7 +199,35 @@ void FltkResource::setWidgetStyle (::fltk::Widget *widget,
}
}
}
-
+
+void FltkResource::setDisplayed(bool displayed)
+{
+ for (Iterator <ViewAndWidget> it = viewsAndWidgets->iterator ();
+ it.hasNext(); ) {
+ ViewAndWidget *viewAndWidget = it.getNext ();
+ if (displayed)
+ viewAndWidget->widget->show();
+ else
+ viewAndWidget->widget->hide();
+ }
+}
+
+bool FltkResource::displayed()
+{
+ bool ret;
+ Iterator <ViewAndWidget> it = viewsAndWidgets->iterator ();
+
+ if (it.hasNext()) {
+ ViewAndWidget *viewAndWidget = it.getNext ();
+ // visible() is not the same thing as being show()n exactly, but
+ // show()/hide() set it appropriately for our purposes.
+ ret = viewAndWidget->widget->visible();
+ } else {
+ ret = false;
+ }
+ return ret;
+}
+
bool FltkResource::isEnabled ()
{
/** \bug Not implemented. */
@@ -487,11 +515,12 @@ int FltkComplexButtonResource::reliefYThickness ()
// ----------------------------------------------------------------------
FltkEntryResource::FltkEntryResource (FltkPlatform *platform, int maxLength,
- bool password):
+ bool password, const char *label):
FltkSpecificResource <dw::core::ui::EntryResource> (platform)
{
this->maxLength = maxLength;
this->password = password;
+ this->label = label ? strdup(label) : NULL;
initText = NULL;
editable = false;
@@ -503,6 +532,8 @@ FltkEntryResource::~FltkEntryResource ()
{
if (initText)
delete initText;
+ if (label)
+ delete label;
}
::fltk::Widget *FltkEntryResource::createNewWidget (core::Allocation
@@ -518,6 +549,10 @@ FltkEntryResource::~FltkEntryResource ()
input->callback (widgetCallback, this);
input->when (::fltk::WHEN_ENTER_KEY_ALWAYS);
+ if (label) {
+ input->label(label);
+ input->set_flag(::fltk::ALIGN_INSIDE_LEFT);
+ }
if (viewsAndWidgets->isEmpty ()) {
// First widget created, attach the set text.
if (initText)
@@ -529,9 +564,15 @@ FltkEntryResource::~FltkEntryResource ()
return input;
}
+void FltkEntryResource::setDisplayed(bool displayed)
+{
+ FltkResource::setDisplayed(displayed);
+ queueResize(true);
+}
+
void FltkEntryResource::sizeRequest (core::Requisition *requisition)
{
- if (style) {
+ if (displayed() && style) {
FltkFont *font = (FltkFont*)style->font;
::fltk::setfont(font->font,font->size);
requisition->width =
@@ -541,8 +582,8 @@ void FltkEntryResource::sizeRequest (core::Requisition *requisition)
requisition->ascent = font->ascent + RELIEF_Y_THICKNESS;
requisition->descent = font->descent + RELIEF_Y_THICKNESS;
} else {
- requisition->width = 1;
- requisition->ascent = 1;
+ requisition->width = 0;
+ requisition->ascent = 0;
requisition->descent = 0;
}
}
diff --git a/dw/fltkui.hh b/dw/fltkui.hh
index 4de99d27..3d19fc63 100644
--- a/dw/fltkui.hh
+++ b/dw/fltkui.hh
@@ -195,6 +195,8 @@ protected:
virtual ::fltk::Widget *createNewWidget (core::Allocation *allocation) = 0;
void setWidgetStyle (::fltk::Widget *widget, core::style::Style *style);
+ void setDisplayed (bool displayed);
+ bool displayed();
public:
~FltkResource ();
@@ -298,15 +300,18 @@ private:
int maxLength;
bool password;
const char *initText;
+ char *label;
bool editable;
static void widgetCallback (::fltk::Widget *widget, void *data);
+ void setDisplayed (bool displayed);
protected:
::fltk::Widget *createNewWidget (core::Allocation *allocation);
public:
- FltkEntryResource (FltkPlatform *platform, int maxLength, bool password);
+ FltkEntryResource (FltkPlatform *platform, int maxLength, bool password,
+ const char *label);
~FltkEntryResource ();
void sizeRequest (core::Requisition *requisition);
diff --git a/dw/image.cc b/dw/image.cc
index ce54f561..56d6a4ec 100644
--- a/dw/image.cc
+++ b/dw/image.cc
@@ -144,8 +144,24 @@ Image::~Image()
void Image::sizeRequestImpl (core::Requisition *requisition)
{
if (buffer) {
- requisition->width = buffer->getRootWidth ();
- requisition->ascent = buffer->getRootHeight ();
+ if (getStyle ()->height == core::style::LENGTH_AUTO &&
+ core::style::isAbsLength (getStyle ()->width) &&
+ buffer->getRootWidth () > 0) {
+ // preserve aspect ratio when only width is given
+ requisition->width = core::style::absLengthVal (getStyle ()->width);
+ requisition->ascent = buffer->getRootHeight () *
+ requisition->width / buffer->getRootWidth ();
+ } else if (getStyle ()->width == core::style::LENGTH_AUTO &&
+ core::style::isAbsLength (getStyle ()->height) &&
+ buffer->getRootHeight () > 0) {
+ // preserve aspect ratio when only height is given
+ requisition->ascent = core::style::absLengthVal (getStyle ()->height);
+ requisition->width = buffer->getRootWidth () *
+ requisition->ascent / buffer->getRootHeight ();
+ } else {
+ requisition->width = buffer->getRootWidth ();
+ requisition->ascent = buffer->getRootHeight ();
+ }
requisition->descent = 0;
} else {
if(altText && altText[0]) {
diff --git a/dw/ui.cc b/dw/ui.cc
index ef7298bf..945395c3 100644
--- a/dw/ui.cc
+++ b/dw/ui.cc
@@ -97,6 +97,11 @@ void Embed::setDescent (int descent)
resource->setDescent (descent);
}
+void Embed::setDisplayed (bool displayed)
+{
+ resource->setDisplayed (displayed);
+}
+
void Embed::draw (View *view, Rectangle *area)
{
drawWidgetBox (view, area, false);
@@ -196,6 +201,10 @@ void Resource::setDescent (int descent)
{
}
+void Resource::setDisplayed (bool displayed)
+{
+}
+
void Resource::draw (View *view, Rectangle *area)
{
}
diff --git a/dw/ui.hh b/dw/ui.hh
index ea8fd4c4..306883c2 100644
--- a/dw/ui.hh
+++ b/dw/ui.hh
@@ -243,6 +243,7 @@ public:
void setWidth (int width);
void setAscent (int ascent);
void setDescent (int descent);
+ void setDisplayed (bool displayed);
void draw (View *view, Rectangle *area);
Iterator *iterator (Content::Type mask, bool atEnd);
void setStyle (style::Style *style);
@@ -336,6 +337,7 @@ public:
virtual void setWidth (int width);
virtual void setAscent (int ascent);
virtual void setDescent (int descent);
+ virtual void setDisplayed (bool displayed);
virtual void draw (View *view, Rectangle *area);
virtual Iterator *iterator (Content::Type mask, bool atEnd) = 0;
virtual void setStyle (style::Style *style);
@@ -539,8 +541,8 @@ public:
virtual ListResource *createListResource (ListResource::SelectionMode
selectionMode) = 0;
virtual OptionMenuResource *createOptionMenuResource () = 0;
- virtual EntryResource *createEntryResource (int maxLength,
- bool password) = 0;
+ virtual EntryResource *createEntryResource (int maxLength, bool password,
+ const char *label) = 0;
virtual MultiLineTextResource *createMultiLineTextResource (int cols,
int rows) = 0;
virtual CheckButtonResource *createCheckButtonResource (bool activated) = 0;