static void growcol_scroll_selbymouse(GGadget *g, GEvent *event) {
    int loff=0, xoff=0, pos;
    GRowCol *grc = (GRowCol *) (g->data);

    if ( event->u.mouse.y<grc->g.inner.y ) {
	if ( grc->loff>0 ) loff = -1;
    } else if ( event->u.mouse.y >= grc->g.inner.y+grc->g.inner.height ) {
	int top = GRowColTopInWindow(grc,grc->ltot-1);
	if ( grc->loff<top ) loff = 1;
    }
    if ( event->u.mouse.x<grc->g.inner.x ) {
	xoff = -GDrawPointsToPixels(grc->g.base,6);
    } else if ( event->u.mouse.x >= grc->g.inner.x+grc->g.inner.width ) {
	xoff = GDrawPointsToPixels(grc->g.base,6);
    }
    GRowColScrollBy(grc,loff,xoff);
    pos = GRowColIndexFromPos(grc,event->u.mouse.y);
    if ( pos==-1 || pos == grc->end )
	/* Do Nothing, nothing selectable */;
    else if ( !grc->multiple_sel ) {
	GRowColClearSel(grc);
	grc->ti[pos]->selected = true;
	grc->start = grc->end = pos;
	_ggadget_redraw(&grc->g);
    } else {
	GRowColExpandSelection(grc,pos);
	grc->end = pos;
	_ggadget_redraw(&grc->g);
    }
}
Beispiel #2
0
static void glist_scroll_selbymouse(GDList *gl, GEvent *event) {
    int loff=0, xoff=0, pos;

    if ( event->u.mouse.y<gl->g.inner.y ) {
	if ( gl->loff>0 ) loff = -1;
    } else if ( event->u.mouse.y >= gl->g.inner.y+gl->g.inner.height ) {
	int top = GListTopInWindow(gl,gl->ltot-1);
	if ( gl->loff<top ) loff = 1;
    }
    if ( event->u.mouse.x<gl->g.inner.x ) {
	xoff = -GDrawPointsToPixels(gl->g.base,6);
    } else if ( event->u.mouse.x >= gl->g.inner.x+gl->g.inner.width ) {
	xoff = GDrawPointsToPixels(gl->g.base,6);
    }
    GListScrollBy(gl,loff,xoff);
    pos = GListIndexFromPos(gl,event->u.mouse.y);
    if ( pos==-1 || pos == gl->end )
	/* Do Nothing, nothing selectable */;
    else if ( !gl->multiple_sel ) {
	GListClearSel(gl);
	gl->ti[pos]->selected = true;
	gl->start = gl->end = pos;
	_ggadget_redraw(&gl->g);
    } else {
	GListExpandSelection(gl,pos);
	gl->end = pos;
	_ggadget_redraw(&gl->g);
    }
}
Beispiel #3
0
static void GRadioChanged(GRadio *gr) {
    GEvent e;

    if ( gr->isradio && gr->ison )
return;		/* Do Nothing, it's already on */
    else if ( gr->isradio ) {
	GRadio *other;
	for ( other=gr->post; other!=gr; other = other->post ) {
	    if ( other->ison ) {
		other->ison = false;
		_ggadget_redraw((GGadget *) other);
	    }
	}
    } else
	/* Checkboxes just default down */;
    gr->ison = !gr->ison;
    e.type = et_controlevent;
    e.w = gr->g.base;
    e.u.control.subtype = et_radiochanged;
    e.u.control.g = &gr->g;
    if ( gr->g.handle_controlevent != NULL )
	(gr->g.handle_controlevent)(&gr->g,&e);
    else
	GDrawPostEvent(&e);
}
static void GRowColSetOrderer(GGadget *g,int (*orderer)(const void *, const void *)) {
    GRowCol *grc = (GRowCol *) g;

    grc->orderer = orderer;
    if ( orderer!=NULL ) {
	GRowColOrderIt(grc);
	GRowColScrollBy(grc,-grc->loff,-grc->xoff);
	_ggadget_redraw(&grc->g);
    }
}
Beispiel #5
0
static void GRadioSetImageTitle(GGadget *g,GImage *img,const unichar_t *tit, int before) {
    GRadio *b = (GRadio *) g;
    if ( b->g.free_box )
	free( b->g.box );
    free(b->label);
    b->label = u_copy(tit);
    b->image = img;
    b->image_precedes = before;
    _ggadget_redraw(g);
}
Beispiel #6
0
static void GListSetOrderer(GGadget *g,int (*orderer)(const void *, const void *)) {
    GDList *gl = (GDList *) g;

    gl->orderer = orderer;
    if ( orderer!=NULL ) {
	GListOrderIt(gl);
	GListScrollBy(gl,-gl->loff,-gl->xoff);
	_ggadget_redraw(&gl->g);
    }
}
static void GRowColSelectOne(GGadget *g, int32 pos) {
    GRowCol *grc = (GRowCol *) g;

    GRowColClearSel(grc);
    if ( pos>=grc->ltot ) pos = grc->ltot-1;
    if ( pos<0 ) pos = 0;
    if ( grc->ltot>0 ) {
	grc->ti[pos]->selected = true;
	_ggadget_redraw(g);
    }
}
static void GRowColSelect(GGadget *g, int32 pos, int32 sel) {
    GRowCol *grc = (GRowCol *) g;

    GRowColClearSel(grc);
    if ( pos>=grc->ltot || pos<0 )
return;
    if ( grc->ltot>0 ) {
	grc->ti[pos]->selected = sel;
	_ggadget_redraw(g);
    }
}
Beispiel #9
0
static void GListSelectOne(GGadget *g, int32_t pos) {
    GDList *gl = (GDList *) g;

    GListClearSel(gl);
    if ( pos>=gl->ltot ) pos = gl->ltot-1;
    if ( pos<0 ) pos = 0;
    if ( gl->ltot>0 ) {
	gl->ti[pos]->selected = true;
	_ggadget_redraw(g);
    }
}
static void GRowColScrollToText(GGadget *g,unichar_t *text,int sel) {
    GRowCol *grc = (GRowCol *) g;
    int pos;

    pos = GRowColFindPosition(grc,text);
    if ( sel && pos<grc->ltot ) {
	GRowColClearSel(grc);
	if ( grc->exactly_one || u_strmatch(text,grc->ti[pos]->text)==0 )
	    grc->ti[pos]->selected = true;
    }
    grc->loff = GRowColAdjustPos(g,pos);
    _ggadget_redraw(g);
}
Beispiel #11
0
static void GListSelect(GGadget *g, int32_t pos, int32_t sel) {
    GDList *gl = (GDList *) g;
    int i;

    if ( pos==-1 && (gl->multiple_sel || (!sel && !gl->exactly_one)) ) {
	/* Select/deselect all */
	for ( i=0; i<gl->ltot; ++i )
	    gl->ti[i]->selected = sel;
	_ggadget_redraw(g);
return;
    }

    if ( pos>=gl->ltot || pos<0 )
return;
    if ( gl->exactly_one && !sel )
return;
    if ( !gl->multiple_sel && sel )
	GListClearSel(gl);
    if ( gl->ltot>0 ) {
	gl->ti[pos]->selected = sel;
	_ggadget_redraw(g);
    }
}
Beispiel #12
0
static void GListScrollToText(GGadget *g,const uint32_t *text,int32_t sel) {
    GDList *gl = (GDList *) g;
    int pos;

    pos = GListFindPosition(gl,(uint32_t *) text);
    if ( sel && pos<gl->ltot ) {
	GListClearSel(gl);
	if ( gl->exactly_one || u32_casecompare(text,gl->ti[pos]->text)==0 )
	    gl->ti[pos]->selected = true;
    }
    gl->loff = GListAdjustPos(g,pos);
    if ( gl->vsb!=NULL )
	GScrollBarSetPos(&gl->vsb->g,gl->loff);
    _ggadget_redraw(g);
}
Beispiel #13
0
static void GTabSetChangeSel(GTabSet *gts, int sel,int sendevent) {
    int i, width;
    int oldsel = gts->sel;

    if ( sel==-2 )		/* left arrow */
	--gts->toff;
    else if ( sel==-3 )
	++gts->toff;
    else if ( sel<0 || sel>=gts->tabcnt || gts->tabs[sel].disabled )
return;
    else {
	if ( gts->vertical )
	    gts->sel = sel;
	else {
	    for ( i=0; i<gts->rcnt && sel>=gts->rowstarts[i+1]; ++i );
	    if ( gts->active_row != i ) {
		gts->active_row = i;
		if ( gts->rcnt>1 && (!gts->filllines || gts->offset_per_row!=0))
		    GTabSetFigureWidths(gts);
	    }
	    gts->sel = sel;
	    if ( sel<gts->toff )
		gts->toff = sel;
	    else if ( gts->scrolled ) {
		for ( i=gts->toff; i<sel && gts->tabs[i].x!=0x7fff; ++i );
		if ( gts->tabs[i].x==0x7fff ) {
		    width = gts->g.r.width-2*gts->arrow_width;	/* it will have a left arrow */
		    if ( sel!=gts->tabcnt )
			width -= gts->arrow_width;		/* it might have a right arrow */
		    for ( i=sel; i>=0 && width-gts->tabs[i].width>=0; --i )
			width -= gts->tabs[i].width;
		    if ( ++i>sel ) i = sel;
		    gts->toff = i;
		}
	    }
	}
	if ( oldsel!=sel ) {
	    if ( sendevent )
		GTabSetChanged(gts,oldsel);
	    if ( gts->tabs[oldsel].w!=NULL )
		GDrawSetVisible(gts->tabs[oldsel].w,false);
	    if ( gts->tabs[gts->sel].w!=NULL )
		GDrawSetVisible(gts->tabs[gts->sel].w,true);
	}
    }
    _ggadget_redraw(&gts->g);
}
static void GRowColSetList(GGadget *g,GTextInfo **ti,int docopy) {
    GRowCol *grc = (GRowCol *) g;
    int same;

    GTextInfoArrayFree(grc->ti);
    if ( docopy || ti==NULL )
	ti = GTextInfoArrayCopy(ti);
    grc->ti = ti;
    grc->ltot = GTextInfoArrayCount(ti);
    if ( grc->orderer!=NULL )
	GRowColOrderIt(grc);
    grc->loff = grc->xoff = 0;
    grc->hmax = GTextInfoGetMaxHeight(g->base,ti,grc->font,&same);
    grc->sameheight = same;
    GRowColCheckSB(grc);
    _ggadget_redraw(&grc->g);
}
Beispiel #15
0
static void GListSetList(GGadget *g,GTextInfo **ti,int32_t docopy) {
    GDList *gl = (GDList *) g;
    int same;

    GTextInfoArrayFree(gl->ti);
    if ( docopy || ti==NULL )
	ti = GTextInfoArrayCopy(ti);
    gl->ti = ti;
    gl->ltot = GTextInfoArrayCount(ti);
    if ( gl->orderer!=NULL )
	GListOrderIt(gl);
    gl->loff = gl->xoff = 0;
    gl->hmax = GTextInfoGetMaxHeight(g->base,ti,gl->font,&same);
    gl->sameheight = same;
    GListCheckSB(gl);
    _ggadget_redraw(&gl->g);
}
Beispiel #16
0
static int gradio_key(GGadget *g, GEvent *event) {
    GRadio *gr = (GRadio *) g;

    if ( !g->takes_input || (g->state!=gs_enabled && g->state!=gs_active && g->state!=gs_focused ))
return(false);

    if ( event->u.chr.keysym == GK_Return || event->u.chr.keysym == GK_Tab ||
	    event->u.chr.keysym == GK_BackTab || event->u.chr.keysym == GK_Escape )
return( false );

    if (event->u.chr.chars[0]==' ' ) {
	GRadioChanged(gr);
	_ggadget_redraw(g);
return( true );
    }
return( false );
}
Beispiel #17
0
int32 GScrollBarSetPos(GGadget *g,int32 pos) {
    GScrollBar *gsb = (GScrollBar *) g;

    if ( pos>gsb->sb_max-gsb->sb_mustshow )
	pos = gsb->sb_max-gsb->sb_mustshow;
    if ( pos<gsb->sb_min )
	pos = gsb->sb_min;
    gsb->sb_pos = pos;

    if ( pos==gsb->sb_min || gsb->sb_min==gsb->sb_max )
	gsb->thumbpos = 0;
    else
	gsb->thumbpos =
	    (gsb->g.vert?gsb->g.inner.height:gsb->g.inner.width)*(pos-gsb->sb_min)/
		    (gsb->sb_max-gsb->sb_min);
    _ggadget_redraw(g);
return( pos );
}
Beispiel #18
0
static int gradio_mouse(GGadget *g, GEvent *event) {
    GRadio *gr = (GRadio *) g;
    int within = gr->within, pressed = gr->pressed;

    if ( !g->takes_input || (g->state!=gs_enabled && g->state!=gs_active && g->state!=gs_focused ))
return( false );

    if ( event->type == et_crossing ) {
	if ( gr->within && !event->u.crossing.entered )
	    gr->within = false;
    } else if ( gr->pressed && event->type!=et_mousemove ) {
	if ( event->type == et_mousedown ) /* They pressed 2 mouse buttons? */
	    gr->pressed = false;
	else if ( GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y)) {
	    gr->pressed = false;
	    if ( !gr->isradio || !gr->ison )
		GRadioChanged(gr);
	} else if ( event->type == et_mouseup )
	    gr->pressed = false;
	else
	    gr->within = true;
    } else if ( event->type == et_mousedown &&
	    GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y)) {
	gr->pressed = true;
	gr->within = true;
    } else if ( event->type == et_mousemove &&
	    GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y)) {
	gr->within = true;
	if ( !gr->pressed && g->popup_msg )
	    GGadgetPreparePopup(g->base,g->popup_msg);
    } else if ( event->type == et_mousemove && gr->within ) {
	gr->within = false;
    } else {
return( false );
    }
    if ( within != gr->within )
	g->state = gr->within? gs_active : gs_enabled;
    if ( within != gr->within || pressed != gr->pressed )
	_ggadget_redraw(g);
return( gr->within );
}
static void GRowColScrollBy(GRowCol *grc,int loff,int xoff) {
    int top = GRowColTopInWindow(grc,grc->ltot-1);
    int ydiff, i;

    if ( grc->loff + loff < 0 )
	loff = -grc->loff;
    else if ( grc->loff + loff > top )
	loff = top-grc->loff;
    if ( xoff+grc->xoff<0 )
	xoff = -grc->xoff;
    else if ( xoff+grc->xoff+grc->g.inner.width > grc->xmax ) {
	xoff = grc->xmax-grc->g.inner.width-grc->xoff;
	if ( xoff<0 ) xoff = 0;
    }
    if ( loff == 0 && xoff==0 )
return;

    ydiff = 0;
    if ( loff>0 ) {
	for ( i=0; i<loff && ydiff<grc->g.inner.height; ++i )
	    ydiff += GTextInfoGetHeight(grc->g.base,grc->ti[i+grc->loff],grc->font);
    } else if ( loff<0 ) {
	for ( i=loff; i<0 && -ydiff<grc->g.inner.height; ++i )
	    ydiff -= GTextInfoGetHeight(grc->g.base,grc->ti[i+grc->loff],grc->font);
    }
    if ( !GDrawIsVisible(grc->g.base))
return;
    GDrawForceUpdate(grc->g.base);
    grc->loff += loff; grc->xoff += xoff;
    if ( ydiff>=grc->g.inner.height || -ydiff >= grc->g.inner.height )
	_ggadget_redraw(&grc->g);
    else if ( ydiff!=0 || xoff!=0 )
	GDrawScroll(grc->g.base,&grc->g.inner,xoff,ydiff);
    if ( loff!=0 )
	GScrollBarSetPos(&grc->vsb->g,grc->loff);
}
static int growcol_key(GGadget *g, GEvent *event) {
    GRowCol *grc = (GRowCol *) g;
    uint16 keysym = event->u.chr.keysym;
    int sofar_pos = grc->sofar_pos;
    int loff, xoff, sel=-1;
    int refresh = false;

    if ( event->type == et_charup )
return( false );
    if ( !g->takes_input || (g->state!=gs_enabled && g->state!=gs_active && g->state!=gs_focused ))
return(false );

    if ( grc->ispopup && event->u.chr.keysym == GK_Return ) {
	GRowColDoubleClick(grc);
return( true );
    }

    if ( event->u.chr.keysym == GK_Return || event->u.chr.keysym == GK_Tab ||
	    event->u.chr.keysym == GK_BackTab || event->u.chr.keysym == GK_Escape )
return( false );

    GDrawCancelTimer(grc->enduser); grc->enduser = NULL; grc->sofar_pos = 0;

    loff = 0x80000000; xoff = 0x80000000; sel = -1;
    if ( keysym == GK_Home || keysym == GK_KP_Home || keysym == GK_Begin || keysym == GK_KP_Begin ) {
	loff = -grc->loff;
	xoff = -grc->xoff;
	sel = 0;
    } else if ( keysym == GK_End || keysym == GK_KP_End ) {
	loff = GRowColTopInWindow(grc,grc->ltot-1)-grc->loff;
	xoff = -grc->xoff;
	sel = grc->ltot-1;
    } else if ( keysym == GK_Up || keysym == GK_KP_Up ) {
	if (( sel = GRowColGetFirstSelPos(&grc->g)-1 )<0 ) {
	    /*if ( grc->loff!=0 ) loff = -1; else loff = 0;*/
	    sel = 0;
	}
    } else if ( keysym == GK_Down || keysym == GK_KP_Down ) {
	if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 )
	    ++sel;
	else
	    /*if ( grc->loff + GRowColLinesInWindow(grc,grc->loff)<grc->ltot ) loff = 1; else loff = 0;*/
	    sel = 0;
    } else if ( keysym == GK_Left || keysym == GK_KP_Left ) {
	xoff = -GDrawPointsToPixels(grc->g.base,6);
    } else if ( keysym == GK_Right || keysym == GK_KP_Right ) {
	xoff = GDrawPointsToPixels(grc->g.base,6);
    } else if ( keysym == GK_Page_Up || keysym == GK_KP_Page_Up ) {
	loff = GRowColTopInWindow(grc,grc->loff);
	if ( loff == grc->loff )		/* Normally we leave one line in window from before, except if only one line fits */
	    loff = GRowColTopInWindow(grc,grc->loff-1);
	loff -= grc->loff;
	if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) {
	    if (( sel += loff )<0 ) sel = 0;
	}
    } else if ( keysym == GK_Page_Down || keysym == GK_KP_Page_Down ) {
	loff = GRowColLinesInWindow(grc,grc->loff)-1;
	if ( loff<=0 ) loff = 1;
	if ( loff + grc->loff >= grc->ltot )
	    loff = GRowColTopInWindow(grc,grc->ltot-1)-grc->loff;
	if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) {
	    if (( sel += loff )>=grc->ltot ) sel = grc->ltot-1;
	}
    } else if ( keysym == GK_BackSpace && grc->orderer ) {
	/* ordered lists may be reversed by typing backspace */
	grc->backwards = !grc->backwards;
	GRowColOrderIt(grc);
	sel = GRowColGetFirstSelPos(&grc->g);
	if ( sel!=-1 ) {
	    int top = GRowColTopInWindow(grc,grc->ltot-1);
	    grc->loff = sel-1;
	    if ( grc->loff > top )
		grc->loff = top;
	    if ( sel-1<0 )
		grc->loff = 0;
	}
	GScrollBarSetPos(&grc->vsb->g,grc->loff);
	_ggadget_redraw(&grc->g);
return( true );
    } else if ( event->u.chr.chars[0]!='\0' && grc->orderer ) {
	int len = u_strlen(event->u.chr.chars);
	if ( sofar_pos+len >= grc->sofar_max ) {
	    if ( grc->sofar_max == 0 )
		grc->sofar = galloc((grc->sofar_max = len+10) * sizeof(unichar_t));
	    else
		grc->sofar = grealloc(grc->sofar,(grc->sofar_max = sofar_pos+len+10)*sizeof(unichar_t));
	}
	u_strcpy(grc->sofar+sofar_pos,event->u.chr.chars);
	grc->sofar_pos = sofar_pos + len;
	sel = GRowColFindPosition(grc,grc->sofar);
	grc->enduser = GDrawRequestTimer(grc->g.base,GRowColTypeTime,0,NULL);
    }

    if ( loff==0x80000000 && sel>=0 ) {
	if ( sel>=grc->ltot ) sel = grc->ltot-1;
	if ( sel<grc->loff ) loff = sel-grc->loff;
	else if ( sel>=grc->loff+GRowColLinesInWindow(grc,grc->loff) )
	    loff = sel-(grc->loff+GRowColLinesInWindow(grc,grc->loff)-1);
    } else
	sel = -1;
    if ( sel!=-1 ) {
	int wassel = grc->ti[sel]->selected;
	refresh = GRowColAnyOtherSels(grc,sel) || !wassel;
	GRowColSelectOne(&grc->g,sel);
	if ( refresh )
	    GRowColSelected(grc);
    }
    if ( loff!=0x80000000 || xoff!=0x80000000 ) {
	if ( loff==0x80000000 ) loff = 0;
	if ( xoff==0x80000000 ) xoff = 0;
	GRowColScrollBy(grc,loff,xoff);
    }
    if ( refresh )
	_ggadget_redraw(g);
    if ( loff!=0x80000000 || xoff!=0x80000000 || sel!=-1 )
return( true );

return( false );
}
static int growcol_mouse(GGadget *g, GEvent *event) {
    GRowCol *grc = (GRowCol *) g;
    int pos;

    if ( !g->takes_input || (g->state!=gs_active && g->state!=gs_enabled && g->state!=gs_focused))
return( false );

    if ( event->type == et_crossing )
return( false );
    if ( event->type==et_mousemove && !grc->pressed && !grc->parentpressed ) {
	if ( GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y) && g->popup_msg )
	    GGadgetPreparePopup(g->base,g->popup_msg);
return( true );
    } else if ( event->type==et_mouseup && grc->parentpressed &&
	    !GGadgetInnerWithin(&grc->g,event->u.mouse.x,event->u.mouse.y)) {
	grc->parentpressed = false;
	GDrawPointerUngrab(GDrawGetDisplayOfWindow(grc->g.base));
    } else if ( event->type==et_mousemove && grc->parentpressed &&
	    GGadgetInnerWithin(&grc->g,event->u.mouse.x,event->u.mouse.y)) {
	if ( grc->pressed == NULL )
	    grc->pressed = GDrawRequestTimer(g->base,GRowColScrollTime,GRowColScrollTime,NULL);
	GDrawPointerUngrab(GDrawGetDisplayOfWindow(grc->g.base));
	grc->parentpressed = false;
	growcol_scroll_selbymouse(grc,event);
return( true );
    } else if ( event->type==et_mousemove && grc->pressed ) {
	growcol_scroll_selbymouse(grc,event);
return( true );
    } else if ( event->type==et_mousedown ) {
	if ( grc->pressed == NULL )
	    grc->pressed = GDrawRequestTimer(g->base,GRowColScrollTime,GRowColScrollTime,NULL);
	pos = GRowColIndexFromPos(grc,event->u.mouse.y);
	if ( pos==-1 )
return( true ); /* Do Nothing, nothing selectable */
	else if ( !grc->exactly_one && grc->ti[pos]->selected &&
		(event->u.mouse.state&(ksm_control|ksm_shift))) {
	    grc->ti[pos]->selected = false;
	} else if ( !grc->multiple_sel ||
		!(event->u.mouse.state&(ksm_control|ksm_shift))) {
	    GRowColClearSel(grc);
	    grc->ti[pos]->selected = true;
	    grc->start = grc->end = pos;
	} else if ( event->u.mouse.state&ksm_control ) {
	    grc->ti[pos]->selected = !grc->ti[pos]->selected;
	    grc->start = grc->end = pos;
	} else if ( event->u.mouse.state&ksm_shift ) {
	    GRowColExpandSelection(grc,pos);
	}
	_ggadget_redraw(&grc->g);
    } else if ( event->type==et_mouseup && grc->pressed ) {
	GDrawCancelTimer(grc->pressed); grc->pressed = NULL;
	if ( GGadgetInnerWithin(&grc->g,event->u.mouse.x,event->u.mouse.y) ) {
	    growcol_scroll_selbymouse(grc,event);
	    if ( event->u.mouse.clicks==2 )
		GRowColDoubleClick(grc);
	    else
		GRowColSelected(grc);
	}
    } else
return( false );

return( true );
}
Beispiel #22
0
static int glist_mouse(GGadget *g, GEvent *event) {
    GDList *gl = (GDList *) g;
    int pos;

    if ( !g->takes_input || (g->state!=gs_active && g->state!=gs_enabled && g->state!=gs_focused))
return( false );

    if ( event->type == et_crossing )
return( false );
    if (( event->type==et_mouseup || event->type==et_mousedown ) &&
	    (event->u.mouse.button>=4 && event->u.mouse.button<=7)) {
	if ( gl->vsb!=NULL )
return( GGadgetDispatchEvent(&gl->vsb->g,event));
	else
return( true );
    }
    if ( event->type==et_mousemove && !gl->pressed && !gl->parentpressed ) {
	if ( GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y) ) {
	    if ( gl->popup_callback!=NULL )
		(gl->popup_callback)(g,GListIndexFromPos(gl,event->u.mouse.y));
	    else if ( g->popup_msg )
		GGadgetPreparePopup(g->base,g->popup_msg);
	}
return( true );
    } else if ( event->type==et_mouseup && gl->parentpressed /* &&
	    !GGadgetInnerWithin(&gl->g,event->u.mouse.x,event->u.mouse.y)*/ ) {
	gl->parentpressed = false;
	GDrawPointerUngrab(GDrawGetDisplayOfWindow(gl->g.base));
    } else if ( event->type==et_mousemove && gl->parentpressed &&
	    GGadgetInnerWithin(&gl->g,event->u.mouse.x,event->u.mouse.y)) {
	if ( gl->pressed == NULL )
	    gl->pressed = GDrawRequestTimer(g->base,GListScrollTime,GListScrollTime,NULL);
	GDrawPointerUngrab(GDrawGetDisplayOfWindow(gl->g.base));
	gl->parentpressed = false;
	glist_scroll_selbymouse(gl,event);
return( true );
    } else if ( event->type==et_mousemove && gl->pressed ) {
	glist_scroll_selbymouse(gl,event);
return( true );
    } else if ( event->type==et_mousedown ) {
	if ( gl->pressed == NULL )
	    gl->pressed = GDrawRequestTimer(g->base,GListScrollTime,GListScrollTime,NULL);
	pos = GListIndexFromPos(gl,event->u.mouse.y);
	if ( pos==-1 )
return( true ); /* Do Nothing, nothing selectable */
	else if ( !gl->exactly_one && gl->ti[pos]->selected &&
		(event->u.mouse.state&(ksm_control|ksm_shift))) {
	    gl->ti[pos]->selected = false;
	    gl->start = gl->end = 0xffff;
	} else if ( !gl->multiple_sel ||
		(!gl->ti[pos]->selected && !(event->u.mouse.state&(ksm_control|ksm_shift)))) {
	    GListClearSel(gl);
	    gl->ti[pos]->selected = true;
	    gl->start = gl->end = pos;
	} else if ( event->u.mouse.state&ksm_control ||
		((event->u.mouse.state&ksm_shift) && gl->ti[pos]->selected)) {
	    gl->ti[pos]->selected = !gl->ti[pos]->selected;
	    gl->start = gl->end = pos;
	} else if ( event->u.mouse.state&ksm_shift ) {
	    GListExpandSelection(gl,pos);
	} else {
	    gl->ti[pos]->selected = true;
	    gl->start = gl->end = pos;
	}
	_ggadget_redraw(&gl->g);
    } else if ( event->type==et_mouseup && gl->pressed ) {
	GDrawCancelTimer(gl->pressed); gl->pressed = NULL;
	if ( GGadgetInnerWithin(&gl->g,event->u.mouse.x,event->u.mouse.y) ) {
	    pos = GListIndexFromPos(gl,event->u.mouse.y);
	    if ( !(event->u.mouse.state&(ksm_control|ksm_shift)) || gl->start!=0xffff )
		glist_scroll_selbymouse(gl,event);
	    if ( event->u.mouse.clicks==2 )
		GListDoubleClick(gl,true,pos);
	    else
		GListSelected(gl,true,pos);
	}
    } else
return( false );

return( true );
}