Exemplo n.º 1
0
void MCButton::GetFormattedWidth(MCExecContext& ctxt, integer_t& r_width)
{
	// MW-2012-02-16: [[ FontRefs ]] As 'formatted' properties require
	//   access to the font, we must be open before we can compute them.
	if (opened)
	{
		// MW-2007-07-05: [[ Bug 2328 ]] - Formatted width of tab buttons incorrect.
		if (getstyleint(flags) == F_MENU && menumode == WM_TOP_LEVEL)
			r_width = (uinteger_t)formattedtabwidth();
		else
		{
			uint2 fwidth;
			
			MCStringRef t_label = getlabeltext();
			if (MCStringIsEmpty(t_label))
				fwidth = 0;
			else 
                fwidth = leftmargin + rightmargin + MCFontMeasureText(m_font, t_label, getstack() -> getdevicetransform());
			
			if (flags & F_SHOW_ICON && icons != NULL)
			{
				reseticon();
				if (icons->curicon != NULL)
				{
					MCRectangle trect = icons->curicon->getrect();
					if (trect.width > fwidth)
						fwidth = trect.width;
				}
			}
			else
				if (getstyleint(flags) == F_CHECK || getstyleint(flags) == F_RADIO)
					fwidth += CHECK_SIZE + leftmargin;
			if (menumode == WM_OPTION)
				fwidth += optionrect.width + (optionrect.width >> 1);
			if (menumode == WM_CASCADE)
				fwidth += rect.height;
			r_width = fwidth;
		}
	}
	else
Exemplo n.º 2
0
void MCButton::GetStyle(MCExecContext& ctxt, intenum_t& r_style)
{
	uint4 t_style;
	t_style = getstyleint(flags);

	if (t_style == F_MENU && getstack() -> hcaddress())
		r_style = kMCButtonStylePopup;
	else if (F_ROUNDRECT <= t_style && t_style <= F_RECTANGLE)
		r_style = (MCInterfaceButtonStyle)t_style;
	else if (!(flags & F_OPAQUE))
		r_style = kMCButtonStyleTransparent;
	else if (flags & F_SHADOW)
		r_style = kMCButtonStyleShadow;
	else if (!(flags & F_SHOW_BORDER))
		r_style = kMCButtonStyleShowBorder;
	else
		r_style = kMCButtonStyleStandard;
}
Exemplo n.º 3
0
void MCButton::SetMenuMode(MCExecContext& ctxt, intenum_t p_mode)
{
	if (entry != nil)
		deleteentry();
	else
		freemenu(False);

	setmenumode((uint1)p_mode);
	
	if (p_mode == WM_COMBO)
		createentry();
	else if (p_mode == WM_TOP_LEVEL)
	{
		if (getstyleint(flags) == F_MENU)
		{
			MCValueRelease(tabs);
			/* UNCHECKED */ MCStringSplit(menustring, MCSTR("\n"), nil, kMCStringOptionCompareExact, tabs);
		}
	}
	
	Redraw();
}
Exemplo n.º 4
0
Boolean MCScrollbar::mdown(uint2 which)
{
	if (state & CS_MFOCUSED)
		return False;
	if (state & CS_MENU_ATTACHED)
		return MCObject::mdown(which);
	state |= CS_MFOCUSED;
	if (!IsMacEmulatedLF() && flags & F_TRAVERSAL_ON && !(state & CS_KFOCUSED))
		getstack()->kfocusset(this);
	uint2 margin;
	MCRectangle brect = compute_bar();
	if (flags & F_SCALE)
		margin = 0;
	else
		if (getstyleint(flags) == F_VERTICAL)
			margin = brect.width - 1;
		else
			margin = brect.height - 1;
	Tool tool = state & CS_NO_MESSAGES ? T_BROWSE : getstack()->gettool(this);
	MCWidgetInfo winfo;
	winfo.type = (Widget_Type)getwidgetthemetype();
	switch (which)
	{
	case Button1:
		switch (tool)
		{
		case T_BROWSE:
			message_with_args(MCM_mouse_down, "1");
			if (flags & F_PROGRESS) //progress bar does not respond to mouse down event
				return False;
			if (MCcurtheme && MCcurtheme->iswidgetsupported(winfo.type))
			{
				getwidgetthemeinfo(winfo);
				Widget_Part wpart = MCcurtheme->hittest(winfo,mx,my,rect);
				// scrollbar needs to check first if mouse-down occured in arrows
				switch (wpart)
				{
				case WTHEME_PART_ARROW_DEC:
					if (MCmodifierstate & MS_SHIFT)
						mode = SM_BEGINNING;
					else
						mode = SM_LINEDEC;
					break;
				case WTHEME_PART_ARROW_INC:
					if (MCmodifierstate & MS_SHIFT)
						mode = SM_END;
					else
						mode = SM_LINEINC;
					break;
				case WTHEME_PART_TRACK_DEC:
					mode = SM_PAGEDEC;
					break;
				case WTHEME_PART_TRACK_INC:
					mode = SM_PAGEINC;
					break;
				}
			}
			else
			{ //Non-theme appearence stuff: for vertical scrollbar or scale
				if (getstyleint(flags) == F_VERTICAL)
				{
					uint2 height;
					if (brect.height <= margin << 1)
						height = 1;
					else
						height = brect.height - (margin << 1);
					markpos = (my - (brect.y + margin))
					          * fabs(endvalue - startvalue) / height;
					if (my < brect.y + margin)
						if (MCmodifierstate & MS_SHIFT)
							mode = SM_BEGINNING;
						else
							mode = SM_LINEDEC;
					else
						if (my > brect.y + brect.height - margin)
							if (MCmodifierstate & MS_SHIFT)
								mode = SM_END;
							else
								mode = SM_LINEINC;
						else
						{
							MCRectangle thumb = compute_thumb(thumbpos);
							if (my < thumb.y)
								mode = SM_PAGEDEC;
							else
								if (my > thumb.y + thumb.height)
									mode = SM_PAGEINC;
						}
				}
				else
				{ //for Horizontal scrollbar or scale
					uint2 width;
					if (brect.width <= (margin << 1))
						width = 1;
					else
						width = brect.width - (margin << 1);
					markpos = (mx - (brect.x + margin))
					          * fabs(endvalue - startvalue) / width;
					if (mx < brect.x + margin)
						if (MCmodifierstate & MS_SHIFT)
							mode = SM_BEGINNING;
						else
							mode = SM_LINEDEC;
					else
						if (mx > brect.x + brect.width - margin)
							if (MCmodifierstate & MS_SHIFT)
								mode = SM_END;
							else
								mode = SM_LINEINC;
						else
						{
							MCRectangle thumb = compute_thumb(thumbpos);
							if (mx < thumb.x)
								mode = SM_PAGEDEC;
							else
								if (mx > thumb.x + thumb.width)
									mode = SM_PAGEINC;
						}
				}
			} //end of Non-MAC-Appearance Manager stuff
			switch (mode)
			{
			case SM_BEGINNING:
				update(0, MCM_scrollbar_beginning);
				break;
			case SM_END:
				update(endvalue, MCM_scrollbar_end);
				break;
			case SM_LINEDEC:
			case SM_LINEINC:
				timer(MCM_internal, NULL);
				redrawarrow(mode);
				break;
			case SM_PAGEDEC:
			case SM_PAGEINC:
				timer(MCM_internal, NULL);
				break;
			default:
				state |= CS_SCROLL;
				markpos = thumbpos;
				if (IsMacEmulatedLF())
					movethumb(thumbpos--);
				else if (MCcurtheme)
				{
					// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
					redrawall();
				}
			}
			break;
		case T_POINTER:
		case T_SCROLLBAR:
			start(True);
			break;
		case T_HELP:
			break;
		default:
			return False;
		}
		break;
	case Button2:
		if (message_with_args(MCM_mouse_down, "2") == ES_NORMAL)
			return True;
		state |= CS_SCROLL;
		{
			real8 newpos;
			real8 range = endvalue - startvalue;
			real8 offset = startvalue;
			if (flags & F_SCALE)
				margin = MOTIF_SCALE_THUMB_SIZE >> 1;
			else
				if (MCproportionalthumbs)
					if (startvalue > endvalue)
						offset += thumbsize / 2.0;
					else
						offset -= thumbsize / 2.0;
				else
					margin = FIXED_THUMB_SIZE >> 1;
			if (getstyleint(flags) == F_VERTICAL)
				newpos = (my - brect.y - margin) * range
				         / (brect.height - (margin << 1)) + offset;
			else
				newpos = (mx - brect.x - margin) * range
				         / (brect.width - (margin << 1)) + offset;
			update(newpos, MCM_scrollbar_drag);
			markpos = thumbpos;
		}
		break;
	case Button3:
		message_with_args(MCM_mouse_down, "3");
		break;
	}
Exemplo n.º 5
0
Boolean MCScrollbar::mfocus(int2 x, int2 y)
{
	// MW-2007-09-18: [[ Bug 1650 ]] Disabled state linked to thumb size
	if (!(flags & F_VISIBLE || MCshowinvisibles)
	        || issbdisabled() && getstack()->gettool(this) == T_BROWSE)
		return False;
	if (state & CS_SCROLL)
	{
		// I.M. [[bz 9559]] disable scrolling where start value & end value are the same
		if (startvalue == endvalue)
			return True;

		real8 newpos;

		double t_thumbsize = thumbsize;
		if (t_thumbsize > fabs(endvalue - startvalue))
			t_thumbsize = fabs(endvalue - startvalue);
		if (flags & F_SCALE)
			t_thumbsize = 0;

		bool t_forward;
		t_forward = (endvalue > startvalue);
		MCRectangle t_bar_rect, t_thumb_rect, t_thumb_start_rect, t_thumb_end_rect;
		t_bar_rect = compute_bar();
		t_thumb_rect = compute_thumb(markpos);
		t_thumb_start_rect = compute_thumb(startvalue);
		if (t_forward)
			t_thumb_end_rect = compute_thumb(endvalue - t_thumbsize);
		else
			t_thumb_end_rect = compute_thumb(endvalue + t_thumbsize);

		int32_t t_bar_start, t_bar_length, t_thumb_start, t_thumb_length;
		int32_t t_movement;
		if (getstyleint(flags) == F_VERTICAL)
		{
			t_bar_start = t_thumb_start_rect.y;
			t_bar_length = t_thumb_end_rect.y + t_thumb_end_rect.height - t_bar_start;
			t_thumb_start = t_thumb_rect.y;
			t_thumb_length = t_thumb_rect.height;
			t_movement = y - my;
		}
		else
		{
			t_bar_start = t_thumb_start_rect.x;
			t_bar_length = t_thumb_end_rect.x + t_thumb_end_rect.width - t_bar_start;
			t_thumb_start = t_thumb_rect.x;
			t_thumb_length = t_thumb_rect.width;
			t_movement = x - mx;
		}

		t_bar_start += t_thumb_length / 2;
		t_bar_length -= t_thumb_length;

        // AL-2013-07-26: [[ Bug 11044 ]] Prevent divide by zero when computing scrollbar thumbposition
        if (t_bar_length == 0)
            t_bar_length = 1;
        
		int32_t t_new_position;
		t_new_position = t_thumb_start + t_thumb_length / 2 + t_movement;
		t_new_position = MCU_min(t_bar_start + t_bar_length, MCU_max(t_bar_start, t_new_position));
		
		if (t_forward)
			newpos = startvalue + ((t_new_position - t_bar_start) / (double)t_bar_length) * (fabs(endvalue - startvalue) - t_thumbsize);
		else
			newpos = startvalue - ((t_new_position - t_bar_start) / (double)t_bar_length) * (fabs(endvalue - startvalue) - t_thumbsize);

		update(newpos, MCM_scrollbar_drag);
		return True;
	}
	else if (!MCdispatcher -> isdragtarget() && MCcurtheme && MCcurtheme->getthemepropbool(WTHEME_PROP_SUPPORTHOVERING)
	         && MCU_point_in_rect(rect, x, y) )
	{
		if (!(state & CS_MFOCUSED) && !getstate(CS_SELECTED))
		{
			MCWidgetInfo winfo;
			winfo.type = (Widget_Type)getwidgetthemetype();
			if (MCcurtheme->iswidgetsupported(winfo.type))
			{
				getwidgetthemeinfo(winfo);
				Widget_Part wpart = MCcurtheme->hittest(winfo,mx,my,rect);
				if (wpart != hover_part)
				{
					hover_part = wpart;
					// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
					redrawall();
				}
			}
		}
	}
	return MCControl::mfocus(x, y);
}
void MCScrollbar::GetOrientation(MCExecContext& ctxt, intenum_t& r_style)
{
	r_style = getstyleint(flags);
}