Help with Macintosh programming

macintosh programming, mac programming, mac os programming, mac os x programming, mac programming language, mac programing

Archive for December, 2010

Learning Cocoa: strange bug in "Dot View"

I give up!

I’ve been struggling with the VERY SIMPLE "Dot View" application in
"Learning Cocoa" for two nights and there is something very strange
going on!

To the best of my knowledge, I have followed the book exactly. (Of
course there must be something wrong.)

Observed behavior:

No warning or compliation errors.
Slider and ColorWell correctly initialized.
Dot has correct size and color initally and can be moved with mouse

Color well can be changed, but it does not affect the color of the dot.
Tracing the instance varable "color" at the beginning and end of method
"changeColor" indicates that "color" is indeed changed and that the
value of is preserved when entering the method again. BUT, when entering
"drawRect" the value of color is always "redColor", which is the inital
value. Further, setting the flag "needsDisplay:YES" (unsure if this is
the correct message name) for self does not invoke "drawRect".

Same with the slider.

So, both methods "setRadius" and "setColor" seem to do what is expected:
being used at the correct time, reading the correct value from the
control and changing the corresponding variable. But, the new values of
the variables are not reflected in drawRect and drawRect is not invoked
through "needsDisplay" in these methods. (It works in "mouseUp".)

Strange things(?):

During initialization, both drawRect and awakeFromNib are used twice.
(Normal behavior?)

Value of the outlets "sizeSlider" and "colorWell" seems to be Nil
outside the methods "setRadius" and "setColor". (Since they are instance
variable, what/who is changing their value?)



Free movies 2018 watch online on Putlocker without downloading. .
posted by admin in Uncategorized and have Comments (2)

Building/Installing Unix code

I am trying to make and install the elastiC interpreter from

It is UNIX like code and by that I mean it was created on linux and
comes with a configure script (autoconf) and a makefile. I managed to
get configure to run by going: ./configure –host=powerpc-apple-bsd but
I have problems when I try to make it. Everything seems to compile OK,
but then I get a bunch of linker errors (undefined symbols).

I type > make and after displaying a bunch of lines about how there is
nothing to be done (everything is already compiled) it shows:

../../../makemodule -c ../../../src/elastic-config
–elastic-import=../../../src/ re_m.o pcre/libpcr
ld  -o  re_m.o pcre/libpcre.a  -lm
ld: Undefined symbols:

<more undefined symbols>

make[6]: *** [] Error 1
make[5]: *** [all-recursive] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive-am] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive-am] Error 2

Any help would be appreciated, I am just starting to learn how
programming works under Mac OS X/Unix.

Thanks in advance,

Nat Friesen

posted by admin in Uncategorized and have No Comments

Developing Java Applets

I did C and C++ programming back in college. These days I write mostly
in some of the various scripting languages around, PHP, ASP, ColdFusion,
etc.. At any rate I’d like to get into Java. Any pointers on where I can
find a book or online reference for developing Java applets with


posted by admin in Uncategorized and have Comment (1)

OpenCPicture + controls + GWorld problems

I’m trying to create a resizable dialog box, pre-Appearance (please, if you’re
going to rag me about non-Appearance, start another thread) whose controls + my
content move when resized.

The only way to do this smoothly without moved-controls being drawn willy-nilly
over some of my content is to double-buffer both my content and the controls,
*just* for the update right after the resize.

I know from the archives that a way to draw the controls offscreen is to

- open a PICT via OpenCPicture()
– draw my controls
– close the PICT
– create an offscreen GWorld
– DrawPicture into it
– copy the GWorld into my window

This sort of works except for two problems:

- All my controls are b/w, no shades, no Appearance-style buttons as drawn by
the Dialog Manager under normal circumstances even in my non-Appearance dialog.
That sounds like either the depth for the PICT or the depth for the GWorld is
wrong, but I see nothing wrong with my code (copied from other sources).
– The button text is kerned (spaced) too widely. This was reported in previous
posts to this newgroup, but I couldn’t find any answers on how to solve it.
SetFractEnable(false) both before and after OpenCPicture does nothing.

The code just to buffer the controls is below. Most error-handling has been
removed. cGrafPtr() is my own function, returns a CGrafPtr belonging to the
dialog. The port was set before this code to the port of the dialog box.

If you can see anything wrong below, or know of other tricks to solve the above
problems, I would appreciate it! Thanks!

– Andrew Pontious

OpenCPicParams theParams =
        theWindowRect,  /* Source rect */
        0×00480000,             /* normal horizontal resolution? */
        0×00480000,             /* normal vertical resolution? */
        -2,                             /* version (2) */
        NULL,                   /* reserved */
        NULL                    /* reserved */


::PenNormal(); // Copied from PowerPlant, doesn’t seem to help

thePicHandle = ::OpenCPicture(&theParams);





GWorldPtr theGWorldPtr(NULL);
// Allocate offscreen G-world.
QDErr theErr = ::NewGWorld(&theGWorldPtr,
                                                   0, /* pixel depth, copy from current port? */
                                                   NULL, /* C-table handle? */
                                                   NULL, /* G-Device handle? */
                                                   NULL /* Flags? */);

// Lock its pixels.
PixMapHandle thePixMapHandle(::GetGWorldPixMap(theGWorldPtr));
        // Erase world, draw out picture there.
        ::SetGWorld(theGWorldPtr, NULL);
        ::DrawPicture(thePicHandle, &theWindowRect);

        // Go back to window, blit our world there.
        ::SetGWorld(cGrafPtr(), NULL);

        ::CopyBits(&(GrafPtr(theGWorldPtr)->portBits),   // coerce graphics
                                                                                                        // PixMap to a BitMap
                           &(grafPtr()->portBits),       // coerce window’s PixMap to a BitMap



::DisposeGWorld(theGWorldPtr);  // dispose of offscreen world


posted by admin in Uncategorized and have Comments (3)

Custom WDEF help:get region msg

I am creating a custom window and I am having a problem figuring out how
to get the window’s rect to for kWindowMsgGetRegion.
Getwindowbounds(…) is useless, it calls the WDEF with calcualte region
msg, which leads to recursion until the system crashes.
I can’t access the window record due to Carbon compliancy.
So HOW do you access the window rect?
The param parameter passes a Point of the Window’s position:it doesn’t
give it it’s size. (Another problem: how do you convert long to a Point,
CWarrior complains).

One last thing : due to poor documentation, it states that the whether
to return the content or structure region in the message parameter, the
one that passed kWindowMsgGetRegion.

Thanks in advance

posted by admin in Uncategorized and have Comment (1)

Opening HTML page in default browser

does anyone knows how i can program the MacOS
so that it opens an HTML page in the default browser

maybe i must first ask : is there somthing like a  ’default’ browser

the underlying idea is that i want to give help with my program
in html files, and when the user clicks the help button, the appropriate
html file
is opened.

posted by admin in Uncategorized and have Comments (2)

CarbonLib weak linking and System 7

I have a carbonized application that runs on the classic Mac OS with
CarbonLib 1.0.4 or better, but on Mac OS X, it uses functions only
available with later CarbonLib versions. So it links the CarbonLib
weakly. Today I launched this application on a Power Mac with System
7.6 (w/o CarbonLib), and it crashed the system completely. Obviously,
it has no toolbox calls available at all, but because of weak linking,
the CFM does not prevent the program from loading. Not a very big
problem because there is a classic version of the app that runs with
System 2 (!!!) to Mac OS 9.2.1, but not Mac like: I want it to show a
dialog box that it canĀ“t run on this old system. Putting a "if ((void
*) Gestalt == (void *) kUnresolvedCFragSymbolAddress) return;" as the
very first statement into main() does not prevent the crash: it
happens in the compiler generated startup code. Any idea how to
archive this (e. g. calling a 68K code resource? – On 68K Macs, the
Carbon app already displays the alert.)


posted by admin in Uncategorized and have Comments (2)

AppleScript and printing to PDF in OSX

I love the ability to create a pdf on the fly of any document under
OSX but have failed to find the way in applescript to print ‘preview’
to a pdf file. I tried to record using script editor but IE doesn’t
respond correctly to be recorded.

Anyone have any clues on how I can script this up?

posted by admin in Uncategorized and have No Comments

Re: Question: mixing C and C++

"Luke Miller" <splo…> wrote…
> the code for set_x_mirror is
> set_x_mirror(int *X_Mirror, int new_value) {
> X_Mirror = new_value;

If you want to set the int X_Mirror points to, you need to
dereference it:

    if (X_Mirror)
        *X_Mirror = new_value;

> }

> Any hints?

Some study on pointers is due, maybe…


Please remove capital A’s from my address when replying by mail

posted by admin in Uncategorized and have Comments (9)

Custom MDEFs & Carbon


say i have a ‘MENU’ resource in which i set the ‘MDEF ID’ field to 128
because i want to use a custom MDEF procedure (i know it’s not recommended
under Carbon, but the support seems to be there and i need it anyway to port
a classic app up to OS9/X).

then, in my code i’ve got the following:

// —
pascal void MyMDEFProc(short message, MenuRef theMenu, Rect *menuRect,
                       Point hitPt, short *whichItem)
        // — DO MDEF STUFF HERE — //


// —
void DoMyPopupMenu()
    MenuDefUPP menuDefProc = NewMenuDefUPP(MyMDEFProc);

    // set up the menu definition spec structure…
    MenuDefSpec mdSpec;

    // Carbon says register w/ the MDEF ID in the custom ‘MENU’
    RegisterMenuDefinition(128,NULL);       // …unregister previous.
    RegisterMenuDefinition(128,&mdSpec);    // …register new.

    // assume that ‘gMyMenuRef’ has been loaded earlier via GetMenu()…
    // …’gMyMenuRef’ refers to a menu loaded from a ‘MENU’ resource
    // …with the ‘MDEF ID’ field set to 128.
    long result = PopUpMenuSelect(gMyMenuRef,20,20,0);

    // deal with ‘result’ here //



…when i do this, it doesn’t ever make it into MyMDEFProc(). that is, my
custom MDEF procedure does not appear to be called.

…am i doing this the right way? do i need to call RegisterMenuDefinition()
BEFORE calling GetMenu() to load the ‘MENU’ resource? i couldn’t find any
documentation that lays out a procedure for using custom MDEFs under Carbon.


Phillip A. Kavan <mailto:kavan5-…>

posted by admin in Uncategorized and have Comment (1)