Skip to content
This repository
tree: 66c7644bfb
Fetching contributors…

Cannot retrieve contributors at this time

file 141 lines (83 sloc) 4.94 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
//
// PSBaseSubtreeView.h
// PSTreeGraphView
//
// Created by Ed Preston on 7/25/10.
// Copyright 2010 Preston Software. All rights reserved.
//
//
// This is a port of the sample code from Max OS X to iOS (iPad).
//
// WWDC 2010 Session 141, “Crafting Custom Cocoa Views”
//


#import <UIKit/UIKit.h>

#import "PSTreeGraphModelNode.h"

@class PSBaseBranchView;
@class PSBaseTreeGraphView;


/// A SubtreeView draws nothing itself (unless showsSubtreeFrames is set to YES for the enclosingTreeGraph), but
/// provides a local coordinate frame and grouping mechanism for a graph subtree, and implements subtree layout.
 

@interface PSBaseSubtreeView : UIView
{

@private
    // Model
    id <PSTreeGraphModelNode> modelNode; // the model node that nodeView represents

    // Views
    UIView *nodeView; // the subview of this SubtreeView that shows a representation
                                            // of the modelNode
    
    PSBaseBranchView *connectorsView; // the view that shows connections from nodeView to its child nodes

    // State
    BOOL expanded; // YES if this subtree is expanded to show its descendants;
                                            // NO if it's been collapsed to show just its root node
    
    BOOL needsGraphLayout; // YES if this SubtreeView needs to position its child views
                                            // and assess its size; NO if we're sure its layout is up to date
}

/// Initializes a SubtreeView with the associated modelNode. This is SubtreeView's designated initializer.
 
- initWithModelNode:( id <PSTreeGraphModelNode> )newModelNode;

/// The root of the model subtree that this SubtreeView represents.
 
@property (nonatomic, retain) id <PSTreeGraphModelNode> modelNode;

/// The view that represents the modelNode. Is a subview of SubtreeView, and may itself have descendant views.
 
@property (nonatomic, assign) IBOutlet UIView *nodeView;

/// Link to the enclosing TreeGraph. (The getter for this is a convenience method that ascends
/// the view tree until it encounters a TreeGraph.)
 
@property (nonatomic, readonly) PSBaseTreeGraphView *enclosingTreeGraph;

// Whether the model node represented by this SubtreeView is a leaf node (one without child nodes). This
// can be a useful property to bind user interface state to. In the TreeGraph demo app, for example,
// we've bound the "isHidden" property of subtree expand/collapse buttons to this, so that expand/collapse
// buttons will only be shown for non-leaf nodes.
 
@property (nonatomic, readonly, getter=isLeaf) BOOL leaf;


#pragma mark - Selection State

/// Whether the node is part of the TreeGraph's current selection. This can be a useful property to bind user
/// interface state to.
 
@property (nonatomic, readonly) BOOL nodeIsSelected;


#pragma mark - Layout

/// Returns YES if this subtree needs relayout.
 
@property (nonatomic, assign) BOOL needsGraphLayout;

/// Recursively marks this subtree, and all of its descendants, as needing relayout.
 
- (void) recursiveSetNeedsGraphLayout;

/// Recursively performs graph layout, if this subtree is marked as needing it.
  
- (CGSize) layoutGraphIfNeeded;

/// Resizes this subtree's nodeView to the minimum size required to hold its content, and returns the nodeView's
/// new size. (This currently does nothing, and is just stubbed out for future use.)
 
- (CGSize) sizeNodeViewToFitContent;

/// Whether this subtree is currently shown as expanded. If NO, the node's children have been collapsed into it.
 
@property (nonatomic, assign, getter=isExpanded) BOOL expanded;

/// Toggles expansion of this subtree. This can be wired up as the action of a button or other user interface
/// control.
 
- (IBAction) toggleExpansion:(id)sender;


#pragma mark - Invalidation

/// Marks all BranchView instances in this subtree as needing display.
 
- (void) recursiveSetConnectorsViewsNeedDisplay;

/// Marks all SubtreeView debug borders as needing display.
 
- (void) resursiveSetSubtreeBordersNeedDisplay;


#pragma mark - Node Hit-Testing

/// Returns the visible model node whose nodeView contains the given point "p", where "p" is specified in the
/// SubtreeView's interior (bounds) coordinate space. Returns nil if there is no node under the specified point.
/// When a subtree is collapsed, only its root nodeView is eligible for hit-testing.
 
- ( id <PSTreeGraphModelNode> ) modelNodeAtPoint:(CGPoint)p;

/// Returns the visible model node that is closest to the specified y coordinate, where "y" is specified in the
/// SubtreeView's interior (bounds) coordinate space.
 
- ( id <PSTreeGraphModelNode> ) modelNodeClosestToY:(CGFloat)y;


#pragma mark - Debugging

/// Returns an indented multi-line NSString summary of the displayed tree. Provided as a debugging aid.
 
- (NSString *) treeSummaryWithDepth:(NSInteger)depth;

@end
Something went wrong with that request. Please try again.