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 185 186 187 188 189 190 191 192 193 194
|
/*
* Copyright (c) 2008, 2015, 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
*/
#pragma once
#include <mforms/base.h>
#include <mforms/view.h>
#ifdef __APPLE__
#define TOP_FORM_PADDING 20
#else
#define TOP_FORM_PADDING 12
#endif
namespace mforms {
enum FormFlag
{
FormNone = 0,
FormSingleFrame = 1 << 0,
FormDialogFrame = 1 << 1,
FormResizable = 1 << 2,
FormMinimizable = 1 << 3,
FormHideOnClose = 1 << 4,
FormStayOnTop = 1 << 5,
FormToolWindow = 1 << 6, // Not combinable with any of the frame styles above. Also min and max
// are not available.
FormNormal = (FormResizable|FormMinimizable)
};
class Form;
class Button;
class MenuBar;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef SWIG
struct MFORMS_EXPORT FormImplPtrs
{
bool (*create)(Form *self, Form *owner, FormFlag flag);
void (*set_title)(Form *self, const std::string &title);
void (*set_menubar)(Form *self, MenuBar *menu);
void (*show_modal)(Form *self, Button *accept, Button *cancel);
bool (*run_modal)(Form *self, Button *accept, Button *cancel);
void (*end_modal)(Form *self, bool result);
void (*set_content)(Form *self, View *view);
void (*close)(Form *self);
void (*center)(Form *self);
void (*flush_events)(Form *self);
};
#endif
#endif
/** A standalone, top-level window.
*/
class MFORMS_EXPORT Form : public View
{
FormImplPtrs *_form_impl;
View *_content;
MenuBar *_menu;
bool _fixed_size;
bool _release_on_close;
bool _active;
boost::function<bool()> _can_close_slot;
boost::signals2::signal<void ()> _closed_signal;
boost::signals2::signal<void ()> _activated_signal;
boost::signals2::signal<void ()> _deactivated_signal;
protected:
Form();
public:
/** Constructor.
@param owner - the owner of this window. Pass 0/None for no owner.
@param flag - flags specifying some features of the window:
FormNone
FormSingleFrame
FormDialogFrame
FormResizable
FormMinimizable
FormHideOnClose
FormStayOnTop
*/
Form(Form *owner, FormFlag flag= (FormFlag)(FormResizable | FormMinimizable));
virtual ~Form();
/** Used to specify the main form to the Form() constructor. The returned object cannot be used for anything else */
static Form* main_form();
static Form* active_form();
/** Sets the content view of the window.
Usually a layouting container, such as a Box or a Table.
*/
virtual void set_content(View *view);
View *get_content() { return _content; }
/** Sets the title of the window.
*/
virtual void set_title(const std::string &title);
/** Sets the menubar for the window
In Linux and Windows, this will add to the toplevel box of the window,
which is expected to have the correct layout.
In MacOS, it will make the menu the active menu, whenever the window becomes key.
*/
virtual void set_menubar(mforms::MenuBar *menu);
mforms::MenuBar *get_menubar() { return _menu; }
/** Deprecated */
virtual void show_modal(Button *accept, Button *cancel);
/** Shows the window as a modal window.
@param accept - a button to be used as the default accept button (ie when user presses Return key) or None
@param cancel - button to be used as cancel button (ie when user presses Escape key) or None
*/
virtual bool run_modal(Button *accept, Button *cancel);
/** Ends a modal session started with run_modal()
This function is automatically called if accept and cancel buttons are given to run_modal.
@param result - the result to be returned by run_modal
*/
virtual void end_modal(bool result);
/** Closes the window. */
virtual void close();
/** Centers the window in the screen. */
virtual void center();
virtual void flush_events();
/** Sets whether the window must be automatically released when closed. */
void set_release_on_close(bool flag);
#ifndef SWIG
/** Function called when window is about to close.
return false to prevent window closing.
In Python use on_close()
*/
void set_on_close(const boost::function<bool ()> &slot) { _can_close_slot = slot; }
/** Signal sent when the user clicks the close button in the window.
In Python use add_closed_callback()
*/
boost::signals2::signal<void ()>* signal_closed() { return &_closed_signal; }
/** Signal sent when the window becomes the active window.
*/
boost::signals2::signal<void ()>* signal_activated() { return &_activated_signal; }
boost::signals2::signal<void ()>* signal_deactivated() { return &_deactivated_signal; }
void activated();
void deactivated();
#endif
bool is_active();
bool can_close();
void was_closed()
{
_closed_signal();
if (_release_on_close)
release();
}
};
};
|