From bb6ac36d410ba62bc8bb481dd6461a30aace42fd Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 30 Jan 2003 21:11:04 +0000 Subject: [PATCH] working popups for moving/resizing --- otk/focuslabel.cc | 29 ++++++++++++++++++++++++++++- otk/focuslabel.hh | 5 +++++ otk/label.cc | 29 ++++++++++++++++++++++++++++- otk/label.hh | 5 +++++ scripts/focus.py | 4 ++-- src/client.hh | 9 +++++++++ 6 files changed, 77 insertions(+), 4 deletions(-) diff --git a/otk/focuslabel.cc b/otk/focuslabel.cc index 6d034794..6d7d5c31 100644 --- a/otk/focuslabel.cc +++ b/otk/focuslabel.cc @@ -29,10 +29,37 @@ void FocusLabel::setStyle(RenderStyle *style) setUnfocusTexture(style->labelUnfocusBackground()); } +void FocusLabel::fitString(const std::string &str) +{ + const Font *ft = style()->labelFont(); + fitSize(ft->measureString(str), ft->height()); +} + +void FocusLabel::fitSize(int w, int h) +{ + unsigned int sidemargin = style()->bevelWidth() * 2; + resize(w + sidemargin * 2, h); +} + +void FocusLabel::update() +{ + if (_dirty) { + int w = _rect.width(), h = _rect.height(); + const Font *ft = style()->labelFont(); + unsigned int sidemargin = style()->bevelWidth() * 2; + if (!_fixed_width) + w = ft->measureString(_text) + sidemargin * 2; + if (!_fixed_height) + h = ft->height(); + internalResize(w, h); + } + FocusWidget::update(); +} + void FocusLabel::renderForeground() { - otk::Widget::renderForeground(); + FocusWidget::renderForeground(); const Font *ft = style()->labelFont(); RenderColor *text_color = (isFocused() ? style()->textFocusColor() diff --git a/otk/focuslabel.hh b/otk/focuslabel.hh index 8db444d3..c25ab29c 100644 --- a/otk/focuslabel.hh +++ b/otk/focuslabel.hh @@ -18,6 +18,11 @@ public: virtual void renderForeground(); + virtual void update(); + + void fitString(const std::string &str); + void fitSize(int w, int h); + virtual void setStyle(RenderStyle *style); private: diff --git a/otk/label.cc b/otk/label.cc index bb8083ab..fa5fefff 100644 --- a/otk/label.cc +++ b/otk/label.cc @@ -25,10 +25,37 @@ void Label::setStyle(RenderStyle *style) setTexture(style->labelUnfocusBackground()); } +void Label::fitString(const std::string &str) +{ + const Font *ft = style()->labelFont(); + fitSize(ft->measureString(str), ft->height()); +} + +void Label::fitSize(int w, int h) +{ + unsigned int sidemargin = style()->bevelWidth() * 2; + resize(w + sidemargin * 2, h); +} + +void Label::update() +{ + if (_dirty) { + int w = _rect.width(), h = _rect.height(); + const Font *ft = style()->labelFont(); + unsigned int sidemargin = style()->bevelWidth() * 2; + if (!_fixed_width) + w = ft->measureString(_text) + sidemargin * 2; + if (!_fixed_height) + h = ft->height(); + internalResize(w, h); + } + Widget::update(); +} + void Label::renderForeground(void) { - otk::Widget::renderForeground(); + Widget::renderForeground(); const Font *ft = style()->labelFont(); unsigned int sidemargin = style()->bevelWidth() * 2; diff --git a/otk/label.hh b/otk/label.hh index e24858f1..9c32e544 100644 --- a/otk/label.hh +++ b/otk/label.hh @@ -18,6 +18,11 @@ public: virtual void renderForeground(void); + virtual void update(); + + void fitString(const std::string &str); + void fitSize(int w, int h); + virtual void setStyle(RenderStyle *style); private: diff --git a/scripts/focus.py b/scripts/focus.py index 5ae40cf2..adba3725 100644 --- a/scripts/focus.py +++ b/scripts/focus.py @@ -203,12 +203,12 @@ def _create_popup_list(data): t = t[:24] + "..." + t[-24:] titles.append(t) _list_windows.append(c) - l = font.measureString(t) + 10 # add margin + l = font.measureString(t) if l > longest: longest = l if len(titles) > 1: for t in titles: w = otk.FocusLabel(_list_widget) - w.resize(longest, height) + w.fitSize(longest, height) w.setText(t) w.unfocus() _list_labels.append(w) diff --git a/src/client.hh b/src/client.hh index 2a55d992..e70dc268 100644 --- a/src/client.hh +++ b/src/client.hh @@ -569,6 +569,15 @@ BB @param window The window id that the Client class should handle //! Returns the window's stacking layer inline StackLayer layer() const { return _layer; } + //! Returns the logical size of the window + /*! + The "logical" size of the window is refers to the user's perception of the + size of the window, and is the value that should be displayed to the user. + For example, with xterms, this value it the number of characters being + displayed in the terminal, instead of the number of pixels. + */ + const otk::Point &logicalSize() const { return _logical_size; } + //! Applies the states requested when the window mapped /*! This should be called only once, during the window mapping process. It -- 2.39.2