libgeetk r9 - in trunk/geetk: gridview ribbon samples
- From: fzipp svn gnome org
- To: svn-commits-list gnome org
- Subject: libgeetk r9 - in trunk/geetk: gridview ribbon samples
- Date: Thu, 24 Jul 2008 15:19:52 +0000 (UTC)
Author: fzipp
Date: Thu Jul 24 15:19:51 2008
New Revision: 9
URL: http://svn.gnome.org/viewvc/libgeetk?rev=9&view=rev
Log:
Namespace change.
Modified:
trunk/geetk/gridview/gridview.vala
trunk/geetk/ribbon/application-button.vala
trunk/geetk/ribbon/application-menu-item.vala
trunk/geetk/ribbon/application-menu.vala
trunk/geetk/ribbon/base-button.vala
trunk/geetk/ribbon/button.vala
trunk/geetk/ribbon/color-scheme.vala
trunk/geetk/ribbon/extra-event-box.vala
trunk/geetk/ribbon/gallery-popup-window.vala
trunk/geetk/ribbon/gallery.vala
trunk/geetk/ribbon/group-style.vala
trunk/geetk/ribbon/quick-access-toolbar.vala
trunk/geetk/ribbon/ribbon-group.vala
trunk/geetk/ribbon/ribbon.vala
trunk/geetk/ribbon/sample-tile.vala
trunk/geetk/ribbon/synthetic-window.vala
trunk/geetk/ribbon/theme.vala
trunk/geetk/ribbon/tile.vala
trunk/geetk/ribbon/toggle-button.vala
trunk/geetk/ribbon/tool-box.vala
trunk/geetk/ribbon/tool-pack.vala
trunk/geetk/samples/ribbondemo.vala
Modified: trunk/geetk/gridview/gridview.vala
==============================================================================
--- trunk/geetk/gridview/gridview.vala (original)
+++ trunk/geetk/gridview/gridview.vala Thu Jul 24 15:19:51 2008
@@ -914,7 +914,7 @@
// XXX
}
- private void on_style_set (GridView s, Style style) {
+ private void on_style_set (GridView s) {
rebuild_dimensions ();
}
Modified: trunk/geetk/ribbon/application-button.vala
==============================================================================
--- trunk/geetk/ribbon/application-button.vala (original)
+++ trunk/geetk/ribbon/application-button.vala Thu Jul 24 15:19:51 2008
@@ -2,134 +2,136 @@
using Cairo;
using Gtk;
-public class ApplicationButton : BaseButton {
+namespace Geetk {
- private const double LINE_WIDTH = 1.0;
+ public class ApplicationButton : BaseButton {
- /** Fired when the button is clicked. */
- public signal void clicked ();
+ private const double LINE_WIDTH = 1.0;
- private ApplicationMenu _app_menu;
- public ApplicationMenu menu {
- get { return _app_menu; }
- }
+ /** Fired when the button is clicked. */
+ public signal void clicked ();
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+ private ApplicationMenu _app_menu;
+ public ApplicationMenu menu {
+ get { return _app_menu; }
+ }
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
- _app_menu = new ApplicationMenu (this);
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
- this.height_request = 36;
- this.width_request = 36;
+ _app_menu = new ApplicationMenu (this);
- _enabled = true;
- }
+ this.height_request = 36;
+ this.width_request = 36;
- // XXX: workaround
- private bool has_click_listener () {
- var signal_id = Signal.lookup ("clicked", typeof (ApplicationButton));
- return Signal.has_handler_pending (this, signal_id, 0, true);
- }
+ _enabled = true;
+ }
- /** Fires the click event. */
- public void click () {
- if (_enabled && has_click_listener ()) {
- clicked ();
+ // XXX: workaround
+ private bool has_click_listener () {
+ var signal_id = Signal.lookup ("clicked", typeof (ApplicationButton));
+ return Signal.has_handler_pending (this, signal_id, 0, true);
}
- _app_menu.realize += () => {
- int x, y;
- get_parent_window ().get_origin (out x, out y);
- x += this.allocation.x;
- y += Gdk.Rect.bottom ((Gdk.Rectangle) this.allocation);
- _app_menu.window.move (x, y);
- };
+ /** Fires the click event. */
+ public void click () {
+ if (_enabled && has_click_listener ()) {
+ clicked ();
+ }
+
+ _app_menu.realize += () => {
+ int x, y;
+ get_parent_window ().get_origin (out x, out y);
+ x += this.allocation.x;
+ y += Gdk.Rect.bottom ((Gdk.Rectangle) this.allocation);
+ _app_menu.window.move (x, y);
+ };
- _app_menu.show ();
- }
+ _app_menu.show ();
+ }
- protected override bool bound_widget_button_press_event (Widget sender,
- Gdk.EventButton evnt) {
- event ((Gdk.Event) evnt);
- return false;
- }
+ protected override bool bound_widget_button_press_event (Widget sender,
+ Gdk.EventButton evnt) {
+ event ((Gdk.Event) evnt);
+ return false;
+ }
- protected override bool bound_widget_button_release_event (Widget sender,
- Gdk.EventButton evnt) {
- event ((Gdk.Event) evnt);
- click ();
- return false;
- }
+ protected override bool bound_widget_button_release_event (Widget sender,
+ Gdk.EventButton evnt) {
+ event ((Gdk.Event) evnt);
+ click ();
+ return false;
+ }
- protected override bool expose_event (Gdk.EventExpose event) {
- var cr = Gdk.cairo_create (this.window);
+ protected override bool expose_event (Gdk.EventExpose event) {
+ var cr = Gdk.cairo_create (this.window);
- cr.rectangle (event.area.x, event.area.y,
- event.area.width, event.area.height);
- cr.clip ();
- draw (cr);
-
-// cr.target.dispose ();
-// cr.dispose ();
-
-// return base.expose_event (event); // FIXME: causes endless loop
- // *** workaround ***
- if (this.child != null) {
- this.child.expose_event (event);
+ cr.rectangle (event.area.x, event.area.y,
+ event.area.width, event.area.height);
+ cr.clip ();
+ draw (cr);
+
+ // cr.target.dispose ();
+ // cr.dispose ();
+
+ // return base.expose_event (event); // FIXME: causes endless loop
+ // *** workaround ***
+ if (this.child != null) {
+ this.child.expose_event (event);
+ }
+ return false;
+ // *** workaround ***
}
- return false;
- // *** workaround ***
- }
- protected void draw (Context cr) {
- _theme.draw_application_button (cr, (Gdk.Rectangle) this.allocation,
- _state, LINE_WIDTH, this);
- }
+ protected void draw (Context cr) {
+ _theme.draw_application_button (cr, (Gdk.Rectangle) this.allocation,
+ _state, LINE_WIDTH, this);
+ }
- protected override bool button_press_event (Gdk.EventButton event) {
-// bool ret = base.button_press_event (event);
- bool ret = false;
- _state = Theme.ButtonState.PRESSED;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool button_press_event (Gdk.EventButton event) {
+ // bool ret = base.button_press_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.PRESSED;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ click ();
+ return ret;
}
- queue_draw ();
- click ();
- return ret;
- }
- protected override bool button_release_event (Gdk.EventButton event) {
-// bool ret = base.button_release_event (event);
- bool ret = false;
- _state = Theme.ButtonState.HOVER;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool button_release_event (Gdk.EventButton event) {
+ // bool ret = base.button_release_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.HOVER;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
- protected override bool enter_notify_event (Gdk.EventCrossing event) {
-// bool ret = base.enter_notify_event (event);
- bool ret = false;
- _state = Theme.ButtonState.HOVER;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool enter_notify_event (Gdk.EventCrossing event) {
+ // bool ret = base.enter_notify_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.HOVER;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
- protected override bool leave_notify_event (Gdk.EventCrossing event) {
-// bool ret = base.leave_notify_event (event);
- bool ret = false;
- _state = Theme.ButtonState.DEFAULT;
- queue_draw ();
- return ret;
+ protected override bool leave_notify_event (Gdk.EventCrossing event) {
+ // bool ret = base.leave_notify_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.DEFAULT;
+ queue_draw ();
+ return ret;
+ }
}
}
-
Modified: trunk/geetk/ribbon/application-menu-item.vala
==============================================================================
--- trunk/geetk/ribbon/application-menu-item.vala (original)
+++ trunk/geetk/ribbon/application-menu-item.vala Thu Jul 24 15:19:51 2008
@@ -1,5 +1,7 @@
using Gtk;
-public class ApplicationMenuItem : Bin {
-}
+namespace Geetk {
+ public class ApplicationMenuItem : Bin {
+ }
+}
Modified: trunk/geetk/ribbon/application-menu.vala
==============================================================================
--- trunk/geetk/ribbon/application-menu.vala (original)
+++ trunk/geetk/ribbon/application-menu.vala Thu Jul 24 15:19:51 2008
@@ -1,439 +1,441 @@
using Gtk;
using Cairo;
-public class ApplicationMenu : Container {
+namespace Geetk {
- private const double LINE_WIDTH = 1.0;
- private const int TOP_PADDING = 24;
- private const int BORDER_WIDTH = 6;
- private const int SPACE = 2;
- private const int VERTICAL_WINDOW_OFFSET = 24 - 2;
-// private const int VERTICAL_WINDOW_OFFSET = TOP_PADDING - SPACE; // XXX
-
- protected Theme _theme = new Theme ();
-
- private Gee.List<ApplicationMenuItem> _items;
- private Widget _default_menu;
- private int _item_height;
- private Gdk.Size _menu_size;
-
- private Widget _active_menu;
-
- private Gdk.Rectangle _items_alloc;
- private int _menu_items_col_width;
- private int _buttons_height;
- private int _exit_button_width;
- private int _options_button_width;
- private int _visible_menu_items;
- private bool _active_menu_visible;
- private bool _options_button_visible;
- private bool _exit_button_visible;
-
- private Window _win;
-
- public ApplicationButton application_button { get; construct; }
-
- private Button _options_button;
- public Button options_button {
- get { return _options_button; }
- set {
- if (_options_button == value) {
- return;
- }
- if (_options_button != null) {
- _options_button.unparent ();
- }
- _options_button = value;
- if (value != null) {
- value.draw_background = true;
- value.opaque_background = true;
- value.set_parent (this);
- value.visible = true;
+ public class ApplicationMenu : Container {
+
+ private const double LINE_WIDTH = 1.0;
+ private const int TOP_PADDING = 24;
+ private const int BORDER_WIDTH = 6;
+ private const int SPACE = 2;
+ private const int VERTICAL_WINDOW_OFFSET = 24 - 2;
+ // private const int VERTICAL_WINDOW_OFFSET = TOP_PADDING - SPACE; // XXX
+
+ protected Theme _theme = new Theme ();
+
+ private Gee.List<ApplicationMenuItem> _items;
+ private Widget _default_menu;
+ private int _item_height;
+ private Gdk.Size _menu_size;
+
+ private Widget _active_menu;
+
+ private Gdk.Rectangle _items_alloc;
+ private int _menu_items_col_width;
+ private int _buttons_height;
+ private int _exit_button_width;
+ private int _options_button_width;
+ private int _visible_menu_items;
+ private bool _active_menu_visible;
+ private bool _options_button_visible;
+ private bool _exit_button_visible;
+
+ private Window _win;
+
+ public ApplicationButton application_button { get; construct; }
+
+ private Button _options_button;
+ public Button options_button {
+ get { return _options_button; }
+ set {
+ if (_options_button == value) {
+ return;
+ }
+ if (_options_button != null) {
+ _options_button.unparent ();
+ }
+ _options_button = value;
+ if (value != null) {
+ value.draw_background = true;
+ value.opaque_background = true;
+ value.set_parent (this);
+ value.visible = true;
+ }
}
}
- }
- private Button _exit_button;
- public Button exit_button {
- get { return _exit_button; }
- set {
- if (_exit_button == value) {
- return;
- }
- if (_exit_button != null) {
- _exit_button.unparent ();
- }
- _exit_button = value;
- if (value != null) {
- value.draw_background = true;
- value.opaque_background = true;
- value.set_parent (this);
- value.visible = true;
+ private Button _exit_button;
+ public Button exit_button {
+ get { return _exit_button; }
+ set {
+ if (_exit_button == value) {
+ return;
+ }
+ if (_exit_button != null) {
+ _exit_button.unparent ();
+ }
+ _exit_button = value;
+ if (value != null) {
+ value.draw_background = true;
+ value.opaque_background = true;
+ value.set_parent (this);
+ value.visible = true;
+ }
}
}
- }
- public int item_height {
- get { return _item_height; }
- set {
- if (_item_height == value) {
- return;
+ public int item_height {
+ get { return _item_height; }
+ set {
+ if (_item_height == value) {
+ return;
+ }
+ _item_height = value;
+ queue_resize ();
}
- _item_height = value;
- queue_resize ();
}
- }
- public Gdk.Size menu_size {
- get { return _menu_size; }
- set {
-// if (_menu_size == value) { // XXX
-// return;
-// }
- _menu_size = value;
- queue_resize ();
+ public Gdk.Size menu_size {
+ get { return _menu_size; }
+ set {
+ // if (_menu_size == value) { // XXX
+ // return;
+ // }
+ _menu_size = value;
+ queue_resize ();
+ }
}
- }
- public Widget default_menu {
- get { return _default_menu; }
- set {
- if (_default_menu == value) {
- return;
- }
- bool update_active = _default_menu == _active_menu;
- if (update_active && _default_menu != null) {
- _default_menu.unparent ();
- }
- _default_menu = value;
- if (update_active) {
- set_active_menu (value);
+ public Widget default_menu {
+ get { return _default_menu; }
+ set {
+ if (_default_menu == value) {
+ return;
+ }
+ bool update_active = _default_menu == _active_menu;
+ if (update_active && _default_menu != null) {
+ _default_menu.unparent ();
+ }
+ _default_menu = value;
+ if (update_active) {
+ set_active_menu (value);
+ }
}
}
- }
-
- /** Returns the number of children. */
- public int n_children {
- get { return _items.size; }
- }
- /** Constructor. */
- public ApplicationMenu (ApplicationButton button) {
- this.application_button = button;
- }
+ /** Returns the number of children. */
+ public int n_children {
+ get { return _items.size; }
+ }
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+ /** Constructor. */
+ public ApplicationMenu (ApplicationButton button) {
+ this.application_button = button;
+ }
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-// this.children = new Gee.ArrayList<Widget> ();
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
-// append (new Button ("OK"));
+ // this.children = new Gee.ArrayList<Widget> ();
- _items = new Gee.ArrayList<ApplicationMenuItem> ();
- _item_height = 32;
- _menu_size = Gdk.Size (240, 320);
- }
+ // append (new Button ("OK"));
- public void prepend (ApplicationMenuItem item) {
- insert (item, 0);
- }
-
- public void append (ApplicationMenuItem item) {
- insert (item, -1);
- }
+ _items = new Gee.ArrayList<ApplicationMenuItem> ();
+ _item_height = 32;
+ _menu_size = Gdk.Size (240, 320);
+ }
- public void insert (ApplicationMenuItem item, int index) {
- item.set_parent (this);
- item.visible = true;
-
- if (index == -1) {
- _items.add (item);
- } else {
- _items.insert (index, item);
+ public void prepend (ApplicationMenuItem item) {
+ insert (item, 0);
}
- }
- public void remove (int index) {
- if (index == -1) {
- index = _items.size - 1;
+ public void append (ApplicationMenuItem item) {
+ insert (item, -1);
}
- _items.get (index).unparent ();
- _items.remove_at (index);
- }
+ public void insert (ApplicationMenuItem item, int index) {
+ item.set_parent (this);
+ item.visible = true;
- public void activate_menu (Widget widget) {
- if (widget == null) {
- set_active_menu (_default_menu);
- } else {
- set_active_menu (widget);
+ if (index == -1) {
+ _items.add (item);
+ } else {
+ _items.insert (index, item);
+ }
}
- }
- private void set_active_menu (Widget widget) {
- if (_active_menu != null) {
- _active_menu.unparent ();
- }
- _active_menu = widget;
- widget.set_parent (this);
- widget.visible = true;
- queue_resize ();
- }
+ public void remove (int index) {
+ if (index == -1) {
+ index = _items.size - 1;
+ }
- public void show_at (int x, int y) {
-// if (_win != null) {
-// kill_menu (true);
-// }
-
-// foreach (var item in _items) {
-// item.set_parent (this);
-// }
-
- if (_win == null) {
- _win = new SyntheticWindow (WindowType.POPUP);
- _win.add (this);
-
- _win.hide += () => {
- kill_menu (true);
- };
-
- _win.show_all ();
- _win.window.move (x, y - VERTICAL_WINDOW_OFFSET);
-
- _win.button_press_event += () => {
- kill_menu (true);
- };
-
- _win.add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
- } else {
- _win.show_all ();
- _win.window.move (x, y - VERTICAL_WINDOW_OFFSET);
- }
-
- Gtk.grab_add (_win);
- Gdk.GrabStatus grabbed = Gdk.pointer_grab (_win.window, true,
- Gdk.EventMask.BUTTON_PRESS_MASK, null, null, 0);
- if (grabbed != Gdk.GrabStatus.SUCCESS) {
- kill_menu (false);
- return;
- }
-
- grabbed = Gdk.keyboard_grab (_win.window, true, 0);
- if (grabbed != Gdk.GrabStatus.SUCCESS) {
- kill_menu (false);
- return;
+ _items.get (index).unparent ();
+ _items.remove_at (index);
}
- }
- private void kill_menu (bool ungrab) {
- if (_win == null) {
- return;
+ public void activate_menu (Widget widget) {
+ if (widget == null) {
+ set_active_menu (_default_menu);
+ } else {
+ set_active_menu (widget);
+ }
}
-// Window win = _win;
-// _win = null;
+ private void set_active_menu (Widget widget) {
+ if (_active_menu != null) {
+ _active_menu.unparent ();
+ }
+ _active_menu = widget;
+ widget.set_parent (this);
+ widget.visible = true;
+ queue_resize ();
+ }
-// win.child = null;
+ public void show_at (int x, int y) {
+ // if (_win != null) {
+ // kill_menu (true);
+ // }
+
+ // foreach (var item in _items) {
+ // item.set_parent (this);
+ // }
+
+ if (_win == null) {
+ _win = new SyntheticWindow (WindowType.POPUP);
+ _win.add (this);
+
+ _win.hide += () => {
+ kill_menu (true);
+ };
+
+ _win.show_all ();
+ _win.window.move (x, y - VERTICAL_WINDOW_OFFSET);
+
+ _win.button_press_event += () => {
+ kill_menu (true);
+ };
+
+ _win.add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+ } else {
+ _win.show_all ();
+ _win.window.move (x, y - VERTICAL_WINDOW_OFFSET);
+ }
+
+ Gtk.grab_add (_win);
+ Gdk.GrabStatus grabbed = Gdk.pointer_grab (_win.window, true,
+ Gdk.EventMask.BUTTON_PRESS_MASK, null, null, 0);
+ if (grabbed != Gdk.GrabStatus.SUCCESS) {
+ kill_menu (false);
+ return;
+ }
- Gtk.grab_remove (_win);
- if (ungrab) {
- Gdk.pointer_ungrab (0);
- Gdk.keyboard_ungrab (0);
+ grabbed = Gdk.keyboard_grab (_win.window, true, 0);
+ if (grabbed != Gdk.GrabStatus.SUCCESS) {
+ kill_menu (false);
+ return;
+ }
}
- _win.hide ();
-// _win.destroy ();
- }
- protected override void forall (bool include_internals, Gtk.Callback callback) {
- foreach (var widget in _items) {
- if (widget.visible) callback (widget);
- }
+ private void kill_menu (bool ungrab) {
+ if (_win == null) {
+ return;
+ }
- if (_options_button != null && _options_button.visible) {
- callback (_options_button);
- }
+ // Window win = _win;
+ // _win = null;
- if (_exit_button != null && _exit_button.visible) {
- callback (_exit_button);
- }
+ // win.child = null;
- if (_active_menu != null && _active_menu.visible) {
- callback (_active_menu);
+ Gtk.grab_remove (_win);
+ if (ungrab) {
+ Gdk.pointer_ungrab (0);
+ Gdk.keyboard_ungrab (0);
+ }
+ _win.hide ();
+ // _win.destroy ();
}
- }
- protected override void size_request (Requisition requisition) {
-// base.size_requested (requisition);
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ foreach (var widget in _items) {
+ if (widget.visible) callback (widget);
+ }
- _menu_items_col_width = 0;
- int menu_items_col_height = 0;
+ if (_options_button != null && _options_button.visible) {
+ callback (_options_button);
+ }
- foreach (var mi in _items) {
- if (mi.visible) {
- mi.height_request = _item_height;
- Gtk.Requisition req;
- mi.size_request (req);
- if (req.width > _menu_items_col_width) {
- _menu_items_col_width = req.width;
- }
- menu_items_col_height += _item_height;
+ if (_exit_button != null && _exit_button.visible) {
+ callback (_exit_button);
+ }
+
+ if (_active_menu != null && _active_menu.visible) {
+ callback (_active_menu);
}
}
- requisition.height = menu_items_col_height;
- requisition.width = _menu_items_col_width;
+ protected override void size_request (Requisition requisition) {
+ // base.size_requested (requisition);
- if (_active_menu != null) {
-// Gtk.Requisition req = _active_menu.size_request ();
-// requisition.width += req.width;
-// if (req.height > requisition.height) {
-// requisition.height = req.height;
-// }
+ _menu_items_col_width = 0;
+ int menu_items_col_height = 0;
- requisition.width += _menu_size.width;
- if (_menu_size.height > requisition.height) {
- requisition.height = _menu_size.height;
+ foreach (var mi in _items) {
+ if (mi.visible) {
+ mi.height_request = _item_height;
+ Gtk.Requisition req;
+ mi.size_request (req);
+ if (req.width > _menu_items_col_width) {
+ _menu_items_col_width = req.width;
+ }
+ menu_items_col_height += _item_height;
+ }
}
- }
- int buttons_width = 0;
- _buttons_height = 0;
+ requisition.height = menu_items_col_height;
+ requisition.width = _menu_items_col_width;
- if (_options_button != null) {
- Gtk.Requisition req;
- _options_button.size_request (req);
- buttons_width = req.width;
- _buttons_height = req.height;
- _options_button_width = req.width;
- }
+ if (_active_menu != null) {
+ // Gtk.Requisition req = _active_menu.size_request ();
+ // requisition.width += req.width;
+ // if (req.height > requisition.height) {
+ // requisition.height = req.height;
+ // }
+
+ requisition.width += _menu_size.width;
+ if (_menu_size.height > requisition.height) {
+ requisition.height = _menu_size.height;
+ }
+ }
+
+ int buttons_width = 0;
+ _buttons_height = 0;
- if (_exit_button != null) {
- Gtk.Requisition req;
- _exit_button.size_request (req);
- buttons_width += req.width;
if (_options_button != null) {
- buttons_width += SPACE;
- }
- if (req.height > _buttons_height) {
+ Gtk.Requisition req;
+ _options_button.size_request (req);
+ buttons_width = req.width;
_buttons_height = req.height;
+ _options_button_width = req.width;
}
- _exit_button_width = req.width;
- }
- if (buttons_width > requisition.width) {
- requisition.width = buttons_width;
- }
+ if (_exit_button != null) {
+ Gtk.Requisition req;
+ _exit_button.size_request (req);
+ buttons_width += req.width;
+ if (_options_button != null) {
+ buttons_width += SPACE;
+ }
+ if (req.height > _buttons_height) {
+ _buttons_height = req.height;
+ }
+ _exit_button_width = req.width;
+ }
- if (_buttons_height > 0) {
- requisition.height += _buttons_height + SPACE;
- }
- requisition.width += BORDER_WIDTH << 1;
- requisition.height += BORDER_WIDTH + TOP_PADDING;
+ if (buttons_width > requisition.width) {
+ requisition.width = buttons_width;
+ }
- this._menu_items_col_width = _menu_items_col_width; // XXX
- }
+ if (_buttons_height > 0) {
+ requisition.height += _buttons_height + SPACE;
+ }
+ requisition.width += BORDER_WIDTH << 1;
+ requisition.height += BORDER_WIDTH + TOP_PADDING;
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocated (allocation);
- this.allocation = (Allocation) allocation; // XXX workaround
+ this._menu_items_col_width = _menu_items_col_width; // XXX
+ }
- _visible_menu_items = 0;
- _exit_button_visible = _options_button_visible = false;
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocated (allocation);
+ this.allocation = (Allocation) allocation; // XXX workaround
- allocation.height -= BORDER_WIDTH;
+ _visible_menu_items = 0;
+ _exit_button_visible = _options_button_visible = false;
- if (_buttons_height + TOP_PADDING <= allocation.height) {
- Gdk.Rectangle alloc;
+ allocation.height -= BORDER_WIDTH;
- if (_buttons_height > 0) {
- alloc.x = Gdk.Rect.right (allocation) - BORDER_WIDTH;
- alloc.y = Gdk.Rect.bottom (allocation) - _buttons_height;
- alloc.height = _buttons_height;
+ if (_buttons_height + TOP_PADDING <= allocation.height) {
+ Gdk.Rectangle alloc;
- if (_exit_button != null) {
- alloc.x -= _exit_button_width;
- alloc.width = _exit_button_width;
- if (alloc.x >= allocation.x + BORDER_WIDTH) {
- _exit_button.size_allocate (alloc);
- }
- }
+ if (_buttons_height > 0) {
+ alloc.x = Gdk.Rect.right (allocation) - BORDER_WIDTH;
+ alloc.y = Gdk.Rect.bottom (allocation) - _buttons_height;
+ alloc.height = _buttons_height;
- if (_options_button != null) {
if (_exit_button != null) {
- alloc.x -= SPACE;
+ alloc.x -= _exit_button_width;
+ alloc.width = _exit_button_width;
+ if (alloc.x >= allocation.x + BORDER_WIDTH) {
+ _exit_button.size_allocate (alloc);
+ }
}
- alloc.x -= _options_button_width;
- alloc.width = _options_button_width;
- if (alloc.x >= allocation.x + BORDER_WIDTH) {
- _options_button.size_allocate (alloc);
+
+ if (_options_button != null) {
+ if (_exit_button != null) {
+ alloc.x -= SPACE;
+ }
+ alloc.x -= _options_button_width;
+ alloc.width = _options_button_width;
+ if (alloc.x >= allocation.x + BORDER_WIDTH) {
+ _options_button.size_allocate (alloc);
+ }
}
+
+ allocation.height -= _buttons_height + SPACE;
}
- allocation.height -= _buttons_height + SPACE;
- }
+ alloc.x = allocation.x + BORDER_WIDTH;
+ alloc.y = allocation.y + TOP_PADDING;
+ _items_alloc.x = alloc.x;
+ _items_alloc.y = alloc.y;
+ alloc.height = _item_height;
+ if (Gdk.Rect.right (allocation) - alloc.x - BORDER_WIDTH < _menu_items_col_width) {
+ _menu_items_col_width = Gdk.Rect.right (allocation) - alloc.x - BORDER_WIDTH;
+ }
- alloc.x = allocation.x + BORDER_WIDTH;
- alloc.y = allocation.y + TOP_PADDING;
- _items_alloc.x = alloc.x;
- _items_alloc.y = alloc.y;
- alloc.height = _item_height;
- if (Gdk.Rect.right (allocation) - alloc.x - BORDER_WIDTH < _menu_items_col_width) {
- _menu_items_col_width = Gdk.Rect.right (allocation) - alloc.x - BORDER_WIDTH;
- }
-
- if (_menu_items_col_width > 0) {
- alloc.width = _menu_items_col_width;
-
- foreach (var mi in _items) {
- if (mi.visible) {
- if (Gdk.Rect.bottom (alloc) <= Gdk.Rect.bottom (allocation)) {
- mi.size_allocate (alloc);
- alloc.y += _item_height;
- _visible_menu_items++;
+ if (_menu_items_col_width > 0) {
+ alloc.width = _menu_items_col_width;
+
+ foreach (var mi in _items) {
+ if (mi.visible) {
+ if (Gdk.Rect.bottom (alloc) <= Gdk.Rect.bottom (allocation)) {
+ mi.size_allocate (alloc);
+ alloc.y += _item_height;
+ _visible_menu_items++;
+ }
}
}
}
- }
- _items_alloc.width = _menu_items_col_width + SPACE;
- _items_alloc.height = Gdk.Rect.bottom (allocation) - _items_alloc.y - BORDER_WIDTH;
+ _items_alloc.width = _menu_items_col_width + SPACE;
+ _items_alloc.height = Gdk.Rect.bottom (allocation) - _items_alloc.y - BORDER_WIDTH;
- if (_active_menu != null) {
- alloc.x = allocation.x + BORDER_WIDTH + _menu_items_col_width + SPACE;
- alloc.width = Gdk.Rect.right (allocation) - alloc.x - BORDER_WIDTH;
- alloc.y = allocation.y + TOP_PADDING;
- alloc.height = Gdk.Rect.bottom (allocation) - alloc.y - BORDER_WIDTH;
+ if (_active_menu != null) {
+ alloc.x = allocation.x + BORDER_WIDTH + _menu_items_col_width + SPACE;
+ alloc.width = Gdk.Rect.right (allocation) - alloc.x - BORDER_WIDTH;
+ alloc.y = allocation.y + TOP_PADDING;
+ alloc.height = Gdk.Rect.bottom (allocation) - alloc.y - BORDER_WIDTH;
- if (alloc.width > 0 && alloc.width > 0) {
- _active_menu.size_allocate (alloc);
+ if (alloc.width > 0 && alloc.width > 0) {
+ _active_menu.size_allocate (alloc);
+ }
}
}
}
- }
- protected override bool expose_event (Gdk.EventExpose event) {
- var cr = Gdk.cairo_create (this.window);
+ protected override bool expose_event (Gdk.EventExpose event) {
+ var cr = Gdk.cairo_create (this.window);
- cr.rectangle (event.area.x, event.area.y, event.area.width, event.area.height);
- cr.clip ();
- draw (cr);
+ cr.rectangle (event.area.x, event.area.y, event.area.width, event.area.height);
+ cr.clip ();
+ draw (cr);
-// cr.target.dispose ();
-// cr.dispose ();
+ // cr.target.dispose ();
+ // cr.dispose ();
-// return base.expose_event (event); // XXX
- return false;
- }
+ // return base.expose_event (event); // XXX
+ return false;
+ }
- protected void draw (Context cr) {
- Gdk.Rectangle rect = (Gdk.Rectangle) this.allocation; // XXX
- _theme.draw_application_menu (cr, rect, _items_alloc, LINE_WIDTH, this);
+ protected void draw (Context cr) {
+ Gdk.Rectangle rect = (Gdk.Rectangle) this.allocation; // XXX
+ _theme.draw_application_menu (cr, rect, _items_alloc, LINE_WIDTH, this);
+ }
}
}
-
Modified: trunk/geetk/ribbon/base-button.vala
==============================================================================
--- trunk/geetk/ribbon/base-button.vala (original)
+++ trunk/geetk/ribbon/base-button.vala Thu Jul 24 15:19:51 2008
@@ -1,198 +1,200 @@
using Gtk;
-/**
- * Foundation of all buttons.
- */
-public abstract class BaseButton : Bin {
-
- protected Theme.ButtonState _state = Theme.ButtonState.DEFAULT;
- protected bool _is_small;
-
- /** Spacing between the content and the widget. */
- protected double _padding;
- public double padding {
- set {
- if (_padding == value) {
- return;
+namespace Geetk {
+
+ /**
+ * Foundation of all buttons.
+ */
+ public abstract class BaseButton : Bin {
+
+ protected Theme.ButtonState _state = Theme.ButtonState.DEFAULT;
+ protected bool _is_small;
+
+ /** Spacing between the content and the widget. */
+ protected double _padding;
+ public double padding {
+ set {
+ if (_padding == value) {
+ return;
+ }
+ _padding = value;
+ queue_draw ();
}
- _padding = value;
- queue_draw ();
+ get { return _padding; }
}
- get { return _padding; }
- }
- /** Shape of the widget. */
- public GroupStyle group_style { get; set; }
+ /** Shape of the widget. */
+ public GroupStyle group_style { get; set; }
- /** <b>true</b> if the widget should paint a background, <b>false</b> otherwise. */
- protected bool _draw_background;
- public bool draw_background {
- set {
- if (_draw_background == value) {
- return;
+ /** <b>true</b> if the widget should paint a background, <b>false</b> otherwise. */
+ protected bool _draw_background;
+ public bool draw_background {
+ set {
+ if (_draw_background == value) {
+ return;
+ }
+ _draw_background = value;
+ queue_draw ();
}
- _draw_background = value;
- queue_draw ();
+ get { return _draw_background; }
}
- get { return _draw_background; }
- }
- protected bool _opaque_background;
- public bool opaque_background {
- set {
- if (_opaque_background == value) {
- return;
+ protected bool _opaque_background;
+ public bool opaque_background {
+ set {
+ if (_opaque_background == value) {
+ return;
+ }
+ _opaque_background = value;
+ queue_draw ();
}
- _opaque_background = value;
- queue_draw ();
+ get { return _opaque_background; }
}
- get { return _opaque_background; }
- }
- /** <b>true</b> if the button is enabled, <b>false</b> otherwise. */
- protected bool _enabled;
- public bool enabled {
- set {
- if (_enabled == value) {
- return;
+ /** <b>true</b> if the button is enabled, <b>false</b> otherwise. */
+ protected bool _enabled;
+ public bool enabled {
+ set {
+ if (_enabled == value) {
+ return;
+ }
+ _enabled = value;
+ queue_draw ();
}
- _enabled = value;
- queue_draw ();
+ get { return _enabled; }
}
- get { return _enabled; }
- }
- /** Image to display. */
- protected Widget _image;
- public Widget image {
- set {
- if (_image == value) {
- return;
- }
- if (_image != null) {
- unbind_widget (_image);
- }
- _image = value;
- if (_image != null) {
- bind_widget (_image);
+ /** Image to display. */
+ protected Widget _image;
+ public Widget image {
+ set {
+ if (_image == value) {
+ return;
+ }
+ if (_image != null) {
+ unbind_widget (_image);
+ }
+ _image = value;
+ if (_image != null) {
+ bind_widget (_image);
+ }
+ update_image_label ();
}
- update_image_label ();
+ get { return _image; }
}
- get { return _image; }
- }
- /** Position of the image relative to the label. */
- protected PositionType _image_position;
- public PositionType image_position {
- set {
- if (_image_position == value) {
- return;
+ /** Position of the image relative to the label. */
+ protected PositionType _image_position;
+ public PositionType image_position {
+ set {
+ if (_image_position == value) {
+ return;
+ }
+ _image_position = value;
+ update_image_label ();
+ }
+ get { return _image_position; }
+ }
+
+ /** Label to display. */
+ protected Label _label;
+ public string label {
+ set {
+ if (_label != null) {
+ unbind_widget (_label);
+ }
+ _label = new Label (value);
+ if (_label != null) {
+ bind_widget (_label);
+ }
+ update_image_label ();
+ }
+ get {
+ return _label == null ? null : _label.text;
}
- _image_position = value;
- update_image_label ();
}
- get { return _image_position; }
- }
- /** Label to display. */
- protected Label _label;
- public string label {
- set {
- if (_label != null) {
- unbind_widget (_label);
- }
- _label = new Label (value);
- if (_label != null) {
- bind_widget (_label);
+ /** Theme used to draw the widget. */
+ protected Theme _theme = new Theme ();
+ public Theme theme {
+ set {
+ _theme = value;
+ queue_draw ();
}
- update_image_label ();
+ get { return _theme; }
}
- get {
- return _label == null ? null : _label.text;
+
+ /** Binds a widget to listen to all button events. */
+ private void bind_widget (Widget w) {
+ w.button_press_event += bound_widget_button_press_event;
+ w.button_release_event += bound_widget_button_release_event;
}
- }
- /** Theme used to draw the widget. */
- protected Theme _theme = new Theme ();
- public Theme theme {
- set {
- _theme = value;
- queue_draw ();
+ /** Unbinds a widget to no longer listen to button events. */
+ private void unbind_widget (Widget w) {
+ w.button_press_event -= bound_widget_button_press_event;
+ w.button_release_event -= bound_widget_button_release_event;
}
- get { return _theme; }
- }
- /** Binds a widget to listen to all button events. */
- private void bind_widget (Widget w) {
- w.button_press_event += bound_widget_button_press_event;
- w.button_release_event += bound_widget_button_release_event;
- }
+ /** Called when a mouse button has been pressed on a binded widget. */
+ protected abstract bool bound_widget_button_press_event (Widget sender,
+ Gdk.EventButton event);
- /** Unbinds a widget to no longer listen to button events. */
- private void unbind_widget (Widget w) {
- w.button_press_event -= bound_widget_button_press_event;
- w.button_release_event -= bound_widget_button_release_event;
- }
+ /** Called when a mouse button has been release on a binded widget. */
+ protected abstract bool bound_widget_button_release_event (Widget sender,
+ Gdk.EventButton event);
+
+ /** Updates the child widget containing the label and/or image. */
+ private void update_image_label () {
+ if (this.child != null) {
+ var con = this.child as Container;
+ if (con != null) {
+ con.remove (_image);
+ con.remove (_label);
+ }
+ remove (this.child);
+ }
- /** Called when a mouse button has been pressed on a binded widget. */
- protected abstract bool bound_widget_button_press_event (Widget sender,
- Gdk.EventButton event);
-
- /** Called when a mouse button has been release on a binded widget. */
- protected abstract bool bound_widget_button_release_event (Widget sender,
- Gdk.EventButton event);
-
- /** Updates the child widget containing the label and/or image. */
- private void update_image_label () {
- if (this.child != null) {
- var con = this.child as Container;
- if (con != null) {
- con.remove (_image);
- con.remove (_label);
- }
- remove (this.child);
- }
-
- if (_label != null && _image != null) {
- switch (_image_position) {
- case PositionType.TOP:
- {
- var box = new VBox (false, 0);
- box.add (_image);
- box.add (_label);
- add (box); // FIXME
- break;
- }
- case PositionType.BOTTOM:
- {
- var box = new VBox (false, 0);
- box.add (_label);
- box.add (_image);
- add (box); // FIXME
- break;
- }
- case PositionType.LEFT:
- {
- var box = new HBox (false, 0);
- box.add (_image);
- box.add (_label);
- add (box); // FIXME
- break;
- }
- case PositionType.RIGHT:
- {
- var box = new HBox (false, 0);
- box.add (_label);
- box.add (_image);
- add (box); // FIXME
- break;
- }
- }
- } else if (_label != null) {
- add (_label); // FIXME why add instead of this.child = ... ?
- } else if (_image != null) {
- add (_image); // FIXME why add instead of this.child = ... ?
+ if (_label != null && _image != null) {
+ switch (_image_position) {
+ case PositionType.TOP:
+ {
+ var box = new VBox (false, 0);
+ box.add (_image);
+ box.add (_label);
+ add (box); // FIXME
+ break;
+ }
+ case PositionType.BOTTOM:
+ {
+ var box = new VBox (false, 0);
+ box.add (_label);
+ box.add (_image);
+ add (box); // FIXME
+ break;
+ }
+ case PositionType.LEFT:
+ {
+ var box = new HBox (false, 0);
+ box.add (_image);
+ box.add (_label);
+ add (box); // FIXME
+ break;
+ }
+ case PositionType.RIGHT:
+ {
+ var box = new HBox (false, 0);
+ box.add (_label);
+ box.add (_image);
+ add (box); // FIXME
+ break;
+ }
+ }
+ } else if (_label != null) {
+ add (_label); // FIXME why add instead of this.child = ... ?
+ } else if (_image != null) {
+ add (_image); // FIXME why add instead of this.child = ... ?
+ }
}
}
}
-
Modified: trunk/geetk/ribbon/button.vala
==============================================================================
--- trunk/geetk/ribbon/button.vala (original)
+++ trunk/geetk/ribbon/button.vala Thu Jul 24 15:19:51 2008
@@ -2,312 +2,314 @@
using Cairo;
using Gtk;
-/** Button to be used in Ribbons. */
-public class Button : BaseButton {
+namespace Geetk {
- private double _arrow_size;
- private Gdk.Rectangle _arrow_allocation;
+ /** Button to be used in Ribbons. */
+ public class Button : BaseButton {
- protected const double LINE_WIDTH = 1.0;
- protected const double ARROW_PADDING = 2.0;
- protected const double SMALL_ARROW_SIZE = 5.0;
- protected const double BIG_ARROW_SIZE = 8.0;
-
- /** Fired when the button is clicked. */
- public signal void clicked ();
-
- /** Drop down menu displayed when the arrow is pressed. */
- private Menu _drop_down_menu;
- public Menu drop_down_menu {
- set {
- _drop_down_menu = value;
- queue_draw ();
- }
- get {
- return _drop_down_menu;
- }
- }
-
- /** Construction method. */
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
-
- this.padding = 2;
- this.image_position = PositionType.TOP;
- _is_small = false;
- _enabled = true;
- }
-
- /**
- * Constructor given a label to display.
- *
- * @param label Label to display.
- */
- public Button.with_label (string label) {
- this.label = label;
- }
-
- /**
- * Constructor given an image to display.
- *
- * @param Image Image to display
- */
- public Button.with_image (Image image) {
- this.image = image;
- }
-
- /**
- * Constructor given a label and an image to display.
- *
- * @param image Image to display.
- * @param label label to display.
- */
- public Button (Image image, string label) {
- this.image = image;
- this.label = label;
- }
+ private double _arrow_size;
+ private Gdk.Rectangle _arrow_allocation;
- /**
- * Constructs a Button from a stock.
- *
- * @param name Name of the stock.
- * @param large <b>true</b> if the image should be large,
- * <b>false</b> otherwise.
- */
- public static Button from_stock (string name, bool large) {
- var img = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
- : IconSize.SMALL_TOOLBAR);
- var btn = new Button.with_image (img);
- if (!large) {
- btn.image_position = PositionType.LEFT;
+ protected const double LINE_WIDTH = 1.0;
+ protected const double ARROW_PADDING = 2.0;
+ protected const double SMALL_ARROW_SIZE = 5.0;
+ protected const double BIG_ARROW_SIZE = 8.0;
+
+ /** Fired when the button is clicked. */
+ public signal void clicked ();
+
+ /** Drop down menu displayed when the arrow is pressed. */
+ private Menu _drop_down_menu;
+ public Menu drop_down_menu {
+ set {
+ _drop_down_menu = value;
+ queue_draw ();
+ }
+ get {
+ return _drop_down_menu;
+ }
}
- return btn;
- }
- /**
- * Constructs a Button from a stock.
- *
- * @param name Name of the stock.
- * @param label label to display.
- * @param large <b>true</b> if the image should be large,
- * <b>false</b> otherwise.
- */
- public static Button from_stock_with_label (string name, string label, bool large) {
- var img = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
- : IconSize.SMALL_TOOLBAR);
- var btn = new Button (img, label);
- if (!large) {
- btn.image_position = PositionType.LEFT;
+ /** Construction method. */
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+
+ this.padding = 2;
+ this.image_position = PositionType.TOP;
+ _is_small = false;
+ _enabled = true;
+ }
+
+ /**
+ * Constructor given a label to display.
+ *
+ * @param label Label to display.
+ */
+ public Button.with_label (string label) {
+ this.label = label;
+ }
+
+ /**
+ * Constructor given an image to display.
+ *
+ * @param Image Image to display
+ */
+ public Button.with_image (Image image) {
+ this.image = image;
+ }
+
+ /**
+ * Constructor given a label and an image to display.
+ *
+ * @param image Image to display.
+ * @param label label to display.
+ */
+ public Button (Image image, string label) {
+ this.image = image;
+ this.label = label;
+ }
+
+ /**
+ * Constructs a Button from a stock.
+ *
+ * @param name Name of the stock.
+ * @param large <b>true</b> if the image should be large,
+ * <b>false</b> otherwise.
+ */
+ public static Button from_stock (string name, bool large) {
+ var img = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
+ : IconSize.SMALL_TOOLBAR);
+ var btn = new Button.with_image (img);
+ if (!large) {
+ btn.image_position = PositionType.LEFT;
+ }
+ return btn;
}
- return btn;
- }
- /** Fires the clicked event. */
- private void click () {
- if (_enabled) {
- clicked ();
+ /**
+ * Constructs a Button from a stock.
+ *
+ * @param name Name of the stock.
+ * @param label label to display.
+ * @param large <b>true</b> if the image should be large,
+ * <b>false</b> otherwise.
+ */
+ public static Button from_stock_with_label (string name, string label, bool large) {
+ var img = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
+ : IconSize.SMALL_TOOLBAR);
+ var btn = new Button (img, label);
+ if (!large) {
+ btn.image_position = PositionType.LEFT;
+ }
+ return btn;
}
- }
-
- // XXX: workaround
- private bool has_click_listener () {
- var signal_id = Signal.lookup ("clicked", typeof (Button));
- return Signal.has_handler_pending (this, signal_id, 0, true);
- }
- /** Displays the drop down menu if any. */
- public void popup () {
- if (_enabled && _drop_down_menu != null) {
- _drop_down_menu.popup (null, null, null, 3, Gtk.get_current_event_time ());
- _drop_down_menu.show_all ();
+ /** Fires the clicked event. */
+ private void click () {
+ if (_enabled) {
+ clicked ();
+ }
}
- }
- protected override bool bound_widget_button_press_event (Widget sender,
- Gdk.EventButton evnt) {
- event ((Gdk.Event) evnt);
- return false;
- }
-
- protected override bool bound_widget_button_release_event (Widget sender,
- Gdk.EventButton evnt) {
- event ((Gdk.Event) evnt);
- click ();
- return false;
- }
+ // XXX: workaround
+ private bool has_click_listener () {
+ var signal_id = Signal.lookup ("clicked", typeof (Button));
+ return Signal.has_handler_pending (this, signal_id, 0, true);
+ }
- protected override void size_request (Requisition requisition) {
-// base.size_request (requisition);
-
- Requisition child_requisition = Requisition ();
- if (this.child != null && this.child.visible) {
- this.child.size_request (child_requisition);
+ /** Displays the drop down menu if any. */
+ public void popup () {
+ if (_enabled && _drop_down_menu != null) {
+ _drop_down_menu.popup (null, null, null, 3, Gtk.get_current_event_time ());
+ _drop_down_menu.show_all ();
+ }
}
- if (_drop_down_menu != null) {
- int arrow_space = (int) ((_is_small ? SMALL_ARROW_SIZE : BIG_ARROW_SIZE)
- + 2 * (LINE_WIDTH + ARROW_PADDING));
+ protected override bool bound_widget_button_press_event (Widget sender,
+ Gdk.EventButton evnt) {
+ event ((Gdk.Event) evnt);
+ return false;
+ }
+
+ protected override bool bound_widget_button_release_event (Widget sender,
+ Gdk.EventButton evnt) {
+ event ((Gdk.Event) evnt);
+ click ();
+ return false;
+ }
+
+ protected override void size_request (Requisition requisition) {
+ // base.size_request (requisition);
+
+ Requisition child_requisition = Requisition ();
+ if (this.child != null && this.child.visible) {
+ this.child.size_request (child_requisition);
+ }
- if (_image_position == PositionType.TOP
- || _image_position == PositionType.BOTTOM) {
- child_requisition.height += arrow_space;
- } else {
- child_requisition.width += arrow_space;
+ if (_drop_down_menu != null) {
+ int arrow_space = (int) ((_is_small ? SMALL_ARROW_SIZE : BIG_ARROW_SIZE)
+ + 2 * (LINE_WIDTH + ARROW_PADDING));
+
+ if (_image_position == PositionType.TOP
+ || _image_position == PositionType.BOTTOM) {
+ child_requisition.height += arrow_space;
+ } else {
+ child_requisition.width += arrow_space;
+ }
}
- }
-// if (this.height_request == -1) {
- requisition.height = child_requisition.height
- + (int) (LINE_WIDTH * 4 + _padding * 2);
-// }
-// if (this.width_request == -1) {
- requisition.width = child_requisition.width
- + (int) (LINE_WIDTH * 4 + _padding * 2);
-// }
- }
+ // if (this.height_request == -1) {
+ requisition.height = child_requisition.height
+ + (int) (LINE_WIDTH * 4 + _padding * 2);
+ // }
+ // if (this.width_request == -1) {
+ requisition.width = child_requisition.width
+ + (int) (LINE_WIDTH * 4 + _padding * 2);
+ // }
+ }
+
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocate (allocation);
+ this.allocation = (Allocation) allocation;
+
+ if (_drop_down_menu != null) {
+ _arrow_size = _is_small ? SMALL_ARROW_SIZE : BIG_ARROW_SIZE;
+
+ if (_image_position == PositionType.TOP
+ || _image_position == PositionType.BOTTOM) {
+ if (has_click_listener ()) {
+ _arrow_allocation.height = (int) (_arrow_size + 2 * ARROW_PADDING);
+ } else {
+ _arrow_allocation.height = (int) (allocation.height - 4 * LINE_WIDTH);
+ }
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocate (allocation);
- this.allocation = (Allocation) allocation;
-
- if (_drop_down_menu != null) {
- _arrow_size = _is_small ? SMALL_ARROW_SIZE : BIG_ARROW_SIZE;
-
- if (_image_position == PositionType.TOP
- || _image_position == PositionType.BOTTOM) {
- if (has_click_listener ()) {
- _arrow_allocation.height = (int) (_arrow_size + 2 * ARROW_PADDING);
+ _arrow_allocation.width = (int) (allocation.width - 4 * LINE_WIDTH);
} else {
+ if (has_click_listener ()) {
+ _arrow_allocation.width = (int) (_arrow_size + 2 * ARROW_PADDING);
+ } else {
+ _arrow_allocation.width = (int) (allocation.width - 4 * LINE_WIDTH);
+ }
+
_arrow_allocation.height = (int) (allocation.height - 4 * LINE_WIDTH);
}
- _arrow_allocation.width = (int) (allocation.width - 4 * LINE_WIDTH);
+ _arrow_allocation.x = (int) (Gdk.Rect.right (allocation)
+ - _arrow_allocation.width
+ - 2 * LINE_WIDTH);
+ _arrow_allocation.y = (int) (Gdk.Rect.bottom (allocation)
+ - _arrow_allocation.height
+ - 2 * LINE_WIDTH);
} else {
- if (has_click_listener ()) {
- _arrow_allocation.width = (int) (_arrow_size + 2 * ARROW_PADDING);
+ _arrow_size = 0;
+ }
+
+ allocation.x += (int) (LINE_WIDTH * 2 + _padding);
+ allocation.y += (int) (LINE_WIDTH * 2 + _padding);
+ allocation.height -= (int) (LINE_WIDTH * 4 + _padding * 2);
+ allocation.width -= (int) (LINE_WIDTH * 4 + _padding * 2);
+
+ if (_drop_down_menu != null) {
+ int arrow_space = (int) ((_is_small ? SMALL_ARROW_SIZE : BIG_ARROW_SIZE)
+ + 2 * (LINE_WIDTH + ARROW_PADDING));
+
+ if (_image_position == PositionType.TOP
+ || _image_position == PositionType.BOTTOM) {
+ allocation.height -= arrow_space;
} else {
- _arrow_allocation.width = (int) (allocation.width - 4 * LINE_WIDTH);
+ allocation.width -= arrow_space;
}
+ }
- _arrow_allocation.height = (int) (allocation.height - 4 * LINE_WIDTH);
+ if (allocation.height < 0) {
+ allocation.height = 0;
+ }
+ if (allocation.width < 0) {
+ allocation.width = 0;
}
- _arrow_allocation.x = (int) (Gdk.Rect.right (allocation)
- - _arrow_allocation.width
- - 2 * LINE_WIDTH);
- _arrow_allocation.y = (int) (Gdk.Rect.bottom (allocation)
- - _arrow_allocation.height
- - 2 * LINE_WIDTH);
- } else {
- _arrow_size = 0;
- }
-
- allocation.x += (int) (LINE_WIDTH * 2 + _padding);
- allocation.y += (int) (LINE_WIDTH * 2 + _padding);
- allocation.height -= (int) (LINE_WIDTH * 4 + _padding * 2);
- allocation.width -= (int) (LINE_WIDTH * 4 + _padding * 2);
-
- if (_drop_down_menu != null) {
- int arrow_space = (int) ((_is_small ? SMALL_ARROW_SIZE : BIG_ARROW_SIZE)
- + 2 * (LINE_WIDTH + ARROW_PADDING));
-
- if (_image_position == PositionType.TOP
- || _image_position == PositionType.BOTTOM) {
- allocation.height -= arrow_space;
- } else {
- allocation.width -= arrow_space;
+ if (this.child != null && this.child.visible) {
+ this.child.size_allocate (allocation);
}
}
- if (allocation.height < 0) {
- allocation.height = 0;
- }
- if (allocation.width < 0) {
- allocation.width = 0;
- }
+ protected override bool expose_event (Gdk.EventExpose event) {
+ var cr = Gdk.cairo_create (this.window);
- if (this.child != null && this.child.visible) {
- this.child.size_allocate (allocation);
+ cr.rectangle (event.area.x, event.area.y,
+ event.area.width, event.area.height);
+ cr.clip ();
+ draw (cr);
+
+ // cr.target.dispose ();
+ // cr.dispose ();
+
+ // return base.expose_event (event); // FIXME: causes endless loop
+ // *** workaround ***
+ if (this.child != null) {
+ this.child.expose_event (event);
+ }
+ return false;
+ // *** workaround ***
}
- }
-
- protected override bool expose_event (Gdk.EventExpose event) {
- var cr = Gdk.cairo_create (this.window);
- cr.rectangle (event.area.x, event.area.y,
- event.area.width, event.area.height);
- cr.clip ();
- draw (cr);
-
-// cr.target.dispose ();
-// cr.dispose ();
-
-// return base.expose_event (event); // FIXME: causes endless loop
- // *** workaround ***
- if (this.child != null) {
- this.child.expose_event (event);
- }
- return false;
- // *** workaround ***
- }
+ protected void draw (Context cr) {
+ Gdk.Rectangle rect = (Gdk.Rectangle) this.allocation;
+ double round_size = _is_small ? 2.0 : 3.0;
+ bool draw_separator = (has_click_listener ()) && (_drop_down_menu != null);
+ _theme.draw_button (cr, rect, _state, round_size, LINE_WIDTH,
+ _arrow_size, ARROW_PADDING, draw_separator, this);
+ }
+
+ protected override bool button_press_event (Gdk.EventButton event) {
+ // bool ret = base.button_press_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.PRESSED;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
- protected void draw (Context cr) {
- Gdk.Rectangle rect = (Gdk.Rectangle) this.allocation;
- double round_size = _is_small ? 2.0 : 3.0;
- bool draw_separator = (has_click_listener ()) && (_drop_down_menu != null);
- _theme.draw_button (cr, rect, _state, round_size, LINE_WIDTH,
- _arrow_size, ARROW_PADDING, draw_separator, this);
- }
+ if (_drop_down_menu != null
+ && Gdk.Rect.contains (_arrow_allocation, (int) event.x, (int) event.y)) {
+ popup ();
+ }
- protected override bool button_press_event (Gdk.EventButton event) {
-// bool ret = base.button_press_event (event);
- bool ret = false;
- _state = Theme.ButtonState.PRESSED;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ return ret;
}
- queue_draw ();
- if (_drop_down_menu != null
- && Gdk.Rect.contains (_arrow_allocation, (int) event.x, (int) event.y)) {
- popup ();
+ protected override bool button_release_event (Gdk.EventButton event) {
+ // bool ret = base.button_release_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.HOVER;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- return ret;
- }
-
- protected override bool button_release_event (Gdk.EventButton event) {
-// bool ret = base.button_release_event (event);
- bool ret = false;
- _state = Theme.ButtonState.HOVER;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool enter_notify_event (Gdk.EventCrossing event) {
+ // bool ret = base.enter_notify_event (event);
+ bool ret = false;
+ _state = Theme.ButtonState.HOVER;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
- protected override bool enter_notify_event (Gdk.EventCrossing event) {
-// bool ret = base.enter_notify_event (event);
- bool ret = false;
- _state = Theme.ButtonState.HOVER;
- if (!_enabled) {
+ protected override bool leave_notify_event (Gdk.EventCrossing event) {
+ // bool ret = base.leave_notify_event (event);
+ bool ret = false;
_state = Theme.ButtonState.DEFAULT;
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
-
- protected override bool leave_notify_event (Gdk.EventCrossing event) {
-// bool ret = base.leave_notify_event (event);
- bool ret = false;
- _state = Theme.ButtonState.DEFAULT;
- queue_draw ();
- return ret;
}
}
-
Modified: trunk/geetk/ribbon/color-scheme.vala
==============================================================================
--- trunk/geetk/ribbon/color-scheme.vala (original)
+++ trunk/geetk/ribbon/color-scheme.vala Thu Jul 24 15:19:51 2008
@@ -1,226 +1,229 @@
using GLib;
-public class ColorScheme : Object {
+namespace Geetk {
- public Color pretty_dark { get; set; }
- public Color dark { get; set; }
- public Color light_dark { get; set; }
- public Color normal { get; set; }
- public Color light_bright { get; set; }
- public Color bright { get; set; }
- public Color pretty_bright { get; set; }
-
- public ColorScheme () {
-// this.normal = Color.from_rgb (0.957, 0.957, 0.957);
- this.normal = Color.from_rgb (0.867, 0.867, 0.867);
-// this.normal = Color.from_rgb (0.925, 0.914, 0.847);
-// this.normal = Color.from_rgb (0.937, 0.922, 0.898);
- // FIXME
- this.pretty_dark = get_color_relative (this.normal, -0.4);
- this.dark = get_color_relative (this.normal, -0.1);
- this.light_dark = get_color_relative (this.normal, -0.05);
- this.light_bright = get_color_relative (this.normal, 0.05);
- this.bright = get_color_relative (this.normal, 0.1);
- this.pretty_bright = get_color_relative (this.normal, 0.15);
- }
-
- public ColorScheme.from_color (Color normal) {
- this.normal = normal;
- // FIXME
- this.pretty_dark = get_color_relative (this.normal, -0.4);
- this.dark = get_color_relative (this.normal, -0.1);
- this.light_dark = get_color_relative (this.normal, -0.05);
- this.light_bright = get_color_relative (this.normal, 0.05);
- this.bright = get_color_relative (this.normal, 0.1);
- this.pretty_bright = get_color_relative (this.normal, 0.15);
- }
-
- construct {
-// this.pretty_dark = get_color_relative (this.normal, -0.4);
-// this.dark = get_color_relative (this.normal, -0.1);
-// this.light_dark = get_color_relative (this.normal, -0.05);
-// this.light_bright = get_color_relative (this.normal, 0.05);
-// this.bright = get_color_relative (this.normal, 0.1);
-// this.pretty_bright = get_color_relative (this.normal, 0.15);
- }
+ public class ColorScheme : Object {
- public static Color set_alpha_channel (Color c, double alpha) {
- return Color.from_rgba (c.r, c.g, c.b, alpha);
- }
-
- public static Color get_color_absolute (Color c, double luminance) {
-// double h, s, v;
-// rgb2hsv (c, out h, out s, out v);
-// v = v + (1.7 * (luminance - 1));
-// if (v < 0) {
-// v = 0;
-// } else if (v > 1) {
-// v = 1;
-// }
-// return hsv2rgb (h, s, v);
-
- double h, s, l;
- rgb2hsl (c, out h, out s, out l);
-// double a = (h % 60) / 60;
-// if (a > 0.5) {
-// a -= 0.5;
-// }
-// l = l + (1.7 * (luminance - 1));
- l = luminance;
- if (l < 0) {
- l = 0;
- } else if (l > 1) {
- l = 1;
+ public Color pretty_dark { get; set; }
+ public Color dark { get; set; }
+ public Color light_dark { get; set; }
+ public Color normal { get; set; }
+ public Color light_bright { get; set; }
+ public Color bright { get; set; }
+ public Color pretty_bright { get; set; }
+
+ public ColorScheme () {
+ // this.normal = Color.from_rgb (0.957, 0.957, 0.957);
+ this.normal = Color.from_rgb (0.867, 0.867, 0.867);
+ // this.normal = Color.from_rgb (0.925, 0.914, 0.847);
+ // this.normal = Color.from_rgb (0.937, 0.922, 0.898);
+ // FIXME
+ this.pretty_dark = get_color_relative (this.normal, -0.4);
+ this.dark = get_color_relative (this.normal, -0.1);
+ this.light_dark = get_color_relative (this.normal, -0.05);
+ this.light_bright = get_color_relative (this.normal, 0.05);
+ this.bright = get_color_relative (this.normal, 0.1);
+ this.pretty_bright = get_color_relative (this.normal, 0.15);
+ }
+
+ public ColorScheme.from_color (Color normal) {
+ this.normal = normal;
+ // FIXME
+ this.pretty_dark = get_color_relative (this.normal, -0.4);
+ this.dark = get_color_relative (this.normal, -0.1);
+ this.light_dark = get_color_relative (this.normal, -0.05);
+ this.light_bright = get_color_relative (this.normal, 0.05);
+ this.bright = get_color_relative (this.normal, 0.1);
+ this.pretty_bright = get_color_relative (this.normal, 0.15);
+ }
+
+ construct {
+ // this.pretty_dark = get_color_relative (this.normal, -0.4);
+ // this.dark = get_color_relative (this.normal, -0.1);
+ // this.light_dark = get_color_relative (this.normal, -0.05);
+ // this.light_bright = get_color_relative (this.normal, 0.05);
+ // this.bright = get_color_relative (this.normal, 0.1);
+ // this.pretty_bright = get_color_relative (this.normal, 0.15);
+ }
+
+ public static Color set_alpha_channel (Color c, double alpha) {
+ return Color.from_rgba (c.r, c.g, c.b, alpha);
+ }
+
+ public static Color get_color_absolute (Color c, double luminance) {
+ // double h, s, v;
+ // rgb2hsv (c, out h, out s, out v);
+ // v = v + (1.7 * (luminance - 1));
+ // if (v < 0) {
+ // v = 0;
+ // } else if (v > 1) {
+ // v = 1;
+ // }
+ // return hsv2rgb (h, s, v);
+
+ double h, s, l;
+ rgb2hsl (c, out h, out s, out l);
+ // double a = (h % 60) / 60;
+ // if (a > 0.5) {
+ // a -= 0.5;
+ // }
+ // l = l + (1.7 * (luminance - 1));
+ l = luminance;
+ if (l < 0) {
+ l = 0;
+ } else if (l > 1) {
+ l = 1;
+ }
+ return hsl2rgb (h, s, l);
}
- return hsl2rgb (h, s, l);
- }
- public static Color get_color_relative (Color c, double luminance) {
- double h, s, l;
- rgb2hsl (c, out h, out s, out l);
-// double a = (h % 60) / 60;
-// if (a > 0.5) {
-// a -= 0.5;
-// }
- l = l + luminance;
- if (l < 0) {
- l = 0;
- } else if (l > 1) {
- l = 1;
+ public static Color get_color_relative (Color c, double luminance) {
+ double h, s, l;
+ rgb2hsl (c, out h, out s, out l);
+ // double a = (h % 60) / 60;
+ // if (a > 0.5) {
+ // a -= 0.5;
+ // }
+ l = l + luminance;
+ if (l < 0) {
+ l = 0;
+ } else if (l > 1) {
+ l = 1;
+ }
+ return hsl2rgb (h, s, l);
}
- return hsl2rgb (h, s, l);
- }
- private static void rgb2hsl (Color c, out double h, out double s, out double l) {
- double r = c.r;
- double g = c.g;
- double b = c.b;
- double max = double.max (r, double.max (g, b));
- double min = double.min (r, double.min (g, b));
- l = 0.5 * (max + min);
- if (max == min) {
- h = double.NAN;
- } else {
- if (max == r) {
- if (g >= b) {
- h = (g - b) / (max - min) * 60;
+ private static void rgb2hsl (Color c, out double h, out double s, out double l) {
+ double r = c.r;
+ double g = c.g;
+ double b = c.b;
+ double max = double.max (r, double.max (g, b));
+ double min = double.min (r, double.min (g, b));
+ l = 0.5 * (max + min);
+ if (max == min) {
+ h = double.NAN;
+ } else {
+ if (max == r) {
+ if (g >= b) {
+ h = (g - b) / (max - min) * 60;
+ } else {
+ h = (g - b) / (max - min) * 60 + 360;
+ }
+ } else if (max == g) {
+ h = (b - r) / (max - min) * 60 + 120;
} else {
- h = (g - b) / (max - min) * 60 + 360;
+ h = (r - g) / (max - min) * 60 + 240;
}
- } else if (max == g) {
- h = (b - r) / (max - min) * 60 + 120;
+ }
+ if (0.0000001 <= l && l <= 0.5) {
+ s = (max - min) / (2 * l);
+ } else if (l > 0.5) {
+ s = (max - min) / (2 - 2 * l);
} else {
- h = (r - g) / (max - min) * 60 + 240;
+ s = 0;
}
}
- if (0.0000001 <= l && l <= 0.5) {
- s = (max - min) / (2 * l);
- } else if (l > 0.5) {
- s = (max - min) / (2 - 2 * l);
- } else {
- s = 0;
- }
- }
- private static Color hsl2rgb (double h, double s, double l) {
- double r = l;
- double g = l;
- double b = l;
- double q;
- if (l < 0.5) {
- q = l * (1 + s);
- } else {
- q = l + s - l * s;
- }
- double p = 2 * l - q;
- if (q > 0) {
- double m = l + l - q;
- h /= 60;
- int i = (int) h % 6;
- double vsf = q * (q - m) / q * (h - i);
- switch (i) {
- case 0:
- r = q;
- g = m + vsf;
- b = m;
- break;
- case 1:
- r = m - vsf;
- g = q;
- b = m;
- break;
- case 2:
- r = m;
- g = q;
- b = m + vsf;
- break;
- case 3:
- r = m;
- g = m - vsf;
- b = q;
- break;
- case 4:
- r = m + vsf;
- g = m;
- b = q;
- break;
- case 5:
- r = q;
- g = m;
- b = m - vsf;
- break;
+ private static Color hsl2rgb (double h, double s, double l) {
+ double r = l;
+ double g = l;
+ double b = l;
+ double q;
+ if (l < 0.5) {
+ q = l * (1 + s);
+ } else {
+ q = l + s - l * s;
+ }
+ double p = 2 * l - q;
+ if (q > 0) {
+ double m = l + l - q;
+ h /= 60;
+ int i = (int) h % 6;
+ double vsf = q * (q - m) / q * (h - i);
+ switch (i) {
+ case 0:
+ r = q;
+ g = m + vsf;
+ b = m;
+ break;
+ case 1:
+ r = m - vsf;
+ g = q;
+ b = m;
+ break;
+ case 2:
+ r = m;
+ g = q;
+ b = m + vsf;
+ break;
+ case 3:
+ r = m;
+ g = m - vsf;
+ b = q;
+ break;
+ case 4:
+ r = m + vsf;
+ g = m;
+ b = q;
+ break;
+ case 5:
+ r = q;
+ g = m;
+ b = m - vsf;
+ break;
+ }
}
+ return Color.from_rgb (r, g, b);
}
- return Color.from_rgb (r, g, b);
- }
- // http://www.daniweb.com/techtalkforums/thread38302.html
- private static void rgb2hsv (Color c, out double h, out double s, out double v) {
- double r = c.r;
- double g = c.g;
- double b = c.b;
- double max = double.max (r, double.max (g, b));
- double min = double.min (r, double.min (g, b));
- double delta = max - min;
- v = max;
- if (Math.fabs (delta) < 0.0000001) {
- h = s = 0;
- } else {
- s = delta / max;
-
- if (r == max) {
- h = 60.0 * (g - b) / delta;
- } else if (g == max) {
- h = 60.0 * (2 + (b - r) / delta);
+ // http://www.daniweb.com/techtalkforums/thread38302.html
+ private static void rgb2hsv (Color c, out double h, out double s, out double v) {
+ double r = c.r;
+ double g = c.g;
+ double b = c.b;
+ double max = double.max (r, double.max (g, b));
+ double min = double.min (r, double.min (g, b));
+ double delta = max - min;
+ v = max;
+ if (Math.fabs (delta) < 0.0000001) {
+ h = s = 0;
} else {
- h = 60.0 * (4 + (r - g) / delta);
- }
+ s = delta / max;
+
+ if (r == max) {
+ h = 60.0 * (g - b) / delta;
+ } else if (g == max) {
+ h = 60.0 * (2 + (b - r) / delta);
+ } else {
+ h = 60.0 * (4 + (r - g) / delta);
+ }
- if (h < 0) {
- h += 360;
- } else if (h > 360) {
- h -= 360;
+ if (h < 0) {
+ h += 360;
+ } else if (h > 360) {
+ h -= 360;
+ }
}
}
- }
- // http://en.wikipedia.org/wiki/HSV_color_space
- private static Color hsv2rgb (double h, double s, double v) {
- int h_i = (int) (h / 60) % 6;
- double f = h / 60 - h_i;
- switch (h_i) {
- case 0:
- return Color.from_rgb (v, v * (1 - (1 - f) * s), v * (1 - s));
- case 1:
- return Color.from_rgb (v * (1 - f * s), v, v * (1 - s));
- case 2:
- return Color.from_rgb (v * (1 - s), v, v * (1 - (1 - f) * s));
- case 3:
- return Color.from_rgb (v * (1 - s), v * (1 - f * s), v);
- case 4:
- return Color.from_rgb (v * (1 - (1 - f) * s), v * (1 - s), v);
+ // http://en.wikipedia.org/wiki/HSV_color_space
+ private static Color hsv2rgb (double h, double s, double v) {
+ int h_i = (int) (h / 60) % 6;
+ double f = h / 60 - h_i;
+ switch (h_i) {
+ case 0:
+ return Color.from_rgb (v, v * (1 - (1 - f) * s), v * (1 - s));
+ case 1:
+ return Color.from_rgb (v * (1 - f * s), v, v * (1 - s));
+ case 2:
+ return Color.from_rgb (v * (1 - s), v, v * (1 - (1 - f) * s));
+ case 3:
+ return Color.from_rgb (v * (1 - s), v * (1 - f * s), v);
+ case 4:
+ return Color.from_rgb (v * (1 - (1 - f) * s), v * (1 - s), v);
+ }
+ return Color.from_rgb (v, v * (1 - s), v * (1 - f * s));
}
- return Color.from_rgb (v, v * (1 - s), v * (1 - f * s));
}
}
Modified: trunk/geetk/ribbon/extra-event-box.vala
==============================================================================
--- trunk/geetk/ribbon/extra-event-box.vala (original)
+++ trunk/geetk/ribbon/extra-event-box.vala Thu Jul 24 15:19:51 2008
@@ -1,18 +1,20 @@
using Gtk;
-/** EventBox extended to transmit all events. */
-public class ExtraEventBox : EventBox {
+namespace Geetk {
- protected override bool event (Gdk.Event event) {
- if (event.any.window == this.window) {
- if (event.type != Gdk.EventType.EXPOSE) {
- if (this.child != null) {
- this.child.event (event);
+ /** EventBox extended to transmit all events. */
+ public class ExtraEventBox : EventBox {
+
+ protected override bool event (Gdk.Event event) {
+ if (event.any.window == this.window) {
+ if (event.type != Gdk.EventType.EXPOSE) {
+ if (this.child != null) {
+ this.child.event (event);
+ }
}
}
+ // return base.event (event);
+ return false;
}
-// return base.event (event);
- return false;
}
}
-
Modified: trunk/geetk/ribbon/gallery-popup-window.vala
==============================================================================
--- trunk/geetk/ribbon/gallery-popup-window.vala (original)
+++ trunk/geetk/ribbon/gallery-popup-window.vala Thu Jul 24 15:19:51 2008
@@ -2,107 +2,110 @@
using Gee;
using Gtk;
-/** Popup gallery. */
-public class GalleryPopupWindow : Window {
+namespace Geetk {
- private const int MAX_HEIGHT = 200;
- private const int SCROLLBAR_SIZE = 20;
+ /** Popup gallery. */
+ public class GalleryPopupWindow : Window {
- private Gee.List<Tile> _tiles;
- private Gee.Map<Tile, Tile> _mapping;
- private uint _rows;
- private uint _columns;
- private Tile _selected_tile;
-
- private ScrolledWindow _internal_window;
- private Table _tile_table;
-
- /** Returns the underlying gallery. */
- public Gallery underlying_gallery { get; construct; }
-
- /**
- * Default constructor.
- *
- * @underlying_gallery The underlying gallery.
- */
- public GalleryPopupWindow (Gallery underlying_gallery) {
- this.type = WindowType.POPUP;
- this.underlying_gallery = underlying_gallery;
- }
-
- construct {
- _tiles = new Gee.ArrayList<Tile> ();
- _mapping = new Gee.HashMap<Tile, Tile> ();
-
- foreach (var tile in this.underlying_gallery.tiles) {
- var copy = tile.copy ();
- copy.show ();
- _tiles.add (copy);
-
- if (tile == this.underlying_gallery.selected_tile) {
- copy.selected = true;
- _selected_tile = tile;
- }
+ private const int MAX_HEIGHT = 200;
+ private const int SCROLLBAR_SIZE = 20;
- _mapping.set (copy, tile);
+ private Gee.List<Tile> _tiles;
+ private Gee.Map<Tile, Tile> _mapping;
+ private uint _rows;
+ private uint _columns;
+ private Tile _selected_tile;
+
+ private ScrolledWindow _internal_window;
+ private Table _tile_table;
+
+ /** Returns the underlying gallery. */
+ public Gallery underlying_gallery { get; construct; }
+
+ /**
+ * Default constructor.
+ *
+ * @underlying_gallery The underlying gallery.
+ */
+ public GalleryPopupWindow (Gallery underlying_gallery) {
+ this.type = WindowType.POPUP;
+ this.underlying_gallery = underlying_gallery;
}
- int width = this.underlying_gallery.allocation.width;
+ construct {
+ _tiles = new Gee.ArrayList<Tile> ();
+ _mapping = new Gee.HashMap<Tile, Tile> ();
+
+ foreach (var tile in this.underlying_gallery.tiles) {
+ var copy = tile.copy ();
+ copy.show ();
+ _tiles.add (copy);
+
+ if (tile == this.underlying_gallery.selected_tile) {
+ copy.selected = true;
+ _selected_tile = tile;
+ }
+
+ _mapping.set (copy, tile);
+ }
+
+ int width = this.underlying_gallery.allocation.width;
- _columns = (uint) (width / this.underlying_gallery.tile_width);
- _rows = (uint) Math.ceil ((double) _tiles.size / _columns);
+ _columns = (uint) (width / this.underlying_gallery.tile_width);
+ _rows = (uint) Math.ceil ((double) _tiles.size / _columns);
- _tile_table = new Table (_rows, _columns, true);
- _tile_table.show ();
- _tile_table.height_request = (int) _rows * this.underlying_gallery.tile_height;
- _tile_table.width_request = (int) _columns * this.underlying_gallery.tile_width;
-
- var vp = new Viewport (null, null);
- vp.show ();
- vp.add (_tile_table); // FIXME: add?
-
- _internal_window = new ScrolledWindow (null, null);
- _internal_window.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
- _internal_window.show ();
- _internal_window.add (vp);
- _internal_window.height_request = int.min (_tile_table.height_request, MAX_HEIGHT) + SCROLLBAR_SIZE;
- _internal_window.width_request = _tile_table.width_request + SCROLLBAR_SIZE;
-
- uint x = 0;
- uint y = 0;
- foreach (var tile in _tiles) {
- var box = new ExtraEventBox ();
- box.show ();
- box.add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
- box.add (tile);
-
- _tile_table.attach_defaults (box, x, x + 1, y, y + 1);
- tile.clicked += tile_clicked;
-
- if (++x == _columns) {
- x = 0;
- ++y;
+ _tile_table = new Table (_rows, _columns, true);
+ _tile_table.show ();
+ _tile_table.height_request = (int) _rows * this.underlying_gallery.tile_height;
+ _tile_table.width_request = (int) _columns * this.underlying_gallery.tile_width;
+
+ var vp = new Viewport (null, null);
+ vp.show ();
+ vp.add (_tile_table); // FIXME: add?
+
+ _internal_window = new ScrolledWindow (null, null);
+ _internal_window.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
+ _internal_window.show ();
+ _internal_window.add (vp);
+ _internal_window.height_request = int.min (_tile_table.height_request, MAX_HEIGHT) + SCROLLBAR_SIZE;
+ _internal_window.width_request = _tile_table.width_request + SCROLLBAR_SIZE;
+
+ uint x = 0;
+ uint y = 0;
+ foreach (var tile in _tiles) {
+ var box = new ExtraEventBox ();
+ box.show ();
+ box.add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+ box.add (tile);
+
+ _tile_table.attach_defaults (box, x, x + 1, y, y + 1);
+ tile.clicked += tile_clicked;
+
+ if (++x == _columns) {
+ x = 0;
+ ++y;
+ }
}
- }
- add (_internal_window);
- this.child.button_press_event += () => {
- return true;
- };
- }
+ add (_internal_window);
+ this.child.button_press_event += () => {
+ return true;
+ };
+ }
- private void tile_clicked (Tile sender) {
- if (_selected_tile != null) {
- _selected_tile.selected = false;
+ private void tile_clicked (Tile sender) {
+ if (_selected_tile != null) {
+ _selected_tile.selected = false;
+ }
+ _selected_tile = sender;
+ _selected_tile.selected = true;
+
+ this.underlying_gallery.selected_tile = _mapping.get (_selected_tile);
+
+ hide ();
}
- _selected_tile = sender;
- _selected_tile.selected = true;
-
- this.underlying_gallery.selected_tile = _mapping.get (_selected_tile);
-
- hide ();
}
}
Modified: trunk/geetk/ribbon/gallery.vala
==============================================================================
--- trunk/geetk/ribbon/gallery.vala (original)
+++ trunk/geetk/ribbon/gallery.vala Thu Jul 24 15:19:51 2008
@@ -4,485 +4,487 @@
using Gdk;
using Cairo;
-/** Gallery of tiles. */
-public class Gallery : Container {
+namespace Geetk {
- private Button _up;
- private Button _down;
- private ToggleButton _expand;
- private GalleryPopupWindow _popup;
-
- private int _first_displayed_tile_index;
- private int _last_displayed_tile_index;
- private int _button_width;
-
- private Requisition _up_req;
- private Requisition _down_req;
- private Requisition _expand_req;
-
- private Gdk.Rectangle _tiles_alloc;
-
- private const double SPACE = 2.0;
- private const double LINE_WIDTH = 1.0;
-
- /** Fired when a Tile has been selected. */
- public signal void tile_selected (Gallery sender, Tile selected_tile);
-
- /** Gets or sets the width of tiles. */
- private int _tile_width;
- public int tile_width {
- set {
- _tile_width = value;
- queue_draw ();
- }
- get { return _tile_width; }
- }
+ /** Gallery of tiles. */
+ public class Gallery : Container {
- /** Gets or sets the height of tiles. */
- private int _tile_height;
- public int tile_height {
- set {
- _tile_height = value;
- queue_draw ();
+ private Button _up;
+ private Button _down;
+ private ToggleButton _expand;
+ private GalleryPopupWindow _popup;
+
+ private int _first_displayed_tile_index;
+ private int _last_displayed_tile_index;
+ private int _button_width;
+
+ private Requisition _up_req;
+ private Requisition _down_req;
+ private Requisition _expand_req;
+
+ private Gdk.Rectangle _tiles_alloc;
+
+ private const double SPACE = 2.0;
+ private const double LINE_WIDTH = 1.0;
+
+ /** Fired when a Tile has been selected. */
+ public signal void tile_selected (Gallery sender, Tile selected_tile);
+
+ /** Gets or sets the width of tiles. */
+ private int _tile_width;
+ public int tile_width {
+ set {
+ _tile_width = value;
+ queue_draw ();
+ }
+ get { return _tile_width; }
}
- get { return _tile_height; }
- }
- /** Gets or sets the spacing between tiles. */
- private int _tile_spacing;
- public int tile_spacing {
- set {
- _tile_spacing = value;
- queue_draw ();
+ /** Gets or sets the height of tiles. */
+ private int _tile_height;
+ public int tile_height {
+ set {
+ _tile_height = value;
+ queue_draw ();
+ }
+ get { return _tile_height; }
}
- get { return _tile_spacing; }
- }
- /** Gets or sets the default number of tiles per row. */
- private int _default_tiles_per_row;
- public int default_tiles_per_row {
- set {
- _default_tiles_per_row = value;
- queue_draw ();
+ /** Gets or sets the spacing between tiles. */
+ private int _tile_spacing;
+ public int tile_spacing {
+ set {
+ _tile_spacing = value;
+ queue_draw ();
+ }
+ get { return _tile_spacing; }
}
- get { return _default_tiles_per_row; }
- }
-
- /** Gets or sets the selected Tile. */
- private Tile _selected_tile;
- public Tile selected_tile {
- set {
- if (_popup != null) {
- Gtk.grab_remove (_popup);
- Gdk.pointer_ungrab (0);
- Gdk.keyboard_ungrab (0);
- _popup.hide ();
-// _popup.destroy ();
- _popup = null;
+ /** Gets or sets the default number of tiles per row. */
+ private int _default_tiles_per_row;
+ public int default_tiles_per_row {
+ set {
+ _default_tiles_per_row = value;
+ queue_draw ();
}
+ get { return _default_tiles_per_row; }
+ }
- if (_selected_tile != null) {
- _selected_tile.selected = false;
- }
- _selected_tile = value;
- if (_selected_tile != null) {
- _selected_tile.selected = true;
+ /** Gets or sets the selected Tile. */
+ private Tile _selected_tile;
+ public Tile selected_tile {
+ set {
+ if (_popup != null) {
+ Gtk.grab_remove (_popup);
+ Gdk.pointer_ungrab (0);
+ Gdk.keyboard_ungrab (0);
- int idx = _tiles.index_of (_selected_tile);
- if (idx != -1) {
- _first_displayed_tile_index = idx / _default_tiles_per_row
- * _default_tiles_per_row;
- _last_displayed_tile_index = -1;
- update_tiles_layout ();
- queue_draw ();
+ _popup.hide ();
+ // _popup.destroy ();
+ _popup = null;
+ }
+
+ if (_selected_tile != null) {
+ _selected_tile.selected = false;
+ }
+ _selected_tile = value;
+ if (_selected_tile != null) {
+ _selected_tile.selected = true;
+
+ int idx = _tiles.index_of (_selected_tile);
+ if (idx != -1) {
+ _first_displayed_tile_index = idx / _default_tiles_per_row
+ * _default_tiles_per_row;
+ _last_displayed_tile_index = -1;
+ update_tiles_layout ();
+ queue_draw ();
+ }
}
}
+ get { return _selected_tile; }
}
- get { return _selected_tile; }
- }
- /** Returns all tiles. */
- private Gee.List<Tile> _tiles;
- public Gee.List<Tile> tiles {
- get {
- return _tiles;
+ /** Returns all tiles. */
+ private Gee.List<Tile> _tiles;
+ public Gee.List<Tile> tiles {
+ get {
+ return _tiles;
+ }
}
- }
- /** Theme used to draw the widget. */
- private Theme _theme = new Theme ();
- public Theme theme {
- set {
- _theme = value;
- queue_draw ();
+ /** Theme used to draw the widget. */
+ private Theme _theme = new Theme ();
+ public Theme theme {
+ set {
+ _theme = value;
+ queue_draw ();
+ }
+ get { return _theme; }
}
- get { return _theme; }
- }
- /** Construction method */
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
-
- _tiles = new Gee.ArrayList<Tile> ();
-
- _default_tiles_per_row = 3;
- _first_displayed_tile_index = 0;
- _last_displayed_tile_index = -1;
-
- _tile_height = 56;
- _tile_width = 72;
- _tile_spacing = 0;
- this.border_width = 2;
-
- _up = new Button.with_label ("\u25B2");
- _up.set_parent (this);
- _up.padding = 0;
- _up.clicked += up_clicked;
-
- _down = new Button.with_label ("\u25BC");
- _down.set_parent (this);
- _down.padding = 0;
- _down.clicked += down_clicked;
-
- _expand = new ToggleButton.with_label ("\u2193");
- _expand.set_parent (this);
- _expand.padding = 0;
- _expand.value_changed += expand_value_changed;
- }
+ /** Construction method */
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
- /**
- * Adds a tile before all existing _tiles.
- *
- * @param tile The tile to add.
- */
- public void prepend_tile (Tile tile) {
- insert_tile (tile, 0);
- }
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
- /**
- * Adds a tile after all existing _tiles.
- *
- * @param tile The tile to add.
- */
- public void append_tile (Tile tile) {
- insert_tile (tile, -1);
- }
+ _tiles = new Gee.ArrayList<Tile> ();
- /**
- * Inserts a tile at the specified location.
- *
- * @param tile The tile to add.
- * @param index The index (starting at 0) at which the tile must be
- * inserted, or -1 to insert the tile after all existing
- * tiles.
- */
- public void insert_tile (Tile tile, int index) {
- if (index == -1 || index == _tiles.size) {
- _tiles.add (tile);
- } else {
- _tiles.insert (index, tile);
- }
-
- if (_tiles.size == 1) {
- this.selected_tile = tile;
- }
-
- // t.set_parent (this);
- tile.visible = true;
- tile.clicked += tile_clicked;
- }
+ _default_tiles_per_row = 3;
+ _first_displayed_tile_index = 0;
+ _last_displayed_tile_index = -1;
- /**
- * Removes the tile at the specified index.
- *
- * @param index Index of the tile to remove.
- */
- public void remove_tile (int index) {
- var tile = _tiles.get (index);
- tile.clicked -= tile_clicked;
- tile.unparent ();
- if (_selected_tile == tile) {
- _selected_tile = null;
- }
+ _tile_height = 56;
+ _tile_width = 72;
+ _tile_spacing = 0;
+ this.border_width = 2;
+
+ _up = new Button.with_label ("\u25B2");
+ _up.set_parent (this);
+ _up.padding = 0;
+ _up.clicked += up_clicked;
+
+ _down = new Button.with_label ("\u25BC");
+ _down.set_parent (this);
+ _down.padding = 0;
+ _down.clicked += down_clicked;
+
+ _expand = new ToggleButton.with_label ("\u2193");
+ _expand.set_parent (this);
+ _expand.padding = 0;
+ _expand.value_changed += expand_value_changed;
+ }
+
+ /**
+ * Adds a tile before all existing _tiles.
+ *
+ * @param tile The tile to add.
+ */
+ public void prepend_tile (Tile tile) {
+ insert_tile (tile, 0);
+ }
+
+ /**
+ * Adds a tile after all existing _tiles.
+ *
+ * @param tile The tile to add.
+ */
+ public void append_tile (Tile tile) {
+ insert_tile (tile, -1);
+ }
+
+ /**
+ * Inserts a tile at the specified location.
+ *
+ * @param tile The tile to add.
+ * @param index The index (starting at 0) at which the tile must be
+ * inserted, or -1 to insert the tile after all existing
+ * tiles.
+ */
+ public void insert_tile (Tile tile, int index) {
+ if (index == -1 || index == _tiles.size) {
+ _tiles.add (tile);
+ } else {
+ _tiles.insert (index, tile);
+ }
- _tiles.remove_at (index);
- }
+ if (_tiles.size == 1) {
+ this.selected_tile = tile;
+ }
- private void up_clicked () {
- move_up ();
- }
-
- private void down_clicked () {
- move_down ();
- }
+ // t.set_parent (this);
+ tile.visible = true;
+ tile.clicked += tile_clicked;
+ }
+
+ /**
+ * Removes the tile at the specified index.
+ *
+ * @param index Index of the tile to remove.
+ */
+ public void remove_tile (int index) {
+ var tile = _tiles.get (index);
+ tile.clicked -= tile_clicked;
+ tile.unparent ();
+ if (_selected_tile == tile) {
+ _selected_tile = null;
+ }
- private void expand_value_changed () {
- if (_expand.value) {
- _popup = new GalleryPopupWindow (this);
- _popup.realize += () => {
- int x, y;
- get_parent_window ().get_origin (out x, out y);
- x += this.allocation.x;
- y += this.allocation.y;
- _popup.window.move (x, y);
- };
-
- _popup.hide += () => {
- _expand.value_changed -= expand_value_changed;
- _expand.value = false;
- _expand.queue_draw ();
- _expand.value_changed += expand_value_changed;
- };
- _popup.show ();
-
- _popup.button_release_event += on_button_released;
- _popup.add_events (Gdk.EventMask.BUTTON_PRESS_MASK);
- Gtk.grab_add (_popup);
-
- Gdk.GrabStatus grabbed = Gdk.pointer_grab (_popup.window, true,
- Gdk.EventMask.BUTTON_RELEASE_MASK, null, null, 0);
- if (grabbed == Gdk.GrabStatus.SUCCESS) {
- grabbed = Gdk.keyboard_grab (_popup.window, true, 0);
+ _tiles.remove_at (index);
+ }
- if (grabbed != Gdk.GrabStatus.SUCCESS) {
+ private void up_clicked () {
+ move_up ();
+ }
+
+ private void down_clicked () {
+ move_down ();
+ }
+
+ private void expand_value_changed () {
+ if (_expand.value) {
+ _popup = new GalleryPopupWindow (this);
+ _popup.realize += () => {
+ int x, y;
+ get_parent_window ().get_origin (out x, out y);
+ x += this.allocation.x;
+ y += this.allocation.y;
+ _popup.window.move (x, y);
+ };
+
+ _popup.hide += () => {
+ _expand.value_changed -= expand_value_changed;
+ _expand.value = false;
+ _expand.queue_draw ();
+ _expand.value_changed += expand_value_changed;
+ };
+ _popup.show ();
+
+ _popup.button_release_event += on_button_released;
+ _popup.add_events (Gdk.EventMask.BUTTON_PRESS_MASK);
+ Gtk.grab_add (_popup);
+
+ Gdk.GrabStatus grabbed = Gdk.pointer_grab (_popup.window, true,
+ Gdk.EventMask.BUTTON_RELEASE_MASK, null, null, 0);
+ if (grabbed == Gdk.GrabStatus.SUCCESS) {
+ grabbed = Gdk.keyboard_grab (_popup.window, true, 0);
+
+ if (grabbed != Gdk.GrabStatus.SUCCESS) {
+ Gtk.grab_remove (_popup);
+ _popup.hide ();
+ // _popup.destroy();
+ _popup = null;
+ return;
+ }
+ } else {
Gtk.grab_remove (_popup);
_popup.hide ();
-// _popup.destroy();
+ // _popup.destroy ();
_popup = null;
- return;
}
} else {
- Gtk.grab_remove (_popup);
- _popup.hide ();
-// _popup.destroy ();
- _popup = null;
- }
- } else {
- if (_popup != null) {
- Gtk.grab_remove (_popup);
- _popup.hide ();
-// _popup.destroy ();
- _popup = null;
+ if (_popup != null) {
+ Gtk.grab_remove (_popup);
+ _popup.hide ();
+ // _popup.destroy ();
+ _popup = null;
+ }
}
}
- }
-
- private void tile_clicked (Tile sender) {
- if (_selected_tile != null) {
- _selected_tile.selected = false;
- }
- _selected_tile = sender;
- _selected_tile.selected = true;
- on_tile_selected (_selected_tile);
- }
- private void move_up () {
- if (_first_displayed_tile_index > 0) {
- _first_displayed_tile_index = -1;
- _last_displayed_tile_index = _first_displayed_tile_index - 1;
- }
- update_tiles_layout ();
- queue_draw ();
- }
-
- private void move_down () {
- if (_last_displayed_tile_index < _tiles.size - 1) {
- _first_displayed_tile_index = _last_displayed_tile_index + 1;
- _last_displayed_tile_index = -1;
+ private void tile_clicked (Tile sender) {
+ if (_selected_tile != null) {
+ _selected_tile.selected = false;
+ }
+ _selected_tile = sender;
+ _selected_tile.selected = true;
+ on_tile_selected (_selected_tile);
}
- update_tiles_layout ();
- queue_draw ();
- }
- /**
- * Fires the selected_tile event.
- *
- * @param selected_tile The Tile that has been selected.
- */
- protected void on_tile_selected (Tile selected_tile) {
- tile_selected (this, selected_tile);
- }
-
- private bool on_button_released (GalleryPopupWindow sender, EventButton event) {
- if (_popup != null) {
- Gtk.grab_remove (_popup);
- Gdk.pointer_ungrab (0);
- Gdk.keyboard_ungrab (0);
-
- _popup.hide ();
- _popup.destroy ();
- _popup = null;
+ private void move_up () {
+ if (_first_displayed_tile_index > 0) {
+ _first_displayed_tile_index = -1;
+ _last_displayed_tile_index = _first_displayed_tile_index - 1;
+ }
+ update_tiles_layout ();
+ queue_draw ();
}
- return false;
- }
-
- private void update_tiles_layout () {
- Gdk.Rectangle tile_alloc;
- tile_alloc.x = _tiles_alloc.x;
- tile_alloc.y = _tiles_alloc.y;
- tile_alloc.height = _tiles_alloc.height;
- tile_alloc.width = _tile_width;
- int max_tiles = (_tiles_alloc.width + _tile_spacing)
- / (_tile_width + _tile_spacing);
-
- if (_first_displayed_tile_index == -1) {
- _first_displayed_tile_index = _last_displayed_tile_index - max_tiles + 1;
- if (_first_displayed_tile_index < 0) {
- _last_displayed_tile_index -= _first_displayed_tile_index;
- _first_displayed_tile_index = 0;
+ private void move_down () {
+ if (_last_displayed_tile_index < _tiles.size - 1) {
+ _first_displayed_tile_index = _last_displayed_tile_index + 1;
+ _last_displayed_tile_index = -1;
}
- } else if (_last_displayed_tile_index == -1) {
- _last_displayed_tile_index = _first_displayed_tile_index + max_tiles - 1;
+ update_tiles_layout ();
+ queue_draw ();
}
- if (_last_displayed_tile_index >= _tiles.size) {
- _last_displayed_tile_index = _tiles.size - 1;
+ /**
+ * Fires the selected_tile event.
+ *
+ * @param selected_tile The Tile that has been selected.
+ */
+ protected void on_tile_selected (Tile selected_tile) {
+ tile_selected (this, selected_tile);
}
- _up.enabled = _first_displayed_tile_index > 0;
- _down.enabled = _last_displayed_tile_index < _tiles.size - 1;
+ private bool on_button_released (GalleryPopupWindow sender, EventButton event) {
+ if (_popup != null) {
+ Gtk.grab_remove (_popup);
+ Gdk.pointer_ungrab (0);
+ Gdk.keyboard_ungrab (0);
- for (int i = 0; i < _first_displayed_tile_index; i++) {
- if (_tiles.get (i).parent != null) {
- _tiles.get (i).unparent ();
+ _popup.hide ();
+ _popup.destroy ();
+ _popup = null;
}
+ return false;
}
- for (int i = _last_displayed_tile_index + 1; i < _tiles.size; i++) {
- if (_tiles.get (i).parent != null) {
- _tiles.get (i).unparent ();
+
+ private void update_tiles_layout () {
+ Gdk.Rectangle tile_alloc;
+ tile_alloc.x = _tiles_alloc.x;
+ tile_alloc.y = _tiles_alloc.y;
+ tile_alloc.height = _tiles_alloc.height;
+ tile_alloc.width = _tile_width;
+
+ int max_tiles = (_tiles_alloc.width + _tile_spacing)
+ / (_tile_width + _tile_spacing);
+
+ if (_first_displayed_tile_index == -1) {
+ _first_displayed_tile_index = _last_displayed_tile_index - max_tiles + 1;
+ if (_first_displayed_tile_index < 0) {
+ _last_displayed_tile_index -= _first_displayed_tile_index;
+ _first_displayed_tile_index = 0;
+ }
+ } else if (_last_displayed_tile_index == -1) {
+ _last_displayed_tile_index = _first_displayed_tile_index + max_tiles - 1;
}
- }
- for (int i = _first_displayed_tile_index; i <= _last_displayed_tile_index; i++) {
- Tile t = _tiles.get (i);
-
- if (t.parent == null) {
- t.set_parent (this);
+ if (_last_displayed_tile_index >= _tiles.size) {
+ _last_displayed_tile_index = _tiles.size - 1;
}
- Requisition req;
- t.size_request (req);
+ _up.enabled = _first_displayed_tile_index > 0;
+ _down.enabled = _last_displayed_tile_index < _tiles.size - 1;
- t.size_allocate (tile_alloc);
- tile_alloc.x += tile_alloc.width + _tile_spacing;
- }
- }
+ for (int i = 0; i < _first_displayed_tile_index; i++) {
+ if (_tiles.get (i).parent != null) {
+ _tiles.get (i).unparent ();
+ }
+ }
+ for (int i = _last_displayed_tile_index + 1; i < _tiles.size; i++) {
+ if (_tiles.get (i).parent != null) {
+ _tiles.get (i).unparent ();
+ }
+ }
- protected override void forall (bool include_internals, Gtk.Callback callback) {
-// if (include_internals) {
- callback (_up);
- callback (_down);
- callback (_expand);
-// }
+ for (int i = _first_displayed_tile_index; i <= _last_displayed_tile_index; i++) {
+ Tile t = _tiles.get (i);
+
+ if (t.parent == null) {
+ t.set_parent (this);
+ }
- for (int i = _first_displayed_tile_index; i <= _last_displayed_tile_index; i++) {
- callback (_tiles.get (i));
- }
- }
+ Requisition req;
+ t.size_request (req);
- protected override void size_request (Requisition requisition) {
-// base.size_requested (requisition);
+ t.size_allocate (tile_alloc);
+ tile_alloc.x += tile_alloc.width + _tile_spacing;
+ }
+ }
- _up.size_request (_up_req);
- _down.size_request (_down_req);
- _expand.size_request (_expand_req);
-
- _button_width = int.max (_up_req.width,
- int.max (_down_req.width, _expand_req.width));
- int btn_height = _up_req.height + _down_req.height + _expand_req.height;
-
- int count = int.min (_tiles.size, _default_tiles_per_row);
- requisition.width = _button_width + (int) SPACE
- + 2 * (int) LINE_WIDTH
- + count * _tile_width
- + (count + 1) * _tile_spacing
- + 2 * (int) this.border_width;
- requisition.height = int.max (_tile_height + 2 * (_tile_spacing + (int) LINE_WIDTH),
- btn_height) + 2 * (int) this.border_width;
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ // if (include_internals) {
+ callback (_up);
+ callback (_down);
+ callback (_expand);
+ // }
- if (this.width_request != -1) {
- requisition.width = this.width_request;
- }
- if (this.height_request != -1) {
- requisition.height = this.height_request;
+ for (int i = _first_displayed_tile_index; i <= _last_displayed_tile_index; i++) {
+ callback (_tiles.get (i));
+ }
}
- }
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocate (allocation);
- this.allocation = (Allocation) allocation;
-
- allocation.x += (int) this.border_width;
- allocation.y += (int) this.border_width;
- allocation.width -= 2 * (int) this.border_width;
- allocation.height -= 2 * (int) this.border_width;
-
- Gdk.Rectangle btn_alloc;
- btn_alloc.width = _button_width;
- btn_alloc.x = allocation.x + allocation.width - btn_alloc.width + 1;
-
- btn_alloc.y = allocation.y;
- btn_alloc.height = _up_req.height;
- _up.size_allocate (btn_alloc);
-
- btn_alloc.y += btn_alloc.height;
- btn_alloc.height = _down_req.height;
- _down.size_allocate (btn_alloc);
-
- btn_alloc.y += btn_alloc.height;
- btn_alloc.height = _expand_req.height;
- _expand.size_allocate (btn_alloc);
-
- _tiles_alloc.x = allocation.x + (int) LINE_WIDTH + _tile_spacing;
- _tiles_alloc.y = allocation.y + (int) LINE_WIDTH + _tile_spacing;
- _tiles_alloc.width = btn_alloc.x - _tiles_alloc.x - _tile_spacing
- - (int) SPACE - 2 * (int) LINE_WIDTH;
- _tiles_alloc.height = allocation.height - 2 * (_tile_spacing + (int) LINE_WIDTH);
+ protected override void size_request (Requisition requisition) {
+ // base.size_requested (requisition);
- update_tiles_layout ();
- }
+ _up.size_request (_up_req);
+ _down.size_request (_down_req);
+ _expand.size_request (_expand_req);
+
+ _button_width = int.max (_up_req.width,
+ int.max (_down_req.width, _expand_req.width));
+ int btn_height = _up_req.height + _down_req.height + _expand_req.height;
+
+ int count = int.min (_tiles.size, _default_tiles_per_row);
+ requisition.width = _button_width + (int) SPACE
+ + 2 * (int) LINE_WIDTH
+ + count * _tile_width
+ + (count + 1) * _tile_spacing
+ + 2 * (int) this.border_width;
+ requisition.height = int.max (_tile_height + 2 * (_tile_spacing + (int) LINE_WIDTH),
+ btn_height) + 2 * (int) this.border_width;
- protected override bool expose_event (Gdk.EventExpose evnt) {
- var cr = Gdk.cairo_create (this.window);
+ if (this.width_request != -1) {
+ requisition.width = this.width_request;
+ }
+ if (this.height_request != -1) {
+ requisition.height = this.height_request;
+ }
+ }
- cr.rectangle (evnt.area.x, evnt.area.y,
- evnt.area.width, evnt.area.height);
- cr.clip ();
- draw (cr);
-
-// cr.target.dispose ();
-// cr.dispose ();
-
-// return base.expose_event (evnt);
- // *** workaround ***
- ((Widget) _up).expose_event (evnt);
- ((Widget) _down).expose_event (evnt);
- ((Widget) _expand).expose_event (evnt);
- for (int i = _first_displayed_tile_index; i <= _last_displayed_tile_index; i++) {
- ((Widget) _tiles.get (i)).expose_event (evnt);
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocate (allocation);
+ this.allocation = (Allocation) allocation;
+
+ allocation.x += (int) this.border_width;
+ allocation.y += (int) this.border_width;
+ allocation.width -= 2 * (int) this.border_width;
+ allocation.height -= 2 * (int) this.border_width;
+
+ Gdk.Rectangle btn_alloc;
+ btn_alloc.width = _button_width;
+ btn_alloc.x = allocation.x + allocation.width - btn_alloc.width + 1;
+
+ btn_alloc.y = allocation.y;
+ btn_alloc.height = _up_req.height;
+ _up.size_allocate (btn_alloc);
+
+ btn_alloc.y += btn_alloc.height;
+ btn_alloc.height = _down_req.height;
+ _down.size_allocate (btn_alloc);
+
+ btn_alloc.y += btn_alloc.height;
+ btn_alloc.height = _expand_req.height;
+ _expand.size_allocate (btn_alloc);
+
+ _tiles_alloc.x = allocation.x + (int) LINE_WIDTH + _tile_spacing;
+ _tiles_alloc.y = allocation.y + (int) LINE_WIDTH + _tile_spacing;
+ _tiles_alloc.width = btn_alloc.x - _tiles_alloc.x - _tile_spacing
+ - (int) SPACE - 2 * (int) LINE_WIDTH;
+ _tiles_alloc.height = allocation.height - 2 * (_tile_spacing + (int) LINE_WIDTH);
+
+ update_tiles_layout ();
+ }
+
+ protected override bool expose_event (Gdk.EventExpose evnt) {
+ var cr = Gdk.cairo_create (this.window);
+
+ cr.rectangle (evnt.area.x, evnt.area.y,
+ evnt.area.width, evnt.area.height);
+ cr.clip ();
+ draw (cr);
+
+ // cr.target.dispose ();
+ // cr.dispose ();
+
+ // return base.expose_event (evnt);
+ // *** workaround ***
+ ((Widget) _up).expose_event (evnt);
+ ((Widget) _down).expose_event (evnt);
+ ((Widget) _expand).expose_event (evnt);
+ for (int i = _first_displayed_tile_index; i <= _last_displayed_tile_index; i++) {
+ ((Widget) _tiles.get (i)).expose_event (evnt);
+ }
+ return false;
+ // *** workaround ***
}
- return false;
- // *** workaround ***
- }
- protected void draw (Context cr) {
- Rectangle alloc;
- alloc.x = this.allocation.x;
- alloc.y = this.allocation.y;
- alloc.width = this.allocation.width;
- alloc.height = this.allocation.height;
- Rectangle tiles;
- tiles.x = _tiles_alloc.x - _tile_spacing;
- tiles.y = _tiles_alloc.y - _tile_spacing;
- tiles.width = _tiles_alloc.width + 2 * _tile_spacing;
- tiles.height = _tiles_alloc.height + 2 * _tile_spacing;
- _theme.draw_gallery (cr, alloc, tiles, this);
+ protected void draw (Context cr) {
+ Rectangle alloc;
+ alloc.x = this.allocation.x;
+ alloc.y = this.allocation.y;
+ alloc.width = this.allocation.width;
+ alloc.height = this.allocation.height;
+ Rectangle tiles;
+ tiles.x = _tiles_alloc.x - _tile_spacing;
+ tiles.y = _tiles_alloc.y - _tile_spacing;
+ tiles.width = _tiles_alloc.width + 2 * _tile_spacing;
+ tiles.height = _tiles_alloc.height + 2 * _tile_spacing;
+ _theme.draw_gallery (cr, alloc, tiles, this);
+ }
}
}
-
Modified: trunk/geetk/ribbon/group-style.vala
==============================================================================
--- trunk/geetk/ribbon/group-style.vala (original)
+++ trunk/geetk/ribbon/group-style.vala Thu Jul 24 15:19:51 2008
@@ -1,10 +1,13 @@
-/**
- * Position of a widget in a group of widget.
- */
-public enum GroupStyle {
- ALONE,
- LEFT,
- CENTER,
- RIGHT
+namespace Geetk {
+
+ /**
+ * Position of a widget in a group of widget.
+ */
+ public enum GroupStyle {
+ ALONE,
+ LEFT,
+ CENTER,
+ RIGHT
+ }
}
Modified: trunk/geetk/ribbon/quick-access-toolbar.vala
==============================================================================
--- trunk/geetk/ribbon/quick-access-toolbar.vala (original)
+++ trunk/geetk/ribbon/quick-access-toolbar.vala Thu Jul 24 15:19:51 2008
@@ -2,125 +2,128 @@
using Gtk;
using Gee;
-public class QuickAccessToolbar : Container {
+namespace Geetk {
- private Gee.List<Widget> _widgets;
- private int[] _widths;
+ public class QuickAccessToolbar : Container {
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+ private Gee.List<Widget> _widgets;
+ private int[] _widths;
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
-
- _widgets = new Gee.ArrayList<Widget> ();
- }
-
- /**
- * Adds a widget before all existing widgets.
- *
- * @param widget The widget to add.
- */
- public void prepend (Widget widget) {
- insert (widget, 0);
- }
-
- /**
- * Adds a widget after all existing widgets.
- *
- * @param widget The widget to add.
- */
- public void append (Widget widget) {
- insert (widget, -1);
- }
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+
+ _widgets = new Gee.ArrayList<Widget> ();
+ }
+
+ /**
+ * Adds a widget before all existing widgets.
+ *
+ * @param widget The widget to add.
+ */
+ public void prepend (Widget widget) {
+ insert (widget, 0);
+ }
+
+ /**
+ * Adds a widget after all existing widgets.
+ *
+ * @param widget The widget to add.
+ */
+ public void append (Widget widget) {
+ insert (widget, -1);
+ }
+
+ /**
+ * Inserts a widget at the specified location.</summary>
+ *
+ * @param widget The widget to add.
+ * @param index The index (starting at 0) at which the widget must
+ * be inserted, or -1 to insert the widget after all
+ * existing widgets.
+ */
+ public void insert (Widget widget, int index) {
+ widget.set_parent (this);
+ widget.visible = true;
+
+ if (index == -1) {
+ _widgets.add (widget);
+ } else {
+ _widgets.insert (index, widget);
+ }
- /**
- * Inserts a widget at the specified location.</summary>
- *
- * @param widget The widget to add.
- * @param index The index (starting at 0) at which the widget must
- * be inserted, or -1 to insert the widget after all
- * existing widgets.
- */
- public void insert (Widget widget, int index) {
- widget.set_parent (this);
- widget.visible = true;
-
- if (index == -1) {
- _widgets.add (widget);
- } else {
- _widgets.insert (index, widget);
+ show_all ();
}
- show_all ();
- }
-
- /**
- * Removes the widget at the specified index.
- *
- * @param index Index of the widget to remove.
- */
- public void remove (int index) {
- if (index == -1) {
- index = _widgets.size -1;
- }
+ /**
+ * Removes the widget at the specified index.
+ *
+ * @param index Index of the widget to remove.
+ */
+ public void remove (int index) {
+ if (index == -1) {
+ index = _widgets.size -1;
+ }
- _widgets.get (index).parent = null;
- _widgets.remove_at (index);
+ _widgets.get (index).parent = null;
+ _widgets.remove_at (index);
- show_all ();
- }
+ show_all ();
+ }
- protected override void forall (bool include_internals, Gtk.Callback callback) {
- foreach (var widget in _widgets) {
- if (widget.visible) {
- callback (widget);
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ foreach (var widget in _widgets) {
+ if (widget.visible) {
+ callback (widget);
+ }
}
}
- }
- protected override void size_request (Requisition requisition) {
- base.size_request (requisition);
+ protected override void size_request (Requisition requisition) {
+ base.size_request (requisition);
- if (_widths == null || _widths.length != _widgets.size) {
- _widths = new int[_widgets.size];
- }
+ if (_widths == null || _widths.length != _widgets.size) {
+ _widths = new int[_widgets.size];
+ }
- requisition.height = 16;
- requisition.width = 0;
+ requisition.height = 16;
+ requisition.width = 0;
- int i = 0;
- foreach (var button in _widgets) {
- button.height_request = requisition.height;
- Requisition req;
- button.size_request (req);
- requisition.width += req.width;
- _widths[i++] = req.width;
- }
- if (this.height_request != -1) {
- requisition.height = this.height_request;
- }
- if (this.width_request != -1) {
- requisition.width = this.width_request;
+ int i = 0;
+ foreach (var button in _widgets) {
+ button.height_request = requisition.height;
+ Requisition req;
+ button.size_request (req);
+ requisition.width += req.width;
+ _widths[i++] = req.width;
+ }
+ if (this.height_request != -1) {
+ requisition.height = this.height_request;
+ }
+ if (this.width_request != -1) {
+ requisition.width = this.width_request;
+ }
}
- }
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocate (allocation);
- this.allocation = (Allocation) allocation; // XXX workaround
-
- int i = 0;
- int x = allocation.x;
- foreach (var button in _widgets) {
- Gdk.Rectangle r;
- r.x = x;
- r.y = allocation.y;
- r.width = _widths[i];
- r.height = allocation.height;
- button.size_allocate (r);
- x += r.width;
- i++;
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocate (allocation);
+ this.allocation = (Allocation) allocation; // XXX workaround
+
+ int i = 0;
+ int x = allocation.x;
+ foreach (var button in _widgets) {
+ Gdk.Rectangle r;
+ r.x = x;
+ r.y = allocation.y;
+ r.width = _widths[i];
+ r.height = allocation.height;
+ button.size_allocate (r);
+ x += r.width;
+ i++;
+ }
}
}
}
Modified: trunk/geetk/ribbon/ribbon-group.vala
==============================================================================
--- trunk/geetk/ribbon/ribbon-group.vala (original)
+++ trunk/geetk/ribbon/ribbon-group.vala Thu Jul 24 15:19:51 2008
@@ -3,280 +3,282 @@
using Gtk;
using Gdk;
-/** Ribbon group. */
-public class RibbonGroup : Bin {
+namespace Geetk {
- private Pango.Layout _label_layout;
- private Button _expand_button;
+ /** Ribbon group. */
+ public class RibbonGroup : Bin {
- private double _bar_height;
- private double _bar_width;
+ private Pango.Layout _label_layout;
+ private Button _expand_button;
- private const double CHILD_PADDING = 1.0;
- private const double LINE_WIDTH = 1.0;
- private const double SPACE = 2.0;
-
- /** Fired whenever the expand button is clicked. */
- public signal void expanded (RibbonGroup sender);
-
- // XXX: is it possible to do something when someone connects/disconnects the signal?
-// {
-// add {
-// _expand_button.visible = has_expand_listener ();
-// }
-// remove {
-// _expand_button.visible = has_expand_listener ();
-// }
-// }
-
- /** Displayed label. */
- private string _label;
- public string label {
- set {
- _label = value;
-
- if (_label == null) {
- _label_layout = null;
- } else if (_label_layout == null) {
- _label_layout = create_pango_layout (_label);
- } else {
- // XXX: size () really needed?
- _label_layout.set_text (_label, (int) _label.size ());
+ private double _bar_height;
+ private double _bar_width;
+
+ private const double CHILD_PADDING = 1.0;
+ private const double LINE_WIDTH = 1.0;
+ private const double SPACE = 2.0;
+
+ /** Fired whenever the expand button is clicked. */
+ public signal void expanded (RibbonGroup sender);
+
+ // XXX: is it possible to do something when someone connects/disconnects the signal?
+ // {
+ // add {
+ // _expand_button.visible = has_expand_listener ();
+ // }
+ // remove {
+ // _expand_button.visible = has_expand_listener ();
+ // }
+ // }
+
+ /** Displayed label. */
+ private string _label;
+ public string label {
+ set {
+ _label = value;
+
+ if (_label == null) {
+ _label_layout = null;
+ } else if (_label_layout == null) {
+ _label_layout = create_pango_layout (_label);
+ } else {
+ // XXX: size () really needed?
+ _label_layout.set_text (_label, (int) _label.size ());
+ }
+ queue_draw ();
}
- queue_draw ();
+ get { return _label; }
}
- get { return _label; }
- }
- /** Theme used to draw the widget. */
- private Theme _theme = new Theme ();
- public Theme theme {
- set {
- _theme = value;
- queue_draw ();
+ /** Theme used to draw the widget. */
+ private Theme _theme = new Theme ();
+ public Theme theme {
+ set {
+ _theme = value;
+ queue_draw ();
+ }
+ get { return _theme; }
}
- get { return _theme; }
- }
- /** Position of the label. */
- private PositionType _label_position = PositionType.BOTTOM;
- public PositionType label_position {
- set {
- _label_position = value;
- queue_draw ();
+ /** Position of the label. */
+ private PositionType _label_position = PositionType.BOTTOM;
+ public PositionType label_position {
+ set {
+ _label_position = value;
+ queue_draw ();
+ }
+ get { return _label_position; }
}
- get { return _label_position; }
- }
-
- /** Construction method. */
- construct {
- // This is a NO_WINDOW widget => it does not have its own Gdk Window
- // => it can be transparent
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
-
- this.label = null;
- this.height_request = 92;
-
- _expand_button = new Button.with_label ("\u21F2");
- _expand_button.padding = 0;
- _expand_button.visible = false;
- _expand_button.set_parent (this);
- _expand_button.clicked += () => {
- expanded (this);
- };
- }
-
- // XXX: workaround
- private bool has_expand_listener () {
- var signal_id = Signal.lookup ("expanded", typeof (RibbonGroup));
- return Signal.has_handler_pending (this, signal_id, 0, true);
- }
- protected override void forall (bool include_internals, Gtk.Callback callback) {
- base.forall (include_internals, callback);
- if (_expand_button != null && _expand_button.visible) {
- callback (_expand_button);
- }
- }
+ /** Construction method. */
+ construct {
+ // This is a NO_WINDOW widget => it does not have its own Gdk Window
+ // => it can be transparent
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
- protected override void size_request (Requisition requisition) {
-// base.size_request (requisition);
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
- int lw, lh;
+ this.label = null;
+ this.height_request = 92;
- if (_label_position == PositionType.TOP
- || _label_position == PositionType.BOTTOM) {
- _label_layout.get_pixel_size (out lw, out lh);
- } else {
- _label_layout.get_pixel_size (out lh, out lw);
+ _expand_button = new Button.with_label ("\u21F2");
+ _expand_button.padding = 0;
+ _expand_button.visible = false;
+ _expand_button.set_parent (this);
+ _expand_button.clicked += () => {
+ expanded (this);
+ };
}
- double frame_size = 2 * LINE_WIDTH + CHILD_PADDING;
+ // XXX: workaround
+ private bool has_expand_listener () {
+ var signal_id = Signal.lookup ("expanded", typeof (RibbonGroup));
+ return Signal.has_handler_pending (this, signal_id, 0, true);
+ }
- _bar_height = lh + 2 * SPACE;
- _bar_width = lw + 2 * SPACE;
-
- if (_expand_button != null && _expand_button.visible) {
- if (_label_position == PositionType.TOP
- || _label_position == PositionType.BOTTOM) {
- _expand_button.set_size_request (lh, lh);
- } else {
- _expand_button.set_size_request (lw, lw);
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ base.forall (include_internals, callback);
+ if (_expand_button != null && _expand_button.visible) {
+ callback (_expand_button);
}
+ }
+
+ protected override void size_request (Requisition requisition) {
+ // base.size_request (requisition);
- Requisition req; // FIXME
- _expand_button.size_request (req);
+ int lw, lh;
if (_label_position == PositionType.TOP
|| _label_position == PositionType.BOTTOM) {
- _bar_width += _expand_button.width_request + (int) SPACE;
+ _label_layout.get_pixel_size (out lw, out lh);
} else {
- _bar_height += _expand_button.height_request + (int) SPACE;
+ _label_layout.get_pixel_size (out lh, out lw);
}
- }
- Requisition child_requisition = Requisition ();
+ double frame_size = 2 * LINE_WIDTH + CHILD_PADDING;
- if (this.child != null && this.child.visible) {
- if (this.height_request != -1) {
- int left = this.height_request;
+ _bar_height = lh + 2 * SPACE;
+ _bar_width = lw + 2 * SPACE;
+
+ if (_expand_button != null && _expand_button.visible) {
if (_label_position == PositionType.TOP
|| _label_position == PositionType.BOTTOM) {
- left -= (int) (2 * frame_size + _bar_height);
+ _expand_button.set_size_request (lh, lh);
} else {
- left -= (int) (2 * frame_size);
+ _expand_button.set_size_request (lw, lw);
}
- this.child.height_request = left;
- }
- if (this.width_request != -1) {
- int left = this.width_request;
+ Requisition req; // FIXME
+ _expand_button.size_request (req);
+
if (_label_position == PositionType.TOP
|| _label_position == PositionType.BOTTOM) {
- left -= (int) (2 * frame_size);
+ _bar_width += _expand_button.width_request + (int) SPACE;
} else {
- left -= (int) (2 * frame_size + _bar_width);
+ _bar_height += _expand_button.height_request + (int) SPACE;
}
- this.child.width_request = left;
}
- this.child.size_request (child_requisition);
- }
- if (this.width_request == -1) {
+ Requisition child_requisition = Requisition ();
+
if (this.child != null && this.child.visible) {
- requisition.width = child_requisition.width + (int) (2 * frame_size);
+ if (this.height_request != -1) {
+ int left = this.height_request;
+ if (_label_position == PositionType.TOP
+ || _label_position == PositionType.BOTTOM) {
+ left -= (int) (2 * frame_size + _bar_height);
+ } else {
+ left -= (int) (2 * frame_size);
+ }
- if (_label_position == PositionType.LEFT
- || _label_position == PositionType.RIGHT) {
- requisition.width += (int) _bar_width;
+ this.child.height_request = left;
}
- } else {
- requisition.width = (int) (2 * frame_size + _bar_width);
+ if (this.width_request != -1) {
+ int left = this.width_request;
+ if (_label_position == PositionType.TOP
+ || _label_position == PositionType.BOTTOM) {
+ left -= (int) (2 * frame_size);
+ } else {
+ left -= (int) (2 * frame_size + _bar_width);
+ }
+ this.child.width_request = left;
+ }
+ this.child.size_request (child_requisition);
}
- }
- if (this.height_request == -1) {
- if (this.child != null && this.child.visible) {
- requisition.height = child_requisition.height + (int) (2 * frame_size);
+ if (this.width_request == -1) {
+ if (this.child != null && this.child.visible) {
+ requisition.width = child_requisition.width + (int) (2 * frame_size);
- if (_label_position == PositionType.TOP
- || _label_position == PositionType.BOTTOM) {
- requisition.height += (int) _bar_height;
+ if (_label_position == PositionType.LEFT
+ || _label_position == PositionType.RIGHT) {
+ requisition.width += (int) _bar_width;
+ }
+ } else {
+ requisition.width = (int) (2 * frame_size + _bar_width);
+ }
+ }
+
+ if (this.height_request == -1) {
+ if (this.child != null && this.child.visible) {
+ requisition.height = child_requisition.height + (int) (2 * frame_size);
+
+ if (_label_position == PositionType.TOP
+ || _label_position == PositionType.BOTTOM) {
+ requisition.height += (int) _bar_height;
+ }
+ } else {
+ requisition.height = (int) (2 * frame_size + _bar_height);
}
- } else {
- requisition.height = (int) (2 * frame_size + _bar_height);
}
}
- }
- protected override void size_allocate (Rectangle allocation) {
-// base.size_allocate (allocation);
- this.allocation = (Allocation) allocation; // workaround
-
- if (_expand_button != null && _expand_button.visible) {
- double frame_size = 2 * LINE_WIDTH + SPACE;
- Rectangle r;
- r.height = _expand_button.height_request;
- r.width = _expand_button.width_request;
+ protected override void size_allocate (Rectangle allocation) {
+ // base.size_allocate (allocation);
+ this.allocation = (Allocation) allocation; // workaround
+
+ if (_expand_button != null && _expand_button.visible) {
+ double frame_size = 2 * LINE_WIDTH + SPACE;
+ Rectangle r;
+ r.height = _expand_button.height_request;
+ r.width = _expand_button.width_request;
- if (_label_position == PositionType.LEFT) {
- r.x = allocation.x + (int) frame_size;
- } else {
- r.x = allocation.x + allocation.width - r.width - (int) frame_size;
- }
+ if (_label_position == PositionType.LEFT) {
+ r.x = allocation.x + (int) frame_size;
+ } else {
+ r.x = allocation.x + allocation.width - r.width - (int) frame_size;
+ }
- if (_label_position == PositionType.TOP) {
- r.y = allocation.y + (int) frame_size;
- } else {
- r.y = allocation.y + allocation.height - r.height - (int) frame_size;
+ if (_label_position == PositionType.TOP) {
+ r.y = allocation.y + (int) frame_size;
+ } else {
+ r.y = allocation.y + allocation.height - r.height - (int) frame_size;
+ }
+
+ _expand_button.size_allocate (r);
}
- _expand_button.size_allocate (r);
- }
+ if (this.child != null && this.child.visible) {
+ double frame_size = 2 * LINE_WIDTH + CHILD_PADDING;
+ int wi = allocation.width - (int) (2 * frame_size);
+ int he = allocation.height - (int) (2 * frame_size);
- if (this.child != null && this.child.visible) {
- double frame_size = 2 * LINE_WIDTH + CHILD_PADDING;
- int wi = allocation.width - (int) (2 * frame_size);
- int he = allocation.height - (int) (2 * frame_size);
+ Rectangle r;
+ r.x = allocation.x + (int) frame_size;
+ r.y = allocation.y + (int) frame_size;
+ r.width = wi;
+ r.height = he;
- Rectangle r;
- r.x = allocation.x + (int) frame_size;
- r.y = allocation.y + (int) frame_size;
- r.width = wi;
- r.height = he;
-
- if (_label_position == PositionType.TOP) {
- r.y += (int) _bar_height;
- } else if (_label_position == PositionType.LEFT) {
- r.x += (int) _bar_width;
- }
+ if (_label_position == PositionType.TOP) {
+ r.y += (int) _bar_height;
+ } else if (_label_position == PositionType.LEFT) {
+ r.x += (int) _bar_width;
+ }
- if (_label_position == PositionType.TOP
- || _label_position == PositionType.BOTTOM) {
- r.height -= (int) _bar_height;
- } else {
- r.width -= (int) _bar_width;
+ if (_label_position == PositionType.TOP
+ || _label_position == PositionType.BOTTOM) {
+ r.height -= (int) _bar_height;
+ } else {
+ r.width -= (int) _bar_width;
+ }
+
+ this.child.size_allocate (r);
}
+ }
- this.child.size_allocate (r);
+ private void draw (Context cr) {
+ Rectangle rect;
+ rect.x = this.allocation.x;
+ rect.y = this.allocation.y;
+ rect.width = this.allocation.width;
+ rect.height = this.allocation.height;
+ _theme.draw_group (cr, rect, 4.0, LINE_WIDTH, SPACE, _label_layout,
+ _expand_button, this);
}
- }
- private void draw (Context cr) {
- Rectangle rect;
- rect.x = this.allocation.x;
- rect.y = this.allocation.y;
- rect.width = this.allocation.width;
- rect.height = this.allocation.height;
- _theme.draw_group (cr, rect, 4.0, LINE_WIDTH, SPACE, _label_layout,
- _expand_button, this);
- }
+ protected override bool expose_event (EventExpose event) {
+ var cr = Gdk.cairo_create (this.window);
+
+ cr.rectangle (event.area.x, event.area.y,
+ event.area.width, event.area.height);
+ cr.clip ();
+ draw (cr);
- protected override bool expose_event (EventExpose event) {
- var cr = Gdk.cairo_create (this.window);
+ // FIXME: is this necessary?
+ // cr.target.dispose ();
+ // cr.dispose ();
- cr.rectangle (event.area.x, event.area.y,
- event.area.width, event.area.height);
- cr.clip ();
- draw (cr);
-
- // FIXME: is this necessary?
-// cr.target.dispose ();
-// cr.dispose ();
-
-// return base.expose_event (event);
- // *** workaround ***
- if (_expand_button != null && _expand_button.visible) {
- // FIXME: why is this cast necessary?
- ((Widget) _expand_button).expose_event (event);
+ // return base.expose_event (event);
+ // *** workaround ***
+ if (_expand_button != null && _expand_button.visible) {
+ // FIXME: why is this cast necessary?
+ ((Widget) _expand_button).expose_event (event);
+ }
+ this.child.expose_event (event);
+ return false;
+ // *** workaround ***
}
- this.child.expose_event (event);
- return false;
- // *** workaround ***
}
}
-
Modified: trunk/geetk/ribbon/ribbon.vala
==============================================================================
--- trunk/geetk/ribbon/ribbon.vala (original)
+++ trunk/geetk/ribbon/ribbon.vala Thu Jul 24 15:19:51 2008
@@ -4,600 +4,603 @@
using Gdk;
using Gee;
-/** Ribbon widget. */
-public class Ribbon : Container {
+namespace Geetk {
- private const double BORDER_WIDTH = 2.0;
- private const double SPACE = 2.0;
- private const double PAGE_PADDING = 3.0;
- private const double TAB_PADDING = 4.0;
- private const double TABS_MIN_HPOS = 8.0;
- private const double LINE_WIDTH = 1.0;
- private const double ROUND_SIZE = 4.0;
-
- private ColorScheme _color_scheme = new ColorScheme ();
-
- private Gee.List<RibbonPage> _pages;
-
- private Rectangle _body_allocation;
- private Rectangle _page_allocation;
- private Requisition _app_button_requisition;
- private Requisition _toolbar_requisition;
- private Requisition _shortcuts_requisition;
- private Requisition _page_requisition;
-
- private double _header_height;
-
- public signal void page_selected (RibbonPage page);
- public signal void page_added (RibbonPage page);
- public signal void page_moved (RibbonPage page);
- public signal void page_removed (RibbonPage page);
-
- private ApplicationButton _app_button;
- public ApplicationButton application_button {
- set {
- if (_app_button != null) {
- _app_button.unparent ();
- }
- _app_button = value;
- if (_app_button != null) {
- _app_button.visible = true;
- _app_button.set_parent (this);
- }
- show_all ();
- }
- get {
- return _app_button;
- }
- }
+ /** Ribbon widget. */
+ public class Ribbon : Container {
- private QuickAccessToolbar _toolbar;
- public QuickAccessToolbar quick_access_toolbar {
- set {
- if (_toolbar != null) {
- _toolbar.unparent ();
- }
- _toolbar = value;
- if (_toolbar != null) {
- _toolbar.visible = true;
- _toolbar.set_parent (this);
+ private const double BORDER_WIDTH = 2.0;
+ private const double SPACE = 2.0;
+ private const double PAGE_PADDING = 3.0;
+ private const double TAB_PADDING = 4.0;
+ private const double TABS_MIN_HPOS = 8.0;
+ private const double LINE_WIDTH = 1.0;
+ private const double ROUND_SIZE = 4.0;
+
+ private ColorScheme _color_scheme = new ColorScheme ();
+
+ private Gee.List<RibbonPage> _pages;
+
+ private Rectangle _body_allocation;
+ private Rectangle _page_allocation;
+ private Requisition _app_button_requisition;
+ private Requisition _toolbar_requisition;
+ private Requisition _shortcuts_requisition;
+ private Requisition _page_requisition;
+
+ private double _header_height;
+
+ public signal void page_selected (RibbonPage page);
+ public signal void page_added (RibbonPage page);
+ public signal void page_moved (RibbonPage page);
+ public signal void page_removed (RibbonPage page);
+
+ private ApplicationButton _app_button;
+ public ApplicationButton application_button {
+ set {
+ if (_app_button != null) {
+ _app_button.unparent ();
+ }
+ _app_button = value;
+ if (_app_button != null) {
+ _app_button.visible = true;
+ _app_button.set_parent (this);
+ }
+ show_all ();
+ }
+ get {
+ return _app_button;
}
- show_all ();
- }
- get {
- return _toolbar;
}
- }
- /**
- * Index of the currently selected page.
- *
- * Returns -1 if no page is selected.
- */
- private int _current_page_index;
- public int current_page_index {
- set {
- if (_current_page_index != -1) {
- this.current_page.label.modify_fg (StateType.NORMAL,
- _theme.get_forecolor_for_ribbon_tabs (false));
- this.current_page.page.unparent ();
+ private QuickAccessToolbar _toolbar;
+ public QuickAccessToolbar quick_access_toolbar {
+ set {
+ if (_toolbar != null) {
+ _toolbar.unparent ();
+ }
+ _toolbar = value;
+ if (_toolbar != null) {
+ _toolbar.visible = true;
+ _toolbar.set_parent (this);
+ }
+ show_all ();
}
- _current_page_index = value;
- if (_current_page_index != -1) {
- this.current_page.label.modify_fg (StateType.NORMAL,
- _theme.get_forecolor_for_ribbon_tabs (true));
- this.current_page.page.set_parent (this);
+ get {
+ return _toolbar;
}
-
- show_all ();
- queue_draw ();
- }
- get {
- return _current_page_index;
}
- }
- /** Currently selected page. */
- public RibbonPage?# current_page { // FIXME: is this right?
- get {
- if (_current_page_index == -1) {
- return null;
+ /**
+ * Index of the currently selected page.
+ *
+ * Returns -1 if no page is selected.
+ */
+ private int _current_page_index;
+ public int current_page_index {
+ set {
+ if (_current_page_index != -1) {
+ this.current_page.label.modify_fg (StateType.NORMAL,
+ _theme.get_forecolor_for_ribbon_tabs (false));
+ this.current_page.page.unparent ();
+ }
+ _current_page_index = value;
+ if (_current_page_index != -1) {
+ this.current_page.label.modify_fg (StateType.NORMAL,
+ _theme.get_forecolor_for_ribbon_tabs (true));
+ this.current_page.page.set_parent (this);
+ }
+
+ show_all ();
+ queue_draw ();
+ }
+ get {
+ return _current_page_index;
}
- return _pages.get (_current_page_index);
}
- }
- /** Number of pages. */
- public int n_pages {
- get {
- return (int) _pages.size;
+ /** Currently selected page. */
+ public RibbonPage?# current_page { // FIXME: is this right?
+ get {
+ if (_current_page_index == -1) {
+ return null;
+ }
+ return _pages.get (_current_page_index);
+ }
}
- }
- /**
- * Shortcuts widget.
- *
- * The shortcuts widget is displayed next to the tabs.
- */
- private Widget _shortcuts;
- public Widget shortcuts {
- set {
- if (_shortcuts != null) {
- _shortcuts.unparent ();
- }
- _shortcuts = value;
- if (_shortcuts != null) {
- _shortcuts.visible = true;
- _shortcuts.set_parent (this);
+ /** Number of pages. */
+ public int n_pages {
+ get {
+ return (int) _pages.size;
}
- queue_draw ();
}
- get { return _shortcuts; }
- }
- /** Theme used to draw the widget. */
- private Theme _theme = new Theme ();
- public Theme theme {
- set {
- _theme = value;
- queue_draw ();
+ /**
+ * Shortcuts widget.
+ *
+ * The shortcuts widget is displayed next to the tabs.
+ */
+ private Widget _shortcuts;
+ public Widget shortcuts {
+ set {
+ if (_shortcuts != null) {
+ _shortcuts.unparent ();
+ }
+ _shortcuts = value;
+ if (_shortcuts != null) {
+ _shortcuts.visible = true;
+ _shortcuts.set_parent (this);
+ }
+ queue_draw ();
+ }
+ get { return _shortcuts; }
}
- get { return _theme; }
- }
- /** Construction method. */
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (EventMask.BUTTON_PRESS_MASK
- | EventMask.BUTTON_RELEASE_MASK
- | EventMask.POINTER_MOTION_MASK);
+ /** Theme used to draw the widget. */
+ private Theme _theme = new Theme ();
+ public Theme theme {
+ set {
+ _theme = value;
+ queue_draw ();
+ }
+ get { return _theme; }
+ }
+
+ /** Construction method. */
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+
+ add_events (EventMask.BUTTON_PRESS_MASK
+ | EventMask.BUTTON_RELEASE_MASK
+ | EventMask.POINTER_MOTION_MASK);
+
+ _pages = new ArrayList<RibbonPage> ();
+ _current_page_index = -1;
+ }
+
+ /**
+ * Adds a new page after all existing pages.
+ *
+ * @param child The widget to use as the content of the page.
+ * @param label The widget to use as the tab.
+ */
+ public void append_page (Widget child, Widget label) {
+ insert_page (child, label, -1);
+ }
+
+ /**
+ * Adds a new page before all existing pages.
+ *
+ * @param child The widget to use as the content of the page.
+ * @param label The widget to use as the tab.
+ */
+ public void prepend_page (Widget child, Widget label) {
+ insert_page (child, label, 0);
+ }
+
+ /**
+ * Adds a new page at the specified position.
+ *
+ * @param child The widget to use as the content of the page.
+ * @param label The widget to use as the tab.
+ * @param position The index (starting at 0) at which the page must be
+ * inserted, or -1 to insert the page after all
+ * existing pages.
+ */
+ public void insert_page (Widget child, Widget label, int position) {
+ var new_page = new RibbonPage (this, child, label);
+
+ if (position == -1) {
+ _pages.add (new_page);
+ } else {
+ _pages.insert (position, new_page);
+
+ if (_current_page_index != -1) {
+ if (position <= _current_page_index) {
+ _current_page_index++;
+ }
+ }
+ }
- _pages = new ArrayList<RibbonPage> ();
- _current_page_index = -1;
- }
+ if (_pages.size == 1) {
+ this.current_page_index = 0;
+ } else {
+ label.modify_fg (StateType.NORMAL,
+ _theme.get_forecolor_for_ribbon_tabs (false));
+ }
- /**
- * Adds a new page after all existing pages.
- *
- * @param child The widget to use as the content of the page.
- * @param label The widget to use as the tab.
- */
- public void append_page (Widget child, Widget label) {
- insert_page (child, label, -1);
- }
+ label.button_press_event += (sender, event) => {
+ // FIXME: Vala doesn't support real closures yet
+ // select_ribbon_page (new_page);
+ };
- /**
- * Adds a new page before all existing pages.
- *
- * @param child The widget to use as the content of the page.
- * @param label The widget to use as the tab.
- */
- public void prepend_page (Widget child, Widget label) {
- insert_page (child, label, 0);
- }
+ label.enter_notify_event += (sender, event) => {
+
+ };
- /**
- * Adds a new page at the specified position.
- *
- * @param child The widget to use as the content of the page.
- * @param label The widget to use as the tab.
- * @param position The index (starting at 0) at which the page must be
- * inserted, or -1 to insert the page after all
- * existing pages.
- */
- public void insert_page (Widget child, Widget label, int position) {
- var new_page = new RibbonPage (this, child, label);
-
- if (position == -1) {
- _pages.add (new_page);
- } else {
- _pages.insert (position, new_page);
+ label.leave_notify_event += (sender, event) => {
+ };
+
+ page_added (new_page);
+ for (int i = position + 1; i < _pages.size; i++) {
+ page_selected (_pages.get (i));
+ }
+ }
+
+ /**
+ * Removes the specified page.
+ *
+ * @param page_number Index of the page to remove.
+ */
+ public void remove_page (int page_number) {
if (_current_page_index != -1) {
- if (position <= _current_page_index) {
- _current_page_index++;
+ if (page_number < _current_page_index) {
+ _current_page_index--;
+ } else if (page_number == _current_page_index) {
+ _current_page_index = -1;
}
}
- }
- if (_pages.size == 1) {
- this.current_page_index = 0;
- } else {
- label.modify_fg (StateType.NORMAL,
- _theme.get_forecolor_for_ribbon_tabs (false));
+ var page = _pages.get (page_number);
+ if (_current_page_index == -1) {
+ _pages.remove_at (_pages.size - 1);
+ } else {
+ _pages.remove_at (page_number);
+ }
+
+ page_removed (page);
+ }
+
+ /**
+ * Returns the index of the specified page given its content widget.
+ *
+ * @param child The content of the page whose index must be returned.
+ * @return The index.
+ */
+ public int page_num (Widget child) {
+ // Since it is unlikely that the widget will contain more than
+ // a dozen pages, it is just fine to do a linear search.
+ for (int i = 0; i < _pages.size; i++) {
+ if (_pages.get (i).page == child) {
+ return i;
+ }
+ }
+ return -1;
}
- label.button_press_event += (sender, event) => {
- // FIXME: Vala doesn't support real closures yet
-// select_ribbon_page (new_page);
- };
-
- label.enter_notify_event += (sender, event) => {
-
- };
+ /**
+ * Returns the index of the specified page.
+ *
+ * @param page The page whose index must be returned.
+ * @return The RibbonPage.
+ */
+ public int ribbon_page_num (RibbonPage page) {
+ // Since it is unlikely that the widget will containe more than
+ // a dozen pages, it is just fine to do a linear search.
+ for (int i = 0; i < _pages.size; i++) {
+ if (_pages.get (i) == page) {
+ return i;
+ }
+ }
+ return -1;
+ }
- label.leave_notify_event += (sender, event) => {
-
- };
+ /**
+ * Sets the label widget of the specified page.
+ *
+ * @param page The content of the page whose label must be modified.
+ * @param label The new label widget.
+ */
+ public void set_page_label (Widget child, Widget label) {
+ _pages.get (page_num (child)).label = label;
+ }
- page_added (new_page);
- for (int i = position + 1; i < _pages.size; i++) {
- page_selected (_pages.get (i));
+ /**
+ * Gets the label widget of the specified page.
+ *
+ * @param child The content of the page whose label must be returned.
+ * @return The label widget.
+ */
+ public Widget get_page_label (Widget child) {
+ return _pages.get (page_num (child)).label;
}
- }
- /**
- * Removes the specified page.
- *
- * @param page_number Index of the page to remove.
- */
- public void remove_page (int page_number) {
- if (_current_page_index != -1) {
- if (page_number < _current_page_index) {
- _current_page_index--;
- } else if (page_number == _current_page_index) {
- _current_page_index = -1;
- }
+ /**
+ * Returns the content widget of the n-th page.
+ *
+ * @param position Index of the page whose content has to be returned.
+ * @return The n-th page.
+ */
+ public Widget get_nth_page (int position) {
+ return _pages.get (position).page;
}
- var page = _pages.get (page_number);
- if (_current_page_index == -1) {
- _pages.remove_at (_pages.size - 1);
- } else {
- _pages.remove_at (page_number);
+ /**
+ * Returns the n-th page.
+ *
+ * @param position Index of the page to return.
+ */
+ public RibbonPage get_nth_ribbon_page (int position) {
+ return _pages.get (position);
}
- page_removed (page);
- }
+ /**
+ * Selects the specified page.
+ *
+ * @param page The page to select.
+ */
+ public void select_ribbon_page (RibbonPage page) {
+ int index = ribbon_page_num (page);
+ if (index != -1) {
+ this.current_page_index = index;
+ }
+ page_selected (page);
+ }
- /**
- * Returns the index of the specified page given its content widget.
- *
- * @param child The content of the page whose index must be returned.
- * @return The index.
- */
- public int page_num (Widget child) {
- // Since it is unlikely that the widget will contain more than
- // a dozen pages, it is just fine to do a linear search.
- for (int i = 0; i < _pages.size; i++) {
- if (_pages.get (i).page == child) {
- return i;
+ /** Selects the previous page. */
+ public void prev_page () {
+ int index = _current_page_index;
+ if (index > 0) {
+ this.current_page_index = index - 1;
}
}
- return -1;
- }
- /**
- * Returns the index of the specified page.
- *
- * @param page The page whose index must be returned.
- * @return The RibbonPage.
- */
- public int ribbon_page_num (RibbonPage page) {
- // Since it is unlikely that the widget will containe more than
- // a dozen pages, it is just fine to do a linear search.
- for (int i = 0; i < _pages.size; i++) {
- if (_pages.get (i) == page) {
- return i;
+ /** Selects the next page. */
+ public void next_page () {
+ int index = _current_page_index;
+ if (index < this.n_pages - 1) {
+ this.current_page_index = index + 1;
}
}
- return -1;
- }
- /**
- * Sets the label widget of the specified page.
- *
- * @param page The content of the page whose label must be modified.
- * @param label The new label widget.
- */
- public void set_page_label (Widget child, Widget label) {
- _pages.get (page_num (child)).label = label;
- }
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ if (is_shown (_toolbar)) {
+ callback (_toolbar);
+ }
- /**
- * Gets the label widget of the specified page.
- *
- * @param child The content of the page whose label must be returned.
- * @return The label widget.
- */
- public Widget get_page_label (Widget child) {
- return _pages.get (page_num (child)).label;
- }
+ if (is_shown (_app_button)) {
+ callback (_app_button);
+ }
- /**
- * Returns the content widget of the n-th page.
- *
- * @param position Index of the page whose content has to be returned.
- * @return The n-th page.
- */
- public Widget get_nth_page (int position) {
- return _pages.get (position).page;
- }
+ if (is_shown (_shortcuts)) {
+ callback (_shortcuts);
+ }
- /**
- * Returns the n-th page.
- *
- * @param position Index of the page to return.
- */
- public RibbonPage get_nth_ribbon_page (int position) {
- return _pages.get (position);
- }
+ foreach (var page in _pages) {
+ callback (page.label);
+ }
- /**
- * Selects the specified page.
- *
- * @param page The page to select.
- */
- public void select_ribbon_page (RibbonPage page) {
- int index = ribbon_page_num (page);
- if (index != -1) {
- this.current_page_index = index;
+ if (this.current_page != null) {
+ callback (this.current_page.page);
+ }
}
- page_selected (page);
- }
- /** Selects the previous page. */
- public void prev_page () {
- int index = _current_page_index;
- if (index > 0) {
- this.current_page_index = index - 1;
+ private bool is_shown (Widget? widget) {
+ return (widget != null) && widget.visible;
}
- }
- /** Selects the next page. */
- public void next_page () {
- int index = _current_page_index;
- if (index < this.n_pages - 1) {
- this.current_page_index = index + 1;
- }
- }
+ protected override void size_request (Requisition requisition) {
+ // base.size_request (requisition);
- protected override void forall (bool include_internals, Gtk.Callback callback) {
- if (is_shown (_toolbar)) {
- callback (_toolbar);
- }
+ double tabs_width = 0;
+ double tabs_height = 0;
+ foreach (var page in _pages) {
+ Requisition req;
+ page.label.size_request (req);
+ tabs_width += req.width;
+ tabs_height = Math.fmax (tabs_height, req.height);
+ page.label_requisition = req;
+ }
+ tabs_width += _pages.size * 2 * TAB_PADDING;
+ tabs_height += 2 * TAB_PADDING;
- if (is_shown (_app_button)) {
- callback (_app_button);
- }
+ double header_width = tabs_width;
- if (is_shown (_shortcuts)) {
- callback (_shortcuts);
- }
+ if (is_shown (_shortcuts)) {
+ _shortcuts.size_request (_shortcuts_requisition);
+ double x = _shortcuts_requisition.width + SPACE;
+ header_width += Math.fmax (x, TABS_MIN_HPOS);
+ } else {
+ _shortcuts_requisition = Requisition ();
+ header_width += TABS_MIN_HPOS;
+ }
- foreach (var page in _pages) {
- callback (page.label);
- }
+ _header_height = Math.fmax (tabs_height, _shortcuts_requisition.height);
- if (this.current_page != null) {
- callback (this.current_page.page);
- }
- }
+ if (is_shown (_toolbar)) {
+ _toolbar.size_request (_toolbar_requisition);
+ }
+ if (is_shown (_app_button)) {
+ _app_button.size_request (_app_button_requisition);
+ }
- private bool is_shown (Widget? widget) {
- return (widget != null) && widget.visible;
- }
+ if (is_shown (_toolbar)) {
+ _header_height += 2 * SPACE + _toolbar_requisition.height;
+ }
- protected override void size_request (Requisition requisition) {
-// base.size_request (requisition);
+ if (is_shown (_app_button)) {
+ _header_height = Math.fmax (_header_height, SPACE + _app_button_requisition.height);
+ }
- double tabs_width = 0;
- double tabs_height = 0;
- foreach (var page in _pages) {
- Requisition req;
- page.label.size_request (req);
- tabs_width += req.width;
- tabs_height = Math.fmax (tabs_height, req.height);
- page.label_requisition = req;
- }
- tabs_width += _pages.size * 2 * TAB_PADDING;
- tabs_height += 2 * TAB_PADDING;
+ double page_width = 0;
+ double page_height = 0;
+ if (this.current_page != null) {
+ this.current_page.page.size_request (_page_requisition);
+ page_width = _page_requisition.width + 2 * PAGE_PADDING;
+ page_height = _page_requisition.height + 2 * PAGE_PADDING;
+ } else {
+ _page_requisition = Requisition ();
+ }
- double header_width = tabs_width;
+ double width = Math.fmax (header_width, page_width);
+ width = BORDER_WIDTH + width + BORDER_WIDTH;
+ double height = _header_height + page_height + 2 * BORDER_WIDTH;
- if (is_shown (_shortcuts)) {
- _shortcuts.size_request (_shortcuts_requisition);
- double x = _shortcuts_requisition.width + SPACE;
- header_width += Math.fmax (x, TABS_MIN_HPOS);
- } else {
- _shortcuts_requisition = Requisition ();
- header_width += TABS_MIN_HPOS;
+ requisition.width = (int) Math.ceil (width - double.EPSILON);
+ requisition.height = (int) Math.ceil (height - double.EPSILON);
}
- _header_height = Math.fmax (tabs_height, _shortcuts_requisition.height);
+ protected override void size_allocate (Rectangle allocation) {
+ // base.size_allocate (allocation); // FIXME: causes endless loop
+ this.allocation = (Allocation) allocation; // workaround
- if (is_shown (_toolbar)) {
- _toolbar.size_request (_toolbar_requisition);
- }
- if (is_shown (_app_button)) {
- _app_button.size_request (_app_button_requisition);
- }
+ if (allocation.height < _header_height + BORDER_WIDTH) {
+ return;
+ }
- if (is_shown (_toolbar)) {
- _header_height += 2 * SPACE + _toolbar_requisition.height;
- }
+ double header_bottom = allocation.y + BORDER_WIDTH + _header_height;
+ double current_x = BORDER_WIDTH;
- if (is_shown (_app_button)) {
- _header_height = Math.fmax (_header_height, SPACE + _app_button_requisition.height);
- }
+ if (is_shown (_app_button)) {
+ Rectangle alloc;
+ alloc.x = (int) current_x;
+ alloc.y = (int) (allocation.y + BORDER_WIDTH);
+ alloc.width = int.min (_app_button_requisition.width,
+ (int) (allocation.width - 2 * SPACE));
+ alloc.height = _app_button_requisition.height;
+ _app_button.size_allocate (alloc);
- double page_width = 0;
- double page_height = 0;
- if (this.current_page != null) {
- this.current_page.page.size_request (_page_requisition);
- page_width = _page_requisition.width + 2 * PAGE_PADDING;
- page_height = _page_requisition.height + 2 * PAGE_PADDING;
- } else {
- _page_requisition = Requisition ();
- }
+ current_x += alloc.width + SPACE;
+ }
- double width = Math.fmax (header_width, page_width);
- width = BORDER_WIDTH + width + BORDER_WIDTH;
- double height = _header_height + page_height + 2 * BORDER_WIDTH;
+ if (is_shown (_toolbar)) {
+ Rectangle alloc;
+ alloc.x = (int) current_x;
+ alloc.y = (int) (allocation.y + SPACE);
+ alloc.width = int.min (_toolbar_requisition.width,
+ (int) (allocation.width - (alloc.x - allocation.x) - SPACE));
+ alloc.height = _toolbar_requisition.height;
+ _toolbar.size_allocate (alloc);
+ }
- requisition.width = (int) Math.ceil (width - double.EPSILON);
- requisition.height = (int) Math.ceil (height - double.EPSILON);
- }
+ if (is_shown (_shortcuts)) {
+ Rectangle alloc;
+ alloc.x = (int) current_x;
+ alloc.y = (int) (header_bottom - _shortcuts_requisition.height);
+ alloc.width = _shortcuts_requisition.width;
+ alloc.height = _shortcuts_requisition.height;
+ _shortcuts.size_allocate (alloc);
+ current_x += _shortcuts_requisition.width;
+ }
- protected override void size_allocate (Rectangle allocation) {
-// base.size_allocate (allocation); // FIXME: causes endless loop
- this.allocation = (Allocation) allocation; // workaround
-
- if (allocation.height < _header_height + BORDER_WIDTH) {
- return;
- }
-
- double header_bottom = allocation.y + BORDER_WIDTH + _header_height;
- double current_x = BORDER_WIDTH;
-
- if (is_shown (_app_button)) {
- Rectangle alloc;
- alloc.x = (int) current_x;
- alloc.y = (int) (allocation.y + BORDER_WIDTH);
- alloc.width = int.min (_app_button_requisition.width,
- (int) (allocation.width - 2 * SPACE));
- alloc.height = _app_button_requisition.height;
- _app_button.size_allocate (alloc);
-
- current_x += alloc.width + SPACE;
- }
-
- if (is_shown (_toolbar)) {
- Rectangle alloc;
- alloc.x = (int) current_x;
- alloc.y = (int) (allocation.y + SPACE);
- alloc.width = int.min (_toolbar_requisition.width,
- (int) (allocation.width - (alloc.x - allocation.x) - SPACE));
- alloc.height = _toolbar_requisition.height;
- _toolbar.size_allocate (alloc);
- }
-
- if (is_shown (_shortcuts)) {
- Rectangle alloc;
- alloc.x = (int) current_x;
- alloc.y = (int) (header_bottom - _shortcuts_requisition.height);
- alloc.width = _shortcuts_requisition.width;
- alloc.height = _shortcuts_requisition.height;
- _shortcuts.size_allocate (alloc);
- current_x += _shortcuts_requisition.width;
- }
-
- current_x += SPACE;
- current_x = Math.fmax (current_x, TABS_MIN_HPOS);
-
- foreach (var page in _pages) {
- Rectangle alloc;
- alloc.x = (int) (current_x + TAB_PADDING);
- alloc.y = (int) (header_bottom - TAB_PADDING - page.label_requisition.height);
- alloc.width = page.label_requisition.width;
- alloc.height = page.label_requisition.height;
- page.label.size_allocate (alloc);
-
- alloc.x = (int) current_x;
- alloc.y = (int) (header_bottom - page.label_requisition.height - 2 * TAB_PADDING);
- alloc.width = (int) (page.label_requisition.width + 2 * TAB_PADDING);
- alloc.height = (int) (page.label_requisition.height + 2 * TAB_PADDING);
- page.label_allocation = alloc;
-
- current_x += page.label_requisition.width + 2 * TAB_PADDING;
- }
-
- _body_allocation.x = allocation.x + (int) BORDER_WIDTH;
- _body_allocation.y = (int) header_bottom;
- _body_allocation.width = allocation.width - _body_allocation.x - (int) BORDER_WIDTH;
- _body_allocation.height = allocation.height - _body_allocation.y - (int) BORDER_WIDTH;
-
- if (this.current_page != null) {
- _page_allocation = _body_allocation;
- int pad = (int) PAGE_PADDING;
- Rect.inflate (_page_allocation, -pad, -pad);
- this.current_page.page.size_allocate (_page_allocation);
- } else {
- _page_allocation = Rectangle ();
- }
- }
+ current_x += SPACE;
+ current_x = Math.fmax (current_x, TABS_MIN_HPOS);
- protected override bool expose_event (EventExpose event) {
- var cr = Gdk.cairo_create (this.window);
+ foreach (var page in _pages) {
+ Rectangle alloc;
+ alloc.x = (int) (current_x + TAB_PADDING);
+ alloc.y = (int) (header_bottom - TAB_PADDING - page.label_requisition.height);
+ alloc.width = page.label_requisition.width;
+ alloc.height = page.label_requisition.height;
+ page.label.size_allocate (alloc);
- cr.rectangle (event.area.x, event.area.y,
- event.area.width, event.area.height);
- cr.clip ();
- draw (cr);
-
- // FIXME: is this necessary with Vala?
-// cr.target.dispose ();
-// cr.dispose ();
-
- // FIXME: causes endless loop, but necessary to draw the children
-// return base.expose_event (event);
- // *** workaround ***
- if (is_shown (_toolbar)) {
- _toolbar.expose_event (event);
- }
- if (is_shown (_app_button)) {
- ((Widget) _app_button).expose_event (event); // XXX why cast?
- }
- if (is_shown (_shortcuts)) {
- _shortcuts.expose_event (event);
- }
- foreach (var page in _pages) {
- page.label.expose_event (event);
+ alloc.x = (int) current_x;
+ alloc.y = (int) (header_bottom - page.label_requisition.height - 2 * TAB_PADDING);
+ alloc.width = (int) (page.label_requisition.width + 2 * TAB_PADDING);
+ alloc.height = (int) (page.label_requisition.height + 2 * TAB_PADDING);
+ page.label_allocation = alloc;
+
+ current_x += page.label_requisition.width + 2 * TAB_PADDING;
+ }
+
+ _body_allocation.x = allocation.x + (int) BORDER_WIDTH;
+ _body_allocation.y = (int) header_bottom;
+ _body_allocation.width = allocation.width - _body_allocation.x - (int) BORDER_WIDTH;
+ _body_allocation.height = allocation.height - _body_allocation.y - (int) BORDER_WIDTH;
+
+ if (this.current_page != null) {
+ _page_allocation = _body_allocation;
+ int pad = (int) PAGE_PADDING;
+ Rect.inflate (_page_allocation, -pad, -pad);
+ this.current_page.page.size_allocate (_page_allocation);
+ } else {
+ _page_allocation = Rectangle ();
+ }
}
- if (this.current_page != null) {
- this.current_page.page.expose_event (event);
+
+ protected override bool expose_event (EventExpose event) {
+ var cr = Gdk.cairo_create (this.window);
+
+ cr.rectangle (event.area.x, event.area.y,
+ event.area.width, event.area.height);
+ cr.clip ();
+ draw (cr);
+
+ // FIXME: is this necessary with Vala?
+ // cr.target.dispose ();
+ // cr.dispose ();
+
+ // FIXME: causes endless loop, but necessary to draw the children
+ // return base.expose_event (event);
+ // *** workaround ***
+ if (is_shown (_toolbar)) {
+ _toolbar.expose_event (event);
+ }
+ if (is_shown (_app_button)) {
+ ((Widget) _app_button).expose_event (event); // XXX why cast?
+ }
+ if (is_shown (_shortcuts)) {
+ _shortcuts.expose_event (event);
+ }
+ foreach (var page in _pages) {
+ page.label.expose_event (event);
+ }
+ if (this.current_page != null) {
+ this.current_page.page.expose_event (event);
+ }
+ return false;
+ // *** workaround ***
}
- return false;
- // *** workaround ***
- }
- protected void draw (Context cr) {
- Rectangle menu_bar_allocation;
- menu_bar_allocation.x = this.allocation.x;
- menu_bar_allocation.y = this.allocation.y;
- menu_bar_allocation.width = this.allocation.width;
- if (is_shown (_toolbar)) {
- menu_bar_allocation.height = (int) (_toolbar.allocation.height + 2 * SPACE);
- } else {
- menu_bar_allocation.height = 0;
- }
- _theme.draw_ribbon (cr, menu_bar_allocation, _body_allocation,
- ROUND_SIZE, LINE_WIDTH, this);
+ protected void draw (Context cr) {
+ Rectangle menu_bar_allocation;
+ menu_bar_allocation.x = this.allocation.x;
+ menu_bar_allocation.y = this.allocation.y;
+ menu_bar_allocation.width = this.allocation.width;
+ if (is_shown (_toolbar)) {
+ menu_bar_allocation.height = (int) (_toolbar.allocation.height + 2 * SPACE);
+ } else {
+ menu_bar_allocation.height = 0;
+ }
+ _theme.draw_ribbon (cr, menu_bar_allocation, _body_allocation,
+ ROUND_SIZE, LINE_WIDTH, this);
+ }
}
-}
-/** Ribbon page. */
-public class RibbonPage : GLib.Object {
+ /** Ribbon page. */
+ public class RibbonPage : GLib.Object {
- public Ribbon parent { private get; construct; }
+ public Ribbon parent { private get; construct; }
- /** Widget used as the content of the page. */
- public Widget page { get; set; }
+ /** Widget used as the content of the page. */
+ public Widget page { get; set; }
- public Requisition label_requisition { get; set; }
- public Rectangle label_allocation { get; set; }
+ public Requisition label_requisition { get; set; }
+ public Rectangle label_allocation { get; set; }
- /** Label widget of the page. */
- private Widget _label;
- public Widget label {
- set {
- if (_label != null) {
- _label.unparent ();
- }
- _label = value;
- if (_label != null) {
- _label.set_parent (this.parent);
+ /** Label widget of the page. */
+ private Widget _label;
+ public Widget label {
+ set {
+ if (_label != null) {
+ _label.unparent ();
+ }
+ _label = value;
+ if (_label != null) {
+ _label.set_parent (this.parent);
+ }
}
+ get { return _label; }
}
- get { return _label; }
- }
- public RibbonPage (Ribbon parent, Widget page, Widget label) {
- this.parent = parent;
- this.page = page;
- this.label = label;
+ public RibbonPage (Ribbon parent, Widget page, Widget label) {
+ this.parent = parent;
+ this.page = page;
+ this.label = label;
+ }
}
}
Modified: trunk/geetk/ribbon/sample-tile.vala
==============================================================================
--- trunk/geetk/ribbon/sample-tile.vala (original)
+++ trunk/geetk/ribbon/sample-tile.vala Thu Jul 24 15:19:51 2008
@@ -1,25 +1,27 @@
-public class SampleTile : Tile {
+namespace Geetk {
- public string text { private get; construct; }
- private Pango.Layout _text_layout;
+ public class SampleTile : Tile {
- public SampleTile (string text) {
- this.text = text;
- }
-
- construct {
- _text_layout = create_pango_layout (text);
- }
+ public string text { private get; construct; }
+ private Pango.Layout _text_layout;
- public override Tile copy () {
- return new SampleTile (this.text);
- }
-
- public override void draw_content (Cairo.Context context, Gdk.Rectangle area) {
- context.set_source_rgb (0, 0, 0);
- Pango.cairo_update_layout (context, _text_layout);
- context.move_to (area.x, area.y);
- Pango.cairo_show_layout (context, _text_layout);
+ public SampleTile (string text) {
+ this.text = text;
+ }
+
+ construct {
+ _text_layout = create_pango_layout (text);
+ }
+
+ public override Tile copy () {
+ return new SampleTile (this.text);
+ }
+
+ public override void draw_content (Cairo.Context context, Gdk.Rectangle area) {
+ context.set_source_rgb (0, 0, 0);
+ Pango.cairo_update_layout (context, _text_layout);
+ context.move_to (area.x, area.y);
+ Pango.cairo_show_layout (context, _text_layout);
+ }
}
}
-
Modified: trunk/geetk/ribbon/synthetic-window.vala
==============================================================================
--- trunk/geetk/ribbon/synthetic-window.vala (original)
+++ trunk/geetk/ribbon/synthetic-window.vala Thu Jul 24 15:19:51 2008
@@ -2,135 +2,138 @@
using Gdk;
using Gtk;
-/** Window generating synthetic events to window-less widgets. */
-public class SyntheticWindow : Gtk.Window {
+namespace Geetk {
- private Gee.List<Widget> _last_hovered_widgets;
+ /** Window generating synthetic events to window-less widgets. */
+ public class SyntheticWindow : Gtk.Window {
- construct {
- _last_hovered_widgets = new Gee.ArrayList<Widget> ();
- }
+ private Gee.List<Widget> _last_hovered_widgets;
- public SyntheticWindow (Gtk.WindowType type) {
- this.type = type;
- }
+ construct {
+ _last_hovered_widgets = new Gee.ArrayList<Widget> ();
+ }
+
+ public SyntheticWindow (Gtk.WindowType type) {
+ this.type = type;
+ }
+
+ protected override bool event (Gdk.Event evnt) {
+ // This method is hooked to block the event as soon as possible if required
+
+ if (evnt.any.window == this.window) {
+ switch (evnt.type) {
+ case EventType.BUTTON_PRESS:
+ case EventType.BUTTON_RELEASE:
+ case EventType.3BUTTON_PRESS:
+ case EventType.2BUTTON_PRESS:
+ var eb = evnt.button;
+ return propagate_event_given_coordinate (evnt, eb.x, eb.x_root, eb.y, eb.y_root);
- protected override bool event (Gdk.Event evnt) {
- // This method is hooked to block the event as soon as possible if required
+ case EventType.MOTION_NOTIFY:
+ var em = evnt.motion;
+ return propagate_event_given_coordinate (evnt, em.x, em.x_root, em.y, em.y_root);
- if (evnt.any.window == this.window) {
- switch (evnt.type) {
- case EventType.BUTTON_PRESS:
- case EventType.BUTTON_RELEASE:
- case EventType.3BUTTON_PRESS:
- case EventType.2BUTTON_PRESS:
- var eb = evnt.button;
- return propagate_event_given_coordinate (evnt, eb.x, eb.x_root, eb.y, eb.y_root);
-
- case EventType.MOTION_NOTIFY:
- var em = evnt.motion;
- return propagate_event_given_coordinate (evnt, em.x, em.x_root, em.y, em.y_root);
-
- case EventType.LEAVE_NOTIFY:
- foreach (var widget in _last_hovered_widgets) {
- widget.event (evnt);
+ case EventType.LEAVE_NOTIFY:
+ foreach (var widget in _last_hovered_widgets) {
+ widget.event (evnt);
+ }
+ _last_hovered_widgets.clear ();
+ // return base.event (evnt); // FIXME
+ return false;
}
- _last_hovered_widgets.clear ();
-// return base.event (evnt); // FIXME
- return false;
}
+ // return base.event (evnt); // FIXME
+ return false;
}
-// return base.event (evnt); // FIXME
- return false;
- }
- private bool propagate_event_given_coordinate (Gdk.Event evnt, double X, double x_root, double Y, double y_root) {
- int x = (int) X;
- int y = (int) Y;
- Container current = this; // Current container containing the coordinate
- Widget match = this; // Current match for the position
- int matched_pos = 0; // Current position in last_hovered_widgets
-
- while (matched_pos < _last_hovered_widgets.size) {
- var candidate = _last_hovered_widgets.get (matched_pos);
- if (candidate.parent == (Widget) current) { // Is it still a child of the current container ?
- Gdk.Rectangle alloc = (Gdk.Rectangle) candidate.allocation;
- if (!Gdk.Rect.contains (alloc, x, y)) { // Does it contain the coordinate ?
- break;
+ private bool propagate_event_given_coordinate (Gdk.Event evnt, double X, double x_root, double Y, double y_root) {
+ int x = (int) X;
+ int y = (int) Y;
+ Container current = this; // Current container containing the coordinate
+ Widget match = this; // Current match for the position
+ int matched_pos = 0; // Current position in last_hovered_widgets
+
+ while (matched_pos < _last_hovered_widgets.size) {
+ var candidate = _last_hovered_widgets.get (matched_pos);
+ if (candidate.parent == (Widget) current) { // Is it still a child of the current container ?
+ Gdk.Rectangle alloc = (Gdk.Rectangle) candidate.allocation;
+ if (!Gdk.Rect.contains (alloc, x, y)) { // Does it contain the coordinate ?
+ break;
+ }
}
+ current = candidate as Container;
+ match = candidate;
+ ++matched_pos;
}
- current = candidate as Container;
- match = candidate;
- ++matched_pos;
- }
- if (matched_pos < _last_hovered_widgets.size) { // Not all widgets match
- // Send a leave notify
- send_synthetic_event (EventType.LEAVE_NOTIFY, evnt, X, x_root, Y, y_root,
- _last_hovered_widgets, matched_pos);
-
- // Remove them
- list_remove_range (_last_hovered_widgets, matched_pos,
- _last_hovered_widgets.size - matched_pos);
- }
+ if (matched_pos < _last_hovered_widgets.size) { // Not all widgets match
+ // Send a leave notify
+ send_synthetic_event (EventType.LEAVE_NOTIFY, evnt, X, x_root, Y, y_root,
+ _last_hovered_widgets, matched_pos);
+
+ // Remove them
+ list_remove_range (_last_hovered_widgets, matched_pos,
+ _last_hovered_widgets.size - matched_pos);
+ }
- while (current != null) {
- Container next = null;
- foreach (var child in current.get_children ()) {
- if ((child.get_flags () & WidgetFlags.NO_WINDOW) != 0) {
- Gdk.Rectangle alloc = (Gdk.Rectangle) child.allocation;
- if (Gdk.Rect.contains (alloc, x, y)) {
- _last_hovered_widgets.add (child);
- match = child;
- next = child as Container;
- break;
+ while (current != null) {
+ Container next = null;
+ foreach (var child in current.get_children ()) {
+ if ((child.get_flags () & WidgetFlags.NO_WINDOW) != 0) {
+ Gdk.Rectangle alloc = (Gdk.Rectangle) child.allocation;
+ if (Gdk.Rect.contains (alloc, x, y)) {
+ _last_hovered_widgets.add (child);
+ match = child;
+ next = child as Container;
+ break;
+ }
}
}
+ current = next;
}
- current = next;
- }
- if (matched_pos < _last_hovered_widgets.size) { // New widgets have been found
- // Send an enter notify
- send_synthetic_event (EventType.ENTER_NOTIFY, evnt, X, x_root, Y, y_root,
- _last_hovered_widgets, matched_pos);
- }
+ if (matched_pos < _last_hovered_widgets.size) { // New widgets have been found
+ // Send an enter notify
+ send_synthetic_event (EventType.ENTER_NOTIFY, evnt, X, x_root, Y, y_root,
+ _last_hovered_widgets, matched_pos);
+ }
- if (match == this) { // No widget found, the window keeps the event
-// return base.event (evnt); // FIXME
- return false;
- } else { // A widget has been found, let's send it the event
- match.event (evnt);
- return true;
+ if (match == this) { // No widget found, the window keeps the event
+ // return base.event (evnt); // FIXME
+ return false;
+ } else { // A widget has been found, let's send it the event
+ match.event (evnt);
+ return true;
+ }
}
- }
- private void send_synthetic_event (EventType type, Event original_event,
- double x, double x_root,
- double y, double y_root,
- Gee.List<Widget> widgets, int index) {
- EventCrossing se;
- se.detail = NotifyType.ANCESTOR;
- se.focus = false;
- se.mode = CrossingMode.NORMAL;
- se.send_event = 0;
- se.state = 0;
- se.subwindow = null;
-// se.Time = DateTime.Now.Ticks / 10000; // TODO: the real value shoud be the uptime I think
- se.time = 0;
- se.type = type;
- se.window = original_event.any.window;
- se.x = x;
- se.x_root = x_root;
- se.y = y;
- se.y_root = y_root;
-
- Event managed_event;
- managed_event.type = EventType.MOTION_NOTIFY;
- managed_event.crossing = se;
+ private void send_synthetic_event (EventType type, Event original_event,
+ double x, double x_root,
+ double y, double y_root,
+ Gee.List<Widget> widgets, int index) {
+ EventCrossing se;
+ se.detail = NotifyType.ANCESTOR;
+ se.focus = false;
+ se.mode = CrossingMode.NORMAL;
+ se.send_event = 0;
+ se.state = 0;
+ se.subwindow = null;
+ // se.Time = DateTime.Now.Ticks / 10000; // TODO: the real value shoud be the uptime I think
+ se.time = 0;
+ se.type = type;
+ se.window = original_event.any.window;
+ se.x = x;
+ se.x_root = x_root;
+ se.y = y;
+ se.y_root = y_root;
+
+ Event managed_event;
+ managed_event.type = EventType.MOTION_NOTIFY;
+ managed_event.crossing = se;
- for (int i = index; i < widgets.size; i++) {
- widgets.get (i).event (managed_event);
+ for (int i = index; i < widgets.size; i++) {
+ widgets.get (i).event (managed_event);
+ }
}
}
}
Modified: trunk/geetk/ribbon/theme.vala
==============================================================================
--- trunk/geetk/ribbon/theme.vala (original)
+++ trunk/geetk/ribbon/theme.vala Thu Jul 24 15:19:51 2008
@@ -2,1034 +2,1037 @@
using Cairo;
using Gtk;
-/**
- * Ribbon theme.
- *
- * Used to draw ribbon widgets.
- */
-public class Theme : GLib.Object {
-
- public enum ButtonState {
- DEFAULT,
- HOVER,
- PRESSED,
- }
+namespace Geetk {
- public enum MenuItemState {
- DEFAULT,
- HILIGHT_ACTION,
- HILIGHT_MENU,
- HILIGHT,
- }
+ /**
+ * Ribbon theme.
+ *
+ * Used to draw ribbon widgets.
+ */
+ public class Theme : GLib.Object {
+
+ public enum ButtonState {
+ DEFAULT,
+ HOVER,
+ PRESSED,
+ }
- private ColorScheme _color_scheme = new ColorScheme ();
+ public enum MenuItemState {
+ DEFAULT,
+ HILIGHT_ACTION,
+ HILIGHT_MENU,
+ HILIGHT,
+ }
- public void draw_application_menu (Context cr, Gdk.Rectangle r, Gdk.Rectangle items_alloc,
- double line_width, ApplicationMenu w) {
- double line_width_05 = line_width / 2;
- double line_width_15 = line_width * 1.5;
- Gdk.Rectangle alloc = (Gdk.Rectangle) w.allocation;
-
- cr.set_source_rgb (0.4, 0.4, 0.4);
- cr.paint ();
-
- cr.rectangle (items_alloc.x, items_alloc.y, items_alloc.width, items_alloc.height);
- cr.set_source_rgb (0.9216, 0.9216, 0.9216);
- cr.fill ();
-
- cr.set_line_width (line_width);
-
- cr.move_to (Gdk.Rect.right (items_alloc) - line_width_05, Gdk.Rect.top (items_alloc));
- cr.line_to (Gdk.Rect.right (items_alloc) - line_width_05, Gdk.Rect.bottom (items_alloc));
- cr.set_source_rgba (1, 1, 1, 0.2);
- cr.stroke ();
-
- cr.move_to (Gdk.Rect.right (items_alloc) - line_width_15, Gdk.Rect.top (items_alloc));
- cr.line_to (Gdk.Rect.right (items_alloc) - line_width_15, Gdk.Rect.bottom (items_alloc));
- cr.set_source_rgba (0, 0, 0, 0.2);
- cr.stroke ();
-
- cr.rectangle (alloc.x, alloc.y, alloc.width, items_alloc.y - alloc.y);
- var lin_grad = new Pattern.linear (0, alloc.y, 0, items_alloc.y - alloc.y);
- lin_grad.add_color_stop_rgb (0.0, 0.4, 0.4, 0.4);
- lin_grad.add_color_stop_rgb (0.3, 0.2, 0.2, 0.2);
- lin_grad.add_color_stop_rgb (0.3, 0, 0, 0);
- lin_grad.add_color_stop_rgb (1.0, 0.4, 0.4, 0.4);
- cr.set_source (lin_grad);
- cr.fill ();
-
- cr.rectangle (alloc.x, Gdk.Rect.bottom (items_alloc), alloc.width,
- Gdk.Rect.bottom (alloc) - Gdk.Rect.bottom (items_alloc));
- lin_grad = new Pattern.linear (0, Gdk.Rect.bottom (items_alloc),
- 0, Gdk.Rect.bottom (alloc));
- lin_grad.add_color_stop_rgb (0.0, 0.4, 0.4, 0.4);
- lin_grad.add_color_stop_rgb (0.3, 0.2, 0.2, 0.2);
- lin_grad.add_color_stop_rgb (0.3, 0, 0, 0);
- lin_grad.add_color_stop_rgb (1.0, 0.4, 0.4, 0.4);
- cr.set_source (lin_grad);
- cr.fill ();
-
- Gdk.Rectangle app_btn_alloc = (Gdk.Rectangle) w.application_button.allocation;
- app_btn_alloc.x = alloc.x;
- app_btn_alloc.y = items_alloc.y - 2 - app_btn_alloc.height;
- draw_application_button (cr, app_btn_alloc, ButtonState.PRESSED, 1.0,
- w.application_button);
- }
+ private ColorScheme _color_scheme = new ColorScheme ();
- public void draw_application_menu_item (Context cr, Gdk.Rectangle body_allocation,
- MenuItemState state, double round_size,
- double line_width, double arrow_size,
- double arrow_padding, bool draw_separator,
- ApplicationMenuItem widget) {
- double line_width_05 = line_width / 2;
- double line_width_15 = line_width_05 * 3;
- double separator_x = body_allocation.x + body_allocation.width
- - 2 * line_width - arrow_size - 2 * arrow_padding;
-
- cr.set_line_width (line_width);
-
- if (state != MenuItemState.DEFAULT) {
- Pattern body_pattern;
- Pattern inner_border_pattern;
- Color border_color;
-
- body_pattern = new Pattern.linear (
- body_allocation.x, body_allocation.y,
- body_allocation.x, body_allocation.y + body_allocation.height);
- body_pattern.add_color_stop_rgb (0.0, 1, 0.996, 0.890);
- body_pattern.add_color_stop_rgb (0.37, 1, 0.906, 0.592);
- body_pattern.add_color_stop_rgb (0.43, 1, 0.843, 0.314);
- body_pattern.add_color_stop_rgb (1.0, 1, 0.906, 0.588);
+ public void draw_application_menu (Context cr, Gdk.Rectangle r, Gdk.Rectangle items_alloc,
+ double line_width, ApplicationMenu w) {
+ double line_width_05 = line_width / 2;
+ double line_width_15 = line_width * 1.5;
+ Gdk.Rectangle alloc = (Gdk.Rectangle) w.allocation;
- inner_border_pattern = new Pattern.linear (
- body_allocation.x, body_allocation.y,
- body_allocation.x + body_allocation.width,
- body_allocation.y + body_allocation.height);
- inner_border_pattern.add_color_stop_rgba (0.0, 1, 1, 0.969, 1);
- inner_border_pattern.add_color_stop_rgba (1.0, 1, 1, 0.969, 0);
+ cr.set_source_rgb (0.4, 0.4, 0.4);
+ cr.paint ();
+
+ cr.rectangle (items_alloc.x, items_alloc.y, items_alloc.width, items_alloc.height);
+ cr.set_source_rgb (0.9216, 0.9216, 0.9216);
+ cr.fill ();
- border_color = Color.from_rgb (0.824, 0.753, 0.553);
+ cr.set_line_width (line_width);
- double x0 = body_allocation.x + line_width_05;
- double y0 = body_allocation.y + line_width_05;
- double x1 = body_allocation.x + body_allocation.width - line_width_05;
- double y1 = body_allocation.y + body_allocation.height - line_width_05;
-
- cr.move_to (x0 + round_size, y0);
- cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
- cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
- cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ cr.move_to (Gdk.Rect.right (items_alloc) - line_width_05, Gdk.Rect.top (items_alloc));
+ cr.line_to (Gdk.Rect.right (items_alloc) - line_width_05, Gdk.Rect.bottom (items_alloc));
+ cr.set_source_rgba (1, 1, 1, 0.2);
+ cr.stroke ();
- cr.set_source (body_pattern);
+ cr.move_to (Gdk.Rect.right (items_alloc) - line_width_15, Gdk.Rect.top (items_alloc));
+ cr.line_to (Gdk.Rect.right (items_alloc) - line_width_15, Gdk.Rect.bottom (items_alloc));
+ cr.set_source_rgba (0, 0, 0, 0.2);
+ cr.stroke ();
+
+ cr.rectangle (alloc.x, alloc.y, alloc.width, items_alloc.y - alloc.y);
+ var lin_grad = new Pattern.linear (0, alloc.y, 0, items_alloc.y - alloc.y);
+ lin_grad.add_color_stop_rgb (0.0, 0.4, 0.4, 0.4);
+ lin_grad.add_color_stop_rgb (0.3, 0.2, 0.2, 0.2);
+ lin_grad.add_color_stop_rgb (0.3, 0, 0, 0);
+ lin_grad.add_color_stop_rgb (1.0, 0.4, 0.4, 0.4);
+ cr.set_source (lin_grad);
+ cr.fill ();
+
+ cr.rectangle (alloc.x, Gdk.Rect.bottom (items_alloc), alloc.width,
+ Gdk.Rect.bottom (alloc) - Gdk.Rect.bottom (items_alloc));
+ lin_grad = new Pattern.linear (0, Gdk.Rect.bottom (items_alloc),
+ 0, Gdk.Rect.bottom (alloc));
+ lin_grad.add_color_stop_rgb (0.0, 0.4, 0.4, 0.4);
+ lin_grad.add_color_stop_rgb (0.3, 0.2, 0.2, 0.2);
+ lin_grad.add_color_stop_rgb (0.3, 0, 0, 0);
+ lin_grad.add_color_stop_rgb (1.0, 0.4, 0.4, 0.4);
+ cr.set_source (lin_grad);
cr.fill ();
- if (state == MenuItemState.HILIGHT_ACTION) {
- cr.set_source_rgba (1, 1, 1, 0.7);
+ Gdk.Rectangle app_btn_alloc = (Gdk.Rectangle) w.application_button.allocation;
+ app_btn_alloc.x = alloc.x;
+ app_btn_alloc.y = items_alloc.y - 2 - app_btn_alloc.height;
+ draw_application_button (cr, app_btn_alloc, ButtonState.PRESSED, 1.0,
+ w.application_button);
+ }
+
+ public void draw_application_menu_item (Context cr, Gdk.Rectangle body_allocation,
+ MenuItemState state, double round_size,
+ double line_width, double arrow_size,
+ double arrow_padding, bool draw_separator,
+ ApplicationMenuItem widget) {
+ double line_width_05 = line_width / 2;
+ double line_width_15 = line_width_05 * 3;
+ double separator_x = body_allocation.x + body_allocation.width
+ - 2 * line_width - arrow_size - 2 * arrow_padding;
+
+ cr.set_line_width (line_width);
+
+ if (state != MenuItemState.DEFAULT) {
+ Pattern body_pattern;
+ Pattern inner_border_pattern;
+ Color border_color;
+
+ body_pattern = new Pattern.linear (
+ body_allocation.x, body_allocation.y,
+ body_allocation.x, body_allocation.y + body_allocation.height);
+ body_pattern.add_color_stop_rgb (0.0, 1, 0.996, 0.890);
+ body_pattern.add_color_stop_rgb (0.37, 1, 0.906, 0.592);
+ body_pattern.add_color_stop_rgb (0.43, 1, 0.843, 0.314);
+ body_pattern.add_color_stop_rgb (1.0, 1, 0.906, 0.588);
+
+ inner_border_pattern = new Pattern.linear (
+ body_allocation.x, body_allocation.y,
+ body_allocation.x + body_allocation.width,
+ body_allocation.y + body_allocation.height);
+ inner_border_pattern.add_color_stop_rgba (0.0, 1, 1, 0.969, 1);
+ inner_border_pattern.add_color_stop_rgba (1.0, 1, 1, 0.969, 0);
+
+ border_color = Color.from_rgb (0.824, 0.753, 0.553);
+
+ double x0 = body_allocation.x + line_width_05;
+ double y0 = body_allocation.y + line_width_05;
+ double x1 = body_allocation.x + body_allocation.width - line_width_05;
+ double y1 = body_allocation.y + body_allocation.height - line_width_05;
+
cr.move_to (x0 + round_size, y0);
- cr.line_to (separator_x, y0);
- cr.line_to (separator_x, y1);
+ cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
+ cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+
+ cr.set_source (body_pattern);
cr.fill ();
- } else if (state == MenuItemState.HILIGHT_MENU) {
- cr.set_source_rgba (1, 1, 1, 0.7);
- cr.move_to (separator_x, y0);
+
+ if (state == MenuItemState.HILIGHT_ACTION) {
+ cr.set_source_rgba (1, 1, 1, 0.7);
+ cr.move_to (x0 + round_size, y0);
+ cr.line_to (separator_x, y0);
+ cr.line_to (separator_x, y1);
+ cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ cr.fill ();
+ } else if (state == MenuItemState.HILIGHT_MENU) {
+ cr.set_source_rgba (1, 1, 1, 0.7);
+ cr.move_to (separator_x, y0);
+ cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
+ cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
+ cr.line_to (separator_x, y1);
+ cr.line_to (separator_x, y0);
+ cr.fill ();
+ }
+
+ x0 = body_allocation.x + line_width_15;
+ y0 = body_allocation.y + line_width_15;
+ x1 = body_allocation.x + body_allocation.width - line_width_15;
+ y1 = body_allocation.y + body_allocation.height - line_width_15;
+
+ double round_size_minus_line_width = round_size - line_width;
+
+ x0 -= line_width;
+
+ cr.move_to (x0 + round_size_minus_line_width, y0);
+ cr.arc (x1 - round_size_minus_line_width, y0 + round_size_minus_line_width,
+ round_size_minus_line_width, 1.5 * Math.PI, 0);
+ cr.arc (x1 - round_size_minus_line_width, y1 - round_size_minus_line_width,
+ round_size_minus_line_width, 0, 0.5 * Math.PI);
+ cr.arc (x0 + round_size_minus_line_width, y1 - round_size_minus_line_width,
+ round_size_minus_line_width, 0.5 * Math.PI, Math.PI);
+ cr.arc (x0 + round_size_minus_line_width, y0 + round_size_minus_line_width,
+ round_size_minus_line_width, Math.PI, 1.5 * Math.PI);
+
+ x0 += line_width;
+
+ cr.set_source (inner_border_pattern);
+ cr.stroke ();
+
+ x0 = body_allocation.x + line_width_05;
+ y0 = body_allocation.y + line_width_05;
+ x1 = body_allocation.x + body_allocation.width - line_width_05;
+ y1 = body_allocation.y + body_allocation.height - line_width_05;
+
+ cr.move_to (x0 + round_size, y0);
cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- cr.line_to (separator_x, y1);
- cr.line_to (separator_x, y0);
+ cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+
+ Cairo.set_color (cr, border_color);
+ cr.stroke ();
+ }
+
+ if (arrow_size > 0) {
+ double x, y;
+
+ x = separator_x;
+ y = body_allocation.y + (body_allocation.height - arrow_size) / 2.0;
+
+ if (draw_separator) {
+ double top = body_allocation.y + 2 * line_width;
+ double bottom = body_allocation.y + body_allocation.height - 2 * line_width;
+ cr.move_to (x - line_width / 2, top);
+ cr.line_to (x - line_width / 2, bottom);
+ cr.set_source_rgba (0, 0, 0, 0.1);
+ cr.stroke ();
+
+ cr.move_to (x + line_width / 2, top);
+ cr.line_to (x + line_width / 2, bottom);
+ cr.set_source_rgba (1, 1, 1, 0.6);
+ cr.stroke ();
+ }
+
+ x += arrow_size / 4.0 + line_width / 2.0;
+
+ cr.move_to (x, y);
+ cr.line_to (x, y + arrow_size);
+ cr.line_to (x + arrow_size / 2.0, y + arrow_size / 2.0);
+ cr.line_to (x, y);
+ cr.set_source_rgb (0, 0, 0);
cr.fill ();
}
+ }
- x0 = body_allocation.x + line_width_15;
- y0 = body_allocation.y + line_width_15;
- x1 = body_allocation.x + body_allocation.width - line_width_15;
- y1 = body_allocation.y + body_allocation.height - line_width_15;
-
- double round_size_minus_line_width = round_size - line_width;
-
- x0 -= line_width;
-
- cr.move_to (x0 + round_size_minus_line_width, y0);
- cr.arc (x1 - round_size_minus_line_width, y0 + round_size_minus_line_width,
- round_size_minus_line_width, 1.5 * Math.PI, 0);
- cr.arc (x1 - round_size_minus_line_width, y1 - round_size_minus_line_width,
- round_size_minus_line_width, 0, 0.5 * Math.PI);
- cr.arc (x0 + round_size_minus_line_width, y1 - round_size_minus_line_width,
- round_size_minus_line_width, 0.5 * Math.PI, Math.PI);
- cr.arc (x0 + round_size_minus_line_width, y0 + round_size_minus_line_width,
- round_size_minus_line_width, Math.PI, 1.5 * Math.PI);
+ /** Draws a group. */
+ public void draw_group (Context cr, Gdk.Rectangle r, double round_size,
+ double line_width, double space, Pango.Layout l,
+ Gtk.Widget expand_button, RibbonGroup w) {
+ double line_width_05 = line_width / 2, line_width_15 = 3 * line_width_05;
+ Pattern lin_grad;
+
+ double x0 = r.x + round_size;
+ double x1 = r.x + r.width - round_size;
+ double y0 = r.y + round_size;
+ double y1 = r.y + r.height - round_size;
+ cr.arc (x1, y1, round_size - line_width_05, 0, Math.PI / 2);
+ cr.arc (x0 + line_width, y1, round_size - line_width_05, Math.PI / 2, Math.PI);
+ cr.arc (x0, y0, round_size - line_width_15, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1, y0 + line_width, round_size - line_width_05, 3 * Math.PI / 2, 0);
+ cr.line_to (x1 + round_size - line_width_05, y1);
+ cr.set_line_width (line_width);
+ Cairo.set_color (cr, _color_scheme.bright);
+ cr.stroke ();
- x0 += line_width;
+ if (l != null) {
+ int lbl_width, lbl_height;
+ Pango.cairo_update_layout (cr, l);
+ l.get_pixel_size (out lbl_width, out lbl_height);
- cr.set_source (inner_border_pattern);
- cr.stroke ();
+ if (w.label_position == PositionType.TOP
+ || w.label_position == PositionType.BOTTOM) {
+ double label_y;
+ double band_height = lbl_height + 2 * space;
+
+ if (w.label_position == PositionType.TOP) {
+ cr.arc (x0, y0, round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1, y0, round_size - line_width_05, 3 * Math.PI / 2, 0);
+ double band_y = y0 - round_size + 2 * line_width + band_height;
+ cr.line_to (x1 + round_size - line_width_15, band_y);
+ cr.line_to (x0 - round_size + line_width_05, band_y);
+ lin_grad = new Pattern.linear (0, band_y - band_height, 0, band_y);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
+ Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+ cr.set_source (lin_grad);
+ cr.fill ();
+
+ label_y = band_y - band_height - space;
+ } else {
+ cr.arc (x1, y1, round_size - line_width_15, 0, Math.PI / 2);
+ cr.arc (x0, y1 - line_width, round_size - line_width_05,
+ Math.PI / 2, Math.PI);
+ double band_y = y1 + round_size - 2 * line_width - band_height;
+ cr.line_to (x0 - round_size + line_width_05, band_y);
+ cr.line_to (x1 + round_size - line_width_15, band_y);
+ lin_grad = new Pattern.linear (0, band_y, 0, band_y + band_height);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
+ Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+ cr.set_source (lin_grad);
+ cr.fill ();
+
+ label_y = band_y;
+ }
+
+ double frame_size = 2 * line_width + space;
+ double available_horizontal_space = r.width - 2 * frame_size;
+ if (expand_button.visible) {
+ available_horizontal_space -= expand_button.width_request + space;
+ }
+
+ cr.save ();
+ cr.rectangle (r.x + frame_size, label_y,
+ available_horizontal_space, band_height);
+ cr.clip ();
+
+ cr.set_source_rgb (1, 1, 1);
+ Pango.cairo_update_layout (cr, l);
+ cr.move_to (r.x + frame_size
+ + Math.fmax (0, (available_horizontal_space - lbl_width) / 2),
+ label_y + space);
+ Pango.cairo_show_layout (cr, l);
+
+ cr.restore ();
+ } else { // label at right or left
+ double label_x;
+ double band_width = lbl_height + 2 * space;
+
+ if (w.label_position == PositionType.LEFT) {
+ cr.arc (x0, y1, round_size - line_width_05, Math.PI / 2, Math.PI);
+ cr.arc (x0, y0, round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
+ double band_x = x0 - round_size + 2 * line_width + band_width;
+ cr.line_to (band_x, y0 - round_size + line_width_05);
+ cr.line_to (band_x, y1 + round_size - line_width_15);
+ lin_grad = new Pattern.linear (band_x - band_width, 0, band_x, 0);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
+ Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+ cr.set_source (lin_grad);
+ cr.fill ();
+
+ label_x = band_x - band_width - space;
+ } else {
+ cr.arc (x1, y0 - line_width_05, round_size - line_width_15,
+ 3 * Math.PI / 2, 0);
+ cr.arc (x1, y1, round_size - line_width_15, 0, Math.PI / 2);
+ double band_x = x1 + round_size - 2 * line_width - band_width;
+ cr.line_to (band_x, y1 + round_size - line_width_15);
+ cr.line_to (band_x, y0 - round_size + line_width_05);
+ lin_grad = new Pattern.linear (band_x, 0, band_x + band_width, 0);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
+ Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+ cr.set_source (lin_grad);
+ cr.fill ();
+
+ label_x = band_x + space;
+ }
+
+ double frame_size = 2 * line_width + space;
+ double available_vertical_space = r.height - 2 * frame_size;
+ if (expand_button.visible) {
+ available_vertical_space -= expand_button.height_request + space;
+ }
+
+ cr.save ();
+ cr.rectangle (label_x, r.y + frame_size,
+ band_width, available_vertical_space);
+ cr.clip ();
+ cr.rotate (-Math.PI / 2);
+
+ cr.set_source_rgb (1, 1, 1);
+ Pango.cairo_update_layout (cr, l);
+ double shift = Math.fmax (0, (available_vertical_space - lbl_width) / 2);
+ if (expand_button.visible) {
+ shift += expand_button.height_request + space;
+ }
+ cr.move_to (-(r.y + r.height - 2 * space - shift), label_x + space);
+ Pango.cairo_show_layout (cr, l);
- x0 = body_allocation.x + line_width_05;
- y0 = body_allocation.y + line_width_05;
- x1 = body_allocation.x + body_allocation.width - line_width_05;
- y1 = body_allocation.y + body_allocation.height - line_width_05;
-
- cr.move_to (x0 + round_size, y0);
- cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
- cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ cr.restore ();
+ }
+ }
- Cairo.set_color (cr, border_color);
+ cr.move_to (x1 + round_size - line_width_15, y1);
+ cr.arc (x1, y1, round_size - line_width_15, 0, Math.PI / 2);
+ cr.arc (x0, y1 - line_width, round_size - line_width_05, Math.PI / 2, Math.PI);
+ cr.arc (x0, y0, round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1 - line_width, y0, round_size - line_width_05, 3 * Math.PI / 2, 0);
+ cr.line_to (x1 + round_size - line_width_15, y1);
+ cr.set_line_width (line_width);
+ lin_grad = new Pattern.linear (0, r.y, 0, r.y + r.height - line_width);
+ Cairo.add_stop (lin_grad, 0.0, ColorScheme.get_color_relative (
+ _color_scheme.pretty_dark, 0.1));
+ Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+ cr.set_source (lin_grad);
cr.stroke ();
}
- if (arrow_size > 0) {
- double x, y;
-
- x = separator_x;
- y = body_allocation.y + (body_allocation.height - arrow_size) / 2.0;
-
- if (draw_separator) {
- double top = body_allocation.y + 2 * line_width;
- double bottom = body_allocation.y + body_allocation.height - 2 * line_width;
- cr.move_to (x - line_width / 2, top);
- cr.line_to (x - line_width / 2, bottom);
- cr.set_source_rgba (0, 0, 0, 0.1);
- cr.stroke ();
-
- cr.move_to (x + line_width / 2, top);
- cr.line_to (x + line_width / 2, bottom);
- cr.set_source_rgba (1, 1, 1, 0.6);
- cr.stroke ();
+ public Gdk.Color get_forecolor_for_ribbon_tabs (bool selected) {
+ if (selected) {
+ return Gdk.new_color (0, 0, 0);
+ } else {
+ return Gdk.new_color (255, 255, 255);
}
-
- x += arrow_size / 4.0 + line_width / 2.0;
-
- cr.move_to (x, y);
- cr.line_to (x, y + arrow_size);
- cr.line_to (x + arrow_size / 2.0, y + arrow_size / 2.0);
- cr.line_to (x, y);
- cr.set_source_rgb (0, 0, 0);
- cr.fill ();
}
- }
- /** Draws a group. */
- public void draw_group (Context cr, Gdk.Rectangle r, double round_size,
- double line_width, double space, Pango.Layout l,
- Gtk.Widget expand_button, RibbonGroup w) {
- double line_width_05 = line_width / 2, line_width_15 = 3 * line_width_05;
- Pattern lin_grad;
-
- double x0 = r.x + round_size;
- double x1 = r.x + r.width - round_size;
- double y0 = r.y + round_size;
- double y1 = r.y + r.height - round_size;
- cr.arc (x1, y1, round_size - line_width_05, 0, Math.PI / 2);
- cr.arc (x0 + line_width, y1, round_size - line_width_05, Math.PI / 2, Math.PI);
- cr.arc (x0, y0, round_size - line_width_15, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1, y0 + line_width, round_size - line_width_05, 3 * Math.PI / 2, 0);
- cr.line_to (x1 + round_size - line_width_05, y1);
- cr.set_line_width (line_width);
- Cairo.set_color (cr, _color_scheme.bright);
- cr.stroke ();
-
- if (l != null) {
- int lbl_width, lbl_height;
- Pango.cairo_update_layout (cr, l);
- l.get_pixel_size (out lbl_width, out lbl_height);
-
- if (w.label_position == PositionType.TOP
- || w.label_position == PositionType.BOTTOM) {
- double label_y;
- double band_height = lbl_height + 2 * space;
-
- if (w.label_position == PositionType.TOP) {
- cr.arc (x0, y0, round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1, y0, round_size - line_width_05, 3 * Math.PI / 2, 0);
- double band_y = y0 - round_size + 2 * line_width + band_height;
- cr.line_to (x1 + round_size - line_width_15, band_y);
- cr.line_to (x0 - round_size + line_width_05, band_y);
- lin_grad = new Pattern.linear (0, band_y - band_height, 0, band_y);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
+ /** Draws a ribbon. */
+ public void draw_ribbon (Context cr, Gdk.Rectangle menu_bar_allocation,
+ Gdk.Rectangle body_allocation, double round_size,
+ double line_width, Ribbon widget) {
+ double line_width_05 = line_width / 2;
+ double line_width_15 = 3 * line_width_05;
+ double x0, x1, y0, y1;
+ Pattern lin_grad;
+
+ // XXX: background painting
+ cr.set_source_rgb (0.3, 0.3, 0.3);
+ cr.paint ();
+ // XXX
+
+ if (menu_bar_allocation.height > 0) {
+ cr.rectangle (menu_bar_allocation.x, menu_bar_allocation.y,
+ menu_bar_allocation.width, menu_bar_allocation.height - 1);
+ lin_grad = new Pattern.linear (0, menu_bar_allocation.y, 0,
+ menu_bar_allocation.y + menu_bar_allocation.height - 1);
+ lin_grad.add_color_stop_rgba (0.0, 1, 1, 1, 0.5);
+ lin_grad.add_color_stop_rgba (0.3, 1, 1, 1, 0.2);
+ lin_grad.add_color_stop_rgba (0.3, 1, 1, 1, 0.0);
+ lin_grad.add_color_stop_rgba (1.0, 1, 1, 1, 0.5);
+
+ cr.set_source (lin_grad);
+ cr.fill ();
+
+ cr.move_to (menu_bar_allocation.x, Gdk.Rect.bottom (menu_bar_allocation) + 0.5);
+ cr.line_to (Gdk.Rect.right (menu_bar_allocation), Gdk.Rect.bottom (menu_bar_allocation) + 0.5);
+ cr.set_source_rgba (1, 1, 1, 0.5);
+ cr.set_line_width (1);
+ cr.stroke();
+
+ // Quick Access Toolbar background
+
+ Gdk.Rectangle alloc = (Gdk.Rectangle) widget.quick_access_toolbar.allocation; // XXX copy?
+ x0 = alloc.x;
+ x1 = Gdk.Rect.right (alloc) - 1;
+ y0 = alloc.y;
+ y1 = Gdk.Rect.bottom (alloc) - 1;
+ double radius = (y1 - y0) / 2;
+
+ cr.set_line_width (1);
+
+ if (widget.application_button != null) {
+ Gdk.Rectangle alloc2 = (Gdk.Rectangle) widget.application_button.allocation; // XXX
+ double cx = alloc2.x + alloc2.width / 2;
+ double cy = alloc2.y + alloc2.height / 2;
+ double radius2 = x0 - cx;
+ double alpha = Math.asin ((y0 - cy) / radius2);
+ double beta = Math.asin ((y1 - cy) / radius2);
+ double curve_width0 = Math.cos (Math.fabs (alpha)) * radius2;
+ double curve_width1 = Math.cos (Math.fabs (beta)) * radius2;
+ double curve_width = Math.fmin (curve_width0, curve_width1);
+
+ cr.save ();
+ cr.rectangle (cx + curve_width, y0, x1 - cx - curve_width, alloc.height);
+ cr.clip_preserve ();
+ cr.arc_negative (cx, cy, radius2, -alpha, -beta);
+ lin_grad = new Pattern.linear (0, y0, 0, y1);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.bright);
Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
cr.set_source (lin_grad);
+ // cr.set_source_rgb (1, 0, 0);
cr.fill ();
-
- label_y = band_y - band_height - space;
- } else {
- cr.arc (x1, y1, round_size - line_width_15, 0, Math.PI / 2);
- cr.arc (x0, y1 - line_width, round_size - line_width_05,
- Math.PI / 2, Math.PI);
- double band_y = y1 + round_size - 2 * line_width - band_height;
- cr.line_to (x0 - round_size + line_width_05, band_y);
- cr.line_to (x1 + round_size - line_width_15, band_y);
- lin_grad = new Pattern.linear (0, band_y, 0, band_y + band_height);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
- Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+ cr.restore ();
+ cr.arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
cr.set_source (lin_grad);
cr.fill ();
- label_y = band_y;
- }
+ cr.arc (cx, cy, radius2, alpha, beta);
+ cr.set_source_rgba (0, 0, 0, 0.6);
+ cr.stroke ();
+ radius2 -= 1;
+ cr.arc (cx, cy, radius2, alpha, beta);
+ cr.set_source_rgba (1, 1, 1, 0.4);
+ cr.stroke ();
- double frame_size = 2 * line_width + space;
- double available_horizontal_space = r.width - 2 * frame_size;
- if (expand_button.visible) {
- available_horizontal_space -= expand_button.width_request + space;
- }
+ cr.move_to (cx + curve_width0, y0 - 0.5);
+ cr.line_to (x1, y0 - 0.5);
+ cr.set_source_rgba (1, 1, 1, 0.4);
+ cr.stroke ();
- cr.save ();
- cr.rectangle (r.x + frame_size, label_y,
- available_horizontal_space, band_height);
- cr.clip ();
-
- cr.set_source_rgb (1, 1, 1);
- Pango.cairo_update_layout (cr, l);
- cr.move_to (r.x + frame_size
- + Math.fmax (0, (available_horizontal_space - lbl_width) / 2),
- label_y + space);
- Pango.cairo_show_layout (cr, l);
-
- cr.restore ();
- } else { // label at right or left
- double label_x;
- double band_width = lbl_height + 2 * space;
-
- if (w.label_position == PositionType.LEFT) {
- cr.arc (x0, y1, round_size - line_width_05, Math.PI / 2, Math.PI);
- cr.arc (x0, y0, round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
- double band_x = x0 - round_size + 2 * line_width + band_width;
- cr.line_to (band_x, y0 - round_size + line_width_05);
- cr.line_to (band_x, y1 + round_size - line_width_15);
- lin_grad = new Pattern.linear (band_x - band_width, 0, band_x, 0);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
- Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
- cr.set_source (lin_grad);
- cr.fill ();
+ cr.move_to (cx + curve_width0, y0 + 0.5);
+ cr.line_to (x1, y0 + 0.5);
+ cr.set_source_rgba (0, 0, 0, 0.6);
+ cr.stroke ();
- label_x = band_x - band_width - space;
+ cr.move_to (cx + curve_width1, y1 - 0.5);
+ cr.line_to (x1, y1 - 0.5);
+ cr.set_source_rgba (0, 0, 0, 0.6);
+ cr.stroke ();
+
+ cr.move_to (cx + curve_width1, y1 + 0.5);
+ cr.line_to (x1, y1 + 0.5);
+ cr.set_source_rgba (1, 1, 1, 0.4);
+ cr.stroke ();
} else {
- cr.arc (x1, y0 - line_width_05, round_size - line_width_15,
- 3 * Math.PI / 2, 0);
- cr.arc (x1, y1, round_size - line_width_15, 0, Math.PI / 2);
- double band_x = x1 + round_size - 2 * line_width - band_width;
- cr.line_to (band_x, y1 + round_size - line_width_15);
- cr.line_to (band_x, y0 - round_size + line_width_05);
- lin_grad = new Pattern.linear (band_x, 0, band_x + band_width, 0);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.dark);
+ cr.rectangle (x0, y0, x1 - x0, alloc.height);
+ lin_grad = new Pattern.linear (0, y0, 0, y1);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.bright);
Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
cr.set_source (lin_grad);
cr.fill ();
- label_x = band_x + space;
- }
-
- double frame_size = 2 * line_width + space;
- double available_vertical_space = r.height - 2 * frame_size;
- if (expand_button.visible) {
- available_vertical_space -= expand_button.height_request + space;
- }
+ cr.arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
+ cr.set_source (lin_grad);
+ cr.fill ();
- cr.save ();
- cr.rectangle (label_x, r.y + frame_size,
- band_width, available_vertical_space);
- cr.clip ();
- cr.rotate (-Math.PI / 2);
+ cr.move_to (x0 + 0.5, y0);
+ cr.line_to (x0 + 0.5, y1);
+ cr.set_source_rgba (1, 1, 1, 0.4);
+ cr.stroke ();
- cr.set_source_rgb (1, 1, 1);
- Pango.cairo_update_layout (cr, l);
- double shift = Math.fmax (0, (available_vertical_space - lbl_width) / 2);
- if (expand_button.visible) {
- shift += expand_button.height_request + space;
+ cr.move_to (x0 + 1.5, y0);
+ cr.line_to (x0 + 1.5, y1);
+ cr.set_source_rgba (0, 0, 0, 0.6);
+ cr.stroke ();
}
- cr.move_to (-(r.y + r.height - 2 * space - shift), label_x + space);
- Pango.cairo_show_layout (cr, l);
-
- cr.restore ();
- }
- }
-
- cr.move_to (x1 + round_size - line_width_15, y1);
- cr.arc (x1, y1, round_size - line_width_15, 0, Math.PI / 2);
- cr.arc (x0, y1 - line_width, round_size - line_width_05, Math.PI / 2, Math.PI);
- cr.arc (x0, y0, round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1 - line_width, y0, round_size - line_width_05, 3 * Math.PI / 2, 0);
- cr.line_to (x1 + round_size - line_width_15, y1);
- cr.set_line_width (line_width);
- lin_grad = new Pattern.linear (0, r.y, 0, r.y + r.height - line_width);
- Cairo.add_stop (lin_grad, 0.0, ColorScheme.get_color_relative (
- _color_scheme.pretty_dark, 0.1));
- Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
- cr.set_source (lin_grad);
- cr.stroke ();
- }
-
- public Gdk.Color get_forecolor_for_ribbon_tabs (bool selected) {
- if (selected) {
- return Gdk.new_color (0, 0, 0);
- } else {
- return Gdk.new_color (255, 255, 255);
- }
- }
-
- /** Draws a ribbon. */
- public void draw_ribbon (Context cr, Gdk.Rectangle menu_bar_allocation,
- Gdk.Rectangle body_allocation, double round_size,
- double line_width, Ribbon widget) {
- double line_width_05 = line_width / 2;
- double line_width_15 = 3 * line_width_05;
- double x0, x1, y0, y1;
- Pattern lin_grad;
-
- // XXX: background painting
- cr.set_source_rgb (0.3, 0.3, 0.3);
- cr.paint ();
- // XXX
-
- if (menu_bar_allocation.height > 0) {
- cr.rectangle (menu_bar_allocation.x, menu_bar_allocation.y,
- menu_bar_allocation.width, menu_bar_allocation.height - 1);
- lin_grad = new Pattern.linear (0, menu_bar_allocation.y, 0,
- menu_bar_allocation.y + menu_bar_allocation.height - 1);
- lin_grad.add_color_stop_rgba (0.0, 1, 1, 1, 0.5);
- lin_grad.add_color_stop_rgba (0.3, 1, 1, 1, 0.2);
- lin_grad.add_color_stop_rgba (0.3, 1, 1, 1, 0.0);
- lin_grad.add_color_stop_rgba (1.0, 1, 1, 1, 0.5);
-
- cr.set_source (lin_grad);
- cr.fill ();
-
- cr.move_to (menu_bar_allocation.x, Gdk.Rect.bottom (menu_bar_allocation) + 0.5);
- cr.line_to (Gdk.Rect.right (menu_bar_allocation), Gdk.Rect.bottom (menu_bar_allocation) + 0.5);
- cr.set_source_rgba (1, 1, 1, 0.5);
- cr.set_line_width (1);
- cr.stroke();
- // Quick Access Toolbar background
-
- Gdk.Rectangle alloc = (Gdk.Rectangle) widget.quick_access_toolbar.allocation; // XXX copy?
- x0 = alloc.x;
- x1 = Gdk.Rect.right (alloc) - 1;
- y0 = alloc.y;
- y1 = Gdk.Rect.bottom (alloc) - 1;
- double radius = (y1 - y0) / 2;
-
- cr.set_line_width (1);
+ cr.arc (x1, y0 + radius, radius + 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
+ cr.set_source_rgba (1, 1, 1, 0.4);
+ cr.stroke ();
- if (widget.application_button != null) {
- Gdk.Rectangle alloc2 = (Gdk.Rectangle) widget.application_button.allocation; // XXX
- double cx = alloc2.x + alloc2.width / 2;
- double cy = alloc2.y + alloc2.height / 2;
- double radius2 = x0 - cx;
- double alpha = Math.asin ((y0 - cy) / radius2);
- double beta = Math.asin ((y1 - cy) / radius2);
- double curve_width0 = Math.cos (Math.fabs (alpha)) * radius2;
- double curve_width1 = Math.cos (Math.fabs (beta)) * radius2;
- double curve_width = Math.fmin (curve_width0, curve_width1);
-
- cr.save ();
- cr.rectangle (cx + curve_width, y0, x1 - cx - curve_width, alloc.height);
- cr.clip_preserve ();
- cr.arc_negative (cx, cy, radius2, -alpha, -beta);
- lin_grad = new Pattern.linear (0, y0, 0, y1);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.bright);
- Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
- cr.set_source (lin_grad);
-// cr.set_source_rgb (1, 0, 0);
- cr.fill ();
- cr.restore ();
cr.arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
- cr.set_source (lin_grad);
- cr.fill ();
-
- cr.arc (cx, cy, radius2, alpha, beta);
cr.set_source_rgba (0, 0, 0, 0.6);
cr.stroke ();
- radius2 -= 1;
- cr.arc (cx, cy, radius2, alpha, beta);
- cr.set_source_rgba (1, 1, 1, 0.4);
- cr.stroke ();
+ }
- cr.move_to (cx + curve_width0, y0 - 0.5);
- cr.line_to (x1, y0 - 0.5);
- cr.set_source_rgba (1, 1, 1, 0.4);
- cr.stroke ();
+ RibbonPage p = widget.current_page;
+ if (p == null) {
+ return;
+ }
- cr.move_to (cx + curve_width0, y0 + 0.5);
- cr.line_to (x1, y0 + 0.5);
- cr.set_source_rgba (0, 0, 0, 0.6);
- cr.stroke ();
+ // Color c = _color_scheme.get_color_absoulte (_color_scheme.bright, 0.92);
+ Color c = _color_scheme.normal;
- cr.move_to (cx + curve_width1, y1 - 0.5);
- cr.line_to (x1, y1 - 0.5);
- cr.set_source_rgba (0, 0, 0, 0.6);
- cr.stroke ();
+ if (body_allocation.height > 0) {
+ // *** PAGE ***
- cr.move_to (cx + curve_width1, y1 + 0.5);
- cr.line_to (x1, y1 + 0.5);
- cr.set_source_rgba (1, 1, 1, 0.4);
+ x0 = body_allocation.x;
+ x1 = body_allocation.x + body_allocation.width;
+ y0 = body_allocation.y;
+ y1 = body_allocation.y + body_allocation.height;
+
+ cr.arc (x0 + round_size, y1 - round_size,
+ round_size - line_width_05, Math.PI / 2, Math.PI);
+ cr.arc (x0 + round_size, y0 + round_size,
+ round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1 - round_size, y0 + round_size,
+ round_size - line_width_05, 3 * Math.PI / 2, 0);
+ cr.arc (x1 - round_size, y1 - round_size,
+ round_size - line_width_05, 0, Math.PI/2);
+ cr.line_to (x0 + round_size, y1 - line_width_05);
+
+ // *** BACKGOUND ***
+ Cairo.set_color (cr, c);
+ cr.fill_preserve ();
+
+ // *** DARK BORDER ***
+ cr.set_line_width (line_width);
+ Cairo.set_color (cr, ColorScheme.get_color_absolute (
+ _color_scheme.normal, 0.75));
cr.stroke ();
- } else {
- cr.rectangle (x0, y0, x1 - x0, alloc.height);
- lin_grad = new Pattern.linear (0, y0, 0, y1);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.bright);
- Cairo.add_stop (lin_grad, 1.0, _color_scheme.pretty_dark);
+
+ // *** GLASS EFFECT ***
+ double ymid = Math.round (y0 + (y1 - y0) * 0.25);
+
+ cr.arc (x0 + round_size, y0 + round_size,
+ round_size - line_width, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1 - round_size, y0 + round_size,
+ round_size - line_width, 3 * Math.PI / 2, 0);
+ cr.line_to (x1 - line_width, ymid);
+ cr.line_to (x0 + line_width, ymid);
+ cr.line_to (x0 + line_width, y0 + round_size);
+ lin_grad = new Pattern.linear (0, y0, 0, ymid);
+ lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.0);
+ lin_grad.add_color_stop_rgba (1.0, 0, 0, 0, 0.075);
cr.set_source (lin_grad);
cr.fill ();
- cr.arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
+ cr.arc (x0 + round_size, y1 - round_size,
+ round_size - line_width, Math.PI / 2, Math.PI);
+ cr.line_to (x0 + line_width, ymid);
+ cr.line_to (x1 - line_width, ymid);
+ cr.arc (x1 - round_size, y1 - round_size,
+ round_size - line_width, 0, Math.PI / 2);
+ cr.line_to (x0 + round_size, y1 - line_width);
+ lin_grad = new Pattern.linear (0, ymid, 0, y1);
+ lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.1);
+ lin_grad.add_color_stop_rgba (0.5, 0, 0, 0, 0.0);
cr.set_source (lin_grad);
cr.fill ();
-
- cr.move_to (x0 + 0.5, y0);
- cr.line_to (x0 + 0.5, y1);
- cr.set_source_rgba (1, 1, 1, 0.4);
- cr.stroke ();
-
- cr.move_to (x0 + 1.5, y0);
- cr.line_to (x0 + 1.5, y1);
- cr.set_source_rgba (0, 0, 0, 0.6);
- cr.stroke ();
}
- cr.arc (x1, y0 + radius, radius + 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
- cr.set_source_rgba (1, 1, 1, 0.4);
- cr.stroke ();
+ // *** TAB ***
- cr.arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
- cr.set_source_rgba (0, 0, 0, 0.6);
- cr.stroke ();
- }
+ Gdk.Rectangle r = p.label_allocation;
- RibbonPage p = widget.current_page;
- if (p == null) {
- return;
- }
+ x0 = r.x;
+ x1 = r.x + r.width;
+ y0 = r.y;
+ y1 = r.y + r.height + line_width;
-// Color c = _color_scheme.get_color_absoulte (_color_scheme.bright, 0.92);
- Color c = _color_scheme.normal;
+ // *** TAB :: BACKGROUND ***
- if (body_allocation.height > 0) {
- // *** PAGE ***
+ cr.move_to (x0 + line_width_05, y1);
+ cr.line_to (x0 + line_width_05, y0 + round_size);
+ cr.arc (x0 + round_size, y0 + round_size,
+ round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1 - round_size, y0 + round_size,
+ round_size - line_width_05, 3 * Math.PI / 2, 0);
+ cr.line_to (x1 - line_width_05, y1);
- x0 = body_allocation.x;
- x1 = body_allocation.x + body_allocation.width;
- y0 = body_allocation.y;
- y1 = body_allocation.y + body_allocation.height;
+ lin_grad = new Pattern.linear (0, y0, 0, y1);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.pretty_bright);
+ Cairo.add_stop (lin_grad, 1.0, c);
+ cr.set_source (lin_grad);
+ cr.fill ();
- cr.arc (x0 + round_size, y1 - round_size,
- round_size - line_width_05, Math.PI / 2, Math.PI);
+ // *** TAB :: DARK BORDER ***
+
+ cr.move_to (x0 + line_width_05, y1);
+ cr.line_to (x0 + line_width_05, y0 + round_size);
cr.arc (x0 + round_size, y0 + round_size,
round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
cr.arc (x1 - round_size, y0 + round_size,
round_size - line_width_05, 3 * Math.PI / 2, 0);
- cr.arc (x1 - round_size, y1 - round_size,
- round_size - line_width_05, 0, Math.PI/2);
- cr.line_to (x0 + round_size, y1 - line_width_05);
-
- // *** BACKGOUND ***
- Cairo.set_color (cr, c);
- cr.fill_preserve ();
+ cr.line_to (x1 - line_width_05, y1);
- // *** DARK BORDER ***
cr.set_line_width (line_width);
- Cairo.set_color (cr, ColorScheme.get_color_absolute (
- _color_scheme.normal, 0.75));
+ Cairo.set_color (cr, ColorScheme.get_color_relative (_color_scheme.bright, -0.1));
cr.stroke ();
- // *** GLASS EFFECT ***
- double ymid = Math.round (y0 + (y1 - y0) * 0.25);
-
+ y1 -= 1.0;
+
+ // *** TAB :: HIGHLIGHT ***
+
+ cr.move_to (x0 + line_width_15, y1);
+ cr.line_to (x0 + line_width_15, y0 + round_size);
cr.arc (x0 + round_size, y0 + round_size,
- round_size - line_width, Math.PI, 3 * Math.PI / 2);
+ round_size - line_width_15, Math.PI, 3 * Math.PI / 2);
cr.arc (x1 - round_size, y0 + round_size,
- round_size - line_width, 3 * Math.PI / 2, 0);
- cr.line_to (x1 - line_width, ymid);
- cr.line_to (x0 + line_width, ymid);
- cr.line_to (x0 + line_width, y0 + round_size);
- lin_grad = new Pattern.linear (0, y0, 0, ymid);
- lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.0);
- lin_grad.add_color_stop_rgba (1.0, 0, 0, 0, 0.075);
- cr.set_source (lin_grad);
- cr.fill ();
+ round_size - line_width_15, 3 * Math.PI / 2, 0);
+ cr.line_to (x1 - line_width_15, y1);
- cr.arc (x0 + round_size, y1 - round_size,
- round_size - line_width, Math.PI / 2, Math.PI);
- cr.line_to (x0 + line_width, ymid);
- cr.line_to (x1 - line_width, ymid);
- cr.arc (x1 - round_size, y1 - round_size,
- round_size - line_width, 0, Math.PI / 2);
- cr.line_to (x0 + round_size, y1 - line_width);
- lin_grad = new Pattern.linear (0, ymid, 0, y1);
- lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.1);
- lin_grad.add_color_stop_rgba (0.5, 0, 0, 0, 0.0);
+ cr.set_line_width (line_width);
+ lin_grad = new Pattern.linear (0, y0 + line_width, 0, y1);
+ Cairo.add_stop (lin_grad, 0.0, _color_scheme.pretty_bright);
+ Cairo.add_stop (lin_grad, 1.0, ColorScheme.set_alpha_channel (
+ _color_scheme.bright, 0));
cr.set_source (lin_grad);
- cr.fill ();
- }
-
- // *** TAB ***
-
- Gdk.Rectangle r = p.label_allocation;
-
- x0 = r.x;
- x1 = r.x + r.width;
- y0 = r.y;
- y1 = r.y + r.height + line_width;
-
- // *** TAB :: BACKGROUND ***
-
- cr.move_to (x0 + line_width_05, y1);
- cr.line_to (x0 + line_width_05, y0 + round_size);
- cr.arc (x0 + round_size, y0 + round_size,
- round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1 - round_size, y0 + round_size,
- round_size - line_width_05, 3 * Math.PI / 2, 0);
- cr.line_to (x1 - line_width_05, y1);
-
- lin_grad = new Pattern.linear (0, y0, 0, y1);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.pretty_bright);
- Cairo.add_stop (lin_grad, 1.0, c);
- cr.set_source (lin_grad);
- cr.fill ();
-
- // *** TAB :: DARK BORDER ***
-
- cr.move_to (x0 + line_width_05, y1);
- cr.line_to (x0 + line_width_05, y0 + round_size);
- cr.arc (x0 + round_size, y0 + round_size,
- round_size - line_width_05, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1 - round_size, y0 + round_size,
- round_size - line_width_05, 3 * Math.PI / 2, 0);
- cr.line_to (x1 - line_width_05, y1);
-
- cr.set_line_width (line_width);
- Cairo.set_color (cr, ColorScheme.get_color_relative (_color_scheme.bright, -0.1));
- cr.stroke ();
-
- y1 -= 1.0;
-
- // *** TAB :: HIGHLIGHT ***
-
- cr.move_to (x0 + line_width_15, y1);
- cr.line_to (x0 + line_width_15, y0 + round_size);
- cr.arc (x0 + round_size, y0 + round_size,
- round_size - line_width_15, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1 - round_size, y0 + round_size,
- round_size - line_width_15, 3 * Math.PI / 2, 0);
- cr.line_to (x1 - line_width_15, y1);
-
- cr.set_line_width (line_width);
- lin_grad = new Pattern.linear (0, y0 + line_width, 0, y1);
- Cairo.add_stop (lin_grad, 0.0, _color_scheme.pretty_bright);
- Cairo.add_stop (lin_grad, 1.0, ColorScheme.set_alpha_channel (
- _color_scheme.bright, 0));
- cr.set_source (lin_grad);
- cr.stroke ();
-
- // *** TAB :: SHADOW ***
-
- cr.move_to (x0 - line_width_05, y1);
- cr.line_to (x0 - line_width_05, y0 + round_size);
- cr.arc (x0 + round_size, y0 + round_size,
- round_size + line_width_05, Math.PI, 3 * Math.PI / 2);
- cr.arc (x1 - round_size, y0 + round_size,
- round_size + line_width_05, 3 * Math.PI / 2, 0);
- cr.line_to (x1 + line_width_05, y1);
-
- cr.set_line_width (line_width);
- cr.set_source_rgba (0, 0, 0, 0.2);
- cr.stroke ();
- }
+ cr.stroke ();
- /** Draws an application button. */
- public void draw_application_button (Context cr, Gdk.Rectangle body_allocation,
- ButtonState state, double line_width,
- BaseButton widget) {
- double drop_shadow_offset = 1; // XXX: local consts not yet in Vala
- double radius = (body_allocation.height - drop_shadow_offset) / 2;
-
- double x = body_allocation.x + radius + drop_shadow_offset;
- double y = body_allocation.y + radius + drop_shadow_offset;
- cr.arc (x, y, radius, 0, 2 * Math.PI);
- cr.set_source_rgba (0, 0, 0, 0.5);
- cr.fill ();
-
- cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
- switch (state) {
- case ButtonState.HOVER:
- cr.set_source_rgb (0.9, 0.815, 0.533);
- break;
- case ButtonState.PRESSED:
- cr.set_source_rgb (0.886, 0.639, 0.356);
- break;
- default:
- cr.set_source_rgb (0.8, 0.8, 0.8);
- break;
- }
- cr.fill ();
+ // *** TAB :: SHADOW ***
- cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
- var lin_grad = new Pattern.linear (0, body_allocation.y, 0, body_allocation.y + body_allocation.height);
- lin_grad.add_color_stop_rgba (0.0, 1, 1, 1, 0.9);
- lin_grad.add_color_stop_rgba (0.5, 1, 1, 1, 0.0);
- lin_grad.add_color_stop_rgba (1.0, 1, 1, 1, 1.0);
- cr.set_source (lin_grad);
- cr.fill ();
-
- cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
- lin_grad = new Pattern.linear (0, body_allocation.y, 0, body_allocation.y + body_allocation.height);
- lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.0);
- lin_grad.add_color_stop_rgba (0.4, 0, 0, 0, 0.0);
- lin_grad.add_color_stop_rgba (0.5, 0, 0, 0, 0.1);
- lin_grad.add_color_stop_rgba (0.75, 0, 0, 0, 0.0);
- lin_grad.add_color_stop_rgba (1.0, 0, 0, 0, 0.0);
- cr.set_source (lin_grad);
- cr.fill ();
-
- cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, Math.PI);
- lin_grad = new Pattern.linear (0, body_allocation.y + radius, 0, body_allocation.y + body_allocation.height);
- lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.0);
- lin_grad.add_color_stop_rgba (1.0, 0, 0, 0, 0.5);
- cr.set_source (lin_grad);
- cr.set_line_width (1.0);
- cr.stroke ();
-
- cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, Math.PI, 0);
- lin_grad = new Pattern.linear (0, body_allocation.y, 0, body_allocation.y + radius);
- lin_grad.add_color_stop_rgba (0.0, 1, 1, 1, 0.5);
- lin_grad.add_color_stop_rgba (1.0, 1, 1, 1, 0.0);
- cr.set_line_width (1.0);
- cr.stroke ();
-
- cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
- var rad_grad = new Pattern.radial (
- body_allocation.x + radius, body_allocation.y + 1.5 * radius, 0,
- body_allocation.x + radius, body_allocation.y + 1.5 * radius, 0.5 * radius);
- rad_grad.add_color_stop_rgba (0, 1, 1, 1, 0.4);
- rad_grad.add_color_stop_rgba (1, 1, 1, 1, 0.0);
- cr.set_source (rad_grad);
- cr.fill ();
- }
+ cr.move_to (x0 - line_width_05, y1);
+ cr.line_to (x0 - line_width_05, y0 + round_size);
+ cr.arc (x0 + round_size, y0 + round_size,
+ round_size + line_width_05, Math.PI, 3 * Math.PI / 2);
+ cr.arc (x1 - round_size, y0 + round_size,
+ round_size + line_width_05, 3 * Math.PI / 2, 0);
+ cr.line_to (x1 + line_width_05, y1);
- /** Draws a button. */
- public void draw_button (Context cr, Gdk.Rectangle body_allocation,
- ButtonState state, double round_size,
- double line_width, double arrow_size,
- double arrow_padding, bool draw_separator,
- BaseButton widget) {
- double line_width_05 = line_width / 2;
- double line_width_15 = line_width_05 * 3;
-
- bool up_left = true;
- bool up_right = true;
- bool down_right = true;
- bool down_left = true;
- switch (widget.group_style) {
- case GroupStyle.LEFT:
- up_right = down_right = false;
- break;
- case GroupStyle.CENTER:
- up_left = down_left = up_right = down_right = false;
- break;
- case GroupStyle.RIGHT:
- up_left = down_left = false;
- break;
+ cr.set_line_width (line_width);
+ cr.set_source_rgba (0, 0, 0, 0.2);
+ cr.stroke ();
}
- cr.set_line_width (line_width);
-
- if (state == ButtonState.PRESSED || state == ButtonState.HOVER) {
- Pattern body_pattern;
- Pattern inner_border_pattern;
- Color border_color;
+ /** Draws an application button. */
+ public void draw_application_button (Context cr, Gdk.Rectangle body_allocation,
+ ButtonState state, double line_width,
+ BaseButton widget) {
+ double drop_shadow_offset = 1; // XXX: local consts not yet in Vala
+ double radius = (body_allocation.height - drop_shadow_offset) / 2;
+
+ double x = body_allocation.x + radius + drop_shadow_offset;
+ double y = body_allocation.y + radius + drop_shadow_offset;
+ cr.arc (x, y, radius, 0, 2 * Math.PI);
+ cr.set_source_rgba (0, 0, 0, 0.5);
+ cr.fill ();
- if (state == ButtonState.PRESSED) {
- body_pattern = new Pattern.linear (
- body_allocation.x,
- body_allocation.y,
- body_allocation.x,
- body_allocation.y + body_allocation.height);
- body_pattern.add_color_stop_rgb (0.0, 0.996, 0.847, 0.667);
- body_pattern.add_color_stop_rgb (0.37, 0.984, 0.710, 0.396);
- body_pattern.add_color_stop_rgb (0.43, 0.980, 0.616, 0.204);
- body_pattern.add_color_stop_rgb (1.0, 0.992, 0.933, 0.667);
+ cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
+ switch (state) {
+ case ButtonState.HOVER:
+ cr.set_source_rgb (0.9, 0.815, 0.533);
+ break;
+ case ButtonState.PRESSED:
+ cr.set_source_rgb (0.886, 0.639, 0.356);
+ break;
+ default:
+ cr.set_source_rgb (0.8, 0.8, 0.8);
+ break;
+ }
+ cr.fill ();
- inner_border_pattern = new Pattern.linear (
- body_allocation.x,
- body_allocation.y,
- body_allocation.x + body_allocation.width,
- body_allocation.y + body_allocation.height);
- inner_border_pattern.add_color_stop_rgba (0.0, 0.876, 0.718, 0.533, 1);
- inner_border_pattern.add_color_stop_rgba (1.0, 0.876, 0.718, 0.533, 0);
+ cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
+ var lin_grad = new Pattern.linear (0, body_allocation.y, 0, body_allocation.y + body_allocation.height);
+ lin_grad.add_color_stop_rgba (0.0, 1, 1, 1, 0.9);
+ lin_grad.add_color_stop_rgba (0.5, 1, 1, 1, 0.0);
+ lin_grad.add_color_stop_rgba (1.0, 1, 1, 1, 1.0);
+ cr.set_source (lin_grad);
+ cr.fill ();
- border_color = Color.from_rgb (0.671, 0.631, 0.549);
- } else {
- body_pattern = new Pattern.linear (
- body_allocation.x,
- body_allocation.y,
- body_allocation.x,
- body_allocation.y + body_allocation.height);
- body_pattern.add_color_stop_rgb (0.0, 1, 0.996, 0.890);
- body_pattern.add_color_stop_rgb (0.37, 1, 0.906, 0.592);
- body_pattern.add_color_stop_rgb (0.43, 1, 0.843, 0.314);
- body_pattern.add_color_stop_rgb (1.0, 1, 0.906, 0.588);
+ cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
+ lin_grad = new Pattern.linear (0, body_allocation.y, 0, body_allocation.y + body_allocation.height);
+ lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.0);
+ lin_grad.add_color_stop_rgba (0.4, 0, 0, 0, 0.0);
+ lin_grad.add_color_stop_rgba (0.5, 0, 0, 0, 0.1);
+ lin_grad.add_color_stop_rgba (0.75, 0, 0, 0, 0.0);
+ lin_grad.add_color_stop_rgba (1.0, 0, 0, 0, 0.0);
+ cr.set_source (lin_grad);
+ cr.fill ();
- inner_border_pattern = new Pattern.linear (
- body_allocation.x,
- body_allocation.y,
- body_allocation.x + body_allocation.width,
- body_allocation.x + body_allocation.height);
- inner_border_pattern.add_color_stop_rgba (0.0, 1, 1, 0.969, 1);
- inner_border_pattern.add_color_stop_rgba (1.0, 1, 1, 0.969, 0);
+ cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, Math.PI);
+ lin_grad = new Pattern.linear (0, body_allocation.y + radius, 0, body_allocation.y + body_allocation.height);
+ lin_grad.add_color_stop_rgba (0.0, 0, 0, 0, 0.0);
+ lin_grad.add_color_stop_rgba (1.0, 0, 0, 0, 0.5);
+ cr.set_source (lin_grad);
+ cr.set_line_width (1.0);
+ cr.stroke ();
- border_color = Color.from_rgb (0.824, 0.753, 0.553);
- }
+ cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, Math.PI, 0);
+ lin_grad = new Pattern.linear (0, body_allocation.y, 0, body_allocation.y + radius);
+ lin_grad.add_color_stop_rgba (0.0, 1, 1, 1, 0.5);
+ lin_grad.add_color_stop_rgba (1.0, 1, 1, 1, 0.0);
+ cr.set_line_width (1.0);
+ cr.stroke ();
- double x0 = body_allocation.x + line_width_05;
- double y0 = body_allocation.y + line_width_05;
- double x1 = body_allocation.x + body_allocation.width - line_width_05;
- double y1 = body_allocation.y + body_allocation.height - line_width_05;
+ cr.arc (body_allocation.x + radius, body_allocation.y + radius, radius, 0, 2 * Math.PI);
+ var rad_grad = new Pattern.radial (
+ body_allocation.x + radius, body_allocation.y + 1.5 * radius, 0,
+ body_allocation.x + radius, body_allocation.y + 1.5 * radius, 0.5 * radius);
+ rad_grad.add_color_stop_rgba (0, 1, 1, 1, 0.4);
+ rad_grad.add_color_stop_rgba (1, 1, 1, 1, 0.0);
+ cr.set_source (rad_grad);
+ cr.fill ();
+ }
- if (up_left) {
- cr.move_to (x0 + round_size, y0);
- } else {
- cr.move_to (x0, y0);
- }
- if (up_right) {
- cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
- } else {
- cr.line_to (x1, y0);
- }
- if (down_right) {
- cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- } else {
- cr.line_to (x1, y1);
- }
- if (down_left) {
- cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
- } else {
- cr.line_to (x0, y1);
- }
- if (up_left) {
- cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
- } else {
- cr.line_to (x0, y0);
+ /** Draws a button. */
+ public void draw_button (Context cr, Gdk.Rectangle body_allocation,
+ ButtonState state, double round_size,
+ double line_width, double arrow_size,
+ double arrow_padding, bool draw_separator,
+ BaseButton widget) {
+ double line_width_05 = line_width / 2;
+ double line_width_15 = line_width_05 * 3;
+
+ bool up_left = true;
+ bool up_right = true;
+ bool down_right = true;
+ bool down_left = true;
+ switch (widget.group_style) {
+ case GroupStyle.LEFT:
+ up_right = down_right = false;
+ break;
+ case GroupStyle.CENTER:
+ up_left = down_left = up_right = down_right = false;
+ break;
+ case GroupStyle.RIGHT:
+ up_left = down_left = false;
+ break;
}
- cr.set_source (body_pattern);
- cr.fill ();
+ cr.set_line_width (line_width);
- x0 = body_allocation.x + line_width_15;
- y0 = body_allocation.y + line_width_15;
- x1 = body_allocation.x + body_allocation.width - line_width_15;
- y1 = body_allocation.y + body_allocation.height - line_width_15;
+ if (state == ButtonState.PRESSED || state == ButtonState.HOVER) {
+ Pattern body_pattern;
+ Pattern inner_border_pattern;
+ Color border_color;
+
+ if (state == ButtonState.PRESSED) {
+ body_pattern = new Pattern.linear (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.x,
+ body_allocation.y + body_allocation.height);
+ body_pattern.add_color_stop_rgb (0.0, 0.996, 0.847, 0.667);
+ body_pattern.add_color_stop_rgb (0.37, 0.984, 0.710, 0.396);
+ body_pattern.add_color_stop_rgb (0.43, 0.980, 0.616, 0.204);
+ body_pattern.add_color_stop_rgb (1.0, 0.992, 0.933, 0.667);
+
+ inner_border_pattern = new Pattern.linear (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.x + body_allocation.width,
+ body_allocation.y + body_allocation.height);
+ inner_border_pattern.add_color_stop_rgba (0.0, 0.876, 0.718, 0.533, 1);
+ inner_border_pattern.add_color_stop_rgba (1.0, 0.876, 0.718, 0.533, 0);
- double round_size_minus_line_width = round_size - line_width;
+ border_color = Color.from_rgb (0.671, 0.631, 0.549);
+ } else {
+ body_pattern = new Pattern.linear (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.x,
+ body_allocation.y + body_allocation.height);
+ body_pattern.add_color_stop_rgb (0.0, 1, 0.996, 0.890);
+ body_pattern.add_color_stop_rgb (0.37, 1, 0.906, 0.592);
+ body_pattern.add_color_stop_rgb (0.43, 1, 0.843, 0.314);
+ body_pattern.add_color_stop_rgb (1.0, 1, 0.906, 0.588);
+
+ inner_border_pattern = new Pattern.linear (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.x + body_allocation.width,
+ body_allocation.x + body_allocation.height);
+ inner_border_pattern.add_color_stop_rgba (0.0, 1, 1, 0.969, 1);
+ inner_border_pattern.add_color_stop_rgba (1.0, 1, 1, 0.969, 0);
- if (widget.group_style != GroupStyle.LEFT) {
- x0 -= line_width;
- }
+ border_color = Color.from_rgb (0.824, 0.753, 0.553);
+ }
- if (up_left) cr.move_to (x0 + round_size_minus_line_width, y0);
- else cr.move_to (x0, y0);
- if (up_right) cr.arc (x1 - round_size_minus_line_width, y0 + round_size_minus_line_width, round_size_minus_line_width, 1.5 * Math.PI, 0);
- else cr.line_to (x1, y0);
- if (down_right) cr.arc (x1 - round_size_minus_line_width, y1 - round_size_minus_line_width, round_size_minus_line_width, 0, 0.5 * Math.PI);
- else cr.line_to (x1, y1);
- if (down_left) cr.arc (x0 + round_size_minus_line_width, y1 - round_size_minus_line_width, round_size_minus_line_width, 0.5 * Math.PI, Math.PI);
- else cr.line_to (x0, y1);
- if (up_left) cr.arc (x0 + round_size_minus_line_width, y0 + round_size_minus_line_width, round_size_minus_line_width, Math.PI, 1.5 * Math.PI);
- else cr.line_to (x0, y0);
+ double x0 = body_allocation.x + line_width_05;
+ double y0 = body_allocation.y + line_width_05;
+ double x1 = body_allocation.x + body_allocation.width - line_width_05;
+ double y1 = body_allocation.y + body_allocation.height - line_width_05;
- if (widget.group_style != GroupStyle.LEFT) {
- x0 += line_width;
- }
+ if (up_left) {
+ cr.move_to (x0 + round_size, y0);
+ } else {
+ cr.move_to (x0, y0);
+ }
+ if (up_right) {
+ cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
+ } else {
+ cr.line_to (x1, y0);
+ }
+ if (down_right) {
+ cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
+ } else {
+ cr.line_to (x1, y1);
+ }
+ if (down_left) {
+ cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ } else {
+ cr.line_to (x0, y1);
+ }
+ if (up_left) {
+ cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ } else {
+ cr.line_to (x0, y0);
+ }
- cr.set_source (inner_border_pattern);
- cr.stroke ();
+ cr.set_source (body_pattern);
+ cr.fill ();
- x0 = body_allocation.x + line_width_05;
- y0 = body_allocation.y + line_width_05;
- x1 = body_allocation.x + body_allocation.width - line_width_05;
- y1 = body_allocation.y + body_allocation.height - line_width_05;
-
- if (up_left) cr.move_to (x0 + round_size, y0);
- else cr.move_to (x0, y0);
- if (up_right) cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
- else cr.line_to (x1, y0);
- if (down_right) cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- else cr.line_to (x1, y1);
- if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
- else cr.line_to (x0, y1);
- if (widget.group_style == GroupStyle.LEFT) {
- if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
- else cr.line_to (x0, y0);
- }
+ x0 = body_allocation.x + line_width_15;
+ y0 = body_allocation.y + line_width_15;
+ x1 = body_allocation.x + body_allocation.width - line_width_15;
+ y1 = body_allocation.y + body_allocation.height - line_width_15;
- Cairo.set_color (cr, border_color);
- cr.stroke ();
- } else if (widget.draw_background) {
- var body_pattern = new Pattern.linear (
- body_allocation.x,
- body_allocation.y,
- body_allocation.x,
- body_allocation.y + body_allocation.height);
- body_pattern.add_color_stop_rgba (0.0, 1, 1, 1, 0.7);
- body_pattern.add_color_stop_rgba (0.37, 1, 1, 1, 0.2);
- body_pattern.add_color_stop_rgba (0.43, 1, 1, 1, 0.2);
- body_pattern.add_color_stop_rgba (1.0, 1, 1, 1, 0.7);
-
- double x0 = body_allocation.x + line_width_05;
- double y0 = body_allocation.y + line_width_05;
- double x1 = body_allocation.x + body_allocation.width - line_width_05;
- double y1 = body_allocation.y + body_allocation.height - line_width_05;
-
- if (up_left) cr.move_to (x0 + round_size, y0);
- else cr.move_to (x0, y0);
- if (up_right) cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
- else cr.line_to (x1, y0);
- if (down_right) cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- else cr.line_to (x1, y1);
- if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
- else cr.line_to (x0, y1);
- if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
- else cr.line_to (x0, y0);
+ double round_size_minus_line_width = round_size - line_width;
- cr.set_source (body_pattern);
- cr.fill ();
+ if (widget.group_style != GroupStyle.LEFT) {
+ x0 -= line_width;
+ }
- if (widget.group_style != GroupStyle.LEFT) {
- if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
- else cr.move_to (x0, y1);
- if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ if (up_left) cr.move_to (x0 + round_size_minus_line_width, y0);
+ else cr.move_to (x0, y0);
+ if (up_right) cr.arc (x1 - round_size_minus_line_width, y0 + round_size_minus_line_width, round_size_minus_line_width, 1.5 * Math.PI, 0);
+ else cr.line_to (x1, y0);
+ if (down_right) cr.arc (x1 - round_size_minus_line_width, y1 - round_size_minus_line_width, round_size_minus_line_width, 0, 0.5 * Math.PI);
+ else cr.line_to (x1, y1);
+ if (down_left) cr.arc (x0 + round_size_minus_line_width, y1 - round_size_minus_line_width, round_size_minus_line_width, 0.5 * Math.PI, Math.PI);
+ else cr.line_to (x0, y1);
+ if (up_left) cr.arc (x0 + round_size_minus_line_width, y0 + round_size_minus_line_width, round_size_minus_line_width, Math.PI, 1.5 * Math.PI);
else cr.line_to (x0, y0);
- cr.set_source_rgba (1, 1, 1, 0.8);
+ if (widget.group_style != GroupStyle.LEFT) {
+ x0 += line_width;
+ }
+
+ cr.set_source (inner_border_pattern);
cr.stroke ();
- }
- if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
- else cr.move_to (x0, y0);
- if (up_right) cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
- else cr.line_to (x1, y0);
- if (down_right) cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
- else cr.line_to (x1, y1);
- if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
- else cr.line_to (x0, y1);
- if (widget.group_style == GroupStyle.LEFT) {
- if (up_left) {
- cr.line_to (x0, y0 + round_size);
- } else {
- cr.line_to (x0, y0);
+ x0 = body_allocation.x + line_width_05;
+ y0 = body_allocation.y + line_width_05;
+ x1 = body_allocation.x + body_allocation.width - line_width_05;
+ y1 = body_allocation.y + body_allocation.height - line_width_05;
+
+ if (up_left) cr.move_to (x0 + round_size, y0);
+ else cr.move_to (x0, y0);
+ if (up_right) cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
+ else cr.line_to (x1, y0);
+ if (down_right) cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
+ else cr.line_to (x1, y1);
+ if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ else cr.line_to (x0, y1);
+ if (widget.group_style == GroupStyle.LEFT) {
+ if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ else cr.line_to (x0, y0);
}
- }
-
- cr.set_source_rgba (0, 0, 0, 0.2);
- cr.stroke ();
- }
- if (arrow_size > 0) {
- double x, y;
+ Cairo.set_color (cr, border_color);
+ cr.stroke ();
+ } else if (widget.draw_background) {
+ var body_pattern = new Pattern.linear (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.x,
+ body_allocation.y + body_allocation.height);
+ body_pattern.add_color_stop_rgba (0.0, 1, 1, 1, 0.7);
+ body_pattern.add_color_stop_rgba (0.37, 1, 1, 1, 0.2);
+ body_pattern.add_color_stop_rgba (0.43, 1, 1, 1, 0.2);
+ body_pattern.add_color_stop_rgba (1.0, 1, 1, 1, 0.7);
+
+ double x0 = body_allocation.x + line_width_05;
+ double y0 = body_allocation.y + line_width_05;
+ double x1 = body_allocation.x + body_allocation.width - line_width_05;
+ double y1 = body_allocation.y + body_allocation.height - line_width_05;
+
+ if (up_left) cr.move_to (x0 + round_size, y0);
+ else cr.move_to (x0, y0);
+ if (up_right) cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
+ else cr.line_to (x1, y0);
+ if (down_right) cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
+ else cr.line_to (x1, y1);
+ if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ else cr.line_to (x0, y1);
+ if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ else cr.line_to (x0, y0);
- switch (widget.image_position) {
- case Gtk.PositionType.BOTTOM:
- case Gtk.PositionType.TOP:
- x = body_allocation.x + (body_allocation.width - arrow_size) / 2.0;
- y = body_allocation.y + body_allocation.height - 2 * line_width
- - arrow_size - 2 * arrow_padding;
+ cr.set_source (body_pattern);
+ cr.fill ();
- if (draw_separator) {
- double left = body_allocation.x + 2 * line_width;
- double right = body_allocation.x + body_allocation.width - 2 * line_width;
+ if (widget.group_style != GroupStyle.LEFT) {
+ if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ else cr.move_to (x0, y1);
+ if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ else cr.line_to (x0, y0);
- cr.move_to (left, y - line_width / 2);
- cr.line_to (right, y - line_width / 2);
- cr.set_source_rgba (0, 0, 0, 0.1);
+ cr.set_source_rgba (1, 1, 1, 0.8);
cr.stroke ();
+ }
- cr.move_to (left, y + line_width / 2);
- cr.line_to (right, y + line_width / 2);
- cr.set_source_rgba (1, 1, 1, 0.6);
- cr.stroke ();
+ if (up_left) cr.arc (x0 + round_size, y0 + round_size, round_size, Math.PI, 1.5 * Math.PI);
+ else cr.move_to (x0, y0);
+ if (up_right) cr.arc (x1 - round_size, y0 + round_size, round_size, 1.5 * Math.PI, 0);
+ else cr.line_to (x1, y0);
+ if (down_right) cr.arc (x1 - round_size, y1 - round_size, round_size, 0, 0.5 * Math.PI);
+ else cr.line_to (x1, y1);
+ if (down_left) cr.arc (x0 + round_size, y1 - round_size, round_size, 0.5 * Math.PI, Math.PI);
+ else cr.line_to (x0, y1);
+ if (widget.group_style == GroupStyle.LEFT) {
+ if (up_left) {
+ cr.line_to (x0, y0 + round_size);
+ } else {
+ cr.line_to (x0, y0);
+ }
}
- y += arrow_padding;
- break;
- default:
- x = body_allocation.x + body_allocation.width - 2 * line_width
- - arrow_size - 2 * arrow_padding;
- y = body_allocation.y + (body_allocation.height - arrow_size) / 2.0;
+ cr.set_source_rgba (0, 0, 0, 0.2);
+ cr.stroke ();
+ }
- if (draw_separator) {
- double top = body_allocation.y + 2 * line_width;
- double bottom = body_allocation.y
- + body_allocation.height
- - 2 * line_width;
- cr.move_to (x - line_width / 2, top);
- cr.line_to (x - line_width / 2, bottom);
- cr.set_source_rgba (0, 0, 0, 0.1);
- cr.stroke ();
+ if (arrow_size > 0) {
+ double x, y;
- cr.move_to (x + line_width / 2, top);
- cr.line_to (x + line_width / 2, bottom);
- cr.set_source_rgba (1, 1, 1, 0.6);
- cr.stroke ();
+ switch (widget.image_position) {
+ case Gtk.PositionType.BOTTOM:
+ case Gtk.PositionType.TOP:
+ x = body_allocation.x + (body_allocation.width - arrow_size) / 2.0;
+ y = body_allocation.y + body_allocation.height - 2 * line_width
+ - arrow_size - 2 * arrow_padding;
+
+ if (draw_separator) {
+ double left = body_allocation.x + 2 * line_width;
+ double right = body_allocation.x + body_allocation.width - 2 * line_width;
+
+ cr.move_to (left, y - line_width / 2);
+ cr.line_to (right, y - line_width / 2);
+ cr.set_source_rgba (0, 0, 0, 0.1);
+ cr.stroke ();
+
+ cr.move_to (left, y + line_width / 2);
+ cr.line_to (right, y + line_width / 2);
+ cr.set_source_rgba (1, 1, 1, 0.6);
+ cr.stroke ();
+ }
+
+ y += arrow_padding;
+ break;
+ default:
+ x = body_allocation.x + body_allocation.width - 2 * line_width
+ - arrow_size - 2 * arrow_padding;
+ y = body_allocation.y + (body_allocation.height - arrow_size) / 2.0;
+
+ if (draw_separator) {
+ double top = body_allocation.y + 2 * line_width;
+ double bottom = body_allocation.y
+ + body_allocation.height
+ - 2 * line_width;
+ cr.move_to (x - line_width / 2, top);
+ cr.line_to (x - line_width / 2, bottom);
+ cr.set_source_rgba (0, 0, 0, 0.1);
+ cr.stroke ();
+
+ cr.move_to (x + line_width / 2, top);
+ cr.line_to (x + line_width / 2, bottom);
+ cr.set_source_rgba (1, 1, 1, 0.6);
+ cr.stroke ();
+ }
+
+ x += arrow_padding;
+ break;
}
- x += arrow_padding;
- break;
+ y += arrow_size / 4.0 + line_width / 2.0;
+ cr.move_to (x, y);
+ cr.line_to (x + arrow_size, y);
+ cr.line_to (x + arrow_size / 2.0, y + arrow_size / 2.0);
+ cr.line_to (x, y);
+ cr.set_source_rgba (0, 0, 0, 1.0);
+ cr.fill ();
}
+ }
- y += arrow_size / 4.0 + line_width / 2.0;
- cr.move_to (x, y);
- cr.line_to (x + arrow_size, y);
- cr.line_to (x + arrow_size / 2.0, y + arrow_size / 2.0);
- cr.line_to (x, y);
- cr.set_source_rgba (0, 0, 0, 1.0);
- cr.fill ();
+ /** Draws a gallery. */
+ public void draw_gallery (Context cr, Gdk.Rectangle body_allocation,
+ Gdk.Rectangle tiles_allocation, Gallery widget) {
+ cr.set_source_rgba (0, 0, 0, 0.3);
+ cr.set_line_width (1);
+ cr.rectangle (
+ tiles_allocation.x - 0.5,
+ tiles_allocation.y - 0.5,
+ tiles_allocation.width + 1.0,
+ tiles_allocation.height + 1.0);
+ cr.stroke ();
}
- }
- /** Draws a gallery. */
- public void draw_gallery (Context cr, Gdk.Rectangle body_allocation,
- Gdk.Rectangle tiles_allocation, Gallery widget) {
- cr.set_source_rgba (0, 0, 0, 0.3);
- cr.set_line_width (1);
- cr.rectangle (
- tiles_allocation.x - 0.5,
- tiles_allocation.y - 0.5,
- tiles_allocation.width + 1.0,
- tiles_allocation.height + 1.0);
- cr.stroke ();
- }
+ /** Draws a tile. */
+ public void draw_tile (Context cr, Gdk.Rectangle body_allocation,
+ Gdk.Rectangle content_allocation, Tile widget) {
+ if (widget.selected) {
+ var grad = new Pattern.linear (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.x,
+ body_allocation.y + body_allocation.height);
+ grad.add_color_stop_rgb (0.00, 0.9922, 0.7373, 0.4353);
+ grad.add_color_stop_rgb (0.27, 0.9961, 0.8039, 0.5569);
+ grad.add_color_stop_rgb (0.33, 0.9961, 0.7255, 0.4078);
+ grad.add_color_stop_rgb (1.00, 0.9843, 0.8980, 0.6313);
+ cr.set_source (grad);
+ cr.rectangle (
+ body_allocation.x,
+ body_allocation.y,
+ body_allocation.width,
+ body_allocation.height);
+ cr.fill ();
+ }
- /** Draws a tile. */
- public void draw_tile (Context cr, Gdk.Rectangle body_allocation,
- Gdk.Rectangle content_allocation, Tile widget) {
- if (widget.selected) {
- var grad = new Pattern.linear (
- body_allocation.x,
- body_allocation.y,
- body_allocation.x,
- body_allocation.y + body_allocation.height);
- grad.add_color_stop_rgb (0.00, 0.9922, 0.7373, 0.4353);
- grad.add_color_stop_rgb (0.27, 0.9961, 0.8039, 0.5569);
- grad.add_color_stop_rgb (0.33, 0.9961, 0.7255, 0.4078);
- grad.add_color_stop_rgb (1.00, 0.9843, 0.8980, 0.6313);
- cr.set_source (grad);
+ cr.set_source_rgb (1, 1, 1);
cr.rectangle (
- body_allocation.x,
- body_allocation.y,
- body_allocation.width,
- body_allocation.height);
+ content_allocation.x,
+ content_allocation.y,
+ content_allocation.width,
+ content_allocation.height);
cr.fill ();
}
-
- cr.set_source_rgb (1, 1, 1);
- cr.rectangle (
- content_allocation.x,
- content_allocation.y,
- content_allocation.width,
- content_allocation.height);
- cr.fill ();
}
}
Modified: trunk/geetk/ribbon/tile.vala
==============================================================================
--- trunk/geetk/ribbon/tile.vala (original)
+++ trunk/geetk/ribbon/tile.vala Thu Jul 24 15:19:51 2008
@@ -1,130 +1,133 @@
using Gtk;
-/**
- * The Tile widget.
- */
-public abstract class Tile : Widget {
-
- /** Gets or sets the width of the border. */
- private uint _border_width;
- public uint border_width {
- set {
- _border_width = value;
- queue_draw ();
+namespace Geetk {
+
+ /**
+ * The Tile widget.
+ */
+ public abstract class Tile : Widget {
+
+ /** Gets or sets the width of the border. */
+ private uint _border_width;
+ public uint border_width {
+ set {
+ _border_width = value;
+ queue_draw ();
+ }
+ get { return _border_width; }
}
- get { return _border_width; }
- }
- /** Gets or sets the state of the Tile. */
- private bool _selected;
- public bool selected {
- set {
- _selected = value;
- queue_draw ();
+ /** Gets or sets the state of the Tile. */
+ private bool _selected;
+ public bool selected {
+ set {
+ _selected = value;
+ queue_draw ();
+ }
+ get { return _selected; }
}
- get { return _selected; }
- }
- /** Fired when the Tile has been clicked. */
- public signal void clicked ();
+ /** Fired when the Tile has been clicked. */
+ public signal void clicked ();
- /** Theme used to draw the widget. */
- private Theme _theme = new Theme ();
- public Theme theme {
- set {
- _theme = value;
- queue_draw ();
+ /** Theme used to draw the widget. */
+ private Theme _theme = new Theme ();
+ public Theme theme {
+ set {
+ _theme = value;
+ queue_draw ();
+ }
+ get { return _theme; }
}
- get { return _theme; }
- }
- /** Construction method */
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
+ /** Construction method */
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
- this.selected = false;
- this.border_width = 4;
- }
-
- /** Creates a carbon copy of the current Tile. */
- public abstract Tile copy ();
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+
+ this.selected = false;
+ this.border_width = 4;
+ }
- protected override bool expose_event (Gdk.EventExpose evnt) {
- var cr = Gdk.cairo_create (this.window);
+ /** Creates a carbon copy of the current Tile. */
+ public abstract Tile copy ();
- Gdk.Rectangle area;
- area.x = evnt.area.x;
- area.y = evnt.area.y;
- area.width = evnt.area.width;
- area.height = evnt.area.height;
- Gdk.Rectangle alloc;
- alloc.x = this.allocation.x;
- alloc.y = this.allocation.y;
- alloc.width = this.allocation.width;
- alloc.height = this.allocation.height;
- Gdk.Rectangle content_area;
- content_area.x = alloc.x + (int) this.border_width;
- content_area.y = alloc.y + (int) this.border_width;
- content_area.width = alloc.width - 2 * (int) this.border_width;
- content_area.height = alloc.height - 2 * (int) this.border_width;
-
- cr.rectangle (area.x, area.y, area.width, area.height);
- cr.clip ();
- _theme.draw_tile (cr, alloc, content_area, this);
-
- draw_content (cr, content_area);
-
-// cr.target.dispose ();
-// cr.dispose ();
-
-// return base.expose_event (evnt);
- return false;
- }
+ protected override bool expose_event (Gdk.EventExpose evnt) {
+ var cr = Gdk.cairo_create (this.window);
- /**
- * Draws the content of the tile.
- *
- * @param context Cairo context to be used to draw the content.
- * @param area Area that can be painted.
- */
- public abstract void draw_content (Cairo.Context context, Gdk.Rectangle area);
-
- // TODO
+ Gdk.Rectangle area;
+ area.x = evnt.area.x;
+ area.y = evnt.area.y;
+ area.width = evnt.area.width;
+ area.height = evnt.area.height;
+ Gdk.Rectangle alloc;
+ alloc.x = this.allocation.x;
+ alloc.y = this.allocation.y;
+ alloc.width = this.allocation.width;
+ alloc.height = this.allocation.height;
+ Gdk.Rectangle content_area;
+ content_area.x = alloc.x + (int) this.border_width;
+ content_area.y = alloc.y + (int) this.border_width;
+ content_area.width = alloc.width - 2 * (int) this.border_width;
+ content_area.height = alloc.height - 2 * (int) this.border_width;
+
+ cr.rectangle (area.x, area.y, area.width, area.height);
+ cr.clip ();
+ _theme.draw_tile (cr, alloc, content_area, this);
+
+ draw_content (cr, content_area);
+
+ // cr.target.dispose ();
+ // cr.dispose ();
+
+ // return base.expose_event (evnt);
+ return false;
+ }
- protected override bool button_press_event (Gdk.EventButton evnt) {
-// bool ret = base.button_press_event (evnt);
- bool ret = false;
+ /**
+ * Draws the content of the tile.
+ *
+ * @param context Cairo context to be used to draw the content.
+ * @param area Area that can be painted.
+ */
+ public abstract void draw_content (Cairo.Context context, Gdk.Rectangle area);
+
+ // TODO
+
+ protected override bool button_press_event (Gdk.EventButton evnt) {
+ // bool ret = base.button_press_event (evnt);
+ bool ret = false;
+
+ queue_draw ();
+ return ret;
+ }
- queue_draw ();
- return ret;
- }
-
- protected override bool button_release_event (Gdk.EventButton evnt) {
-// bool ret = base.button_release_event (evnt);
- bool ret = false;
- clicked ();
- queue_draw ();
- return ret;
- }
-
- protected override bool enter_notify_event (Gdk.EventCrossing evnt) {
-// bool ret = base.enter_notify_event (evnt);
- bool ret = false;
+ protected override bool button_release_event (Gdk.EventButton evnt) {
+ // bool ret = base.button_release_event (evnt);
+ bool ret = false;
+ clicked ();
+ queue_draw ();
+ return ret;
+ }
- queue_draw ();
- return ret;
- }
-
- protected override bool leave_notify_event (Gdk.EventCrossing evnt) {
-// bool ret = base.leave_notify_event (evnt);
- bool ret = false;
+ protected override bool enter_notify_event (Gdk.EventCrossing evnt) {
+ // bool ret = base.enter_notify_event (evnt);
+ bool ret = false;
+
+ queue_draw ();
+ return ret;
+ }
- queue_draw ();
- return ret;
+ protected override bool leave_notify_event (Gdk.EventCrossing evnt) {
+ // bool ret = base.leave_notify_event (evnt);
+ bool ret = false;
+
+ queue_draw ();
+ return ret;
+ }
}
}
Modified: trunk/geetk/ribbon/toggle-button.vala
==============================================================================
--- trunk/geetk/ribbon/toggle-button.vala (original)
+++ trunk/geetk/ribbon/toggle-button.vala Thu Jul 24 15:19:51 2008
@@ -1,229 +1,231 @@
using Cairo;
using Gtk;
-/** Toggle button to be used in Ribbons. */
-public class ToggleButton : BaseButton {
+namespace Geetk {
- protected const double LINE_WIDTH = 1.0;
+ /** Toggle button to be used in Ribbons. */
+ public class ToggleButton : BaseButton {
- public signal void value_changed ();
+ protected const double LINE_WIDTH = 1.0;
- private bool _value;
- public bool value {
- set {
- if (_value != value) {
- _value = value;
- value_changed ();
+ public signal void value_changed ();
+
+ private bool _value;
+ public bool value {
+ set {
+ if (_value != value) {
+ _value = value;
+ value_changed ();
+ }
}
+ get { return _value; }
}
- get { return _value; }
- }
-
- /** Construction method */
- construct {
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
-
- this.padding = 2;
- this.image_position = PositionType.TOP;
- _is_small = false;
- _enabled = true;
- _value = false;
- }
-
- /**
- * Constructor given a label to display.
- *
- * @param label Label to display.
- */
- public ToggleButton.with_label (string label) {
- this.label = label;
- }
- /**
- * Constructor given an image to display.
- *
- * @param image Image to display
- */
- public ToggleButton.with_image (Image image) {
- this.image = image;
- }
-
- /**
- * Constructor given a label and an image to display.
- *
- * @param image Image to display.
- * @param label Label to display.
- */
- public ToggleButton (Image image, string label) {
- this.image = image;
- this.label = label;
- }
+ /** Construction method */
+ construct {
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+
+ this.padding = 2;
+ this.image_position = PositionType.TOP;
+ _is_small = false;
+ _enabled = true;
+ _value = false;
+ }
+
+ /**
+ * Constructor given a label to display.
+ *
+ * @param label Label to display.
+ */
+ public ToggleButton.with_label (string label) {
+ this.label = label;
+ }
+
+ /**
+ * Constructor given an image to display.
+ *
+ * @param image Image to display
+ */
+ public ToggleButton.with_image (Image image) {
+ this.image = image;
+ }
+
+ /**
+ * Constructor given a label and an image to display.
+ *
+ * @param image Image to display.
+ * @param label Label to display.
+ */
+ public ToggleButton (Image image, string label) {
+ this.image = image;
+ this.label = label;
+ }
+
+ /**
+ * Constructs a Button from a stock.
+ *
+ * @param name Name of the stock.
+ * @param large <b>true</b> if the image should be large,
+ * <b>false</b> otherwise.
+ */
+ public static ToggleButton from_stock (string name, bool large) {
+ var image = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
+ : IconSize.SMALL_TOOLBAR);
+ var button = new ToggleButton.with_image (image);
+ if (!large) {
+ button.image_position = PositionType.LEFT;
+ }
+ return button;
+ }
- /**
- * Constructs a Button from a stock.
- *
- * @param name Name of the stock.
- * @param large <b>true</b> if the image should be large,
- * <b>false</b> otherwise.
- */
- public static ToggleButton from_stock (string name, bool large) {
- var image = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
- : IconSize.SMALL_TOOLBAR);
- var button = new ToggleButton.with_image (image);
- if (!large) {
- button.image_position = PositionType.LEFT;
+ /**
+ * Constructs a Button from a stock.
+ *
+ * @param name Name of the stock.
+ * @param label Label to display.
+ * @param large <b>true</b> if the image should be large,
+ * <b>false</b> otherwise.
+ */
+ public static ToggleButton from_stock_with_label (string name, string label, bool large) {
+ var image = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
+ : IconSize.SMALL_TOOLBAR);
+ var button = new ToggleButton (image, label);
+ if (!large) {
+ button.image_position = PositionType.LEFT;
+ }
+ return button;
}
- return button;
- }
- /**
- * Constructs a Button from a stock.
- *
- * @param name Name of the stock.
- * @param label Label to display.
- * @param large <b>true</b> if the image should be large,
- * <b>false</b> otherwise.
- */
- public static ToggleButton from_stock_with_label (string name, string label, bool large) {
- var image = new Image.from_stock (name, large ? IconSize.LARGE_TOOLBAR
- : IconSize.SMALL_TOOLBAR);
- var button = new ToggleButton (image, label);
- if (!large) {
- button.image_position = PositionType.LEFT;
+ protected override bool bound_widget_button_press_event (Widget sender,
+ Gdk.EventButton evnt) {
+ event ((Gdk.Event) evnt);
+ return false;
}
- return button;
- }
- protected override bool bound_widget_button_press_event (Widget sender,
- Gdk.EventButton evnt) {
- event ((Gdk.Event) evnt);
- return false;
- }
+ protected override bool bound_widget_button_release_event (Widget sender,
+ Gdk.EventButton evnt) {
+ event ((Gdk.Event) evnt);
+ this.value = !this.value;
+ queue_draw ();
+ return false;
+ }
- protected override bool bound_widget_button_release_event (Widget sender,
- Gdk.EventButton evnt) {
- event ((Gdk.Event) evnt);
- this.value = !this.value;
- queue_draw ();
- return false;
- }
+ protected override void size_request (Requisition requisition) {
+ // base.size_request (requisition);
- protected override void size_request (Requisition requisition) {
-// base.size_request (requisition);
+ Requisition child_requisition = Requisition ();
+ if (this.child != null && this.child.visible) {
+ this.child.size_request (child_requisition);
+ }
- Requisition child_requisition = Requisition ();
- if (this.child != null && this.child.visible) {
- this.child.size_request (child_requisition);
+ if (this.height_request == -1) {
+ requisition.height = child_requisition.height
+ + (int) (LINE_WIDTH * 4 + _padding * 2);
+ }
+ if (this.width_request == -1) {
+ requisition.width = child_requisition.width
+ + (int) (LINE_WIDTH * 4 + _padding * 2);
+ }
}
- if (this.height_request == -1) {
- requisition.height = child_requisition.height
- + (int) (LINE_WIDTH * 4 + _padding * 2);
- }
- if (this.width_request == -1) {
- requisition.width = child_requisition.width
- + (int) (LINE_WIDTH * 4 + _padding * 2);
- }
- }
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocate (allocation);
+ this.allocation = (Allocation) allocation; // FIXME: workaround
+
+ allocation.x += (int) (LINE_WIDTH * 2 + _padding);
+ allocation.y += (int) (LINE_WIDTH * 2 + _padding);
+ allocation.height -= (int) (LINE_WIDTH * 4 + _padding * 2);
+ allocation.width -= (int) (LINE_WIDTH * 4 + _padding * 2);
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocate (allocation);
- this.allocation = (Allocation) allocation; // FIXME: workaround
-
- allocation.x += (int) (LINE_WIDTH * 2 + _padding);
- allocation.y += (int) (LINE_WIDTH * 2 + _padding);
- allocation.height -= (int) (LINE_WIDTH * 4 + _padding * 2);
- allocation.width -= (int) (LINE_WIDTH * 4 + _padding * 2);
-
- if (allocation.height < 0) {
- allocation.height = 0;
- }
- if (allocation.width < 0) {
- allocation.width = 0;
- }
+ if (allocation.height < 0) {
+ allocation.height = 0;
+ }
+ if (allocation.width < 0) {
+ allocation.width = 0;
+ }
- if (this.child != null && this.child.visible) {
- this.child.size_allocate (allocation);
+ if (this.child != null && this.child.visible) {
+ this.child.size_allocate (allocation);
+ }
}
- }
- protected override bool expose_event (Gdk.EventExpose evnt) {
- var cr = Gdk.cairo_create (this.window);
+ protected override bool expose_event (Gdk.EventExpose evnt) {
+ var cr = Gdk.cairo_create (this.window);
- cr.rectangle (evnt.area.x, evnt.area.y,
- evnt.area.width, evnt.area.height);
- cr.clip ();
- draw (cr);
-
-// cr.target.dispose ();
-// cr.dispose ();
-
-// return base.expose_event (evnt);
- // *** workaround ***
- if (this.child != null) {
- this.child.expose_event (evnt);
+ cr.rectangle (evnt.area.x, evnt.area.y,
+ evnt.area.width, evnt.area.height);
+ cr.clip ();
+ draw (cr);
+
+ // cr.target.dispose ();
+ // cr.dispose ();
+
+ // return base.expose_event (evnt);
+ // *** workaround ***
+ if (this.child != null) {
+ this.child.expose_event (evnt);
+ }
+ return false;
+ // *** workaround ***
}
- return false;
- // *** workaround ***
- }
- protected void draw (Context cr) {
- Gdk.Rectangle rect;
- rect.x = this.allocation.x;
- rect.y = this.allocation.y;
- rect.width = this.allocation.width;
- rect.height = this.allocation.height;
- double round_size = _is_small ? 2.0 : 3.0;
- var s = _state;
- if (_value == true) {
- s = Theme.ButtonState.PRESSED;
+ protected void draw (Context cr) {
+ Gdk.Rectangle rect;
+ rect.x = this.allocation.x;
+ rect.y = this.allocation.y;
+ rect.width = this.allocation.width;
+ rect.height = this.allocation.height;
+ double round_size = _is_small ? 2.0 : 3.0;
+ var s = _state;
+ if (_value == true) {
+ s = Theme.ButtonState.PRESSED;
+ }
+ _theme.draw_button (cr, rect, s, round_size, LINE_WIDTH, 0, 0, false, this);
}
- _theme.draw_button (cr, rect, s, round_size, LINE_WIDTH, 0, 0, false, this);
- }
- protected override bool button_press_event (Gdk.EventButton evnt) {
-// bool ret = base.button_press_event (evnt);
- bool ret = false;
- _state = Theme.ButtonState.PRESSED;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool button_press_event (Gdk.EventButton evnt) {
+ // bool ret = base.button_press_event (evnt);
+ bool ret = false;
+ _state = Theme.ButtonState.PRESSED;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
- protected override bool button_release_event (Gdk.EventButton evnt) {
-// bool ret = base.button_release_event (evnt);
- bool ret = false;
- _state = Theme.ButtonState.HOVER;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool button_release_event (Gdk.EventButton evnt) {
+ // bool ret = base.button_release_event (evnt);
+ bool ret = false;
+ _state = Theme.ButtonState.HOVER;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
- protected override bool enter_notify_event (Gdk.EventCrossing evnt) {
-// bool ret = base.enter_notify_event (evnt);
- bool ret = false;
- _state = Theme.ButtonState.HOVER;
- if (!_enabled) {
- _state = Theme.ButtonState.DEFAULT;
+ protected override bool enter_notify_event (Gdk.EventCrossing evnt) {
+ // bool ret = base.enter_notify_event (evnt);
+ bool ret = false;
+ _state = Theme.ButtonState.HOVER;
+ if (!_enabled) {
+ _state = Theme.ButtonState.DEFAULT;
+ }
+ queue_draw ();
+ return ret;
}
- queue_draw ();
- return ret;
- }
- protected override bool leave_notify_event (Gdk.EventCrossing evnt) {
-// bool ret = base.leave_notify_event (evnt);
- bool ret = false;
- _state = Theme.ButtonState.DEFAULT;
- queue_draw ();
- return ret;
+ protected override bool leave_notify_event (Gdk.EventCrossing evnt) {
+ // bool ret = base.leave_notify_event (evnt);
+ bool ret = false;
+ _state = Theme.ButtonState.DEFAULT;
+ queue_draw ();
+ return ret;
+ }
}
}
-
Modified: trunk/geetk/ribbon/tool-box.vala
==============================================================================
--- trunk/geetk/ribbon/tool-box.vala (original)
+++ trunk/geetk/ribbon/tool-box.vala Thu Jul 24 15:19:51 2008
@@ -2,241 +2,244 @@
using Gee;
using Gtk;
-/** ToolBox containing several widgets displayed in rows. */
-public class ToolBox : Container {
+namespace Geetk {
- private Gee.List<Widget> _widgets;
- private Gtk.Requisition[] _requisitions;
+ /** ToolBox containing several widgets displayed in rows. */
+ public class ToolBox : Container {
- /** Gets or sets the spacing between children. */
- private int _spacing;
- public int spacing {
- set {
- _spacing = value;
- queue_draw ();
+ private Gee.List<Widget> _widgets;
+ private Gtk.Requisition[] _requisitions;
+
+ /** Gets or sets the spacing between children. */
+ private int _spacing;
+ public int spacing {
+ set {
+ _spacing = value;
+ queue_draw ();
+ }
+ get { return _spacing; }
}
- get { return _spacing; }
- }
- /** Construction method */
- construct {
- _widgets = new Gee.ArrayList<Widget> ();
+ /** Construction method */
+ construct {
+ _widgets = new Gee.ArrayList<Widget> ();
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
- _spacing = 2;
- }
-
- /**
- * Adds a widget before all existing widgets.
- *
- * @param widget The widget to add.
- */
- public void prepend (Widget widget) {
- insert (widget, 0);
- }
-
- /**
- * Adds a widget after all existing widgets.
- *
- * @param widget The widget to add.
- */
- public void append (Widget widget) {
- insert (widget, -1);
- }
-
- /**
- * Inserts a widget at the specified location.
- *
- * @param widget The widget to add.
- * @param index The index (starting at 0) at which the widget must
- * be inserted, or -1 to insert the widget after all
- * existing widgets.
- */
- public void insert (Widget widget, int index) {
- widget.set_parent (this);
- widget.visible = true;
-
- if (index == -1) {
- _widgets.add (widget);
- } else {
- _widgets.insert (index, widget);
+ _spacing = 2;
}
-
- show_all ();
- }
-
- /**
- * Removes the widget at the specified index.
- *
- * @param index Index of the widget to remove.
- */
- public void remove (int index) {
- _widgets.get (index).parent = null;
-
- if (index == -1) {
- _widgets.remove_at (_widgets.size - 1);
- } else {
- _widgets.remove_at (index);
+
+ /**
+ * Adds a widget before all existing widgets.
+ *
+ * @param widget The widget to add.
+ */
+ public void prepend (Widget widget) {
+ insert (widget, 0);
}
- show_all ();
- }
+ /**
+ * Adds a widget after all existing widgets.
+ *
+ * @param widget The widget to add.
+ */
+ public void append (Widget widget) {
+ insert (widget, -1);
+ }
+
+ /**
+ * Inserts a widget at the specified location.
+ *
+ * @param widget The widget to add.
+ * @param index The index (starting at 0) at which the widget must
+ * be inserted, or -1 to insert the widget after all
+ * existing widgets.
+ */
+ public void insert (Widget widget, int index) {
+ widget.set_parent (this);
+ widget.visible = true;
- protected override void forall (bool include_internals, Gtk.Callback callback) {
- foreach (var widget in _widgets) {
- if (widget.visible) {
- callback (widget);
+ if (index == -1) {
+ _widgets.add (widget);
+ } else {
+ _widgets.insert (index, widget);
}
+
+ show_all ();
}
- }
- protected override void size_request (Requisition requisition) {
-// base.size_request (requisition);
+ /**
+ * Removes the widget at the specified index.
+ *
+ * @param index Index of the widget to remove.
+ */
+ public void remove (int index) {
+ _widgets.get (index).parent = null;
- if (_requisitions == null || _requisitions.length != _widgets.size) {
- _requisitions = new Gtk.Requisition[_widgets.size];
+ if (index == -1) {
+ _widgets.remove_at (_widgets.size - 1);
+ } else {
+ _widgets.remove_at (index);
+ }
+
+ show_all ();
}
- int total_width = 0;
- int row_height = 0;
- foreach (var widget in _widgets) {
- if (widget.visible) {
- Requisition req;
- widget.size_request (req);
- row_height = int.max (row_height, req.height);
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ foreach (var widget in _widgets) {
+ if (widget.visible) {
+ callback (widget);
+ }
}
}
- int i = 0;
- foreach (var widget in _widgets) {
- if (widget.visible) {
- widget.height_request = row_height;
- // FIXME workaround
- Requisition req;
- widget.size_request (req);
- _requisitions[i] = req;
- // FIXME workaround
- total_width += _requisitions[i].width;
- }
- ++i;
- }
-
- if (this.width_request != -1 && this.height_request != -1) {
- requisition.width = this.width_request;
- requisition.height = this.height_request;
- } else if (this.width_request != -1) {
- int total_height = row_height;
- int cur_width = 0;
- int avail_width = this.width_request - 2 * (int) this.border_width;
+ protected override void size_request (Requisition requisition) {
+ // base.size_request (requisition);
+
+ if (_requisitions == null || _requisitions.length != _widgets.size) {
+ _requisitions = new Gtk.Requisition[_widgets.size];
+ }
- i = 0;
+ int total_width = 0;
+ int row_height = 0;
foreach (var widget in _widgets) {
if (widget.visible) {
- Gtk.Requisition r = _requisitions[i];
-
- if (cur_width == 0 || cur_width + r.width <= avail_width) {
- // Continue current line
- cur_width += r.width;
- if (cur_width != 0) {
- cur_width += _spacing;
- }
- } else {
- // Start new line
- total_height += row_height + _spacing;
- cur_width = 0;
- }
+ Requisition req;
+ widget.size_request (req);
+ row_height = int.max (row_height, req.height);
}
- ++i;
}
- requisition.width = this.width_request;
- requisition.height = total_height + 2 * (int) this.border_width;
- } else {
- int rows_left = (int) Math.floor ((double) (this.height_request + _spacing)
- / (double) (row_height + _spacing));
- if (rows_left == 0) {
- rows_left = 1;
- }
- int width_left = total_width;
- int cur_width = 0;
- int max_width = 0;
- int min_width = width_left / rows_left;
-
- i = 0;
- int current_widget_counter = 0;
+ int i = 0;
foreach (var widget in _widgets) {
if (widget.visible) {
- Gtk.Requisition r = _requisitions[i];
-
- width_left -= r.width;
- cur_width += r.width;
- ++current_widget_counter;
-
- if (cur_width >= min_width) {
- // Start new line
- cur_width += (current_widget_counter - 1) * _spacing;
- max_width = int.max (max_width, cur_width);
- cur_width = 0;
- --rows_left;
- if (rows_left == 0) {
- break;
- }
- min_width = width_left / rows_left;
- current_widget_counter = 0;
- }
+ widget.height_request = row_height;
+ // FIXME workaround
+ Requisition req;
+ widget.size_request (req);
+ _requisitions[i] = req;
+ // FIXME workaround
+ total_width += _requisitions[i].width;
}
++i;
}
- requisition.width = max_width + 2 * (int) this.border_width;
+ if (this.width_request != -1 && this.height_request != -1) {
+ requisition.width = this.width_request;
+ requisition.height = this.height_request;
+ } else if (this.width_request != -1) {
+ int total_height = row_height;
+ int cur_width = 0;
+ int avail_width = this.width_request - 2 * (int) this.border_width;
+
+ i = 0;
+ foreach (var widget in _widgets) {
+ if (widget.visible) {
+ Gtk.Requisition r = _requisitions[i];
+
+ if (cur_width == 0 || cur_width + r.width <= avail_width) {
+ // Continue current line
+ cur_width += r.width;
+ if (cur_width != 0) {
+ cur_width += _spacing;
+ }
+ } else {
+ // Start new line
+ total_height += row_height + _spacing;
+ cur_width = 0;
+ }
+ }
+ ++i;
+ }
- if (this.height_request == -1) {
- requisition.height = row_height;
+ requisition.width = this.width_request;
+ requisition.height = total_height + 2 * (int) this.border_width;
} else {
- requisition.height = this.height_request;
+ int rows_left = (int) Math.floor ((double) (this.height_request + _spacing)
+ / (double) (row_height + _spacing));
+ if (rows_left == 0) {
+ rows_left = 1;
+ }
+ int width_left = total_width;
+ int cur_width = 0;
+ int max_width = 0;
+ int min_width = width_left / rows_left;
+
+ i = 0;
+ int current_widget_counter = 0;
+ foreach (var widget in _widgets) {
+ if (widget.visible) {
+ Gtk.Requisition r = _requisitions[i];
+
+ width_left -= r.width;
+ cur_width += r.width;
+ ++current_widget_counter;
+
+ if (cur_width >= min_width) {
+ // Start new line
+ cur_width += (current_widget_counter - 1) * _spacing;
+ max_width = int.max (max_width, cur_width);
+ cur_width = 0;
+ --rows_left;
+ if (rows_left == 0) {
+ break;
+ }
+ min_width = width_left / rows_left;
+ current_widget_counter = 0;
+ }
+ }
+ ++i;
+ }
+
+ requisition.width = max_width + 2 * (int) this.border_width;
+
+ if (this.height_request == -1) {
+ requisition.height = row_height;
+ } else {
+ requisition.height = this.height_request;
+ }
}
}
- }
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocated (allocation);
- this.allocation = (Allocation) allocation; // FIXME workaround
-
- int right = allocation.x + allocation.width - (int) this.border_width;
- int left = allocation.x + (int) this.border_width;
- int bottom = allocation.y + allocation.height - (int) this.border_width;
- int x = left;
- int row_y = allocation.y + (int) this.border_width;
- int max_height = 0;
-
- int i = 0;
- foreach (var widget in _widgets) {
- if (widget.visible) {
- Gdk.Rectangle r;
- r.width = _requisitions[i].width;
- r.height = _requisitions[i].height;
-
- if (x > left && x + r.width > right) {
- row_y += max_height + _spacing;
- max_height = 0;
- x = left;
- }
-
- r.x = x;
- r.y = row_y;
- r.width = int.min (right, r.x + r.width) - r.x;
- r.height = int.min (bottom, r.y + r.height) - r.y;
- widget.size_allocate (r);
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocated (allocation);
+ this.allocation = (Allocation) allocation; // FIXME workaround
+
+ int right = allocation.x + allocation.width - (int) this.border_width;
+ int left = allocation.x + (int) this.border_width;
+ int bottom = allocation.y + allocation.height - (int) this.border_width;
+ int x = left;
+ int row_y = allocation.y + (int) this.border_width;
+ int max_height = 0;
- x += r.width + _spacing;
- max_height = int.max (max_height, r.height);
+ int i = 0;
+ foreach (var widget in _widgets) {
+ if (widget.visible) {
+ Gdk.Rectangle r;
+ r.width = _requisitions[i].width;
+ r.height = _requisitions[i].height;
+
+ if (x > left && x + r.width > right) {
+ row_y += max_height + _spacing;
+ max_height = 0;
+ x = left;
+ }
+
+ r.x = x;
+ r.y = row_y;
+ r.width = int.min (right, r.x + r.width) - r.x;
+ r.height = int.min (bottom, r.y + r.height) - r.y;
+ widget.size_allocate (r);
+
+ x += r.width + _spacing;
+ max_height = int.max (max_height, r.height);
+ }
+ ++i;
}
- ++i;
}
}
}
Modified: trunk/geetk/ribbon/tool-pack.vala
==============================================================================
--- trunk/geetk/ribbon/tool-pack.vala (original)
+++ trunk/geetk/ribbon/tool-pack.vala Thu Jul 24 15:19:51 2008
@@ -2,161 +2,164 @@
using Cairo;
using Gtk;
-/** Set of ribbon buttons packed together. */
-public class ToolPack : Container {
+namespace Geetk {
- private Gee.List<BaseButton> _buttons;
- private int[] _widths;
+ /** Set of ribbon buttons packed together. */
+ public class ToolPack : Container {
- /** Construction method */
- construct {
- _buttons = new Gee.ArrayList<BaseButton> ();
-
- set_flags (get_flags () | WidgetFlags.NO_WINDOW);
-
- add_events (Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK);
- }
-
- /**
- * Adds a button before all existing buttons.
- *
- * @param widget The button to add.
- */
- public void PrependButton (BaseButton widget) {
- insert_button (widget, 0);
- }
+ private Gee.List<BaseButton> _buttons;
+ private int[] _widths;
- /**
- * Adds a button after all existing buttons.
- *
- * @param widget The button to add.
- */
- public void append_button (BaseButton widget) {
- insert_button (widget, -1);
- }
+ /** Construction method */
+ construct {
+ _buttons = new Gee.ArrayList<BaseButton> ();
+
+ set_flags (get_flags () | WidgetFlags.NO_WINDOW);
+
+ add_events (Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.BUTTON_RELEASE_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK);
+ }
+
+ /**
+ * Adds a button before all existing buttons.
+ *
+ * @param widget The button to add.
+ */
+ public void PrependButton (BaseButton widget) {
+ insert_button (widget, 0);
+ }
+
+ /**
+ * Adds a button after all existing buttons.
+ *
+ * @param widget The button to add.
+ */
+ public void append_button (BaseButton widget) {
+ insert_button (widget, -1);
+ }
+
+ /**
+ * Inserts a button at the specified location.
+ *
+ * @param widget The button to add.
+ * @param button_index The index (starting at 0) at which the button must
+ * be inserted, or -1 to insert the button after all
+ * existing buttons.
+ */
+ public void insert_button (BaseButton widget, int button_index) {
+ widget.set_parent (this);
+ widget.visible = true;
+
+ widget.draw_background = true;
+
+ if (button_index == -1 || button_index == _buttons.size) {
+ if (_buttons.size == 0) {
+ widget.group_style = GroupStyle.ALONE;
+ } else {
+ widget.group_style = GroupStyle.RIGHT;
- /**
- * Inserts a button at the specified location.
- *
- * @param widget The button to add.
- * @param button_index The index (starting at 0) at which the button must
- * be inserted, or -1 to insert the button after all
- * existing buttons.
- */
- public void insert_button (BaseButton widget, int button_index) {
- widget.set_parent (this);
- widget.visible = true;
-
- widget.draw_background = true;
-
- if (button_index == -1 || button_index == _buttons.size) {
- if (_buttons.size == 0) {
- widget.group_style = GroupStyle.ALONE;
+ if (_buttons.size == 1) {
+ _buttons.get (_buttons.size - 1).group_style = GroupStyle.LEFT;
+ } else if (_buttons.size > 1) {
+ _buttons.get (_buttons.size - 1).group_style = GroupStyle.CENTER;
+ }
+ }
+ _buttons.add (widget);
} else {
- widget.group_style = GroupStyle.RIGHT;
-
- if (_buttons.size == 1) {
+ if (button_index == 0) {
_buttons.get (_buttons.size - 1).group_style = GroupStyle.LEFT;
- } else if (_buttons.size > 1) {
- _buttons.get (_buttons.size - 1).group_style = GroupStyle.CENTER;
+ if (_buttons.size == 1) {
+ _buttons.get (0).group_style = GroupStyle.RIGHT;
+ } else {
+ _buttons.get (0).group_style = GroupStyle.CENTER;
+ }
}
+ _buttons.insert (button_index, widget);
}
- _buttons.add (widget);
- } else {
- if (button_index == 0) {
- _buttons.get (_buttons.size - 1).group_style = GroupStyle.LEFT;
- if (_buttons.size == 1) {
- _buttons.get (0).group_style = GroupStyle.RIGHT;
- } else {
- _buttons.get (0).group_style = GroupStyle.CENTER;
- }
- }
- _buttons.insert (button_index, widget);
+
+ show_all ();
}
- show_all ();
- }
+ /**
+ * Removes the button at the specified index.
+ *
+ * @param button_index Index of the button to remove.
+ */
+ public void remove_button (int button_index) {
+ _buttons.get (button_index).parent = null;
- /**
- * Removes the button at the specified index.
- *
- * @param button_index Index of the button to remove.
- */
- public void remove_button (int button_index) {
- _buttons.get (button_index).parent = null;
-
- if (button_index == 0) {
- if (_buttons.size > 1) {
- if (_buttons.size > 2) {
- _buttons.get (0).group_style = GroupStyle.LEFT;
- } else {
- _buttons.get (0).group_style = GroupStyle.ALONE;
+ if (button_index == 0) {
+ if (_buttons.size > 1) {
+ if (_buttons.size > 2) {
+ _buttons.get (0).group_style = GroupStyle.LEFT;
+ } else {
+ _buttons.get (0).group_style = GroupStyle.ALONE;
+ }
+ }
+ } else if (button_index == _buttons.size - 1) {
+ if (_buttons.size > 1) {
+ if (_buttons.size > 2) {
+ _buttons.get (0).group_style = GroupStyle.RIGHT;
+ } else {
+ _buttons.get (0).group_style = GroupStyle.ALONE;
+ }
}
}
- } else if (button_index == _buttons.size - 1) {
- if (_buttons.size > 1) {
- if (_buttons.size > 2) {
- _buttons.get (0).group_style = GroupStyle.RIGHT;
- } else {
- _buttons.get (0).group_style = GroupStyle.ALONE;
+ _buttons.remove_at (button_index);
+
+ show_all ();
+ }
+
+ protected override void forall (bool include_internals, Gtk.Callback callback) {
+ foreach (var button in _buttons) {
+ if (button.visible) {
+ callback (button);
}
}
}
- _buttons.remove_at (button_index);
+
+ protected override void size_request (Requisition requisition) {
+ // base.size_request (requisition);
- show_all ();
- }
+ if (_widths == null || _widths.length != _buttons.size) {
+ _widths = new int[_buttons.size];
+ }
- protected override void forall (bool include_internals, Gtk.Callback callback) {
- foreach (var button in _buttons) {
- if (button.visible) {
- callback (button);
+ requisition.height = requisition.width = 0;
+ int i = 0;
+ foreach (var button in _buttons) {
+ Gtk.Requisition req;
+ button.size_request (req);
+ if (requisition.height < req.height) {
+ requisition.height = req.height;
+ }
+ requisition.width += req.width;
+ _widths[i++] = req.width;
}
- }
- }
-
- protected override void size_request (Requisition requisition) {
-// base.size_request (requisition);
-
- if (_widths == null || _widths.length != _buttons.size) {
- _widths = new int[_buttons.size];
- }
-
- requisition.height = requisition.width = 0;
- int i = 0;
- foreach (var button in _buttons) {
- Gtk.Requisition req;
- button.size_request (req);
- if (requisition.height < req.height) {
- requisition.height = req.height;
+ if (this.height_request != -1) {
+ requisition.height = this.height_request;
+ }
+ if (this.width_request != -1) {
+ requisition.width = this.width_request;
}
- requisition.width += req.width;
- _widths[i++] = req.width;
- }
- if (this.height_request != -1) {
- requisition.height = this.height_request;
- }
- if (this.width_request != -1) {
- requisition.width = this.width_request;
}
- }
- protected override void size_allocate (Gdk.Rectangle allocation) {
-// base.size_allocate (allocation);
- this.allocation = (Allocation) allocation;
-
- int i = 0, x = allocation.x;
- foreach (var button in _buttons) {
- Gdk.Rectangle r;
- r.x = x;
- r.y = allocation.y;
- r.width = _widths[i];
- r.height = allocation.height;
- button.size_allocate (r);
- x += r.width;
- ++i;
+ protected override void size_allocate (Gdk.Rectangle allocation) {
+ // base.size_allocate (allocation);
+ this.allocation = (Allocation) allocation;
+
+ int i = 0, x = allocation.x;
+ foreach (var button in _buttons) {
+ Gdk.Rectangle r;
+ r.x = x;
+ r.y = allocation.y;
+ r.width = _widths[i];
+ r.height = allocation.height;
+ button.size_allocate (r);
+ x += r.width;
+ ++i;
+ }
}
}
}
Modified: trunk/geetk/samples/ribbondemo.vala
==============================================================================
--- trunk/geetk/samples/ribbondemo.vala (original)
+++ trunk/geetk/samples/ribbondemo.vala Thu Jul 24 15:19:51 2008
@@ -23,7 +23,7 @@
| Gdk.EventMask.BUTTON_RELEASE_MASK
| Gdk.EventMask.POINTER_MOTION_MASK);
- var button_0 = new Button.with_label ("Hello World");
+ var button_0 = new Geetk.Button.with_label ("Hello World");
var group_0 = new RibbonGroup ();
group_0.label = "Summer of Code";
group_0.add (button_0);
@@ -35,11 +35,11 @@
var foo_txt = new MenuItem.with_label ("foo.txt");
open_menu.append (foo_txt);
- var open = Button.from_stock_with_label (STOCK_OPEN, "Open", false);
+ var open = Geetk.Button.from_stock_with_label (STOCK_OPEN, "Open", false);
open.drop_down_menu = open_menu;
open.clicked += on_click;
- var button_1 = new Button.with_label ("Menu Test");
+ var button_1 = new Geetk.Button.with_label ("Menu Test");
button_1.clicked += on_click;
var button_1_menu = new Menu ();
var option_1 = new MenuItem.with_label ("Option 1");
@@ -47,17 +47,17 @@
button_1.drop_down_menu = button_1_menu;
var file_tool_pack = new ToolPack ();
- file_tool_pack.append_button (Button.from_stock_with_label (STOCK_NEW, "New", false));
+ file_tool_pack.append_button (Geetk.Button.from_stock_with_label (STOCK_NEW, "New", false));
file_tool_pack.append_button (open);
- file_tool_pack.append_button (Button.from_stock_with_label (STOCK_SAVE, "Save", false));
+ file_tool_pack.append_button (Geetk.Button.from_stock_with_label (STOCK_SAVE, "Save", false));
var printer_tool_pack = new ToolPack ();
- printer_tool_pack.append_button (Button.from_stock_with_label (STOCK_PRINT, "Print", false));
+ printer_tool_pack.append_button (Geetk.Button.from_stock_with_label (STOCK_PRINT, "Print", false));
var font_tool_pack = new ToolPack ();
- font_tool_pack.append_button (ToggleButton.from_stock (STOCK_BOLD, false));
- font_tool_pack.append_button (ToggleButton.from_stock (STOCK_ITALIC, false));
- font_tool_pack.append_button (ToggleButton.from_stock (STOCK_UNDERLINE, false));
+ font_tool_pack.append_button (Geetk.ToggleButton.from_stock (STOCK_BOLD, false));
+ font_tool_pack.append_button (Geetk.ToggleButton.from_stock (STOCK_ITALIC, false));
+ font_tool_pack.append_button (Geetk.ToggleButton.from_stock (STOCK_UNDERLINE, false));
var font_combo = Gtk.combo_box_from_entries (new string[] {"Arial", "Verdana"});
font_combo.active = 0;
@@ -110,7 +110,7 @@
var page_label_1 = new Label ("Page 2");
var page_label_2 = new Label ("Page 3");
- var shortcuts = new Button.with_label ("Menu");
+ var shortcuts = new Geetk.Button.with_label ("Menu");
shortcuts.child.modify_fg (StateType.NORMAL, Gdk.new_color (255, 255, 255));
_main_menu = new Menu ();
@@ -127,8 +127,8 @@
};
var qat = new QuickAccessToolbar ();
- qat.append (Button.from_stock (STOCK_NEW, false));
- qat.append (Button.from_stock (STOCK_SAVE, false));
+ qat.append (Geetk.Button.from_stock (STOCK_NEW, false));
+ qat.append (Geetk.Button.from_stock (STOCK_SAVE, false));
var ribbon = new Ribbon ();
ribbon.application_button = new ApplicationButton ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]