powerpoint listview

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

powerpoint listview

Post by localmotion34 »

Code updated for 5.20+

here is an attempt at a powerpoint like listview that i have been working on. give it a try and see what you think. post any comments or suggestions you have about it.

Code: Select all

Global PPL ,rect.RECT,scrollareachildfirstchild,scrollareachildnextchild,scrollareachildlastchild,scrollareachild

Structure FindWindowData
  childwindowhandle.l ; variable to store a handle
EndStructure

Global NewList FindChild.FindWindowData()

Procedure.l EnumChildProc(hChild, lParam)
  AddElement(FindChild())
  FindChild()\childwindowhandle= hChild
  ProcedureReturn 1
EndProcedure

Global Dim PPTimages(100)
rect.RECT

Procedure PPTcallback(WindowID,message,wParam,lParam)
  If IsGadget(PPL)
    scrollareachild=GetWindow_(GadgetID(PPL),#GW_CHILD)   
    scrollareachildfirstchild=GetWindow_(scrollareachild,#GW_CHILD)
    scrollareachildnextchild=GetWindow_(scrollareachildfirstchild,#GW_HWNDNEXT)
    scrollareachildlastchild=GetWindow_(scrollareachildfirstchild,#GW_HWNDLAST)
    ClearList(FindChild())
    EnumChildWindows_(scrollareachild, @EnumChildProc(), 0)
    Result=#PB_ProcessPureBasicEvents
    Select message
      Case #WM_COMMAND
        ResetList(FindChild())
        ForEach FindChild()
          Index = ListIndex(FindChild())
          If lParam = FindChild()\childwindowhandle
            SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_DLGMODALFRAME)
            RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
            SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
            ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
            Debug "you pressed image" + " " + Str(Index+1)
            ForEach FindChild()
              If lParam <> FindChild()\childwindowhandle
                SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_WINDOWEDGE   )
                ;RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
                RedrawWindow_(FindChild()\childwindowhandle,0,0,3)
                RedrawWindow_(GetParent_(GetParent_(FindChild()\childwindowhandle)),0,0,3)
                ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
              EndIf
            Next
          EndIf
        Next
    EndSelect
  EndIf
  ProcedureReturn Result
EndProcedure

Procedure PPtListview(x,y,Width,Height,Imagenumber)
  imagex=5
  imagewidth=Width-30
  imageheightF.f=imagewidth*(5/7)
  imageheightF$=StrF(imageheightF)
  Result$ = StringField(imageheightF$, 1,".")
  imageheight=Val(Result$)
  imagey=0-imageheight
  If Imagenumber>4
    scrollheight=Imagenumber*(imageheight+10)
  Else
    scrollheight=600
  EndIf
  scrollarea=ScrollAreaGadget(#PB_Any, x,y,Width,Height, Width-20,scrollheight, 10)
  For a=1 To Imagenumber
    imagey=imagey+ 5+ imageheight
    PPTimages(a)=ImageGadget(#PB_Any,imagex,imagey, imagewidth, imageheight, Image0,#PB_Image_Border)
    PPT=GetWindowLong_(GadgetID(PPTimages(a)),#GWL_STYLE)
    SetWindowLong_(GadgetID(PPTimages(a)),#GWL_STYLE,PPT|#SS_NOTIFY)
  Next
  CloseGadgetList()
  SetWindowCallback(@PPTcallback())
  ProcedureReturn scrollarea
EndProcedure

Procedure GetPPTstate(PPTlistview)
  ResetList(FindChild())
  While NextElement(FindChild())
    Index = ListIndex(FindChild())
    If GetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE)=257
      ProcedureReturn Index+1
      Break
    Else
    EndIf
  Wend
EndProcedure

Procedure SetPPTstate(PPTlistview,item,State)
  If State =0
    ResetList(FindChild())
    While NextElement(FindChild())
      SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_WINDOWEDGE)
      RedrawWindow_(FindChild()\childwindowhandle,0,0,3)
      RedrawWindow_(GetParent_(GetParent_(FindChild()\childwindowhandle)),0,0,3)
      ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
    Wend
  ElseIf State=1
    ResetList(FindChild())
    While NextElement(FindChild())
      If ListIndex(FindChild())=item-1
        SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_DLGMODALFRAME)
        RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
        SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
        ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
      Else
        SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_WINDOWEDGE)
        RedrawWindow_(FindChild()\childwindowhandle,0,0,3)
        RedrawWindow_(GetParent_(GetParent_(FindChild()\childwindowhandle)),0,0,3)
        ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
      EndIf
    Wend
  EndIf
EndProcedure

OpenWindow(0,0,0,600,600,"PPTlistview Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
PPL=PPtListview(10,10,190,500,4)
ButtonGadget(1,250,100,150,20,"Get PPTLv State")
ButtonGadget(2,250,130,150,20,"Set PPTLv State To 0")
ButtonGadget(3,250,160,150,20,"Set PPTLv State To 2")

;-Event Loop   
Repeat
  Select WaitWindowEvent()
    Case  #PB_Event_CloseWindow
      End
    Case  #PB_Event_Gadget
      Select EventGadget()
        Case 1
          State=GetPPTstate(PPL)
          MessageRequester("","PPT Listview State =" +" " +Str(State))
        Case 2
          SetPPTstate(PPL,0,0)
        Case 3
          SetPPTstate(PPL,2,1)
      EndSelect
      
  EndSelect
  
ForEver 
regards,

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

added "addpptitem" to the list of commands. seems like when i use setgadgetstate with an image on one of the image items, the image drawn covers the 3D window border i use to show the selected item. oh well, someone got an idea about that or any suggestions/comments?

Code: Select all

#SS_NOTIFY=256
#SS_OWNERDRAW=$D
Global PPL ,rect.RECT,scrollareachildfirstchild,scrollareachildnextchild,scrollareachildlastchild,scrollareachild

Structure FindWindowData
  childwindowhandle.l ; variable to store a handle
EndStructure

NewList FindChild.FindWindowData()

Procedure.l EnumChildProc(hChild, lParam)
  AddElement(FindChild())
  FindChild()\childwindowhandle= hChild
  ProcedureReturn 1
EndProcedure

Dim PPTimages(100)
rect.RECT

Procedure PPTcallback(WindowID,message,wParam,lParam)
  scrollareachild=GetWindow_(GadgetID(PPL),#GW_CHILD)	
  scrollareachildfirstchild=GetWindow_(scrollareachild,#GW_CHILD)
  scrollareachildnextchild=GetWindow_(scrollareachildfirstchild,#GW_HWNDNEXT)
  scrollareachildlastchild=GetWindow_(scrollareachildfirstchild,#GW_HWNDLAST)
  ClearList(FindChild())
  EnumChildWindows_(scrollareachild, @EnumChildProc(), 0)
  Result=#PB_ProcessPureBasicEvents
  Select message
    Case #WM_COMMAND
      ResetList(FindChild())
      ForEach FindChild()
        Index = ListIndex(FindChild()) 
        If lParam = FindChild()\childwindowhandle
          SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_DLGMODALFRAME)
          RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
          SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE) 
          ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
          Debug "you pressed image" + " " + Str(Index+1)
          ForEach FindChild()
            If lParam <> FindChild()\childwindowhandle
              SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_WINDOWEDGE	)
              ;RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
              RedrawWindow_(FindChild()\childwindowhandle,0,0,3)
              RedrawWindow_(GetParent_(GetParent_(FindChild()\childwindowhandle)),0,0,3)
              ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
            EndIf 
          Next 
        EndIf 
      Next 
  EndSelect 
  ProcedureReturn Result 
EndProcedure 

Procedure PPtListview(x,y,Width,Height,Imagenumber)
  imagex=5
  imagewidth=Width-30
  imageheightF.f=imagewidth*(5/7)
  imageheightF$=StrF(imageheightF)
  Result$ = StringField(imageheightF$, 1,".")
  imageheight=Val(Result$)
  imagey=0-imageheight 
  If Imagenumber>4
    scrollheight=Imagenumber*(imageheight+10)
  Else 
    scrollheight=600
  EndIf 
  scrollarea=ScrollAreaGadget(#PB_Any, x,y,Width,Height, Width-20,scrollheight, 10)
  For a=1 To Imagenumber
    imagey=imagey+ 5+ imageheight
    PPTimages(a)=ImageGadget(#PB_Any,imagex,imagey, imagewidth, imageheight, Image0,#PB_Image_Border)
    PPT=GetWindowLong_(GadgetID(PPTimages(a)),#GWL_STYLE) 
    SetWindowLong_(GadgetID(PPTimages(a)),#GWL_STYLE,PPT|#SS_NOTIFY)
    ;SetWindowLong_(GadgetID(PPTimages(a)),#GWL_STYLE,PPT|#SS_NOTIFY|#WS_CHILD|#WS_VISIBLE|#SS_OWNERDRAW)
  Next 
  CloseGadgetList()
  SetWindowCallback(@PPTcallback())
  ProcedureReturn scrollarea
EndProcedure

Procedure GetPPTstate(PPTlistview)
  ResetList(FindChild())
  While NextElement(FindChild())
    Index = ListIndex(FindChild()) 
    If GetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE)=257
      ProcedureReturn Index+1
      Break 
    Else
    EndIf 
  Wend 
EndProcedure 

Procedure SetPPTstate(PPTlistview,item,State)
  If State =0
    ResetList(FindChild())
    While NextElement(FindChild())
      SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_WINDOWEDGE)
      RedrawWindow_(FindChild()\childwindowhandle,0,0,3)
      RedrawWindow_(GetParent_(GetParent_(FindChild()\childwindowhandle)),0,0,3)
      ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
    Wend 
  ElseIf State=1
    ResetList(FindChild())
    While NextElement(FindChild())
      If ListIndex(FindChild())=item-1
        SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_DLGMODALFRAME)
        RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
        SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE) 
        ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
      Else 
        SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_WINDOWEDGE)
        RedrawWindow_(FindChild()\childwindowhandle,0,0,3)
        RedrawWindow_(GetParent_(GetParent_(FindChild()\childwindowhandle)),0,0,3)
        ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
      EndIf 
    Wend 
  EndIf 
EndProcedure 
Procedure AddPPTitem(PPTlistview)
  numberimages=CountList(FindChild())
  AddElement(FindChild())
  imagex=5
  Width=GadgetWidth(PPTlistview)
  y=GadgetY(PPTimages(numberimages))
  imagewidth=Width-30
  imageheightF.f=imagewidth*(5/7)
  imageheightF$=StrF(imageheightF)
  Result$ = StringField(imageheightF$, 1,".")
  imageheight=Val(Result$)
  imagey=y+imageheight+5
  OpenGadgetList(PPTlistview)
  PPTimages(numberimages+1)=ImageGadget(#PB_Any,imagex,imagey, imagewidth, imageheight, Image0,#PB_Image_Border)
  PPT=GetWindowLong_(GadgetID(PPTimages(numberimages+1)),#GWL_STYLE) 
  SetWindowLong_(GadgetID(PPTimages(numberimages+1)),#GWL_STYLE,PPT|#SS_NOTIFY)
  ;SetWindowCallback(@PPTcallback())
  CloseGadgetList()
  If numberimages>4
    scrollheight=(numberimages+1)*(imageheight+10)
    SetGadgetAttribute(PPTlistview,#PB_ScrollArea_InnerHeight,scrollheight)
  EndIf 
EndProcedure 
  
OpenWindow(0,0,0,600,600,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"PPTlistview Test")
CreateGadgetList(WindowID(0)) 
PPL=PPtListview(10,10,190,500,4)
ButtonGadget(1,250,100,150,20,"Get PPTLv State")
ButtonGadget(2,250,130,150,20,"Set PPTLv State To 0")
ButtonGadget(3,250,160,150,20,"Set PPTLv State To 2")
ButtonGadget(5,250,190,150,20,"Add PPTlv Item")
ImageGadget(4,250,250,280,210,0,#PB_Image_Border)
  
 ;-Event Loop   
Repeat 
  Select WaitWindowEvent() 
    Case  #PB_Event_CloseWindow 
      End 
    Case  #PB_Event_Gadget 
      Select EventGadgetID()
        Case 1
          State=GetPPTstate(PPL)
          MessageRequester("","PPT Listview State =" +" " +Str(State))
        Case 2
          SetPPTstate(PPL,0,0)
        Case 3
          SetPPTstate(PPL,2,1)
        Case 5
          AddPPTitem(PPL)
      EndSelect
      
  EndSelect 
  
ForEver 
  
  

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Fred
Administrator
Administrator
Posts: 18253
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Cool Gadget :)
Post Reply