changeset 1833:5b8f66e6f715

view changes
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Sat, 15 Jan 2011 19:18:58 +0000
parents 553e63661ec1
children 5c6c8a1a3cb7
files dw/fltkflatview.cc dw/fltkplatform.cc dw/fltkpreview.cc dw/fltkviewbase.cc dw/fltkviewbase.hh dw/fltkviewport.cc dw/fltkviewport.hh
diffstat 7 files changed, 101 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkflatview.cc	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkflatview.cc	Sat Jan 15 19:18:58 2011 +0000
@@ -21,12 +21,8 @@
 
 #include "fltkflatview.hh"
 
-#include <fltk/draw.h>
-#include <fltk/events.h>
-
 #include <stdio.h>
 
-using namespace fltk;
 using namespace lout::container::typed;
 
 namespace dw {
--- a/dw/fltkplatform.cc	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkplatform.cc	Sat Jan 15 19:18:58 2011 +0000
@@ -64,10 +64,7 @@
    font = FL_HELVETICA;
 #endif
 
-#if 0
-PORT1.3
-   setfont(font, size);
-#endif
+   fl_font(font, size);
    spaceWidth = misc::max(0, (int)fl_width(' ') + letterSpacing);
    int xh, xw = 0;
    fl_measure("x", xw, xh, 0);
--- a/dw/fltkpreview.cc	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkpreview.cc	Sat Jan 15 19:18:58 2011 +0000
@@ -124,7 +124,7 @@
     * else that measures text).
     */
    FltkFont *ff = (FltkFont*)font;
-   setfont(ff->font, translateCanvasXToViewX (ff->size));
+   Fl::set_font(ff->font, translateCanvasXToViewX (ff->size));
 #if 0
    /**
     * \todo Normally, this should already be known, maybe it
--- a/dw/fltkviewbase.cc	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkviewbase.cc	Sat Jan 15 19:18:58 2011 +0000
@@ -45,10 +45,13 @@
    canvasHeight = 1;
    bgColor = FL_WHITE;
    mouse_x = mouse_y = 0;
+#if 0
+PORT1.3
    exposeArea = NULL;
    if (backBuffer == NULL) {
       backBuffer = new Fl_Image ();
    }
+#endif
 }
 
 FltkViewBase::~FltkViewBase ()
@@ -58,7 +61,10 @@
 
 void FltkViewBase::setBufferedDrawing (bool b) {
    if (b && backBuffer == NULL) {
+#if 0
+PORT1.3 
       backBuffer = new Fl_Image ();
+#endif
    } else if (!b && backBuffer != NULL) {
       delete backBuffer;
       backBuffer = NULL;
@@ -69,7 +75,7 @@
 {
    int d = damage ();
 
-   if ((d & DAMAGE_VALUE) && !(d & FL_DAMAGE_EXPOSE)) {
+   if ((d & FL_DAMAGE_USER1) && !(d & FL_DAMAGE_EXPOSE)) {
       lout::container::typed::Iterator <core::Rectangle> it;
 
       for (it = drawRegion.rectangles (); it.hasNext (); ) {
@@ -77,7 +83,7 @@
       }
 
       drawRegion.clear ();
-      d &= ~DAMAGE_VALUE;
+      d &= ~FL_DAMAGE_USER1;
    }
 
    if (d & FL_DAMAGE_CHILD) {
@@ -105,6 +111,8 @@
 void FltkViewBase::draw (const core::Rectangle *rect,
                          DrawType type)
 {
+#if 0
+PORT1.3
    int offsetX = 0, offsetY = 0;
 
    /* fltk-clipping does not use widget coordinates */
@@ -118,7 +126,7 @@
    ::fltk::intersect_with_clip (viewRect);
 
    viewRect.x (viewRect.x () - offsetX);
-   viewRect.y (viewRect.y () - offsetY);
+   viewRect.y (viewRect.y () - offsetY);A
 
    if (! viewRect.empty ()) {
       dw::core::Rectangle r (
@@ -163,15 +171,24 @@
 
       exposeArea = NULL;
    }
+#endif
+   core::Rectangle r (rect->x, rect->y, rect->width, rect->height);
+   fl_color(bgColor);
+   fl_rectf(translateViewXToCanvasX (rect->x),
+      translateCanvasYToViewY (rect->y), rect->width, rect->height);
+   theLayout->expose (this, &r);
 }
 
 void FltkViewBase::drawChildWidgets () {
    for (int i = children () - 1; i >= 0; i--) {
       Fl_Widget& w = *child(i);
+#if 0
+PORT1.3
       if (w.damage() & DAMAGE_CHILD_LABEL) {
          draw_outside_label(w);
          w.set_damage(w.damage() & ~DAMAGE_CHILD_LABEL);
       }
+#endif
       update_child(w);
    }
 }
@@ -314,7 +331,10 @@
    */
 
    /** \bug Does not work */
+#if 0
+PORT1.3
    this->cursor (mapDwToFltk[cursor]);
+#endif
 }
 
 void FltkViewBase::setBgColor (core::style::Color *color)
@@ -336,12 +356,12 @@
 {
    drawRegion.addRectangle (area);
    /** DAMAGE_VALUE is just an arbitrary value other than DAMAGE_EXPOSE here */
-   redraw (DAMAGE_VALUE);
+   damage (FL_DAMAGE_USER1);
 }
 
 void FltkViewBase::queueDrawTotal ()
 {
-   redraw (FL_DAMAGE_EXPOSE);
+   damage (FL_DAMAGE_EXPOSE);
 }
 
 void FltkViewBase::cancelQueueDraw ()
@@ -358,9 +378,9 @@
                              core::style::Color::Shading shading,
                              int x1, int y1, int x2, int y2)
 {
-   setcolor(((FltkColor*)color)->colors[shading]);
-   drawline (translateCanvasXToViewX (x1), translateCanvasYToViewY (y1),
-             translateCanvasXToViewX (x2), translateCanvasYToViewY (y2));
+   fl_color(((FltkColor*)color)->colors[shading]);
+   fl_line (translateCanvasXToViewX (x1), translateCanvasYToViewY (y1),
+            translateCanvasXToViewX (x2), translateCanvasYToViewY (y2));
 }
 
 void FltkViewBase::drawTypedLine (core::style::Color *color,
@@ -379,21 +399,21 @@
       d = len % f*width;
       gap = ng ? d/ng + (w > 3 ? 2 : 0) : 0;
       dashes[0] = 1; dashes[1] = f*width-gap; dashes[2] = 0;
-      line_style(FL_DASH + FL_CAP_ROUND, w, dashes);
+      fl_line_style(FL_DASH + FL_CAP_ROUND, w, dashes);
 
       /* These formulas also work, but ain't pretty ;)
-       * line_style(FL_DOT + FL_CAP_ROUND, w);
+       * fl_line_style(FL_DOT + FL_CAP_ROUND, w);
        * dashes[0] = 1; dashes[1] = 3*width-2; dashes[2] = 0;
        */
    } else if (type == core::style::LINE_DASHED) {
-      line_style(FL_DASH + FL_CAP_ROUND, w);
+      fl_line_style(FL_DASH + FL_CAP_ROUND, w);
    }
 
-   setcolor(((FltkColor*)color)->colors[shading]);
+   fl_color(((FltkColor*)color)->colors[shading]);
    drawLine (color, shading, x1, y1, x2, y2);
 
    if (type != core::style::LINE_NORMAL)
-      line_style(FL_SOLID);
+      fl_line_style(FL_SOLID);
 }
 
 void FltkViewBase::drawRectangle (core::style::Color *color,
@@ -401,7 +421,7 @@
                                   bool filled,
                                   int x, int y, int width, int height)
 {
-   setcolor(((FltkColor*)color)->colors[shading]);
+   fl_color(((FltkColor*)color)->colors[shading]);
    if (width < 0) {
       x += width;
       width = -width;
@@ -416,17 +436,19 @@
    int x2 = translateCanvasXToViewX (x + width);
    int y2 = translateCanvasYToViewY (y + height);
 
+#if 0
+PORT1.3
    // We only support rectangles with line width 1px, so we clip with
    // a rectangle 1px wider and higher than what we actually expose.
    // This is only really necessary for non-filled rectangles.
    clipPoint (&x1, &y1, 1);
    clipPoint (&x2, &y2, 1);
+#endif
 
-   ::fltk::Rectangle rect (x1, y1, x2 - x1, y2 - y1);
    if (filled)
-      fillrect (rect);
+      fl_rectf (x1, y1, x2 - x1, y2 - y1);
    else
-      strokerect (rect);
+      fl_rect (x1, y1, x2 - x1, y2 - y1);
 }
 
 void FltkViewBase::drawArc (core::style::Color *color,
@@ -434,7 +456,9 @@
                             int centerX, int centerY, int width, int height,
                             int angle1, int angle2)
 {
-   setcolor(((FltkColor*)color)->colors[shading]);
+   fl_color(((FltkColor*)color)->colors[shading]);
+#if 0
+PORT1.3
    int x = translateCanvasXToViewX (centerX) - width / 2;
    int y = translateCanvasYToViewY (centerY) - height / 2;
    ::fltk::Rectangle rect (x, y, width, height);
@@ -444,12 +468,15 @@
       fillpath();
    else
       strokepath();
+#endif
 }
 
 void FltkViewBase::drawPolygon (core::style::Color *color,
                                 core::style::Color::Shading shading,
                                 bool filled, int points[][2], int npoints)
 {
+#if 0
+PORT1.3
    if (npoints > 0) {
       for (int i = 0; i < npoints; i++) {
          points[i][0] = translateCanvasXToViewX(points[i][0]);
@@ -463,6 +490,7 @@
       else
          strokepath();
    }
+#endif
 }
 
 core::View *FltkViewBase::getClippingView (int x, int y, int width, int height)
@@ -490,6 +518,8 @@
 }
 
 void FltkWidgetView::layout () {
+#if 0
+PORT1.3
    /**
     * pass layout to child widgets. This is needed for complex fltk
     * widgets as TextEditor.
@@ -502,6 +532,7 @@
          widget->layout ();
       }
    }
+#endif
 }
 
 void FltkWidgetView::drawText (core::style::Font *font,
@@ -510,12 +541,12 @@
                              int x, int y, const char *text, int len)
 {
    FltkFont *ff = (FltkFont*)font;
-   setfont(ff->font, ff->size);
-   setcolor(((FltkColor*)color)->colors[shading]);
+   fl_font(ff->font, ff->size);
+   fl_color(((FltkColor*)color)->colors[shading]);
 
    if (!font->letterSpacing && !font->fontVariant) {
-      drawtext(text, len,
-               translateCanvasXToViewX (x), translateCanvasYToViewY (y));
+      fl_draw(text, len,
+              translateCanvasXToViewX (x), translateCanvasYToViewY (y));
    } else {
       /* Nonzero letter spacing adjustment, draw each glyph individually */
       int viewX = translateCanvasXToViewX (x),
@@ -531,25 +562,28 @@
             wc = fl_utf8decode(text + curr, text + next, &nb);
             if ((wcu = towupper(wc)) == wc) {
                /* already uppercase, just draw the character */
-               setfont(ff->font, ff->size);
-               drawtext(text + curr, next - curr, viewX, viewY);
+               fl_font(ff->font, ff->size);
+               fl_draw(text + curr, next - curr, viewX, viewY);
                viewX += font->letterSpacing;
-               viewX += (int)getwidth(text + curr, next - curr);
+               viewX += (int)fl_width(text + curr, next - curr);
             } else {
+#if 0
+PORT1.3
                /* make utf8 string for converted char */
                nb = utf8encode(wcu, chbuf);
-               setfont(ff->font, sc_fontsize);
-               drawtext(chbuf, nb, viewX, viewY);
+#endif
+               fl_font(ff->font, sc_fontsize);
+               fl_draw(chbuf, nb, viewX, viewY);
                viewX += font->letterSpacing;
-               viewX += (int)getwidth(chbuf, nb);
+               viewX += (int)fl_width(chbuf, nb);
             }
          }
       } else {
          while (next < len) {
             next = theLayout->nextGlyph(text, curr);
-            drawtext(text + curr, next - curr, viewX, viewY);
+            fl_draw(text + curr, next - curr, viewX, viewY);
             viewX += font->letterSpacing +
-                     (int)getwidth(text + curr,next - curr);
+                     (int)fl_width(text + curr,next - curr);
             curr = next;
          }
       }
@@ -570,33 +604,36 @@
    return true;
 }
 
-void FltkWidgetView::addFltkWidget (::fltk::Widget *widget,
-                                  core::Allocation *allocation)
+void FltkWidgetView::addFltkWidget (Fl_Widget *widget,
+                                    core::Allocation *allocation)
 {
    allocateFltkWidget (widget, allocation);
    add (widget);
 }
 
-void FltkWidgetView::removeFltkWidget (::fltk::Widget *widget)
+void FltkWidgetView::removeFltkWidget (Fl_Widget *widget)
 {
    remove (widget);
 }
 
-void FltkWidgetView::allocateFltkWidget (::fltk::Widget *widget,
+void FltkWidgetView::allocateFltkWidget (Fl_Widget *widget,
                                        core::Allocation *allocation)
 {
-   widget->x (translateCanvasXToViewX (allocation->x));
-   widget->y (translateCanvasYToViewY (allocation->y));
-   widget->w (allocation->width);
-   widget->h (allocation->ascent + allocation->descent);
+   widget->resize (translateCanvasXToViewX (allocation->x),
+      translateCanvasYToViewY (allocation->y),
+      allocation->width,
+      allocation->ascent + allocation->descent);
 
+#if 0
+PORT1.3
    /* widgets created tiny and later resized need this flag to display */
    uchar damage = widget->layout_damage ();
    damage |= LAYOUT_XYWH;
    widget->layout_damage (damage);
+#endif
 }
 
-void FltkWidgetView::drawFltkWidget (::fltk::Widget *widget,
+void FltkWidgetView::drawFltkWidget (Fl_Widget *widget,
                                    core::Rectangle *area)
 {
    draw_child (*widget);
--- a/dw/fltkviewbase.hh	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkviewbase.hh	Sat Jan 15 19:18:58 2011 +0000
@@ -20,12 +20,13 @@
 
    int bgColor;
    core::Region drawRegion;
-   ::fltk::Rectangle *exposeArea;
+   //::fltk::Rectangle *exposeArea;
    static Fl_Image *backBuffer;
    static bool backBufferInUse;
 
    void draw (const core::Rectangle *rect, DrawType type);
    void drawChildWidgets ();
+#if 0
    inline void clipPoint (int *x, int *y, int border) {
       if (exposeArea) {
          if (*x < exposeArea->x () - border)
@@ -38,7 +39,7 @@
             *y = exposeArea->b () + border;
       }
    }
-
+#endif
 protected:
    core::Layout *theLayout;
    int canvasWidth, canvasHeight;
--- a/dw/fltkviewport.cc	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkviewport.cc	Sat Jan 15 19:18:58 2011 +0000
@@ -143,18 +143,19 @@
 
 // ----------------------------------------------------------------------
 
-void FltkViewport::layout ()
+void FltkViewport::resize(int X, int Y, int W, int H) 
 {
-   theLayout->viewportSizeChanged (this, w(), h());
-   adjustScrollbarsAndGadgetsAllocation ();
-
-   FltkWidgetView::layout ();
+   if (W != w() || H != h()) {
+      theLayout->viewportSizeChanged (this, W, H);
+      adjustScrollbarsAndGadgetsAllocation ();
+   }
+   Fl_Group::resize(X, Y, W, H);
 }
 
-void FltkViewport::draw_area (void *data, const Rectangle& cr )
+void FltkViewport::draw_area (void *data, int x, int y, int w, int h)
 {
   FltkViewport *vp = (FltkViewport*) data;
-  fl_push_clip(cr.x, cr.y, cr.w, cr.h);
+  fl_push_clip(x, y, w, h);
 
   vp->FltkWidgetView::draw ();
 
@@ -172,18 +173,17 @@
 {
    int hdiff = vscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
    int vdiff = hscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
-   Rectangle cr (0, 0, w () - hdiff, h () - vdiff);
    int d = damage();
 
    if (d & FL_DAMAGE_SCROLL) {
       Fl::damage (FL_DAMAGE_SCROLL);
-      scrollrect(cr, -scrollDX, -scrollDY, draw_area, this);
+      fl_scroll(0, 0, w () - hdiff, h () - vdiff, -scrollDX, -scrollDY, draw_area, this);
       d &= ~FL_DAMAGE_SCROLL;
       Fl::damage (d);
    }
 
    if (d) {
-      draw_area(this, cr);
+      draw_area(this, 0, 0, w () - hdiff, h () - vdiff);
 
       if (d == FL_DAMAGE_CHILD) {
          if (hscrollbar->damage ())
@@ -203,7 +203,8 @@
 int FltkViewport::handle (int event)
 {
    _MSG("FltkViewport::handle %d\n", event);
-
+#if 0
+PORT1.3
    if (hscrollbar->Rectangle::contains (Fl::event_x (), Fl::event_y ()) &&
        !(Fl::event_state() & (FL_SHIFT | FL_CTRL | FL_ALT)) &&
        hscrollbar->handle (event)) {
@@ -214,6 +215,7 @@
       vscrollbar->handle (event)) {
       return 1;
    }
+#endif
 
    switch(event) {
    case FL_KEYBOARD:
@@ -226,7 +228,8 @@
 
    case FL_FOCUS:
       /** \bug Draw focus box. */
-
+#if 0
+PORT1.3
       /* If the user clicks with the left button we take focus
        * and thereby unfocus any form widgets.
        * Otherwise we let fltk do the focus handling.
@@ -235,6 +238,7 @@
          focus_index(-1);
          return 1;
       }
+#endif
       break;
 
    case FL_UNFOCUS:
@@ -377,9 +381,9 @@
 void FltkViewport::scroll (core::ScrollCommand cmd)
 {
    if (cmd == core::SCREEN_UP_CMD) {
-      scroll (0, -vscrollbar->pagesize ());
+      scroll (0, -h ());
    } else if (cmd == core::SCREEN_DOWN_CMD) {
-      scroll (0, vscrollbar->pagesize ());
+      scroll (0, h ());
    } else if (cmd == core::LINE_UP_CMD) {
       scroll (0, (int) -vscrollbar->linesize ());
    } else if (cmd == core::LINE_DOWN_CMD) {
--- a/dw/fltkviewport.hh	Sat Jan 15 16:30:31 2011 +0000
+++ b/dw/fltkviewport.hh	Sat Jan 15 19:18:58 2011 +0000
@@ -39,7 +39,7 @@
    static void vscrollbarCallback (Fl_Widget *vscrollbar, void *viewportPtr);
 
    void updateCanvasWidgets (int oldScrollX, int oldScrollY);
-   static void draw_area (void *data, const Rectangle& cr);
+   static void draw_area (void *data, int x, int y, int w, int h);
 
 protected:
    int translateViewXToCanvasX (int x);
@@ -51,7 +51,7 @@
    FltkViewport (int x, int y, int w, int h, const char *label = 0);
    ~FltkViewport ();
 
-   void layout();
+   void resize(int x, int y, int w, int h);
    void draw ();
    int handle (int event);