Beispiel #1
0
void set_window (int limit, int x)
{
  if (limit)
  {
    WindowLimits (Window,
		  RastPort->cp_x + RastPort->TxWidth + Window->BorderRight + x,
		  Window->BorderTop + Window->BorderBottom + (RastPort->TxHeight * 3), ~0, ~0);
  }
  else
  {
    WindowLimits (Window, Window->Width, Window->Height, Window->Width,
		  Window->Height);
  }
}
// Set size limit for a lister
void lister_set_limits(Lister *lister)
{
	short width,height;

	// In zoomed mode?
	if (lister->more_flags&LISTERF_TITLEBARRED)
		return;

	// Calculate limits
	lister_calc_limits(lister,lister->window->WScreen);

	// Get current lister size
	width=lister->window->Width;
	height=lister->window->Height;

	// Bounds check
	if (width<lister->win_limits.Left)
		width=lister->win_limits.Left;
	if (height<lister->win_limits.Top)
		height=lister->win_limits.Top;

	// Need to resize?
	if (width!=lister->window->Width ||
		height!=lister->window->Height)
	{
		// Set to infinite limits
		WindowLimits(
			lister->window,
			1,1,
			(UWORD)~0,(UWORD)~0);

		// Change size
		ChangeWindowBox(
			lister->window,
			lister->window->LeftEdge,
			lister->window->TopEdge,
			width,
			height);
	}

	// Set window limits
	WindowLimits(
		lister->window,
		lister->win_limits.Left,
		lister->win_limits.Top,
		(UWORD)~0,
		(UWORD)~0);
}
Beispiel #3
0
// Open font window
BOOL font_open(font_data *data)
{
	struct Screen *screen=NULL;

	// Screen supplied?
	if (data->arg_array[ARG_SCREEN])
		screen=LockPubScreen((char *)data->arg_array[ARG_SCREEN]);	

	// Fill out new window
	data->new_win.parent=screen;
	data->new_win.dims=&data->win_dims;
	data->new_win.title=GetString(&data->locale,MSG_FONT_TITLE);
	data->new_win.locale=&data->locale;
	data->new_win.flags=WINDOW_SCREEN_PARENT|WINDOW_VISITOR|WINDOW_AUTO_KEYS|WINDOW_SIZE_BOTTOM|WINDOW_SIMPLE;

	// Default dimensions
	data->win_dims=font_window;

	// Read settings
	font_read_settings(data);

	// Open window
	if ((data->window=OpenConfigWindow(&data->new_win)))
		data->list=AddObjectList(data->window,font_objects);

	// Unlock screen
	UnlockPubScreen(0,screen);

	// Failed to open?
	if (!data->list) return FALSE;

	// Fix sizing limits
	WindowLimits(data->window,
		(font_window.char_dim.Width*data->window->RPort->TxWidth)+font_window.fine_dim.Width,
		(font_window.char_dim.Height*data->window->RPort->TxHeight)+font_window.fine_dim.Height,
		~0,~0);

	// Add menus
	AddWindowMenus(data->window,font_menus);

	// Add AppWindow
	if (data->appport)
		data->appwindow=AddAppWindowA(0,0,data->window,data->appport,0);

	// Get the font
	font_get_font(data);
	return TRUE;
}
// Refresh buttons display
void buttons_refresh(Buttons *buttons,ULONG type)
{
	int x,y;
	Cfg_Button *button;

	// Lock bank
	GetSemaphore(&buttons->bank->lock,SEMF_SHARED,0);

	// Make selector visible
	if (type&BUTREFRESH_SELECTOR)
	{
		if (buttons_visible_select(buttons))
			type|=BUTREFRESH_REFRESH;
	}

	// Font reset
	if (type&BUTREFRESH_FONT)
	{
		// See if font has changed
		if ((strcmp(
			buttons->window->RPort->Font->tf_Message.mn_Node.ln_Name,
			buttons->bank->window.font_name))!=0 ||
			buttons->window->RPort->Font->tf_YSize!=buttons->bank->window.font_size)
		{
			// Get new font
			buttons_get_font(buttons);

			// Do full reset
			type=BUTREFRESH_RESIZE|BUTREFRESH_REFRESH;

			// Clear resized flag
			buttons->flags&=~BUTTONF_RESIZED;
		}
	}

	// Resize event?
	if (type&BUTREFRESH_RESIZE)
	{
		unsigned short min_width,min_height;
		unsigned short max_width,max_height;
		short border_x=0,border_y=0;

		// Borderless window?
		if (buttons->flags&BUTTONF_BORDERLESS)
		{
			ULONG flags;
			short old_width,old_height;
			ULONG old_border;

			// Save drag gadget flags and size
			flags=buttons->drag_gadget.Flags;
			old_width=buttons->drag_gadget.Width;
			old_height=buttons->drag_gadget.Height;
			old_border=buttons->border_type;

			// See if drag bar orientation has changed
			if (buttons_fix_drag(buttons))
			{
				short width,height;

				// Get current width/height
				width=buttons->window->Width;
				height=buttons->window->Height;

				// If bar is now horizontal, it used to be vertical
				if (buttons->drag_gadget.Flags&GFLG_RELWIDTH && flags&GFLG_RELHEIGHT)
				{
					// Adjust accordingly
					width-=old_width;
					height+=buttons->drag_gadget.Height;
				}

				// And vice versa
				else
				if (buttons->drag_gadget.Flags&GFLG_RELHEIGHT && flags&GFLG_RELWIDTH)
				{
					// Adjust
					height-=old_height;
					width+=buttons->drag_gadget.Width;
				}

				// No drag bar
				else
				if (!(buttons->drag_gadget.Flags&(GFLG_RELWIDTH|GFLG_RELHEIGHT)))
				{
					// Adjust size
					if (flags&GFLG_RELHEIGHT)
					{
						if (old_border&BTNWF_RIGHT_BELOW) border_x=old_width;
						width-=old_width;
					}
					else
					if (flags&GFLG_RELWIDTH)
					{
						if (old_border&BTNWF_RIGHT_BELOW) border_y=old_height;
						height-=old_height;
					}
				}

				// State of right/below flag changed
				else
				if (!(old_border&BTNWF_RIGHT_BELOW) && (buttons->bank->window.flags&BTNWF_RIGHT_BELOW))
				{
					// Move window up or right depending on border
					if (buttons->bank->window.flags&BTNWF_HORIZ)
						border_y=-((GUI->screen_info&SCRI_LORES)?DRAG_LO_HEIGHT:DRAG_HI_HEIGHT);
					else
					if (buttons->bank->window.flags&BTNWF_VERT)
						border_x=-DRAG_WIDTH;
				}

				// Is size not changing?
				if (buttons->window->Width==width && buttons->window->Height==height)
				{
					// Refresh buttons display
					type|=BUTREFRESH_REFRESH;
					RefreshGList(&buttons->drag_gadget,buttons->window,0,1);
				}

				// Size is changing so window will be refreshed automatically
				else
				{
					// Resize window
					ChangeWindowBox(
						buttons->window,
						buttons->window->LeftEdge+border_x,buttons->window->TopEdge+border_y,
						width,height);
					buttons->flags|=BUTTONF_RESIZED;
				}

				// Recalculate internal size
				buttons_fix_internal(buttons);
			}

			// Refresh drag gadget
			else
			{
				RefreshGList(&buttons->drag_gadget,buttons->window,0,1);
			}
		}

		// Get the maximum size of a button
		buttons_get_max_size(buttons,&max_width,&max_height);

		// Graphical buttons?
		if (buttons->bank->window.flags&BTNWF_GFX)
		{
			// Maximum is also minimum
			min_width=max_width;
		}

		// Text buttons
		else
		{
			// Get minimum width
			min_width=TextLength(buttons->window->RPort,"a",1)*6;

			// Border?
			if (!(buttons->flags&BUTTONF_BORDERLESS))
			{
				// Calculate button size from window
				max_width=buttons->window->GZZWidth/buttons->bank->window.columns;
			}

			// Is button width less than minimum?
			if (max_width<min_width) max_width=min_width;
		}

		// Store button size
		buttons->button_width=max_width;
		buttons->button_height=max_height;

		// No border or toolbar?
		if (buttons->flags&(BUTTONF_BORDERLESS|BUTTONF_TOOLBAR))
		{
			short side_borders,top_borders;

			// Start with maximum columns/rows
			buttons->button_cols=buttons->bank->window.columns;
			buttons->button_rows=buttons->bank->window.rows;

			// Calculate window size
			max_width=buttons->button_width*buttons->button_cols;
			max_height=buttons->button_height*buttons->button_rows;

			// Calculate border sizes
			side_borders=buttons->window->Width-buttons->internal.Width;
			top_borders=buttons->window->Height-buttons->internal.Height;

			// Too big for screen?
			if (max_width+side_borders>buttons->window->WScreen->Width)
			{
				buttons->button_cols=(buttons->window->WScreen->Width-side_borders)/buttons->button_width;
				max_width=buttons->button_cols*buttons->button_width;
			}
			if (max_height+top_borders>buttons->window->WScreen->Height)
			{
				buttons->button_rows=(buttons->window->WScreen->Height-top_borders)/buttons->button_height;
				max_height=buttons->button_rows*buttons->button_height;
			}

			// Add border size
			max_width+=side_borders;
			max_height+=top_borders;

			// Minimum is the maximum
			min_width=max_width;
			min_height=max_height;
		}

		// Normal borders
		else
		{
			// Get columns/rows
			buttons->button_cols=buttons->window->GZZWidth/buttons->button_width;
			buttons->button_rows=buttons->window->GZZHeight/buttons->button_height;

			// Check columns/rows don't exceed actual number of buttons
			if (buttons->button_cols>buttons->bank->window.columns)
				buttons->button_cols=buttons->bank->window.columns;
			if (buttons->button_rows>buttons->bank->window.rows)
				buttons->button_rows=buttons->bank->window.rows;

			// Get window minimum size
			min_width+=buttons->window->BorderLeft+buttons->window->BorderRight;
			min_height=buttons->window->BorderTop+buttons->window->BorderBottom+buttons->button_height;

			// Get window maximum size
			max_width=(!(buttons->bank->window.flags&BTNWF_GFX))?buttons->window->WScreen->Width:
				buttons->window->BorderLeft+
				buttons->window->BorderRight+
				buttons->bank->window.columns*buttons->button_width;
			max_height=
				buttons->window->BorderTop+
				buttons->window->BorderBottom+
				buttons->button_height*buttons->bank->window.rows;
		}

		// Set window limits
		WindowLimits(buttons->window,0,0,(ULONG)-1,(ULONG)-1);

		// See if window size can be changed
		if (!(buttons->flags&BUTTONF_RESIZED))
		{
			short width,height;

			// No border?
			if (buttons->flags&BUTTONF_BORDERLESS)
			{
				// Get desired size
				width=max_width;
				height=max_height;
			}

			// Normal borders
			else
			{
				// Get initial size
				width=buttons->window->Width;
				height=buttons->window->Height;

				// Is window narrower than minimum?
				if (buttons->window->Width<min_width) width=min_width;

				// Or wider than maximum?
				else
				if (buttons->window->Width>max_width) width=max_width;

				// Otherwise, size to button boundary
				else
				{
					// Drop back to last whole column
					width-=buttons->window->GZZWidth-(buttons->button_cols*buttons->button_width);

					// Size to make window bigger?
					if (buttons->window->Width>buttons->last_position.Width &&
						buttons->button_cols<buttons->bank->window.columns)
					{
						short new_width;

						// Get new width
						new_width=width+buttons->button_width;

						// Would this be legal?
						if (buttons->window->LeftEdge+new_width<=buttons->window->WScreen->Width)
							width=new_width;
					}
				}

				// Is window shorter than minimum?
				if (buttons->window->Height<min_height) height=min_height;

				// Or taller than maximum?
				else
				if (buttons->window->Height>max_height) height=max_height;

				// Otherwise, size to button boundary
				else
				{
					// Drop back to last whole row
					height-=buttons->window->GZZHeight-(buttons->button_rows*buttons->button_height);

					// Size to make window bigger?
					if (buttons->window->Height>buttons->last_position.Height &&
						buttons->button_rows<buttons->bank->window.rows)
					{
						short new_height;

						// Get new height
						new_height=height+buttons->button_height;

						// Would this be legal?
						if (buttons->window->TopEdge+new_height<=buttons->window->WScreen->Height)
							height=new_height;
					}
				}
			}

			// Does window need to be resized?
			if (buttons->window->Width!=width ||
				buttons->window->Height!=height)
			{
				// Resize window
				ChangeWindowBox(
					buttons->window,
					buttons->window->LeftEdge+border_x,buttons->window->TopEdge+border_y,
					width,height);
				buttons->flags|=BUTTONF_RESIZED;

				// Set window limits
				WindowLimits(buttons->window,
					min_width,
					min_height,
					max_width,
					max_height);

				// Unlock bank
				FreeSemaphore(&buttons->bank->lock);
				return;
			}
		}

		// Returned from a resize; refresh frame
		else RefreshWindowFrame(buttons->window);

		// Save window position
		buttons->last_position=*((struct IBox *)&buttons->window->LeftEdge);

		// Set window limits
		WindowLimits(buttons->window,
			min_width,
			min_height,
			max_width,
			max_height);

		// Fix sliders
		if (buttons->vert_scroll)
		{
			SetGadgetAttrs(buttons->vert_scroll,buttons->window,0,
				PGA_Total,buttons->bank->window.rows,
				PGA_Visible,buttons->button_rows,
				TAG_END);
		}
		if (buttons->horiz_scroll)
		{
			SetGadgetAttrs(buttons->horiz_scroll,buttons->window,0,
				PGA_Total,buttons->bank->window.columns,
				PGA_Visible,buttons->button_cols,
				TAG_END);
		}

		// Make sure selector is visible
		if (buttons->editor) buttons_visible_select(buttons);
	}

	// Refresh event
	if (type&BUTREFRESH_REFRESH)
	{
		// Get vertical position
		if (buttons->vert_scroll)
			GetAttr(PGA_Top,buttons->vert_scroll,(ULONG *)&buttons->button_top);
		else buttons->button_top=0;

		// Horizontal
		if (buttons->horiz_scroll)
			GetAttr(PGA_Top,buttons->horiz_scroll,(ULONG *)&buttons->button_left);
		else  buttons->button_left=0;

		// Draw buttons
		button=(Cfg_Button *)buttons->bank->buttons.lh_Head;
		for (y=0;y<buttons->bank->window.rows;y++)
		{
			for (x=0;x<buttons->bank->window.columns;x++)
			{
				// Check button is valid
				if (button && !button->node.ln_Succ) button=0;

				// Is button visible?
				if (y>=buttons->button_top && y<buttons->button_top+buttons->button_rows &&
					x>=buttons->button_left && x<buttons->button_left+buttons->button_cols)
				{
					// Draw button
					buttons_show_button(
						buttons,
						button,
						x-buttons->button_left,
						y-buttons->button_top,
						(button)?button->current:0,0);
				}

				// Get next button
				if (button) button=(Cfg_Button *)button->node.ln_Succ;
			}
		}
	}

	// Clear resized flag
	buttons->flags&=~BUTTONF_RESIZED;

	// Unlock bank
	FreeSemaphore(&buttons->bank->lock);
}