This is MiscTableBorder.h in view mode; [Download] [Up]
#ifndef __MiscTableBorder_h
#define __MiscTableBorder_h
#ifdef __GNUC__
# pragma interface
#endif
//=============================================================================
//
// Copyright (C) 1995-1997 by Paul S. McCarthy and Eric Sunshine.
// Written by Paul S. McCarthy and Eric Sunshine.
// All Rights Reserved.
//
// This notice may not be removed from this source code.
//
// This object is included in the MiscKit by permission from the authors
// and its use is governed by the MiscKit license, found in the file
// "License.rtf" in the MiscKit distribution. Please refer to that file
// for a list of all applicable permissions and restrictions.
//
//=============================================================================
//-----------------------------------------------------------------------------
// MiscTableBorder.h
//
// Structure describing border of an MiscTableView.
//
// NOTE: Many of the sub-arrays in an MiscTableBorder are conditional.
// They are not guaranteed to be allocated for every instance. They are
// only allocated when the caller tries to store a value in them. Doing
// a "set" creates the array, even if the value is the default value.
//
// "Springy" slots get adjusted when the total size exceeds the global
// min/max size.
//
// NOTE *1* These methods return true if the new value is different than
// the old value, and the display needs updating.
//
// MAINTENANCE NOTE:
// Consider breaking data_size out of slots into a separate array of
// its own.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// $Id: MiscTableBorder.h,v 1.14 97/04/04 05:01:52 sunshine Exp $
// $Log: MiscTableBorder.h,v $
// Revision 1.14 97/04/04 05:01:52 sunshine
// 0.125.6: NSArchiver* --> NSCoder* (to be consistent with rest of OPENSTEP).
//
// Revision 1.13 97/03/20 19:13:48 sunshine
// v123.1: Selection methods can now optionally *extend* the selection.
// Added deselection methods.
//
// Revision 1.12 97/03/10 10:30:04 sunshine
// v113.1: Fixed bug: clickedSlot_P() was using wrong mapping.
//-----------------------------------------------------------------------------
#include <MiscTableScroll.h>
#include "MiscSparseSet.h"
#include "MiscTableUtil.h"
@class MiscTableScroll;
@class NSCoder, NSArray, NSCell;
struct MiscTableSlot
{
MiscPixels offset; // Offset of this slot.
MiscPixels adj_size; // Size adjusted for springy-ness.
MiscPixels data_size; // Current size of data.
MiscPixels size; // Target size.
MiscPixels min_size; // Minimum size.
MiscPixels max_size; // Maximum size.
MiscTableSizing sizing; // Sizing options.
bool isSpringy() const { return ::isSpringy(sizing); }
bool isData() const { return ::isData(sizing); }
void initWithCoder( NSCoder*, int ver );
void encodeWithCoder( NSCoder* );
};
class MiscTableBorder
{
private:
MiscBorderType type; // Row / Col.
MiscTableScroll* owner;
MiscTableSlot def_slot; // Default slot configuration.
int max_slots; // Capacity. Allocation size of arrays.
int num_slots; // Active number of rows/cols.
MiscTableSlot* slots; // Indexed by visual coords.
MiscCoord_P* v2p; // Visual -> Physical coord map.
MiscCoord_V* p2v; // Physical -> Visual coord map.
int def_tag; // Default tag value.
int* tags; // Indexed by physical coords.
MiscPixels uniform_size; // 0 = not uniform.
MiscPixels min_total_size; // Min size for the entire border.
MiscPixels max_total_size; // Max size for the entire border.
int num_springy; // Number of "springy" slots.
MiscTableTitleMode title_mode;
NSString** titles; // Indexed by visual coords.
MiscTableCellStyle def_style;
MiscTableCellStyle* styles;
id* prototypes;
MiscCompareEntryFunc* sort_funcs;
MiscSortDirection* sort_dirs;
MiscSortType* sort_types;
MiscSparseSet selection; // Selection (visual coordinates).
MiscCoord_V selected_slot; // Selected slot.
MiscCoord_V cursor; // Keyboard cursor.
MiscCoord_V clicked_slot; // Clicked slot.
bool selectable; // User can select slot-titles.
bool sizeable; // User can resize slots.
bool draggable; // User can rearrange slots.
bool modifier_drag; // Use modifier key to drag slots.
bool needs_recalc; // Offset values are "stale".
int shrink_mode( MiscTableSlot& );
void global_shrink( MiscPixels );
MiscCoord_V find_springy_slot() const;
void global_grow( MiscPixels );
void init_slot( MiscCoord_V, MiscCoord_P );
void destroy_slot( MiscCoord_V );
void do_shift( void*, int, int, int );
void do_shift( MiscCoord_V, MiscCoord_V );
void* do_remap( void*, int, MiscCoord_V const* );
void do_remap( MiscCoord_V const* );
MiscCoord_V find_slot_for_offset( MiscPixels );
void perform_recalc();
void do_recalc();
void recalc_if_needed();
int alloc_size( int rec_size );
void* do_alloc( int );
void* do_alloc_init( int );
void* do_realloc( void*, int );
void do_realloc();
void do_delete( void*, int, int );
void do_delete( MiscCoord_V, MiscCoord_P );
void do_insert( void*, int, int );
void do_insert( MiscCoord_V, MiscCoord_P );
void alloc_slots();
void alloc_vmap();
void alloc_titles();
void dealloc_titles();
void alloc_tags();
void alloc_styles();
void alloc_prototypes();
id new_prototype( MiscCoord_V );
void alloc_sort_funcs();
void alloc_sort_dirs();
void alloc_sort_types();
NSString* get_title( MiscCoord_V ) const;
id get_prototype( MiscCoord_V ) const;
NSArray* selected_slots( bool do_tags ) const;
void select_slots( NSArray*, bool clear, bool set );
void select_tags( NSArray*, bool clear, bool set );
public:
MiscTableBorder( MiscBorderType );
~MiscTableBorder();
MiscTableScroll* getOwner() const { return owner; }
void setOwner( MiscTableScroll* );
int count() const { return num_slots; }
int capacity() const { return max_slots; }
void setCount( int );
void setCapacity( int );
void freeExtraCapacity();
void empty();
void emptyAndFree() { empty(); freeExtraCapacity(); }
bool goodPos( int x ) const { return 0 <= x && x < count(); }
void deleteAt( MiscCoord_V );
void insertAt( MiscCoord_V, MiscCoord_P );
void add() { insertAt(count(),count()); }
void moveFromTo( MiscCoord_V, MiscCoord_V );
MiscSparseSet& selectionSet() { return selection; }
MiscTableSlot const* getSlots() const { return slots; }
MiscCoord_V const* getP2VMap() const { return p2v; }
MiscCoord_P const* getV2PMap() const { return v2p; }
void setSlotSizes( MiscPixels const* );
bool setP2VMap( MiscCoord_P const* );
bool setV2PMap( MiscCoord_V const* );
bool good_map( int const* map, bool onescomp ) const;
void clearVMap();
MiscBorderType getType() const { return type; }
bool isColBorder() const { return type == MISC_COL_BORDER; }
bool isRowBorder() const { return type == MISC_ROW_BORDER; }
bool isSelectable() const { return selectable; }
bool isSizeable() const { return sizeable; }
bool isDraggable() const { return draggable; }
bool isModifierDrag() const { return modifier_drag; }
bool isUniformSize() const { return uniform_size != 0; }
MiscPixels getUniformSize() const { return uniform_size; }
MiscTableTitleMode getTitleMode() const { return title_mode; }
bool needsRecalc() const { return needs_recalc; }
void setType( MiscBorderType );
void setDraggable( bool x ) { draggable = x; }
void setModifierDrag( bool x ) { modifier_drag = x; }
void setSelectable( bool x ) { selectable = x; }
void setSizeable( bool x ) { sizeable = x; }
bool setUniformSize( MiscPixels ); // NOTE *1*
bool setTitleMode( MiscTableTitleMode ); // NOTE *1*
MiscPixels totalSize();
MiscPixels getMinTotalSize() const { return min_total_size; }
MiscPixels getMaxTotalSize() const { return max_total_size; }
void setMinTotalSize( MiscPixels );
void setMaxTotalSize( MiscPixels );
MiscCoord_P visualToPhysical( MiscCoord_V x ) const
{ return (x >= 0 && v2p != 0) ? v2p[x] : (MiscCoord_P)x; }
MiscCoord_V physicalToVisual( MiscCoord_P x ) const
{ return (x >= 0 && p2v != 0) ? p2v[x] : (MiscCoord_V)x; }
void visualToPhysical( MiscSparseSet const&, MiscSparseSet& ) const;
void physicalToVisual( MiscSparseSet const&, MiscSparseSet& ) const;
MiscCoord_V visualForOffset( MiscPixels );
void recalcOffsets();
MiscPixels getOffset( MiscCoord_V );
MiscPixels getSize( MiscCoord_V ) const; // target size.
MiscPixels getMinSize( MiscCoord_V ) const;
MiscPixels getMaxSize( MiscCoord_V ) const;
MiscPixels getDataSize( MiscCoord_V ) const;
MiscPixels effectiveSize( MiscCoord_V ); // adj_size.
MiscPixels effectiveMaxSize( MiscCoord_V ); // With global
MiscPixels effectiveMinSize( MiscCoord_V ); // limts.
NSString* getTitle( MiscCoord_V ) const;
int getTag( MiscCoord_V ) const;
MiscTableCellStyle getStyle( MiscCoord_V ) const;
id getPrototype( MiscCoord_V );
MiscCompareEntryFunc getSortFunc( MiscCoord_V ) const;
MiscSortDirection getSortDirection( MiscCoord_V ) const;
MiscSortType getSortType( MiscCoord_V ) const;
MiscTableSizing getSizing( MiscCoord_V ) const;
bool isSortable( MiscCoord_V x ) const
{ return getSortFunc(x) != 0 ||
getSortType(x) != MISC_SORT_SKIP; }
bool isFixed( MiscCoord_V x ) const
{ return ::isFixed(getSizing(x)); }
bool isSpringy( MiscCoord_V x ) const
{ return ::isSpringy(getSizing(x)); }
bool isSizeable( MiscCoord_V x ) const
{ return ::isSizeable(getSizing(x)); }
bool isData( MiscCoord_V x ) const
{ return ::isData(getSizing(x)); }
void setSize( MiscCoord_V, MiscPixels );
void setMinSize( MiscCoord_V, MiscPixels );
void setMaxSize( MiscCoord_V, MiscPixels );
void setDataSize( MiscCoord_V, MiscPixels );
bool setTitle( MiscCoord_V, NSString* ); // NOTE *1*
void setTag( MiscCoord_V, int );
void setStyle( MiscCoord_V, MiscTableCellStyle );
void setPrototype( MiscCoord_V, id );
void setSortFunc( MiscCoord_V, MiscCompareEntryFunc );
void setSortDirection( MiscCoord_V, MiscSortDirection );
void setSortType( MiscCoord_V, MiscSortType );
void setSizing( MiscCoord_V, MiscTableSizing );
void setSpringy( MiscCoord_V x, bool b )
{ setSizing( x, ::setSpringy(getSizing(x),b) ); }
void setSizeable( MiscCoord_V x, bool b )
{ setSizing( x, ::setSizeable(getSizing(x),b) ); }
void setData( MiscCoord_V x, bool b )
{ setSizing( x, ::setData(getSizing(x),b) ); }
// DEFAULT VALUES ARE USED TO INITIALIZE NEW SLOTS.
MiscPixels getDefaultSize() const { return def_slot.size; }
MiscPixels getDefaultMinSize() const { return def_slot.min_size; }
MiscPixels getDefaultMaxSize() const { return def_slot.min_size; }
MiscTableSizing getDefaultSizing() const { return def_slot.sizing; }
int getDefaultTag() const { return def_tag; }
MiscTableCellStyle getDefaultStyle() const{ return def_style; }
void setDefaultSize( MiscPixels x )
{ needs_recalc = true; def_slot.size = x; }
void setDefaultMinSize( MiscPixels x )
{ needs_recalc = true; def_slot.min_size = x; }
void setDefaultMaxSize( MiscPixels x )
{ needs_recalc = true; def_slot.max_size = x; }
void setDefaultSizing( MiscTableSizing x )
{ needs_recalc = true; def_slot.sizing = x; }
void setDefaultTag( int x ) { def_tag = x; }
void setDefaultStyle( MiscTableCellStyle x )
{ def_style = x; }
// SELECTION
MiscSparseSet const& selectionSet() const { return selection; }
bool hasSelection() const { return !selection.isEmpty(); }
bool hasMultipleSelection() const;
unsigned int numSelected() const { return selection.count(); }
MiscCoord_V selectedSlot() const { return selected_slot; }
void clearSelectedSlot() { selected_slot = -1; }
void setSelectedSlot( MiscCoord_V x )
{ selected_slot = selection.coerce(x);}
void fixSelectedSlot() { setSelectedSlot(selectedSlot()); }
bool isSelected( MiscCoord_V x ) const { return selection.contains(x);}
void toggle( MiscCoord_V x ) {selection.toggle(x); setSelectedSlot(x);}
void select( MiscCoord_V x ) {selection.add(x); setSelectedSlot(x);}
void select( MiscCoord_V lo, MiscCoord_V hi )
{ selection.add(lo,hi); setSelectedSlot(hi); }
void unselect( MiscCoord_V x )
{ selection.remove(x); fixSelectedSlot(); }
void unselect( MiscCoord_V lo, MiscCoord_V hi )
{ selection.remove(lo,hi); fixSelectedSlot(); }
void selectOne( MiscCoord_V x ) { selection.empty(); select(x); }
void selectAll() { if (count() > 0) { selection.add( 0, count() - 1 );
setSelectedSlot( count() - 1 ); } }
void selectNone() { selection.empty(); clearSelectedSlot(); }
void selectSlots( NSArray* l, bool extend ) // Physical coords.
{ select_slots( l, !extend, true ); }
NSArray* selectedSlots() const { return selected_slots(false); }
void selectTags( NSArray* l, bool extend )
{ select_tags( l, !extend, true ); }
NSArray* selectedTags() const { return selected_slots(true); }
void unselectSlots( NSArray* l ) // Physical coords.
{ select_slots( l, false, false ); }
void unselectTags( NSArray* l ) { select_tags( l, false, false ); }
// KEYBOARD CURSOR
MiscCoord_V getCursor() const { return cursor; }
void setCursor( MiscCoord_V c )
{ if (c >= 0 && c < count()) cursor = c; }
void clearCursor() { setCursor(-1); }
bool hasValidCursor() const { return cursor >= 0 && cursor < count(); }
// CLICKED SLOT
MiscCoord_V clickedSlot() const { return clicked_slot; }
void setClickedSlot( MiscCoord_V s ) { clicked_slot = s; }
void clearClickedSlot() { setClickedSlot(-1); }
// PHYSICAL-COORDINATE CONVENIENCE METHODS.
void deleteAt_P( MiscCoord_P x )
{ deleteAt( physicalToVisual(x) ); }
MiscPixels getOffset_P( MiscCoord_P x )
{ return getOffset( physicalToVisual(x) ); }
MiscPixels effectiveSize_P( MiscCoord_P x )
{ return effectiveSize( physicalToVisual(x) ); }
MiscPixels getSize_P( MiscCoord_P x ) const
{ return getSize( physicalToVisual(x) ); }
MiscPixels getMinSize_P( MiscCoord_P x ) const
{ return getMinSize( physicalToVisual(x) ); }
MiscPixels getMaxSize_P( MiscCoord_P x ) const
{ return getMaxSize( physicalToVisual(x) ); }
MiscPixels getDataSize_P( MiscCoord_P x ) const
{ return getDataSize( physicalToVisual(x) ); }
NSString* getTitle_P( MiscCoord_P x ) const
{ return getTitle( physicalToVisual(x) ); }
int getTag_P( MiscCoord_P x ) const
{ return getTag( physicalToVisual(x) ); }
MiscTableCellStyle getStyle_P( MiscCoord_P x ) const
{ return getStyle( physicalToVisual(x) ); }
id getPrototype_P( MiscCoord_V x )
{ return getPrototype( physicalToVisual(x) ); }
MiscCompareEntryFunc getSortFunc_P( MiscCoord_V x ) const
{ return getSortFunc( physicalToVisual(x) ); }
MiscSortDirection getSortDirection_P( MiscCoord_V x ) const
{ return getSortDirection( physicalToVisual(x) ); }
MiscSortType getSortType_P( MiscCoord_V x ) const
{ return getSortType( physicalToVisual(x) ); }
bool isSortable_P( MiscCoord_P x ) const
{ return isSortable( physicalToVisual(x) ); }
MiscTableSizing getSizing_P( MiscCoord_P x ) const
{ return getSizing( physicalToVisual(x) ); }
bool isFixed_P( MiscCoord_P x ) const
{ return ::isFixed(getSizing_P(x)); }
bool isSpringy_P( MiscCoord_P x ) const
{ return ::isSpringy(getSizing_P(x)); }
bool isSizeable_P( MiscCoord_P x ) const
{ return ::isSizeable(getSizing_P(x)); }
bool isData_P( MiscCoord_P x ) const
{ return ::isData(getSizing_P(x)); }
void setSize_P( MiscCoord_P x, MiscPixels y )
{ setSize( physicalToVisual(x), y ); }
void setMinSize_P( MiscCoord_P x, MiscPixels y )
{ setMinSize( physicalToVisual(x), y ); }
void setMaxSize_P( MiscCoord_P x, MiscPixels y )
{ setMaxSize( physicalToVisual(x), y ); }
void setDataSize_P( MiscCoord_P x, MiscPixels y )
{ setDataSize( physicalToVisual(x), y ); }
bool setTitle_P( MiscCoord_P x, NSString* y )
{ return setTitle( physicalToVisual(x), y ); }
void setTag_P( MiscCoord_P x, int y )
{ setTag( physicalToVisual(x), y ); }
void setStyle_P( MiscCoord_P x, MiscTableCellStyle y )
{ setStyle( physicalToVisual(x), y ); }
void setPrototype_P( MiscCoord_P x, id y )
{ setPrototype( physicalToVisual(x), y ); }
void setSortFunc_P( MiscCoord_P x, MiscCompareEntryFunc y )
{ setSortFunc( physicalToVisual(x), y ); }
void setSortDirection_P( MiscCoord_P x, MiscSortDirection y )
{ setSortDirection( physicalToVisual(x), y ); }
void setSortType_P( MiscCoord_P x, MiscSortType y )
{ setSortType( physicalToVisual(x), y ); }
void setSizing_P( MiscCoord_P x, MiscTableSizing y )
{ setSizing( physicalToVisual(x), y ); }
void setSpringy_P( MiscCoord_P x, bool y )
{ setSpringy( physicalToVisual(x), y ); }
void setSizeable_P( MiscCoord_P x, bool y )
{ setSizeable( physicalToVisual(x), y ); }
void setData_P( MiscCoord_P x, bool y )
{ setData( physicalToVisual(x), y ); }
MiscCoord_P selectedSlot_P() const
{ return visualToPhysical(selected_slot); }
void setSelectedSlot_P( MiscCoord_P x )
{ setSelectedSlot( physicalToVisual(x) ); }
void toggle_P( MiscCoord_P x ) { toggle( physicalToVisual(x) ); }
void select_P( MiscCoord_P x ) { select( physicalToVisual(x) ); }
void unselect_P( MiscCoord_P x ){ unselect( physicalToVisual(x) ); }
bool isSelected_P( MiscCoord_P x ) const
{ return isSelected( physicalToVisual(x) ); }
void selectOne_P( MiscCoord_P x ) { selectOne(physicalToVisual(x)); }
void setCursor_P( MiscCoord_P x ) { setCursor(physicalToVisual(x)); }
MiscCoord_P getCursor_P() const
{ return visualToPhysical(getCursor()); }
MiscCoord_P clickedSlot_P() const
{ return visualToPhysical( clickedSlot() ); }
void setClickedSlot_P( MiscCoord_P x )
{ setClickedSlot( physicalToVisual(x) ); }
// ARCHIVING SUPPORT.
void encodeWithCoder( NSCoder* );
void initWithCoder( NSCoder*, int ver );
};
#endif // __MiscTableBorder_h
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.