Moveable dialogs don't work with text input fields

Previous topic - Next topic

Quentin

When setting a DDGui dialog MOVEABLE and a text input field within the dialog get the focus, the dialog is no longer moveable.

Example:
Code (glbasic) Select

DDgui_pushdialog(100, 100, 200, 100)
DDgui_set("", "TEXT", "Test dialog")
DDgui_set("", "MOVEABLE", TRUE)

LOCAL line$ = "test text"
DDgui_widget("", "Test input:", 0, 0)
DDgui_text("tx_test", line$, 80, 0)

WHILE TRUE
DDgui_show(FALSE)
SHOWSCREEN
WEND

Kitty Hello


Quentin

found one possible solution for it.
I think problem is, that the focus is set permanently for text input fields, not only for the time of a click, right?
So I changed function DDgui_show_intern and delete the focus, when dialog is moved and restore it afterwards.
(added commands are colored in red)
It works, can't see any side effects since now.

   // MOVE dialog
   IF is_current
      // handle move-bar
      IF ddgui_vals.moveable%
         LOCAL l_focus$
         l_focus$ = ddgui_vals.focus$
         ddgui_vals.focus$ = ""
         IF realb1
            i=BOXCOLL(x,y,width,ty, mx,my,1,1)
            IF (i OR ddgui_vals.moving%) AND LEN(ddgui_vals.focus$)=0
               ddgui_vals.moving%=TRUE
               x = MAX(0, x + mx - movemousex%)
               y = MAX(0, y + my - movemousey%)
               ddgui_vals.xpos = x
               ddgui_vals.ypos = y
            ENDIF
         ELSE
            ddgui_vals.moving%=FALSE
         ENDIF
         ddgui_vals.focus$ = l_focus$
      ENDIF
   ENDIF

Kitty Hello

You da man! So many thanks. I'll add that to the next update.

Quentin


Kitty Hello

Line 848. Add:
ddgui_vals.focus$=""

That is, when you press the left button down, clear the current focus.

Quentin

yes, but I didn't want the text field loose its focus. So I think it's better to restore it afterwards as it's nearer to the behavior of "normal" windows programs :)

Kitty Hello

oh dear. Because with your method, when a dialog has a slider and you slide too much up, the moving starts.

Quentin

oops, you're right. So restoring focus is only necessary for text input field.

new suggestion (ok, looks not even nice, I think)

   // MOVE dialog
   IF is_current
      // handle move-bar
      IF ddgui_vals.moveable%
         LOCAL l_clearfocus%, l_focus$
         FOREACH w IN ddgui_vals.widgets[]
            IF w.wid$ = ddgui_vals.focus$ AND w.wtype$ = "TEXT"
               l_clearfocus = TRUE
               BREAK
            ENDIF
         NEXT
         IF l_clearfocus
            l_focus$ = ddgui_vals.focus$
            ddgui_vals.focus$ = ""
         ENDIF

         IF realb1
            i=BOXCOLL(x,y,width,ty, mx,my,1,1)
            IF (i OR ddgui_vals.moving%) AND LEN(ddgui_vals.focus$)=0
               ddgui_vals.moving%=TRUE
               x = MAX(0, x + mx - movemousex%)
               y = MAX(0, y + my - movemousey%)
               ddgui_vals.xpos = x
               ddgui_vals.ypos = y
            ENDIF
         ELSE
            ddgui_vals.moving%=FALSE
         ENDIF
         IF l_clearfocus THEN ddgui_vals.focus$ = l_focus$
      ENDIF
   ENDIF

Kitty Hello

The focus of a scrollbar will be "SB" + widgetname$, thus the main dialog has no name and focus$="SB".

Might be wise to check against MID$(focus$,0,2)="SB", though.