Page 5 of 7

Re: [PB Cocoa] Cocoa companion library

Posted: Thu Aug 30, 2012 6:36 pm
by wilbert
Added

SearchField_Create (WindowID, x, y, width, height) - Create a search field object.
SearchField_GetText (SearchField) - Gets the text of the search field.


Example

Code: Select all

ProcedureC Callback(SearchField)
  Debug SearchField_GetText(SearchField)  
EndProcedure

If OpenWindow(0, 0, 0, 400, 300, "SearchField", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  
  MySearchField = SearchField_Create(WindowID(0), 10, 10, 380, 30)
  SetTargetActionCallback(MySearchField, @Callback())
  
  Repeat
    EventID = WaitWindowEvent()
  Until EventID = #PB_Event_CloseWindow
  
EndIf

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Sep 11, 2012 4:31 pm
by jesperbrannmark
Weeeebcaaaam... (please?)

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Sep 11, 2012 4:54 pm
by wilbert
jesperbrannmark wrote:Weeeebcaaaam... (please?)
What do you need ?
The easiest way would be the picture taker
https://developer.apple.com/library/mac ... icker.html
but I don't know if that will be enough for you.

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Sep 11, 2012 7:04 pm
by jesperbrannmark
It wasn't all easy to understand that, but yes. here we can take both snapshot and import other images. that would be awsome!

Re: [PB Cocoa] Cocoa companion library

Posted: Tue Sep 11, 2012 7:57 pm
by wilbert
jesperbrannmark wrote:It wasn't all easy to understand that, but yes. here we can take both snapshot and import other images. that would be awsome!
You should be able to do it with the current library but I can't get setting the output size to work.

Code: Select all

EnableExplicit

; *** make sure the Quartz framework is linked ***

ImportC "/System/Library/Frameworks/Quartz.framework/Quartz"
EndImport

; *** run the picture taker ***

Define PictureTaker = CocoaMessage(0, 0, "IKPictureTaker pictureTaker")
CocoaMessage(0, PictureTaker, "runModal")
Define ImageID = CocoaMessage(0, PictureTaker, "outputImage")

; *** present the result ***

If OpenWindow(0, 0, 0, 320, 320, "Picture Taker", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ImageGadget(0,  10, 10, 300, 300, ImageID)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: [PB Cocoa] Cocoa companion library

Posted: Thu Feb 07, 2013 7:01 pm
by Niffo
I am VERY interested in the following functions :

Notification_Observe (Object, NotificationName.s)
Notification_RemoveObserve (Object, NotificationName.s)
Notification_SetCallback (@NotificationCallback())
SetTargetActionCallback(Control, @Callback())

... but i would like not to have an external library to use. Can you please help me to implement them in pure PureBasic ?
I had a look at the sources, but i am sadly not very fiendly with Objective-C :(

Here is my first try for Notification_Observe()/Notification_RemoveObserve() (inspired from another post) :

Code: Select all

ImportC ""
   sel_registerName(str.p-ascii)
   class_addMethod(class, selector, imp, types.p-ascii)
EndImport

OpenWindow(0, 100, 100, 300, 200, "Test")
ProcedureC CallBack(obj, sel, notification)
   Debug "Callback()"
EndProcedure

notificationCenter = CocoaMessage(0, 0, "NSNotificationCenter defaultCenter")
appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
delegateClass = CocoaMessage(0, appDelegate, "class")

selector = sel_registerName("Callback:") ; Necessary ?
class_addMethod(delegateClass, selector, @Callback(), "v@:@")
CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selector, "name:", #Null, "object:", WindowID(0))

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate, "name:", #Null, "object:", WindowID(0))
... but how to do for SetTargetActionCallback() ?
And how to implement a RemoveTargetAction() ?

Regards.

Re: [PB Cocoa] Cocoa companion library

Posted: Thu Feb 07, 2013 8:15 pm
by wilbert
@Niffo, can you tell me what kind of notifications you want to observe ?

Re: [PB Cocoa] Cocoa companion library

Posted: Fri Feb 08, 2013 9:20 am
by Niffo
Thanks for your answer.
In fact, i use :
- Notification_Observe (WindowID(x), "") to receive all Window notifications in the Callback (seems to work in my code above)
- SetTargetActionCallback(GadgetID(x), @Callback()) to receive live events like drags in scrollbars and trackbars, ...

Re: [PB Cocoa] Cocoa companion library

Posted: Fri Feb 08, 2013 11:18 am
by Niffo
Seems to be ok for "SetTargetActionCallback()" :

Code: Select all

OpenWindow(0, 100, 100, 300, 200, "Test")
ScrollBarGadget(0, 10, 10, 200, 20, 0, 100, 10)

ImportC ""
   sel_registerName(str.p-ascii)
   class_addMethod(class, selector, imp, types.p-ascii)
EndImport

Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")

ProcedureC Callback(obj, sel, notification)
   Debug "Callback()"
EndProcedure

selector = sel_registerName("Callback:")
class_addMethod(delegateClass, selector, @Callback(), "v@:@")
;CocoaMessage(0, GadgetID(0), "setTag:", @Callback())
CocoaMessage(0, GadgetID(0), "setTarget:", appDelegate)
CocoaMessage(0, GadgetID(0), "setAction:", selector)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

CocoaMessage(0, GadgetID(0), "setTarget:", #Null)
CocoaMessage(0, GadgetID(0), "setAction:", #Null)

Re: [PB Cocoa] Cocoa companion library

Posted: Fri Feb 08, 2013 6:43 pm
by wilbert
Niffo wrote:Thanks for your answer.
In fact, i use :
- Notification_Observe (WindowID(x), "") to receive all Window notifications in the Callback (seems to work in my code above)
- SetTargetActionCallback(GadgetID(x), @Callback()) to receive live events like drags in scrollbars and trackbars, ...
It's not an exact translation but I hope this will help
http://www.purebasic.fr/english/viewtop ... 84#p403784

Re: [PB Cocoa] Cocoa companion library

Posted: Fri Feb 08, 2013 7:42 pm
by Niffo
Thank you very much :)

Re: [PB Cocoa] Cocoa companion library

Posted: Sat Jan 11, 2014 1:18 am
by devulder
wilbert wrote:A lib to work with the Cocoa version of PureBasic.
The lib supports both x86 and x64. PPC is not supported.

x86 / x64 static library archive : http://www.waterlijn.info/pb/cocoa/libPBCocoa.zip
help file : http://www.waterlijn.info/pb/cocoa/help.zip
source : http://www.waterlijn.info/pb/cocoa/source.zip

Code: Select all

Command list
============

oAutorelease (Object)
oAutoreleasePool ()
oClass (ClassName.s)
oClassAddMethod (Class, Selector, Imp, Types.s)
oClassExists (ClassName.s)
oClassName (Object)
oCreateClass (Superclass, ClassName.s)
oDescription (Object)
oInheritance (Object)
oRegisterClass (Class)
oRelease (Object)
oRetain (Object)
oSel (Selector.s)

AppleScript (Script.s) - Execute AppleScript code.

Application_MemoryUsage() - Returns the memory usage of the application in bytes.
Application_SetBadgeText (Text.s) - Sets the badge text of the application.
Application_Uptime () - Returns the uptime of the application in seconds.

DoubleToNSNumber (Number.d [, Autorelease]) - Convert Double to NSNumber.

Editor_CatchRTF (GadgetID, *MemoryAddress, Size) - Catch rtf from memory.
Editor_LoadRTF (GadgetID, FileName.s) - Loads a rtf file.
Editor_PrintContent (GadgetID) - Print editor content.
Editor_SetBackgroundPattern (GadgetID, ImageID) - Sets a pattern to use as a background.
Editor_SetHTMLText (GadgetID, HTMLText.s) - Sets HTML text.
Editor_SetWordWrap (GadgetID, Wrap) - Sets word wrap to #True or #False.

EnableFullScreenButton (WindowID) - Enable OSX 10.7+ full screen button.

Gadget_BringToFront (GadgetID) - Bring gadget to front.
Gadget_SendToBack (GadgetID) - Send gadget to back.
Gadget_SetFilter (GadgetID, FilterObject) - Sets a gadget filter.

Image_Catch (*MemoryAddress, Size) - Catch image from memory.
Image_FilteredImage (ImageObject, FilterObject, CropToSource)
Image_GetHeight (ImageObject) - Gets the height of the image object.
Image_GetWidth (ImageObject) - Gets the width of the image object.
Image_Load (FileName.s) - Load image.
Image_Save (ImageObject, FileName.s, Type [, Compression.f]) - Saves the image object.

ImageFilter_ExposureAdjust (EV.f)
ImageFilter_GaussianBlur (Radius.f)
ImageFilter_Grayscale ()
ImageFilter_Posterize (Levels)

Local_DecimalSeparator () - Returns the decimal separator.
Local_Language () - Returns the local language code.
Local_OffsetFromGMT () - Returns the offset in seconds from GMT.

MacOSVersion () - Returns the OS version.

MainBundle_GetInfo (Key.s) - Gets info from main bundle Info.plist file.
MainBundle_ResourcePath () - Returns the resource path.

Menu_ItemAtIndex (MenuObject, Index1 [, Index2 [, Index3 [, Index4]]]) - Get menu item for index. 
Menu_ItemWithTitle (MenuObject, Title.s, ExactMatch) - Search for item with title.
Menu_SetItemEnabled (MenuItemObject, Enabled) - Sets the item to disabled(0), enabled(1) or hidden(-1).
Menu_SetItemKey (MenuItemObject, Key.s, Modifier) - Sets the key equivalent for the item.
Menu_SetItemToolTip (MenuItemObject, Tip.s) - Sets a tip for the item.

Message_OSD (Message.s [, FontSize.f]) - Display an OSD message.

Midi_Catch (*MemoryAddress, Size) - Catch midi from memory.
Midi_Load (FileName.s) - Load midi.
Midi_Play (MidiPlayer [, Loop]) - Starts playing midi.
Midi_Release (MidiPlayer) - Release the MidiPlayer object.
Midi_SendEvent (Status, Data1, Data2)
Midi_SetVolume (Volume.f) - Sets the volume for midi playback.
Midi_Stop (MidiPlayer) - Stops playing midi.

NSApp () - Returns the application instance.
NSNumberToDouble (Number) - Convert NSNumber to Double.
NSNumberToQuad (Number) - Convert NSNumber to Quad.
NSStringToString (String) - Convert NSString to String.

Notification_Observe (Object, NotificationName.s)
Notification_RemoveObserve (Object, NotificationName.s)
Notification_SetCallback (@NotificationCallback())

PDFViewer_CatchPDF (PDFViewerObject, *MemoryAddress, Size) - Catch pdf from memory.
PDFViewer_Create (WindowID, x, y, width, height) - Create a pdf viewer object.
PDFViewer_LoadPDF (PDFViewerObject, FileName.s) - Loads a pdf file.

QuadToNSNumber (Number.q [, Autorelease]) - Convert Quad to NSNumber.

SearchField_Create (WindowID, x, y, width, height) - Create a search field object.
SearchField_GetText (SearchField) - Gets the text of the search field.

SetTargetActionCallback(Control, @Callback())

SlideShow_PresentImages (@ImageID_Array(), ArraySize, AutoPlay) - Presents a slideshow of images.
SlideShow_PresentFiles (@FileNames_Array(), ArraySize, AutoPlay) - Presents a slideshow of files.

Sound_Catch (*MemoryAddress, Size) - Catch sound from memory.
Sound_IsPlaying (SoundObject) - Returns #True is the sound object is playing.
Sound_Load (FileName.s) - Load sound.
Sound_Play (SoundObject [, Loop]) - Starts playing the sound object.
Sound_Release (SoundObject) - Releases the sound object.
Sound_SetVolume (SoundObject, Volume.f) - Sets the volume of the sound object.
Sound_Stop (SoundObject) - Stops playing the sound object.

StringToNSString (String.s [, Autorelease]) - Convert String to NSString.

ToolBar_GetItemPos (ToolbarItemObject) - Gets the horizontal coordinate for an item containing a gadget.
ToolBar_ItemAtIndex (ToolbarID, Index) - Gets toolbar item for index.
ToolBar_SetItemGadget (ToolbarItemObject, GadgetID) - Sets the toolbar item gadget.
ToolBar_SetItemImage (ToolbarItemObject, ImageID) - Sets the toolbar item image.
ToolBar_SetItemLabel (ToolbarItemObject, Label.s) - Sets the toolbar item label.
ToolBar_SetMode (ToolbarID, DisplayMode, SizeMode) - Sets the toolbar mode.

UUID_Create() - Returns a universally unique identifier.

Window_SetAlpha (WindowID, Alpha.f) - Sets the alpha value of the window.
Window_SetBackgroundPattern (WindowID, ImageID) - Sets a pattern to use as a background for a window.
Hi,
What is procedure for install ?

Re: [PB Cocoa] Cocoa companion library

Posted: Sat Jan 11, 2014 3:27 am
by J. Baker
devulder wrote:
Hi,
What is procedure for install ?
Copy the x86 or x64 library to your "PureBasic/purelibraries/userlibraries/" folder. ;)

Re: [PB Cocoa] Cocoa companion library

Posted: Sat Jan 11, 2014 11:15 am
by devulder
thanks,

Re: [PB Cocoa] Cocoa companion library

Posted: Thu Mar 20, 2014 5:57 pm
by metalos
Hello Wilbert,

Your lib and really great congratulations for your work. 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. Thank you in advance.