Updated Flexgrid

Share your advanced PureBasic knowledge/code with the community.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Updated Flexgrid

Post by localmotion34 »

Code updated For 5.20+

here is the rest of my code tyo get someone started with a flexgrid and the entry of the events. ive got the basic layout, the double click with event window popup, time blocking ( very simply), although someone could probably use ownerdraw to block out colors instead of what i did. i also included some code that has been commeneted out because it highlights the entire event block when any part of it has been clicked, BUT in combination with the double click event they seem to cancel each other out. so if anyone can fix and use that, please do. i also wondered why i never got any responses about this. ive seen numerous posts about a flexgrid from people, including myself. is no one interested? i am trung to find a way to maybe flip this over to C or somehow mak a PB lib out of it so we can have a new gadget. just a thought.

Code: Select all


; PureBasic Visual Designer v3.81 BETA build 1302

Global listiconnumber,clickedlisticon,currentitemselection,eventname$,totaleventitems
;- Window Constants
;
Enumeration
  #Window_0
  #Window_1
EndEnumeration
;- Gadget Constants
Enumeration
  #Button_0
  #Button_1
  #Combo_0
  #Combo_1
  #Text_0
  #Text_1
  #String_0
  #Text_3
  #Editor_0
  #Text_5
  #ScrollArea_1
EndEnumeration
Procedure Flexgridgadget(scrollareanumber,flexgridx,flexgridy,flexgridwidth,flexgridheight,scrollwidth,scrollheight)
  ScrollAreaGadget(scrollareanumber, flexgridx, flexgridy, flexgridwidth, flexgridheight, scrollwidth, scrollheight, 10)
  listiconnumber=scrollareanumber
  ListIconGadget(listiconnumber+1, 40, 30, 110, 700, "Sunday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ListIconGadget(listiconnumber+2, 150, 30, 110, 700, "Monday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ListIconGadget(listiconnumber+3, 260, 30, 110, 700, "Tuesday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ListIconGadget(listiconnumber+4, 370, 30, 110, 700, "Wednesday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ListIconGadget(listiconnumber+5, 480, 30, 110, 700, "Thursday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ListIconGadget(listiconnumber+6, 590, 30, 110, 700, "Friday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ListIconGadget(listiconnumber+7, 700, 30, 110, 700, "Saturday", 105, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  ;add text boxes EVERY OTHER ITEM that mark the hours
  starttimehour=5
  textgadgetnumber=listiconnumber+7
  y=25    ;start at height=25
  For a=listiconnumber+7 To listiconnumber+30
    y=y+28  ;this value works best to line up boxes with listicon rows
    textgadgetnumber=textgadgetnumber+1 ;add one to the previous gadget number
    starttimehour=starttimehour+1 ;add one to the previous hour
    If starttimehour>=0 And  starttimehour<=11
      ampm$="am"
    ElseIf  starttimehour>=12 And  starttimehour<=23
      ampm$="pm"
    EndIf
    If starttimehour=24 ;when we get to midnight, we start all over
      starttimehour=starttimehour-24
      ampm$="am"
      TextGadget(textgadgetnumber,0,y,40,13,Str(starttimehour)+":00"+ampm$)
    Else
      TextGadget(textgadgetnumber,0,y,40,13,Str(starttimehour)+":00"+ampm$)
    EndIf
  Next
  For a= listiconnumber+1 To listiconnumber+7
    ;         LockColumnSize(a, #PB_LockAll )
  Next
  For a= listiconnumber+1 To listiconnumber+7   ;now we add empty spaces to the listicons
    For b=0 To 47
      AddGadgetItem(a,b,"")
    Next
  Next
EndProcedure

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 108, 40, 830, 609, "PB FlexGrid",  #PB_Window_SystemMenu | #PB_Window_TitleBar )
    
    Flexgridgadget(#ScrollArea_1,0, 10, 830, 590, 850, 750)
    CreateMenu(0, WindowID(#Window_0))    ; here the menu creating starts....
    MenuTitle("File")
    MenuItem(1, "Open")
    MenuItem(2, "Save")
    MenuItem(3, "Save as")
    MenuItem(4, "Print")
  EndIf
EndProcedure
Procedure Open_Window_1() ;this is the information window
  If OpenWindow(#Window_1, 237, 162, 458, 293 , "Enter Information",  #PB_Window_SizeGadget |#PB_Window_TitleBar)
    ;         If CreateGadgetList(WindowID())
    ButtonGadget(#Button_0, 110, 250, 90, 30, "Enter")
    ButtonGadget(#Button_1, 240, 250, 90, 30, "Cancel")
    ComboBoxGadget(#Combo_0, 170, 20, 100, 350)
    ComboBoxGadget(#Combo_1, 170, 60, 100, 350)
    TextGadget(#Text_0, 70, 20, 70, 20, "Start:", #PB_Text_Center)
    TextGadget(#Text_1, 70, 60, 70, 20, "Stop:", #PB_Text_Center)
    StringGadget(#String_0, 110, 100, 310, 20, "")
    TextGadget(#Text_3, 40, 100, 70, 20, "Event:", #PB_Text_Center)
    EditorGadget(#Editor_0, 110, 130, 310, 110)
    TextGadget(#Text_5, 40, 170, 70, 20, "Notes:", #PB_Text_Center)
    ;         EndIf
    hour=5 ;here we add all the times to the comboboxes
    d=-2
    For a=0 To 23
      d=d+2
      hour=hour+1
      If hour>=0 And  hour<=11
        ampm$="am"
      ElseIf  hour>=12 And  hour<=23
        ampm$="pm"
      EndIf
      If hour=24
        hour=hour-24
        ampm$="am"
        AddGadgetItem(#Combo_0,d,Str(hour)+":00"+ampm$)
        AddGadgetItem(#Combo_0,d+1,Str(hour)+":30"+ampm$)
      Else
        AddGadgetItem(#Combo_0,d,Str(hour)+":00"+ampm$)
        AddGadgetItem(#Combo_0,d+1,Str(hour)+":30"+ampm$)
      EndIf
    Next
    hour=5 ;here we add all the times to the comboboxes
    d=-2
    For a=0 To 23
      d=d+2
      hour=hour+1
      If hour>=0 And  hour<=11
        ampm$="am"
      ElseIf  hour>=12 And  hour<=23
        ampm$="pm"
      EndIf
      If hour=24
        hour=hour-24
        ampm$="am"
        AddGadgetItem(#Combo_1,d,Str(hour)+":00"+ampm$)
        AddGadgetItem(#Combo_1,d+1,Str(hour)+":30"+ampm$)
      Else
        AddGadgetItem(#Combo_1,d,Str(hour)+":00"+ampm$)
        AddGadgetItem(#Combo_1,d+1,Str(hour)+":30"+ampm$)
      EndIf
    Next
  EndIf
EndProcedure


;-Main Program
Open_Window_0();open our window
;-Event Loop

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      eventtype=EventType()
      Select EventType()
        Case #PB_EventType_LeftClick
          GadgetID = EventGadget()
          ;          If GadgetID>=listiconnumber+1 And GadgetID<=listiconnumber+7
          ;            clickedlisticon=GadgetID
          ;            currentitemselection=GetGadgetState(clickedlisticon)
          ;            currentevent$=GetGadgetItemText(clickedlisticon,currentitemselection,0)
          ;            g=currentitemselection
          ;            If currentevent$<>"|||||||||||||||||||||||||||||||||||||||||||||||" And currentevent$<>""
          ;              Repeat
          ;                g=g+1
          ;                currentevent$=GetGadgetItemText(clickedlisticon,g,0)
          ;                If currentevent$<> "|||||||||||||||||||||||||||||||||||||||||||||||"
          ;                  Break
          ;                EndIf
          ;                SetGadgetItemState(clickedlisticon,g,1)
          ;              Until currentevent$<> "|||||||||||||||||||||||||||||||||||||||||||||||"
          ;           
          ;          ElseIf currentevent$="|||||||||||||||||||||||||||||||||||||||||||||||"
          ;            g=currentitemselection
          ;            Repeat
          ;              g=g+1
          ;              currentevent$=GetGadgetItemText(clickedlisticon,g,0)
          ;              If currentevent$= "|||||||||||||||||||||||||||||||||||||||||||||||"
          ;                SetGadgetItemState(clickedlisticon,g,1)
          ;              EndIf
          ;            Until currentevent$<>"|||||||||||||||||||||||||||||||||||||||||||||||"
          ;            g=currentitemselection
          ;            Repeat
          ;              g=g-1
          ;              currentevent$=GetGadgetItemText(clickedlisticon,g,0)
          ;              If currentevent$= "|||||||||||||||||||||||||||||||||||||||||||||||"
          ;                SetGadgetItemState(clickedlisticon,g,1)
          ;              EndIf
          ;            Until currentevent$<>"|||||||||||||||||||||||||||||||||||||||||||||||"
          ;          EndIf
          ;        EndIf
          Select GadgetID
            Case #Button_1
              EnableWindow_(WindowID(#Window_0),#True)
              HideWindow(#Window_1,1)
            Case #Button_0
              timeresult=GetGadgetState(#Combo_0)
              timeresult1=GetGadgetState(#Combo_1)
              totaltime=timeresult1-timeresult
              If totaltime<0
                MessageRequester("Error","You Specified A Time Range That Goes Backwards",#PB_MessageRequester_Ok)
              Else
                EnableWindow_(WindowID(#Window_0),#True)
                eventname$=GetGadgetText(#String_0)
                If eventname$=""
                Else
                  SetGadgetItemText(clickedlisticon,currentitemselection,eventname$,0)
                  For f=currentitemselection+1 To currentitemselection+totaltime
                    SetGadgetItemText(clickedlisticon,f,"|||||||||||||||||||||||||||||||||||||||||||||||",0)
                  Next
                  If totaltime<>totaleventitems
                    itemstoclear=totaleventitems-totaltime
                    For s=currentitemselection+totaltime+1 To currentitemselection+totaltime+1+itemstoclear
                      SetGadgetItemText(clickedlisticon,s,"",0)
                    Next
                  ElseIf eventname$=""
                    For s=currentitemselection To totaleventitems
                      SetGadgetItemText(clickedlisticon,s,"",0)
                    Next
                  EndIf
                EndIf
                HideWindow(#Window_1,1)
              EndIf
              
          EndSelect
        Case #PB_EventType_LeftDoubleClick
          GadgetID = EventGadget()
          If GadgetID>=listiconnumber+1 And GadgetID<=listiconnumber+7
            clickedlisticon=GadgetID
            currentitemselection=GetGadgetState(clickedlisticon)
            currentevent$=GetGadgetItemText(clickedlisticon,currentitemselection,0)
            g=currentitemselection
            totaleventitems=1
            Repeat
              g=g+1
              result$=GetGadgetItemText(clickedlisticon,g,0)
              If result$="|||||||||||||||||||||||||||||||||||||||||||||||"
                totaleventitems=totaleventitems+1
              ElseIf result$=""
                Break
              EndIf
            Until result$<>"|||||||||||||||||||||||||||||||||||||||||||||||"
            If currentevent$="|||||||||||||||||||||||||||||||||||||||||||||||"
            Else
              Open_Window_1()
              SetGadgetState(#Combo_0,currentitemselection)
              SetGadgetState(#Combo_1,currentitemselection+totaleventitems-1)
              SetGadgetText(#String_0,currentevent$)
              EnableWindow_(WindowID(#Window_0),#False);user double clicks, and presto--info window pops up
            EndIf
          EndIf
      EndSelect
      eventmenu=EventMenu()
      Select eventmenu
          
          
      EndSelect
  EndSelect
Until Event = #PB_Event_CloseWindow
End

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
NelsonN
User
User
Posts: 12
Joined: Mon Dec 22, 2003 1:38 am
Location: Puerto Rico

Re: Updated Flexgrid

Post by NelsonN »

I am getting an error here:
LockColumnSize - is not a function, an array, or a linked list

I am all for a StringGrid, is this what this is? As in a Delphi type of StringGrid.

I use StringGrids a lot and only use those with the ability to include checkboxes in cells as well. I couldn't use PureBasic for a project because it lacked such a component, and I just don't have the time to write one.
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Re: Updated Flexgrid

Post by RJP Computing »

NelsonN wrote:I am getting an error here:
LockColumnSize - is not a function, an array, or a linked list
I got the same error.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

you need the "morelisticongadget" user library. that includes functions like lockcolumnsize. search the forum for morelisticongadget user library. ive tested the flexgrid with the user library update pack from the japbe homepage, which installs all the current available libs

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

MoreListIconGadget is one of my libs and you could find it on my page here (self-extracting file).


http://denislabarre.free.fr/index_en.html


some new command will be soon avalaible to set individual colors cells for a listicongadget. It seems to work correctly, i have to write the doc now. May be next week-end...
A+
Denis
boop64
User
User
Posts: 14
Joined: Tue Nov 18, 2003 12:42 pm
Contact:

works fine

Post by boop64 »

I comipled the code and recived the same error, but if you comment out the line:

LockColumnSize(a, #PB_LockAll )

:the code will still compile just fine. Nice code I like it.

Boop64
Post Reply