1 // Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org> 2 // 3 // Permission to use, copy, modify, and distribute this software for any 4 // purpose with or without fee is hereby granted, provided that the above 5 // copyright notice and this permission notice appear in all copies. 6 // 7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 // 15 // Aegisub Project http://www.aegisub.org/ 16 17 /// @file persist_location.h 18 /// @see persist_location.cpp 19 /// @ingroup utility 20 21 namespace agi { class OptionValue; } 22 class wxDialog; 23 class wxMoveEvent; 24 class wxSizeEvent; 25 26 #include <string> 27 28 /// @class PersistLocation 29 /// @brief Automatically save and restore the location of a dialog 30 /// 31 /// This class saves the location of the supplied dialog to the preferences 32 /// file with the given prefix, then restores the saved position when it is 33 /// recreated in the future. This class should always have lifetime equal to 34 /// the associated dialog, as it does not unbind its events. 35 class PersistLocation { 36 agi::OptionValue *x_opt; 37 agi::OptionValue *y_opt; 38 agi::OptionValue *w_opt; 39 agi::OptionValue *h_opt; 40 agi::OptionValue *maximize_opt; 41 wxDialog *dialog; 42 43 void OnMove(wxMoveEvent&); 44 void OnSize(wxSizeEvent&); 45 46 public: 47 /// Persist the location of a dialog 48 /// @param dialog The dialog to save and restore the position of 49 /// @param options_prefix Prefix for the options names to store the location 50 /// @param size_too Save and restore the size in addition to position 51 PersistLocation(wxDialog *dialog, std::string options_prefix, bool size_too = false); 52 }; 53