New Update v2.0 :ListIcon MultiLines edit and more(Windows)

Windows specific forum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

New Update v2.0 :ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

I am glad that Sparkie is still around
and I miss Kale and PB ,to be in a powerful enviroment is something

Code: Select all

Global Column_0_W,WinX,WinY,XX,YY,StdColor,AltColor,ColColor,ColColor_2,Item_Sp,Nolines,brush_1,brush_1_2,brush_4,brush_4_2,XP_BR_1,XP_BR_4
Global OldCallback,OldEditProc,hEdit,rct.RECT,r.RECT,rc.RECT,CellSelectOn,CurItem,CurSubItem,CurSelItem,CurSelSubItem,WState,Sortflag,Editflag,HCFlag
Global rfont,hfont,hfonth,rfonth,RFontS,HFontS,STCbcolor,STCfcolor,Oddbrush,Evenbrush,index,Coln,LI_size
Global header_h ,row_h,imageList
Global Dim AlignColumn(0),Dim MaskedColumn(0),Dim FixedColumn(0)

#CDDS_ITEMPREPAINT = #CDDS_ITEM|#CDDS_PREPAINT 
#CDDS_SUBITEMPREPAINT = #CDDS_SUBITEM|#CDDS_ITEMPREPAINT

Prototype.i SetTheme(Gadget.i, String_1.p-unicode,String_2.p-unicode) 

Procedure EndEdit() 
    If hEdit
      SetGadgetItemText(1, CurItem, GetGadgetText(2)+Chr(10), CurSubItem)
      If CurSubItem = 1
      SetGadgetItemText(4, CurItem, GetGadgetText(2)+Chr(10), 1)
      EndIf 
      FreeGadget(2) 
      hEdit = 0 
    EndIf  
EndProcedure


Procedure EditFocus(hwnd, *rc.RECT) 
    hDC = GetDC_(hwnd) 
    OldPen = SelectObject_(hDC, CreatePen_(#PS_INSIDEFRAME,1,$0000FF)) 
    OldBrush = SelectObject_(hDC, GetStockObject_(#NULL_BRUSH)) 
    Rectangle_(hDC, *rc\left, *rc\top, *rc\right, *rc\bottom) 
    SelectObject_(hDC, OldBrush) 
    SelectObject_(hDC, OldPen) 
    ReleaseDC_(hwnd, hDC) 
EndProcedure


;Return for new line
;Esc or 'LeftClick on any other field' to end edit
Procedure EditProc(hwnd, uMsg, wParam, lParam)
    result = CallWindowProc_(OldEditProc, hwnd, uMsg, wParam, lParam)
    Select uMsg 
      Case #WM_KEYDOWN ,#WM_MENUSELECT
          result = CallWindowProc_(OldEditProc, hwnd, uMsg, wParam, lParam)
           RedrawWindow_(hEdit, 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE)      
         If wParam=#VK_RETURN
            If SendMessage_(hwnd,#EM_GETLINECOUNT,0,0) = Int(Row_h/(RFontS+3))
               EndEdit() 
               ProcedureReturn 0
            EndIf
         ElseIf wParam=#VK_ESCAPE
             EndEdit()
         EndIf          
      EndSelect
    ProcedureReturn result 
EndProcedure


Procedure LIcallback(hwnd, msg, wparam, lparam)

If IsGadget(4)
   ShowScrollBar_(GadgetID(4),#SB_BOTH,0)
EndIf
  result = CallWindowProc_(oldCallback, hwnd, msg, wparam, lparam)
  
  Select msg
  
    Case #WM_NOTIFY
      SetActiveGadget(1)
      If HCFlag = 1
      *NMHDR.NMHDR = lparam
        If *NMHDR\code = #NM_CUSTOMDRAW
        *pnmcd.NMCUSTOMDRAW = lparam
            Select *pnmcd\dwDrawStage
              Case #CDDS_PREPAINT
                result = #CDRF_NOTIFYITEMDRAW
              Case #CDDS_ITEMPREPAINT
                text$=GetGadgetItemText(GetDlgCtrlID_(hWnd),-1,*pnmcd\dwItemSpec)
                If *pnmcd\uItemState & #CDIS_SELECTED
                  DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH|#DFCS_PUSHED)
                  InflateRect_(*pnmcd\rc,-1,-1)
                Else
                  DrawFrameControl_(*pnmcd\hdc, *pnmcd\rc, #DFC_BUTTON, #DFCS_BUTTONPUSH)
                EndIf
                *pnmcd\rc\bottom-1 : *pnmcd\rc\right-1
                SetBkMode_(*pnmcd\hdc,#TRANSPARENT)
                If *pnmcd\dwItemSpec&1
                  FillRect_(*pnmcd\hdc, *pnmcd\rc,Oddbrush)
                  SetTextColor_(*pnmcd\hdc, #Blue)
                Else
                  FillRect_(*pnmcd\hdc, *pnmcd\rc,Evenbrush)
                  SetTextColor_(*pnmcd\hdc, #Red)
                EndIf
                *pnmcd\rc\top+1
                InflateRect_(*pnmcd\rc,-5,0)
                If *pnmcd\rc\right>*pnmcd\rc\left
                  DrawText_(*pnmcd\hdc, @text$, Len(text$), *pnmcd\rc,AlignColumn(*pnmcd\dwItemSpec)|#DT_VCENTER|#DT_END_ELLIPSIS)
                EndIf
                result = #CDRF_SKIPDEFAULT
            EndSelect
        EndIf
      EndIf

    Case #WM_RBUTTONDOWN
          For i=1 To coln
          SendMessage_(GadgetID(1), #LVM_SETCOLUMNWIDTH, i,#LVSCW_AUTOSIZE)
          Next
          SendMessage_(GadgetID(1), #LVM_SETCOLUMNWIDTH, coln,#LVSCW_AUTOSIZE_USEHEADER)
          InvalidateRect_(GadgetID(1),0,1)
          InvalidateRect_(GadgetID(4),0,1)
          
          
    Case #WM_RBUTTONDBLCLK
          For i=1 To coln
          SendMessage_(GadgetID(1), #LVM_SETCOLUMNWIDTH, i,#LVSCW_AUTOSIZE_USEHEADER & #LVSCW_AUTOSIZE)
          Length1=SendMessage_(hwnd, #LVM_GETCOLUMNWIDTH, i, 0)
          StartDrawing(WindowOutput(0))
          DrawingFont(hfont)
          Length2 = TextWidth(GetGadgetItemText(1,-1,i))+2*hfonth
          StopDrawing()
          If Length2 > Length1
          SendMessage_(hwnd, #LVM_SETCOLUMNWIDTH, i,Length2)
          EndIf
          Next
          InvalidateRect_(GadgetID(1),0,1)
          InvalidateRect_(GadgetID(4),0,1)
             
  
    Case #WM_LBUTTONDBLCLK
        If Editflag <> 0 And GetDlgCtrlID_(hWnd) <> 4
           If hwnd<>hEdit 
            EndEdit() 
            pInfo.LVHITTESTINFO 
            pInfo\pt\x = lParam & $FFFF 
            pInfo\pt\y = lParam >> 16 & $FFFF 
            SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, pInfo) 
            rc.RECT 
            rc\top = pInfo\iSubItem 
            rc\left = #LVIR_BOUNDS 
            SendMessage_(hwnd, #LVM_GETSUBITEMRECT, pInfo\iItem, rc) 
            If hEdit=0
              UseGadgetList(hwnd) 
              CurItem = pInfo\iItem
              CurSubItem = pInfo\iSubItem
              If MaskedColumn(CurSubItem) = 0 And GetDlgCtrlID_(hWnd) <> 4
                Text$ = GetGadgetItemText(1, CurItem, CurSubItem)
                hEdit = StringGadget(2, rc\left, rc\top, rc\right-rc\left, rc\bottom-rc\top, Text$,#ES_MULTILINE|#PB_String_BorderLess) 
                SendMessage_(hEdit, #WM_SETFONT, rfont, #True)
                RedrawWindow_(GadgetID(1),#Null,#Null,#RDW_INVALIDATE|#RDW_UPDATENOW) 
                OldEditProc = SetWindowLongPtr_(hEdit, #GWL_WNDPROC, @EditProc()) 
                SetFocus_(hEdit)
              EndIf 
            EndIf 
           Else 
            result = CallWindowProc_(oldCallback, hwnd, uMsg, wParam, lParam)
           EndIf
        EndIf
     
    Case #WM_LBUTTONDOWN
    If GetDlgCtrlID_(hWnd) <> 4
           If hwnd<>hEdit And GetActiveGadget() = 1
            EndEdit()                      
            pInfo.LVHITTESTINFO 
            pInfo\pt\x = lParam & $FFFF
            pInfo\pt\y = lParam >> 16 & $FFFF 
            SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, pInfo) 
            rc.RECT 
            rc\top = pInfo\iSubItem 
            rc\left = #LVIR_BOUNDS
            SendMessage_(hwnd, #LVM_GETSUBITEMRECT, pInfo\iItem, rc)
            If CellSelectOn
              InvalidateRect_(hwnd, rct, #True) 
            EndIf 
            CellSelectOn = 1 
            CurSelItem = pInfo\iItem 
            CurSelSubItem = pInfo\iSubItem 
            If CurSelSubItem=0 
              rc\right = rc\left+SendMessage_(hwnd, #LVM_GETCOLUMNWIDTH, 0, 0) 
            EndIf
            If Editflag <> 0 Or GetDlgCtrlID_(hWnd) <> 4
              EditFocus(hwnd, rc)
              SetFocus_(hEdit)
            Else
              CellSelectOn = 0
            EndIf
            CopyMemory(rc, rct, SizeOf(RECT))
          Else       
            SetFocus_(hEdit)               
            result = CallWindowProc_(oldCallback, hwnd, uMsg, wParam, lParam)
          EndIf
   EndIf
            
       
    Case #WM_CTLCOLOREDIT 
          If GetFocus_()=lParam 
            SetBkMode_(wParam, #TRANSPARENT)
            SetTextColor_(wParam, $0000FF) 
            result = CreateSolidBrush_($FFFFFF) 
          Else 
            result = CallWindowProc_(oldCallback, hwnd, uMsg, wParam, lParam)
          EndIf
       
    Case #WM_VSCROLL,#WM_MOUSEWHEEL 
          Item_Sp = SendMessage_(GadgetID(1), #LVM_GETITEMSPACING, #True, 0) >> 16 
          SelItem = GetScrollPos_(GadgetID(1),#SB_VERT) - GetScrollPos_(GadgetID(4),#SB_VERT)  
          SendMessage_(GadgetID(4), #LVM_SCROLL, 0, SelItem * Item_Sp)          
          UpdateWindow_(GadgetID(4))
          rc.RECT 
          TopVisibleItem = SendMessage_(hwnd, #LVM_GETTOPINDEX, 0, 0) 
          If CellSelectOn 
            rc\top = CurSelSubItem
            rc\left = #LVIR_BOUNDS
            SendMessage_(hwnd, #LVM_GETSUBITEMRECT, CurSelItem, rc) 
            rct\top = rc\top 
            rct\bottom = rc\bottom
            If TopVisibleItem <= CurSelItem And hEdit = 0
              EditFocus(hwnd, rct) 
            EndIf 
          EndIf 
          If hEdit 
            If TopVisibleItem<=CurItem 
              ResizeGadget(2,#PB_Ignore, rc\top,#PB_Ignore,#PB_Ignore) 
              HideGadget(2, 0) 
              RedrawWindow_(hEdit, 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) 
            Else 
              HideGadget(2, 1) 
            EndIf 
            SetFocus_(hEdit)             
          EndIf

    
;        
    Case #WM_HSCROLL
          rc.RECT 
          TopVisibleItem = SendMessage_(hwnd, #LVM_GETTOPINDEX, 0, 0) 
          If CellSelectOn 
            rc\top = CurSelSubItem 
            rc\left = #LVIR_BOUNDS
            SendMessage_(hwnd, #LVM_GETSUBITEMRECT, CurSelItem, rc) 
            rct\left = rc\left 
            rct\right = rc\right 
            If TopVisibleItem<=CurSelItem 
              EditFocus(hwnd, rct) 
            EndIf 
          EndIf 
          If hEdit 
            If TopVisibleItem<=CurItem 
              ResizeGadget(2, rc\left,#PB_Ignore,#PB_Ignore,#PB_Ignore) 
              HideGadget(2, #False) 
              RedrawWindow_(hEdit, 0, 0, #RDW_INTERNALPAINT|#RDW_ERASE|#RDW_INVALIDATE) 
            Else 
              HideGadget(2, #True) 
            EndIf 
            SetFocus_(hEdit) 
          EndIf
                       

          
     Case #WM_KEYDOWN ,#WM_MENUSELECT
          If wParam=#VK_NEXT                       
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_PAGEDOWN,0)
          ElseIf wParam=#VK_PRIOR
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_PAGEUP,0)
          ElseIf wParam=#VK_UP
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_LINEUP,0)
          ElseIf wParam=#VK_DOWN
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_LINEDOWN,0)
          ElseIf wParam=#VK_HOME
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_TOP,0)
          ElseIf wParam=#VK_END
            SendMessage_(GadgetID(1),#WM_VSCROLL,#SB_BOTTOM,0)
          ElseIf wParam=#VK_LEFT
            SendMessage_(GadgetID(1),#WM_HSCROLL,#SB_LINELEFT,0)
          ElseIf wParam=#VK_RIGHT
            SendMessage_(GadgetID(1),#WM_HSCROLL,#SB_LINERIGHT,0)
          EndIf
  
   EndSelect
  ProcedureReturn result
EndProcedure

Procedure RAddColumn(LiID.l,Title$,Colw.l,Align.l,Editmask.l,Fixedmask.l)
    Coln = Coln + 1
    ReDim AlignColumn(Coln)
    ReDim MaskedColumn(Coln)
    ReDim FixedColumn(Coln)     
    AddGadgetColumn(LiID,Coln,Title$,Colw)
    liColumn.LV_COLUMN
    liColumn\mask = #LVCF_FMT
    Select align
        Case 0: liColumn\fmt = #LVCFMT_LEFT
        Case 1: liColumn\fmt = #LVCFMT_CENTER
        Case 2: liColumn\fmt = #LVCFMT_RIGHT
    EndSelect
    SendMessage_(GadgetID(LiID), #LVM_SETCOLUMN,coln, liColumn)
    AlignColumn(Coln) = Align.l
    MaskedColumn(Coln) = Editmask
    FixedColumn(Coln) = Fixedmask
EndProcedure


Procedure RAdd_0_Column(STCbcolor.l,STCfcolor.l,Align.l,Editmask.l,Fixedmask.l)    
    SendMessage_(WindowID(0),#LVM_GETITEMRECT,0,r.Rect)
    OpenWindow(2,r\left+10 ,r\top+10,Column_0_W,r\bottom-78,"FixedIconGadget Test",#WS_POPUP,WindowID(0))
    ListIconGadget(4,0,0,Column_0_W-2,r\bottom-80,"Column 1",0)
    SendMessage_(GadgetID(4),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)
    AddGadgetColumn(4,1,"Column 1",Column_0_W)
    oldCallback = SetWindowLongPtr_(GadgetID(4), #GWL_WNDPROC, @LIcallback())
    liColumn.LV_COLUMN
    liColumn\mask = #LVCF_FMT
    Select align
        Case 0: liColumn\fmt = #LVCFMT_LEFT
        Case 1: liColumn\fmt = #LVCFMT_CENTER
        Case 2: liColumn\fmt = #LVCFMT_RIGHT
    EndSelect
    SendMessage_(GadgetID(4), #LVM_SETCOLUMN,0,liColumn)
    AlignColumn(0) = Align
    MaskedColumn(0) = Editmask
    FixedColumn(0) = Fixedmask
    SetGadgetColor(4,#PB_Gadget_BackColor,STCbcolor)
    SetGadgetColor(4,#PB_Gadget_FrontColor,STCfcolor)
    SendMessage_(GadgetID(4), #LVM_SETIMAGELIST, #LVSIL_SMALL, imageList)
EndProcedure


Procedure SortingUpd(ListIconGadget,columns)      
    ItemCount = SendMessage_(ListIconGadget, #LVM_GETITEMCOUNT, 0, 0)
    lvi.LV_ITEM
    lvi\mask = #LVIF_PARAM
    lvi\iItem = 0
    While ItemCount>0
      lvi\lParam = lvi\iItem
      For SubItem = 0 To columns-1
        lvi\iSubItem = SubItem
        SendMessage_(ListIconGadget, #LVM_SETITEM, 0, @lvi)
      Next SubItem
      lvi\iItem +1
      ItemCount -1
    Wend      
EndProcedure


Procedure ListIconSortFunction(lParam1,lParam2,lParamSort)
      A$ = Space(200)
      B$ = Space(200)
      result = 0
      lvi.LV_ITEM
      lvi\iSubItem = lParamSort&$FFFF
      lvi\pszText = @A$
      lvi\cchTextMax = 200
      lvi\mask = #LVIF_TEXT
      SendMessage_(GadgetID(1), #LVM_GETITEMTEXT,lParam1,@lvi)
      lvi\pszText = @B$
      SendMessage_(GadgetID(1), #LVM_GETITEMTEXT,lParam2,@lvi)
    
      If A$ = B$
        ProcedureReturn 0 ; equal
      EndIf
    
      x = (lParamSort>>16)&$FFFF
      If x
        If A$ > B$
          ProcedureReturn  1
        Else
          ProcedureReturn -1
        EndIf
      Else
        If A$ > B$
          ProcedureReturn -1
        Else
          ProcedureReturn  1
        EndIf
      EndIf
      ProcedureReturn result
EndProcedure  


Procedure RHR_F_St_Sz( hfontn$,hh.l,hfflag.l,rfontn$,rh.l,rfflag.l)      
      hfonth = hh
      rfonth = rh
      rfont = LoadFont(0, rfontn$, rfonth,rfflag)
      SendMessage_(GadgetID(1), #WM_SETFONT, rfont, 1)
      SendMessage_(GadgetID(4), #WM_SETFONT, rfont, 1)
      If hfonth <> 0      
        Header_1 = SendMessage_(GadgetID(1), #LVM_GETHEADER, 0, 0)
        Header_4 = SendMessage_(GadgetID(4), #LVM_GETHEADER, 0, 0)
        SetWindowTheme_(Header_1, @null.w, @null.w)
        SetWindowTheme_(Header_4, @null.w, @null.w) 
        hfont = LoadFont(1, hfontn$, hfonth,hfflag)
        SendMessage_(Header_1, #WM_SETFONT, hfont, 1)
        SendMessage_(Header_4, #WM_SETFONT, hfont, 1)
          If OpenLibrary(0, "UxTheme.dll")
              swt.SetTheme = GetFunction(0, "SetWindowTheme")
              swt(Header_1,"", "HEADER")
              swt(Header_3,"", "HEADER")
              swt(Header_4,"", "HEADER")
          EndIf
       Else      
        SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE)|#LVS_NOCOLUMNHEADER)
        SetWindowLongPtr_(GadgetID(4), #GWL_STYLE, GetWindowLongPtr_(GadgetID(4), #GWL_STYLE)|#LVS_NOCOLUMNHEADER)        
      EndIf   
EndProcedure


Procedure WndProc(hwnd, uMsg, wParam, lParam)
      If GetActiveGadget() = 4
        SetActiveGadget(1)
      EndIf
      If IsWindow(0)
      WinX = WindowWidth(0)
      WinY = WindowHeight(0)
      GetWindowRect_(WindowID(0), wr.RECT)
      EndIf
      If IsGadget(1)
       GetWindowRect_(GadgetID(1), gr.RECT)
      EndIf
      XX = gr\left - wr\left - 2
      YY = gr\top - wr\top - 2
      result = #PB_ProcessPureBasicEvents 

Select uMsg
   
   Case #WM_NOTIFY,#WM_SETREDRAW
    *NMHDR.NMHDR = lParam
       ; Sort by Column       
       If *NMHDR\hWndFrom = GetDlgItem_(hwnd,wParam) And Sortflag = 1
        If *NMHDR\code = #LVN_COLUMNCLICK
          *NMLV.NMLISTVIEW = lParam
          column = *NMLV\iSubItem
          index = index!1
          SendMessage_(GadgetID(1),#LVM_SORTITEMS,column|((index)<<16),@ListIconSortFunction())
          For i=0 To LI_size
          SetGadgetItemText(4,i,GetGadgetItemText(1,i ,1),1)
          Next
          SortingUpd(GadgetID(1),coln) 
        EndIf                 ;  
       EndIf      
      ; Fixed Column Width
       If *NMHDR\hWndFrom = GetWindow_(GadgetID(1),#GW_CHILD) And *NMHDR\code = #HDN_FIRST
          *phdn.NMHEADER = lParam
             Li_c0 = SendMessage_(GadgetID(1), #LVM_GETCOLUMNWIDTH, 1,0)                       
              If *phdn\Iitem = 0 Or FixedColumn(*phdn\Iitem) = 1 Or Li_c0 > WinX - 40
                    ProcedureReturn 1
              Else
                  Column_0_W = SendMessage_(GadgetID(1),#LVM_GETCOLUMNWIDTH,1,0) + 4          
              EndIf
       EndIf
       If IsGadget(4) And *NMHDR\hWndFrom = GetWindow_(GadgetID(4),#GW_CHILD) And *NMHDR\code = #HDN_FIRST
          *phdn.NMHEADER = lParam                  
              If *phdn\Iitem = 0
                    ProcedureReturn 1              
              EndIf   
       EndIf
       
       
    Select *NMHDR\code 
      Case #NM_CUSTOMDRAW 
        *LVCDHeader.NMLVCUSTOMDRAW = lParam
          Select *LVCDHeader\nmcd\dwDrawStage    ;               
            Case #CDDS_PREPAINT
               result = #CDRF_NOTIFYITEMDRAW 
            Case #CDDS_ITEMPREPAINT
               result = #CDRF_NOTIFYSUBITEMDRAW            
            Case #CDDS_SUBITEMPREPAINT 
                Row = *LVCDHeader\nmcd\dwItemSpec 
                Col = *LVCDHeader\iSubItem
                If OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
                    subItemRect1.RECT\left = #LVIR_LABEL 
                    subItemRect1.RECT\top = *LVCDHeader\iSubItem
                    subItemRect4.RECT\left = #LVIR_LABEL 
                    subItemRect4.RECT\top = *LVCDHeader\iSubItem                
                    SendMessage_(GadgetID(1), #LVM_GETSUBITEMRECT, Row, @subItemRect1)
                    SendMessage_(GadgetID(4), #LVM_GETSUBITEMRECT, Row, @subItemRect4)
                    subItemText1$ = GetGadgetItemText(1, Row, Col)
                    If IsWindowVisible_(WindowID(2))
                        If Col = 1
                           subItemText1$ = ""
                        EndIf
                        subItemText4$ = GetGadgetItemText(1, Row, 1)
                    EndIf
                    If Row&1=1                      
                      If GetDlgItem_(hwnd,wParam) = GadgetID(1)
                         FillRect_(*LVCDHeader\nmcd\hdc, subItemRect1,XP_BR_1)
                      ElseIf GetDlgItem_(hwnd,wParam) = GadgetID(4)
                         FillRect_(*LVCDHeader\nmcd\hdc, subItemRect4,XP_BR_4)                         
                      EndIf
                    EndIf
                    If Right(GetGadgetItemText(1,Row,Col), 1)=Chr(10)
                        SetTextColor_(*LVCDHeader\nmcd\hdc , $0000FF)
                    Else
                        SetTextColor_(*LVCDHeader\nmcd\hdc , $000000)
                    EndIf                     
                    subItemRect1\left + 4
                    subItemRect1\top + 4  
                    subItemRect1\right - 4
                    subItemRect1\bottom - 4                                        
                    subItemRect4\left + 4
                    subItemRect4\top + 4  
                    subItemRect4\right - 4
                    subItemRect4\bottom - 4
                    DrawText_(*LVCDHeader\nmcd\hdc, subItemText1$, Len(subItemText1$), subItemRect1,AlignColumn(Col)|#DT_END_ELLIPSIS | #DT_WORDBREAK)                                       
                    DrawText_(*LVCDHeader\nmcd\hdc, subItemText4$, Len(subItemText4$), subItemRect4,AlignColumn(Col)|#DT_END_ELLIPSIS | #DT_WORDBREAK) 
                    result = #CDRF_SKIPDEFAULT
                Else
                    If Col=0 
                      SelectObject_(*LVCDHeader\nmcd\hDC, rfont) 
                    Else 
                      SelectObject_(*LVCDHeader\nmcd\hDC, rfont) 
                    EndIf
    
                    ; Odd Row Color
                    If Row&1=1
                     If  GetDlgItem_(hwnd,wParam) = GadgetID(1)
                        *LVCDHeader\clrTextBk = ColColor
                     ElseIf GetDlgItem_(hwnd,wParam) = GadgetID(4)
                        *LVCDHeader\clrTextBk = ColColor_2
                     EndIf
                    EndIf                
                    If  Right(GetGadgetItemText(1,Row,Col), 1)=Chr(10)
                        *LVCDHeader\clrText = $0000FF
                    Else
                        *LVCDHeader\clrText = $000000
                    EndIf
                    result = #CDRF_NEWFONT
               EndIf                   
          EndSelect
    EndSelect
    
    
      *nmHEADER.HD_NOTIFY = lParam
      Gadget_ID = *nmHEADER\hdr\hwndFrom  
      Select *nmHEADER\hdr\code 
        Case #HDN_ITEMCHANGING                          
                SendMessage_(GadgetID(1),#LVM_GETITEMRECT,0,r.Rect)                                                                              
                If (r\right - r\left + 40) > WinX
                   MoveWindow_(WindowID(2),WindowX(0)+XX ,WindowY(0)+YY,Column_0_W,WinY-76,1)
                Else
                   MoveWindow_(WindowID(2),WindowX(0)+XX ,WindowY(0)+YY,Column_0_W,WinY-56,1)
                EndIf
                If CellSelectOn = 1
                    FreeGadget(2) 
                    hEdit = 0 
                    InvalidateRect_(GadgetID(1),0,#True)
                    CellSelectOn = 0
                EndIf
                  
             
                
        Case #HDN_ENDTRACK,#LVN_ENDSCROLL
              If OSVersion() = #PB_OS_Windows_XP Or OSVersion() = #PB_OS_Windows_Server_2003
                 InvalidateRect_(GadgetID(1),0,1)
                 InvalidateRect_(GadgetID(4),0,1)
                 SetFocus_(hEdit)
               EndIf 

                 
                
        Case #HDN_DIVIDERDBLCLICK
                *phdn.NMHEADER = lParam
                If *phdn\iItem = 1
                    SendMessage_(GadgetID(1), #LVM_SETCOLUMNWIDTH, 1,#LVSCW_AUTOSIZE)
                EndIf
                
  EndSelect  
             
    
      Case #WM_GETMINMAXINFO                                       ;Min resizing for windows        
        *pMinMax.MINMAXINFO = lParam
        If Column_0_W+60 > 580
            *pMinMax\ptMinTrackSize\x=Column_0_W+60
        Else
            *pMinMax\ptMinTrackSize\x=580
        EndIf
            *pMinMax\ptMinTrackSize\y=350
      
      
      Case #WM_SIZE,#WM_MOVE,#WM_PAINT
        MoveWindow_(GadgetID(1),10,10,WinX-20,WinY-60,1)           
        SendMessage_(GadgetID(1),#LVM_GETITEMRECT,0,r.Rect)
        If (r\right - r\left + 40) > WinX
        MoveWindow_(WindowID(2),WindowX(0)+XX ,WindowY(0)+YY,Column_0_W,WinY-76,1) 
        Else
        MoveWindow_(WindowID(2),WindowX(0)+XX ,WindowY(0)+YY,Column_0_W,WinY-56,1)
        EndIf
        MoveWindow_(GadgetID(4),2,2,Column_0_W-3,WinY-60,1)
        SendMessage_(GadgetID(4), #LVM_SETCOLUMNWIDTH, 1,Column_0_W +1)
        MoveWindow_(GadgetID(5),10,WinY-35,100,25,1)
        MoveWindow_(GadgetID(6),120,WinY-35,100,25,1)
        MoveWindow_(GadgetID(8),340,WinY-35,100,25,1)
        MoveWindow_(GadgetID(9),450,WinY-35,100,25,1)    
   EndSelect   
  ProcedureReturn result 
EndProcedure


new:
  index = 1  
  WinX = 1024
  WinY = 768
  LI_size = 1000
  Column_0_W = 210                                                                      ;Default Column Width  
  StdColor = $E6FFFF                                                                    ;Default Row Color
  AltColor = $BAEEE8                                                                    ;Alternate Row Color
  Oddbrush=CreateSolidBrush_($00FFFF)                                                   ;Odd Header Style Back Color
  Evenbrush=CreateSolidBrush_($00FFFF)                                                  ;Even Header Style Back Color                                                                   
  ;HSOcolor = $FF0000                                                                   ;Header Style Text Odd Color
  ;HSEcolor = $0000FF                                                                   ;Header Style Text Even Color 
  HFontS=32                                                                             ;New Header Font Size
  RFontS=10                                                                             ;New Item Font Size
  Nolines =3                                                                            ;No. of lines per Row                                                                            
  Sortflag =1                                                                           ;Sorting Flag (1 = Sort , 0 = No Sort)   
  coln = 0
   
If OSVersion() < 60
    MessageRequester("Error","For XP and Newer Versions Only",#MB_ICONWARNING)
    End
EndIf

brush_1 = CreateSolidBrush_($E6FFFF)
brush_1_2 = CreateSolidBrush_($BAEEE8)

brush_4 = CreateSolidBrush_($E6FEE1)
brush_4_2 = CreateSolidBrush_($B9FCAB)

XP_BR_1 = brush_1
XP_BR_4 = brush_4

OpenWindow(0,0,0,WinX,WinY,"RASHAD ListView Pro",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
If WState = #PB_Window_Maximize
SetWindowState(0,#PB_Window_Maximize) 
EndIf

ListIconGadget(1,10,10,WinX-20,WinY-60,"Column 0",0)
SendMessage_(GadgetID(1),#LVM_SETEXTENDEDLISTVIEWSTYLE,#LVS_EX_GRIDLINES,#LVS_EX_GRIDLINES)
;Row Height for 3 Lines
row_h = 2* Nolines * RFontS
imageList = ImageList_Create_(1,row_h, #ILC_COLOR32, 0, 30)                           ; Row height
SendMessage_(GadgetID(1), #LVM_SETIMAGELIST, #LVSIL_SMALL, imageList)

SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE) | #WS_CLIPSIBLINGS)
SetWindowPos_(GadgetID(1), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)

HideGadget(1,1)
SetGadgetColor(1,#PB_Gadget_BackColor,StdColor)

ButtonGadget(5,10,WinY - 35,100,25,"Fr/Unfreeze C0" ,#PB_Button_Toggle)
ButtonGadget(6,120,WinY - 35,100,25,"En/Disable Edit" ,#PB_Button_Toggle)
;ButtonGadget(7,230,WinY - 35,100,25,"Font and Size" ,#PB_Button_Toggle)
ButtonGadget(8,340,WinY - 35,100,25,"Header Style" ,#PB_Button_Toggle)
ButtonGadget(9,450,WinY - 35,100,25,"Rows Color" ,#PB_Button_Toggle)

;RAddColumn(ListIconID, Title$, Column_Width, Column_Alignment(0=Left 1=Center 2=Right), Column_Edit_Mask(1=Masked 0=Non Masked), Column_Width_Fixed(1=Masked 0=Non Masked)
;RAdd_0_Column(Column_0 Backcolor,Column_0 Frontcolor,Align.l,Editmask.l,Fixedmask.l)
;Align.l : 0 = Left aligned 1 = Center aligned 2 = Right aligned
;Editmask.l : 1 = noedit / 0 = editable
;Fixedmask.l : 1 = Fixed width / 0 = Resizeable
;********************************************
RAddColumn(1,"Column 1",Column_0_W-4,0,0,0)                       ;Note 1: The last 3 parameter must be the same as RAdd_0_Column
;********************************************
RAddColumn(1,"Column 2",200,1,0,1)
RAddColumn(1,"Column 3",200,0,0,0)
RAddColumn(1,"Column 4",200,0,1,1)
RAddColumn(1,"Column 5",200,0,0,0)
RAddColumn(1,"Column 6",200,2,1,0)
RAddColumn(1,"Column 7",200,2,0,1)


;To edit Column 0 : 1- Make Editmask = 1 2- Unfreeze C0 3- Edit the subitems 4- Freeze it again
STCbcolor = $E6FEE1
STCfcolor = $000000
;*****************************************
RAdd_0_Column(STCbcolor,STCfcolor,0,0,0)                          ;Note 1:The last 3 parameter must be the same as RAddColumn 1
;*****************************************

;Remember to add the data of column 0 of Gadget(1) to column 0 of Gadget(4)
For i=0 To LI_size
  ;First
  AddGadgetItem(1, -1,""+Chr(10)+ "Line "+Str(i)+" column number zero"+Chr(10)+"Line "+Str(i)+" col 1"+Chr(10)+"Line "+Str(i)+" col 2"+Chr(10)+"Line "+Str(i)+" col 3"+Chr(10)+"Line "+Str(i)+" col 4"+Chr(10)+"Line "+Str(i)+" col 5"+Chr(10)+"Line "+Str(i)+" col 6")
  ;Second
  AddGadgetItem(4, -1,""+Chr(10)+"Line "+Str(i)+" column number zero")
Next

SortingUpd(GadgetID(1),Coln)                                                         ;For Sorting 

;RHR_F_St_St(Header_Font_name ,Header_Font_Height ,Header_Font_Style ,Row_Font_name ,Row_Font_Height ,Row_Font_Style)
;Header_Font_Height : HFontS = 0 No Header
;Header_Font_Style / Row_Font_Style : Bold = 256 ,Default = 0 ,Heigh Quality = 16 ,Italic = 512 ,StrikeOut = 8 ,Underline = 4

RHR_F_St_Sz("Tahoma",HFontS,16,"Microsoft Sans Serif",RFontS,0)

HideGadget(1,0)
oldCallback = SetWindowLongPtr_(GadgetID(1), #GWL_WNDPROC, @LIcallback())

SetWindowCallback(@WndProc())

ColColor = StdColor
ColColor_2 = $E6FEE1
HideWindow(2,1)
SetActiveGadget(1)

Repeat ; Start of the event loop

  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows

  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures

  GadgetID = EventGadget() ; Is it a gadget event?

  EventType = EventType() ; The event type


Select Event

  Case #PB_Event_Gadget
  
    Select EventGadget()
      
      Case 5
            If GetGadgetState(5) = 1            
            HideWindow(2,0)            
            Else            
            HideWindow(2,1)            
            EndIf
      
      Case 6
            Editflag = Editflag!1
            For i = 0 To LI_size
            SetGadgetItemText(4,i,GetGadgetItemText(1,i,0),0)
            Next
      
      
      Case 8
            HCFlag = HCFlag!1
            InvalidateRect_(WindowID(0),0,#True)
        
      Case 9
          If GetGadgetState(9) = 1
            ColColor = AltColor
            ColColor_2 = $B9FCAB
            XP_BR_1 = brush_1_2
            XP_BR_4 = brush_4_2 
          Else
            ColColor = StdColor
            ColColor_2 = $E6FEE1
            XP_BR_1 = brush_1
            XP_BR_4 = brush_4
          EndIf
            InvalidateRect_(GadgetID(1),0,1) 
            InvalidateRect_(GadgetID(4),0,1)

   EndSelect
   If Editflag = 0
      SetActiveGadget(1)
   EndIf
EndSelect 

Until event = #PB_Event_CloseWindow

XP and Win 7 tested
Edit :Update
Update : 2 Improvement
Last edited by RASHAD on Mon May 03, 2010 6:16 am, edited 10 times in total.
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ListIcon MultiLines edit and more(Windows)

Post by srod »

Right, I can only find a couple of bugs this time! Nearly there! :wink:

Run the program and freeze column 0. Click a cell in column zero and then a cell in another column. Repeat this (click a cell in column 0 and then another cell in any other column, a different cell than previous). On my system (Vista x86) the red highlighting box is not removed and I end up with multiple cells being highlighted.
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

First Post just updated
1- Fix many bugs
2- Added row color effects to XP

Now XP the same as Win Vista or Win 7
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ListIcon MultiLines edit and more(Windows)

Post by srod »

Aye, that's fixed the last one. :)

New bug... :wink:

Run the program, resize column 0 so it is larger and then freeze it. Now double click the column-0 header divider to resize it and column 1 partly disappears.
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

Bugs fixed

@srod
You are the creator of EsGrid and ExGrid so if you mention any new bug you will be obliged to
give me a free copy of your ExGrid ,ExGrid not Es one
Egypt my love
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ListIcon MultiLines edit and more(Windows)

Post by Demivec »

RASHAD: Very good.

A few bugs.
  • * The even columns are not resizable.

    * If an odd column is made too narrow, it overwrites what is in the cell without replacing it.

    * If 'Row Color' is selected and the scrollbar moved vertically the colored bars move also (correct) but if keyboard or arrows on scrollbar are used to scroll vertically the colors do not scroll.

    * If Column 0 is Frozen and MouseWheel is used to scroll vertically, Column 0 does not scroll but the other columns do. If the MouseWheel has been moved at all before Freezing Column 0, the content of some cell's in Column 0 will not be visible (the amount visible depends on a cyclic movement of the MouseWheel between the times Freezing was set/unset).

Using Win XP SP3 x86.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ListIcon MultiLines edit and more(Windows)

Post by srod »

RASHAD wrote:Bugs fixed

@srod
You are the creator of EsGrid and ExGrid so if you mention any new bug you will be obliged to
give me a free copy of your ExGrid ,ExGrid not Es one
You are welcome to ExGRID. Course, ExGRID will not compile without EsGRID and so it won't do you much good! :wink:
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

@Demivec Hi
Before anything give me a name for any software you made to ask you for a free copy
The even columns are not resizable this is a built in you can change it by changing the column
fixed width mask
for the others I will look at them deeply but not now I will go to sleep untill you think about my proposal

and your making it very complicated (I did not made it yet good for keys and you are talking about mouse wheel)
Demivec have mercey will you?
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

@srod
I was sure that you will escape by some trick of yours
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ListIcon MultiLines edit and more(Windows)

Post by srod »

RASHAD wrote:@Demivec Hi
Before anything give me a name for any software you made to ask you for a free copy
The even columns are not resizable this is a built in you can change it by changing the column
fixed width mask
for the others I will look at them deeply but not now I will go to sleep untill you think about my proposal

and your making it very complicated (I did not made it yet good for keys and you are talking about mouse wheel)
Demivec have mercey will you?
Rashad, people post bug reports simply to help out. They are doing you a favour as much as you are by providing the code for free etc.

Personally, and no offence intended, I would not have posted such a complex piece of code as this within the tips and tricks section whilst it is incomplete and, well, with a few too many bugs. I'd probably have posted in the General Discussion board and invited some testers etc. Only when it looked like all the obvious bugs had been fixed would I post in the tips and tricks etc.

By posting here and then being 'bombarded' with bug reports, you are not going to get many people using your otherwise excellent utility.

Just my opinion.

@srod
I was sure that you will escape by some trick of yours
If its free code you want then I give you COMatePLUS, Nexus, comDoc, ADOmate, coffIT, EasyVENT, GoScintilla... I think you get the message! :wink:
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

@srod
I am not upset you got me wrong (The english language is not even my second language) just kidding with you so please continue your bug reports
The tip is the listicon multi-line all the other featurs to demonstrate the action
About your free software I got it allready do not worry
Boys I am not upset how can I explain that ?
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

@Demivec
Updated first post
Check please
and I will not ask you for any free soft
Egypt my love
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ListIcon MultiLines edit and more(Windows)

Post by Demivec »

RASHAD wrote:@Demivec
Updated first post
Check please
and I will not ask you for any free soft
@RASHAD: Great work, you must have gotten a little rest. :)

I still notice one bug where the text in the cell overwrites itself when the column is resized skinnier so that the text wraps. It seems to need a repaint so perhaps invalidating the area in the resized column may work to fix it.


You can ask me for all the free software you like, unfortunately I have none to offer. I did understand the humor present in your previous request. :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon MultiLines edit and more(Windows)

Post by RASHAD »

Rest for One hour only or may be more
Please continue your reports
It is not intended to be a utility but a collection of ListIcon features

And thank you for everything
Egypt my love
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: ListIcon MultiLines edit and more(Windows)

Post by Rings »

moved into general.
Rashad: If its ready, repost it in tips&tricks :)
SPAMINATOR NR.1
Post Reply