/* 
 * © 2008-2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _MFORMS_VIEW_H_
#define _MFORMS_VIEW_H_

#include <mforms/base.h>
#include <sigc++/sigc++.h>

namespace mforms {

  class View;

  struct ViewImplPtrs
  {
    int (__stdcall *get_width)(View *self);
    int (__stdcall *get_height)(View *self);
    int (__stdcall *get_preferred_width)(View *self);
    int (__stdcall *get_preferred_height)(View *self);
    void (__stdcall *set_size)(View *self, int, int);

    int (__stdcall *get_x)(View *self);
    int (__stdcall *get_y)(View *self);
    void (__stdcall *set_position)(View *self, int, int);

    void (__stdcall *show)(View *self, bool);
    bool (__stdcall *is_shown)(View *self);
    
    void (__stdcall *set_tooltip)(View *self, const std::string&);
    void (__stdcall *set_name)(View *self, const std::string&);
    
    void (__stdcall *set_enabled)(View *self, bool);
    void (__stdcall *relayout)(View *self);

    void (__stdcall *set_layout_dirty)(View *self);
  };

  // Describes in which direction a control might be resized by the layouters.
  enum AutoResizeMode {
    ResizeNone,
    ResizeVertical,
    ResizeHorizontal,
    ResizeBoth
  };

  class MFORMS_EXPORT View : public Object
  {
    friend class ControlFactory;

    ViewImplPtrs *_view_impl;
  private:
    std::string _name;
    AutoResizeMode _resize_mode;
  protected:
    View();

    View *_parent;
    std::list<View*> _subviews; // Filled only by controls which need that (e.g. table). Add general handling here instead?

    sigc::signal<void> _signal_resized;

  public:
    virtual ~View() { 
#if 0
      printf("destroy view %p\n", this); 
#endif
    };
    
    AutoResizeMode get_resize_mode();
    void set_resize_mode(AutoResizeMode mode);

    sigc::signal<void> signal_resized() { return _signal_resized; }
    
    void set_name(const std::string &name);
    void set_tooltip(const std::string &text);
    std::string get_name();
    void set_parent(View *parent);
    View *get_parent() const;
    virtual int get_width();
    virtual int get_height();
    virtual int get_preferred_width();
    virtual int get_preferred_height();
    virtual int get_x();
    virtual int get_y();
    virtual void set_position(int x, int y);
    virtual void set_size(int width, int height);
    void show(bool flag= true);
    bool is_shown();
    void set_enabled(bool flag);
    virtual void needs_resize();
    virtual void relayout();
    virtual void set_layout_dirty();
    virtual void on_resize();
  };
};

#endif
