diff --git a/src/bundle.nim b/src/bundle.nim deleted file mode 100644 index 54487b2..0000000 --- a/src/bundle.nim +++ /dev/null @@ -1,55 +0,0 @@ -import json, os, plists, times - -if paramCount() >= 1: - let fname = paramStr(1) - - let dt = now() - - let appAuthor = "Armando I. Rivera" - let appName = fname - let iconFile = "appIcon.icns" - let bundleIdentifier = "net.binarymagic." & appName - let appVersion = "0.1" - let appInfo = appVersion & " Created by " & appAuthor & " on " & dt.format("MM-dd-yyyy") - let appCopyRight = "Copyright" & dt.format(" yyyy ") & appAuthor & ". All rights reserved." - let appBundle = appName & ".app" - - if fname.len > 0: - var pl = %* - - { "CFBundlePackageType" : "APPL", - "CFBundleInfoDictionaryVersion" : "6.0", - "CFBundleName" : appName, - "CFBundleExecutable" : appName, - "CFBundleIconFile" : iconFile , - "CFBundleIdentifier" : bundleIdentifier , - "CFBundleVersion" : appVersion , - "CFBundleGetInfoString" : appInfo, - "CFBundleShortVersionString" : appVersion , - "NSHumanReadableCopyright" : appCopyRight , - "NSPrincipalClass" : "NSApplication" , - "NSMainNibFile" : "MainMenu" - } - - - createDir(appBundle & "/Contents/MacOS") - createDir(appBundle & "/Contents/Resources") - createDir(appBundle & "/Contents/Frameworks") - - if appName.fileExists: - appName.copyFileWithPermissions(appBundle & "/Contents/MacOS/" & appName) - - if iconFile.fileExists: - iconFile.copyFileWithPermissions(appBundle & "/Contents/Resources/" & iconFile) - - if "Credits.rtf".fileExists: - "Credits.rtf".copyFileWithPermissions(appBundle & "/Contents/Resources/Credits.rtf") - - - pl.writePlist(appBundle & "/Contents/Info.plist") - - discard execShellCmd("touch " & appBundle) - discard execShellCmd("open " & appBundle) -else: - echo "Usage: bundle " - diff --git a/src/cocoa.nim b/src/cocoa.nim deleted file mode 100644 index 7df5dd5..0000000 --- a/src/cocoa.nim +++ /dev/null @@ -1,7 +0,0 @@ -import Cocoa / [NSButton, NSCombobox, NSLabel, NSMenu, NSSavedialog, NSTextfield] -import Cocoa / [NSCheckbox, NSDialog, NSLine, NSMessagebox, NSSlider, NSWindow] -import Cocoa / [NSColordialog, NSFunctions, NSListbox, NSOpendialog, NSTextedit] - -export NSButton, NSCombobox, NSLabel, NSMenu, NSSavedialog, NSTextfield -export NSCheckbox, NSDialog, NSLine, NSMessagebox, NSSlider, NSWindow -export NSColordialog, NSFunctions, NSListbox, NSOpendialog, NSTextedit \ No newline at end of file diff --git a/src/cocoa/NSButton.nim b/src/cocoa/NSButton.nim deleted file mode 100644 index 452e81d..0000000 --- a/src/cocoa/NSButton.nim +++ /dev/null @@ -1,20 +0,0 @@ -{.compile: "widgets/button.m".} - -import NSFunctions - -proc newButton*(parent: ID; caption: cstring; left: cint; top: cint; width: cint; height: cint; `func`: ACTION): ID {.cdecl, importc: "createButton".} -## Creates new Button object -## -## Example: -## -## .. code-block::nim -## btn1 = newButton(mainWindow, "Open", width-100, 20, 90, 24, btnClicked) -## -## -## Callback must be in the form: -## -## .. code-block::nim -## proc buttonCB(sender: ID) {.cdecl.} = -## <..code...> -## - diff --git a/src/cocoa/NSCheckbox.nim b/src/cocoa/NSCheckbox.nim deleted file mode 100644 index 7eb01de..0000000 --- a/src/cocoa/NSCheckbox.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/checkbox.m".} - -import NSFunctions - -proc newCheckBox*(parent: ID, caption: cstring, left, top, width, height:int): ID {.cdecl, importc: "createCheckBox".} \ No newline at end of file diff --git a/src/cocoa/NSColordialog.nim b/src/cocoa/NSColordialog.nim deleted file mode 100644 index e69de29..0000000 diff --git a/src/cocoa/NSCombobox.nim b/src/cocoa/NSCombobox.nim deleted file mode 100644 index 91d8c8d..0000000 --- a/src/cocoa/NSCombobox.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/combobox.m".} - -import NSFunctions - -proc newComboBox*(parent: ID; left: cint; top: cint; width: cint; height: cint; `callback`: ACTION): ID {.cdecl, importc: "createComboBox".} \ No newline at end of file diff --git a/src/cocoa/NSContainer.nim b/src/cocoa/NSContainer.nim deleted file mode 100644 index 71c9ec8..0000000 --- a/src/cocoa/NSContainer.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/container.m".} - -import NSFunctions - -proc newContainer*(parent: ID, title: cstring; left: cint; top: cint; width: cint; height: cint): ID {.cdecl, importc: "createBox".} \ No newline at end of file diff --git a/src/cocoa/NSDialog.nim b/src/cocoa/NSDialog.nim deleted file mode 100644 index cde1073..0000000 --- a/src/cocoa/NSDialog.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/dialog.m".} - -# import NSFunctions - -proc newDialog*(title, message: cstring, height: cint): cint {.cdecl, importc: "createDialog".} \ No newline at end of file diff --git a/src/cocoa/NSFunctions.nim b/src/cocoa/NSFunctions.nim deleted file mode 100644 index 7579286..0000000 --- a/src/cocoa/NSFunctions.nim +++ /dev/null @@ -1,82 +0,0 @@ -{.compile: "widgets/functions.m".} -{.compile: "widgets/bind.m".} - -type - ID* = pointer - ACTION* = proc (a2: ID) {.cdecl.} - - -# WINDOW STYLES -const - NSWindowStyleMaskBorderless* = 0 - NSWindowStyleMaskTitled* = 1 shl 0 - NSWindowStyleMaskClosable* = 1 shl 1 - NSWindowStyleMaskMiniaturizable* = 1 shl 2 - NSWindowStyleMaskResizable* = 1 shl 3 - NSWindowStyleMaskUtilityWindow* = 1 shl 4 - NSWindowStyleMaskDocModalWindow* = 1 shl 6 - NSWindowStyleMaskNonactivatingPanel* = 1 shl 7 - NSWindowStyleMaskUnifiedTitleAndToolbar* = 1 shl 12 - NSWindowStyleMaskHUDWindow* = 1 shl 13 - NSWindowStyleMaskFullScreen* = 1 shl 14 - NSWindowStyleMaskFullSizeContentView* = 1 shl 15 - -# GUI ANCHOR SYSTEM -const - akNone* = 0 - akRight* = 1 - akWidth* = 2 - akLeft* = 4 - akBottom* = 8 - akHeight* = 16 - akFull* = 18 - akTop* = 32 - - # Flags for GUI Anchor System - - # akNone No Anchor - # akRight Anchor to Right of Window - # akWidth Anchor to Left and Right (width) - # akLeft Anchor to Left - # akBottom Anchor to Bottom - # akHeight Anchor to Top and Bottom - # akFull Anchor to Left/Right/Top/Bottom - # akTop Anchor to Top - -proc Cocoa_Init*() {.cdecl, importc: "Cocoa_Init".} - -proc Cocoa_Run*(a2: ID) {.cdecl, importc: "Cocoa_Run".} - -proc Cocoa_Quit*(a2: ID) {.cdecl, importc: "Cocoa_Quit".} - -proc Cocoa_About*() {.cdecl, importc: "Cocoa_About".} -proc `anchor=`*(widget: ID; value: cint) {.cdecl, importc: "Pin".} -proc `text=`*(widget: ID; txt: cstring) {.cdecl, importc: "SetText".} - -proc text*(widget: ID): cstring {.cdecl, importc: "GetText".} - -proc value*(widget: ID): cint {.cdecl, importc: "GetValue".} - -proc `value=`*(widget: ID; value: cint) {.cdecl, importc: "SetValue".} - -proc add*(widget: ID; txt: cstring) {.cdecl, importc: "AddItem".} - -proc `action=`*(widget: ID; `func`: ACTION) {.cdecl, importc: "SetAction".} - -proc `state=`*(widget: ID; state: bool) {.cdecl, importc: "SetState".} - -proc state*(widget: ID): cint {.cdecl, importc: "State".} - -proc clear*(widget: ID) {.cdecl, importc: "LB_Clear".} -proc `item=`(widget: ID; pos: cint) {.cdecl, importc: "SetItem".} -proc remove*(widget: ID; pos: cint) {.cdecl, importc: "RemoveItem".} -proc getColor*(panel: ID): cstring {.cdecl, importc: "getColor".} -proc hexColor*(cPanel: ID): cstring {.cdecl, importc: "hexColor".} - -proc Notify*(title: cstring; subtitle: cstring; text: cstring) {.cdecl, importc: "Notify".} - -proc newSeparator*(parent: ID; x: cint; y: cint; width: cint): ID {.cdecl, importc: "createLine".} - -proc link*( widget: ID, widgetIvar: cstring, target: ID, targetIvar: cstring) {.cdecl, importc:"bind".} - -proc `tooltip=`*(widget: ID, tip: cstring) {.cdecl, importc: "setToolTip".} \ No newline at end of file diff --git a/src/cocoa/NSLabel.nim b/src/cocoa/NSLabel.nim deleted file mode 100644 index 0b8564b..0000000 --- a/src/cocoa/NSLabel.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/label.m".} - -import NSFunctions - -proc newLabel*(parent: ID; txt: cstring, left, top, width, height: int): ID {.cdecl, importc: "createLabel".} \ No newline at end of file diff --git a/src/cocoa/NSLine.nim b/src/cocoa/NSLine.nim deleted file mode 100644 index 0562a61..0000000 --- a/src/cocoa/NSLine.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/line.m".} - -import NSFunctions - -proc newLine*(parent: ID, left, top, width: cint): ID {.cdecl, importc: "createLine".} \ No newline at end of file diff --git a/src/cocoa/NSListbox.nim b/src/cocoa/NSListbox.nim deleted file mode 100644 index 4b25d52..0000000 --- a/src/cocoa/NSListbox.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/listbox.m".} - -import NSFunctions - -proc newListBox*(parent: ID, left, top, width, height: cint): ID {.cdecl, importc: "createListBox".} \ No newline at end of file diff --git a/src/cocoa/NSMenu.nim b/src/cocoa/NSMenu.nim deleted file mode 100644 index f37adf2..0000000 --- a/src/cocoa/NSMenu.nim +++ /dev/null @@ -1,11 +0,0 @@ -{.compile: "widgets/menu.m".} - -import NSFunctions - -proc newMenu*(title: cstring): ID {.cdecl, importc: "createMenu".} -proc newMenuItem*(parent: ID, caption, key: cstring, `callback`:ACTION) {.cdecl, importc: "createMenuItem".} -proc newMenuSeparator*(parent: ID) {.cdecl, importc: "createMenuSeparator".} -proc setSystemAction*(widget: ID, title, actionName: cstring) {.cdecl, importc: "setSystemAction".} -proc newFileMenu*() {.cdecl, importc: "createFileMenu".} -proc newEditMenu*() {.cdecl, importc: "createEditMenu".} -proc newFormatMenu*() {.cdecl, importc: "createFormatMenu".} \ No newline at end of file diff --git a/src/cocoa/NSMessagebox.nim b/src/cocoa/NSMessagebox.nim deleted file mode 100644 index 1576c47..0000000 --- a/src/cocoa/NSMessagebox.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/messagebox.m".} - -# import NSFunctions - -proc newMessageBox*(title, message: cstring, height: cint): cint {.cdecl, importc: "createMessageBox".} diff --git a/src/cocoa/NSOpendialog.nim b/src/cocoa/NSOpendialog.nim deleted file mode 100644 index 9ee9791..0000000 --- a/src/cocoa/NSOpendialog.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/opendialog.m".} - -import NSFunctions - -proc newOpenDialog*(parent: ID, types: cstring): cstring {.cdecl, importc: "createOpenDialog".} \ No newline at end of file diff --git a/src/cocoa/NSRadioButton.nim b/src/cocoa/NSRadioButton.nim deleted file mode 100644 index f68c583..0000000 --- a/src/cocoa/NSRadioButton.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/radiobutton.m".} - -import NSFunctions - -proc newRadioButton*(parent: ID, caption: cstring; left: cint; top: cint; width: cint; height: cint; callback: ACTION): ID {.cdecl, importc: "createRadioButton".} \ No newline at end of file diff --git a/src/cocoa/NSSavedialog.nim b/src/cocoa/NSSavedialog.nim deleted file mode 100644 index b579975..0000000 --- a/src/cocoa/NSSavedialog.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/savedialog.m".} - -import NSFunctions - -proc newSaveDialog*(parent: ID, title: cstring, types: cstring): cstring {.cdecl, importc: "createSaveDialog".} \ No newline at end of file diff --git a/src/cocoa/NSSlider.nim b/src/cocoa/NSSlider.nim deleted file mode 100644 index d6137ac..0000000 --- a/src/cocoa/NSSlider.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/slider.m".} - -import NSFunctions - -proc newSlider*(parent: ID; left, top, width, height: int, `func`: ACTION): ID {.cdecl, importc: "createSlider".} \ No newline at end of file diff --git a/src/cocoa/NSTabView.nim b/src/cocoa/NSTabView.nim deleted file mode 100644 index 1905984..0000000 --- a/src/cocoa/NSTabView.nim +++ /dev/null @@ -1,8 +0,0 @@ -{.compile: "widgets/tabview.m".} - -import NSFunctions - -proc newTabBox*(parent: ID, label: cstring; left: cint; top: cint; width: cint; height: cint): ID {.cdecl, importc: "createTabView".} - -proc addTab*(parent: ID, label: cstring) {.cdecl, importc: "addTab".} -proc getTab*(parent: ID, label: cstring): ID {.cdecl, importc: "getTab".} \ No newline at end of file diff --git a/src/cocoa/NSTableview.nim b/src/cocoa/NSTableview.nim deleted file mode 100644 index 7d6f985..0000000 --- a/src/cocoa/NSTableview.nim +++ /dev/null @@ -1,9 +0,0 @@ -{.compile: "widgets/tableview.m".} - -import NSFunctions - -proc newTableview*(parent: ID, left, top, width, height: cint): ID {.cdecl, importc: "createTableView".} -proc addColumn*(parent: ID, name: cstring) {.cdecl, importc: "newTableColumn".} -proc addRow*(parent: ID, person: cstring) {.cdecl, importc: "addRow".} -proc saveTableView*(tview: ID, path: cstring) {.cdecl, importc: "tableviewSaveToFile".} -proc loadTableView*(tview: ID, path: cstring) {.cdecl, importc: "tableviewLoadFromFile".} \ No newline at end of file diff --git a/src/cocoa/NSTextedit.nim b/src/cocoa/NSTextedit.nim deleted file mode 100644 index 0de4deb..0000000 --- a/src/cocoa/NSTextedit.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/textedit.m".} - -import NSFunctions - -proc newTextEdit*(parent: ID; txt: cstring, left, top, width, height: int): ID {.cdecl, importc: "createTextEdit".} \ No newline at end of file diff --git a/src/cocoa/NSTextfield.nim b/src/cocoa/NSTextfield.nim deleted file mode 100644 index f60a29a..0000000 --- a/src/cocoa/NSTextfield.nim +++ /dev/null @@ -1,5 +0,0 @@ -{.compile: "widgets/textfield.m".} - -import NSFunctions - -proc newTextField*(parent: ID; txt: cstring; left: cint; top: cint; width: cint; height: cint): ID {.cdecl, importc: "createTextField".} \ No newline at end of file diff --git a/src/cocoa/NSWindow.nim b/src/cocoa/NSWindow.nim deleted file mode 100644 index 14a1524..0000000 --- a/src/cocoa/NSWindow.nim +++ /dev/null @@ -1,8 +0,0 @@ -{.compile: "widgets/window.m".} -{.compile: "widgets/saneview.m".} - -import NSFunctions - -{.passL: "-fobjc-arc -framework Cocoa"} - -proc newWindow*(title: cstring, width, height: int, style: int): ID {.importc: "createWindow".} diff --git a/src/cocoa/col.nim b/src/cocoa/col.nim deleted file mode 100644 index f6ee1ae..0000000 --- a/src/cocoa/col.nim +++ /dev/null @@ -1,119 +0,0 @@ -{.pragma: libcol_s, cdecl.} -{.passL: "-fobjc-arc -framework Cocoa -lcol_s"} - - -type - id* = pointer - ACTION* = proc (a1: id) {.cdecl.} - - -const - akNone* = 0 - akRight* = 1 - akWidth* = 2 - akLeft* = 4 - akBottom* = 8 - akHeight* = 16 - akFull* = 18 - akTop* = 32 - - -proc newWindow*(title: cstring; width: cint; height: cint): id {.cdecl, importc: "createWindow".} - -proc Pin(widget: id; value: cint) {.cdecl, importc: "Pin".} - -proc Cocoa_Init*() {.cdecl, importc: "Cocoa_Init".} - -proc Cocoa_Run*(a2: id) {.cdecl, importc: "Cocoa_Run".} - -proc Cocoa_Quit*(a2: id) {.cdecl, importc: "Cocoa_Quit".} - -proc Cocoa_About*() {.cdecl, importc: "Cocoa_About".} - -proc SetText(widget: id; txt: cstring) {.cdecl, importc: "SetText".} - -proc GetText(widget: id): cstring {.cdecl, importc: "GetText".} - -proc GetValue(widget: id): cint {.cdecl, importc: "GetValue".} - -proc SetValue(widget: id; value: cint) {.cdecl, importc: "SetValue".} - -proc AddItem(widget: id; txt: cstring) {.cdecl, importc: "AddItem".} - -proc newTextField*(parent: id; txt: cstring; l: cint; t: cint; w: cint; h: cint): id {.cdecl, importc: "createTextField".} - -proc newComboBox*(parent: id; l: cint; t: cint; w: cint; h: cint; callback: ACTION): id {.cdecl, importc: "createComboBox".} - -proc newButton*(parent: id; caption: cstring; l: cint; t: cint; w: cint; h: cint; `func`: ACTION): id {.cdecl, importc: "createButton".} - -proc SetAction(widget: id; `func`: ACTION) {.cdecl, importc: "SetAction".} -proc newCheckBox*(parent: id; caption: cstring; l: cint; t: cint; w: cint; h: cint): id {.cdecl, importc: "createCheckBox".} - -proc SetState(widget: id; state: bool) {.cdecl, importc: "SetState".} - -proc State(widget: id): cint {.cdecl, importc: "State".} - -proc newListBox*(parent: id; l: cint; t: cint; w: cint; h: cint): id {.cdecl, importc: "createListBox".} - -proc Clearitems*(widget: id) {.cdecl, importc: "LB_Clear".} -proc SetItem*(widget: id; pos: cint) {.cdecl, importc: "SetItem".} -proc RemoveItem*(widget: id; pos: cint) {.cdecl, importc: "RemoveItem".} -proc newOpenDialog*(parent: id; types: cstring): cstring {.cdecl, importc: "createOpenDialog".} - -proc newSaveDialog*(parent: id; title: cstring; types: cstring): cstring {.cdecl, importc: "createSaveDialog".} - -proc newDialog*(title: cstring; message: cstring; `type`: cint): cint {.cdecl, importc: "createDialog".} -proc newMessageBox*(title: cstring; message: cstring; `type`: cint): cint {.cdecl, importc: "createMessageBox".} - -proc newColorDialog*(): id {.cdecl, importc: "createColorDialog".} -proc getColor*(panel: id): cstring {.cdecl, importc: "getColor".} -proc hexColor*(cPanel: id): cstring {.cdecl, importc: "hexColor".} -proc newLabel*(parent: id; txt: cstring; l: cint; t: cint; w: cint; h: cint): id {.cdecl, importc: "createLabel".} - -proc newTextEdit*(parent: id; txt: cstring; l: cint; t: cint; w: cint; h: cint): id {.cdecl, importc: "createTextEdit".} - -proc Notify*(title: cstring; subtitle: cstring; text: cstring) {.cdecl, importc: "Notify".} - -proc newSeparator*(parent: id; x: cint; y: cint; width: cint): id {.cdecl, importc: "createLine".} -proc newMenu*(Title: cstring): id {.cdecl, importc: "createMenu".} -proc newMenuItem*(parent: id; caption: cstring; key: cstring; callback: ACTION) {.cdecl, importc: "createMenuItem".} -proc newMenuSeparator*(parent: id) {.cdecl, importc: "createMenuSeparator".} -proc newSlider*(parent: id; left: cint; top: cint; width: cint; height: cint; callback: ACTION): id {.cdecl, importc: "createSlider".} - -proc `text=`*(widget: id; txt: cstring) = - widget.SetText(txt) - -proc `reset`*(widget: id) = - widget.SetText("") - -proc `text`*(widget: id): string = - $GetText(widget) - -# proc `item`*(widget: id): cstring = -# GetItem(widget) - -proc `anchor=`*(widget: id; value: cint) = - widget.Pin(value) - -proc `state`*(widget: id): cint = - widget.State() - -proc `state=`*(widget: id; val: bool) = - widget.SetState(val) - -proc `item=`*(widget: id, val: cstring) = - widget.AddItem(val) - -proc `item`*(widget: id): string = - $GetText(widget) - -proc action*(widget: id, action:ACTION) = - SetAction(widget, action) - -proc value*(widget: id, value: cint) = - SetValue(widget, value) - -proc value*(widget: id): cint = - GetValue(widget) - -# #endif \ No newline at end of file diff --git a/src/cocoa/widgets/bind.m b/src/cocoa/widgets/bind.m deleted file mode 100644 index 3fc2279..0000000 --- a/src/cocoa/widgets/bind.m +++ /dev/null @@ -1,6 +0,0 @@ -#import - - -void bind( id widget, const char * widgetIvar, id target, const char *targetIvar) { - [widget bind: [NSString stringWithUTF8String: widgetIvar] toObject: target withKeyPath:[NSString stringWithUTF8String: targetIvar] options:nil]; -} \ No newline at end of file diff --git a/src/cocoa/widgets/button.m b/src/cocoa/widgets/button.m deleted file mode 100644 index 3392883..0000000 --- a/src/cocoa/widgets/button.m +++ /dev/null @@ -1,34 +0,0 @@ -#import - -#import "col.h" - - - - -@implementation CocoaButton - - @synthesize buttonAction; - - - - (void) click:(id)sender { - buttonAction(sender); -} -@end - -id createButton(id parent, const char* caption, int l, int t, int w, int h, ACTION func){ - CocoaButton *widget = [[[CocoaButton alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - [widget setButtonType:NSMomentaryPushInButton]; - [widget setBezelStyle: NSRoundedBezelStyle]; - [widget setTitle: [NSString stringWithUTF8String:caption]]; - [widget setTarget: widget]; -// [widget setAutoresizingMask: NSViewMinXMargin ]; - - if (func) { - [widget setButtonAction:func]; - [widget setAction: @selector(click:)]; - } - addToParent(parent, widget); - - return widget; -} - diff --git a/src/cocoa/widgets/checkbox.m b/src/cocoa/widgets/checkbox.m deleted file mode 100644 index 7cdf252..0000000 --- a/src/cocoa/widgets/checkbox.m +++ /dev/null @@ -1,53 +0,0 @@ -#import - -#import "col.h" - -@interface CocoaCheckbox : NSButton - { - int state; - } - @property int state; - - (void) click:(id)sender; -@end - -@implementation CocoaCheckbox - - @synthesize state; - - - (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - if (self) { - [self setButtonType:NSSwitchButton]; - [self setBezelStyle: 0]; - - [self setTarget: self]; - [self setAction: @selector(click:)]; - } - return self; - } - - - (void) click:(id)sender { - self.state = [self intValue]; - } -@end - -id createCheckBox(id parent, const char* caption, int l, int t, int w, int h){ - id self = [[[CocoaCheckbox alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - [self setTitle: [NSString stringWithUTF8String:caption]]; - - addToParent(parent, self); - - return self; -} - -void SetState(id widget, bool state) { - if (state == TRUE) { - [widget setState: NSOnState]; - }else{ - [widget setState: NSOffState]; - } -} - -int State(id widget) { - return [widget state]; -} diff --git a/src/cocoa/widgets/col.h b/src/cocoa/widgets/col.h deleted file mode 100644 index 9a729c0..0000000 --- a/src/cocoa/widgets/col.h +++ /dev/null @@ -1,630 +0,0 @@ -#import - -#ifdef __cplusplus - extern "C" { -#endif - - typedef void* id; - #define NSSTR(txt) [NSString stringWithUTF8String:txt] - #define BeginMenu dispatch_async(dispatch_get_main_queue(), ^{ - #define EndMenu }); - - - #ifndef NSWindowStyleMaskTitled - #define NSWindowStyleMaskTitled NSTitledWindowMask - #endif - - #ifndef NSWindowStyleMaskClosable - #define NSWindowStyleMaskClosable NSClosableWindowMask - #endif - - #ifndef NSWindowStyleMaskMiniaturizable - #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask - #endif - - #ifndef NSWindowStyleMaskResizable - #define NSWindowStyleMaskResizable NSResizableWindowMask - #endif - - #ifndef NSAlertStyleWarning - #define NSAlertStyleWarning NSWarningAlertStyle - #endif - - #ifndef NSTextAlignmentLeft - #define NSTextAlignmentLeft NSLeftTextAlignment - #endif - - #ifndef NSAlertStyleWarning - #define NSAlertStyleWarning NSWarningAlertStyle - #endif - - #ifndef NSEventTypeKeyDown - #define NSEventTypeKeyDown NSKeyDown - #endif - - #ifndef NSEventModifierFlagCommand - #define NSEventModifierFlagCommand NSCommandKeyMask - #endif - - #ifndef NSEventModifierFlagOption - #define NSEventModifierFlagOption NSAlternateKeyMask - #endif - - - - typedef void(*ACTION)(id); - /** - Used by Internal Callback System - to route callback to user provided - subroutine - - Subroutine must not return value - - Ex: - void Example(void); - */ - - typedef void(*EVENT_ACTION)(id, const char*); - - enum { - akNone, - akRight, - akWidth, - akLeft = 4, - akBottom = 8, - akHeight = 16, - akFull = 18, - akTop = 32 - - }; - /** - Flags for Widget Anchor System - - akNone No Anchor - akRight Anchor to Right of Window - akWidth Anchor to Left and Right (width) - akLeft Anchor to Left - akBottom Anchor to Bottom - akHeight Anchor to Top and Bottom - akTop Anchor to Top - */ - - @interface SaneView : NSClipView - - (BOOL)isFlipped; - @end - - @interface CocoaWindow : NSWindow - { - // NOT USED - } - - - (void)applicationDidFinishLaunching: (NSNotification *)notification; - - (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification; - - (id) initFormWithTitle:(NSString*)title width:(NSInteger)width height:(NSInteger)height windowStyle: (NSWindowStyleMask) style; - - (void)createApplicationMenu; - @end - - @interface awColorPanel: NSColorPanel { - NSColor* theColor; - NSModalSession modalSession; - } - @property (copy) NSColor* theColor; - - - (void)colorUpdate:(NSColorPanel*)colorPanel; - - -(void)changeColor:(id)sender; - - - (const char *) hexColor; - @end - - @interface CocoaListBox : NSScrollView - { - NSTableView *tbl; - NSTableColumn *tblc; - NSMutableArray *db; - - - int cnt; - } - @property (retain) NSTableView *tbl; - @property (retain) NSMutableArray *db; - - - - (id)initWithFrame:(NSRect)frame; - - (void)doubleclicked:(id)sender; - - (void)selected:(id)sender; - @end - - @interface CocoaTableView : NSScrollView - { - NSTableView *tbl; - NSTableColumn *tblc; - NSTableColumn *tbld; - NSMutableArray *db; - NSMutableDictionary *dict; - - - int cnt; - } - @property (retain) NSTableView *tbl; - @property (retain) NSMutableArray *db; - @property (retain) NSMutableDictionary *dict; - - - - (id)initWithFrame:(NSRect)frame; - - (void)doubleclicked:(id)sender; - - (void)selected:(id)sender; - @end - - @interface CocoaButton: NSButton{ - ACTION buttonAction; - EVENT_ACTION eventAction; - } - @property ACTION buttonAction; - @property EVENT_ACTION eventAction; - - - - (void) click:(id)sender; - - (void)mouseEntered:(NSEvent *)theEvent; - - (void)mouseExited:(NSEvent *)theEvent; - @end - - @interface RadioButton: NSButton{ - ACTION buttonAction; - } - @property ACTION buttonAction; - - - - (void) click:(id)sender; - @end - @interface CocoaComboBox : NSComboBox { - // NSInteger currentItem; - ACTION comboCallBack; - } - - @property ACTION comboCallBack; - @property NSInteger currentItem; - - - (id)initWithFrame:(NSRect)frame; - - /* notification responders */ - - (void)comboBoxSelectionDidChange:(NSNotification *)notification; - - @end - - @interface CocoaTextEdit : NSScrollView - { - NSTextView *widget; - } - @property (retain) NSTextView *widget; - - (id)initWithFrame:(NSRect)frame; - @end - - @interface CocoaMenu : NSMenu - { - ACTION menuAction; - } - - @property (retain) NSMenu *menu; - @property ACTION menuAction; - - - - (void) CreateMenu: (NSString*) Title; - - (void) AddItem: (NSString*)Title withShortcut: (NSString*)key andCallback: (ACTION) callback; - // - (void) click:(id)sender; - - (void) SetAction: (id) widget Callback: (ACTION) func; - - (void)addSeparator; - //- (void) click:(id)sender; - - @end - - @interface CocoaMenuItem : NSMenuItem - { - ACTION menuItemAction; - } - @property ACTION menuItemAction; - - - (void) click:(id)sender; - @end - - @interface CocoaSlider: NSSlider - { - int Value; - ACTION sliderAction; - } - @property int Value; - @property ACTION sliderAction; - - - (IBAction)onChanged:(id)sender; - - (id) initWithFrame:(NSRect)rect callBack:(ACTION)func; -@end - - id createWindow(const char* title, int width, int height, NSWindowStyleMask style); - /** - \brief Creates Main Window - - parameters: - String: Title of Window, - INT: Width of Window, - INT: Height of Window - - Returns: - Pointer: Created Window - */ - - void Pin(id widget, NSInteger value); - /** - \brief Specifies how child widget responds to resize of Parent - - parameters: - Pointer: Widget - INT: Anchor point (see Enum above) - - Returns: - None - */ - - void Cocoa_Init(); - /** - \brief Initializes Cocoa GUI - - parameters: - None - - Returns: - None - */ - - void Cocoa_Run(); - /** - \brief Passes control over to Cocoa Runtime - - parameters: - None - - Returns: - None - */ - - void Cocoa_Quit(); - /** - \brief Terminates Cocoa Runtime - - parameters: - None - - Returns: - None - */ - - void Cocoa_About(); - /** - \brief Displays Cocoa About Dialog - - parameters: - None - - Returns: - None - - Note: - Utilizes information contained in Application Bundle's Info.plist - */ - - void SetText(id widget, const char* txt); - /** - \brief Sets Widget Text - - parameters: - Pointer: Target Widget - Text to set - - Returns: - None - */ - - const char* GetText(id widget); - /** - \brief Retrives Text from Widget - - parameters: - Pointer: Target Widget - - Returns: - String: from Widget - */ - - int GetValue(id widget); - /** - \brief Retrieves INT value from Widget - parameters: - Pointer: Target Widget - - Returns: - integer: from Widget - */ - - void SetValue(id widget, int value); - /** - \brief Sets INT value for Widget - parameters: - Pointer: Target Widget - INT: Value to set - - */ - - void AddItem(id widget, const char* txt ); - /** - \brief Adds TEXT Item to ComboBox/ListBox - - parameters: - Pointer: Target Widget - String: Text to Add - - Returns: - None - */ - - // char* GetItem(id widget); - /** - \brief Retrieves Selected Text from ComboBox/ListBox - - parameters: - Pointer: Target Widget - - Returns: - String: Text of Selected Item - */ - - id createTextField(id parent,const char* txt,int l, int t, int w, int h); - /** - \brief Creates TextField (TextBox/TextEntry) Widget - - parameters: - Pointer: Parent Widget, - String: Default Text to Display, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget - - Returns: - Pointer: Created TextField - */ - - id createComboBox(id parent,int l, int t, int w, int h, ACTION callback); - /** - \brief Creates ComboBox Widget - - parameters: - Pointer: Parent Widget, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget, - ACTION: Callback Function or NULL - - Returns: - Pointer: Created ComboBox - */ - - id createButton(id parent, const char* caption, int l, int t, int w, int h, ACTION func); - /** - \brief Creates Button Widget - - parameters: - Pointer: Parent Widget, - String: Button Caption, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget, - ACTION: Callback Function or NULL - - Returns: - Pointer to Created Button - */ - - void SetAction(id widget, SEL func); - - id createCheckBox(id parent, const char* caption, int l, int t, int w, int h); - /** - \brief Creates CheckBox Widget - - parameters: - Pointer: Parent Widget, - String: CheckBox Caption, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget, - ACTION: Callback Function or NULL - - Returns: - Pointer to Created TextField - */ - - void SetState(id widget, bool state); - /** - \brief Sets State of CheckBox Widget (Checked/Unchecked) - - parameters: - Pointer: Parent Widget, - BOOL: State (True for on, False for off) - - Returns: - None - */ - - int State(id widget); - /** - \brief Retrieves State of Checkbox (On[True], Off[False]) - - parameters: - Pointer: Checkbox Widget, - - Returns: - BOOL: State [True/False] - */ - - id createRadioButton(id parent, const char* caption, int l, int t, int w, int h, ACTION func); - /** - \brief Creates RadioButton Widget - - parameters: - Pointer: Parent Widget, - String: Button Caption, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget, - ACTION: Callback Function or NULL - - Returns: - Pointer to Created RadioButton - */ - - id createListBox(id parent,int l, int t, int w, int h); - /** - \brief Creates ListBox Widget - - parameters: - Pointer: Parent Widget, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget - - Returns: - Pointer: Created ListBox Widget - */ - - void LB_Clear(id widget); - void SetItem(id widget, int pos); - void RemoveItem(id widget, int pos); - - - char* createOpenDialog( id parent, const char *types); - /** - \brief Displays OpenFile Dialog Widget - - parameters: - Pointer: Parent Widget, - String: File Types Filter, separated by ":" - - Returns: - String: Path to Selected File, or Blank String - - Example: - char *fName = OpenDialog(mywin,"txt:c:h"); - */ - - char* createSaveDialog(id parent, const char* title, const char *types); - /** - \brief Displays SaveFile Dialog Widget - - parameters: - Pointer: Parent Widget, - String: Dialog Title, - String: File Types Filter, separated by ":" - - Returns: - String: Path to Selected File, or Blank String - - Example: - char *fName = SaveDialog(mywin,"txt:c:h"); - */ - - int createDialog(const char *title, const char *message, int type); - int createMessageBox(const char *title, const char *message, int type); - /** - \brief Displays MessageBox Dialog Widget - - parameters: - String: Dialog Title, - String: Message to Display, - INT: Type of Dialog(?) - - Returns: - INT: Value corresponding to OK or Cancel - - Example: - char *fName = SaveDialog(mywin,"txt:c:h"); - */ - - id createColorDialog(); - id getColor(id panel); - void setColor(id target, id source); - - const char* hexColor(id cPanel); - - id createLabel(id parent, const char* txt, int l, int t, int w, int h); - /** - \brief Creates Label Widget - - parameters: - Pointer: Parent Widget, - String: Caption of Label, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget - - Returns: - Pointer: Label Widget - */ - - id createTextEdit(id parent, const char* txt, int l, int t, int w, int h); - /** - \brief Creates TextEdit Widget - - parameters: - Pointer: Parent Widget, - String: Default Text, - INT: Left Position in Parent, - INT: Top Position in Parent, - INT: Width of Widget, - INT: Height of Widget - - Returns: - Pointer: Label Widget - */ - - void Notify(const char *title, const char * subtitle, const char *text); - /** - \brief Sends Notification to macOS Notification System - - parameters: - String: Title of Notification, - String: Subtitle of Notification, - String: Message to Display - - Returns: - None - */ - - id createLine(id parent, int x, int y, int width); - - id createMenu(const char * Title); - void createMenuItem(id parent, const char *caption, const char *key, ACTION callback); - void createMenuSeparator(id parent); - - id createSlider(id parent, int left, int top, int width, int height, ACTION callback); - - void addToParent(id parent, id child); - - id createBox(id parent, const char* title, int x, int y, int width, int height); - - id createRadioButton(id parent, const char* caption, int l, int t, int w, int h, ACTION func); - - id createTabView(id parent, const char *label, int x, int y, int width, int height); - void addTab(id parent, const char *name); - id getTab(id parent, const char *name); - - void eventAction(id widget, EVENT_ACTION callback); - -#ifdef __cplusplus - } -#endif - -// #endif diff --git a/src/cocoa/widgets/colordialog.m b/src/cocoa/widgets/colordialog.m deleted file mode 100644 index c85847d..0000000 --- a/src/cocoa/widgets/colordialog.m +++ /dev/null @@ -1,47 +0,0 @@ -#import - -#include "col.h" - - - - - -@implementation awColorPanel - @synthesize theColor; - - - (void)colorUpdate:(awColorPanel*)colorPanel{ - theColor = colorPanel.color; -// printf("%s\n",[self hexColor]); - } - - - (const char *) hexColor { - NSString* hexString = [NSString stringWithFormat:@"%02X%02X%02X", - (int) (theColor.redComponent * 0xFF), - (int) (theColor.greenComponent * 0xFF), - (int) (theColor.blueComponent * 0xFF)]; - return [hexString UTF8String]; - } -@end - -id createColorDialog() { - NSColorPanel *cp = [awColorPanel sharedColorPanel]; - [cp setTarget:cp]; - [cp setAction:@selector(colorUpdate:)]; - // [NSApp runModalForWindow: cp]; - [cp makeKeyAndOrderFront:nil]; - - return cp; - -} - -const char* hexColor(awColorPanel* cPanel) { - return [cPanel hexColor]; -} - -id getColor(id panel) { - return theColor; -} - -void setColor(id target, id source) { - [target setBackgroundColor: [source color]]; -} \ No newline at end of file diff --git a/src/cocoa/widgets/combobox.m b/src/cocoa/widgets/combobox.m deleted file mode 100644 index fe81f48..0000000 --- a/src/cocoa/widgets/combobox.m +++ /dev/null @@ -1,44 +0,0 @@ -#import - -#import "col.h" - - - -@implementation CocoaComboBox - -@synthesize currentItem; -@synthesize comboCallBack; - -- (id)initWithFrame:(NSRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - [self setEditable: NO]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(comboBoxSelectionDidChange:) - name:NSComboBoxSelectionDidChangeNotification - object:self]; - } - return self; -} - -- (void)comboBoxSelectionDidChange:(NSNotification *)notification { - // [self setCurrentItem: [self indexOfSelectedItem]]; - self.currentItem = [self indexOfSelectedItem]; - if (self.comboCallBack != NULL) comboCallBack(self); -} -@end - -id createComboBox(id parent,int l, int t, int w, int h, ACTION callback){ - id widget = [[[CocoaComboBox alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - if (callback) { - [widget setComboCallBack:callback]; - // [widget setAction: @selector(click:)]; - } - - addToParent(parent, widget); - - return widget; -} - diff --git a/src/cocoa/widgets/container.m b/src/cocoa/widgets/container.m deleted file mode 100644 index 47ec76a..0000000 --- a/src/cocoa/widgets/container.m +++ /dev/null @@ -1,17 +0,0 @@ -#import - -#import "col.h" - - -id createBox(id parent, const char* title, int x, int y, int width, int height) { - id widget = [[[NSBox alloc] initWithFrame: NSMakeRect(x, y, width, height)] autorelease]; - [widget setTitle: [NSString stringWithUTF8String: title]]; - - // Do we need to create a contentView??? - id sv = [[[SaneView alloc] initWithFrame: NSZeroRect] autorelease]; - [sv setBackgroundColor: [NSColor windowBackgroundColor]]; - [widget setContentView: sv]; - [widget setBorderType: NSLineBorder]; - addToParent(parent, widget); - return widget; -} \ No newline at end of file diff --git a/src/cocoa/widgets/dialog.m b/src/cocoa/widgets/dialog.m deleted file mode 100644 index 39af961..0000000 --- a/src/cocoa/widgets/dialog.m +++ /dev/null @@ -1,15 +0,0 @@ -#import - -#include "col.h" - - -int createDialog(const char *title, const char *message, int type) { - NSAlert *alert = [[NSAlert new] autorelease]; - [alert addButtonWithTitle:@"Continue"]; - [alert addButtonWithTitle:@"Cancel"]; - [alert setMessageText:[NSString stringWithUTF8String:title] ]; - [alert setInformativeText:[NSString stringWithUTF8String:message] ]; - [alert setAlertStyle:NSAlertStyleWarning]; - return [alert runModal]; -} - diff --git a/src/cocoa/widgets/functions.m b/src/cocoa/widgets/functions.m deleted file mode 100644 index e734204..0000000 --- a/src/cocoa/widgets/functions.m +++ /dev/null @@ -1,183 +0,0 @@ -#import - -#import "col.h" - -void Pin(id widget, NSInteger value) { - [(NSView*)widget setAutoresizingMask: value]; -} - -void SetText(id widget, const char* txt){ - NSString *widgetClass = [[widget class] description]; - - if ([widgetClass isEqualToString:@"CocoaTextEdit"]) - { - [[widget documentView] setString: [NSString stringWithUTF8String: txt]]; - [widget setNeedsDisplay: YES]; - }else if ([widgetClass isEqualToString:@"CocoaWindow"]) { - [widget setTitle: [NSString stringWithUTF8String: txt]]; - }else{ - [widget setStringValue:[NSString stringWithUTF8String:txt]]; - } -} - -void AddItem(id widget, const char* txt ){ - NSString *widgetClass = [[widget class] description]; - - /* ListBox */ - if ([widgetClass isEqualToString:@"CocoaListBox"] || [widgetClass isEqualToString:@"CocoaTableView"]) - { - [[widget db] addObject: [NSString stringWithUTF8String: txt]]; - [[widget tbl] reloadData]; - }else{ - /* ComboBox */ - [widget addItemWithObjectValue:[NSString stringWithUTF8String:txt]]; - } -} - -const char* GetText(id widget) { - NSString *widgetClass = [[widget class] description]; - - /* ListBox */ - if ([widgetClass isEqualToString:@"CocoaListBox"]) { - NSInteger row = [[widget tbl] selectedRow]; - // NSString *dbValue = [[widget db]objectAtIndex:row]; - // return strdup([dbValue UTF8String]); - return [[[widget db]objectAtIndex:row] UTF8String]; - - /* TextEdit */ - }else if ([widgetClass isEqualToString:@"CocoaTextEdit"]) { - if ( [[[widget documentView] string] length] > 0) { - return [[[widget documentView] string] UTF8String]; - }else{ - return @"".UTF8String; - } - // const char* str = [[[widget textStorage] string] UTF8String]; - // if (strlen(str)>0) { - // return strdup(str); - // }else{ - // return strdup(""); - // } - /* ComboBox */ - }else if ([widgetClass isEqualToString: @"CocoaComboBox"]) { - return [[widget objectValueOfSelectedItem] UTF8String]; - - /* RadioButton, Box */ - }else if ([widgetClass isEqualToString: @"RadioButton"] || [widgetClass isEqualToString: @"NSBox"]) { - return [[widget title] UTF8String]; - - }else{ - /* Everything Else */ - return [[widget stringValue] UTF8String]; - } -} - -int GetValue(id widget) { - NSString *widgetClass = [[widget class] description]; - - /* Slider */ - if ([widgetClass isEqualToString: @"CocoaSlider"]) { - return [widget Value]; - } - return 0; -} - -void SetValue(id widget, int value) { - NSString *widgetClass = [[widget class] description]; - - /* Slider */ - if ([widgetClass isEqualToString: @"CocoaSlider"]) { - [widget setIntValue:value]; - } -} - -void SetItem(id widget, int pos) { - NSString *widgetClass = [[widget class] description]; - if ([widgetClass isEqualToString:@"CocoaListbox"]) { - NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:pos]; - [widget selectRowIndexes: indexSet byExtendingSelection:NO]; - }else if ([widgetClass isEqualToString:@"CocoaComboBox"]) { - [widget selectItemAtIndex:pos]; - [widget setObjectValue:[widget objectValueOfSelectedItem]]; - } -} - -void RemoveItem(id widget, int index) { - NSString *widgetClass = [[widget class] description]; - - if ([widgetClass isEqualToString:@"CocoaListBox"]) { - [[widget db]removeObjectAtIndex: index]; - [[widget tbl] reloadData]; - }else if ([widgetClass isEqualToString:@"CocoaComboBox"]) { - [widget removeItemAtIndex: index]; - } -} - -void LB_Clear(id widget) { - [[widget db] removeAllObjects]; - [[widget tbl] reloadData]; -} - -void Cocoa_Init() { - [NSApplication sharedApplication]; - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; -} - -void Cocoa_Run() { - // NSApplicationMain(0,0); - // [NSApp setDelegate:mainWin]; - [NSApp activateIgnoringOtherApps:YES]; - [NSApp run]; -} - -void Cocoa_Quit() { - [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0]; -} - -void Cocoa_About() { - [NSApp performSelector:@selector(orderFrontStandardAboutPanel:) withObject:nil afterDelay:0.0]; -} - -void Notify(const char *title, const char * subtitle, const char *text) { - if (strlen(title)>0 && strlen(text)>0) { - - NSUserNotificationCenter *nc = NSUserNotificationCenter.defaultUserNotificationCenter; - - NSUserNotification *note = NSUserNotification.new; - note.title = [NSString stringWithUTF8String:title]; - note.subtitle = [NSString stringWithUTF8String:subtitle]; - note.informativeText = [NSString stringWithUTF8String:text]; - note.soundName = NSUserNotificationDefaultSoundName; - - [nc deliverNotification:note]; - - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - - } - -} - -void addToParent(id parent, id child) { - NSString *widgetClass = [[parent class] description]; - if ([widgetClass isEqualToString:@"NSTabViewItem"]) { - [[parent view] addSubview: child]; - } else { - [[parent contentView] addSubview: child]; - } -} - -void setToolTip(id widget, const char *tooltip) { - [widget setToolTip: [NSString stringWithUTF8String: tooltip]]; -} - -void eventAction(id widget, EVENT_ACTION callback) { - [widget setEventAction: callback]; -} - -void setSystemAction(id widget, const char *Title, const char *actionName) { - SEL selector = NSSelectorFromString(NSSTR(actionName)); - id menuItem = [widget itemWithTitle: NSSTR(Title)]; - NSLog(@"%d",[menuItem respondsToSelector: selector]); - if (selector) { - [menuItem setAction: @selector(selector)]; - } -} diff --git a/src/cocoa/widgets/label.m b/src/cocoa/widgets/label.m deleted file mode 100644 index 4bceefc..0000000 --- a/src/cocoa/widgets/label.m +++ /dev/null @@ -1,14 +0,0 @@ -#import - -#import "col.h" - -id createLabel(id parent, const char* txt, int l, int t, int w, int h){ - NSTextField *widget = [[[NSTextField alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - [widget setStringValue:[NSString stringWithUTF8String:txt]]; - [widget setEditable: NO]; - [widget setAlignment: NSTextAlignmentLeft]; - [widget setDrawsBackground: NO]; - [widget setBordered: NO]; - addToParent(parent, widget); - return widget; -} diff --git a/src/cocoa/widgets/line.m b/src/cocoa/widgets/line.m deleted file mode 100644 index a32d381..0000000 --- a/src/cocoa/widgets/line.m +++ /dev/null @@ -1,24 +0,0 @@ -#import - -#import "col.h" - -id createLine(id parent, int x, int y, int width) { - NSBox *widget = [[[NSBox alloc] initWithFrame:NSMakeRect(x,y,width,1)] autorelease]; - widget.boxType = NSBoxSeparator; - addToParent(parent, widget); - return widget; -} - -// create a horizontally oriented separator - -// NSBox *horizontalSeparator=[[NSBox alloc] initWithFrame:NSMakeRect(15.0,250.0,250.0,1.0)]; - -// [horizontalSeparator setBoxType:NSBoxSeparator]; - - - -// create a vertically oriented separator - -// NSBox *verticalSeparator=[[NSBox alloc] initWithFrame:NSMakeRect(250.0,15.0,1.0,250.0)]; - -// [verticalSeparator setBoxType:NSBoxSeparator]; diff --git a/src/cocoa/widgets/listbox.m b/src/cocoa/widgets/listbox.m deleted file mode 100644 index 6921b05..0000000 --- a/src/cocoa/widgets/listbox.m +++ /dev/null @@ -1,85 +0,0 @@ -#import - -#import "col.h" - - -@implementation CocoaListBox - -@synthesize tbl; -@synthesize db; - -- (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - db = [NSMutableArray new]; - - if (self) { - tblc = [[NSTableColumn alloc] initWithIdentifier: @"Name"]; - [tblc setEditable: NO]; - - tbl = [[NSTableView alloc] initWithFrame: NSMakeRect(5,40,335,185)]; - [tbl setGridStyleMask: NSTableViewGridNone]; - [tbl setAllowsColumnSelection: NO]; - [tbl setAllowsColumnReordering: NO]; - [tbl setAllowsEmptySelection: NO]; - [tbl setAllowsMultipleSelection: NO]; - [tbl setColumnAutoresizingStyle: NSTableViewUniformColumnAutoresizingStyle]; - [tbl addTableColumn: tblc]; - [tbl setDataSource: self]; - [tbl setDelegate: self]; - [tbl setTarget:self]; - [tbl setDoubleAction:@selector(doubleclicked:)]; - // [tbl setAction:@selector(selected:)]; - - [tbl setHeaderView:nil]; - - [self setHasHorizontalScroller: NO]; - [self setHasVerticalScroller: YES]; - [self setDocumentView: tbl]; - // [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - - [tblc setResizingMask: NSTableColumnAutoresizingMask]; - [tblc setWidth:10000]; - [tbl reloadData]; - - cnt = 0; - } - return self; -} - -- (void)doubleclicked:(id)sender -{ - // int rowIndex = [sender selectedRow]; -} - -- (void)selected:(id)sender -{ - // [tbl selectRowIndexes:[NSIndexSet indexSetWithIndex:item->row] byExtendingSelection:NO]; -} - --(void)tableViewSelectionDidChange:(NSNotification *)notification -{ - NSInteger row = [tbl selectedRow]; - -} - -- (long)numberOfRowsInTableView:(NSTableView *)aTableView -{ - return db.count; -} - --(id)tableView:(NSTableView *)tableView - objectValueForTableColumn:(NSTableColumn *)tableColumn - row:(NSInteger)row -{ - return self.db[row]; -} - - -@end - - -id createListBox(id parent,int l, int t, int w, int h){ - id self = [[[CocoaListBox alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - addToParent(parent, self); - return self; -} diff --git a/src/cocoa/widgets/menu.m b/src/cocoa/widgets/menu.m deleted file mode 100644 index 57e7396..0000000 --- a/src/cocoa/widgets/menu.m +++ /dev/null @@ -1,176 +0,0 @@ -#import "col.h" - -@implementation CocoaMenuItem - @synthesize menuItemAction; - -- (void) click:(id)sender { - menuItemAction(sender); -} -@end - -@implementation CocoaMenu - -@synthesize menu; -@synthesize menuAction; - - -- (void) CreateMenu: (NSString*) Title { - NSMenuItem *newMenuItem = [[NSMenuItem alloc] initWithTitle:Title action:NULL keyEquivalent:@""]; - - self.menu = [[NSMenu alloc] initWithTitle:Title]; - [newMenuItem setSubmenu:self.menu]; - [[[NSApplication sharedApplication] mainMenu] addItem: newMenuItem]; -} - -- (void) AddItem: (NSString*)Title withShortcut: (NSString*)key andCallback: (ACTION) callback { - CocoaMenuItem *item = [[[CocoaMenuItem alloc] init] autorelease]; - [item setTitle:Title]; - [item setTarget:item]; - [item setKeyEquivalent: key]; - [item setIdentifier: Title]; - - if (callback != NULL) { - [item setMenuItemAction: callback]; - [item setAction: @selector(click:)]; - } - - [self.menu addItem: item]; -} - -- (void)addSeparator { - [self.menu addItem: [NSMenuItem separatorItem]]; -} - -- (void) SetAction: (id) widget Callback: (ACTION) func { - [widget setMenuAction:func]; -} - -- (id) createFileMenu { - NSMenuItem *newMenuItem = [[NSMenuItem alloc] initWithTitle:@"File" action:NULL keyEquivalent:@""]; - - NSMenu *fileMenu = [[NSMenu alloc] initWithTitle:@"File"]; - - id newMenu =[[[NSMenuItem alloc] initWithTitle:@"New" - action:@selector(newDocument:) - keyEquivalent:@"n"] - autorelease]; - [fileMenu addItem:newMenu]; - - [newMenuItem setSubmenu: fileMenu]; - [[[NSApplication sharedApplication] mainMenu] addItem: newMenuItem]; - - -} - -- (id) createEditMenu { - NSString *appName = [[NSProcessInfo processInfo] processName]; - NSMenuItem *newMenuItem = [[NSMenuItem alloc] initWithTitle:@"Edit" action:NULL keyEquivalent:@""]; - - NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"Edit"]; - - id undoMenu =[[[NSMenuItem alloc] initWithTitle:@"Undo" - action:@selector(undo:) - keyEquivalent:@"z"] - autorelease]; - [editMenu addItem:undoMenu]; - - // ; - - id redoMenu =[[[NSMenuItem alloc] initWithTitle:@"Redo" - action:@selector(redo:) - keyEquivalent:@"Z"] - autorelease]; - [editMenu addItem:redoMenu]; - - [editMenu addItem: [NSMenuItem separatorItem]]; - - id cutMenu =[[[NSMenuItem alloc] initWithTitle:@"Cut" - action:@selector(cut:) - keyEquivalent:@"x"] - autorelease]; - [editMenu addItem:cutMenu]; - - - id copyMenu =[[[NSMenuItem alloc] initWithTitle:@"Copy" - action:@selector(copy:) - keyEquivalent:@"c"] - autorelease]; - [editMenu addItem:copyMenu]; - - - - id pasteMenu =[[[NSMenuItem alloc] initWithTitle:@"Paste" - action:@selector(paste:) - keyEquivalent:@"v"] - autorelease]; - [editMenu addItem:pasteMenu]; - - id pasteAndMatchMenu =[[[NSMenuItem alloc] initWithTitle:@"Paste and Match Style" - action:@selector(pastAsPlainText:) - keyEquivalent:@""] - autorelease]; - [editMenu addItem:pasteAndMatchMenu]; - - id selectAllMenu =[[[NSMenuItem alloc] initWithTitle:@"Select All" - action:@selector(selectAll:) - keyEquivalent:@"a"] - autorelease]; - [editMenu addItem:selectAllMenu]; - - // [newMenuItem setSubmenu: selectAllMenu]; - - // [editMenu addItem: [NSMenuItem separatorItem]]; - [newMenuItem setSubmenu: editMenu]; - [[[NSApplication sharedApplication] mainMenu] addItem: newMenuItem]; -} - -- (id) createFormatMenu{ - - NSFontManager *fontManager = [NSFontManager sharedFontManager]; - [fontManager setDelegate: self]; - NSMenu *fontMenu = [fontManager fontMenu:YES]; - // [[[NSApplication sharedApplication] mainMenu] addItem: fontManager]; - - NSMenuItem *newMenuItem = [[NSMenuItem alloc] initWithTitle:@"Format" action:NULL keyEquivalent:@""]; - - NSMenu *blah = [[NSMenu alloc] initWithTitle: @"Format"]; - [newMenuItem setSubmenu: blah]; - - [newMenuItem setSubmenu: fontMenu]; - [[[NSApplication sharedApplication] mainMenu] addItem: newMenuItem]; -} -@end - - -id createMenu(const char * Title) { - id widget = [CocoaMenu new]; - [widget CreateMenu: NSSTR(Title)]; - return widget; - -} - -void createMenuItem(id parent, const char *caption, const char *key, ACTION callback) { - - [parent AddItem: NSSTR(caption) withShortcut: NSSTR(key) andCallback: callback]; - -} -void createMenuSeparator(id parent){ - [parent addSeparator]; -} - -id createFileMenu() { - id widget = [CocoaMenu new]; - [widget createFileMenu]; - return widget; -} - -id createFormatMenu() { - id widget = [CocoaMenu new]; - [widget createFormatMenu]; - return widget; -} -id createEditMenu() { - id widget = [CocoaMenu new]; - [widget createEditMenu]; - return widget; -} \ No newline at end of file diff --git a/src/cocoa/widgets/messagebox.m b/src/cocoa/widgets/messagebox.m deleted file mode 100644 index e3ea07f..0000000 --- a/src/cocoa/widgets/messagebox.m +++ /dev/null @@ -1,14 +0,0 @@ -#import - -#import "col.h" - - - -int createMessageBox(const char *title, const char *message, int type) { - NSAlert *alert = [[NSAlert new] autorelease]; - [alert addButtonWithTitle:@"Ok"]; - [alert setMessageText:[NSString stringWithUTF8String:title] ]; - [alert setInformativeText:[NSString stringWithUTF8String:message] ]; - [alert setAlertStyle:NSAlertStyleWarning]; - return [alert runModal]; -} diff --git a/src/cocoa/widgets/nsslider.m b/src/cocoa/widgets/nsslider.m deleted file mode 100644 index 22d1de4..0000000 --- a/src/cocoa/widgets/nsslider.m +++ /dev/null @@ -1,30 +0,0 @@ -#import -#import "col.h" - -@implementation CocoaSlider -{ - -} -@synthesize Value; -@synthesize sliderAction; - -- (IBAction)onChanged:(id)sender{ - self.Value = [sender intValue]; - sliderAction(sender); -} - -- (id) initWithFrame:(NSRect)rect callBack:(ACTION)func { - self = [super initWithFrame: rect]; - [self setMinValue:0]; - [self setMaxValue:100]; - [self setAllowsTickMarkValuesOnly:NO]; - [self setNumberOfTickMarks:0]; - [self setTickMarkPosition:1]; - [self setTarget:self]; - if (func != NULL) { - [self setSliderAction: func]; - [self setAction: @selector(onChanged:)]; - } - return self; -} -@end diff --git a/src/cocoa/widgets/opendialog.m b/src/cocoa/widgets/opendialog.m deleted file mode 100644 index 11a944a..0000000 --- a/src/cocoa/widgets/opendialog.m +++ /dev/null @@ -1,43 +0,0 @@ -#import - -#import "col.h" - - -char* createOpenDialog( id parent, const char *types) { - NSOpenPanel* widget = [NSOpenPanel openPanel]; - - // Enable the selection of files in the dialog. - [widget setCanChooseFiles:YES]; - - widget.showsResizeIndicator = YES; - widget.showsHiddenFiles = NO; - widget.canCreateDirectories = YES; - - // Change "Open" dialog button to "Select" - [widget setPrompt:@"Select"]; - - // Set FileTypes - if ( strlen(types) > 0 ) { - NSString *fileTypes = [NSString stringWithUTF8String:types]; - NSArray *fTypes = [fileTypes componentsSeparatedByString:@":"]; - - [widget setAllowedFileTypes:fTypes]; - } - - // if ( [widget runModal] == NSModalResponseOK ) { - // NSString* path = [[widget URL] path]; - // return strdup([path UTF8String]); - // } - [widget beginSheetModalForWindow:parent completionHandler:^(NSInteger result) { - [NSApp stopModalWithCode:result]; - }]; - if ([NSApp runModalForWindow:parent] == NSFileHandlingPanelOKButton) { - NSString* path = [[widget URL] path]; - return strdup([path UTF8String]); - } - - return strdup(""); -} - - - diff --git a/src/cocoa/widgets/radiobutton.m b/src/cocoa/widgets/radiobutton.m deleted file mode 100644 index 3b3a879..0000000 --- a/src/cocoa/widgets/radiobutton.m +++ /dev/null @@ -1,30 +0,0 @@ -#import - -#import "col.h" - -@implementation RadioButton - - @synthesize buttonAction; - - - - (void) click:(id)sender { - buttonAction(sender); - } -@end - -id createRadioButton(id parent, const char* caption, int l, int t, int w, int h, ACTION func){ - NSButton *self = [[[RadioButton alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - [self setButtonType: NSButtonTypeRadio]; - [self setBezelStyle: 0]; - [self setTitle: [NSString stringWithUTF8String:caption]]; - [self setTarget: self]; - - if (func) { - [self setButtonAction:func]; - [self setAction: @selector(click:)]; - } - - addToParent(parent, self); - - return self; -} \ No newline at end of file diff --git a/src/cocoa/widgets/saneview.m b/src/cocoa/widgets/saneview.m deleted file mode 100644 index a6efea5..0000000 --- a/src/cocoa/widgets/saneview.m +++ /dev/null @@ -1,11 +0,0 @@ -#import - -#import "col.h" - - -@implementation SaneView -- (BOOL)isFlipped -{ - return YES; -} -@end diff --git a/src/cocoa/widgets/savedialog.m b/src/cocoa/widgets/savedialog.m deleted file mode 100644 index 4f6a4a0..0000000 --- a/src/cocoa/widgets/savedialog.m +++ /dev/null @@ -1,48 +0,0 @@ -#include - -#import "col.h" - - -char* createSaveDialog(id parent, const char* title, const char* types) { - NSString* path = @""; - NSSavePanel *widget = [NSSavePanel savePanel]; - - if (strlen(title)>0) { - widget.title = [NSString stringWithUTF8String: title]; - }else{ - widget.title = @"Save File"; - } - - - // Set FileTypes - if ( strlen(types) > 0 ) { - NSString *fileTypes = [NSString stringWithUTF8String:types]; - NSArray *fTypes = [fileTypes componentsSeparatedByString:@":"]; - - [widget setAllowedFileTypes:fTypes]; - } - - widget.showsResizeIndicator = YES; - widget.showsHiddenFiles = NO; - widget.canCreateDirectories = YES; - widget.allowsOtherFileTypes = YES; - - - // if ( [widget runModal] == NSModalResponseOK ) { - // path = [[widget URL] path]; - // } - - [widget beginSheetModalForWindow:parent completionHandler:^(NSInteger result) { - [NSApp stopModalWithCode:result]; - }]; - - if ([NSApp runModalForWindow:parent] == NSFileHandlingPanelOKButton) { - NSString* path = [[widget URL] path]; - return strdup([path UTF8String]); - } - return strdup([path UTF8String]); - -} - - - diff --git a/src/cocoa/widgets/slider.m b/src/cocoa/widgets/slider.m deleted file mode 100644 index 4691f98..0000000 --- a/src/cocoa/widgets/slider.m +++ /dev/null @@ -1,38 +0,0 @@ -#import -#import "col.h" - -@implementation CocoaSlider -{ - -} -@synthesize Value; -@synthesize sliderAction; - -- (IBAction)onChanged:(id)sender{ - self.Value = [sender intValue]; - sliderAction(sender); -} - -- (id) initWithFrame:(NSRect)rect callBack:(ACTION)callback { - self = [super initWithFrame: rect]; - [self setMinValue:0]; - [self setMaxValue:100]; - [self setAllowsTickMarkValuesOnly:NO]; - [self setNumberOfTickMarks:0]; - [self setTickMarkPosition:1]; - [self setTarget:self]; - [self setContinuous: YES]; - if (callback != NULL) { - [self setSliderAction: callback]; - [self setAction: @selector(onChanged:)]; - } - return self; -} -@end - -id createSlider(id parent, int left, int top, int width, int height, ACTION callback) { - id widget = [[CocoaSlider alloc] initWithFrame:NSMakeRect(left, top, width, height) callBack:callback]; - - addToParent(parent, widget); - return widget; -} diff --git a/src/cocoa/widgets/tableview.m b/src/cocoa/widgets/tableview.m deleted file mode 100644 index 5d60312..0000000 --- a/src/cocoa/widgets/tableview.m +++ /dev/null @@ -1,131 +0,0 @@ -#import - -#import "col.h" - -#ifndef NSSTR - #define NSSTR(txt) [NSString stringWithUTF8String:txt] -#endif - - - -@implementation CocoaTableView - -@synthesize tbl; -@synthesize db; -@synthesize dict; - -- (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - db = [NSMutableArray new]; - dict = [NSMutableDictionary new]; - - if (self) { - - tbl = [[NSTableView alloc] initWithFrame: NSMakeRect(5,40,335,185)]; - [tbl setGridStyleMask: NSTableViewGridNone]; - [tbl setUsesAlternatingRowBackgroundColors: YES]; - [tbl setAllowsColumnSelection: YES]; - [tbl setAllowsColumnReordering: YES]; - [tbl setAllowsEmptySelection: NO]; - [tbl setAllowsMultipleSelection: NO]; - [tbl setColumnAutoresizingStyle: NSTableViewUniformColumnAutoresizingStyle]; - - [tbl setDataSource: self]; - [tbl setDelegate: self]; - [tbl setTarget:self]; - [tbl setDoubleAction:@selector(doubleclicked:)]; - - [self setHasHorizontalScroller: YES]; - [self setHasVerticalScroller: YES]; - [self setDocumentView: tbl]; - [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - - - [tbl reloadData]; - - cnt = 0; - } - return self; -} - -- (void)doubleclicked:(id)sender -{ - // int rowIndex = [sender selectedRow]; -} - -- (void)selected:(id)sender -{ - // [tbl selectRowIndexes:[NSIndexSet indexSetWithIndex:item->row] byExtendingSelection:NO]; -} - --(void)tableViewSelectionDidChange:(NSNotification *)notification -{ - NSInteger row = [tbl selectedRow]; - -} - -- (long)numberOfRowsInTableView:(NSTableView *)aTableView -{ - return db.count; - // return dict.count; -} - --(id)tableView:(NSTableView *)tableView - objectValueForTableColumn:(NSTableColumn *)tableColumn - row:(NSInteger)row -{ - // NSString *columnIdentifier = [tableColumn identifier]; - - return [self.db[row] valueForKey: [tableColumn identifier]]; - // return [self.dict valueForKey: [tableColumn identifier]]; - -} - - -@end - - -id createTableView(id parent,int l, int t, int w, int h){ - id self = [[[CocoaTableView alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - addToParent(parent, self); - return self; -} - -void addRow(id parent, const char *person) { - NSArray *tmpArray = [NSSTR(person) componentsSeparatedByString: @"|"]; - NSMutableDictionary *myDic = [NSMutableDictionary new]; - NSArray *columns = [[parent tbl] tableColumns]; - - for (int i = 0; i < tmpArray.count; i++) { - NSString *ident = [[parent tbl] tableColumns][i].identifier; - [myDic setObject: tmpArray[i] forKey: ident]; - } - - [[parent db] addObject: myDic]; - - [[parent tbl] reloadData]; -} - -void newTableColumn(id parent, const char *name) { - NSString *title = [NSString stringWithUTF8String: name]; - id tCol = [[NSTableColumn alloc] initWithIdentifier: [title lowercaseString]]; - [tCol setMinWidth: 200]; - [tCol setTitle: title]; - - [[parent tbl] addTableColumn: tCol]; -} - -void tableviewSaveToFile(id tview, const char *path) { - - [[tview db] writeToFile: NSSTR(path) atomically:YES]; -} - -void tableviewLoadFromFile(id tview, const char *path) { - NSArray *fileArrary = [NSArray arrayWithContentsOfFile: NSSTR(path)]; - [[tview db] removeAllObjects]; - for (NSMutableDictionary *x in fileArrary) { - [[tview db] addObject: x]; - } - - [[tview tbl] reloadData]; -} \ No newline at end of file diff --git a/src/cocoa/widgets/tabview.m b/src/cocoa/widgets/tabview.m deleted file mode 100644 index 3e0291b..0000000 --- a/src/cocoa/widgets/tabview.m +++ /dev/null @@ -1,42 +0,0 @@ -#import - -#import "col.h" - - -id createTabView(id parent, const char *label, int x, int y, int width, int height) { - NSString *str = [NSString stringWithUTF8String:label]; - NSArray *items = [str componentsSeparatedByString: @"|"]; - - id *widget = [[[NSTabView alloc] initWithFrame:NSMakeRect(x,y,width,height)] autorelease]; - - for(NSString *x in items) { - id sv = [[[SaneView alloc] initWithFrame: NSZeroRect] autorelease]; - [sv setBackgroundColor: [NSColor windowBackgroundColor]]; - - id *tabwidget = [[[NSTabViewItem alloc] initWithIdentifier: x ] autorelease]; - [tabwidget setLabel: x]; - [tabwidget setView: sv]; - [widget addTabViewItem: tabwidget]; - } - - [[parent contentView] addSubview:widget]; - return widget; -} - -void addTab(id parent, const char *name) { - NSString *str = [NSString stringWithUTF8String:name]; - NSArray *items = [str componentsSeparatedByString: @"|"]; - - for(NSString *x in items){ - id *widget = [[[NSTabViewItem alloc] initWithIdentifier: x ] autorelease]; - [widget setLabel: x]; - [parent addTabViewItem: widget]; - } -} - -id getTab(id parent, const char *name) { - NSString *str = [NSString stringWithUTF8String:name]; - NSInteger index = [parent indexOfTabViewItemWithIdentifier: str]; - // NSLog(@"%@", [[parent tabViewItemAtIndex: index] view]); - return [parent tabViewItemAtIndex: index]; -} diff --git a/src/cocoa/widgets/textedit.m b/src/cocoa/widgets/textedit.m deleted file mode 100644 index 1076452..0000000 --- a/src/cocoa/widgets/textedit.m +++ /dev/null @@ -1,110 +0,0 @@ -#import - -#import "col.h" - -@implementation CocoaTextEdit - @synthesize widget; - -- (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - if (self) { - self.widget = [[[NSTextView alloc] initWithFrame:frame] autorelease]; - [[self.widget textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)]; - [[self.widget textContainer] setWidthTracksTextView:NO]; - [self.widget setHorizontallyResizable:YES]; - [self.widget setTextContainerInset:NSMakeSize(2.0,2.0)]; - - [self.widget setAllowsUndo: YES]; - - [self setHasHorizontalScroller: YES]; - [self setHasVerticalScroller: YES]; - [self.widget setFont: [NSFont userFontOfSize:13.0]]; - [self.widget setDelegate:self]; - [self.widget becomeFirstResponder]; -// [self.widget setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [self setDocumentView: widget]; - } - return self; -} - -- (BOOL)performKeyEquivalent:(NSEvent *)theEvent -{ - if (([theEvent type] == NSEventTypeKeyDown) && ([theEvent modifierFlags] & NSEventModifierFlagCommand)) { - NSResponder * responder = [[self window] firstResponder]; - - if ((responder != nil) && [responder isKindOfClass:[NSTextView class]]) { - NSTextView * textView = (NSTextView *)responder; - NSRange range = [textView selectedRange]; - bool bHasSelectedTexts = (range.length > 0); - - // NSLog(@"Keycod: %hu", [theEvent keyCode]); - unsigned short keyCode = [theEvent keyCode]; - - bool bHandled = false; - - //6 Z, 7 X, 8 C, 9 V - if (keyCode == 6 ) { - if ([[textView undoManager] canUndo]) - { - [[textView undoManager] undo]; - bHandled = true; - } - } - else if (keyCode == 7 && bHasSelectedTexts) { - [textView cut:self]; - bHandled = true; - } - else if (keyCode== 8 && bHasSelectedTexts) { - [textView copy:self]; - bHandled = true; - } - else if (keyCode == 9) { - [textView paste:self]; - bHandled = true; - } - - if (bHandled) - return YES; - } - } - // }else if (([theEvent type] == NSEventTypeKeyDown) && ([theEvent modifierFlags] & NSEventModifierFlagCommand & NSEventModifierFlagShift)) { - // NSResponder * responder = [[self window] firstResponder]; - - // if ((responder != nil) && [responder isKindOfClass:[NSTextView class]]) { - // NSTextView * textView = (NSTextView *)responder; - // NSRange range = [textView selectedRange]; - // bool bHasSelectedTexts = (range.length > 0); - - // unsigned short keyCode = [theEvent keyCode]; - - // bool bHandled = false; - - // if (keyCode == 6) { - // if ([[textView undoManager] canRedo]) - // { - // [[textView undoManager] redo]; - // bHandled = true; - // } - // } - // if (bHandled) - // return YES; - // } - // } - - return NO; -} - - -@end - -id createTextEdit(id parent, const char* txt, int l, int t, int w, int h) { - CocoaTextEdit *widget = [[[CocoaTextEdit alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - if (strlen(txt)>0) { - NSString *str = [NSString stringWithUTF8String:txt]; - [[widget documentView] setString:str]; - } - - addToParent(parent, widget); - return widget; -} - diff --git a/src/cocoa/widgets/textfield.m b/src/cocoa/widgets/textfield.m deleted file mode 100644 index f51a9c0..0000000 --- a/src/cocoa/widgets/textfield.m +++ /dev/null @@ -1,11 +0,0 @@ -#import - -#import "col.h" - -id createTextField(id parent, const char* txt, int l, int t, int w, int h){ - NSTextField *widget = [[[NSTextField alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease]; - [widget setStringValue:[NSString stringWithUTF8String:txt]]; -// [widget setAutoresizingMask: NSViewWidthSizable]; - addToParent(parent, widget); - return widget; -} diff --git a/src/cocoa/widgets/window.m b/src/cocoa/widgets/window.m deleted file mode 100644 index e539884..0000000 --- a/src/cocoa/widgets/window.m +++ /dev/null @@ -1,117 +0,0 @@ -#import - -#import "col.h" - - - - -@implementation CocoaWindow : NSWindow - - NSMenuItem* item; - NSMenu* subMenu; - --(id) initFormWithTitle:(NSString*)title width:(NSInteger)width height:(NSInteger)height windowStyle: (NSWindowStyleMask) style -{ - self = [super initWithContentRect: NSMakeRect(0, 0, width, height) - styleMask: style //(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable) - // styleMask: (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) - backing: NSBackingStoreBuffered - defer: NO]; - if (self) { - SaneView *sv; - sv = [[SaneView alloc] initWithFrame: [[self contentView] frame]]; - [self setContentView:sv]; - [sv setBackgroundColor: [NSColor windowBackgroundColor]]; - [self setTitle: title]; - [self center]; - [self setMinSize: NSMakeSize(width,height)]; - [self setInitialFirstResponder: nil]; - [self setAutorecalculatesKeyViewLoop: YES]; - [self makeKeyAndOrderFront:nil]; - [self createApplicationMenu]; - - - } - return self; -} - -- (void)createApplicationMenu { - // Create MenuBar - id menubar = [[NSMenu new] autorelease]; - id appMenuItem = [[NSMenuItem new] autorelease]; - [menubar addItem:appMenuItem]; - [NSApp setMainMenu:menubar]; - - // Create Application Menu - id appMenu = [[NSMenu new] autorelease]; - id appName = [[NSProcessInfo processInfo] processName]; - - // About Menu - id aboutMenu =[[[NSMenuItem alloc] initWithTitle:[@"About " stringByAppendingString:appName] - action:@selector(orderFrontStandardAboutPanel:) - keyEquivalent:@""] - autorelease]; - [appMenu addItem:aboutMenu]; - - // Preferences Menu - id prefMenu = [[[NSMenuItem alloc] initWithTitle:@"Preferences…" - action:NULL keyEquivalent:@","] - autorelease]; - [prefMenu setTarget:self]; - [appMenu addItem:prefMenu]; - [appMenu addItem:[NSMenuItem separatorItem]]; - - // Show/Hide Menu - id hideMenuItem = [[[NSMenuItem alloc] initWithTitle:[@"Hide " stringByAppendingString:appName] - action:@selector(hide:) - keyEquivalent:@"h"] - autorelease]; - [appMenu addItem:hideMenuItem]; - - id hideOthersMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Hide Others" - action:@selector(hideOtherApplications:) - keyEquivalent:@"h"] - autorelease]; - [hideOthersMenuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption | NSEventModifierFlagCommand)]; - [appMenu addItem:hideOthersMenuItem]; - - id showMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Show All" - action:@selector(unhideAllApplications:) - keyEquivalent:@""] - autorelease]; - [appMenu addItem:showMenuItem]; - [appMenu addItem:[NSMenuItem separatorItem]]; - - // Quit Menu - id quitMenuItem=[[[NSMenuItem alloc] initWithTitle:@"Quit" - action:@selector(terminate:) - keyEquivalent:@"q"] - autorelease]; - [appMenu addItem:quitMenuItem]; - [appMenuItem setSubmenu:appMenu]; - -} -- (void)applicationDidFinishLaunching: (NSNotification *)notification -{ - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; - -} - -- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification -{ - return YES; -} - -- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification -{ - return YES; -} - -@end - - - - -id createWindow(const char* title, int width, int height, NSWindowStyleMask style) { - return [[[CocoaWindow alloc] initFormWithTitle:[NSString stringWithUTF8String:title] width: width height: height windowStyle: style] autorelease]; -}