Modified: desktop/trunk/lib/tooltips.class.php (66 => 67)
--- desktop/trunk/lib/tooltips.class.php 2006-12-10 22:02:36 UTC (rev 66)
+++ desktop/trunk/lib/tooltips.class.php 2006-12-11 16:26:40 UTC (rev 67)
@@ -27,27 +27,33 @@
{
/**
- * singleton instance for this class
- * @var $singleton instanceof Tooltips
+ * singleton instances for this class (so you can have multiple tooltip sets)
+ * @var $singletons array of instanceof Tooltips
*/
- static protected $singleton;
+ static protected $singletons = array();
/**
+ * fake tooltip window
+ * @var $tooltip instanceof GtkWindow
+ */
+ protected $tooltip;
+
+ /**
* public function __construct
*
* sets delay and enables tooltips
*
* @return void
*/
- public function __construct()
+ public function __construct($name)
{
- if (!is_null(self::$singleton))
+ if (isset(self::$singletons[$name]))
{
throw new CC_Exception(
'%1$s is a singleton class - use %1$s::instance() to retrieve the current object',
'CC_Tooltips');
}
- self::$singleton = $this;
+ self::$singletons[$name] = $this;
parent::__construct();
$this->enable();
@@ -62,12 +68,21 @@
* @param object $wiget instanceof GtkObject
* @return void
*/
- public function set_tip($widget, $tooltip)
+ public function set_tip($widget, $tooltip, $path = null)
{
if ($widget instanceof GtkToolItem)
{
$widget->set_tooltip($this, $tooltip);
}
+ elseif($widget instanceof GtkTreeView || $widget instanceof GtkIconView)
+ {
+ if (is_null($this->tooltip))
+ {
+ $this->tooltip_window();
+ }
+ $widget->connect('motion-notify-event', array($this, 'on_motion_event'), $tooltip, $path);
+ $widget->connect_simple('leave-notify-event', array($this, 'on_leave_event'));
+ }
else
{
parent::set_tip($widget, $tooltip);
@@ -75,20 +90,116 @@
return;
}
+ //----------------------------------------------------------------
+ // Faking Tooltips for non GtkWidgets
+ //----------------------------------------------------------------
+
/**
+ * protected function tooltip_window
+ *
+ * creates a fake tooltip window
+ *
+ * @return void
+ */
+ protected function tooltip_window()
+ {
+ $this->tooltip = new GtkWindow(Gtk::WINDOW_POPUP);
+ $this->tooltip->set_name('gtk-tooltips');
+ $this->tooltip->set_resizable(false);
+ $this->tooltip->set_border_width(4);
+ $this->tooltip->set_app_paintable(true);
+ $this->tooltip->connect('expose-event', array($this, 'on_expose_event'));
+
+ $this->tooltip->label = $label = new GtkLabel('');
+ $label->set_line_wrap(true);
+ $label->set_alignment(0.5, 0.5);
+ $label->set_use_markup(true);
+ $this->tooltip->add($label);
+ return;
+ }
+
+ /**
+ * public function on_expose_event
+ *
+ * makes the window look like a tooltip
+ *
+ * @return void
+ */
+ public function on_expose_event($window, $event)
+ {
+ if(!$this->get_property('enabled'))
+ {
+ return;
+ }
+ $size = $window->size_request();
+ $window->style->paint_flat_box($window->window, Gtk::STATE_NORMAL,
+ Gtk::SHADOW_OUT, null, $window, 'tooltip', 0, 0, $size->width,
+ $size->height);
+ return;
+ }
+
+ /**
+ * public function on_leave_event
+ *
+ * hides the tooltip window
+ *
+ * @return void
+ */
+ public function on_leave_event()
+ {
+ if(!$this->get_property('enabled'))
+ {
+ return;
+ }
+ $this->tooltip->hide();
+ return;
+ }
+
+ /**
+ * public function on_motion_event
+ *
+ * actually does the work - checks for location of mouse
+ * and pops up tooltip appropriately
+ *
+ * @return void
+ */
+ public function on_motion_event($view, $event, $tooltip, $path)
+ {
+ if(!$this->get_property('enabled'))
+ {
+ return;
+ }
+ $current = $view->get_path_at_pos($event->x, $event->y);
+ if (is_null($path))
+ {
+ return;
+ }
+ if($current == $path)
+ {
+ $this->tooltip->label->set_markup($tooltip);
+ $size = $this->tooltip->size_request();
+ $this->tooltip->move($event->x_root - $size->width/2, $event->y_root + 12);
+ $this->tooltip->show_all();
+ }
+
+ return;
+ }
+
+
+ /**
* static public function instance
*
* this is how items can access the tooltips
*
* @return object instanceof CC_Tooltips
*/
- static public function instance()
+ static public function instance($name = 'default')
{
- if (is_null(self::$singleton))
+ if (!isset(self::$singletons[$name]))
{
- self::$singleton = new CC_Tooltips();
+ new CC_Tooltips($name);
}
- return self::$singleton;
+ return self::$singletons[$name];
}
/**