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

#include <mforms/mforms.h>
#include "mforms/utilities.h"

#include "wf_mforms.h"

using namespace std;
using namespace mforms;
using namespace Windows::Forms;

namespace MySQL {
  namespace Forms {

    /**
     * A custom message box for the output as there is no predefined dialog which allos to
     * have custom button captions.
     */
    public ref class CustomMessageBox : Windows::Forms::Form
    {
    private:
      // Constructor is private. CustomMessageBox should be accessed through the public ShowBox() method
      CustomMessageBox();

      // GUI Elements, we have 3 buttons whose text can be customized.
      Windows::Forms::Label^ _messageLabel;
      Windows::Forms::Button^ _button1;
      Windows::Forms::Button^ _button2;
      Windows::Forms::Button^ _button3;
      Windows::Forms::PictureBox^ _picture;

      static mforms::DialogResult lastResult;

      void ComputeLayout();
      void ButtonClick(System::Object^ sender, EventArgs^ e);
    public:
      static mforms::DialogResult Show(String^ title, String^ text, Drawing::Image^ image, String^ button1, String^ button2, String^ button3);
    };

    public ref class UtilitiesImpl
    {
    protected:
      UtilitiesImpl();

      static int show_message(const string &title, const string &text, const string &ok, 
        const string &cancel, const string &other);
      static int show_error(const string &title, const string &text, const string &ok, 
        const string &cancel, const string &other);
      static int show_warning(const string &title, const string &text, const string &ok, 
        const string &cancel, const string &other);

      static void set_clipboard_text(const string &content);
      static string get_clipboard_text();
      static string get_special_folder(FolderType type);

      static void open_url(const string &url);
    public:
      static void init(Manager ^mgr)
      {
        ::mforms::ControlFactory *f= ::mforms::ControlFactory::get_instance();

        DEF_CALLBACK5(int, const string&, const string&, const string&, const string&, const string&, 
          mgr, f->_utilities_impl, UtilitiesImpl, show_message);
        DEF_CALLBACK5(int, const string&, const string&, const string&, const string&, const string&, 
          mgr, f->_utilities_impl, UtilitiesImpl, show_error);
        DEF_CALLBACK5(int, const string&, const string&, const string&, const string&, const string&, 
          mgr, f->_utilities_impl, UtilitiesImpl, show_warning);
        DEF_CALLBACK1(void, const string&, mgr, f->_utilities_impl, UtilitiesImpl, set_clipboard_text);
        DEF_CALLBACK0(string, mgr, f->_utilities_impl, UtilitiesImpl, get_clipboard_text);
        DEF_CALLBACK1(void, const string&, mgr, f->_utilities_impl, UtilitiesImpl, open_url);
        DEF_CALLBACK1(string, mforms::FolderType, mgr, f->_utilities_impl, UtilitiesImpl, get_special_folder);
      }
    };

  };
};

#endif // _WF_Utilities_H_
