//----------------------------------------------------------------------------
NasalWidget::NasalWidget(naRef impl):
- _nasal_impl(impl)
+ Object(impl)
{
- assert( naIsHash(_nasal_impl.get_naRef()) );
+
}
//----------------------------------------------------------------------------
{
if( _geometry == geom )
return;
-
_geometry = geom;
- if( _set_geometry )
- _set_geometry(_nasal_impl.get_naRef(), geom);
+ if( !_set_geometry )
+ return;
+
+ naContext c = naNewContext();
+ try
+ {
+ _set_geometry(nasal::to_nasal(c, this), geom);
+ }
+ catch( std::exception const& ex )
+ {
+ SG_LOG(
+ SG_GUI,
+ SG_WARN,
+ "NasalWidget::setGeometry: callback error: '" << ex.what() << "'"
+ );
+ }
+ naFreeContext(c);
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
- void NasalWidget::setImpl(naRef obj)
+ void NasalWidget::setHeightForWidthFunc(const HeightForWidthFunc& func)
{
- _nasal_impl.reset(obj);
+ _height_for_width = func;
+ invalidateParent();
}
//----------------------------------------------------------------------------
- naRef NasalWidget::getImpl() const
+ void NasalWidget::setMinimumHeightForWidthFunc(const HeightForWidthFunc& func)
{
- return _nasal_impl.get_naRef();
+ _min_height_for_width = func;
+ invalidateParent();
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
- bool NasalWidget::_set(naContext c, const std::string& key, naRef val)
+ bool NasalWidget::hasHeightForWidth() const
{
- if( !_nasal_impl.valid() )
- return false;
+ return !_height_for_width.empty() || !_min_height_for_width.empty();
+ }
- nasal::Hash(_nasal_impl.get_naRef(), c).set(key, val);
- return true;
+ //----------------------------------------------------------------------------
+ int NasalWidget::heightForWidth(int w) const
+ {
+ return callHeightForWidthFunc( _height_for_width.empty()
+ ? _min_height_for_width
+ : _height_for_width, w );
+ }
+
+ //----------------------------------------------------------------------------
+ int NasalWidget::minimumHeightForWidth(int w) const
+ {
+ return callHeightForWidthFunc( _min_height_for_width.empty()
+ ? _height_for_width
+ : _min_height_for_width, w );
}
//----------------------------------------------------------------------------
{
nasal::Ghost<NasalWidgetRef>::init("canvas.Widget")
.bases<LayoutItemRef>()
- ._set(&NasalWidget::_set)
- .member("parents", &NasalWidget::getParents)
+ .bases<nasal::ObjectRef>()
.method("setSetGeometryFunc", &NasalWidget::setSetGeometryFunc)
+ .method("setMinimumHeightForWidthFunc",
+ &NasalWidget::setMinimumHeightForWidthFunc)
+ .method("setHeightForWidthFunc", &NasalWidget::setHeightForWidthFunc)
.method("setSizeHint", &NasalWidget::setSizeHint)
.method("setMinimumSize", &NasalWidget::setMinimumSize)
.method("setMaximumSize", &NasalWidget::setMaximumSize);
}
//----------------------------------------------------------------------------
- naRef NasalWidget::getParents(NasalWidget& w, naContext c)
+ int NasalWidget::callHeightForWidthFunc( const HeightForWidthFunc& hfw,
+ int w ) const
{
- naRef parents[] = { w._nasal_impl.get_naRef() };
- return nasal::to_nasal(c, parents);
+ if( hfw.empty() )
+ return -1;
+
+ naContext c = naNewContext();
+ try
+ {
+ return hfw(nasal::to_nasal(c, const_cast<NasalWidget*>(this)), w);
+ }
+ catch( std::exception const& ex )
+ {
+ SG_LOG(
+ SG_GUI,
+ SG_WARN,
+ "NasalWidget.heightForWidth: callback error: '" << ex.what() << "'"
+ );
+ }
+ naFreeContext(c);
+
+ return -1;
}
//----------------------------------------------------------------------------