2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/win_local.h"
34 // source file that includes just the standard includes
35 // Radiant.pch will be the pre-compiled header
36 // stdafx.obj will contain the pre-compiled type information
39 ===============================================================================
43 ===============================================================================
46 bool afxInitialized = false;
53 void InitAfx( void ) {
54 if ( !afxInitialized ) {
55 AfxWinInit( win32.hInstance, NULL, "", SW_SHOW );
57 afxInitialized = true;
63 ===============================================================================
67 ===============================================================================
75 int DefaultOnToolHitTest( const toolTip_t *toolTips, const CDialog *dialog, CPoint point, TOOLINFO* pTI ) {
77 RECT clientRect, rect;
79 dialog->GetWindowRect( &clientRect );
80 point.x += clientRect.left;
81 point.y += clientRect.top;
82 for ( int i = 0; toolTips[i].tip; i++ ) {
83 wnd = dialog->GetDlgItem( toolTips[i].id );
84 if ( !( wnd->GetStyle() & WS_VISIBLE ) ) {
87 wnd->GetWindowRect( &rect );
88 if ( point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom ) {
89 pTI->hwnd = dialog->GetSafeHwnd();
90 pTI->uFlags |= TTF_IDISHWND;
91 pTI->uFlags &= ~TTF_CENTERTIP;
92 pTI->uId = (UINT_PTR) wnd->GetSafeHwnd();
101 DefaultOnToolTipNotify
104 BOOL DefaultOnToolTipNotify( const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
105 // need to handle both ANSI and UNICODE versions of the message
106 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
107 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
111 UINT nID = pNMHDR->idFrom;
112 if ( pTTTA->uFlags & TTF_IDISHWND ) {
113 // idFrom is actually the HWND of the tool
114 nID = ::GetDlgCtrlID((HWND)nID);
118 for ( i = 0; toolTips[i].tip; i++ ) {
119 if ( toolTips[i].id == nID ) {
124 if ( !toolTips[i].tip ) {
128 if ( pNMHDR->code == TTN_NEEDTEXTA ) {
129 lstrcpyn( pTTTA->szText, toolTips[i].tip, sizeof(pTTTA->szText) );
131 _mbstowcsz( pTTTW->szText, toolTips[i].tip, sizeof(pTTTW->szText) );
138 ===============================================================================
140 Common control tools.
142 ===============================================================================
149 returns true if [Enter] was hit in the edit box
150 all 'return' characters in the text are removed and a single line is maintained
151 the edit control must be multi-line with auto-vscroll
154 bool EditControlEnterHit( CEdit *edit ) {
155 CString strIn, strOut;
156 if ( edit->GetLineCount() > 1 ) {
157 edit->GetWindowText( strIn );
158 for ( int i = 0; i < strIn.GetLength(); i++ ) {
159 if ( strIn[i] >= ' ' ) {
160 strOut.AppendChar( strIn[i] );
163 edit->SetWindowText( strOut );
164 edit->SetSel( 0, strOut.GetLength() );
175 float EditVerifyFloat( CEdit *edit, bool allowNegative ) {
177 CString strIn, strOut;
181 edit->GetSel( start, end );
182 edit->GetWindowText( strIn );
183 for ( int i = 0; i < strIn.GetLength(); i++ ) {
184 // first character may be a minus sign
185 if ( allowNegative && strOut.GetLength() == 0 && strIn[i] == '-' ) {
186 strOut.AppendChar( '-' );
188 // the string may contain one dot
189 else if ( !dot && strIn[i] == '.' ) {
190 strOut.AppendChar( strIn[i] );
193 else if ( strIn[i] >= '0' && strIn[i] <= '9' ) {
194 strOut.AppendChar( strIn[i] );
197 edit->SetWindowText( strOut );
198 edit->SetSel( start, end );
200 return atof(strOut.GetBuffer(0));
209 void SpinFloatString( CString &str, bool up ) {
210 int i, dotIndex = -1, digitIndex = -1;
212 for ( i = 0; str[i]; i++ ) {
213 if ( str[i] == '.' ) {
214 if ( dotIndex == -1 ) {
218 else if ( str[i] != '0' ) {
219 if ( digitIndex == -1 ) {
224 if ( digitIndex == -1 ) {
225 str.SetString( "1" );
229 if ( dotIndex != -1 ) {
230 str.Delete( dotIndex, 1 );
231 if ( digitIndex > dotIndex ) {
240 if ( str[digitIndex] == '9' ) {
241 str.SetAt( digitIndex, '0' );
242 if ( digitIndex == 0 ) {
243 str.Insert( 0, '1' );
247 str.SetAt( digitIndex-1, '1' );
251 str.SetAt( digitIndex, str[digitIndex] + 1 );
255 if ( str[digitIndex] == '1' ) {
256 if ( str[digitIndex+1] == '\0' ) {
257 str.SetAt( digitIndex, '0' );
258 str.AppendChar( '9' );
260 else if ( str[digitIndex+1] == '0' ) {
261 str.SetAt( digitIndex, '0' );
262 str.SetAt( digitIndex+1, '9' );
265 str.SetAt( digitIndex+1, str[digitIndex+1] - 1 );
269 str.SetAt( digitIndex, str[digitIndex] - 1 );
272 if ( dotIndex < str.GetLength() ) {
273 str.Insert( dotIndex, '.' );
274 // remove trailing zeros
275 for ( i = str.GetLength()-1; i >= 0; i-- ) {
276 if ( str[i] != '0' && str[i] != '.' ) {
280 if ( i < str.GetLength() - 1 ) {
281 str.Delete( i+1, str.GetLength() - i );
284 for ( i = 0; str[i]; i++ ) {
285 if ( str[i] == '.' ) {
287 str.Delete( 0, i-1 );
291 if ( str[i] != '0' ) {
305 float EditSpinFloat( CEdit *edit, bool up ) {
308 edit->GetWindowText( str );
309 SpinFloatString( str, up );
310 edit->SetWindowText( str );
316 SetSafeComboBoxSelection
319 int SetSafeComboBoxSelection( CComboBox *combo, const char *string, int skip ) {
322 index = combo->FindString( -1, string );
326 if ( combo->GetCount() != 0 ) {
327 if ( index == skip ) {
328 index = ( skip + 1 ) % combo->GetCount();
330 combo->SetCurSel( index );
341 int GetSafeComboBoxSelection( CComboBox *combo, CString &string, int skip ) {
344 index = combo->GetCurSel();
345 if ( index == CB_ERR ) {
348 if ( combo->GetCount() != 0 ) {
349 if ( index == skip ) {
350 index = ( skip + 1 ) % combo->GetCount();
352 combo->GetLBText( index, string );
363 UnsetSafeComboBoxSelection
366 int UnsetSafeComboBoxSelection( CComboBox *combo, CString &string ) {
369 skip = combo->FindString( -1, string );
370 index = combo->GetCurSel();
371 if ( index == CB_ERR ) {
374 if ( combo->GetCount() != 0 ) {
375 if ( index == skip ) {
376 index = ( skip + 1 ) % combo->GetCount();
378 combo->SetCurSel( index );