FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xbrowse in a Toolbar?
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 09:48 PM
Is it possible to place an xbrowse on a toolbar?

Code (fw): Select all Collapse
...
   DEFINE REBAR oReBar OF ::oWnd

   DEFINE TOOLBAR oToolBar OF oReBar SIZE 50, 58 IMAGELIST oImageList BALLOON // tooltips balloon style

...
      @ 01, 535 XBROWSE oBrw ARRAY { { "one" }, { "two" } } OF oToolBar SIZE 150, 30 PIXEL AUTOCOLS HEADERS "Schedules"


So far I haven't had any luck. The xbrowse does not display. Perhaps we can't place an xbrowse on a toolbar?

My purpose is to have a multi-select list. I'm thinking an xbrowse would be a nice solution.

Thank you,
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 10:06 PM

Reinaldo,

can you build a compilable and runnable sample, please?

EMG

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 10:32 PM
Enrico;

Good idea. Here is a reduced self-contained sample:

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "xbrowse.ch"

FUNCTION Start() 
   LOCAL oImageList, orebar, oToolBar, oBrw, oWnd


   DEFINE WINDOW oWnd MDI
   
   DEFINE IMAGELIST oImageList SIZE 32, 32

   DEFINE IMGBITMAP OF oImageList NAME "ViewCal132"   COLOR nRGB( 255, 0, 255 )

   DEFINE REBAR oReBar OF oWnd

   DEFINE TOOLBAR oToolBar OF oReBar SIZE 50, 58 IMAGELIST oImageList BALLOON // tooltips balloon style

   DEFINE TBBUTTON of oToolBar Action MsgInfo( "only testing" ) 

   DEFINE TBSEPARATOR OF oToolBar

   @ 01, 535 XBROWSE oBrw ARRAY { { "one" }, { "two" } } OF oToolBar SIZE 150, 30 PIXEL AUTOCOLS HEADERS "Header1"

   oReBar:InsertBand( oToolBar )

   ACTIVATE WINDOW oWnd 
   
RETURN NIL
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 10:53 PM
Probably you might have forgotten oBrw:CreateFromCode()

This sample code worked for me:
Code (fw): Select all Collapse
function XBrwOnToolBar()

   local oWnd, oReBar, oBar, oBrw

   DEFINE WINDOW oWnd
   DEFINE REBAR oReBar OF oWnd

   DEFINE TOOLBAR oBar OF oReBar SIZE 50, 58 BALLOON // tooltips balloon style

   @ 01, 535 XBROWSE oBrw ARRAY { { "one" }, { "two" } } OF oBar SIZE 150, 57 PIXEL AUTOCOLS HEADERS "Schedules" CELL
   WITH OBJECT oBrw
      :lRecordSelector  := .f.
      :lHScroll         := .f.
      :nStretchCol      := 1
      //
      :CreateFromCode()
   END

   oRebar:InsertBand( oBar )

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 10:54 PM

Rao;

ooops.

Thank you.

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 11:29 PM
Maybe a colored rounded border needed ( can have a shadow ) ?



Code (fw): Select all Collapse
@ 2, 650 TITLE oTitle SIZE  160, 68 OF oToolBar PIXEL SHADOWSIZE 0
oTitle:lRound := .T.    // Round 
oTitle:lTransparent := .F.
oTitle:lBorder := .F.
oTitle:aGrdBack := { { 1, 255, 255 }, { 1, 255, 255 } } 

@ 5, 5 XBROWSE oBrw ARRAY { { "one" }, { "two" } } OF oTitle SIZE 150, 57 PIXEL AUTOCOLS HEADERS "Schedules" CELL
WITH OBJECT oBrw
      :lRecordSelector  := .f.
      :lHScroll         := .f.
      :nStretchCol      := 1
      //
      :CreateFromCode()
END




Code (fw): Select all Collapse
@ 2, 650 TITLE oTitle SIZE  154, 62 OF oToolBar PIXEL SHADOW bottomright SHADOWSIZE 10 
oTitle:lRound := .F.    // Round 
oTitle:lTransparent := .F.
oTitle:lBorder := .F.
oTitle:aGrdBack := { { 1, NIL, NIL }, { 1, NIL, NIL } } 

@ 1, 1 XBROWSE oBrw ARRAY { { "one" }, { "two" }, { "three" } } OF oTitle SIZE 150, 57 PIXEL AUTOCOLS HEADERS "Schedules" CELL
WITH OBJECT oBrw
      :lRecordSelector  := .f.
      :lHScroll         := .f.
      :lHeader         := .f.
      :nStretchCol      := 1
      //
      :CreateFromCode()
END


best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 11:35 PM

Rao,

How about removing the header? is it possible?

Thank you,

Reinaldo.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 11:40 PM
reinaldocrespo wrote:Rao,

How about removing the header? is it possible?

Thank you,

Reinaldo.

oBrw:lHeader := .f.
Regards



G. N. Rao.

Hyderabad, India
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: xbrowse in a Toolbar?

Posted: Tue Feb 10, 2015 11:49 PM

Rao,

Yes!

Thank you.

However... as I look at the result, I'm thinking perhaps I should place a multi-selectable dropdown listbox. Can you make a recommendation for a multi-selectable dropdown combobox style control?

Again, thank you.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: xbrowse in a Toolbar?

Posted: Wed Feb 11, 2015 12:46 AM

A combobox is more suitable for this kind of interface than xbrowse.
Unfortunately, combobox does not support multiple selection, as far as I know.

Both listbox and xbrowse support multiple selection and listbox looks more elegant here than xbrowse. But both suffer from the limitation that their display is clipped by the size of the parent window ( In this case, the ToolBar ).

Alternative-1:

Have a Get with Bitmap Button (down arrow is the best) on the toolbar displaying the selected options. This gives a familiar look of a combobox.

The button action is to create a simple list box with multiple selection option, precisely positioned below the Get. The parent window is the parent window of the Rebar. We take care of the display coordinates of the listbox at runtime inside the button-action. We also provide a way to close the listbox. When closed, the selected options are displayed by the Get.

The idea is to give a look and feel of a dropdown combobox with multiple selection.

Alternative-2:
Much simpler.
One of the toolbar buttons to have a drop-down menu with selected items checked.

I prefer the second alternative.

There can probably many other alternative approaches but this strikes to my mind immediately.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: xbrowse in a Toolbar?

Posted: Wed Feb 11, 2015 01:56 AM
This is a sample using 2nd alternative. I used buttonbar instead of rebar, but can be adopted to rebars too.
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

function TestSel()

   local oWnd, oBar, oFont
   local aItems   := { "One", "Two", "Three", "Four" }
   local aSel     := { "Three" }

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE WINDOW oWnd
   oWnd:SetFont( oFont )
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,64 2007
   DEFINE BUTTON OF oBar PROMPT "Test" ACTION XBrowse( aSel )
   DEFINE BUTTON OF oBar PROMPT { || If( Empty( aSel ), "Select", FW_ArrayAsList( aSel, ", " ) ) } ;
      MENU { || ItemMenu( aItems, aSel ) } ACTION This:ShowPopup()

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

static function ItemMenu( aItems, aSel )

   local oPop, cPrompt

   MENU oPop POPUP 2007
   FOR EACH cPrompt IN aItems
      MENUITEM cPrompt WHEN { |o| o:SetCheck( AScan( aSel, o:cPrompt ) > 0 ), .t. } ;
         ACTION If( oMenuItem:lChecked, ;
                    ( ADel( aSel, AScan( aSel, oMenuItem:cPrompt ), .t. ), ;
                      oMenuItem:SetCheck( .f. ) ), ;
                    ( AAdd( aSel, oMenuItem:cPrompt ), ;
                      oMenuItem:SetCheck( .t. ) ) )
   NEXT
   ENDMENU

return oPop

//----------------------------------------------------------------------------//

Note: Specifying a codeblock as prompt of a button is possible with recent versions of FWH. In older versions as well as toolbars, we need to keep modifying the prompt and refresh as and when required during runtime.
Regards



G. N. Rao.

Hyderabad, India
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: xbrowse in a Toolbar?

Posted: Wed Feb 11, 2015 02:20 AM

Rao,

Yes, that will do perfectly. Thank you very much.

Reinaldo.

Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: xbrowse in a Toolbar?

Posted: Wed Feb 11, 2015 02:40 AM
Excuse me for interrupting but can someone explain what "This:" is for and when to use it? TIA

Code (fw): Select all Collapse
DEFINE BUTTON OF oBar PROMPT { || If( Empty( aSel ), "Select", FW_ArrayAsList( aSel, ", " ) ) } ;
      MENU { || ItemMenu( aItems, aSel ) } ACTION This:ShowPopup()
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: xbrowse in a Toolbar?

Posted: Wed Feb 11, 2015 03:00 AM
hua wrote:Excuse me for interrupting but can someone explain what "This:" is for and when to use it? TIA

Code (fw): Select all Collapse
DEFINE BUTTON OF oBar PROMPT { || If( Empty( aSel ), "Select", FW_ArrayAsList( aSel, ", " ) ) } ;
      MENU { || ItemMenu( aItems, aSel ) } ACTION This:ShowPopup()


In this case, This refers to the button (tbtnbmp()) object.

From a reading of command translate "DEFINE BUTTON OF oBar" in fivewin.ch, we see that "ACTION This:ShowPopup()" will be translated by the pre-processor as { |This| This:ShowPopop() }
Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: xbrowse in a Toolbar?

Posted: Wed Feb 11, 2015 03:06 AM

I see. Thanks for the explanation Rao

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion