summaryrefslogtreecommitdiffabout
path: root/T42Document.cpp
blob: 3eeb427828d5f1d0ada37d6540f29e9f0029139e (plain)
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
// T42Document.cpp : implementation file
//

#include "stdafx.h"
#include "T42.h"
#include "T42Document.h"

#include "T42View.h"
#include "T42Frame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// T42Document

IMPLEMENT_DYNCREATE(T42Document, CDocument)

T42Document::T42Document()
{
	m_pView=NULL;
	m_pRobot = NULL;
	m_bHidden = FALSE;
}

BOOL T42Document::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
	return TRUE;
}

T42Document::~T42Document()
{
	if(m_pRobot)
		DetachRobot();
}


BEGIN_MESSAGE_MAP(T42Document, CDocument)
	//{{AFX_MSG_MAP(T42Document)
	ON_COMMAND(ID_WINDOW_SAVELAYOUT, OnWindowSavelayout)
	ON_UPDATE_COMMAND_UI(ID_WINDOW_AUTOSAVELAYOUT, OnUpdateWindowAutosavelayout)
	ON_COMMAND(ID_WINDOW_AUTOSAVELAYOUT, OnWindowAutosavelayout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// T42Document diagnostics

#ifdef _DEBUG
void T42Document::AssertValid() const
{
	CDocument::AssertValid();
}

void T42Document::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// T42Document serialization

void T42Document::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
	}
	else
	{
	}
}

/////////////////////////////////////////////////////////////////////////////
// T42Document commands

void T42Document::Talk(LPCTSTR from,LPCTSTR to,LPCTSTR tty,BOOL bPrompt)
{
	ASSERT(m_pView);
	ASSERT(m_pView->m_pFrame);
	m_pView->m_pFrame->m_Target = to?to:"";
	m_pView->m_pFrame->m_LocalUser = from?from:"";
	m_pView->m_pFrame->m_TargetTTY = tty?tty:"";
	if(bPrompt || !(to && from))
		m_pView->m_pFrame->PostMessage(WM_COMMAND,MAKELONG(ID_TALK_REMOTEUSER,0),NULL);
	else
		m_pView->m_pFrame->PostMessage(WM_INITIATETALK);
}

void T42Document::OnChangedViewList() 
{
	CDocument::OnChangedViewList();
POSITION p = GetFirstViewPosition();
	m_pView=NULL;
	while(p){
	CView* pView = GetNextView(p);
		ASSERT_KINDOF(T42View,pView);
		ASSERT(!m_pView);
		m_pView=(T42View*)pView;
	}
}

void T42Document::SaveLayout()
{
	ASSERT(m_pView);
	m_pView->SaveLayout();
	ASSERT(m_pView->m_pFrame);
	m_pView->m_pFrame->SaveLayout();
}

void T42Document::OnWindowSavelayout() 
{
	SaveLayout();
}

void T42Document::OnUpdateWindowAutosavelayout(CCmdUI* pCmdUI) 
{
CT42App* app = (CT42App*)AfxGetApp();
	pCmdUI->SetCheck(app->m_bt42AutosaveLayout?1:0);
}

void T42Document::OnWindowAutosavelayout() 
{
CT42App* app = (CT42App*)AfxGetApp();
	app->m_bt42AutosaveLayout=!app->m_bt42AutosaveLayout;
}

void T42Document::AutosaveLayout()
{
CT42App* app = (CT42App*)AfxGetApp();
	if(app->m_bt42AutosaveLayout)
		SaveLayout();
}

BOOL T42Document::AttachRobot(CT42Robot* pRobot)
{
	if(m_pRobot)
		DetachRobot();
	m_pRobot = pRobot;
	return m_pRobot->OnAttach(this);
}

BOOL T42Document::DetachRobot()
{
	ASSERT(m_pRobot);
BOOL rv = m_pRobot->OnDetach();
	m_pRobot=NULL;
	return rv;
}

BOOL T42Document::SendOver(LPCTSTR str)
{
	// *** Or call T42View function?
	for(LPCTSTR ptr=str;*ptr;ptr++){
		m_pView->m_localCtl.PutCharacter(*ptr);
		m_pView->m_pFrame->PostMessage(WM_TALKCHAR,0xFF&((WORD)*ptr));
	}
	return TRUE;
}

BOOL T42Document::OnOpenDocument(LPCTSTR lpszPathName) 
{
//	if (!CDocument::OnOpenDocument(lpszPathName))
//		return FALSE;

	if(lpszPathName)
		m_bHidden = TRUE;
	
	return TRUE;
}

void T42Document::OnMinute()
{
	if(m_pRobot)
		m_pRobot->OnMinute();
}