changeset 772:c1104104babf

Added lout/msg.h and normalized debug messages to use it.
author Jorge Arellano Cid <jcid@dillo.org>
date Fri, 16 Jan 2009 10:37:30 -0300
parents b49d97d4b439
children c1dd6bdfffe0
files ChangeLog dw/fltkimgbuf.cc dw/fltkplatform.cc dw/fltkui.cc dw/fltkviewbase.cc dw/fltkviewport.cc dw/image.cc dw/layout.cc dw/style.cc dw/table.cc dw/textblock.cc dw/types.cc dw/widget.cc lout/Makefile.am lout/msg.h
diffstat 15 files changed, 255 insertions(+), 236 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jan 15 22:26:48 2009 +0100
+++ b/ChangeLog	Fri Jan 16 10:37:30 2009 -0300
@@ -59,6 +59,8 @@
    Patch: place (AKA corvid)
 +- Cleaned up unused code in fltkviewbase.
    Patch: Johannes Hofmann
++- Added lout/msg.h and normalized debug messages to use it.
+   Patch: Jorge Arellano Cid
 
 -----------------------------------------------------------------------------
 
--- a/dw/fltkimgbuf.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/fltkimgbuf.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -21,6 +21,7 @@
 
 
 #include "fltkcore.hh"
+#include "../lout/msg.h"
 #include "../lout/misc.hh"
 
 #include <fltk/draw.h>
@@ -35,13 +36,13 @@
 
 FltkImgbuf::FltkImgbuf (Type type, int width, int height)
 {
-   //printf("FltkImgbuf: new root %p\n", this);
+   _MSG("FltkImgbuf: new root %p\n", this);
    init (type, width, height, NULL);
 }
 
 FltkImgbuf::FltkImgbuf (Type type, int width, int height, FltkImgbuf *root)
 {
-   //printf("FltkImgbuf: new scaled %p, root is %p\n", this, root);
+   _MSG("FltkImgbuf: new scaled %p, root is %p\n", this, root);
    init (type, width, height, root);
 }
 
@@ -58,8 +59,7 @@
       case RGB:  bpp = 3; break;
       default:   bpp = 1; break;
    }
-   //fprintf(stderr,"FltkImgbuf::init width=%d height=%d bpp=%d\n",
-   //        width, height, bpp);
+   _MSG("FltkImgbuf::init width=%d height=%d bpp=%d\n", width, height, bpp);
    rawdata = new uchar[bpp * width * height];
    // Set light-gray as interim background color.
    memset(rawdata, 222, width*height*bpp);
@@ -85,7 +85,7 @@
 
 FltkImgbuf::~FltkImgbuf ()
 {
-   //printf("~FltkImgbuf[%s %p] deleted\n", isRoot() ? "root":"scaled", this);
+   _MSG("~FltkImgbuf[%s %p] deleted\n", isRoot() ? "root":"scaled", this);
 
    if (!isRoot())
       root->detachScaledBuf (this);
@@ -105,8 +105,8 @@
 {
    scaledBuffers->detachRef (scaledBuf);
 
-   //printf("FltkImgbuf[root %p]: scaled buffer %p is detached, %d left\n",
-   //       this, scaledBuf, scaledBuffers->size ());
+   _MSG("FltkImgbuf[root %p]: scaled buffer %p is detached, %d left\n",
+        this, scaledBuf, scaledBuffers->size ());
 
    if (refCount == 0 && scaledBuffers->isEmpty () && deleteOnUnref)
       // If the root buffer is not used anymore, but this is the last scaled
@@ -202,8 +202,8 @@
       area->y = row;
       area->width = width;
       area->height = 1;
-      //fprintf(stderr,"::getRowArea: area x=%d y=%d width=%d height=%d\n",
-      //        area->x, area->y, area->width, area->height);
+      _MSG("::getRowArea: area x=%d y=%d width=%d height=%d\n",
+           area->x, area->y, area->width, area->height);
    } else {
       // scaled buffer
       int sr1 = scaledY (row);
@@ -213,8 +213,8 @@
       area->y = sr1;
       area->width = width;
       area->height = sr2 - sr1;
-      //fprintf(stderr,"::getRowArea: area x=%d y=%d width=%d height=%d\n",
-      //        area->x, area->y, area->width, area->height);
+      _MSG("::getRowArea: area x=%d y=%d width=%d height=%d\n",
+           area->x, area->y, area->width, area->height);
    }
 }
 
@@ -233,19 +233,19 @@
    refCount++;
 
    //if (root)
-   //   printf("FltkImgbuf[scaled %p, root is %p]: ref() => %d\n",
-   //          this, root, refCount);
+   //   MSG("FltkImgbuf[scaled %p, root is %p]: ref() => %d\n",
+   //        this, root, refCount);
    //else
-   //   printf("FltkImgbuf[root %p]: ref() => %d\n", this, refCount);
+   //   MSG("FltkImgbuf[root %p]: ref() => %d\n", this, refCount);
 }
 
 void FltkImgbuf::unref ()
 {
    //if (root)
-   //   printf("FltkImgbuf[scaled %p, root is %p]: ref() => %d\n",
-   //          this, root, refCount - 1);
+   //   MSG("FltkImgbuf[scaled %p, root is %p]: ref() => %d\n",
+   //       this, root, refCount - 1);
    //else
-   //   printf("FltkImgbuf[root %p]: ref() => %d\n", this, refCount - 1);
+   //   MSG("FltkImgbuf[root %p]: ref() => %d\n", this, refCount - 1);
 
    if (--refCount == 0) {
       if (isRoot ()) {
@@ -253,9 +253,10 @@
          // See also FltkImgbuf::detachScaledBuf().
          if (scaledBuffers->isEmpty () && deleteOnUnref) {
             delete this;
-         } else
-            printf("FltkImgbuf[root %p]: not deleted. numScaled=%d\n",
-                   this, scaledBuffers->size ());
+         } else {
+            _MSG("FltkImgbuf[root %p]: not deleted. numScaled=%d\n",
+                 this, scaledBuffers->size ());
+         }
       } else
          // Scaled buffer buffer, simply delete it.
          delete this;
@@ -291,27 +292,13 @@
 void FltkImgbuf::draw (::fltk::Widget *target, int xRoot, int yRoot,
                        int x, int y, int width, int height)
 {
-   // TODO (i):  Implementation.
-   // TODO (ii): Clarify the question, whether "target" is the current widget
-   //            (and so has not to be passed at all).
-
-/*
-   setcolor (0);
+   // TODO: Clarify the question, whether "target" is the current widget
+   //       (and so has not to be passed at all).
 
-   for (int row = y; row < y + height; row++) {
-      if (copiedRows->get (row)) {
-         ::fltk::Rectangle rect (x + xRoot, row + yRoot, width, 1);
-         fillrect (rect);
-      }
-   }
-*/
+   _MSG("::draw: xRoot=%d x=%d yRoot=%d y=%d width=%d height=%d\n"
+        "        this->width=%d this->height=%d\n",
+        xRoot, x, yRoot, y, width, height, this->width, this->height);
 
-   //fprintf(stderr,"::draw: xRoot=%d x=%d yRoot=%d y=%d width=%d height=%d\n"
-   //        "        this->width=%d this->height=%d\n",
-   //        xRoot, x, yRoot, y, width, height, this->width, this->height);
-
-//{
-#if 1
    if (x > this->width || y > this->height) {
       return;
    }
@@ -324,19 +311,10 @@
       height = this->height - y;
    }
 
-   // almost OK for rows. For some unknown reason it trims the bottom and 
-   // rightmost parts when scrolling.
+   // Draw 
    ::fltk::Rectangle rect (xRoot + x, yRoot + y, width, height);
    PixelType ptype = (type == RGBA) ? ::fltk::RGBA : ::fltk::RGB;
    drawimage(rawdata+bpp*(y*this->width + x),ptype,rect,bpp*this->width);
-
-#else
-   // OK for full image.
-   ::fltk::Rectangle rect (xRoot, yRoot, this->width, this->height);
-   PixelType ptype = (type == RGBA) ? ::fltk::RGBA : ::fltk::RGB;
-   drawimage(rawdata,ptype,rect);
-#endif
-//}
 }
 
 } // namespace dw
--- a/dw/fltkplatform.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/fltkplatform.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -55,7 +55,6 @@
 
    font = ::fltk::font(name, fa);
    if(font == NULL) {
-      //fprintf(stderr, "No font '%s', using default sans-serif font.\n",name);
       /*
        * If using xft, fltk::HELVETICA just means sans, fltk::COURIER
        * means mono, and fltk::TIMES means serif.
--- a/dw/fltkui.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/fltkui.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -23,6 +23,7 @@
 #include "fltkcore.hh"
 #include "fltkflatview.hh"
 #include "fltkcomplexbutton.hh"
+#include "../lout/msg.h"
 #include "../lout/misc.hh"
 
 #include <stdio.h>
@@ -120,7 +121,7 @@
       }
    }
 
-   fprintf (stderr, "FltkResource::detachView: View not found.");
+   MSG_WARN("FltkResource::detachView: View not found.");
 }
 
 void FltkResource::sizeAllocate (core::Allocation *allocation)
@@ -444,9 +445,8 @@
       }
    }
 
-   fprintf (stderr,
-            "FltkComplexButtonResourceResource::detachView: View not "
-            "found.\n");
+   MSG_WARN("FltkComplexButtonResourceResource::detachView: "
+            "View not found.\n");
 }
 
 void FltkComplexButtonResource::sizeAllocate (core::Allocation *allocation)
@@ -597,7 +597,7 @@
     * The Back or Forward, buttons, or the first click on a rendered
     * page. BUG: this must be investigated and reported to FLTK2 team
     */
-   printf ("when = %d\n", widget->when ());
+   MSG("when = %d\n", widget->when ());
    if ((widget->when () & ::fltk::WHEN_ENTER_KEY_ALWAYS) &&
        (::fltk::event_key() == ::fltk::ReturnKey))
       ((FltkEntryResource*)data)->emitActivate ();
@@ -648,11 +648,11 @@
 
    // Check values. Upper bound check is left to the caller.
    if (numCols < 1) {
-      fprintf (stderr, "WARNING: numCols = %d is set to 1.\n", numCols);
+      MSG_WARN("numCols = %d is set to 1.\n", numCols);
       numCols = 1;
    }
    if (numRows < 1) {
-      fprintf (stderr, "WARNING: numRows = %d is set to 1.\n", numRows);
+      MSG_WARN("numRows = %d is set to 1.\n", numRows);
       numRows = 1;
    }
 
--- a/dw/fltkviewbase.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/fltkviewbase.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -30,6 +30,7 @@
 #include <fltk/run.h>
 
 #include <stdio.h>
+#include "../lout/msg.h"
 
 using namespace fltk;
 using namespace lout::object;
@@ -203,7 +204,7 @@
                                  translateViewXToCanvasX (event_x ()),
                                  translateViewYToCanvasY (event_y ()),
                                  getDwButtonState (), event_button ());
-      //printf ("PUSH => %s\n", processed ? "true" : "false");
+      _MSG("PUSH => %s\n", processed ? "true" : "false");
       if (processed) {
          /* pressed dw content; give focus to the view */
          ::fltk::focus(this);
@@ -216,7 +217,7 @@
                                    translateViewXToCanvasX (event_x ()),
                                    translateViewYToCanvasY (event_y ()),
                                    getDwButtonState (), event_button ());
-      //printf ("RELEASE => %s\n", processed ? "true" : "false");
+      _MSG("RELEASE => %s\n", processed ? "true" : "false");
       return processed ? true : Group::handle (event);
 
    case MOVE:
@@ -227,7 +228,7 @@
                                   translateViewXToCanvasX (mouse_x),
                                   translateViewYToCanvasY (mouse_y),
                                   getDwButtonState ());
-      //printf ("MOVE => %s\n", processed ? "true" : "false");
+      _MSG("MOVE => %s\n", processed ? "true" : "false");
       return processed ? true : Group::handle (event);
 
    case DRAG:
@@ -236,7 +237,7 @@
                                   translateViewXToCanvasX (event_x ()),
                                   translateViewYToCanvasY (event_y ()),
                                   getDwButtonState ());
-      //printf ("DRAG => %s\n", processed ? "true" : "false");
+      _MSG("DRAG => %s\n", processed ? "true" : "false");
       return processed ? true : Group::handle (event);
 
    case ENTER:
@@ -306,7 +307,7 @@
       "CURSOR_HELP"
    };
 
-   printf ("Cursor changes to '%s'.\n", cursorName[cursor]);
+   MSG("Cursor changes to '%s'.\n", cursorName[cursor]);
    */
 
    /** \bug Does not work */
--- a/dw/fltkviewport.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/fltkviewport.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -27,6 +27,7 @@
 #include <fltk/events.h>
 
 #include <stdio.h>
+#include "../lout/msg.h"
 
 using namespace fltk;
 using namespace lout::object;
@@ -211,7 +212,7 @@
 
 int FltkViewport::handle (int event)
 {
-   //printf("FltkViewport::handle %d\n", event);
+   _MSG("FltkViewport::handle %d\n", event);
 
    if (hscrollbar->Rectangle::contains (event_x (), event_y ()) &&
        !(event_state() & (SHIFT | CTRL | ALT)) &&
--- a/dw/image.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/image.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -21,6 +21,7 @@
 
 
 #include "image.hh"
+#include "../lout/msg.h"
 #include "../lout/misc.hh"
 
 namespace dw {
@@ -197,15 +198,15 @@
    dx = getStyle()->boxDiffWidth ();
    dy = getStyle()->boxDiffHeight ();
 #if 0
-   printf("boxDiffHeight = %d + %d, buffer=%p\n",
-          getStyle()->boxOffsetY(), getStyle()->boxRestHeight(), buffer);
-   printf("getContentWidth() = allocation.width - style->boxDiffWidth ()"
-          " = %d - %d = %d\n",
-          this->allocation.width, getStyle()->boxDiffWidth(),
-          this->allocation.width - getStyle()->boxDiffWidth());
-   printf("getContentHeight() = getHeight() - style->boxDiffHeight ()"
-          " = %d - %d = %d\n", this->getHeight(), getStyle()->boxDiffHeight(),
-          this->getHeight() - getStyle()->boxDiffHeight());
+   MSG("boxDiffHeight = %d + %d, buffer=%p\n",
+       getStyle()->boxOffsetY(), getStyle()->boxRestHeight(), buffer);
+   MSG("getContentWidth() = allocation.width - style->boxDiffWidth ()"
+       " = %d - %d = %d\n",
+       this->allocation.width, getStyle()->boxDiffWidth(),
+       this->allocation.width - getStyle()->boxDiffWidth());
+   MSG("getContentHeight() = getHeight() - style->boxDiffHeight ()"
+       " = %d - %d = %d\n", this->getHeight(), getStyle()->boxDiffHeight(),
+       this->getHeight() - getStyle()->boxDiffHeight());
 #endif
    if (buffer && (getContentWidth () > 0 || getContentHeight () > 0)) {
       // Zero content size : simply wait...
--- a/dw/layout.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/layout.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -22,6 +22,7 @@
 
 #include "core.hh"
 
+#include "../lout/msg.h"
 #include "../lout/debug.hh"
 #include "../lout/misc.hh"
 
@@ -128,7 +129,7 @@
 void Layout::addWidget (Widget *widget)
 {
    if (topLevel) {
-      fprintf (stderr, "widget already set\n");
+      MSG_WARN("widget already set\n");
       return;
    }
 
@@ -261,8 +262,8 @@
                         bool scrollingInterrupted)
 {
    if (usesViewport) {
-      //printf ("scrollTo (%d, %d, %s)\n",
-      //        x, y, scrollingInterrupted ? "true" : "false");
+      _MSG("scrollTo (%d, %d, %s)\n",
+           x, y, scrollingInterrupted ? "true" : "false");
 
       scrollTargetHpos = hpos;
       scrollTargetVpos = vpos;
@@ -353,7 +354,7 @@
       canvasAscent + canvasDescent - (viewportHeight - hScrollbarThickness));
    scrollY = misc::max (scrollY, 0);
 
- //printf("adjustScrollPos: scrollX=%d scrollY=%d\n", scrollX, scrollY);
+   _MSG("adjustScrollPos: scrollX=%d scrollY=%d\n", scrollX, scrollY);
 }
 
 bool Layout::calcScrollInto (int requestedValue, int requestedSize,
@@ -413,7 +414,7 @@
  */
 void Layout::setAnchor (const char *anchor)
 {
-   //printf ("setAnchor (%s)\n", anchor);
+   _MSG("setAnchor (%s)\n", anchor);
 
    if (requestedAnchor)
       delete requestedAnchor;
@@ -523,7 +524,7 @@
 void Layout::resizeIdle ()
 {
    //static int calls = 0;
-   //printf(" Layout::resizeIdle calls = %d\n", ++calls);
+   //MSG(" Layout::resizeIdle calls = %d\n", ++calls);
 
    while (resizeIdleId != -1) {
       // Reset already here, since in this function, queueResize() may be
@@ -739,8 +740,8 @@
  */
 Widget *Layout::getWidgetAtPoint (int x, int y)
 {
-   //_MSG ("------------------------------------------------------------\n");
-   //_MSG ("widget at (%d, %d)\n", x, y);
+   _MSG ("------------------------------------------------------------\n");
+   _MSG ("widget at (%d, %d)\n", x, y);
    if (topLevel)
       return topLevel->getWidgetAtPoint (x, y, 0);
    else
@@ -879,8 +880,8 @@
  */
 void Layout::viewportSizeChanged (View *view, int width, int height)
 {
-   //printf("Layout::viewportSizeChanged w=%d h=%d new_w=%d new_h=%d\n",
-   //       viewportWidth, viewportHeight, width, height);
+   _MSG("Layout::viewportSizeChanged w=%d h=%d new_w=%d new_h=%d\n",
+        viewportWidth, viewportHeight, width, height);
 
    /* If the width has become higher, we test again, whether the vertical
     * scrollbar (so to speak) can be hidden again. */
--- a/dw/style.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/style.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -26,6 +26,7 @@
 #include <ctype.h>
 
 #include "core.hh"
+#include "../lout/msg.h"
 
 namespace dw {
 namespace core {
@@ -324,7 +325,7 @@
    }
 
    if (font == NULL)
-      fprintf (stderr, "Could not find any font.\n");
+      MSG_WARN("Could not find any font.\n");
 
    return font;
 }
@@ -450,11 +451,10 @@
             points[3][1] = y1 + width;
          }
 
-         /*
-         printf ("drawPolygon: (%d, %d) .. (%d, %d) .. (%d, %d) .. (%d, %d)\n",
-                 points[0][0], points[0][1], points[1][0], points[1][1],
-                 points[2][0], points[2][1], points[3][0], points[3][1]);
-         */
+         _MSG("drawPolygon: (%d, %d) .. (%d, %d) .. (%d, %d) .. (%d, %d)\n",
+              points[0][0], points[0][1], points[1][0], points[1][1],
+              points[2][0], points[2][1], points[3][0], points[3][1]);
+
          view->drawPolygon (color, shading, true, points, 4);
       }
    }
--- a/dw/table.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/table.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -21,6 +21,7 @@
 //#define DBG
 
 #include "table.hh"
+#include "../lout/msg.h"
 #include "../lout/misc.hh"
 
 #define MAX misc::max
@@ -141,10 +142,8 @@
               core::style::absLengthVal(getStyle()->width));
    }
 
-#ifdef DBG
-   printf(" Table::getExtremesImpl, {%d, %d} numCols=%d\n",
-          extremes->minWidth, extremes->maxWidth, numCols);
-#endif
+   _MSG(" Table::getExtremesImpl, {%d, %d} numCols=%d\n",
+       extremes->minWidth, extremes->maxWidth, numCols);
 }
 
 void Table::sizeAllocateImpl (core::Allocation *allocation)
@@ -203,9 +202,7 @@
 {  
    // If limitTextWidth is set, a queueResize may also be necessary.
    if (availWidth != width || limitTextWidth) {
-#ifdef DBG
-      printf(" Table::setWidth %d\n", width);
-#endif
+      _MSG(" Table::setWidth %d\n", width);
       availWidth = width;
       queueResize (0, false);
    }
@@ -277,22 +274,22 @@
    // We limit the values for colspan and rowspan to 50, to avoid
    // attacks by malicious web pages.
    if (colspan > 50 || colspan < 0) {
-      fprintf (stderr, "WARNING: colspan = %d is set to 50.\n", colspan);
+      MSG_WARN("colspan = %d is set to 50.\n", colspan);
       colspan = 50;
    }
    if (rowspan > 50 || rowspan <= 0) {
-      fprintf (stderr, "WARNING: rowspan = %d is set to 50.\n", rowspan);
+      MSG_WARN("rowspan = %d is set to 50.\n", rowspan);
       rowspan = 50;
    }
 
    if (numRows == 0) {
       // to prevent a crash
-      fprintf (stderr, "WARNING: Cell without row.\n");
+      MSG_WARN("Cell without row.\n");
       addRow (NULL);
    }
 
    if (rowClosed) {
-      fprintf (stderr, "WARNING: Last cell had colspan=0.\n");
+      MSG_WARN("Last cell had colspan=0.\n");
       addRow (NULL);
    }
 
@@ -308,10 +305,9 @@
           child->type == Child::SPAN_SPACE)
       curCol++;
 
-#ifdef DBG
-   printf("Table::addCell numCols=%d,curCol=%d,colspan=%d,colspanEff=%d\n",
-          numCols, curCol, colspan, colspanEff);
-#endif
+   _MSG("Table::addCell numCols=%d,curCol=%d,colspan=%d,colspanEff=%d\n",
+       numCols, curCol, colspan, colspanEff);
+
    // Increase children array, when necessary.
    if (curRow + rowspan > numRows)
       reallocChildren (numCols, curRow + rowspan);
@@ -351,18 +347,18 @@
       for (int col = 0; col < numCols; col++) {
          int n = row * numCols + col;
          if (!(child = children->get (n))) {
-            printf("[null     ] ");
+            MSG("[null     ] ");
          } else if (children->get(n)->type == Child::CELL) {
-            printf("[CELL rs=%d] ", child->cell.rowspan);
+            MSG("[CELL rs=%d] ", child->cell.rowspan);
          } else if (children->get(n)->type == Child::SPAN_SPACE) {
-            printf("[SPAN rs=%d] ", child->cell.rowspan);
+            MSG("[SPAN rs=%d] ", child->cell.rowspan);
          } else {
-            printf("[Unk.     ] ");
+            MSG("[Unk.     ] ");
          }
       }
-      printf("\n");
+      MSG("\n");
    }
-   printf("\n");
+   MSG("\n");
 #endif
 }
 
@@ -503,28 +499,28 @@
       totalWidth = availWidth;
       forceTotalWidth = 0;
    }
-#ifdef DBG
-   printf(" availWidth = %d\n", availWidth);
-   printf(" totalWidth1 = %d\n", totalWidth);
-#endif
+
+   _MSG(" availWidth = %d\n", availWidth);
+   _MSG(" totalWidth1 = %d\n", totalWidth);
+
    if (totalWidth < extremes.minWidth)
       totalWidth = extremes.minWidth;
    totalWidth = totalWidth
                 - (numCols + 1) * getStyle()->hBorderSpacing
                 - getStyle()->boxDiffWidth ();
-#ifdef DBG
-   printf(" totalWidth2 = %d curCol=%d\n", totalWidth,curCol);
-#endif
+
+   _MSG(" totalWidth2 = %d curCol=%d\n", totalWidth,curCol);
+
 
    colWidths->setSize (numCols, 0);
    cumHeight->setSize (numRows + 1, 0);
    rowSpanCells->setSize (0);
    baseline->setSize (numRows);
-#ifdef DBG
-   printf(" extremes = %d,%d\n", extremes.minWidth, extremes.maxWidth);
-   printf(" getStyle()->boxDiffWidth() = %d\n", getStyle()->boxDiffWidth());
-   printf(" getStyle()->hBorderSpacing = %d\n", getStyle()->hBorderSpacing);
-#endif
+
+   _MSG(" extremes = %d,%d\n", extremes.minWidth, extremes.maxWidth);
+   _MSG(" getStyle()->boxDiffWidth() = %d\n", getStyle()->boxDiffWidth());
+   _MSG(" getStyle()->hBorderSpacing = %d\n", getStyle()->hBorderSpacing);
+
 
    apportion_percentages2 (totalWidth, forceTotalWidth);
    if (!hasColPercent)
@@ -583,10 +579,9 @@
          continue;
 
       // Cell size is too small.
-#ifdef DBG
-      printf("Short cell %d, sumRows=%d spanHeight=%d\n",
-             n,sumRows,spanHeight);
-#endif
+      _MSG("Short cell %d, sumRows=%d spanHeight=%d\n",
+          n,sumRows,spanHeight);
+
       // Fill height array
       if (!rowHeight) {
          rowHeight = new int[numRows];
@@ -594,10 +589,10 @@
             rowHeight[i] = cumHeight->get(i+1) - cumHeight->get(i);
       }
 #ifdef DBG
-      printf (" rowHeight { ");
+      MSG(" rowHeight { ");
       for (int i = 0; i < numRows; i++)
-         printf ("%d ", rowHeight[i]);
-      printf ("}\n");
+         MSG("%d ", rowHeight[i]);
+      MSG("}\n");
 #endif
 
       // Calc new row sizes for this span.
@@ -607,12 +602,12 @@
             sumRows == 0 ? (int)((float)(spanHeight-cumHnew_i)/(row+rs-i)) :
             (sumRows-cumh_i) <= 0 ? 0 :
             (int)((float)(spanHeight-cumHnew_i)*rowHeight[i]/(sumRows-cumh_i));
-#ifdef DBG
-         printf (" i=%-3d h=%d hnew_i=%d =%d*%d/%d   cumh_i=%d cumHnew_i=%d\n",
-                 i,rowHeight[i],hnew_i,
-                 spanHeight-cumHnew_i,rowHeight[i],sumRows-cumh_i,
-                 cumh_i, cumHnew_i);
-#endif
+
+         _MSG(" i=%-3d h=%d hnew_i=%d =%d*%d/%d   cumh_i=%d cumHnew_i=%d\n",
+             i,rowHeight[i],hnew_i,
+             spanHeight-cumHnew_i,rowHeight[i],sumRows-cumh_i,
+             cumh_i, cumHnew_i);
+
          cumHnew_i += hnew_i;
          cumh_i += rowHeight[i];
          rowHeight[i] = hnew_i;
@@ -642,9 +637,8 @@
  */
 void Table::forceCalcColumnExtremes ()
 {
-#ifdef DBG
-   printf("  Table::forceCalcColumnExtremes  numCols=%d\n", numCols);
-#endif
+   _MSG("  Table::forceCalcColumnExtremes  numCols=%d\n", numCols);
+
    if (numCols == 0)
       return;
 
@@ -678,13 +672,13 @@
                cellMinW = cellExtremes.minWidth;
                cellMaxW = cellExtremes.maxWidth;
             }
-#ifdef DBG
-            printf("FCCE, col%d colMin,colMax,cellMin,cellMax = %d,%d,%d,%d\n",
-                   col,
-                   colExtremes->getRef(col)->minWidth,
-                   colExtremes->getRef(col)->maxWidth,
-                   cellMinW, cellMaxW);
-#endif
+
+            _MSG("FCCE, col%d colMin,colMax,cellMin,cellMax = %d,%d,%d,%d\n",
+                col,
+                colExtremes->getRef(col)->minWidth,
+                colExtremes->getRef(col)->maxWidth,
+                cellMinW, cellMaxW);
+
             colExtremes->getRef(col)->minWidth =
                MAX (colExtremes->getRef(col)->minWidth, cellMinW);
             colExtremes->getRef(col)->maxWidth =
@@ -737,10 +731,10 @@
          minSumCols += colExtremes->getRef(col+i)->minWidth;
          maxSumCols += colExtremes->getRef(col+i)->maxWidth;
       }
-#ifdef DBG
-      printf("cs=%d spanWidth=%d,%d sumCols=%d,%d\n",
-              cs,cellMinW,cellMaxW,minSumCols,maxSumCols);
-#endif
+
+      _MSG("cs=%d spanWidth=%d,%d sumCols=%d,%d\n",
+          cs,cellMinW,cellMaxW,minSumCols,maxSumCols);
+
       if (minSumCols >= cellMinW && maxSumCols >= cellMaxW)
          continue;
 
@@ -785,7 +779,7 @@
             int d_a = colExtremes->getRef(i)->maxWidth;
             int d_w = curAppW > 0 ? (int)((float)curExtraW * d_a/curAppW) : 0;
             if (d_a < 0||d_w < 0) {
-               printf("d_a=%d d_w=%d\n",d_a,d_w);
+               MSG("d_a=%d d_w=%d\n",d_a,d_w);
                exit(1);
             }
             wMin = colExtremes->getRef(i)->minWidth + d_w;
@@ -809,19 +803,19 @@
          cumMaxWnew += wMax;
          cumMaxWold += colExtremes->getRef(i)->maxWidth;
          colExtremes->getRef(i)->maxWidth = wMax;
-#ifdef DBG
-         printf ("i=%d, wMin=%d wMax=%d cumMaxWold=%d\n",
-                  i,wMin,wMax,cumMaxWold);
-#endif
+
+         _MSG("i=%d, wMin=%d wMax=%d cumMaxWold=%d\n",
+             i,wMin,wMax,cumMaxWold);
+
       }
 #ifdef DBG
-      printf ("col min,max: [");
+      MSG("col min,max: [");
       for (int i = 0; i < numCols; i++)
-         printf ("%d,%d ", 
-                 colExtremes->getRef(i)->minWidth,
-                 colExtremes->getRef(i)->maxWidth);
-      printf ("]\n");
-      printf ("getStyle()->hBorderSpacing = %d\n", getStyle()->hBorderSpacing);
+         MSG("%d,%d ",
+             colExtremes->getRef(i)->minWidth,
+             colExtremes->getRef(i)->maxWidth);
+      MSG("]\n");
+      MSG("getStyle()->hBorderSpacing = %d\n", getStyle()->hBorderSpacing);
 #endif
    }
 }
@@ -835,13 +829,13 @@
    if (colExtremes->size() == 0)
       return;
 #ifdef DBG
-   printf("app2, availWidth=%d, totalWidth=%d, forceTotalWidth=%d\n",
-          availWidth, totalWidth, forceTotalWidth);
-   printf("app2, extremes: ( ");
+   MSG("app2, availWidth=%d, totalWidth=%d, forceTotalWidth=%d\n",
+       availWidth, totalWidth, forceTotalWidth);
+   MSG("app2, extremes: ( ");
    for (int i = 0; i < colExtremes->size (); i++)
-      printf("%d,%d ",
-             colExtremes->get(i).minWidth, colExtremes->get(i).maxWidth);
-   printf(")\n");
+      MSG("%d,%d ",
+          colExtremes->get(i).minWidth, colExtremes->get(i).maxWidth);
+   MSG(")\n");
 #endif
    int minAutoWidth = 0, maxAutoWidth = 0, availAutoWidth = totalWidth;
    for (int col = 0; col < numCols; col++) {
@@ -871,10 +865,9 @@
    int curMaxWidth = maxAutoWidth;
    int curNewWidth = minAutoWidth;
    for (int col = 0; col < numCols; col++) {
-#ifdef DBG
-      printf("app2, col %d, minWidth=%d maxWidth=%d\n",
-             col,extremes->get(col).minWidth, colExtremes->get(col).maxWidth);
-#endif
+      _MSG("app2, col %d, minWidth=%d maxWidth=%d\n",
+          col,extremes->get(col).minWidth, colExtremes->get(col).maxWidth);
+
       if (colPercents->get(col) != LEN_AUTO)
          continue;
 
@@ -882,19 +875,19 @@
       int colMaxWidth = colExtremes->getRef(col)->maxWidth;
       int w = (curMaxWidth <= 0) ? 0 :
                  (int)((float)curTargetWidth * colMaxWidth/curMaxWidth);
-#ifdef DBG
-      printf("app2, curTargetWidth=%d colMaxWidth=%d curMaxWidth=%d "
-             "curNewWidth=%d  ",
-             curTargetWidth, colMaxWidth,curMaxWidth,curNewWidth);
-      printf("w = %d, ", w);
-#endif
+
+      _MSG("app2, curTargetWidth=%d colMaxWidth=%d curMaxWidth=%d "
+          "curNewWidth=%d  ",
+          curTargetWidth, colMaxWidth,curMaxWidth,curNewWidth);
+      _MSG("w = %d, ", w);
+
       if (w <= colMinWidth)
          w = colMinWidth;
       else if (curNewWidth - colMinWidth + w > curTargetWidth)
          w = colMinWidth + curExtraWidth;
-#ifdef DBG
-      printf("w = %d\n", w);
-#endif
+
+      _MSG("w = %d\n", w);
+
       curNewWidth -= colMinWidth;
       curMaxWidth -= colMaxWidth;
       curExtraWidth -= (w - colMinWidth);
@@ -902,10 +895,10 @@
       setColWidth (col, w);
    }
 #ifdef DBG
-   printf("app2, result: ( ");
+   MSG("app2, result: ( ");
    for (int i = 0; i < colWidths->size (); i++)
-      printf("%d ", colWidths->get (i));
-   printf(")\n");
+      MSG("%d ", colWidths->get (i));
+   MSG(")\n");
 #endif
 }
 
@@ -917,19 +910,17 @@
       return;
 
    // If there's a table-wide percentage, totalWidth comes already scaled.
-#ifdef DBG
-   printf("APP_P, availWidth=%d, totalWidth=%d, forceTotalWidth=%d\n",
-          availWidth, totalWidth, forceTotalWidth);
-#endif
+   _MSG("APP_P, availWidth=%d, totalWidth=%d, forceTotalWidth=%d\n",
+       availWidth, totalWidth, forceTotalWidth);
 
    if (!hasColPercent) {
 #ifdef DBG
-      printf("APP_P, only a table-wide percentage\n");
-      printf("APP_P, extremes = { ");
+      MSG("APP_P, only a table-wide percentage\n");
+      MSG("APP_P, extremes = { ");
       for (int col = 0; col < numCols; col++)
-         printf("%d,%d ", colExtremes->getRef(col)->minWidth,
-                          colExtremes->getRef(col)->maxWidth);
-      printf("}\n");
+         MSG("%d,%d ", colExtremes->getRef(col)->minWidth,
+                       colExtremes->getRef(col)->maxWidth);
+      MSG("}\n");
 #endif
       // It has only a table-wide percentage. Apportion non-absolute widths.
       int sumMaxWidth = 0, perAvailWidth = totalWidth;
@@ -939,10 +930,10 @@
          else
             sumMaxWidth += colExtremes->getRef(col)->maxWidth;
       }
-#ifdef DBG
-      printf("APP_P, perAvailWidth=%d, sumMaxWidth=%d\n",
-             perAvailWidth, sumMaxWidth);
-#endif
+
+      _MSG("APP_P, perAvailWidth=%d, sumMaxWidth=%d\n",
+          perAvailWidth, sumMaxWidth);
+
       for (int col = 0; col < numCols; col++) {
          int max_wi = colExtremes->getRef(col)->maxWidth, new_wi;
          if (colPercents->get(col) != LEN_ABS) {
@@ -954,17 +945,16 @@
          }
       }
 #ifdef DBG
-      printf("APP_P, result = { ");
+      MSG("APP_P, result = { ");
       for (int col = 0; col < numCols; col++)
-         printf("%d ", result->get(col));
-      printf("}\n");
+         MSG("%d ", result->get(col));
+      MSG("}\n");
 #endif
 
    } else {
       // we'll have to apportion...
-#ifdef DBG
-      printf("APP_P, we'll have to apportion...\n");
-#endif
+      _MSG("APP_P, we'll have to apportion...\n");
+
       // Calculate cumPercent and available space
       float cumPercent = 0.0f;
       int hasAutoCol = 0;
@@ -979,11 +969,10 @@
          }
          sumMinWidth += colExtremes->getRef(col)->minWidth;
          sumMaxWidth += colExtremes->getRef(col)->maxWidth;
-#ifdef DBG
-         printf("APP_P, col %d minWidth=%d maxWidth=%d\n", col,
-                colExtremes->getRef(col)->minWidth,
-                colExtremes->getRef(col)->maxWidth);
-#endif
+
+         _MSG("APP_P, col %d minWidth=%d maxWidth=%d\n", col,
+             colExtremes->getRef(col)->minWidth,
+             colExtremes->getRef(col)->maxWidth);
       }
       int oldTotalWidth = totalWidth;
       if (!forceTotalWidth) {
@@ -1011,11 +1000,11 @@
          workingWidth = totalWidth;
          curPerWidth = sumMinWidth;
       }
-#ifdef DBG
-      printf("APP_P, oldTotalWidth=%d totalWidth=%d"
-             " workingWidth=%d extraWidth=%d sumMinNonPer=%d\n",
-             oldTotalWidth,totalWidth,workingWidth,extraWidth,sumMinNonPer);
-#endif
+
+      _MSG("APP_P, oldTotalWidth=%d totalWidth=%d"
+          " workingWidth=%d extraWidth=%d sumMinNonPer=%d\n",
+          oldTotalWidth,totalWidth,workingWidth,extraWidth,sumMinNonPer);
+
       for (int col = 0; col < numCols; col++) {
          int colMinWidth = colExtremes->getRef(col)->minWidth;
          if (colPercents->get(col) >= 0.0f) {
@@ -1035,20 +1024,20 @@
       if (cumPercent < 0.99f) {
          // Will have to apportion the other columns
 #ifdef DBG
-         printf("APP_P, extremes: ( ");
+         MSG("APP_P, extremes: ( ");
          for (int i = 0; i < colExtremes->size (); i++)
-            printf("%d,%d ",
-                   colExtremes->get(i).minWidth, colExtremes->get(i).maxWidth);
-         printf(")\n");
+            MSG("%d,%d ",
+                colExtremes->get(i).minWidth, colExtremes->get(i).maxWidth);
+         MSG(")\n");
 #endif
          curPerWidth -= sumMinNonPer;
          int perWidth = (int)(curPerWidth/cumPercent);
          totalWidth = MAX (totalWidth, perWidth);
          totalWidth = misc::min (totalWidth, oldTotalWidth);
-#ifdef DBG
-         printf("APP_P, curPerWidth=%d perWidth=%d, totalWidth=%d\n",
-                curPerWidth, perWidth, totalWidth);
-#endif
+
+         _MSG("APP_P, curPerWidth=%d perWidth=%d, totalWidth=%d\n",
+             curPerWidth, perWidth, totalWidth);
+
          if (hasAutoCol == 0) {
             // Special case, cumPercent < 100% and no other columns to expand.
             // We'll honor totalWidth by expanding the percentage cols.
@@ -1062,22 +1051,22 @@
          }
       }
 #ifdef DBG
-      printf("APP_P, result ={ ");
+      MSG("APP_P, result ={ ");
       for (int col = 0; col < numCols; col++)
-         printf("%d ", colWidths->get(col));
-      printf("}\n");
+         MSG("%d ", colWidths->get(col));
+      MSG("}\n");
 #endif
       apportion2 (totalWidth, 2);
 
 #ifdef DBG
-      printf("APP_P, percent={");
+      MSG("APP_P, percent={");
       for (int col = 0; col < numCols; col++)
-         printf("%f ", colPercents->get(col));
-      printf("}\n");
-      printf("APP_P, result ={ ");
+         MSG("%f ", colPercents->get(col));
+      MSG("}\n");
+      MSG("APP_P, result ={ ");
       for (int col = 0; col < numCols; col++)
-         printf("%d ", colWidths->get(col));
-      printf("}\n");
+         MSG("%d ", colWidths->get(col));
+      MSG("}\n");
 #endif
    }
 }
--- a/dw/textblock.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/textblock.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -21,6 +21,7 @@
 
 
 #include "textblock.hh"
+#include "../lout/msg.h"
 #include "../lout/misc.hh"
 
 #include <stdio.h>
@@ -260,8 +261,8 @@
                   extremes->minWidth = wordExtremes.minWidth;
             }
 
-            //printf("parMax = %d, wordMaxWidth=%d, prevWordSpace=%d\n",
-            //       parMax, wordExtremes.maxWidth, prevWordSpace);
+            _MSG("parMax = %d, wordMaxWidth=%d, prevWordSpace=%d\n",
+                 parMax, wordExtremes.maxWidth, prevWordSpace);
             if (word->content.type != core::Content::BREAK)
                parMax += prevWordSpace;
             parMax += wordExtremes.maxWidth;
@@ -1417,7 +1418,7 @@
          break;
 
       default:
-         fprintf (stderr,  "BUG!!! at (%d, %d).\n", xWorld, yWorldBase + diff);
+         MSG_ERR("at (%d, %d).\n", xWorld, yWorldBase + diff);
          break;
       }
 
--- a/dw/types.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/types.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -21,6 +21,7 @@
 
 
 #include "core.hh"
+#include "../lout/msg.h"
 
 namespace dw {
 namespace core {
@@ -180,8 +181,8 @@
    bool cross =
       linesCross0 (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2) &&
       linesCross0 (bx1, by1, bx2, by2, ax1, ay1, ax2, ay2);
-   //printf ("(%d, %d) - (%d, %d) and (%d, %d) - (%d, %d) cross? %s.\n",
-   //        ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, cross ? "Yes" : "No");
+   _MSG("(%d, %d) - (%d, %d) and (%d, %d) - (%d, %d) cross? %s.\n",
+        ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, cross ? "Yes" : "No");
    return cross;
 }
 
--- a/dw/widget.cc	Thu Jan 15 22:26:48 2009 +0100
+++ b/dw/widget.cc	Fri Jan 16 10:37:30 2009 -0300
@@ -22,6 +22,7 @@
 
 #include "core.hh"
 
+#include "../lout/msg.h"
 #include "../lout/debug.hh"
 
 using namespace lout::object;
@@ -315,7 +316,7 @@
 {
    /** \todo Maybe only the intersection? */
    layout->queueDraw (x + allocation.x, y + allocation.y, width, height);
- //printf("Widget::queueDrawArea x=%d y=%d w=%d h=%d\n", x, y, width, height);
+   _MSG("Widget::queueDrawArea x=%d y=%d w=%d h=%d\n", x, y, width, height);
 }
 
 /**
@@ -547,7 +548,7 @@
       widget = widget->parent;
    }
 
-   fprintf (stderr, "No background color found!\n");
+   MSG_WARN("No background color found!\n");
    return NULL;
 
 }
@@ -692,7 +693,7 @@
    /* Search upwards. */
    while (widget1 != widget2) {
       if (widget1->parent == NULL) {
-         fprintf (stderr, "widgets in different trees\n");
+         MSG_WARN("widgets in different trees\n");
          return NULL;
       }
       
--- a/lout/Makefile.am	Thu Jan 15 22:26:48 2009 +0100
+++ b/lout/Makefile.am	Fri Jan 16 10:37:30 2009 -0300
@@ -11,4 +11,5 @@
 	object.cc \
 	object.hh \
 	signal.cc \
-	signal.hh
+	signal.hh \
+	msg.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lout/msg.h	Fri Jan 16 10:37:30 2009 -0300
@@ -0,0 +1,43 @@
+#ifndef __MSG_H__
+#define __MSG_H__
+
+#include <stdio.h>
+
+/*#include "prefs.h"*/
+#define prefs_show_msg    1
+
+#define D_STMT_START      do
+#define D_STMT_END        while (0)
+
+/*
+ * You can disable any MSG* macro by adding the '_' prefix.
+ */
+#define _MSG(...)
+#define _MSG_WARN(...)
+#define _MSG_HTTP(...)
+
+
+#define MSG(...)                                   \
+   D_STMT_START {                                  \
+      if (prefs_show_msg){                         \
+         printf(__VA_ARGS__);                      \
+         fflush (stdout);                          \
+      }                                            \
+   } D_STMT_END
+
+#define MSG_WARN(...)                              \
+   D_STMT_START {                                  \
+      if (prefs_show_msg)                          \
+         printf("** WARNING **: " __VA_ARGS__);    \
+   } D_STMT_END
+
+#define MSG_ERR(...)                               \
+   D_STMT_START {                                  \
+      if (prefs_show_msg)                          \
+         printf("** ERROR **: " __VA_ARGS__);      \
+   } D_STMT_END
+
+#define MSG_HTTP(...)                              \
+   printf("HTTP warning: " __VA_ARGS__)
+
+#endif /* __MSG_H__ */