xref: /haiku/src/apps/cortex/ValControl/ValCtrlLayoutEntry.h (revision 8728f4797fcb3e99b6e1ec2629efbf4119c37497)
1 /*
2  * Copyright (c) 1999-2000, Eric Moon.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions, and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 // ValCtrlValCtrlLayoutEntry.h
33 // +++++ cortex integration 23aug99:
34 //       hide this class!
35 //
36 // e.moon 28jan99
37 #ifndef VAL_CTRL_LAYOUT_ENTRY_H
38 #define VAL_CTRL_LAYOUT_ENTRY_H
39 
40 
41 #include "cortex_defs.h"
42 
43 #include <View.h>
44 
45 
46 __BEGIN_CORTEX_NAMESPACE
47 
48 // a ValCtrlLayoutEntry manages the layout state information for
49 // a single child view
50 
51 class ValCtrlLayoutEntry {
52 	public:
53 		friend class ValControl;
54 
55 	public: // static instances
56 		static ValCtrlLayoutEntry decimalPoint;
57 
58 	public:
59 		enum entry_type {
60 			SEGMENT_ENTRY,
61 			VIEW_ENTRY,
62 			DECIMAL_POINT_ENTRY
63 		};
64 
65 		enum layout_flags {
66 			LAYOUT_NONE	= 0,
67 			LAYOUT_NO_PADDING = 1,	// disables left/right padding
68 		};
69 
70 	public:
71 		ValCtrlLayoutEntry() {}
72 			// stl compatibility ctor
73 
74 		// standard: yes, the frame is left invalid; that's for
75 		// ValControl::insertEntry() to fix
76 		ValCtrlLayoutEntry(BView* _pView, entry_type t,
77 			layout_flags f = LAYOUT_NONE)
78 			:
79 			pView(_pView),
80 			type(t),
81 			flags(f),
82 			fPadding(0.0)
83 			{}
84 
85 		ValCtrlLayoutEntry(entry_type t, layout_flags f = LAYOUT_NONE)
86 			:
87 			pView(0),
88 			type(t),
89 			flags(f),
90 			fPadding(0.0)
91 			{}
92 
93 		ValCtrlLayoutEntry(const ValCtrlLayoutEntry& clone) {
94 			operator=(clone);
95 		}
96 
97 		ValCtrlLayoutEntry& operator=(const ValCtrlLayoutEntry& clone) {
98 			type = clone.type;
99 			flags = clone.flags;
100 			pView = clone.pView;
101 
102 			frame = clone.frame;
103 			fPadding = clone.fPadding;
104 			return *this;
105 		}
106 
107 		// order first by x position, then by y:
108 		bool operator<(const ValCtrlLayoutEntry& b) const {
109 			return frame.left < b.frame.left ||
110 				frame.top < b.frame.top;
111 		}
112 
113 	protected:
114 		// move & size ref'd child view to match 'frame'
115 		static void InitChildFrame(ValCtrlLayoutEntry& e);
116 
117 	public:
118 		BView* pView;
119 
120 		entry_type type;
121 		layout_flags flags;
122 
123 		// layout state info (filled in by ValControl):
124 		BRect frame;
125 		float fPadding;
126 };
127 
128 __END_CORTEX_NAMESPACE
129 #endif	// VAL_CTRL_LAYOUT_ENTRY_H
130