Ok, So here's the answers:
 
>I'm looking at the WxRichTextCtrl buttons on:
>http://docs.wxwidgets.org/stable/wx_wxrichtextctrloverview.html 
>and wondering how to implement them.

>Does anyone know where the code is?

Thanks to the C++ wx-users group for this:  it's in the wxWidgets
distribution, samples/richtext/richtext.cpp.

>and wondering how to implement them.

Well here is my stab.  Any comments or improvements would be very welcome.
I hope the subroutine names will be self-explanatory.  
 
Regards

Steve

sub on_click_richtext_bold{
        my ($self, $event) = @_;
        $self->{Ctl_Report_Text_Txt}->ApplyBoldToSelection;
        return $self;
}
sub on_click_richtext_italics{
        my ($self, $event) = @_;
        $self->{Ctl_Report_Text_Txt}->ApplyItalicToSelection;
        return $self;
}
sub on_click_richtext_underline{
        my ($self, $event) = @_;
        $self->{Ctl_Report_Text_Txt}->ApplyUnderlineToSelection;
        return $self;
}
sub on_click_richtext_align_left{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_LEF
T);
        return $self;
}
sub on_click_richtext_align_centre{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_CEN
TRE);
        return $self;
}
sub on_click_richtext_align_right{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_RIG
HT);
        return $self;
}
sub on_click_richtext_align_justify{
        my ($self, $event) = @_;
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_JUS
TIFIED);
        return $self;
}

sub on_click_richtext_indent{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_indent_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);

        $loc_indent_style ->SetLeftIndent(($loc_indent_style ->
GetLeftIndent()) + 50); # Add 5mm to indent position

 
$self->{Ctl_Report_Text_Txt}->SetStyleRange($loc_range,$loc_indent_style);
        return $self;
}

sub on_click_richtext_outdent{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_indent_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);

        $loc_indent_style ->SetLeftIndent(($loc_indent_style ->
GetLeftIndent()) - 50); # Subtract 5mm to indent position

 
$self->{Ctl_Report_Text_Txt}->SetStyleRange($loc_range,$loc_indent_style);
        return $self;
}
sub on_click_richtext_preview{
        my ($self, $event) = @_;
        my $loc_RTC_printing = Wx::RichTextPrinting->new();
        $loc_RTC_printing
->PreviewBuffer($self->{Ctl_Report_Text_Txt}->GetBuffer());
        return $self;
}
sub on_click_richtext_print{
        my ($self, $event) = @_;
        
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_JUS
TIFIED);
        return $self;
}
sub on_click_richtext_pagesetup{
        my ($self, $event) = @_;
        
 
$self->{Ctl_Report_Text_Txt}->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_JUS
TIFIED);
        return $self;
}
sub on_click_richtext_copy{
        my ($self, $event) = @_;
        
        $self->{Ctl_Report_Text_Txt}->Copy();
        return $self;
}
sub on_click_richtext_cut{
        my ($self, $event) = @_;
        
        $self->{Ctl_Report_Text_Txt}->Cut();
        return $self;
}
sub on_click_richtext_paste{
        my ($self, $event) = @_;
        
        $self->{Ctl_Report_Text_Txt}->Paste();
        return $self;
}

sub on_click_richtext_bullets{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);

        my $loc_RTC_Bullet_Style_Definition =
Wx::RichTextListStyleDefinition->new("Bullet List 1");
        for (my $i=0;$i<10;$i++){
                $loc_RTC_Bullet_Style_Definition -> SetAttributes($i, $i*50,
50, wxTEXT_ATTR_BULLET_STYLE_STANDARD, "standard/Square");
        }
        $loc_RTC_Bullet_Style_Definition -> SetStyle($loc_style);
        
 
$self->{Ctl_Report_Text_Txt}->ApplyStyle($loc_RTC_Bullet_Style_Definition);
        return $self;
}

sub on_click_richtext_paragraph{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);
        my $log_pages =
wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_BULLETS|wxRICHTEXT_FORMA
T_TABS;
        my $dlg_format = Wx::RichTextFormattingDialog -> newFull
($log_pages,$self,"Format Paragraph",wxID_ANY, wxDefaultPosition,
wxDefaultSize,wxDEFAULT_DIALOG_STYLE); # , -1, (t("Paragraph details"))
        $dlg_format -> GetStyle ($self->{Ctl_Report_Text_Txt}, $loc_range);
        if ($dlg_format->ShowModal()==wxID_OK){
 
$dlg_format->ApplyStyle($self->{Ctl_Report_Text_Txt},$loc_range,wxRICHTEXT_S
ETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_PARAGRAPH
S_ONLY)
        }
        
        return $self;
}

sub on_click_richtext_font{
        my ($self, $event) = @_;
        my $loc_position = $self->{Ctl_Report_Text_Txt} ->
GetCaretPosition();          # Get current position
        my $loc_range = Wx::RichTextRange->new($loc_position,$loc_position);
        if ($self->{Ctl_Report_Text_Txt} -> HasSelection) {
# If there is a selection
                $loc_range = $self->{Ctl_Report_Text_Txt} ->
GetSelectionRange();       # Get current range
        }
        my $loc_style =
$self->{Ctl_Report_Text_Txt}->GetRichTextAttrStyle($loc_position);
        my $log_pages = wxRICHTEXT_FORMAT_FONT;
        my $dlg_format = Wx::RichTextFormattingDialog -> newFull
($log_pages,$self,"Format Paragraph",wxID_ANY, wxDefaultPosition,
wxDefaultSize,wxDEFAULT_DIALOG_STYLE); # , -1, (t("Paragraph details"))
        $dlg_format -> GetStyle ($self->{Ctl_Report_Text_Txt}, $loc_range);
        if ($dlg_format->ShowModal()==wxID_OK){
 
$dlg_format->ApplyStyle($self->{Ctl_Report_Text_Txt},$loc_range,wxRICHTEXT_S
ETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_CHARACTER
S_ONLY)
        }
        
        return $self;
}


Reply via email to