Mercurial > ~dholland > hg > ag > index.cgi
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/vaclgui/fileview.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,149 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1997-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * fileview.cpp + */ + +#include "agcstack.h" +#include "dspar.hpp" +#include "fileview.hpp" +#include "vaclgui.hpp" + +//#define INCLUDE_LOGGING +#include "log.h" + + +FileView::FileView(IWindow *owner, text_file &file_) + : AgView(owner) + , file(file_) + , dataColorChange(this, onColorChange) + , fontChange(this, onFontChange) +{ + LOGSECTION("FileView::FileView"); + LOGV(file.name.pointer()); + LOGV(file.size()); + LOGV((int) file.text.pointer()); + dataColorChange.attach(&ColorSpec::syntaxFile); + dataColorChange.attach(&ColorSpec::activeCursor); + dataColorChange.attach(&ColorSpec::inactiveCursor); + + setFont(FontSpec::syntaxFile); + fontChange.attach(&FontSpec::syntaxFile); +} + +FileView::~FileView() { + LOGSECTION("FileView::~FileView"); +} + +void FileView::onFontChange() { + setFont(FontSpec::syntaxFile); + tableWidth = 0; + doLayout(); +} + +AgString FileView::getLine(unsigned ln) { + //LOGSECTION("FileView::getLine", Log::off); + //LOGSECTION_OFF("FileView::getLine"); + LOGSECTION_ON("FileView::getLine"); + LOGV(ln); + AgCharStack line; + if (ln >= file.size().y) { + return AgString(); + } + char *p = file.line(ln); + LOGV((int) p); + while (*p && *p != '\n') { + char c = *p++; + if (c == '\r') { + continue; + } + line.push(c); + } + AgString lineString = line.popString(); + LOGV(lineString); + return lineString; + //return line.popString(); +} + +void FileWindow::init(text_file &file, IRectangle initialRect) { + LOGSECTION("FileWindow::init"); + windowId = id(); + + AgString viewName = file.name.lastCut("\\/").rightX().lastCut('.').leftX(); + setClient(&fileView); + IFont viewFont = FontSpec::syntaxFile; + LOGV(viewName.pointer()); + registerTitle(viewName); + LOGV(initialRect.asString()) LCV(initialRect.area()); + if (initialRect.area() <= 0) { + int height = viewFont.externalLeading() + viewFont.maxSize().height(); + height *= 15; +/* + int width = fileView.suggestSize().width(); + int minWidth = 60*viewFont.avgCharWidth(); + if (width < minWidth) { + width = minWidth; + } +*/ + int width = 80*viewFont.avgCharWidth(); + LOGV(width); + LOGV(viewFont.name()) LCV(viewFont.pointSize()) LCV(viewFont.isFixed()); + if (viewFont.isFixed()) { + width = 80*viewFont.maxSize().width(); + } + LOGV(width); + ISize size(width, height); + LOGV(size.asString()); + sizeTo(frameRectFor(IRectangle(size)).size()); + //positionFrame(); + } + else { + moveSizeTo(adjustPos(initialRect)); + } + + windowTitle.setViewText(viewName.pointer()); +} + +Boolean FileView::findNext(AgString s) { + LOGSECTION("FileView::findNext"); + cint loc = getCursorLocation(); + int flag; + + if (cursorLineHighlight) { + loc.y++; + if (loc.y >= nLines()) { + return false; + } + loc.x = 0; + flag = file.findNext(loc, s); + if (!flag) { + loc = getCursorLocation(); + } + } + else { + flag = file.findNext(loc, s); + } + setCursorLocation(loc); + return flag; +} + +Boolean FileView::findPrev(AgString s) { + LOGSECTION("FileView::findPrev"); + cint loc = getCursorLocation(); + int flag; + if (cursorLineHighlight) { + loc.x = 0; + flag = file.findPrev(loc, s); + if (!flag) { + loc = getCursorLocation(); + } + } + else { + flag = file.findPrev(loc,s); + } + setCursorLocation(loc); + return flag; +} +