libtest.m

Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : August 03 2010
00003     copyright   : (C) 2010 by Samuel Strupp
00004 
00005  ***************************************************************************
00006  *          Please see toplevel file COPYING for license details           *
00007  ***************************************************************************/
00008 
00009 
00010 //#include "../testdialogs/dlg_test.h"
00011 
00012 #include <gwenhywfar/gwenhywfar.h>
00013 #include <gwenhywfar/gui.h>
00014 #include <gwenhywfar/dialog.h>
00015 #include <gwenhywfar/debug.h>
00016 
00017 
00018 #include <unistd.h>
00019 
00020 #import <Foundation/Foundation.h>
00021 #import <AppKit/AppKit.h>
00022 
00023 @interface AppDelegate : NSObject {
00024         
00025 }
00026 
00027 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
00028 
00029 @end
00030 
00031 @implementation AppDelegate
00032 
00033 -(id) init {
00034         self = [super init];
00035         if (self) {
00036                 
00037         }
00038         return self;
00039 }
00040 
00041 -(void) dealloc {
00042         [super dealloc];
00043 }
00044 
00045 - (void)windowWillClose:(NSNotification *)notification {
00046         [NSApp stop:self];
00047 }
00048 
00049 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
00050         
00051         NSLog(@"Test");
00052         
00053         NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(100.0, 100.0, 200.0, 200.0) styleMask:NSTitledWindowMask|NSClosableWindowMask backing:NSBackingStoreBuffered defer:YES];
00054         [window setDelegate:self];
00055         [window makeKeyAndOrderFront:nil];
00056         
00057         test1();
00058 }
00059 
00060 @end
00061 
00062 
00063 int test1() {
00064         //fprintf(stderr, "Test\n");
00065         
00066         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00067         
00068         NSLog(@"Start");
00069         
00070         GWEN_GUI *gui;
00071         int rv;
00072         GWEN_DIALOG *dlg;
00073         
00074         rv=GWEN_Init();
00075         if (rv) {
00076                 DBG_ERROR_ERR(0, rv);
00077                 return 2;
00078         }
00079         
00080         NSLog(@"GWEN Gui initialized");
00081         
00082         GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
00083         
00084         //gtk_set_locale ();
00085         //gtk_init (&argc, &argv);
00086         
00087         // create GUI
00088         gui=Cocoa_Gui_new();
00089         GWEN_Gui_SetGui(gui);
00090         
00091         NSLog(@"Cocoa Gui set");
00092         
00093         dlg=Dlg_Test1_new();
00094         if (dlg==NULL) {
00095                 fprintf(stderr, "Could not create dialog.\n");
00096                 return 2;
00097         }
00098         
00099         NSLog(@"Test new");
00100         
00101         rv=GWEN_Gui_ExecDialog(dlg, 0);
00102         fprintf(stderr, "Result: %d\n", rv);
00103         
00104         
00105         /* GWEN_GUI *gui;
00106          int rv;
00107          GWEN_DIALOG *dlg;
00108          
00109          rv=GWEN_Init();
00110          if (rv) {
00111          DBG_ERROR_ERR(0, rv);
00112          return 2;
00113          }
00114          
00115          GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
00116          
00117          gtk_set_locale ();
00118          gtk_init (&argc, &argv);
00119          
00120          // create GUI
00121          gui=Gtk2_Gui_new();
00122          GWEN_Gui_SetGui(gui);
00123          
00124          dlg=Dlg_Test1_new();
00125          if (dlg==NULL) {
00126          fprintf(stderr, "Could not create dialog.\n");
00127          return 2;
00128          }
00129          
00130          rv=GWEN_Gui_ExecDialog(dlg, 0);
00131          fprintf(stderr, "Result: %d\n", rv);*/
00132         
00133         [pool release];
00134         
00135         return 0;
00136 }
00137 
00138 
00139 
00140 
00141 
00142 /*int test2(int argc, char **argv) {
00143   int rv;
00144   uint32_t id1;
00145   uint32_t id2;
00146   uint64_t i1;
00147   uint64_t i2;
00148   GWEN_GUI *gui;
00149 
00150   gtk_set_locale ();
00151   gtk_init (&argc, &argv);
00152 
00153   gui=Gtk2_Gui_new();
00154   GWEN_Gui_SetGui(gui);
00155 
00156   id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00157                              GWEN_GUI_PROGRESS_SHOW_ABORT |
00158                              GWEN_GUI_PROGRESS_KEEP_OPEN,
00159                              "Progress-Title",
00160                              "<html>"
00161                              "<p><b>This</b> is an example <i>text</i>..</p>"
00162                              "<p>As you can see <font color=red>colors</font> can "
00163                              "be used.</p>"
00164                              "</html>",
00165                              10,
00166                              0);
00167   for (i1=1; i1<=10; i1++) {
00168     char numbuf[128];
00169 
00170     snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
00171     GWEN_Gui_ProgressLog(id1, GWEN_LoggerLevel_Notice, numbuf);
00172     id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00173                                GWEN_GUI_PROGRESS_DELAY |
00174                                GWEN_GUI_PROGRESS_SHOW_ABORT,
00175                                "2nd progress",
00176                                "Starting 2nd progress...",
00177                                10,
00178                                id1);
00179     for (i2=1; i2<=10; i2++) {
00180       sleep(1);
00181       fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
00182       rv=GWEN_Gui_ProgressAdvance(id2, i2);
00183       if (rv==GWEN_ERROR_USER_ABORTED) {
00184         fprintf(stderr, "Aborted by user (2)\n");
00185         break;
00186       }
00187     }
00188     GWEN_Gui_ProgressEnd(id2);
00189 
00190     rv=GWEN_Gui_ProgressAdvance(id1, i1);
00191     if (rv==GWEN_ERROR_USER_ABORTED) {
00192       fprintf(stderr, "Aborted by user (1)\n");
00193       break;
00194     }
00195   }
00196 
00197   GWEN_Gui_ProgressEnd(id1);
00198 
00199   return 0;
00200 }*/
00201 
00202 
00203 
00204 int test3(int argc, char **argv) {
00205  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00206 
00207  NSLog(@"Cocoa-Test");
00208  NSString *cocoa_string = @"Das ist ein Cocoa String";
00209 
00210  [pool release];
00211  return 0;
00212 }
00213 
00214 
00215 
00216 
00217 
00218 int main(int argc, char **argv) {
00219         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
00220         NSApplication *app = [NSApplication sharedApplication];
00221         AppDelegate *app_delegate = [[AppDelegate alloc] init];
00222         NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Testprogramm"];
00223         [menu addItemWithTitle:@"Quit" action:@selector(windowWillClose:) keyEquivalent:@"Q"];
00224         [app setDelegate:app_delegate];
00225         [app setMainMenu:menu];
00226         [NSApp run];
00227         [menu release];
00228         [pool release];
00229   //test1(argc, argv);
00230         
00231   //return test2(argc, argv);
00232   //return test3(argc, argv);
00233 /*#if 0
00234   GWEN_GUI *gui;
00235 
00236   gtk_set_locale ();
00237   gtk_init (&argc, &argv);
00238 
00239   gui=Gtk2_Gui_new();
00240   GWEN_Gui_SetGui(gui);
00241 
00242   return 0;
00243 #endif*/
00244 }
00245 
00246