~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/forms/winforms/wf_utilities.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

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