xref: /haiku/src/libs/alm/SharedSolver.h (revision 35bf0b5c1c5f89dac389efde9bcf19e880fa04e4)
1 /*
2  * Copyright 2012, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _SHARED_SOLVER_H
6 #define _SHARED_SOLVER_H
7 
8 
9 #include <LayoutContext.h>
10 #include <ObjectList.h>
11 #include <Referenceable.h>
12 
13 #include "LinearSpec.h"
14 
15 
16 class BMessage;
17 
18 namespace BALM {
19 	class BALMLayout;
20 };
21 
22 
23 using BALM::BALMLayout;
24 
25 
26 
27 namespace BPrivate {
28 
29 
30 class SharedSolver : BLayoutContextListener, public BReferenceable {
31 public:
32 								SharedSolver();
33 								~SharedSolver();
34 
35 			void				Invalidate(bool children);
36 
37 			LinearSpec*			Solver() const;
38 			ResultType			Result();
39 
40 			void				RegisterLayout(BALMLayout* layout);
41 			void				LayoutLeaving(const BALMLayout* layout);
42 
43 			ResultType			ValidateMinSize();
44 			ResultType			ValidateMaxSize();
45 			ResultType			ValidatePreferredSize();
46 			ResultType			ValidateLayout(BLayoutContext* context);
47 
48 			status_t			AddFriendReferences(const BALMLayout* layout,
49 									BMessage* archive, const char* field);
50 private:
51 			struct MinSizeValidator;
52 			struct MaxSizeValidator;
53 			struct PreferredSizeValidator;
54 
55 			friend struct MinSizeValidator;
56 			friend struct MaxSizeValidator;
57 			friend struct PreferredSizeValidator;
58 
59 			void				SetMaxSize(BALM::BALMLayout* layout,
60 									const BSize& max);
61 			void				SetMinSize(BALM::BALMLayout* layout,
62 									const BSize& min);
63 			void				SetPreferredSize(BALM::BALMLayout* layout,
64 									const BSize& preferred);
65 
66 	virtual	void				LayoutContextLeft(BLayoutContext* context);
67 
68 			void				_UpdateConstraints();
69 			void				_SetContext(BLayoutContext* context);
70 			bool				_IsMinSet();
71 			bool				_IsMaxSet();
72 			void				_ValidateConstraints();
73 
74 			template <class Validator>
75 			void				_Validate(bool& isValid, ResultType& result);
76 
77 
78 			bool				fConstraintsValid;
79 			bool				fMinValid;
80 			bool				fMaxValid;
81 			bool				fPreferredValid;
82 			bool				fLayoutValid;
83 
84 			BLayoutContext*		fLayoutContext;
85 			BObjectList<BALM::BALMLayout> fLayouts;
86 			LinearSpec			fLinearSpec;
87 
88 			ResultType			fMinResult;
89 			ResultType			fMaxResult;
90 			ResultType			fPreferredResult;
91 			ResultType			fLayoutResult;
92 };
93 
94 
95 };
96 
97 
98 using BPrivate::SharedSolver;
99 
100 
101 #endif
102