Modified: desktop/trunk/lib/tooltips.class.php (68 => 69)
--- desktop/trunk/lib/tooltips.class.php 2006-12-11 21:01:15 UTC (rev 68)
+++ desktop/trunk/lib/tooltips.class.php 2006-12-12 17:28:02 UTC (rev 69)
@@ -33,6 +33,12 @@
static protected $singleton;
/**
+ * make sure constructor can ONLY be called by instance
+ * @var $check bool
+ */
+ static protected $check;
+
+ /**
* fake tooltip window
* @var $tooltip instanceof GtkWindow
*/
@@ -47,13 +53,11 @@
*/
public function __construct()
{
- if (isset(self::$singleton))
+ // pretend this is a protected method - throw the same error php does
+ if (self::$check == false)
{
- throw new CC_Exception(
- '%1$s is a singleton class - use %1$s::instance() to retrieve the current object',
- 'CC_Tooltips');
+ trigger_error('Call to protected ' . __METHOD__ . ' from invalid context', E_USER_ERROR);
}
- self::$singleton = $this;
parent::__construct();
$this->enable();
@@ -85,6 +89,28 @@
}
else
{
+ // flags for menu items must be set incorrectly, because you can set tooltips on them
+ if(!($widget instanceof GtkMenuItem) && $widget->flags() & Gtk::NO_WINDOW)
+ {
+ $parent = $widget->get_parent();
+ $box = new GtkEventBox();
+ if($parent instanceof GtkBox)
+ {
+ $pos = array_search($widget, $parent->get_children(), TRUE);
+ $pack = $parent->query_child_packing($widget);
+ $parent->pack_end($box);
+ $parent->set_child_packing($box, $pack[0], $pack[1], $pack[2], $pack[3]);
+ $parent->reorder_child($box, $pos);
+ $widget->reparent($box);
+ }
+ else
+ {
+ $widget->reparent($box);
+ $parent->add($box);
+ }
+ parent::set_tip($box, $tooltip);
+ return;
+ }
parent::set_tip($widget, $tooltip);
}
return;
@@ -127,7 +153,7 @@
*/
public function on_expose_event($window, $event)
{
- if(!$this->get_property('enabled'))
+ if(!$this->enabled)
{
return;
}
@@ -147,7 +173,7 @@
*/
public function on_leave_event()
{
- if(!$this->get_property('enabled'))
+ if(!$this->enabled)
{
return;
}
@@ -165,16 +191,16 @@
*/
public function on_motion_event($view, $event, $tooltip, $path)
{
- if(!$this->get_property('enabled'))
+ if(!$this->enabled)
{
return;
}
$current = $view->get_path_at_pos($event->x, $event->y);
- if (is_null($path))
+ if (is_null($path) || is_null($current[0]))
{
return;
}
- if($current == $path)
+ if($current[0] == $path)
{
$this->tooltip->label->set_markup($tooltip);
$size = $this->tooltip->size_request();
@@ -197,22 +223,20 @@
{
if (!isset(self::$singleton))
{
- new CC_Tooltips();
+ self::$check = true;
+ self::$singleton = new CC_Tooltips();
+ self::$check = false;
}
return self::$singleton;
}
/**
- * public function __clone()
+ * protected function __clone()
*
* disable cloning of a singleton
*
* @return void
*/
- public function __clone()
- {
- throw new CC_Exception('Cannot clone singleton object %s', 'CC_Tooltips');
- return;
- }
+ protected function __clone() {}
}
?>
\ No newline at end of file