Example #1
0
int raine_file_select_ex( char *message, char *path,  char *ext, int size,int width, int height)
{
   char buf[512];
   int ret;
   char *p;

   if (width == -1)
      width = 305;

   #ifdef HAVE_DIR_LIST

      if (height == -1)
         height = 161;

   #else

      if (height == -1)
         height = 189;

   #endif

   /* for fs_dlist_proc() */
   ASSERT(size >= 4 * uwidth_max(U_CURRENT));

   ustrcpy(updir, empty_string);
   file_selector[FS_MESSAGE].dp = (char *)message;
   file_selector[FS_EDIT].d1 = size/uwidth_max(U_CURRENT) - 1;
   file_selector[FS_EDIT].dp = path;
   file_selector[FS_OK].dp = (void*)raine_get_config_text("OK");
   file_selector[FS_CANCEL].dp = (void*)raine_get_config_text("Cancel");
   fext = ext;

   if (!ugetc(path)) {
      if (!getcwd(buf, sizeof(buf)))
         buf[0]=0;
      do_uconvert(buf, U_ASCII, path, U_CURRENT, size);
      fix_filename_case(path);
      fix_filename_slashes(path);
      put_backslash(path);
   }

   clear_keybuf();

   do {
   } while (gui_mouse_b());

   stretch_dialog(file_selector, width, height);

   centre_dialog(file_selector);
   // Stupid correction of the allegro colors...
   file_selector[FS_FILES].fg = CGUI_COL_TEXT_1;
   file_selector[FS_FILES].bg = CGUI_BOX_COL_MIDDLE;
#ifdef HAVE_DIR_LIST       /* not all platforms need a directory list */
   file_selector[FS_DISKS].fg = CGUI_COL_TEXT_1;
   file_selector[FS_DISKS].bg = CGUI_BOX_COL_MIDDLE;
#endif

   ret = do_dialog(file_selector, FS_EDIT);

   if (ret == FS_CANCEL)
      return FALSE;

   p = get_extension(path);
   if ((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", NULL)))) {
      p += usetc(p, '.');
      ustrcpy(p, ext);
   }

   return TRUE;
}
Example #2
0
/* jwin_file_select_ex:
  *  Displays the JWin file selector, with the message as caption.
  *  Allows the user to select a file, and stores the selection in the
  *  path buffer, whose length in bytes is given by size and should have
  *  room for at least 80 characters. The files are filtered according to
  *  the file extensions in ext. Passing NULL includes all files, "PCX;BMP"
  *  includes only files with .PCX or .BMP extensions. Returns zero if it
  *  was closed with the Cancel button or non-zero if it was OK'd.
  */
int jwin_file_select_ex(AL_CONST char *message, char *path, AL_CONST char *ext, int size, int width, int height, FONT *title_font)
{
    static attrb_state_t default_attrb_state[ATTRB_MAX] = DEFAULT_ATTRB_STATE;
    int ret;
    char *p;
    char tmp[32];
    ASSERT(message);
    ASSERT(path);
    
    if(title_font)
    {
        file_selector[0].dp2=title_font;
    }
    
    if(width == OLD_FILESEL_WIDTH)
        width = 304;
        
#ifdef HAVE_DIR_LIST
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 160;
        
#else
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 188;
        
#endif
        
    /* for fs_dlist_proc() */
    ASSERT(size >= 4 * uwidth_max(U_CURRENT));
    
    usetc(updir, 0);
    file_selector[FS_WIN].dp = (char *)message;
    file_selector[FS_EDIT].d1 = size/uwidth_max(U_CURRENT) - 1;
    file_selector[FS_EDIT].dp = path;
    file_selector[FS_OK].dp = (void*)get_config_text("OK");
    file_selector[FS_CANCEL].dp = (void*)get_config_text("Cancel");
    
    /* Set default attributes. */
    memcpy(attrb_state, default_attrb_state, sizeof(default_attrb_state));
    
    /* Parse extension string. */
//  if (ext)// && ugetc(ext))
    {
        parse_extension_string(ext);
    }
    
    if(!ugetc(path))
    {
    
#ifdef HAVE_DIR_LIST
    
        int drive = _al_getdrive();
        
#else
        
        int drive = 0;
#endif
        
        _al_getdcwd(drive, path, size - ucwidth(OTHER_PATH_SEPARATOR));
        fix_filename_case(path);
        fix_filename_slashes(path);
        put_backslash(path);
    }
    
    clear_keybuf();
    
    do
    {
    }
    while(gui_mouse_b());
    
    file_selector[FS_TYPES].proc = fs_dummy_proc;
    enlarge_file_selector(width, height);
    ret = popup_zqdialog(file_selector, FS_EDIT);
    
    if(fext)
    {
        zc_free(fext);
        fext = NULL;
    }
    
    if(fext_p)
    {
        _al_free(fext_p);
        fext_p = NULL;
    }
    
    if((ret == FS_CANCEL) || (ret == FS_WIN) || (!ugetc(get_filename(path))))
        return FALSE;
        
    p = get_extension(path);
    
    if((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", tmp))))
    {
        size -= ((long)(size_t)p - (long)(size_t)path + ucwidth('.'));
        
        if(size >= uwidth_max(U_CURRENT) + ucwidth(0))          /* do not end with '.' */
        {
            p += usetc(p, '.');
            ustrzcpy(p, size, ext);
        }
    }
    
    return TRUE;
}
Example #3
0
/* d_editbox_proc:
  *  A text box object. The dp field points to a char * which is the text
  *  to be displayed in the text box. If the text is long, there will be
  *  a vertical scrollbar on the right hand side of the object which can
  *  be used to scroll through the text. The default is to print the text
  *  with word wrapping, but if the D_SELECTED flag is set, the text will
  *  be printed with character wrapping. The d1 field is used internally
  *  to store the number of lines of text, and d2 is used to store how far
  *  it has scrolled through the text.
  */
int d_editbox_proc(int msg, DIALOG *d, int c)
{
	EditboxModel *model= (EditboxModel *)d->dp;
	int ret = D_O_K;
  
	static clock_t ticks;
	bool dontredraw=false;
	switch(msg)
	{
	case MSG_START:
		{
			model->getSelection().clearSelection();
			model->getView()->initialize(model);
			break;
		}
	case MSG_IDLE:
		{
			if ((d->flags & D_GOTFOCUS)&&(clock()>ticks))
			{
				d->flags |= D_DIRTY;
				ticks=clock()+(CLOCKS_PER_SEC/2);
				model->getCursor().invertVisibility();
			}
			break;
		}
	case MSG_DRAW:
		{
			model->getView()->draw();
			break;
		}
	case MSG_WANTFOCUS:
		{
			ret = D_WANTFOCUS;
			break;
		}
	case MSG_CHAR:
		{
			//handle selecting (bah)
			
			switch(c>>8)
			{
			case KEY_LEFT:
			case KEY_RIGHT:
			case KEY_UP:
			case KEY_DOWN:
			case KEY_HOME:
			case KEY_END:
			case KEY_PGUP:
			case KEY_PGDN:
				if (key[KEY_LSHIFT]||key[KEY_RSHIFT])
				{
					model->getSelection().ensureSelecting(model->getCursor());
				}
				else
				{
					model->getSelection().clearSelection();
				}
			}
			
			//normal event handling
			switch(c>>8)
			{
			case KEY_LEFT:
				model->getCursor()--;
				ret = D_USED_CHAR;
				break;
			case KEY_RIGHT:
				model->getCursor()++;
				ret = D_USED_CHAR;
				break;
			case KEY_UP:
				model->getView()->lineUp();
				ret = D_USED_CHAR;
				break;
			case KEY_DOWN:
				model->getView()->lineDown();
				ret = D_USED_CHAR;
				break;
			case KEY_HOME:
				model->getView()->lineHome();
				ret = D_USED_CHAR;
				break;
			case KEY_END:
				model->getView()->lineEnd();
				ret = D_USED_CHAR;
				break;
			case KEY_PGDN:
				model->getView()->pageDown();
				ret = D_USED_CHAR;
				break;
			case KEY_PGUP:
				model->getView()->pageUp();
				ret = D_USED_CHAR;
				break;
			case KEY_ENTER:
			case KEY_ENTER_PAD:
				model->clear();
				model->getCursor().insertNewline();
				ret = D_USED_CHAR;
				break;
			case KEY_TAB:
				{
					model->clear();
					int ch = Unicode::getCharAtOffset(uconvert_ascii("\t",NULL),0);
					model->getCursor().insertChar(ch);
					ret = D_USED_CHAR;
					break;
				}
			case KEY_DEL:
			case KEY_DEL_PAD:
				if(model->getSelection().hasSelection())
					model->clear();
				else
					model->getCursor().deleteChar();
				ret = D_USED_CHAR;
				break;
			case KEY_BACKSPACE:
				if(model->getSelection().hasSelection())
					model->clear();
				else if(model->getCursor().getPosition() != 0)
				{
					model->getCursor()--;
					model->getCursor().deleteChar();
				}
				ret = D_USED_CHAR;
				break;
			case KEY_C:
				if (key[KEY_LCONTROL]||key[KEY_RCONTROL])
				{
					model->copy();
					ret = D_USED_CHAR;
					break;
				}
				ret = D_O_K;
				break;
			case KEY_X:
				if (key[KEY_LCONTROL]||key[KEY_RCONTROL])
				{
					model->cut();
					ret = D_USED_CHAR;
					break;
				}
				ret = D_O_K;
				break;
			case KEY_V:
				if(key[KEY_LCONTROL]||key[KEY_RCONTROL])
				{
					model->clear();
					model->paste();
					ret = D_USED_CHAR;
					break;
				}
				ret = D_O_K;
				break;
			case KEY_ESC:
				return D_EXIT;
			case KEY_F1:
				model->doHelp();
				ret = D_USED_CHAR;
				dontredraw=true;
				break;
			}
			//selection post-processing
			if (key[KEY_LSHIFT]||key[KEY_RSHIFT])
			{
				switch(c>>8)
				{
				case KEY_LEFT:
				case KEY_RIGHT:
				case KEY_UP:
				case KEY_DOWN:
				case KEY_HOME:
				case KEY_END:
				case KEY_PGUP:
				case KEY_PGDN:
					model->getSelection().adjustSelection(model->getCursor());
				}
			}
			break;
		}
	case MSG_UCHAR:
		{
			ret = D_USED_CHAR;
			if ((c >= ' ') && (uisok(c)))
			{
				model->clear();
				model->getCursor().insertChar(c);
			}
		}
		break;
	case MSG_CLICK:
		{
			bool redraw = model->getView()->mouseClick(gui_mouse_x(), gui_mouse_y());
			if(model->getCursor().isVisible())
					model->getCursor().invertVisibility();
			if(redraw)
			{
				object_message(d, MSG_DRAW, 0);
			}
			while(gui_mouse_b())
			{
				
				if(model->getView()->mouseDrag(gui_mouse_x(), gui_mouse_y()))
				{
					scare_mouse();
					object_message(d, MSG_DRAW, 0);
					unscare_mouse();
				}
			}
			model->getView()->mouseRelease(gui_mouse_x(), gui_mouse_y());
			if(!model->getCursor().isVisible())
					model->getCursor().invertVisibility();
			d->flags |= D_DIRTY;
			break;
		}
	case MSG_WHEEL:
		{
			if(c>0)
				model->getView()->scrollUp();
			else
				model->getView()->scrollDown();
			d->flags |= D_DIRTY;
			break;
		}
    
	}
	if(ret == D_USED_CHAR && !dontredraw)
	{
		//redraw
		if(!model->getCursor().isVisible())
			model->getCursor().invertVisibility();
		ticks=clock()+(CLOCKS_PER_SEC/2);
		model->getView()->ensureCursorOnScreen();
		d->flags |= D_DIRTY;
	}
	return ret;
}