mirror of
https://github.com/Airr/nim-cocoa.git
synced 2025-05-11 11:02:08 +00:00
Initial Commit
This commit is contained in:
parent
bfbe13a301
commit
0d67f969db
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
# ---> Nim
|
.DS_Store
|
||||||
nimcache/
|
*.app
|
||||||
|
|
||||||
|
5
Cocoa/NSButton.nim
Normal file
5
Cocoa/NSButton.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.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".}
|
5
Cocoa/NSCheckbox.nim
Normal file
5
Cocoa/NSCheckbox.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/checkbox.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newCheckBox*(parent: ID, caption: cstring, left, top, width, height:int): ID {.cdecl, importc: "createCheckBox".}
|
0
Cocoa/NSColordialog.nim
Normal file
0
Cocoa/NSColordialog.nim
Normal file
5
Cocoa/NSCombobox.nim
Normal file
5
Cocoa/NSCombobox.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/combobox.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newComboBox*(parent: ID; left: cint; top: cint; width: cint; height: cint; `callback`: ACTION): ID {.cdecl, importc: "createComboBox".}
|
5
Cocoa/NSDialog.nim
Normal file
5
Cocoa/NSDialog.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/dialog.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newDialog*(title, message: cstring, height: cint): cint {.cdecl, importc: "createDialog".}
|
56
Cocoa/NSFunctions.nim
Normal file
56
Cocoa/NSFunctions.nim
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{.compile: "widgets/functions.m".}
|
||||||
|
|
||||||
|
type
|
||||||
|
ID* = pointer
|
||||||
|
ACTION* = proc (a2: ID)
|
||||||
|
|
||||||
|
# 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 `anchor=`*(widget: ID; value: cint) {.cdecl, importc: "Pin".}
|
||||||
|
proc Cocoa_Init*() {.cdecl, importc: "Cocoa_Init".}
|
||||||
|
proc Cocoa_Run*() {.cdecl, importc: "Cocoa_Run".}
|
||||||
|
proc `text=`*(widget: ID; txt: cstring) {.cdecl, importc: "SetText".}
|
||||||
|
proc `text`*(widget: ID): cstring {.cdecl, importc: "GetText".}
|
||||||
|
proc `item=`*(widget: ID; txt: cstring) {.cdecl, importc: "AddItem".}
|
||||||
|
proc `item`*(widget: ID) {.cdecl, importc: "GetItem".}
|
||||||
|
proc `value=`*(widget: ID, value: cint) {.cdecl, importc: "SetValue".}
|
||||||
|
proc `value`*(widget: ID): cint {.cdecl, importc: "GetValue".}
|
||||||
|
|
||||||
|
|
||||||
|
# proc `text=`*(widget: ID; txt: cstring) =
|
||||||
|
# widget.SetText(txt)
|
||||||
|
|
||||||
|
# proc `text`*(widget: ID): cstring =
|
||||||
|
# GetText(widget)
|
||||||
|
|
||||||
|
# proc `item`*(widget: ID): cstring =
|
||||||
|
# GetItem(widget)
|
||||||
|
|
||||||
|
# proc `anchor=`*(widget: ID; value: cint) =
|
||||||
|
# widget.AutoSizeMask(value)
|
||||||
|
|
||||||
|
# proc `value=`*(widget: ID, value: cint) =
|
||||||
|
# widget.SetValue(value)
|
||||||
|
|
||||||
|
# proc `value`*(widget: ID): cint =
|
||||||
|
# result = widget.GetValue()
|
5
Cocoa/NSLabel.nim
Normal file
5
Cocoa/NSLabel.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/label.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newLabel*(parent: ID; txt: cstring, left, top, width, height: int): ID {.cdecl, importc: "createLabel".}
|
5
Cocoa/NSLine.nim
Normal file
5
Cocoa/NSLine.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/line.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newLine*(parent: ID, left, top, width: cint): ID {.cdecl, importc: "createLine".}
|
5
Cocoa/NSListbox.nim
Normal file
5
Cocoa/NSListbox.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/listbox.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newListBox*(parent: ID, left, top, width, height: cint): ID {.cdecl, importc: "createListBox".}
|
7
Cocoa/NSMenu.nim
Normal file
7
Cocoa/NSMenu.nim
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{.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".}
|
5
Cocoa/NSMessagebox.nim
Normal file
5
Cocoa/NSMessagebox.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/messagebox.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newMessageBox*(title, message: cstring, height: cint): cint {.cdecl, importc: "createMessageBox".}
|
5
Cocoa/NSOpendialog.nim
Normal file
5
Cocoa/NSOpendialog.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/opendialog.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newOpenDialog*(parent: ID, types: cstring): cstring {.cdecl, importc: "createOpenDialog".}
|
5
Cocoa/NSSavedialog.nim
Normal file
5
Cocoa/NSSavedialog.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/savedialog.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newSaveDialog*(parent: ID, types: cstring): cstring {.cdecl, importc: "createSaveDialog".}
|
5
Cocoa/NSSlider.nim
Normal file
5
Cocoa/NSSlider.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/slider.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newSlider*(parent: ID; left, top, width, height: int, `func`: ACTION): ID {.cdecl, importc: "createSlider".}
|
5
Cocoa/NSTextedit.nim
Normal file
5
Cocoa/NSTextedit.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/textedit.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newTextEdit*(parent: ID; txt: cstring, left, top, width, height: int): ID {.cdecl, importc: "createTextEdit".}
|
5
Cocoa/NSTextfield.nim
Normal file
5
Cocoa/NSTextfield.nim
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{.compile: "widgets/textfield.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
proc newTextField*(parent: ID; txt: cstring; left: cint; top: cint; width: cint; height: cint): ID {.cdecl, importc: "createTextField".}
|
8
Cocoa/NSWindow.nim
Normal file
8
Cocoa/NSWindow.nim
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{.compile: "widgets/window.m".}
|
||||||
|
{.compile: "widgets/saneview.m".}
|
||||||
|
|
||||||
|
import NSFunctions
|
||||||
|
|
||||||
|
{.passL: "-fobjc-arc -framework Cocoa"}
|
||||||
|
|
||||||
|
proc newWindow*(title: cstring, width, height: int): ID {.importc: "createWindow".}
|
33
Cocoa/widgets/button.m
Normal file
33
Cocoa/widgets/button.m
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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:)];
|
||||||
|
}
|
||||||
|
[[parent contentView] addSubview:widget];
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
29
Cocoa/widgets/checkbox.m
Normal file
29
Cocoa/widgets/checkbox.m
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#import "col.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
id createCheckBox(id parent, const char* caption, int l, int t, int w, int h){
|
||||||
|
NSButton *self = [[[NSButton alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease];
|
||||||
|
[self setButtonType:NSSwitchButton];
|
||||||
|
[self setBezelStyle: 0];
|
||||||
|
[self setTitle: [NSString stringWithUTF8String:caption]];
|
||||||
|
[self setTarget: self];
|
||||||
|
|
||||||
|
[[parent contentView] addSubview: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];
|
||||||
|
}
|
562
Cocoa/widgets/col.h
Normal file
562
Cocoa/widgets/col.h
Normal file
@ -0,0 +1,562 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 <NSApplicationDelegate,NSUserNotificationCenterDelegate,NSWindowDelegate>
|
||||||
|
{
|
||||||
|
// NOT USED
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
|
||||||
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification;
|
||||||
|
- (id) initFormWithTitle:(NSString*)title width:(NSInteger)width height:(NSInteger)height;
|
||||||
|
- (void)createApplicationMenu;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface awColorPanel: NSColorPanel {
|
||||||
|
NSColor* theColor;
|
||||||
|
NSModalSession modalSession;
|
||||||
|
}
|
||||||
|
@property (copy) NSColor* theColor;
|
||||||
|
|
||||||
|
- (void)colorUpdate:(NSColorPanel*)colorPanel;
|
||||||
|
|
||||||
|
- (const char *) hexColor;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface CocoaListBox : NSScrollView <NSTableViewDataSource, NSTableViewDelegate>
|
||||||
|
{
|
||||||
|
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 CocoaButton: 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 <NSTextViewDelegate,NSMenuDelegate>
|
||||||
|
{
|
||||||
|
NSTextView *widget;
|
||||||
|
}
|
||||||
|
@property (retain) NSTextView *widget;
|
||||||
|
- (id)initWithFrame:(NSRect)frame;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface CocoaMenu : NSMenu <NSMenuDelegate>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
/**
|
||||||
|
\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 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();
|
||||||
|
const char *getColor(id panel);
|
||||||
|
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);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// #endif
|
98
Cocoa/widgets/colordialog.m
Normal file
98
Cocoa/widgets/colordialog.m
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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];
|
||||||
|
}
|
||||||
|
// @interface NSColorPanel (CPL)
|
||||||
|
//
|
||||||
|
// - (void)disablePanel;
|
||||||
|
// - (void)enablePanel;
|
||||||
|
// + (NSString *)strColor;
|
||||||
|
//
|
||||||
|
// @end
|
||||||
|
//
|
||||||
|
// #include <tgmath.h>
|
||||||
|
//
|
||||||
|
// static BOOL colorPanelEnabled = YES;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// @implementation NSColorPanel (CPL)
|
||||||
|
//
|
||||||
|
// - (void)disablePanel {
|
||||||
|
// colorPanelEnabled = NO;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// - (void)enablePanel {
|
||||||
|
// colorPanelEnabled = YES;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// - (void)orderFront:(id)sender {
|
||||||
|
// if (colorPanelEnabled) {
|
||||||
|
// NSColorPanel *panel = [BFColorPickerPopover sharedPopover].colorPanel;
|
||||||
|
// if (panel) {
|
||||||
|
// self.contentView = panel.contentView;
|
||||||
|
// }
|
||||||
|
// [super orderFront:sender];
|
||||||
|
// } else {
|
||||||
|
// // Don't do anything.
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// + (NSString *)strColor {
|
||||||
|
// NSColorPanel *panel = [NSColorPanel sharedColorPanel];
|
||||||
|
// [panel orderFront:nil];
|
||||||
|
// NSColor *color = [panel.color colorUsingColorSpaceName: NSDeviceRGBColorSpace];
|
||||||
|
// return [NSString stringWithFormat:@"r: %d, g: %d, b: %d, a: %d",
|
||||||
|
// (int)round([color redComponent]*255),
|
||||||
|
// (int)round([color greenComponent]*255),
|
||||||
|
// (int)round([color blueComponent]*255),
|
||||||
|
// (int)round([color alphaComponent]*255)];
|
||||||
|
// // return @"";
|
||||||
|
// }
|
||||||
|
// @end
|
||||||
|
|
||||||
|
// const char* ColorDialog() {
|
||||||
|
// NSColorPanel *panel = [NSColorPanel sharedColorPanel];
|
||||||
|
// [panel orderFront:nil];
|
||||||
|
// NSString *aColor = [NSColorPanel strColor];
|
||||||
|
// return [[NSString stringWithFormat:@"r: %d, g: %d, b: %d, a: %d",
|
||||||
|
// (int)round([color redComponent]*255),
|
||||||
|
// (int)round([color greenComponent]*255),
|
||||||
|
// (int)round([color blueComponent]*255),
|
||||||
|
// (int)round([color alphaComponent]*255)] UTF8String];
|
||||||
|
// return [aColor UTF8String];
|
||||||
|
// }
|
43
Cocoa/widgets/combobox.m
Normal file
43
Cocoa/widgets/combobox.m
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[parent contentView] addSubview:widget];
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
15
Cocoa/widgets/dialog.m
Normal file
15
Cocoa/widgets/dialog.m
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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];
|
||||||
|
}
|
||||||
|
|
154
Cocoa/widgets/functions.m
Normal file
154
Cocoa/widgets/functions.m
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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"])
|
||||||
|
{
|
||||||
|
[[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 textStorage] string] length] > 0) {
|
||||||
|
return [[[widget textStorage] 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];
|
||||||
|
|
||||||
|
}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]];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
14
Cocoa/widgets/label.m
Normal file
14
Cocoa/widgets/label.m
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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];
|
||||||
|
[[parent contentView] addSubview:widget];
|
||||||
|
return widget;
|
||||||
|
}
|
24
Cocoa/widgets/line.m
Normal file
24
Cocoa/widgets/line.m
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
[[parent contentView] addSubview: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];
|
85
Cocoa/widgets/listbox.m
Normal file
85
Cocoa/widgets/listbox.m
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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];
|
||||||
|
[[parent contentView] addSubview:self];
|
||||||
|
return self;
|
||||||
|
}
|
64
Cocoa/widgets/menu.m
Normal file
64
Cocoa/widgets/menu.m
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#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];
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
@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];
|
||||||
|
}
|
14
Cocoa/widgets/messagebox.m
Normal file
14
Cocoa/widgets/messagebox.m
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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];
|
||||||
|
}
|
30
Cocoa/widgets/nsslider.m
Normal file
30
Cocoa/widgets/nsslider.m
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#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
|
43
Cocoa/widgets/opendialog.m
Normal file
43
Cocoa/widgets/opendialog.m
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
11
Cocoa/widgets/saneview.m
Normal file
11
Cocoa/widgets/saneview.m
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#import "col.h"
|
||||||
|
|
||||||
|
|
||||||
|
@implementation SaneView
|
||||||
|
- (BOOL)isFlipped
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
@end
|
48
Cocoa/widgets/savedialog.m
Normal file
48
Cocoa/widgets/savedialog.m
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
38
Cocoa/widgets/slider.m
Normal file
38
Cocoa/widgets/slider.m
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#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];
|
||||||
|
|
||||||
|
[[parent contentView] addSubview:widget];
|
||||||
|
return widget;
|
||||||
|
}
|
83
Cocoa/widgets/textedit.m
Normal file
83
Cocoa/widgets/textedit.m
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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 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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[parent contentView] addSubview:widget];
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
11
Cocoa/widgets/textfield.m
Normal file
11
Cocoa/widgets/textfield.m
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#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];
|
||||||
|
[[parent contentView] addSubview:widget];
|
||||||
|
return widget;
|
||||||
|
}
|
190
Cocoa/widgets/window.m
Normal file
190
Cocoa/widgets/window.m
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#import "col.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@implementation CocoaWindow : NSWindow
|
||||||
|
|
||||||
|
NSMenuItem* item;
|
||||||
|
NSMenu* subMenu;
|
||||||
|
|
||||||
|
-(id) initFormWithTitle:(NSString*)title width:(NSInteger)width height:(NSInteger)height
|
||||||
|
{
|
||||||
|
self = [super initWithContentRect: NSMakeRect(0, 0, width, height)
|
||||||
|
styleMask: (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 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];
|
||||||
|
// NSString *appName = [[NSProcessInfo processInfo] processName];
|
||||||
|
|
||||||
|
// NSMenuItem* item;
|
||||||
|
// NSMenu *subMenu;
|
||||||
|
// NSMenu *servicesMenu;
|
||||||
|
// self.menu=[[NSMenu alloc] initWithTitle:@"AMainMenu"];
|
||||||
|
|
||||||
|
|
||||||
|
// //Create the application menu.
|
||||||
|
// item=[[NSMenuItem alloc] initWithTitle:@"Apple"
|
||||||
|
// action:NULL
|
||||||
|
// keyEquivalent:@""];
|
||||||
|
// [self.menu addItem:item];
|
||||||
|
// subMenu=[[NSMenu alloc] initWithTitle:@"Apple"];
|
||||||
|
// [self.menu setSubmenu:subMenu forItem:item];
|
||||||
|
// [item release];
|
||||||
|
|
||||||
|
// // About Menu
|
||||||
|
// item=[[[NSMenuItem alloc] initWithTitle:[@"About " stringByAppendingString:appName]
|
||||||
|
// action:@selector(orderFrontStandardAboutPanel:)
|
||||||
|
// keyEquivalent:@""]
|
||||||
|
// autorelease];
|
||||||
|
// [subMenu addItem:item];
|
||||||
|
// [subMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
// // Preferences Menu
|
||||||
|
// item = [[[NSMenuItem alloc] initWithTitle:@"Preferences…"
|
||||||
|
// action:NULL keyEquivalent:@","]
|
||||||
|
// autorelease];
|
||||||
|
// [item setTarget:self];
|
||||||
|
// [subMenu addItem:item];
|
||||||
|
// [subMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
// // Services Menu
|
||||||
|
// // item = [[[NSMenuItem alloc] initWithTitle:@"Services"
|
||||||
|
// // action:NULL
|
||||||
|
// // keyEquivalent:@""]
|
||||||
|
// // autorelease];
|
||||||
|
// // servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease];
|
||||||
|
// // [item setSubmenu:servicesMenu];
|
||||||
|
// // [NSApp setServicesMenu:servicesMenu];
|
||||||
|
// // [subMenu addItem:item];
|
||||||
|
// // [subMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
// // Show/Hide Menu
|
||||||
|
// item = [[[NSMenuItem alloc] initWithTitle:[@"Hide " stringByAppendingString:appName]
|
||||||
|
// action:@selector(hide:)
|
||||||
|
// keyEquivalent:@"h"]
|
||||||
|
// autorelease];
|
||||||
|
// [subMenu addItem:item];
|
||||||
|
// item = [[[NSMenuItem alloc] initWithTitle:@"Hide Others"
|
||||||
|
// action:@selector(hideOtherApplications:)
|
||||||
|
// keyEquivalent:@"h"]
|
||||||
|
// autorelease];
|
||||||
|
// [item setKeyEquivalentModifierMask:(NSEventModifierFlagOption | NSEventModifierFlagCommand)];
|
||||||
|
// [subMenu addItem:item];
|
||||||
|
// item = [[[NSMenuItem alloc] initWithTitle:@"Show All"
|
||||||
|
// action:@selector(unhideAllApplications:)
|
||||||
|
// keyEquivalent:@""]
|
||||||
|
// autorelease];
|
||||||
|
// [subMenu addItem:item];
|
||||||
|
// [subMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
|
||||||
|
// // Quit Menu
|
||||||
|
// item=[[[NSMenuItem alloc] initWithTitle:@"Quit"
|
||||||
|
// action:@selector(terminate:)
|
||||||
|
// keyEquivalent:@"q"]
|
||||||
|
// autorelease];
|
||||||
|
// [subMenu addItem:item];
|
||||||
|
// [subMenu release];
|
||||||
|
// [NSApp setMenu: self.menu];
|
||||||
|
// [self.menu release];
|
||||||
|
// [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
|
||||||
|
// [self orderFront: 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) {
|
||||||
|
return [[[CocoaWindow alloc] initFormWithTitle:[NSString stringWithUTF8String:title] width: width height: height] autorelease];
|
||||||
|
}
|
26
slider.nim
Normal file
26
slider.nim
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import Cocoa / [NSWindow, NSFunctions, NSLabel, NSSlider]
|
||||||
|
|
||||||
|
const
|
||||||
|
width = 320
|
||||||
|
height = 120
|
||||||
|
|
||||||
|
var mainWindow, label, slider: ID
|
||||||
|
|
||||||
|
proc sliderCB(sender: ID) =
|
||||||
|
label.text = "Slider Value: " & $slider.value
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
|
||||||
|
Cocoa_Init()
|
||||||
|
|
||||||
|
mainWindow = newWindow("Nim Mac GUI Slider Demo", width,height)
|
||||||
|
label = newLabel(mainWindow,"Slider Value: 0", 16,20,120,24)
|
||||||
|
label.anchor = akWidth
|
||||||
|
slider = newSlider(mainWindow, 16,40,width-40,24, sliderCB)
|
||||||
|
slider.anchor = akWidth
|
||||||
|
|
||||||
|
|
||||||
|
Cocoa_Run()
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
main()
|
41
test1.nim
Normal file
41
test1.nim
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import Cocoa / [NSWindow, NSTextfield, NSButton, NSFunctions, NSCombobox, NSCheckbox, NSLabel, NSSlider, NSTextedit, NSOpenDialog]
|
||||||
|
|
||||||
|
const
|
||||||
|
width = 800
|
||||||
|
height = 600
|
||||||
|
|
||||||
|
var mainWindow, txt1, btn1, combo, chkbox, label1, slider1, editor: ID
|
||||||
|
|
||||||
|
proc btnClicked(sender:ID) =
|
||||||
|
let fName = newOpenDialog(mainWindow, "nim")
|
||||||
|
if fName.len > 0:
|
||||||
|
txt1.text = fName
|
||||||
|
let fText = readFile($fName)
|
||||||
|
editor.text = fText
|
||||||
|
proc sliderCallback(sender: ID) =
|
||||||
|
echo label1.text
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
Cocoa_Init()
|
||||||
|
|
||||||
|
mainWindow = createWindow("Nim Cocoa Module GUI Test", width, height)
|
||||||
|
txt1 = newTextField(mainWindow,"Welcome to AIR's Cocoa Demo", 16, 20, width-122, 22)
|
||||||
|
btn1 = newButton(mainWindow, "Open", width-100, 20, 90, 24, btnClicked)
|
||||||
|
combo = newComboBox(mainWindow, 16,54,210,26, nil)
|
||||||
|
for item in ["One", "Two", "Three"]: combo.AddItem(item)
|
||||||
|
combo.text = "Two"
|
||||||
|
|
||||||
|
chkbox = newCheckBox(mainWindow,"Check Box 1", 240, 54, 100, 24)
|
||||||
|
label1 = newLabel(mainWindow,"This is a Label", 360, 57, 100, 24)
|
||||||
|
slider1 = newSlider(mainWindow, 680, 57, 100, 24, sliderCallback)
|
||||||
|
slider1.value = 1
|
||||||
|
editor = newTextEdit(mainWindow, "", 16, 96, width-32, height-120)
|
||||||
|
|
||||||
|
txt1.anchor = akWidth
|
||||||
|
btn1.anchor = akRight
|
||||||
|
editor.anchor = akFull
|
||||||
|
|
||||||
|
Cocoa_Run()
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user