1 /* -*- tab-width: 4 -*-
2 *
3 * Electric(tm) VLSI Design System
4 *
5 * File: graphpcmsgview.cpp
6 * Message window implementation file
7 * Written by: Steven M. Rubin, Static Free Software
8 *
9 * Copyright (c) 2000 Static Free Software.
10 *
11 * Electric(tm) is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Electric(tm) is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Electric(tm); see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
24 * Boston, Mass 02111-1307, USA.
25 *
26 * Static Free Software
27 * 4119 Alpine Road
28 * Portola Valley, California 94028
29 * info@staticfreesoft.com
30 */
31
32 #include "graphpcstdafx.h"
33 #include "graphpc.h"
34 #include "graphpcmsgview.h"
35 #include "graphpcchildframe.h"
36 #include "global.h"
37
38 #ifdef _DEBUG
39 #define new DEBUG_NEW
40 #endif
41
42 /////////////////////////////////////////////////////////////////////////////
43 /* CElectricMsgView */
44
45 IMPLEMENT_DYNCREATE(CElectricMsgView, CRichEditView)
46
47 COLORREF CElectricMsgView::fForeColor = RGB(0, 0, 0);
48 COLORREF CElectricMsgView::fBackColor = RGB(200, 200, 200);
49
CElectricMsgView()50 CElectricMsgView::CElectricMsgView()
51 {
52 }
53
~CElectricMsgView()54 CElectricMsgView::~CElectricMsgView()
55 {
56 }
57
BEGIN_MESSAGE_MAP(CElectricMsgView,CRichEditView)58 BEGIN_MESSAGE_MAP(CElectricMsgView, CRichEditView)
59 //{{AFX_MSG_MAP(CElectricMsgView)
60 ON_WM_CHAR()
61 ON_WM_SIZE()
62 ON_WM_KEYDOWN()
63 //}}AFX_MSG_MAP
64 END_MESSAGE_MAP()
65
66 /////////////////////////////////////////////////////////////////////////////
67 /* CElectricMsgView drawing */
68
69 void CElectricMsgView::OnDraw(CDC* pDC)
70 {
71 CDocument* pDoc = GetDocument();
72 }
73
74 /////////////////////////////////////////////////////////////////////////////
75 /* CElectricMsgView diagnostics */
76
77 #ifdef _DEBUG
AssertValid() const78 void CElectricMsgView::AssertValid() const
79 {
80 CRichEditView::AssertValid();
81 }
82
Dump(CDumpContext & dc) const83 void CElectricMsgView::Dump(CDumpContext& dc) const
84 {
85 CRichEditView::Dump(dc);
86 }
87 #endif
88
89 /////////////////////////////////////////////////////////////////////////////
90 /* CElectricMsgView message handlers */
91
92 void gra_activateframe(CChildFrame *frame, BOOL bActivate);
93 void gra_resize(CChildFrame *frame, int cx, int cy);
94 void gra_keyaction(UINT nChar, INTBIG special, UINT nRepCnt);
95
OnChar(UINT nChar,UINT nRepCnt,UINT nFlags)96 void CElectricMsgView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
97 {
98 gra_keyaction(nChar, 0, 1);
99 }
100
OnActivateView(BOOL bActivate,CView * pActivateView,CView * pDeactiveView)101 void CElectricMsgView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
102 {
103 extern CChildFrame *gra_messageswindow;
104
105 CRichEditView::OnActivateView(bActivate, pActivateView, pDeactiveView);
106 LoadColors();
107 gra_activateframe(gra_messageswindow, bActivate);
108 }
109
OnSize(UINT nType,int cx,int cy)110 void CElectricMsgView::OnSize(UINT nType, int cx, int cy)
111 {
112 extern CChildFrame *gra_messageswindow;
113
114 CRichEditView::OnSize(nType, cx, cy);
115
116 if (cx != 0 && cy != 0 && gra_messageswindow != 0)
117 gra_resize(gra_messageswindow, cx, cy);
118 }
119
OnKeyDown(UINT nChar,UINT nRepCnt,UINT nFlags)120 void CElectricMsgView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
121 {
122 INTBIG special;
123
124 /* handle function keys */
125 if (nChar == VK_F1) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF1 <<SPECIALKEYSH), nRepCnt); return; }
126 if (nChar == VK_F2) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF2 <<SPECIALKEYSH), nRepCnt); return; }
127 if (nChar == VK_F3) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF3 <<SPECIALKEYSH), nRepCnt); return; }
128 if (nChar == VK_F4) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF4 <<SPECIALKEYSH), nRepCnt); return; }
129 if (nChar == VK_F5) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF5 <<SPECIALKEYSH), nRepCnt); return; }
130 if (nChar == VK_F6) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF6 <<SPECIALKEYSH), nRepCnt); return; }
131 if (nChar == VK_F7) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF7 <<SPECIALKEYSH), nRepCnt); return; }
132 if (nChar == VK_F8) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF8 <<SPECIALKEYSH), nRepCnt); return; }
133 if (nChar == VK_F9) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF9 <<SPECIALKEYSH), nRepCnt); return; }
134 if (nChar == VK_F10) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF10<<SPECIALKEYSH), nRepCnt); return; }
135 if (nChar == VK_F11) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF11<<SPECIALKEYSH), nRepCnt); return; }
136 if (nChar == VK_F12) { gra_keyaction(0, SPECIALKEYDOWN|(SPECIALKEYF12<<SPECIALKEYSH), nRepCnt); return; }
137
138 /* handle numeric keypad with control key pressed */
139 special = 0;
140 if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) special |= ACCELERATORDOWN;
141 if ((special&ACCELERATORDOWN) != 0)
142 {
143 if (nChar == VK_NUMPAD0)
144 { gra_keyaction('0', special, nRepCnt); return; }
145 if (nChar == VK_NUMPAD1)
146 { gra_keyaction('1', special, nRepCnt); return; }
147 if (nChar == VK_NUMPAD2)
148 { gra_keyaction('2', special, nRepCnt); return; }
149 if (nChar == VK_NUMPAD3)
150 { gra_keyaction('3', special, nRepCnt); return; }
151 if (nChar == VK_NUMPAD4)
152 { gra_keyaction('4', special, nRepCnt); return; }
153 if (nChar == VK_NUMPAD5)
154 { gra_keyaction('5', special, nRepCnt); return; }
155 if (nChar == VK_NUMPAD6)
156 { gra_keyaction('6', special, nRepCnt); return; }
157 if (nChar == VK_NUMPAD7)
158 { gra_keyaction('7', special, nRepCnt); return; }
159 if (nChar == VK_NUMPAD8)
160 { gra_keyaction('8', special, nRepCnt); return; }
161 if (nChar == VK_NUMPAD9)
162 { gra_keyaction('9', special, nRepCnt); return; }
163 if (nChar == VK_OEM_PLUS)
164 { gra_keyaction('+', special, nRepCnt); return; }
165 if (nChar == VK_OEM_MINUS)
166 { gra_keyaction('-', special, nRepCnt); return; }
167 if (nChar == VK_OEM_PERIOD)
168 { gra_keyaction('.', special, nRepCnt); return; }
169 if (nChar == VK_OEM_COMMA)
170 { gra_keyaction(',', special, nRepCnt); return; }
171 }
172
173 CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
174 }
175
SetColors(COLORREF fore,COLORREF back)176 void CElectricMsgView::SetColors(COLORREF fore, COLORREF back)
177 {
178 fForeColor = fore;
179 fBackColor = back;
180
181 LoadColors();
182 Invalidate();
183 }
184
LoadColors(void)185 void CElectricMsgView::LoadColors(void)
186 {
187 /* added part: */
188 CRichEditCtrl *ctrl;
189 CHARFORMAT2 cf;
190 long startsel, endsel;
191
192 ctrl = &GetRichEditCtrl();
193 if (ctrl == 0) return;
194 ctrl->SetBackgroundColor(FALSE, fBackColor);
195
196 /* set foreground color */
197 ctrl->GetSel(startsel, endsel);
198 ctrl->SetSel(0, -1);
199 cf.cbSize = sizeof (CHARFORMAT2);
200 cf.dwMask = CFM_COLOR;
201 cf.dwEffects = 0;
202 cf.crTextColor = fForeColor;
203 ctrl->SetSelectionCharFormat(cf);
204 ctrl->SetSel(startsel, endsel);
205 ctrl->SetDefaultCharFormat(cf);
206 }
207