-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConsoleTab.cpp
228 lines (191 loc) · 5.86 KB
/
ConsoleTab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/****************************************************************************************/
/* ConsoleTab.cpp */
/* */
/* Author: Jim Mischel, Ken Baird, Jeff Lomax */
/* Description: Cheezy text console */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/*Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/****************************************************************************************/
#include "stdafx.h"
#include "ConsoleTab.h"
#include "FusionTabControls.h" // this is probably bad
#include "FusionDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static HWND ConHwnd;
/////////////////////////////////////////////////////////////////////////////
// CConsoleTab dialog
CConsoleTab::CConsoleTab(CFusionTabControls* pParent /*=NULL*/, CFusionDoc* pDoc)
: CDialog(CConsoleTab::IDD, pParent),
Font(NULL), bNewFont (FALSE)
{
//{{AFX_DATA_INIT(CConsoleTab)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pFusionDoc = pDoc;
m_pParentCtrl = pParent;
CDialog::Create( IDD, (CWnd*) pParent );
}
void CConsoleTab::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConsoleTab)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
void CConsoleTab::SetConHwnd(void)
{
GetDlgItem(IDC_CONEDIT, &ConHwnd);
}
BEGIN_MESSAGE_MAP(CConsoleTab, CDialog)
//{{AFX_MSG_MAP(CConsoleTab)
ON_WM_DESTROY()
ON_EN_MAXTEXT(IDC_CONEDIT, OnMaxtextConedit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConsoleTab message handlers
BOOL CConsoleTab::OnInitDialog()
{
CDialog::OnInitDialog();
// Position the new dialog on the tab...
RECT rect;
RECT rect2;
m_pParentCtrl->GetClientRect( &rect );
m_pParentCtrl->GetItemRect( 0, &rect2 );
rect.top = rect2.bottom + FTC_BORDER_SIZE_TOP;
rect.left = rect.left + FTC_BORDER_SIZE_LEFT;
rect.right = rect.right - FTC_BORDER_SIZE_RIGHT ;
rect.bottom = rect.bottom - FTC_BORDER_SIZE_BOTTOM ;
SetWindowPos( NULL, rect.left,
rect.top, rect.right, rect.bottom, SWP_NOZORDER );
GetDlgItem(IDC_CONEDIT, &ConHwnd);
GetDlgItem(IDC_CONEDIT)->SetWindowPos
(
NULL,
FTC_BORDER_SIZE_LEFT, FTC_BORDER_SIZE_TOP,
rect.right-4, rect.bottom-28,
SWP_NOZORDER
);
#if 1
Font = ::CreateFont
(
11, // logical height of font
0, // logical average character width
0, // angle of escapement
0, // base-line orientation angle
FW_NORMAL, // font weight
0, // italic attribute flag
0, // underline attribute flag
0, // strikeout attribute flag
ANSI_CHARSET, // character set identifier
OUT_DEFAULT_PRECIS, // output precision
CLIP_DEFAULT_PRECIS, // clipping precision
DRAFT_QUALITY, // output quality
DEFAULT_PITCH, // pitch and family
"MS Sans Serif" // pointer to typeface name string
);
#endif
if (Font == NULL)
{
Font = (HFONT)(::GetStockObject (SYSTEM_FIXED_FONT));
}
else
{
bNewFont = TRUE;
}
if (ConHwnd != NULL)
{
::SendMessage (ConHwnd, WM_SETFONT, (WPARAM)Font, FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CConsoleTab::OnDestroy()
{
CDialog::OnDestroy();
//Set the hwnd for ConPrintf to null
if (bNewFont != FALSE)
{
::DeleteObject (Font);
Font = NULL;
}
ConHwnd=NULL;
}
char *TranslateString(char *buf)
{
static char buf2[32768];
char *out;
unsigned int i;
for(i=0, out=buf2;i < strlen(buf);i++)
{
if(buf[i]=='\n')
{
*out++ ='\r';
*out++ ='\n';
}
else
{
*out++ =buf[i];
}
}
*out++ =0;
return buf2;
}
void ConClear(void)
{
char text[4];
text[0] =0;
if(ConHwnd)
{
SendMessage(ConHwnd, WM_SETTEXT, 0, (LPARAM)text);
}
}
void ConPrintf(char *text, ...)
{
char buf[32768]; //this is ... cautious
char *out;
va_list argptr;
va_start(argptr, text);
vsprintf(buf, text, argptr);
va_end(argptr);
out =TranslateString(buf);
if(ConHwnd)
{
SendMessage(ConHwnd, EM_REPLACESEL, 0, (LPARAM)out);
}
}
void ConError(char *text, ...)
{
char buf[32768]; //this is ... cautious
char *out;
va_list argptr;
va_start(argptr, text);
vsprintf(buf, text, argptr);
va_end(argptr);
out =TranslateString(buf);
if(ConHwnd)
{
SendMessage(ConHwnd, EM_REPLACESEL, 0, (LPARAM)out);
}
}
void CConsoleTab::OnMaxtextConedit(void)
{
ConClear();
}