2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ViewMan* ViewMan::instance = NULL;
38 ViewMan* ViewMan::getInstance()
45 if (initted) return 0;
50 int ViewMan::shutdown()
52 if (!initted) return 0;
54 // FIXME don't think this can work properly, removeAll leaves the wallpaper there!
61 int ViewMan::add(View* v)
63 if (!initted) return 0;
64 if (numViews == 16) return 0;
66 views[numViews++] = v;
71 // ---------------------------------------------------- REMOVE CODE
73 int ViewMan::removeView(View* toDelete)
75 if (!initted) return 0;
76 if (numViews == 0) return 0;
78 // Log::getInstance()->log("ViewMan", Log::DEBUG, "entering remove, numViews=%i", numViews);
84 toDelete = views[numViews-1];
89 // to be deleted view is more likely to be at the top
90 for (i = numViews-1; i >= 0; i--)
92 // Log::getInstance()->log("ViewMan", Log::DEBUG, "todel: %p, i=%i, views[i]=%p", toDelete, i, views[i]);
93 if (views[i] == toDelete) break;
98 // not a View we have!
103 // Log::getInstance()->log("ViewMan", Log::DEBUG, "Starting deleteView");
105 // Log::getInstance()->log("ViewMan", Log::DEBUG, "Done deleteView");
107 // Shift the views on top down one
109 for(int j = i; j < numViews; j++) views[j] = views[j+1];
117 /////////////////////////////////////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////////////
121 void ViewMan::deleteView(int z)
123 // Log::getInstance()->log("ViewMan", Log::DEBUG, "Delete view %i of %i", z, numViews);
125 boxSplit(views[z]->area, z + 1, numViews, 1, rl);
128 repaintRevealed(z, rl.front());
133 void ViewMan::updateView(View* toUpdate, Region* regionToUpdate)
135 // Log::getInstance()->log("ViewMan", Log::DEBUG, "UpdateView called");
136 // Get the z index of the view
139 for (z = 0; z < numViews; z++)
141 if (views[z] == toUpdate) break;
146 // not a View we have!
150 // get the region for the whole view, could be less than that
151 // for smaller updates
153 Region r = views[z]->area;
157 // Can be null if the whole view should be updated
158 // If this is given the numbers are relative to the size of the view, not the screen
160 r.x += regionToUpdate->x;
161 r.y += regionToUpdate->y;
162 r.w = regionToUpdate->w;
163 r.h = regionToUpdate->h;
169 boxSplit(r, z+1, numViews, 1, rl);
179 void ViewMan::repaintRevealed(int x, Region r)
182 boxSplit(r, x - 1, -1, -1, rl);
188 views[r2.z]->blt(r2);
193 void ViewMan::boxSplit(Region r, int start, int end, int direction, RegionList& rl)
195 // printf("Y= S=%i E=%i D=%i: Boxsplit: %i %i %i %i\n", start, end, direction, r.x, r.y, r.w, r.h);
197 for(int z = start; z != end; z += direction)
199 if (r.overlappedBy(views[z]->area))
201 // printf("Z=%i S=%i E=%i D=%i: %i overlaps\n", z, start, end, direction, z);
206 if (views[z]->area.y > r.y)
208 // printf("Z=%i S=%i E=%i D=%i: Case 1 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
209 top = views[z]->area.y;
214 newR.h = views[z]->area.y - r.y;
215 boxSplit(newR, z + direction, end, direction, rl);
221 newR2.y = views[z]->area.y;
223 newR2.h = r.h - newR.h;
224 boxSplit(newR2, z, end, -1, rl);
229 if (views[z]->area.y2() < r.y2())
231 // printf("Z=%i S=%i E=%i D=%i: Case 2 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
232 btm = views[z]->area.y2();
235 newR.y = views[z]->area.y2() + 1;
237 newR.h = r.y2() - newR.y + 1;
238 boxSplit(newR, z + direction, end, direction, rl);
246 newR2.h = r.h - newR.h;
247 boxSplit(newR2, z, end, -1, rl);
252 if (views[z]->area.x > r.x)
254 // printf("Z=%i S=%i E=%i D=%i: Case 3 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
258 newR.w = views[z]->area.x - r.x;
259 newR.h = btm - top + 1;
260 boxSplit(newR, z + direction, end, direction, rl);
265 newR2.x = r.x + newR.w;
267 newR2.w = r.w - newR.w;
269 boxSplit(newR2, z, end, -1, rl);
274 if (views[z]->area.x2() < r.x2())
276 // printf("Z=%i S=%i E=%i D=%i: Case 4 for %i %i %i %i split by %i: %i %i %i %i\n", z, start, end, direction, r.x, r.y, r.w, r.h, z, views[z]->area.x, views[z]->area.y, views[z]->area.w, views[z]->area.h);
278 newR.x = views[z]->area.x2() + 1;
280 newR.w = r.x2() - newR.x + 1;
281 newR.h = btm - top + 1;
282 boxSplit(newR, z + direction, end, direction, rl);
289 newR2.w = r.w - newR.w;
291 boxSplit(newR2, z, end, -1, rl);
298 // we are going down the stack
299 // r is underlapped by views[z]
300 // but we have not split
301 // Therefore this region under test is
302 // completely covering views[z]
304 // don't go any further down, generate a region and quit
306 // printf("Repaint region: %i %i %i %i\n", r.x, r.y, r.w, r.h);
311 // printf("Returning from Z=%i\n", z);
316 // printf("Z=%i S=%i E=%i D=%i: %i does not overlap\n", z, start, end, direction, z);
320 // if direction = 1 then we have come to a region that is
321 // entirely clear of higher views and needs to be redrawn
323 // if direction = -1 then we have come to a region that is on
324 // the very bottom with nothing below it to repaint.
325 // do nothing. stale window data will be left on screen?
333 /////////////////////////////////////////////////////////////////////////////
335 /////////////////////////////////////////////////////////////////////////////
337 // ---------------------------------------------------- END OF REMOVE CODE
340 void ViewMan::removeAll()
342 // 1.. Don't delete wallpaper. No point.
343 for (; numViews > 1; --numViews)
345 delete views[numViews-1];
349 int ViewMan::handleCommand(UCHAR command)
355 if (command != Remote::NA_NONE)
357 // handle command return values
358 // 0 - drop through to next view
359 // 1 - dont drop to next view, but not handled
360 // 2 - handled - stop command here
361 // 4 - handled - delete this view
363 for (i=numViews-1; i>=0; i--)
365 // Log::getInstance()->log("ViewMan", Log::DEBUG, "Giving command to i=%i", i);
366 retVal = views[i]->handleCommand(command);
369 // not handled but don't give to any more views
379 else if (retVal == 4)
381 // Log::getInstance()->log("ViewMan", Log::DEBUG, "Return 4: i=%i, views[i]=%p", i, views[i]);
382 removeView(views[i]);
390 // fake the return code
394 // Log::getInstance()->log("ViewMan", Log::DEBUG, "out of handlecommand code, now on to messages");
396 // processMessageQueue();
401 void ViewMan::processMessage(Message* m)
405 for (int i = numViews-1; i >= 0; i--)
407 if (views[i] == m->to)
409 Log::getInstance()->log("ViewMan", Log::DEBUG, "sending message from view %p to view %p %lu", m->from, m->to, m->message);
410 views[i]->processMessage(m);
417 Log::getInstance()->log("ViewMan", Log::DEBUG, "it's for meeee!");
421 case Message::CLOSE_ME:
423 removeView((View*)m->from);
426 case Message::ADD_VIEW: // currently not used by anything but it might come in useful again
428 View* toAdd = (View*)m->parameter;