/* 
 * © 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 _WF_SCROLLPANEL_H_
#define _WF_SCROLLPANEL_H_

#include "mforms/scrollpanel.h"

#include "wf_panel.h"

/**
 * Specialized mform panel with scrollbars.
 */
using namespace System::Windows::Forms;
using namespace Layout;

namespace MySQL {
  namespace Forms {

    private ref class ScrollFillLayout : public LayoutEngine
    {
    public:
      virtual bool Layout(Object^ container, LayoutEventArgs^ arguments) override;
    };

    /**
     * A panel with a fill layout that can be scrolled.
     */
    public ref class ScrollFillPanel : public Panel
    {
    private:
      ScrollFillLayout^ layoutEngine;
      Drawing::Size preferredSize;
    public:
      ScrollFillPanel()
      {
        preferredSize= Drawing::Size(0, 0);
      }

      virtual Drawing::Size GetPreferredSize(Drawing::Size proposedSize) override;

      virtual property Windows::Forms::Layout::LayoutEngine^ LayoutEngine
      {
        Windows::Forms::Layout::LayoutEngine^ get() override
        {
          if (layoutEngine == nullptr)
            layoutEngine = gcnew ScrollFillLayout();

          return layoutEngine;
        }
      }

      void SetPreferredSize(const Drawing::Size% size) { preferredSize= size; };
    };

    public ref class ScrollPanelImpl : public ViewImpl
    {
    private:
      ScrollableControl^ _container; // The actual control that takes the content.

    protected:
      static bool create(::mforms::ScrollPanel *self, bool bordered);
      static void add(::mforms::ScrollPanel *self, ::mforms::View *view);
      static void remove(::mforms::ScrollPanel *self);
    public:
      ScrollPanelImpl(::mforms::ScrollPanel *self);

      void add(::mforms::View *view);
      void remove();

      static void init(Manager ^mgr)
      {
        ::mforms::ControlFactory *f= ::mforms::ControlFactory::get_instance();

        DEF_CALLBACK2(bool, ::mforms::ScrollPanel*, bool, mgr, f->_spanel_impl, ScrollPanelImpl, create);
        DEF_CALLBACK2(void, ::mforms::ScrollPanel*, ::mforms::View*, mgr, f->_spanel_impl, ScrollPanelImpl, add);
        DEF_CALLBACK1(void, ::mforms::ScrollPanel*, mgr, f->_spanel_impl, ScrollPanelImpl, remove);
      }
    };

  };
};

#endif // _WF_SCROLLPANEL_H_
