Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 12, 2008, 07:52 AM   #1
resander
macrumors newbie
 
Join Date: Apr 2008
Converting Windows program to Mac

I would like to convert some programs from Windows.

The programs use the Windows API (would work from Windows 95 to Windows
XP) and are heavily text-based. One important part converts a mouse-
click in a text window to the nearest line number and character ordinal
position, for example line 3 at character position 189. This is easy to do under Windows; just receive and interpret a few event messages sent by Windows to the text window (procedure).

Q1.
is mouse-click to character-coordinate conversion similar?, easy to
do under Mac OS X?

I am a total Mac OS newbie and do not even own a a Mac (mini). Will go out and buy one if the answer to Q1 is affirmative!
resander is offline   0 Reply With Quote
Old Apr 12, 2008, 08:24 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Assuming:

1) You are using Cocoa, not Carbon (which is recommended)
2) You are using the standard NSTextView, not some alternative of your own devising

then the documentation contains the answers
robbieduncan is offline   0 Reply With Quote
Old Apr 12, 2008, 08:27 AM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
You haven't stated whether you'll be using Carbon or Cocoa. Carbon will look similar and easy since it's a C-based API just like Win32, but in the long run it isn't worth it since it's virtually being deprecated by Apple.

I'd suggest Cocoa, which may be a bit tough initially since you'll have to learn Objective-C, but it's pretty easy once you get going.

NSTextView (which is the main control for handling large amounts of text input) contains a method called characterIndexForInsertionAtPoint, which takes a single argument of type NSPoint, which you can be used with [NSEvent mouseLocation]. Once you have the character index, you can then use normal NSString methods and determine the line number and character index for that line.

Edit: robbieduncan beat me to it
kainjow is offline   0 Reply With Quote
Old May 5, 2008, 07:00 AM   #4
resander
Thread Starter
macrumors newbie
 
Join Date: Apr 2008
Many thanks for your advice.

The programs I am converting are written in procedural (non-OO) C++
without using MFC or NET frameworks. There are about 100 dialogs many of them non-trivial, i.e. values of certain fields determine the value sets and
mode of display of other fields. There are about 150 source files, so
at least by my standards the programs are quite large.

I also need to continue to support the programs on Windows.

I think I have two choices:

1. totally rewrite the GUI using Cocoa or Carbon for Mac and keep the
Windows programs without changes. Drawback:
two GUIs to support for the remaining lifetime of the
programs.

2. the algorithmic stuff (ca 25%) should translate without any changes.
The problem area is handling the GUI events which is different
under Windows. I have looked at Carbon and (think I) can see how to
rewrite the GUI on Windows to use and installl event handlers the way
it is done on Mac. End result: only one GUI to look after.
For this choice I could not use Cocoa for the GUI.

Not sure which alternative is best OR if there are better ways.
Advice welcome.
resander is offline   0 Reply With Quote
Old May 5, 2008, 07:14 AM   #5
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by resander View Post
Many thanks for your advice.

The programs I am converting are written in procedural (non-OO) C++
without using MFC or NET frameworks. There are about 100 dialogs many of them non-trivial, i.e. values of certain fields determine the value sets and
mode of display of other fields. There are about 150 source files, so
at least by my standards the programs are quite large.

I also need to continue to support the programs on Windows.

I think I have two choices:

1. totally rewrite the GUI using Cocoa or Carbon for Mac and keep the
Windows programs without changes. Drawback:
two GUIs to support for the remaining lifetime of the
programs.

2. the algorithmic stuff (ca 25%) should translate without any changes.
The problem area is handling the GUI events which is different
under Windows. I have looked at Carbon and (think I) can see how to
rewrite the GUI on Windows to use and installl event handlers the way
it is done on Mac. End result: only one GUI to look after.
For this choice I could not use Cocoa for the GUI.

Not sure which alternative is best OR if there are better ways.
Advice welcome.
You could always port the GUI to use Qt or something similar and just have one GUI architecture for Mac OS X, Windows and Linux for free rather than having a Cocoa or Carbon Mac version and a win32 Windows version. Qt is just one example that you could use, there are many more cross platform GUI libraries.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old May 6, 2008, 02:18 AM   #6
Columbo X
macrumors member
 
Join Date: Jun 2007
Location: UK
Hi resander,

I've converted a lot of code from Windows (Win32) to Mac OS. Despite Carbon being "closer" to Win32, I actually find it easier to move code to Cocoa. The initial confusion is that much of what you do by hand under Windows (WinMain setup, query event loop and message dispatch to the dialog handler or your window's WndProc event handler) is done for you. If you dig deep enough you'll find much of this is handled automatically in the NSApplication class and Cocoa run loop. As far as processing events, each Cocoa view class (including text views) have explicit methods to handle events rather than having to decode wparam and lparam values sent to your event handler function. For example, Cocoa implements a drawRect: method which is equivalent to WM_PAINT, mouseDown: which is equivalent to WM_LBUTTONDOWN etc.

I can understand wanting to maintain only one code base, but there will always be differences at the interface level. Check out Model-View-Controller if you haven't already. This is a very good way of organizing your code to minimise code changes from one platform to the next,

Also, setting up and maintaining interfaces using Interface Builder is far easier than using Visual Studio with Win32 (which seems geared towards MFC and .NET).
Columbo X is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Converting windows program to Mac ATOMANT Windows, Linux & Others on the Mac 3 Jun 24, 2009 11:36 PM
Convert windows iPod to mac version? Timmbo iPod 1 Nov 4, 2008 01:47 PM
Convert Windows Starcraft to Mac? Keleko Mac and PC Games 23 Sep 18, 2008 09:27 AM
Convert Windows programs to Mac ceytl Mac Programming 10 Aug 27, 2008 04:09 AM
help converting windows games to mac... buggybear Mac Programming 11 Mar 13, 2005 07:48 PM


All times are GMT -5. The time now is 11:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC