33 #include "lib/charbuf.h" 34 #include "lib/aengine.h" 35 #include "main/evaluator.h" 44 #pragma GCC diagnostic ignored "-Wno-multichar" 47 #include <Application.h> 48 #include <ScrollView.h> 49 #include <LayoutBuilder.h> 52 #include <private/interface/AboutWindow.h> 54 HaikuWindow::HaikuWindow(
const char *prompt, CharValidator *validator) :
57 BRect(150, 150, 800, 600),
60 B_ASYNCHRONOUS_CONTROLS
63 BRect textRect = Bounds();
64 textRect.OffsetTo(0, 0);
65 textRect.InsetBy(5, 5);
67 BFont font(be_fixed_font);
68 textView =
new HaikuTextView(
74 textView->SetStylable(
true);
75 DetachMemSafe(textView);
77 BScrollView *scrollView =
new BScrollView(
78 TXTTITLE
"ScrollView",
84 DetachMemSafe(scrollView);
104 HaikuWindow::~HaikuWindow(
void)
108 void HaikuWindow::Exit(
void)
110 be_app->PostMessage(B_QUIT_REQUESTED);
113 void HaikuWindow::Start(
void)
115 textView->MakeFocus(
true);
121 void HaikuWindow::StartMessage(
void)
124 run.font = be_bold_font;
129 run.color.alpha = 255;
131 text_run_array runArray;
133 runArray.runs[0] = run;
135 textView->Insert(INTROMSG, &runArray);
138 void HaikuWindow::ShowAbout(
void)
140 BAboutWindow* about =
new BAboutWindow(
"About amath",
"application/x-vnd.amath");
141 DetachMemSafe(about);
143 CharBuffer *buf =
new CharBuffer();
144 static const char* version = TXTTITLE SPACE RELDATESTAMP;
145 static const char* compiler = TXTCOMPMSG;
146 static const char* footer =
"Details specified in license.";
147 int len = StrLen(version) + StrLen(compiler) + StrLen(footer) + 10;
149 buf->EnsureSize(len);
150 buf->Append(version);
151 buf->Append(NEWLINE);
152 buf->Append(compiler);
153 buf->Append(NEWLINE);
154 buf->Append(NEWLINE);
157 about->AddCopyright(2014,
"Carsten Sonne Larsen");
158 about->AddExtraInfo(buf->GetString());
164 void HaikuWindow::ShowLicense(
void)
167 ConsoleBase::ShowLicense();
170 void HaikuWindow::ShowVersion(
void)
173 run.font = be_bold_font;
176 run.color.green = 139;
178 run.color.alpha = 255;
180 text_run_array runArray;
182 runArray.runs[0] = run;
184 textView->Insert(GetVersionText(), &runArray);
185 textView->Insert(NEWLINE);
187 runArray.runs[0].font = be_plain_font;
188 runArray.runs[0].font.SetFace(B_REGULAR_FACE);
189 runArray.runs[0].color.red = 0;
190 runArray.runs[0].color.green = 0;
191 runArray.runs[0].color.blue = 0;
193 textView->Insert(GetCompilerText(), &runArray);
194 textView->Insert(NEWLINE);
197 void HaikuWindow::Clear(
void)
199 textView->SetText(EMPTYSTRING);
202 void HaikuWindow::WriteString(
const char *string)
205 run.font = be_fixed_font;
210 run.color.alpha = 255;
212 text_run_array runArray;
214 runArray.runs[0] = run;
216 textView->Insert(string, &runArray);
219 void HaikuWindow::Execute(
void)
221 int lineIndex = textView->CurrentLine();
222 int lineStart = textView->OffsetAt(lineIndex);
223 int lineCount = textView->CountLines();
225 if (lineCount != lineIndex + 1)
230 int len = textView->TextLength() - lineStart;
231 char *line =
new char[len + 1];
232 textView->GetText(lineStart, lineStart + len, line);
233 *(line + len) =
'\0';
237 while (*input == *p && *input !=
'\0')
243 WriteString(NEWLINE);
244 Evaluator *evaluator =
new Evaluator(input);
245 evaluator->Evaluate();
246 const char *out = evaluator->GetResult();
253 textView->ScrollToOffset(textView->TextLength() - 1);
256 void HaikuWindow::MessageReceived(BMessage* msg)
260 case B_ABOUT_REQUESTED:
264 BWindow::MessageReceived(msg);
269 void HaikuWindow::FrameResized(
float w,
float h)
274 void HaikuWindow::UpdateTextRect(
void)
276 BRect rect(textView->Bounds());
278 textView->SetTextRect(rect);
281 bool HaikuWindow::QuitRequested()
287 HaikuTextView::HaikuTextView(
292 const BFont *initialFont,
293 const rgb_color *initialColor) :
300 B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED
305 HaikuTextView::~HaikuTextView(
void)
309 void HaikuTextView::KeyDown(
const char *bytes, int32 numBytes)
317 BTextView::KeyDown(bytes, numBytes);