|
From: <cre...@us...> - 2007-02-19 00:27:17
|
Revision: 1607
http://svn.sourceforge.net/frontierkernel/?rev=1607&view=rev
Author: creecode
Date: 2007-02-18 16:27:12 -0800 (Sun, 18 Feb 2007)
Log Message:
-----------
trying a way to provide more detail when converting a database, still pretty crude
Modified Paths:
--------------
Frontier/branches/Frontier_Long_File_Paths/Common/source/cancoon.c
Modified: Frontier/branches/Frontier_Long_File_Paths/Common/source/cancoon.c
===================================================================
--- Frontier/branches/Frontier_Long_File_Paths/Common/source/cancoon.c 2007-01-17 19:44:42 UTC (rev 1606)
+++ Frontier/branches/Frontier_Long_File_Paths/Common/source/cancoon.c 2007-02-19 00:27:12 UTC (rev 1607)
@@ -29,7 +29,10 @@
#include "standard.h"
#ifdef MACVERSION
+
#include <land.h>
+ #include "MoreFilesX.h"
+
#endif
#include "memory.h"
@@ -399,6 +402,7 @@
disposehandle ((Handle) hc);
return (true);
+
} /*disposecancoonrecord*/
@@ -572,11 +576,70 @@
} /*clearcancoonglobals*/
+#ifdef MACVERSION
+
+ static boolean flConvert;
+
+ // Dialog event handler
+ static pascal OSStatus ConvertDialogWindowEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData)
+ {
+ EventRecord er;
+ OSStatus result = eventNotHandledErr;
+ HICommand command;
+ bool stopModalLoop = FALSE;
+
+ // Get the HI Command
+ GetEventParameter (event, kEventParamDirectObject, typeHICommand, NULL,
+ sizeof (HICommand), NULL, &command);
+ // Look for our 'YES ' and 'NO ' commands
+ switch (command.commandID)
+ {
+ case 'CNVT':
+ flConvert = true;
+ stopModalLoop = TRUE;
+ result = noErr;
+ break;
+ case 'CNCL':
+ stopModalLoop = TRUE;
+ result = noErr;
+ break;
+ }
+
+ ConvertEventRefToEventRecord ( event, &er );
+
+ if( IsWindowPathSelectClick( userData, &er ) )
+ {
+ SInt32 itemSelected;
+
+ if (WindowPathSelect( userData, NULL, &itemSelected ) == noErr )
+ {
+ // Prior to Carbon, it was necessary to switch to the Finder
+ // after calling WindowPathSelect; in Carbon, WindowPathSelect
+ // does it for you automatically.
+ }
+ }
+
+ // Stop the modal loop.
+ if (stopModalLoop)
+ {
+ QuitAppModalLoopForWindow((WindowRef)userData);
+ }
+
+ //Return how we handled the event.
+ return result;
+ }
+
+#endif // MACVERSION
+
+
static boolean loadversion2cancoonfile ( dbaddress adr, hdlcancoonrecord hcancoon, boolean flhavehost ) {
//
- // 2007-01-16 creedon: support for long odb item names and file paths
+ // 2007-02-18 creedon: support for long odb item names and file paths
//
+ // more detail about a database when it needs to be
+ // converted
+ //
// 5.0a2 dmb: install the menubar if the database hasn't been upgraded
//
// 5.0d18 dmb: have to ccwindowsetup _after_ loading system table now
@@ -628,6 +691,7 @@
diskgetfontnum (windowinfo.fontname, &windowinfo.fontnum);
(**hc).windowinfo [i] = windowinfo;
+
} /*for*/
frontier4root = info.versionnumber < 3;
@@ -651,16 +715,125 @@
dbrefhandle (info.adrscriptstring, (Handle *) &hstring);
if ( frontier5root ) {
+
+ /* bigstring bsprompt;
- bigstring bsprompt;
-
shellgetstring ( openolddatabasestring, bsprompt );
if ( twowaydialog ( bsprompt, BIGSTRING ( "\x06" "Cancel" ), BIGSTRING ( "\x07" "Convert" ) ) )
- return ( false );
+ return ( false ); */
+
+ #ifdef MACVERSION
+ CFIndex length;
+ CFStringRef convertDatabaseString, csr;
+ ControlID id = { 'xyzt', 1 }; // set with Interface Builder in the Inspector
+ EventTypeSpec dialogSpec = {kEventClassCommand, kEventCommandProcess };
+ EventHandlerUPP dialogUPP;
+ FSSpec fsspec;
+ Handle h, handleApplicationName, handleFileName;
+ HIViewRef textView;
+ IBNibRef nibRef;
+ OSErr err;
+ OSStatus status;
+ unsigned char cstring [ 255 ];
+ WindowRef window;
+ tyfilespec fs;
+
+ flConvert = false;
+
+ clearbytes ( &fs, sizeof ( fs ) );
+
+ if ( ! newtexthandle ( BIGSTRING ( "\x08" "Frontier" ), &handleApplicationName ) ) // i'd like to grab the short name of the application at runtime
+ return ( false );
+
+ // Create a Nib reference passing the name of the nib file (without the .nib extension)
+ // CreateNibReference only searches into the application bundle.
+ status = CreateNibReference(CFSTR("main"), &nibRef);
+ require_noerr(status, CantGetNibRef);
+
+ // Then create a window. "twowaycautiondialog" is the name of the window object. This name is set in
+ // InterfaceBuilder when the nib is created.
+ status = CreateWindowFromNib(nibRef, CFSTR("twowaycautiondialog"), &window);
+ require_noerr(status, CantCreateWindow);
+
+ // We don't need the nib reference anymore.
+ DisposeNibReference(nibRef);
+
+ HIViewFindByID(HIViewGetRoot(window), id, &textView);
+
+ convertDatabaseString = CFCopyLocalizedString ( CFSTR ("convertDatabase"), "Localized convert string." );
+
+ length = CFStringGetLength ( convertDatabaseString );
+
+ if ( ! newhandle ( length, &h ) )
+ return ( false );
+
+ CFStringGetBytes ( convertDatabaseString, CFRangeMake ( 0,
+ length ), kCFStringEncodingMacRoman, '^', false, ( UInt8 * ) *h, length, NULL );
+
+ CFRelease ( convertDatabaseString );
+
+ err = FileRefNumGetFSRef ( ( **( **hc ).hdatabase ).fnumdatabase, &fs.fsref );
+
+ FSRefGetName ( &fs.fsref, &csr );
+
+ CFStringRefToCString ( csr, cstring );
+
+ CFRelease ( csr );
+
+ if ( ! newfilledhandle ( &cstring, strlen ( cstring ), &handleFileName ) )
+ return ( false );
+
+ parsedialoghandle ( h, handleFileName, handleApplicationName, NULL, NULL );
+
+ disposehandle ( handleApplicationName );
+
+ status = TXNSetData(HITextViewGetTXNObject(textView), kTXNTextData, *h, gethandlesize ( h ), kTXNStartOffset, kTXNStartOffset);
+
+ disposehandle ( h );
+
+ windowsettitle ( window, handleFileName );
+
+ disposehandle ( handleFileName );
+
+ status = SetWindowProxyCreatorAndType ( window, 'LAND', 'TABL', kOnSystemDisk );
+
+ err = FSRefMakeFSSpec ( &fs.fsref, &fsspec );
+
+ status = SetWindowProxyFSSpec( window, &fsspec );
+
+ // Install our event handler
+ dialogUPP = NewEventHandlerUPP (ConvertDialogWindowEventHandler);
+ status = InstallWindowEventHandler (window, dialogUPP, 1, &dialogSpec, (void *) window, NULL);
+ require_noerr( status, CantInstallDialogHandler );
+
+ // The window was created hidden so show it.
+ ShowWindow(window);
+
+ // Run modally
+ RunAppModalLoopForWindow(window);
+
+ HideWindow(window);
+ DisposeWindow(window);
+ DisposeEventHandlerUPP(dialogUPP);
+
+ if ( flConvert )
+ goto success;
+
+ CantCreateWindow:
+ CantGetNibRef:
+ CantInstallDialogHandler:
+
+ return ( false );
+
+ success:
+ ;
+
+ #endif // MACVERSION
+
}
-
+
(**hc).hscriptstring = (Handle) hstring;
(**hc).flflagdisabled = (info.flags & flflagdisabled_mask) != 0;
@@ -673,28 +846,29 @@
if (!ccloadsystemtable (hc, info.adrroottable, !flhavehost))
return (false);
-
+
flguest = systemtable == nil;
#ifdef fltrialsize
if (flguest) {
-
+
(**cancoonwindowinfo).hdata = nil; /*unlink data from window to avoid crash*/
shelltrialerror (noguestdatabasesstring);
return (false);
+
}
-
+
#endif
if (!flguest) {
-
+
linksystemtablestructure (roottable);
if (frontier4root) {
-
+
if (resourcestable != nil) {
Handle h;
@@ -776,6 +950,7 @@
}
return (false);
+
} /*cctrialviolation*/
#endif
@@ -785,7 +960,7 @@
#pragma unused(rnum)
//
- // 2007-01-16 creedon: support for long odb item names and file paths
+ // 2007-02-18 creedon: support for long odb item names and file paths
//
// 6.1fc2 AR: Don't link cancoondata into (**cancoonwindowinfo).hdata.
// This would crash some installations during the initialization
@@ -796,12 +971,13 @@
//
register hdlcancoonrecord hc = nil;
+
dbaddress adr;
+ hdlcancoonrecord origglobals = cancoonglobals;
short versionnumber;
- hdlcancoonrecord origglobals = cancoonglobals;
- boolean flhavehost = origglobals != nil;
- boolean flhide;
+ boolean flhavehost = origglobals != nil, flhide;
+
cancoondata = nil; /*default error return*/
if (!dbopenfile (fnum, false))
@@ -815,20 +991,21 @@
shellexitmaineventloop ();
goto error;
+
}
-
+
#endif
dbgetview (cancoonview, &adr);
if (!dbreference (adr, sizeof (versionnumber), &versionnumber))
goto error;
-
+
disktomemshort (versionnumber);
if (!newcancoonrecord (&cancoondata))
goto error;
-
+
hc = cancoondata; /*copy into register*/
//(**cancoonwindowinfo).hdata = (Handle) hc; /*link data to window*/
@@ -836,7 +1013,7 @@
(**hc).hdatabase = databasedata; /*result from dbopenfile*/
switch (versionnumber) {
-
+
/*
case 1:
if (!loadversion1cancoonfile (adr, hc))
@@ -860,6 +1037,7 @@
flhide = !ccinexpertmode () || (**hc).windowinfo [ixcancooninfo].flhidden;
(**cancoonwindowinfo).flhidden = flhide;
+
}
// ccnewfilewindow (idscriptprocessor);
@@ -867,9 +1045,11 @@
return (true);
default:
+
alertstring (baddatabaseversionstring);
goto error;
+
} /*switch*/
error:
@@ -883,6 +1063,7 @@
setcancoonglobals (origglobals); /*restore databasedata, etc.*/
return (false);
+
} /*ccloadfile*/
@@ -1789,6 +1970,7 @@
return (settablestructureglobals (rootvariable, false));
return (true);
+
} /*ccchecktablestructureglobals*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|