Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

TreeView Class Reference

Calculates the directory entry sizes and displays the rectangles. More...

#include <dutree.h>

Inheritance diagram for TreeView:

Inheritance graph
[legend]
Collaboration diagram for TreeView:

Collaboration graph
[legend]
List of all members.

Public Methods

 TreeView (gint x_size=0, gint y_size=0)
 Constructor.

EnTree const & get_EnTree () const
 Gets the EnTree that the mouse is currently over, or the top EnTree.

void set_EnTree (EnTree const &newcur)
 Set the current EnTree for display.

EnTree const & get_top_EnTree () const
 Return the EnTree at the top.

void modified (DirTree const &moddir)
 Updates the display when the file sizes change significantly.

void EnTree_rect (EnTree const *curent, bool vertical, gint x, gint y, gint width, gint height)
 Calculates the position and dimensions of the rectangles, based on the EnTree.

void draw_rect ()
 Draws the rectangles to the screen from the rectangles vector.

bool isReady ()
 Determines whether the TreeView is ready for use.

void test_tree ()
void setDrawer (Drawer *d)
void set_cpick (ColorPicker *cp)
DrawergetDrawer ()
gint expose_event_impl (GdkEventExpose *)
 Displays the space use graph.

gint delayed_calc ()
bool clicked (EntryRect const *, int button)
 Called when a rectangle is clicked.

virtual bool region_hover (EntryRect &region)

Public Attributes

RecTransform rt

Detailed Description

Calculates the directory entry sizes and displays the rectangles.


Constructor & Destructor Documentation

TreeView::TreeView gint    x_size = 0,
gint    y_size = 0
 

Constructor.

Parameters:
x_size  The width of the imagemap
y_size  The height of the imagemap

00087                                           :
00088    drawing(false), rt(150,150,0.5,0.5)
00089 {
00090    Context cx1("TreeView::TreeView(gint, gint)");
00091    size(x_size, y_size);
00092    //treeGen.max_depth=3;
00093    set_events(GDK_ENTER_NOTIFY_MASK| GDK_LEAVE_NOTIFY_MASK|GDK_EXPOSURE_MASK | 
00094       GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 
00095       GDK_BUTTON_PRESS_MASK);
00096    treeGen.opt_separate_dirs=false;
00097    treeGen.set_watcher(*this);
00098    srandom(1);
00099    my_tree.reset(new EnTree);
00100    cur_tree=NULL;
00101    over_rect=NULL;
00102    firsttime=true;
00103    oldsize=0;
00104    //dwr.reset(new DarkFirst(get_window()));
00105 }


Member Function Documentation

EnTree const & TreeView::get_EnTree   const
 

Gets the EnTree that the mouse is currently over, or the top EnTree.

Returns:
The top EnTree or NULL on failure;

00112 {
00113    if (mouse_in && over_rect!=NULL ) return over_rect->get_EnTree();
00114    else if (cur_tree==NULL)
00115    {
00116       Exception err;
00117       throw err;
00118    }
00119    return *cur_tree;
00120 }

void TreeView::set_EnTree EnTree const &    newcur
 

Set the current EnTree for display.

Parameters:
newcur  The new current entry

00140 {
00141    if (&newcur==cur_tree) return;
00142 
00143    cur_tree=&newcur;
00144    rectangles.clear();
00145    EnTree_rect(cur_tree, false, 0,0,width(),height());
00146    draw_rect();
00147    seek_over();
00148    me_modified();
00149 }

EnTree const & TreeView::get_top_EnTree   const
 

Return the EnTree at the top.

00126 {
00127    if (my_tree.get()==NULL)
00128    {
00129       Exception err;
00130       throw err;
00131    }
00132    return *my_tree;
00133 }

void TreeView::modified DirTree const &    moddir [virtual]
 

Updates the display when the file sizes change significantly.

Parameters:
moddir  The DirTree that contains file size info

Implements Watcher< DirTree >.

00156 {
00157    if (cur_tree==NULL || my_tree.get()==NULL) return;
00158    if (oldsize==0)
00159    {
00160       oldsize=my_tree->size;
00161       return;
00162    }
00163    if (my_tree->size*100/oldsize>115)
00164    {
00165       rectangles.clear();
00166       EnTree_rect(cur_tree, false, 0, 0, 300, 300);
00167       draw_rect();
00168       oldsize=my_tree->size;
00169    }
00170 }

void TreeView::EnTree_rect EnTree const *    curent,
bool    vertical,
gint    x,
gint    y,
gint    width,
gint    height
 

Calculates the position and dimensions of the rectangles, based on the EnTree.

Parameters:
curent  The EnTree to base calculations on
vertical  If true, draw the boxes vertically.
x  The x coordinate of the available space
y  The y coordinate of the available space
width  The width of the available space
height  The height of the available space

00260 {
00261    if(curent==NULL) return;
00262    if (firsttime)
00263    {
00264 
00265    cout << curent->name << endl;
00266    cout << "x: " << x << " y: "<< y << " width: " << width << " height: " <<\
00267       height << endl;
00268    }
00269 
00270 /* calculate the total size of children */
00271    uintmax_t childsize=0;
00272    for (EnTree *curchild=curent->child; curchild!=NULL; 
00273       curchild=curchild->next)
00274    {
00275       childsize+=curchild->size;
00276    }
00277 
00278 /* calculate the size of the entry without children */
00279    uintmax_t selfsize=curent->size-childsize;
00280    
00281 /* prepare the adjustable dimension and coordinate */ 
00282    gint &dimension=(vertical)?width:height;
00283    gint &coordinate=(vertical)?x:y;
00284    gint olddimension=dimension;
00285    dimension=(selfsize==0)?0:dimension*selfsize/curent->size;
00286    EntryRect cur(x, y, width+1, height, *curent, *this);
00287    rectangles.push_back(cur);
00288 /* draw the rectangle */   
00289 
00290    
00291    if (firsttime)
00292    {
00293    cout << "x: " << x << " y: "<< y << " width: " << width << " height: " <<\
00294       height << endl << endl;
00295    }
00296 
00297 /* ajust the coordiate and dimension for drawing children */
00298    coordinate+=dimension;
00299    dimension=olddimension-dimension;
00300 
00301    /* prepare the adjustable (opposite) dimension and coordinate for the child  */
00302    gint &child_dimension=(vertical)?height:width;
00303    olddimension=child_dimension;
00304    gint &child_coordinate=(vertical)?y:x;
00305 
00306    float fcoord=child_coordinate;
00307 
00308    gint oldx, oldy, oldwidth=-1, oldheight=-1;
00309    for (EnTree *curchild=curent->child; curchild!=NULL; 
00310       curchild=curchild->next)
00311    {
00312       float fdim;
00313       fdim=(curchild->size==0)?0:1.0f*child_dimension*curchild->size/childsize;
00314       child_dimension=static_cast<int>(fdim);
00315       if (x!=oldx || y!=oldy || width!=oldwidth || height!=oldheight) 
00316          EnTree_rect(curchild, vertical, x, y, width, height);
00317       oldx=x; 
00318       oldy=y; 
00319       oldwidth=width; 
00320       oldheight=height;
00321       fcoord+=fdim;
00322       child_coordinate=static_cast<int>(fcoord);
00323       if (firsttime)
00324       {
00325          cout << fcoord << "," << fdim<<endl;
00326       }
00327       child_dimension=olddimension;
00328    }
00329 }

void TreeView::draw_rect  
 

Draws the rectangles to the screen from the rectangles vector.

00335 {
00336 
00337    if (drawing) 
00338    {
00339       ContException err("Drawing on top!");
00340       throw err;
00341    }
00342    drawing=true;
00343    over_rect=NULL;
00344 
00345    for (size_t i=0; i<rectangles.size(); ++i)
00346    {
00347       (*dwr)(rectangles[i], (*cpick)(rectangles[i]));
00348    }
00349    drawing=false;
00350 }

bool TreeView::isReady  
 

Determines whether the TreeView is ready for use.

00356 {
00357    return (cur_tree!=NULL);
00358 }

void TreeView::test_tree  
 

00361 {
00362    EnTree *child;
00363    my_tree.reset(new EnTree());
00364    my_tree->set(100, "Top");
00365    child=new EnTree();
00366    child->set(25, "Yark");
00367    my_tree->add_child(child);
00368    child=new EnTree();
00369    child->set(12, "Park");
00370    my_tree->add_child(child);
00371    EnTree *childchild=new EnTree();
00372    childchild->set(6, "Park");
00373    child->add_child(childchild);
00374    child=new EnTree();
00375    child->set(13, "Sark");
00376    my_tree->add_child(child); 
00377 }

void TreeView::setDrawer Drawer   d [inline]
 

00218    {
00219       dwr.reset(d);
00220    }

void TreeView::set_cpick ColorPicker   cp [inline]
 

00223    {
00224       cpick.reset(cp);
00225    }

Drawer* TreeView::getDrawer   [inline]
 

00228    {
00229       return dwr.get();
00230    }

gint TreeView::expose_event_impl GdkEventExpose *    event
 

Displays the space use graph.

Note:
Calculates the space use graph, the first time
Parameters:
event  ignored (but required by gtkmm interface)
Returns:
true (event handled)

00179 {
00180    Context cx1("TreeView::expose_event_impl()");
00181    try 
00182    {
00183       static int oldwidth=-1, oldheight=-1;
00184       if (cpick.get()==NULL)
00185     cpick.reset(new AgeColor);
00186 
00187       if (dwr.get()==NULL)
00188     dwr.reset(new PrettyDrawer(get_window()));
00189       if (firsttime || oldheight!=event->area.height || 
00190     oldwidth!=event->area.width)
00191       {
00192     {
00193        Context cx2("Calculating directories");
00194        firsttime=false;
00195 
00196        cur_tree=my_tree.get();
00197        treeGen.calc_EnTree(".", my_tree.get());
00198     }
00199     {
00200        Context cx3("Drawing rectangles");
00201        if (cur_tree==NULL) return true;
00202        rectangles.clear();
00203        EnTree_rect(cur_tree, false, 0,0,width(),height());
00204        me_modified();
00205        oldwidth=width();
00206        oldheight=height();
00207     }
00208       }
00209       draw_rect();
00210    }
00211    catch (ContException &cex)
00212    {
00213       cex.print();
00214    }
00215    return true;
00216 }

gint TreeView::delayed_calc  
 

00219 {
00220    cur_tree=my_tree.get();
00221    treeGen.calc_EnTree(".", my_tree.get());
00222    return false;
00223 }

bool TreeView::clicked EntryRect const *    rect,
int    button
[virtual]
 

Called when a rectangle is clicked.

Parameters:
rect  The EntryRect that was clicked
button  The mouse button that clicked, enumerated as in GTK

Implements ImageMap.

00231 {
00232    if (cur_tree==NULL) return true;
00233    if (rect==NULL) return false;
00234    //left click 
00235    if (button == 1 && rect!=NULL) 
00236       set_EnTree(rect->get_EnTree());
00237 
00238    //right click
00239    if (button == 3)
00240    {
00241       if (cur_tree->parent!=NULL) set_EnTree(*cur_tree->parent);
00242    }
00243    return true;
00244 }

virtual bool TreeView::region_hover EntryRect   region [inline, virtual]
 

Reimplemented from RegionWatcher< EntryRect >.

00238    {
00239       me_modified();
00240       //set_EnTree(region.get_EnTree());
00241       return true;
00242    }


Member Data Documentation

RecTransform TreeView::rt
 


The documentation for this class was generated from the following files:
Generated on Mon Apr 7 19:43:58 2003 for DuTree by doxygen1.2.18