Example #1
0
void AnimationObjectPlayFwdBack( WindowObjectType *wo )
{

	AnimationObjectType	*a;

	a =  wo->animationObject;
	if( ! a ) {
		a = wo->animationObject = AnimationObjectCreate( wo );
		if( ! a ) 
			return;
	}

/*
 *	See if we have enough frames in the loop for an animation
 */
	if ( CountEligibleFrames ( wo ) < 2 ) return;
		
/*
 *	Start things going by setting the animation flag and
 *	scheduling the animation to start...
 */
	a->direction   = FORWARD;
	a->command     = LOOPFORWARDBACKWARD;
	if ( ! a->isAnimating ) {
		a->isAnimating = True;
		ScheduleAnimation( a );
	}
	
	return;

}
void FormElementOfInterest::DoActivate()
{
	((OpButton*)source)->Click();
	((OpButton*)clone)->SetValue(source->GetValue());
	source->SetFocus(FOCUS_REASON_MOUSE);

	OpRect bigger_dest(dest_rect.x - dest_rect.width * 2, dest_rect.y - dest_rect.height * 2, dest_rect.width *4 , dest_rect.height * 4);
	ScheduleAnimation(dest_rect, 1.0f, bigger_dest, 0.0f, 400);

}
OP_STATUS FormElementOfInterest::MakeClone(BOOL expanded)
{
	OpRect anim_start_rect;
	float  anim_start_opacity = 0.0f;
	if (expanded)
	{
		if (GetElementExpander()->GetState() == EE_EXPANDED)
		{
			anim_start_rect = dest_rect;
			anim_start_opacity = 1.0f;
		}
		else
		{
			anim_start_rect = orig_rect;
		}
	}

	OpWidget *old_widget = clone;
	OpWidget *root = widget_container->GetRoot();

	RETURN_IF_ERROR(source->CreateClone(&clone, root, WIDGETS_F_T_FONTSIZE, expanded));

	if (old_widget)
	{
		old_widget->Remove();
		old_widget->Delete();
	}

	INT32 cols = 20;
	INT32 rows = GetPreferredNumberOfRows(expanded);

	int minimum_size = (ElementExpander::GetFingertipPixelRadius(widget_container->GetWindow()) - LAYER_PADDING) * 2;
	int preferred_w = MAX(minimum_size, source->GetBounds().width);
	int preferred_h = MAX(MAX(minimum_size, source->GetBounds().height), dest_rect.height);
	minimum_size = GetElementExpander()->GetElementMinimumSize();
	if (preferred_w < minimum_size)
		preferred_w = minimum_size;
	if (preferred_h < minimum_size)
		preferred_h = minimum_size;

	clone->GetVisualDevice()->SetFont(font);
	clone->GetPreferedSize(&preferred_w, &preferred_h, cols, rows);
	clone->SetListener(this);

	OpRect visible_rect;
	GetElementExpander()->GetAvailableRect(visible_rect);

	// Limit size to screensize
	preferred_w = MIN(preferred_w, visible_rect.width - LAYER_PADDING * 2);
	preferred_h = MIN(preferred_h, visible_rect.height - LAYER_PADDING * 2);

	widget_a_frag->SetRect(OpRect(LAYER_PADDING, LAYER_PADDING, preferred_w, preferred_h), 0);

	// Calculate new dest_rect
	int total_w = 0;
	int total_h = preferred_h;
	int x = LAYER_PADDING;

	for (AnchorFragment* fragment = (AnchorFragment*) region.First(); fragment; fragment = fragment->Suc())
	{
		int y = preferred_h + LAYER_PADDING * 2 - fragment->GetHeight();
		TextAnchorFragment *text_anchor_frag = fragment->GetTextAnchorFragment();
		if (text_anchor_frag)
		{
			RETURN_IF_ERROR(text_anchor_frag->UpdateWidgetString(root, GetMaxWidth() - preferred_w, FALSE));
		}

		int frag_w = fragment->GetWidth();
		int frag_h = fragment->GetHeight();

		// Checkbox and radiobutton captions should not be too close to the image.
		if (text_anchor_frag)
		{
			switch (clone->GetType())
			{
				case OpTypedObject::WIDGET_TYPE_RADIOBUTTON:
				case OpTypedObject::WIDGET_TYPE_CHECKBOX:
					// TODO: Adapt this to RTL languages!
					y = (frag_h + LAYER_BG_PADDING * 2 - font.GetHeight() + (preferred_h - frag_h)) / 2;
					x += 5;
					frag_w += 5;
					break;
			}
		}

		fragment->SetPos(x, y);

		total_w += frag_w;
		total_h = MAX(total_h, frag_h);
		x += frag_w;
    }

	int y = LAYER_PADDING;
	switch (clone->GetType())
	{
		case OpTypedObject::WIDGET_TYPE_RADIOBUTTON:
		case OpTypedObject::WIDGET_TYPE_CHECKBOX:
			y = (total_h+2*LAYER_PADDING-preferred_h)/2;
			break;
	}

	clone->SetRect(OpRect(LAYER_PADDING, y, preferred_w, preferred_h));

	dest_rect.width = total_w;
	dest_rect.height = total_h;

	if (expanded)
	{
		dest_rect.width += LAYER_PADDING * 2;
		dest_rect.height += LAYER_PADDING * 2;
		ElementExpanderImpl::SmartPositionRectInRect(dest_rect, visible_rect,
													 ElementExpanderImpl::EDGE_NORTH,
													 ElementExpanderImpl::EDGE_WEST);
		AdjustSize();
		ScheduleAnimation(anim_start_rect, anim_start_opacity, dest_rect, 1.0f, 400);
	}
	else
	{
		AdjustSize();
	}

	return OpStatus::OK;
}