"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/InterViews/aggr.c" (9 Oct 2020, 5278 Bytes) of package /linux/misc/ivtools-ivtools-2.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "aggr.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 1987, 1988, 1989, 1990, 1991 Stanford University
    3  * Copyright (c) 1991 Silicon Graphics, Inc.
    4  *
    5  * Permission to use, copy, modify, distribute, and sell this software and 
    6  * its documentation for any purpose is hereby granted without fee, provided
    7  * that (i) the above copyright notices and this permission notice appear in
    8  * all copies of the software and related documentation, and (ii) the names of
    9  * Stanford and Silicon Graphics may not be used in any advertising or
   10  * publicity relating to the software without the specific, prior written
   11  * permission of Stanford and Silicon Graphics.
   12  * 
   13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
   14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
   15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
   16  *
   17  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
   18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
   19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
   20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
   21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
   22  * OF THIS SOFTWARE.
   23  */
   24 
   25 /*
   26  * Aggregate - composite glyph
   27  */
   28 
   29 #include <InterViews/aggr.h>
   30 #include <InterViews/canvas.h>
   31 #include <InterViews/hit.h>
   32 #include <InterViews/printer.h>
   33 #include <OS/list.h>
   34 
   35 class AggregateInfo {
   36 public:
   37     AggregateInfo();
   38 
   39     Glyph* glyph_;
   40     Allocation allocation_;
   41     Extension extension_;
   42 };
   43 
   44 declareList(AggregateInfo_List,AggregateInfo)
   45 implementList(AggregateInfo_List,AggregateInfo)
   46 
   47 AggregateInfo::AggregateInfo() {
   48     glyph_ = nil;
   49 }
   50 
   51 Aggregate::Aggregate(GlyphIndex size) : Glyph() {
   52     info_ = new AggregateInfo_List(size);
   53 }
   54 
   55 Aggregate::~Aggregate() {
   56     GlyphIndex count = info_->count();
   57     for (GlyphIndex i = 0; i < count; ++i) {
   58         AggregateInfo& info = info_->item_ref(i);
   59     Resource::unref(info.glyph_);
   60     }
   61     delete info_;
   62     info_ = nil;
   63 }
   64 
   65 GlyphIndex Aggregate::count() const {
   66     return info_->count();
   67 }
   68 
   69 Glyph* Aggregate::component(GlyphIndex index) const {
   70     return info_->item_ref(index).glyph_;
   71 }
   72 
   73 void Aggregate::allotment(
   74     GlyphIndex index, DimensionName res, Allotment& a
   75 ) const {
   76     a = info_->item_ref(index).allocation_.allotment(res);
   77 }
   78 
   79 void Aggregate::allot(GlyphIndex i, DimensionName res, const Allotment& al) {
   80     Allocation& a = info_->item_ref(i).allocation_;
   81     a.allot(res, al);
   82 }
   83 
   84 void Aggregate::change(GlyphIndex) { }
   85 
   86 void Aggregate::append(Glyph* glyph) {
   87     AggregateInfo info;
   88     info.glyph_ = glyph;
   89     info_->append(info);
   90     Resource::ref(glyph);
   91 }
   92 
   93 void Aggregate::prepend(Glyph* glyph) {
   94     AggregateInfo info;
   95     info.glyph_ = glyph;
   96     info_->prepend(info);
   97     Resource::ref(glyph);
   98 }
   99 
  100 void Aggregate::insert(GlyphIndex index, Glyph* glyph) {
  101     AggregateInfo info;
  102     info.glyph_ = glyph;
  103     info_->insert(index, info);
  104     Resource::ref(glyph);
  105 }
  106 
  107 void Aggregate::remove(GlyphIndex index) {
  108     AggregateInfo& info = info_->item_ref(index);
  109     Resource::unref(info.glyph_);
  110     info_->remove(index);
  111 }
  112 
  113 void Aggregate::replace(GlyphIndex index, Glyph* glyph) {
  114     AggregateInfo& info = info_->item_ref(index);
  115     Resource::ref(glyph);
  116     Resource::unref(info.glyph_);
  117     info.glyph_ = glyph;
  118 }
  119 
  120 void Aggregate::allocate(Canvas* canvas, const Allocation&, Extension& ext) {
  121     GlyphIndex count = info_->count();
  122     for (GlyphIndex index = 0; index < count; ++index) {
  123         AggregateInfo& info = info_->item_ref(index);
  124         if (info.glyph_ != nil) {
  125             Allocation& a = info.allocation_;
  126             Extension& b = info.extension_;
  127         b.clear();
  128             info.glyph_->allocate(canvas, a, b);
  129             ext.merge(b);
  130         }
  131     }
  132 }
  133 
  134 void Aggregate::draw(Canvas* canvas, const Allocation&) const {
  135     GlyphIndex count = info_->count();
  136     for (GlyphIndex index = 0; index < count; ++index) {
  137         AggregateInfo& info = info_->item_ref(index);
  138         if (info.glyph_ != nil) {
  139             Allocation& a = info.allocation_;
  140             if (canvas->damaged(info.extension_)) {
  141                 info.glyph_->draw(canvas, a);
  142             }
  143         }
  144     }
  145 }
  146 
  147 void Aggregate::print(Printer* p, const Allocation&) const {
  148     GlyphIndex count = info_->count();
  149     for (GlyphIndex index = 0; index < count; ++index) {
  150         AggregateInfo& info = info_->item_ref(index);
  151         if (info.glyph_ != nil) {
  152             Allocation& a = info.allocation_;
  153             if (p->damaged(info.extension_)) {
  154                 info.glyph_->print(p, a);
  155             }
  156         }
  157     }
  158 }
  159 
  160 void Aggregate::pick(Canvas* c, const Allocation&, int depth, Hit& h) {
  161     Coord x = h.left();
  162     Coord y = h.bottom();
  163     GlyphIndex count = info_->count();
  164     for (GlyphIndex index = 0; index < count; ++index) {
  165         AggregateInfo& info = info_->item_ref(index);
  166         if (info.glyph_ != nil) {
  167             Extension& b = info.extension_;
  168             Allocation& a = info.allocation_;
  169             if (
  170                 x >= b.left() && x < b.right()
  171                 && y >= b.bottom() && y < b.top()
  172             ) {
  173         h.begin(depth, this, index);
  174         info.glyph_->pick(c, a, depth + 1, h);
  175         h.end();
  176             }
  177         }
  178     }
  179 }