<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">###############################################################################
#
#   Package: NaturalDocs::Menu::Entry
#
###############################################################################
#
#   A class representing an entry in the menu.
#
###############################################################################

# This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure
# Natural Docs is licensed under the GPL

use strict;
use integer;

package NaturalDocs::Menu::Entry;


###############################################################################
# Group: Implementation

#
#   Constants: Members
#
#   The object is implemented as a blessed arrayref with the indexes below.
#
#       TYPE      - The &lt;MenuEntryType&gt;
#       TITLE     - The title of the entry.
#       TARGET  - The target of the entry.  If the type is &lt;MENU_FILE&gt;, it will be the source &lt;FileName&gt;.  If the type is
#                       &lt;MENU_LINK&gt;, it will be the URL.  If the type is &lt;MENU_GROUP&gt;, it will be an arrayref of
#                       &lt;NaturalDocs::Menu::Entry&gt; objects representing the group's content.  If the type is &lt;MENU_INDEX&gt;, it will be
#                       a &lt;TopicType&gt;.
#       FLAGS    - Any &lt;Menu Entry Flags&gt; that apply.
#
use constant TYPE =&gt; 0;
use constant TITLE =&gt; 1;
use constant TARGET =&gt; 2;
use constant FLAGS =&gt; 3;
# DEPENDENCY: New() depends on the order of these constants.


###############################################################################
# Group: Functions

#
#   Function: New
#
#   Creates and returns a new object.
#
#   Parameters:
#
#       type     - The &lt;MenuEntryType&gt;.
#       title      - The title of the entry.
#       target   - The target of the entry, if applicable.  If the type is &lt;MENU_FILE&gt;, use the source &lt;FileName&gt;.  If the type is
#                     &lt;MENU_LINK&gt;, use the URL.  If the type is &lt;MENU_INDEX&gt;, use the &lt;TopicType&gt;.  Otherwise set it to undef.
#       flags     - Any &lt;Menu Entry Flags&gt; that apply.
#
sub New #(type, title, target, flags)
    {
    # DEPENDENCY: This gode depends on the order of the constants.

    my $package = shift;

    my $object = [ @_ ];
    bless $object, $package;

    if ($object-&gt;[TYPE] == ::MENU_GROUP())
        {  $object-&gt;[TARGET] = [ ];  };
    if (!defined $object-&gt;[FLAGS])
        {  $object-&gt;[FLAGS] = 0;  };

    return $object;
    };


#   Function: Type
#   Returns the &lt;MenuEntryType&gt;.
sub Type
    {  return $_[0]-&gt;[TYPE];  };

#   Function: Title
#   Returns the title of the entry.
sub Title
    {  return $_[0]-&gt;[TITLE];  };

# Function: SetTitle
# Replaces the entry's title.
sub SetTitle #(title)
    {  $_[0]-&gt;[TITLE] = $_[1];  };

#
#   Function: Target
#
#   Returns the target of the entry, if applicable.  If the type is &lt;MENU_FILE&gt;, it returns the source &lt;FileName&gt;.  If the type is
#   &lt;MENU_LINK&gt;, it returns the URL.  If the type is &lt;MENU_INDEX&gt;, it returns the &lt;TopicType&gt;.  Otherwise it returns undef.
#
sub Target
    {
    my $self = shift;

    # Group entries are the only time when target won't be undef when it should be.
    if ($self-&gt;Type() == ::MENU_GROUP())
        {  return undef;  }
    else
        {  return $self-&gt;[TARGET];  };
    };

# Function: SetTarget
# Replaces the entry's target.
sub SetTarget #(target)
    {  $_[0]-&gt;[TARGET] = $_[1];  };

#   Function: Flags
#   Returns the &lt;Menu Entry Flags&gt;.
sub Flags
    {  return $_[0]-&gt;[FLAGS];  };

# Function: SetFlags
# Replaces the &lt;Menu Entry Flags&gt;.
sub SetFlags #(flags)
    {  $_[0]-&gt;[FLAGS] = $_[1];  };



###############################################################################
# Group: Group Functions
#
#   All of these functions assume the type is &lt;MENU_GROUP&gt;.  Do *not* call any of these without checking &lt;Type()&gt; first.


#
#   Function: GroupContent
#
#   Returns an arrayref of &lt;NaturalDocs::Menu::Entry&gt; objects representing the contents of the
#   group, or undef otherwise.  This arrayref will always exist for &lt;MENU_GROUP&gt;'s and can be changed.
#
sub GroupContent
    {
    return $_[0]-&gt;[TARGET];
    };


#
#   Function: GroupIsEmpty
#
#   If the type is &lt;MENU_GROUP&gt;, returns whether the group is empty.
#
sub GroupIsEmpty
    {
    my $self = shift;
    return (scalar @{$self-&gt;GroupContent()} &gt; 0);
    };


#
#   Function: PushToGroup
#
#   Pushes the entry to the end of the group content.
#
sub PushToGroup #(entry)
    {
    my ($self, $entry) = @_;
    push @{$self-&gt;GroupContent()}, $entry;
    };


#
#   Function: DeleteFromGroup
#
#   Deletes an entry from the group content by index.
#
sub DeleteFromGroup #(index)
    {
    my ($self, $index) = @_;

    my $groupContent = $self-&gt;GroupContent();

    splice( @$groupContent, $index, 1 );
    };


#
#   Function: MarkEndOfOriginal
#
#   If the group doesn't already have one, adds a &lt;MENU_ENDOFORIGINAL&gt; entry to the end and sets the
#   &lt;MENU_GROUP_HASENDOFORIGINAL&gt; flag.
#
sub MarkEndOfOriginal
    {
    my $self = shift;

    if (($self-&gt;Flags() &amp; ::MENU_GROUP_HASENDOFORIGINAL()) == 0)
        {
        $self-&gt;PushToGroup( NaturalDocs::Menu::Entry-&gt;New(::MENU_ENDOFORIGINAL(), undef, undef, undef) );
        $self-&gt;SetFlags( $self-&gt;Flags() | ::MENU_GROUP_HASENDOFORIGINAL() );
        };
    };


1;
</pre></body></html>