1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // editable_range.cpp : implementation file
21 #include "object_viewer.h"
22 #include "editable_range.h"
26 #include "range_manager.h"
27 #include "range_selector.h"
30 /////////////////////////////////////////////////////////////////////////////
31 // CEditableRange dialog
34 CEditableRange::CEditableRange(const std::string
&id
, CParticleWorkspace::CNode
*node
)
35 : _Id(id
), _Node(node
)
37 //{{AFX_DATA_INIT(CEditableRange)
49 void CEditableRange::update()
52 updateValueFromReader();
55 BOOL
CEditableRange::EnableWindow( BOOL bEnable
)
57 m_ValueCtrl
.EnableWindow(bEnable
);
58 m_SliderCtrl
.EnableWindow(bEnable
);
59 m_UpdateValue
.EnableWindow(bEnable
);
60 m_SelectRange
.EnableWindow(bEnable
);
64 return CEditAttribDlg::EnableWindow(bEnable
);
67 void CEditableRange::init(uint32 x
, uint32 y
, CWnd
*pParent
)
69 Create(IDD_EDITABLE_RANGE
, pParent
);
72 MoveWindow(x
, y
, r
.right
, r
.bottom
);
73 // set the slider size
74 CSliderCtrl
*sl
= (CSliderCtrl
*) GetDlgItem(IDC_SLIDER
);
79 void CEditableRange::DoDataExchange(CDataExchange
* pDX
)
81 CDialog::DoDataExchange(pDX
);
82 //{{AFX_DATA_MAP(CEditableRange)
83 DDX_Control(pDX
, IDC_SLIDER
, m_SliderCtrl
);
84 DDX_Control(pDX
, IDC_VALUE
, m_ValueCtrl
);
85 DDX_Control(pDX
, IDC_UPDATE_VALUE
, m_UpdateValue
);
86 DDX_Control(pDX
, IDC_SELECT_RANGE
, m_SelectRange
);
87 DDX_Text(pDX
, IDC_MIN_RANGE
, m_MinRange
);
88 DDX_Text(pDX
, IDC_MAX_RANGE
, m_MaxRange
);
89 DDX_Text(pDX
, IDC_VALUE
, m_Value
);
90 DDX_Slider(pDX
, IDC_SLIDER
, m_SliderPos
);
97 BEGIN_MESSAGE_MAP(CEditableRange
, CDialog
)
98 //{{AFX_MSG_MAP(CEditableRange)
99 ON_NOTIFY(NM_RELEASEDCAPTURE
, IDC_SLIDER
, OnReleasedcaptureSlider
)
100 ON_BN_CLICKED(IDC_SELECT_RANGE
, OnSelectRange
)
101 ON_EN_SETFOCUS(IDC_VALUE
, OnSetfocusValue
)
102 ON_BN_CLICKED(IDC_UPDATE_VALUE
, OnUpdateValue
)
103 ON_EN_KILLFOCUS(IDC_VALUE
, OnKillfocusValue
)
104 ON_EN_CHANGE(IDC_VALUE
, OnChangeValue
)
109 /////////////////////////////////////////////////////////////////////////////
110 // CEditableRange message handlers
117 BOOL
CEditableRange::OnInitDialog()
119 CDialog::OnInitDialog();
122 updateValueFromReader();
124 return TRUE
; // return TRUE unless you set the focus to a control
125 // EXCEPTION: OCX Property Pages should return FALSE
129 void CEditableRange::OnReleasedcaptureSlider(NMHDR
* pNMHDR
, LRESULT
* pResult
)
132 CSliderCtrl
*sl
= (CSliderCtrl
*) GetDlgItem(IDC_SLIDER
);
134 (sl
->GetRangeMax() - sl
->GetRangeMin()) != 0
137 updateValueFromSlider(m_SliderPos
* 1.f
/ (sl
->GetRangeMax() - sl
->GetRangeMin()));
141 updateValueFromSlider(0);
146 void CEditableRange::OnSelectRange()
153 void CEditableRange::OnUpdateValue()
156 updateValueFromText();
160 void CEditableRange::emptyDialog(void)
167 void CEditableRange::OnSetfocusValue()
169 CEdit
*ce
= (CEdit
*) GetDlgItem(IDC_VALUE
);
170 ce
->PostMessage(EM_SETSEL
, 0, -1);
175 void CEditableRange::OnKillfocusValue()
177 // When kill Focus from the edit text, update the value.
179 updateValueFromText(); */
183 static void concatEdit2Lines(CEdit
&edit
)
185 const uint lineLen
= 1000;
187 // retrieve the 2 lines.
188 TCHAR tmp0
[2*lineLen
];
190 n
= edit
.GetLine(0, tmp0
, lineLen
); tmp0
[n
]= 0;
191 n
= edit
.GetLine(1, tmp1
, lineLen
); tmp1
[n
]= 0;
192 // concat and update the CEdit.
193 edit
.SetWindowText(_tcscat(tmp0
, tmp1
));
197 void CEditableRange::OnChangeValue()
200 // Trick to track "Enter" keypress: CEdit are multiline. If GetLineCount()>1, then
201 // user has press enter.
202 if(m_ValueCtrl
.GetLineCount()>1)
204 // must ccat 2 lines of the CEdit.
205 concatEdit2Lines(m_ValueCtrl
);
206 m_ValueCtrl
.GetWindowText(m_Value
);
207 updateValueFromText();
211 void CEditableRange::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
213 if (nSBCode
== SB_THUMBPOSITION
|| nSBCode
== SB_THUMBTRACK
|| nSBCode
== SB_LINERIGHT
|| nSBCode
== SB_LINELEFT
)
216 if (nSBCode
== SB_THUMBPOSITION
|| nSBCode
== SB_THUMBTRACK
)
222 CSliderCtrl
*sl
= (CSliderCtrl
*) GetDlgItem(IDC_SLIDER
);
224 (sl
->GetRangeMax() - sl
->GetRangeMin()) != 0
227 updateValueFromSlider(m_SliderPos
* 1.f
/ (sl
->GetRangeMax() - sl
->GetRangeMin()));
231 updateValueFromSlider(0);
234 CDialog::OnHScroll(nSBCode
, nPos
, pScrollBar
);