Alaska Software Inc. - XbpMenuBar()
Username: Password:
AuthorTopic: XbpMenuBar()
Carlos Beling XbpMenuBar()
on Tue, 21 Nov 2023 09:28:22 -0300
Good day.
How can I change the color of the entire background of XbpMenuBar() once 
or when XbpMenuBar() is resized?
I couldn't find an example that works this way.

Fraternally
Beling
Slavoljub DamnjanovicRe: XbpMenuBar()
on Wed, 22 Nov 2023 12:33:11 +0100
Good day.
There is Alaska example menus.prg for creating ownerdraw menu system in the
folder source\samples\basics\ownerdrw. You can change the color of the entire
background of XbpMenuBar() in the DrawMenuBarItem() function, using functions:
oPS:setPageSize(), GraSetColor(oPS, ...) and GraBox(oPS, ...).

Regards,
Slavoljub
Carlos Beling Re: XbpMenuBar()
on Thu, 23 Nov 2023 09:17:30 -0300
Hi Slavoljub good day.
The problem is that XbpMenuBar() clears the background area and does not 
sets aInfo[02] as XBP_DRAWACTION_DRAWALL; then the menu's background can 
not being redrawn.

Fraternally
Beling

Em 22/11/2023 08:33, Slavoljub Damnjanovic escreveu:
> Good day.
> There is Alaska example menus.prg for creating ownerdraw menu system in the
> folder source\samples\basics\ownerdrw. You can change the color of the entire
> background of XbpMenuBar() in the DrawMenuBarItem() function, using functions:
> oPS:setPageSize(), GraSetColor(oPS, ...) and GraBox(oPS, ...).
> 
> Regards,
> Slavoljub
Carlos Beling Re: XbpMenuBar()
on Thu, 23 Nov 2023 18:45:22 -0300
Hi Slavoljub.
Good night.
Excuse my empty last post.

Really XbpMenubar() has in its method XbpMenuBar:drawitem the  test:
if BAnd(aInfo[2], XBP_DRAWACTION_DRAWALL) <> 0 where you can redraw the 
background color.
The problem is that XbpMenuBar() sometimes clears the background and 
does not set aInfo[2] with XBP_DRAWACTION_DRAWALL).

Fraternally
Beling


Em 22/11/2023 08:33, Slavoljub Damnjanovic escreveu:
> Good day.
> There is Alaska example menus.prg for creating ownerdraw menu system in the
> folder source\samples\basics\ownerdrw. You can change the color of the entire
> background of XbpMenuBar() in the DrawMenuBarItem() function, using functions:
> oPS:setPageSize(), GraSetColor(oPS, ...) and GraBox(oPS, ...).
> 
> Regards,
> Slavoljub
Slavoljub DamnjanovicRe: XbpMenuBar()
on Fri, 24 Nov 2023 08:10:11 +0100
Hi Carlos.

Try this code, it works at me.

ps_wdt = oPS:setPageSize()[1,1]
GraSetColor(oPS,bg_clr)
GraBox(oPS,{3,0},{ps_wdt + 2,1},GRA_FILL)
IF BAND(aInfo[2],XBP_DRAWACTION_DRAWALL) <> 0 .AND. aInfo[1] = oMBar:numItems()
  GraBox(oPS,{aRect[1],aRect[2]},{ps_wdt + 2,aRect[4] + 1},GRA_FILL)
  aInfo[2] = BOR(aInfo[2],XBP_DRAWACTION_SELCHANGE)
ENDIF


Regards,
Slavoljub
Carlos Beling Re: XbpMenuBar()
on Fri, 24 Nov 2023 16:07:06 -0300
Hi Slavoljub.
Many thanks again.
The problem is that in some cases aInfo[2] does not contain 
XBP_DRAWACTION_DRAWALL when the menu's background is redraw in the 
default color. It seems to me that this happens when the method 
XbpMenuBar:MeasureItem is executed.

Fraternally
Beling

Em 24/11/2023 04:10, Slavoljub Damnjanovic escreveu:
> Hi Carlos.
> 
> Try this code, it works at me.
> 
> ps_wdt = oPS:setPageSize()[1,1]
> GraSetColor(oPS,bg_clr)
> GraBox(oPS,{3,0},{ps_wdt + 2,1},GRA_FILL)
> IF BAND(aInfo[2],XBP_DRAWACTION_DRAWALL) <> 0 .AND. aInfo[1] = oMBar:numItems()
>    GraBox(oPS,{aRect[1],aRect[2]},{ps_wdt + 2,aRect[4] + 1},GRA_FILL)
>    aInfo[2] = BOR(aInfo[2],XBP_DRAWACTION_SELCHANGE)
> ENDIF
> 
> 
> Regards,
> Slavoljub
Slavoljub DamnjanovicRe: XbpMenuBar()
on Sat, 25 Nov 2023 17:52:34 +0100
Hi Carlos.

That is not happening at me. Can you send me your code for XbpMenuBar:MeasureItem()? Maybe it misses something.

Regards,
Slavoljub
Carlos Beling Re: XbpMenuBar()
on Wed, 29 Nov 2023 12:37:16 -0300
Hi  Slavoljub.
Good afternoon.
Many thanks again.
Here is the used code:

Fraternally
Beling


 Overloaded :MeasureItem() method for computing
 the dimensions of the menu entries. The method
 uses GraQueryTextBox() to compute the textbox
 required for rendering the menu caption and
 adds the space required for drawing the bar
 at the left-hand side.

#define cabMENU_ITEM_SPACING             5
METHOD CabMenuBar_:MeasureItem( nItem, aDims )

  LOCAL aItem    := ::oMenu:getItem( nItem )
  LOCAL xCaption
  LOCAL cType
  LOCAL aBox

    xCaption     := aItem[01]
    cType        := ValType(xCaption)
    IF     cType == "C"
    ELSEIf cType == "O"
           if xCaption:isderivedFrom('XbpMenuBar')
              xCaption  := xCaption:title
           else
              aDims[01] := (xCaption:xSize + (cabMENU_ITEM_SPACING * 2))
              aDims[02] := (xCaption:ySize + (cabMENU_ITEM_SPACING * 2))
              RETURN Self
           endif
    ELSE
           aDims[01]    := cabMENU_ITEM_SPACING
           aDims[02]    := cabMENU_ITEM_SPACING
           RETURN Self
    ENDIF

     Compute the dimensions of a menu item that
     has a caption string. The item's width is
     derived from the textbox required for
     rendering the caption string.
    aBox := GraQueryTextBox(::oQuery, StrTran(xCaption, '~', '')) <== 
::oQuery := XbpPresSpace()...:SetFont(oFont)

    aDims[1] := ((aBox[03, 01] - aBox[02, 01]) + cabMENU_ITEM_SPACING - 1)
    aDims[2] := (::nFontHeight                 + cabMENU_ITEM_SPACING)
RETURN Self

Em 25/11/2023 13:52, Slavoljub Damnjanovic escreveu:
> Hi Carlos.
> 
> That is not happening at me. Can you send me your code for XbpMenuBar:MeasureItem()? Maybe it misses something.
> 
> Regards,
> Slavoljub
Slavoljub DamnjanovicRe: XbpMenuBar()
on Wed, 29 Nov 2023 20:38:51 +0100
Hi Carlsos,

Try to make this correction:

if xCaption:isderivedFrom('XbpMenu')     NOT 'XbpMenuBar'
  xCaption = xCaption:title
elseif xCaption:isderivedFrom('XbpBitmap')
  aDims[01] = xCaption:xSize + cabMENU_ITEM_SPACING * 2
  aDims[02] = xCaption:ySize + cabMENU_ITEM_SPACING * 2
  RETURN Self
else
  aDims[01] = cabMENU_ITEM_SPACING
  aDims[02] = cabMENU_ITEM_SPACING
  RETURN Self
endif


Regards,
Slavoljub
Carlos Beling Re: XbpMenuBar()
on Tue, 05 Dec 2023 12:39:38 -0300
Hi Slavoljub:
Good day. I foound out the problem: I was using in a 
XbpMenubar:measureItem() a XbpPresSpace() linked to a XbpBitmap() 
instead linked to a :winDevice(); then the measures did not match with 
those used in the XbpBmenubar:drawitem().
Sorry by bother you and thanks again,

Fraternally
Beling

Em 29/11/2023 16:38, Slavoljub Damnjanovic escreveu:
> Hi Carlsos,
> 
> Try to make this correction:
> 
> if xCaption:isderivedFrom('XbpMenu')     NOT 'XbpMenuBar'
>    xCaption = xCaption:title
> elseif xCaption:isderivedFrom('XbpBitmap')
>    aDims[01] = xCaption:xSize + cabMENU_ITEM_SPACING * 2
>    aDims[02] = xCaption:ySize + cabMENU_ITEM_SPACING * 2
>    RETURN Self
> else
>    aDims[01] = cabMENU_ITEM_SPACING
>    aDims[02] = cabMENU_ITEM_SPACING
>    RETURN Self
> endif
> 
> 
> Regards,
> Slavoljub
Slavoljub DamnjanovicRe: XbpMenuBar()
on Wed, 06 Dec 2023 08:01:13 +0100
Hi Carlos,

I am glad your solved your problem. I will give you a better suggestion to
avoid it. The item dimensions should not be calculated in :measureItem(). It
is the best to calculate them in :create() method or even better in your main
program and pass them to :create(), since item captions are defined there. For
PS use AppDesktop():lockPS(). Then write dimensions in an array instance
variable of your ownerdrawn XbpMenu/Xbpmenubar objects, and just read and
return them in :measureItem(). BTW, :measureItem() is executed each time
XbpMenubar is redisplayed and this is often in the application life time. In
this way item dimensions are not recalculated all the time.

Regards,
Slavoljub
Carlos Beling Re: XbpMenuBar()
on Wed, 06 Dec 2023 15:42:25 -0300
Hi Slavoljub.
Many many thanks again.
For sure I will to try it.

Fraternally
Beling

Em 06/12/2023 04:01, Slavoljub Damnjanovic escreveu:
> Hi Carlos,
> 
> I am glad your solved your problem. I will give you a better suggestion to
> avoid it. The item dimensions should not be calculated in :measureItem(). It
> is the best to calculate them in :create() method or even better in your main
> program and pass them to :create(), since item captions are defined there. For
> PS use AppDesktop():lockPS(). Then write dimensions in an array instance
> variable of your ownerdrawn XbpMenu/Xbpmenubar objects, and just read and
> return them in :measureItem(). BTW, :measureItem() is executed each time
> XbpMenubar is redisplayed and this is often in the application life time. In
> this way item dimensions are not recalculated all the time.
> 
> Regards,
> Slavoljub