[futurebasic] Re: [FB] Trouble using DataBrowser For Dummies with FBtoC

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Joe Lertola <joefb@...>
Date: Thu, 10 Jan 2008 23:45:10 -0500
Thanks Bernie and Robert for your help with this. I did not know about  
DBData.incl until today. I have been playing around with it and I  
think I have almost all the pieces I need to replace my DataBrowser  
for Dummies  browsers with new ones. I can detect clicks and double  
clicks on the browser as shown in the demo below.

One thing I do not know how to do is to replace the content of the  
browser with new items. I tried just calling the browser  
initialization function again with new content. This seems to work  
except if the new content is shorter than the previous content old  
items are retained at the bottom of the list. You can see this happen  
in the demo when you click the Reset Data Browser button. With  
DataBrowser for Dummies there is a function called fn  
DeleteAllItemsInBrowser which I use to erase the old items before I  
add new content. So far I have not been able to figure out how to  
accomplish this with DBData.incl. Any help would be appreciated.

Thanks,
-Joe Lertola


include "DBData.incl"

begin globals
dim as ControlRef @gBrowser
end globals

begin enum 1
_Untitled1Wnd
end enum

begin enum 1
_cMyEdit
_cResetDataBrowserBtn
end enum

// cBrowser propertyIDs
_cBrowserC001 = _"C001"

local fn SetHeaderButtonDesc( title as Str255, titleOffset as long, ¬
contentType as long, initialOrder as long, minWidth as long, ¬
maxWidth as long, columnDesc as ^DatabrowserListViewColumnDesc )
'~'1
columnDesc.headerBtnDesc.version = _kDataBrowserListViewLatestHeaderDesc
columnDesc.headerBtnDesc.btnContentInfo.contentType = contentType
columnDesc.headerBtnDesc.titleString = fn CFSTR( title )
columnDesc.headerBtnDesc.titleOffset = titleOffset
columnDesc.headerBtnDesc.initialOrder = initialOrder
columnDesc.headerBtnDesc.minimumWidth = minWidth
columnDesc.headerBtnDesc.maximumWidth = maxWidth
end fn
'~'5

local fn SetPropertyDesc( propertyID as DataBrowserPropertyID, ¬
propertyType as DataBrowserPropertyType, ¬
propertyFlags as DataBrowserPropertyFlags, ¬
columnDesc as ^DatabrowserListViewColumnDesc )
'~'1
columnDesc.propertyDesc.propertyID = propertyID
columnDesc.propertyDesc.propertyType = propertyType
columnDesc.propertyDesc.propertyFlags = propertyFlags
end fn
'~'5

local fn AddColumns_cBrowser( browser as ControlRef )
'~'1
dim as DatabrowserListViewColumnDesc columnDesc
dim as OSStatus ignore
dim as OSErr err

// C001
BlockZero( @columnDesc, sizeof(columnDesc) )
columnDesc.headerBtnDesc.version = _kDataBrowserListViewLatestHeaderDesc
fn SetHeaderButtonDesc( "My browser", 0, _kControlContentTextOnly, ¬
_kDataBrowserOrderIncreasing, 30, 500, @columnDesc )
fn SetPropertyDesc( _cBrowserC001, _kDataBrowserTextType,¬
0¬
  , @columnDesc )
fn DBDataSetPropertyType( browser, _cBrowserC001, ¬
_kDataBrowserTextType )
call AddDataBrowserListViewColumn( browser, columnDesc, ¬
_kDataBrowserListViewAppendColumn )
ignore = fn SetDataBrowserTableViewNamedColumnWidth¬
( browser, _cBrowserC001, 250 )

end fn
'~'5

local fn CreateDataBrowser_cBrowser as ControlRef
'~'1
dim as Rect @ r
dim as ControlRef @ browser
dim as OSStatus ignore
dim as OSErr err
dim as Boolean @ bool

// create
SetRect( r, 360, 32, 548, 374 )
ignore = fn CreateDataBrowserControl( window( _wndRef ), r, ¬
_kDataBrowserListView, @browser )

// scroll bars
ignore = fn SetDataBrowserHasScrollBars( browser, _false, _true )

// hilite style
ignore = fn SetDataBrowserTableViewHiliteStyle( browser, ¬
_kDataBrowserTableViewFillHilite )

// selection flags
call SetDataBrowserSelectionFlags( browser, _kDataBrowserSelectOnlyOne )

// add columns
fn AddColumns_cBrowser( browser )

// initial selection
ignore = fn RevealDataBrowserItem( browser, 1, _cBrowserC001, ¬
_kDataBrowserRevealWithoutSelecting )


end fn = browser
'~'5

local fn InitBrowserData_cBrowser( browser as ControlRef )
'~'1
dim as Str255 s(26)
dim as long item, itemID

s(1) = "Alpha"
s(2) = "Bravo"
s(3) = "Charlie"
s(4) = "Delta"
s(5) = "Echo"
s(6) = "Foxtrot"
s(7) = "Golf"
s(8) = "Hotel"
s(9) = "India"
s(10) = "Juliet"
s(11) = "Kilo"
s(12) = "Lima"
s(13) = "Mike"
s(14) = "November"
s(15) = "Oscar"
s(16) = "Papa"
s(17) = "Quebec"
s(18) = "Romeo"
s(19) = "Sierra"
s(20) = "Tango"
s(21) = "Uniform"
s(22) = "Victor"
s(23) = "Whisky"
s(24) = "Xray"
s(25) = "Yankee"
s(26) = "Zulu"

itemID = 0
for item = 1 to rnd(26)
itemID++
fn DBDataSetPString( browser, _cBrowserC001, itemID, str$(item) ¬
+ " " + s(rnd(26)) )
next item

def SetButtonTextString(_cMyEdit, "Browser should contain:" ¬
+ str$(itemID) + " items")

fn DBDataPopulateBrowser( browser )

end fn

'~'5
Clear Local Fn MyItemNotification( browser As ControlRef, ¬
itemID As DataBrowserItemID, ¬
message As DataBrowserItemNotification )
dim as str255 msg$

Select message
Case _kDataBrowserItemSelected' Item has has been selected
def SetButtonTextString(_cMyEdit, "Row selected:" + str$(itemID))

Case _kDataBrowserItemDoubleClicked' The user double clicked on an item.
def SetButtonTextString(_cMyEdit, "Double clicked:" + str$(itemID))

End Select

End fn

'~'5
local fn BuildUntitled1Wnd
'~'1
dim as Rect r
dim as WindowAttributes wa
dim as OSErr err
dim as ControlRef @ browser

wa = _kWindowCloseBoxAttribute¬
  _kWindowCollapseBoxAttribute¬
  _kWindowFullZoomAttribute¬
  _kWindowResizableAttribute

//SetRect( r, 0, 0, 576, 444 )// Optional FB auto-centre
SetRect( r, 638, 63, 1214, 507 )
appearance window -_Untitled1Wnd, "Untitled 1", @r,  
_kDocumentWindowClass, wa
def SetWindowBackground( _kThemeActiveDialogBackgroundBrush, _zTrue )
err = fn SetAutomaticControlDragTrackingEnabledForWindow¬
( window( _wndRef ), _zTrue )

SetRect(r, 23, 30, 279, 46)
appearance button _cMyEdit, _activeBtn,,,,, @r, _kControlEditTextProc
def SetButtonTextString(_cMyEdit, "Data Browser Item")

SetRect(r, 20, 75, 282, 95)
appearance button _cResetDataBrowserBtn, _activeBtn,,,,¬
"Reset Data Browser", @r, _kControlPushButtonProc

gBrowser = fn CreateDataBrowser_cBrowser()
fn InitBrowserData_cBrowser( gBrowser )

appearance window _Untitled1Wnd
end fn

'~'5
local fn Init
'~'1
fn BuildUntitled1Wnd
fn DBDataInstallUserItemNotificationCB( gBrowser, @Fn  
MyItemNotification )
fn DBDataSetAlternatingRowColors( gBrowser , _true )
end fn

'~'5
local fn DoDialog
'~'1
dim as Rect r
dim as long ev, id

ev = dialog( 0 )
id = dialog( ev )
select ev
case _wndClick : window id
case _wndClose
case _wndRefresh
case _wndResized
case _wndActivate
case _btnClick
select window( _outputWnd )
case _Untitled1Wnd
select id
case _cResetDataBrowserBtn
fn InitBrowserData_cBrowser( gBrowser )
end select
end select
case _preview
select id
case _preMenuClick
case _preWndGrow
end select
end select
end fn

'~'5
fn Init

on dialog fn DoDialog

do
HandleEvents
until gFBQuit