1 //------------------------------------------------------------------------------
2 // emWindowStateSaver.h
3 //
4 // Copyright (C) 2016 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20 
21 #ifndef emWindowStateSaver_h
22 #define emWindowStateSaver_h
23 
24 #ifndef emWindow_h
25 #include <emCore/emWindow.h>
26 #endif
27 
28 
29 //==============================================================================
30 //============================= emWindowStateSaver =============================
31 //==============================================================================
32 
33 class emWindowStateSaver : public emEngine {
34 
35 public:
36 
37 	// Class for making the geometry of a window (class) persistent. This
38 	// saves the position, size and maximization state in a file. For using
39 	// this class, simply create an instance of it as a member of your
40 	// window. The state is restored up-on construction (if file valid), and
41 	// it is saved on each geometry change or focusing of the window.
42 	// Actually the saving happens immediately to a shared internal model
43 	// and with delay to the file.
44 
45 	emWindowStateSaver(
46 		emWindow & window, const emString & filePath,
47 		bool allowRestoreFullscreen=false
48 	);
49 		// Constructor.
50 		// Arguments:
51 		//   window                 - The window whose state is to be
52 		//                            restored and saved by this window
53 		//                            state saver.
54 		//   filePath               - Path and name for the file. This
55 		//                            should be unique for the window
56 		//                            class. The file has an emRec
57 		//                            format.
58 		//   allowRestoreFullscreen - Whether to allow restoring
59 		//                            fullscreen mode.
60 
61 	virtual ~emWindowStateSaver();
62 		// Destructor.
63 
64 protected:
65 
66 	virtual bool Cycle();
67 
68 private:
69 
70 	void Save();
71 	void Restore();
72 
73 	class ModelClass : public emConfigModel, public emStructRec {
74 	public:
75 
76 		static emRef<ModelClass> Acquire(
77 			emRootContext & rootContext,
78 			const emString & filePath
79 		);
80 
81 		emDoubleRec ViewX;
82 		emDoubleRec ViewY;
83 		emDoubleRec ViewWidth;
84 		emDoubleRec ViewHeight;
85 		emBoolRec Maximized;
86 		emBoolRec Fullscreen;
87 
88 		virtual const char * GetFormatName() const;
89 
90 	protected:
91 
92 		ModelClass(emContext & context, const emString & filePath);
93 		virtual ~ModelClass();
94 	};
95 
96 	emWindow & Window;
97 	bool AllowRestoreFullscreen;
98 	emRef<ModelClass> Model;
99 	double OwnNormalX,OwnNormalY,OwnNormalW,OwnNormalH;
100 };
101 
102 
103 #endif
104