1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _WF_Utilities_H_
#define _WF_Utilities_H_
#include "mforms/utilities.h"
#include "wf_mforms.h"
using namespace std;
using namespace mforms;
namespace MySQL {
namespace Forms {
// Message type for the C# interface.
public enum class MessageType
{
MessageInfo,
MessageWarning,
MessageError
};
/**
* A custom message box for the output as there is no predefined dialog which allows to
* have custom button captions.
*/
public ref class CustomMessageBox : Windows::Forms::Form
{
private:
// Constructor is private. CustomMessageBox should be accessed through the public Show() 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;
Windows::Forms::CheckBox^ _checkbox;
void ComputeLayout();
void ButtonClick(System::Object^ sender, EventArgs^ e);
static mforms::DialogResult ShowVistaStyle(const std::string& title, const std::string& text,
PCWSTR mainIcon, const std::string& buttonOK, const std::string& buttonCancel,
const std::string& buttonOther, const std::string& checkbox, bool& checked);
static mforms::DialogResult ShowTraditionalStyle(String^ title, String^ text, System::Drawing::Image^ image,
String^ button1, String^ button2, String^ button3, String^ checkbox, bool& checked);
public:
// C++ interface
static mforms::DialogResult Show(const std::string& title, const std::string& text,
PCWSTR mainIcon, const std::string& buttonOK, const std::string& buttonCancel,
const std::string& buttonOther, const std::string& checkbox, bool& checked);
// C# interface
static Windows::Forms::DialogResult Show(MessageType type, String^ title, String^ text, String^ buttonOK,
String^ buttonCancel, String^ buttonOther, String^ checkbox, [Out] bool% checked);
static Windows::Forms::DialogResult Show(MessageType type, String^ title, String^ text, String^ buttonOK);
};
private ref class InvokationResult
{
private:
void* _result;
public:
InvokationResult(void* result)
{
_result = result;
}
property void* Result
{
void* get()
{
return _result;
}
};
};
private ref class DispatchControl : Control
{
private:
const boost::function<void* ()>* _slot;
InvokationResult^ RunSlot();
public:
void* RunOnMainThread(const boost::function<void* ()>& slot, bool wait);
};
public ref class UtilitiesImpl
{
private:
static DispatchControl^ _dispatcher;
static void load_passwords();
static void unload_passwords(bool store);
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 int show_message_with_checkbox(const string &title, const string &text, const string &ok,
const string &cancel, const string &other, const std::string &checkbox_text, bool &isChecked);
static void show_wait_message(const string &title, const string &text);
static bool hide_wait_message();
static bool run_cancelable_wait_message(const string &title, const string &text,
const boost::function<void ()> &start_task, const boost::function<bool ()> &cancel_slot);
static void stop_cancelable_wait_message();
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);
static bool move_to_trash(const string &file_name);
static void add_timeout(float interval, const boost::function<bool ()> &slot);
static void store_password(const std::string &service, const std::string &account, const std::string &password);
static bool find_password(const std::string &service, const std::string &account, std::string &password);
static void forget_password(const std::string &service, const std::string &account);
static void* perform_from_main_thread(const boost::function<void* ()> &slot, bool wait);
public:
static Windows::Forms::Form^ get_mainform();
static void init(Manager ^mgr)
{
_dispatcher = gcnew DispatchControl();
_dispatcher->Handle; // create window handle
::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_CALLBACK7(int, const string&, const string&, const string&, const string&, const string&,
const string&, bool&, mgr, f->_utilities_impl, UtilitiesImpl, show_message_with_checkbox);
DEF_CALLBACK2(void, const string&, const string&, mgr, f->_utilities_impl, UtilitiesImpl,
show_wait_message);
DEF_CALLBACK0(bool, mgr, f->_utilities_impl, UtilitiesImpl, hide_wait_message);
DEF_CALLBACK4(bool, const std::string&, const std::string&, const boost::function<void ()> &, const boost::function<bool ()>&, mgr, f->_utilities_impl, UtilitiesImpl, run_cancelable_wait_message);
DEF_CALLBACK0(void, mgr, f->_utilities_impl, UtilitiesImpl, stop_cancelable_wait_message);
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(bool, const string&, mgr, f->_utilities_impl, UtilitiesImpl, move_to_trash);
DEF_CALLBACK2(void, float, const boost::function<bool ()>&, mgr, f->_utilities_impl, UtilitiesImpl, add_timeout);
DEF_CALLBACK1(string, mforms::FolderType, mgr, f->_utilities_impl, UtilitiesImpl, get_special_folder);
DEF_CALLBACK3(void, const string&, const string&, const string&, mgr, f->_utilities_impl, UtilitiesImpl, store_password);
DEF_CALLBACK3(bool, const string&, const string&, string&, mgr, f->_utilities_impl, UtilitiesImpl, find_password);
DEF_CALLBACK2(void, const string&, const string&, mgr, f->_utilities_impl, UtilitiesImpl, forget_password);
DEF_CALLBACK2(void*, const boost::function<void* ()>&, bool, mgr, f->_utilities_impl, UtilitiesImpl, perform_from_main_thread);
}
};
};
};
#endif // _WF_Utilities_H_
|