/**
 * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
 *
 * Published under the BSD license.
 * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
 * of the license.
 */

/** api: (define)
 *  module = GeoExt.ux
 *  class = Mouse Position bar item
 *  base_link = `Ext.Toolbar.TextItem <http://extjs.com/deploy/dev/docs/?class=Ext.Toolbar.TextItem>`_
 */

Ext.namespace("GeoExt.ux.Toolbar");

GeoExt.ux.Toolbar.MousePositionItem = Ext.extend(Ext.Toolbar.TextItem, {

    /** api: config[map]
     *  ``OpenLayers.Map`` or :class:`GeoExt.MapPanel`
     */
    map: null,

    /** api: config[mousePositionControl]
     *  ``OpenLayers.Control.MousePosition`` Optional mouse position control
     */
    mousePositionControl: null,

    /** private: method[constructor]
     *  Construct the component.
     */
    constructor: function(config) {
        if (config.map && config.map instanceof GeoExt.MapPanel) {
            config.map = config.map.map;
        }
        if (config.map) {
           this.map = config.map
        } else {
            this.map = GeoExt.MapPanel.guess().map;
        }
        this.controlOptions = config.controlOptions || {};
        GeoExt.ux.Toolbar.MousePositionItem.superclass.constructor.call(this, this.text || "");
    },

    /** private: method[render]
     *  Render the component.
     *  :param td: ``Element/HTMLElement/String`` Container
     */
    render: function(td) {
        var config = OpenLayers.Util.extend(this.controlOptions, {
            div:this.el
        });
        if (this.map) {
            if (!this.mousePositionControl) {
                this.mousePositionControl = new OpenLayers.Control.MousePosition(config);
            }
            this.map.addControl(this.mousePositionControl);
        }
        GeoExt.ux.Toolbar.MousePositionItem.superclass.render.call(this, td);
    }
});

/** api: xtype = gxux_mouseposition */

Ext.reg('gxux_mouseposition', GeoExt.ux.Toolbar.MousePositionItem);



