[PB Cocoa] Cocoa companion library

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

metalos wrote:I have wanted to know if it was possible to move in a ToolBar 1 Boutton the oposite of the other and if so how.
I've read your question multiple times but I still don't understand what you are exactly asking. :?
Can you try to explain a bit more ?
Windows (x64)
Raspberry Pi OS (Arm64)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

Sorry for my English but I use Google Translate.

Using an example of the documentation for your library I get this result for the ToolBar.

Code: Select all

If OpenWindow(0, 0, 0, 600, 200, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  StringGadget(0, 0, 0, 96, 32, "")
  
  CreateImage(0, 32, 32)
  StartDrawing(ImageOutput(0))
  Box(0,0,32,32,RGB(255,255,255))
  Box(4,4,24,24,RGB(255,0,0))
  StopDrawing()
  
  CreateToolBar(0, WindowID(0))
  TB_ID = ToolBarID(0)
  ToolBar_SetMode(TB_ID, 1, 1)
  
  ToolBarImageButton(0, ImageID(0))
  Item = ToolBar_ItemAtIndex(TB_ID, 0)
  ToolBar_SetItemLabel(Item, "Button")
  
  ToolBarImageButton(1, ImageID(0))
  Item = ToolBar_ItemAtIndex(TB_ID, 1)
  ToolBar_SetItemLabel(Item, "String gadget")
  ToolBar_SetItemGadget(Item, GadgetID(0))
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
  
EndIf
Image


I would like to place the StringGadget the oposite of BouttonImage like this:

Image


My request is can not be possible with your library and if this is the case do you add this option in the future? Thank you for your help.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

It's a bit complicated since I don't know the PureBasic internals.
What you need to get what you want is a flexible space item.
You can insert one after you create the toolbar like this

Code: Select all

CocoaMessage(0, ToolBarID(0), "insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem", "atIndex:", 1)
The problem is that there seem to be additional items on the toolbar that mess up the way things look and I don't know if there is a reason these items are there.
On my system there seem to be two and once I remove those things look fine

Code: Select all

CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", 2)
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", 2)
CocoaMessage(0, ToolBarID(0), "insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem", "atIndex:", 1)
I just can't guarantee it is the same on every OSX version, if it will stay this way and if these additional items have any reason to be there.
So without any confirmation on this from Fred it's not really a safe option.
Windows (x64)
Raspberry Pi OS (Arm64)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

I'll try anyway, thanks;-)
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [PB Cocoa] Cocoa companion library

Post by Shardik »

As Wilbert correctly describes it, it's really a bit complicated because of PureBasic's internal toolbar implementation. PureBasic always adds a flexible space, a space and a separator (on Snow Leopard but not on Mavericks!) behind the last visible toolbar button. You may inspect this by executing the following code which enables you to customize your toolbar and by the way see all visible and invisible items which PureBasic always adds to your toolbar:

Code: Select all

#SilkThemePath = #PB_Compiler_Home + "Themes/"
#IconNameList = "disk.png+delete.png+arrow_left.png+arrow_right.png"

UsePNGImageDecoder()
UseZipPacker()

OpenWindow(0, 270, 100, 290, 50, "Customizable toolbar")
CreateToolBar(0, WindowID(0))

If OpenPack(0, #SilkThemePath + "SilkTheme.zip")
  *ImageBuffer = AllocateMemory(1024)

  If ExaminePack(0)
    For i = 0 To CountString(#IconNameList, "+")
      ImageSize = UncompressPackMemory(0, *ImageBuffer, MemorySize(*ImageBuffer),
        StringField(#IconNameList, i + 1, "+"))

      If ImageSize > 0
        If CatchImage(i, *ImageBuffer, ImageSize)
          ToolBarImageButton(i, ImageID(i))

          If i = 2
            ToolBarSeparator()
          EndIf
        EndIf
      EndIf
    Next i
  EndIf

  FreeMemory(*ImageBuffer)
EndIf

; ----- Display dialog to customize toolbar
CocoaMessage(0, ToolBarID(0), "runCustomizationPalette:", ToolBarID(0))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Also keep in mind that these PureBasic internals may change with new releases, so please use the following hackish solution with care:

Code: Select all

#NSToolbarSizeModeRegular = 1

OpenWindow(0, 270, 100, 350, 200, "ToolBar with button at right end")

CreateImage(0, 24, 24)

StartDrawing(ImageOutput(0))
  Box(0, 0, 24, 24, $FF0000)
  Box(4, 4, 16, 16, $FFFF)
StopDrawing()

CreateImage(1, 24, 24)

StartDrawing(ImageOutput(1))
  Box(0, 0, 24, 24, $FF)
  Box(4, 4, 16, 16, $FFFF)
StopDrawing()

CreateToolBar(0, WindowID(0))

CocoaMessage(0, ToolBarID(0), "setSizeMode:", #NSToolbarSizeModeRegular)

ToolBarImageButton(0, ImageID(0))
ToolBarImageButton(1, ImageID(1))

; ----- Count visible and invisible toolbar items
ItemCount = CocoaMessage(0, CocoaMessage(0, ToolBarID(0), "items"), "count")

If OSVersion() <= #PB_OS_MacOSX_10_6
  ; ----- Remove rightmost separator
  CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
  ItemCount - 1
EndIf

; ----- Remove rightmost space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1

; ----- Remove rightmost flexible space
CocoaMessage(0, ToolBarID(0), "removeItemAtIndex:", ItemCount - 1)
ItemCount - 1

; ----- Insert flexible space between 1st and 2nd button
CocoaMessage(0, ToolBarID(0),
  "insertItemWithItemIdentifier:$", @"NSToolbarFlexibleSpaceItem",
  "atIndex:", 1)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

Another option might be to create a Toolbar yourself from the NSToolbar class but that also means defining all the required delegate methods.
Windows (x64)
Raspberry Pi OS (Arm64)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

Ok thanks
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

Could someone sticky this? I think it's a must have for OS X users.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

Hello,

I returned to you because when I add the parameter # PB_ToolBar_Toggle my ToolBarImageButton () it does not seem to work. Do you have an idea of the problem? Thank you in advance.

Code: Select all

If OpenWindow(0, 0, 0, 600, 200, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  StringGadget(0, 0, 0, 96, 32, "")
  
  CreateImage(0, 32, 32)
  StartDrawing(ImageOutput(0))
  Box(0,0,32,32,RGB(255,255,255))
  Box(4,4,24,24,RGB(255,0,0))
  StopDrawing()
  
  CreateToolBar(0, WindowID(0))
  TB_ID = ToolBarID(0)
  ToolBar_SetMode(TB_ID, 1, 1)
  
  ToolBarImageButton(0, ImageID(0), #PB_ToolBar_Toggle)
  Item = ToolBar_ItemAtIndex(TB_ID, 0)
  ToolBar_SetItemLabel(Item, "Button")
  
  ToolBarImageButton(1, ImageID(0))
  Item = ToolBar_ItemAtIndex(TB_ID, 1)
  ToolBar_SetItemLabel(Item, "String gadget")
  ToolBar_SetItemGadget(Item, GadgetID(0))
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
  
EndIf
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

metalos wrote:when I add the parameter # PB_ToolBar_Toggle my ToolBarImageButton () it does not seem to work.
It looks like this is a PureBasic bug.
The optional #PB_ToolBar_Toggle doesn't seem to do anything.
You could post a bug report in the bugs section of the forum.
Windows (x64)
Raspberry Pi OS (Arm64)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: [PB Cocoa] Cocoa companion library

Post by metalos »

I just mentioned. Thank you.
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

Missing a couple of files on build...

Code: Select all

Last login: Mon Jun  9 17:34:56 on ttys000
Joseph-Bakers-MacBook-Air:~ jbaker$ /Users/jbaker/Documents/Cocoa/PBCocoa64/PBUserlib/build.command ; exit;
cp: /Users/jbaker/Documents/Cocoa/PBCocoa64/build/PBCocoa.build/Release/PBCocoa.build/Objects-normal/i386/libPBCocoa.a: No such file or directory
cp: /Users/jbaker/Documents/Cocoa/PBCocoa64/build/PBCocoa.build/Release/PBCocoa.build/Objects-normal/x86_64/libPBCocoa.a: No such file or directory
Can't open the main file: libPBCocoa_x86.a
Can't open the main file: libPBCocoa_x64.a
rm: *.zip: No such file or directory
  adding: libPBCocoa_x64 (deflated 66%)
  adding: libPBCocoa_x86 (deflated 66%)
logout

[Process completed]
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [PB Cocoa] Cocoa companion library

Post by wilbert »

J. Baker wrote:Missing a couple of files on build...
Do you also have this problem with other user libraries Joe ?
Maybe it is related to using Yosemite.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

wilbert wrote:
J. Baker wrote:Missing a couple of files on build...
Do you also have this problem with other user libraries Joe ?
Maybe it is related to using Yosemite.
The last lib I tried was with TailBite. That's been a while. I'm actually on Snow Leopard. I thought that maybe those directories and files were missing from the source? Or is there something else I'm missing or should be doing?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [PB Cocoa] Cocoa companion library

Post by J. Baker »

removed

EDIT: I got it. I had to remove the fullscreen code as I'm using an earlier version of xcode. ;)
Last edited by J. Baker on Tue Jun 10, 2014 6:53 pm, edited 1 time in total.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply