Thread: Carbon help

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    86

    Carbon help

    I'm trying to develop a class to ease input from data fields in a carbon NIB reference.

    I set up the constructor, and everything worked perfectly.

    When I tried to add a method to read input from a text field, I started getting errors.

    The thing compiles, but the application shuts down and exits "with signal 6, SIGABRT"

    here's the code:

    Code:
    /*
     *  carbonGraphicIO.h
     *  
     *
     *  Created by Erik Schmidt on 3/25/05.
     *  Copyright 2005 Erik_Soft. All rights reserved.
     *
     *  Provides eased IO capability within text field in a carbon application
     *
     *  C++ version
     *
     */
    
    #include <Carbon/Carbon.h>
    #include <sstream>
    #include <string>
    #include <cstring>
    
    using namespace std;
    
    class DataField {
    private:
    
    	/*static ControlID ctrl;
    	static CFStringRef textBuffer;
    	static ostringstream textBufferConvert;*/
    
    public:
    
    	static ControlID ctrl;
    	static CFStringRef textBuffer;
    	static ostringstream textBufferConvert;
    
    	DataField(ControlID ctr){
    	
    		ctrl=ctr;
    		
    	}//end constructor
    	
    	pascal CFStringRef getCFStringData(WindowRef window){
    	
    		ControlHandle dataField;
    		
    		GetControlByID(window,&ctrl,&dataField);
    		
    		return CFSTR("void");
    		
    	}//end getCFStringData
    	
    };//end class DataField
    Code:
    //
    //  main.c
    //  carbonGraphicIOTest
    //
    //  Created by erik on 3/25/05.
    //  Copyright __MyCompanyName__ 2005. All rights reserved.
    //
    
    #include <Carbon/Carbon.h>
    #include <iostream>
    #include "carbonGraphicIO.h"
    
    using namespace std;
    
    pascal OSStatus CGIOMainWindowEventHandler(EventHandlerCallRef handlerRef,EventRef event,void *userData);
    pascal void TestCommand(WindowRef window);
    
    int main(int argc, char* argv[])
    {
        IBNibRef 		nibRef;
        WindowRef 		window;
    	
    	EventTypeSpec mainSpec={kEventClassCommand,kEventCommandProcess};
    	
    	DataField inputTest((ControlID){129,'CGIO'});
    	DataField outputTest((ControlID){130,'CGIO'});
        
        OSStatus		err;
    
        // Create a Nib reference passing the name of the nib file (without the .nib extension)
        // CreateNibReference only searches into the application bundle.
        err = CreateNibReference(CFSTR("main"), &nibRef);
        require_noerr( err, CantGetNibRef );
        
        // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
        // object. This name is set in InterfaceBuilder when the nib is created.
        err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
        require_noerr( err, CantSetMenuBar );
        
        // Then create a window. "MainWindow" is the name of the window object. This name is set in 
        // InterfaceBuilder when the nib is created.
        err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
        require_noerr( err, CantCreateWindow );
    
        // We don't need the nib reference anymore.
        DisposeNibReference(nibRef);
        
    	InstallWindowEventHandler(window,NewEventHandlerUPP(CGIOMainWindowEventHandler),1,&mainSpec,(void *)window,NULL);
    	
        // The window was created hidden so show it.
        ShowWindow( window );
        
        // Call the event loop
        RunApplicationEventLoop();
    
    	CantCreateWindow:
    		CantSetMenuBar:
    			CantGetNibRef:
    				return err;
    }
    
    pascal OSStatus CGIOMainWindowEventHandler(EventHandlerCallRef handlerRef,EventRef event,void *userData){
    
    	OSStatus err=eventNotHandledErr;
    	HICommand command;
    	
    	GetEventParameter(event,kEventParamDirectObject,typeHICommand,NULL,sizeof(HICommand),NULL,&command);
    	
    	switch(command.commandID){
    	
    		case 'tEst':
    		
    			TestCommand((WindowRef)userData);
    			
    			err=noErr;
    			
    			break;
    			
    		//end case
    		
    	}//end switch
    	
    	return err;
    	
    }//end CGIOMainWindowEventHAndler
    
    pascal void TestCommand(WindowRef window){
    
    	//cout<<"test\n";
    	
    }//end TestCommand
    Any ideas?

  2. #2
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    c'mon now...someone has to know carbon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with project
    By Noori88 in forum C Programming
    Replies: 8
    Last Post: 04-24-2007, 06:06 AM
  2. Help! Right Math, Wrong Output
    By verd in forum C Programming
    Replies: 12
    Last Post: 03-15-2005, 07:49 PM
  3. Carbon CFString
    By pktcperlc++java in forum Tech Board
    Replies: 3
    Last Post: 02-14-2005, 07:49 PM
  4. OS X Carbon GUI
    By Exile in forum C Programming
    Replies: 0
    Last Post: 02-05-2005, 10:43 PM
  5. Genetic manipulation of humans?
    By The V. in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 12-05-2001, 09:57 AM