/*  Canon Bubble Jet Print Filter.
 *  Copyright CANON INC. 2001-2003
 *  All Rights Reserved.
 *
 *  This program is free software; you can redistribute it 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.
 *
 *  This program 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 more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * NOTE:
 *  - As a special exception, this program is permissible to link with the
 *    libraries released as the binary modules.
 *  - If you write modifications of your own for these programs, it is your
 *    choice whether to permit this exception to apply to your modifications.
 *    If you do not wish that, delete this exception.
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>
#ifdef	USE_LIB_GLADE
#	include <glade/glade.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <time.h>			
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>

#include "callbacks.h"
#ifndef USE_LIB_GLADE
#	include "interface.h"
#	include "support.h"
#endif

#include "bjuidefs.h"
#include "utildef.h"
#include "msgicon.h"

static	int	result;

static	int	page_pause_mode;
static	int	scan_pause_mode;
static	char	*power_on_mode;
static	char	*power_off_mode;	
static	int poweron_index=0;		// Added '01.12.26
static	int poweroff_index=0;		// Added '01.12.26
static	int drylevel_value;		// Added '01.11.05
static 	int quiet_mode;			// Added '01.11.05
static	int warning_mode;		// Added '01.11.16
static 	int black_reset;		// Added '01.11.16
static	int color_reset;		// Added '01.11.16

static	GdkPixmap	*regi_pixmap;	


static	HOTSPOT		HotSpot[REGI_EDITMAX];	
static	short		ItemValue[REGI_EDITMAX];
static	short		nKindCnt;				
static	u_short		type;					
static	short		nPageNum;
static	LPCTRLITEM	lpCtrlItem;				
static	LPBOXINF	lpBoxInf;				
static	char		**lpBJLtbl;				
static	short		head_type;				
static	short		regi_flag=0;

static	short		refresh_head_type;	

extern	char	*g_hostname;				
extern	gchar	*g_socketname;				
extern	KeyTextList	*g_keytext_list;		

int getnum(char *ptr);
char *GetParamValue(char **Keytbl, char **Valuetbl, int n, char *mode);	
void SetComboBox(GtkWidget *combo, char **Keytbl, int n, int index);
int GetAutoPowerIndex(char **Keytbl, int n, char *mode);




static gboolean message_box_delete_event
(GtkWidget *widget, GdkEvent *event, gpointer data) 
{
	result = ID_CANCEL;
	gtk_window_set_modal(data,FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));

	return TRUE;
}


static void message_box_destroy(GtkWidget *widget, gpointer data)
{
	gtk_main_quit();						
	gtk_window_set_modal(data, FALSE);
}


static void message_box_ok(GtkWidget *widget, gpointer data)
{
	result = ID_OK;
	gtk_window_set_modal(data, FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));	
}


static void message_box_cancel(GtkWidget *widget, gpointer data)
{
	result = ID_CANCEL;
	gtk_window_set_modal(data, FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));	
}


static void message_box_yes(GtkWidget *widget, gpointer data)
{
	result = ID_YES;
	gtk_window_set_modal(data, FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));	
}


static void message_box_no(GtkWidget *widget, gpointer data)
{
	result = ID_NO;
	gtk_window_set_modal(data, FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));	
}


static void message_box_abort(GtkWidget *widget, gpointer data)
{
  	result = ID_ABORT;
	gtk_window_set_modal(data, FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));	
}


static void message_box_ignore(GtkWidget *widget, gpointer data)
{
  	result = ID_IGNORE;
	gtk_window_set_modal(data, FALSE);
	gtk_widget_destroy(GTK_WIDGET(data));	
}


static int UtilMessageBoxSetDefault(
	char *message,				
	char *title,                
	unsigned int flag,
	unsigned int default_flag)          
{
	GtkWidget	*dialog;				
	GtkWidget	*dialog_action_area1;   
	GtkWidget	*dialog_vbox1;          
	GtkWidget	*hbox1;                 
	GtkWidget	*pixmap;                
	GtkWidget	*label;                 
	GtkWidget	*hbuttonbox1;           
	GtkWidget	*button;                
	GdkPixmap	*icon = NULL;
	GdkPixmap	*iconMask = NULL;
	GtkStyle	*style;
	int		i;
	
	dialog = gtk_dialog_new();				
	gtk_widget_realize(dialog);				
	gtk_window_set_title(GTK_WINDOW(dialog), title);	
	gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE);	
	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);	
	
	gtk_signal_connect(GTK_OBJECT(dialog), "destroy",	
			      GTK_SIGNAL_FUNC(message_box_destroy), dialog);
	gtk_signal_connect (GTK_OBJECT (dialog), "delete_event",
						GTK_SIGNAL_FUNC (message_box_delete_event), dialog);
						
		
	dialog_action_area1 = GTK_DIALOG(dialog)->action_area;	
	dialog_vbox1 = GTK_DIALOG(dialog)->vbox;	

	
	hbox1 = gtk_hbox_new(FALSE, 0);	
	gtk_widget_show(hbox1);			
	gtk_box_pack_start(GTK_BOX(dialog_vbox1), hbox1, TRUE, TRUE, 5);	
  
	
	style = gtk_widget_get_style(dialog);
	switch (flag & 0x0000000f) {	
		case MB_ICON_INFORMATION:	
 			icon = gdk_pixmap_create_from_xpm_d(dialog->window,
  										  &iconMask,
  										  &style->bg[GTK_STATE_NORMAL],
  										  info_xpm);
  			break;
		
		case MB_ICON_EXCLAMATION:	
 			icon = gdk_pixmap_create_from_xpm_d(dialog->window,
  										  &iconMask,
  										  &style->bg[GTK_STATE_NORMAL],
  										  exclam_xpm);
			break;

		case MB_ICON_SYSERR:	
 			icon = gdk_pixmap_create_from_xpm_d(dialog->window,
  										  &iconMask,
  										  &style->bg[GTK_STATE_NORMAL],
  										  syserr_xpm);
			break;
	}

	pixmap = gtk_pixmap_new(icon, iconMask);			
	gtk_box_pack_start(GTK_BOX(hbox1), pixmap, TRUE, TRUE, 10);	
	gtk_widget_show(pixmap);			

	label = gtk_label_new(message);	
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);		
	gtk_widget_show(label);			
	gtk_box_pack_start(GTK_BOX(hbox1), label, TRUE, TRUE, 10);	


	hbuttonbox1 = gtk_hbutton_box_new();		
	gtk_button_box_set_layout(
		GTK_BUTTON_BOX(hbuttonbox1), GTK_BUTTONBOX_SPREAD);	
	gtk_box_pack_start(
		GTK_BOX(dialog_action_area1), hbuttonbox1, TRUE, FALSE, 0);	
	gtk_widget_show(hbuttonbox1);		
	
	i = 0;			
	
	if (flag & MB_OK) {		
		button = gtk_button_new_with_label(
					LookupText(g_keytext_list, "message_button_ok"));	
		gtk_widget_show(button);					
		gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);	
		GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
		
  		gtk_signal_connect(GTK_OBJECT(button), "clicked",	
					     GTK_SIGNAL_FUNC(message_box_ok),
					     dialog);
		if( default_flag & MB_OK ){
			gtk_widget_grab_focus(button);
			gtk_widget_grab_default(button);
		}
		i++;
	}
	
	if (flag & MB_CANCEL) {		
		button = gtk_button_new_with_label(
					LookupText(g_keytext_list, "message_button_cancel"));	
		gtk_widget_show(button);					
		gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);	
		GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
  		gtk_signal_connect(GTK_OBJECT(button), "clicked",	
					     GTK_SIGNAL_FUNC(message_box_cancel),
					     dialog);
		if( default_flag & MB_CANCEL ){
			gtk_widget_grab_focus(button);
			gtk_widget_grab_default(button);
		}
		
		i++;
	}
	
	if (flag & MB_YES) {		
		button = gtk_button_new_with_label(
					LookupText(g_keytext_list, "message_button_yes"));	
		gtk_widget_show(button);					
		gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);
		GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
  		gtk_signal_connect(GTK_OBJECT(button), "clicked",	
					     GTK_SIGNAL_FUNC(message_box_yes),
					     dialog);
		if( default_flag & MB_YES ){
			gtk_widget_grab_focus(button);
			gtk_widget_grab_default(button);
		}
		i++;
	}
	
	if (flag & MB_NO) {		
		button = gtk_button_new_with_label(
					LookupText(g_keytext_list, "message_button_no"));	
		gtk_widget_show(button);					
		gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);
		GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
  		gtk_signal_connect(GTK_OBJECT(button), "clicked",	
					     GTK_SIGNAL_FUNC(message_box_no),
					     dialog);
		if( default_flag & MB_NO ){
			gtk_widget_grab_focus(button);
			gtk_widget_grab_default(button);
		}

		i++;
	}

	if (flag & MB_ABORT) {		
		button = gtk_button_new_with_label(
					LookupText(g_keytext_list, "message_button_abort"));	
		gtk_widget_show(button);					
		gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);	
		GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
  		gtk_signal_connect(GTK_OBJECT(button), "clicked",	
					     GTK_SIGNAL_FUNC(message_box_abort),
					     dialog);
		if( default_flag & MB_ABORT ){
			gtk_widget_grab_focus(button);
			gtk_widget_grab_default(button);
		}
		i++;
	}

	if (flag & MB_IGNORE) {		
		button = gtk_button_new_with_label(
					LookupText(g_keytext_list, "message_button_ignore"));	
		gtk_widget_show(button);					
		gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);	
		GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
  		gtk_signal_connect(GTK_OBJECT(button), "clicked",	
					     GTK_SIGNAL_FUNC(message_box_ignore),
					     dialog);
		if( default_flag & MB_IGNORE ){
			gtk_widget_grab_focus(button);
			gtk_widget_grab_default(button);
		}
		i++;
	}

	
	gtk_window_set_transient_for(GTK_WINDOW(dialog),
		 GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	gtk_widget_show(dialog);				
	gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);	

	
	gtk_main();

	gdk_pixmap_unref(icon);		
	return result;				
}


int UtilMessageBox(
	char *message,				
	char *title,                
	unsigned int flag)          
{

	return(UtilMessageBoxSetDefault(message, title, flag, MB_OK|MB_YES));

}


static void special_set_default(GtkWidget *widget)
{

	GtkWidget	*page_button;		
	GtkWidget	*scan_button;		

	page_button = LookupWidget(widget, "page_checkbutton");	
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page_button), FALSE);	
	scan_button = LookupWidget(widget, "scan_checkbutton");	
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(scan_button), FALSE);	

}


gboolean on_special_dialog_delete_event
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;
	
#ifdef USE_LIB_GLADE
	special_set_default(widget);
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
		
	return TRUE;
}


void on_special_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}


void on_special_send_button_clicked(GtkButton *button, gpointer user_data)
{

	GtkWidget	*page_button;		
	GtkWidget	*scan_button;		
  
	result = ID_OK;

	
	page_button = LookupWidget(GTK_WIDGET(button), "page_checkbutton");	
	page_pause_mode = GTK_TOGGLE_BUTTON(page_button)->active;	
	scan_button = LookupWidget(GTK_WIDGET(button), "scan_checkbutton");	
	scan_pause_mode = GTK_TOGGLE_BUTTON(scan_button)->active;	

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}



void on_special_cancel_button_clicked(GtkButton *button, gpointer user_data)
{
		
	GtkWidget *window = GetTopWidget(GTK_WIDGET(button));

	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	special_set_default(window);
	gtk_widget_hide(window);	
	gtk_main_quit();			
#else
	gtk_widget_destroy(window);	
#endif
}



void on_special_std_button_clicked(GtkButton *button, gpointer user_data)
{
	
	special_set_default(GetTopWidget(GTK_WIDGET(button)));
}




static void InitItemValue(void)
{
		int i;
		for(i=0; i < nKindCnt; i++)
		  ItemValue[i] = 0;
}



void SetPenColor(GdkGC *gc, int red, int green, int blue)
{
  GdkColor  color;

  color.red   = red;
  color.green = green;
  color.blue  = blue;

  gdk_color_alloc(gdk_colormap_get_system(),&color);	
  gdk_gc_set_foreground(gc, &color);					
}




char *GetRegiDialogName(short page)
{
	int		i, index;
	char	*model_name;

	model_name = GetModelName();		
	index = -1;
	for (i=0; i < sizeof(RegiInfo)/sizeof(REGINFO); i++) {		
		if (!strcmp(RegiInfo[i].ModelName, model_name)) {	
			index = i;			
			break;
		}
	}
	index = (index == -1)? 0 : index;	
	
	return (RegiInfo[index].regi[page].DialogName);		
}




char *GetRegiDrawingName(short page)
{
	int		i, index;
	char	*model_name;

	model_name = GetModelName();		
	index = -1;
	for (i=0; i < sizeof(RegiInfo)/sizeof(REGINFO); i++) {		
		if (!strcmp(RegiInfo[i].ModelName, model_name)) {	
			index = i;			
			break;
		}
	}
	index = (index == -1)? 0 : index;	
	
	return (RegiInfo[index].regi[page].DrawingName);	
}



void DrawTestPrintPage(
	GtkWidget *regi_dialog,			
	GdkPixmap *pixmap,              
	HOTSPOT *hotspot,               
	CTRLITEM *ctrlitem,             
	short *items,                   
	short	group,                  
	short kindcnt)                  
{
	int			i;
	int			nStep = 17;			
	int			width, height;      
	short		x, y;               
	GdkGC		*gc;                
	GdkPoint	aPoints[6];         
	GtkWidget	*drawarea;          
	GdkRectangle	update_rect;    
	
	gc = gdk_gc_new(regi_dialog->window);		

	
	gdk_window_get_size(pixmap, &width, &height);		
	gdk_draw_rectangle(pixmap,					
						regi_dialog->style->bg_gc[GTK_STATE_NORMAL],
						TRUE, 0, 0, width, height);
	
	
	aPoints[0].x = 0;			
	aPoints[0].y = 0;
	aPoints[1].x = 0;
	aPoints[1].y = height -1;
	aPoints[2].x = width - nStep;
	aPoints[2].y = height -1;
	aPoints[3].x = width - nStep;
	aPoints[3].y = height - nStep;
	aPoints[4].x = width -1;
	aPoints[4].y = height - nStep;
	aPoints[5].x = width -1;
	aPoints[5].y = 0;
	SetPenColor(gc, 0xffff, 0xffff, 0xffff);	
	gdk_draw_polygon(pixmap, gc, TRUE, aPoints, 6);	
	SetPenColor(gc, 0, 0, 0);		
	gdk_draw_polygon(pixmap, gc, FALSE, aPoints, 6);	
	
	
	aPoints[0].x = width - nStep;
	aPoints[0].y = height -1;
	aPoints[1].x = width - nStep;
	aPoints[1].y = height - nStep;
	aPoints[2].x = width -1;
	aPoints[2].y = height - nStep;
	SetPenColor(gc, 0xc000, 0xc000, 0xc000);		
	gdk_draw_polygon(pixmap, gc, TRUE, aPoints, 3);	
	SetPenColor(gc, 0, 0, 0);				
	gdk_draw_polygon(pixmap, gc, FALSE, aPoints, 3);	

	
	SetPenColor(gc, 0x8000, 0x8000, 0x8000);		
	gdk_draw_line(pixmap, gc, 0, 0, 0, height -1);
	gdk_draw_line(pixmap, gc, 0, 0, width -1, 0);
	gdk_draw_line(pixmap, gc, width - nStep, height-1, width-1, height - nStep);
	
	
	for (i=0; i<kindcnt; i++) {		
		short	nOffsetX, nOffsetY, nStepX, nStepY, j;
		short	dx, dy;
		short	box_width, box_height;
		short	rep;
		
		if (hotspot[i].linedir) {	
			nOffsetX = 0;				
			nOffsetY = hotspot[i].len;	
			dx = hotspot[i].width;		
			dy = 0;
		} else {		
			nOffsetX = hotspot[i].len;	
			nOffsetY = 0;				
			dx = 0;
			dy = hotspot[i].width;		
		}
		
		if (hotspot[i].stepdir) {	
			nStepX = 0;					
			nStepY = hotspot[i].step;	
		} else {					
			nStepX = hotspot[i].step;	
			nStepY = 0;					
		}
		
		if (hotspot[i].repeat) {	
			if (group == i)
				SetPenColor(gc,
					hotspot[i].red, hotspot[i].green, hotspot[i].blue);
			else
				SetPenColor(gc, 0xc000, 0xc000, 0xc000);
				
			for (rep=0; rep < hotspot[i].repeat; rep++) {
				x = hotspot[i].drawx + dx * rep;
				y = hotspot[i].drawy + dy * rep;
				for (j=0; j < hotspot[i].cnt; j++, x+=nStepX, y+=nStepY) {
					gdk_draw_line(pixmap, gc,
						x-nOffsetX, y-nOffsetY, x+nOffsetX, y+nOffsetY);
				}
			}
		} else if (type & ORNAMENT_S600) {	
			
		 	x = hotspot[i].drawx;		
		 	y = hotspot[i].drawy;
		 	box_width = hotspot[i].width;
		 	box_height =  hotspot[i].len*2 + (i+1);
		 	for (j=0; j<hotspot[i].cnt; j++, x+=nStepX, y+=nStepY) {	
		 		int		startx, starty;
				if (group == i)		
				 	SetPenColor(gc,
						hotspot[i].red, hotspot[i].green, hotspot[i].blue);	
		 		else		
					SetPenColor(gc, 0xc000, 0xc000, 0xc000);	
		 		startx = x - nOffsetX;	
		 		starty = y - nOffsetY; 
		 		gdk_draw_rectangle(pixmap, gc, TRUE, startx, starty,	
		 								box_width, box_height);
		 		
				if (group == i)		
				 	SetPenColor(gc, 0, 0, 0);				
			 	else		
		 			SetPenColor(gc, 0xc000, 0xc000, 0xc000);	

		 		if (i == 0) {		
		 			int		linex, liney;
		 			linex = startx + box_width + 3;
		 			liney = starty + box_height/2;
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+2, liney-2);		
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+2, liney+2);
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+5, liney);
		 			
		 			linex = startx;
		 			gdk_draw_line (pixmap, gc,
						linex, liney, linex+box_width-1, liney);	
		 		} else {	
		 			int		linex, liney;
		 			linex = startx + box_width + 3;
		 			liney = starty + box_height/3;
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+2, liney-2);		
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+2, liney+2);
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+5, liney);
		 			linex = startx;
		 			gdk_draw_line (pixmap, gc,
						linex, liney, linex+box_width-1, liney);	
		 			
		 			linex = startx + box_width + 3;
		 			liney += box_height/3 + 1;
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+2, liney-2);		
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+2, liney+2);
		 			gdk_draw_line (pixmap, gc, linex, liney, linex+5, liney);
		 			linex = startx;
		 			gdk_draw_line (pixmap, gc,
						linex, liney, linex+box_width-1, liney);	
		 		}
			}
			
		} else {		
			if (group == i)		
			 	SetPenColor(gc,
					hotspot[i].red, hotspot[i].green, hotspot[i].blue);	
		 	else		
		 		SetPenColor(gc, 0xc000, 0xc000, 0xc000);	
		 	
		 	x = hotspot[i].drawx;		
		 	y = hotspot[i].drawy;
		 	box_width = hotspot[i].width;
		 	box_height = (!strcmp(GetModelName(), "BJF850"))?
							hotspot[i].len*2-1 : hotspot[i].len*2;
		 	for (j=0; j<hotspot[i].cnt; j++, x+=nStepX, y+=nStepY) {	
		 		int		startx, starty;
		 		startx = x - nOffsetX;	
		 		starty = y - nOffsetY; 
		 		gdk_draw_rectangle(pixmap, gc, TRUE, startx, starty,	
		 								box_width, box_height);
		 	}
		}
	}

	
	
	
	for (i=0; i<kindcnt; i++) {		
		if (i == group) 		
			SetPenColor(gc, 0xffff, 0x0000, 0x0000);	
		else 		
			SetPenColor(gc, 0xc000, 0xc000, 0xc000);	
		
		x = hotspot[i].selbox_x;
		y = hotspot[i].selbox_y;
		if (hotspot[i].stepdir) 	
			y += hotspot[i].step*(lpCtrlItem[i].nMax - items[i]);
		else			
			x += hotspot[i].step*(lpCtrlItem[i].nMax + items[i]);
		
		gdk_draw_rectangle(pixmap, gc, FALSE, x, y,	 		
							hotspot[i].selbox_width, hotspot[i].selbox_height);
	}
	
	
	
	
	drawarea
		= LookupWidget(GTK_WIDGET(regi_dialog), GetRegiDrawingName(nPageNum));
	gdk_window_get_size(drawarea->window, &width, &height);
	update_rect.x      = 0;			
	update_rect.y      = 0;
	update_rect.width  = width;
	update_rect.height = height;
	gtk_widget_draw(drawarea, &update_rect);		
	
	
	gdk_gc_destroy(gc);			
}



void MakeHotSpotTable(
	short page,					
	GtkWidget *dialog)          
{
	int			i, draw_width, draw_height, index;
	GtkWidget	*drawarea;		
	char		*model_name;	
	short		frame_width, frame_height;		
	
	
	model_name = GetModelName();		
	index = -1;
	for (i=0; i < sizeof(RegiInfo)/sizeof(REGINFO); i++) {
		if (!strcmp(RegiInfo[i].ModelName, model_name)) {	
			index = i;			
			break;
		}
	}
	index = (index == -1)? 0 : index;	
	
	
	lpCtrlItem = RegiInfo[index].regi[page].pCtrlItem;		
	lpBJLtbl   = RegiInfo[index].regi[page].pBJLTbl;        
	lpBoxInf   = RegiInfo[index].regi[page].lpBoxInf;       
	nKindCnt   = RegiInfo[index].regi[page].cnt;            
	type	   = RegiInfo[index].regi[page].type;			
	
	
	drawarea = LookupWidget(GTK_WIDGET(dialog), GetRegiDrawingName(nPageNum));	
	gdk_window_get_size(drawarea->window, &draw_width, &draw_height);           
	
	
	for (i=0; i < nKindCnt; i++) {		
		
		HotSpot[i].drawx = HotSpot[i].x = lpBoxInf[i].x;	
		HotSpot[i].drawy = HotSpot[i].y = lpBoxInf[i].y;
		HotSpot[i].width = lpBoxInf[i].width;			
		HotSpot[i].len = lpBoxInf[i].len;               
		HotSpot[i].step = lpBoxInf[i].step;             
		HotSpot[i].stepdir = lpBoxInf[i].stepdir;       
		HotSpot[i].linedir = lpBoxInf[i].linedir;       
		HotSpot[i].repeat = lpBoxInf[i].repeat;
		HotSpot[i].cnt = lpCtrlItem[i].nMax - lpCtrlItem[i].nMin + 1;	

		
		if (type & BIGAREA_TYPE2) {
			frame_width  = PICTURE_WIDTH_BIG2;
			frame_height = PICTURE_HEIGHT_BIG2;
		} else if (type & BIGAREA_TYPE3) {
			frame_width  = PICTURE_WIDTH_BIG3;
			frame_height = PICTURE_HEIGHT_BIG3;
		} else {
			frame_width  = PICTURE_WIDTH;
			frame_height = PICTURE_HEIGHT;
		}
		HotSpot[i].x += (draw_width - frame_width)/2 + lpBoxInf[i].selbox_dx;
		HotSpot[i].y += (draw_height - frame_height)/2 + lpBoxInf[i].selbox_dy;
		
		
		HotSpot[i].selbox_x = HotSpot[i].drawx + lpBoxInf[i].selbox_dx;
		HotSpot[i].selbox_y = HotSpot[i].drawy + lpBoxInf[i].selbox_dy;
		HotSpot[i].selbox_width = lpBoxInf[i].selbox_width;		
		HotSpot[i].selbox_height = lpBoxInf[i].selbox_height;

		
		HotSpot[i].red = lpBoxInf[i].red;			
		HotSpot[i].green = lpBoxInf[i].green;       
		HotSpot[i].blue = lpBoxInf[i].blue;         
	}
}





int UtilRegiDialog(short page)
{

	int			i;
	GtkWidget	*regi_dialog;		
	GtkObject	*adj;               
	short		frame_width, frame_height;		

	
#ifdef USE_LIB_GLADE
	regi_dialog = LookupWidget(NULL, GetRegiDialogName(page));	
#else
	regi_dialog = create_regi_dialog();		
#endif

	gtk_widget_realize(regi_dialog);		
	gtk_widget_realize(LookupWidget(regi_dialog, GetRegiDrawingName(page)));  

#ifdef USE_LIB_GLADE
	gtk_widget_add_events(LookupWidget(regi_dialog, GetRegiDrawingName(page)),
												 GDK_BUTTON_PRESS_MASK);
#endif

	
	if (!(strcmp(GetModelName(), "BJF860") & strcmp(GetModelName(), "BJF870"))) {	
		gtk_label_set_text(
			GTK_LABEL(LookupWidget(regi_dialog, "label8")),
				LookupText(g_keytext_list, "regi_bidir"));
		adj = gtk_adjustment_new(0, -5, 5, 1, 0, 0);
		gtk_spin_button_set_adjustment(
			GTK_SPIN_BUTTON(LookupWidget(regi_dialog, "regi_spinbutton6")), 
				GTK_ADJUSTMENT(adj));	
	}

	
	MakeHotSpotTable(page, regi_dialog);			
	InitItemValue();
	
   	
	if (type & BIGAREA_TYPE2) {		
		frame_width  = PICTURE_WIDTH_BIG2;
		frame_height = PICTURE_HEIGHT_BIG2;
	} else if (type & BIGAREA_TYPE3) {
			frame_width  = PICTURE_WIDTH_BIG3;
			frame_height = PICTURE_HEIGHT_BIG3;
	} else {		
		frame_width  = PICTURE_WIDTH;
		frame_height = PICTURE_HEIGHT;
	}
	regi_pixmap
		= gdk_pixmap_new(regi_dialog->window, frame_width, frame_height, -1);	
		
	DrawTestPrintPage(regi_dialog,
		regi_pixmap, HotSpot, lpCtrlItem, ItemValue, 0, nKindCnt);
	
	
	for(i=0; i < nKindCnt; i++) {
		gtk_spin_button_set_value(
			GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(regi_dialog),
			lpCtrlItem[i].CtrlName)),ItemValue[i]);
	}
	


	gtk_widget_show(regi_dialog);	
	gtk_window_set_transient_for(
		GTK_WINDOW(regi_dialog), GTK_WINDOW(UI_DIALOG(g_main_window)->window));

	gtk_main();						

	gdk_pixmap_unref(regi_pixmap);		
	
	if(result != ID_OK)
	  return(ID_CANCEL);

	return(ID_OK);
}




gboolean on_regi_dialog_delete_event(
	GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	gtk_widget_hide(GTK_WIDGET(widget));	
	gtk_main_quit();
#else
    gtk_widget_destroy(GTK_WIDGET(widget));	
#endif
	
	return TRUE;
}




void on_regi_dialog_destroy(GtkObject *object, gpointer user_data)
{
  gtk_main_quit();
}




gboolean on_regi_drawingarea_button_press_event(
	GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
	int		xPos, yPos, hit, i, j, current;
	short	items[REGI_EDITMAX];	
	GtkWidget	*dialog;
	
	xPos = event->x;		
	yPos = event->y;
	hit = FALSE;
	
	for (i=0; i<nKindCnt && !hit; i++) {	
		if (HotSpot[i].stepdir) {		
			if(HotSpot[i].x <= xPos
			   && xPos <= HotSpot[i].x + HotSpot[i].selbox_width) {	
				for(j=0; j<HotSpot[i].cnt; j++) {	
					if(HotSpot[i].y + HotSpot[i].step*j <= yPos &&
					   yPos <= (HotSpot[i].y + HotSpot[i].step*j
											 + HotSpot[i].selbox_height))
					{
						hit = TRUE;			
						current= i;		
						gtk_spin_button_set_value(
							GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(widget),
								lpCtrlItem[i].CtrlName)),
									lpCtrlItem[i].nMax - j);	
						break;
					}
				}
			}
		} else {		
			if (HotSpot[i].y <=yPos
			 && yPos<=(HotSpot[i].y + HotSpot[i].selbox_height)) {
				for(j=0; j<HotSpot[i].cnt; j++) {
					if ((HotSpot[i].x + HotSpot[i].step*j)<=xPos
					  && xPos<=(HotSpot[i].x + HotSpot[i].step*j
											 + HotSpot[i].selbox_width))
					{
						hit = TRUE;
						current = i;
						gtk_spin_button_set_value(
							GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(widget),
								lpCtrlItem[i].CtrlName)),
									j + lpCtrlItem[i].nMin);
						break;
					}
				}
			}
		}
	}
	if (!hit)			
		return FALSE;			
	
	
	for (i=0; i<nKindCnt; i++)
		items[i] = gtk_spin_button_get_value_as_int(
			GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(widget),
				lpCtrlItem[i].CtrlName)));

	
	dialog = LookupWidget(GTK_WIDGET(widget), GetRegiDialogName(nPageNum));	
	DrawTestPrintPage(dialog, regi_pixmap,
		HotSpot, lpCtrlItem, items, current, nKindCnt);
	
	return FALSE;
}




gboolean on_regi_drawingarea_expose_event(
	GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
	int	width, height, pix_width, pix_height;
	
	
	gdk_window_get_size(widget->window, &width, &height);	
	gdk_window_get_size(regi_pixmap, &pix_width, &pix_height);	
	
	gdk_draw_pixmap(widget->window,									
					widget->style->fg_gc[GTK_WIDGET_STATE(widget)],	
					regi_pixmap,                                    
					event->area.x-(width - pix_width)/2,            
					event->area.y-(height - pix_height)/2,          
					event->area.x,                                  
					event->area.y,                                  
					event->area.width, event->area.height);         
	
	return FALSE;
}




void on_regi_spinbutton_changed(GtkEditable *editable, gpointer user_data)
{
	int		current, i;
	short	items[REGI_EDITMAX];
	GtkWidget	*dialog;
	
	current = getnum(user_data);
	dialog = LookupWidget(GTK_WIDGET(editable), GetRegiDialogName(nPageNum));
	
	for (i=0; i<nKindCnt; i++)
		items[i] = gtk_spin_button_get_value_as_int(
			GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(editable),
				lpCtrlItem[i].CtrlName)));

	DrawTestPrintPage(dialog, regi_pixmap, HotSpot, lpCtrlItem,
		items, current, nKindCnt);
}




gboolean on_regi_spinbutton_focus_in_event(
	GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
{
	GtkWidget	*dialog;
	int			current, i;
	short	items[REGI_EDITMAX];
	
	current = getnum(user_data);
	dialog = LookupWidget(GTK_WIDGET(widget), GetRegiDialogName(nPageNum));
	
	for (i=0; i<nKindCnt; i++)
		items[i] = gtk_spin_button_get_value_as_int(
			GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(widget),
				lpCtrlItem[i].CtrlName)));

	DrawTestPrintPage(dialog, regi_pixmap, HotSpot, lpCtrlItem,
		items, current, nKindCnt);
	
	return FALSE;
}




int getnum(char *ptr)
{
	while (1) {
		if (*ptr >= 0x30 && *ptr <= 0x39)
			return (*ptr - 0x30);
		if (*ptr == 0x00)
			return 0;
		ptr++;
	}
}




int	SetCurrentTime(char *buf)
{
	time_t	t_time;
	struct	tm		*ltime;
	int		n;
	char	*p = buf;           
	
	memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;								
	memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;					
	memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;			

	memcpy(p, BJLSETTIME, BJLSETTIMELEN); p+=BJLSETTIMELEN;				
	time (&t_time);									
	ltime = localtime(&t_time);						
	n = sprintf(p, "%4d", ltime->tm_year + 1900); p += n;	
	n = sprintf(p, "%02d", ltime->tm_mon + 1); p += n;
	n = sprintf(p, "%02d", ltime->tm_mday);	p += n;
	n = sprintf(p, "%02d", ltime->tm_hour);	p += n;
	n = sprintf(p, "%02d", ltime->tm_min); p += n;
	n = sprintf(p, "%02d\x0a", ltime->tm_sec); p += n;

	memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;		
	
	return (BJLLEN + BJLSTARTLEN + BJLCTRLMODELEN
			+ BJLSETTIMELEN + BJLSETTIMEPARAMLEN + BJLENDLEN);
}	




void on_regi_ok_button_clicked(GtkButton *button, gpointer user_data)
{
	int	i;
	
	result = ID_OK;

	for (i=0; i<nKindCnt; i++)
		ItemValue[i] = gtk_spin_button_get_value_as_int(
			GTK_SPIN_BUTTON(LookupWidget(GTK_WIDGET(button),
				lpCtrlItem[i].CtrlName)));
	regi_flag++;

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));
	gtk_main_quit();
#else
    gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));
#endif
}



static void cleaning_set_default(GtkWidget *widget)
{

	GtkWidget	*radio_button;

	radio_button
	  = LookupWidget(GTK_WIDGET(widget), "cleaning_radiobutton1");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), TRUE);	
	radio_button
	  = LookupWidget(GTK_WIDGET(widget), "cleaning_radiobutton2");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), FALSE);	
	radio_button
	  = LookupWidget(GTK_WIDGET(widget), "cleaning_radiobutton3");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), FALSE);	
}	


gboolean on_cleaning_dialog_delete_event
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;			

#ifdef USE_LIB_GLADE
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
		
	return TRUE;
}


void on_cleaning_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}




void on_cleaning_execute_button_clicked(GtkButton *button, gpointer user_data)
{
	result = ID_OK;

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}



void on_cleaning_cancel_button_clicked(GtkButton *button, gpointer user_data)
{
	
	result = ID_CANCEL;			

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}


void on_cleaning_radiobutton_toggled(
	GtkToggleButton *togglebutton, gpointer user_data)
{
	if (GTK_TOGGLE_BUTTON(togglebutton)->active)	
		head_type = getnum(user_data);		
}


static void refreshing_set_default(GtkWidget *widget)
{

	GtkWidget	*radio_button;

	radio_button
	  = LookupWidget(GTK_WIDGET(widget), "refreshing_radiobutton1");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), TRUE);	
	radio_button
	  = LookupWidget(GTK_WIDGET(widget), "refreshing_radiobutton2");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), FALSE);	
	radio_button
	  = LookupWidget(GTK_WIDGET(widget), "refreshing_radiobutton3");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), FALSE);	
}	


gboolean
on_refreshing_dialog_delete_event      (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{

	result = ID_CANCEL;			

#ifdef USE_LIB_GLADE
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
		
	return TRUE;

}


void
on_refreshing_dialog_destroy           (GtkObject       *object,
                                        gpointer         user_data)
{
	gtk_main_quit();		
}


void
on_refreshing_execute_button_clicked   (GtkButton       *button,
                                        gpointer         user_data)
{
	result = ID_OK;

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif

}



void
on_refreshing_cancel_button_clicked    (GtkButton       *button,
                                        gpointer         user_data)
{

	result = ID_CANCEL;			

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif

}



void
on_refreshing_radiobutton_toggled      (GtkToggleButton *togglebutton,
                                        gpointer         user_data)
{

	if (GTK_TOGGLE_BUTTON(togglebutton)->active)	
		refresh_head_type = getnum(user_data);

}


static void autopower_set_default(void)
{
	poweron_index = 0;
	poweroff_index = 0;

}


gboolean on_autopower_dialog_delete_event
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;
	
#ifdef USE_LIB_GLADE
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
	autopower_set_default();
	
	return TRUE;
}

void on_autopower_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}


void on_autopower_send_button_clicked(GtkButton *button, gpointer user_data)
{
	GtkWidget	*power_on_combo;		
	GtkWidget	*power_off_combo;		

	result = ID_OK;

	power_on_combo = LookupWidget(GTK_WIDGET(button), "autopower_combo1");	
	power_off_combo = LookupWidget(GTK_WIDGET(button), "autopower_combo2");	

	/* Ver.2.80 */
	power_on_mode = gtk_combo_box_get_active_text(GTK_COMBO_BOX(power_on_combo));
	power_off_mode = gtk_combo_box_get_active_text(GTK_COMBO_BOX(power_off_combo));
//	power_on_mode = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(power_on_combo)->entry));	
//	power_off_mode = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(power_off_combo)->entry));	
	
	poweron_index = GetAutoPowerIndex(AutoPowerOnKey, 2, power_on_mode);
	poweroff_index = GetAutoPowerIndex(AutoPowerOffKey, 6, power_off_mode);

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}


void on_autopower_cancel_button_clicked(GtkButton *button, gpointer user_data)
{
	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
	autopower_set_default();
}



static void drylevel_set_default(GtkWidget *widget)
{
 
	GtkWidget	*radio_button = NULL;
	char		*model_name = GetModelName();
   
	if( !strcmp(model_name, "BJF900") || !strcmp(model_name, "BJF9000") || 
		!strcmp(model_name, "PIXUS950I") ){
		radio_button = LookupWidget(GTK_WIDGET(widget),
									"drylevel3_radiobutton1");
	
	}else if( !strcmp(model_name, "BJS500") || !strcmp(model_name, "PIXUS550I")
			 || !strcmp(model_name, "PIXUS850I") ){
		radio_button =  LookupWidget(GTK_WIDGET(widget),
									"drylevel5_radiobutton3");
	}
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), TRUE);  
}


gboolean
on_drylevel_dialog_delete_event
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	drylevel_set_default(widget);
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
		
	return TRUE;

}

void on_drylevel_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}


void on_drylevel_send_button_clicked(GtkButton *button, gpointer user_data)
{

	result = ID_OK;

	
#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif

}



void on_drylevel_cancel_button_clicked
				(GtkButton *button, gpointer user_data)
{

	GtkWidget	*window = GetTopWidget(GTK_WIDGET(button));

	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	drylevel_set_default(window);
	gtk_widget_hide(window);	
	gtk_main_quit();			
#else
	gtk_widget_destroy(window);	
#endif
}



void on_drylevel_std_button_clicked(GtkButton *button, gpointer user_data)
{
	drylevel_set_default(GetTopWidget(GTK_WIDGET(button)));
}

void on_drylevel_radiobutton_toggled(GtkToggleButton *togglebutton,
									 gpointer user_data)
{

	if (GTK_TOGGLE_BUTTON(togglebutton)->active)
	  drylevel_value = getnum(user_data);

}





/*****************************************************************
 *
 *	 Quiet Mode Signal Handler 
 *			    Added '01.11.05
 *****************************************************************/


static void quiet_set_default(GtkWidget *widget)
{

	GtkWidget *quiet_button = 
			LookupWidget(GTK_WIDGET(widget), "quiet_checkbutton");

	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(quiet_button), FALSE);  

}


void on_quiet_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}


gboolean
on_quiet_dialog_delete_event 
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	
	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	quiet_set_default(GTK_WIDGET(widget));
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
	return TRUE;

}




void on_quiet_send_button_clicked(GtkButton *button, gpointer user_data)
{

	GtkWidget	*quiet_button;

	result = ID_OK;

	quiet_button = LookupWidget(GTK_WIDGET(button), "quiet_checkbutton");	
	quiet_mode = GTK_TOGGLE_BUTTON(quiet_button)->active;


#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}




void on_quiet_cancel_button_clicked
				(GtkButton *button, gpointer user_data)
{

	GtkWidget *window = GetTopWidget(GTK_WIDGET(button));

	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	quiet_set_default(window);
	gtk_widget_hide(window);	
	gtk_main_quit();			
#else
	gtk_widget_destroy(window);	
#endif

}



void on_quiet_std_button_clicked(GtkButton *button, gpointer user_data)
{
		
	quiet_set_default(GetTopWidget(GTK_WIDGET(button)));

}






/*****************************************************************
 *
 *	 Ink Warning Signal Handler 
 *			    Added '01.11.16
 *****************************************************************/

static void ink_warning_set_default(GtkWidget *widget)
{

	GtkWidget *warning_button = 
			LookupWidget(widget, "ink_warning_checkbutton");
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(warning_button), TRUE);
	
}


void on_ink_warning_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}


gboolean
on_ink_warning_dialog_delete_event 
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;


#ifdef USE_LIB_GLADE
	ink_warning_set_default(widget);
	gtk_widget_hide(GTK_WIDGET(widget));
	gtk_main_quit();
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
	return TRUE;

}




void on_ink_warning_send_button_clicked(GtkButton *button, gpointer user_data)
{

	GtkWidget	*warning_button;

	result = ID_OK;

	warning_button = LookupWidget(GTK_WIDGET(button),
								  "ink_warning_checkbutton");	
	warning_mode = GTK_TOGGLE_BUTTON(warning_button)->active;


#ifdef USE_LIB_GLADE
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}



void on_ink_warning_cancel_button_clicked
				(GtkButton *button, gpointer user_data)
{

	GtkWidget *window = GetTopWidget(GTK_WIDGET(button));
	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	ink_warning_set_default(window);
	gtk_widget_hide(window);	
	gtk_main_quit();			
#else
	gtk_widget_destroy(window);
#endif

}



void on_ink_warning_std_button_clicked(GtkButton *button, gpointer user_data)
{
	
	ink_warning_set_default(GetTopWidget(GTK_WIDGET(button)));
}




/*****************************************************************
 *
 *	 Ink Reset Signal Handler 
 *			    Added '01.11.16
 *****************************************************************/


void
on_ink_reset_button_toggled            (GtkToggleButton *togglebutton,
                                        gpointer         user_data)
{

	GtkWidget*	window;
	GtkWidget*	black_button;
	GtkWidget*	color_button;
	GtkWidget*	excute_button;
	
	window = GetTopWidget(GTK_WIDGET(togglebutton));
	excute_button = LookupWidget(window, "ink_reset_excute_button");

	black_button = LookupWidget(window, "black_reset_checkbutton");
	color_button = LookupWidget(window, "color_reset_checkbutton");
	
	if( !(GTK_TOGGLE_BUTTON(black_button)->active) &&
		!(GTK_TOGGLE_BUTTON(color_button)->active) ){
		gtk_widget_grab_default( LookupWidget(window,
									"ink_reset_cancel_button"));
		gtk_widget_set_sensitive(excute_button, FALSE);
	}
	else{
		gtk_widget_set_sensitive(excute_button, TRUE);
		gtk_widget_grab_default(excute_button);
  }

}



void on_ink_reset_dialog_destroy(GtkObject *object, gpointer user_data)
{
	gtk_main_quit();			
}


gboolean
on_ink_reset_dialog_delete_event 
(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{

	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	{
		GtkWidget	*black_button;
		GtkWidget	*color_button;

		black_button = LookupWidget(GTK_WIDGET(widget),
									"black_reset_checkbutton");	
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(black_button), FALSE);  
		color_button = LookupWidget(GTK_WIDGET(widget),
									"color_reset_checkbutton");
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(color_button), FALSE);  
		gtk_widget_hide(GTK_WIDGET(widget));
		gtk_main_quit();
	}
#else
	gtk_widget_destroy(GTK_WIDGET(widget));
#endif
	return TRUE;

}



void on_ink_reset_execute_button_clicked(GtkButton *button, gpointer user_data)
{

	GtkWidget	*black_button;
	GtkWidget	*color_button;
	
	result = ID_OK;

	black_button = LookupWidget(GTK_WIDGET(button),
								"black_reset_checkbutton");	
	black_reset= GTK_TOGGLE_BUTTON(black_button)->active;
	color_button = LookupWidget(GTK_WIDGET(button),
								"color_reset_checkbutton");	
	color_reset = GTK_TOGGLE_BUTTON(color_button)->active;

#ifdef USE_LIB_GLADE
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(black_button), FALSE);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(color_button), FALSE);
	gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
	gtk_main_quit();			
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif
}




void on_ink_reset_cancel_button_clicked
				(GtkButton *button, gpointer user_data)
{
	result = ID_CANCEL;

#ifdef USE_LIB_GLADE
	{
		GtkWidget	*black_button;
		GtkWidget	*color_button;

		black_button = LookupWidget(GTK_WIDGET(button),
									"black_reset_checkbutton");	
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(black_button), FALSE);  
		color_button = LookupWidget(GTK_WIDGET(button),
									"color_reset_checkbutton");
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(color_button), FALSE);  
		gtk_widget_hide(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
		gtk_main_quit();			
	}
#else
	gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button)));	
#endif

}





static void SetDryLevel(void)
{

	GtkWidget*	drylevel_dialog = NULL;
	char 		buf[128];
	char		*p=buf;
	char 		temp[32];
	int 		total_bytes;
	int 		cmd_bytes;
	char		*model_name;
	GtkWidget	*button=NULL;
	GtkWidget*	send_button=NULL;

	model_name = GetModelName();
	
	if(!strcmp(model_name, "BJF900") || !strcmp(model_name, "BJF9000") 
		|| !strcmp( model_name, "PIXUS950I") ){

#ifdef USE_LIB_GLADE
		drylevel_dialog = LookupWidget(NULL, "drylevel3_dialog");
#else
		drylevel_dialog = create_drylevel3_dialog();
#endif
				
		gtk_widget_realize(drylevel_dialog);
		gtk_widget_show(drylevel_dialog);
		gtk_window_set_transient_for(GTK_WINDOW(drylevel_dialog),
								 GTK_WINDOW(UI_DIALOG(g_main_window)->window));
		button = LookupWidget(drylevel_dialog, "drylevel3_radiobutton1");
		send_button = LookupWidget(drylevel_dialog, "drylevel3_send_button");
		gtk_widget_grab_focus(send_button);

	}else if(!strcmp(model_name, "BJS500") || !strcmp( model_name, "PIXUS550I")
		|| !strcmp( model_name, "PIXUS850I") ){
#ifdef USE_LIB_GLADE
		drylevel_dialog = LookupWidget(NULL, "drylevel5_dialog");
#else
		drylevel_dialog = create_drylevel5_dialog();
#endif
		
		gtk_widget_realize(drylevel_dialog);
		gtk_widget_show(drylevel_dialog);
		gtk_window_set_transient_for(GTK_WINDOW(drylevel_dialog),
								 GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	
		button = LookupWidget(drylevel_dialog, "drylevel5_radiobutton3");
		send_button = LookupWidget(drylevel_dialog, "drylevel5_send_button");
		gtk_widget_grab_focus(send_button);
	}

	gtk_signal_emit_by_name(GTK_OBJECT(button), "toggled", NULL);

	gtk_main();
	
	if(result != ID_OK)
	  return;
	
	 	
	if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_9"),
					  g_window_title, MB_ICON_EXCLAMATION | MB_OK | 
					  MB_CANCEL)==ID_CANCEL){
		drylevel_set_default(drylevel_dialog);
		return ;
	}
		
	memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
	memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
	memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;
	cmd_bytes = sprintf(temp, BJLDRYLEVEL, drylevel_value);
	memcpy(p, temp, cmd_bytes); p+=cmd_bytes;
	memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
	*p = 0x00;
	total_bytes = BJLLEN + BJLSTARTLEN
						+ BJLCTRLMODELEN + cmd_bytes + BJLENDLEN +1;

	PutPrintData(buf, total_bytes);
}




void UtilCleaning(LPUIDB uidb)
{
	char		buf[128];			
	char		*p = buf;           
	char		*model_name;		
	GtkWidget*	cleaning_dialog;	
	
	if (g_socketname == NULL)		
		return ;                    

	model_name = GetModelName();	

	
	if (!strcmp(model_name,"BJS600") || !strcmp(model_name,"BJS630")
	 || !strcmp(model_name,"BJS6300") || !strcmp(model_name, "BJS500")
		|| !strcmp(model_name,"BJS300") || !strcmp(model_name, "PIXUS550I")
		|| !strcmp( model_name, "PIXUS850I") ) {
		
		GtkWidget *excute_button;

#ifdef USE_LIB_GLADE
		cleaning_dialog = LookupWidget(NULL, "cleaning_dialog");	
#else
		cleaning_dialog = create_cleaning_dialog();	
#endif
		gtk_widget_realize(cleaning_dialog);			
		cleaning_set_default(cleaning_dialog);
		gtk_widget_show(cleaning_dialog);			
		gtk_window_set_transient_for(GTK_WINDOW(cleaning_dialog),
			GTK_WINDOW(UI_DIALOG(g_main_window)->window));

		excute_button = LookupWidget(cleaning_dialog, "cleaning_button1");
		gtk_widget_grab_focus(excute_button);

		gtk_main();									
  		
  		if (result != ID_OK)		
			return ;				
	}
	
	
	if (UtilMessageBox(LookupText(g_keytext_list, "utility_message_11"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
		return;
	
	
	if (!strcmp(model_name, "BJF850") | !strcmp(model_name, "BJF860") |
					 !strcmp(model_name, "BJF870")) {	
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, BJLCLEAN1, BJLCLEAN1LEN); p+=BJLCLEAN1LEN;        
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;                 
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLCLEAN1LEN+BJLENDLEN+1);	
	} else if (!strcmp(model_name, "BJF360")) {		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, BJLCLEAN3, BJLCLEAN3LEN); p+=BJLCLEAN3LEN;        
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;                 
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLCLEAN3LEN+BJLENDLEN+1);	
	} else if (!strcmp( model_name, "BJF900") || !strcmp(model_name, "BJF9000")
			   || !strcmp(model_name, "PIXUS950I") ){		

		int		n;
		n = SetCurrentTime(p); p+=n;
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, BJLCLEAN3, BJLCLEAN3LEN); p+=BJLCLEAN3LEN;   
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;                 
		*p = 0x00;
		PutPrintData(buf,
			n+BJLLEN+BJLSTARTLEN+BJLCLEAN3LEN+BJLENDLEN+1);
	} else {		
		int		n;
		
		n = SetCurrentTime(p); p+=n;			
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, S600CleanCommand[head_type].cmd,
			S600CleanCommand[head_type].len);	
		p+=S600CleanCommand[head_type].len;
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;                 
		*p = 0x00;
		PutPrintData(buf,
			n+BJLLEN+BJLSTARTLEN+S600CleanCommand[head_type].len+BJLENDLEN+1);
	}
	
	UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK);
}





void UtilRefreshing(LPUIDB uidb)
{
	char		buf[128];
	char		*p = buf;
	char		*model_name;		
	char*		msg=NULL;
	
	GtkWidget* refreshing_dialog = NULL;


	if (g_socketname == NULL)			
		return;                         


	model_name = GetModelName();	

	
	if ( !strcmp(model_name, "PIXUS550I") || !strcmp(model_name, "PIXUS850I")){
				
		GtkWidget *excute_button = NULL;

#ifdef USE_LIB_GLADE
		refreshing_dialog = LookupWidget(NULL, "refreshing_dialog");	
#else
		refreshing_dialog = create_refreshing_dialog();	
#endif
		gtk_widget_realize( refreshing_dialog );
		
		refreshing_set_default(refreshing_dialog);
		gtk_widget_show(refreshing_dialog);
		gtk_window_set_transient_for(GTK_WINDOW(refreshing_dialog),
			GTK_WINDOW(UI_DIALOG(g_main_window)->window));

		excute_button = 
			LookupWidget(refreshing_dialog, "refreshing_execute_button");
		gtk_widget_grab_focus(excute_button);

		gtk_main();
  		
  		if (result != ID_OK)
			return ;
		
		switch( refresh_head_type ){
			
		case 0:
			msg = LookupText(g_keytext_list, "utility_message_12");
			break;
		case 1:
			msg = LookupText(g_keytext_list, "utility_message_23");
			break;
		case 2:
			msg = LookupText(g_keytext_list, "utility_message_24");
			break;
		}
	}
	else if( !strcmp(model_name, "PIXUS950I") ){
		msg = LookupText(g_keytext_list, "utility_message_22");
	}
	else{
		msg = LookupText(g_keytext_list, "utility_message_12");
	}

	if (UtilMessageBox( msg, g_window_title, 
						MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
		return;
	
	if (!strcmp(model_name, "BJF850") | !strcmp(model_name, "BJF860") |
					!strcmp(model_name, "BJF870")) {	
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;    	
		memcpy(p, BJLCLEAN2, BJLCLEAN2LEN); p+=BJLCLEAN2LEN;	
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;				
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLCLEAN2LEN+BJLENDLEN+1);	
	} else if (!strcmp(model_name, "BJF360")) {		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;       
		memcpy(p, BJLCLEAN4, BJLCLEAN4LEN); p+=BJLCLEAN4LEN;    
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;             
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLCLEAN4LEN+BJLENDLEN+1);	

	} // Ver.2.2 Start 
	else if (!strcmp(model_name, "PIXUS550I") || 
			   !strcmp(model_name, "PIXUS850I") ){
		int n;

		n = SetCurrentTime(p); p+=n;
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, RefreshingCommand[refresh_head_type].cmd,
			   RefreshingCommand[refresh_head_type].len);	
		p+=RefreshingCommand[refresh_head_type].len;
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;                 
		*p = 0x00;
		PutPrintData(buf, n+BJLLEN+BJLSTARTLEN+
					 RefreshingCommand[refresh_head_type].len+BJLENDLEN+1);

	} // Ver.2.2 End 
	else {		
		int		n;
		
		n = SetCurrentTime(p); p+=n;		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;       
		memcpy(p, BJLCLEAN4, BJLCLEAN4LEN); p+=BJLCLEAN4LEN;    
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;             
		*p = 0x00;
		PutPrintData(buf, n+BJLLEN+BJLSTARTLEN+BJLCLEAN4LEN+BJLENDLEN+1);	
	}
	
	
	UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK);
}


void UtilNozzleCheck(LPUIDB uidb)
{
	char		buf[128];
	char		*p = buf;
	char		*model_name;		
	
	if (g_socketname == NULL)
		return ;

	if (UtilMessageBox(LookupText(g_keytext_list, "utility_message_7"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_OK) {

		model_name = GetModelName();		

		if (!strcmp(model_name, "BJS600") | !strcmp(model_name, "BJS630") |
			!strcmp(model_name, "BJS6300") | !strcmp(model_name, "BJF900") | 
			!strcmp(model_name, "BJF9000") | !strcmp(model_name, "BJS300") |
			!strcmp(model_name, "BJS500") | !strcmp(model_name, "PIXUS550I") |
			!strcmp(model_name, "PIXUS850I") | !strcmp(model_name,"PIXUS950I"))
		  {
			int		n;
		
			n = SetCurrentTime(p); p+=n;	
			memcpy(p, bjl_cmds, BJLLEN);p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN);p+=BJLSTARTLEN;
			memcpy(p, BJLNOZZLECHECK, BJLNOZZLECHECKLEN);p+=BJLNOZZLECHECKLEN;
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;
			*p = 0x00;
			PutPrintData(buf,
				n+BJLLEN+BJLSTARTLEN+BJLNOZZLECHECKLEN+BJLENDLEN+1);
		} else {		
			memcpy(p, bjl_cmds, BJLLEN);p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN);p+=BJLSTARTLEN;
			memcpy(p, BJLNOZZLECHECK, BJLNOZZLECHECKLEN);p+=BJLNOZZLECHECKLEN;
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;
			*p = 0x00;
			PutPrintData(buf, 
						 BJLLEN+BJLSTARTLEN+BJLNOZZLECHECKLEN+BJLENDLEN+1);
		}
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);		
	}

}


void UtilHeadAdjust(LPUIDB uidb)
{
	int			i;
	char		buf[REGI_BUF_SIZE];			
	char		temp[REGI_TMP_SIZE];        
	char		*p = buf;                   
	char		*msg;                       
	int			nValue;
	char		*model_name;				

	if (g_socketname == NULL)			
		return ;                        

	model_name = GetModelName();		

	
	if (!strcmp(model_name,"BJF850") || !strcmp(model_name,"BJF860")
	 || !strcmp(model_name,"BJF870")) {
		if (!strcmp(GetModelName(), "BJF850"))	
			msg = LookupText(g_keytext_list, "utility_message_1");
		else		
			msg = LookupText(g_keytext_list, "utility_message_16");
		
		
		if (UtilMessageBox(msg, g_window_title,		
				MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
			return ;			

		
		if (!strcmp(GetModelName(), "BJF850")) {	
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;				
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;	
			memcpy(p, BJLMANUAL, BJLMANUALLEN); p+=BJLMANUALLEN;
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;			
			*p = 0x00;
			PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLMANUALLEN+BJLENDLEN+1);	
		} else {	
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;				
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;   
			memcpy(p, BJLREGI1, BJLREGI1LEN); p+=BJLREGI1LEN;   
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;          
			*p = 0x00;
			PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLREGI1LEN+BJLENDLEN+1);	
		}
		
		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_3"),
			g_window_title, MB_ICON_EXCLAMATION | MB_YES | MB_NO) == ID_NO) {	
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_4"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			return;
		}
  
		
		nPageNum = 0;
		if (UtilRegiDialog(nPageNum) != ID_OK)		
			return ;						
	
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;			
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
		
  		for (i=0; i<nKindCnt; i++) {	
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG,
				lpBJLtbl[i], nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		}
  		
  		nValue = ItemValue[2];
  		sprintf(temp, BJLSETREG,
			lpBJLtbl[6], nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
			BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
			+(BJLSETREGLEN*(nKindCnt+1))+BJLENDLEN+1);
  	
		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_5"),
			g_window_title, MB_ICON_INFORMATION | MB_OK);

	
	
	
	} else if (!strcmp(model_name, "BJF360")) {	
		
		msg = LookupText(g_keytext_list, "utility_message_18");
		if (UtilMessageBox(msg, g_window_title,
				MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
			return ;			

		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy(p, BJLMANUAL1, BJLMANUAL1LEN); p+=BJLMANUAL1LEN;	
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;				
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLMANUAL1LEN+BJLENDLEN+1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_3"),
			g_window_title, MB_ICON_EXCLAMATION | MB_YES | MB_NO) == ID_NO) {	
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_4"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			return;
		}
  
		
		nPageNum = 0;
		if (UtilRegiDialog(nPageNum) != ID_OK)		
			return ;						
	
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;			
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
		
  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG, lpBJLtbl[i],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		}
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
			BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
			+(BJLSETREGLEN*nKindCnt)+BJLENDLEN+1);	
  		
		msg = LookupText(g_keytext_list, "utility_message_19");
		UtilMessageBox(msg, g_window_title,	MB_ICON_EXCLAMATION | MB_OK);
  		
		
		p = buf;
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;       
		memcpy(p, BJLMANUAL2, BJLMANUAL2LEN); p+=BJLMANUAL2LEN; 
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;              
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLMANUALLEN+BJLENDLEN+1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		nPageNum = 1;
		if (UtilRegiDialog(nPageNum) != ID_OK)
			return ;						
  		
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;  
		
  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG, lpBJLtbl[i],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		}
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
			BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
			+(BJLSETREGLEN*nKindCnt)+BJLENDLEN+1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_5"),
			g_window_title, MB_ICON_INFORMATION | MB_OK);

	
	
	} else if (!strcmp(model_name,"BJF900") || !strcmp(model_name,"BJF9000")||
			   !strcmp(model_name,"BJS300") || !strcmp(model_name,"BJS500") ||
			   !strcmp( model_name, "PIXUS550I") ){
												
		int 	n;
		
		msg = LookupText(g_keytext_list, "utility_message_20");

		if (UtilMessageBox(msg, g_window_title,
				MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
			return ;			

		
		p = buf;
		n = SetCurrentTime(p); p += n;		
		
		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy(p, BJLREGI1, BJLREGI1LEN); p+=BJLREGI1LEN;		
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;				
		*p = 0x00;
		PutPrintData(buf,
			n + BJLLEN + BJLSTARTLEN + BJLREGI1LEN + BJLENDLEN + 1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_3"),
			g_window_title, MB_ICON_EXCLAMATION | MB_YES | MB_NO) == ID_NO) { 
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_4"),
						   g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			return;
		}
  
		
		nPageNum = 0;
		if (UtilRegiDialog(nPageNum) != ID_OK)		
			return ;						
	
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;			
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
		
  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG, lpBJLtbl[i],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		}

		nValue = ItemValue[2];
  		sprintf(temp, BJLSETREG, lpBJLtbl[6],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
			BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
			+(BJLSETREGLEN*(nKindCnt+1))+BJLENDLEN+1);
	
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_5"),
			g_window_title, MB_ICON_INFORMATION | MB_OK);
  		
		
		  
	} 
	else if (!strcmp(model_name,"PIXUS950I") ){
		
		int 	n;

		msg = LookupText(g_keytext_list, "utility_message_25");
		if (UtilMessageBox(msg, g_window_title,
				MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
			return ;			

		
		p = buf;
		n = SetCurrentTime(p); p += n;		
		
		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy(p, BJLREGI1, BJLREGI1LEN); p+=BJLREGI1LEN;		
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;				
		*p = 0x00;
		PutPrintData(buf,
			n + BJLLEN + BJLSTARTLEN + BJLREGI1LEN + BJLENDLEN + 1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_3"),
			g_window_title, MB_ICON_EXCLAMATION | MB_YES | MB_NO) == ID_NO) { 
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_4"),
						   g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			return;
		}
  
		
		nPageNum = 0;
		if (UtilRegiDialog(nPageNum) != ID_OK)		
			return ;						
	
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;			
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
		


  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG, lpBJLtbl[i],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		}
				
		// Yellow
		nValue = ItemValue[0];
		sprintf(temp, BJLSETREG, lpBJLtbl[8],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
		
		// Yellow Bi
		nValue = ItemValue[5];
		sprintf(temp, BJLSETREG, lpBJLtbl[9],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;

		// LC Bi
		nValue = ItemValue[6];
		sprintf(temp, BJLSETREG, lpBJLtbl[10],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;

		// LM Bi
		nValue = ItemValue[7];
		sprintf(temp, BJLSETREG, lpBJLtbl[11],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;


		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
					 BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
					 +(BJLSETREGLEN*(nKindCnt+4))+BJLENDLEN+1);


		UtilMessageBox(LookupText(g_keytext_list, "utility_message_5"),
			g_window_title, MB_ICON_INFORMATION | MB_OK);
  		
		
		  
	} 
	else if (!strcmp(model_name,"PIXUS850I") ){
		
		int 	n;
		
		msg = LookupText(g_keytext_list, "utility_message_25");
		if (UtilMessageBox(msg, g_window_title,
				MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
			return ;			

		
		p = buf;
		n = SetCurrentTime(p); p += n;		
		
		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy(p, BJLREGI1, BJLREGI1LEN); p+=BJLREGI1LEN;		
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;				
		*p = 0x00;
		PutPrintData(buf,
			n + BJLLEN + BJLSTARTLEN + BJLREGI1LEN + BJLENDLEN + 1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_3"),
			g_window_title, MB_ICON_EXCLAMATION | MB_YES | MB_NO) == ID_NO) { 
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_4"),
						   g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			return;
		}
  
		
		nPageNum = 0;
		if (UtilRegiDialog(nPageNum) != ID_OK)		
			return ;						
	
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;			
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
		
  		
		
		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG, lpBJLtbl[i],
					nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
			
		}
		
		nValue = ItemValue[2];
		sprintf(temp, BJLSETREG, lpBJLtbl[11],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
		
		nValue = ItemValue[8];
		sprintf(temp, BJLSETREG, lpBJLtbl[12],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
		
		
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
					 BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
					 +(BJLSETREGLEN*(nKindCnt+2))+BJLENDLEN+1);
		
		

		if( UtilMessageBoxSetDefault(
			LookupText(g_keytext_list, "utility_message_26"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL, MB_CANCEL)
			==ID_CANCEL )
			return;
  		
		
		p = buf;
		n = SetCurrentTime(p); p += n;		

		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;       
		memcpy(p, BJLBANDREGI1, BJLBANDREGI1LEN); p+=BJLBANDREGI1LEN; 
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;              
		*p = 0x00;
		PutPrintData(buf,
			 n + BJLLEN + BJLSTARTLEN + BJLBANDREGI1LEN + BJLENDLEN + 1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
					   g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		nPageNum = 1;
		if (UtilRegiDialog(nPageNum) != ID_OK)
			return ;						
  		
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;  
		
  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETBANDREG, lpBJLtbl[i],
					nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETBANDREGLEN); p += BJLSETBANDREGLEN;
  		}
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
					 BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
					 +(BJLSETBANDREGLEN*nKindCnt)+BJLENDLEN+1);
		
		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_5"),
					   g_window_title, MB_ICON_INFORMATION | MB_OK);
		
		
		
		
	}
	else {			// For BJS600
		int		n;
		
		msg = LookupText(g_keytext_list, "utility_message_20");
		if (UtilMessageBox(msg, g_window_title,
				MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_CANCEL)
			return ;			

		
		p = buf;
		n = SetCurrentTime(p); p += n;		
		
		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy(p, BJLREGI1, BJLREGI1LEN); p+=BJLREGI1LEN;		
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;				
		*p = 0x00;
		PutPrintData(buf,
			n + BJLLEN + BJLSTARTLEN + BJLREGI1LEN + BJLENDLEN + 1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_3"),
			g_window_title, MB_ICON_EXCLAMATION | MB_YES | MB_NO) == ID_NO) {	
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_4"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			return;
		}
  
		
		nPageNum = 0;
		if (UtilRegiDialog(nPageNum) != ID_OK)		
			return ;						
	
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;			
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
		
  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETREG, lpBJLtbl[i],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
  		}

  		
  		nValue = ItemValue[2];
  		sprintf(temp, BJLSETREG, lpBJLtbl[6],
			nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  		memcpy(p, temp, BJLSETREGLEN); p += BJLSETREGLEN;
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
			BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
			+(BJLSETREGLEN*(nKindCnt+1))+BJLENDLEN+1);
  		
  		
		msg = LookupText(g_keytext_list, "utility_message_21");
		UtilMessageBox(msg, g_window_title,	MB_ICON_EXCLAMATION | MB_OK);
  		
		
		p = buf;
		n = SetCurrentTime(p); p += n;		

		
		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;					
		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;       
		memcpy(p, BJLBANDREGI1, BJLBANDREGI1LEN); p+=BJLBANDREGI1LEN; 
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;              
		*p = 0x00;
		PutPrintData(buf,
			n + BJLLEN + BJLSTARTLEN + BJLBANDREGI1LEN + BJLENDLEN + 1);	

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK);

		
		nPageNum = 1;
		if (UtilRegiDialog(nPageNum) != ID_OK)
			return ;						
  		
		
		p = buf;
  		memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;						
  		memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;           
		memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;  
		
  		for (i=0; i<nKindCnt; i++) {	
  			int		nValue;
  		
  			nValue = ItemValue[i];		
  			sprintf(temp, BJLSETBANDREG, lpBJLtbl[i],
				nValue<0? '-':(nValue>0? '+':'0'), abs(nValue));
  			memcpy(p, temp, BJLSETBANDREGLEN); p += BJLSETBANDREGLEN;
  		}
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;	
		*p = 0x00;			
		PutPrintData(buf,
			BJLLEN+BJLSTARTLEN+BJLCTRLMODELEN
			+(BJLSETBANDREGLEN*nKindCnt)+BJLENDLEN+1);

		
		UtilMessageBox(LookupText(g_keytext_list, "utility_message_5"),
			g_window_title, MB_ICON_INFORMATION | MB_OK);
	}
}





void UtilRollerCleaning(LPUIDB uidb)
{
	char		buf[128];
	char		*p = buf;
	char		*model_name;

	if (g_socketname == NULL)
		return ;

	model_name = GetModelName();		
	if (!strcmp(model_name,"BJS600") || !strcmp(model_name,"BJS630") ||
		!strcmp(model_name,"BJS6300") || !strcmp(model_name,"BJF900") ||
		!strcmp(model_name,"BJF900") || !strcmp(model_name,"BJS300") ||
		!strcmp(model_name,"BJS500") ) 
		return;						
	
	if (strcmp(model_name, "BJF360")) {		
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_10"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL)==ID_OK) {

			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLROLLER1, BJLROLLER1LEN); p+=BJLROLLER1LEN;
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;
			*p = 0x00;
			PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLROLLER1LEN+BJLENDLEN+1);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_13"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);

			p = buf;
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLROLLER2, BJLROLLER2LEN); p+=BJLROLLER2LEN;
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;
			*p = 0x00;
			PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLROLLER2LEN+BJLENDLEN+1);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_14"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);

			PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLROLLER2LEN+BJLENDLEN+1);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_15"),
				g_window_title, MB_ICON_INFORMATION | MB_OK);
		}
	} else {
		if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_17"),
			g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL)==ID_OK) {
			
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLROLLER2, BJLROLLER2LEN); p+=BJLROLLER2LEN;
			memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;
			*p = 0x00;
			PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLROLLER2LEN+BJLENDLEN+1);
			
			UtilMessageBox(LookupText(g_keytext_list, "utility_message_6"),
				g_window_title, MB_ICON_EXCLAMATION | MB_OK);
		}
	}
}


void UtilPowerOff(LPUIDB uidb)
{
	char		buf[128];
	char		*p = buf;

	if (g_socketname == NULL)
		return;

	if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_8"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL) == ID_OK) {

		memcpy(p, bjl_cmds, BJLLEN);p+=BJLLEN;
		memcpy(p, BJLSTART, BJLSTARTLEN);p+=BJLSTARTLEN;
		memcpy(p, BJLPOWEROFF, BJLPOWEROFFLEN);p+=BJLPOWEROFFLEN;
		memcpy(p, BJLEND, BJLENDLEN);p+=BJLENDLEN;
		*p = 0x00;
		PutPrintData(buf, BJLLEN+BJLSTARTLEN+BJLPOWEROFFLEN+BJLENDLEN+1);
	}
}


void UtilSetConfig(LPUIDB uidb)
{
	char		buf[128];
	char		*p = buf;
	int			cmd_bytes;			
	GtkWidget*	special_dialog;
	GtkWidget*	send_button;
	char		*model_name;
	
	if (g_socketname == NULL)		
		return;						

	model_name = GetModelName();
	
	if (!strcmp(model_name, "BJF850") || !strcmp(model_name, "BJF860") ||
					!strcmp(model_name, "BJF870"))		
		return;						

	if (!strcmp(model_name, "BJF900") || !strcmp(model_name, "BJF9000") ||
		!strcmp(model_name, "BJS500") || !strcmp( model_name, "PIXUS550I") ||
		!strcmp( model_name, "PIXUS850I") || !strcmp( model_name, "PIXUS950I")
		) {
		SetDryLevel();
		return;
	}

#ifdef USE_LIB_GLADE
	special_dialog = LookupWidget(NULL, "special_dialog");	
#else
	special_dialog = create_special_dialog();	
#endif
	gtk_widget_realize(special_dialog);			
	gtk_widget_show(special_dialog);			
	gtk_window_set_transient_for(GTK_WINDOW(special_dialog),
		GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	send_button = LookupWidget(special_dialog, "special_send_button");
	gtk_widget_grab_focus(send_button);


	gtk_main();									
  
  	if (result != ID_OK)		
		return ;				

 	if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_9"),
		g_window_title,	MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL)==ID_CANCEL){
 		special_set_default(special_dialog);
		return ;		
	}


	
	
	
	if (!strcmp(model_name, "BJF360")) {		
		
		if (page_pause_mode) {		
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;
			memcpy(p, BJLPAGEDELAY, BJLPAGEDELAYLEN); p+=BJLPAGEDELAYLEN;
			cmd_bytes = BJLLEN + BJLSTARTLEN
						+ BJLCTRLMODELEN + BJLPAGEDELAYLEN;
		} else {		
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;
			memcpy(p, BJLNOPAGEDELAY, BJLNOPAGEDELAYLEN); p+=BJLNOPAGEDELAYLEN;
			cmd_bytes = BJLLEN + BJLSTARTLEN
						+ BJLCTRLMODELEN + BJLNOPAGEDELAYLEN;
		}

		if (scan_pause_mode) {	
			memcpy(p, BJLSCANDELAY, BJLSCANDELAYLEN); p+=BJLSCANDELAYLEN;
			memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
			*p = 0x00;
			cmd_bytes += BJLSCANDELAYLEN + BJLENDLEN + 1;
		} else {		
			memcpy(p, BJLNOSCANDELAY, BJLNOSCANDELAYLEN); p+=BJLNOSCANDELAYLEN;
			memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
			*p = 0x00;
			cmd_bytes += BJLNOSCANDELAYLEN + BJLENDLEN + 1;
		}
	
	
	
	} else if (!strcmp(model_name, "BJS600") | !strcmp(model_name, "BJS630") |
			   !strcmp(model_name, "BJS6300") | !strcmp(model_name, "BJS300"))
		{	
		
		if (page_pause_mode) {		
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;
			memcpy(p, BJLPAGEDELAY1, BJLPAGEDELAYLEN1); p+=BJLPAGEDELAYLEN1;
			cmd_bytes = BJLLEN + BJLSTARTLEN
						+ BJLCTRLMODELEN + BJLPAGEDELAYLEN1;
		} else {		
			memcpy(p, bjl_cmds, BJLLEN); p+=BJLLEN;
			memcpy(p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;
			memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;
			memcpy(p, BJLNOPAGEDELAY1, BJLNOPAGEDELAYLEN1);
			p+=BJLNOPAGEDELAYLEN1;
			cmd_bytes = BJLLEN + BJLSTARTLEN
						+ BJLCTRLMODELEN + BJLNOPAGEDELAYLEN1;
		}

		if (scan_pause_mode) {	
			memcpy(p, BJLSCANDELAY1, BJLSCANDELAYLEN1); p+=BJLSCANDELAYLEN1;
			memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
			*p = 0x00;
			cmd_bytes += BJLSCANDELAYLEN1 + BJLENDLEN + 1;
		} else {		
			memcpy(p, BJLNOSCANDELAY1, BJLNOSCANDELAYLEN1);
			p+=BJLNOSCANDELAYLEN1;
			memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
			*p = 0x00;
			cmd_bytes += BJLNOSCANDELAYLEN1 + BJLENDLEN + 1;
		}
	} else {	
		return;						
	}
	
	PutPrintData(buf, cmd_bytes);	
}






void UtilAutoPower(LPUIDB uidb)
{
	GtkWidget*	autopower_dialog;	
	GtkWidget*	send_button;
	char		*param;				
	char		buf[128];
	char		temp[32];
	int			cmd_bytes, total_bytes;
	char		*p = buf;
	GtkWidget	*poweron_combo, *poweroff_combo;
	char *model_name;

	
	if (g_socketname == NULL)		
		return;						

	model_name = GetModelName();

	if (strcmp(model_name,"BJS600")	&& strcmp(model_name,"BJS630")
		&& strcmp(model_name,"BJS6300") && strcmp(model_name,"BJF900")
		&& strcmp(model_name,"BJF9000")	&& strcmp(model_name,"BJS300")
		&& strcmp(model_name,"BJS500") && strcmp( model_name, "PIXUS550I")
		&& strcmp(model_name,"PIXUS850I") && strcmp( model_name, "PIXUS950I"))
	  return;						
	
	
#ifdef USE_LIB_GLADE
	autopower_dialog = LookupWidget(NULL, "autopower_dialog");	
#else
	autopower_dialog = create_autopower_dialog();	
#endif
	gtk_widget_realize(autopower_dialog);			
	
	poweron_combo = LookupWidget(autopower_dialog, "autopower_combo1");	
	SetComboBox(poweron_combo, AutoPowerOnKey, 2, poweron_index);		
	poweroff_combo = LookupWidget(autopower_dialog, "autopower_combo2");	
	SetComboBox(poweroff_combo, AutoPowerOffKey, 6, poweroff_index);
	
	gtk_widget_show(autopower_dialog);				
	gtk_window_set_transient_for(GTK_WINDOW(autopower_dialog),
		GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	send_button = LookupWidget(autopower_dialog, "autopower_button1");
	gtk_widget_grab_focus(send_button);

	gtk_main();									
  
  	if (result != ID_OK)		
		return ;				
	
	
 	if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_9"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL)==ID_CANCEL){
		autopower_set_default();
 		return ;
	}
	
	param = GetParamValue(AutoPowerOnKey, AutoPowerOnValue, 2, power_on_mode);	
	memcpy (p, bjl_cmds, BJLLEN); p+=BJLLEN;				
	memcpy (p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
	memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
	cmd_bytes = sprintf(temp, BJLAUTOPOWERON, param);		
	memcpy (p, temp, cmd_bytes); p+=cmd_bytes;
	total_bytes = BJLLEN + BJLSTARTLEN + BJLCTRLMODELEN + cmd_bytes;
	
	param = GetParamValue(
				AutoPowerOffKey, AutoPowerOffValue, 6, power_off_mode);
	cmd_bytes = sprintf(temp, BJLAUTOPOWEROFF, param);		
	memcpy (p, temp, cmd_bytes); p+=cmd_bytes;
	memcpy (p, BJLEND, BJLENDLEN); p+=BJLENDLEN;			
	*p = 0x00;							
	total_bytes += cmd_bytes + BJLENDLEN + 1;
	
	PutPrintData(buf, total_bytes);		
	
	poweron_index = GetAutoPowerIndex(AutoPowerOnKey, 2, power_on_mode);
	poweroff_index = GetAutoPowerIndex(AutoPowerOffKey, 6, power_off_mode);

}



void UtilInkReset(LPUIDB uidb)
{

	GtkWidget*	reset_dialog;	
	char		buf[128];
	char		*p = buf;
	char 		*model_name;
	int			total_bytes=0;
	GtkWidget*	cancel_button;
	
	if (g_socketname == NULL)		
		return;						

	model_name = GetModelName();

	if (strcmp(model_name,"BJS300"))
		return;

#ifdef USE_LIB_GLADE
	reset_dialog = LookupWidget(NULL, "ink_reset_dialog");	
#else
	reset_dialog = create_ink_reset_dialog();	
#endif
	gtk_widget_realize(reset_dialog);			
	gtk_widget_show(reset_dialog);				
	gtk_window_set_transient_for(GTK_WINDOW(reset_dialog),
		GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	
	cancel_button = LookupWidget(reset_dialog, "ink_reset_cancel_button");
	gtk_widget_grab_focus(cancel_button);
	gtk_widget_grab_default(cancel_button);
	gtk_widget_set_sensitive( 
				LookupWidget(reset_dialog, "ink_reset_excute_button"), FALSE);
	

	gtk_main();									
  
  	if (result != ID_OK)		
		return ;				
	
	
	if(black_reset==0 && color_reset==0)
		return;
	
	if(black_reset){
		memcpy (p, bjl_cmds, BJLLEN); p+=BJLLEN;				
		memcpy (p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy (p, BJLRESETBLACK, BJLRESETBLACKLEN); p+=BJLRESETBLACKLEN;
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;		
		*p = 0x00;
		total_bytes = BJLLEN + BJLSTARTLEN + BJLRESETBLACKLEN + BJLENDLEN + 1;
	}

	if(color_reset){
		memcpy (p, bjl_cmds, BJLLEN); p+=BJLLEN;				
		memcpy (p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
		memcpy (p, BJLRESETCMY, BJLRESETCMYLEN); p+=BJLRESETCMYLEN;
		memcpy(p, BJLEND, BJLENDLEN); p+=BJLENDLEN;		
		*p = 0x00;
		total_bytes += BJLLEN + BJLSTARTLEN + BJLRESETCMYLEN + BJLENDLEN + 1;
	}
	
	PutPrintData(buf, total_bytes);

}


void UtilInkWarning(LPUIDB uidb)
{

	GtkWidget*	warning_dialog;	
	char		buf[128];
	int			cmd_bytes;
	char		*p = buf;
	char 		temp[32];
	char 		*model_name;
	int 		total_bytes;
	GtkWidget*	send_button;
	
	if (g_socketname == NULL)		
		return;						

	model_name = GetModelName();

	if (strcmp(model_name,"BJS300"))
		return;
	
	
#ifdef USE_LIB_GLADE
	warning_dialog = LookupWidget(NULL, "ink_warning_dialog");	
#else
	warning_dialog = create_ink_warning_dialog();	
#endif
	gtk_widget_realize(warning_dialog);			
	gtk_widget_show(warning_dialog);				
	gtk_window_set_transient_for(GTK_WINDOW(warning_dialog),
		GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	send_button = LookupWidget(warning_dialog, "ink_warning_send_button");
	gtk_widget_grab_focus(send_button);


	gtk_main();									
  
  	if (result != ID_OK)		
		return ;				
	

 	if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_9"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL)==ID_CANCEL){
		ink_warning_set_default(warning_dialog);
 		return ;
	}

	memcpy (p, bjl_cmds, BJLLEN); p+=BJLLEN;				
	memcpy (p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
	memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
	

	cmd_bytes = sprintf(temp, BJLINKDETECTION, SwitchString[warning_mode]);	
	memcpy (p, temp, cmd_bytes); p+=cmd_bytes;
	memcpy (p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
	*p = 0x00;							
	total_bytes = BJLLEN + BJLSTARTLEN + BJLCTRLMODELEN + 
					cmd_bytes + BJLENDLEN + 1;
	
	PutPrintData(buf, total_bytes);		


}


void UtilQuietMode(LPUIDB uidb)
{

	GtkWidget*	quiet_dialog;	
	char		buf[128];
	int			cmd_bytes;
	char		*p = buf;
	char 		temp[32];
	char 		*model_name;
	int 		total_bytes;
	GtkWidget*	send_button;
	
	if (g_socketname == NULL)		
		return;						

	model_name = GetModelName();

	if (strcmp(model_name,"BJF900") && strcmp(model_name,"BJF9000") && 
		strcmp( model_name, "PIXUS550I") && strcmp(model_name, "PIXUS850I") &&
		strcmp( model_name, "PIXUS950I") )
		return;
	
#ifdef USE_LIB_GLADE
	quiet_dialog = LookupWidget(NULL, "quiet_dialog");	
#else
	quiet_dialog = create_quiet_dialog();	
#endif
	gtk_widget_realize(quiet_dialog);			
	gtk_widget_show(quiet_dialog);				
	gtk_window_set_transient_for(GTK_WINDOW(quiet_dialog),
		GTK_WINDOW(UI_DIALOG(g_main_window)->window));
	send_button = LookupWidget(quiet_dialog, "quiet_send_button");
	gtk_widget_grab_focus(send_button);

	gtk_main();									
  
  	if (result != ID_OK)		
		return ;				

 	if(UtilMessageBox(LookupText(g_keytext_list, "utility_message_9"),
		g_window_title, MB_ICON_EXCLAMATION | MB_OK | MB_CANCEL)==ID_CANCEL){
		quiet_set_default(quiet_dialog);
 		return ;
	}

	memcpy (p, bjl_cmds, BJLLEN); p+=BJLLEN;				
	memcpy (p, BJLSTART, BJLSTARTLEN); p+=BJLSTARTLEN;		
	memcpy(p, BJLCTRLMODE, BJLCTRLMODELEN); p+=BJLCTRLMODELEN;	
	

	cmd_bytes = sprintf(temp, BJLSILENT, SwitchString[quiet_mode]);		
	memcpy (p, temp, cmd_bytes); p+=cmd_bytes;
	memcpy (p, BJLEND, BJLENDLEN); p+=BJLENDLEN;
	*p = 0x00;							
	total_bytes = BJLLEN + BJLSTARTLEN + BJLCTRLMODELEN + 
					cmd_bytes + BJLENDLEN + 1;
	
	PutPrintData(buf, total_bytes);		


}


void SetComboBox(GtkWidget *combo, char **Keytbl, int n, int index)
{
	int		i;
	GList	*popdown;
	
	popdown = NULL;			
	for (i=0; i < n; i++) {		
		popdown = g_list_append(popdown, LookupText(g_keytext_list, Keytbl[i]));
	}
	
	gtk_combo_set_popdown_strings(GTK_COMBO(combo), popdown);	
	gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), 
						g_list_nth_data(popdown, index));
}




char	*GetParamValue(char **Keytbl, char **Valuetbl, int n, char *mode)
{
	int			i;
	
	for (i=0; i < n; i++) {
		if (!strcmp(LookupText(g_keytext_list, Keytbl[i]), mode))	
			return Valuetbl[i];		
	}
	
	return Valuetbl[0];		
}


int GetAutoPowerIndex(char **Keytbl, int n, char *mode)
{
	int			i;
	
	for (i=0; i < n; i++) {
		if (!strcmp(LookupText(g_keytext_list, Keytbl[i]), mode))	
			return i;		
	}
	return 0;		
}


