Hi Alex,

What I've done (and it's working well so far) is to create a
qx.ui.tabview.Button that inherits from the qx.ui.form.RadioButton.  On
this button, I've overridden the _onMouseDown and _onMouseUp methods so
that it will handle normal clicks, as well as drag events properly.
I've also re-introduced the showCloseButton and closeButtonImage
properties (pulled from 0.7 code) for this class.  I've then updated the
qx.ui.tabview.Page._createChildControlImpl() method to use the new
qx.ui.tabview.Button instead of the form.RadioButton.

Everything is working well so far, and I've copied the code below if
you'd like to have a look.  I can create this as a patch if you'd be
interested in applying it to the trunk as a permanent change.  If not,
I'm happy to keep it in my patch library for our own use.

Sincerely,
Mr. Hericus
m...@hericus.com
http://www.hericus.com/

On Thu, 2009-01-08 at 15:07 +0100, Alexander Back wrote:
> Hi,
> 
> Mr. Hericus wrote:
> > Hi All,
> > 
> > I'm on the verge of diving into the Button code to directly add support
> > for dragging, but I wanted to check first to see if I'm way off track
> > and there's an easier solution.
> I guess, there is no simple solution, because you will run into other 
> problems especially with the event system. Is there another alternative 
> to drag and drop?
> 
> cheers,
>    Alex
> 
> 
> 
> ------------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It is the best place to buy or sell services for
> just about anything Open Source.
> http://p.sf.net/sfu/Xq1LFB
> _______________________________________________
> qooxdoo-devel mailing list
> qooxdoo-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel



/*
************************************************************************

   qooxdoo - the new era of web development

   http://qooxdoo.org

   Copyright:
     2004-2008 1&1 Internet AG, Germany, http://www.1und1.de

   License:
     LGPL: http://www.gnu.org/licenses/lgpl.html
     EPL: http://www.eclipse.org/org/documents/epl-v10.php
     See the LICENSE file in the project's top-level directory for
details.

   Authors:
     * Sebastian Werner (wpbasti)
     * Andreas Ecker (ecker)

************************************************************************
*/

/**
 * Extension of the qx.ui.form.RadioButton that removes the mouse
capturing
 * to allow TabView buttons to work with drag & drop, and re-introduces
the 
 * ability to display a close-button on the tab.
 *
 */
qx.Class.define("qx.ui.tabview.Button",
{
  extend : qx.ui.form.RadioButton,

  /*

*****************************************************************************
     CONSTRUCTOR

*****************************************************************************
  */

  /**
   * @param label {String?null} An optional label for the radio button.
   */
  construct : function(label)
  {
    if (qx.core.Variant.isSet("qx.debug", "on")) {
      this.assertArgumentsCount(arguments, 0, 1);
    }

    this.base(arguments, label);

  },

  /*

*****************************************************************************
     EVENTS

*****************************************************************************
  */

  events :
  {
          "closetab" : "qx.event.type.Event"
  },

  /*

*****************************************************************************
      PROPERTIES

*****************************************************************************
   */

   properties :
   {
          
          /** Default close tab button */
          showCloseButton :
          {
                check : "Boolean",
                init : false,
                apply : "_applyShowCloseButton",
                event : "changeShowCloseButton"
          },
          
          /** Close Tab Icon */
          closeButtonImage :
          {
                  check : "String",
                  init : "icon/16/actions/dialog-close.png",
                  apply : "_applyCloseButtonImage"
          }
   },

  /*

*****************************************************************************
     MEMBERS

*****************************************************************************
  */
  members :
  {
            /*

---------------------------------------------------------------------------
              EVENT LISTENERS

---------------------------------------------------------------------------
            */

           /** Fires the "closetab" event.
            * 
            */
           _ontabclose : function(e) {
                        this.fireDataEvent("closetab", this);
                        e.stopPropagation();
                },
           
           
           /**
             * Listener method for "mousedown" event
             * <ul>
             * <li>Removes "abandoned" state</li>
             * <li>Adds "pressed" state</li>
             * </ul>
             *
             * @param e {Event} Mouse event
             * @return {void}
             */
            _onMouseDown : function(e)
            {
              if (!e.isLeftPressed()) {
                return;
              }

              this.removeState("abandoned");
              this.addState("pressed");
            },


            /**
             * Listener method for "mouseup" event
             * <ul>
             * <li>Removes "pressed" state (if set)</li>
             * <li>Removes "abandoned" state (if set)</li>
             * <li>Adds "hovered" state (if "abandoned" state is not set)</li>
             *</ul>
             *
             * @param e {Event} Mouse event
             * @return {void}
             */
            _onMouseUp : function(e)
            {
              // We must remove the states before executing the command
              // because in cases were the window lost the focus while
              // executing we get the capture phase back (mouseout).
              var hasPressed = this.hasState("pressed");
              var hasAbandoned = this.hasState("abandoned");

              if (hasPressed) {
                this.removeState("pressed");
              }

              if (hasAbandoned)
              {
                this.removeState("abandoned");
              }
              else
              {
                this.addState("hovered");

                if (hasPressed) {
                  this.execute();
                }
              }
            },

            /*

---------------------------------------------------------------------------
              APPLY ROUTINES

---------------------------------------------------------------------------
            */
            /** Adds or removes the close button image.
             * 
             */
            _applyShowCloseButton : function (value, old)
            {
                // if no image exists, then create one
                if(!this._closeButtonImage){
                        this._closeButtonImage = new
qx.ui.basic.Image(this.getCloseButtonImage());
                }
                
                if( value ){
                        this._closeButtonImage.addListener("click", 
this._ontabclose,
this);
                        this._add(this._closeButtonImage);
                } else {
                        this._remove(this._closeButtonImage);
                        this._closeButtonImage.removeListener("click", 
this._ontabclose,
this);
                }
            },
            
            /** Sets the image for the close button on tabs.
             * 
             */
            _applyCloseButtonImage : function(value, old){
                if(this._closeButtonImage){
                        this._closeButtonImage.setSource(value);
                }
            }
  },
  
  /*

*****************************************************************************
      DESTRUCTOR

*****************************************************************************
   */

   destruct : function() {
          this._disposeObjects("_closeButtonImage");
   }
  
});






------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to