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
27 BoxStack* BoxStack::instance = NULL;
42 BoxStack* BoxStack::getInstance()
49 if (initted) return 0;
54 int BoxStack::shutdown()
56 if (!initted) return 0;
58 // FIXME don't think this can work properly, removeAll leaves the wallpaper there!
65 int BoxStack::add(Boxx* v)
67 if (!initted) return 0;
68 if (numBoxes == 16) return 0;
70 boxes[numBoxes++] = v;
75 // ---------------------------------------------------- REMOVE CODE
77 int BoxStack::remove(Boxx* toDelete)
79 if (!initted) return 0;
80 if (numBoxes == 0) return 0;
82 // Log::getInstance()->log("BoxStack", Log::DEBUG, "entering remove, numBoxes=%i", numBoxes);
88 toDelete = boxes[numBoxes-1];
93 // to be deleted box is more likely to be at the top
94 for (i = numBoxes-1; i >= 0; i--)
96 // Log::getInstance()->log("BoxStack", Log::DEBUG, "todel: %p, i=%i, boxes[i]=%p", toDelete, i, boxes[i]);
97 if (boxes[i] == toDelete) break;
102 // not a Box we have!
107 // Log::getInstance()->log("BoxStack", Log::DEBUG, "Starting deleteBox");
109 // Log::getInstance()->log("BoxStack", Log::DEBUG, "Done deleteBox");
111 // Shift the boxes on top down one
113 for(int j = i; j < numBoxes; j++) boxes[j] = boxes[j+1];
118 // If there is only the wallpaper left signal command
121 Message* m = new Message();
122 m->to = Command::getInstance();
123 m->message = Message::LAST_VIEW_CLOSE;
124 Command::getInstance()->postMessageNoLock(m);
130 /////////////////////////////////////////////////////////////////////////////
132 /////////////////////////////////////////////////////////////////////////////
134 void BoxStack::deleteBox(int z)
136 // Log::getInstance()->log("BoxStack", Log::DEBUG, "Delete box %i of %i", z, numBoxes);
138 boxSplit(boxes[z]->area, z + 1, numBoxes, 1, rl);
141 repaintRevealed(z, rl.front());
146 void BoxStack::update(Boxx* toUpdate, Region* regionToUpdate)
148 // Log::getInstance()->log("BoxStack", Log::DEBUG, "Update called");
149 // Get the z index of the box
152 for (z = 0; z < numBoxes; z++)
154 if (boxes[z] == toUpdate) break;
159 // not a Box we have!
163 // get the region for the whole box, could be less than that
164 // for smaller updates
166 Region r = toUpdate->area;
170 // Can be null if the whole box should be updated
171 // If this is given the numbers are relative to the size of the box, not the screen
173 r.x += regionToUpdate->x;
174 r.y += regionToUpdate->y;
175 r.w = regionToUpdate->w;
176 r.h = regionToUpdate->h;
182 boxSplit(r, z+1, numBoxes, 1, rl);
192 void BoxStack::repaintRevealed(int x, Region r)
195 boxSplit(r, x - 1, -1, -1, rl);
201 boxes[r2.z]->blt(r2);
206 void BoxStack::boxSplit(Region r, int start, int end, int direction, RegionList& rl)
208 // 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);
210 for(int z = start; z != end; z += direction)
212 if (r.overlappedBy(boxes[z]->area))
214 // printf("Z=%i S=%i E=%i D=%i: %i overlaps\n", z, start, end, direction, z);
219 if (boxes[z]->area.y > r.y)
221 // 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, boxes[z]->area.x, boxes[z]->area.y, boxes[z]->area.w, boxes[z]->area.h);
222 top = boxes[z]->area.y;
227 newR.h = boxes[z]->area.y - r.y;
228 boxSplit(newR, z + direction, end, direction, rl);
234 newR2.y = boxes[z]->area.y;
236 newR2.h = r.h - newR.h;
237 boxSplit(newR2, z, end, -1, rl);
242 if (boxes[z]->area.y2() < r.y2())
244 // 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, boxes[z]->area.x, boxes[z]->area.y, boxes[z]->area.w, boxes[z]->area.h);
245 btm = boxes[z]->area.y2();
248 newR.y = boxes[z]->area.y2() + 1;
250 newR.h = r.y2() - newR.y + 1;
251 boxSplit(newR, z + direction, end, direction, rl);
259 newR2.h = r.h - newR.h;
260 boxSplit(newR2, z, end, -1, rl);
265 if (boxes[z]->area.x > r.x)
267 // 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, boxes[z]->area.x, boxes[z]->area.y, boxes[z]->area.w, boxes[z]->area.h);
271 newR.w = boxes[z]->area.x - r.x;
272 newR.h = btm - top + 1;
273 boxSplit(newR, z + direction, end, direction, rl);
278 newR2.x = r.x + newR.w;
280 newR2.w = r.w - newR.w;
282 boxSplit(newR2, z, end, -1, rl);
287 if (boxes[z]->area.x2() < r.x2())
289 // 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, boxes[z]->area.x, boxes[z]->area.y, boxes[z]->area.w, boxes[z]->area.h);
291 newR.x = boxes[z]->area.x2() + 1;
293 newR.w = r.x2() - newR.x + 1;
294 newR.h = btm - top + 1;
295 boxSplit(newR, z + direction, end, direction, rl);
302 newR2.w = r.w - newR.w;
304 boxSplit(newR2, z, end, -1, rl);
311 // we are going down the stack
312 // r is underlapped by boxes[z]
313 // but we have not split
314 // Therefore this region under test is
315 // completely covering boxes[z]
317 // don't go any further down, generate a region and quit
319 // printf("Repaint region: %i %i %i %i\n", r.x, r.y, r.w, r.h);
324 // printf("Returning from Z=%i\n", z);
329 // printf("Z=%i S=%i E=%i D=%i: %i does not overlap\n", z, start, end, direction, z);
333 // if direction = 1 then we have come to a region that is
334 // entirely clear of higher boxes and needs to be redrawn
336 // if direction = -1 then we have come to a region that is on
337 // the very bottom with nothing below it to repaint.
338 // do nothing. stale window data will be left on screen?
346 /////////////////////////////////////////////////////////////////////////////
348 /////////////////////////////////////////////////////////////////////////////
350 // ---------------------------------------------------- END OF REMOVE CODE
353 void BoxStack::removeAll()
355 // 1.. Don't delete wallpaper. No point.
356 for (; numBoxes > 1; --numBoxes)
358 delete boxes[numBoxes-1];
362 int BoxStack::handleCommand(int command)
368 if (command != Remote::NA_NONE)
370 // handle command return values
371 // 0 - drop through to next box
372 // 1 - dont drop to next box, but not handled
373 // 2 - handled - stop command here
374 // 4 - handled - delete this box
376 for (i=numBoxes-1; i>=0; i--)
378 // Log::getInstance()->log("BoxStack", Log::DEBUG, "Giving command to i=%i", i);
379 retVal = boxes[i]->handleCommand(command);
382 // not handled but don't give to any more boxes
392 else if (retVal == 4)
394 // Log::getInstance()->log("BoxStack", Log::DEBUG, "Return 4: i=%i, boxes[i]=%p", i, boxes[i]);
403 // fake the return code
410 void BoxStack::processMessage(Message* m)
414 for (int i = numBoxes-1; i >= 0; i--)
416 if (boxes[i] == m->to)
418 Log::getInstance()->log("BoxStack", Log::DEBUG, "sending message from box %p to box %p %lu", m->from, m->to, m->message);
419 boxes[i]->processMessage(m);
426 /* Handle mouse events*/
427 // They come in with m->to = NULL? and just need to be delivered to top box?
428 if ((numBoxes > 1) && ((m->message == Message::MOUSE_MOVE) || (m->message == Message::MOUSE_LBDOWN)))
430 boxes[numBoxes-1]->processMessage(m);
434 Log::getInstance()->log("BoxStack", Log::DEBUG, "it's for meeee!");
438 case Message::CLOSE_ME:
440 remove((Boxx*)m->from);
443 case Message::ADD_VIEW: // currently not used by anything but it might come in useful again
445 Boxx* toAdd = (Boxx*)m->parameter;
451 case Message::REDRAW:
453 Boxx* toRedraw = (Boxx*)m->from;
454 Region* toRedrawRegion = (Region*)m->parameter;
455 update(toRedraw, toRedrawRegion);