comparison anagram/guisupport/windowreg.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 * windowreg.cpp
7 */
8
9 #include "ctrlpanel.hpp" // sigh... XXX (for syntaxFileId/syntaxFileRect)
10 #include "vaclgui.hpp" // XXX (for cascadeOrigin/cascadeOffset)
11 #include "windowreg.h"
12
13 //#define INCLUDE_LOGGING
14 #include "log.h"
15
16
17 void WindowRegistry::registerId(AgFrame *window,
18 AgString title, AgAction action) {
19 LOGSECTION("WindowRegistry::registerId");
20 int id = window->id();
21 int first = 0, last = registry.size();
22 LOGV(id) LCV(title.pointer()) LCV(last);
23 int firstClone = -1;
24 int firstViewNumber = 0;
25 int maxView = 1;
26
27 while (first < last) {
28 registry[first++].isActive = 0;
29 }
30 first = 0;
31 while (first < last) {
32 WindowRecord &windowRecord = registry[first];
33 if (windowRecord.id == id) {
34 windowRecord.action = action;
35 windowRecord.title = title;
36 windowRecord.window = window;
37 windowRecord.isActive = 1;
38 return;
39 }
40 if (windowRecord.title == title) {
41 int viewNumber = windowRecord.window->windowTitle.viewNumber();
42 if (firstClone == -1) {
43 firstClone = first;
44 firstViewNumber = viewNumber;
45 }
46 if (maxView < viewNumber) {
47 maxView = viewNumber;
48 }
49 }
50 first++;
51 }
52 LOGV(maxView);
53 registry.push(WindowRecord());
54 LOGV(first) LCV(registry.size());
55 WindowRecord &windowRecord = registry[first];
56 LOGV((int) &registry[first]);
57 LOGV((int) &windowRecord);
58 windowRecord.id = id;
59 windowRecord.action = action;
60 windowRecord.title = title;
61 windowRecord.window = window;
62 windowRecord.isActive = 1;
63 if (firstClone == -1) {
64 return;
65 }
66 if (firstViewNumber == 0) {
67 LOGV(firstClone);
68 registry[firstClone].window->windowTitle.setViewNumber(1);
69 }
70 window->windowTitle.setViewNumber(maxView+1);
71 LOGS("registration complete");
72 }
73
74 void WindowRegistry::refresh(AgString title) {
75 LOGSECTION("WindowRegistry::refresh");
76 int first = 0, last = registry.size();
77 LOGV(title.pointer()) LCV(last);
78 while (first < last) {
79 WindowRecord &windowRecord = registry[first];
80 if (windowRecord.title == title) {
81 windowRecord.window->refresh();
82 }
83 first++;
84 }
85 }
86
87 void WindowRegistry::remove(int id) {
88 LOGSECTION("WindowRegistry::remove");
89 LOGV(id);
90 int first = 0, last = registry.size();
91 while (first < last) {
92 if (registry[first].id == id) {
93 LOGV(registry[first].title.pointer());
94 if (id == syntaxFileId) {
95 LOGV(syntaxFileId);
96 LOGV(syntaxFileRect.asString());
97 syntaxFileRect = registry[first].window->rect();
98 LOGV(syntaxFileRect.asString());
99 syntaxFileId = 0;
100 }
101 last--;
102 while (first < last) {
103 registry[first] = registry[first+1];
104 first++;
105 }
106 registry.pop();
107 break;
108 }
109 first++;
110 }
111 if (registry.size() == 0) {
112 cascadeOffset = cascadeOrigin;
113 }
114 }
115
116 AgFrame *WindowRegistry::find(AgString title) {
117 LOGSECTION("WindowRegistry::find(AgString)");
118 LOGV(title.pointer());
119 int first = 0, last = registry.size();
120 LOGV(last);
121 while (first < last) {
122 LOGV(registry[first].title.pointer());
123 if (registry[first].title == title) {
124 return registry[first].window;
125 }
126 first++;
127 }
128 return NULL;
129 }
130
131 AgFrame *WindowRegistry::find(int id) {
132 LOGSECTION("WindowRegistry::find(int)");
133 int first = 0, last = registry.size();
134 while (first < last) {
135 LOGV(registry[first].id);
136 LOGV(registry[first].title.pointer());
137 if (registry[first].id == id) {
138 return registry[first].window;
139 }
140 first++;
141 }
142 return NULL;
143 }
144
145 AgString WindowRegistry::getTitle(int id) {
146 int first = 0, last = registry.size();
147 while (first < last) {
148 if (registry[first].id == id) {
149 return registry[first].title;
150 }
151 first++;
152 }
153 return AgString();
154 }
155
156 /*
157 void WindowRegistry::bubbleUp(int id) {
158 LOGSECTION("WindowRegistry::bubbleUp");
159 if (cascadeFlag) return;
160 int first = 0, last = registry.size() - 1;
161 while (first < last) {
162 LOGV(registry[first].id) LCV(registry[first].title.pointer());
163 if (registry[first].id == id) {
164 LOGS("found it");
165 WindowRecord save = registry[first];
166 for (int i = first; i < last; i++) registry[i] = registry[i+1];
167 registry[last] = save;
168 return;
169 }
170 first++;
171 }
172 }
173 */
174
175 void WindowRegistry::markActive(int id) {
176 LOGSECTION("WindowRegistry::markActive");
177 if (cascadeFlag) {
178 return;
179 }
180 int first = 0, last = registry.size();
181 while (first < last) {
182 registry[first++].isActive = 0;
183 }
184 first = 0;
185 while (first < last) {
186 LOGV(registry[first].id) LCV(registry[first].title.pointer());
187 if (registry[first].id == id) {
188 LOGS("found it");
189 registry[first].isActive = 1;
190 return;
191 }
192 first++;
193 }
194 }
195
196 void WindowRegistry::clearActive() {
197 LOGSECTION("WindowRegistry::clearActive");
198 int first = 0, last = registry.size();
199 while (first < last) {
200 registry[first++].isActive = 0;
201 }
202 }
203
204 int WindowRegistry::action(int id) {
205 LOGSECTION("WindowRegistry::action");
206 int first = 0, last = registry.size();
207 while (first < last) {
208 if (registry[first].id == id) {
209 registry[first].action.perform();
210 return 1;
211 }
212 first++;
213 }
214 LOGS("command not recognized");
215 return 0;
216 }
217
218 int WindowRegistry::action(AgString title) {
219 LOGSECTION("WindowRegistry::action(AgString)");
220 LOGV(title.pointer());
221 int first = 0, last = registry.size();
222 LOGV(last);
223 while (first < last) {
224 LOGV(registry[first].title.pointer());
225 if (registry[first].title == title) {
226 registry[first].action.perform();
227 return 1;
228 }
229 first++;
230 }
231 return 0;
232 }
233