Exemplo n.º 1
0
void PrintCmd::Execute () {
    GraphicComp* comps = GetGraphicComp();
    boolean ok;

    if (_dialog == nil) {
        _dialog = new PrintDialog;
    }

    do {
        _editor->InsertDialog(_dialog);
        boolean accepted = _dialog->Accept();
        _editor->RemoveDialog(_dialog);

        if (!accepted) {
            break;
        }

        filebuf fbuf;
        char* tmpfilename;

        if (_dialog->ToPrinter()) {
            tmpfilename = tmpnam(nil);
            ok = fbuf.open(tmpfilename, IOS_OUT) != 0;
        } else {
            ok = fbuf.open((char*) _dialog->Choice(), IOS_OUT) != 0;
        }

        if (ok) {
            ostream out(&fbuf);
            ExternView* ev = (ExternView*) comps->Create(POSTSCRIPT_VIEW);
            comps->Attach(ev);
            ev->Update();
            ok = ev->Emit(out);
	    out.flush();
            delete ev;

            if (_dialog->ToPrinter()) {
                ok = print(_dialog->Choice(), tmpfilename) == 0;
            }
        }
        if (!ok) {
            _dialog->SetTitle("Couldn't print!");
        }
    } while (!ok);

    _dialog->SetTitle("");
}