Exemplo n.º 1
0
/**********************************************************
  NAME         : SetupObjectSystem
  DESCRIPTION  : Initializes all COOL constructs, functions,
                   and data structures
  INPUTS       : None
  RETURNS      : Nothing useful
  SIDE EFFECTS : COOL initialized
  NOTES        : Order of setup calls is important
 **********************************************************/
globle void SetupObjectSystem(
    void *theEnv)
{
    ENTITY_RECORD defclassEntityRecord = { (char*)"DEFCLASS_PTR", DEFCLASS_PTR,1,0,0,
                                           NULL,NULL,NULL,NULL,NULL,
                                           DecrementDefclassBusyCount,
                                           IncrementDefclassBusyCount,
                                           NULL,NULL,NULL,NULL,NULL
                                         };

    AllocateEnvironmentData(theEnv,DEFCLASS_DATA,sizeof(struct defclassData),NULL);
    AddEnvironmentCleanupFunction(theEnv,(char*)"defclasses",DeallocateDefclassData,-500);

    memcpy(&DefclassData(theEnv)->DefclassEntityRecord,&defclassEntityRecord,sizeof(struct entityRecord));

#if ! RUN_TIME
    DefclassData(theEnv)->ClassDefaultsMode = CONVENIENCE_MODE;
    DefclassData(theEnv)->ISA_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,SUPERCLASS_RLN);
    IncrementSymbolCount(DefclassData(theEnv)->ISA_SYMBOL);
    DefclassData(theEnv)->NAME_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,NAME_RLN);
    IncrementSymbolCount(DefclassData(theEnv)->NAME_SYMBOL);
#if DEFRULE_CONSTRUCT
    DefclassData(theEnv)->INITIAL_OBJECT_SYMBOL = (SYMBOL_HN *) EnvAddSymbol(theEnv,INITIAL_OBJECT_NAME);
    IncrementSymbolCount(DefclassData(theEnv)->INITIAL_OBJECT_SYMBOL);
#endif
#endif

    SetupDefclasses(theEnv);
    SetupInstances(theEnv);
    SetupMessageHandlers(theEnv);

#if DEFINSTANCES_CONSTRUCT
    SetupDefinstances(theEnv);
#endif

#if INSTANCE_SET_QUERIES
    SetupQuery(theEnv);
#endif

#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
    SetupObjectsBload(theEnv);
#endif

#if CONSTRUCT_COMPILER && (! RUN_TIME)
    SetupObjectsCompiler(theEnv);
#endif

#if DEFRULE_CONSTRUCT
    SetupObjectPatternStuff(theEnv);
#endif
}
Exemplo n.º 2
0
void CatBrowser::MessageReceived(BMessage *msg)
{
	switch(msg->what)
	{
		case M_QUIT_APP:
		{
			be_app->PostMessage(B_QUIT_REQUESTED);
			break;
		}
		case M_SET_CATEGORY:
		{
			BMenuItem *marked = fCategories->FindMarked();
			if(!marked)
				break;
			else
				fCategory = marked->Label();
			fBack->SetEnabled(false);
			SetupQuery();
			RunQuery();
			
			if(fPageCount < 2)
				fNext->SetEnabled(false);
			else
				fNext->SetEnabled(true);
			break;
		}
		case M_RESULTS_BACK:
		{
			if(fCurrentPage > 0)
			{
				fCurrentPage--;
				RunQuery();
			}
			if(fCurrentPage < fPageCount - 1)
				fNext->SetEnabled(true);
			
			if(fCurrentPage == 0)
				fBack->SetEnabled(false);
			break;
		}
		case M_RESULTS_NEXT:
		{
			if(fCurrentPage < fPageCount - 1)
			{
				fCurrentPage++;
				if(fCurrentPage >= fPageCount - 1)
					fNext->SetEnabled(false);
				
				RunQuery();
			}
			
			if(!fBack->IsEnabled())
				fBack->SetEnabled(true);
			break;
		}
		case M_RECATEGORIZE_RECIPE:
		{
			int32 number;
			BString oldcat, newcat;
			msg->FindInt32("number",&number);
			msg->FindString("oldcategory",&oldcat);
			msg->FindString("newcategory",&newcat);
			
			int32 index = 0, selection;
			DBCommand("BEGIN","CatBrowser:begin mass recat");
			BeginViewTransaction();
			do
			{
				selection = fList->CurrentSelection(index);
				index++;
				if(selection >=0)
				{
					RecipeItem *item = (RecipeItem*)fList->ItemAt(selection);
					if(item)
					{
						ChangeCategory(item->fNumber, item->fCategory.String(),
										newcat.String());
					}
				}
				
			} while(selection >= 0);
			EndViewTransaction();
			DBCommand("COMMIT","ChefView:end mass recat");
			SetupQuery();
			RunQuery();
			break;
		}
		case M_SHOW_RECAT:
		{
			int32 selection, firstselection, count=0;
			firstselection = selection = fList->CurrentSelection();
			if(selection < 0)
				break;
			count++;
			
			do
			{
				selection = fList->CurrentSelection(count);
				if(selection >= 0)
					count++;
			} while (selection >= 0);
			
			RecipeItem *item = (RecipeItem*)fList->ItemAt(firstselection);
			if(item)
			{
				BRect r(Frame().OffsetByCopy(20,20));
				r.right = r.left + 300;
				r.bottom = r.top + 200;
				RecatWindow *win = new RecatWindow(r,BMessenger(this), 
												(count>1) ? -1 : item->fNumber,
												item->fCategory.String());
				win->AddToSubset(this);
				win->Show();
			}
			break;
		}
		case M_DELETE_RECIPE:
		{
			int32 index = 0, selection;
			DBCommand("BEGIN","CatBrowser:begin mass delete");
			BeginViewTransaction();
			do
			{
				selection = fList->CurrentSelection(index);
				index++;
				if(selection >=0)
				{
					RecipeItem *item = (RecipeItem*)fList->ItemAt(selection);
					if(item)
						DeleteRecipe(item->fNumber, item->fCategory.String());
				}
				
			} while(selection >= 0);
			EndViewTransaction();
			DBCommand("COMMIT","ChefView:end mass recat");
			SetupQuery();
			RunQuery();
			
			// refresh the display in the main window in case we deleted something
			// that would be in the results
			BMessage msg(M_FIND_RECIPE);
			fMessenger.SendMessage(&msg);
			break;
		}
		case M_SET_RECIPE:
		{
			if(fEditMode)
			{
				if(fList->CurrentSelection(1)>=0)
					break;
			}
			
			RecipeItem *item = (RecipeItem*)fList->ItemAt(fList->CurrentSelection());
			if(item)
			{
				BMessage msg(M_LOOKUP_RECIPE);
				msg.AddInt32("number",item->fNumber);
				msg.AddString("category",item->fCategory);
				msg.AddString("name",item->fName);
				fMessenger.SendMessage(&msg);
			}
			break;
		}
		default:
			BWindow::MessageReceived(msg);
	}
}