Ejemplo n.º 1
0
void 
PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
{
	switch(msg->what) {
			// Get currently selected printer
		case PSRV_GET_ACTIVE_PRINTER: {
				BMessage reply('okok');
				BString printerName;
				if (fDefaultPrinter)
					printerName = fDefaultPrinter->Name();
				BString mime;
				if (fUseConfigWindow && MimeTypeForSender(msg, mime)) {
					BAutolock lock(gLock);
					if (lock.IsLocked()) {
							// override with printer for application
						PrinterSettings* p = fSettings->FindPrinterSettings(
							mime.String());
						if (p)
							printerName = p->GetPrinter();
					}
				}
				reply.AddString("printer_name", printerName);
				// BeOS knows not if color or not, so always color
				reply.AddInt32("color", BPrintJob::B_COLOR_PRINTER);
				msg->SendReply(&reply);
			}
			break;

			//make printer active (currently always quietly :))
		case PSRV_MAKE_PRINTER_ACTIVE_QUIETLY:
			//make printer active quietly
		case PSRV_MAKE_PRINTER_ACTIVE: {
				BString newActivePrinter;
				if (msg->FindString("printer",&newActivePrinter) == B_OK) {
					SelectPrinter(newActivePrinter.String());
				}
			}
			break;

		case PSRV_SHOW_PAGE_SETUP:
		case PSRV_SHOW_PRINT_SETUP:
		case PSRV_GET_DEFAULT_SETTINGS:
		case PSRV_MAKE_PRINTER:
			AsyncHandleMessage(DetachCurrentMessage());
			break;

			// Tell printer addon to print a spooled job
		case PSRV_PRINT_SPOOLED_JOB:
			HandleSpooledJobs();
			break;
	}
}
Ejemplo n.º 2
0
void
PrintServerApp::HandleScriptingCommand(BMessage* msg)
{
	BString propName;
	BMessage spec;
	int32 idx;

	if (msg->GetCurrentSpecifier(&idx,&spec) == B_OK &&
		spec.FindString("property",&propName) == B_OK) {
		switch(msg->what) {
			case B_GET_PROPERTY:
				if (propName == "ActivePrinter") {
					BMessage reply(B_REPLY);
					reply.AddString("result", fDefaultPrinter
						? fDefaultPrinter->Name() : "");
					reply.AddInt32("error", B_OK);
					msg->SendReply(&reply);
				} else if (propName == "UseConfigWindow") {
					BMessage reply(B_REPLY);
					reply.AddString("result", fUseConfigWindow
						? "true" : "false");
					reply.AddInt32("error", B_OK);
					msg->SendReply(&reply);
				}
				break;

			case B_SET_PROPERTY:
				if (propName == "ActivePrinter") {
					BString newActivePrinter;
					if (msg->FindString("data", &newActivePrinter) == B_OK) {
						BMessage reply(B_REPLY);
						reply.AddInt32("error",
							SelectPrinter(newActivePrinter.String()));
						msg->SendReply(&reply);
					}
				} else if (propName == "UseConfigWindow") {
					bool useConfigWindow;
					if (msg->FindBool("data", &useConfigWindow) == B_OK) {
						fUseConfigWindow = useConfigWindow;
						BMessage reply(B_REPLY);
						reply.AddInt32("error", fUseConfigWindow);
						msg->SendReply(&reply);
					}
				}
				break;

			case B_CREATE_PROPERTY:
				if (propName == "Printer") {
					BString name, driver, transport, config;

					if (msg->FindString("name", &name) == B_OK
						&& msg->FindString("driver", &driver) == B_OK
						&& msg->FindString("transport", &transport) == B_OK
						&& msg->FindString("config", &config) == B_OK) {
						BMessage reply(B_REPLY);
						reply.AddInt32("error", CreatePrinter(name.String(),
							driver.String(), "Local", transport.String(),
							config.String()));
						msg->SendReply(&reply);
					}
				}
				break;

			case B_DELETE_PROPERTY: {
					Printer* printer = GetPrinterFromSpecifier(&spec);
					status_t rc = B_BAD_VALUE;

					if (printer != NULL)
						rc=printer->Remove();

					BMessage reply(B_REPLY);
					reply.AddInt32("error", rc);
					msg->SendReply(&reply);
				}
				break;

			case B_COUNT_PROPERTIES:
				if (propName == "Printers") {
					BMessage reply(B_REPLY);
					reply.AddInt32("result", Printer::CountPrinters());
					reply.AddInt32("error", B_OK);
					msg->SendReply(&reply);
				} else if (propName == "Transports") {
					BMessage reply(B_REPLY);
					reply.AddInt32("result", Transport::CountTransports());
					reply.AddInt32("error", B_OK);
					msg->SendReply(&reply);
				}
				break;
		}
	}
}
Ejemplo n.º 3
0
void GTerm::pc_arg( void )
{
    int i, yp, yp2;

    //printf("pc_arg: pc_curcmd = %d...\n", pc_curcmd);

    pc_args[pc_argcount++ ] = * input_data;

    if (pc_argcount == pc_numargs)
    {
        switch (pc_curcmd)
        {
            case GTERM_PC_CMD_CURONOFF:
                //printf("pc_arg: curonoff got %d\n", *input_data);
                if (* input_data)
                    clear_mode_flag(CURSORINVISIBLE);
                else
                    set_mode_flag(CURSORINVISIBLE);

                current_state = pc_cmd_state;
                changed_line(cursor_y, cursor_x, cursor_x);
                break;

            case GTERM_PC_CMD_MOVECURSOR:
                //printf("pc_arg: movecursor (%d, %d)\n", pc_args[0], pc_args[1]);
                move_cursor(pc_args[0], pc_args[1]);
                current_state = pc_cmd_state;
                break;

            case GTERM_PC_CMD_PUTTEXT:
                //printf("pc_arg: puttext got %d, %d, %d, %d\n", pc_args[0], pc_args[1], pc_args[2], pc_args[3]);
                pc_numdata = pc_args[2] * pc_args[3] * 2;
                pc_datacount = 0;
                pc_curx = pc_args[0];
                pc_cury = pc_args[1];

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                    current_state = pc_cmd_state;

                break;

            case GTERM_PC_CMD_WRITE:
                //printf("pc_arg: write got %d, %d, %d, %d\n", pc_args[0], pc_args[1], pc_args[2], pc_args[3]);
                pc_numdata = pc_args[2];
                pc_datacount = 0;
                pc_curx = pc_args[0];
                pc_cury = pc_args[1];

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                    current_state = pc_cmd_state;

                break;

            case GTERM_PC_CMD_MOVETEXT: // <sx> <sy> <wid> <len> <dx> <dy>
                if (pc_args[1]<pc_args[5])
                {
                    for (i = 0; i<pc_args[3]; i++)
                    {
						int idx1 = pc_args[1] + i;
						yp = linenumbers[idx1] * MAXWIDTH;

						int idx2 = pc_args[5] + i;
						yp2 = linenumbers[idx2] * MAXWIDTH;

                        memmove(& text[yp2 + pc_args[4]], & text[yp + pc_args[0]], pc_args[2]);

						string substring = tm[idx1].substr(pc_args[0], pc_args[2]);
						tm[idx2].replace(pc_args[4], pc_args[2], substring);

                        memmove(& color[yp2 + pc_args[4]], & color[yp + pc_args[0]], pc_args[2]);
						// TODO Doesn't seem to get here in normal use, but probably ought to
						//		eventually figure out what's going on so I can manipulate the text manager here
                        changed_line(pc_args[5] + i, pc_args[4], pc_args[4] + pc_args[2] - 1);
                    }
                }
                else
                {
                    for (i = pc_args[3] - 1; i>=0; i--)
                    {
						int idx1 = pc_args[1] + i;
						yp = linenumbers[idx1] * MAXWIDTH;

						int idx2 = pc_args[5] + i;
						yp2 = linenumbers[idx2] * MAXWIDTH;

                        memmove(& text[yp2 + pc_args[4]], & text[yp + pc_args[0]], pc_args[2]);

						string substring = tm[idx1].substr(pc_args[0], pc_args[2]);
						tm[idx2].replace(pc_args[4], pc_args[2], substring);

                        memmove(& color[yp2 + pc_args[4]], & color[yp + pc_args[0]], pc_args[2]);
						// TODO ditto as with previous
                        changed_line(pc_args[5] + i, pc_args[4], pc_args[4] + pc_args[2] - 1);
                    }
                }

                current_state = pc_cmd_state;
                break;

            case GTERM_PC_CMD_SELECTPRINTER:
                pc_numdata = pc_args[0];
                pc_datacount = 0;
                memset(pc_printername, 0, sizeof(pc_printername));

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                {
                    SelectPrinter("");

                    current_state = pc_cmd_state;
                }

                break;

            case GTERM_PC_CMD_PRINTCHAR:
                PrintChars(1, & pc_args[0]);
                current_state = pc_cmd_state;
                break;

            case GTERM_PC_CMD_PRINTCHARS:
                pc_numdata = (pc_args[0] << 8) + pc_args[1];
                pc_datacount = 0;

                if (pc_numdata)
                    current_state = pc_data_state;
                else
                    current_state = pc_cmd_state;

                break;
        }
    }
}
Ejemplo n.º 4
0
void GTerm::pc_data( void )
{
    int yp;
	int altY;

    //printf("pc_data: pc_curcmd = %d, pc_datacount = %d, pc_numdata = %d, pc_curx = %d, pc_cur_y = %d...\n", pc_curcmd, pc_datacount, pc_numdata, pc_curx, pc_cury);
    switch (pc_curcmd)
    {
        case GTERM_PC_CMD_PUTTEXT:
            yp = linenumbers[pc_cury] * MAXWIDTH;

			altY = m_nextLineCounter * MAXWIDTH;

            if (!(pc_datacount & 1))
            {
                //printf("pc_data: got char %d\n", *input_data);
                //text[yp + pc_curx] = * input_data;

				tm[pc_cury][pc_curx] = *input_data;
            }
            else
            {
                //printf("pc_data: got attr %d\n", *input_data);
                //color[yp + pc_curx] = * input_data << 4;
				tm.SetColorAdjusted(pc_cury, pc_curx, (*input_data << 4));
            }

            if (pc_datacount & 1)
            {
                changed_line(pc_cury, pc_args[0], pc_curx);

                pc_curx++;

                if (pc_curx == pc_args[0] + pc_args[2])
                {
                    pc_curx = pc_args[0];

                    pc_cury++;
                }
            }

            break;

        case GTERM_PC_CMD_WRITE:
            yp = linenumbers[pc_cury] * MAXWIDTH;
			altY = m_nextLineCounter * MAXWIDTH;

            //text[yp + pc_curx] = * input_data;
			tm[pc_cury][pc_curx] = *input_data;

            //color[yp + pc_curx] = (unsigned short)pc_args[3] << 4;
			tm.SetColorAdjusted(pc_cury, pc_curx, ((unsigned short)pc_args[3] << 4) );
            changed_line(pc_cury, pc_args[0], pc_curx);
            pc_curx++;
            break;

        case GTERM_PC_CMD_SELECTPRINTER:
            if (pc_datacount<GTERM_PC_MAXPRINTERNAME - 1)
                pc_printername[pc_datacount] = * input_data;

            if (pc_datacount == pc_numdata - 1)
                SelectPrinter(pc_printername);

            break;

        case GTERM_PC_CMD_PRINTCHARS:
            PrintChars(1, input_data);
            break;
    }

    pc_datacount++;

    if (pc_datacount == pc_numdata)
        current_state = pc_cmd_state;
}