diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | dw/fltkimgbuf.cc | 76 | ||||
-rw-r--r-- | dw/fltkplatform.cc | 1 | ||||
-rw-r--r-- | dw/fltkui.cc | 14 | ||||
-rw-r--r-- | dw/fltkviewbase.cc | 11 | ||||
-rw-r--r-- | dw/fltkviewport.cc | 3 | ||||
-rw-r--r-- | dw/image.cc | 19 | ||||
-rw-r--r-- | dw/layout.cc | 21 | ||||
-rw-r--r-- | dw/style.cc | 12 | ||||
-rw-r--r-- | dw/table.cc | 267 | ||||
-rw-r--r-- | dw/textblock.cc | 7 | ||||
-rw-r--r-- | dw/types.cc | 5 | ||||
-rw-r--r-- | dw/widget.cc | 7 | ||||
-rw-r--r-- | lout/Makefile.am | 3 | ||||
-rw-r--r-- | lout/msg.h | 43 |
15 files changed, 255 insertions, 236 deletions
@@ -59,6 +59,8 @@ dw 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 ----------------------------------------------------------------------------- diff --git a/dw/fltkimgbuf.cc b/dw/fltkimgbuf.cc index 571a8abd..835f6e76 100644 --- a/dw/fltkimgbuf.cc +++ b/dw/fltkimgbuf.cc @@ -21,6 +21,7 @@ #include "fltkcore.hh" +#include "../lout/msg.h" #include "../lout/misc.hh" #include <fltk/draw.h> @@ -35,13 +36,13 @@ using namespace container::typed; 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 @@ void FltkImgbuf::init (Type type, int width, int height, FltkImgbuf *root) 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 @@ void FltkImgbuf::init (Type type, int width, int height, FltkImgbuf *root) 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 @@ void FltkImgbuf::detachScaledBuf (FltkImgbuf *scaledBuf) { 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 @@ void FltkImgbuf::getRowArea (int row, dw::core::Rectangle *area) 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 @@ void FltkImgbuf::getRowArea (int row, dw::core::Rectangle *area) 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 @@ void FltkImgbuf::ref () 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 @@ void FltkImgbuf::unref () // 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 @@ int FltkImgbuf::scaledY(int ySrc) 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); - - for (int row = y; row < y + height; row++) { - if (copiedRows->get (row)) { - ::fltk::Rectangle rect (x + xRoot, row + yRoot, width, 1); - fillrect (rect); - } - } -*/ + // TODO: Clarify the question, whether "target" is the current widget + // (and so has not to be passed at all). - //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); + _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); -//{ -#if 1 if (x > this->width || y > this->height) { return; } @@ -324,19 +311,10 @@ void FltkImgbuf::draw (::fltk::Widget *target, int xRoot, int yRoot, 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 diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index e35027d4..c354d035 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -55,7 +55,6 @@ FltkFont::FltkFont (core::style::FontAttrs *attrs) 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. diff --git a/dw/fltkui.cc b/dw/fltkui.cc index f4090521..676cde51 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -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 @@ void FltkResource::detachView (FltkView *view) } } - fprintf (stderr, "FltkResource::detachView: View not found."); + MSG_WARN("FltkResource::detachView: View not found."); } void FltkResource::sizeAllocate (core::Allocation *allocation) @@ -444,9 +445,8 @@ void FltkComplexButtonResource::detachView (FltkView *view) } } - 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 @@ void FltkEntryResource::widgetCallback (::fltk::Widget *widget, * 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 @@ FltkMultiLineTextResource::FltkMultiLineTextResource (FltkPlatform *platform, // 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; } diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc index b4596edb..ad1b3bc7 100644 --- a/dw/fltkviewbase.cc +++ b/dw/fltkviewbase.cc @@ -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 @@ int FltkViewBase::handle (int event) 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 @@ int FltkViewBase::handle (int event) 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 @@ int FltkViewBase::handle (int event) 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 @@ int FltkViewBase::handle (int event) 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 @@ void FltkViewBase::setCursor (core::style::Cursor cursor) "CURSOR_HELP" }; - printf ("Cursor changes to '%s'.\n", cursorName[cursor]); + MSG("Cursor changes to '%s'.\n", cursorName[cursor]); */ /** \bug Does not work */ diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc index c999745a..411c9566 100644 --- a/dw/fltkviewport.cc +++ b/dw/fltkviewport.cc @@ -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 @@ void FltkViewport::draw () 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)) && diff --git a/dw/image.cc b/dw/image.cc index 2d3d6337..ec5633ff 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -21,6 +21,7 @@ #include "image.hh" +#include "../lout/msg.h" #include "../lout/misc.hh" namespace dw { @@ -197,15 +198,15 @@ void Image::sizeAllocateImpl (core::Allocation *allocation) 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... diff --git a/dw/layout.cc b/dw/layout.cc index 2e29b05d..2fc83c97 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -22,6 +22,7 @@ #include "core.hh" +#include "../lout/msg.h" #include "../lout/debug.hh" #include "../lout/misc.hh" @@ -128,7 +129,7 @@ Layout::~Layout () void Layout::addWidget (Widget *widget) { if (topLevel) { - fprintf (stderr, "widget already set\n"); + MSG_WARN("widget already set\n"); return; } @@ -261,8 +262,8 @@ void Layout::scrollTo0 (HPosition hpos, VPosition vpos, 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 @@ void Layout::adjustScrollPos () 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::draw (View *view, Rectangle *area) */ 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::updateBgColor () 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 @@ void Layout::leaveNotify (View *view, ButtonState state) */ 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::scrollPosChanged (View *view, int x, int y) */ 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. */ diff --git a/dw/style.cc b/dw/style.cc index 106f2592..8d36f510 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -26,6 +26,7 @@ #include <ctype.h> #include "core.hh" +#include "../lout/msg.h" namespace dw { namespace core { @@ -324,7 +325,7 @@ Font *Font::createFromList (Layout *layout, FontAttrs *attrs, } 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 @@ static void drawPolygon (View *view, Color *color, Color::Shading shading, 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); } } diff --git a/dw/table.cc b/dw/table.cc index 4135799b..456b7d81 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -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 @@ void Table::getExtremesImpl (core::Extremes *extremes) 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 @@ void Table::setWidth (int width) { // 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 @@ void Table::addCell (Widget *widget, int colspan, int rowspan) // 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 @@ void Table::addCell (Widget *widget, int colspan, int rowspan) 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 @@ void Table::addCell (Widget *widget, int colspan, int rowspan) 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 @@ void Table::forceCalcCellSizes () 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 @@ void Table::apportionRowSpan () 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 @@ void Table::apportionRowSpan () 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 @@ void Table::apportionRowSpan () 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::calcColumnExtremes () */ 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 @@ void Table::forceCalcColumnExtremes () 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 @@ void Table::forceCalcColumnExtremes () 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 @@ void Table::forceCalcColumnExtremes () 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 @@ void Table::forceCalcColumnExtremes () 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 @@ void Table::apportion2 (int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion2 (int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion2 (int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion2 (int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) } } #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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) } 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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) 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 @@ void Table::apportion_percentages2(int totalWidth, int forceTotalWidth) } } #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 } } diff --git a/dw/textblock.cc b/dw/textblock.cc index 2f5c66ae..2f242f86 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -21,6 +21,7 @@ #include "textblock.hh" +#include "../lout/msg.h" #include "../lout/misc.hh" #include <stdio.h> @@ -260,8 +261,8 @@ void Textblock::getExtremesImpl (core::Extremes *extremes) 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 @@ void Textblock::drawLine (Line *line, core::View *view, core::Rectangle *area) break; default: - fprintf (stderr, "BUG!!! at (%d, %d).\n", xWorld, yWorldBase + diff); + MSG_ERR("at (%d, %d).\n", xWorld, yWorldBase + diff); break; } diff --git a/dw/types.cc b/dw/types.cc index 94f95b42..d72d46cf 100644 --- a/dw/types.cc +++ b/dw/types.cc @@ -21,6 +21,7 @@ #include "core.hh" +#include "../lout/msg.h" namespace dw { namespace core { @@ -180,8 +181,8 @@ bool Polygon::linesCross(int ax1, int ay1, int ax2, int ay2, 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; } diff --git a/dw/widget.cc b/dw/widget.cc index e3ce8e3d..9a77d0b1 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -22,6 +22,7 @@ #include "core.hh" +#include "../lout/msg.h" #include "../lout/debug.hh" using namespace lout::object; @@ -315,7 +316,7 @@ void Widget::queueDrawArea (int x, int y, int width, int height) { /** \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 @@ style::Color *Widget::getBgColor () widget = widget->parent; } - fprintf (stderr, "No background color found!\n"); + MSG_WARN("No background color found!\n"); return NULL; } @@ -692,7 +693,7 @@ Widget *Widget::getNearestCommonAncestor (Widget *otherWidget) /* 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; } diff --git a/lout/Makefile.am b/lout/Makefile.am index 18e00cf2..5a246708 100644 --- a/lout/Makefile.am +++ b/lout/Makefile.am @@ -11,4 +11,5 @@ liblout_a_SOURCES = \ object.cc \ object.hh \ signal.cc \ - signal.hh + signal.hh \ + msg.h diff --git a/lout/msg.h b/lout/msg.h new file mode 100644 index 00000000..219a9744 --- /dev/null +++ b/lout/msg.h @@ -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__ */ |