void Label::calcDefaultSizes()
{
- unsigned int longest = 0;
+ int longest = 0;
// find the longest line
std::vector<ustring>::iterator it, end = _parsedtext.end();
for (it = _parsedtext.begin(); it != end; ++it) {
- unsigned int length = _font->measureString(*it);
+ int length = _font->measureString(*it);
+ if (length < 0) continue; // lines too long get skipped
if (length > longest) longest = length;
}
setMinSize(Size(longest + borderWidth() * 2 + bevel() * 4,
void Label::renderForeground(Surface &surface)
{
const RenderControl *control = display->renderControl(screen());
- unsigned int sidemargin = bevel() * 2;
+ int sidemargin = bevel() * 2;
int y = bevel();
- unsigned int w = area().width() - borderWidth() * 2 - sidemargin * 2;
- unsigned int h = area().height() - borderWidth() * 2 - bevel() * 2;
+ int w = area().width() - borderWidth() * 2 - sidemargin * 2;
+ int h = area().height() - borderWidth() * 2 - bevel() * 2;
switch (_justify_vert) {
case RenderStyle::RightBottomJustify:
// find a string that will fit inside the area for text
ustring::size_type text_len = t.size();
- unsigned int length;
+ int length;
do {
t.resize(text_len);
length = _font->measureString(t);
} while (length > w && text_len-- > 0);
+ if (length < 0) continue; // lines too long get skipped
if (text_len <= 0) continue; // won't fit anything
Rect() : _p(), _s() {}
Rect(const Point &p, const Size &s) : _p(p), _s(s) {}
Rect(const Rect &r) : _p(r._p), _s(r._s) {}
- Rect(int x, int y, unsigned int w, unsigned int h)
+ Rect(int x, int y, int w, int h)
: _p(x, y), _s(w, h) {}
inline int x() const { return _p.x(); }
inline int y() const { return _p.y(); }
- inline unsigned int width() const { return _s.width(); }
- inline unsigned int height() const { return _s.height(); }
+ inline int width() const { return _s.width(); }
+ inline int height() const { return _s.height(); }
inline int left() const { return _p.x(); }
inline int top() const { return _p.y(); }
_file(stylefile)
{
// pick one..
-#define FIERON
-//#define MERRY
+//#define FIERON
+#define MERRY
#ifdef FIERON
_root_color = new RenderColor(_screen, 0x272a2f);
namespace otk {
-ScreenInfo::ScreenInfo(unsigned int num) {
+ScreenInfo::ScreenInfo(int num) {
+ assert(num >= 0 && num < ScreenCount(**display));
+
_screen = num;
_root_window = RootWindow(**display, _screen);
Colormap _colormap;
int _depth;
- unsigned int _screen;
+ int _screen;
std::string _display_string;
Size _size;
#ifdef XINERAMA
#endif
public:
- ScreenInfo(unsigned int num);
+ ScreenInfo(int num);
inline Visual *visual() const { return _visual; }
inline Window rootWindow() const { return _root_window; }
inline Colormap colormap() const { return _colormap; }
inline int depth() const { return _depth; }
- inline unsigned int screen() const { return _screen; }
+ inline int screen() const { return _screen; }
inline const Size& size() const { return _size; }
inline const std::string& displayString() const { return _display_string; }
#ifdef XINERAMA
#ifndef __size_hh
#define __size_hh
+#include <cassert>
+
namespace otk {
class Size {
- unsigned int _w, _h;
+ int _w, _h;
public:
Size() : _w(1), _h(1) {}
- Size(unsigned int w, unsigned int h) : _w(w), _h(h) {}
- Size(const Size &s) : _w(s._w), _h(s._h) {}
+ Size(int w, int h) : _w(w), _h(h) { assert(_w >= 0 && _h >= 0); }
+ Size(const Size &s) : _w(s._w), _h(s._h) { assert(_w >= 0 && _h >= 0); }
- inline unsigned int width() const { return _w; }
- inline unsigned int height() const { return _h; }
+ inline int width() const { return _w; }
+ inline int height() const { return _h; }
bool operator==(const Size &o) const { return _w == o._w && _h == o._h; }
bool operator!=(const Size &o) const { return _w != o._w || _h != o._h; }
void Surface::setPixmap(XImage *image)
{
- assert((unsigned)image->width == _size.width());
- assert((unsigned)image->height == _size.height());
+ assert(image->width == _size.width());
+ assert(image->height == _size.height());
if (_pixmap == None)
createObjects();
Surface &sf, const RenderTexture &texture) const
{
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
- unsigned int off, x;
+ int w = sf.size().width(), h = sf.size().height();
+ int off, x;
const ScreenInfo *info = display->screenInfo(_screen);
XImage *im = XCreateImage(**display, info->visual(), info->depth(),
if (texture.relief() != RenderTexture::Flat) {
if (texture.bevel() == RenderTexture::Bevel1) {
- if (w >= 1 && h >= 1) {
- for (off = 1, x = 1; x < w - 1; ++x, off++)
- highlight(data + off,
- data + off + (h-1) * w,
- texture.relief()==RenderTexture::Raised);
- for (off = 0, x = 0; x < h; ++x, off++)
- highlight(data + off * w,
- data + off * w + w - 1,
- texture.relief()==RenderTexture::Raised);
- }
+ for (off = 1, x = 1; x < w - 1; ++x, off++)
+ highlight(data + off,
+ data + off + (h-1) * w,
+ texture.relief()==RenderTexture::Raised);
+ for (off = 0, x = 0; x < h; ++x, off++)
+ highlight(data + off * w,
+ data + off * w + w - 1,
+ texture.relief()==RenderTexture::Raised);
}
if (texture.bevel() == RenderTexture::Bevel2) {
- if (w >= 2 && h >= 2) {
- for (off = 2, x = 2; x < w - 2; ++x, off++)
- highlight(data + off + w,
- data + off + (h-2) * w,
- texture.relief()==RenderTexture::Raised);
- for (off = 1, x = 1; x < h-1; ++x, off++)
- highlight(data + off * w + 1,
- data + off * w + w - 2,
- texture.relief()==RenderTexture::Raised);
- }
+ for (off = 2, x = 2; x < w - 2; ++x, off++)
+ highlight(data + off + w,
+ data + off + (h-2) * w,
+ texture.relief()==RenderTexture::Raised);
+ for (off = 1, x = 1; x < h-1; ++x, off++)
+ highlight(data + off * w + 1,
+ data + off * w + w - 2,
+ texture.relief()==RenderTexture::Raised);
}
}
pixel32 current;
float dr, dg, db;
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
+ int w = sf.size().width(), h = sf.size().height();
dr = (float)(texture.secondary_color().red() - texture.color().red());
dr/= (float)h;
db = (float)(texture.secondary_color().blue() - texture.color().blue());
db/= (float)h;
- for (unsigned int y = 0; y < h; ++y) {
+ for (int y = 0; y < h; ++y) {
r = texture.color().red() + (int)(dr * y);
g = texture.color().green() + (int)(dg * y);
b = texture.color().blue() + (int)(db * y);
current = (r << default_red_shift)
+ (g << default_green_shift)
+ (b << default_blue_shift);
- for (unsigned int x = 0; x < w; ++x, ++data)
+ for (int x = 0; x < w; ++x, ++data)
*data = current;
}
}
pixel32 current;
float drx, dgx, dbx, dry, dgy, dby;
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
+ int w = sf.size().width(), h = sf.size().height();
- for (unsigned int y = 0; y < h; ++y) {
+ for (int y = 0; y < h; ++y) {
drx = (float)(texture.secondary_color().red() - texture.color().red());
dry = drx/(float)h;
drx/= (float)w;
dbx = (float)(texture.secondary_color().blue() - texture.color().blue());
dby = dbx/(float)h;
dbx/= (float)w;
- for (unsigned int x = 0; x < w; ++x, ++data) {
+ for (int x = 0; x < w; ++x, ++data) {
r = texture.color().red() + ((int)(drx * x) + (int)(dry * y))/2;
g = texture.color().green() + ((int)(dgx * x) + (int)(dgy * y))/2;
b = texture.color().blue() + ((int)(dbx * x) + (int)(dby * y))/2;
pixel32 current;
float drx, dgx, dbx, dry, dgy, dby;
unsigned int r,g,b;
- unsigned int w = sf.size().width(), h = sf.size().height();
+ int w = sf.size().width(), h = sf.size().height();
- for (unsigned int y = 0; y < h; ++y) {
+ for (int y = 0; y < h; ++y) {
drx = (float)(texture.secondary_color().red() - texture.color().red());
dry = drx/(float)h;
drx/= (float)w;
ExposureMask | StructureNotifyMask),
_alignment(RenderStyle::CenterJustify),
_direction(direction),
- _max_size(UINT_MAX, UINT_MAX),
+ _max_size(INT_MAX, INT_MAX),
_visible(false),
_bordercolor(0),
_borderwidth(0),
ExposureMask | StructureNotifyMask),
_alignment(RenderStyle::CenterJustify),
_direction(direction),
- _max_size(UINT_MAX, UINT_MAX),
+ _max_size(INT_MAX, INT_MAX),
_visible(false),
_bordercolor(0),
_borderwidth(0),
void Widget::moveresize(const Rect &r)
{
- unsigned int w, h;
+ int w, h;
w = std::min(std::max(r.width(), minSize().width()), maxSize().width());
h = std::min(std::max(r.height(), minSize().height()), maxSize().height());
update();
}
-void Widget::internal_moveresize(int x, int y, unsigned w, unsigned int h)
+void Widget::internal_moveresize(int x, int y, int w, int h)
{
assert(w > 0);
assert(h > 0);
if (visible.empty()) return;
- if ((unsigned)(_borderwidth * 2 + _bevel * 2) > _area.width() ||
- (unsigned)(_borderwidth * 2 + _bevel * 2) > _area.height())
- return; // not worth laying anything out!
-
- int x, y; unsigned int w, h; // working area
+ int x, y, w, h; // working area
x = y = _bevel;
w = _area.width() - _borderwidth * 2 - _bevel * 2;
h = _area.height() - _borderwidth * 2 - _bevel * 2;
+ if (w < 0 || h < 0) return; // not worth laying anything out!
int free = w - (visible.size() - 1) * _bevel;
if (free < 0) free = 0;
- unsigned int each;
+ int each;
std::list<Widget*> adjustable = visible;
each = free / adjustable.size();
for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
std::list<Widget*>::iterator next = it; ++next;
- unsigned int m = (*it)->maxSize().width() - (*it)->minSize().width();
+ int m = (*it)->maxSize().width() - (*it)->minSize().width();
if (m > 0 && m < each) {
free -= m;
if (free < 0) free = 0;
else
each = 0;
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
- unsigned int w;
+ int w;
// is the widget adjustable?
std::list<Widget*>::const_iterator
found = std::find(adjustable.begin(), adjustable.end(), *it);
}
// align it vertically
int yy = y;
- unsigned int hh = std::max(std::min(h, (*it)->_max_size.height()),
- (*it)->_min_size.height());
+ int hh = std::max(std::min(h, (*it)->_max_size.height()),
+ (*it)->_min_size.height());
if (hh < h) {
switch(_alignment) {
case RenderStyle::RightBottomJustify:
if (visible.empty()) return;
- if ((unsigned)(_borderwidth * 2 + _bevel * 2) > _area.width() ||
- (unsigned)(_borderwidth * 2 + _bevel * 2) > _area.height())
- return; // not worth laying anything out!
-
- int x, y; unsigned int w, h; // working area
+ int x, y, w, h; // working area
x = y = _bevel;
w = _area.width() - _borderwidth * 2 - _bevel * 2;
h = _area.height() - _borderwidth * 2 - _bevel * 2;
+ if (w < 0 || h < 0) return; // not worth laying anything out!
int free = h - (visible.size() - 1) * _bevel;
if (free < 0) free = 0;
- unsigned int each;
+ int each;
std::list<Widget*> adjustable = visible;
each = free / adjustable.size();
for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
std::list<Widget*>::iterator next = it; ++next;
- unsigned int m = (*it)->maxSize().height() - (*it)->minSize().height();
+ int m = (*it)->maxSize().height() - (*it)->minSize().height();
if (m > 0 && m < each) {
free -= m;
if (free < 0) free = 0;
else
each = 0;
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
- unsigned int h;
+ int h;
// is the widget adjustable?
std::list<Widget*>::const_iterator
found = std::find(adjustable.begin(), adjustable.end(), *it);
}
// align it horizontally
int xx = x;
- unsigned int ww = std::max(std::min(w, (*it)->_max_size.width()),
- (*it)->_min_size.width());
+ int ww = std::max(std::min(w, (*it)->_max_size.width()),
+ (*it)->_min_size.width());
if (ww < w) {
switch(_alignment) {
case RenderStyle::RightBottomJustify:
void Widget::render()
{
if (!_texture || !_dirty) return;
- if ((unsigned)_borderwidth * 2 > _area.width() ||
- (unsigned)_borderwidth * 2 > _area.height())
+ if (_borderwidth * 2 > _area.width() ||
+ _borderwidth * 2 > _area.height())
return; // no surface to draw on
Surface *s = new Surface(_screen, Size(_area.width() - _borderwidth * 2,
ev.xconfigure.height = e.height;
while (XCheckTypedWindowEvent(**display, window(), ConfigureNotify, &ev));
- if (!((unsigned)ev.xconfigure.width == area().width() &&
- (unsigned)ev.xconfigure.height == area().height())) {
+ if (!(ev.xconfigure.width == area().width() &&
+ ev.xconfigure.height == area().height())) {
_area = Rect(_area.position(), Size(e.width, e.height));
update();
}
RenderTexture *_texture;
private:
- void internal_moveresize(int x, int y, unsigned w, unsigned int h);
+ void internal_moveresize(int x, int y, int w, int h);
int _screen;
Widget *_parent;
w = _cw + dx
h = _ch + dy
- if w < 0: w = 0
- if h < 0: h = 0
if RESIZE_RUBBERBAND:
# draw the outline ...
_size_inc = otk::Size(1, 1);
_base_size = otk::Size(0, 0);
_min_size = otk::Size(0, 0);
- _max_size = otk::Size(UINT_MAX, UINT_MAX);
+ _max_size = otk::Size(INT_MAX, INT_MAX);
// get the hints from the window
if (XGetWMNormalHints(**otk::display, _window, &size, &ret)) {
while (c->_transient_for) // go up the tree
c = c->_transient_for;
replacement = c->findModalChild(this); // find a modal child, skipping this
+ assert(replacement != this);
c = this;
while (c->_transient_for) {
#endif
-void Client::resize(Corner anchor, unsigned int w, unsigned int h)
+void Client::resize(Corner anchor, int w, int h)
{
if (!(_functions & Func_Resize)) return;
internal_resize(anchor, w, h);
}
-void Client::internal_resize(Corner anchor, unsigned int w, unsigned int h,
+void Client::internal_resize(Corner anchor, int w, int h,
bool user, int x, int y)
{
- if (_base_size.width() < w)
- w -= _base_size.width();
- else
- w = 0;
- if (_base_size.height() < h)
- h -= _base_size.height();
- else
- h = 0;
+ w -= _base_size.width();
+ h -= _base_size.height();
if (user) {
// for interactive resizing. have to move half an increment in each
// direction.
- unsigned int mw = w % _size_inc.width(); // how far we are towards the next
- // size inc
- unsigned int mh = h % _size_inc.height();
- unsigned int aw = _size_inc.width() / 2; // amount to add
- unsigned int ah = _size_inc.height() / 2;
+ int mw = w % _size_inc.width(); // how far we are towards the next size inc
+ int mh = h % _size_inc.height();
+ int aw = _size_inc.width() / 2; // amount to add
+ int ah = _size_inc.height() / 2;
// don't let us move into a new size increment
if (mw + aw >= _size_inc.width()) aw = _size_inc.width() - mw - 1;
if (mh + ah >= _size_inc.height()) ah = _size_inc.height() - mh - 1;
The x and y coordinates must both be sepcified together, or they will have
no effect. When they are specified, the anchor is ignored.
*/
- void internal_resize(Corner anchor, unsigned int w, unsigned int h,
+ void internal_resize(Corner anchor, int w, int h,
bool user = true, int x = INT_MIN, int y = INT_MIN);
//! Attempts to find and return a modal child of this window, recursively.
@param w The width component of the new size for the client.
@param h The height component of the new size for the client.
*/
- void resize(Corner anchor, unsigned int w, unsigned int h);
+ void resize(Corner anchor, int w, int h);
//! Reapplies the maximized state to the window
/*!
_numbuttons = 0;
_buttons = new Window[0];
_buttons_sur = new otk::Surface*[0];
- _titleorder = new unsigned int[1];
- _titleorder[0] = (unsigned)-1;
+ _titleorder = new int[1];
+ _titleorder[0] = -1;
// register all of the windows with the event dispatcher
Window *w = allWindows();
openbox->clearHandler(w[i]);
delete [] w;
- for (unsigned int i = 0; i < _numbuttons; ++i) {
+ for (int i = 0; i < _numbuttons; ++i) {
XDestroyWindow(**otk::display, _buttons[i]);
delete _buttons_sur[i];
}
w[i++] = _handle;
w[i++] = _lgrip;
w[i++] = _rgrip;
- for (unsigned int j = 0; j < _numbuttons; ++j)
+ for (int j = 0; j < _numbuttons; ++j)
w[j + i++] = _buttons[j];
w[i] = 0;
return w;
XResizeWindow(**otk::display, _lgrip, geom.grip_width(), geom.handle_height);
XResizeWindow(**otk::display, _rgrip, geom.grip_width(), geom.handle_height);
- for (unsigned int i = 0; i < _numbuttons; ++i)
+ for (int i = 0; i < _numbuttons; ++i)
XResizeWindow(**otk::display, _buttons[i],
geom.button_size, geom.button_size);
}
otk::ustring t = _client->title(); // the actual text to draw
int x = geom.bevel; // x coord for the text
- if ((unsigned)x * 2 > geom.label_width) return; // no room at all
+ if (x * 2 > geom.label_width) return; // no room at all
// find a string that will fit inside the area for text
otk::ustring::size_type text_len = t.size();
- unsigned int length;
- unsigned int maxsize = geom.label_width - geom.bevel * 2;
+ int length;
+ int maxsize = geom.label_width - geom.bevel * 2;
do {
t.resize(text_len);
- length = font->measureString(t);
+ length = font->measureString(t); // this returns an unsigned, so check < 0
+ if (length < 0) length = maxsize; // if the string's that long just adjust
} while (length > maxsize && text_len-- > 0);
if (text_len <= 0) return; // won't fit anything
//! Varius geometry settings in the frame decorations
struct FrameGeometry {
- unsigned int width; // title and handle
- unsigned int font_height;
- unsigned int title_height() { return font_height + bevel*2; }
- unsigned int label_width;
- unsigned int label_height() { return font_height; }
- unsigned int handle_height; // static, from the style
+ int width; // title and handle
+ int font_height;
+ int title_height() { return font_height + bevel*2; }
+ int label_width;
+ int label_height() { return font_height; }
+ int handle_height; // static, from the style
int handle_y;
- unsigned int button_size; // static, from the style
- unsigned grip_width() { return button_size * 2; }
- unsigned bevel; // static, from the style
- unsigned bwidth; // frame elements' border width
- unsigned cbwidth; // client border width
+ int button_size; // static, from the style
+ int grip_width() { return button_size * 2; }
+ int bevel; // static, from the style
+ int bwidth; // frame elements' border width
+ int cbwidth; // client border width
};
//! Holds and decorates a frame around an Client (client window)
Window _lgrip; // lefthand resize grab on the handle
Window _rgrip; // righthand resize grab on the handle
Window *_buttons; // all of the titlebar buttons
- unsigned int _numbuttons; // number of buttons, size of _buttons array
- unsigned int *_titleorder; // order of the buttons and the label (always
- // holds '_numbuttons + 1' elements (for the
- // label, which is coded as '-1')
+ int _numbuttons; // number of buttons, size of _buttons array
+ int *_titleorder; // order of the buttons and the label (always
+ // holds '_numbuttons + 1' elements (for the
+ // label, which is coded as '-1')
// surfaces for each
otk::Surface *_frame_sur;