Page 1 of 1

Can't create a Scintilla gadget after opening a new window.

Posted: Wed Feb 11, 2015 6:35 pm
by rmenezes
This forum might not be the right place to ask, since it'll probably be a Scintilla code problem, but begging you pardon...

I'm building a multieditor application (as many others already did) based on the Scintilla gadget. One thing I'd like to do is to open a secondary window where the user can add some text metadata (so far nothing new). Everything works fine until... to my surprise, once I've opened any secondary window I can no longer create a new Scintilla gadget!

What follows is a testbed To demonstrate this behavior. You can press "Make Sci" as many times as you wish. The editors are created as expected and reported in the debug window. Press "Open win" to briefly open a (empty) window and then close it right back. The next time you press "Make Sci" the ScintillaGadget function returns 0 and the gadget is not created.

Any thoughts on this? I'd really appreciate it.


Code: Select all

EnableExplicit
InitScintilla()

#mainWin = 0
#subWin = 1
#mkSciBtn = 1
#opWinBtn = 2

Procedure DoSciCallback(i, *scinotify.SCNotification)
EndProcedure

Procedure TestSci(sciNum)
  If sciNum > 0
    Debug "Created sci# "+Str(sciNum)
  Else
    Debug "** Sci not created **"
    End
  EndIf
EndProcedure  

Procedure MakeSci()
  Protected sciNum  
  sciNum = ScintillaGadget(#PB_Any, 100, 0, WindowWidth(#mainWin)-100, WindowHeight(#mainWin), @DoSciCallback())
  TestSci(sciNum)
EndProcedure

Procedure OpenSubWin()
  DisableWindow(#mainWin, #True)
  OpenWindow(#subWin, 0, 0, 300, 300, "secondary Window!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EndProcedure

Procedure CloseSubWin()
  CloseWindow(#subWin)
  DisableWindow(#mainWin, #False)
EndProcedure

;
; Main
;

OpenWindow(#mainWin, 0, 0, 600, 700, "Main Window!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#mkSciBtn, 0, 10, 100, 20, "Make sci")
ButtonGadget(#opWinBtn, 0, 40, 100, 20, "Open win")
BindGadgetEvent(#mkSciBtn, @MakeSci())
BindGadgetEvent(#opWinBtn, @OpenSubWin())

Define event, window
Repeat
  event = WaitWindowEvent()
  window = EventWindow()
  Select window
    Case #subWin
      If event = #PB_Event_CloseWindow
        CloseSubWin()
      EndIf
    Case #mainWin
      If event = #PB_Event_CloseWindow
        End
      EndIf
  EndSelect
ForEver
End
Cheers!

Re: Can't create a Scintilla gadget after opening a new wind

Posted: Wed Feb 11, 2015 7:03 pm
by infratec
Hi,

simple:

If you disable the main window you can not press the button.

Bernd

Re: Can't create a Scintilla gadget after opening a new wind

Posted: Wed Feb 11, 2015 11:10 pm
by netmaestro
Simple yes but not that simple. Here is the code you need:

Code: Select all

Procedure CloseSubWin()
  CloseWindow(#subWin)
  DisableWindow(#mainWin, #False)
  UseGadgetList(WindowID(#mainWin)) ; <------- Opening the second window changed the current GadgetList, you must set it back
EndProcedure

Re: Can't create a Scintilla gadget after opening a new wind

Posted: Thu Feb 12, 2015 6:15 pm
by rmenezes
@NetMaestro,

Once again your divine intervention saved the day! Thank you very much.


You know, I kind of suspected that it had something to do with updating the GadgetList. I just couldn't pinpoint it. What threw me off was the fact that in 5.3 you no longer need to initialize it explicitly. So I figured the compiler would know when to go back to the previous list. But this is over now. Back to work!

Cheers!

(PB forums: the best customer support in the Net)