comparison anagram/vaclgui/fileview.cpp @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * fileview.cpp
7 */
8
9 #include "agcstack.h"
10 #include "dspar.hpp"
11 #include "fileview.hpp"
12 #include "vaclgui.hpp"
13
14 //#define INCLUDE_LOGGING
15 #include "log.h"
16
17
18 FileView::FileView(IWindow *owner, text_file &file_)
19 : AgView(owner)
20 , file(file_)
21 , dataColorChange(this, onColorChange)
22 , fontChange(this, onFontChange)
23 {
24 LOGSECTION("FileView::FileView");
25 LOGV(file.name.pointer());
26 LOGV(file.size());
27 LOGV((int) file.text.pointer());
28 dataColorChange.attach(&ColorSpec::syntaxFile);
29 dataColorChange.attach(&ColorSpec::activeCursor);
30 dataColorChange.attach(&ColorSpec::inactiveCursor);
31
32 setFont(FontSpec::syntaxFile);
33 fontChange.attach(&FontSpec::syntaxFile);
34 }
35
36 FileView::~FileView() {
37 LOGSECTION("FileView::~FileView");
38 }
39
40 void FileView::onFontChange() {
41 setFont(FontSpec::syntaxFile);
42 tableWidth = 0;
43 doLayout();
44 }
45
46 AgString FileView::getLine(unsigned ln) {
47 //LOGSECTION("FileView::getLine", Log::off);
48 //LOGSECTION_OFF("FileView::getLine");
49 LOGSECTION_ON("FileView::getLine");
50 LOGV(ln);
51 AgCharStack line;
52 if (ln >= file.size().y) {
53 return AgString();
54 }
55 char *p = file.line(ln);
56 LOGV((int) p);
57 while (*p && *p != '\n') {
58 char c = *p++;
59 if (c == '\r') {
60 continue;
61 }
62 line.push(c);
63 }
64 AgString lineString = line.popString();
65 LOGV(lineString);
66 return lineString;
67 //return line.popString();
68 }
69
70 void FileWindow::init(text_file &file, IRectangle initialRect) {
71 LOGSECTION("FileWindow::init");
72 windowId = id();
73
74 AgString viewName = file.name.lastCut("\\/").rightX().lastCut('.').leftX();
75 setClient(&fileView);
76 IFont viewFont = FontSpec::syntaxFile;
77 LOGV(viewName.pointer());
78 registerTitle(viewName);
79 LOGV(initialRect.asString()) LCV(initialRect.area());
80 if (initialRect.area() <= 0) {
81 int height = viewFont.externalLeading() + viewFont.maxSize().height();
82 height *= 15;
83 /*
84 int width = fileView.suggestSize().width();
85 int minWidth = 60*viewFont.avgCharWidth();
86 if (width < minWidth) {
87 width = minWidth;
88 }
89 */
90 int width = 80*viewFont.avgCharWidth();
91 LOGV(width);
92 LOGV(viewFont.name()) LCV(viewFont.pointSize()) LCV(viewFont.isFixed());
93 if (viewFont.isFixed()) {
94 width = 80*viewFont.maxSize().width();
95 }
96 LOGV(width);
97 ISize size(width, height);
98 LOGV(size.asString());
99 sizeTo(frameRectFor(IRectangle(size)).size());
100 //positionFrame();
101 }
102 else {
103 moveSizeTo(adjustPos(initialRect));
104 }
105
106 windowTitle.setViewText(viewName.pointer());
107 }
108
109 Boolean FileView::findNext(AgString s) {
110 LOGSECTION("FileView::findNext");
111 cint loc = getCursorLocation();
112 int flag;
113
114 if (cursorLineHighlight) {
115 loc.y++;
116 if (loc.y >= nLines()) {
117 return false;
118 }
119 loc.x = 0;
120 flag = file.findNext(loc, s);
121 if (!flag) {
122 loc = getCursorLocation();
123 }
124 }
125 else {
126 flag = file.findNext(loc, s);
127 }
128 setCursorLocation(loc);
129 return flag;
130 }
131
132 Boolean FileView::findPrev(AgString s) {
133 LOGSECTION("FileView::findPrev");
134 cint loc = getCursorLocation();
135 int flag;
136 if (cursorLineHighlight) {
137 loc.x = 0;
138 flag = file.findPrev(loc, s);
139 if (!flag) {
140 loc = getCursorLocation();
141 }
142 }
143 else {
144 flag = file.findPrev(loc,s);
145 }
146 setCursorLocation(loc);
147 return flag;
148 }
149