App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/Wx/Utils.pm  view on Meta::CPAN


################ ################

sub ellipsize( $widget, %opts ) {
    my $text = $opts{text} // $widget->GetText;
    my $home = ChordPro::Paths->get->home;
    $text =~ s/^\Q$home\E\/*/~\//;
    my $width = ($widget->GetSizeWH)[0];

    $text = Wx::Control::Ellipsize( $text, Wx::WindowDC->new($widget),
				    $opts{type} // wxELLIPSIZE_END(),
				    $width-10, wxELLIPSIZE_FLAGS_DEFAULT() )
      if Wx::Control->can("Ellipsize");

    # Change w/o triggering a EVT_TEXT event.
    $widget->ChangeValue($text);
}

push( @EXPORT, "ellipsize" );

################ ################

sub kbdkey( $key ) {
    $key =~ s/Shift-/⇧/;
    $key =~ s/Alt-/⎇/;
    $key =~ s/Option-/⌥/;
    my $c = is_macos ? "⌘" : "Ctrl-";
    $key =~ s/Ctrl-/$c/;
    return $key;
}

push( @EXPORT, "kbdkey" );

use Storable();

################ ################

sub clone( $struct ) { Storable::dclone($struct) }

push( @EXPORT, "clone" );

################ ################

sub Wx::ColourPickerCtrl::GetAsHTML( $self ) {
    $self->GetColour->GetAsString(wxC2S_HTML_SYNTAX);
}

################ ################

# Override Wx::Bitmap to use resource search.
unless ( $::wxbitmapnew ) {
    $::wxbitmapnew = \&Wx::Bitmap::new;
    no warnings 'redefine';
    use File::Basename;
    *Wx::Bitmap::new = sub {
	# Only handle Wx::Bitmap->new(file, type) case.
	goto &$::wxbitmapnew if @_ != 3 || fs_test( f => $_[1] );
	my ($self, @rest) = @_;
	$rest[0] = ChordPro::Paths->get->findres( basename($rest[0]),
						  class => "icons" );
	$rest[0] ||= ChordPro::Paths->get->findres( "missing.png",
						    class => "icons" );
	$::wxbitmapnew->($self, @rest);
    };
}

################ ################

sub has_appearance() {
    Wx::SystemSettings->can("GetAppearance");
}

push( @EXPORT, 'has_appearance' );

################ ################



( run in 0.642 second using v1.01-cache-2.11-cpan-df04353d9ac )