import xcffib
import struct
import io

MAJOR_VERSION = 1
MINOR_VERSION = 0
key = xcffib.ExtensionKey("XpExtension")
_events = {}
_errors = {}
from . import xproto


class PRINTER(xcffib.Struct):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Struct.__init__(self, unpacker)
        base = unpacker.offset
        (self.nameLen,) = unpacker.unpack("=I")
        self.name = xcffib.List(unpacker, "c", self.nameLen)
        (self.descLen,) = unpacker.unpack("=I")
        unpacker.pad("c")
        self.description = xcffib.List(unpacker, "c", self.descLen)
        self.bufsize = unpacker.offset - base

    def pack(self):
        buf = io.BytesIO()
        buf.write(struct.pack("=I", self.nameLen))
        buf.write(xcffib.pack_list(self.name, "c"))
        buf.write(
            struct.pack(
                "=4x",
            )
        )
        buf.write(struct.pack("=I", self.descLen))
        buf.write(xcffib.pack_list(self.description, "c"))
        buf.write(
            struct.pack(
                "=4x",
            )
        )
        return buf.getvalue()

    @classmethod
    def synthetic(cls, nameLen, name, descLen, description):
        self = cls.__new__(cls)
        self.nameLen = nameLen
        self.name = name
        self.descLen = descLen
        self.description = description
        return self


class GetDoc:
    Finished = 0
    SecondConsumer = 1


class EvMask:
    NoEventMask = 0
    PrintMask = 1 << 0
    AttributeMask = 1 << 1


class Detail:
    StartJobNotify = 1
    EndJobNotify = 2
    StartDocNotify = 3
    EndDocNotify = 4
    StartPageNotify = 5
    EndPageNotify = 6


class Attr:
    JobAttr = 1
    DocAttr = 2
    PageAttr = 3
    PrinterAttr = 4
    ServerAttr = 5
    MediumAttr = 6
    SpoolerAttr = 7


class PrintQueryVersionReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        self.major_version, self.minor_version = unpacker.unpack("=xx2x4xHH")
        self.bufsize = unpacker.offset - base


class PrintQueryVersionCookie(xcffib.Cookie):
    reply_type = PrintQueryVersionReply


class PrintGetPrinterListReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.listCount,) = unpacker.unpack("=xx2x4xI20x")
        self.printers = xcffib.List(unpacker, PRINTER, self.listCount)
        self.bufsize = unpacker.offset - base


class PrintGetPrinterListCookie(xcffib.Cookie):
    reply_type = PrintGetPrinterListReply


class PrintGetContextReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.context,) = unpacker.unpack("=xx2x4xI")
        self.bufsize = unpacker.offset - base


class PrintGetContextCookie(xcffib.Cookie):
    reply_type = PrintGetContextReply


class PrintGetScreenOfContextReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.root,) = unpacker.unpack("=xx2x4xI")
        self.bufsize = unpacker.offset - base


class PrintGetScreenOfContextCookie(xcffib.Cookie):
    reply_type = PrintGetScreenOfContextReply


class PrintGetDocumentDataReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        self.status_code, self.finished_flag, self.dataLen = unpacker.unpack(
            "=xx2x4xIII12x"
        )
        self.data = xcffib.List(unpacker, "B", self.dataLen)
        self.bufsize = unpacker.offset - base


class PrintGetDocumentDataCookie(xcffib.Cookie):
    reply_type = PrintGetDocumentDataReply


class PrintInputSelectedReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        self.event_mask, self.all_events_mask = unpacker.unpack("=xx2x4xII")
        self.bufsize = unpacker.offset - base


class PrintInputSelectedCookie(xcffib.Cookie):
    reply_type = PrintInputSelectedReply


class PrintGetAttributesReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.stringLen,) = unpacker.unpack("=xx2x4xI20x")
        self.attributes = xcffib.List(unpacker, "c", self.stringLen)
        self.bufsize = unpacker.offset - base


class PrintGetAttributesCookie(xcffib.Cookie):
    reply_type = PrintGetAttributesReply


class PrintGetOneAttributesReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.valueLen,) = unpacker.unpack("=xx2x4xI20x")
        self.value = xcffib.List(unpacker, "c", self.valueLen)
        self.bufsize = unpacker.offset - base


class PrintGetOneAttributesCookie(xcffib.Cookie):
    reply_type = PrintGetOneAttributesReply


class PrintGetPageDimensionsReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (
            self.width,
            self.height,
            self.offset_x,
            self.offset_y,
            self.reproducible_width,
            self.reproducible_height,
        ) = unpacker.unpack("=xx2x4xHHHHHH")
        self.bufsize = unpacker.offset - base


class PrintGetPageDimensionsCookie(xcffib.Cookie):
    reply_type = PrintGetPageDimensionsReply


class PrintQueryScreensReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.listCount,) = unpacker.unpack("=xx2x4xI20x")
        self.roots = xcffib.List(unpacker, "I", self.listCount)
        self.bufsize = unpacker.offset - base


class PrintQueryScreensCookie(xcffib.Cookie):
    reply_type = PrintQueryScreensReply


class PrintSetImageResolutionReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        self.status, self.previous_resolutions = unpacker.unpack("=xB2x4xH")
        self.bufsize = unpacker.offset - base


class PrintSetImageResolutionCookie(xcffib.Cookie):
    reply_type = PrintSetImageResolutionReply


class PrintGetImageResolutionReply(xcffib.Reply):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Reply.__init__(self, unpacker)
        base = unpacker.offset
        (self.image_resolution,) = unpacker.unpack("=xx2x4xH")
        self.bufsize = unpacker.offset - base


class PrintGetImageResolutionCookie(xcffib.Cookie):
    reply_type = PrintGetImageResolutionReply


class NotifyEvent(xcffib.Event):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Event.__init__(self, unpacker)
        base = unpacker.offset
        self.detail, self.context, self.cancel = unpacker.unpack("=xB2xIB")
        self.bufsize = unpacker.offset - base

    def pack(self):
        buf = io.BytesIO()
        buf.write(struct.pack("=B", 0))
        buf.write(struct.pack("=B2xIB", self.detail, self.context, self.cancel))
        buf_len = len(buf.getvalue())
        if buf_len < 32:
            buf.write(struct.pack(("%dx" % (32 - buf_len))))
        return buf.getvalue()

    @classmethod
    def synthetic(cls, detail, context, cancel):
        self = cls.__new__(cls)
        self.detail = detail
        self.context = context
        self.cancel = cancel
        return self


_events[0] = NotifyEvent


class AttributNotifyEvent(xcffib.Event):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Event.__init__(self, unpacker)
        base = unpacker.offset
        self.detail, self.context = unpacker.unpack("=xB2xI")
        self.bufsize = unpacker.offset - base

    def pack(self):
        buf = io.BytesIO()
        buf.write(struct.pack("=B", 1))
        buf.write(struct.pack("=B2xI", self.detail, self.context))
        buf_len = len(buf.getvalue())
        if buf_len < 32:
            buf.write(struct.pack(("%dx" % (32 - buf_len))))
        return buf.getvalue()

    @classmethod
    def synthetic(cls, detail, context):
        self = cls.__new__(cls)
        self.detail = detail
        self.context = context
        return self


_events[1] = AttributNotifyEvent


class BadContextError(xcffib.Error):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Error.__init__(self, unpacker)
        base = unpacker.offset
        unpacker.unpack("=xx2x")
        self.bufsize = unpacker.offset - base

    def pack(self):
        buf = io.BytesIO()
        buf.write(struct.pack("=B", 0))
        buf.write(struct.pack("=x2x"))
        return buf.getvalue()


BadBadContext = BadContextError
_errors[0] = BadContextError


class BadSequenceError(xcffib.Error):
    xge = False

    def __init__(self, unpacker):
        if isinstance(unpacker, xcffib.Protobj):
            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
        xcffib.Error.__init__(self, unpacker)
        base = unpacker.offset
        unpacker.unpack("=xx2x")
        self.bufsize = unpacker.offset - base

    def pack(self):
        buf = io.BytesIO()
        buf.write(struct.pack("=B", 1))
        buf.write(struct.pack("=x2x"))
        return buf.getvalue()


BadBadSequence = BadSequenceError
_errors[1] = BadSequenceError


class xprintExtension(xcffib.Extension):
    def PrintQueryVersion(self, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2x"))
        return self.send_request(0, buf, PrintQueryVersionCookie, is_checked=is_checked)

    def PrintQueryVersionChecked(self):
        return self.PrintQueryVersion(is_checked=True)

    def PrintQueryVersionUnchecked(self):
        return self.PrintQueryVersion(is_checked=False)

    def PrintGetPrinterList(
        self, printerNameLen, localeLen, printer_name, locale, is_checked=True
    ):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xII", printerNameLen, localeLen))
        buf.write(xcffib.pack_list(printer_name, "c"))
        buf.write(
            struct.pack(
                "=4x",
            )
        )
        buf.write(xcffib.pack_list(locale, "c"))
        return self.send_request(
            1, buf, PrintGetPrinterListCookie, is_checked=is_checked
        )

    def PrintGetPrinterListChecked(
        self, printerNameLen, localeLen, printer_name, locale
    ):
        return self.PrintGetPrinterList(
            printerNameLen, localeLen, printer_name, locale, is_checked=True
        )

    def PrintGetPrinterListUnchecked(
        self, printerNameLen, localeLen, printer_name, locale
    ):
        return self.PrintGetPrinterList(
            printerNameLen, localeLen, printer_name, locale, is_checked=False
        )

    def PrintRehashPrinterList(self, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2x"))
        return self.send_request(20, buf, is_checked=is_checked)

    def PrintRehashPrinterListChecked(self):
        return self.PrintRehashPrinterList(is_checked=True)

    def PrintRehashPrinterListUnchecked(self):
        return self.PrintRehashPrinterList(is_checked=False)

    def CreateContext(
        self,
        context_id,
        printerNameLen,
        localeLen,
        printerName,
        locale,
        is_checked=False,
    ):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xIII", context_id, printerNameLen, localeLen))
        buf.write(xcffib.pack_list(printerName, "c"))
        buf.write(
            struct.pack(
                "=4x",
            )
        )
        buf.write(xcffib.pack_list(locale, "c"))
        return self.send_request(2, buf, is_checked=is_checked)

    def CreateContextChecked(
        self, context_id, printerNameLen, localeLen, printerName, locale
    ):
        return self.CreateContext(
            context_id, printerNameLen, localeLen, printerName, locale, is_checked=True
        )

    def CreateContextUnchecked(
        self, context_id, printerNameLen, localeLen, printerName, locale
    ):
        return self.CreateContext(
            context_id, printerNameLen, localeLen, printerName, locale, is_checked=False
        )

    def PrintSetContext(self, context, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xI", context))
        return self.send_request(3, buf, is_checked=is_checked)

    def PrintSetContextChecked(self, context):
        return self.PrintSetContext(context, is_checked=True)

    def PrintSetContextUnchecked(self, context):
        return self.PrintSetContext(context, is_checked=False)

    def PrintGetContext(self, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2x"))
        return self.send_request(4, buf, PrintGetContextCookie, is_checked=is_checked)

    def PrintGetContextChecked(self):
        return self.PrintGetContext(is_checked=True)

    def PrintGetContextUnchecked(self):
        return self.PrintGetContext(is_checked=False)

    def PrintDestroyContext(self, context, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xI", context))
        return self.send_request(5, buf, is_checked=is_checked)

    def PrintDestroyContextChecked(self, context):
        return self.PrintDestroyContext(context, is_checked=True)

    def PrintDestroyContextUnchecked(self, context):
        return self.PrintDestroyContext(context, is_checked=False)

    def PrintGetScreenOfContext(self, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2x"))
        return self.send_request(
            6, buf, PrintGetScreenOfContextCookie, is_checked=is_checked
        )

    def PrintGetScreenOfContextChecked(self):
        return self.PrintGetScreenOfContext(is_checked=True)

    def PrintGetScreenOfContextUnchecked(self):
        return self.PrintGetScreenOfContext(is_checked=False)

    def PrintStartJob(self, output_mode, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xB", output_mode))
        return self.send_request(7, buf, is_checked=is_checked)

    def PrintStartJobChecked(self, output_mode):
        return self.PrintStartJob(output_mode, is_checked=True)

    def PrintStartJobUnchecked(self, output_mode):
        return self.PrintStartJob(output_mode, is_checked=False)

    def PrintEndJob(self, cancel, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xB", cancel))
        return self.send_request(8, buf, is_checked=is_checked)

    def PrintEndJobChecked(self, cancel):
        return self.PrintEndJob(cancel, is_checked=True)

    def PrintEndJobUnchecked(self, cancel):
        return self.PrintEndJob(cancel, is_checked=False)

    def PrintStartDoc(self, driver_mode, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xB", driver_mode))
        return self.send_request(9, buf, is_checked=is_checked)

    def PrintStartDocChecked(self, driver_mode):
        return self.PrintStartDoc(driver_mode, is_checked=True)

    def PrintStartDocUnchecked(self, driver_mode):
        return self.PrintStartDoc(driver_mode, is_checked=False)

    def PrintEndDoc(self, cancel, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xB", cancel))
        return self.send_request(10, buf, is_checked=is_checked)

    def PrintEndDocChecked(self, cancel):
        return self.PrintEndDoc(cancel, is_checked=True)

    def PrintEndDocUnchecked(self, cancel):
        return self.PrintEndDoc(cancel, is_checked=False)

    def PrintPutDocumentData(
        self,
        drawable,
        len_data,
        len_fmt,
        len_options,
        data,
        doc_format,
        options,
        is_checked=False,
    ):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xIIHH", drawable, len_data, len_fmt, len_options))
        buf.write(xcffib.pack_list(data, "B"))
        buf.write(
            struct.pack(
                "=4x",
            )
        )
        buf.write(xcffib.pack_list(doc_format, "c"))
        buf.write(
            struct.pack(
                "=4x",
            )
        )
        buf.write(xcffib.pack_list(options, "c"))
        return self.send_request(11, buf, is_checked=is_checked)

    def PrintPutDocumentDataChecked(
        self, drawable, len_data, len_fmt, len_options, data, doc_format, options
    ):
        return self.PrintPutDocumentData(
            drawable,
            len_data,
            len_fmt,
            len_options,
            data,
            doc_format,
            options,
            is_checked=True,
        )

    def PrintPutDocumentDataUnchecked(
        self, drawable, len_data, len_fmt, len_options, data, doc_format, options
    ):
        return self.PrintPutDocumentData(
            drawable,
            len_data,
            len_fmt,
            len_options,
            data,
            doc_format,
            options,
            is_checked=False,
        )

    def PrintGetDocumentData(self, context, max_bytes, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xII", context, max_bytes))
        return self.send_request(
            12, buf, PrintGetDocumentDataCookie, is_checked=is_checked
        )

    def PrintGetDocumentDataChecked(self, context, max_bytes):
        return self.PrintGetDocumentData(context, max_bytes, is_checked=True)

    def PrintGetDocumentDataUnchecked(self, context, max_bytes):
        return self.PrintGetDocumentData(context, max_bytes, is_checked=False)

    def PrintStartPage(self, window, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xI", window))
        return self.send_request(13, buf, is_checked=is_checked)

    def PrintStartPageChecked(self, window):
        return self.PrintStartPage(window, is_checked=True)

    def PrintStartPageUnchecked(self, window):
        return self.PrintStartPage(window, is_checked=False)

    def PrintEndPage(self, cancel, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xB3x", cancel))
        return self.send_request(14, buf, is_checked=is_checked)

    def PrintEndPageChecked(self, cancel):
        return self.PrintEndPage(cancel, is_checked=True)

    def PrintEndPageUnchecked(self, cancel):
        return self.PrintEndPage(cancel, is_checked=False)

    def PrintSelectInput(self, context, event_mask, is_checked=False):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xII", context, event_mask))
        return self.send_request(15, buf, is_checked=is_checked)

    def PrintSelectInputChecked(self, context, event_mask):
        return self.PrintSelectInput(context, event_mask, is_checked=True)

    def PrintSelectInputUnchecked(self, context, event_mask):
        return self.PrintSelectInput(context, event_mask, is_checked=False)

    def PrintInputSelected(self, context, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xI", context))
        return self.send_request(
            16, buf, PrintInputSelectedCookie, is_checked=is_checked
        )

    def PrintInputSelectedChecked(self, context):
        return self.PrintInputSelected(context, is_checked=True)

    def PrintInputSelectedUnchecked(self, context):
        return self.PrintInputSelected(context, is_checked=False)

    def PrintGetAttributes(self, context, pool, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xIB3x", context, pool))
        return self.send_request(
            17, buf, PrintGetAttributesCookie, is_checked=is_checked
        )

    def PrintGetAttributesChecked(self, context, pool):
        return self.PrintGetAttributes(context, pool, is_checked=True)

    def PrintGetAttributesUnchecked(self, context, pool):
        return self.PrintGetAttributes(context, pool, is_checked=False)

    def PrintGetOneAttributes(self, context, nameLen, pool, name, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xIIB3x", context, nameLen, pool))
        buf.write(xcffib.pack_list(name, "c"))
        return self.send_request(
            19, buf, PrintGetOneAttributesCookie, is_checked=is_checked
        )

    def PrintGetOneAttributesChecked(self, context, nameLen, pool, name):
        return self.PrintGetOneAttributes(context, nameLen, pool, name, is_checked=True)

    def PrintGetOneAttributesUnchecked(self, context, nameLen, pool, name):
        return self.PrintGetOneAttributes(
            context, nameLen, pool, name, is_checked=False
        )

    def PrintSetAttributes(
        self,
        context,
        stringLen,
        pool,
        rule,
        attributes_len,
        attributes,
        is_checked=False,
    ):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xIIBB2x", context, stringLen, pool, rule))
        buf.write(xcffib.pack_list(attributes, "c"))
        return self.send_request(18, buf, is_checked=is_checked)

    def PrintSetAttributesChecked(
        self, context, stringLen, pool, rule, attributes_len, attributes
    ):
        return self.PrintSetAttributes(
            context, stringLen, pool, rule, attributes_len, attributes, is_checked=True
        )

    def PrintSetAttributesUnchecked(
        self, context, stringLen, pool, rule, attributes_len, attributes
    ):
        return self.PrintSetAttributes(
            context, stringLen, pool, rule, attributes_len, attributes, is_checked=False
        )

    def PrintGetPageDimensions(self, context, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xI", context))
        return self.send_request(
            21, buf, PrintGetPageDimensionsCookie, is_checked=is_checked
        )

    def PrintGetPageDimensionsChecked(self, context):
        return self.PrintGetPageDimensions(context, is_checked=True)

    def PrintGetPageDimensionsUnchecked(self, context):
        return self.PrintGetPageDimensions(context, is_checked=False)

    def PrintQueryScreens(self, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2x"))
        return self.send_request(
            22, buf, PrintQueryScreensCookie, is_checked=is_checked
        )

    def PrintQueryScreensChecked(self):
        return self.PrintQueryScreens(is_checked=True)

    def PrintQueryScreensUnchecked(self):
        return self.PrintQueryScreens(is_checked=False)

    def PrintSetImageResolution(self, context, image_resolution, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xIH", context, image_resolution))
        return self.send_request(
            23, buf, PrintSetImageResolutionCookie, is_checked=is_checked
        )

    def PrintSetImageResolutionChecked(self, context, image_resolution):
        return self.PrintSetImageResolution(context, image_resolution, is_checked=True)

    def PrintSetImageResolutionUnchecked(self, context, image_resolution):
        return self.PrintSetImageResolution(context, image_resolution, is_checked=False)

    def PrintGetImageResolution(self, context, is_checked=True):
        buf = io.BytesIO()
        buf.write(struct.pack("=xx2xI", context))
        return self.send_request(
            24, buf, PrintGetImageResolutionCookie, is_checked=is_checked
        )

    def PrintGetImageResolutionChecked(self, context):
        return self.PrintGetImageResolution(context, is_checked=True)

    def PrintGetImageResolutionUnchecked(self, context):
        return self.PrintGetImageResolution(context, is_checked=False)


xcffib._add_ext(key, xprintExtension, _events, _errors)
