doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StdAfx.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../../sys/win32/win_local.h"
33 
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
37 
38 /*
39 ===============================================================================
40 
41  Afx initialization.
42 
43 ===============================================================================
44 */
45 
46 bool afxInitialized = false;
47 
48 /*
49 ================
50 InitAfx
51 ================
52 */
53 void InitAfx( void ) {
54  if ( !afxInitialized ) {
55  AfxWinInit( win32.hInstance, NULL, "", SW_SHOW );
56  AfxInitRichEdit();
57  afxInitialized = true;
58  }
59 }
60 
61 
62 /*
63 ===============================================================================
64 
65  Tool Tips.
66 
67 ===============================================================================
68 */
69 
70 /*
71 ================
72 DefaultOnToolHitTest
73 ================
74 */
75 int DefaultOnToolHitTest( const toolTip_t *toolTips, const CDialog *dialog, CPoint point, TOOLINFO* pTI ) {
76  CWnd *wnd;
77  RECT clientRect, rect;
78 
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 ) ) {
85  continue;
86  }
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();
93  return pTI->uId;
94  }
95  }
96  return -1;
97 }
98 
99 /*
100 ================
101 DefaultOnToolTipNotify
102 ================
103 */
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;
108 
109  *pResult = 0;
110 
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);
115  }
116 
117  int i;
118  for ( i = 0; toolTips[i].tip; i++ ) {
119  if ( toolTips[i].id == nID ) {
120  break;
121  }
122  }
123 
124  if ( !toolTips[i].tip ) {
125  return FALSE;
126  }
127 
128  if ( pNMHDR->code == TTN_NEEDTEXTA ) {
129  lstrcpyn( pTTTA->szText, toolTips[i].tip, sizeof(pTTTA->szText) );
130  } else {
131  _mbstowcsz( pTTTW->szText, toolTips[i].tip, sizeof(pTTTW->szText) );
132  }
133  return TRUE;
134 }
135 
136 
137 /*
138 ===============================================================================
139 
140  Common control tools.
141 
142 ===============================================================================
143 */
144 
145 /*
146 ================
147 EditControlEnterHit
148 
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
152 ================
153 */
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] );
161  }
162  }
163  edit->SetWindowText( strOut );
164  edit->SetSel( 0, strOut.GetLength() );
165  return true;
166  }
167  return false;
168 }
169 
170 /*
171 ================
172 EditVerifyFloat
173 ================
174 */
175 float EditVerifyFloat( CEdit *edit, bool allowNegative ) {
176 
177  CString strIn, strOut;
178  bool dot = false;
179  int start, end;
180 
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( '-' );
187  }
188  // the string may contain one dot
189  else if ( !dot && strIn[i] == '.' ) {
190  strOut.AppendChar( strIn[i] );
191  dot = true;
192  }
193  else if ( strIn[i] >= '0' && strIn[i] <= '9' ) {
194  strOut.AppendChar( strIn[i] );
195  }
196  }
197  edit->SetWindowText( strOut );
198  edit->SetSel( start, end );
199 
200  return atof(strOut.GetBuffer(0));
201 
202 }
203 
204 /*
205 ================
206 SpinFloatString
207 ================
208 */
209 void SpinFloatString( CString &str, bool up ) {
210  int i, dotIndex = -1, digitIndex = -1;
211 
212  for ( i = 0; str[i]; i++ ) {
213  if ( str[i] == '.' ) {
214  if ( dotIndex == -1 ) {
215  dotIndex = i;
216  }
217  }
218  else if ( str[i] != '0' ) {
219  if ( digitIndex == -1 ) {
220  digitIndex = i;
221  }
222  }
223  }
224  if ( digitIndex == -1 ) {
225  str.SetString( "1" );
226  return;
227  }
228 
229  if ( dotIndex != -1 ) {
230  str.Delete( dotIndex, 1 );
231  if ( digitIndex > dotIndex ) {
232  digitIndex--;
233  }
234  }
235  else {
236  dotIndex = i;
237  }
238 
239  if ( up ) {
240  if ( str[digitIndex] == '9' ) {
241  str.SetAt( digitIndex, '0' );
242  if ( digitIndex == 0 ) {
243  str.Insert( 0, '1' );
244  dotIndex++;
245  }
246  else {
247  str.SetAt( digitIndex-1, '1' );
248  }
249  }
250  else {
251  str.SetAt( digitIndex, str[digitIndex] + 1 );
252  }
253  }
254  else {
255  if ( str[digitIndex] == '1' ) {
256  if ( str[digitIndex+1] == '\0' ) {
257  str.SetAt( digitIndex, '0' );
258  str.AppendChar( '9' );
259  }
260  else if ( str[digitIndex+1] == '0' ) {
261  str.SetAt( digitIndex, '0' );
262  str.SetAt( digitIndex+1, '9' );
263  }
264  else {
265  str.SetAt( digitIndex+1, str[digitIndex+1] - 1 );
266  }
267  }
268  else {
269  str.SetAt( digitIndex, str[digitIndex] - 1 );
270  }
271  }
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] != '.' ) {
277  break;
278  }
279  }
280  if ( i < str.GetLength() - 1 ) {
281  str.Delete( i+1, str.GetLength() - i );
282  }
283  }
284  for ( i = 0; str[i]; i++ ) {
285  if ( str[i] == '.' ) {
286  if ( i > 1 ) {
287  str.Delete( 0, i-1 );
288  }
289  break;
290  }
291  if ( str[i] != '0' ) {
292  if ( i > 0 ) {
293  str.Delete( 0, i );
294  }
295  break;
296  }
297  }
298 }
299 
300 /*
301 ================
302 EditSpinFloat
303 ================
304 */
305 float EditSpinFloat( CEdit *edit, bool up ) {
306  CString str;
307 
308  edit->GetWindowText( str );
309  SpinFloatString( str, up );
310  edit->SetWindowText( str );
311  return atof( str );
312 }
313 
314 /*
315 ================
316 SetSafeComboBoxSelection
317 ================
318 */
319 int SetSafeComboBoxSelection( CComboBox *combo, const char *string, int skip ) {
320  int index;
321 
322  index = combo->FindString( -1, string );
323  if ( index == -1 ) {
324  index = 0;
325  }
326  if ( combo->GetCount() != 0 ) {
327  if ( index == skip ) {
328  index = ( skip + 1 ) % combo->GetCount();
329  }
330  combo->SetCurSel( index );
331  }
332 
333  return index;
334 }
335 
336 /*
337 ================
338 GetComboBoxSelection
339 ================
340 */
341 int GetSafeComboBoxSelection( CComboBox *combo, CString &string, int skip ) {
342  int index;
343 
344  index = combo->GetCurSel();
345  if ( index == CB_ERR ) {
346  index = 0;
347  }
348  if ( combo->GetCount() != 0 ) {
349  if ( index == skip ) {
350  index = ( skip + 1 ) % combo->GetCount();
351  }
352  combo->GetLBText( index, string );
353  }
354  else {
355  string = "";
356  }
357 
358  return index;
359 }
360 
361 /*
362 ================
363 UnsetSafeComboBoxSelection
364 ================
365 */
366 int UnsetSafeComboBoxSelection( CComboBox *combo, CString &string ) {
367  int skip, index;
368 
369  skip = combo->FindString( -1, string );
370  index = combo->GetCurSel();
371  if ( index == CB_ERR ) {
372  index = 0;
373  }
374  if ( combo->GetCount() != 0 ) {
375  if ( index == skip ) {
376  index = ( skip + 1 ) % combo->GetCount();
377  }
378  combo->SetCurSel( index );
379  }
380 
381  return index;
382 }
BOOL DefaultOnToolTipNotify(const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult)
Definition: StdAfx.cpp:104
int SetSafeComboBoxSelection(CComboBox *combo, const char *string, int skip)
Definition: StdAfx.cpp:319
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
void InitAfx(void)
Definition: StdAfx.cpp:53
GLuint index
Definition: glext.h:3476
void SpinFloatString(CString &str, bool up)
Definition: StdAfx.cpp:209
GLuint GLuint end
Definition: glext.h:2845
#define NULL
Definition: Lib.h:88
int DefaultOnToolHitTest(const toolTip_t *toolTips, const CDialog *dialog, CPoint point, TOOLINFO *pTI)
Definition: StdAfx.cpp:75
char * tip
Definition: StdAfx.h:50
int UnsetSafeComboBoxSelection(CComboBox *combo, CString &string)
Definition: StdAfx.cpp:366
bool EditControlEnterHit(CEdit *edit)
Definition: StdAfx.cpp:154
int GetSafeComboBoxSelection(CComboBox *combo, CString &string, int skip)
Definition: StdAfx.cpp:341
float EditSpinFloat(CEdit *edit, bool up)
Definition: StdAfx.cpp:305
#define FALSE
Definition: mprintf.c:70
#define TRUE
Definition: mprintf.c:69
bool afxInitialized
Definition: StdAfx.cpp:46
float dot(float a[], float b[])
Definition: Model_lwo.cpp:3883
HINSTANCE hInstance
Definition: win_local.h:102
Win32Vars_t win32
Definition: win_main.cpp:65
GLuint start
Definition: glext.h:2845
float EditVerifyFloat(CEdit *edit, bool allowNegative)
Definition: StdAfx.cpp:175