# Path: mcomix/log.py
# def print_(*args, **options):
#     def print_generic(text):
#     def print_win32(text):
#     def __init__(self):
#     def emit(self, record):
#         INVALID_HANDLE_VALUE, STD_OUTPUT_HANDLE = -1, -11
# class PrintHandler(logging.Handler):
# 
# Path: mcomix/image_tools.py
# def fit_in_rectangle(src, width, height, scale_up=False, rotation=0):
# def fit_2_in_rectangle(src1, src2, width, height, scale_up=False,
#   rotation1=0, rotation2=0):
# def add_border(pixbuf, thickness, colour=0x000000FF):
# def get_most_common_edge_colour(pixbufs, edge=2):
#     def round_color(color, steps=10):
#         def round(color_value):
#     def get_edge_pixbuf(pixbuf, side, edge):
# def pil_to_pixbuf(image):
# def pixbuf_to_pil(pixbuf):
# def load_pixbuf(path):
# def load_pixbuf_size(path, width, height):
# def load_pixbuf_data(imgdata):
# def enhance(pixbuf, brightness=1.0, contrast=1.0, saturation=1.0,
#   sharpness=1.0, autocontrast=False):
# def get_implied_rotation(pixbuf):
# def combine_pixbufs( pixbuf1, pixbuf2, are_in_manga_mode ):
# def is_image_file(path):
#         IS_RGBA = image.mode == 'RGBA'


import gtk
import ctypes
import cStringIO
import sys
from mcomix import log
from mcomix import image_tools
        """ Copies pixbuf and path to the clipboard.
        Uses native Win32 API, as GTK+ doesn't seem to work. """

        windll = ctypes.windll
        OpenClipboard = windll.user32.OpenClipboard
        EmptyClipboard = windll.user32.EmptyClipboard
        SetClipboardData = windll.user32.SetClipboardData
        CloseClipboard = windll.user32.CloseClipboard
        GlobalAlloc = windll.kernel32.GlobalAlloc
        GlobalLock = windll.kernel32.GlobalLock
        GlobalLock.restype = ctypes.c_void_p
        GlobalUnlock = windll.kernel32.GlobalUnlock

        def buffer_to_handle(buffer, buffer_size):
            """ Creates a memory handle for the passed data.
            This handle doesn't need to be freed by the application. """
            global_mem = GlobalAlloc(
                0x0042, # GMEM_MOVEABLE | GMEM_ZEROINIT
                buffer_size)
            lock = GlobalLock(global_mem)
            ctypes.memmove(lock, ctypes.addressof(buffer), buffer_size)
            GlobalUnlock(global_mem)

            return global_mem

        # Paste the text as Unicode string
        text_buffer = ctypes.create_unicode_buffer(path)
        text_handle = buffer_to_handle(text_buffer,
                ctypes.sizeof(text_buffer))
        # Paste the image as Win32 DIB structure

# Path: mcomix/log.py
# def print_(*args, **options):
#     def print_generic(text):
#     def print_win32(text):
#     def __init__(self):
#     def emit(self, record):
#         INVALID_HANDLE_VALUE, STD_OUTPUT_HANDLE = -1, -11
# class PrintHandler(logging.Handler):
# 
# Path: mcomix/image_tools.py
# def fit_in_rectangle(src, width, height, scale_up=False, rotation=0):
# def fit_2_in_rectangle(src1, src2, width, height, scale_up=False,
#   rotation1=0, rotation2=0):
# def add_border(pixbuf, thickness, colour=0x000000FF):
# def get_most_common_edge_colour(pixbufs, edge=2):
#     def round_color(color, steps=10):
#         def round(color_value):
#     def get_edge_pixbuf(pixbuf, side, edge):
# def pil_to_pixbuf(image):
# def pixbuf_to_pil(pixbuf):
# def load_pixbuf(path):
# def load_pixbuf_size(path, width, height):
# def load_pixbuf_data(imgdata):
# def enhance(pixbuf, brightness=1.0, contrast=1.0, saturation=1.0,
#   sharpness=1.0, autocontrast=False):
# def get_implied_rotation(pixbuf):
# def combine_pixbufs( pixbuf1, pixbuf2, are_in_manga_mode ):
# def is_image_file(path):
#         IS_RGBA = image.mode == 'RGBA'


# Path: mcomix/clipboard.py
import gtk
import ctypes
import cStringIO
import sys
from mcomix import log
from mcomix import image_tools

        """ Copies pixbuf and path to the clipboard.
        Uses native Win32 API, as GTK+ doesn't seem to work. """

        windll = ctypes.windll
        OpenClipboard = windll.user32.OpenClipboard
        EmptyClipboard = windll.user32.EmptyClipboard
        SetClipboardData = windll.user32.SetClipboardData
        CloseClipboard = windll.user32.CloseClipboard
        GlobalAlloc = windll.kernel32.GlobalAlloc
        GlobalLock = windll.kernel32.GlobalLock
        GlobalLock.restype = ctypes.c_void_p
        GlobalUnlock = windll.kernel32.GlobalUnlock

        def buffer_to_handle(buffer, buffer_size):
            """ Creates a memory handle for the passed data.
            This handle doesn't need to be freed by the application. """
            global_mem = GlobalAlloc(
                0x0042, # GMEM_MOVEABLE | GMEM_ZEROINIT
                buffer_size)
            lock = GlobalLock(global_mem)
            ctypes.memmove(lock, ctypes.addressof(buffer), buffer_size)
            GlobalUnlock(global_mem)

            return global_mem

        # Paste the text as Unicode string
        text_buffer = ctypes.create_unicode_buffer(path)
        text_handle = buffer_to_handle(text_buffer,
                ctypes.sizeof(text_buffer))
        # Paste the image as Win32 DIB structure

        pil = image_tools.pixbuf_to_pil(pixbuf)