| Subject |
Re: attaching a method to MYTOOLBAR |
| From |
Gaetano <gaetanodd@hotmail.com> |
| Date |
Wed, 2 Sep 2020 18:39:06 +1000 |
| Newsgroups |
dbase.getting-started |
| Attachment(s) |
customControls.wfm, mycontrols.cc |
Hi Andy,
Here is the custom controls design form and the .cc file where those
controls are exported to. Look for Mytoolbar in the .cc file. It has a
function named resetToolbar.
What I want to achieve is to include this function in the form and have
it exported together with the actual toolbar through the File-Save as
custom menu option.
The way it is coded in the cc file, I can call that function in any form
where the toolbar is used. I have included teh reset in some buttons but
it doesn't make sense for the PBNEW button because I only want to reset
the buttons if the record is being saved or abandoned. As long as it is
in apend mode, I want the buttons disabled. That's why I need to call
this function from within the form in the canSave event handler (per my
other post about shortening references).
Cheers,
Gaetano.
On 02/09/2020 10:26, Andy Taylor wrote:
> Gaetano,
>
> I have attached a simple form that has a floating toolbar (at 0,0 on screen).
> Right Clicking on the form changes the toolbar properties using a function within the toolbar class definition.
> Is that the sort of thing that you need?
>
> Andy
>
>> Gaetano,
>>
>> I don\'t think that\'s true.
>> The problem here is that it\'s hard to visualise what you want without some sample code.
>> Stripped down as much as you like... then we have something to work with.
>> It\'s easy for you to understand what you want... you can see your code and understand your problem... we have to guess.
>>
>> Regards,
>> Andy
>>
>>
>>> It\'s a lot easier to design visual components visually, in a form, so if
>>> I cannot include a function that is not tied to a baseclass event, I
>>> guess I just need to remember to add it manually to the cc file :)
>>>
>>> On 01/09/2020 19:37, Maurizio S. wrote:
>>>> I have very old approach with \'mytoolbar.cc\'
>>>> derived from dBulletin
>>>> never changed it, because is very useful
>>>> maybe there are better solutions, but... once works
>>>> rarely use constructor form and/or menu, as prefer editing by hand
>>>>
>>>> sincerely, I do not understand what are you looking for
>>>>
>>>>
>>>> tks
>>>> Maurizio
>>>>
>>>> Il 31/08/20 23:48, Gaetano ha scritto:
>>>>>
>>>>> Hi there,
>>>>>
>>>>> I need a simple function to reset all the MYTOOLBAR button\'s enabled
>>>>> property to true.
>>>>>
>>>>> In the tutorial, we design custom controls in a form, then export it
>>>>> to mycontrols.cc. However, I have not found a way to link a standalone
>>>>> function (i.e. a function that is not linked to an event) to the
>>>>> toolbar. If I add the function to the form, nothing links it to the
>>>>> toolbar and it is not included in the \"save as custom\" export to
>>>>> mycontrols.cc file.
>>>>>
>>>>> I can add it manually to the CC file but every time I make an update
>>>>> to the control in the form and re-export it, the function is lost
>>>>> because I don\'t know how to attach the function to the toolbar object
>>>>> inside the form.
>>>>>
>>>>> Is there a way around that or do I just need to remember to re-add the
>>>>> function manually in the .cc file inside the toolbar class definition?
>>>>>
>>>>> Thanks,
>>>>> Gaetano.
>>>
>>
>
| ** END HEADER -- do not remove this line
//
// Generated on 01/09/2020
//
parameter bModal
local f
f = new customControlsForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class customControlsForm of FORM
set procedure to :DT_custom:MyControls.cc additive
with (this)
metric = 6 // Pixels
height = 511.0
left = 468.0
top = 122.0
width = 706.0
text = ""
endwith
this.MYTEXT = new TEXT(this)
with (this.MYTEXT)
height = 22.0
left = 14.0
top = 55.0
width = 84.0
text = "MyText"
borderStyle = 10 // Etched Out
endwith
this.MYENTRYFIELD1 = new MYENTRYFIELD(this)
with (this.MYENTRYFIELD1)
height = 22.0
left = 126.0
top = 11.0
width = 56.0
endwith
this.MYTEXTLABEL = new TEXTLABEL(this)
with (this.MYTEXTLABEL)
height = 22.0
left = 21.0
top = 88.0
width = 84.0
transparent = true
text = "MyTextLabel"
fontBold = true
alignHorizontal = 2 // Right
endwith
this.MYPUSHBUTTON = new PUSHBUTTON(this)
with (this.MYPUSHBUTTON)
height = 24.0
left = 35.0
top = 4.0
width = 62.0
text = "MyPushButton"
endwith
this.MYSPINBOX = new SPINBOX(this)
with (this.MYSPINBOX)
onGotFocus = class::MYSPINBOX_ONGOTFOCUS
height = 22.0
left = 60.0
top = 202.0
width = 56.0
picture = "99999"
colorHighLight = "WindowText/0x80ffff"
rangeMax = 100
rangeMin = 1
value = 1
endwith
this.MYCOMBOBOX = new COMBOBOX(this)
with (this.MYCOMBOBOX)
onGotFocus = class::MYCOMBOBOX_ONGOTFOCUS
onChange = class::MYCOMBOBOX_ONCHANGE
height = 22.0
left = 75.0
top = 250.0
width = 84.0
colorHighLight = "WindowText/0x80ffff"
style = 2 // DropDownList
dropDownHeight = 132.0
endwith
this.MYRADIOBUTTON = new RADIOBUTTON(this)
with (this.MYRADIOBUTTON)
transparent = true
height = 24.0
left = 217.0
top = 22.0
width = 110.0
text = "Radiobutton"
endwith
this.MYCONTAINER = new CONTAINER(this)
with (this.MYCONTAINER)
transparent = true
left = 432.0
top = 42.0
width = 184.0
height = 101.0
borderStyle = 4 // Single
endwith
this.MYGRID = new GRID(this)
with (this.MYGRID)
colorHighLight = "WindowText/0x80ffff"
cellHeight = 22.0
rowSelect = true
allowEditing = false
allowAddRows = false
height = 88.0
left = 434.0
top = 208.0
width = 182.0
endwith
this.MYTABBOX = new TABBOX(this)
with (this.MYTABBOX)
onSelChange = class::TABBOX_ONSELCHANGE
onOpen = class::MYTABBOX_ONOPEN
id = 110
height = 22.0
left = 0.0
top = 487.0
width = 704.0
colorHighLight = "WindowText/0x80ffff"
dataSource = 'ARRAY {"Individual Record","Find Record"}'
endwith
this.MYIMAGE = new IMAGE(this)
with (this.MYIMAGE)
height = 88.0
left = 209.0
top = 80.0
width = 99.0
alignment = 3 // Keep Aspect Stretch
endwith
this.MYEDITOR = new EDITOR(this)
with (this.MYEDITOR)
key = class::MYEDITOR_KEY
height = 88.0
left = 196.0
top = 187.0
width = 221.0
value = ""
colorHighLight = "WindowText/0x80ffff"
evalTags = false
popupEnable = false
endwith
this.DISABLEDENTRY = new MYENTRYFIELD(this)
with (this.DISABLEDENTRY)
when = class::DISABLEDENTRY_WHEN
height = 22.0
left = 71.0
top = 324.0
width = 56.0
colorNormal = "White/Maroon"
value = "DisabledEntry"
mousePointer = 12 // No
endwith
this.MYTITLETEXT = new MYTEXT(this)
with (this.MYTITLETEXT)
height = 28.0
left = 247.0
top = 324.0
width = 84.0
colorNormal = "Blue/BtnFace"
alignHorizontal = 1 // Center
fontSize = 14.0
text = "MyTitle"
borderStyle = 1 // Raised
speedTip = "Form Title"
endwith
this.MYTOOLBAR = new MYCONTAINER(this)
with (this.MYTOOLBAR)
onOpen = class::MYTOOLBAR_ONOPEN
left = 182.0
top = 363.0
width = 429.0
height = 37.0
endwith
this.MYTOOLBAR.PBNEW = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBNEW)
onClick = class::PBNEW_ONCLICK
height = 24.0
left = 7.0
top = 6.0
width = 64.0
text = "&New"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\favourites_16.png"
fontSize = 8.0
speedTip = "Add new record"
pageno = 0
endwith
this.MYTOOLBAR.PBEDIT = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBEDIT)
onClick = class::PBEDIT_ONCLICK
height = 24.0
left = 69.0
top = 6.0
width = 62.0
text = "&Edit"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\document_open_16.png"
fontSize = 8.0
speedTip = "Edit current record"
pageno = 0
endwith
this.MYTOOLBAR.PBSAVE = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBSAVE)
onClick = class::PBSAVE_ONCLICK
height = 24.0
left = 125.0
top = 6.0
width = 62.0
text = "&Save"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\save_16.png"
fontSize = 8.0
speedTip = "Save current record"
pageno = 0
endwith
this.MYTOOLBAR.PBABANDON = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBABANDON)
onClick = class::PBABANDON_ONCLICK
height = 24.0
left = 181.0
top = 6.0
width = 62.0
text = "&Cancel"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\stop_16.png"
fontSize = 8.0
speedTip = "Cancel Changes"
pageno = 0
endwith
this.MYTOOLBAR.PBDELETE = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBDELETE)
onClick = class::PBDELETE_ONCLICK
height = 24.0
left = 241.0
top = 6.0
width = 62.0
text = "&Delete"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\delete_16.png"
fontSize = 8.0
speedTip = "Delete current record"
pageno = 0
endwith
this.MYTOOLBAR.PBNEXT = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBNEXT)
onClick = class::PBNEXT_ONCLICK
height = 24.0
left = 360.0
top = 6.0
width = 62.0
text = "&Next"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\arrow_right_16.png"
fontSize = 8.0
speedTip = "Next record"
pageno = 0
endwith
this.MYTOOLBAR.PBPREVIOUS = new MYPUSHBUTTON(this.MYTOOLBAR)
with (this.MYTOOLBAR.PBPREVIOUS)
onClick = class::PBPREVIOUS_ONCLICK
height = 24.0
left = 300.0
top = 6.0
width = 62.0
text = "&Previous"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\arrow_left_16.png"
fontSize = 8.0
speedTip = "Previous record"
pageno = 0
endwith
function DISABLEDENTRY_when(bOpen)
return false
function MYCOMBOBOX_onChange()
// this = combobox
// datalink = field
// parent = field array
// parent = rowset
if this.datalink.parent.parent.state == 1
this.value = this.savedValue
this.datalink.parent.parent.modified = false
this.datalink.parent.parent.abandon()
endif
return
function MYCOMBOBOX_onGotFocus()
this.savedValue = this.value
return
function MYEDITOR_key(nChar, nPosition,bShift,bControl)
/*
This code by Gary White is provided to
get around a problem with rowsets that
have the autoEdit property set to false,
and editors. The editor seems to be immune
to this property once you make a change
in it -- if you then save or abandon, you
can actually edit the contents of the editor
object ...
*/
// this = editor
// dataLink = field
// parent = fieldArray
// parent = rowset
if type( "this.datalink.parent.parent" ) # "U"
r = this.datalink.parent.parent
if r.autoEdit == false and ;
( r.state # 2 and r.state # 3 )
return 0
endif
endif
return
function MYENTRYFIELD_onGotFocus()
this.keyboard( "{Home}" )
return
function PBNEXT_onClick()
if ( not form.rowset.next() )
form.rowset.next( -1 )
msgbox( "At end of rowset", "Can't Navigate", 64 )
endif
return
function MYSPINBOX_onGotFocus()
this.keyboard( "{Home}" )
return
function MYTABBOX_onOpen()
this.curSel := 1
form.pageNo := 1
return
function resetToolbar()
this.pbabandon.enabled=true
this.pbsave.enabled=true
this.pbdelete.enabled=true
this.pbnext.enabled=true
this.pbprevious.enabled=true
this.pbedit.enabled=true
this.pbadd.enabled=true
return
function MYTOOLBAR_onOpen()
this.pbabandon.enabled=true
this.pbsave.enabled=true
this.pbdelete.enabled=true
this.pbnext.enabled=true
this.pbprevious.enabled=true
this.pbedit.enabled=true
this.pbnew.enabled=true
return
function PBABANDON_onClick()
if form.rowset.modified
if msgbox( "Abandon changes to this row?", "Abandon changes?", 36 ) == 6
form.rowset.abandon()
endif
else
form.rowset.abandon()
endif
return
function PBDELETE_onClick()
if msgbox( "Delete this row?", "Delete Row?", 36 ) == 6
form.rowset.delete()
endif
return
function PBEDIT_onClick()
form.rowset.edit()
return
function PBNEW_onClick()
this.parent.pbnext.enabled=false
this.parent.pbprevious.enabled=false
form.rowset.beginAppend()
return
function PBPREVIOUS_onClick()
if ( not form.rowset.next(-1) )
form.rowset.next()
msgbox( "At beginning of rowset", "Can't Navigate", 64 )
endif
return
function PBSAVE_onClick()
form.rowset.save()
return
function TABBOX_onSelChange()
form.pageNo := this.curSel
return
endclass
| class MYENTRYFIELD(parentObj) of ENTRYFIELD(parentObj) custom
with (this)
onGotFocus = class::MYENTRYFIELD_ONGOTFOCUS
height = 22.0
left = 62.0
top = 102.0
width = 56.0
metric = 6 // Pixels
colorHighLight = "WindowText/0x80ffff"
value = "MyEntryfield"
endwith
function MYENTRYFIELD_onGotFocus()
this.keyboard( "{Home}" )
return
endclass
class MYTEXT(parentObj) of TEXT(parentObj) custom
with (this)
height = 22.0
left = 14.0
top = 55.0
width = 84.0
metric = 6 // Pixels
text = "MyText"
borderStyle = 10 // Etched Out
endwith
endclass
class MYTEXTLABEL(parentObj) of TEXTLABEL(parentObj) custom
with (this)
height = 22.0
left = 53.0
top = 107.0
width = 84.0
metric = 6 // Pixels
transparent = true
text = "MyTextLabel"
fontBold = true
alignHorizontal = 2 // Right
alignVertical = 1 // Middle
endwith
endclass
class MYSPINBOX(parentObj) of SPINBOX(parentObj) custom
with (this)
onGotFocus = class::MYSPINBOX_ONGOTFOCUS
height = 22.0
left = 60.0
top = 202.0
width = 56.0
metric = 6 // Pixels
picture = "99999"
colorHighLight = "WindowText/0x80ffff"
rangeMax = 100
rangeMin = 1
value = 1
endwith
function MYSPINBOX_onGotFocus()
this.keyboard( "{Home}" )
return
endclass
class MYCOMBOBOX(parentObj) of COMBOBOX(parentObj) custom
with (this)
onGotFocus = class::MYCOMBOBOX_ONGOTFOCUS
onChange = class::MYCOMBOBOX_ONCHANGE
height = 22.0
left = 75.0
top = 250.0
width = 84.0
metric = 6 // Pixels
colorHighLight = "WindowText/0x80ffff"
style = 2 // DropDownList
dropDownHeight = 132.0
endwith
function MYCOMBOBOX_onGotFocus()
this.savedValue = this.value
return
function MYCOMBOBOX_onChange()
// this = combobox
// datalink = field
// parent = field array
// parent = rowset
if this.datalink.parent.parent.state == 1
this.value = this.savedValue
this.datalink.parent.parent.modified = false
this.datalink.parent.parent.abandon()
endif
return
endclass
class MYRADIOBUTTON(parentObj) of RADIOBUTTON(parentObj) custom
with (this)
transparent = true
height = 24.0
left = 217.0
top = 22.0
width = 110.0
text = "Radiobutton"
metric = 6 // Pixels
endwith
endclass
class MYCONTAINER(parentObj) of CONTAINER(parentObj) custom
with (this)
transparent = true
left = 432.0
top = 42.0
width = 184.0
height = 101.0
metric = 6 // Pixels
borderStyle = 4 // Single
endwith
endclass
class MYGRID(parentObj) of GRID(parentObj) custom
with (this)
colorHighLight = "WindowText/0x80ffff"
cellHeight = 22.0
rowSelect = true
allowEditing = false
allowAddRows = false
height = 88.0
left = 434.0
top = 208.0
width = 182.0
metric = 6 // Pixels
bgcolor="White"
endwith
endclass
class MYTABBOX(parentObj) of TABBOX(parentObj) custom
with (this)
onSelChange = class::TABBOX_ONSELCHANGE
onOpen = class::MYTABBOX_ONOPEN
id = 110
height = 22.0
left = 0.0
top = 316.0
width = 644.0
metric = 6 // Pixels
colorHighLight = "WindowText/0x80ffff"
dataSource = 'ARRAY {"Individual Record","Find Record"}'
endwith
function TABBOX_onSelChange()
form.pageNo := this.curSel
return
function MYTABBOX_onOpen()
this.curSel := 1
form.pageNo := 1
return
endclass
class MYIMAGE(parentObj) of IMAGE(parentObj) custom
with (this)
height = 88.0
left = 209.0
top = 80.0
width = 99.0
metric = 6 // Pixels
alignment = 3 // Keep Aspect Stretch
endwith
endclass
class MYEDITOR(parentObj) of EDITOR(parentObj) custom
with (this)
key = class::MYEDITOR_KEY
height = 88.0
left = 196.0
top = 187.0
width = 221.0
metric = 6 // Pixels
value = ""
colorHighLight = "WindowText/0x80ffff"
evalTags = false
popupEnable = false
endwith
function MYEDITOR_key(nChar, nPosition,bShift,bControl)
/*
This code by Gary White is provided to
get around a problem with rowsets that
have the autoEdit property set to false,
and editors. The editor seems to be immune
to this property once you make a change
in it -- if you then save or abandon, you
can actually edit the contents of the editor
object ...
*/
// this = editor
// dataLink = field
// parent = fieldArray
// parent = rowset
if type( "this.datalink.parent.parent" ) # "U"
r = this.datalink.parent.parent
if r.autoEdit == false and ;
( r.state # 2 and r.state # 3 )
return 0
endif
endif
return
endclass
class DISABLEDENTRY(parentObj) of MYENTRYFIELD(parentObj) custom
with (this)
when = class::DISABLEDENTRY_WHEN
height = 22.0
left = 71.0
top = 324.0
width = 56.0
colorNormal = "White/Maroon"
value = "DisabledEntry"
mousePointer = 12 // No
endwith
function DISABLEDENTRY_when(bOpen)
return false
endclass
class MYPUSHBUTTON(parentObj) of PUSHBUTTON(parentObj) custom
with (this)
height = 24.0
left = 35.0
top = 4.0
width = 62.0
text = "MyPushButton"
metric = 6 // Pixels
endwith
endclass
class MYTITLETEXT(parentObj) of MYTEXT(parentObj) custom
with (this)
height = 28.0
left = 247.0
top = 324.0
width = 84.0
colorNormal = "Blue/BtnFace"
alignHorizontal = 1 // Center
fontSize = 14.0
text = "MyTitle"
borderStyle = 1 // Raised
speedTip = "Form Title"
endwith
endclass
class MYTOOLBAR(parentObj, name) of MYCONTAINER(parentObj, name) custom
with (this)
left = 182.0
top = 363.0
width = 429.0
height = 37.0
endwith
this.PBNEW = new MYPUSHBUTTON(this)
with (this.PBNEW)
onClick = class::PBNEW_ONCLICK
height = 24.0
left = 7.0
top = 6.0
width = 64.0
text = "&New"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\favourites_16.png"
fontSize = 8.0
speedTip = "Add new record"
pageno = 0
endwith
this.PBEDIT = new MYPUSHBUTTON(this)
with (this.PBEDIT)
onClick = class::PBEDIT_ONCLICK
height = 24.0
left = 69.0
top = 6.0
width = 62.0
text = "&Edit"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\document_open_16.png"
fontSize = 8.0
speedTip = "Edit current record"
pageno = 0
endwith
this.PBSAVE = new MYPUSHBUTTON(this)
with (this.PBSAVE)
onClick = class::PBSAVE_ONCLICK
height = 24.0
left = 125.0
top = 6.0
width = 62.0
text = "&Save"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\save_16.png"
fontSize = 8.0
speedTip = "Save current record"
pageno = 0
endwith
this.PBABANDON = new MYPUSHBUTTON(this)
with (this.PBABANDON)
onClick = class::PBABANDON_ONCLICK
height = 24.0
left = 181.0
top = 6.0
width = 62.0
text = "&Cancel"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\stop_16.png"
fontSize = 8.0
speedTip = "Cancel Changes"
pageno = 0
endwith
this.PBDELETE = new MYPUSHBUTTON(this)
with (this.PBDELETE)
onClick = class::PBDELETE_ONCLICK
height = 24.0
left = 241.0
top = 6.0
width = 62.0
text = "&Delete"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\delete_16.png"
fontSize = 8.0
speedTip = "Delete current record"
pageno = 0
endwith
this.PBNEXT = new MYPUSHBUTTON(this)
with (this.PBNEXT)
onClick = class::PBNEXT_ONCLICK
height = 24.0
left = 360.0
top = 6.0
width = 62.0
text = "&Next"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\arrow_right_16.png"
fontSize = 8.0
speedTip = "Next record"
pageno = 0
endwith
this.PBPREVIOUS = new MYPUSHBUTTON(this)
with (this.PBPREVIOUS)
onClick = class::PBPREVIOUS_ONCLICK
height = 24.0
left = 300.0
top = 6.0
width = 62.0
text = "&Previous"
upBitmap = "filename :Glyfx:\Aero\CE\Dbase Aero\PNG\16x16\arrow_left_16.png"
fontSize = 8.0
speedTip = "Previous record"
pageno = 0
endwith
function PBDELETE_onClick()
if msgbox( "Delete this row?", "Delete Row?", 36 ) == 6
form.rowset.delete()
this.parent.resettoolbar()
endif
return
function PBABANDON_onClick()
if form.rowset.modified
if msgbox( "Abandon changes to this row?", "Abandon changes?", 36 ) == 6
form.rowset.abandon()
this.parent.resettoolbar()
endif
else
form.rowset.abandon()
endif
return
function PBPREVIOUS_onClick()
if ( not form.rowset.next(-1) )
form.rowset.next()
msgbox( "At beginning of rowset", "Can't Navigate", 64 )
endif
return
function PBSAVE_onClick()
form.rowset.save()
this.parent.resettoolbar()
return
function PBNEW_onClick()
this.parent.pbnext.enabled=false
this.parent.pbprevious.enabled=false
form.rowset.beginAppend()
return
function PBNEXT_onClick()
if ( not form.rowset.next() )
form.rowset.next( -1 )
msgbox( "At end of rowset", "Can't Navigate", 64 )
endif
return
function PBEDIT_onClick()
form.rowset.edit()
return
function resetToolbar
this.PBNEXT.enabled=true
this.PBprevious.enabled=true
endclass
|
|