1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
13 OtkWidget::OtkWidget(OtkWidget
*parent
, Direction direction
)
14 : OtkBaseWidget(parent
),
16 _direction(direction
), _stretchable_vert(false), _stretchable_horz(false),
17 _event_dispatcher(parent
->getEventDispatcher())
20 _event_dispatcher
->registerHandler(getWindow(), this);
23 OtkWidget::OtkWidget(OtkEventDispatcher
*event_dispatcher
, Style
*style
,
24 Direction direction
, Cursor cursor
, int bevel_width
)
25 : OtkBaseWidget(style
, cursor
, bevel_width
),
27 _direction(direction
), _stretchable_vert(false), _stretchable_horz(false),
28 _event_dispatcher(event_dispatcher
)
30 assert(event_dispatcher
);
31 _event_dispatcher
->registerHandler(getWindow(), this);
34 OtkWidget::~OtkWidget()
36 _event_dispatcher
->clearHandler(_window
);
39 void OtkWidget::adjust(void)
41 if (_direction
== Horizontal
)
47 void OtkWidget::adjustHorz(void)
49 if (_children
.size() == 0)
53 OtkBaseWidgetList::iterator it
, end
= _children
.end();
56 int width
= _bevel_width
;
57 OtkBaseWidgetList stretchable
;
59 for (it
= _children
.begin(); it
!= end
; ++it
) {
60 if (!(tmp
= dynamic_cast<OtkWidget
*>(*it
))) continue;
61 if (tmp
->isStretchableVert())
62 tmp
->setHeight(_rect
.height() > _bevel_width
* 2 ?
63 _rect
.height() - _bevel_width
* 2 : _bevel_width
);
64 if (tmp
->isStretchableHorz())
65 stretchable
.push_back(tmp
);
67 width
+= tmp
->_rect
.width() + _bevel_width
;
69 if (tmp
->_rect
.height() > tallest
)
70 tallest
= tmp
->_rect
.height();
73 if (stretchable
.size() > 0) {
74 OtkBaseWidgetList::iterator str_it
= stretchable
.begin(),
75 str_end
= stretchable
.end();
77 int str_width
= _rect
.width() - width
/ stretchable
.size();
79 for (; str_it
!= str_end
; ++str_it
)
80 (*str_it
)->setWidth(str_width
> _bevel_width
? str_width
- _bevel_width
84 OtkWidget
*prev_widget
= 0;
86 for (it
= _children
.begin(); it
!= end
; ++it
) {
87 if (!(tmp
= dynamic_cast<OtkWidget
*>(*it
))) continue;
91 x
= prev_widget
->_rect
.x() + prev_widget
->_rect
.width() + _bevel_width
;
93 x
= _rect
.x() + _bevel_width
;
94 y
= (tallest
- tmp
->_rect
.height()) / 2 + _bevel_width
;
101 internalResize(width
, tallest
+ _bevel_width
* 2);
104 void OtkWidget::adjustVert(void)
106 if (_children
.size() == 0)
110 OtkBaseWidgetList::iterator it
, end
= _children
.end();
113 int height
= _bevel_width
;
114 OtkBaseWidgetList stretchable
;
116 for (it
= _children
.begin(); it
!= end
; ++it
) {
117 if (!(tmp
= dynamic_cast<OtkWidget
*>(*it
))) continue;
118 if (tmp
->isStretchableHorz())
119 tmp
->setWidth(_rect
.width() > _bevel_width
* 2 ?
120 _rect
.width() - _bevel_width
* 2 : _bevel_width
);
121 if (tmp
->isStretchableVert())
122 stretchable
.push_back(tmp
);
124 height
+= tmp
->_rect
.height() + _bevel_width
;
126 if (tmp
->_rect
.width() > widest
)
127 widest
= tmp
->_rect
.width();
130 if (stretchable
.size() > 0) {
131 OtkBaseWidgetList::iterator str_it
= stretchable
.begin(),
132 str_end
= stretchable
.end();
134 int str_height
= _rect
.height() - height
/ stretchable
.size();
136 for (; str_it
!= str_end
; ++str_it
)
137 (*str_it
)->setHeight(str_height
> _bevel_width
?
138 str_height
- _bevel_width
: _bevel_width
);
141 OtkWidget
*prev_widget
= 0;
143 for (it
= _children
.begin(); it
!= end
; ++it
) {
144 if (!(tmp
= dynamic_cast<OtkWidget
*>(*it
))) continue;
148 y
= prev_widget
->_rect
.y() + prev_widget
->_rect
.height() + _bevel_width
;
150 y
= _rect
.y() + _bevel_width
;
151 x
= (widest
- tmp
->_rect
.width()) / 2 + _bevel_width
;
158 internalResize(widest
+ _bevel_width
* 2, height
);
161 void OtkWidget::update(void)
166 OtkBaseWidget::update();
169 void OtkWidget::internalResize(int w
, int h
)
171 assert(w
> 0 && h
> 0);
173 // if (! _fixed_width && ! _fixed_height)
175 // else if (! _fixed_width)
176 // resize(w, _rect.height());
177 // else if (! _fixed_height)
178 // resize(_rect.width(), h);
181 void OtkWidget::setEventDispatcher(OtkEventDispatcher
*disp
)
183 if (_event_dispatcher
)
184 _event_dispatcher
->clearHandler(_window
);
185 _event_dispatcher
= disp
;
186 _event_dispatcher
->registerHandler(_window
, this);
189 void OtkWidget::exposeHandler(const XExposeEvent
&e
)
191 OtkEventHandler::exposeHandler(e
);
196 void OtkWidget::configureHandler(const XConfigureEvent
&e
)
198 OtkEventHandler::configureHandler(e
);
199 if (_ignore_config
) {
202 if (!(e
.width
== _rect
.width() && e
.height
== _rect
.height())) {
204 _rect
.setSize(e
.width
, e
.height
);