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

/**
 * Implementation of a generic interface to allow the back end to trigger messages in the front end. 
 */

#include <mforms/base.h>

namespace mforms {
  // Constants for special folders on a system. Constants have been taken over from Windows definition
  // and are used directly in the Windows code, hence avoid changing them or fix the platform code if you do.
  enum MFORMS_EXPORT FolderType {
    //
    // Summary:
    //     The "My Documents" folder.
    MyDocuments = 5,
    Documents = 5,
    //
    // Summary:
    //     The directory used to physically store file objects on the desktop.
    DesktopDirectory = 16,
    Desktop = 16
    //
    // Summary:
    //     The directory that serves as a common repository for application-specific
    //     data that is used by the current, non-roaming user.
    //LocalApplicationData = 28,
  };

  struct MFORMS_EXPORT UtilitiesImplPtrs
  {
    int (__stdcall *show_message)(const std::string &title, const std::string &text,
                                  const std::string &ok, const std::string &cancel,
                                  const std::string &other);
    int (__stdcall *show_error)(const std::string &title, const std::string &text,
                                  const std::string &ok, const std::string &cancel,
                                  const std::string &other);
    int (__stdcall *show_warning)(const std::string &title, const std::string &text,
                                  const std::string &ok, const std::string &cancel,
                                  const std::string &other);
    
    void (__stdcall *set_clipboard_text)(const std::string &text);
    std::string (__stdcall *get_clipboard_text)();
    std::string (__stdcall *get_special_folder)(mforms::FolderType type);
    
    void (__stdcall *open_url)(const std::string &url);
  };

  enum DialogResult {
    ResultOk     =  1,
    ResultCancel =  0,
    ResultOther  = -1
  };
  
  class Box;
  class Button;

  class MFORMS_EXPORT Utilities
  {
  public:
    static int show_message(const std::string &title, const std::string &text,
                            const std::string &ok, const std::string &cancel="",
                            const std::string &other="");
    static int show_error(const std::string &title, const std::string &text,
                            const std::string &ok, const std::string &cancel="",
                            const std::string &other="");
    static int show_warning(const std::string &title, const std::string &text,
                            const std::string &ok, const std::string &cancel="",
                            const std::string &other="");
        
    static void set_clipboard_text(const std::string &text);
    static std::string get_clipboard_text();

    static std::string get_special_folder(FolderType type);

    static void open_url(const std::string &url);

    static void add_end_ok_cancel_buttons(mforms::Box *box, mforms::Button *ok, mforms::Button *cancel);
  };
};

#endif // _MFORMS_Utilities_H_
