void config_env_store_sound(config_env_data *data)
{
	short num;
	Cfg_SoundEntry *sound;

	// Get selection
	if ((num=GetGadgetValue(data->option_list,GAD_SETTINGS_SOUNDLIST))>-1 &&
		(sound=(Cfg_SoundEntry *)Att_FindNode((Att_List *)&data->sound_list,num)))
	{
		short flags,old_volume;
		char old_sound[256];
		
		strcpy(old_sound,sound->dse_Sound);
		old_volume=sound->dse_Volume;

		strcpy(sound->dse_Sound,(char *)GetGadgetValue(data->option_list,GAD_SETTINGS_SOUNDLIST_PATH));
		UpdateGadgetValue(data->option_list,0,GAD_SETTINGS_VOLUME);
		if ((sound->dse_Volume=GetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME))<0)
			sound->dse_Volume=0;
		else
		if (sound->dse_Volume>64)
			sound->dse_Volume=64;
		SetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME,sound->dse_Volume);
		SetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME_SLIDER,sound->dse_Volume);

		// Did sound change?
		if (strcmp(old_sound,sound->dse_Sound)!=0)
		{
			// Fix pen usage
			flags=sound->dse_Node.lve_Flags;
			if (sound->dse_Sound[0])
				sound->dse_Node.lve_Flags|=LVEF_USE_PEN;
			else
				sound->dse_Node.lve_Flags&=~LVEF_USE_PEN;
			if (flags!=sound->dse_Node.lve_Flags)
			{
				SetGadgetChoices(data->objlist,GAD_SETTINGS_SOUNDLIST,(APTR)~0);
				SetGadgetChoices(data->objlist,GAD_SETTINGS_SOUNDLIST,&data->sound_list);
			}
			sound->dse_Node.lve_Flags|=LVEF_TEMP;
		}

		// Or volume?
		else
		if (old_volume!=sound->dse_Volume)
			sound->dse_Node.lve_Flags|=LVEF_TEMP;
	}
}
void config_env_test_sound(config_env_data *data)
{
	struct Library *ModuleBase;
	BOOL ok=0;

	// Busy the window
	SetWindowBusy(data->window);

	// Open play.module
	if (ModuleBase=OpenLibrary("dopus5:modules/play.module",0))
	{
		short num;
		Cfg_SoundEntry *sound;

		// Get selection
		if ((num=GetGadgetValue(data->option_list,GAD_SETTINGS_SOUNDLIST))>-1 &&
			(sound=(Cfg_SoundEntry *)Att_FindNode((Att_List *)&data->sound_list,num)) &&
			sound->dse_Sound[0])
		{
			struct Node node;
			struct List list;

			// Build file list
			NewList(&list);
			node.ln_Name=sound->dse_Sound;
			AddTail(&list,&node);

			// Play the sound
			Module_Entry(
				&list,
				data->window->WScreen,
				data->ipc,
				data->main_ipc,
				(ULONG)data->window,
				sound->dse_Volume<<8);
			ok=1;
		}

		// Close module
		CloseLibrary(ModuleBase);
	}

	// Unbusy the window
	ClearWindowBusy(data->window);
	if (!ok) DisplayBeep(data->window->WScreen);
}
void config_env_show_sound(config_env_data *data)
{
	short num;
	Cfg_SoundEntry *sound;

	// Get selection
	if ((num=GetGadgetValue(data->option_list,GAD_SETTINGS_SOUNDLIST))>-1 &&
		(sound=(Cfg_SoundEntry *)Att_FindNode((Att_List *)&data->sound_list,num)) && sound->dse_Sound[0])
	{
		SetGadgetValue(data->option_list,GAD_SETTINGS_SOUNDLIST_PATH,(ULONG)sound->dse_Sound);
		SetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME,sound->dse_Volume);
		SetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME_SLIDER,sound->dse_Volume);
	}
	else
	{
		SetGadgetValue(data->option_list,GAD_SETTINGS_SOUNDLIST_PATH,0);
		SetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME,64);
		SetGadgetValue(data->option_list,GAD_SETTINGS_VOLUME_SLIDER,64);
	}
}
Exemple #4
0
// Show font example
void font_show_font(font_data *data,BOOL refresh)
{
	struct Rectangle rect;
	struct Region *region;
	struct RastPort rp;

	// Get display rectangle
	GetObjectRect(data->list,GAD_FONT_DISPLAY,&rect);

	// Move rectangle in
	rect.MinX+=3;
	rect.MinY+=3;
	rect.MaxX-=3;
	rect.MaxY-=3;

	// Copy rastport
	rp=*data->window->RPort;

	// Refresh?
	if (refresh)
	{
		LockLayerInfo(&data->window->WScreen->LayerInfo);
		BeginRefresh(data->window);
	}

	// Clear background
	SetAPen(&rp,DRAWINFO(data->window)->dri_Pens[SHINEPEN]);
	RectFill(&rp,rect.MinX-1,rect.MinY-1,rect.MaxX+1,rect.MaxY+1);

	// Refreshing?
	if (refresh) EndRefresh(data->window,FALSE);

	// Create region
	if ((region=NewRegion()))
	{
		// Set rectangle
		OrRectRegion(region,&rect);

		// Install region
		InstallClipRegion(data->window->WLayer,region);
	}

	// Refreshing?
	if (refresh) BeginRefresh(data->window);

	// Got a font?
	if (data->font)
	{
		ULONG flags;
		short y;
		struct TextExtent extent;
		char *ptr,*end;

		// Set pen and font
		SetAPen(&rp,DRAWINFO(data->window)->dri_Pens[TEXTPEN]);
		SetDrMd(&rp,JAM1);
		SetFont(&rp,data->font);

		// Get style flags
		flags=0;
		if (GetGadgetValue(data->list,GAD_FONT_BOLD)) flags|=FSF_BOLD;
		if (GetGadgetValue(data->list,GAD_FONT_ITALIC)) flags|=FSF_ITALIC;
		if (GetGadgetValue(data->list,GAD_FONT_ULINE)) flags|=FSF_UNDERLINED;

		// Set styles
		SetSoftStyle(&rp,flags,FSF_BOLD|FSF_ITALIC|FSF_UNDERLINED);

		// Valid font to draw?
		if (data->font_text[0])
		{
			// Get end of the string
			end=data->font_text+strlen(data->font_text);

			// Initial coordinates
			y=rect.MinY;

			// Initialise position
			if (!(ptr=strchr(data->font_text,'A')))
				ptr=data->font_text;
			Move(&rp,rect.MinX,y+rp.TxBaseline);

			// Draw until we reach the bottom
			while (y<rect.MaxY)
			{
				// New line
				if (rp.cp_x>rect.MaxX)
				{
					// Bump position
					y+=rp.TxHeight+1;
					Move(&rp,rect.MinX,y+rp.TxBaseline);
				}

				// Otherwise
				else
				{
					short len,maxlen;

					// Get text that will fit
					len=
						TextFit(
							&rp,
							ptr,
							(maxlen=strlen(ptr)),
							&extent,
							0,1,
							rect.MaxX-rp.cp_x+1,
							rp.TxHeight);

					// Check against length, add extra character if ok
					if (len<maxlen) ++len;

					// Draw text
					Text(&rp,ptr,len);

					// Bump text position
					ptr+=len;

					// End of the string?
					if (ptr>=end) ptr=data->font_text;
				}
			}
		}
	}

	// Finished refreshing?
	if (refresh) EndRefresh(data->window,TRUE);

	// Remove region
	if (region)
	{
		InstallClipRegion(data->window->WLayer,0);
		DisposeRegion(region);
	}

	// Unlock layers if we refreshed
	if (refresh) UnlockLayerInfo(&data->window->WScreen->LayerInfo);
}
Exemple #5
0
int main(int argc,char **argv)
{
	font_data *data;

	// Need dopus library
	if (!(DOpusBase=OpenLibrary("dopus5.library",LIB_VERSION)))
		if (!(DOpusBase=OpenLibrary("dopus5:libs/dopus5.library",55)))
			return(10);
#ifdef __amigaos4__
	if (!(IDOpus = (struct DOpusIFace *)GetInterface(DOpusBase, "main", 1, NULL)))
	{
		CloseLibrary(DOpusBase);
		return(10);
	}
#endif

	// Allocate data
	if (!(data=AllocVec(sizeof(font_data),MEMF_CLEAR)))
	{
		font_free(0);
		return(5);
	}

	// Parse arguments
	data->args=
		ReadArgs(
			"FONT,SIZE/N,B=BOLD/S,I=ITALIC/S,U=ULINE/S,PUBSCREEN/K",
			(APTR)data->arg_array,
			NULL);

	// Default to topaz 8
#ifdef __AROS__
	strcpy(data->font_name,"ttcourier.font");
#else
	strcpy(data->font_name,"topaz.font");
#endif
	data->font_size=8;

	// Got font name?
	if (data->arg_array[ARG_FONT])
		font_get_name(data,(char *)data->arg_array[ARG_FONT]);

	// Got a font size?
	if (data->arg_array[ARG_SIZE] && *((long *)data->arg_array[ARG_SIZE]))
	{
		data->font_size=*((long *)data->arg_array[ARG_SIZE]);
		data->first=TRUE;
	}

	// Initialise locale
	init_locale_data(&data->locale);

	// Got locale library?
	if (LocaleBase)
	{
		BPTR lock;

		// Change PROGDIR: to dopus5:
		if ((lock=Lock("dopus5:",ACCESS_READ)))
#ifdef __AROS__
			// the lock returned here is the initial PROGDIR: which belongs to the system,
			// so it's not a very good idea to just UnLock it
			SetProgramDir(lock);
#else
			UnLock(SetProgramDir(lock));
#endif

		// Initialise
		data->locale.li_LocaleBase=LocaleBase;
		data->locale.li_Catalog=OpenCatalogA(0,"viewfont.catalog",0);
		data->locale.li_Locale=OpenLocale(0);
	}

	// Create message port
	data->appport=CreateMsgPort();

	// Open window
	if (!(font_open(data)))
	{
		font_free(data);
		return(5);
	}

	// Initial gadget settings
	if (data->arg_array[ARG_BOLD]) SetGadgetValue(data->list,GAD_FONT_BOLD,1);
	if (data->arg_array[ARG_ITALIC]) SetGadgetValue(data->list,GAD_FONT_ITALIC,1);
	if (data->arg_array[ARG_ULINE]) SetGadgetValue(data->list,GAD_FONT_ULINE,1);

	// Show font
	font_show_font(data,FALSE);

	// Initialise refresh hook
	data->refresh_hook.h_Entry=(ULONG (*)())font_refresh;
	data->refresh_hook.h_Data=data;

	// Event loop
	FOREVER
	{
		struct IntuiMessage *msg;
		BOOL quit_flag=FALSE;

		// AppWindow?
		if (data->appwindow)
		{
			struct AppMessage *amsg;

			// Get messages
			while ((amsg=(struct AppMessage *)GetMsg(data->appport)))
			{
				// Got file?
				if (amsg->am_NumArgs>0)
				{
					char buf[256];

					// Get name
					DevNameFromLockDopus(amsg->am_ArgList[0].wa_Lock,buf,256);
					if (amsg->am_ArgList[0].wa_Name && *amsg->am_ArgList[0].wa_Name)
						AddPart(buf,amsg->am_ArgList[0].wa_Name,256);

					// Get font name
					font_get_name(data,buf);

					// Get new font
					font_get_font(data);
					font_show_font(data,FALSE);
				}

				// Reply to message
				ReplyMsg((struct Message *)amsg);
			}
		}

		// Requester?
		if (data->about)
		{
			// Handle requester
			if (SysReqHandler(data->about,0,0)>=0)
			{
				// Close requester
				FreeSysRequest(data->about);
				data->about=NULL;
			}
		}

		// Intuition messages
		if (data->window)
		{
			while ((msg=GetWindowMsg(data->window->UserPort)))
			{
				struct IntuiMessage msg_copy;
				UWORD id=0;

				// Copy message and reply
				msg_copy=*msg;
				ReplyWindowMsg(msg);

				// Get gadget ID
				if (msg_copy.Class==IDCMP_GADGETUP)
					id=((struct Gadget *)msg_copy.IAddress)->GadgetID;

				// Look at message
				switch (msg_copy.Class)
				{
					// Close window
					case IDCMP_CLOSEWINDOW:
						quit_flag=TRUE;
						break;


					// New size
					case IDCMP_NEWSIZE:

						// Redraw font
						font_show_font(data,FALSE);

						// Set flag to say we resized
						data->resized=TRUE;
						break;


					// Menu
					case IDCMP_MENUPICK:
						{
							struct MenuItem *item;

							// Get item
							if (!(item=ItemAddress(data->window->MenuStrip,msg_copy.Code)))
								break;

							// Get ID
							id=GTMENUITEM_USERDATA(item);

							// Fall through
						}

					// Gadget
					case IDCMP_GADGETUP:
						switch (id)
						{
							// Show requester
							case GAD_FONT_FONT_POPUP:
							case MENU_OPEN_FONT:

								// Ask for name
								font_ask_name(data);
								break;


							// Font name typed
							case GAD_FONT_FONT:

								// Get name
								font_get_name(data,(char *)GetGadgetValue(data->list,GAD_FONT_FONT));

								// Get new font
								font_get_font(data);
								font_show_font(data,FALSE);
								break;


							// Font size up/down
							case GAD_FONT_UP:
							case GAD_FONT_DOWN:
								{
									short size;

									// Get next size
									size=font_get_size(data,(id==GAD_FONT_UP)?1:-1);

									// No change?
									if (size==data->font_size) break;

									// Use this size
									data->font_size=size;
									SetGadgetValue(data->list,GAD_FONT_SIZE,size);
								}

							// Font size given
							case GAD_FONT_CYCLE:

								// Check id
								if (id==GAD_FONT_CYCLE)
								{
									short size;

									// Get size
									if (!(size=atoi(data->size_labels[msg_copy.Code])))
										break;

									// Refresh gadget
									data->font_size=size;
									SetGadgetValue(data->list,GAD_FONT_SIZE,data->font_size);
								}

							// Font size
							case GAD_FONT_SIZE:

								// Entered size
								if (id==GAD_FONT_SIZE)
								{
									// Bounds check gadget
									data->font_size=
										BoundsCheckGadget(
											data->list,
											GAD_FONT_SIZE,
											4,
											255);
								}

								// Get new font
								font_get_font(data);
								font_show_font(data,FALSE);
								break;

							// Styles changed
							case GAD_FONT_BOLD:
							case GAD_FONT_ITALIC:
							case GAD_FONT_ULINE:

								// Redraw font
								font_show_font(data,FALSE);
								break;


							// Save settings
							case MENU_SAVE_SETTINGS:
								font_save_settings(data);
								break;


							// Quit
							case MENU_QUIT:
								quit_flag=TRUE;
								break;


							// About
							case MENU_ABOUT:
								font_show_about(data);
								break;
						}
						break;


					// Rawkey
					case IDCMP_RAWKEY:

						// Help?
						if (msg_copy.Code==0x5f)
							font_show_about(data);

					// Key
					case IDCMP_VANILLAKEY:

						// Escape does quit
						if (msg_copy.Code==0x1b) quit_flag=TRUE;
						break;


					// Refresh
					case IDCMP_REFRESHWINDOW:

						// Have we just resized?
						if (data->resized)
						{
							// Don't need to refresh
							BeginRefresh(data->window);
							EndRefresh(data->window,TRUE);
							data->resized=FALSE;
							break;
						}

						// Refresh font display
						font_show_font(data,TRUE);
						break;
				}

				// Check window is still valid
				if (!data->window) break;
			}
		}

		if (quit_flag) break;

		// Wait for signal (ctrl-c breaks)
		if ((Wait(SIGBREAKF_CTRL_C|
					((data->window)?(1<<data->window->UserPort->mp_SigBit):0)|
					((data->about)?(1<<data->about->UserPort->mp_SigBit):0)|
					((data->appwindow)?(1<<data->appport->mp_SigBit):0)))&SIGBREAKF_CTRL_C) break;
	}

	// Free stuff
	font_free(data);
	return(0);
}
// Change entry's path
void config_paths_change(config_path_data *data)
{
	char *str;
	BPTR lock;
	char path[256];
	position_rec *pos;
	Att_Node *node;
	struct List *search;

	// No path selected?
	if (!data->path_sel) return;

	// Get path string
	str=(char *)GetGadgetValue(data->objlist,GAD_PATHFORMAT_PATH);

	// Invalid?
	if (!str || !*str)
	{
		// Remove this path
		config_paths_remove(data,TRUE);
		return;
	}

	// Try to lock
	if ((lock=Lock(str,ACCESS_READ)))
	{
		// Get full pathname
		NameFromLock(lock,path,256);
		UnLock(lock);
	}

	// Otherwise, use entered path
	else strcpy(path,str);

	// Fix path with trailing /
	AddPart(path,"",256);

	// See if path is already in edit list
	if ((node=(Att_Node *)FindNameI((struct List *)data->path_list,path)))
	{
		// Not the currently selected node?
		if (node!=data->path_sel)
		{
			// Error
			DisplayBeep(data->window->WScreen);
			ActivateStrGad(GADGET(GetObject(data->objlist,GAD_PATHFORMAT_PATH)),data->window);
			return;
		}
	}

	// Is path already in snapshot list?
	search=data->paths;
	while ((pos=(position_rec *)FindNameI(search,path)))
	{
		// Position entry?
		if (pos->node.ln_Type==PTYPE_POSITION) break;
		search=(struct List *)pos;
	}

	// Found it?
	if (pos)
	{
		// Different entry?
		if (pos!=(position_rec *)data->path_sel->data)
		{
			// Remove current entry from list
			Remove((struct Node *)data->path_sel->data);

			// Free current data
			FreeMemH((void *)data->path_sel->data);
			data->path_sel->data=(ULONG)pos;
		}

		// If path exists, clear "new" flag
		if (lock) pos->flags&=~POSITIONF_NEW;
	}

	// It is now
	else pos=(position_rec *)data->path_sel->data;

	// Set its user flag
	pos->flags|=POSITIONF_USER;

	// Store new name
	strcpy(pos->name,path);

	// Remove list from gadget
	SetGadgetChoices(data->objlist,GAD_PATHFORMAT_PATHS,(APTR)~0);

	// Remove existing node and add new one
	Att_RemNode(data->path_sel);

	// Add to list
	data->path_sel=Att_NewNode(data->path_list,pos->node.ln_Name,(ULONG)pos,ADDNODE_SORT);

	// Attach list to gadget
	SetGadgetChoices(data->objlist,GAD_PATHFORMAT_PATHS,data->path_list);

	// Select the new node
	config_paths_select(data,data->path_sel,TRUE);
}
void FunctionEditor(void)
{
	struct IntuiMessage *gmsg,msg;
	int break_flag=0;
	UWORD gadgetid=0;
	ULONG waitbits;
	FuncEdData *data;
	IPCData *ipc;
	NewConfigWindow newwin;
	FunctionStartup *startup=0;
	IPCMessage *submsg;
	int success=0;
	BOOL open_window=1;
	BPTR lock;
	ConfigWindow windims;

	// Do startup
	if (!(ipc=Local_IPC_ProcStartup((ULONG *)&startup, (APTR)&funced_init)))
	{
		funced_cleanup(startup->data);
		return;
	}

	// Get data pointer
	data=startup->data;

	// Lock RAM: and CD to it
	if ((lock=Lock("ram:",ACCESS_READ)))
		lock=CurrentDir(lock);

	// Copy dimensions
	if (startup->flags&FUNCEDF_CENTER)
		windims=_function_editor_window_center;
	else
	if (startup->flags&FUNCEDF_LABEL)
		windims=_function_editor_label_window;
	else
		windims=_function_editor_window;

	// Fill in new window
	newwin.parent=startup->window;
	newwin.dims=&windims;
	newwin.title=(startup->title[0])?startup->title:(char *)GetString(startup->locale,MSG_FUNCED_TITLE);
	newwin.locale=startup->locale;
	newwin.port=0;
	newwin.flags=WINDOW_VISITOR|WINDOW_AUTO_KEYS|WINDOW_REQ_FILL;//|WINDOW_SIZE_BOTTOM;
	newwin.font=0;

	// Build flag list
	funced_build_flaglist(data);
	waitbits=1<<ipc->command_port->mp_SigBit|1<<data->drag.timer->port->mp_SigBit;

	// Event loop
	FOREVER
	{
		// Check drag
		if (config_drag_check(&data->drag))
		{
			// End drag
			functioned_end_drag(data,0);
		}

		// Task message?
		while ((submsg=(IPCMessage *)GetMsg(ipc->command_port)))
		{
			// Close message?
			if (submsg->command==IPC_QUIT)
			{
				// Keep changes?
				success=submsg->flags;

				// Set break flag
				break_flag=1;
			}

			// Activate
			else
			if (submsg->command==IPC_ACTIVATE && data->window)
			{
				WindowToFront(data->window);
				ActivateWindow(data->window);
			}

			// Hide
			else
			if (submsg->command==IPC_HIDE && data->window)
			{
				// Store changes in function
				funced_store_edits(data);

				// End any drag in progress
				functioned_end_drag(data,0);

				// Remove AppWindow
				RemoveAppWindow(data->appwindow);
				data->appwindow=0;

				// Close window
				CloseConfigWindow(data->window);

				// Zero stuff
				data->window=0;
				data->objlist=0;
				waitbits=1<<ipc->command_port->mp_SigBit;
			}

			// Show
			else
			if (submsg->command==IPC_SHOW && !data->window)
			{
				// Set flag to open window
				open_window=1;
				newwin.parent=(struct Window *)submsg->data;
			}

			// Passed-along app message
			else
			if (submsg->command==CFG_APPMESSAGE_PASS)
			{
				funced_appmsg(data,submsg->data);
				ReplyMsg((struct Message *)submsg->data);
			}

			// Update our identity
			else
			if (submsg->command==CFG_NEW_ID)
			{
				data->function->function.func_type=submsg->flags;
				startup->object_flags=(ULONG)submsg->data;
			}

			// Copy a function
			else
			if (submsg->command==FUNCTIONEDIT_COPY_LINE)
			{
				FunctionEntry *entry,*next;

				// Copy function
				functioned_copy_line(
					data,
					(FunctionEntry *)submsg->data,
					0,
					(Point *)submsg->data_free);

				// Free function
				entry=(FunctionEntry *)submsg->data;
				while (entry)
				{
					// Get next
					next=(FunctionEntry *)entry->node;

					// Free entry
					FreeVec(entry);
					entry=next;
				}
			}

			// Clip button
			else
			if (submsg->command==BUTTONEDIT_CLIP_BUTTON)
			{
				Cfg_ButtonFunction *func;

				// Show busy pointer
				SetWindowBusy(data->window);

				// Stop editing
				funced_end_edit(data,data->edit_node,0,0);
				data->edit_node=0;

				// Get first function
				if ((func=(Cfg_ButtonFunction *)
					FindFunctionType(
						(struct List *)&((Cfg_Button *)submsg->data)->function_list,
						FTYPE_LEFT_BUTTON)))
				{
					FunctionEntry dummy;
					Cfg_Instruction *ins;

					// Go through instructions
					for (ins=(Cfg_Instruction *)func->instructions.mlh_Head;
						ins->node.mln_Succ;
						ins=(Cfg_Instruction *)ins->node.mln_Succ)
					{
						// Fill out dummy entry
						dummy.type=ins->type;
						if (ins->string) strcpy(dummy.buffer,ins->string);
						else dummy.buffer[0]=0;

						// Copy function line
						data->edit_node=funced_new_entry(data,0,&dummy);
					}

					// Start editing last line
					funced_start_edit(data);

					// Get flags
					data->function->function.flags=func->function.flags;
					data->function->function.code=func->function.code;
					data->function->function.qual=func->function.qual;
					data->function->function.qual_mask=func->function.qual_mask;
					data->function->function.qual_same=func->function.qual_same;

					// Update flag list
					funced_update_flaglist(data);

					// Update key
					funced_show_key(data);
				}

				// Free button
				FreeButton((Cfg_Button *)submsg->data);

				// Clear busy pointer
				ClearWindowBusy(data->window);
			}

			// Reply the message
			IPC_Reply(submsg);
		}

		// Open window?
		if (open_window)
		{
			// Open window
			if (!(data->window=OpenConfigWindow(&newwin)) ||
				!(data->p_objlist=AddObjectList(
					data->window,
					(startup->flags&FUNCEDF_IMAGE)?_function_editor_image_objects:
						((startup->flags&FUNCEDF_LABEL)?_function_editor_label_objects:
														_function_editor_normal_objects))) ||
				!(data->objlist=AddObjectList(data->window,_function_editor_objects)))
				break;

			// Add use or save button
			AddObjectList(data->window,(startup->flags&FUNCEDF_SAVE)?_function_editor_objects_save:_function_editor_objects_use);

			// Store window for drag
			data->drag.window=data->window;

			// Set window ID
			SetWindowID(data->window,0,WINDOW_FUNCTION_EDITOR,(struct MsgPort *)ipc);

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

			// Make this an AppWindow
			data->appwindow=AddAppWindowA(0,0,data->window,data->appport,0);

			// Get waitbits
			waitbits|=1<<data->window->UserPort->mp_SigBit;
			if (data->appwindow) waitbits|=1<<data->appport->mp_SigBit;

			// Disable key?
			if (startup->flags&FUNCEDF_NO_KEY)
			{
				DisableObject(data->objlist,GAD_FUNCED_KEY,TRUE);
			}

			// Initialise gadgets with function data.
			funced_init_gads(data);
			open_window=0;
		}

		// Intuimessage
		if (data->window)
		{
			while ((gmsg=GetWindowMsg(data->window->UserPort)))
			{
				Att_Node *node;

				// Copy message and reply (unless IDCMPUPDATE)
				msg=*gmsg;
				if (gmsg->Class!=IDCMP_IDCMPUPDATE)
				{
					ReplyWindowMsg(gmsg);
					gmsg=0;
				}

				// Get GadgetID
				if (msg.Class==IDCMP_GADGETDOWN ||
					msg.Class==IDCMP_GADGETUP)
					gadgetid=((struct Gadget *)msg.IAddress)->GadgetID;

				// Look at message
				switch (msg.Class)
				{
					// Key press
					case IDCMP_VANILLAKEY:

						// If editing something, activate string gadget
						if (data->edit_node)
							ActivateStrGad(GADGET(GetObject(data->objlist,GAD_FUNCED_EDIT)),data->window);
						break;


					// Close window
					case IDCMP_CLOSEWINDOW:

						// Set break flag
						break_flag=1;
						break;


					// Mouse move
					case IDCMP_MOUSEMOVE:

						// Handle drag move
						config_drag_move(&data->drag);
						break;


					// Inactive window does menu down
					case IDCMP_INACTIVEWINDOW:
						msg.Code=MENUDOWN;

					// Mouse buttons
					case IDCMP_MOUSEBUTTONS:

						// Valid drag info?
						if (data->drag.drag)
						{
							short ok=-1;

							// Dropped ok?
							if (msg.Code==SELECTUP)
							{
								// Is shift down?
								if (msg.Qualifier&(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
									data->drag_shift=1;
								else data->drag_shift=0;

								// Remember last position
								data->drag.drag_x=data->window->WScreen->MouseX;
								data->drag.drag_y=data->window->WScreen->MouseY;
								ok=1;
							}

							// Aborted
							else
							if (msg.Code==MENUDOWN)
							{
								// Set abort
								ok=0;
							}

							// End drag?
							if (ok!=-1) functioned_end_drag(data,ok);
						}
						break;


					// Menu
					case IDCMP_MENUPICK:

						{
							struct MenuItem *item;

							// Get item
							if (!(item=ItemAddress(data->window->MenuStrip,msg.Code)))
								break;

							// Treat as gadget
							gadgetid=MENUID(item);
						}

					// Gadget
					case IDCMP_GADGETUP:
					case IDCMP_GADGETDOWN:

						// Look at gadget ID
						switch (gadgetid)
						{
							// Hotkey
							case GAD_FUNCED_KEY:
								{
									IX ix;
									char *ptr;

									// Get key, see if it's invalid
									if ((ptr=(char *)GetGadgetValue(data->objlist,GAD_FUNCED_KEY)) && *ptr)
									{
										// Try to parse
										if (ParseIX(ptr,&ix))
										{
											// Flash screen
											DisplayBeep(data->window->WScreen);

											// Activate key field again
											ActivateStrGad(GADGET(GetObject(data->objlist,GAD_FUNCED_KEY)),data->window);
										}
										else
										{
											data->function->function.code=ix.ix_Code;
											data->function->function.qual=QualValid(ix.ix_Qualifier);
											data->function->function.qual_mask=ix.ix_QualMask;
											data->function->function.qual_same=ix.ix_QualSame;
										}
									}
								}
								break;


							// Flag selected
							case GAD_FUNCED_FLAGS:

								// Get selected node
								node=Att_FindNode(data->flag_list,msg.Code);

								// Set flag
								data->function->function.flags^=node->data;

								// Check change
								funced_check_flag(&data->function->function.flags,node->data);

								// Update flag list
								funced_update_flaglist(data);
								break;


							// Edit a line
							case GAD_FUNCED_LISTER:

								// Get selected node
								node=Att_FindNode(data->func_display_list,msg.Code);

								// Is this the node we're already editing?
								if (node==data->edit_node) break;

								// If we're editing another one, store its contents
								if (data->edit_node)
									funced_end_edit(data,data->edit_node,0,0);

								// Start editing this entry
								data->edit_node=node;
								funced_start_edit(data);
								break;


							// Return pressed in edit line
							case GAD_FUNCED_EDIT:

								// See if we were editing something
								if (data->edit_node)
								{
									// Stop editing
									funced_end_edit(data,data->edit_node,END_DISABLE,msg.Qualifier);
									data->edit_node=0;
								}
								break;


							// New entry
							case GAD_FUNCED_NEW_ENTRY:
							case GAD_FUNCED_INSERT_ENTRY:

								// Create new entry
								functioned_copy_line(data,0,gadgetid,0);
								break;


							// Delete entry
							case GAD_FUNCED_DELETE_ENTRY:
								// Check we were editing something
								if (!data->edit_node) break;

								// Stop editing (signal delete)
								funced_end_edit(data,data->edit_node,END_DISABLE|END_DELETE,0);
								data->edit_node=0;
								break;


							// Function type
							case GAD_FUNCED_FUNCTION_TYPE:
								// Check we were editing something
								if (!data->edit_node) break;

								// Store type
								((FunctionEntry *)data->edit_node->data)->type=msg.Code;

								// Disable popup button if no functions
								DisableObject(
									data->objlist,
									GAD_FUNCED_EDIT_GLASS,
									(msg.Code==INST_COMMAND && !data->startup->func_list));
								break;


							// Glass gadget
							case GAD_FUNCED_EDIT_GLASS:

								// Check we were editing something
								if (data->edit_node)
								{
									char buffer[256];

									// Put up requester
									if (!(funced_command_req(
										data,
										buffer,
										((FunctionEntry *)data->edit_node->data)->type)))
										break;

									// Insert string in edit line
									funced_edit_insertstring(
										data->objlist,
										GAD_FUNCED_EDIT,
										buffer,
										DOpusBase,(struct Library *)IntuitionBase);
								}
								break;


							// Argument list
							case GAD_FUNCED_EDIT_ARGUMENT:

								// Check we were editing something
								if (data->edit_node)
								{
									char buffer[80];

									// Put up requester
									if (!(funced_command_req(
										data,
										buffer,
										-1))) break;

									// Insert string in edit line
									funced_edit_insertstring(
										data->objlist,
										GAD_FUNCED_EDIT,
										buffer,
										DOpusBase,(struct Library *)IntuitionBase);
								}
								break;


							// Export
							case MENU_FUNCED_EXPORT_ASCII:
							case MENU_FUNCED_EXPORT_CMD:

								// Got file requester?
								if (WINREQUESTER(data->window))
								{
									struct TagItem tags[6];
									struct FileRequester *req=WINREQUESTER(data->window);

									// Show busy pointer
									SetWindowBusy(data->window);

									// File requester tags
									tags[0].ti_Tag=ASLFR_Window;
									tags[0].ti_Data=(ULONG)data->window;
									tags[1].ti_Tag=ASLFR_TitleText;
									tags[1].ti_Data=(ULONG)GetString(startup->locale,MSG_FUNCED_SELECT_FILE);
									tags[2].ti_Tag=ASLFR_Flags1;
									tags[2].ti_Data=FRF_DOSAVEMODE|FRF_PRIVATEIDCMP;
									tags[3].ti_Tag=ASLFR_Flags2;
									tags[3].ti_Data=FRF_REJECTICONS;
									tags[4].ti_Tag=(gadgetid==MENU_FUNCED_EXPORT_CMD)?ASLFR_InitialDrawer:TAG_DONE;
									tags[4].ti_Data=(ULONG)"DOpus5:Commands";
									tags[5].ti_Tag=TAG_DONE;

									// Show filerequester
									if (AslRequest(req,tags))
									{
										// Build filename
										strcpy(data->buffer,req->fr_Drawer);
										AddPart(data->buffer,req->fr_File,256);

										// Store changes in function
										funced_store_edits(data);

										// Do export
										if (gadgetid==MENU_FUNCED_EXPORT_CMD)
											function_export_cmd(data->buffer,0,data->function);
										else
											L_FunctionExportASCII(data->buffer,0,data->function,startup->a4);
									}

									// Remove busy pointer
									ClearWindowBusy(data->window);
								}
								break;


							// Cut/Copy
							case MENU_FUNCED_CUT:
							case MENU_FUNCED_COPY:
								{
									APTR iff;

									// Set busy pointer
									SetWindowBusy(data->window);

									// Open clipboard
									if ((iff=IFFOpen((char *)0,IFF_CLIP_WRITE,ID_OPUS)))
									{
										// Stop editing
										funced_end_edit(data,data->edit_node,END_DISABLE,0);
										data->edit_node=0;

										// Store changes in function
										funced_store_edits(data);

										// Save function
										SaveFunction(iff,data->function);

										// Close clipboard
										IFFClose(iff);
									}

									// Just copy, not cut?
									if (gadgetid==MENU_FUNCED_COPY)
									{
										// Clear busy pointer
										ClearWindowBusy(data->window);
										break;
									}

									// Fall through, paste null function
								}

							// Paste
							case MENU_FUNCED_PASTE:
								{
									Cfg_Function *func=0;

									// Set busy pointer
									SetWindowBusy(data->window);

									// End any edit
									funced_end_edit(data,data->edit_node,END_DISABLE,0);
									data->edit_node=0;

									// Paste?
									if (gadgetid==MENU_FUNCED_PASTE)
									{
										APTR iff;

										// Open clipboard
										if ((iff=IFFOpen((char *)0,IFF_CLIP_READ,ID_OPUS)))
										{
											// Find function
											if (IFFNextChunk(iff,ID_FUNC))
											{
												// Read function
												func=ReadFunction(iff,0,0,0);
											}

											// Close clipboard
											IFFClose(iff);
										}

										// No valid function?
										if (!func)
										{
											// Flash error
											DisplayBeep(data->window->WScreen);
											ClearWindowBusy(data->window);
											break;
										}
									}

									// Detach existing list
									SetGadgetChoices(data->objlist,GAD_FUNCED_FLAGS,(APTR)~0);

									// Clear function list
									Att_RemList(data->function_list,REMLIST_SAVELIST|REMLIST_FREEDATA);

									// Free existing instructions
									FreeInstructionList(data->function);

									// Rebuild display list
									funced_build_display(data);

									// Clear flags
									data->function->function.flags=0;
									funced_update_flaglist(data);

									// Clear key
									data->function->function.code=0xffff;
									SetGadgetValue(data->objlist,GAD_FUNCED_KEY,0);

									// Clear label
									if (startup->flags&FUNCEDF_LABEL)
									{
										data->label[0]=0;
										SetGadgetValue(data->p_objlist,GAD_FUNCED_LABEL,0);
									}

									// Paste function in?
									if (func)
									{
										short type;

										// Save type
										type=data->function->function.func_type;

										// Copy function in
										CopyFunction(func,0,data->function);
										data->function->function.func_type=type;

										// Free copied function
										FreeFunction(func);

										// Initialise gadgets
										funced_init_gads(data);
									}
	
									// Clear busy pointer
									ClearWindowBusy(data->window);
								}
								break;


							// Use
							case GAD_FUNCED_USE:
								success=1;

							// Cancel
							case GAD_FUNCED_CANCEL:
								break_flag=1;
								break;
						}
						break;


					// Key press
					case IDCMP_RAWKEY:

						// Help?
						if (msg.Code==0x5f &&
							!(msg.Qualifier&VALID_QUALIFIERS))	
						{
							// Set busy pointer
							SetWindowBusy(data->window);

							// Send help command
							IPC_Command(startup->main_owner,IPC_HELP,(1<<31),"Function Editor",0,REPLY_NO_PORT);

							// Clear busy pointer
							ClearWindowBusy(data->window);
						}
						break;


					// BOOPSI message
					case IDCMP_IDCMPUPDATE:
						{
							struct TagItem *tags=(struct TagItem *)msg.IAddress;
							short item;

							// Check ID
							if (GetTagData(GA_ID,0,tags)!=GAD_FUNCED_LISTER)
								break;

							// Get item
							if ((item=GetTagData(DLV_DragNotify,-1,tags))!=-1)
							{
								// Start the drag
								config_drag_start(&data->drag,data->func_display_list,item,tags,TRUE);
							}
						}
						break;


					// Ticks
					case IDCMP_INTUITICKS:
						++data->drag.tick_count;
						break;
				}

				// Reply to any outstanding message
				if (gmsg) ReplyWindowMsg(gmsg);
			}
		}

		// AppMessage
		if (data->appwindow)
		{
			struct AppMessage *msg;

			while ((msg=(struct AppMessage *)GetMsg(data->appport)))
			{
				// Make sure window is active
				ActivateWindow(data->window);

				// Handle message
				funced_appmsg(data,msg);
				ReplyMsg((struct Message *)msg);
			}
		}

		// Check break flag
		if (break_flag) break;

		// Wait for message
		Wait(waitbits);
	}

	// Restore CD
	if (lock) UnLock(CurrentDir(lock));

	// Edit successful?
	if (success)
	{
		FunctionReturn ret;

		// Store changes in function
		funced_store_edits(data);

		// Fill out return data
		ret.object=startup->object;
		ret.object_flags=startup->object_flags;
		ret.function=data->function;

		// Send new function back
		IPC_Command(startup->owner_ipc,FUNCTIONEDIT_RETURN,0,&ret,0,REPLY_NO_PORT);
	}

	// End any drag in progress
	functioned_end_drag(data,0);

	// Free edit function
	FreeFunction(data->function);

	// Close window
	RemoveAppWindow(data->appwindow);
	CloseConfigWindow(data->window);

	// Close application port
	if (data->appport)
	{
		struct Message *msg;
		while ((msg=GetMsg(data->appport)))
			ReplyMsg(msg);
		DeleteMsgPort(data->appport);
	}

	// Say goodbye
	IPC_Goodbye(ipc,startup->owner_ipc,startup->object_flags);

	// Delete IPC data
	Forbid();
	IPC_Free(ipc);

	// Free data
	funced_cleanup(data);
	FreeVec(startup);
}
void _config_env_screenmode_fix_gadgets(config_env_data *data)
{
	BOOL state=FALSE;

	// If screen mode is WORKBENCH_CLONE, select both default checks and disable them
	if (data->config->screen_mode==MODE_WORKBENCHCLONE)
	{
		// Set default size flags
		SetGadgetValue(data->option_list,GAD_ENVIRONMENT_SCREENMODE_DEFWIDTH,1);
		SetGadgetValue(data->option_list,GAD_ENVIRONMENT_SCREENMODE_DEFHEIGHT,1);
		state=TRUE;
	}

	// Or if mode is a USE mode, disable them
	else
	if (data->config->screen_mode==MODE_WORKBENCHUSE ||
		data->config->screen_mode==MODE_PUBLICSCREEN)
		state=TRUE;

	// Set enable/disable state of default checks
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_DEFWIDTH,state);
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_DEFHEIGHT,state);

	// If default width is checked, fill out width field with default width
	// and disable it
	if (GetGadgetValue(data->option_list,GAD_ENVIRONMENT_SCREENMODE_DEFWIDTH))
	{
		SetGadgetValue(data->option_list,GAD_ENVIRONMENT_SCREENMODE_WIDTH,data->mode_size_default.MaxX);
		state=TRUE;
	}

	// Or if mode is a USE mode, disable it
	else
	if (data->config->screen_mode==MODE_WORKBENCHUSE ||
		data->config->screen_mode==MODE_PUBLICSCREEN)
		state=TRUE;

	// Otherwise, make sure field is enabled
	else state=FALSE;

	// Set enable state
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_WIDTH,state);

	// If default height is checked, fill out height field with default height
	// and disable it
	if (GetGadgetValue(data->option_list,GAD_ENVIRONMENT_SCREENMODE_DEFHEIGHT))
	{
		SetGadgetValue(data->option_list,GAD_ENVIRONMENT_SCREENMODE_HEIGHT,data->mode_size_default.MaxY);
		state=TRUE;
	}

	// Or if mode is a USE mode, disable it
	else
	if (data->config->screen_mode==MODE_WORKBENCHUSE ||
		data->config->screen_mode==MODE_PUBLICSCREEN)
		state=TRUE;

	// Otherwise, make sure field is enabled
	else state=FALSE;

	// Set enable state
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_HEIGHT,state);

	// Fix depth slider limits
	SetGadgetChoices(
		data->option_list,
		GAD_ENVIRONMENT_SCREENMODE_COLORS,
		(APTR)(((ULONG)data->mode_max_colours<<16)|2));
	SetGadgetValue(
		data->option_list,
		GAD_ENVIRONMENT_SCREENMODE_COLORS,
		data->config->screen_depth);

	// Is mode is a USE mode, disable colours selector and font gadgets
	state=(data->config->screen_mode==MODE_WORKBENCHUSE || data->config->screen_mode==MODE_PUBLICSCREEN);
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_COLORS,state);
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_FONT,state);
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_FONTNAME,state);
	DisableObject(data->option_list,GAD_ENVIRONMENT_SCREENMODE_FONTSIZE,state);

	// Check maximum/minimum values
	_config_env_screenmode_check_values(data);
}
// Get search data
static int search_get_data(
	FunctionHandle *handle,
	SearchData *data)
{
	NewConfigWindow new_win;
	struct Window *window;
	ObjectList *objlist;
	Lister *lister;
	short cancel=1;

	// Fill out new window
	if ((lister=function_lister_current(&handle->source_paths)))
	{
		new_win.parent=lister->window;
		new_win.flags=0;
	}
	else
	{
		new_win.parent=GUI->screen_pointer;
		new_win.flags=WINDOW_SCREEN_PARENT;
	}
	new_win.dims=&search_window;
	new_win.title=GetString(&locale,MSG_ENTER_SEARCH_STRING);
	new_win.locale=&locale;
	new_win.port=0;
	new_win.flags|=WINDOW_NO_CLOSE|WINDOW_VISITOR|WINDOW_AUTO_KEYS|WINDOW_REQ_FILL;
	new_win.font=0;

	// Open window
	if (!(window=OpenConfigWindow(&new_win)) ||
		!(objlist=AddObjectList(window,search_objects)))
	{
		CloseConfigWindow(window);
		return 0;
	}

	// Initial settings
	SetGadgetValue(objlist,GAD_SEARCH_TEXT,(ULONG)data->search_text);
	SetGadgetValue(objlist,GAD_SEARCH_CASE,data->search_flags&SEARCH_NOCASE);
	SetGadgetValue(objlist,GAD_SEARCH_WILD,data->search_flags&SEARCH_WILDCARD);
	SetGadgetValue(objlist,GAD_SEARCH_ONLYWORD,data->search_flags&SEARCH_ONLYWORDS);
	SetGadgetValue(objlist,GAD_SEARCH_RESULT,data->search_result);

	// Activate text field
	ActivateStrGad(GADGET(GetObject(objlist,GAD_SEARCH_TEXT)),window);

	// Event loop
	FOREVER
	{
		struct IntuiMessage *msg;
		BOOL break_flag=0;

		// Check for abort
		if (function_check_abort(handle))
			break;

		// Activate?
		if (handle->flags2&FUNCF_ACTIVATE_ME)
		{
			ActivateWindow(window);
			WindowToFront(window);
			handle->flags2&=~FUNCF_ACTIVATE_ME;
		}

		// Any Intuition messages?
		while ((msg=GetWindowMsg(window->UserPort)))
		{
			struct IntuiMessage copy_msg;

			// Copy message and reply
			copy_msg=*msg;
			ReplyWindowMsg(msg);

			// Gadget?
			if (copy_msg.Class==IDCMP_GADGETUP)
			{
				UWORD gadgetid;

				// Get gadget id
				gadgetid=((struct Gadget *)copy_msg.IAddress)->GadgetID;

				// Look at gadget ID
				switch (gadgetid)
				{
					// Okay
					case GAD_SEARCH_TEXT:
					case GAD_SEARCH_OKAY:

						// Store flags
						data->search_flags=0;
						if (GetGadgetValue(objlist,GAD_SEARCH_CASE))
							data->search_flags|=SEARCH_NOCASE;
						if (GetGadgetValue(objlist,GAD_SEARCH_WILD))
							data->search_flags|=SEARCH_WILDCARD;
						if (GetGadgetValue(objlist,GAD_SEARCH_ONLYWORD))
							data->search_flags|=SEARCH_ONLYWORDS;
						data->search_result=GetGadgetValue(objlist,GAD_SEARCH_RESULT);

						// Get search text
						strcpy(data->search_text,(char *)GetGadgetValue(objlist,GAD_SEARCH_TEXT));
						cancel=0;

					// Cancel
					case GAD_SEARCH_CANCEL:
						break_flag=1;
						break;
				}
			}
		}

		// Check break flag
		if (break_flag) break;

		// Wait for an event
		Wait(1<<window->UserPort->mp_SigBit|1<<handle->ipc->command_port->mp_SigBit);
	}

	// Close window
	CloseConfigWindow(window);

	// Return
	return !cancel;
}
void SAVEDS PaletteBox(void)
{
	PaletteBoxData *data;
	struct Window *window;
	IPCData *ipc;

	// Do startup
	if (!(ipc=Local_IPC_ProcStartup((ULONG *)&data,0)))
	{
		Forbid();
		return;
	}

	// Get pen count
	data->pen_count=data->screen_data.pen_count;

	// Open window
	if ((window=palette_box_open(data,data->stuff.stuff1.object_def,data->pen_array,data->pen_array)))
	{
		// Event loop
		FOREVER
		{
			struct IntuiMessage *msg;
			IPCMessage *imsg;
			short break_flag=0;

			// IPC messages
			while ((imsg=(IPCMessage *)GetMsg(ipc->command_port)))
			{
				switch (imsg->command)
				{
					// Quit
					case IPC_QUIT:
						break_flag=1;
						break;

					// Activate
					case IPC_ACTIVATE:
						if (window)
						{
							WindowToFront(window);
							ActivateWindow(window);
						}
						break;

					// Hide
					case IPC_HIDE:
						CloseConfigWindow(window);
						window=0;
						break;

					// Show
					case IPC_SHOW:
						data->newwin.parent=(void *)imsg->data;
						if (!(window=palette_box_open(data,data->stuff.stuff1.object_def,data->pen_array,data->pen_array)))
							break_flag=1;
						break;
				}

				IPC_Reply(imsg);
			}

			// Intuition messages
			if (window)
			{
				while ((msg=GetWindowMsg(window->UserPort)))
				{
					struct IntuiMessage msg_copy;
					msg_copy=*msg;
					ReplyWindowMsg(msg);

					// Close
					if (msg_copy.Class==IDCMP_CLOSEWINDOW)
						break_flag=1;

					// Gadget
					else
					if (msg_copy.Class==IDCMP_GADGETUP)
					{
						short fg,bg;

						// Get foreground and background colours
						fg=GetGadgetValue(OBJLIST(window),GAD_PALETTE_FOREGROUND);
						bg=GetGadgetValue(OBJLIST(window),GAD_PALETTE_BACKGROUND);

						// Fix pens
						if (((struct Library*)IntuitionBase)->lib_Version>=39)
						{
							if (fg>=4 && fg<8) fg=248+fg;
							else
							if (fg>7) fg-=4;
							if (bg>=4 && bg<8) bg=248+bg;
							else
							if (bg>7) bg-=4;
						}
						data->fgpen=fg;
						data->bgpen=bg;

						// Send new colours
						IPC_Command(
							data->owner_ipc,
							BUTTONEDIT_NEW_COLOURS,
							data->fgpen,
							(APTR)data->bgpen,
							0,
							0);
					}

					// Key
					else
					if (msg_copy.Class==IDCMP_RAWKEY)
					{
						// Help?
						if (msg_copy.Code==0x5f &&
							!(msg_copy.Qualifier&VALID_QUALIFIERS))
						{
							// Set busy pointer
							SetWindowBusy(window);

							// Send help command
							IPC_Command(data->main_ipc,IPC_HELP,(1<<31),"Select Colours",0,REPLY_NO_PORT);

							// Clear busy pointer
							ClearWindowBusy(window);
						}
					}
				}
			}

			if (break_flag) break;

			Wait(1<<ipc->command_port->mp_SigBit|
				((window)?1<<window->UserPort->mp_SigBit:0));
		}

		CloseConfigWindow(window);
	}