Page 1 of 1

Panel crashing when adding new tabs

Posted: Thu Jul 24, 2003 1:53 pm
by RJP Computing
I have a couple of problems.

First, in Windows XP only when I add a new tab to a panel and then add a Editor gadget to the tab I loose the border around the Editor gadget. I did find a work around by using invalidateRect API call but I think this is a bug in the Editor or panel Gadget. (see code below for example)

Second, this is the first time I have used the panel gadget and the example below fails for calling a 'CloseGadgetList' before calling an open. It does this only after the seventh tab. I have to be missing something.

Example Code:

Code: Select all

;-Init Constants

#WindowIndex    =0
#GadgetIndex    =0
#ImageIndex     =0
#StatusBarIndex =0
#MenuBarIndex   =0




;-Window Constants
#Window_Form1                           = #WindowIndex:#WindowIndex=#WindowIndex+1
#Window_About                           = #WindowIndex:#WindowIndex=#WindowIndex+1



;-Gadget Constants

;Window_Form1
#MenuBar_Form1                          = #MenuBarIndex:#MenuBarIndex=#MenuBarIndex+1
#MenuBar_Form1_New                      = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_Form1_Open                     = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_Form1_Save                     = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_Form1_Exit                     = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_Form1_Settings                 = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_Form1_Help                     = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_Form1_About                    = #GadgetIndex:#GadgetIndex=#GadgetIndex+1

#Gadget_Form1_Panel1                    = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_Form1_Editor1_1                 = #GadgetIndex:#GadgetIndex=#GadgetIndex+1

#StatusBar_Form1                        = #StatusBarIndex:#StatusBarIndex=#StatusBarIndex+1
#StatusBar_Form1_Field1                 = 0

;Window_About
#Gadget_About_RJPLogo                   = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_Appname                   = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_Version                   = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_VersionText               = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_Build                     = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_BuildText                 = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_Copyright                 = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_Homepage                  = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_OK                        = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_About_Frame3D12                 = #GadgetIndex:#GadgetIndex=#GadgetIndex+1

;-Image Constants
#Image_About_RJPLogo                    = #ImageIndex:#ImageIndex=#ImageIndex+1

;- General Constants
#BUILD        = #PB_COMPILER_DATE

;-Load Images
;CatchImage(#Image_About_RJPLogo,?_IMG_About_RJPLogo)

; DataSection
;   _IMG_About_RJPLogo:IncludeBinary "Images\rjplogo_small.bmp"
; EndDataSection
  
  
  
  
  ;--------------------
  ;-Language Data
  Procedure Build_Language(languagefile.s)
    Dim language.s(10)
    flag.l=0
    If languagefile<>"" And FileSize(languagefile)>0
      If ReadFile(0,languagefile)
        For tmp=1 To 10
          language(tmp)=ReadString()
        Next
        flag=1
        CloseFile(0)
      EndIf
    EndIf
    If flag=0
      Restore LanguageData
      For tmp=1 To 10
        Read language(tmp)
      Next
    EndIf
  EndProcedure
  
  Build_Language("")
  
  DataSection
  LanguageData:
  Data.s "About"
  Data.s "Panel Test"
  Data.s "Version :"
  Data.s "0.01"
  Data.s "Build :"
  Data.s ""
  Data.s "Copyright (c) 2003 RJP Computing"
  Data.s "www.rjpcomputing.com"
  Data.s "OK"
  Data.s ""
  EndDataSection
  
  Procedure.l Window_Form1()
    If OpenWindow(#Window_Form1,175,0,400,300,#PB_Window_SystemMenu|#PB_Window_WindowCentered|#PB_Window_Invisible,language(2))
      CreateMenu(#MenuBar_Form1,WindowID(#Window_Form1))
      MenuTitle("File")
      MenuItem(#MenuBar_Form1_New,"New")
      MenuBar()
      MenuItem(#MenuBar_Form1_Open,"Open")
      MenuItem(#MenuBar_Form1_Save,"Save")
      MenuBar()
      MenuItem(#MenuBar_Form1_Exit,"Exit")
      MenuTitle("Edit")
      MenuItem(#MenuBar_Form1_Settings,"Settings")
      MenuTitle("Help")
      MenuItem(#MenuBar_Form1_Help,"Help")
      MenuBar()
      MenuItem(#MenuBar_Form1_About,"About")
      If CreateGadgetList(WindowID())
        PanelGadget(#Gadget_Form1_Panel1,0,0,400,256)
        AddGadgetItem(#Gadget_Form1_Panel1,-1,"Tab1")
        EditorGadget(#Gadget_Form1_Editor1_1,0,0,395,232)
        CloseGadgetList()
        CreateStatusBar(#StatusBar_Form1,WindowID(#Window_Form1))
        AddStatusBarField(100)
        HideWindow(#Window_Form1,0)
        ProcedureReturn WindowID()
      EndIf
    EndIf
  EndProcedure
  
  Procedure.l Window_About(pParent.l)
    If OpenWindow(#Window_About,175,0,260,155,#PB_Window_WindowCentered|#PB_Window_Invisible,language(1),WindowID(pParent))
      ;MakeToolWindow(WindowID(#Window_About), #True) ;Uses the PureTools Lib
      
      If CreateGadgetList(WindowID())
        ;ImageGadget(#Gadget_About_RJPLogo,5,10,67,49,UseImage(#Image_About_RJPLogo),#PB_Image_Border)
        TextGadget(#Gadget_About_Appname,90,10,165,15,language(2))
        TextGadget(#Gadget_About_Version,90,30,45,15,language(3))
        TextGadget(#Gadget_About_VersionText,135,30,120,15,language(4))
        TextGadget(#Gadget_About_Build,90,50,30,15,language(5))
        TextGadget(#Gadget_About_BuildText,120,50,135,15,Str(#PB_COMPILER_DATE))
        TextGadget(#Gadget_About_Copyright,15,80,230,15,language(7),#PB_Text_Center)
        HyperLinkGadget(#Gadget_About_Homepage,70,105,115,15,language(8),16744448)
        ButtonGadget(#Gadget_About_OK,95,130,60,20,language(9),#PB_Button_Default)
        Frame3DGadget(#Gadget_About_Frame3D12,5,65,250,60,language(10))
        HideWindow(#Window_About,0)
        ProcedureReturn WindowID()
      EndIf 
    EndIf
  EndProcedure

;-Main Loop
If Window_Form1()
  panelCount = 2
  editorCount = 2
  quitForm1=0
  Repeat
    EventID=WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID()=#Window_Form1
          quitForm1=1
        ElseIf EventWindowID()=#Window_About
          CloseWindow(#Window_About)
          ActivateGadget(#Gadget_Form1_Editor1_1)
        EndIf

      Case #PB_Event_Menu
        Select EventMenuID()
          Case #MenuBar_Form1_New
            ;CallDebugger
            OpenGadgetList(#Gadget_Form1_Panel1) 
            AddGadgetItem(#Gadget_Form1_Panel1,-1,"Tab " + Str(panelCount)) : panelCount + 1
            EditorGadget(editorCount,0,0,395,232):editorCount+1
            CloseGadgetList() ; <----- this fails for closeing without opening after the
                              ;        'Tab 7' is created
            
            ; This is needed to bet the border back around the Editor Gadget!
            ; I think this might be an XP bug. (It only does it on XP)
            invalidateRect_(GadgetID(#Gadget_Form1_Panel1), 0, 1)
          Case #MenuBar_Form1_Open 
          Case #MenuBar_Form1_Save
          Case #MenuBar_Form1_Exit
            quitForm1 = 1
          Case #MenuBar_Form1_Settings
          Case #MenuBar_Form1_Help
          Case #MenuBar_Form1_About
            Window_About(#Window_Form1)
        EndSelect

      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case #Gadget_Form1_Panel1
          Case #Gadget_Form1_Editor1_1
          Case #Gadget_About_OK
            CloseWindow(#Window_About)
            ActivateGadget(#Gadget_Form1_Editor1_1)
          Case #Gadget_About_Homepage
            RunProgram("http://www.rjpcomputing.com")
        EndSelect

    EndSelect
  Until quitForm1
  CloseWindow(#Window_Form1)
EndIf
End
Thanks

Posted: Fri Aug 01, 2003 6:48 pm
by RJP Computing
Does anybody have any ideas on this bug? I am at a loss.

Thanks in advance

Posted: Fri Aug 01, 2003 7:28 pm
by Pupil
You don't need to use OpenGadgetList() for adding a panel to the panelgadget, but i think you can if you feel better about it ;). But the biggest misstake you made was to to start the 'editorcount' variable at a number that is lower than the last defined gadget constant. What happened is that as this variable increases you will reach the number 7 when you will create a new EditorGadget with the same ID as the PanelGadget, the next time you try to add a panel you're actually trying to add it to the editorgadget and that's a no no...

Remember that gadget ID's should be unique unless they are static gadgets that doesn't need to be changed..

Posted: Fri Aug 01, 2003 7:37 pm
by Paul
Yes, as Pupil points out you need to change
editorCount = 2
to
editorCount = #GadgetIndex

also it would work better if you changed
invalidateRect_(GadgetID(#Gadget_Form1_Panel1), 0, 1)
to
SetGadgetState(#Gadget_Form1_Panel1,panelCount-2)


:)

Posted: Fri Aug 01, 2003 7:53 pm
by TerryHough
Ryan, perhaps you are looking at the wrong problem. Maybe the
problem is with the EditorGadget?

I remmed out the EditorGadget create line and could then create
panels well beyond Tab 7.

I confirm that it ails here on Win98Se after 7 panels with the
EditorGadget being created.