AeAssetWindow.c++ 15.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

//////////////////////////////////////////////////////////////
//
// Source file for AeAssetWindow
//
//    This class is a ViewKit VkWindow subclass
//
//
// Normally, very little in this file should need to be changed.
// Create/add/modify menus using the builder.
//
// Try to restrict any changes to the bodies of functions
// corresponding to menu items, the constructor and destructor.
//
// Restrict changes to those sections between
// the "//--- Start/End editable code block" markers
//
// Doing so will allow you to make changes using the builder
// without losing any changes you may have made manually
//
// Avoid gratuitous reformatting and other changes that might
// make it difficult to integrate changes made using the builder
//////////////////////////////////////////////////////////////
#include <Vk/VkApp.h>
#include <Vk/VkFileSelectionDialog.h>
#include <Vk/VkSubMenu.h>
#include <Vk/VkRadioSubMenu.h>
#include <Vk/VkMenuItem.h>
#include <iostream.h>
#include <assert.h>

#include "AeAssetWindow.h"
#include "AeBankWindow.h"
#include "AeBinView.h"
#include "AeAssetEditor.h"

#include "AeN64Driver.h"	// temporary - debugging only


// These are default resources for widgets in objects of this class
// All resources will be prepended by *<name> at instantiation,
// where <name> is the name of the specific instance, as well as the
// name of the baseWidget. These are only defaults, and may be overriden
// in a resource file by providing a more specific resource name

String  AeAssetWindow::_defaultResources[] = {
        "*title:  Asset Catalog",
        "*filePane.labelString:  File",
        "*filePane.mnemonic:  F",
        "*openButton.labelString:  Open...",
        "*openButton.mnemonic:  O",
        "*openButton.accelerator:  Ctrl<Key>O",
        "*openButton.acceleratorText:  Ctrl+O",
        "*closeButton.labelString:  Close",
        "*closeButton.mnemonic:  C",
        "*closeButton.accelerator:  Ctrl<Key>W",
        "*closeButton.acceleratorText:  Ctrl+W",
        "*saveButton.labelString:  Save",
        "*saveButton.mnemonic:  S",
        "*saveButton.accelerator:  Ctrl<Key>S",
        "*saveButton.acceleratorText:  Ctrl+S",
        "*saveasButton.labelString:  Save As...",
        "*saveasButton.mnemonic:  A",
        "*exitButton.labelString:  Exit",
        "*exitButton.mnemonic:  x",
        "*exitButton.accelerator:  Ctrl<Key>Q",
        "*exitButton.acceleratorText:  Ctrl+Q",
        "*editPane.labelString:  Edit",
        "*editPane.mnemonic:  E",
        "*undoButton1.labelString:  Undo",
        "*undoButton1.mnemonic:  U",
        "*undoButton1.accelerator:  Ctrl<Key>Z",
        "*undoButton1.acceleratorText:  Ctrl+Z",
        "*cutButton.labelString:  Cut",
        "*cutButton.mnemonic:  t",
        "*cutButton.accelerator:  Ctrl<Key>X",
        "*cutButton.acceleratorText:  Ctrl+X",
        "*copyButton.labelString:  Copy",
        "*copyButton.mnemonic:  C",
        "*copyButton.accelerator:  Ctrl<Key>C",
        "*copyButton.acceleratorText:  Ctrl+C",
        "*pasteButton.labelString:  Paste",
        "*pasteButton.mnemonic:  P",
        "*pasteButton.accelerator:  Ctrl<Key>V",
        "*pasteButton.acceleratorText:  Ctrl+V",
        "*helpPane.labelString:  Help",
        "*helpPane.mnemonic:  H",
        "*help_click_for_help.labelString:  Click For Help",
        "*help_click_for_help.mnemonic:  C",
        "*help_click_for_help.accelerator:  Shift<Key>F1",
        "*help_click_for_help.acceleratorText:  Shift+F1",
        "*help_overview.labelString:  Overview",
        "*help_overview.mnemonic:  O",
        "*help_index.labelString:  Index",
        "*help_index.mnemonic:  I",
        "*help_keys_and_short.labelString:  Keys and Shortcuts",
        "*help_keys_and_short.mnemonic:  K",
        "*help_prod_info.labelString:  Product Information",
        "*help_prod_info.mnemonic:  P",
        "*assetPane.labelString:  Assets",
        "*assetPane.mnemonic:  A",
        "*insertButton.labelString:  Insert",
        "*insertButton.accelerator:  <Key>Insert",
        "*insertButton.acceleratorText:  Insert",
        "*deleteButton.labelString:  Delete",
        "*deleteButton.accelerator:  <Key>Delete",
        "*deleteButton.acceleratorText:  Delete",
        "*insertChildButton.labelString:  Insert Child",
        "*insertChildButton.mnemonic:  I",
        "*removeChildButton.labelString:  Remove Child",
        "*removeChildButton.mnemonic:  R",
        "*importButton.labelString:  Import...",
        "*importButton.accelerator:  Ctrl<Key>M",
        "*importButton.acceleratorText:  Ctrl+M",
        "*selectPane.labelString:  Select",
        "*selectPane.mnemonic:  S",
        "*parentsButton.labelString:  Select Parents",
        "*orphansButton.labelString:  Select Orphans",
        (char*)NULL
};


//---- Class declaration

AeAssetWindow::AeAssetWindow( const char *name,
			      AeAssetEditor * editor,
                              ArgList args,
                              Cardinal argCount) : 
    VkWindow (name, args, argCount) 
{
    // Load any class-default resources for this object

    setDefaultResources(baseWidget(), _defaultResources  );

    fEditor = editor;

    // Create the view component contained by this window

    // fView= new AeBinForm("aeBinForm", mainWindowWidget());
    fView = new AeBinView ("assetView", (AeBinEditor *)editor, mainWindowWidget ());

    XtVaSetValues ( fView->baseWidget(),
                    XmNwidth, 500, 
                    XmNheight, 272, 
                    (XtPointer) NULL );

    // Add the component as the main view

    addView (fView);
    fView->setParent(this);

    // Create the panes of this window's menubar. The menubar itself
    //  is created automatically by ViewKit


    // The filePane menu pane

    _filePane =  addMenuPane("filePane");

    _openButton =  _filePane->addAction ( "openButton", 
                                        &AeAssetWindow::openFileCallback, 
                                        (XtPointer) this );

    _closeButton =  _filePane->addAction ( "closeButton", 
                                        &AeAssetWindow::closeCallback, 
                                        (XtPointer) this );

    _saveButton =  _filePane->addAction ( "saveButton", 
                                        &AeAssetWindow::saveCallback, 
                                        (XtPointer) this );

    _saveasButton =  _filePane->addAction ( "saveasButton", 
                                        &AeAssetWindow::saveasCallback, 
                                        (XtPointer) this );

    _filePane->addSeparator();

    _exitButton =  _filePane->addAction ( "exitButton", 
                                        &AeAssetWindow::quitCallback, 
                                        (XtPointer) this );

    // The editPane menu pane

    _editPane =  addMenuPane("editPane");

    _cutButton =  _editPane->addAction ( "cutButton", 
                                        &AeAssetWindow::cutCallback, 
                                        (XtPointer) this );

    _copyButton =  _editPane->addAction ( "copyButton", 
                                        &AeAssetWindow::copyCallback, 
                                        (XtPointer) this );

    _pasteButton =  _editPane->addAction ( "pasteButton", 
                                        &AeAssetWindow::pasteCallback, 
                                        (XtPointer) this );

    // currently, these commands are not yet supported
    _cutButton->deactivate ();
    _copyButton->deactivate ();
    _pasteButton->deactivate ();

    // The assetPane menu pane

    _assetPane =  addMenuPane("assetPane");

    _insertButton =  _assetPane->addAction ( "insertButton", 
                                        &AeAssetWindow::insertAssetCallback, 
                                        (XtPointer) this );

    _deleteButton =  _assetPane->addAction ( "deleteButton", 
                                        &AeAssetWindow::deleteAssetCallback, 
                                        (XtPointer) this );

    _assetPane->addSeparator();

    _insertChildButton =  _assetPane->addAction ( "insertChildButton", 
                                        &AeAssetWindow::insertChildCallback, 
                                        (XtPointer) this );

    _removeChildButton =  _assetPane->addAction ( "removeChildButton", 
                                        &AeAssetWindow::removeChildCallback, 
                                        (XtPointer) this );

    _assetPane->addSeparator();

    _importButton =  _assetPane->addAction ( "importButton", 
                                        &AeAssetWindow::importAssetCallback, 
                                        (XtPointer) this );

    // The selectPane menu pane

    _selectPane =  addMenuPane("selectPane");

    _parentsButton =  _selectPane->addAction ( "parentsButton", 
					&AeAssetWindow::selectParentsCallback, 
					(XtPointer) this );

    _orphansButton =  _selectPane->addAction ( "orphansButton", 
                                        &AeAssetWindow::selectOrphansCallback, 
                                        (XtPointer) this );

} // End Constructor


AeAssetWindow::~AeAssetWindow()
{
    delete fView;
}


const char *AeAssetWindow::className()
{
    return ("AeAssetWindow");
}


Boolean AeAssetWindow::okToQuit()
{
    // This member function is called when the user quits by calling
    // theApplication->terminate() or uses the window manager close protocol
    // This function can abort the operation by returning FALSE, or do some.
    // cleanup before returning TRUE. The actual decision is normally passed on
    // to the view object


    // Query the view object, and give it a chance to cleanup
    return ( fView->okToQuit() );
}



/////////////////////////////////////////////////////////////// 
// The following functions are static member functions used to 
// interface with Motif.
/////////////////////////////////// 

void AeAssetWindow::closeCallback ( Widget    w,
				    XtPointer clientData,
				    XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->close ( w, callData );
}

void AeAssetWindow::copyCallback ( Widget    w,
				   XtPointer clientData,
				   XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->copy ( w, callData );
}

void AeAssetWindow::cutCallback ( Widget    w,
				  XtPointer clientData,
				  XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->cut ( w, callData );
}


void AeAssetWindow::insertAssetCallback ( Widget    w,
					  XtPointer clientData,
					  XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->insertAsset ( w, callData );
}

void AeAssetWindow::deleteAssetCallback ( Widget    w,
					  XtPointer clientData,
					  XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->deleteAsset ( w, callData );
}

void AeAssetWindow::insertChildCallback ( Widget    w,
				       XtPointer clientData,
				       XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->insertChild ( w, callData );
}

void AeAssetWindow::removeChildCallback ( Widget    w,
					  XtPointer clientData,
					  XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->removeChild ( w, callData );
}

void AeAssetWindow::importAssetCallback ( Widget    w,
					  XtPointer clientData,
					  XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->importAsset ( w, callData );
}

void AeAssetWindow::selectOrphansCallback ( Widget    w,
					    XtPointer clientData,
					    XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->selectOrphans ( w, callData );
}

void AeAssetWindow::selectParentsCallback ( Widget    w,
					    XtPointer clientData,
					    XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->selectParents ( w, callData );
}

void AeAssetWindow::openFileCallback ( Widget    w,
				       XtPointer clientData,
				       XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->openFile ( w, callData );
}

void AeAssetWindow::pasteCallback ( Widget    w,
				    XtPointer clientData,
				    XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->paste ( w, callData );
}

void AeAssetWindow::quitCallback ( Widget    w,
                                           XtPointer clientData,
                                           XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->quit ( w, callData );
}

void AeAssetWindow::saveCallback ( Widget    w,
                                           XtPointer clientData,
                                           XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->save ( w, callData );
}

void AeAssetWindow::saveasCallback ( Widget    w,
                                             XtPointer clientData,
                                             XtPointer callData ) 
{ 
    AeAssetWindow* obj = ( AeAssetWindow * ) clientData;
    obj->saveas ( w, callData );
}





/////////////////////////////////////////////////////////////// 
// The following functions are called from the menu items 
// in this window.
/////////////////////////////////// 

void AeAssetWindow::close ( Widget, XtPointer ) 
{
    assert (fEditor);
    
    fEditor->CloseFile ();
}

void AeAssetWindow::copy ( Widget w, XtPointer callData ) 
{
}


void AeAssetWindow::cut ( Widget w, XtPointer callData ) 
{
}


void AeAssetWindow::insertAsset ( Widget w, XtPointer callData ) 
{
    assert (fEditor);
    fEditor->InsertAsset ();
}


void AeAssetWindow::deleteAsset ( Widget w, XtPointer callData ) 
{
    assert (fEditor);
    fEditor->DeleteAssetUI ();
}


void AeAssetWindow::insertChild ( Widget w, XtPointer callData ) 
{
    assert (fEditor);
    fEditor->InsertChildAsset ();
}


void AeAssetWindow::removeChild ( Widget w, XtPointer callData ) 
{
    assert (fEditor);
    fEditor->RemoveChildAsset ();
}


void AeAssetWindow::importAsset ( Widget w, XtPointer callData ) 
{
    if (theFileSelectionDialog->postAndWait("Import file:") == VkDialogManager::OK)
    {
	fEditor->ImportAsset (theFileSelectionDialog->fileName ());
    }
}


void AeAssetWindow::selectOrphans ( Widget w, XtPointer callData ) 
{
    assert (fEditor);
    fEditor->SelectOrphans ();
}


void AeAssetWindow::selectParents ( Widget w, XtPointer callData ) 
{
    assert (fEditor);
    fEditor->SelectParents ();
}


void AeAssetWindow::openFile ( Widget, XtPointer ) 
{
    theFileSelectionDialog->setFilterPattern ("*inst");
    if (theFileSelectionDialog->postAndWait("Open inst file:") == VkDialogManager::OK)
    {
        fEditor->OpenFile (theFileSelectionDialog->fileName());
    }
}

void AeAssetWindow::paste ( Widget w, XtPointer callData ) 
{
}


//
// Exit via quitYourself() to allow the application
// to go through its normal shutdown routines, checking with
// all windows, views, and so on.
//
void AeAssetWindow::quit ( Widget, XtPointer ) 
{
    theApplication->quitYourself();
}

void AeAssetWindow::save ( Widget w, XtPointer callData ) 
{
    assert (fEditor);

    if (fEditor->HasFile ())
	fEditor->SaveFile ();
    else
	saveas (w, callData);
}


void AeAssetWindow::saveas ( Widget, XtPointer ) 
{
    assert (fEditor);

    if (theFileSelectionDialog->postAndWait("Save as:") == VkDialogManager::OK)
        fEditor->SaveAsFile (theFileSelectionDialog->fileName());
}