Esempio n. 1
0
void _GWidget_RemoveGadget(GGadget *g) {
    struct gwidgetcontainerdata *gd;
    GTopLevelD *td;
    GWindow gw = g->base;
    GGadget *next;

    if ( gw==NULL )
return;

    gd = (struct gwidgetcontainerdata *) (gw->widget_data);
    if ( gd==NULL || !gd->iscontainer )
	GDrawIError( "Attempt to remove a gadget to something which is not a container");
    if ( gd->gadgets==g )
	gd->gadgets = g->prev;
    else {
	for ( next = gd->gadgets; next!=NULL && next->prev!=g; next = next->prev );
	if ( next==NULL )
	    GDrawIError( "Attempt to remove a gadget which is not in the gadget list" );
	else
	    next->prev = g->prev;
    }
    if ( gd->grabgadget == g ) gd->grabgadget = NULL;
    g->prev = NULL;
    g->base = NULL;

    while ( gw->parent!=NULL && !gw->is_toplevel ) gw = gw->parent;
    td = (GTopLevelD *) (gw->widget_data);
    if ( td->gdef == g ) td->gdef = NULL;
    if ( td->gcancel == g ) td->gcancel = NULL;
    if ( td->gfocus == g ) td->gfocus = NULL;
}
Esempio n. 2
0
static void MakeContainerWidget(GWindow gw) {
    struct gwidgetcontainerdata *gd;

    if ( gw->widget_data!=NULL )
	GDrawIError( "Attempt to make a window into a widget twice");
    if ( !widgets_initted )
	gwidget_init();
    if ( gw->parent==NULL || gw->is_toplevel )
	gd = calloc(1,sizeof(struct gtopleveldata));
    else
	gd = calloc(1,sizeof(struct gwidgetcontainerdata));
    gw->widget_data = (struct gwidgetdata *) gd;
    gd->w = gw;
    gd->e_h = gw->eh;
    gw->eh = _GWidget_Container_eh;
    gd->enabled = true;
    gd->iscontainer = true;
    gd->funcs = &_gwidget_container_funcs;
    if ( gw->parent!=NULL && !gw->is_toplevel ) {
	if ( gw->parent->widget_data==NULL )
	    MakeContainerWidget(gw->parent);
	if ( !gw->parent->widget_data->iscontainer )
	    GDrawIError( "Attempt to add a widget to something which is not a container");
	gd->next = ((struct gwidgetcontainerdata *) (gw->parent->widget_data))->widgets;
	((struct gwidgetcontainerdata *) (gw->parent->widget_data))->widgets =
		(struct gwidgetdata *) gd;
    } else {
	struct gtopleveldata *topd;
	topd = (struct gtopleveldata *) gd;
	gd->funcs = &_gwidget_toplevel_funcs;
	gw->eh = _GWidget_TopLevel_eh;
	topd->handle_key = _GWidget_TopLevel_Key;
	topd->istoplevel = true;
    }
}
Esempio n. 3
0
void _GWidget_AddGGadget(GWindow gw,GGadget *g) {
    struct gwidgetcontainerdata *gd;

    if ( gw->widget_data==NULL )
	MakeContainerWidget(gw);
    gd = (struct gwidgetcontainerdata *) (gw->widget_data);
    if ( !gd->iscontainer )
	GDrawIError( "Attempt to add a gadget to something which is not a container");
    g->prev = gd->gadgets;
    gd->gadgets = g;
    if ( g->base!=NULL )
	GDrawIError( "Attempt to add a gadget to two widgets" );
    g->base = gw;
}
Esempio n. 4
0
void _GWidget_ClearGrabGadget(GGadget *g) {
    struct gwidgetcontainerdata *gd=NULL;
    GWindow gw = g->base;

    if ( gw!=NULL )
        gd = (struct gwidgetcontainerdata *) (gw->widget_data);
    if ( gd==NULL || !gd->iscontainer )
        GDrawIError( "This gadget isn't in a container, can't be a grab gadget" );
    else
        gd->grabgadget = NULL;
}
Esempio n. 5
0
void _GWidget_ClearPopupOwner(GGadget *g) {
    struct gtopleveldata *gd=NULL;
    GWindow gw = g->base;

    if ( gw!=NULL ) while ( gw->parent != NULL && !gw->is_toplevel ) gw = gw->parent;
    if ( gw!=NULL )
	gd = (struct gtopleveldata *) (gw->widget_data);
    if ( gd==NULL || !gd->istoplevel )
	GDrawIError( "This gadget isn't in a top level widget, can't have a popup" );
    else
	gd->popupowner = NULL;
}
Esempio n. 6
0
void _GWidget_SetMenuBar(GGadget *g) {
    struct gtopleveldata *gd=NULL;
    GWindow gw = g->base;

    if ( gw!=NULL ) while ( gw->parent != NULL && !gw->is_toplevel ) gw = gw->parent;
    if ( gw!=NULL )
	gd = (struct gtopleveldata *) (gw->widget_data);
    if ( gd==NULL || !gd->istoplevel )
	GDrawIError( "This gadget isn't in a top level widget, can't be a menubar" );
    else
	gd->gmenubar = g;
}
Esempio n. 7
0
void _GWidget_SetDefaultButton(GGadget *g) {
    struct gtopleveldata *gd=NULL;
    GWindow gw = g->base;

    if ( gw!=NULL ) while ( gw->parent != NULL && !gw->is_toplevel ) gw = gw->parent;
    if ( gw!=NULL )
	gd = (struct gtopleveldata *) (gw->widget_data);
    if ( gd==NULL || !gd->istoplevel )
	GDrawIError( "This gadget isn't in a top level widget, can't be a default button" );
    else
	gd->gdef = g;
}
Esempio n. 8
0
void GScrollBarSetMustShow(GGadget *g, int32 sb_min, int32 sb_max, int32 sb_pagesize,
	int32 sb_mustshow ) {
    GScrollBar *gsb = (GScrollBar *) g;

    if ( sb_min>sb_max || sb_pagesize<=0 ) {
	GDrawIError("Invalid scrollbar bounds min=%d max=%d, pagesize=%d",
		sb_min, sb_max, sb_pagesize );
return;
    }
    gsb->sb_min = sb_min;
    gsb->sb_max = sb_max;
    gsb->sb_pagesize = sb_pagesize;
    gsb->sb_mustshow = sb_mustshow;
    gsb->thumbsize = (gsb->g.vert?gsb->g.inner.height:gsb->g.inner.width);
    if ( sb_max-sb_min > sb_pagesize )
	gsb->thumbsize = (gsb->thumbsize*gsb->sb_pagesize)/(sb_max-sb_min);
    if ( gsb->thumbsize<2*gsb->thumbborder+4 ) {
	gsb->thumbsize = 2*gsb->thumbborder+6;
	if ( gsb->thumbsize>(gsb->g.vert?gsb->g.inner.height:gsb->g.inner.width) )
	    gsb->thumbsize = (gsb->g.vert?gsb->g.inner.height:gsb->g.inner.width);
    }
    GScrollBarSetPos(g,gsb->sb_pos);
}
Esempio n. 9
0
void help(char *file) {
    char fullspec[1024], *temp, *pt;

    if ( browser[0]=='\0' )
	findbrowser();
#ifndef __CygWin
    if ( browser[0]=='\0' ) {
	gwwv_post_error(_("No Browser"),_("Could not find a browser. Set the BROWSER environment variable to point to one"));
return;
    }
#endif

    if ( strstr(file,"http://")==NULL ) {
	fullspec[0] = 0;
	if ( ! GFileIsAbsolute(file) ) {
	    if ( helpdir==NULL || *helpdir=='\0' ) {
#ifdef DOCDIR
		strcpy(fullspec,DOCDIR "/");
#elif defined(SHAREDIR)
		strcpy(fullspec,SHAREDIR "/doc/fontforge/");
#else
		strcpy(fullspec,"/usr/local/share/doc/fontforge/");
#endif
	    } else {
		strcpy(fullspec,helpdir);
	    }
	}
	strcat(fullspec,file);
	if (( pt = strrchr(fullspec,'#') )!=NULL ) *pt ='\0';
	if ( !GFileReadable( fullspec )) {
	    if ( *file!='/' ) {
		strcpy(fullspec,"/usr/share/doc/fontforge/");
		strcat(fullspec,file);
		if (( pt = strrchr(fullspec,'#') )!=NULL ) *pt ='\0';
	    }
	}
	if ( !GFileReadable( fullspec )) {
	    strcpy(fullspec,"http://fontforge.sf.net/");
	    AppendSupportedLocale(fullspec);
	    strcat(fullspec,file);
	} else if ( pt!=NULL )
	    *pt = '#';
    } else
	strcpy(fullspec,file);
#if __CygWin
    if ( (strstrmatch(browser,"/cygdrive")!=NULL || browser[0]=='\0') &&
		strstr(fullspec,":/")==NULL ) {
	/* It looks as though the browser is a windows application, so we */
	/*  should give it a windows file name */
	char *pt, *tpt;
	temp = galloc(1024);
	cygwin_conv_to_full_win32_path(fullspec,temp);
	for ( pt = fullspec, tpt = temp; *tpt && pt<fullspec+sizeof(fullspec)-3; *pt++ = *tpt++ )
	    if ( *tpt=='\\' )
		*pt++ = '\\';
	*pt = '\0';
	free(temp);
    }
#endif
#if __Mac
    if ( strcmp(browser,"open")==0 )
	/* open doesn't want "file:" prepended */;
    else
#endif
    if ( strstr(fullspec,":/")==NULL ) {
	char *t1 = galloc(strlen(fullspec)+strlen("file:")+20);
#if __CygWin
	sprintf( t1, "file:\\\\\\%s", fullspec );
#else
	sprintf( t1, "file:%s", fullspec);
#endif
	strcpy(fullspec,t1);
	free(t1);
    }
#if 0 && __Mac
    /* Starting a Mac application is weird... system() can't do it */
    /* Thanks to Edward H. Trager giving me an example... */
    if ( strstr(browser,".app")!=NULL ) {
	*strstr(browser,".app") = '\0';
	pt = strrchr(browser,'/');
	if ( pt==NULL ) pt = browser-1;
	++pt;
	temp = galloc(strlen(pt)+strlen(fullspec) +
		strlen( "osascript -l AppleScript -e \"Tell application \"\" to getURL \"\"\"" )+
		20);
	/* this doesn't work on Max OS X.0 (osascript does not support -e) */
	sprintf( temp, "osascript -l AppleScript -e \"Tell application \"%s\" to getURL \"%s\"\"",
	    pt, fullspec);
	system(temp);
	ff_post_notice(_("Leave X"),_("A browser is probably running in the native Mac windowing system. You must leave the X environment to view it. Try Cmd-Opt-A"));
    } else {
#elif __Mac
    /* This seems a bit easier... Thanks to riggle */
    if ( strcmp(browser,"open")==0 ) {
	char *str = "DYLD_LIBRARY_PATH=\"\"; open ";
	temp = galloc(strlen(str) + strlen(fullspec) + 20);
	sprintf( temp, "%s \"%s\" &", str, fullspec );
	system(temp);
    } else {
#elif __CygWin
    if ( browser[0]=='\0' ) {
	do_windows_browser(fullspec);
	temp = NULL;
    } else {
#else
    {
#endif
	temp = galloc(strlen(browser) + strlen(fullspec) + 20);
	sprintf( temp, strcmp(browser,"kfmclient openURL")==0 ? "%s \"%s\" &" : "\"%s\" \"%s\" &", browser, fullspec );
	system(temp);
    }
    free(temp);
}
#endif

static void UI_IError(const char *format,...) {
    va_list ap;
    char buffer[300];
    va_start(ap,format);
    vsnprintf(buffer,sizeof(buffer),format,ap);
    GDrawIError("%s",buffer);
    va_end(ap);
}

#define MAX_ERR_LINES	400
static struct errordata {
    char *errlines[MAX_ERR_LINES];
    GFont *font;
    int fh, as;
    GGadget *vsb;
    GWindow gw, v;
    int cnt, linecnt;
    int offtop;
    int showing;
    int start_l, start_c, end_l, end_c;
    int down;
} errdata;

static void ErrHide(void) {
    GDrawSetVisible(errdata.gw,false);
    errdata.showing = false;
}

static void ErrScroll(struct sbevent *sb) {
    int newpos = errdata.offtop;

    switch( sb->type ) {
      case et_sb_top:
        newpos = 0;
      break;
      case et_sb_uppage:
        newpos -= errdata.linecnt;
      break;
      case et_sb_up:
        --newpos;
      break;
      case et_sb_down:
        ++newpos;
      break;
      case et_sb_downpage:
        newpos += errdata.linecnt;
      break;
      case et_sb_bottom:
        newpos = errdata.cnt-errdata.linecnt;
      break;
      case et_sb_thumb:
      case et_sb_thumbrelease:
        newpos = sb->pos;
      break;
    }
    if ( newpos>errdata.cnt-errdata.linecnt )
        newpos = errdata.cnt-errdata.linecnt;
    if ( newpos<0 ) newpos =0;
    if ( newpos!=errdata.offtop ) {
	errdata.offtop = newpos;
	GScrollBarSetPos(errdata.vsb,errdata.offtop);
	GDrawRequestExpose(errdata.v,NULL,false);
    }
}
Esempio n. 10
0
void help(char *file) {
    char fullspec[PATH_MAX], *temp, *pt;

    if ( browser[0]=='\0' )
        findbrowser();
    if ( browser[0]=='\0' ) {
        gwwv_post_error(_("No Browser"),_("Could not find a browser. Set the BROWSER environment variable to point to one"));
        return;
    }

    if ( strstr(file,"http://")==NULL ) {
        memset(fullspec,0,sizeof(fullspec));
        if ( ! GFileIsAbsolute(file) )
            snprintf(fullspec, PATH_MAX, "%s", getHelpDir());
        strcat(fullspec,file);
        if (( pt = strrchr(fullspec,'#') )!=NULL ) *pt ='\0';
        if ( !GFileReadable( fullspec )) {
            if ( *file!='/' ) {
                strcpy(fullspec,"/usr/share/doc/fontforge/");
                strcat(fullspec,file);
                if (( pt = strrchr(fullspec,'#') )!=NULL ) *pt ='\0';
            }
        }
        if ( !GFileReadable( fullspec )) {
            strcpy(fullspec,"http://fontforge.sf.net/");
            AppendSupportedLocale(fullspec);
            strcat(fullspec,file);
        } else if ( pt!=NULL )
            *pt = '#';
    } else
        strncpy(fullspec,file,sizeof(fullspec));
#if __Mac
    if ( strcmp(browser,"open")==0 )
        /* open doesn't want "file:" prepended */;
    else
#endif
        if ( strstr(fullspec,":/")==NULL ) {
            if ( (temp=malloc(strlen(fullspec)+strlen("file:")+20))==NULL )
                return;
            sprintf(temp,"file:%s",fullspec);
            strncpy(fullspec,temp,sizeof(fullspec));
            fullspec[sizeof(fullspec)-1] = '\0';
            free(temp);
        }
#if __Mac
    /* This seems a bit easier... Thanks to riggle */
    if ( strcmp(browser,"open")==0 ) {
        char *str = "DYLD_LIBRARY_PATH=\"\"; open ";
        if ( (temp=malloc(strlen(str) + strlen(fullspec) + 20))==NULL )
            return;
        sprintf( temp, "%s \"%s\" &", str, fullspec );
        system(temp);
        free(temp);
    } else {
#else
    {
#endif
        if ( (temp=malloc(strlen(browser) + strlen(fullspec) + 20))==NULL )
            return;
        sprintf( temp, strcmp(browser,"kfmclient openURL")==0 ? "%s \"%s\" &" : "\"%s\" \"%s\" &", browser, fullspec );
        system(temp);
        free(temp);
    }
}
#endif

static void UI_IError(const char *format,...) {
    va_list ap;
    char buffer[300];
    va_start(ap,format);
    vsnprintf(buffer,sizeof(buffer),format,ap);
    GDrawIError("%s",buffer);
    va_end(ap);
}