/* ===========================================================================
 * AScd: the AfterStep and WindowMaker CD player
 * gui_wings.c: window handling using WINGs toolkit
 * ===========================================================================
 * Copyright (c) 1999 Denis Bourez and Rob Malda. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    This product includes software developed by Denis Bourez & Rob Malda
 * 4. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY DENIS BOUREZ AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL DENIS BOUREZ, ROB MALDA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 * ===========================================================================
 */

#ifdef WMK

#include <WINGs.h>

WMScreen *scr;
WMWindow *win;

WMButton *b_title;

WMPopUpButton *pop, *pop2, *pop3;

WMTextField *b_back;
WMTextField *b_fore;

WMButton *b_autoplay;
WMButton *b_autorepeat;
WMSlider *b_volume;

WMTextField *b_cuetime;
WMTextField *b_fadestep;

WMTextField *b_minvol;
WMTextField *b_maxvol;
WMTextField *b_mutedvol;

WMButton *b_save;
WMButton *b_quit;
WMButton *b_close;

WMWindow *dbwin;


WMTextField *db_artist;
WMTextField *db_title;
WMTextField *db_track;
WMButton *db_avoid;
WMButton *db_close;
WMButton *db_prev;
WMButton *db_next;
WMWidget *db_tlabel;

int en_vue = FALSE;
int db_en_vue = FALSE;
int pistes = 0;

int db_curtrack = 1;

/*int old_track = 0;*/

void close_win(WMWidget *self, void *data) {
    WMCloseWindow(win);
    en_vue = FALSE;
    muted_volume = atoi(WMGetTextFieldText(b_mutedvol));
    min_volume = atoi(WMGetTextFieldText(b_minvol));
    max_volume = atoi(WMGetTextFieldText(b_maxvol));
    cue_time = atoi(WMGetTextFieldText(b_cuetime));
    fade_step = atoi(WMGetTextFieldText(b_fadestep));
}

void close_dbwin(WMWidget *self, void *data) {
    char txt[127];
    char txt2 [127];

    WMCloseWindow(dbwin);
    strcpy(cd->artist, WMGetTextFieldText(db_artist));
    strcpy(cd->cdname, WMGetTextFieldText(db_title));
    if (strlen(WMGetTextFieldText(db_track)) > 0) {
	cd->trk[db_curtrack - 1].songname = malloc(strlen(WMGetTextFieldText(db_track)) + 1);
	strcpy(cd->trk[db_curtrack - 1].songname, WMGetTextFieldText(db_track)); 
    }

    save();
    load();

    if (cd->artist != NULL) {
	strcpy(txt, cd->artist);
	if (strcmp(txt, "") == 0) strcpy(txt, "unknown artist");
    } else {
	strcpy(txt, "unknown artist");
    }
	    
    strcat(txt, "\n");
    
    if (cd->cdname != NULL) {
	strcpy(txt2, cd->cdname);
	if (strcmp(txt2, "") == 0) strcpy(txt2, "unknown album");
    } else {
	strcpy(txt2, "unknown album");
    }
    
    strcat(txt, txt2);
    WMSetButtonText(b_title, txt);
    
    db_en_vue = FALSE;
}

void quit_ascd(WMWidget *self, void *data) {
    exit(0);
}

void save_cb(WMWidget *self, void *data) {
    muted_volume = atoi(WMGetTextFieldText(b_mutedvol));
    min_volume = atoi(WMGetTextFieldText(b_minvol));
    max_volume = atoi(WMGetTextFieldText(b_maxvol));
    cue_time = atoi(WMGetTextFieldText(b_cuetime));
    fade_step = atoi(WMGetTextFieldText(b_fadestep));
    strcpy(led_color, "X c ");
    strcpy(led_bgcolor, "  c ");
    strcat(led_color, WMGetTextFieldText(b_fore));
    strcat(led_bgcolor, WMGetTextFieldText(b_back));
    save_rc_file();
}

void track_select(WMWidget *self, void *data) {
    show_db_pos = 0;
    direct_track =  WMGetPopUpButtonSelectedItem(self) + 1;
    cd_control(DIRECTTRACK);
    old_track = 0;
    if (cur_cdmode == WM_CDM_STOPPED) cd_control(PLAY);
}

void display_mode_cb(WMWidget *self, void *data) {
    time_mode =  WMGetPopUpButtonSelectedItem(self);
}


void autoplay_cb(WMWidget *self, void *data) {
    if (autoplay) autoplay = 0;
    else autoplay = 1;
}

void autorepeat_cb(WMWidget *self, void *data) {
    if (autorepeat) autorepeat = 0;
    else autorepeat = 1;
}

void volume_cb(WMWidget *self, void *data) {
    if (cur_cdmode != WM_CDM_EJECTED) {
	volume = WMGetSliderValue(self);
	cd_volume(volume, 10, max_volume);
    }
}

void db_prev_cb(WMWidget *self, void *data) {
    char txt[127];
    char txt2 [127];

    strcpy(cd->artist, WMGetTextFieldText(db_artist));
    strcpy(cd->cdname, WMGetTextFieldText(db_title));
    if (strlen(WMGetTextFieldText(db_track)) > 0) {
	cd->trk[db_curtrack - 1].songname = malloc(strlen(WMGetTextFieldText(db_track)) + 1);
	strcpy(cd->trk[db_curtrack - 1].songname, WMGetTextFieldText(db_track));
    }
    save();
    load();

    if (db_curtrack == 1) db_curtrack = cur_ntracks;
    else db_curtrack--;
    sprintf(txt, "Tk %d:", db_curtrack);
    WMSetLabelText(db_tlabel, txt);

    if (cd->trk[db_curtrack - 1].songname != NULL) {
	sprintf(txt,  cd->trk[db_curtrack - 1].songname);
    } else {
	sprintf(txt, "");
    }
    WMSetTextFieldText(db_track, txt);

    if (cd->trk[db_curtrack - 1].avoid) {
	WMSetButtonSelected(db_avoid, TRUE);
    } else {
	WMSetButtonSelected(db_avoid, FALSE);
    }    
    
    WMRealizeWidget(dbwin);
}

void db_next_cb(WMWidget *self, void *data) {
    char txt[127];
    char txt2 [127];

    strcpy(cd->artist, WMGetTextFieldText(db_artist));
    strcpy(cd->cdname, WMGetTextFieldText(db_title));
    if (strlen(WMGetTextFieldText(db_track)) > 0) {
	cd->trk[db_curtrack - 1].songname = malloc(strlen(WMGetTextFieldText(db_track)) + 1);
	strcpy(cd->trk[db_curtrack - 1].songname, WMGetTextFieldText(db_track));
    }
    save();
    load();

    if (db_curtrack == cur_ntracks) db_curtrack = 1;
    else db_curtrack++;
    sprintf(txt, "Tk %d:", db_curtrack);
    WMSetLabelText(db_tlabel, txt);

    if (cd->trk[db_curtrack - 1].songname != NULL) {
	sprintf(txt,  cd->trk[db_curtrack - 1].songname);
    } else {
	sprintf(txt, "");
    }
    WMSetTextFieldText(db_track, txt);

    if (cd->trk[db_curtrack - 1].avoid) {
	WMSetButtonSelected(db_avoid, TRUE);
    } else {
	WMSetButtonSelected(db_avoid, FALSE);
    }
    
    WMRealizeWidget(dbwin);
}

void db_avoid_cb(WMWidget *self, void *data) {
    if (cd->trk[db_curtrack - 1].avoid) {
	cd->trk[db_curtrack - 1].avoid = 0;
    } else {
	cd->trk[db_curtrack - 1].avoid = 1;
    }
    save();
    load();
}

void create_db_window(WMScreen *scr) {
    char txt[80];
    WMWidget *fr, *fr2, *fr3, *fr4;
    WMWidget *lb1, *lb2;
    WMWidget *infos;

    dbwin = WMCreateWindow(scr, "AScd-db");
    WMSetWindowCloseAction(dbwin, close_dbwin, NULL);
    WMSetWindowTitle(dbwin, "Database edition");
    WMResizeWidget(dbwin, 320, 155);

    lb1 = WMCreateLabel(dbwin);
    WMResizeWidget(lb1, 50, 20);
    WMMoveWidget(lb1, 10, 10);
    WMSetLabelText(lb1, "Artist:");

    db_artist = WMCreateTextField(dbwin);
    WMMoveWidget(db_artist, 70, 10);
    WMResizeWidget(db_artist, 235, 20);

    lb2 = WMCreateLabel(dbwin);
    WMResizeWidget(lb2, 50, 20);
    WMMoveWidget(lb2, 10, 30);
    WMSetLabelText(lb2, "Title:");

    db_title = WMCreateTextField(dbwin);
    WMMoveWidget(db_title, 70, 30);
    WMResizeWidget(db_title, 235, 20);

    db_tlabel = WMCreateLabel(dbwin);
    WMResizeWidget(db_tlabel, 50, 20);
    WMMoveWidget(db_tlabel, 10, 70);
    sprintf(txt, "Tk %d:", db_curtrack);
    WMSetLabelText(db_tlabel, txt);

    db_track = WMCreateTextField(dbwin);
    WMMoveWidget(db_track, 70, 70);
    WMResizeWidget(db_track, 235, 20);

    db_avoid = WMCreateButton(dbwin, WBTSwitch);
    WMMoveWidget(db_avoid, 70, 95);
    WMResizeWidget(db_avoid, 235, 20);
    WMSetButtonText(db_avoid, "don't play this track");
    WMSetButtonAction(db_avoid, db_avoid_cb, NULL);

    /* --- */

    db_prev = WMCreateButton(dbwin, NULL);
    WMResizeWidget(db_prev, 110, 30);
    WMMoveWidget(db_prev, 10, 120);
    WMSetButtonText(db_prev, "Previous Track");
    WMSetButtonAction(db_prev, db_prev_cb, NULL);

    db_next = WMCreateButton(dbwin, NULL);
    WMResizeWidget(db_next, 110, 30);
    WMMoveWidget(db_next, 125, 120);
    WMSetButtonText(db_next, "Next Track");
    WMSetButtonAction(db_next, db_next_cb, NULL);

    db_close = WMCreateButton(dbwin, NULL);
    WMResizeWidget(db_close, 50, 30);
    WMMoveWidget(db_close, 260, 120);
    WMSetButtonText(db_close, "Close");
    WMSetButtonAction(db_close, close_dbwin, NULL);

    WMRealizeWidget(dbwin);
}

void db_window(WMScreen *scr) {
    int i;
    char txt[127];

    if (! db_en_vue) {
	if (cur_cdmode == WM_CDM_EJECTED) return;

	load();
	if (cd->artist != NULL) strcpy(txt, cd->artist);
	else strcpy(txt, "");
	WMSetTextFieldText(db_artist, txt);

	if (cd->cdname != NULL) strcpy(txt, cd->cdname);
	else strcpy(txt, "");
	WMSetTextFieldText(db_title, txt);

	if (cd->trk[db_curtrack - 1].songname != NULL) {
	    sprintf(txt,  cd->trk[db_curtrack - 1].songname);
	} else {
	    sprintf(txt, "");
	}
	WMSetTextFieldText(db_track, txt);

	if (cd->trk[db_curtrack - 1].avoid) {
	    WMSetButtonSelected(db_avoid, TRUE);
	} else {
	    WMSetButtonSelected(db_avoid, FALSE);
	}

	WMRealizeWidget(dbwin);
	WMMapSubwidgets(dbwin);
	WMMapWidget(dbwin);
	db_en_vue = TRUE;
    } else {
	WMCloseWindow(dbwin);
	db_en_vue = FALSE;
    }
}

void db_cb(WMWidget *self, void *data) {
    char txt[127];
    sprintf(txt, "Tk %d:", db_curtrack);
    WMSetLabelText(db_tlabel, txt);
    /*WMRealizeWidget(dbwin);*/
    db_window(scr);
}

void create_big_window(WMScreen *scr) {
    char txt[80];
    WMWidget *fr, *fr2, *fr3, *fr4;
    WMWidget *lb1, *lb2, *lb3, *lb4, *lb5;
    WMWidget *infos;

    win = WMCreateWindow(scr, "AScd");
    WMSetWindowCloseAction(win, close_win, NULL);
    sprintf(txt, "%s %s", PACKAGE, VERSION);
    WMSetWindowTitle(win, txt);
    WMResizeWidget(win, 320, 335);

    b_title = WMCreateButton(win, NULL);
    WMResizeWidget(b_title, 300, 40);
    WMMoveWidget(b_title, 10, 5);
    WMSetButtonText(b_title, "1\n2");
    WMSetButtonAction(b_title, db_cb, NULL);

    pop = WMCreatePopUpButton(win);
    WMResizeWidget(pop, 300, 20);
    WMMoveWidget(pop, 10, 55);
    WMSetPopUpButtonPullsDown(pop, True);
    WMSetPopUpButtonText(pop, "Tracks");
    WMAddPopUpButtonItem(pop, "1");
    WMSetPopUpButtonAction(pop, track_select, NULL); 

    fr = WMCreateFrame(win);
    WMMoveWidget(fr, 10, 80);
    WMResizeWidget(fr, 110, 70);
    WMSetFrameTitle(fr, "Playback:");

    b_autoplay = WMCreateButton(win, WBTSwitch);
    WMMoveWidget(b_autoplay, 20, 95);
    WMResizeWidget(b_autoplay, 90, 20);
    WMSetButtonText(b_autoplay, "autoplay");
    WMSetButtonAction(b_autoplay, autoplay_cb, NULL);

    b_autorepeat = WMCreateButton(win, WBTSwitch);
    WMMoveWidget(b_autorepeat, 20, 120);
    WMResizeWidget(b_autorepeat, 90, 20);
    WMSetButtonText(b_autorepeat, "autorepeat");
    WMSetButtonAction(b_autorepeat, autorepeat_cb, NULL);

    fr3 = WMCreateFrame(win);
    WMMoveWidget(fr3, 130, 80);
    WMResizeWidget(fr3, 180, 70);
    WMSetFrameTitle(fr3, "Display:");

    b_back = WMCreateTextField(win);
    WMMoveWidget(b_back, 140, 95);
    WMResizeWidget(b_back, 80, 20);

    b_fore = WMCreateTextField(win);
    WMMoveWidget(b_fore, 220, 95);
    WMResizeWidget(b_fore, 80, 20);

    pop2 = WMCreatePopUpButton(win);
    WMResizeWidget(pop2, 160, 20);
    WMMoveWidget(pop2, 140, 120);
    WMSetPopUpButtonPullsDown(pop2, True);
    WMSetPopUpButtonText(pop2, "Display Mode");
    WMAddPopUpButtonItem(pop2, "Track, ellasped time");
    WMAddPopUpButtonItem(pop2, "Track, remaining time");
    WMAddPopUpButtonItem(pop2, "CD, ellapsed time");
    WMAddPopUpButtonItem(pop2, "CD, remaining time");
    WMSetPopUpButtonAction(pop2, display_mode_cb, NULL); 

    fr2 = WMCreateFrame(win);
    WMMoveWidget(fr2, 10, 155);
    WMResizeWidget(fr2, 300, 50);
    WMSetFrameTitle(fr2, "Misc Options:");

    lb2 = WMCreateLabel(win);
    WMResizeWidget(lb2, 70, 20);
    WMMoveWidget(lb2, 20, 175);
    WMSetLabelText(lb2, "Cue Time");

    b_cuetime = WMCreateTextField(win);
    WMResizeWidget(b_cuetime, 40, 20);
    WMMoveWidget(b_cuetime, 90, 175);

    lb3 = WMCreateLabel(win);
    WMResizeWidget(lb3, 70, 20);
    WMMoveWidget(lb3, 190, 175);
    WMSetLabelText(lb3, "Fade Step");

    b_fadestep = WMCreateTextField(win);
    WMResizeWidget(b_fadestep, 40, 20);
    WMMoveWidget(b_fadestep, 260, 175);

    fr4 = WMCreateFrame(win);
    WMMoveWidget(fr4, 10, 210);
    WMResizeWidget(fr4, 300, 75);
    WMSetFrameTitle(fr4, "Volume:");

    lb4 = WMCreateLabel(win);
    WMResizeWidget(lb4, 35, 20);
    WMMoveWidget(lb4, 20, 230);
    WMSetLabelText(lb4, "From");

    b_minvol = WMCreateTextField(win);
    WMResizeWidget(b_minvol, 40, 20);
    WMMoveWidget(b_minvol, 60, 230);

    lb5 = WMCreateLabel(win);
    WMResizeWidget(lb5, 30, 20);
    WMMoveWidget(lb5, 103, 230);
    WMSetLabelText(lb5, "to");

    b_maxvol = WMCreateTextField(win);
    WMResizeWidget(b_maxvol, 40, 20);
    WMMoveWidget(b_maxvol, 123, 230);

    lb1 = WMCreateLabel(win);
    WMResizeWidget(lb1, 40, 20);
    WMMoveWidget(lb1, 215, 230);
    WMSetLabelText(lb1, "Muted");

    b_mutedvol = WMCreateTextField(win);
    WMResizeWidget(b_mutedvol, 40, 20);
    WMMoveWidget(b_mutedvol, 260, 230);

    b_volume = WMCreateSlider(win);
    WMResizeWidget(b_volume, 280, 16);
    WMMoveWidget(b_volume, 20, 257);
    WMSetSliderKnobThickness(b_volume, 22);
    WMSetSliderAction(b_volume, volume_cb, NULL);

    b_save = WMCreateButton(win, NULL);
    WMResizeWidget(b_save, 50, 30);
    WMMoveWidget(b_save, 150, 295);
    WMSetButtonText(b_save, "Save");
    WMSetButtonAction(b_save, save_cb, NULL);

    b_save = WMCreateButton(win, NULL);
    WMResizeWidget(b_save, 50, 30);
    WMMoveWidget(b_save, 205, 295);
    WMSetButtonText(b_save, "Quit");
    WMSetButtonAction(b_save, quit_ascd, NULL);

    b_close = WMCreateButton(win, NULL);
    WMResizeWidget(b_close, 50, 30);
    WMMoveWidget(b_close, 260, 295);
    WMSetButtonText(b_close, "Close");
    WMSetButtonAction(b_close, close_win, NULL);

    infos = WMCreateLabel(win);
    WMResizeWidget(infos, 138, 30);
    WMMoveWidget(infos, 10, 295);
    sprintf(txt, "CDC %s\n%s", cd_control_version(), wm_libver_string());
    WMSetLabelText(infos, txt);

    WMRealizeWidget(win);
    /*
    WMMapSubwidgets(win);
    WMMapWidget(win);
    */

}

void update_track() {
    int i;
    char txt[127];
    char txt2[127];

    if (en_vue) {
	if (cur_cdmode != WM_CDM_EJECTED) {

	    if (cd->artist != NULL) {
		strcpy(txt, cd->artist);
		if (strcmp(txt, "") == 0) strcpy(txt, "unknown artist");
	    } else {
		strcpy(txt, "unknown artist");
	    }
	    
	    strcat(txt, "\n");

	    if (cd->cdname != NULL) {
		strcpy(txt2, cd->cdname);
		if (strcmp(txt2, "") == 0) strcpy(txt2, "unknown album");
	    } else {
		strcpy(txt2, "unknown album");
	    }

	    strcat(txt, txt2);
	    WMSetButtonText(b_title, txt);

	    for (i = WMGetPopUpButtonNumberOfItems(pop); i >= 0; i --) {
		WMRemovePopUpButtonItem(pop, i);
	    }

	    for (i = 0; i < cur_ntracks; i++) {
		sprintf(txt, "%2d ", i + 1);
		if (cd->trk[i].songname != NULL) strcat(txt,  cd->trk[i].songname);
		WMAddPopUpButtonItem(pop, txt);
	    }

	pistes = cur_ntracks;

	if (cd->trk[cur_track - 1].songname != NULL) {
	    sprintf(txt, "%s", cd->trk[cur_track - 1].songname);
	    if (strcmp(txt, "") == 0) sprintf(txt, "Track %d", cur_track);
	    WMSetPopUpButtonText(pop, txt);
	} else {
	    sprintf(txt, "Track %d", cur_track);
	    WMSetPopUpButtonText(pop, txt);
	}

	}
    }
}

void big_window(WMScreen *scr) {
    int i;
    char txt[127];
    char txt2[127];

    if (! en_vue) {

	if (cur_cdmode == WM_CDM_EJECTED) return;

	sprintf(txt, "%d", cue_time);
	WMSetTextFieldText(b_cuetime, txt);
	sprintf(txt, "%d", fade_step);
	WMSetTextFieldText(b_fadestep, txt);
	sprintf(txt, "%d", min_volume);
	WMSetTextFieldText(b_minvol, txt);
	sprintf(txt, "%d", max_volume);
	WMSetTextFieldText(b_maxvol, txt);
	sprintf(txt, "%d", muted_volume);
	WMSetTextFieldText(b_mutedvol, txt);

	WMSetTextFieldText(b_back, led_bgcolor + 4);
	WMSetTextFieldText(b_fore, led_color + 4);

	WMSetSliderMinValue(b_volume, min_volume);
	WMSetSliderMaxValue(b_volume, max_volume);
	WMSetSliderValue(b_volume, volume);

	for (i = WMGetPopUpButtonNumberOfItems(pop); i >= 0; i --) {
	    WMRemovePopUpButtonItem(pop, i);
	}


	if (cd->artist != NULL) {
	    strcpy(txt, cd->artist);
	    if (strcmp(txt, "") == 0) strcpy(txt, "unknown artist");
	} else {
	    strcpy(txt, "unknown artist");
	}
	
	strcat(txt, "\n");
	
	if (cd->cdname != NULL) {
	    strcpy(txt2, cd->cdname);
	    if (strcmp(txt2, "") == 0) strcpy(txt2, "unknown album");
	} else {
	    strcpy(txt2, "unknown album");
	}
	
	strcat(txt, txt2);
	WMSetButtonText(b_title, txt);
	
	for (i = 0; i < cur_ntracks; i++) {
	    sprintf(txt, "%2d ", i + 1);
	    if (cd->trk[i].songname != NULL) strcat(txt,  cd->trk[i].songname);
	    WMAddPopUpButtonItem(pop, txt);
	}
	
	if (cd->trk[cur_track - 1].songname != NULL) {
	    sprintf(txt, "%s", cd->trk[cur_track - 1].songname);
	    if (strcmp(txt, "") == 0) sprintf(txt, "Track %d", cur_track);
	    WMSetPopUpButtonText(pop, txt);
	} else {
	    sprintf(txt, "Track %d", cur_track);
	    WMSetPopUpButtonText(pop, txt);
	}

	pistes = cur_ntracks;

	if (autoplay) {
	    WMSetButtonSelected(b_autoplay, TRUE);
	} else {
	    WMSetButtonSelected(b_autoplay, FALSE);
	}

	if (autorepeat) {
	    WMSetButtonSelected(b_autorepeat, TRUE);
	} else {
	    WMSetButtonSelected(b_autorepeat, FALSE);
	}

	WMRealizeWidget(win);
	WMMapSubwidgets(win);
	WMMapWidget(win);

	en_vue = TRUE;
    } else {
	WMCloseWindow(win);
	muted_volume = atoi(WMGetTextFieldText(b_mutedvol));
	min_volume = atoi(WMGetTextFieldText(b_minvol));
	max_volume = atoi(WMGetTextFieldText(b_maxvol));
	cue_time = atoi(WMGetTextFieldText(b_cuetime));
	fade_step = atoi(WMGetTextFieldText(b_fadestep));
	en_vue = FALSE;
    }
}

#endif
