FBP-Perl

 view release on metacpan or  search on metacpan

lib/FBP/Perl.pm  view on Meta::CPAN

readable. The produced code can be used either as a starter template which
you modify, or as a pristine class which you subclass in order to customise.

Born from the L<Padre> Perl IDE project, the code generation API provided by
B<FBP::Perl> is also extremely amenable to being itself subclassed.

This allows you to relatively easily write customised code generators that
produce output more closely tailored to your large Wx-based application, or
to automatically integrate Perl Tidy or other beautifiers into your workflow.

=head1 METHODS

TO BE COMPLETED

=cut

use 5.008005;
use strict;
use warnings;
use B                  ();
use Scalar::Util  1.19 ();
use Params::Util  1.00 ();
use FBP           0.41 ();

our $VERSION    = '0.78';
our $COMPATIBLE = '0.67';

# Event Macro Binding Table
our %MACRO = (
	# Common low level events
	OnEraseBackground         => [ 1, 'EVT_ERASE_BACKGROUND'           ],
	OnPaint                   => [ 1, 'EVT_PAINT'                      ],
	OnUpdateUI                => [ 2, 'EVT_UPDATE_UI'                  ],

	# wxActivateEvent
	OnActivate                => [ 1, 'EVT_ACTIVATE'                   ],
	OnActivateApp             => [ 1, 'EVT_ACTIVATE_APP'               ],

	# wxCalendar
	OnCalendar                => [ 2, 'EVT_CALENDAR'                   ],
	OnCalendarSelChanged      => [ 2, 'EVT_CALENDAR_SEL_CHANGED'       ],
	OnCalendarDay             => [ 2, 'EVT_CALENDAR_DAY'               ],
	OnCalendarMonth           => [ 2, 'EVT_CALENDAR_MONTH'             ],
	OnCalendarYear            => [ 2, 'EVT_CALENDAR_YEAR'              ],
	OnCalendarWeekDayClicked  => [ 2, 'EVT_CALENDAR_WEEKDAY_CLICKED'   ],

	# wxChoicebook
	OnChoicebookPageChanged   => [ 2, 'EVT_CHOICEBOOK_PAGE_CHANGED'    ],
	OnChoicebookPageChanging  => [ 2, 'EVT_CHOICEBOOK_PAGE_CHANGING'   ],

	# wxCommandEvent
	OnButtonClick             => [ 2, 'EVT_BUTTON'                     ],
	OnToggleButton            => [ 2, 'EVT_TOGGLEBUTTON'               ],
	OnCheckBox                => [ 2, 'EVT_CHECKBOX'                   ],
	OnChoice                  => [ 2, 'EVT_CHOICE'                     ],
	OnCombobox                => [ 2, 'EVT_COMBOBOX'                   ],
	OnListBox                 => [ 2, 'EVT_LISTBOX'                    ],
	OnListBoxDClick           => [ 2, 'EVT_LISTBOX_DCLICK'             ],
	OnText                    => [ 2, 'EVT_TEXT'                       ],
	OnTextEnter               => [ 2, 'EVT_TEXT_ENTER'                 ],
	OnMenu                    => [ 2, 'EVT_MENU'                       ],

	# wxColourPickerCtrl
	OnColourChanged           => [ 2, 'EVT_COLOURPICKER_CHANGED'       ],

	# wxCloseEvent
	OnClose                   => [ 1, 'EVT_CLOSE'                      ],

	# wxDatePickerCtrl
	OnDateChanged             => [ 2, 'EVT_DATE_CHANGED'               ],

	# wxFilePickerCtrl
	OnFileChanged             => [ 2, 'EVT_FILEPICKER_CHANGED'         ],

	# wxFocusEvent
	OnKillFocus               => [ 1, 'EVT_KILL_FOCUS'                 ],
	OnSetFocus                => [ 1, 'EVT_SET_FOCUS'                  ],

	# wxFontPickerCtrl
	OnFontChanged             => [ 2, 'EVT_FONTPICKER_CHANGED'         ],

	# wxGrid
	OnGridCellLeftClick       => [ 1, 'EVT_GRID_CELL_LEFT_CLICK'       ],
	OnGridCellRightClick      => [ 1, 'EVT_GRID_CELL_RIGHT_CLICK'      ],
	OnGridCellLeftDClick      => [ 1, 'EVT_GRID_CELL_LEFT_DCLICK'      ],
	OnGridCellRightDClick     => [ 1, 'EVT_GRID_CELL_RIGHT_DCLICK'     ],
	OnGridLabelLeftClick      => [ 1, 'EVT_GRID_LABEL_LEFT_CLICK'      ],
	OnGridLabelRightClick     => [ 1, 'EVT_GRID_LABEL_RIGHT_CLICK'     ],
	OnGridLabelLeftDClick     => [ 1, 'EVT_GRID_LABEL_LEFT_DCLICK'     ],
	OnGridLabelRightDClick    => [ 1, 'EVT_GRID_LABEL_RIGHT_DCLICK'    ],
	OnGridCellChange          => [ 1, 'EVT_GRID_CELL_CHANGE'           ],
	OnGridSelectCell          => [ 1, 'EVT_GRID_SELECT_CELL'           ],
	OnGridEditorHidden        => [ 1, 'EVT_GRID_EDITOR_HIDDEN'         ],
	OnGridEditorShown         => [ 1, 'EVT_GRID_EDITOR_SHOWN'          ],
	OnGridColSize             => [ 1, 'EVT_GRID_COL_SIZE'              ],
	OnGridRowSize             => [ 1, 'EVT_GRID_ROW_SIZE'              ],
	OnGridRangeSelect         => [ 1, 'EVT_GRID_RANGE_SELECT'          ],
	OnGridEditorCreated       => [ 1, 'EVT_GRID_EDITOR_CREATED'        ],

	# Not sure why wxFormBuilder makes these grid event duplicates
	# so we just slavishly cargo cult what they do in the C code.
	OnGridCmdCellLeftClick    => [ 1, 'EVT_GRID_CELL_LEFT_CLICK'       ],
	OnGridCmdCellRightClick   => [ 1, 'EVT_GRID_CELL_RIGHT_CLICK'      ],
	OnGridCmdCellLeftDClick   => [ 1, 'EVT_GRID_CELL_LEFT_DCLICK'      ],
	OnGridCmdCellRightDClick  => [ 1, 'EVT_GRID_CELL_RIGHT_DCLICK'     ],
	OnGridCmdLabelLeftClick   => [ 1, 'EVT_GRID_LABEL_LEFT_CLICK'      ],
	OnGridCmdLabelRightClick  => [ 1, 'EVT_GRID_LABEL_RIGHT_CLICK'     ],
	OnGridCmdLabelLeftDClick  => [ 1, 'EVT_GRID_LABEL_LEFT_DCLICK'     ],
	OnGridCmdLabelRightDClick => [ 1, 'EVT_GRID_LABEL_RIGHT_DCLICK'    ],
	OnGridCmdCellChange       => [ 1, 'EVT_GRID_CELL_CHANGE'           ],
	OnGridCmdSelectCell       => [ 1, 'EVT_GRID_SELECT_CELL'           ],
	OnGridCmdEditorHidden     => [ 1, 'EVT_GRID_EDITOR_HIDDEN'         ],
	OnGridCmdEditorShown      => [ 1, 'EVT_GRID_EDITOR_SHOWN'          ],
	OnGridCmdColSize          => [ 1, 'EVT_GRID_COL_SIZE'              ],
	OnGridCmdRowSize          => [ 1, 'EVT_GRID_ROW_SIZE'              ],
	OnGridCmdRangeSelect      => [ 1, 'EVT_GRID_RANGE_SELECT'          ],
	OnGridCmdEditorCreated    => [ 1, 'EVT_GRID_EDITOR_CREATED'        ],

	# wxHtmlWindow
	OnHtmlCellClicked         => [ 2, 'EVT_HTML_CELL_CLICKED'          ],
	OnHtmlCellHover           => [ 2, 'EVT_HTML_CELL_HOVER'            ],
	OnHtmlLinkClicked         => [ 2, 'EVT_HTML_LINK_CLICKED'          ],

	# wxIconizeEvent
	OnIconize                 => [ 1, 'EVT_ICONIZE'                    ],

	# wxIdleEvent
	OnIdle                    => [ 1, 'EVT_IDLE'                       ],

	# wxInitDialogEvent
	OnInitDialog              => [ 1, 'EVT_INIT_DIALOG'                ],

	# wxKeyEvent
	OnChar                    => [ 1, 'EVT_CHAR'                       ],
	OnKeyDown                 => [ 1, 'EVT_KEY_DOWN'                   ],
	OnKeyUp                   => [ 1, 'EVT_KEY_UP'                     ],

	# wxListEvent
	OnListBeginDrag           => [ 2, 'EVT_LIST_BEGIN_DRAG'            ],
	OnListBeginRDrag          => [ 2, 'EVT_LIST_BEGIN_RDRAG'           ],
	OnListBeginLabelEdit      => [ 2, 'EVT_LIST_BEGIN_LABEL_EDIT'      ],
	OnListCacheHint           => [ 2, 'EVT_LIST_CACHE_HINT'            ],
	OnListEndLabelEdit        => [ 2, 'EVT_LIST_END_LABEL_EDIT'        ],
	OnListDeleteItem          => [ 2, 'EVT_LIST_DELETE_ITEM'           ],
	OnListDeleteAllItems      => [ 2, 'EVT_LIST_DELETE_ALL_ITEMS'      ],
	OnListInsertItem          => [ 2, 'EVT_LIST_INSERT_ITEM'           ],
	OnListItemActivated       => [ 2, 'EVT_LIST_ITEM_ACTIVATED'        ],
	OnListItemSelected        => [ 2, 'EVT_LIST_ITEM_SELECTED'         ],
	OnListItemDeselected      => [ 2, 'EVT_LIST_ITEM_DESELECTED'       ],
	OnListItemFocused         => [ 2, 'EVT_LIST_ITEM_FOCUSED'          ],
	OnListItemMiddleClick     => [ 2, 'EVT_LIST_MIDDLE_CLICK'          ],
	OnListItemRightClick      => [ 2, 'EVT_LIST_RIGHT_CLICK'           ],
	OnListKeyDown             => [ 2, 'EVT_LIST_KEY_DOWN'              ],
	OnListColClick            => [ 2, 'EVT_LIST_COL_CLICK'             ],
	OnListColRightClick       => [ 2, 'EVT_LIST_COL_RIGHT_CLICK'       ],
	OnListColBeginDrag        => [ 2, 'EVT_LIST_COL_BEGIN_DRAG'        ],
	OnListColDragging         => [ 2, 'EVT_LIST_COL_DRAGGING'          ],
	OnListColEndDrag          => [ 2, 'EVT_LIST_COL_END_DRAG'          ],

	# wxMenuEvent
	OnMenuSelection           => [ 2, 'EVT_MENU'                       ],

	# wxMouseEvent
	OnEnterWindow             => [ 1, 'EVT_ENTER_WINDOW'               ],
	OnLeaveWindow             => [ 1, 'EVT_LEAVE_WINDOW'               ],
	OnLeftDClick              => [ 1, 'EVT_LEFT_DCLICK'                ],
	OnLeftDown                => [ 1, 'EVT_LEFT_DOWN'                  ],
	OnLeftUp                  => [ 1, 'EVT_LEFT_UP'                    ],
	OnMiddleDClick            => [ 1, 'EVT_MIDDLE_DCLICK'              ],
	OnMiddleDown              => [ 1, 'EVT_MIDDLE_DOWN'                ],
	OnMiddleUp                => [ 1, 'EVT_MIDDLE_UP'                  ],
	OnMotion                  => [ 1, 'EVT_MOTION'                     ],
	OnMouseEvents             => [ 1, 'EVT_MOUSE_EVENTS'               ],
	OnMouseWheel              => [ 1, 'EVT_MOUSEWHEEL'                 ],
	OnRightDClick             => [ 1, 'EVT_RIGHT_DCLICK'               ],
	OnRightDown               => [ 1, 'EVT_RIGHT_DOWN'                 ],
	OnRightUp                 => [ 1, 'EVT_RIGHT_UP'                   ],

	# wxNotebookEvent
	OnNotebookPageChanging    => [ 2, 'EVT_NOTEBOOK_PAGE_CHANGING'     ],
	OnNotebookPageChanged     => [ 2, 'EVT_NOTEBOOK_PAGE_CHANGED'      ],

	# wxRadioBox
	OnRadioBox                => [ 2, 'EVT_RADIOBOX'                   ],

	# wxRadioButton
	OnRadioButton             => [ 2, 'EVT_RADIOBUTTON'                ],

	# wxSizeEvent
	OnSize                    => [ 1, 'EVT_SIZE'                       ],

	# wxStdDialogButtonSizer (placeholders)
	OnOKButtonClick           => [                                  ],
	OnYesButtonClick          => [                                  ],
	OnSaveButtonClick         => [                                  ],
	OnApplyButtonClick        => [                                  ],
	OnNoButtonClick           => [                                  ],
	OnCancelButtonClick       => [                                  ],
	OnHelpButtonClick         => [                                  ],
	OnContextTextButtonClick  => [                                  ],

	# wxSearchCtrl
	OnSearchButton            => [ 2, 'EVT_SEARCHCTRL_SEARCH_BTN'      ],
	OnCancelButton            => [ 2, 'EVT_SEARCHCTRL_CANCEL_BTN'      ],

	# wxSpinButton
	OnSpin                    => [ 1, 'EVT_SCROLL_THUMBTRACK'          ],
	OnSpinUp                  => [ 1, 'EVT_SCROLL_LINEUP'              ],
	OnSpinDown                => [ 1, 'EVT_SCROLL_LINEDOWN'            ],

	# wxSplitterEvent
	OnSplitterSashPosChanging => [ 2, 'EVT_SPLITTER_SASH_POS_CHANGING' ],
	OnSplitterSashPosChanged  => [ 2, 'EVT_SPLITTER_SASH_POS_CHANGED'  ],
	OnSplitterUnsplit         => [ 2, 'EVT_SPLITTER_UNSPLIT'           ],
	OnSplitterDClick          => [ 2, 'EVT_SPLITTER_DCLICK'            ],

	# wxToolbar events
	OnToolClicked             => [ 2, 'EVT_TOOL'                       ],
	OnToolRClicked            => [ 2, 'EVT_TOOL_RCLICKED'              ],
	OnToolEnter               => [ 2, 'EVT_TOOL_ENTER'                 ],

	# wxTreeCtrl events
	OnTreeGetInfo             => [ 2, 'EVT_TREE_GET_INFO'              ],
	OnTreeSetInfo             => [ 2, 'EVT_TREE_SET_INFO'              ],
	OnTreeItemGetTooltip      => [ 2, 'EVT_TREE_ITEM_GETTOOLTIP'       ],
	OnTreeStateImageClick     => [ 2, 'EVT_TREE_STATE_IMAGE_CLICK'     ],
	OnTreeBeginDrag           => [ 2, 'EVT_TREE_BEGIN_DRAG'            ],
	OnTreeBeginRDrag          => [ 2, 'EVT_TREE_BEGIN_RDRAG'           ],
	OnTreeEndDrag             => [ 2, 'EVT_TREE_END_DRAG'              ],
	OnTreeBeginLabelEdit      => [ 2, 'EVT_TREE_BEGIN_LABEL_EDIT'      ],
	OnTreeEndLabelEdit        => [ 2, 'EVT_TREE_END_LABEL_EDIT'        ],
	OnTreeItemActivated       => [ 2, 'EVT_TREE_ITEM_ACTIVATED'        ],
	OnTreeItemCollapsed       => [ 2, 'EVT_TREE_ITEM_COLLAPSED'        ],
	OnTreeItemCollapsing      => [ 2, 'EVT_TREE_ITEM_COLLAPSING'       ],
	OnTreeItemExpanded        => [ 2, 'EVT_TREE_ITEM_EXPANDED'         ],
	OnTreeItemExpanding       => [ 2, 'EVT_TREE_ITEM_EXPANDING'        ],
	OnTreeItemRightClick      => [ 2, 'EVT_TREE_ITEM_RIGHT_CLICK'      ],
	OnTreeItemMiddleClick     => [ 2, 'EVT_TREE_ITEM_MIDDLE_CLICK'     ],
	OnTreeSelChanged          => [ 2, 'EVT_TREE_SEL_CHANGED'           ],
	OnTreeSelChanging         => [ 2, 'EVT_TREE_SEL_CHANGING'          ],
	OnTreeKeyDown             => [ 2, 'EVT_TREE_KEY_DOWN'              ],
	OnTreeItemMenu            => [ 2, 'EVT_TREE_ITEM_MENU'             ],
);

# Event Connect Binding Table
our %CONNECT = (
	# Common low level events
	# OnEraseBackground        => 'wxEVT_ERASE_BACKGROUND',
	# OnPaint                  => 'wxEVT_PAINT',
	# OnUpdateUI               => 'wxEVT_UPDATE_UI',

# # 	wxActivateEvent
	# OnActivate               => 'wxEVT_ACTIVATE',
	# OnActivateApp            => 'wxEVT_ACTIVATE_APP',

# # 	wxCalendar
	# OnCalendar               => 'wxEVT_CALENDAR_DOUBLECLICKED',
	# OnCalendarSelChanged     => 'wxEVT_CALENDAR_SEL_CHANGED',
	# OnCalendarDay            => 'wxEVT_CALENDAR_DAY_CHANGED',
	# OnCalendarMonth          => 'wxEVT_CALENDAR_MONTH_CHANGED',
	# OnCalendarYear           => 'wxEVT_CALENDAR_YEAR_CHANGED',
	# OnCalendarWeekDayClicked => 'wxEVT_CALENDAR_WEEKDAY_CLICKED',

# # 	wxChoicebook
	# OnChoicebookPageChanged  => 'wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED',
	# OnChoicebookPageChanging => 'wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING',

# # 	wxCommandEvent
	# OnButtonClick            => 'wxEVT_COMMAND_BUTTON_CLICKED',
	# OnCheckBox               => 'wxEVT_COMMAND_CHECKBOX_CLICKED',
	# OnChoice                 => 'wxEVT_COMMAND_CHOICE_SELECTED',
	# OnCombobox               => 'wxEVT_COMMAND_COMBOBOX_SELECTED',
	# OnListBox                => 'wxEVT_COMMAND_LISTBOX_SELECTED',
	# OnListBoxDClick          => 'wxEVT_COMMAND_LISTBOX_DOUBLECLICKED',
	# OnText                   => 'wxEVT_COMMAND_TEXT_UPDATED',
	# OnTextEnter              => 'wxEVT_COMMAND_TEXT_ENTER',
	# OnMenu                   => 'wxEVT_COMMAND_MENU_SELECTED',

# # 	wxColourPickerCtrl
	# OnColourChanged          => 'wxEVT_COLOURPICKER_CHANGED',

# # 	wxCloseEvent
	# OnClose                  => 'wxEVT_CLOSE_WINDOW',

# # 	wxDatePickerCtrl
	# OnDateChanged            => 'wxEVT_DATE_CHANGED',

# # 	wxFilePickerCtrl
	# OnFileChanged            => 'wxEVT_FILEPICKER_CHANGED',

# # 	wxFocusEvent
	# OnKillFocus              => 'wxEVT_KILL_FOCUS',
	# OnSetFocus               => 'wxEVT_SET_FOCUS',

# # 	wxFontPickerCtrl
	# OnFontChanged            => 'wxEVT_FONTPICKER_CHANGED',
);





######################################################################
# Constructor

sub new {
	my $class = shift;
	my $self  = bless { @_ }, $class;

	# Check params and apply defaults
	unless ( Params::Util::_INSTANCE($self->project, 'FBP::Project') ) {
		die "Missing or invalid 'project' param";
	}
	unless ( defined $self->version ) {
		$self->{version} = '0.01';
	}
	unless ( defined Params::Util::_STRING($self->version) ) {
		die "Missing or invalid 'version' param";
	}
	unless ( defined $self->prefix ) {
		$self->{prefix} = 0;
	}
	unless ( defined Params::Util::_NONNEGINT($self->prefix) ) {
		die "Missing of invalid 'prefix' param";
	}
	unless ( defined $self->i18n ) {
		$self->{i18n} = $self->project->internationalize;
	}
	unless ( defined $self->i18n_trim ) {
		$self->{i18n_trim} = 0;
	}
	$self->{i18n_trim} = $self->i18n_trim ? 1 : 0;
	unless ( defined $self->nocritic ) {
		$self->{nocritic} = 0;
	}
	$self->{nocritic}  = $self->nocritic  ? 1 : 0;
	$self->{shim}      = $self->shim      ? 1 : 0;

lib/FBP/Perl.pm  view on Meta::CPAN

		"$size,",
		$self->window_style($panel),
		");",
	);
}

sub form_sizers {
	my $self     = shift;
	my $form     = shift;
	my $sizer    = $self->form_rootsizer($form);
	my $variable = $self->object_variable($sizer);
	my @children = $self->sizer_pack($sizer);
	my $setsize  = $self->window_setsize($form);

	return (
		@children,
		[
			"\$self->$setsize($variable);",
			"\$self->Layout;",
		]
	);
}

sub form_rootsizer {
	my $self   = shift;
	my $form   = shift;
	my @sizers = grep { $_->isa('FBP::Sizer') } @{$form->children};
	unless ( @sizers ) {
		die "Form does not contain any sizers";
	}
	unless ( @sizers == 1 ) {
		die "Form contains more than one root sizer";
	}
	return $sizers[0];
}

sub form_setsizehints {
	my $self = shift;
	my $form = shift;

	# Only dialogs and frames can resize
	if ( $form->isa('FBP::Dialog') or $form->isa('FBP::Frame') ) {
		# If the dialog has size hints, we do need them
		if ( $self->size($form->minimum_size) ) {
			return 1;
		}
		if ( $self->size($form->maximum_size) ) {
			return 1;
		}
	}

	return 0;
}

sub form_methods {
	my $self    = shift;
	my $form    = shift;
	my @objects = (
		$form,
		$form->find( isa => 'FBP::Window' ),
		$form->find( isa => 'FBP::MenuItem' ),
		$form->find( isa => 'FBP::StdDialogButtonSizer' ),
	);
	my %seen    = ();
	my %done    = ();
	my @methods = ();

	# Add the accessor methods
	foreach my $object ( @objects ) {
		next unless $object->can('name');
		next unless $object->can('permission');
		next unless $object->permission eq 'public';

		# Protect against duplicates
		my $name = $object->name;
		if ( $seen{$name}++ ) {
			die "Duplicate method '$name' detected";
		}

		push @methods, $self->object_accessor($object);
	}

	# Add the event handler methods
	foreach my $object ( @objects ) {
		foreach my $event ( sort keys %MACRO ) {
			next unless $object->can($event);

			my $name   = $object->name;
			my $method = $object->$event();
			next unless defined $method;
			next unless length $method;

			# Protect against duplicates
			if ( $seen{$method} ) {
				die "Duplicate method '$method' detected";
			}
			next if $done{$method}++;

			push @methods, $self->object_event($object, $event);
		}
	}

	# Convert back to a single block of lines
	return [
		map { ( "", @$_ ) } grep { scalar @$_ } @methods
	];
}





######################################################################
# Window and Control Generators

sub children_create {
	my $self    = shift;
	my $object  = shift;
	my $parent  = shift;
	my @windows = ();

lib/FBP/Perl.pm  view on Meta::CPAN


	return @windows;
}

sub window_create {
	my $self   = shift;
	my $window = shift;
	my $parent = shift;
	my $lines  = undef;

	if ( $window->isa('FBP::AnimationCtrl') ) {
		$lines = $self->animationctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::BitmapButton') ) {
		$lines = $self->bitmapbutton_create($window, $parent);
	} elsif ( $window->isa('FBP::Button') ) {
		$lines = $self->button_create($window, $parent);
	} elsif ( $window->isa('FBP::CalendarCtrl') ) {
		$lines = $self->calendarctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::CheckBox') ) {
		$lines = $self->checkbox_create($window, $parent);
	} elsif ( $window->isa('FBP::Choice') ) {
		$lines = $self->choice_create($window, $parent);
	} elsif ( $window->isa('FBP::Choicebook') ) {
		$lines = $self->choicebook_create($window, $parent);
	} elsif ( $window->isa('FBP::ComboBox') ) {
		$lines = $self->combobox_create($window, $parent);
	} elsif ( $window->isa('FBP::ColourPickerCtrl') ) {
		$lines = $self->colourpickerctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::CustomControl' ) ) {
		$lines = $self->customcontrol_create($window, $parent);
	} elsif ( $window->isa('FBP::DatePickerCtrl') ) {
		die "Wx::DatePickerCtrl is not supported by Wx.pm";
		$lines = $self->datepickerctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::DirPickerCtrl') ) {
		$lines = $self->dirpickerctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::FilePickerCtrl') ) {
		$lines = $self->filepickerctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::FontPickerCtrl') ) {
		$lines = $self->fontpickerctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::Gauge') ) {
		$lines = $self->gauge_create($window, $parent);
	} elsif ( $window->isa('FBP::GenericDirCtrl') ) {
		$lines = $self->genericdirctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::Grid') ) {
		$lines = $self->grid_create($window, $parent);
	} elsif ( $window->isa('FBP::HtmlWindow') ) {
		$lines = $self->htmlwindow_create($window, $parent);
	} elsif ( $window->isa('FBP::HyperlinkCtrl') ) {
		$lines = $self->hyperlink_create($window, $parent);
	} elsif ( $window->isa('FBP::Listbook') ) {
		# We emulate the creation of simple listbooks via treebooks
		if ( $window->wxclass eq 'Wx::Treebook' ) {
			$lines = $self->treebook_create($window, $parent);
		} else {
			$lines = $self->listbook_create($window, $parent);
		}
	} elsif ( $window->isa('FBP::ListBox') ) {
		$lines = $self->listbox_create($window, $parent);
	} elsif ( $window->isa('FBP::ListCtrl') ) {
		$lines = $self->listctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::MenuBar') ) {
		$lines = $self->menubar_create($window, $parent);
	} elsif ( $window->isa('FBP::Notebook') ) {
		$lines = $self->notebook_create($window, $parent);
	} elsif ( $window->isa('FBP::Panel') ) {
		$lines = $self->panel_create($window, $parent);
	} elsif ( $window->isa('FBP::RadioBox') ) {
		$lines = $self->radiobox_create($window, $parent);
	} elsif ( $window->isa('FBP::RadioButton') ) {
		$lines = $self->radiobutton_create($window, $parent);
	} elsif ( $window->isa('FBP::RichTextCtrl') ) {
		$lines = $self->richtextctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::ScrollBar') ) {
		$lines = $self->scrollbar_create($window, $parent);
	} elsif ( $window->isa('FBP::ScrolledWindow') ) {
		$lines = $self->scrolledwindow_create($window, $parent);
	} elsif ( $window->isa('FBP::SearchCtrl') ) {
		$lines = $self->searchctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::Slider') ) {
		$lines = $self->slider_create($window, $parent);
	} elsif ( $window->isa('FBP::SpinButton') ) {
		$lines = $self->spinbutton_create($window, $parent);
	} elsif ( $window->isa('FBP::SpinCtrl') ) {
		$lines = $self->spinctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::SplitterWindow') ) {
		$lines = $self->splitterwindow_create($window, $parent);
	} elsif ( $window->isa('FBP::StaticBitmap') ) {
		$lines = $self->staticbitmap_create($window, $parent);
	} elsif ( $window->isa('FBP::StaticLine') ) {
		$lines = $self->staticline_create($window, $parent);
	} elsif ( $window->isa('FBP::StaticText') ) {
		$lines = $self->statictext_create($window, $parent);
	} elsif ( $window->isa('FBP::StatusBar') ) {
		$lines = $self->statusbar_create($window, $parent);
	} elsif ( $window->isa('FBP::TextCtrl') ) {
		$lines = $self->textctrl_create($window, $parent);
	} elsif ( $window->isa('FBP::ToggleButton') ) {
		$lines = $self->togglebutton_create($window, $parent);
	} elsif ( $window->isa('FBP::ToolBar') ) {
		$lines = $self->toolbar_create($window, $parent);
	} elsif ( $window->isa('FBP::TreeCtrl') ) {
		$lines = $self->treectrl_create($window, $parent);
	} else {
		die 'Cannot create constructor code for ' . ref($window);
	}

	# Add common modifications
	push @$lines, $self->window_changes($window);
	push @$lines, $self->object_bindings($window);

	return $lines;
}

sub animationctrl_create {
	my $self      = shift;
	my $control   = shift;
	my $parent    = $self->object_parent(@_);
	my $id        = $self->object_id($control);
	my $animation = $self->animation($control->animation);
	my $position  = $self->object_position($control);
	my $size      = $self->object_wxsize($control);

lib/FBP/Perl.pm  view on Meta::CPAN


	return $self->nested(
		$self->object_new($control),
		"$parent,",
		"$id,",
		"$position,",
		"$size,",
		$self->window_style($control),
		");",
	);
}

sub listbox_create {
	my $self     = shift;
	my $control  = shift;
	my $parent   = $self->object_parent(@_);
	my $id       = $self->object_id($control);
	my $position = $self->object_position($control);
	my $size     = $self->object_wxsize($control);
	my $items    = $self->control_items($control);

	return $self->nested(
		$self->object_new($control),
		"$parent,",
		"$id,",
		"$position,",
		"$size,",
		$items,
		$self->window_style($control),
		");",
	);
}

sub listctrl_create {
	my $self     = shift;
	my $control  = shift;
	my $parent   = $self->object_parent(@_);
	my $id       = $self->object_id($control);
	my $position = $self->object_position($control);
	my $size     = $self->object_wxsize($control);

	return $self->nested(
		$self->object_new($control),
		"$parent,",
		"$id,",
		"$position,",
		"$size,",
		$self->window_style($control),
		");",
	);
}

sub menu_create {
	my $self     = shift;
	my $menu     = shift;
	my $scope    = $self->object_scope($menu);
	my $variable = $self->object_variable($menu);

	# Generate our children
	my @lines = (
		"$scope$variable = Wx::Menu->new;",
		"",
	);
	foreach my $child ( @{$menu->children} ) {
		if ( $child->isa('FBP::Menu') ) {
			push @lines, @{ $self->menu_create($child, $menu) };

		} elsif ( $child->isa('FBP::MenuItem') ) {
			push @lines, @{ $self->menuitem_create($child, $menu) };

		} else {
			next;
		}
		push @lines, "";
	}

	# Fill the menu
	foreach my $child ( @{$menu->children} ) {
		if ( $child->isa('FBP::Menu') ) {
			push @lines, $self->nested(
				"$variable->Append(",
				$self->object_variable($_) . ',',
				$self->object_label($_) . ',',
				");",
			);
		} elsif ( $child->isa('FBP::MenuItem') ) {
			push @lines, "$variable->Append( "
				. $self->object_variable($child)
				. " );";
		} elsif ( $child->isa('FBP::MenuSeparator') ) {
			push @lines, "$variable->AppendSeparator;";
		}
	}

	return \@lines;
}

sub menubar_create {
	my $self     = shift;
	my $window   = shift;
	my $parent   = $self->object_parent(@_);
	my $scope    = $self->object_scope($window);
	my $variable = $self->object_variable($window);
	my $style    = $self->wx($window->styles || 0);

	# Generate our children
	my @children = map {
		$self->menu_create($_, $self)
	} @{$window->children};

	# Build the append list
	my @append = map {
		$self->nested(
			"$variable->Append(",
			$self->object_variable($_) . ',',
			$self->object_label($_) . ',',
			");",
		)
	} @{$window->children};
 
	return [
		( map { @$_, "" } @children ),
		"$scope$variable = Wx::MenuBar->new($style);",
		"",
		@append,
		"",
		"$parent->SetMenuBar( $variable );",
	];
}

sub menuitem_create {
	my $self     = shift;
	my $menu     = shift;
	my $parent   = $self->object_parent(@_);
	my $scope    = $self->object_scope($menu);
	my $variable = $self->object_variable($menu);
	my $id       = $self->object_id($menu);
	my $label    = $self->object_label($menu);
	my $help     = $self->text( $menu->help );
	my $kind     = $self->wx( $menu->kind );

	# Create the menu item
	my $lines = $self->nested(
		"$scope$variable = Wx::MenuItem->new(",
		"$parent,",
		"$id,",
		"$label,",
		"$help,",
		"$kind,",
		");",
	);

	# Add the event bindings
	push @$lines, $self->object_bindings($menu);

	return $lines;
}

sub notebook_create {
	my $self     = shift;
	my $control  = shift;
	my $parent   = $self->object_parent(@_);
	my $id       = $self->object_id($control);
	my $position = $self->object_position($control);
	my $size     = $self->object_wxsize($control);

	return $self->nested(
		$self->object_new($control),
		"$parent,",
		"$id,",
		"$position,",
		"$size,",
		$self->window_style($control),
		");",
	);
}

sub panel_create {
	my $self     = shift;
	my $window   = shift;
	my $parent   = $self->object_parent(@_);
	my $id       = $self->object_id($window);
	my $position = $self->object_position($window);
	my $size     = $self->object_wxsize($window);

	return $self->nested(
		$self->object_new($window),
		"$parent,",
		"$id,",
		"$position,",
		"$size,",
		$self->window_style($window),
		");",
	);
}

sub radiobox_create {
	my $self     = shift;
	my $control  = shift;
	my $parent   = $self->object_parent(@_);
	my $id       = $self->object_id($control);
	my $label    = $self->object_label($control);
	my $position = $self->object_position($control);
	my $size     = $self->object_wxsize($control);



( run in 1.614 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )