"""\
Code generator functions for wxDatePickerCtrl objects

@copyright: 2002-2007 Alberto Griggio
@copyright: 2014-2016 Carsten Grohmann
@copyright: 2016-2021 Dietmar Schwertberger
@license: MIT (see LICENSE.txt) - THIS PROGRAM COMES WITH NO WARRANTY
"""

import common, compat
import wcodegen


class PythonDatePickerCtrlGenerator(wcodegen.PythonWidgetCodeWriter):
    tmpl = '%(name)s = %(klass)s(%(parent)s, %(id)s%(style)s)\n'

    # XXX the following needs to depend on the code generator when Phoenix is about to be supported fully:
    if compat.IS_PHOENIX:
        import_modules = ['import wx.adv\n']

    if compat.IS_PHOENIX:
        def cn(self, name):
            # don't process already formatted items again
            if name.startswith('wx.'):
                return name
            if name.startswith('wx'):
                return 'wx.adv.' + name[2:]
            elif name.startswith('EVT_'):
                return 'wx.adv.' + name
            return name

    def _prepare_tmpl_content(self, obj):
        wcodegen.PythonWidgetCodeWriter._prepare_tmpl_content(self, obj)
        self.has_setdefault = int(obj.properties.get('default', 0))
        return



class CppDatePickerCtrlGenerator(wcodegen.CppWidgetCodeWriter):
    import_modules = ['<wx/datectrl.h>']
    tmpl = '%(name)s = new %(klass)s(%(parent)s, %(id)s, ' \
           'wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, ' \
           '%(style)s);\n'

    prefix_style = False
    set_default_style = True

    def _prepare_tmpl_content(self, obj):
        wcodegen.CppWidgetCodeWriter._prepare_tmpl_content(self, obj)
        self.has_setdefault = int(obj.properties.get('default', 0))
        return



def xrc_code_generator(obj):
    xrcgen = common.code_writers['XRC']

    class DatePickerCtrlXrcObject(xrcgen.DefaultXrcObject):
        def write_property(self, name, val, output, tabs):
            if name == 'label':
                # translate & into _ as accelerator marker
                val2 = val.replace('&', '_')
                if val.count('&&') > 0:
                    while True:
                        index = val.find('&&')
                        if index < 0:
                            break
                        val = val2[:index] + '&&' + val2[index+2:]
                else:
                    val = val2
            xrcgen.DefaultXrcObject.write_property(self, name, val, output, tabs)

    return DatePickerCtrlXrcObject(obj)


def initialize():
    klass = 'wxDatePickerCtrl'
    common.class_names['EditDatePickerCtrl'] = klass
    common.register('python', klass, PythonDatePickerCtrlGenerator(klass))
    common.register('C++',    klass, CppDatePickerCtrlGenerator(klass))
    common.register('XRC',    klass, xrc_code_generator)

[((81, 4, 81, 56), 'common.register', 'common.register', ({(81, 20, 81, 25): '"""XRC"""', (81, 30, 81, 35): 'klass', (81, 37, 81, 55): 'xrc_code_generator'}, {}), "('XRC', klass, xrc_code_generator)", False, 'import common, compat\n'), ((33, 8, 33, 72), 'wcodegen.PythonWidgetCodeWriter._prepare_tmpl_content', 'wcodegen.PythonWidgetCodeWriter._prepare_tmpl_content', ({(33, 62, 33, 66): 'self', (33, 68, 33, 71): 'obj'}, {}), '(self, obj)', False, 'import wcodegen\n'), ((49, 8, 49, 69), 'wcodegen.CppWidgetCodeWriter._prepare_tmpl_content', 'wcodegen.CppWidgetCodeWriter._prepare_tmpl_content', ({(49, 59, 49, 63): 'self', (49, 65, 49, 68): 'obj'}, {}), '(self, obj)', False, 'import wcodegen\n')]