# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1298647554 0 # Node ID d7badd5606ca2364c3ea7910d5d18e6939205615 # Parent eee90a788876c4af30c79a321bdd13186d0b46ca Removed the Carbon source file, and changes to configure to build the Cocoa version. Mac GTK version should still work. Carbon was unfinished, Cocoa version is more complete. diff -r eee90a788876 -r d7badd5606ca Makefile.in --- a/Makefile.in Fri Feb 25 03:45:44 2011 +0000 +++ b/Makefile.in Fri Feb 25 15:25:54 2011 +0000 @@ -6,9 +6,10 @@ LFLAGS = @LIBS@ @ARCH@ INSTALL = @INSTALL@ DW_SRC = @DW_SRC@ +DW_DIR = @DW_DIR@ INCPATH = -I.. -I. -I$(srcdir) TARGET = @TARGET@ -SRCS = $(srcdir)/$(DW_SRC)/dw.c $(DW_SRC)rel2abs.c +SRCS = $(srcdir)/$(DW_DIR)/$(DW_SRC) $(DW_DIR)rel2abs.c BROWSER_OBJECT=@BROWSER_OBJECT@ COMPAT_OBJECT=@COMPAT_OBJECT@ INSTALL_COMPAT=@INSTALL_COMPAT@ @@ -114,7 +115,7 @@ rm -f *.o rm -f *~ rm -f *.a - rm -f $(DW_SRC)/*.o + rm -f $(DW_DIR)/*.o rm -f dwtest $(SYSCONF_LINK_TARGET2): $(OBJECTS2) @@ -123,11 +124,11 @@ $(SYSCONF_LINK_TARGET): $(OBJECTS) $(SYSCONF_LINK_LIB) -dw.o: $(srcdir)/$(DW_SRC)/dw.c - $(CC) -c $(INCPATH) $(CCFLAGS) -o $@ $(srcdir)/$(DW_SRC)/dw.c +dw.o: $(srcdir)/$(DW_DIR)/$(DW_SRC) + $(CC) -c $(INCPATH) $(CCFLAGS) -o $@ $(srcdir)/$(DW_DIR)/$(DW_SRC) -browser.o: $(srcdir)/$(DW_SRC)/browser.cpp - $(CXX) -c $(INCPATH) $(CCFLAGS) -o $@ $(srcdir)/$(DW_SRC)/browser.cpp +browser.o: $(srcdir)/$(DW_DIR)/browser.cpp + $(CXX) -c $(INCPATH) $(CCFLAGS) -o $@ $(srcdir)/$(DW_DIR)/browser.cpp compat.o: $(srcdir)/compat.c $(CC) -c $(INCPATH) $(CCFLAGS) -o $@ $(srcdir)/compat.c diff -r eee90a788876 -r d7badd5606ca configure.in --- a/configure.in Fri Feb 25 03:45:44 2011 +0000 +++ b/configure.in Fri Feb 25 15:25:54 2011 +0000 @@ -10,7 +10,8 @@ AC_SUBST(TARGET) AC_SUBST(TARGET2) -DW_SRC=gtk +DW_DIR=gtk +DW_SRC=dw.c DW_DEFINE=__UNIX__ SHAREDFLAG=-shared SOSUFFIX=so @@ -138,13 +139,15 @@ SHAREDFLAG="-dynamiclib -flat_namespace -undefined suppress" SOSUFFIX=dylib if test $with_gtk = yes; then - DW_SRC=gtk + DW_DIR=gtk + DW_SRC=dw.c LIBS="$LIBS -framework Gtk -framework Glib -framework Cairo" GTK_CFLAGS="-I/Library/Frameworks/Gtk.framework/Headers -I/Library/Frameworks/Glib.framework/Headers -I/Library/Frameworks/Cairo.framework/Headers" else - DW_SRC=mac + DW_DIR=mac + DW_SRC=dw.m DW_DEFINE=__MAC__ - LIBS="$LIBS -framework Carbon" + LIBS="$LIBS -framework Cocoa -framework WebKit" fi else AC_CHECK_PROG(PKG_CFG, pkg-config, pkg-config) @@ -253,6 +256,7 @@ AC_SUBST(SONAME) AC_SUBST(DW_SRC) +AC_SUBST(DW_DIR) AC_SUBST(DW_DEFINE) AC_SUBST(BROWSER_OBJECT) AC_SUBST(COMPAT_OBJECT) diff -r eee90a788876 -r d7badd5606ca mac/dw.c --- a/mac/dw.c Fri Feb 25 03:45:44 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3525 +0,0 @@ -/* - * Dynamic Windows: - * A GTK like implementation of the MacOS GUI - * - * (C) 2003-2004 Brian Smith - * - */ -#include "dw.h" - -static void _do_resize(Box *thisbox, int x, int y); - -typedef struct _sighandler -{ - struct _sighandler *next; - ULONG message; - HWND window; - int id; - void *signalfunction; - void *data; - -} SignalHandler; - -SignalHandler *Root = NULL; - -typedef struct -{ - ULONG message; - char name[30]; - -} SignalList; - -const Rect CreationRect = { 0, 0, 2000, 1000 }; -WindowRef CreationWindow = 0; -ControlRef RootControl = 0; -int _dw_screen_width = 0, _dw_screen_height = 0, _dw_color_depth = 16; - -/* List of signals and their equivilent MacOS event */ -#define SIGNALMAX 15 - -SignalList SignalTranslate[SIGNALMAX] = { - { nullEvent, DW_SIGNAL_CONFIGURE }, - { keyUp, DW_SIGNAL_KEY_PRESS }, - { mouseDown, DW_SIGNAL_BUTTON_PRESS }, - { mouseUp, DW_SIGNAL_BUTTON_RELEASE }, - { nullEvent, DW_SIGNAL_MOTION_NOTIFY }, - { nullEvent, DW_SIGNAL_DELETE }, - { updateEvt, DW_SIGNAL_EXPOSE }, - { nullEvent, DW_SIGNAL_CLICKED }, - { nullEvent, DW_SIGNAL_ITEM_ENTER }, - { nullEvent, DW_SIGNAL_ITEM_CONTEXT }, - { nullEvent, DW_SIGNAL_LIST_SELECT }, - { nullEvent, DW_SIGNAL_ITEM_SELECT }, - { activateEvt, DW_SIGNAL_SET_FOCUS }, - { nullEvent, DW_SIGNAL_VALUE_CHANGED }, - { nullEvent, DW_SIGNAL_SWITCH_PAGE } -}; - -/* This function adds a signal handler callback into the linked list. - */ -void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data) -{ - SignalHandler *new = malloc(sizeof(SignalHandler)); - - new->message = message; - new->window = window; - new->id = id; - new->signalfunction = signalfunction; - new->data = data; - new->next = NULL; - - if (!Root) - Root = new; - else - { - SignalHandler *prev = NULL, *tmp = Root; - while(tmp) - { - if(tmp->message == message && - tmp->window == window && - tmp->signalfunction == signalfunction) - { - tmp->data = data; - free(new); - return; - } - prev = tmp; - tmp = tmp->next; - } - if(prev) - prev->next = new; - else - Root = new; - } -} - -/* Finds the message number for a given signal name */ -static ULONG _findsigmessage(char *signame) -{ - int z; - - for(z=0;ztype) - { - /* If the box is going in the direction we want, then we - * return the entire sum of the items. - */ - for(z=0;zcount;z++) - { - if(tmp->items[z].type == TYPEBOX) - { - int s, os; - - _count_size(tmp->items[z].hwnd, type, &s, &os); - size += s; - origsize += os; - } - else - { - size += (type == DW_HORZ ? tmp->items[z].width : tmp->items[z].height); - origsize += (type == DW_HORZ ? tmp->items[z].origwidth : tmp->items[z].origheight); - } - } - } - else - { - /* If the box is not going in the direction we want, then we only - * want to return the maximum value. - */ - int tmpsize = 0, tmporigsize = 0; - - for(z=0;zcount;z++) - { - if(tmp->items[z].type == TYPEBOX) - _count_size(tmp->items[z].hwnd, type, &tmpsize, &tmporigsize); - else - { - tmpsize = (type == DW_HORZ ? tmp->items[z].width : tmp->items[z].height); - tmporigsize = (type == DW_HORZ ? tmp->items[z].origwidth : tmp->items[z].origheight); - } - - if(tmpsize > size) - size = tmpsize; - } - } - - *xsize = size; - *xorigsize = origsize; -} - -/* This function calculates how much space the widgets and boxes require - * and does expansion as necessary. - */ -static int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, - int pass, int *usedpadx, int *usedpady) -{ - int z, currentx = 0, currenty = 0; - int uymax = 0, uxmax = 0; - int upymax = 0, upxmax = 0; - /* Used for the SIZEEXPAND */ - int nux = *usedx, nuy = *usedy; - int nupx = *usedpadx, nupy = *usedpady; - - (*usedx) += (thisbox->pad * 2); - (*usedy) += (thisbox->pad * 2); - - for(z=0;zcount;z++) - { - if(thisbox->items[z].type == TYPEBOX) - { - int initialx, initialy; - Box *tmp = _get_window_pointer(thisbox->items[z].hwnd); - - initialx = x - (*usedx); - initialy = y - (*usedy); - - if(tmp) - { - int newx, newy; - int nux = *usedx, nuy = *usedy; - int upx = *usedpadx + (tmp->pad*2), upy = *usedpady + (tmp->pad*2); - - /* On the second pass we know how big the box needs to be and how - * much space we have, so we can calculate a ratio for the new box. - */ - if(pass == 2) - { - int deep = *depth + 1; - - _resize_box(tmp, &deep, x, y, &nux, &nuy, 1, &upx, &upy); - - tmp->upx = upx - *usedpadx; - tmp->upy = upy - *usedpady; - - newx = x - nux; - newy = y - nuy; - - tmp->width = thisbox->items[z].width = initialx - newx; - tmp->height = thisbox->items[z].height = initialy - newy; - - tmp->parentxratio = thisbox->xratio; - tmp->parentyratio = thisbox->yratio; - - tmp->parentpad = tmp->pad; - - /* Just in case */ - tmp->xratio = thisbox->xratio; - tmp->yratio = thisbox->yratio; - - if(thisbox->type == DW_VERT) - { - if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) - tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))); - } - else - { - if((thisbox->items[z].width-tmp->upx)!=0) - tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx))/((float)(thisbox->items[z].width-tmp->upx)); - } - if(thisbox->type == DW_HORZ) - { - if((thisbox->items[z].height-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) - tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].height-((thisbox->items[z].pad*2)+(tmp->pad*2)))); - } - else - { - if((thisbox->items[z].height-tmp->upy)!=0) - tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy)); - } - - nux = *usedx; nuy = *usedy; - upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); - } - - (*depth)++; - - _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); - - (*depth)--; - - newx = x - nux; - newy = y - nuy; - - tmp->minwidth = thisbox->items[z].width = initialx - newx; - tmp->minheight = thisbox->items[z].height = initialy - newy; - } - } - - if(pass > 1 && *depth > 0) - { - if(thisbox->type == DW_VERT) - { - if((thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))) == 0) - thisbox->items[z].xratio = 1.0; - else - thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); - } - else - { - if(thisbox->minwidth-thisbox->upx == 0) - thisbox->items[z].xratio = 1.0; - else - thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx)); - } - - if(thisbox->type == DW_HORZ) - { - if((thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))) == 0) - thisbox->items[z].yratio = 1.0; - else - thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); - } - else - { - if(thisbox->minheight-thisbox->upy == 0) - thisbox->items[z].yratio = 1.0; - else - thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); - } - - if(thisbox->items[z].type == TYPEBOX) - { - Box *tmp = _get_window_pointer(thisbox->items[z].hwnd); - - if(tmp) - { - tmp->parentxratio = thisbox->items[z].xratio; - tmp->parentyratio = thisbox->items[z].yratio; - } - } - } - else - { - thisbox->items[z].xratio = thisbox->xratio; - thisbox->items[z].yratio = thisbox->yratio; - } - - if(thisbox->type == DW_VERT) - { - if((thisbox->items[z].width + (thisbox->items[z].pad*2)) > uxmax) - uxmax = (thisbox->items[z].width + (thisbox->items[z].pad*2)); - if(thisbox->items[z].hsize != SIZEEXPAND) - { - if(((thisbox->items[z].pad*2) + thisbox->items[z].width) > upxmax) - upxmax = (thisbox->items[z].pad*2) + thisbox->items[z].width; - } - else - { - if(thisbox->items[z].pad*2 > upxmax) - upxmax = thisbox->items[z].pad*2; - } - } - else - { - if(thisbox->items[z].width == -1) - { - /* figure out how much space this item requires */ - /* thisbox->items[z].width = */ - } - else - { - (*usedx) += thisbox->items[z].width + (thisbox->items[z].pad*2); - if(thisbox->items[z].hsize != SIZEEXPAND) - (*usedpadx) += (thisbox->items[z].pad*2) + thisbox->items[z].width; - else - (*usedpadx) += thisbox->items[z].pad*2; - } - } - if(thisbox->type == DW_HORZ) - { - if((thisbox->items[z].height + (thisbox->items[z].pad*2)) > uymax) - uymax = (thisbox->items[z].height + (thisbox->items[z].pad*2)); - if(thisbox->items[z].vsize != SIZEEXPAND) - { - if(((thisbox->items[z].pad*2) + thisbox->items[z].height) > upymax) - upymax = (thisbox->items[z].pad*2) + thisbox->items[z].height; - } - else - { - if(thisbox->items[z].pad*2 > upymax) - upymax = thisbox->items[z].pad*2; - } - } - else - { - if(thisbox->items[z].height == -1) - { - /* figure out how much space this item requires */ - /* thisbox->items[z].height = */ - } - else - { - (*usedy) += thisbox->items[z].height + (thisbox->items[z].pad*2); - if(thisbox->items[z].vsize != SIZEEXPAND) - (*usedpady) += (thisbox->items[z].pad*2) + thisbox->items[z].height; - else - (*usedpady) += thisbox->items[z].pad*2; - } - } - } - - (*usedx) += uxmax; - (*usedy) += uymax; - (*usedpadx) += upxmax; - (*usedpady) += upymax; - - currentx += thisbox->pad; - currenty += thisbox->pad; - - /* The second pass is for expansion and actual placement. */ - if(pass > 1) - { - /* Any SIZEEXPAND items should be set to uxmax/uymax */ - for(z=0;zcount;z++) - { - if(thisbox->items[z].hsize == SIZEEXPAND && thisbox->type == DW_VERT) - thisbox->items[z].width = uxmax-(thisbox->items[z].pad*2); - if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) - thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); - /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ - if(thisbox->items[z].type == TYPEBOX) - { - Box *tmp = _get_window_pointer(thisbox->items[z].hwnd); - - if(tmp) - { - if(*depth > 0) - { - float calcval; - - if(thisbox->type == DW_VERT) - { - calcval = (float)(tmp->minwidth-((thisbox->items[z].pad*2)+(thisbox->pad*2))); - if(calcval == 0.0) - tmp->xratio = thisbox->xratio; - else - tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; - tmp->width = thisbox->items[z].width; - } - if(thisbox->type == DW_HORZ) - { - calcval = (float)(tmp->minheight-((thisbox->items[z].pad*2)+(thisbox->pad*2))); - if(calcval == 0.0) - tmp->yratio = thisbox->yratio; - else - tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; - tmp->height = thisbox->items[z].height; - } - } - - (*depth)++; - - _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); - - (*depth)--; - - } - } - } - - for(z=0;z<(thisbox->count);z++) - { - int height = thisbox->items[z].height; - int width = thisbox->items[z].width; - int pad = thisbox->items[z].pad; - HWND handle = thisbox->items[z].hwnd; - int vectorx, vectory; - - /* When upxmax != pad*2 then ratios are incorrect. */ - vectorx = (int)((width*thisbox->items[z].xratio)-width); - vectory = (int)((height*thisbox->items[z].yratio)-height); - - if(width > 0 && height > 0) - { - /* This is a hack to fix rounding of the sizing */ - if(*depth == 0) - { - vectorx++; - vectory++; - } - - /* If this item isn't going to expand... reset the vectors to 0 */ - if(thisbox->items[z].vsize != SIZEEXPAND) - vectory = 0; - if(thisbox->items[z].hsize != SIZEEXPAND) - vectorx = 0; - - MoveControl(handle, currentx + pad, currenty + pad); - SizeControl(handle, width + vectorx, height + vectory); - - if(thisbox->type == DW_HORZ) - currentx += width + vectorx + (pad * 2); - if(thisbox->type == DW_VERT) - currenty += height + vectory + (pad * 2); - } - } - } - return 0; -} - -static void _do_resize(Box *thisbox, int x, int y) -{ - if(x != 0 && y != 0) - { - if(thisbox) - { - int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; - - _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); - - if(usedx-usedpadx == 0 || usedy-usedpady == 0) - return; - - thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); - thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); - - usedx = usedy = usedpadx = usedpady = depth = 0; - - _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); - } - } -} - -static void _changebox(Box *thisbox, int percent, int type) -{ - int z; - - for(z=0;zcount;z++) - { - if(thisbox->items[z].type == TYPEBOX) - { - Box *tmp = _get_window_pointer(thisbox->items[z].hwnd); - _changebox(tmp, percent, type); - } - else - { - if(type == DW_HORZ) - { - if(thisbox->items[z].hsize == SIZEEXPAND) - thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); - } - else - { - if(thisbox->items[z].vsize == SIZEEXPAND) - thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); - } - } - } -} - -static pascal OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon) -{ - ExitToShell(); -} - -/* - * Initializes the Dynamic Windows engine. - * Parameters: - * newthread: True if this is the only thread. - * False if there is already a message loop running. - */ -int API dw_init(int newthread, int argc, char *argv[]) -{ - GDHandle gd = GetMainDevice(); - - FlushEvents(everyEvent, 0); - InitCursor(); - CreateNewWindow (kDocumentWindowClass, kWindowOpaqueForEventsAttribute, - &CreationRect, &CreationWindow); - CreateRootControl(CreationWindow, &RootControl); - HideWindow(CreationWindow); - if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitAppleEventHandler), 0, false) != noErr) - ExitToShell(); - - /* Save the height, width and color depth */ - _dw_screen_height = (*gd)->gdRect.bottom - (*gd)->gdRect.top; - _dw_screen_width = (*gd)->gdRect.right - (*gd)->gdRect.left; - _dw_color_depth = (*(*gd)->gdPMap)->cmpSize * (*(*gd)->gdPMap)->cmpCount; - return 0; -} - -/* - * Runs a message loop for Dynamic Windows. - */ -void API dw_main(void) -{ - RunApplicationEventLoop(); -} - -/* - * Runs a message loop for Dynamic Windows, for a period of milliseconds. - * Parameters: - * milliseconds: Number of milliseconds to run the loop for. - */ -void API dw_main_sleep(int milliseconds) -{ - double start = (double)clock(); - - while(((((clock() - start) / CLOCKS_PER_SEC)/1000)) <= milliseconds) - { - RunCurrentEventLoop(1); - } -} - -/* - * Processes a single message iteration and returns. - */ -void API dw_main_iteration(void) -{ - EventRecord eventStructure; - - if(WaitNextEvent(everyEvent, &eventStructure, 0, 0)) - RunCurrentEventLoop(0); -} - -/* - * Free's memory allocated by dynamic windows. - * Parameters: - * ptr: Pointer to dynamic windows allocated - * memory to be free()'d. - */ -void API dw_free(void *ptr) -{ - free(ptr); -} - -/* - * Allocates and initializes a dialog struct. - * Parameters: - * data: User defined data to be passed to functions. - */ -DWDialog * API dw_dialog_new(void *data) -{ - DWDialog *tmp = malloc(sizeof(DWDialog)); - - tmp->eve = dw_event_new(); - dw_event_reset(tmp->eve); - tmp->data = data; - tmp->done = FALSE; - tmp->result = NULL; - - return tmp; -} - -/* - * Accepts a dialog struct and returns the given data to the - * initial called of dw_dialog_wait(). - * Parameters: - * dialog: Pointer to a dialog struct aquired by dw_dialog_new). - * result: Data to be returned by dw_dialog_wait(). - */ -int API dw_dialog_dismiss(DWDialog *dialog, void *result) -{ - dialog->result = result; - dw_event_post(dialog->eve); - dialog->done = TRUE; - return 0; -} - -/* - * Accepts a dialog struct waits for dw_dialog_dismiss() to be - * called by a signal handler with the given dialog struct. - * Parameters: - * dialog: Pointer to a dialog struct aquired by dw_dialog_new). - */ -void * API dw_dialog_wait(DWDialog *dialog) -{ - void *tmp; - - while(!dialog->done) - { - RunCurrentEventLoop(180); - } - dw_event_close(&dialog->eve); - tmp = dialog->result; - free(dialog); - return tmp; -} - - -/* - * Displays a Message Box with given text and title.. - * Parameters: - * title: The title of the message box. - * format: printf style format string. - * ...: Additional variables for use in the format. - */ -int API dw_messagebox(char *title, int flags, char *format, ...) -{ - va_list args; - char outbuf[1024]; - AlertStdCFStringAlertParamRec param; - DialogRef dialog; - CFStringRef cftext, cftitle; - DialogItemIndex item; - int ret = DW_MB_RETURN_OK; - AlertType alert = kAlertPlainAlert; - - va_start(args, format); - vsprintf(outbuf, format, args); - va_end(args); - - GetStandardAlertDefaultParams(¶m, kStdCFStringAlertVersionOne); - param.movable = TRUE; - param.helpButton = FALSE; - if(flags & DW_MB_INFORMATION) - alert = kAlertNoteAlert; - else if(flags & DW_MB_ERROR) - alert = kAlertStopAlert; - else if(flags & DW_MB_WARNING) - alert = kAlertCautionAlert; - - if(flags & DW_MB_OK || flags & DW_MB_OKCANCEL) - { - param.defaultText = CFSTR("Ok"); - param.cancelText = flags & DW_MB_OK ? 0 : CFSTR("Cancel"); - } - else - { - param.defaultText = CFSTR("Yes"); - param.cancelText = CFSTR("No"); - param.otherText = CFSTR("Cancel"); - } - cftext = CFStringCreateWithCString(NULL, outbuf, kCFStringEncodingDOSLatinUS); - cftitle = CFStringCreateWithCString(NULL, title, kCFStringEncodingDOSLatinUS); - if(CreateStandardAlert(alert, cftext, cftitle, ¶m, &dialog) == noErr) - { - if(RunStandardAlert(dialog, NULL, &item) == noErr) - { - if(item == kAlertStdAlertOtherButton) - ret = DW_MB_RETURN_CANCEL; - else if(item == kAlertStdAlertCancelButton) - { - if(flags & DW_MB_OK || flags & DW_MB_OKCANCEL) - ret = DW_MB_RETURN_CANCEL; - else - ret = DW_MB_RETURN_NO; - } - else if(item == kAlertStdAlertOKButton) - { - if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) - ret = DW_MB_RETURN_YES; - } - } - } - CFRelease(cftext); - CFRelease(cftitle); - return ret; -} - -/* - * Makes the window topmost. - * Parameters: - * handle: The window handle to make topmost. - */ -int API dw_window_raise(HWND handle) -{ - BringToFront((WindowRef)handle); - return 0; -} - -/* - * Makes the window bottommost. - * Parameters: - * handle: The window handle to make bottommost. - */ -int API dw_window_lower(HWND handle) -{ - return 0; -} - -/* - * Makes the window visible. - * Parameters: - * handle: The window handle to make visible. - */ -int API dw_window_show(HWND handle) -{ - ShowWindow((WindowRef)handle); - return 0; -} - -/* - * Minimizes or Iconifies a top-level window. - * Parameters: - * handle: The window handle to minimize. - */ -int API dw_window_minimize(HWND handle) -{ - return 0; -} - -/* - * Makes the window invisible. - * Parameters: - * handle: The window handle to make visible. - */ -int API dw_window_hide(HWND handle) -{ - HideWindow((WindowRef)handle); - return 0; -} - -/* - * Destroys a window and all of it's children. - * Parameters: - * handle: The window handle to destroy. - */ -int API dw_window_destroy(HWND handle) -{ - DisposeWindow((WindowRef)handle); - return 0; -} - -/* Causes entire window to be invalidated and redrawn. - * Parameters: - * handle: Toplevel window handle to be redrawn. - */ -void API dw_window_redraw(HWND handle) -{ -} - -/* - * Changes a window's parent to newparent. - * Parameters: - * handle: The window handle to destroy. - * newparent: The window's new parent window. - */ -void API dw_window_reparent(HWND handle, HWND newparent) -{ -} - -/* - * Sets the font used by a specified window (widget) handle. - * Parameters: - * handle: The window (widget) handle. - * fontname: Name and size of the font in the form "size.fontname" - */ -int API dw_window_set_font(HWND handle, char *fontname) -{ - return 0; -} - -/* - * Sets the colors used by a specified window (widget) handle. - * Parameters: - * handle: The window (widget) handle. - * fore: Foreground color in DW_RGB format or a default color index. - * back: Background color in DW_RGB format or a default color index. - */ -int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) -{ - return 0; -} - -/* - * Sets the font used by a specified window (widget) handle. - * Parameters: - * handle: The window (widget) handle. - * border: Size of the window border in pixels. - */ -int API dw_window_set_border(HWND handle, int border) -{ - return 0; -} - -/* - * Captures the mouse input to this window. - * Parameters: - * handle: Handle to receive mouse input. - */ -void API dw_window_capture(HWND handle) -{ -} - -/* - * Releases previous mouse capture. - */ -void API dw_window_release(void) -{ -} - -/* - * Tracks this window movement. - * Parameters: - * handle: Handle to frame to be tracked. - */ -void API dw_window_track(HWND handle) -{ -} - -/* - * Changes the appearance of the mouse pointer. - * Parameters: - * handle: Handle to widget for which to change. - * cursortype: ID of the pointer you want. - */ -void API dw_window_set_pointer(HWND handle, int pointertype) -{ - SetCursor(*GetCursor(pointertype)); -} - -/* - * Create a new Window Frame. - * Parameters: - * owner: The Owner's window handle or HWND_DESKTOP. - * title: The Window title. - * flStyle: Style flags, see the PM reference. - */ -HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) -{ - WindowRef hwnd = 0; - ControlRef rootcontrol = 0; - - CreateNewWindow (kDocumentWindowClass, flStyle | kWindowStandardHandlerAttribute, - &CreationRect, &hwnd); - CreateRootControl(hwnd, &rootcontrol); - dw_window_set_text((HWND)hwnd, title); - return (HWND)hwnd; -} - -/* - * Create a new Box to be packed. - * Parameters: - * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). - * pad: Number of pixels to pad around the box. - */ -HWND API dw_box_new(int type, int pad) -{ - ControlRef hwnd = NewControl(CreationWindow, NULL, "", - true, kControlSupportsEmbedding | kControlHasSpecialBackground, - 0, 1, kControlUserPaneProc, (SInt32) 0); - return (HWND)hwnd; -} - -/* - * Create a new Group Box to be packed. - * Parameters: - * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). - * pad: Number of pixels to pad around the box. - * title: Text to be displayined in the group outline. - */ -HWND API dw_groupbox_new(int type, int pad, char *title) -{ - HWND hwnd = 0; - CreateRadioGroupControl(CreationWindow, &CreationRect, &hwnd); - return hwnd; -} - -/* - * Create a new MDI Frame to be packed. - * Parameters: - * id: An ID to be used with dw_window_from_id or 0L. - */ -HWND API dw_mdi_new(unsigned long id) -{ - return 0; -} - -/* - * Create a bitmap object to be packed. - * Parameters: - * id: An ID to be used with dw_window_from_id() or 0L. - */ -HWND API dw_bitmap_new(ULONG id) -{ - HWND hwnd = 0; - CreateImageWellControl(CreationWindow, &CreationRect, NULL, &hwnd); - return hwnd; -} - -/* - * Create a notebook object to be packed. - * Parameters: - * id: An ID to be used for getting the resource from the - * resource file. - */ -HWND API dw_notebook_new(ULONG id, int top) -{ - HWND hwnd = 0; - CreateTabsControl(CreationWindow, &CreationRect, kControlTabSizeSmall, kControlTabDirectionNorth, 1, NULL, &hwnd); - return hwnd; -} - -char _removetilde(char *dest, char *src) -{ - int z, cur=0; - char accel = '\0'; - - for(z=0;zosName,"MacOS"); - env->MajorBuild = atoi(&verbuf[3]); - verbuf[3] = 0; - env->MinorVersion = atoi(&verbuf[2]); - verbuf[2] = 0; - env->MajorVersion = atoi(verbuf); - - env->MinorBuild = 0; - - strcpy(env->buildDate, __DATE__); - strcpy(env->buildTime, __TIME__); - env->DWMajorVersion = DW_MAJOR_VERSION; - env->DWMinorVersion = DW_MINOR_VERSION; - env->DWSubVersion = DW_SUB_VERSION; -} - -/* - * Opens a file dialog and queries user selection. - * Parameters: - * title: Title bar text for dialog. - * defpath: The default path of the open dialog. - * ext: Default file extention. - * flags: DW_FILE_OPEN or DW_FILE_SAVE. - * Returns: - * NULL on error. A malloced buffer containing - * the file path on success. - * - */ -char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) -{ - return NULL; -} - -/* - * Execute and external program in a seperate session. - * Parameters: - * program: Program name with optional path. - * type: Either DW_EXEC_CON or DW_EXEC_GUI. - * params: An array of pointers to string arguements. - * Returns: - * -1 on error. - */ -int API dw_exec(char *program, int type, char **params) -{ - return -1; -} - -/* - * Loads a web browser pointed at the given URL. - * Parameters: - * url: Uniform resource locator. - */ -int API dw_browse(char *url) -{ - return -1; -} - -/* - * Returns a pointer to a static buffer which containes the - * current user directory. Or the root directory (C:\ on - * OS/2 and Windows). - */ -char * API dw_user_dir(void) -{ - static char _user_dir[1024] = ""; - - if(!_user_dir[0]) - { - char *home = getenv("HOME"); - - if(home) - strcpy(_user_dir, home); - else - strcpy(_user_dir, "/"); - } - return _user_dir; -} - -/* - * Call a function from the window (widget)'s context. - * Parameters: - * handle: Window handle of the widget. - * function: Function pointer to be called. - * data: Pointer to the data to be passed to the function. - */ -void API dw_window_function(HWND handle, void *function, void *data) -{ -} - -/* Functions for managing the user data lists that are associated with - * a given window handle. Used in dw_window_set_data() and - * dw_window_get_data(). - */ -static UserData *_find_userdata(UserData **root, char *varname) -{ - UserData *tmp = *root; - - while(tmp) - { - if(strcasecmp(tmp->varname, varname) == 0) - return tmp; - tmp = tmp->next; - } - return NULL; -} - -static int _new_userdata(UserData **root, char *varname, void *data) -{ - UserData *new = _find_userdata(root, varname); - - if(new) - { - new->data = data; - return TRUE; - } - else - { - new = malloc(sizeof(UserData)); - if(new) - { - new->varname = strdup(varname); - new->data = data; - - new->next = NULL; - - if (!*root) - *root = new; - else - { - UserData *prev = NULL, *tmp = *root; - while(tmp) - { - prev = tmp; - tmp = tmp->next; - } - if(prev) - prev->next = new; - else - *root = new; - } - return TRUE; - } - } - return FALSE; -} - -static int _remove_userdata(UserData **root, char *varname, int all) -{ - UserData *prev = NULL, *tmp = *root; - - while(tmp) - { - if(all || strcasecmp(tmp->varname, varname) == 0) - { - if(!prev) - { - *root = tmp->next; - free(tmp->varname); - free(tmp); - if(!all) - return 0; - tmp = *root; - } - else - { - /* If all is true we should - * never get here. - */ - prev->next = tmp->next; - free(tmp->varname); - free(tmp); - return 0; - } - } - else - { - prev = tmp; - tmp = tmp->next; - } - } - return 0; -} - -/* - * Add a named user data item to a window handle. - * Parameters: - * window: Window handle of signal to be called back. - * dataname: A string pointer identifying which signal to be hooked. - * data: User data to be passed to the handler function. - */ -void API dw_window_set_data(HWND window, char *dataname, void *data) -{ - WindowData *blah = (WindowData *)_get_window_pointer(window); - - if(!blah) - { - if(!dataname) - return; - - blah = calloc(1, sizeof(WindowData)); - _set_window_pointer(window, blah); - } - - if(data) - _new_userdata(&(blah->root), dataname, data); - else - { - if(dataname) - _remove_userdata(&(blah->root), dataname, FALSE); - else - _remove_userdata(&(blah->root), NULL, TRUE); - } -} - -/* - * Gets a named user data item to a window handle. - * Parameters: - * window: Window handle of signal to be called back. - * dataname: A string pointer identifying which signal to be hooked. - * data: User data to be passed to the handler function. - */ -void *dw_window_get_data(HWND window, char *dataname) -{ - WindowData *blah = (WindowData *)_get_window_pointer(window); - - if(blah && blah->root && dataname) - { - UserData *ud = _find_userdata(&(blah->root), dataname); - if(ud) - return ud->data; - } - return NULL; -} - -/* - * Add a callback to a timer event. - * Parameters: - * interval: Milliseconds to delay between calls. - * sigfunc: The pointer to the function to be used as the callback. - * data: User data to be passed to the handler function. - * Returns: - * Timer ID for use with dw_timer_disconnect(), 0 on error. - */ -int API dw_timer_connect(int interval, void *sigfunc, void *data) -{ - return 0; -} - -/* - * Removes timer callback. - * Parameters: - * id: Timer ID returned by dw_timer_connect(). - */ -void API dw_timer_disconnect(int id) -{ - SignalHandler *prev = NULL, *tmp = Root; - - /* 0 is an invalid timer ID */ - if(!id) - return; - - while(tmp) - { - if(tmp->id == id) - { - if(prev) - { - prev->next = tmp->next; - free(tmp); - tmp = prev->next; - } - else - { - Root = tmp->next; - free(tmp); - tmp = Root; - } - } - else - { - prev = tmp; - tmp = tmp->next; - } - } -} - -/* - * Add a callback to a window event. - * Parameters: - * window: Window handle of signal to be called back. - * signame: A string pointer identifying which signal to be hooked. - * sigfunc: The pointer to the function to be used as the callback. - * data: User data to be passed to the handler function. - */ -void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) -{ - ULONG message = 0L; - - if(window && signame && sigfunc) - { - if((message = _findsigmessage(signame)) != 0) - _new_signal(message, window, 0, sigfunc, data); - } -} - -/* - * Removes callbacks for a given window with given name. - * Parameters: - * window: Window handle of callback to be removed. - */ -void API dw_signal_disconnect_by_name(HWND window, char *signame) -{ - SignalHandler *prev = NULL, *tmp = Root; - ULONG message; - - if(!window || !signame || (message = _findsigmessage(signame)) == 0) - return; - - while(tmp) - { - if(tmp->window == window && tmp->message == message) - { - if(prev) - { - prev->next = tmp->next; - free(tmp); - tmp = prev->next; - } - else - { - Root = tmp->next; - free(tmp); - tmp = Root; - } - } - else - { - prev = tmp; - tmp = tmp->next; - } - } -} - -/* - * Removes all callbacks for a given window. - * Parameters: - * window: Window handle of callback to be removed. - */ -void API dw_signal_disconnect_by_window(HWND window) -{ - SignalHandler *prev = NULL, *tmp = Root; - - while(tmp) - { - if(tmp->window == window) - { - if(prev) - { - prev->next = tmp->next; - free(tmp); - tmp = prev->next; - } - else - { - Root = tmp->next; - free(tmp); - tmp = Root; - } - } - else - { - prev = tmp; - tmp = tmp->next; - } - } -} - -/* - * Removes all callbacks for a given window with specified data. - * Parameters: - * window: Window handle of callback to be removed. - * data: Pointer to the data to be compared against. - */ -void API dw_signal_disconnect_by_data(HWND window, void *data) -{ - SignalHandler *prev = NULL, *tmp = Root; - - while(tmp) - { - if(tmp->window == window && tmp->data == data) - { - if(prev) - { - prev->next = tmp->next; - free(tmp); - tmp = prev->next; - } - else - { - Root = tmp->next; - free(tmp); - tmp = Root; - } - } - else - { - prev = tmp; - tmp = tmp->next; - } - } -} - - diff -r eee90a788876 -r d7badd5606ca mac/dw.m --- a/mac/dw.m Fri Feb 25 03:45:44 2011 +0000 +++ b/mac/dw.m Fri Feb 25 15:25:54 2011 +0000 @@ -559,9 +559,10 @@ -(int)addRow:(NSArray *)input; -(int)addRows:(int)number; -(void)editCell:(id)input at:(int)row and:(int)col; --(int)cellType:(int)col; +-(void)removeRow:(int)row; -(void)setRow:(int)row title:(void *)input; -(void *)getRowTitle:(int)row; +-(int)cellType:(int)col; -(int)lastAddPoint; -(void)clear; -(void)setup; @@ -661,9 +662,30 @@ [data replaceObjectAtIndex:index withObject:input]; } } --(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } +-(void)removeRow:(int)row +{ + if(tvcols) + { + int z, start, end; + int count = [tvcols count]; + + start = count * row; + end = start + count; + + for(z=start;z 0 && lastAddPoint < row) + { + lastAddPoint--; + } + } +} -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } } -(void *)getRowTitle:(int)row { if(titles) { return [titles pointerAtIndex:row]; } return NULL; } +-(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } -(int)lastAddPoint { return lastAddPoint; } -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } -(void)setup @@ -2755,6 +2777,7 @@ } NSBezierPath* aPath = [NSBezierPath bezierPath]; [aPath setLineWidth: 0.5]; + [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; [aPath moveToPoint:NSMakePoint(x1, y1)]; [aPath lineToPoint:NSMakePoint(x2, y2)]; @@ -2780,6 +2803,7 @@ if([image isMemberOfClass:[NSView class]]) { [image lockFocusIfCanDraw]; + [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; NSDictionary *dict = [[NSDictionary alloc] init]; [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; [image unlockFocus]; @@ -2790,6 +2814,7 @@ { image = (id)pixmap->handle; [image lockFocus]; + [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; NSDictionary *dict = [[NSDictionary alloc] init]; [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; [image unlockFocus]; @@ -2856,6 +2881,7 @@ } NSBezierPath* aPath = [NSBezierPath bezierPath]; [aPath setLineWidth: 0.5]; + [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] set]; [aPath moveToPoint:NSMakePoint(*x, *y)]; for(z=1;z