Re: question about List text colors

new topic     » goto parent     » topic index » view thread      » older message » newer message

Derek,

I just remembered WHY I created that treeview.  I was working on an email
client, and wanted to use a listview(treeview) to display the contents of
the INBOX.  I tried faking a listview control, which turned out OK, but it
was just going to be too much work.  Here's the guts of the program,
perhaps you can modify it for your project:


------------------------------- BEGIN CODE --------------------------------
without warning
with trace

include win32lib.ew

constant WS_FIXEDFRAME = #4A0000
constant WS_PASSWORD = #20
constant MainWin = create(Window,"Fake Listview
Example",0,0,0,522,480,WS_FIXEDFRAME)
constant MainWinStatBar = create(StatusBar,"Ready",MainWin,0,0,0,0,#400000)
constant MainWinListView = create(Pixmap,"Test2",MainWin,0,0,500,374,0)
constant MainWinListViewVScroll = create(VScroll,"",MainWin,500,40,16,374,0)
--=======================================================================
sequence ListViewItem
ListViewItem =
{
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Message for you...","2k"},
  {"noicon","Brian Jackson","Re: Message for you...","5k"}
}
global constant Image   = 1,
                Sender  = 2,
                Subject = 3,
                Size    = 4

sequence ListViewContents
ListViewContents = { 1,      -- selected object(s)
                     30,     -- total objects(s)
                     1}      -- top index
global constant SelectedMembers   = 1,
                TotalMembers      = 2,
                TopVisibleMember  = 3
--========================================================================
procedure repaintListView()
  integer curY
  object  owork

  -- this draws the background
  setPenColor(MainWinListView,rgb(255,255,255))
  drawRectangle(MainWinListView,1,0,0,500,374)
  setPenColor(MainWinListView,rgb(192,192,192))
  drawRectangle(MainWinListView,1,1,0,500,16)
  setPenColor(MainWinListView,Black)
  drawLine(MainWinListView,0,0,0,374)
  drawLine(MainWinListView,1,16,500,16)
  setPosition(MainWinListView,6,2)
  wPuts(MainWinListView,"Flags")
  setPosition(MainWinListView,56,2)
  wPuts(MainWinListView,"Sender")
  setPosition(MainWinListView,256,2)
  wPuts(MainWinListView,"Subject")
  drawLine(MainWinListView,51,1,51,16)
  drawLine(MainWinListView,251,1,251,16)

  setPenColor(MainWinListView,rgb(255,255,255))
  drawLine(MainWinListView,1,1,50,1)
  drawLine(MainWinListView,1,1,1,16)
  drawLine(MainWinListView,52,1,250,1)
  drawLine(MainWinListView,52,1,52,16)
  drawLine(MainWinListView,252,1,500,1)
  drawLine(MainWinListView,252,1,252,16)

  -- now let's display each line one at a time
  if ListViewContents[TotalMembers] then
    curY = 18
    for i = ListViewContents[TopVisibleMember] to
        ListViewContents[TotalMembers] do

      -- display the sender
      setPosition(MainWinListView,56,curY)
      wPuts(MainWinListView,ListViewItem[i][Sender])

      -- display the subject
      setPosition(MainWinListView,256,curY)
      wPuts(MainWinListView,ListViewItem[i][Subject])

      -- move down a line, until we run out of room
      curY += 16
      if curY > 360 then
        -- stop before we go off the bottom of the listview
        exit
      end if

    end for
  end if

  owork = ListViewContents[SelectedMembers]
  if atom(owork) then
    if owork >= ListViewContents[TopVisibleMember] then
      -- draw a box around the selected one
      curY = (owork - ListViewContents[TopVisibleMember] + 1) * 16
      setPenColor(MainWinListView,rgb(0,0,127))
      drawRectangle(MainWinListView, 1, 0, curY, 500, curY + 16)
      setPenColor(MainWinListView,rgb(192,192,192))

      -- set text color to white
      setTextColor(MainWinListView, rgb(255,255,255))

      -- display the sender
      setPosition(MainWinListView,56,curY)
      wPuts(MainWinListView,ListViewItem[owork][Sender])

      -- display the subject
      setPosition(MainWinListView,256,curY)
      wPuts(MainWinListView,ListViewItem[owork][Subject])

      -- set text color to black
      setTextColor(MainWinListView, rgb(0,0,0))

    end if
  else
    for i = 1 to length(owork) do
      -- draw a box around the selected one
      curY = (owork[i] - ListViewContents[TopVisibleMember] + 1) * 16
      setPenColor(MainWinListView,rgb(0,0,127))
      drawRectangle(MainWinListView, 1, 0, curY, 500, curY + 16)
      setPenColor(MainWinListView,rgb(192,192,192))

      -- set text color to white
      setTextColor(MainWinListView, rgb(255,255,255))

      -- display the sender
      setPosition(MainWinListView,56,curY)
      wPuts(MainWinListView,ListViewItem[owork[i]][Sender])

      -- display the subject
      setPosition(MainWinListView,256,curY)
      wPuts(MainWinListView,ListViewItem[owork[i]][Subject])

      -- set text color to black
      setTextColor(MainWinListView, rgb(0,0,0))
    end for
  end if

  copyBlt(MainWin,0,40,MainWinListView)

end procedure
--=======================================================================
procedure onMouseListView(integer event, integer x, integer y, integer z)
  integer ok
  if event = LEFT_DOWN then
    -- set a new selected item
    y -= 40
    y = floor(y/16)
    y += ListViewContents[TopVisibleMember] - 1
    if y <= ListViewContents[TotalMembers] then
      if not z then
        -- no shift key here
        ListViewContents[SelectedMembers] = y
      else
      -- the shift key is pressed
        ListViewContents[SelectedMembers] &= y
      end if
    else
      ListViewContents[SelectedMembers] = 0
    end if

    repaintListView()
  elsif event = LEFT_DOUBLECLICK then
    ok = message_box("dshgdjas","kgfdkjgfd",MB_ICONINFORMATION + MB_OK)
  end if
end procedure
--=======================================================================
procedure onMouseMainWin(integer event,integer x, integer y, integer z)
  if  event = LEFT_DOUBLECLICK then
  trace(1)
  end if
  if x >= 0
  and x <= 500
  and y >= 40
  and y <= 414 then
    onMouseListView(event,x,y,z)
  end if
end procedure
onMouse[MainWin] = routine_id("onMouseMainWin")
--=========================================================================
procedure onPaintMainWin(integer x1, integer y1, integer x2, integer y2)
  repaintListView()
end procedure
onPaint[MainWin] = routine_id("onPaintMainWin")
--=========================================================================
procedure onScrollMainWinListViewVScroll(integer y)
  ListViewContents[TopVisibleMember] = y
  repaintListView()
end procedure
onScroll[MainWinListViewVScroll] =
      routine_id("onScrollMainWinListViewVScroll")
--=========================================================================
procedure onOpenMainWindow()
  setWindowBackColor(MainWin,rgb(192,192,192))

  setIcon(MainWin,"client.ico")

  -- let's set the state of the scrollbar too
  if ListViewContents[TotalMembers] > 22 then
    setEnable(MainWinListViewVScroll, 1)
    setScrollRange(MainWinListViewVScroll,1,
            ListViewContents[TotalMembers] - 22)
    setScrollChange(MainWinListViewVScroll, 1, 22)
    setScrollPos(MainWinListViewVScroll, ListViewContents[TopVisibleMember])
  else
    setEnable(MainWinListViewVScroll, 0)
  end if

end procedure
onOpen[MainWin] = routine_id("onOpenMainWindow")
--=======================================================================
WinMain(MainWin,Normal)
------------------------------ END CODE ------------------------------------

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu