Powerpoint Listview Version 1.0

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 Version 1.0

Post by localmotion34 »

Code updated for 5.20+

here is the uncompiled source for the PPT listview ive been working on. it has about everything you need to really make this work. the procedures are defined but not documented. as of now, you only can use ONE PPT listview. when i compile this with tailbite, ill register the individual numbers of gadgets. try this out and please tell me what you think. it took me a long time to fool around with this, and hopefully in a week or so this will be a completely finished gadget ready to distribute.

Code: Select all

UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()

Global PPL ,rect.RECT,scrollareachildfirstchild,scrollareachildnextchild,scrollareachildlastchild,scrollareachild
Global globalwidth,Globalx,globaly,globalheight,imageclicked
Structure FindWindowData
  childwindowhandle ; variable to store a handle
EndStructure

Global NewList FindChild.FindWindowData()

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

Declare GetPPTstate(PPTlistview)
Global Dim PPTimages(500)

Declare SetPPTstate(PPTlistview,item,State)
rect.RECT
MoveMode=1
Procedure PPTcallback(WindowID,message,wParam,lParam)
  Shared PPL,Globalx,globaly,globalheight,globalwidth
  
  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
            clickedimage=FindChild()\childwindowhandle
            imageclicked=FindChild()\childwindowhandle
            SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_DLGMODALFRAME)
            RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
            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_CLIENTEDGE   )
                ;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=4
  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+ 6+ 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)
    If CreateImage(a,imagewidth, imageheight)
      StartDrawing(ImageOutput(a))
      Box(0,0,imagewidth, imageheight,110+40*a)
      StopDrawing()
      SetGadgetState(PPTimages(a),ImageID(a))
    EndIf
  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_CLIENTEDGE)
      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
        imageclicked=FindChild()\childwindowhandle
        makesure=100
        SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_DLGMODALFRAME)
        RedrawWindow_(GetParent_(FindChild()\childwindowhandle),0,0,3)
        ShowWindow_(FindChild()\childwindowhandle,#SW_SHOW)
      Else
        SetWindowLong_(FindChild()\childwindowhandle,#GWL_EXSTYLE,#WS_EX_CLIENTEDGE)
        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,optionalimage)
  numberimages=ListSize(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)
  CloseGadgetList()
  If numberimages>4
    scrollheight=(numberimages+1)*(imageheight+10)
    SetGadgetAttribute(PPTlistview,#PB_ScrollArea_InnerHeight,scrollheight)
  EndIf
  If optionalimage <> 0 Or optionalimage <>#Null
    numberimages=ListSize(FindChild())
    imagewidth=GadgetWidth(PPTimages(numberimages+1))
    imageheight=GadgetHeight(PPTimages(numberimages+1))
    ResizeImage(optionalimage,imagewidth,imageheight)
    SetGadgetState(PPTimages(numberimages+1), ImageID(optionalimage))
  EndIf
EndProcedure
 
Procedure CountPPTitems(PPTlistview)
  itemcount=ListSize(FindChild())
  ProcedureReturn itemcount
EndProcedure

Procedure DeletePPTitem(PPTlistview,item)
EndProcedure

Procedure SetPPTitemImage(PPTlistview,item,Image)
  numberimages=ListSize(FindChild())
  imagewidth=GadgetWidth(PPTimages(numberimages))
  imageheight=GadgetHeight(PPTimages(numberimages))
  ResizeImage(Image,imagewidth,imageheight)
  SetGadgetState(PPTimages(item),ImageID(Image))
EndProcedure

Procedure GetPPTitemImage(PPTlistview,item)
  If item=0
  Else
    imagewidth=GadgetWidth(PPTimages(item))
    imageheightF.f=imagewidth*(5/7)
    imageheightF$=StrF(imageheightF)
    Result$ = StringField(imageheightF$, 1,".")
    imageheight=Val(Result$)
    Width=imagewidth*3
    Height=imageheight*3
    imagehandle=SendMessage_(GadgetID(PPTimages(item)),#STM_GETIMAGE,#IMAGE_BITMAP,0)
    imagereturn=CreateImage(#PB_Any,Width,Height)
    If StartDrawing(ImageOutput(imagereturn))
      DrawImage(imagehandle,0,0,Width,Height)
      StopDrawing()
    EndIf
  EndIf
  ProcedureReturn imagereturn
EndProcedure
 
OpenWindow(0,0,0,600,600,"PPTlistview Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
PPL=PPtListview(10,10,190,500,4)
ButtonGadget(8,250,40,150,20,"Grab Selected Image")
ButtonGadget(7,250,70,150,20,"Add Image To First Item")
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")
ButtonGadget(6,250,220,150,20,"Count PPTlv Items")
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 EventGadget()
        Case 1
          State=GetPPTstate(PPL)
          MessageRequester("Info","The PPT Listview State is " + Str(State))
        Case 2
          SetPPTstate(PPL,0,0)
        Case 3
          SetPPTstate(PPL,2,1)
        Case 5
          AddPPTitem(PPL,0)
        Case 6
          number=CountPPTitems(PPL)
          MessageRequester("Info" ,"There are" + " " + Str(number) + " "+"Items In the PPT Listview")
        Case 7
          Filename$ = OpenFileRequester("Choose an Image", "", "All Images Formats|*.bmp;*.jpg;*.png;*.tif;*.tga", 0)
          If Filename$
            currentimage=LoadImage(#PB_Any,Filename$)
            SetPPTitemImage(PPL,1,currentimage)
          EndIf
        Case 8
          currentimage=GetPPTitemImage(PPL,GetPPTstate(PPL))
          If currentimage
            ResizeImage(currentimage,GadgetWidth(4)-4,GadgetHeight(4)-4)
            SetGadgetState(4,ImageID(currentimage))
          EndIf
      EndSelect
     
  EndSelect
 
ForEver
regards

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Seems to work OK apart from the following two things:

* There is a gap between the left side of the frame and the gadgets, but not between the gadgets and the scrollbar (right side). Purely an aesthetical thing, but looks odd.

* Debugger error on exit at line "scrollareachild=GetWindowLong_(..." in the PPTcallback() procedure - "#Gadget object not initialised". The callback might be getting called after the gadget is killed, best to remove it before closing the window / ending the program using a line such as "SetWindowCallback(0)".

* Remember that the callback you set using SetWindowCallback() is active for all windows
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply