/*
 * Closes the widget
 */
int SDL_WidgetClose(SDL_Widget *Widget)
{
    SDL_WidgetList *current_widget,*prev;

    current_widget=SDL_WindowGetWidgetList();
    prev=NULL;

    while(current_widget)
    {
        if(current_widget->Widget == Widget)
        {
            prev->Next = current_widget->Next;
            return 1;
        }
        prev=current_widget;
        current_widget=current_widget->Next;
    }
    return 0;
}
Exemple #2
0
void clearWin()
{
	// This function should remove and free all widgets on the top window.
	// should find a way to judge the widget type
	SDL_WidgetList *temp;

	temp = SDL_WindowGetWidgetList();
	while(temp)
	{
		/* tangg temporarily modified */
		if (	temp->Widget != button_leave 
			&& temp->Widget != ((SDL_Button *)button_leave)->Label 
			&& temp->Widget != line_style1) 
			SDL_WidgetClose(temp->Widget);

		temp = temp->Next;
	}
	
	refreshWin();
	
	clearGlobals();
}
/* return 0 if no windows are available */
int SDL_WindowManagerEvent(SDL_Event *event)
{
    SDL_WidgetList* WidgetList;
    SDL_Widget* focus_widget=NULL;
    SDL_Window *window;

    SDL_WindowManagerWindowEvent(event);
    window = SDL_WindowGetTopVisibleWindow();

    if(SDL_WindowAvailable() == 0)
        return 0;

    if(window && event->type >= SDL_MOUSEMOTION)
    {
        event->motion.xrel = event->motion.x;
        event->motion.yrel = event->motion.y;
        event->motion.x -= window->Widget.Rect.x;
        event->motion.y -= window->Widget.Rect.y;
    }

    focus_widget = SDL_WindowGetFocusWidget();

    if(event->type == SDL_MOUSEBUTTONDOWN &&
       focus_widget != NULL &&
       SDL_WidgetIsInside(focus_widget,event->motion.x,event->motion.y))
    {
        SDL_WidgetEvent(focus_widget,event);
        return 1;
    }
    if(event->type == SDL_MOUSEBUTTONDOWN)
    {
        SDL_WidgetList*  focus_widget = SDL_WindowGetWidgetList();
        while(focus_widget)
        {
            SDL_Widget *w=(SDL_Widget*)focus_widget->Widget;
            
            if(SDL_WidgetIsInside(w,event->motion.x,event->motion.y))
            {
                if(focus_widget->Widget->flags & WIDGET_FOCUSABLE)
                {
                    SDL_WindowSetFocusWidget(focus_widget->Widget);
                    SDL_WidgetRedrawEvent(focus_widget->Widget);
                }
                /*  Bug found when there are overlapping widgets the focus is set to the wrong widget */
            }
            focus_widget=focus_widget->Next;
        }
    }

    WidgetList = SDL_WindowGetWidgetList();
    while(WidgetList)
    {
	/* ATTEN: here should be the old value of the WidgetList, if the win->WidgetList value changed in the following 
	 * SDL_WidgetEvent() function, then this pointer here could not update immediately.
	 */
        SDL_Widget *Widget=(SDL_Widget*)WidgetList->Widget;

        /* tangg added */
        if(Widget && (Widget->flags & WIDGET_VISIBLE))
        {
            SDL_WidgetEvent(Widget,event);
        }
        WidgetList=WidgetList->Next;
    }

    /* If the widgets don't handle the event pass
       the event to the event handler of the window */
    {
        SDL_Window *Win;

        Win=SDL_WindowGetTopVisibleWindow();
        
        if(Win && Win->EventHandler)
        {

            Win->EventHandler(*event);
        }
    }
    return 1;
}
int SDL_WindowManagerWindowEvent(SDL_Event *event)
{
    SDL_WindowListElem *CurrentWindow  = (SDL_WindowListElem*)WindowList.last;
    SDL_WindowListElem *PreviousWindow = NULL;
    SDL_WindowListElem *StoredPreviousWindow = NULL;
    SDL_WindowListElem *StoredWindow         = NULL;

    switch(event->type)
    {
    case SDL_KEYDOWN:
        switch( event->key.keysym.sym ) 
        {
        case SDLK_TAB:
        {
            SDL_Widget     *FocusWidget;
            SDL_WidgetList *WidgetList;
            SDL_Widget     *FirstFocusWidget=NULL;
            int store=0;

            WidgetList  = SDL_WindowGetWidgetList();
            FocusWidget = SDL_WindowGetFocusWidget();
            
            while(WidgetList)
            {
                if(FocusWidget == NULL)
                {
                    if(WidgetList->Widget->flags & WIDGET_FOCUSABLE)
                    {
                        SDL_WindowSetFocusWidget(WidgetList->Widget);
                        break;
                    }
                }
                else
                {
                    if((WidgetList->Widget->flags & WIDGET_FOCUSABLE) && FirstFocusWidget == NULL)
                        FirstFocusWidget=WidgetList->Widget;

                    if(store && (WidgetList->Widget->flags & WIDGET_FOCUSABLE))
                    {
                        SDL_WindowSetFocusWidget(WidgetList->Widget);
                        break;
                    }
                    if(WidgetList->Widget == FocusWidget)
                        store=1;

                }
                WidgetList = WidgetList->Next;
            
            }
            if(WidgetList == NULL)
            {
                if(FirstFocusWidget)
                    SDL_WindowSetFocusWidget(FirstFocusWidget);
            }
            SDL_WidgetRedrawEvent(FocusWidget);
            
        }
        break;

        default:
            break;
        }
        break;
        
    }

    if(event->type == SDL_MOUSEBUTTONDOWN && CurrentWindow)
    {
        while(CurrentWindow->ll.next)
        {
            if(SDL_WidgetIsInside(&CurrentWindow->Window->Widget,event->motion.x,event->motion.y))
            {
                /* Remember the top most visible window which is clicked on */
                StoredWindow         = CurrentWindow;                
              	StoredPreviousWindow = PreviousWindow;
            }
            PreviousWindow = CurrentWindow;
            CurrentWindow  = (SDL_WindowListElem*)CurrentWindow->ll.next;
        }

        if(StoredWindow)
        {
            /* If there is a window click, make sure it becomes the top visible window */
            CurrentWindow->ll.next = &StoredWindow->ll;
            if(StoredPreviousWindow == NULL)
                WindowList.first = StoredWindow->ll.next;
            else
                StoredPreviousWindow->ll.next = StoredWindow->ll.next;
            StoredWindow->ll.next = NULL;
            return 1;
        }
   
    }
    return 0;
}