/****************************************************************************
 *   Copyright (C) 2004 by Arboretum Systems, Inc.                          *
 *   Technical administrator: Alain Mazy, hav@mazy.be                       *
 *   Lead program designer: Georges Jaroslaw, gjaro@arboretum.com           *
 *                                                                          *
 *   HyperEngine-AV is a video, audio and text editor that can be used to   *
 *   record, import, edit, process and arrange together video, sound and    *
 *   text. These are all achieved in the program's free-form document       *
 *   window, with no limitations to the number of tracks.                   *
 *   The purpose of this program is to provide to users at all levels of    *
 *   expertise a readily accessible tool enabling them to create movies,    *
 *   slide shows or presentations.                                          *
 *                                                                          *
 *   HyperEngine-AV itself is free software. However, plug-ins that can be  *
 *   used as add-ons to HyperEngine-AV may or may not be free software, at  *
 *   the discretion of each plug-in developer and as specified by these     *
 *   plug-ins' respective licenses.                                         *
 *   You can redistribute HyperEngine-AV itself and/or modify it under the  *
 *   terms of the GNU General Public License as published by the Free       *
 *   Software Foundation; either version 2 of the License, or (at your      *
 *   option) any later version.                                             *
 *                                                                          *
 *   HyperEngine-AV is distributed in the hope that it will be useful, but  *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of             *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *   GNU General Public License for all applicable details.                 *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program; if not, write to:                             *
 *   Free Software Foundation, Inc.,                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
 ****************************************************************************/

#import "MIContainerRep.h"
#import "MIImageController.h"
#import "MIObject.h"
#import "MISliceSelectionTracker.h"
#import "MITopLevelContainerRep.h"
#import "MIMainViewController.h"
#import "MIWSSelection.h"

@implementation MIContainerRep

- (id)initWithFrame:(NSRect)frame inTLC:(MITopLevelContainerRep*)theTLC
{
    self = [super initWithFrame:frame inTLC:theTLC];
	//fLeftBarImage = mainImageController->fContainerGroupBarOnLeft;
    //fCenterBarImage = mainImageController->fContainerGroupBarOnCenter;
    //fRightBarImage = mainImageController->fContainerGroupBarOnRight;

	fHasTopBottomHandles = YES;
	fHasLeftRightHandles = YES;
	fHasCollapseButton = NO;
	fHasPropertiesButton = NO;
	fHasOnOffButton = NO;
	
    return self;
}

- (void)setImagesAndColor
{
	if ( [self isSelected] && [[[fTLCRep mainViewController] selection] type] == kMIWSSelectionTypeObjects )
	{
		[self setBackgroundColor:mainImageController->fGroupNegativeColor];
		fLeftTitleImage = mainImageController->fLeftGroupNegativeTitleBarImage;
		fCenterTitleImage = mainImageController->fCenterGroupNegativeTitleBarImage;
		fRightTitleImage = mainImageController->fRightGroupNegativeTitleBarImage;
	}
	else if ( [fRepresentedObject isMuted] )
	{
		[self setBackgroundColor:mainImageController->fGroupDimColor];
		fLeftTitleImage = mainImageController->fLeftGroupDimTitleBarImage;
		fCenterTitleImage = mainImageController->fCenterGroupDimTitleBarImage;
		fRightTitleImage = mainImageController->fRightGroupDimTitleBarImage;
	}
	else 
	{
		[self setBackgroundColor:mainImageController->fGroupBrightColor];
		fLeftTitleImage = mainImageController->fLeftGroupBrightTitleBarImage;
		fCenterTitleImage = mainImageController->fCenterGroupBrightTitleBarImage;
		fRightTitleImage = mainImageController->fRightGroupBrightTitleBarImage;
	}
}
/*
  $$$TODO $$$ALAIN $$$STEPHAN

- (void)toggleOnOff
{
	[super toggleOnOff];

	[fRepresentedObject WSObject]->Enable([fRepresentedObject isTurnedOn]);
}
*/

- (MIObjectMouseHandling)handleMoreMouseTracking:(NSPoint)mouseLoc modifier:(unsigned int)modifier type:(NSEventType)type
{
	MIObjectMouseHandling answer;
	
	// our frame
	NSRect myFrame = [self frame];
	myFrame.origin = NSZeroPoint;

	answer = [super handleMoreMouseTracking:mouseLoc modifier:modifier type:type];
	// if the parent does NOT handle it, and if we are in the body, let's create a selection tracker (if option is pressed)
	if((answer == MIContinueMouseHandling) && (mouseLoc.y < (NSMaxY(myFrame) - [fCenterTitleImage size].height)) && ( modifier & NSAlternateKeyMask ) )
	{
		fTemporaryTracker = [[MISliceSelectionTracker alloc] initWithObjectRep:self inView:fTLCRep 
		atPos:[self convertPointToTLCCoords:mouseLoc] withModifiers:nil];
		return MIAskMeATracker;
	}
	else
	{
		return answer;
	}
}

- (void)drawBaseBodyRect:(NSRect)frameInDrawCoords clippedTo:(NSRect)clippingRect
{
	float titleHeight;
	
#ifdef SCALABLE_TITLEBAR
	titleHeight = [[self getTopLevelContainerRep] MIVPosToPixel:[fRepresentedObject getTitleHeight]];
#else
	titleHeight = kRepTitleHeight;
#endif

	[super drawBaseBodyRect:frameInDrawCoords clippedTo:clippingRect];

	if ( ![fRepresentedObject isCollapsed] )
	{
		[mainImageController->fResizeIndicatorDownLeft compositeToPoint:frameInDrawCoords.origin operation:NSCompositeSourceAtop];
		[mainImageController->fResizeIndicatorDownRight compositeToPoint:NSMakePoint(NSMaxX(frameInDrawCoords)-11, NSMinY(frameInDrawCoords)) operation:NSCompositeSourceAtop];

		[mainImageController->fResizeIndicatorUpLeft compositeToPoint:NSMakePoint(NSMinX(frameInDrawCoords), NSMaxY(frameInDrawCoords)- 11) operation:NSCompositeSourceAtop];
		[mainImageController->fResizeIndicatorUpRight compositeToPoint:NSMakePoint(NSMaxX(frameInDrawCoords)-11, NSMaxY(frameInDrawCoords)- 11) operation:NSCompositeSourceAtop];		
	}
}

@end
