Hi Dominik,

changing the Window widget's "active" property fires a "changeActive" 
event. This is not to be confused with the "activate" and "deactivate" 
events fired by qx.ui.core.Widget.

The playground example works if you change the code as follows:

win = new qx.ui.window.Window("First Window");
win.setWidth(300);
win.setHeight(200);
win.setShowMinimize(false);
win.addListener("changeActive", function(e) {
   if (e.getTarget().setCaption != null) {
     if (e.getData()) {
       e.getTarget().setCaption("activated");
     } else {
       e.getTarget().setCaption("deactivated");
     }
   }
}, this);

this.getRoot().add(win, {left:20, top:20});
win.open();

As for your taskbar widget, I think you could save yourself a bunch of 
work by using data binding to synchronize the window's "active" property 
with the taskbar button's "value". Have you looked into that?


Regards,
Daniel

Dominik Horb schrieb:
> Hi,
> below is some playground code, which gave me a little headache, while 
> tracking it down.
> It seems, that a window movement deactivates the window and doesn't 
> reactivate it again and also minimization seems to not  send a 
> deactivation event, which I assumed it would.. Is there something I'm 
> missing about the intent of the active state of windows?
> 
> My problem is that, I'm trying to implement a taskbar and I don't find a 
> way that activates a button that is attached to a window if the window 
> gets activated, i.e. if you click minimize on the currently active 
> window on a desktop the next window gets focused, but I want also the 
> attached taskbar button to get activated and this doesn't happen right 
> now. On the bottom you can see the current state of my taskbar widget.
> 
> I tested many different combinations of event listeners, which I can't 
> really remember anymore,  would be very nice, if someone could take a 
> look at my code and help me a bit..
> 
> Best regards
> 
> Dominik
> 
> // PLAYGROUND EXAMPLE
> var win = new qx.ui.window.Window("First Window");
> win.setWidth(300);
> win.setHeight(200);
> win.setShowMinimize(false);
> win.addListener("deactivate", function(e){e.getTarget().set("caption", 
> "deactivated");}, this);
> win.addListener("activate", function(e){e.getTarget().set("caption", 
> "activated");}, this);
> 
> this.getRoot().add(win, {left:20, top:20});
> win.open();
> //END
> 
> //TASKBAR CLASS
> 
> /**
>  * This class provides some well known operating system like taskbar
>  * behaviours. To every added window a toggle button is attached, that
>  * can switch the window between maximized and minimized state.
>  *
>  * *Example*
>  *
>  * Here is a little example of how to use the widget.
>  *
>  * <pre class='javascript'>
>  * var win = new qx.ui.window.Window("A window");
>  * var taskbar = new addressbook.widgets.Taskbar();
>  * taskbar.attachWindow();
>  * </pre>
>  *
>  *
>  */
> qx.Class.define("addressbook.widgets.Taskbar",
> {
>   extend : qx.ui.core.Widget,
> 
>   /*
>   
> *****************************************************************************
>      CONSTRUCTOR
>   
> *****************************************************************************
>   */
> 
>   construct : function()
>   {
>     this.base(arguments);
>    
>     //the menu to which all the windows are added
>     var taskbar = new qx.ui.toolbar.ToolBar();
>     this.setHeight(26);
>     taskbar.setSpacing(0);
>    
>     //TODO stop the bar from stretching if too many windows are added
>     this._setLayout(new qx.ui.layout.VBox());
>     this._add(taskbar);
>     this.__taskbar = taskbar;
>   },
>  
>   /*
>   
> *****************************************************************************
>      PROPERTIES
>   
> *****************************************************************************
>   */
> 
>   properties :
>   {
>     /** Appearance of the widget */
>     appearance :
>     {
>       refine : true,
>       init : "taskbar"
>     }
>   },
>  
>   /*
>   
> *****************************************************************************
>      MEMBERS
>   
> *****************************************************************************
>   */
>   members : {
>     __taskbar : null,
>    
>     /**
>      * Every window that is added gets an associated taskbar button 
> which can toggle
>      * it between minimized and maximized.
>      */
>     attachWindow : function(window) {
>       var button = this.__newTaskbarItem(window);
>       this.__createWindowListeners(window);
>       this.__taskbar.add(button);
>      
>       if(window.get("active")){
>         button.set("value", true);
>       }
>     },
>    
>     /*
>     
> ---------------------------------------------------------------------------
>       LISTENERS
>     
> ---------------------------------------------------------------------------
>     */
>    
>     /**
>      * Adds the Listeners to the given window.
>      */
>     __createWindowListeners : function(window){
>       window.addListener("close", this.__close, this);
>      
>       window.addListener("activate", this.__activateButton, this);
>      
>       //window.addListener("deactivate", this.__deactivateButton, this);
>       window.addListener("blur", this.__deactivateButton, this);
>       window.addListener("minimize", this.__deactivateButton, this);
>     },
>    
>     /**
>      * Listens to added windows and removes their taskbar button if they 
> are closed.
>      */
>     __close : function(e) {
>       var button = e.getTarget().getUserData("taskbarButton");
>       if(button !==null){
>         button.destroy();
>       }
>     },
>    
>     /**
>      * Listens to the activation of the added windows and activates 
> their associated button.
>      */
>     __activateButton : function(e){
>       this.debug("activateButton");
>       this.__setButtonValue(e.getTarget().getUserData("taskbarButton"), 
> true);
>     },
>    
>     /**
>      * Listens to the deactivation of the added windows and deactivates 
> their associated button.
>      */
>     __deactivateButton : function(e){
>       this.debug("deactivateButton");
>       this.__setButtonValue(e.getTarget().getUserData("taskbarButton"), 
> false);
>     },
>    
>     /**
>      * Switches the window between shown and hidden
>      */
>     __toggleMinMax : function(e){
>       e.preventDefault();
>       var window = e.getTarget().getUserData("window");
>       this.debug("value: " + e.getTarget().get("value"));
>       this.debug(window);
>       if(e.getTarget().get("value") || window.get("active")){
>         window.minimize();
>         e.getTarget().set("value", false);
>       } else {
>         window.open();
>         e.getTarget().set("value", true);
>         this.debug("value set: " + e.getTarget().get("value"));
>       }
>     },
>    
>     /**
>      * Helper for the toggle buttons.
>      */
>     __setButtonValue : function (button, value) {
>       if(button !=null){
>         button.setValue(value);
>       } else {
>         this.debug("Button ist null");
>       }
>     },
>        
>     /**
>      * Creates a taskbar button that represents the given window.
>      */
>     __newTaskbarItem : function(window){
> 
>       var button = new 
> addressbook.widgets.CheckButton(window.get("caption"), window.get("icon"));
>       button.setAppearance("button");
>       //attach the window to this button, so it can be shown again if 
> the button is clicked
>       button.setUserData("window", window);
>       //attach the button to the window, so it can be removed, if the 
> window is closed
>       window.setUserData("taskbarButton", button);
>      
>       //if the button is clicked switch the state of the window and the 
> button
>       button.addListener("mousedown", this.__toggleMinMax, this);
>       return button;
>     }
>   }
>  
> });
> 
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
> 
> 

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to