1 /*
2 * MFBoolItem.cpp
3 *
4 * Copyright (C) 1999 Stephen F. White
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file "COPYING" for details); if
18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 * Cambridge, MA 02139, USA.
20 */
21
22 #include "MFBoolItem.h"
23 #include "MFBool.h"
24 #include "SFBoolItem.h"
25 #include "SFBool.h"
26 #include "FieldView.h"
27 #include "swt.h"
28
MFBoolItem(FieldView * view)29 MFBoolItem::MFBoolItem(FieldView *view) : MFieldViewItem(view)
30 {
31 }
32
33 FieldValue *
OnMouseMove(FieldValue * value,int index,int delta)34 MFBoolItem::OnMouseMove(FieldValue *value, int index, int delta)
35 {
36 bool val;
37
38 if (delta > 0)
39 val = true;
40 else
41 val = false;
42 return new MFBool(val);
43 }
44
45 FieldViewItem *
CreateSFItem()46 MFBoolItem::CreateSFItem()
47 {
48 return new SFBoolItem(m_view);
49 }
50
51 //
52 // when an item is collapsed, draw the 1st element
53 //
54
55 void
Draw(SDC dc,int x,int y)56 MFBoolItem::Draw(SDC dc, int x, int y)
57 {
58 if (IsCollapsed()) {
59 if (((MFBool *) m_value)->getSize() == 1) {
60 m_children[0]->Draw(dc, x, y);
61 }
62 }
63 }
64
65 //
66 // allow the 1st element to be edited, when the item is collapsed
67 //
68
69 bool
IsEditable() const70 MFBoolItem::IsEditable() const
71 {
72 return !IsCollapsed() || (((MFBool *)m_value)->getSize() < 2);
73 }
74
75 bool
IsTrackable() const76 MFBoolItem::IsTrackable() const
77 {
78 return !IsCollapsed() || (((MFBool *)m_value)->getSize() == 1);
79 }
80
81
82 void
StartEditing(MyString & str,int offset)83 MFBoolItem::StartEditing(MyString &str, int offset)
84 {
85 MFBool *v = (MFBool *) m_value;
86 char buf[128];
87
88 if (!IsCollapsed() || (v->getSize() == 0)) {
89 InsertSFValue(0);
90 m_children.insert(new FieldViewItem(m_view), 0);
91 } else
92 str = "";
93 InitIndexValue(0, m_value);
94 if (v->getValue(0))
95 strcpy(buf, "TRUE");
96 else
97 strcpy(buf, "FALSE");
98 str = buf;
99 }
100
101 FieldValue *
StopEditing(const char * str,int offset)102 MFBoolItem::StopEditing(const char *str, int offset)
103 {
104 int i = 0;
105 ((MFBool *)m_value)->setSFValue(offset, i);
106 InitIndexValue(offset, m_value);
107 return m_value;
108 }
109
110 void
InsertSFValue(int index)111 MFBoolItem::InsertSFValue(int index)
112 {
113 ((MFBool *)m_value)->insertSFValue(index, false);
114 }
115
116 void
RemoveSFValue(int index)117 MFBoolItem::RemoveSFValue(int index)
118 {
119 ((MFBool *)m_value)->removeSFValue(index);
120 }
121
122 FieldValue *
OnMouseDown(int x,int y,int modifiers)123 MFBoolItem::OnMouseDown(int x, int y, int modifiers)
124 {
125 int width = m_view->GetItemWidth();
126 int buttonSize = m_view->GetItemHeight() - 1;
127
128 if (x >= width - buttonSize && x < width) {
129 if (m_field->getStrings()) {
130 // create popup
131 }
132 }
133 return NULL;
134 }
135
136