comparison anagram/vaclgui/dpanel.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 * dpanel.cpp
7 */
8
9
10 #include "agcstack.h"
11 #include "dpanel.hpp"
12 #include "myalloc.h"
13
14 //#define INCLUDE_LOGGING
15 #include "log.h"
16
17
18 AgDataPanel::AgDataPanel(WindowData *data)
19 : AgFrame( IFrameWindow::maximizeButton
20 | IFrameWindow::systemMenu
21 | IFrameWindow::sizingBorder)
22 , dataView(new AgDataView(this, data))
23 , helpDemon(&windowTitle, data->headTitle())
24 {
25 LOGSECTION("AgDataPanel::AgDataPanel(WindowData *)");
26 LOGV(windowId);
27 ok_ptr(data);
28 syntaxDependent = data->syntaxDependent();
29 init();
30 }
31
32 AgDataPanel::AgDataPanel()
33 : AgFrame( IFrameWindow::maximizeButton
34 | IFrameWindow::systemMenu
35 | IFrameWindow::sizingBorder)
36 , helpDemon(&windowTitle)
37 {
38 LOGSECTION("AgDataPanel::AgDataPanel()");
39 LOGV(windowId);
40 }
41
42 void AgDataPanel::init() {
43 LOGSECTION("AgDataPanel::init");
44 LOGV(windowId);
45 AgString titleString;
46 AgString title;
47 AgString simpleTitle;
48
49 ok_ptr(dataView->windowData);
50 title = dataView->windowData->headTitle();
51 helpDemon.setTopic(title);
52 LOGV(title.pointer());
53
54 AgString name = dataView->windowData->fileName();
55 char buf[500] = "AnaGram";
56 if (syntaxDependent && name.exists()) {
57 sprintf(buf, "AnaGram : %s", name.pointer());
58 }
59 AgString objectName = buf;
60
61 AgString foot = dataView->windowData->footTitle();
62 if (foot.exists() && foot.size()) {
63 simpleTitle = AgString::format("%s (%s)", title.pointer(), foot.pointer());
64 }
65 else {
66 simpleTitle = title;
67 }
68
69 LOGV(windowTitle.objectText());
70 LOGV(windowTitle.viewText());
71 LOGV(windowTitle.text());
72
73 windowTitle.setObjectText(objectName.pointer());
74 windowTitle.setViewText(simpleTitle.pointer());
75 AgCharStack cs;
76 //cs.push(name).push(" - ").push(simpleTitle);
77 cs << name;
78 cs << " - " << simpleTitle;
79 dataView->copyTitle = cs.popString();
80 LOGV(dataView->copyTitle);
81 LOGV(windowTitle.objectText());
82 LOGV(windowTitle.viewText());
83 LOGV(windowTitle.text());
84
85 registerTitle(simpleTitle);
86
87 ISize tableSize = dataView->suggestSize();
88
89 int width = 40*dataView->font().avgCharWidth();
90 int testWidth = tableSize.width();
91
92 int titleWidth
93 = windowTitle.displaySize(windowTitle.text()).width()
94 + windowTitle.minimumSize().width();
95
96 LOGV(windowTitle.text());
97 LOGV(titleWidth);
98 LOGV(testWidth);
99
100 if (testWidth < titleWidth) {
101 testWidth = titleWidth;
102 }
103 LOGV(width);
104 LOGV(testWidth);
105
106 if (testWidth < width/2) {
107 width = width/2;
108 }
109 else if (testWidth > 2*width) {
110 width = 2*width;
111 }
112 else {
113 width = testWidth;
114 }
115
116 LOGV(width);
117
118 ISize clientSize(width, tableSize.height());
119 IRectangle frameRect(frameRectFor(clientSize));
120 LOGV(clientSize.asString());
121 LOGV(frameRect.size().asString());
122 sizeTo(frameRect.size());
123
124 //LOGV(cascadeOffset.asString());
125
126 setClient(dataView);
127
128 positionFrame();
129 //show();
130 }
131
132 AgDataPanel::~AgDataPanel() {
133 LOGSECTION("AgDataPanel::~AgDataPanel");
134 LOGV(windowId);
135 //dataView->disconnect();
136 ok_ptr(dataView->windowData);
137 //dataView->disconnect();
138 //if (dataView->windowData) dataView->windowData->close();
139 delete dataView;
140 }
141
142 void AgDataPanel::disconnect() {
143 LOGSECTION("AgDataPanel::disconnect");
144 dataView->disconnect();
145 }
146
147 AgDataPanel &AgDataPanel::close() {
148 LOGSECTION("AgDataPanel::close");
149 /*
150 if (dataView->windowData) {
151 dataView->windowData->close();
152 }
153 delete dataView->windowData;
154 */
155 //dataView->windowData = 0;
156 //dataView->disconnect();
157 IFrameWindow::close();
158 return *this;
159 }
160
161 unsigned AgDataPanel::getLineNumber() {
162 return dataView->getCursorLine();
163 }
164
165 void AgDataPanel::setLineNumber(unsigned n) {
166 dataView->setCursorLine(n);
167 }
168
169 Boolean AgDataPanel::findNext(AgString s) {
170 return dataView->findNext(s);
171 }
172
173 Boolean AgDataPanel::findPrev(AgString s) {
174 return dataView->findPrev(s);
175 }