Article View: comp.windows.interviews
Article #61ided modification
From: zen kishimoto
Date: Wed, 04 Nov 1992 16:32
Date: Wed, 04 Nov 1992 16:32
105 lines
3565 bytes
3565 bytes
I am trying to make a new editor inheriting from IdrawEditor. To understand
how the Unidraw package works, I have been playing with it and Idraw. Currently,
I added a menu to Idraw, which allows me to draw a rectangular when I push a
button in that menu. I wrote the following code and the new menu comes up. But
when I push the button, nothing is drawn. What am I doing wrong?
Added to ided.h and ided.c
---------------ided.h----------------
#ifndef eded_h
#define eded_h
class EdEditor : public IdrawEditor {
public:
EdEditor(GraphicComp * );
EdEditor(const char* );
private:
void Init1();
virtual Interactor* Commands();
PulldownMenu * MyMenu();
};
---------------ided.c-------------------
EdEditor::EdEditor(GraphicComp * comp) : IdrawEditor(comp){this->Init1();}
EdEditor::EdEditor(const char * file) : IdrawEditor(file){this->Init1();}
Interactor* EdEditor::Commands () {
MenuBar* commands = (MenuBar *)IdrawEditor::Commands();
commands->Include(MyMenu());
return commands;
}
PulldownMenu* EdEditor::MyMenu () {
PulldownMenu* pdm = MakePulldown("Mine");
Include(
new MyCmd(new ControlInfo("My Command", KLBL_MY, CODE_MY)),
pdm
);
return pdm;
}
void EdEditor::Init1(){
this->Init();
}
#endif
Added to Unidraw's grcomp.c
----------grcomp.c----------------
} else if (cmd->IsA(MY_CMD)) {
const unit = 15;
cout << "my command is executed " << endl;
SF_Rect* rect = new SF_Rect(0, 0, unit, unit*4/5, stdgraphic);
rect ->SetPattern(psnonepat);
RectComp * rectComp = new RectComp(rect);
GraphicView * rectView = (GraphicView *) rectComp->Create(COMPONENT_VIEW);
rectComp->Attach(rectView);
Clipboard* cb = new Clipboard(rectComp);
cmd->SetClipboard(cb);
Iterator i;
for (cb->First(i); !cb->Done(i); cb->Next(i)) {
cout << "in for loop "<< endl;
Append(cb->GetComp(i));
}
Notify();
SelectClipboard(cb, ed);
unidraw->Update();
-----------------------------------
BTW, why the interpret member function of GraphicComponent is implemented that
way?
GraphicComponent * gc = new SomeComp(...);
Command * c = new Somecommand(...);
rectComp->interpret(c);
And inside of intepret, basically according to the type of the command,
if-then-else is used to process the command. I read John's technical
report discussing this problem and am a little confused. He did it that
way because there are two objects (rather than one) for resolution?
If we define a virtual function called Execute_it for each subclass of the
Command class, can we rewrite Interpret as in the following?
Interpret (Command * c){
c->Excute_it();
}
If that is the case, adding a new command, subclass of Command, becomes
trivial. Am I wrong?
Zen Kishimoto (zen@syl.dl.nec.com)
Technical Details
Message-ID:
<zen.720894746@texas>Path:
arc1-ca.pugleaf.net!sparky!uunet!know!mips2!cass.ma02.bull.com!think.com!ames!saimiri.primate.wisc.edu!sdd.hp.com!sgiblab!nec-gw!netkeeper!vivaldi!texas!texas!zenShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!mips2!cass.ma02.bull.com!think.com!ames!saimiri.primate.wisc.edu!sdd.hp.com!sgiblab!nec-gw!netkeeper!vivaldi!texas!texas!zen From: zen@syl.dl.nec.com (zen kishimoto) Newsgroups: comp.windows.interviews Subject: ided modification Summary: I wonder why this does not work. Keywords: Unidraw Idraw Message-ID: <zen.720894746@texas> Date: 4 Nov 92 16:32:26 GMT Sender: news@syl.dl.nec.com (CCSL News--cjk) Organization: NEC Systems Lab., C&C Software Technology Center (Dallas, TX) Lines: 105 Nntp-Posting-Host: texas.syl.dl.nec.com